|
|
1.1 root 1: /*
2: *
3: * General purpose routines.
4: *
5: */
6:
7: #include <stdio.h>
8: #include <ctype.h>
9: #include <fcntl.h>
10:
11: #include "gen.h"
12: #include "ext.h"
13: #include "path.h"
14:
15: int nolist = 0; /* number of specified ranges */
16: int olist[50]; /* processing range pairs */
17:
18: /*****************************************************************************/
19:
20: out_list(str)
21:
22: char *str;
23:
24: {
25:
26: int start, stop;
27:
28: /*
29: *
30: * Grab page ranges from str, save them in olist[], and update the nolist
31: * count. Range syntax matches nroff/troff syntax.
32: *
33: */
34:
35: while ( *str && nolist < sizeof(olist) - 2 ) {
36: start = stop = str_convert(&str, 0);
37:
38: if ( *str == '-' && *str++ )
39: stop = str_convert(&str, 9999);
40:
41: if ( start > stop )
42: error(FATAL, "illegal range %d-%d", start, stop);
43:
44: olist[nolist++] = start;
45: olist[nolist++] = stop;
46:
47: if ( *str != '\0' ) str++;
48: } /* End while */
49:
50: olist[nolist] = 0;
51:
52: } /* End of out_list */
53:
54: /*****************************************************************************/
55:
56: in_olist(num)
57:
58: int num;
59:
60: {
61:
62: int i;
63:
64: /*
65: *
66: * Return ON if num is in the current page range list. Print everything if
67: * there's no list.
68: *
69: */
70: if ( nolist == 0 )
71: return(ON);
72:
73: for ( i = 0; i < nolist; i += 2 )
74: if ( num >= olist[i] && num <= olist[i+1] )
75: return(ON);
76:
77: return(OFF);
78:
79: } /* End of in_olist */
80:
81: /*****************************************************************************/
82:
83: setencoding(name)
84:
85: char *name;
86:
87: {
88:
89: char path[150];
90:
91: /*
92: *
93: * Include the font encoding file selected by name. It's a full pathname if
94: * it begins with /, otherwise append suffix ".enc" and look for the file in
95: * ENCODINGDIR. Missing files are silently ignored.
96: *
97: */
98:
99: if ( name == NULL )
100: name = "Default";
101:
102: if ( *name == '/' )
103: strcpy(path, name);
104: else sprintf(path, "%s/%s.enc", ENCODINGDIR, name);
105:
106: if ( cat(path) == TRUE )
107: writing = strncmp(name, "UTF", 3) == 0;
108:
109: } /* End of setencoding */
110:
111: /*****************************************************************************/
112:
113: cat(file)
114:
115: char *file;
116:
117: {
118:
119: int fd_in;
120: int fd_out;
121: char buf[512];
122: int count;
123:
124: /*
125: *
126: * Copy *file to stdout. Return FALSE is there was a problem.
127: *
128: */
129:
130: fflush(stdout);
131:
132: if ( (fd_in = open(file, O_RDONLY)) == -1 )
133: return(FALSE);
134:
135: fd_out = fileno(stdout);
136: while ( (count = read(fd_in, buf, sizeof(buf))) > 0 )
137: write(fd_out, buf, count);
138:
139: close(fd_in);
140:
141: return(TRUE);
142:
143: } /* End of cat */
144:
145: /*****************************************************************************/
146:
147: str_convert(str, err)
148:
149: char **str;
150: int err;
151:
152: {
153:
154: int i;
155:
156: /*
157: *
158: * Grab the next integer from **str and return its value or err if *str
159: * isn't an integer. *str is modified after each digit is read.
160: *
161: */
162:
163: if ( ! isdigit(**str) )
164: return(err);
165:
166: for ( i = 0; isdigit(**str); *str += 1 )
167: i = 10 * i + **str - '0';
168:
169: return(i);
170:
171: } /* End of str_convert */
172:
173: /*****************************************************************************/
174:
175: error(kind, mesg, a1, a2, a3)
176:
177: int kind;
178: char *mesg;
179: unsigned a1, a2, a3;
180:
181: {
182:
183: /*
184: *
185: * Print an error message and quit if kind is FATAL.
186: *
187: */
188:
189: if ( mesg != NULL && *mesg != '\0' ) {
190: fprintf(stderr, "%s: ", prog_name);
191: fprintf(stderr, mesg, a1, a2, a3);
192: if ( lineno > 0 )
193: fprintf(stderr, " (line %d)", lineno);
194: if ( position > 0 )
195: fprintf(stderr, " (near byte %d)", position);
196: putc('\n', stderr);
197: } /* End if */
198:
199: if ( kind == FATAL && ignore == OFF ) {
200: if ( temp_file != NULL )
201: unlink(temp_file);
202: exit(x_stat | 01);
203: } /* End if */
204:
205: } /* End of error */
206:
207: /*****************************************************************************/
208:
209: void interrupt(sig)
210:
211: int sig;
212:
213: {
214:
215: /*
216: *
217: * Signal handler for translators.
218: *
219: */
220:
221: if ( temp_file != NULL )
222: unlink(temp_file);
223:
224: exit(1);
225:
226: } /* End of interrupt */
227:
228: /*****************************************************************************/
229:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.