cem.c 14 KB

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