| 1 |
|
| 2 |
%{ |
| 3 |
#include "pscan.h" |
| 4 |
static void skip_strings(char literal); |
| •5 |
extern int cur_lineno; |
| 6 |
%} |
| 7 |
|
| 8 |
%x comment |
| 9 |
%x strings |
| 10 |
|
| •11 |
reserved "default"|"struct"|"void"|"for"|"if"|"else"|"while"|"do"|"return"|"case"|"switch"|"break"|"auto"|"continue"|"goto"|"sizeof"|"static"|"typedef"|"union"|"volatile"|"asm" |
| 12 |
|
| 13 |
vartype "char"|"double"|"enum"|"extern"|"float"|"int"|"long"|"register"|"short"|"signed"|"unsigned"|"const" |
| 14 |
|
| •15 |
cprep "include"|"define"|"undef"|"if"|"else"|"elif"|"endif"|"ifdef"|"ifndef"|"error"|"line"|"pragma" |
| 16 |
|
| 17 |
|
| 18 |
%% |
| •19 |
{reserved} {// Ignore reserved words because issue arises |
| 20 |
// if reserved sizeof used as argument to a defined |
| 21 |
// problematic function such as snprintf |
| 22 |
// but we also do not want to attempt to check these |
| 23 |
// for defined issues in setup_checks function as we know |
| 24 |
// they are undefined |
| 25 |
// Default last_token state is NOT_PROBLEMATIC |
| 26 |
|
| 27 |
// state->last_token = NOT_PROBLEMATIC; |
| 28 |
} |
| 29 |
|
| 30 |
{vartype} state->last_token = NOT_PROBLEMATIC; |
| 31 |
|
| 32 |
|
| 33 |
"#"{cprep} state->last_token = NOT_PROBLEMATIC; |
| 34 |
|
| 35 |
NULL { if ((state->last_token == PROBLEMATIC) && |
| 36 |
(state->constant_string < 0)) { |
| 37 |
state->constant_string = state->args; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
\" { |
| 42 |
if (state->last_token == PROBLEMATIC) { |
| 43 |
if (state->constant_string < 0) { |
| 44 |
state->constant_string = state->args; |
| 45 |
} |
| 46 |
} |
| 47 |
skip_strings('"'); |
| 48 |
} |
| 49 |
|
| 50 |
\' skip_strings('\''); |
| 51 |
|
| •52 |
|
| 53 |
\/\/[^\n]* /* skip C++ style comments */ |
| 54 |
|
| 55 |
[a-zA-Z_][_a-zA-Z0-9]* state = setup_checks(yytext, state); |
| 56 |
|
| 57 |
[ \t]+ /* eat up whitespace */ |
| 58 |
|
| 59 |
\( { |
| 60 |
if (state->args < 0) state->args = 0; |
| 61 |
state->braces++; |
| 62 |
if (state->braces > 1) { |
| 63 |
state = push_stack(state); |
| 64 |
state->last_token = NOT_PROBLEMATIC; |
| 65 |
state->braces = 1; |
| 66 |
state->args = -1; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
\, if (state->last_token == PROBLEMATIC) { |
| 71 |
if (state->braces != 0) { |
| 72 |
state->args++; |
| 73 |
} else { |
| 74 |
state->last_token = NOT_PROBLEMATIC; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
\) if (state->last_token == PROBLEMATIC) { |
| 79 |
check_function(state); |
| 80 |
state->last_token = NOT_PROBLEMATIC; |
| 81 |
} else if (state->braces != 0) { |
| 82 |
state->braces--; |
| 83 |
if (state->braces == 0) { |
| 84 |
state = pop_stack(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
. { |
| 89 |
if ((state->last_token == PROBLEMATIC) && |
| 90 |
(state->braces == 0)) { |
| 91 |
state->last_token = NOT_PROBLEMATIC; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
"/*" BEGIN(comment); |
| 96 |
|
| 97 |
<comment>[^*\n]* /* eat anything that's not a '*' */ |
| 98 |
<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ |
| •99 |
<comment>\n {cur_lineno++;} |
| 100 |
<comment>"*"+"/" BEGIN(INITIAL); |
| 101 |
|
| •102 |
"\n" { cur_lineno++;} |
| 103 |
|
| 104 |
%% |
| 105 |
/********************************************************************** |
| 106 |
* pscan: http://www.striker.ottawa.on.ca/~aland/pscan/ |
| 107 |
* |
| 108 |
* Copyright (C) 2000 Alan DeKok <[email protected]> |
| 109 |
* |
| 110 |
* This program is free software; you can redistribute it and/or modify |
| 111 |
* it under the terms of the GNU General Public License as published by |
| 112 |
* the Free Software Foundation; either version 2 of the License, or |
| 113 |
* (at your option) any later version. |
| 114 |
* |
| 115 |
* This program is distributed in the hope that it will be useful, |
| 116 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 117 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 118 |
* GNU General Public License for more details. |
| 119 |
* |
| 120 |
* You should have received a copy of the GNU General Public License |
| 121 |
* along with this program; if not, write to the Free Software |
| 122 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
| 123 |
* |
| 124 |
**********************************************************************/ |
| 125 |
static const char rcsid[] = "$Id: scanner.l,v 1.4 2000/07/17 18:51:45 aland Exp $"; |
| 126 |
|
| 127 |
/* static */ |
| 128 |
void skip_strings(char literal) |
| 129 |
{ |
| •130 |
int c,last_c=0,done=0; |
| 131 |
|
| 132 |
while (!done) |
| 133 |
{ |
| 134 |
c=input(); |
| 135 |
|
| 136 |
if (c==EOF) |
| 137 |
return; |
| 138 |
|
| 139 |
if ((last_c!='\\') && (c==literal)) // non escaped literal found |
| 140 |
done=1; |
| 141 |
else if ((last_c=='\\') && (c=='\\')) // avoid \\ issue |
| 142 |
last_c=0; |
| 143 |
else |
| 144 |
last_c=c; |
| 145 |
} |
| 146 |
|
| •147 |
return; |
| 148 |
} |