t3.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* t3.c: interpret commands affecting whole table */
  2. # include "t.h"
  3. struct optstr {
  4. char *optnam;
  5. int *optadd;
  6. } options [] = {
  7. "expand", &expflg,
  8. "EXPAND", &expflg,
  9. "center", &ctrflg,
  10. "CENTER", &ctrflg,
  11. "box", &boxflg,
  12. "BOX", &boxflg,
  13. "allbox", &allflg,
  14. "ALLBOX", &allflg,
  15. "doublebox", &dboxflg,
  16. "DOUBLEBOX", &dboxflg,
  17. "frame", &boxflg,
  18. "FRAME", &boxflg,
  19. "doubleframe", &dboxflg,
  20. "DOUBLEFRAME", &dboxflg,
  21. "tab", &tab,
  22. "TAB", &tab,
  23. "linesize", &linsize,
  24. "LINESIZE", &linsize,
  25. "delim", &delim1,
  26. "DELIM", &delim1,
  27. 0, 0};
  28. void
  29. getcomm(void)
  30. {
  31. char line[200], *cp, nb[25], *t;
  32. struct optstr *lp;
  33. int c, ci, found;
  34. for (lp = options; lp->optnam; lp++)
  35. *(lp->optadd) = 0;
  36. texname = texstr[texct=0];
  37. tab = '\t';
  38. Bprint(&tabout, ".nr %d \\n(.s\n", LSIZE);
  39. gets1(line, sizeof(line));
  40. /* see if this is a command line */
  41. if (strchr(line, ';') == 0) {
  42. backrest(line);
  43. return;
  44. }
  45. for (cp = line; (c = *cp) != ';'; cp++) {
  46. if (!letter(c))
  47. continue;
  48. found = 0;
  49. for (lp = options; lp->optadd; lp++) {
  50. if (prefix(lp->optnam, cp)) {
  51. *(lp->optadd) = 1;
  52. cp += strlen(lp->optnam);
  53. if (letter(*cp))
  54. error("Misspelled global option");
  55. while (*cp == ' ')
  56. cp++;
  57. t = nb;
  58. if ( *cp == '(')
  59. while ((ci = *++cp) != ')')
  60. *t++ = ci;
  61. else
  62. cp--;
  63. *t++ = 0;
  64. *t = 0;
  65. if (lp->optadd == &tab) {
  66. if (nb[0])
  67. *(lp->optadd) = nb[0];
  68. }
  69. if (lp->optadd == &linsize)
  70. Bprint(&tabout, ".nr %d %s\n", LSIZE, nb);
  71. if (lp->optadd == &delim1) {
  72. delim1 = nb[0];
  73. delim2 = nb[1];
  74. }
  75. found = 1;
  76. break;
  77. }
  78. }
  79. if (!found)
  80. error("Illegal option");
  81. }
  82. cp++;
  83. backrest(cp);
  84. return;
  85. }
  86. void
  87. backrest(char *cp)
  88. {
  89. char *s;
  90. for (s = cp; *s; s++)
  91. ;
  92. un1getc('\n');
  93. while (s > cp)
  94. un1getc(*--s);
  95. return;
  96. }