options.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* U S E R O P T I O N - H A N D L I N G */
  2. #include <em_arith.h>
  3. #include <em_label.h>
  4. #include "class.h"
  5. #include "const.h"
  6. #include "idfsize.h"
  7. #include "main.h"
  8. #include "type.h"
  9. #include "nocross.h"
  10. #include "dbsymtab.h"
  11. #define MINIDFSIZE 9
  12. #if MINIDFSIZE < 9
  13. You fouled up! MINIDFSIZE has to be at least 10 or the compiler will not
  14. recognize some keywords!
  15. #endif
  16. extern int idfsize;
  17. DoOption(text)
  18. register char *text;
  19. {
  20. switch( *text++ ) {
  21. default:
  22. options[text[-1]]++; /* flags, debug options etc. */
  23. break;
  24. /* recognized flags:
  25. -i: largest value of set of integer
  26. -u, -U: allow underscore in identifier
  27. -w: no warnings
  28. -R: no range checks
  29. -A: range checks for array references
  30. and many more if DEBUG
  31. */
  32. #ifdef DBSYMTAB
  33. case 'g':
  34. options['g'] = 1;
  35. options['n'] = 1;
  36. break;
  37. #endif
  38. case 'i': { /* largest value of set of integer */
  39. char *t = text;
  40. max_intset = txt2int(&t);
  41. text = t;
  42. if( max_intset <= (arith) 0 || *t ) {
  43. error("bad -i flag : use -i<num>");
  44. max_intset = 0;
  45. }
  46. break;
  47. }
  48. case 'M': { /* maximum identifier length */
  49. char *t = text;
  50. idfsize = txt2int(&t);
  51. text = t;
  52. if( idfsize <= 0 || *t ) {
  53. fatal("malformed -M option");
  54. /*NOTREACHED*/
  55. }
  56. if( idfsize > IDFSIZE ) {
  57. idfsize = IDFSIZE;
  58. warning("maximum identifier length is %d", IDFSIZE);
  59. }
  60. if( idfsize < MINIDFSIZE ) {
  61. idfsize = MINIDFSIZE;
  62. warning("minimum identifier length is %d", MINIDFSIZE);
  63. }
  64. break;
  65. }
  66. /* case 'u': /* underscore allowed in identifiers */
  67. /* class('_') = STIDF;
  68. /* inidf['_'] = 1;
  69. /* break;
  70. */
  71. case 'V' : { /* set object sizes and alignment requirements */
  72. /* syntax : -V[ [w|i|l|f|p] size? [.alignment]? ]* */
  73. #ifndef NOCROSS
  74. register arith size;
  75. register int align;
  76. char c, *t;
  77. while( c = *text++ ) {
  78. char *strchr();
  79. t = text;
  80. size = txt2int(&t);
  81. align = 0;
  82. if( *(text = t) == '.' ) {
  83. t = text + 1;
  84. align = txt2int(&t);
  85. text = t;
  86. }
  87. if( !strchr("wilfpS", c) )
  88. error("-V: bad type indicator %c\n", c);
  89. if( size )
  90. switch( c ) {
  91. case 'w': /* word */
  92. word_size = size;
  93. break;
  94. case 'i': /* int */
  95. int_size = size;
  96. break;
  97. case 'l': /* long */
  98. long_size = size;
  99. break;
  100. case 'f': /* real */
  101. real_size = size;
  102. break;
  103. case 'p': /* pointer */
  104. pointer_size = size;
  105. break;
  106. case 'S': /* structure */
  107. /* discard size */
  108. break;
  109. }
  110. if( align )
  111. switch( c ) {
  112. case 'w': /* word */
  113. word_align = align;
  114. break;
  115. case 'i': /* int */
  116. int_align = align;
  117. break;
  118. case 'l': /* long */
  119. long_align = align;
  120. break;
  121. case 'f': /* real */
  122. real_align = align;
  123. break;
  124. case 'p': /* pointer */
  125. pointer_align = align;
  126. break;
  127. case 'S': /* initial record alignment */
  128. struct_align = align;
  129. break;
  130. }
  131. }
  132. break;
  133. #endif /* NOCROSS */
  134. }
  135. }
  136. }
  137. int
  138. txt2int(tp)
  139. register char **tp;
  140. {
  141. /* the integer pointed to by *tp is read, while increasing
  142. *tp; the resulting value is yielded.
  143. */
  144. register int val = 0;
  145. register int ch;
  146. while( ch = **tp, ch >= '0' && ch <= '9' ) {
  147. val = val * 10 + ch - '0';
  148. (*tp)++;
  149. }
  150. return val;
  151. }