📄 gfuntype.c
字号:
/****************************************************************************
*
* Copyright (c) 2002, John Forkosh Associates, Inc. All rights reserved.
* --------------------------------------------------------------------------
* This file is part of mimeTeX, which is free software. You may redistribute
* and/or modify it under the terms of the GNU General Public License,
* version 2 or later, as published by the Free Software Foundation.
* MimeTeX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY, not even the implied warranty of MERCHANTABILITY.
* See the GNU General Public License for specific details.
* By using mimeTeX, you warrant that you have read, understood and
* agreed to these terms and conditions, and that you are at least 18 years
* of age and possess the legal right and ability to enter into this
* agreement and to use mimeTeX in accordance with it.
* Your mimeTeX distribution should contain a copy of the GNU General
* Public License. If not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* --------------------------------------------------------------------------
*
* Program: gfuntype [-g gformat] [-u isnoname] [-m msglevel]
* [-n fontname] [infile [outfile]]
*
* Purpose: Parses output from gftype -i
* and writes pixel bitmap data of the characters
* in a format suitable for a C header file, etc.
*
* --------------------------------------------------------------------------
*
* Command-line Arguments:
* --- args can be in any order ---
* infile name of input file
* (defaults to stdin if no filenames given)
* outfile name of output file
* (defaults to stdout if <2 filenames given)
* -g gformat gformat=1(default) for bitmap representation,
* or 2,3 for 8-bit,4-bit .gf-like compression,
* or 0 to choose smallest format.
* Add 10 (gformat=10,12,13,14) to embed scan
* line repeat counts in format.
* -u isnoname isnoname=1(default) to output symbols not
* defined/named in mimetex.h, or 0 to omit them
* -m msglevel verbose if msglevel>=9 (vv if >=99)
* -n fontname string used for fontname
* (defaults to noname)
*
* Exits: 0=success, 1=some error
*
* Notes: o To compile
* cc gfuntype.c mimetex.c -lm -o gfuntype
* needs mimetex.c and mimetex.h
*
* Source: gfuntype.c
*
* --------------------------------------------------------------------------
* Revision History:
* 09/22/02 J.Forkosh Installation.
* 10/11/05 J.Forkosh .gf-style format options added.
*
****************************************************************************/
/* --------------------------------------------------------------------------
standard headers, program parameters, global data and macros
-------------------------------------------------------------------------- */
/* --- standard headers --- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* --- application headers --- */
/* #define SIGNEDCHAR */
#include "mimetex.h"
/* --- parameters either -D defined on cc line, or defaulted here --- */
#ifndef MSGLEVEL
#define MSGLEVEL 0
#endif
#ifndef GFORMAT
#define GFORMAT 1
#endif
#ifndef ISREPEAT
#define ISREPEAT 1
#endif
/* --- message level (verbose test) --- */
static int msglevel = MSGLEVEL; /* verbose if msglevel >= 9 */
static FILE *msgfp; /* verbose output goes here */
/* --- output file format --- */
static int isnoname = 1; /* true to output unnamed symbols */
static char *noname = "(noname)"; /* char name used if lookup fails */
static int gformat = GFORMAT; /* 1=bitmap, 2=.gf-like */
static int isrepeat = ISREPEAT; /* true to store line repeat counts*/
/* extern int imageformat; */ /* as per gformat, 1=bitmap,2=.gf */
/* --- miscellaneous other data --- */
#define CORNER_STUB ".<--" /* start of upper,lower-left line */
#define BLANKCHAR_STUB "character is entirely blank" /* signals blank char */
#define TYPECAST "(pixbyte *)" /* typecast for pixmap string */
/* ==========================================================================
* Function: main() for gfuntype.c
* Purpose: interprets command-line args, etc
* --------------------------------------------------------------------------
* Command-Line Arguments:
* See above
* --------------------------------------------------------------------------
* Returns: 0=success, 1=some error
* --------------------------------------------------------------------------
* Notes: o
* ======================================================================= */
/* --- entry point --- */
int main ( int argc, char *argv[] )
{
/* --------------------------------------------------------------------------
Allocations and Declarations
-------------------------------------------------------------------------- */
int argnum = 0; /* argv[] index for command-line args */
int inarg=0, outarg=0; /* argv[] indexes for infile, outfile */
int iserror = 1; /* error signal */
int charnum, /* character number (nextchar->charnum) */
nchars = 0; /* #chars in font */
char fontname[99] = "noname", /* font name */
*getcharname(); /* get character name from its number */
FILE /* *fopen(),*/ *infp=stdin, *outfp=stdout; /* init file pointers */
chardef *getnextchar(), *nextchar, /* read and parse next char in infp */
*fontdef[256]; /* chars stored using charnum as index */
int cstruct_chardef(); /* emit C struct for a character map */
int type_raster(); /* display debugging output */
char *copyright = /* copyright, gnu/gpl notice */
"+-----------------------------------------------------------------------+\n"
"|gfuntype ver 1.00, Copyright(c) 2002-2003, John Forkosh Associates, Inc|\n"
"+-----------------------------------------------------------------------+\n"
"| gfuntype is free software licensed to you under terms of the GNU/GPL, |\n"
"| and comes with absolutely no warranty whatsoever. |\n"
"+-----------------------------------------------------------------------+";
/* --------------------------------------------------------------------------
interpret command-line arguments
-------------------------------------------------------------------------- */
while ( argc > ++argnum ) /* check for flags and filenames */
if ( *argv[argnum] == '-' ) /* got some '-' flag */
{
char flag = tolower(*(argv[argnum]+1)); /* char following '-' */
argnum++; /* arg following flag is usually its value */
switch ( flag ) /* see what user wants to tell us */
{
/* --- no usage for clueless users yet --- */
default: exit(iserror); /* exit quietly for unrecognized input */
/* --- adjustable program parameters (not checking input) --- */
case 'g': gformat = atoi(argv[argnum]);
isrepeat = (gformat>=10?1:0);
gformat = gformat%10; break;
case 'u': isnoname = atoi(argv[argnum]); break;
case 'm': msglevel = atoi(argv[argnum]); break;
case 'n': strcpy(fontname,argv[argnum]); break;
} /* --- end-of-switch() --- */
} /* --- end-of-if(*argv[]=='-') --- */
else /* this arg not a -flag, so it must be... */
if ( inarg == 0 ) /* no infile arg yet */
inarg = argnum; /* so use this one */
else /* we already have an infile arg */
if ( outarg == 0 ) /* but no outfile arg yet */
outarg = argnum; /* so use this one */
/* --- set verbose file ptr --- */
msgfp = (outarg>0? stdout : stderr); /* use stdout or stderr */
/* --- emit copyright, gnu/gpl notice --- */
fprintf(msgfp,"%s\n",copyright); /* display copyright, gnu/gpl info */
/* --- display input args if verbose output --- */
if ( msglevel >= 9 ) /* verbose output requested */
fprintf(msgfp,"gfuntype> infile=%s outfile=%s, fontname=%s format=%d.%d\n",
(inarg>0?argv[inarg]:"stdin"), (outarg>0?argv[outarg]:"stdout"),
fontname, gformat,isrepeat);
/* --------------------------------------------------------------------------
initialization
-------------------------------------------------------------------------- */
/* --- initialize font[] array --- */
for ( charnum=0; charnum<256; charnum++ ) /*for each possible char in font*/
fontdef[charnum] = (chardef *)NULL; /* char doesn't exist yet */
/* --- open input file (if necessary) --- */
if ( inarg > 0 ) /* input from file, not from stdin */
if ( (infp = fopen(argv[inarg],"r")) == NULL ) /*try to open input file*/
{ fprintf(msgfp,"gfuntype> can't open %s for read\n",argv[inarg]);
goto end_of_job; } /* report error and quit */
/* --- set format for mimetex.c functions --- */
if ( gformat<0 || gformat>3 ) gformat=1; /* sanity check */
/* if ( gformat == 1 ) imageformat = 1; */ /* force bitmap format */
/* else gformat = imageformat = 2; */ /* or force .gf format */
/* --------------------------------------------------------------------------
process input file
-------------------------------------------------------------------------- */
while ( (nextchar=getnextchar(infp)) != NULL ) /* get each char in file */
{
/* --- display character info --- */
if ( msglevel >= 9 ) /* verbose output requested */
fprintf(msgfp,"gfuntype> Char#%3d, loc %4d: ul=(%d,%d) ll=(%d,%d)\n",
nextchar->charnum, nextchar->location,
nextchar->topleftcol,nextchar->toprow,
nextchar->botleftcol,nextchar->botrow);
if ( msglevel >= 19 ) /* if a bit more verbose */
type_raster(&(nextchar->image),msgfp); /*display ascii image of raster*/
/* --- store character in font */
charnum = nextchar->charnum; /* get char number of char in font */
if ( charnum>=0 && charnum<=255 ) /* check for valid range */
fontdef[charnum] = nextchar; /* store char in font */
} /* --- end-of-while(charnum>0) --- */
/* --------------------------------------------------------------------------
generate output file
-------------------------------------------------------------------------- */
/* --- open output file (if necessary) --- */
if ( outarg > 0 ) /* output to a file, not to stdout */
if ( (outfp = fopen(argv[outarg],"w")) == NULL ) /*try to open output file*/
{ fprintf(msgfp,"gfuntype> can't open %s for write\n",argv[outarg]);
goto end_of_job; } /* report error and quit */
/* --- header lines --- */
fprintf(outfp,"/%c --- fontdef for %s --- %c/\n", '*',fontname,'*');
fprintf(outfp,"static\tchardef %c%s[] =\n {\n", ' ',fontname);
/* --- write characters comprising font --- */
for ( charnum=0; charnum<256; charnum++ ) /*for each possible char in font*/
if ( fontdef[charnum] != (chardef *)NULL ) /*check if char exists in font*/
{ char *charname = getcharname(fontname,charnum);
if ( charname!=NULL || isnoname ) { /* char defined or want undefined */
if ( ++nchars > 1 ) /* bump count */
fprintf(outfp,",\n"); /* and terminate preceding chardef */
fprintf(outfp," /%c --- pixel bitmap for %s char#%d %s --- %c/\n",
'*',fontname,charnum,(charname==NULL?noname:charname),'*');
cstruct_chardef(fontdef[charnum],outfp,6); } /*emit chardef struct*/
else
if(0)fprintf(outfp,"NULL"); /* no character in this position */
} /* --- end-of-if(fontdef[]!=NULL) --- */
else
if(0)fprintf(outfp,"NULL"); /* no character in this position */
/* --- write trailer chardef and closing brace --- */
fprintf(outfp,",\n"); /* finish up last map from loop */
fprintf(outfp," /%c --- trailer --- %c/\n",'*','*'); /* trailer... */
fprintf(outfp," { -99, -999, 0,0,0,0, { 0,0,0,0, %s\"\\0\" } }\n",
TYPECAST);
fprintf(outfp," } ;\n"); /* terminating }; for fontdef */
/* --------------------------------------------------------------------------
end-of-job
-------------------------------------------------------------------------- */
/* --- reset error status for okay exit --- */
iserror = 0;
/* --- close files (if they're open and not stdin/out) --- */
end_of_job:
if ( infp!=NULL && infp!=stdin ) fclose( infp);
if ( outfp!=NULL && outfp!=stdout ) fclose(outfp);
exit ( iserror );
} /* --- end-of-function main() --- */
/* ==========================================================================
* Function: getnextchar ( fp )
* Purpose: Reads and parses the next character definition on fp,
* and returns a new chardef struct describing that character.
* --------------------------------------------------------------------------
* Arguments: fp (I) FILE * to input file
* (containing output from gftype -i)
* Returns: ( chardef * ) ptr to chardef struct describing character,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -