Annotation of researchv10no/cmd/dimpress/readrast.c, revision 1.1.1.1

1.1       root        1: 
                      2: 
                      3: /*
                      4:  *
                      5:  * Reads raster files in Imagen's format and dumps all the glyphs, or
                      6:  * just the ones selected by the -o option, to stdout. The non-option
                      7:  * arguments are the names of the raster files that you want to display.
                      8:  * For example to dump glyphs 12, 23, and 24 in raster file cmasc10.r10
                      9:  * just type,
                     10:  *
                     11:  *                  readrast -o12,23,24 cmasc10.r10
                     12:  *
                     13:  * The raster files are all assumed to be in directory *rastdir, which by
                     14:  * default is set to ".", but it can be changed by using the -R option.
                     15:  *
                     16:  * A word of warning is in order here. Because I've written readrastfile()
                     17:  * so it accepts two different raster file naming conventions there isn't
                     18:  * a one to one mapping of file names to font name, size pairs. That means
                     19:  * if you have two similiarly named raster files, differing only in the
                     20:  * naming convention used, and you keep them in the same directory you'll
                     21:  * always display glyphs from the preferred file no matter which file
                     22:  * you list on the command line. I don't think it will cause any real
                     23:  * problems so I'm not going to change any of this stuff.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: #include <stdio.h>
                     29: 
                     30: #include "gen.h"                       /* general purpose definitions */
                     31: #include "ext.h"                       /* external variable declarations */
                     32: #include "rast.h"                      /* raster file definitions */
                     33: 
                     34: 
                     35: /*****************************************************************************/
                     36: 
                     37: 
                     38: main(agc, agv)
                     39: 
                     40: 
                     41:     int                agc;
                     42:     char       *agv[];
                     43: 
                     44: 
                     45: {
                     46: 
                     47: 
                     48: /*
                     49:  *
                     50:  * As I mentioned before this program is used to display glyph bitmaps
                     51:  * from Imagen formatted raster files on stdout. Use the -o option to
                     52:  * select one or more glyphs.
                     53:  *
                     54:  */
                     55: 
                     56: 
                     57:     argc = agc;                                /* other routines may want them */
                     58:     argv = agv;
                     59: 
                     60:     prog_name = argv[0];               /* really just for error messages */
                     61:     rastdir = ".";                     /* current directory by default */
                     62: 
                     63:     options();                         /* first get command line options */
                     64:     arguments();                       /* then process non-option arguments */
                     65: 
                     66:     exit(x_stat);                      /* everything probably went OK */
                     67: 
                     68: }   /* End of main */
                     69: 
                     70: 
                     71: /*****************************************************************************/
                     72: 
                     73: 
                     74: options()
                     75: 
                     76: 
                     77: {
                     78: 
                     79: 
                     80:     int                ch;                     /* return value from getopt() */
                     81:     char       *names = "DIF:R:o:";
                     82: 
                     83:     extern char        *optarg;                /* used by getopt() */
                     84:     extern int optind;
                     85: 
                     86: 
                     87: /*
                     88:  *
                     89:  * Reads and processes the command line options. Right now the recognized
                     90:  * options are,
                     91:  *
                     92:  */
                     93: 
                     94: 
                     95:     while ( (ch = getopt(argc, argv, names)) != EOF )  {
                     96: 
                     97:        switch ( ch )  {
                     98: 
                     99:            case 'o':                   /* processing range list */
                    100:                    out_list(optarg);
                    101:                    break;
                    102: 
                    103:            case 'F':                   /* new troff font directory */
                    104:                    fontdir = optarg;
                    105:                    break;
                    106: 
                    107:            case 'R':                   /* set raster table directory */
                    108:                    rastdir = optarg;
                    109:                    break;
                    110: 
                    111:            case 'D':                   /* debug flag */
                    112:                    debug = ON;
                    113:                    break;
                    114: 
                    115:            case 'I':                   /* ignore FATAL errors */
                    116:                    ignore = ON;
                    117:                    break;
                    118: 
                    119:            case '?':                   /* don't understand the option */
                    120:                    error(FATAL, "");
                    121:                    break;
                    122: 
                    123:            default:                    /* don't know what to do for ch */
                    124:                    error(FATAL, "missing case for option %c\n", ch);
                    125:                    break;
                    126: 
                    127:        }   /* End switch */
                    128: 
                    129:     }   /* End while */
                    130: 
                    131:     argc -= optind;                    /* get ready for non-option args */
                    132:     argv += optind;
                    133: 
                    134: }   /* End of options */
                    135: 
                    136: 
                    137: /*****************************************************************************/
                    138: 
                    139: 
                    140: arguments()
                    141: 
                    142: 
                    143: {
                    144: 
                    145: 
                    146:     char       name[100];              /* raster file pathname */
                    147:     char       *font;                  /* includes up to the '.' in *argv */
                    148:     char       *size;                  /* number after '.' and possibly 'r' */
                    149:     int                i;                      /* just a loop index */
                    150: 
                    151:     char       *strtok();
                    152: 
                    153: 
                    154: /*
                    155:  *
                    156:  * All the remaining arguments are the names of raster files in *rastdir
                    157:  * that we want to display. Because two raster file naming conventions
                    158:  * are used in rast.c we can't be absolutely sure we're really displaying
                    159:  * the raster file that the user wanted. That's why the pathname is built
                    160:  * up in name[] and access to the file is checked. That's probably good
                    161:  * enough for our purposes, but it still doesn't guarantee you get what
                    162:  * you asked for. It shouldn't cause any real problems as long as you
                    163:  * don't try and keep raster files with the two different naming conventions
                    164:  * in the same directory.
                    165:  *
                    166:  */
                    167: 
                    168: 
                    169:     if ( argc < 1 )
                    170:        error(FATAL, "can't read standard input");
                    171:     else  {                            /* have at least one argument */
                    172:        while ( argc > 0 )  {
                    173:            sprintf(name, "%s/%s", rastdir, *argv);
                    174:            if ( access(name, 04) == -1 )
                    175:                error(FATAL, "can't read file %s", name);
                    176: 
                    177:            if ( (font = strtok(*argv, ".")) == NULL )
                    178:                error(FATAL, "Bad raster file name %s", *argv);
                    179: 
                    180:            if ( *(size = font + strlen(font) + 1) == 'r' ) size++;
                    181: 
                    182:            fprintf(stdout, "Get raster file for font %s, size %s\n", font, size);
                    183:            getrastdata(font, atoi(size));
                    184: 
                    185:            for ( i = fam->first; i <= fam->last; i++ )
                    186:                if ( in_olist(i) == ON )
                    187:                    dump_glyph(i, stdout);
                    188: 
                    189:            argc--;
                    190:            argv++;
                    191:        }   /* End while */
                    192:     }   /* End else */
                    193: 
                    194: }   /* End of arguments */
                    195: 
                    196: 
                    197: /*****************************************************************************/
                    198: 
                    199: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.