2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: custom.c /main/3 1995/11/08 09:29:32 rswiston $ */
25 Copyright (c) 1988, 1989 Hewlett-Packard Co.
28 /* Custom.c contains standard PARSER functions, customized for the HP
29 HelpTag formatting system. */
37 /* Standard startup code doesn't have room to load inherited environments
38 in some cases. Since they're not used, don't bother. (Using Microsoft
40 void _setenvp(M_NOPAR);
44 /* Write input file and line number for an error message */
45 void m_dumpline(file, line)
53 sprintf(buffer, "%d", line);
56 { /* no entity file */
58 { /* use main input, instead. Only if set though. */
59 mbyte = MakeMByteString(inputname);
62 m_free(mbyte, "multi-byte string");
66 { /* yes, entity file */
67 mbyte = MakeMByteString(file);
70 m_free(mbyte, "multi-byte string");
74 /* Write error message prefix */
75 void m_eprefix(M_NOPAR)
77 m_errline("\n*****\n");
78 m_dumpline(m_thisfile(), m_thisline());
82 /* Process error message text */
90 if (m_errfile) putc(*p, m_errfile);
98 /* Write error message suffix */
99 void m_esuffix(M_NOPAR)
103 if (++m_errcnt == m_errlim)
105 m_error("Too many errors, processing stopped");
116 if (m_outfile != stdout)
119 { /* sph: is this really necessary? */
120 fseek(m_outfile, 0L, SEEK_END);
123 if (prebye == postpreamble)
124 m_error("No text in document");
130 if (status == 77) /* tell helptag to re-run for forward xrefs */
144 exit(1); /* tell helptag to quit */
146 exit(2); /* tell helptag to continue to next phases */
152 /* Get-char procedure */
159 char mbyte[32]; /* make this bigger than any possible multi-byte char */
161 static M_WCHAR wcr = 0, wsb, wsp, wtb;
164 /* Unix/Dos compatibility: 0D0A handling */
167 mbtowc(&wcr, "\r", 1);
168 mbtowc(&wsb, "\032", 1);
171 mbtowc(&wsp, &space, 1);
174 mbtowc(&wtb, &tab, 1);
179 if ((c = getc((FILE *) m_ptr)) == EOF) return(EOF);
184 if (mblen(mbyte,length) != -1) break; /* hurray! */
185 if (length == MB_CUR_MAX)
186 { /* reached max without a hit */
187 m_error("An invalid multi-byte character was found in the input");
192 if ((c = getc((FILE *) m_ptr)) == EOF)
194 m_error("End-of-file found in within a multi-byte character");
198 mbtowc(&wc,mbyte,length);
200 while ((wc == wcr) || (wc == wsb));
202 /* Change tabs to spaces */
203 if (wc == wtb) return((int) wsp);
207 /* Open SYSTEM entity procedure */
208 void *m_openent(entcontent)
216 mb_entcontent = MakeMByteString(entcontent);
217 if (!*mb_entcontent) return NULL; /* null file name, don't open a directory */
219 open = fopen(mb_entcontent, "r");
222 m_free(mb_entcontent, "multi-byte string");
223 return((void *) open);
226 for (searchp = path ; searchp ; searchp = searchp->next)
229 m_malloc(strlen(searchp->directory) +
230 strlen(mb_entcontent) + 1,
232 strcpy(filename, searchp->directory);
233 strcat(filename, mb_entcontent);
234 open = fopen(filename, "r");
235 m_free(filename, "filename");
238 m_free(mb_entcontent, "multi-byte string");
239 return((void *) open);
243 m_free(mb_entcontent, "multi-byte string");
247 /* Open input file */
248 void *m_openfirst(M_NOPAR)
257 m_malloc(strlen(m_argv[1]) + strlen(".htg") + 1, "input file name");
258 strcpy(input, m_argv[1]);
259 strcat(input, ".htg");
260 m_openchk(&first, input, "r");
261 if (filelist) puts(input);
262 /* keep name for global use */
263 length = strlen(input);
264 inputname = (M_WCHAR *) m_malloc(length + 1, "saved input file name");
265 mbstowcs(inputname, input, length + 1);
266 m_free(input, "input file name");
270 if (filelist) puts(m_argv[1]);
271 m_openchk(&first, m_argv[1], "r");
272 length = strlen(m_argv[1]);
273 inputname = (M_WCHAR *) m_malloc(length + 1, "saved input file name");
274 mbstowcs(inputname, m_argv[1], length + 1);
277 /* Set E option (to suppress error message on duplicate entity
278 declarations) if file begins with "<!--Index" */
283 return((void *) first);
286 /* Set program options */
289 /* F option used for FILELIST (checking done in basename, which is
290 called before this function is called) */
292 m_optstring(m_argv[2]);
293 if (strchr(m_argv[2], 'o')) tracetostd = TRUE;
294 if (strchr(m_argv[2], 'O')) tracetostd = TRUE;
295 /* Option "p" tells the search path to look at paths one level
296 higher when relative pathes are specified.
298 The following two lines of code should be here, but they are moved
299 to global START-CODE of tex.if. For some reason, global START-CODE
300 is executed before this procedure is called (parser.c), but we need
301 to have the order reversed. Moving this procedure to a spot earlier
302 is risky, since we don't know full reasons of why things are in a
303 particular order. This way, we minimize the damage:
305 if (strchr(m_argv[2], 'p')) parentsrch = TRUE;
306 if (strchr(m_argv[2], 'P')) parentsrch = TRUE;
311 /* Process signon message text, stripping out MARKUP version number, so
312 only one version number will appear */
319 if (q = strstr(p, VERSION)) {
321 q = strstr(pCopy, VERSION);
330 /* All entity declarations have been processed. Can now check if .TEX
331 file uptodate and open appropriate output file */
337 unsigned char wheredef;
350 { /* list files that make up document */
351 while (name = m_cyclent(init, &type, &content, &wheredef))
355 if (type == M_SYSTEM)
356 qfile = searchforfile(content);
359 mbyte = MakeMByteString(qfile);
361 m_free(qfile, "figure filename");
362 m_free(mbyte, "multi-byte string");
364 else if (type == M_SYSTEM)
365 m_err2("Can't find file %s (declared in entity %s)", content, name);
367 if (idxpath) puts(idxpath);
372 /* Write debugging trace information */
376 if (tracetostd) fputs(p, stdout);
377 else fputs(p, m_outfile);
386 mb_p = MakeMByteString(p);
388 m_free(mb_p,"multi-byte string");