driver.c 14 KB

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