cem.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /* $Header$ */
  2. /*
  3. Driver for the CEMCOM compiler: works like /bin/cc and accepts
  4. most of the options accepted by /bin/cc and /usr/em/bin/ack.
  5. Date written: dec 4, 1985
  6. Adapted for 68000 (Aug 19, 1986)
  7. Merged the vax and mantra versions (Nov 10, 1986)
  8. Author: Erik Baalbergen
  9. */
  10. #include <stdio.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <errno.h>
  14. #include <signal.h>
  15. #define MAXARGC 256 /* maximum number of arguments allowed in a list */
  16. #define USTR_SIZE 1024 /* maximum length of string variable */
  17. struct arglist {
  18. int al_argc;
  19. char *al_argv[MAXARGC];
  20. };
  21. /* some system-dependent variables */
  22. char *PP = "/lib/cpp";
  23. char *CEM = "/usr/em/lib/em_cemcom";
  24. char *ENCODE = "/usr/em/lib/em_encode";
  25. char *DECODE = "/usr/em/lib/em_decode";
  26. char *OPT = "/usr/em/lib/em_opt";
  27. char *SHELL = "/bin/sh";
  28. #ifndef MANTRA
  29. char *CG = "/usr/em/lib/vax4/cg";
  30. char *AS = "/bin/as";
  31. char *AS_FIX = "/user1/erikb/bin/mcomm";
  32. char *LD = "/bin/ld";
  33. char *LIBDIR = "/user1/cem/lib";
  34. char *V_FLAG = "-Vs2.2w4.4i4.4l4.4f4.4d8.4p4.4";
  35. #else MANTRA
  36. char *CG = "/usr/em/lib/m68k2/cg";
  37. char *AS = "/usr/em/lib/m68k2/as";
  38. char *LD = "/usr/em/lib/em_led";
  39. char *CV = "/usr/em/lib/m68k2/cv";
  40. char *LIBDIR = "/usr/em/lib/m68k2";
  41. char *V_FLAG = "-Vs2.2w2.2i2.2l4.2f4.2d8.2p4.2";
  42. #endif MANTRA
  43. struct arglist LD_HEAD = {
  44. 2,
  45. {
  46. #ifndef MANTRA
  47. "/usr/em/lib/vax4/head_em",
  48. "/usr/em/lib/vax4/head_cc"
  49. #else MANTRA
  50. "/usr/em/lib/m68k2/head_em",
  51. "/usr/em/lib/m68k2/head_cc"
  52. #endif MANTRA
  53. }
  54. };
  55. struct arglist LD_TAIL = {
  56. #ifndef MANTRA
  57. 4,
  58. {
  59. "/user1/cem/lib/libc.a",
  60. "/user1/cem/lib/stb.o",
  61. "/usr/em/lib/vax4/tail_mon",
  62. "/usr/em/lib/vax4/tail_em"
  63. }
  64. #else MANTRA
  65. 7,
  66. {
  67. "/usr/em/lib/m68k2/tail_cc.1s",
  68. "/usr/em/lib/m68k2/tail_cc.2g",
  69. "/usr/em/lib/m68k2/tail_cem",
  70. "/usr/em/lib/m68k2/tail_fp.a",
  71. "/usr/em/lib/m68k2/tail_em.rt",
  72. "/usr/em/lib/m68k2/tail_mon",
  73. "/usr/em/lib/m68k2/end_em"
  74. }
  75. #endif MANTRA
  76. };
  77. char *o_FILE = "a.out";
  78. #ifdef MANTRA
  79. char *cv_FILE = "cv.out";
  80. #endif MANTRA
  81. #define remove(str) (((FLAG(t) == 0) && unlink(str)), (str)[0] = '\0')
  82. #define cleanup(str) (str && remove(str))
  83. #define mkname(dst, s1, s2) mkstr(dst, (s1), (s2), 0)
  84. #define init(al) (al)->al_argc = 1
  85. #define library(nm) \
  86. mkstr(alloc((unsigned int)strlen(nm) + strlen(LIBDIR) + 7), \
  87. LIBDIR, "/lib", nm, ".a", 0)
  88. struct arglist SRCFILES, LDFILES, GEN_LDFILES, PP_FLAGS, CEM_FLAGS,
  89. OPT_FLAGS, DECODE_FLAGS, ENCODE_FLAGS, CG_FLAGS, AS_FLAGS,
  90. O_FLAGS, DEBUG_FLAGS, CALL_VEC;
  91. #ifndef MANTRA
  92. struct arglist LD_FLAGS;
  93. #else MANTRA
  94. struct arglist LD_FLAGS = {
  95. 5,
  96. {
  97. "-b0:0x80000",
  98. "-a0:2",
  99. "-a1:2",
  100. "-a2:2",
  101. "-a3:2"
  102. }
  103. };
  104. struct arglist CV_FLAGS;
  105. int Nc_flag = 0;
  106. #endif MANTRA
  107. /* option naming */
  108. #define NAME(chr) chr
  109. #define FLAG(chr) NAME(chr)_flag
  110. int E_flag, P_flag, S_flag, c_flag, e_flag, k_flag,
  111. m_flag, o_flag, t_flag, v_flag;
  112. /* various passes */
  113. struct prog {
  114. char *p_name;
  115. char **p_task;
  116. struct arglist *p_flags;
  117. } ProgParts[] = {
  118. { "cpp", &PP, &PP_FLAGS },
  119. { "cem", &CEM, &CEM_FLAGS },
  120. { "opt", &OPT, &OPT_FLAGS },
  121. { "decode", &DECODE, &DECODE_FLAGS },
  122. { "encode", &ENCODE, &ENCODE_FLAGS },
  123. { "be", &CG, &CG_FLAGS },
  124. { "cg", &CG, &CG_FLAGS },
  125. { "as", &AS, &AS_FLAGS },
  126. { "ld", &LD, &LD_FLAGS },
  127. #ifdef MANTRA
  128. { "cv", &CV, &CV_FLAGS },
  129. #endif MANTRA
  130. { 0, 0, 0 }
  131. };
  132. /* various forward declarations */
  133. int trap();
  134. char *mkstr();
  135. char *alloc();
  136. long sizeof_file();
  137. /* various globals */
  138. char *ProgCall = 0;
  139. int debug = 0;
  140. int exec = 1;
  141. int RET_CODE = 0;
  142. main(argc, argv)
  143. char *argv[];
  144. {
  145. char *str, **argvec, *file, *ldfile = 0;
  146. int count, ext;
  147. char Nfile[USTR_SIZE], kfile[USTR_SIZE], sfile[USTR_SIZE],
  148. mfile[USTR_SIZE], ofile[USTR_SIZE], BASE[USTR_SIZE];
  149. register struct arglist *call = &CALL_VEC;
  150. set_traps(trap);
  151. ProgCall = *argv++;
  152. append(&CEM_FLAGS, "-L");
  153. while (--argc > 0) {
  154. if (*(str = *argv++) != '-') {
  155. append(&SRCFILES, str);
  156. continue;
  157. }
  158. switch (str[1]) {
  159. case '-':
  160. switch (str[2]) {
  161. case 'C':
  162. case 'E':
  163. case 'P':
  164. FLAG(E) = 1;
  165. append(&PP_FLAGS, str);
  166. PP = CEM;
  167. FLAG(P) = (str[2] == 'P');
  168. break;
  169. default:
  170. append(&DEBUG_FLAGS, str);
  171. break;
  172. }
  173. break;
  174. case 'B':
  175. PP = CEM = &str[2];
  176. break;
  177. case 'C':
  178. case 'E':
  179. case 'P':
  180. FLAG(E) = 1;
  181. append(&PP_FLAGS, str);
  182. FLAG(P) = (str[1] == 'P');
  183. break;
  184. case 'c':
  185. if (str[2] == '.') {
  186. switch (str[3]) {
  187. case 's':
  188. FLAG(S) = 1;
  189. break;
  190. case 'k':
  191. FLAG(k) = 1;
  192. break;
  193. case 'o':
  194. FLAG(c) = 1;
  195. break;
  196. case 'm':
  197. FLAG(m) = 1;
  198. break;
  199. case 'e':
  200. FLAG(e) = 1;
  201. break;
  202. default:
  203. bad_option(str);
  204. }
  205. }
  206. else
  207. if (str[2] == '\0')
  208. FLAG(c) = 1;
  209. else
  210. bad_option(str);
  211. break;
  212. case 'D':
  213. case 'I':
  214. case 'U':
  215. append(&PP_FLAGS, str);
  216. break;
  217. case 'k':
  218. FLAG(k) = 1;
  219. break;
  220. case 'l':
  221. if (str[2] == '\0') /* no standard libraries */
  222. LD_HEAD.al_argc = LD_TAIL.al_argc = 0;
  223. else /* use library from library directory */
  224. append(&SRCFILES, library(&str[2]));
  225. break;
  226. case 'L': /* change default library directory */
  227. LIBDIR = &str[2];
  228. break;
  229. case 'm':
  230. FLAG(m) = 1;
  231. break;
  232. #ifdef MANTRA
  233. case 'N':
  234. switch (str[2]) {
  235. case 'c': /* no a.out conversion */
  236. Nc_flag = 1;
  237. break;
  238. case 'l': /* no default options to led */
  239. LD_FLAGS.al_argc = 0;
  240. break;
  241. default:
  242. bad_option(str);
  243. }
  244. break;
  245. #endif MANTRA
  246. case 'o':
  247. FLAG(o) = 1;
  248. if (argc-- < 0)
  249. bad_option(str);
  250. else
  251. o_FILE = *argv++;
  252. break;
  253. case 'O':
  254. append(&O_FLAGS, "-O");
  255. break;
  256. case 'R':
  257. if (str[2] == '\0')
  258. append(&CEM_FLAGS, str);
  259. else
  260. Roption(str);
  261. break;
  262. case 'S':
  263. FLAG(S) = 1;
  264. break;
  265. case 't':
  266. FLAG(t) = 1;
  267. break;
  268. case 'v': /* set debug switches */
  269. FLAG(v) = 1;
  270. switch (str[2]) {
  271. case 'd':
  272. debug = 1;
  273. break;
  274. case 'n': /* no execute */
  275. exec = 0;
  276. break;
  277. case '\0':
  278. break;
  279. default:
  280. bad_option(str);
  281. }
  282. break;
  283. case 'V':
  284. V_FLAG = str;
  285. break;
  286. default:
  287. append(&LD_FLAGS, str);
  288. }
  289. }
  290. if (debug) report("Note: debug output");
  291. if (exec == 0)
  292. report("Note: no execution");
  293. count = SRCFILES.al_argc;
  294. argvec = &(SRCFILES.al_argv[0]);
  295. Nfile[0] = '\0';
  296. while (count-- > 0) {
  297. basename(file = *argvec++, BASE);
  298. if (FLAG(E)) {
  299. char ifile[USTR_SIZE];
  300. init(call);
  301. append(call, PP);
  302. concat(call, &DEBUG_FLAGS);
  303. concat(call, &PP_FLAGS);
  304. append(call, file);
  305. runvec(call, FLAG(P) ? mkname(ifile, BASE, ".i") : 0);
  306. continue;
  307. }
  308. ext = extension(file);
  309. /* .c to .k and .N */
  310. if (ext == 'c' || ext == 'i') {
  311. init(call);
  312. append(call, CEM);
  313. concat(call, &DEBUG_FLAGS);
  314. append(call, V_FLAG);
  315. concat(call, &CEM_FLAGS);
  316. concat(call, &PP_FLAGS);
  317. append(call, file);
  318. append(call, mkname(kfile, BASE, ".k"));
  319. append(call, mkname(Nfile, BASE, ".N"));
  320. if (runvec(call, (char *)0)) {
  321. file = kfile;
  322. ext = 'k';
  323. if (sizeof_file(Nfile) <= 0L)
  324. remove(Nfile);
  325. }
  326. else {
  327. remove(kfile);
  328. remove(Nfile);
  329. continue;
  330. }
  331. }
  332. /* .e to .k */
  333. if (ext == 'e') {
  334. init(call);
  335. append(call, ENCODE);
  336. concat(call, &ENCODE_FLAGS);
  337. append(call, file);
  338. append(call, mkname(kfile, BASE, ".k"));
  339. if (runvec(call, (char *)0) == 0)
  340. continue;
  341. file = kfile;
  342. ext = 'k';
  343. }
  344. if (FLAG(k))
  345. continue;
  346. /* decode .k or .m */
  347. if (FLAG(e) && (ext == 'k' || ext == 'm')) {
  348. char efile[USTR_SIZE];
  349. init(call);
  350. append(call, DECODE);
  351. concat(call, &DECODE_FLAGS);
  352. append(call, file);
  353. append(call, mkname(efile, BASE, ".e"));
  354. runvec(call, (char *)0);
  355. cleanup(kfile);
  356. continue;
  357. }
  358. /* .k to .m */
  359. if (ext == 'k') {
  360. init(call);
  361. append(call, OPT);
  362. concat(call, &OPT_FLAGS);
  363. append(call, file);
  364. if (runvec(call, mkname(mfile, BASE, ".m")) == 0)
  365. continue;
  366. file = mfile;
  367. ext = 'm';
  368. cleanup(kfile);
  369. }
  370. if (FLAG(m))
  371. continue;
  372. /* .m to .s */
  373. if (ext == 'm') {
  374. init(call);
  375. append(call, CG);
  376. concat(call, &CG_FLAGS);
  377. append(call, file);
  378. append(call, mkname(sfile, BASE, ".s"));
  379. if (runvec(call, (char *)0) == 0)
  380. continue;
  381. if (Nfile[0] != '\0') {
  382. #ifndef MANTRA
  383. init(call);
  384. append(call, AS_FIX);
  385. append(call, Nfile);
  386. append(call, sfile);
  387. runvec(call, (char *)0);
  388. #endif MANTRA
  389. remove(Nfile);
  390. }
  391. cleanup(mfile);
  392. file = sfile;
  393. ext = 's';
  394. }
  395. if (FLAG(S))
  396. continue;
  397. /* .s to .o */
  398. if (ext == 's') {
  399. ldfile = FLAG(c) ?
  400. ofile :
  401. alloc((unsigned)strlen(BASE) + 3);
  402. init(call);
  403. append(call, AS);
  404. concat(call, &AS_FLAGS);
  405. #ifdef MANTRA
  406. append(call, "-");
  407. #endif MANTRA
  408. append(call, "-o");
  409. append(call, mkname(ldfile, BASE, ".o"));
  410. append(call, file);
  411. if (runvec(call, (char *)0) == 0)
  412. continue;
  413. file = ldfile;
  414. ext = 'o';
  415. cleanup(sfile);
  416. }
  417. if (FLAG(c))
  418. continue;
  419. append(&LDFILES, file);
  420. if (ldfile) {
  421. append(&GEN_LDFILES, ldfile);
  422. ldfile = 0;
  423. }
  424. }
  425. /* *.o to a.out */
  426. if (RET_CODE == 0 && LDFILES.al_argc > 0) {
  427. init(call);
  428. append(call, LD);
  429. concat(call, &LD_FLAGS);
  430. append(call, "-o");
  431. #ifndef MANTRA
  432. append(call, o_FILE);
  433. #else MANTRA
  434. append(call, Nc_flag ? o_FILE : cv_FILE);
  435. #endif MANTRA
  436. concat(call, &LD_HEAD);
  437. concat(call, &LDFILES);
  438. concat(call, &LD_TAIL);
  439. if (runvec(call, (char *)0)) {
  440. register i = GEN_LDFILES.al_argc;
  441. while (i-- > 0)
  442. remove(GEN_LDFILES.al_argv[i]);
  443. #ifdef MANTRA
  444. /* convert to local a.out format */
  445. if (Nc_flag == 0) {
  446. init(call);
  447. append(call, CV);
  448. concat(call, &CV_FLAGS);
  449. append(call, cv_FILE);
  450. append(call, o_FILE);
  451. if (runvec(call, (char *)0))
  452. remove(cv_FILE);
  453. }
  454. #endif MANTRA
  455. }
  456. }
  457. exit(RET_CODE);
  458. }
  459. #define BUFSIZE (USTR_SIZE * MAXARGC)
  460. char alloc_buf[BUFSIZE];
  461. char *
  462. alloc(u)
  463. unsigned u;
  464. {
  465. static char *bufptr = &alloc_buf[0];
  466. register char *p = bufptr;
  467. if ((bufptr += u) >= &alloc_buf[BUFSIZE])
  468. panic("no space");
  469. return p;
  470. }
  471. append(al, arg)
  472. register struct arglist *al;
  473. char *arg;
  474. {
  475. if (al->al_argc >= MAXARGC)
  476. panic("argument list overflow");
  477. al->al_argv[(al->al_argc)++] = arg;
  478. }
  479. concat(al1, al2)
  480. struct arglist *al1, *al2;
  481. {
  482. register int i = al2->al_argc;
  483. register char **p = &(al1->al_argv[al1->al_argc]);
  484. register char **q = &(al2->al_argv[0]);
  485. if ((al1->al_argc += i) >= MAXARGC)
  486. panic("argument list overflow");
  487. while (i-- > 0)
  488. *p++ = *q++;
  489. }
  490. /* The next function is a dirty old one, taking a variable number of
  491. arguments.
  492. Take care that the last argument is a null-valued pointer!
  493. */
  494. /*VARARGS1*/
  495. char *
  496. mkstr(dst, arg)
  497. char *dst, *arg;
  498. {
  499. char **vec = (char **) &arg;
  500. register char *p;
  501. register char *q = dst;
  502. while (p = *vec++) {
  503. while (*q++ = *p++);
  504. q--;
  505. }
  506. return dst;
  507. }
  508. Roption(str)
  509. char *str; /* of the form "prog=/-arg" */
  510. {
  511. char *eq;
  512. char *prog, *arg;
  513. char bc;
  514. char *cindex();
  515. prog = &str[2];
  516. if (eq = cindex(prog, '='))
  517. bc = '=';
  518. else
  519. if (eq = cindex(prog, '-'))
  520. bc = '-';
  521. else {
  522. bad_option(str);
  523. return;
  524. }
  525. *eq++ = '\0';
  526. if (arg = eq) {
  527. char *opt = 0;
  528. struct prog *pp = &ProgParts[0];
  529. if (bc == '-')
  530. opt = mkstr(alloc((unsigned)strlen(arg) + 2),
  531. "-", arg, 0);
  532. while (pp->p_name) {
  533. if (strcmp(prog, pp->p_name) == 0) {
  534. if (opt)
  535. append(pp->p_flags, opt);
  536. else
  537. *(pp->p_task) = arg;
  538. return;
  539. }
  540. pp++;
  541. }
  542. }
  543. bad_option(str);
  544. }
  545. basename(str, dst)
  546. char *str;
  547. register char *dst;
  548. {
  549. register char *p1 = str;
  550. register char *p2 = p1;
  551. while (*p1)
  552. if (*p1++ == '/')
  553. p2 = p1;
  554. p1--;
  555. if (*--p1 == '.') {
  556. *p1 = '\0';
  557. while (*dst++ = *p2++) {}
  558. *p1 = '.';
  559. }
  560. else
  561. while (*dst++ = *p2++) {}
  562. }
  563. int
  564. extension(fn)
  565. register char *fn;
  566. {
  567. char c;
  568. while (*fn++) {}
  569. fn--;
  570. c = *--fn;
  571. return (*--fn == '.') ? c : 0;
  572. }
  573. long
  574. sizeof_file(nm)
  575. char *nm;
  576. {
  577. struct stat stbuf;
  578. if (stat(nm, &stbuf) == 0)
  579. return stbuf.st_size;
  580. return -1;
  581. }
  582. char * sysmsg[] = {
  583. 0,
  584. "Hangup",
  585. "Interrupt",
  586. "Quit",
  587. "Illegal instruction",
  588. "Trace/BPT trap",
  589. "IOT trap",
  590. "EMT trap",
  591. "Floating exception",
  592. "Killed",
  593. "Bus error",
  594. "Memory fault",
  595. "Bad system call",
  596. "Broken pipe",
  597. "Alarm call",
  598. "Terminated",
  599. "Signal 16"
  600. };
  601. runvec(vec, outp)
  602. struct arglist *vec;
  603. char *outp;
  604. {
  605. int status, fd;
  606. char *task = vec->al_argv[1];
  607. vec->al_argv[vec->al_argc] = 0;
  608. if (FLAG(v))
  609. print_vec(vec);
  610. if (exec == 0)
  611. return 1;
  612. if (fork() == 0) { /* start up the process */
  613. extern int errno;
  614. if (outp) { /* redirect standard output */
  615. close(1);
  616. if ((fd = creat(outp, 0666)) < 0)
  617. panic("cannot create %s", outp);
  618. if (fd != 1)
  619. panic("illegal redirection");
  620. }
  621. if (debug) report("exec %s", task);
  622. execv(task, &(vec->al_argv[1]));
  623. /* not an a.out file, let's try it with the SHELL */
  624. if (debug) report("try it with %s", SHELL);
  625. if (errno == ENOEXEC) {
  626. vec->al_argv[0] = SHELL;
  627. execv(SHELL, &(vec->al_argv[0]));
  628. }
  629. /* failed, so ... */
  630. panic("cannot execute %s", task);
  631. exit(1);
  632. }
  633. else {
  634. int loworder, highorder, sig;
  635. wait(&status);
  636. loworder = status & 0377;
  637. highorder = (status >> 8) & 0377;
  638. if (loworder == 0) {
  639. if (highorder)
  640. report("%s: exit status %d", task, highorder);
  641. return highorder ? ((RET_CODE = 1), 0) : 1;
  642. }
  643. else {
  644. sig = loworder & 0177;
  645. if (sig == 0177)
  646. report("%s: stopped by ptrace", task);
  647. else
  648. if (sysmsg[sig])
  649. report("%s: %s%s", task, sysmsg[sig],
  650. (loworder & 0200)
  651. ? " - core dumped"
  652. : "");
  653. RET_CODE = 1;
  654. return 0;
  655. }
  656. }
  657. /*NOTREACHED*/
  658. }
  659. bad_option(str)
  660. char *str;
  661. {
  662. report("bad option %s", str);
  663. }
  664. /*VARARGS1*/
  665. report(fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
  666. char *fmt;
  667. {
  668. fprintf(stderr, "%s: ", ProgCall);
  669. fprintf(stderr, fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
  670. fprintf(stderr, "\n");
  671. }
  672. /*VARARGS1*/
  673. panic(fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
  674. char *fmt;
  675. {
  676. fprintf(stderr, "%s: ", ProgCall);
  677. fprintf(stderr, fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
  678. fprintf(stderr, "\n");
  679. exit(1);
  680. }
  681. set_traps(f)
  682. int (*f)();
  683. {
  684. signal(SIGHUP, f);
  685. signal(SIGINT, f);
  686. signal(SIGQUIT, f);
  687. signal(SIGALRM, f);
  688. signal(SIGTERM, f);
  689. }
  690. /*ARGSUSED*/
  691. trap(sig)
  692. {
  693. set_traps(SIG_IGN);
  694. panic("Trapped");
  695. }
  696. print_vec(vec)
  697. struct arglist *vec;
  698. {
  699. register i;
  700. for (i = 1; i < vec->al_argc; i++)
  701. printf("%s ", vec->al_argv[i]);
  702. printf("\n");
  703. }
  704. char *
  705. cindex(s, c)
  706. char *s, c;
  707. {
  708. while (*s)
  709. if (*s++ == c)
  710. return s - 1;
  711. return (char *) 0;
  712. }