t1.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* t1.c: main control and input switching */
  2. #
  3. # include "t.h"
  4. # define MACROS "/sys/lib/tmac/tmac.s"
  5. # define PYMACS "/sys/lib/tmac/tmac.m"
  6. # define ever (;;)
  7. void
  8. main(int argc, char *argv[])
  9. {
  10. exits(tbl(argc, argv)? "error" : 0);
  11. }
  12. int
  13. tbl(int argc, char *argv[])
  14. {
  15. char line[5120];
  16. /*int x;*/
  17. /*x=malloc((char *)0); uncomment when allocation breaks*/
  18. Binit(&tabout, 1, OWRITE);
  19. setinp(argc, argv);
  20. while (gets1(line, sizeof(line))) {
  21. Bprint(&tabout, "%s\n", line);
  22. if (prefix(".TS", line))
  23. tableput();
  24. }
  25. Bterm(tabin);
  26. return(0);
  27. }
  28. int sargc;
  29. char **sargv;
  30. void
  31. setinp(int argc, char **argv)
  32. {
  33. sargc = argc;
  34. sargv = argv;
  35. sargc--;
  36. sargv++;
  37. if (sargc == 0 || swapin() == 0) {
  38. tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
  39. Binit(tabin, 0, OREAD);
  40. }
  41. }
  42. int
  43. swapin(void)
  44. {
  45. char *name;
  46. while (sargc > 0 && **sargv == '-') {
  47. if (match("-ms", *sargv)) {
  48. *sargv = MACROS;
  49. break;
  50. }
  51. if (match("-mm", *sargv)) {
  52. *sargv = PYMACS;
  53. break;
  54. }
  55. if (match("-TX", *sargv))
  56. pr1403 = 1;
  57. if (match("-", *sargv))
  58. break;
  59. sargc--;
  60. sargv++;
  61. }
  62. if (sargc <= 0)
  63. return(0);
  64. /* file closing is done by GCOS troff preprocessor */
  65. if(tabin)
  66. Bterm(tabin);
  67. ifile = *sargv;
  68. name = ifile;
  69. if (match(ifile, "-")) {
  70. tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
  71. Binit(tabin, 0, OREAD);
  72. } else
  73. tabin = Bopen(ifile, OREAD);
  74. iline = 1;
  75. Bprint(&tabout, ".ds f. %s\n", ifile);
  76. Bprint(&tabout, ".lf %d %s\n", iline, name);
  77. if (tabin == 0)
  78. error("Can't open file");
  79. sargc--;
  80. sargv++;
  81. return(1);
  82. }