updated to get closer to building using cygwin, which is difficult because
[feisty_meow.git] / nucleus / tools / dependency_tool / makedep.cpp
1 /* $XConsortium: main.c,v 1.84 94/11/30 16:10:44 kaleb Exp $ */
2 /* $XFree86: xc/config/makedepend/main.c,v 3.3 1995/01/28 15:41:03 dawes Exp $ */
3 /*
4
5 Copyright (c) 1993, 1994  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
27
28 */
29
30 #ifdef __WIN32__
31   #pragma warning(disable : 4996)
32 #endif
33
34 #include "def.h"
35
36 #ifdef _MSC_VER
37 #include <io.h>
38 #else
39 #include <unistd.h>
40 #endif
41 #include <stdio.h>
42 #include <string.h>
43
44 #ifdef hpux
45 #define sigvec sigvector
46 #endif /* hpux */
47
48 #ifdef X_POSIX_C_SOURCE
49 #define _POSIX_C_SOURCE X_POSIX_C_SOURCE
50 #include <signal.h>
51 #undef _POSIX_C_SOURCE
52 #else
53 #if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
54 #include <signal.h>
55 #else
56 #define _POSIX_SOURCE
57 #include <signal.h>
58 #undef _POSIX_SOURCE
59 #endif
60 #endif
61
62 #if NeedVarargsPrototypes
63 #include <stdarg.h>
64 #endif
65
66 #ifdef MINIX
67 #define USE_CHMOD  1
68 #endif
69
70 #ifdef DEBUG
71 int  _debugmask;
72 #endif
73
74 char *ProgramName;
75
76 const char  *directives[] = {
77   "if",
78   "ifdef",
79   "ifndef",
80   "else",
81   "endif",
82   "define",
83   "undef",
84   "include",
85   "line",
86   "pragma",
87   "error",
88   "ident",
89   "sccs",
90   "elif",
91   "eject",
92   "import",
93   NULL
94 };
95
96 #define MAKEDEPEND
97 #include "imakemdep.h"  /* from config sources */
98 #undef MAKEDEPEND
99
100 struct  inclist inc_list[ MAXFILES ], *inclistp = inc_list, maininclist;
101
102 char  *filelist[ MAXFILES ];
103 char  *includedirs[ MAXDIRS + 1 ];
104 char  *excludedirs[ MAXDIRS + 1 ];
105 char  *notdotdot[ MAXDIRS ];
106 char  *objprefix = (char *)"";
107 char  *objsuffix = (char *)".obj"; /* OBJSUFFIX;  */
108 char  *startat = (char *)"# DO NOT DELETE";
109 int  width = 78;
110 bool  append = false;
111 bool  printed = false;
112 bool  verbose = false;
113 bool  show_where_not = false;
114 bool warn_multiple = false;  /* Warn on multiple includes of same file */
115
116 static
117 #ifdef SIGNALRETURNSINT
118 int
119 #else
120 void
121 #endif
122 c_catch(int sig)
123 {
124   fflush (stdout);
125   fatalerr ((char *)"got signal %d\n", sig);
126 }
127
128 #if defined(USG) || (defined(i386) && defined(SYSV)) || defined(WIN32) || defined(__EMX__) || defined(__OS2__)
129 #define USGISH
130 #endif
131
132 #ifndef USGISH
133 #ifndef _POSIX_SOURCE
134 #define sigaction sigvec
135 #define sa_handler sv_handler
136 #define sa_mask sv_mask
137 #define sa_flags sv_flags
138 #endif
139 struct sigaction sig_act;
140 #endif /* USGISH */
141
142 // turns the cygwin name format into a usable windos filename.
143 char *translate_cygwin(char *fname)
144 {
145   if (!strncmp(fname, "/cygdrive/", 10)) {
146     int oldlen = strlen(fname);
147     char *newprefix = (char *)malloc(oldlen); // at least long enough.
148     newprefix[0] = fname[10];
149     newprefix[1] = ':';
150     newprefix[2] = '\0';
151     strncat(newprefix, fname + 11, oldlen - 11 + 1);  // one extra for null char.
152 printf("translate cygwin: new filename is %s\n", newprefix);
153     return newprefix;  // ignoring mem leak here.  cannot be helped for quicky fix.
154   } else return fname;
155 }
156
157 /* fatty boombalatty, and wrong idea here.
158
159 // adds any subdirectories under dirname into the list of
160 // include directories, so we can get a whole hierarchies set of
161 // include files.
162 void add_subdirs(char *dirname, char ** &incp)
163 {
164   directory dir(dirname);
165   string_array subdirs = dir.directories();
166   for (int i = 0; i < subdirs.length(); i++) {
167     istring curr = istring(dirname) + "/" + subdirs[i];
168     // add the current subdirectory.
169     if (incp >= includedirs + MAXDIRS)
170       fatalerr("Too many -I flags.\n");
171     *incp++ = strdup(curr.s());
172 printf((istring("added ") + curr + "\n").s());
173     add_subdirs(curr.s(), incp);
174   }
175 }
176 */
177
178 int main(int argc, char  **argv)
179 {
180   register char  **fp = filelist;
181   register char  **incp = includedirs;
182   register char  **excp = excludedirs;
183   register char  *p;
184   register struct inclist  *ip;
185   char  *makefile = NULL;
186   struct filepointer  *filecontent;
187   struct symtab *psymp = predefs;
188   char *endmarker = NULL;
189   char *defincdir = NULL;
190
191   ProgramName = argv[0];
192
193   while (psymp->s_name)
194   {
195       define2(psymp->s_name, psymp->s_value, &maininclist);
196       psymp++;
197   }
198   if (argc == 2 && argv[1][0] == '@') {
199       struct stat ast;
200       int afd;
201       char *args;
202       char **nargv;
203       int nargc;
204       char quotechar = '\0';
205
206       nargc = 1;
207       if ((afd = open(translate_cygwin(argv[1]+1), O_RDONLY)) < 0)
208     fatalerr("cannot open \"%s\"\n", translate_cygwin(argv[1]+1));
209       fstat(afd, &ast);
210       args = (char *)malloc(ast.st_size + 2);
211       if ((ast.st_size = read(afd, args, ast.st_size)) < 0)
212     fatalerr("failed to read %s\n", argv[1]+1);
213       args[ast.st_size] = '\n';
214       args[ast.st_size + 1] = '\0';
215       close(afd);
216       for (p = args; *p; p++) {
217     if (quotechar) {
218         if (quotechar == '\\' ||
219       (*p == quotechar && p[-1] != '\\'))
220       quotechar = '\0';
221         continue;
222     }
223     switch (*p) {
224     case '\\':
225     case '"':
226     case '\'':
227         quotechar = *p;
228         break;
229     case ' ':
230     case '\n':
231         *p = '\0';
232         if (p > args && p[-1])
233       nargc++;
234         break;
235     }
236       }
237       if (p[-1])
238     nargc++;
239       nargv = (char **)malloc(nargc * sizeof(char *));
240       nargv[0] = argv[0];
241       argc = 1;
242       for (p = args; argc < nargc; p += strlen(p) + 1)
243     if (*p) nargv[argc++] = p;
244       argv = nargv;
245   }
246   for(argc--, argv++; argc; argc--, argv++) {
247         /* if looking for endmarker then check before parsing */
248     if (endmarker && strcmp (endmarker, *argv) == 0) {
249         endmarker = NULL;
250         continue;
251     }
252     if (**argv != '-') {
253       /* treat +thing as an option for C++ */
254       if (endmarker && **argv == '+')
255         continue;
256       *fp++ = argv[0];
257       continue;
258     }
259     switch(argv[0][1]) {
260     case '-':
261       endmarker = &argv[0][2];
262       if (endmarker[0] == '\0') endmarker = (char *)"--";
263       break;
264     case 'D':
265       if (argv[0][2] == '\0') {
266         argv++;
267         argc--;
268       }
269       for (p=argv[0] + 2; *p ; p++)
270         if (*p == '=') {
271           *p = ' ';
272           break;
273         }
274       define(argv[0] + 2, &maininclist);
275       break;
276     case 'i':
277       {
278         char* delim;
279         char* envinclude;
280         char* prevdir;
281         if (endmarker) break;
282         if (argv[0][2] == '\0') {
283           argv++;
284           argc--;
285           envinclude = getenv(argv[0]);
286         } else  envinclude = getenv(argv[0]+2);
287         if (!envinclude)  break;
288         prevdir = envinclude;
289         delim = (char*)strchr(envinclude, ';');
290         while(delim)
291         {
292           if (incp >= includedirs + MAXDIRS)  fatalerr("Too many Include directories.\n");
293           *delim = '\0';
294           delim++;
295           *incp++ = prevdir;
296           prevdir = delim;
297           delim = (char*)strchr(delim, ';');
298         }
299       }
300       break;
301     case 'X':
302 //fprintf(stderr, "adding Xclude %s\n", argv[0]+2);
303       // add a directory to the exclusions list.
304       if (excp >= excludedirs + MAXDIRS)
305           fatalerr("Too many -X flags.\n");
306       *excp++ = argv[0]+2;
307       if (**(excp-1) == '\0') {
308         // fix the prior entry, but don't incremement yet; we'll do that
309         // on the include list instead.
310         *(excp-1) = *(argv + 1);
311       }
312       if (incp >= includedirs + MAXDIRS)
313           fatalerr("Too many -I flags via -X.\n");
314       *incp++ = argv[0]+2;
315       if (**(incp-1) == '\0') {
316         *(incp-1) = *(++argv);
317         argc--;
318       }
319       break;
320     case 'I':
321       if (incp >= includedirs + MAXDIRS)
322           fatalerr("Too many -I flags.\n");
323       *incp++ = argv[0]+2;
324       if (**(incp-1) == '\0') {
325         *(incp-1) = *(++argv);
326         argc--;
327       }
328 ///      add_subdirs(*(incp-1), incp);
329       break;
330     case 'Y':
331       defincdir = argv[0]+2;
332       break;
333     /* do not use if endmarker processing */
334     case 'a':
335       if (endmarker) break;
336       append = true;
337       break;
338     case 'w':
339       if (endmarker) break;
340       if (argv[0][2] == '\0') {
341         argv++;
342         argc--;
343         width = atoi(argv[0]);
344       } else
345         width = atoi(argv[0]+2);
346       break;
347     case 'o':
348       if (endmarker) break;
349       if (argv[0][2] == '\0') {
350         argv++;
351         argc--;
352         objsuffix = argv[0];
353       } else
354         objsuffix = argv[0]+2;
355       break;
356     case 'p':
357       if (endmarker) break;
358       if (argv[0][2] == '\0') {
359         argv++;
360         argc--;
361         objprefix = argv[0];
362       } else
363         objprefix = argv[0]+2;
364         objprefix = translate_cygwin(objprefix);
365       break;
366     case 'v':
367       if (endmarker) break;
368       verbose = true;
369 #ifdef DEBUG
370       if (argv[0][2])
371         _debugmask = atoi(argv[0]+2);
372 #endif
373       break;
374     case 's':
375       if (endmarker) break;
376       startat = argv[0]+2;
377       if (*startat == '\0') {
378         startat = *(++argv);
379         argc--;
380       }
381       if (*startat != '#')
382         fatalerr("-s flag's value should start %s\n",
383           "with '#'.");
384       break;
385     case 'f':
386       if (endmarker) break;
387       makefile = argv[0]+2;
388       if (*makefile == '\0') {
389         makefile = *(++argv);
390         argc--;
391       }
392       break;
393     case 'm':
394       warn_multiple = true;
395       break;
396       
397     /* Ignore -O, -g so we can just pass ${CFLAGS} to
398        makedepend
399      */
400     case 'O':
401     case 'g':
402       break;
403     default:
404       if (endmarker) break;
405   /*    fatalerr("unknown opt = %s\n", argv[0]); */
406       warning("ignoring option %s\n", argv[0]);
407     }
408   }
409
410   if (!defincdir) {
411 #ifdef PREINCDIR
412       if (incp >= includedirs + MAXDIRS)
413     fatalerr("Too many -I flags.\n");
414       *incp++ = PREINCDIR;
415 #endif
416 #ifdef INCLUDEDIR
417       if (incp >= includedirs + MAXDIRS)
418     fatalerr("Too many -I flags.\n");
419       *incp++ = INCLUDEDIR;
420 #endif
421 #ifdef POSTINCDIR
422       if (incp >= includedirs + MAXDIRS)
423     fatalerr("Too many -I flags.\n");
424       *incp++ = POSTINCDIR;
425 #endif
426   } else if (*defincdir) {
427       if (incp >= includedirs + MAXDIRS)
428     fatalerr("Too many -I flags.\n");
429       *incp++ = defincdir;
430   }
431
432   redirect(startat, makefile);
433
434   /*
435    * c_catch signals.
436    */
437 #ifdef USGISH
438 /*  should really reset SIGINT to SIG_IGN if it was.  */
439 #ifdef SIGHUP
440   signal (SIGHUP, c_catch);
441 #endif
442   signal (SIGINT, c_catch);
443 #ifdef SIGQUIT
444   signal (SIGQUIT, c_catch);
445 #endif
446   signal (SIGILL, c_catch);
447 #ifdef SIGBUS
448   signal (SIGBUS, c_catch);
449 #endif
450   signal (SIGSEGV, c_catch);
451 #ifdef SIGSYS
452   signal (SIGSYS, c_catch);
453 #endif
454 #else
455   sig_act.sa_handler = c_catch;
456 #ifdef _POSIX_SOURCE
457   sigemptyset(&sig_act.sa_mask);
458   sigaddset(&sig_act.sa_mask, SIGINT);
459   sigaddset(&sig_act.sa_mask, SIGQUIT);
460 #ifdef SIGBUS
461   sigaddset(&sig_act.sa_mask, SIGBUS);
462 #endif
463   sigaddset(&sig_act.sa_mask, SIGILL);
464   sigaddset(&sig_act.sa_mask, SIGSEGV);
465   sigaddset(&sig_act.sa_mask, SIGHUP);
466   sigaddset(&sig_act.sa_mask, SIGPIPE);
467 #ifdef SIGSYS
468   sigaddset(&sig_act.sa_mask, SIGSYS);
469 #endif
470 #else
471   sig_act.sa_mask = ((1<<(SIGINT -1))
472          |(1<<(SIGQUIT-1))
473 #ifdef SIGBUS
474          |(1<<(SIGBUS-1))
475 #endif
476          |(1<<(SIGILL-1))
477          |(1<<(SIGSEGV-1))
478          |(1<<(SIGHUP-1))
479          |(1<<(SIGPIPE-1))
480 #ifdef SIGSYS
481          |(1<<(SIGSYS-1))
482 #endif
483          );
484 #endif /* _POSIX_SOURCE */
485   sig_act.sa_flags = 0;
486   sigaction(SIGHUP, &sig_act, (struct sigaction *)0);
487   sigaction(SIGINT, &sig_act, (struct sigaction *)0);
488   sigaction(SIGQUIT, &sig_act, (struct sigaction *)0);
489   sigaction(SIGILL, &sig_act, (struct sigaction *)0);
490 #ifdef SIGBUS
491   sigaction(SIGBUS, &sig_act, (struct sigaction *)0);
492 #endif
493   sigaction(SIGSEGV, &sig_act, (struct sigaction *)0);
494 #ifdef SIGSYS
495   sigaction(SIGSYS, &sig_act, (struct sigaction *)0);
496 #endif
497 #endif /* USGISH */
498
499   /*
500    * now peruse through the list of files.
501    */
502   for(fp=filelist; *fp; fp++) {
503     filecontent = getfile(*fp);
504     ip = newinclude(*fp, (char *)NULL);
505
506     find_includes(filecontent, ip, ip, 0, false);
507     freefile(filecontent);
508     recursive_pr_include(ip, ip->i_file, base_name(*fp));
509     inc_clean();
510   }
511   if (printed)
512     printf("\n");
513
514   return 0;
515 }
516
517 struct filepointer *getfile(char  *file)
518 {
519   register int  fd;
520   struct filepointer  *content;
521   struct stat  st;
522
523   content = (struct filepointer *)malloc(sizeof(struct filepointer));
524   content->f_name = strdup(translate_cygwin(file));
525   if ((fd = open(file, O_RDONLY)) < 0) {
526     warning("cannot open \"%s\"\n", translate_cygwin(file));
527     content->f_p = content->f_base = content->f_end = (char *)malloc(1);
528     *content->f_p = '\0';
529     return(content);
530   }
531   fstat(fd, &st);
532   content->f_base = (char *)malloc(st.st_size+1);
533   if (content->f_base == NULL)
534     fatalerr("cannot allocate mem\n");
535   if ((st.st_size = read(fd, content->f_base, st.st_size)) < 0)
536     fatalerr("failed to read %s\n", translate_cygwin(file));
537   close(fd);
538   content->f_len = st.st_size+1;
539   content->f_p = content->f_base;
540   content->f_end = content->f_base + st.st_size;
541   *content->f_end = '\0';
542   content->f_line = 0;
543   return(content);
544 }
545
546 void freefile(struct filepointer  *fp)
547 {
548   free(fp->f_name);
549   free(fp->f_base);
550   free(fp);
551 }
552
553 char *copy(register char  *str)
554 {
555   register char  *p = (char *)malloc(strlen(str) + 1);
556
557   strcpy(p, str);
558   return(p);
559 }
560
561 int match(register const char *str, register const char **list)
562 {
563   register int  i;
564
565   for (i=0; *list; i++, list++)
566     if (strcmp(str, *list) == 0)
567       return i;
568   return -1;
569 }
570
571 /*
572  * Get the next line.  We only return lines beginning with '#' since that
573  * is all this program is ever interested in.
574  */
575 char *getline(register struct filepointer  *filep)
576 {
577   register char  *p,  /* walking pointer */
578       *eof,  /* end of file pointer */
579       *bol;  /* beginning of line pointer */
580   register  int lineno;  /* line number */
581
582   eof = filep->f_end;
583 ////  if (p >= eof) return NULL;
584   lineno = filep->f_line;
585   bol = filep->f_p;
586
587   // p is always pointing at the "beginning of a line" when we start this loop.
588   // this means that we must start considering the stuff on that line as
589   // being a useful thing to look at.
590   for (p = filep->f_p; p < eof; p++) {
591 if (bol > p) fatalerr("somehow bol got ahead of p.");
592     if (*p == '/' && *(p+1) == '*') {
593       /* consume C-style comments */
594       *p++ = ' '; *p++ = ' ';  // skip the two we've already seen.
595       while (p < eof) {
596         if (*p == '*' && *(p+1) == '/') {
597           *p++ = ' '; *p = ' ';
598             // skip one of these last two, let the loop skip the next.
599           break;
600         } else if (*p == '\n') lineno++;
601         p++;  // skip the current character.
602       }
603       continue;
604     } else if (*p == '/' && *(p+1) == '/') {
605       /* consume C++-style comments */
606       *p++ = ' '; *p++ = ' ';  // skip the comment characters.
607       while (p < eof && (*p != '\n') ) *p++ = ' ';
608         // we scan until we get to the end of line.
609 ///no count, since we'll see it again.      lineno++;
610       p--;  // skip back to just before \n.
611       continue;  // let the loop skip past the eol that we saw.
612     } else if (*p == '\\') {
613       // handle an escape character.
614       if (*(p+1) == '\n') {
615         // we modify the stream so we consider the line correctly.
616         *p = ' ';
617         *(p+1) = ' ';
618         lineno++;
619       }
620     } else if (*p == '\n') {
621       // we've finally reached the end of the line.
622       lineno++;
623       *p = '\0';  // set the end of line to be a end of string now.
624       if (bol < p) {
625         // it's not at the same position as the end of line, so it's worth
626         // considering.
627         while ( (bol < p) && ((*bol == ' ') || (*bol == '\t')) ) bol++;
628 ////fprintf(stderr, "%s: %s\n", filep->f_name, bol);
629 ////fflush(stderr);
630         if (*bol == '#') {
631           register char *cp;
632           /* punt lines with just # (yacc generated) */
633           for (cp = bol+1; *cp && (*cp == ' ' || *cp == '\t'); cp++) {}
634           if (*cp) { p++; goto done; }
635         }
636       }
637       // this is a failure now.  we reset the beginning of line.
638       bol = p+1;
639     }
640   }
641   if (*bol != '#') bol = NULL;
642 done:
643   filep->f_p = p;
644   filep->f_line = lineno;
645   return bol;
646 }
647
648 /*
649  * Strip the file name down to what we want to see in the Makefile.
650  * It will have objprefix and objsuffix around it.
651  */
652 char *base_name(register char  *file)
653 {
654   register char  *p;
655
656   file = copy(file);
657   for(p=file+strlen(file); p>file && *p != '.'; p--) ;
658
659   if (*p == '.')
660     *p = '\0';
661   return(file);
662 }
663
664 #if defined(USG) && !defined(CRAY) && !defined(SVR4) && !defined(__EMX__)
665 int rename(char *from, char *to)
666 {
667     (void) unlink (to);
668     if (link (from, to) == 0) {
669   unlink (from);
670   return 0;
671     } else {
672   return -1;
673     }
674 }
675 #endif /* USGISH */
676
677 void redirect(char  *line, char  *makefile)
678 {
679   struct stat  st;
680   FILE  *fdin, *fdout;
681   char  backup[ BUFSIZ ],
682     buf[ BUFSIZ ];
683   bool  found = false;
684   int  len;
685
686   /*
687    * if makefile is "-" then let it pour onto stdout.
688    */
689   if (makefile && *makefile == '-' && *(makefile+1) == '\0')
690     return;
691
692   /*
693    * use a default makefile is not specified.
694    */
695   if (!makefile) {
696     if (stat("Makefile", &st) == 0)
697       makefile = (char *)"Makefile";
698     else if (stat("makefile", &st) == 0)
699       makefile = (char *)"makefile";
700     else
701       fatalerr("[mM]akefile is not present\n");
702   }
703   else
704       stat(makefile, &st);
705   if ((fdin = fopen(translate_cygwin(makefile), "r")) == NULL)
706     fatalerr("cannot open \"%s\"\n", translate_cygwin(makefile));
707   sprintf(backup, "%s.bak", makefile);
708   unlink(backup);
709 #if defined(WIN32) || defined(__EMX__) || defined(__OS2__)
710   fclose(fdin);
711 #endif
712   if (rename(translate_cygwin(makefile), translate_cygwin(backup)) < 0)
713     fatalerr("cannot rename %s to %s\n", translate_cygwin(makefile), translate_cygwin(backup));
714 #if defined(WIN32) || defined(__EMX__) || defined(__OS2__)
715   if ((fdin = fopen(translate_cygwin(backup), "r")) == NULL)
716     fatalerr("cannot open \"%s\"\n", translate_cygwin(backup));
717 #endif
718   if ((fdout = freopen(translate_cygwin(makefile), "w", stdout)) == NULL)
719     fatalerr("cannot open \"%s\"\n", translate_cygwin(backup));
720   len = int(strlen(line));
721   while (!found && fgets(buf, BUFSIZ, fdin)) {
722     if (*buf == '#' && strncmp(line, buf, len) == 0)
723       found = true;
724     fputs(buf, fdout);
725   }
726   if (!found) {
727     if (verbose)
728     warning("Adding new delimiting line \"%s\" and dependencies...\n",
729       line);
730     puts(line); /* same as fputs(fdout); but with newline */
731   } else if (append) {
732       while (fgets(buf, BUFSIZ, fdin)) {
733     fputs(buf, fdout);
734       }
735   }
736   fflush(fdout);
737 #if defined(USGISH) || defined(_SEQUENT_) || defined(USE_CHMOD)
738   chmod(makefile, st.st_mode);
739 #else
740         fchmod(fileno(fdout), st.st_mode);
741 #endif /* USGISH */
742 }
743
744 #if NeedVarargsPrototypes
745 void fatalerr(const char *msg, ...)
746 #else
747 /*VARARGS*/
748 void fatalerr(char *msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
749 #endif
750 {
751 #if NeedVarargsPrototypes
752   va_list args;
753 #endif
754   fprintf(stderr, "%s: error:  ", ProgramName);
755 #if NeedVarargsPrototypes
756   va_start(args, msg);
757   vfprintf(stderr, msg, args);
758   va_end(args);
759 #else
760   fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
761 #endif
762   exit (1);
763 }
764
765 #if NeedVarargsPrototypes
766 void warning(const char *msg, ...)
767 #else
768 /*VARARGS0*/
769 void warning(const char *msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
770 #endif
771 {
772 #if NeedVarargsPrototypes
773   va_list args;
774 #endif
775   fprintf(stderr, "%s: warning:  ", ProgramName);
776 #if NeedVarargsPrototypes
777   va_start(args, msg);
778   vfprintf(stderr, msg, args);
779   va_end(args);
780 #else
781   fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
782 #endif
783 }
784
785 #if NeedVarargsPrototypes
786 void warning1(const char *msg, ...)
787 #else
788 /*VARARGS0*/
789 void warning1(const char *msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
790 #endif
791 {
792 #if NeedVarargsPrototypes
793   va_list args;
794   va_start(args, msg);
795   vfprintf(stderr, msg, args);
796   va_end(args);
797 #else
798   fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
799 #endif
800 }
801