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
|
||||
|
Reference in New Issue
Block a user