t3.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. };
  29. void
  30. getcomm(void)
  31. {
  32. char line[200], *cp, nb[25], *t;
  33. struct optstr *lp;
  34. int c, ci, found;
  35. for (lp = options; lp->optnam; lp++)
  36. *(lp->optadd) = 0;
  37. texname = texstr[texct=0];
  38. tab = '\t';
  39. Bprint(&tabout, ".nr %d \\n(.s\n", LSIZE);
  40. gets1(line, sizeof(line));
  41. /* see if this is a command line */
  42. if (strchr(line, ';') == 0) {
  43. backrest(line);
  44. return;
  45. }
  46. for (cp = line; (c = *cp) != ';'; cp++) {
  47. if (!letter(c))
  48. continue;
  49. found = 0;
  50. for (lp = options; lp->optadd; lp++) {
  51. if (prefix(lp->optnam, cp)) {
  52. *(lp->optadd) = 1;
  53. cp += strlen(lp->optnam);
  54. if (letter(*cp))
  55. error("Misspelled global option");
  56. while (*cp == ' ')
  57. cp++;
  58. t = nb;
  59. if ( *cp == '(')
  60. while ((ci = *++cp) != ')')
  61. *t++ = ci;
  62. else
  63. cp--;
  64. *t++ = 0;
  65. *t = 0;
  66. if (lp->optadd == &tab) {
  67. if (nb[0])
  68. *(lp->optadd) = nb[0];
  69. }
  70. if (lp->optadd == &linsize)
  71. Bprint(&tabout, ".nr %d %s\n", LSIZE, nb);
  72. if (lp->optadd == &delim1) {
  73. delim1 = nb[0];
  74. delim2 = nb[1];
  75. }
  76. found = 1;
  77. break;
  78. }
  79. }
  80. if (!found)
  81. error("Illegal option");
  82. }
  83. cp++;
  84. backrest(cp);
  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. }