readDESC.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <ctype.h>
  5. #include "common.h"
  6. #include "tr2post.h"
  7. #include "comments.h"
  8. #include "path.h"
  9. char *printdesclang = 0;
  10. char *encoding = 0;
  11. int devres;
  12. int unitwidth;
  13. int nspechars = 0;
  14. struct charent spechars[MAXSPECHARS];
  15. #define NDESCTOKS 9
  16. static char *desctoks[NDESCTOKS] = {
  17. "PDL",
  18. "Encoding",
  19. "fonts",
  20. "sizes",
  21. "res",
  22. "hor",
  23. "vert",
  24. "unitwidth",
  25. "charset"
  26. };
  27. char *spechar[MAXSPECHARS];
  28. int
  29. hash(char *s, int l) {
  30. unsigned i;
  31. for (i=0; *s; s++)
  32. i = i*10 + *s;
  33. return(i % l);
  34. }
  35. BOOLEAN
  36. readDESC(void) {
  37. char token[MAXTOKENSIZE];
  38. char *descnameformat = "%s/dev%s/DESC";
  39. char *descfilename = 0;
  40. Biobuf *bfd;
  41. Biobufhdr *Bfd;
  42. int i, state = -1;
  43. int fontindex = 0;
  44. if (debug) Bprint(Bstderr, "readDESC()\n");
  45. descfilename = galloc(descfilename, strlen(descnameformat)+strlen(FONTDIR)
  46. +strlen(devname), "readdesc");
  47. sprint(descfilename, descnameformat, FONTDIR, devname);
  48. if ((bfd = Bopen(descfilename, OREAD)) == 0) {
  49. error(WARNING, "cannot open file %s\n", descfilename);
  50. return(0);
  51. }
  52. Bfd = &(bfd->Biobufhdr);
  53. while (Bgetfield(Bfd, 's', token, MAXTOKENSIZE) > 0) {
  54. for (i=0; i<NDESCTOKS; i++) {
  55. if (strcmp(desctoks[i], token) == 0) {
  56. state = i;
  57. break;
  58. }
  59. }
  60. if (i<NDESCTOKS) continue;
  61. switch (state) {
  62. case 0:
  63. printdesclang=galloc(printdesclang, strlen(token)+1, "readdesc:");
  64. strcpy(printdesclang, token);
  65. if (debug) Bprint(Bstderr, "PDL %s\n", token);
  66. break;
  67. case 1:
  68. encoding=galloc(encoding, strlen(token)+1, "readdesc:");
  69. strcpy(encoding, token);
  70. if (debug) Bprint(Bstderr, "encoding %s\n", token);
  71. break;
  72. case 2:
  73. if (fontmnt <=0) {
  74. if (!isdigit(*token)) {
  75. error(WARNING, "readdesc: expecting number of fonts in mount table.\n");
  76. return(FALSE);
  77. }
  78. fontmnt = atoi(token) + 1;
  79. fontmtab = galloc(fontmtab, fontmnt*sizeof(char *), "readdesc:");
  80. for (i=0; i<fontmnt; i++)
  81. fontmtab[i] = 0;
  82. fontindex = 0;
  83. } else {
  84. mountfont(++fontindex, token);
  85. findtfn(token, TRUE);
  86. }
  87. break;
  88. case 3:
  89. /* I don't really care about sizes */
  90. break;
  91. case 4:
  92. /* device resolution in dots per inch */
  93. if (!isdigit(*token)) {
  94. error(WARNING, "readdesc: expecting device resolution.\n");
  95. return(FALSE);
  96. }
  97. devres = atoi(token);
  98. if (debug) Bprint(Bstderr, "res %d\n", devres);
  99. break;
  100. case 5:
  101. /* I don't really care about horizontal motion resolution */
  102. if (debug) Bprint(Bstderr, "ignoring horizontal resolution\n");
  103. break;
  104. case 6:
  105. /* I don't really care about vertical motion resolution */
  106. if (debug) Bprint(Bstderr, "ignoring vertical resolution\n");
  107. break;
  108. case 7:
  109. /* unitwidth is the font size at which the character widths are 1:1 */
  110. if (!isdigit(*token)) {
  111. error(WARNING, "readdesc: expecting unitwidth.\n");
  112. return(FALSE);
  113. }
  114. unitwidth = atoi(token);
  115. if (debug) Bprint(Bstderr, "unitwidth %d\n", unitwidth);
  116. break;
  117. case 8:
  118. /* I don't really care about this list of special characters */
  119. if (debug) Bprint(Bstderr, "ignoring special character <%s>\n", token);
  120. break;
  121. default:
  122. if (*token == '#')
  123. Brdline(Bfd, '\n');
  124. else
  125. error(WARNING, "unknown token %s in DESC file.\n", token);
  126. break;
  127. }
  128. }
  129. Bterm(Bfd);
  130. }