Annotation of researchv10dc/cmd/dimpress/misc.c, revision 1.1

1.1     ! root        1: 
        !             2: /*
        !             3:  *
        !             4:  * A few general purpose routines that can be used with any of the built
        !             5:  * from these files.
        !             6:  *
        !             7:  */
        !             8: 
        !             9: 
        !            10: #include <stdio.h>
        !            11: #include <ctype.h>
        !            12: 
        !            13: #include "gen.h"                       /* a few general purpose definitions */
        !            14: #include "ext.h"                       /* external variable declarations */
        !            15: 
        !            16: 
        !            17: int    nolist = 0;                     /* number of specified ranges */
        !            18: int    olist[30];                      /* processing range pairs */
        !            19: 
        !            20: 
        !            21: /*****************************************************************************/
        !            22: 
        !            23: 
        !            24: putint(n, fp)
        !            25: 
        !            26: 
        !            27:     int                n;                      /* number we want written out */
        !            28:     FILE       *fp;                    /* as next two bytes in this file */
        !            29: 
        !            30: 
        !            31: {
        !            32: 
        !            33: 
        !            34: /*
        !            35:  *
        !            36:  * Makes sure the value stored in the lower 16 bits of integer n is written
        !            37:  * as the next two bytes in file *fp. Used to write Impress commands that
        !            38:  * have 'word' values.
        !            39:  *
        !            40:  */
        !            41: 
        !            42: 
        !            43:     putc(n >> BYTE, fp);
        !            44:     putc(n & BMASK, fp);
        !            45: 
        !            46: }   /* End of putint */
        !            47: 
        !            48: 
        !            49: /*****************************************************************************/
        !            50: 
        !            51: 
        !            52: out_list(str)
        !            53: 
        !            54: 
        !            55:     char       *str;                   /* process ranges in this string */
        !            56: 
        !            57: 
        !            58: {
        !            59: 
        !            60: 
        !            61:     int                start, stop;            /* range end points */
        !            62: 
        !            63: 
        !            64: /*
        !            65:  *
        !            66:  * Called to get the processing ranges that were specified by using the
        !            67:  * -o option. Hopefully the range syntax is identical to the one used in
        !            68:  * troff and nroff. Depending on the program the ranges may be used to
        !            69:  * select pages we want printed or possibly glyphs that we want to display.
        !            70:  *
        !            71:  */
        !            72: 
        !            73: 
        !            74:     while ( *str  &&  nolist < sizeof(olist) - 2 )  {
        !            75:        start = stop = str_convert(&str, 0);
        !            76: 
        !            77:        if ( *str == '-'  &&  *str++ )
        !            78:            stop = str_convert(&str, 9999);
        !            79: 
        !            80:        if ( start > stop )
        !            81:            error(FATAL, "illegal range %d-%d", start, stop);
        !            82: 
        !            83:        olist[nolist++] = start;
        !            84:        olist[nolist++] = stop;
        !            85: 
        !            86:        if ( *str != '\0' ) str++;
        !            87: 
        !            88:     }  /* End while */
        !            89: 
        !            90:     olist[nolist] = 0;
        !            91: 
        !            92: }   /* End of out_list */
        !            93: 
        !            94: 
        !            95: /*****************************************************************************/
        !            96: 
        !            97: 
        !            98: in_olist(num)
        !            99: 
        !           100: 
        !           101:     int                num;                    /* should we process this guy? */
        !           102: 
        !           103: 
        !           104: {
        !           105: 
        !           106: 
        !           107:     int                i;                      /* just a loop index */
        !           108: 
        !           109: 
        !           110: /*
        !           111:  *
        !           112:  * If num (may be a page or glyph) should be processed ON will be returned,
        !           113:  * otherwise OFF is returned. If no ranges were initially selected nolist
        !           114:  * will be zero and we'll assume everything is supposed to be processed.
        !           115:  *
        !           116:  */
        !           117: 
        !           118: 
        !           119:     if ( nolist == 0 )                 /* everything's included */
        !           120:        return(ON);
        !           121: 
        !           122:     for ( i = 0; i < nolist; i += 2 )
        !           123:        if ( num >= olist[i]  &&  num <= olist[i+1] )
        !           124:            return(ON);
        !           125: 
        !           126:     return(OFF);
        !           127: 
        !           128: }   /* End of in_olist */
        !           129: 
        !           130: 
        !           131: /*****************************************************************************/
        !           132: 
        !           133: 
        !           134: str_convert(str, err)
        !           135: 
        !           136: 
        !           137:     char       **str;                  /* get next number from this string */
        !           138:     int                err;                    /* value returned on error */
        !           139: 
        !           140: 
        !           141: {
        !           142: 
        !           143: 
        !           144:     int                i;                      /* just a loop index */
        !           145: 
        !           146: 
        !           147: /*
        !           148:  *
        !           149:  * Gets the next integer from **str and returns its value to the caller.
        !           150:  * If **str isn't an integer err is returned. *str is updated after each
        !           151:  * digit is processed.
        !           152:  *
        !           153:  */
        !           154: 
        !           155: 
        !           156:     if ( ! isdigit(**str) )            /* something's wrong */
        !           157:        return(err);
        !           158: 
        !           159:     for ( i = 0; isdigit(**str); *str += 1 )
        !           160:        i = 10 * i + **str - '0';
        !           161: 
        !           162:     return(i);
        !           163: 
        !           164: }   /* End of str_convert */
        !           165: 
        !           166: 
        !           167: /*****************************************************************************/
        !           168: 
        !           169: 
        !           170: error(kind, mesg, a1, a2, a3)
        !           171: 
        !           172: 
        !           173:     int                kind;                   /* FATAL or NON_FATAL error */
        !           174:     char       *mesg;                  /* error message control string */
        !           175:     unsigned   a1, a2, a3;             /* control string arguments */
        !           176: 
        !           177: 
        !           178: {
        !           179: 
        !           180: 
        !           181: /*
        !           182:  *
        !           183:  * Called when we've run into some kind of program error. First *mesg is
        !           184:  * printed using the control string arguments a?. Then if kind is FATAL
        !           185:  * and we're not ignoring errors the program will be terminated. Probably
        !           186:  * should call a routine to clean things up for whatever program is using
        !           187:  * this routine. Could use signal() to figure out who, if anyone, should
        !           188:  * be called.
        !           189:  *
        !           190:  * If mesg is NULL or *mesg is the NULL string nothing will be printed.
        !           191:  *
        !           192:  */
        !           193: 
        !           194: 
        !           195:     if ( mesg != NULL  &&  *mesg != '\0' )  {
        !           196:        fprintf(stderr, "%s: ", prog_name);
        !           197:        fprintf(stderr, mesg, a1, a2, a3);
        !           198:        if ( lineno > 0 )
        !           199:            fprintf(stderr, " (line %d)", lineno);
        !           200:        putc('\n', stderr);
        !           201:     }  /* End if */
        !           202: 
        !           203:     if ( kind == FATAL  &&  ignore == OFF )
        !           204:        exit(x_stat == 0 ? 01 : x_stat);
        !           205: 
        !           206: }   /* End of error */
        !           207: 
        !           208: 
        !           209: /*****************************************************************************/
        !           210: 
        !           211: 

unix.superglobalmegacorp.com

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