1: /******************************************************************************
2: *
3: * main -- main routine for dipress
4: * (ditroff to interpress conversion)
5: *
6: * John Mellor-Crummey (Xerox Corp)
7: *
8: * Copyright 1985 Xerox Corporation
9: *
10: *****************************************************************************/
11:
12: #include <stdio.h>
13: #include <ctype.h>
14: #include <sys/types.h>
15: #include <sys/file.h>
16: #include <sys/stat.h>
17: #include <strings.h>
18:
19: #include "defs.h" /* constant and macro definitions */
20: #include "externs.h" /* declarations for global variables */
21:
22:
23: /*-----------------------------------------------------------------------------
24: *
25: * main processes the list of command line options and opens the
26: * necessary temporary files
27: *
28: *---------------------------------------------------------------------------*/
29: main(argc, argv)
30: int argc;
31: char **argv;
32: {
33: FILE *inputfile;
34:
35: /* set up signal handlers to insure clean termination */
36: signalHandler();
37:
38: /* process command line options */
39:
40: while ((--argc > 0) && (**++argv == '-'))
41: {
42: switch (*++*argv)
43: {
44: case 'd':
45: /* produce debugging info */
46: dbg = atoi(++*argv);
47: if (dbg == 0) dbg = 1;
48: setbuf(stdout, (char *)NULL);
49: printf("debugging level %d\n", dbg);
50: break;
51: case 'f':
52: case 'F':
53: /* reset default font directory
54: * accept either form '-f <dir>' or '-f<dir>'
55: */
56: if (*(*argv+1) == '\0')
57: {
58: fontdirectory = *++argv;
59: --argc;
60: }
61: else
62: fontdirectory = ++*argv;
63: break;
64: case 'o':
65: /* read the following list of page numbers */
66: readPageList(++*argv);
67: break;
68: case 't':
69: /* dump the interpress to the standard output */
70: outputfile = fileno(stdout);
71: break;
72: default:
73: reportError(CONTINUE,"option -%c not recognized\n", (char *) **argv);
74: break;
75: }
76: }
77:
78: /* construct name for temporary files */
79: (void) sprintf(tempfilename, "/tmp/dip%d", getpid());
80:
81: if (outputfile != fileno(stdout))
82: {
83: /* open file to hold master */
84: if ((outputfile=open(tempfilename, O_WRONLY | O_TRUNC | O_CREAT, 0666)) == -1)
85: reportError(QUIT, "temporary file %s: %s",
86: tempfilename, sys_errlist[errno]);
87: ip_select(outputfile);
88: }
89:
90: /* open file to hold body */
91: (void) strcat(tempfilename, "b");
92:
93: if ((pagebodyfile = open(tempfilename, O_WRONLY | O_TRUNC | O_CREAT, 0666)) == -1)
94: reportError(QUIT, "temporary file %s: %s",
95: tempfilename, sys_errlist[errno]);
96:
97: ip_raw_select(pagebodyfile);
98:
99:
100:
101: if (argc <= 0) /* if no file specified, default to stdin */
102: ditroffToIpress(stdin);
103: else
104: /* process files explicitly specified */
105: while (argc-- > 0)
106: {
107: if ((inputfile = fopen(*argv++, "r")) == NULL)
108: reportError(QUIT, "can't open %s: %s",
109: *argv, sys_errlist[errno]);
110: ditroffToIpress(inputfile);
111: (void) fclose(inputfile);
112: }
113: goodbye();
114: }
115:
116:
117: /*-----------------------------------------------------------------------------
118: * readPageList -- read a list of page specifications of the form
119: * p1 or p1-p2 separated by commas. if in the dash form
120: * either p1 or p2 is omitted, it will appropriately
121: * default to the first of last page of the document
122: *---------------------------------------------------------------------------*/
123: readPageList(ptr)
124: char *ptr;
125: {
126: while(*ptr != '\0')
127: {
128: pagerange[nPageRanges][0] =
129: ((isdigit(*ptr)) ? readPageNumber(&ptr): DEFAULTRANGEBOT);
130: pagerange[nPageRanges][1] =
131: ((*ptr != '-') ? pagerange[nPageRanges][0] :
132: ((isdigit(*++ptr)) ? readPageNumber(&ptr) :
133: DEFAULTRANGETOP));
134: nPageRanges++;
135: if (*ptr != '\0') ptr++;
136: }
137: }
138:
139:
140: /*-----------------------------------------------------------------------------
141: * readPageNumber -- read a page number from a string and update the
142: * pointer to the next non-digit
143: *---------------------------------------------------------------------------*/
144: readPageNumber(ptr)
145: char **ptr;
146: {
147: int pagenumber = 0;
148:
149: while(isdigit(**ptr))
150: {
151: pagenumber = pagenumber * 10 + **ptr - '0';
152: ++*ptr;
153: }
154: return(pagenumber);
155: }
Defined functions
main
defined in line
29;
never used