41#endif /* not lint */ 42#endif 43 44/* 45 * Here we have the token scanner for indent. It scans off one token and puts 46 * it in the global variable "token". It returns a code, indicating the type 47 * of token scanned. 48 */ 49 50#include <stdio.h> 51#include <ctype.h> 52#include <stdlib.h> 53#include <string.h> 54#include "indent_globs.h" 55#include "indent_codes.h" 56#include "indent.h" 57 58#define alphanum 1 59#define opchar 3 60 61void fill_buffer(void); 62 63struct templ { 64 const char *rwd; 65 int rwcode; 66}; 67 68struct templ specials[1000] = 69{ 70 {"switch", 1}, 71 {"case", 2}, 72 {"break", 0}, 73 {"struct", 3}, 74 {"union", 3}, 75 {"enum", 3}, 76 {"default", 2}, 77 {"int", 4}, 78 {"char", 4}, 79 {"float", 4}, 80 {"double", 4}, 81 {"long", 4}, 82 {"short", 4}, 83 {"typdef", 4}, 84 {"unsigned", 4}, 85 {"register", 4}, 86 {"static", 4}, 87 {"global", 4}, 88 {"extern", 4}, 89 {"void", 4}, 90 {"goto", 0}, 91 {"return", 0}, 92 {"if", 5}, 93 {"while", 5}, 94 {"for", 5}, 95 {"else", 6}, 96 {"do", 6}, 97 {"sizeof", 7}, 98 {"const", 9}, 99 {"volatile", 9}, 100 {0, 0} 101}; 102 103char chartype[128] = 104{ /* this is used to facilitate the decision of 105 * what type (alphanumeric, operator) each 106 * character is */ 107 0, 0, 0, 0, 0, 0, 0, 0, 108 0, 0, 0, 0, 0, 0, 0, 0, 109 0, 0, 0, 0, 0, 0, 0, 0, 110 0, 0, 0, 0, 0, 0, 0, 0, 111 0, 3, 0, 0, 1, 3, 3, 0, 112 0, 0, 3, 3, 0, 3, 0, 3, 113 1, 1, 1, 1, 1, 1, 1, 1, 114 1, 1, 0, 0, 3, 3, 3, 3, 115 0, 1, 1, 1, 1, 1, 1, 1, 116 1, 1, 1, 1, 1, 1, 1, 1, 117 1, 1, 1, 1, 1, 1, 1, 1, 118 1, 1, 1, 0, 0, 0, 3, 1, 119 0, 1, 1, 1, 1, 1, 1, 1, 120 1, 1, 1, 1, 1, 1, 1, 1, 121 1, 1, 1, 1, 1, 1, 1, 1, 122 1, 1, 1, 0, 3, 0, 3, 0 123}; 124 125int 126lexi(void) 127{ 128 int unary_delim; /* this is set to 1 if the current token 129 * forces a following operator to be unary */ 130 static int last_code; /* the last token type returned */ 131 static int l_struct; /* set to 1 if the last token was 'struct' */ 132 int code; /* internal code to be returned */ 133 char qchar; /* the delimiter character for a string */ 134 135 e_token = s_token; /* point to start of place to save token */ 136 unary_delim = false; 137 ps.col_1 = ps.last_nl; /* tell world that this token started in 138 * column 1 iff the last thing scanned was nl */ 139 ps.last_nl = false; 140 141 while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */ 142 ps.col_1 = false; /* leading blanks imply token is not in column 143 * 1 */ 144 if (++buf_ptr >= buf_end) 145 fill_buffer(); 146 } 147 148 /* Scan an alphanumeric token */ 149 if (chartype[(int)*buf_ptr] == alphanum || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { 150 /* 151 * we have a character or number 152 */ 153 const char *j; /* used for searching thru list of 154 * 155 * reserved words */
| 41#endif /* not lint */ 42#endif 43 44/* 45 * Here we have the token scanner for indent. It scans off one token and puts 46 * it in the global variable "token". It returns a code, indicating the type 47 * of token scanned. 48 */ 49 50#include <stdio.h> 51#include <ctype.h> 52#include <stdlib.h> 53#include <string.h> 54#include "indent_globs.h" 55#include "indent_codes.h" 56#include "indent.h" 57 58#define alphanum 1 59#define opchar 3 60 61void fill_buffer(void); 62 63struct templ { 64 const char *rwd; 65 int rwcode; 66}; 67 68struct templ specials[1000] = 69{ 70 {"switch", 1}, 71 {"case", 2}, 72 {"break", 0}, 73 {"struct", 3}, 74 {"union", 3}, 75 {"enum", 3}, 76 {"default", 2}, 77 {"int", 4}, 78 {"char", 4}, 79 {"float", 4}, 80 {"double", 4}, 81 {"long", 4}, 82 {"short", 4}, 83 {"typdef", 4}, 84 {"unsigned", 4}, 85 {"register", 4}, 86 {"static", 4}, 87 {"global", 4}, 88 {"extern", 4}, 89 {"void", 4}, 90 {"goto", 0}, 91 {"return", 0}, 92 {"if", 5}, 93 {"while", 5}, 94 {"for", 5}, 95 {"else", 6}, 96 {"do", 6}, 97 {"sizeof", 7}, 98 {"const", 9}, 99 {"volatile", 9}, 100 {0, 0} 101}; 102 103char chartype[128] = 104{ /* this is used to facilitate the decision of 105 * what type (alphanumeric, operator) each 106 * character is */ 107 0, 0, 0, 0, 0, 0, 0, 0, 108 0, 0, 0, 0, 0, 0, 0, 0, 109 0, 0, 0, 0, 0, 0, 0, 0, 110 0, 0, 0, 0, 0, 0, 0, 0, 111 0, 3, 0, 0, 1, 3, 3, 0, 112 0, 0, 3, 3, 0, 3, 0, 3, 113 1, 1, 1, 1, 1, 1, 1, 1, 114 1, 1, 0, 0, 3, 3, 3, 3, 115 0, 1, 1, 1, 1, 1, 1, 1, 116 1, 1, 1, 1, 1, 1, 1, 1, 117 1, 1, 1, 1, 1, 1, 1, 1, 118 1, 1, 1, 0, 0, 0, 3, 1, 119 0, 1, 1, 1, 1, 1, 1, 1, 120 1, 1, 1, 1, 1, 1, 1, 1, 121 1, 1, 1, 1, 1, 1, 1, 1, 122 1, 1, 1, 0, 3, 0, 3, 0 123}; 124 125int 126lexi(void) 127{ 128 int unary_delim; /* this is set to 1 if the current token 129 * forces a following operator to be unary */ 130 static int last_code; /* the last token type returned */ 131 static int l_struct; /* set to 1 if the last token was 'struct' */ 132 int code; /* internal code to be returned */ 133 char qchar; /* the delimiter character for a string */ 134 135 e_token = s_token; /* point to start of place to save token */ 136 unary_delim = false; 137 ps.col_1 = ps.last_nl; /* tell world that this token started in 138 * column 1 iff the last thing scanned was nl */ 139 ps.last_nl = false; 140 141 while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */ 142 ps.col_1 = false; /* leading blanks imply token is not in column 143 * 1 */ 144 if (++buf_ptr >= buf_end) 145 fill_buffer(); 146 } 147 148 /* Scan an alphanumeric token */ 149 if (chartype[(int)*buf_ptr] == alphanum || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { 150 /* 151 * we have a character or number 152 */ 153 const char *j; /* used for searching thru list of 154 * 155 * reserved words */
|