dpost.ps: increase linewidth to match groff
[troff.git] / tr2ps / misc.c
blob5bae7e205d8781860ca2fb3c6d246f523c77d5fc
1 /*
3 * General purpose routines.
5 */
6 #include <ctype.h>
7 #include <fcntl.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <sys/types.h>
13 #include "gen.h"
14 #include "ext.h"
15 #include "path.h"
17 int nolist = 0; /* number of specified ranges */
18 int olist[50]; /* processing range pairs */
21 * Grab page ranges from str, save them in olist[], and update the
22 * nolist count. Range syntax matches nroff/troff syntax.
24 void out_list(char *str)
26 int start, stop;
28 while (*str && nolist < sizeof(olist) - 2) {
29 start = stop = str_convert(&str, 0);
31 if (*str == '-' && *str++)
32 stop = str_convert(&str, 9999);
33 if (start > stop)
34 error(FATAL, "illegal range %d-%d", start, stop);
35 olist[nolist++] = start;
36 olist[nolist++] = stop;
38 if (*str != '\0')
39 str++;
41 olist[nolist] = 0;
45 * Return ON if num is in the current page range list. Print everything
46 * if there's no list.
48 int in_olist(int num)
50 int i;
51 if (nolist == 0)
52 return ON;
54 for (i = 0; i < nolist; i += 2)
55 if (num >= olist[i] && num <= olist[i+1])
56 return ON;
57 return OFF;
61 * Include the font encoding file selected by name. It's a full
62 * pathname if it begins with /, otherwise append suffix ".enc" and
63 * look for the file in ENCODINGDIR. Missing files are silently
64 * ignored.
66 void setencoding(char *name)
69 char path[150];
71 if (name == NULL)
72 name = "Default";
73 if (*name == '/')
74 strcpy(path, name);
75 else
76 sprintf(path, "%s/%s.enc", ENCODINGDIR, name);
78 if (cat(path) == TRUE)
79 writing = strncmp(name, "UTF", 3) == 0;
84 * Grab the next integer from **str and return its value or err if *str
85 * isn't an integer. *str is modified after each digit is read.
87 int str_convert(char **str, int err)
90 int i;
91 if (!isdigit(**str))
92 return err;
93 for (i = 0; isdigit(**str); *str += 1)
94 i = 10 * i + **str - '0';
95 return i;
98 /* Signal handler for translators. */
99 void interrupt(int sig)
101 if (temp_file != NULL)
102 unlink(temp_file);
103 exit(1);