3 * General purpose routines.
18 int nolist = 0; /* number of specified ranges */
19 int olist[50]; /* processing range pairs */
21 int str_convert(char **str, int err);
22 void error(int kind, char *mesg, unsigned int a1, unsigned int a2, unsigned int a3);
25 /*****************************************************************************/
26 extern int str_convert();
39 * Grab page ranges from str, save them in olist[], and update the nolist
40 * count. Range syntax matches nroff/troff syntax.
44 while ( *str && nolist < sizeof(olist) - 2 ) {
45 start = stop = str_convert(&str, 0);
47 if ( *str == '-' && *str++ )
48 stop = str_convert(&str, 9999);
51 error(FATAL, "illegal range %d-%d", start, stop, 0);
53 olist[nolist++] = start;
54 olist[nolist++] = stop;
56 if ( *str != '\0' ) str++;
61 } /* End of out_list */
63 /*****************************************************************************/
75 * Return ON if num is in the current page range list. Print everything if
82 for ( i = 0; i < nolist; i += 2 )
83 if ( num >= olist[i] && num <= olist[i+1] )
88 } /* End of in_olist */
90 /*****************************************************************************/
102 * Include the font encoding file selected by name. It's a full pathname if
103 * it begins with /, otherwise append suffix ".enc" and look for the file in
104 * ENCODINGDIR. Missing files are silently ignored.
113 else sprintf(path, "%s/%s.enc", ENCODINGDIR, name);
115 if ( cat(path) == TRUE )
116 writing = strncmp(name, "UTF", 3) == 0;
118 } /* End of setencoding */
120 /*****************************************************************************/
135 * Copy *file to stdout. Return FALSE is there was a problem.
141 if ( (fd_in = open(file, O_RDONLY)) == -1 )
144 fd_out = fileno(stdout);
145 while ( (count = read(fd_in, buf, sizeof(buf))) > 0 )
146 write(fd_out, buf, count);
154 /*****************************************************************************/
157 str_convert(str, err)
168 * Grab the next integer from **str and return its value or err if *str
169 * isn't an integer. *str is modified after each digit is read.
173 if ( ! isdigit(**str) )
176 for ( i = 0; isdigit(**str); *str += 1 )
177 i = 10 * i + **str - '0';
181 } /* End of str_convert */
183 /*****************************************************************************/
186 error(kind, mesg, a1, a2, a3)
196 * Print an error message and quit if kind is FATAL.
200 if ( mesg != NULL && *mesg != '\0' ) {
201 fprintf(stderr, "%s: ", prog_name);
202 fprintf(stderr, mesg, a1, a2, a3);
204 fprintf(stderr, " (line %ld)", lineno);
206 fprintf(stderr, " (near byte %ld)", position);
210 if ( kind == FATAL && ignore == OFF ) {
211 if ( temp_file != NULL )
218 /*****************************************************************************/
228 * Signal handler for translators.
232 if ( temp_file != NULL )
237 } /* End of interrupt */
239 /*****************************************************************************/