t1.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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) {
  38. if(swapin() == 0)
  39. error("flags but no input files");
  40. } else {
  41. tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
  42. Binit(tabin, 0, OREAD);
  43. }
  44. }
  45. int
  46. swapin(void)
  47. {
  48. char *name;
  49. while (sargc > 0 && **sargv == '-') {
  50. if (match("-ms", *sargv)) {
  51. *sargv = MACROS;
  52. break;
  53. }
  54. if (match("-mm", *sargv)) {
  55. *sargv = PYMACS;
  56. break;
  57. }
  58. if (match("-TX", *sargv))
  59. pr1403 = 1;
  60. if (match("-", *sargv))
  61. break;
  62. sargc--;
  63. sargv++;
  64. }
  65. if (sargc <= 0)
  66. return(0);
  67. /* file closing is done by GCOS troff preprocessor */
  68. if(tabin)
  69. Bterm(tabin);
  70. ifile = *sargv;
  71. name = ifile;
  72. if (match(ifile, "-")) {
  73. tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
  74. Binit(tabin, 0, OREAD);
  75. } else
  76. tabin = Bopen(ifile, OREAD);
  77. iline = 1;
  78. Bprint(&tabout, ".ds f. %s\n", ifile);
  79. Bprint(&tabout, ".lf %d %s\n", iline, name);
  80. if (tabin == 0)
  81. error("Can't open file");
  82. sargc--;
  83. sargv++;
  84. return(1);
  85. }