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 libraries 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 10:07:46 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 if (prebye == postpreamble)
120 m_error("No text in document");
126 if (status == 77) /* tell helptag to re-run for forward xrefs */
140 exit(1); /* tell helptag to quit */
142 exit(2); /* tell helptag to continue to next phases */
148 /* Get-char procedure */
155 char mbyte[32]; /* make this bigger than any possible multi-byte char */
157 static M_WCHAR wcr = 0, wsb, wsp, wtb;
160 /* Unix/Dos compatibility: 0D0A handling */
163 mbtowc(&wcr, "\r", 1);
164 mbtowc(&wsb, "\032", 1);
167 mbtowc(&wsp, &space, 1);
170 mbtowc(&wtb, &tab, 1);
175 if ((c = getc((FILE *) m_ptr)) == EOF) return(EOF);
180 if (mblen(mbyte,length) != -1) break; /* hurray! */
181 if (length == MB_CUR_MAX)
182 { /* reached max without a hit */
183 m_error("An invalid multi-byte character was found in the input");
188 if ((c = getc((FILE *) m_ptr)) == EOF)
190 m_error("End-of-file found in within a multi-byte character");
194 mbtowc(&wc,mbyte,length);
196 while ((wc == wcr) || (wc == wsb));
198 /* Change tabs to spaces */
199 if (wc == wtb) return((int) wsp);
203 /* Open SYSTEM entity procedure */
204 void *m_openent(entcontent)
212 mb_entcontent = MakeMByteString(entcontent);
213 if (!*mb_entcontent) /* null file name, don't open a directory */
215 m_free(mb_entcontent, "multi-byte string");
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);
281 return((void *) first);
284 /* Set program options */
287 /* F option used for FILELIST (checking done in basename, which is
288 called before this function is called) */
291 m_optstring(m_argv[2]);
292 if (strchr(m_argv[2], 'o')) tracetostd = TRUE;
293 if (strchr(m_argv[2], 'O')) tracetostd = TRUE;
297 /* Process signon message text, stripping out MARKUP version number, so
298 only one version number will appear */
305 if (q = strstr(p, VERSION)) {
307 q = strstr(pCopy, VERSION);
318 /* All entity declarations have been processed. Can now check if .TEX
319 file uptodate and open appropriate output file */
325 unsigned char wheredef;
338 { /* list files that make up document */
339 while (name = m_cyclent(init, &type, &content, &wheredef))
343 if (type == M_SYSTEM)
344 qfile = searchforfile(content);
347 mbyte = MakeMByteString(qfile);
349 m_free(qfile, "figure filename");
350 m_free(mbyte, "multi-byte string");
352 else if (type == M_SYSTEM)
353 m_err2("Can't find file %s (declared in entity %s)", content, name);
359 /* Write debugging trace information */
363 if (tracetostd) fputs(p, stdout);
364 else fputs(p, m_outfile);
373 mb_p = MakeMByteString(p);
375 m_free(mb_p,"multi-byte string");