32#if !defined(USGISH) || !defined(_SEQUENT_) || !defined(USE_CHMOD)
33#define _DEFAULT_SOURCE
38#define sigvec sigvector
41#ifdef X_POSIX_C_SOURCE
42#define _POSIX_C_SOURCE X_POSIX_C_SOURCE
46#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
118#ifdef SIGNALRETURNSINT
129#if defined(USG) || (defined(i386) && defined(SYSV)) || defined(WIN32) || defined(__EMX__) || defined(Lynx_22)
135#define sigaction sigvec
136#define sa_handler sv_handler
137#define sa_mask sv_mask
138#define sa_flags sv_flags
147 struct inclist *file_red,
int recursion,
159 char *makefile =
NULL;
161 struct symtab *psymp = predefs;
162 char *endmarker =
NULL;
163 char *defincdir =
NULL;
164 char **undeflist =
NULL;
165 int numundefs = 0, i;
174 if (argc == 2 && argv[1][0] ==
'@') {
180 char quotechar =
'\0';
183 if ((afd = open(argv[1] + 1, O_RDONLY)) < 0)
184 fatalerr(
"cannot open \"%s\"\n", argv[1] + 1);
186 args = (
char *)
malloc(ast.st_size + 1);
188 fatalerr(
"failed to allocate memory\n");
189 int bytes_read =
read(afd, args, ast.st_size);
191 fatalerr(
"failed to read %s\n", argv[1] + 1);
192 args[bytes_read] =
'\0';
194 for (p = args; *p; p++) {
196 if (quotechar ==
'\\' ||
197 (*p == quotechar && p[-1] !=
'\\'))
210 if (p > args && p[-1])
217 nargv = (
char **)
malloc(nargc *
sizeof(
char *));
220 for (p = args; argc < nargc; p += strlen(p) + 1)
221 if (*p) nargv[argc++] = p;
224 for (argc--, argv++; argc; argc--, argv++) {
226 if (endmarker && strcmp(endmarker, *argv) == 0) {
232 if (endmarker && **argv ==
'+')
239 switch (argv[0][1]) {
241 endmarker = &argv[0][2];
242 if (endmarker[0] ==
'\0') endmarker =
"--";
245 if (endmarker)
break;
247 fatalerr(
"-t should follow a file name\n");
249 *(tp - 1) = argv[0] + 2;
253 if (argv[0][2] ==
'\0') {
257 for (p = argv[0] + 2; *p ; p++)
267 *incp++ = argv[0] + 2;
268 if (**(incp - 1) ==
'\0') {
269 *(incp - 1) = *(++argv);
277 undeflist =
malloc(
sizeof(
char *));
280 numundefs *
sizeof(
char *));
281 if (argv[0][2] ==
'\0') {
285 undeflist[numundefs - 1] = argv[0] + 2;
288 defincdir = argv[0] + 2;
291 if (!strcmp(argv[0] + 2,
"sysroot")) {
299 if (endmarker)
break;
303 if (endmarker)
break;
304 if (argv[0][2] ==
'\0') {
307 width = atoi(argv[0]);
309 width = atoi(argv[0] + 2);
312 if (endmarker)
break;
313 if (argv[0][2] ==
'\0') {
321 if (endmarker)
break;
322 if (argv[0][2] ==
'\0') {
330 if (endmarker)
break;
334 _debugmask = atoi(argv[0] + 2);
338 if (endmarker)
break;
345 fatalerr(
"-s flag's value should start %s\n",
349 if (endmarker)
break;
350 makefile = argv[0] + 2;
351 if (*makefile ==
'\0') {
352 makefile = *(++argv);
368 if (endmarker)
break;
370 warning(
"ignoring option %s\n", argv[0]);
374 for (i = 0; i < numundefs; i++)
387 char *emxinc = getenv(
"C_INCLUDE_PATH");
391 beg = (
char*)strdup(emxinc);
393 end = (
char*)strchr(beg,
';');
396 fatalerr(
"Too many include dirs\n");
406 *incp++ =
"/usr/include";
412 *incp++ = POSTINCDIR;
414 }
else if (*defincdir) {
446 sigaddset(&
sig_act.sa_mask, SIGINT);
447 sigaddset(&
sig_act.sa_mask, SIGQUIT);
449 sigaddset(&
sig_act.sa_mask, SIGBUS);
451 sigaddset(&
sig_act.sa_mask, SIGILL);
452 sigaddset(&
sig_act.sa_mask, SIGSEGV);
453 sigaddset(&
sig_act.sa_mask, SIGHUP);
454 sigaddset(&
sig_act.sa_mask, SIGPIPE);
456 sigaddset(&
sig_act.sa_mask, SIGSYS);
459 sig_act.sa_mask = ((1 << (SIGINT - 1))
460 | (1 << (SIGQUIT - 1))
462 | (1 << (SIGBUS - 1))
464 | (1 << (SIGILL - 1))
465 | (1 << (SIGSEGV - 1))
466 | (1 << (SIGHUP - 1))
467 | (1 << (SIGPIPE - 1))
469 | (1 << (SIGSYS - 1))
514static int elim_cr(
char *buf,
int sz)
517 for (i = wp = 0; i < sz;
i++) {
532 if ((fd = open(
file, O_RDONLY)) < 0) {
535 *content->
f_p =
'\0';
542 if ((st.st_size =
read(fd, content->
f_base, st.st_size)) < 0)
545 st.st_size = elim_cr(content->
f_base, st.st_size);
548 content->
f_len = st.st_size + 1;
551 *content->
f_end =
'\0';
564 register char *p = (
char *)
malloc(strlen(str) + 1);
570int match(
register char *str,
register char **list)
574 for (i = 0; *list; i++, list++)
575 if (strcmp(str, *list) == 0)
594 return((
char *)
NULL);
597 for (bol = p--; ++p < eof;) {
599 if (*(p + 1) ==
'/') {
600 *p++ =
' ', *p++ =
' ';
601 while (*p && *p !=
'\n')
605 }
else if (*(p + 1) ==
'*') {
606 *p++ =
' ', *p++ =
' ';
608 if (*p ==
'*' && *(p + 1) ==
'/') {
609 *p++ =
' ', *p =
' ';
611 }
else if (*p ==
'\n')
617 }
else if (*p ==
'\\') {
618 if (*(p + 1) ==
'\n') {
623 }
else if (*p ==
'\n') {
631 (*cp ==
' ' || *cp ==
'\t'); cp++) {};
654 for (p =
file + strlen(
file); p >
file && *p !=
'.'; p--) ;
661#if defined(USG) && !defined(CRAY) && !defined(SVR4) && !defined(__EMX__) && !defined(clipper) && !defined(__clipper__)
666 if (link(from, to) == 0) {
678 FILE *fdin = 0, *fdout = 0;
679 char backup[ BUFSIZ ],
681 boolean found =
FALSE;
687 if (makefile && *makefile ==
'-' && *(makefile + 1) ==
'\0') {
696 if (stat(
"Makefile", &st) == 0)
697 makefile =
"Makefile";
698 else if (stat(
"makefile", &st) == 0)
699 makefile =
"makefile";
701 fatalerr(
"[mM]akefile is not present\n");
705 if ((fdin = fopen(makefile,
"r")) ==
NULL)
706 fatalerr(
"cannot open \"%s\"\n", makefile);
707 sprintf(backup,
"%s.bak", makefile);
709#if defined(WIN32) || defined(__EMX__)
712 if (rename(makefile, backup) < 0)
713 fatalerr(
"cannot rename %s to %s\n", makefile, backup);
714#if defined(WIN32) || defined(__EMX__)
715 if ((fdin = fopen(backup,
"r")) ==
NULL)
716 fatalerr(
"cannot open \"%s\"\n", backup);
719 if ((fdout = freopen(makefile,
"w", stdout)) ==
NULL)
720 fatalerr(
"cannot open \"%s\"\n", makefile);
723 while (!found && fgets(buf, BUFSIZ, fdin)) {
724 if (*buf ==
'#' && strncmp(
line, buf, len) == 0)
730 warning(
"Adding new delimiting line \"%s\" and dependencies...\n",
734 while (fgets(buf, BUFSIZ, fdin)) {
739#if defined(USGISH) || defined(_SEQUENT_) || defined(USE_CHMOD)
740 chmod(makefile, st.st_mode);
742 fchmod(fileno(fdout), st.st_mode);
756 vfprintf(stderr, msg, args);
767 vfprintf(stderr, msg, args);
777 vfprintf(stderr, msg, args);
double signal(double *x, double *par)
struct inclist * newinclude(char *, char *)
printf("Client 0: bytes recv = %d, bytes sent = %d\n", s0->GetBytesRecv(), s0->GetBytesSent())
struct inclist * inclistp
void warning1(char *msg,...)
void fatalerr(char *msg,...)
void undefine(char *symbol, struct inclist *file)
int main_orig(int argc, char **argv)
void redirect(char *, char *)
struct inclist maininclist
void define(char *def, struct inclist *file)
void define2(char *name, char *val, struct inclist *file)
struct filepointer * getfile(char *file)
char * base_name(register char *file)
void recursive_pr_include(struct inclist *head, char *file, char *base, char *dep)
void freefile(struct filepointer *)
char * copy(register char *str)
char * rgetline(register struct filepointer *filep)
static void catch(int sig)
void warning(char *msg,...)
int match(register char *str, register char **list)
int find_includes(struct filepointer *filep, struct inclist *file, struct inclist *file_red, int recursion, boolean failOK)