Resolved issue of including path to .alpha file and tested with multiple directories
This commit is contained in:
20
runner.c
20
runner.c
@ -21,17 +21,12 @@ int main(int argc, char *argv[]) {
|
||||
arg = TOK_ARG; //it is a -tok arg with a valid alpha file at argv[2]
|
||||
yyin = fopen(argv[2], "r");
|
||||
}
|
||||
token = yylex();
|
||||
fprintf(stderr, "made it here");
|
||||
while (token != 0) {
|
||||
while (0 != (token = yylex())) {
|
||||
if (arg == TOK_ARG) {
|
||||
fprintf(output, "%d %d %3d \"%s\"\n", line_number, column_number, token, yytext);
|
||||
}
|
||||
token = yylex();
|
||||
fprintf(stderr, "made it past yylex");
|
||||
}
|
||||
|
||||
fprintf(stderr, "returned 0\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -43,6 +38,19 @@ char *is_tok(int argc, char *argv[]) {
|
||||
if (is_alpha_file(input_prog, file_len) != 0) {
|
||||
return INVALID_ARG;
|
||||
}
|
||||
|
||||
int ignore_path = 0;
|
||||
int count_since_slash = 0;
|
||||
for (int i = 0; i < file_len; i++) {
|
||||
count_since_slash++;
|
||||
if (input_prog[i] == '/') {
|
||||
ignore_path += count_since_slash;
|
||||
count_since_slash = 0;
|
||||
}
|
||||
}
|
||||
|
||||
file_len -= ignore_path;
|
||||
input_prog += ignore_path;
|
||||
char* FILE_tok = calloc(sizeof(char), file_len - ALPHA_OFFSET + TOK_LEN);
|
||||
strncpy(FILE_tok, input_prog, file_len - ALPHA_OFFSET); //copy name of prog before .alpha
|
||||
strcpy(FILE_tok + sizeof(char) * (file_len - ALPHA_OFFSET), ".tok"); //add .tok to end of file name
|
||||
|
23
tests/testPath/testPath.alpha
Normal file
23
tests/testPath/testPath.alpha
Normal file
@ -0,0 +1,23 @@
|
||||
This is a test
|
||||
9combined 7okens
|
||||
12345
|
||||
893247892
|
||||
combined'DueToUnknownChar _validtoken __validtoken1 _valid_token2 validToken3_
|
||||
true false
|
||||
null while !wrong if when
|
||||
else type function
|
||||
return external as
|
||||
string _NOte_that_was_not_reserved
|
||||
([)]{}:;,->"\
|
||||
+-*/%
|
||||
<=
|
||||
:=
|
||||
"This is not a valid
|
||||
String"
|
||||
"This is a valid String"
|
||||
!|
|
||||
..
|
||||
(* this is a comment *)
|
||||
(*Not a comment
|
||||
$^&
|
||||
>
|
17
tests/test_operators.alpha~
Normal file
17
tests/test_operators.alpha~
Normal file
@ -0,0 +1,17 @@
|
||||
+
|
||||
-
|
||||
*
|
||||
/
|
||||
\
|
||||
%
|
||||
<
|
||||
>
|
||||
=
|
||||
:=
|
||||
=:
|
||||
:
|
||||
=
|
||||
!
|
||||
&
|
||||
|
|
||||
.
|
Reference in New Issue
Block a user