driver.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /* fcc/fm2/fpc
  2. Driver for fast ACK compilers.
  3. Derived from the C compiler driver from Minix.
  4. Compile this file with
  5. cc -O -I<ACK home directory>/config -DF?? driver.c
  6. where F?? is either FCC, FPC, or FM2.
  7. Install the resulting binaries in the EM bin directory.
  8. Suggested names: afcc, afm2, and afpc.
  9. */
  10. #if FM2+FPC+FCC > 1
  11. Something wrong here! Only one of FM2, FPC, or FCC must be defined
  12. #endif
  13. #ifdef sun3
  14. #define MACHNAME "m68020"
  15. #define SYSNAME "sun3"
  16. #endif
  17. #ifdef vax4
  18. #define MACHNAME "vax4"
  19. #define SYSNAME "vax4"
  20. #endif
  21. #ifdef i386
  22. #define MACHNAME "i386"
  23. #define SYSNAME "i386"
  24. #endif
  25. #include <errno.h>
  26. #include <signal.h>
  27. #include <stdio.h>
  28. #include <em_path.h>
  29. #if __STDC__
  30. #include <stdarg.h>
  31. #else
  32. #include <varargs.h>
  33. #endif
  34. /*
  35. Version producing ACK .o files in one pass.
  36. */
  37. #define MAXARGC 256 /* maximum number of arguments allowed in a list */
  38. #define USTR_SIZE 128 /* maximum length of string variable */
  39. typedef char USTRING[USTR_SIZE];
  40. struct arglist {
  41. int al_argc;
  42. char *al_argv[MAXARGC];
  43. };
  44. #define CPP_NAME "$H/lib.bin/cpp"
  45. #define LD_NAME "$H/lib.bin/em_led"
  46. #define CV_NAME "$H/lib.bin/$S/cv"
  47. #define SHELL "/bin/sh"
  48. char *CPP;
  49. char *COMP;
  50. char *cc = "cc";
  51. int kids = -1;
  52. int ecount = 0;
  53. struct arglist CPP_FLAGS = {
  54. #ifdef FCC
  55. 7,
  56. #else
  57. 13,
  58. #endif
  59. {
  60. "-D__unix",
  61. "-D_EM_WSIZE=4",
  62. "-D_EM_PSIZE=4",
  63. "-D_EM_SSIZE=2",
  64. "-D_EM_LSIZE=4",
  65. "-D_EM_FSIZE=4",
  66. "-D_EM_DSIZE=8",
  67. #ifndef FCC
  68. "-DEM_WSIZE=4",
  69. "-DEM_PSIZE=4",
  70. "-DEM_SSIZE=2",
  71. "-DEM_LSIZE=4",
  72. "-DEM_FSIZE=4",
  73. "-DEM_DSIZE=8",
  74. #endif
  75. }
  76. };
  77. struct arglist LD_HEAD = {
  78. 2,
  79. {
  80. "$H/lib/$S/head_em",
  81. #ifdef FCC
  82. "$H/lib/$S/head_$A"
  83. #endif
  84. #ifdef FM2
  85. "$H/lib/$S/head_m2"
  86. #endif
  87. #ifdef FPC
  88. "$H/lib/$S/head_pc"
  89. #endif
  90. }
  91. };
  92. struct arglist LD_TAIL = {
  93. #if defined(sun3) || defined(i386)
  94. 5,
  95. #else
  96. 4,
  97. #endif
  98. {
  99. #ifdef FCC
  100. "$H/lib/$S/tail_$A",
  101. #endif
  102. #ifdef FM2
  103. "$H/lib/$S/tail_m2",
  104. #endif
  105. #ifdef FPC
  106. "$H/lib/$S/tail_pc",
  107. #endif
  108. #if defined(sun3) || defined(i386)
  109. "$H/lib/$M/tail_fp",
  110. #endif
  111. "$H/lib/$M/tail_em",
  112. "$H/lib/$S/tail_mon",
  113. "$H/lib/$M/end_em"
  114. }
  115. };
  116. struct arglist align = {
  117. 5, {
  118. #ifdef sun3
  119. "-a0:4",
  120. "-a1:4",
  121. "-a2:0x20000",
  122. "-a3:4",
  123. "-b0:0x2020"
  124. #endif
  125. #ifdef vax4
  126. "-a0:4",
  127. "-a1:4",
  128. "-a2:0x400",
  129. "-a3:4",
  130. "-b0:0"
  131. #endif
  132. #ifdef i386
  133. "-a0:4",
  134. "-a1:4",
  135. "-a2:4",
  136. "-a3:4",
  137. "-b1:0x1880000"
  138. #endif
  139. }
  140. };
  141. struct arglist COMP_FLAGS;
  142. char *o_FILE = "a.out"; /* default name for executable file */
  143. #define remove(str) ((noexec || unlink(str)), (str)[0] = '\0')
  144. #define cleanup(str) (str && str[0] && remove(str))
  145. #define init(al) ((al)->al_argc = 1)
  146. char ProgCall[128];
  147. struct arglist SRCFILES;
  148. struct arglist LDFILES;
  149. int RET_CODE = 0;
  150. struct arglist LD_FLAGS;
  151. struct arglist CALL_VEC;
  152. int o_flag = 0;
  153. int c_flag = 0;
  154. int g_flag = 0;
  155. int v_flag = 0;
  156. int O_flag = 0;
  157. int ansi_c = 0;
  158. #if __STDC__
  159. char *mkstr(char *, ...);
  160. #else
  161. char *mkstr();
  162. #endif
  163. char *malloc();
  164. char *alloc();
  165. char *extension();
  166. char *expand_string();
  167. USTRING ofile;
  168. USTRING BASE;
  169. USTRING tmp_file;
  170. int noexec = 0;
  171. extern char *strcat(), *strcpy(), *mktemp(), *strchr();
  172. trapcc(sig)
  173. int sig;
  174. {
  175. signal(sig, SIG_IGN);
  176. if (kids != -1) kill(kids, sig);
  177. cleanup(ofile);
  178. cleanup(tmp_file);
  179. exit(1);
  180. }
  181. #ifdef FCC
  182. #define lang_suffix() "c"
  183. #define comp_name() "$H/lib.bin/c_ce"
  184. #define ansi_c_name() "$H/lib.bin/c_ce.ansi"
  185. #endif /* FCC */
  186. #ifdef FM2
  187. #define lang_suffix() "mod"
  188. #define comp_name() "$H/lib.bin/m2_ce"
  189. #endif /* FM2 */
  190. #ifdef FPC
  191. #define lang_suffix() "p"
  192. #define comp_name() "$H/lib.bin/pc_ce"
  193. #endif /* FPC */
  194. #ifdef FCC
  195. int
  196. lang_opt(str)
  197. char *str;
  198. {
  199. switch(str[1]) {
  200. case 'R':
  201. if (! ansi_c) {
  202. append(&COMP_FLAGS, str);
  203. return 1;
  204. }
  205. break;
  206. case '-': /* debug options */
  207. append(&COMP_FLAGS, str);
  208. return 1;
  209. case 'a': /* -ansi flag */
  210. if (! strcmp(str, "-ansi")) {
  211. ansi_c = 1;
  212. COMP = expand_string(ansi_c_name());
  213. return 1;
  214. }
  215. break;
  216. case 'w': /* disable warnings */
  217. if (! ansi_c) {
  218. append(&COMP_FLAGS, str);
  219. return 1;
  220. }
  221. if (str[2]) {
  222. str[1] = '-';
  223. append(&COMP_FLAGS, &str[1]);
  224. }
  225. else append(&COMP_FLAGS, "-a");
  226. return 1;
  227. }
  228. return 0;
  229. }
  230. #endif /* FCC */
  231. #ifdef FM2
  232. int
  233. lang_opt(str)
  234. char *str;
  235. {
  236. switch(str[1]) {
  237. case '-': /* debug options */
  238. case 'w': /* disable warnings */
  239. case 'R': /* no runtime checks */
  240. case 'W': /* add warnings */
  241. case 'L': /* no line numbers */
  242. case 'A': /* extra array bound checks */
  243. case '3': /* only accept 3rd edition Modula-2 */
  244. append(&COMP_FLAGS, str);
  245. return 1;
  246. case 'I':
  247. append(&COMP_FLAGS, str);
  248. break; /* !!! */
  249. case 'U': /* underscores in identifiers allowed */
  250. if (str[2] == '\0') {
  251. append(&COMP_FLAGS, str);
  252. return 1;
  253. }
  254. break;
  255. case 'e': /* local extension for Modula-2 compiler:
  256. procedure constants
  257. */
  258. str[1] = 'l';
  259. append(&COMP_FLAGS, str);
  260. return 1;
  261. }
  262. return 0;
  263. }
  264. #endif /* FM2 */
  265. #ifdef FPC
  266. int
  267. lang_opt(str)
  268. char *str;
  269. {
  270. switch(str[1]) {
  271. case '-': /* debug options */
  272. case 'a': /* enable assertions */
  273. case 'd': /* allow doubles (longs) */
  274. case 'i': /* set size of integer sets */
  275. case 't': /* tracing */
  276. case 'w': /* disable warnings */
  277. case 'A': /* extra array bound checks */
  278. case 'C': /* distinguish between lower case and upper case */
  279. case 'L': /* no FIL and LIN instructions */
  280. case 'R': /* no runtime checks */
  281. append(&COMP_FLAGS, str);
  282. return 1;
  283. case 'u':
  284. case 'U':
  285. /* underscores in identifiers */
  286. case 's':
  287. /* only compile standard pascal */
  288. case 'c':
  289. /* C type strings */
  290. if (str[2] == '+' && str[3] == '\0') {
  291. str[2] = 0;
  292. append(&COMP_FLAGS, str);
  293. return 1;
  294. }
  295. }
  296. return 0;
  297. }
  298. #endif /* FPC */
  299. main(argc, argv)
  300. char *argv[];
  301. {
  302. char *str;
  303. char **argvec;
  304. int count;
  305. char *ext;
  306. register struct arglist *call = &CALL_VEC;
  307. char *file;
  308. char *ldfile;
  309. char *INCLUDE = 0;
  310. int compile_cnt = 0;
  311. setbuf(stdout, (char *) 0);
  312. basename(*argv++,ProgCall);
  313. COMP = expand_string(comp_name());
  314. CPP = expand_string(CPP_NAME);
  315. #ifdef vax4
  316. append(&CPP_FLAGS, "-D__vax");
  317. #endif
  318. #ifdef sun3
  319. append(&CPP_FLAGS, "-D__sun");
  320. #endif
  321. #ifdef m68020
  322. append(&CPP_FLAGS, "-D__mc68020");
  323. append(&CPP_FLAGS, "-D__mc68000");
  324. #endif
  325. if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
  326. signal(SIGHUP, trapcc);
  327. if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  328. signal(SIGINT, trapcc);
  329. if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
  330. signal(SIGQUIT, trapcc);
  331. while (--argc > 0) {
  332. if (*(str = *argv++) != '-') {
  333. append(&SRCFILES, str);
  334. continue;
  335. }
  336. if (lang_opt(str)) {
  337. }
  338. else switch (str[1]) {
  339. case 'c': /* stop after producing .o files */
  340. c_flag = 1;
  341. break;
  342. case 'D': /* preprocessor #define */
  343. case 'U': /* preprocessor #undef */
  344. append(&CPP_FLAGS, str);
  345. break;
  346. case 'I': /* include directory */
  347. append(&CPP_FLAGS, str);
  348. break;
  349. case 'g': /* debugger support */
  350. append(&COMP_FLAGS, str);
  351. g_flag = 1;
  352. break;
  353. case 'a': /* -ansi flag */
  354. if (! strcmp(str, "-ansi")) {
  355. ansi_c = 1;
  356. return 1;
  357. }
  358. break;
  359. case 'o': /* target file */
  360. if (argc-- >= 0) {
  361. o_flag = 1;
  362. o_FILE = *argv++;
  363. ext = extension(o_FILE);
  364. if (ext != o_FILE && ! strcmp(ext, lang_suffix())
  365. ) {
  366. error("-o would overwrite %s", o_FILE);
  367. }
  368. }
  369. break;
  370. case 'u': /* mark identifier as undefined */
  371. append(&LD_FLAGS, str);
  372. if (argc-- >= 0)
  373. append(&LD_FLAGS, *argv++);
  374. break;
  375. case 'O': /* use built in peephole optimizer */
  376. O_flag = 1;
  377. break;
  378. case 'v': /* verbose */
  379. v_flag++;
  380. if (str[2] == 'n')
  381. noexec = 1;
  382. break;
  383. case 'l': /* library file */
  384. append(&SRCFILES, str);
  385. break;
  386. case 'M': /* use other compiler (for testing) */
  387. strcpy(COMP, str+2);
  388. break;
  389. case 's': /* strip */
  390. if (str[2] == '\0') {
  391. append(&LD_FLAGS, str);
  392. break;
  393. }
  394. /* fall through */
  395. default:
  396. warning("%s flag ignored", str);
  397. break;
  398. }
  399. }
  400. if (ecount) exit(1);
  401. count = SRCFILES.al_argc;
  402. argvec = &(SRCFILES.al_argv[0]);
  403. while (count-- > 0) {
  404. ext = extension(*argvec);
  405. if (*argvec[0] != '-' &&
  406. ext != *argvec++ && (! strcmp(ext, lang_suffix())
  407. )) {
  408. compile_cnt++;
  409. }
  410. }
  411. if (compile_cnt > 1 && c_flag && o_flag) {
  412. warning("-o flag ignored");
  413. o_flag = 0;
  414. }
  415. #ifdef FM2
  416. INCLUDE = expand_string("-I$H/lib/m2");
  417. #endif /* FM2 */
  418. #ifdef FCC
  419. INCLUDE = expand_string(ansi_c ? "-I$H/include/tail_ac" : "-I$H/include/_tail_cc");
  420. append(&COMP_FLAGS, "-L");
  421. #endif /* FCC */
  422. count = SRCFILES.al_argc;
  423. argvec = &(SRCFILES.al_argv[0]);
  424. while (count-- > 0) {
  425. register char *f;
  426. basename(file = *argvec++, BASE);
  427. ext = extension(file);
  428. if (file[0] != '-' &&
  429. ext != file && (!strcmp(ext, lang_suffix())
  430. )) {
  431. if (compile_cnt > 1) printf("%s\n", file);
  432. ldfile = c_flag ? ofile : alloc((unsigned)strlen(BASE)+3);
  433. if (
  434. #ifdef FCC
  435. !strcmp(ext, "s") &&
  436. #endif
  437. needsprep(file)) {
  438. strcpy(tmp_file, TMP_DIR);
  439. strcat(tmp_file, "/F_XXXXXX");
  440. mktemp(tmp_file);
  441. init(call);
  442. append(call, CPP);
  443. concat(call, &CPP_FLAGS);
  444. append(call, INCLUDE);
  445. append(call, file);
  446. if (runvec(call, tmp_file)) {
  447. file = tmp_file;
  448. }
  449. else {
  450. remove(tmp_file);
  451. tmp_file[0] = '\0';
  452. continue;
  453. }
  454. }
  455. init(call);
  456. if (o_flag && c_flag) {
  457. f = o_FILE;
  458. }
  459. else f = mkstr(ldfile, BASE, ".", "o", (char *)0);
  460. append(call, COMP);
  461. #ifdef FCC
  462. concat(call, &CPP_FLAGS);
  463. #endif
  464. concat(call, &COMP_FLAGS);
  465. #if FM2 || FCC
  466. append(call, INCLUDE);
  467. #endif
  468. append(call, file);
  469. append(call, f);
  470. if (runvec(call, (char *) 0)) {
  471. file = f;
  472. }
  473. else {
  474. remove(f);
  475. continue;
  476. }
  477. cleanup(tmp_file);
  478. tmp_file[0] = '\0';
  479. }
  480. else if (file[0] != '-' &&
  481. strcmp(ext, "o") && strcmp(ext, "a")) {
  482. warning("file with unknown suffix (%s) passed to the loader", ext);
  483. }
  484. if (c_flag)
  485. continue;
  486. append(&LDFILES, file);
  487. }
  488. /* *.s to a.out */
  489. if (RET_CODE == 0 && LDFILES.al_argc > 0) {
  490. init(call);
  491. expand(&LD_HEAD);
  492. cc = "cc.2g";
  493. expand(&LD_TAIL);
  494. append(call, expand_string(LD_NAME));
  495. concat(call, &align);
  496. append(call, "-o");
  497. strcpy(tmp_file, TMP_DIR);
  498. strcat(tmp_file, "/F_XXXXXX");
  499. mktemp(tmp_file);
  500. append(call, tmp_file);
  501. concat(call, &LD_HEAD);
  502. concat(call, &LD_FLAGS);
  503. concat(call, &LDFILES);
  504. if (g_flag) append(call, expand_string("$H/lib/$M/tail_db"));
  505. #ifdef FCC
  506. if (! ansi_c) append(call, expand_string("$H/lib/$S/tail_cc.1s"));
  507. #endif
  508. concat(call, &LD_TAIL);
  509. if (! runvec(call, (char *) 0)) {
  510. cleanup(tmp_file);
  511. exit(RET_CODE);
  512. }
  513. init(call);
  514. append(call, expand_string(CV_NAME));
  515. append(call, tmp_file);
  516. append(call, o_FILE);
  517. runvec(call, (char *) 0);
  518. cleanup(tmp_file);
  519. }
  520. exit(RET_CODE);
  521. }
  522. needsprep(name)
  523. char *name;
  524. {
  525. int file;
  526. char fc;
  527. file = open(name,0);
  528. if (file < 0) return 0;
  529. if (read(file, &fc, 1) != 1) fc = 0;
  530. close(file);
  531. return fc == '#';
  532. }
  533. char *
  534. alloc(u)
  535. unsigned u;
  536. {
  537. char *p = malloc(u);
  538. if (p == 0)
  539. panic("no space");
  540. return p;
  541. }
  542. char *
  543. expand_string(s)
  544. char *s;
  545. {
  546. char buf[1024];
  547. register char *p = s;
  548. register char *q = &buf[0];
  549. int expanded = 0;
  550. if (!p) return p;
  551. while (*p) {
  552. if (*p == '$') {
  553. p++;
  554. expanded = 1;
  555. switch(*p++) {
  556. case 'A':
  557. if (ansi_c) strcpy(q, "ac");
  558. else strcpy(q, cc);
  559. break;
  560. case 'H':
  561. strcpy(q, EM_DIR);
  562. break;
  563. case 'M':
  564. strcpy(q, MACHNAME);
  565. break;
  566. case 'S':
  567. strcpy(q, SYSNAME);
  568. break;
  569. default:
  570. panic("internal error");
  571. break;
  572. }
  573. while (*q) q++;
  574. }
  575. else *q++ = *p++;
  576. }
  577. if (! expanded) return s;
  578. *q++ = '\0';
  579. p = alloc((unsigned int) (q - buf));
  580. return strcpy(p, buf);
  581. }
  582. append(al, arg)
  583. register struct arglist *al;
  584. char *arg;
  585. {
  586. if (!arg || !*arg) return;
  587. if (al->al_argc >= MAXARGC)
  588. panic("argument list overflow");
  589. al->al_argv[(al->al_argc)++] = arg;
  590. }
  591. expand(al)
  592. register struct arglist *al;
  593. {
  594. register int i = al->al_argc;
  595. register char **p = &(al->al_argv[0]);
  596. while (i-- > 0) {
  597. *p = expand_string(*p);
  598. p++;
  599. }
  600. }
  601. concat(al1, al2)
  602. struct arglist *al1, *al2;
  603. {
  604. register i = al2->al_argc;
  605. register char **p = &(al1->al_argv[al1->al_argc]);
  606. register char **q = &(al2->al_argv[0]);
  607. if ((al1->al_argc += i) >= MAXARGC)
  608. panic("argument list overflow");
  609. while (i-- > 0) {
  610. *p++ = *q++;
  611. }
  612. }
  613. #if __STDC__
  614. /*VARARGS*/
  615. char *
  616. mkstr(char *dst, ...)
  617. {
  618. va_list ap;
  619. va_start(ap, dst);
  620. {
  621. register char *p;
  622. register char *q;
  623. q = dst;
  624. p = va_arg(ap, char *);
  625. while (p) {
  626. while (*q++ = *p++);
  627. q--;
  628. p = va_arg(ap, char *);
  629. }
  630. }
  631. va_end(ap);
  632. return dst;
  633. }
  634. #else
  635. /*VARARGS*/
  636. char *
  637. mkstr(va_alist)
  638. va_dcl
  639. {
  640. va_list ap;
  641. char *dst;
  642. va_start(ap);
  643. {
  644. register char *p;
  645. register char *q;
  646. dst = q = va_arg(ap, char *);
  647. p = va_arg(ap, char *);
  648. while (p) {
  649. while (*q++ = *p++);
  650. q--;
  651. p = va_arg(ap, char *);
  652. }
  653. }
  654. va_end(ap);
  655. return dst;
  656. }
  657. #endif
  658. basename(str, dst)
  659. char *str;
  660. register char *dst;
  661. {
  662. register char *p1 = str;
  663. register char *p2 = p1;
  664. while (*p1)
  665. if (*p1++ == '/')
  666. p2 = p1;
  667. p1--;
  668. while (*p1 != '.' && p1 >= p2) p1--;
  669. if (p1 >= p2) {
  670. *p1 = '\0';
  671. while (*dst++ = *p2++);
  672. *p1 = '.';
  673. }
  674. else
  675. while (*dst++ = *p2++);
  676. }
  677. char *
  678. extension(fn)
  679. char *fn;
  680. {
  681. register char *c = fn;
  682. while (*c++) ;
  683. while (*--c != '.' && c >= fn) { }
  684. if (c++ < fn || !*c) return fn;
  685. return c;
  686. }
  687. runvec(vec, outp)
  688. struct arglist *vec;
  689. char *outp;
  690. {
  691. int pid, status;
  692. if (v_flag) {
  693. pr_vec(vec);
  694. putc('\n', stderr);
  695. }
  696. if ((pid = fork()) == 0) { /* start up the process */
  697. if (outp) { /* redirect standard output */
  698. close(1);
  699. if (creat(outp, 0666) != 1)
  700. panic("cannot create output file");
  701. }
  702. ex_vec(vec);
  703. }
  704. if (pid == -1)
  705. panic("no more processes");
  706. kids = pid;
  707. wait(&status);
  708. if (status) switch(status & 0177) {
  709. case SIGHUP:
  710. case SIGINT:
  711. case SIGQUIT:
  712. case SIGTERM:
  713. case 0:
  714. break;
  715. default:
  716. error("%s died with signal %d\n", vec->al_argv[1], status&0177);
  717. }
  718. kids = -1;
  719. return status ? ((RET_CODE = 1), 0) : 1;
  720. }
  721. /*VARARGS1*/
  722. error(str, s1, s2)
  723. char *str, *s1, *s2;
  724. {
  725. fprintf(stderr, "%s: ", ProgCall);
  726. fprintf(stderr, str, s1, s2);
  727. putc('\n', stderr);
  728. ecount++;
  729. }
  730. /*VARARGS1*/
  731. warning(str, s1, s2)
  732. char *str, *s1, *s2;
  733. {
  734. fprintf(stderr, "%s: (warning) ", ProgCall);
  735. fprintf(stderr, str, s1, s2);
  736. putc('\n', stderr);
  737. }
  738. panic(str)
  739. char *str;
  740. {
  741. error(str);
  742. trapcc(SIGINT);
  743. }
  744. pr_vec(vec)
  745. register struct arglist *vec;
  746. {
  747. register char **ap = &vec->al_argv[1];
  748. vec->al_argv[vec->al_argc] = 0;
  749. fprintf(stderr, "%s", *ap);
  750. while (*++ap) {
  751. fprintf(stderr, " %s", *ap);
  752. }
  753. }
  754. extern int errno;
  755. ex_vec(vec)
  756. register struct arglist *vec;
  757. {
  758. if (noexec)
  759. exit(0);
  760. vec->al_argv[vec->al_argc] = 0;
  761. execv(vec->al_argv[1], &(vec->al_argv[1]));
  762. if (errno == ENOEXEC) { /* not an a.out, try it with the SHELL */
  763. vec->al_argv[0] = SHELL;
  764. execv(SHELL, &(vec->al_argv[0]));
  765. }
  766. if (access(vec->al_argv[1], 1) == 0) {
  767. /* File is executable. */
  768. error("cannot execute %s", vec->al_argv[1]);
  769. } else {
  770. error("%s is not executable", vec->al_argv[1]);
  771. }
  772. exit(1);
  773. }