5 * Contains get_pascal_char(), which parses C code.
15 #include "trueprint.h"
22 #include "lang_pascal.h"
27 char lang_pascal_defaults
[] = "--f --F --i";
50 static char procedure_string
[] = "procedure";
51 static char function_string
[] = "function";
52 static char begin_string
[] = "begin";
53 static char end_string
[] = "end";
57 * detects comment starts and ends;
58 * finds function names;
59 * detects function ends;
60 * returns one of the following:
71 get_pascal_char(char *input_char
, char_status
*status
)
75 static pascal_states state
= PAS_SPACE
;
76 static pascal_fn_states fn_state
= FN_CODE
;
77 static long start_char
;
78 static char fn_name
[SYMBOL_LEN
];
80 static size_t token_index
;
81 static short function_depth
= 0;
83 *status
= CHAR_NORMAL
;
85 if (restart_language
== TRUE
)
91 restart_language
= FALSE
;
94 retval
= getnextchar(input_char
);
99 if (isspace(*input_char
)) break;
100 if (*input_char
== '{')
103 *status
= CHAR_ITALIC
;
105 else if (*input_char
== '(')
110 if (c
== '*') *status
= CHAR_ITALIC
;
112 state
=PAS_COMMENT_START
;
115 case PAS_COMMENT_START
:
116 if (*input_char
== '*')
119 *status
= CHAR_ITALIC
;
124 case PAS_COMMENT_END
:
125 *status
= CHAR_ITALIC
;
126 if (*input_char
== ')') state
= PAS_SPACE
;
129 *status
= CHAR_ITALIC
;
130 if (*input_char
== '}')
134 else if (*input_char
== '*')
136 state
= PAS_COMMENT_END
;
143 if ((state
== PAS_SPACE
) || (state
== PAS_COMMENT_START
))
148 if (*input_char
== 'b'){fn_state
=FN_BEGIN
;token_index
=1;break;}
149 if (*input_char
== 'e'){fn_state
=FN_END
;token_index
=1;break;}
150 if (*input_char
== 'f'){fn_state
=FN_FUNCTION
;token_index
=1;break;}
151 if (*input_char
== 'p'){fn_state
=FN_PROCEDURE
;token_index
=1;break;}
154 if (*input_char
== procedure_string
[token_index
])
156 if (++token_index
== strlen(procedure_string
))
157 { token_index
= 0; fn_state
= FN_SPACE
; }
163 if (*input_char
== function_string
[token_index
])
165 if (++token_index
== strlen(function_string
))
166 { token_index
= 0; fn_state
= FN_SPACE
; }
172 if (*input_char
== begin_string
[token_index
])
174 if (++token_index
== strlen(begin_string
))
185 if (*input_char
== end_string
[token_index
])
187 if (++token_index
== strlen(end_string
))
191 if (braces_depth
!= 0)
192 if (--braces_depth
== function_depth
)
194 retval
|=STREAM_FUNCTION_END
;
195 end_function(page_number
);
204 if (!isspace(*input_char
))
206 if (isalpha(*input_char
))
209 fn_name
[token_index
++] = *input_char
;
210 start_char
= char_number
;
211 fn_page
= page_number
;
219 if ((isalnum(*input_char
)||*input_char
== '_') && (token_index
< SYMBOL_LEN
-1))
220 fn_name
[token_index
++] = *input_char
;
223 fn_name
[token_index
] = '\0';
224 add_function(fn_name
,start_char
,char_number
-1,fn_page
,current_filename
);
226 function_depth
= braces_depth
;
234 if (pass
==1) *status
= get_function_name_posn(char_number
,*status
);