31 #pragma warning(disable : 4996)
45 #define sigvec sigvector
48 #ifdef X_POSIX_C_SOURCE
49 #define _POSIX_C_SOURCE X_POSIX_C_SOURCE
51 #undef _POSIX_C_SOURCE
53 #if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
62 #if NeedVarargsPrototypes
117 #ifdef SIGNALRETURNSINT
125 fatalerr ((
char *)
"got signal %d\n", sig);
128 #if defined(USG) || (defined(i386) && defined(SYSV)) || defined(WIN32) || defined(__EMX__) || defined(__OS2__)
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
145 if (!strncmp(fname,
"/cygdrive/", 10)) {
146 int oldlen = strlen(fname);
147 char *newprefix = (
char *)malloc(oldlen);
148 newprefix[0] = fname[10];
151 strncat(newprefix, fname + 11, oldlen - 11 + 1);
152 printf(
"translate cygwin: new filename is %s\n", newprefix);
178 int main(
int argc,
char **argv)
185 char *makefile = NULL;
187 struct symtab *psymp = predefs;
188 char *endmarker = NULL;
189 char *defincdir = NULL;
198 if (argc == 2 && argv[1][0] ==
'@') {
204 char quotechar =
'\0';
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';
216 for (p = args; *p; p++) {
218 if (quotechar ==
'\\' ||
219 (*p == quotechar && p[-1] !=
'\\'))
232 if (p > args && p[-1])
239 nargv = (
char **)malloc(nargc *
sizeof(
char *));
242 for (p = args; argc < nargc; p += strlen(p) + 1)
243 if (*p) nargv[argc++] = p;
246 for(argc--, argv++; argc; argc--, argv++) {
248 if (endmarker && strcmp (endmarker, *argv) == 0) {
254 if (endmarker && **argv ==
'+')
261 endmarker = &argv[0][2];
262 if (endmarker[0] ==
'\0') endmarker = (
char *)
"--";
265 if (argv[0][2] ==
'\0') {
269 for (p=argv[0] + 2; *p ; p++)
281 if (endmarker)
break;
282 if (argv[0][2] ==
'\0') {
285 envinclude = getenv(argv[0]);
286 }
else envinclude = getenv(argv[0]+2);
287 if (!envinclude)
break;
288 prevdir = envinclude;
289 delim = (
char*)strchr(envinclude,
';');
297 delim = (
char*)strchr(delim,
';');
307 if (**(excp-1) ==
'\0') {
310 *(excp-1) = *(argv + 1);
313 fatalerr(
"Too many -I flags via -X.\n");
315 if (**(incp-1) ==
'\0') {
316 *(incp-1) = *(++argv);
324 if (**(incp-1) ==
'\0') {
325 *(incp-1) = *(++argv);
331 defincdir = argv[0]+2;
335 if (endmarker)
break;
339 if (endmarker)
break;
340 if (argv[0][2] ==
'\0') {
343 width = atoi(argv[0]);
345 width = atoi(argv[0]+2);
348 if (endmarker)
break;
349 if (argv[0][2] ==
'\0') {
357 if (endmarker)
break;
358 if (argv[0][2] ==
'\0') {
367 if (endmarker)
break;
371 _debugmask = atoi(argv[0]+2);
375 if (endmarker)
break;
382 fatalerr(
"-s flag's value should start %s\n",
386 if (endmarker)
break;
387 makefile = argv[0]+2;
388 if (*makefile ==
'\0') {
389 makefile = *(++argv);
404 if (endmarker)
break;
406 warning(
"ignoring option %s\n", argv[0]);
420 *incp++ = INCLUDEDIR;
425 *incp++ = POSTINCDIR;
427 }
else if (*defincdir) {
441 signal (SIGHUP, c_catch);
443 signal (SIGINT, c_catch);
445 signal (SIGQUIT, c_catch);
447 signal (SIGILL, c_catch);
449 signal (SIGBUS, c_catch);
451 signal (SIGSEGV, c_catch);
453 signal (SIGSYS, c_catch);
459 sigaddset(&
sig_act.sa_mask, SIGINT);
460 sigaddset(&
sig_act.sa_mask, SIGQUIT);
462 sigaddset(&
sig_act.sa_mask, SIGBUS);
464 sigaddset(&
sig_act.sa_mask, SIGILL);
465 sigaddset(&
sig_act.sa_mask, SIGSEGV);
466 sigaddset(&
sig_act.sa_mask, SIGHUP);
467 sigaddset(&
sig_act.sa_mask, SIGPIPE);
469 sigaddset(&
sig_act.sa_mask, SIGSYS);
472 sig_act.sa_mask = ((1<<(SIGINT -1))
487 sigaction(SIGHUP, &
sig_act, (
struct sigaction *)0);
488 sigaction(SIGINT, &
sig_act, (
struct sigaction *)0);
489 sigaction(SIGQUIT, &
sig_act, (
struct sigaction *)0);
490 sigaction(SIGILL, &
sig_act, (
struct sigaction *)0);
492 sigaction(SIGBUS, &
sig_act, (
struct sigaction *)0);
494 sigaction(SIGSEGV, &
sig_act, (
struct sigaction *)0);
496 sigaction(SIGSYS, &
sig_act, (
struct sigaction *)0);
528 content->
f_p = content->
f_base = content->
f_end = (
char *)malloc(1);
529 *content->
f_p =
'\0';
533 content->
f_base = (
char *)malloc(st.st_size+1);
534 if (content->
f_base == NULL)
536 if ((st.st_size =
read(fd, content->
f_base, st.st_size)) < 0)
539 content->
f_len = st.st_size+1;
542 *content->
f_end =
'\0';
556 register char *p = (
char *)malloc(strlen(str) + 1);
562 int match(
register const char *str,
register const char **list)
566 for (i=0; *list; i++, list++)
567 if (strcmp(str, *list) == 0)
591 for (p = filep->
f_p; p < eof; p++) {
592 if (bol > p)
fatalerr(
"somehow bol got ahead of p.");
593 if (*p ==
'/' && *(p+1) ==
'*') {
595 *p++ =
' '; *p++ =
' ';
597 if (*p ==
'*' && *(p+1) ==
'/') {
598 *p++ =
' '; *p =
' ';
601 }
else if (*p ==
'\n') lineno++;
605 }
else if (*p ==
'/' && *(p+1) ==
'/') {
607 *p++ =
' '; *p++ =
' ';
608 while (p < eof && (*p !=
'\n') ) *p++ =
' ';
613 }
else if (*p ==
'\\') {
615 if (*(p+1) ==
'\n') {
621 }
else if (*p ==
'\n') {
628 while ( (bol < p) && ((*bol ==
' ') || (*bol ==
'\t')) ) bol++;
634 for (cp = bol+1; *cp && (*cp ==
' ' || *cp ==
'\t'); cp++) {}
635 if (*cp) { p++;
goto done; }
642 if (*bol !=
'#') bol = NULL;
658 for(p=file+strlen(file); p>file && *p !=
'.'; p--) ;
665 #if defined(USG) && !defined(CRAY) && !defined(SVR4) && !defined(__EMX__)
666 int rename(
char *from,
char *to)
669 if (link (from, to) == 0) {
682 char backup[ BUFSIZ ],
690 if (makefile && *makefile ==
'-' && *(makefile+1) ==
'\0')
697 if (
stat(
"Makefile", &st) == 0)
698 makefile = (
char *)
"Makefile";
699 else if (
stat(
"makefile", &st) == 0)
700 makefile = (
char *)
"makefile";
702 fatalerr(
"[mM]akefile is not present\n");
708 sprintf(backup,
"%s.bak", makefile);
710 #if defined(WIN32) || defined(__EMX__) || defined(__OS2__)
715 #if defined(WIN32) || defined(__EMX__) || defined(__OS2__)
721 len = int(strlen(line));
722 while (!found && fgets(buf, BUFSIZ, fdin)) {
723 if (*buf ==
'#' && strncmp(line, buf, len) == 0)
729 warning(
"Adding new delimiting line \"%s\" and dependencies...\n",
733 while (fgets(buf, BUFSIZ, fdin)) {
738 #if defined(USGISH) || defined(_SEQUENT_) || defined(USE_CHMOD)
739 chmod(makefile, st.st_mode);
741 fchmod(
fileno(fdout), st.st_mode);
745 #if NeedVarargsPrototypes
749 void fatalerr(
char *msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
752 #if NeedVarargsPrototypes
756 #if NeedVarargsPrototypes
758 vfprintf(stderr, msg, args);
761 fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
766 #if NeedVarargsPrototypes
767 void warning(
const char *msg, ...)
770 void warning(
const char *msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
773 #if NeedVarargsPrototypes
777 #if NeedVarargsPrototypes
779 vfprintf(stderr, msg, args);
782 fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
786 #if NeedVarargsPrototypes
790 void warning1(
const char *msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
793 #if NeedVarargsPrototypes
796 vfprintf(stderr, msg, args);
799 fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
void recursive_pr_include(register inclist *head, register char *file, register char *base)
int find_includes(filepointer *filep, inclist *file, inclist *file_red, int recursion, bool failOK)
void define2(char *name, char *val, inclist *file)
inclist * newinclude(register char *newfile, register char *incstring)
void define(char *def, inclist *file)
char * translate_cygwin(char *fname)
void freefile(struct filepointer *fp)
void warning1(const char *msg, x1, x2, x3, x4, x5, x6, x7, x8, x9)
const char * directives[]
int main(int argc, char **argv)
struct filepointer * getfile(char *file)
char * notdotdot[MAXDIRS]
struct inclist maininclist
struct inclist inc_list[MAXFILES]
void fatalerr(char *msg, x1, x2, x3, x4, x5, x6, x7, x8, x9)
char * filelist[MAXFILES]
char * getline(register struct filepointer *filep)
char * excludedirs[MAXDIRS+1]
char * base_name(register char *file)
int match(register const char *str, register const char **list)
void redirect(char *line, char *makefile)
char * includedirs[MAXDIRS+1]
void warning(const char *msg, x1, x2, x3, x4, x5, x6, x7, x8, x9)
struct inclist * inclistp
char * copy(register char *str)