3 * General purpose routines.
10 #include <sys/types.h>
19 int nolist = 0; /* number of specified ranges */
20 int olist[50]; /* processing range pairs */
22 int str_convert(char **str, int err);
23 void error(int kind, char *mesg, unsigned int a1, unsigned int a2, unsigned int a3);
26 /*****************************************************************************/
27 extern int str_convert();
40 * Grab page ranges from str, save them in olist[], and update the nolist
41 * count. Range syntax matches nroff/troff syntax.
45 while ( *str && nolist < sizeof(olist) - 2 ) {
46 start = stop = str_convert(&str, 0);
48 if ( *str == '-' && *str++ )
49 stop = str_convert(&str, 9999);
52 error(FATAL, "illegal range %d-%d", start, stop, 0);
54 olist[nolist++] = start;
55 olist[nolist++] = stop;
57 if ( *str != '\0' ) str++;
62 } /* End of out_list */
64 /*****************************************************************************/
76 * Return ON if num is in the current page range list. Print everything if
83 for ( i = 0; i < nolist; i += 2 )
84 if ( num >= olist[i] && num <= olist[i+1] )
89 } /* End of in_olist */
91 /*****************************************************************************/
103 * Include the font encoding file selected by name. It's a full pathname if
104 * it begins with /, otherwise append suffix ".enc" and look for the file in
105 * ENCODINGDIR. Missing files are silently ignored.
114 else sprintf(path, "%s/%s.enc", ENCODINGDIR, name);
116 if ( cat(path) == TRUE )
117 writing = strncmp(name, "UTF", 3) == 0;
119 } /* End of setencoding */
121 /*****************************************************************************/
136 * Copy *file to stdout. Return FALSE is there was a problem.
142 if ( (fd_in = open(file, O_RDONLY)) == -1 )
145 fd_out = fileno(stdout);
146 while ( (count = read(fd_in, buf, sizeof(buf))) > 0 )
147 write(fd_out, buf, count);
155 /*****************************************************************************/
158 str_convert(str, err)
169 * Grab the next integer from **str and return its value or err if *str
170 * isn't an integer. *str is modified after each digit is read.
174 if ( ! isdigit(**str) )
177 for ( i = 0; isdigit(**str); *str += 1 )
178 i = 10 * i + **str - '0';
182 } /* End of str_convert */
184 /*****************************************************************************/
187 error(kind, mesg, a1, a2, a3)
197 * Print an error message and quit if kind is FATAL.
201 if ( mesg != NULL && *mesg != '\0' ) {
202 fprintf(stderr, "%s: ", prog_name);
203 fprintf(stderr, mesg, a1, a2, a3);
205 fprintf(stderr, " (line %ld)", lineno);
207 fprintf(stderr, " (near byte %ld)", position);
211 if ( kind == FATAL && ignore == OFF ) {
212 if ( temp_file != NULL )
219 /*****************************************************************************/
229 * Signal handler for translators.
233 if ( temp_file != NULL )
238 } /* End of interrupt */
240 /*****************************************************************************/