/** Parse a node's input or output filelist. Parse through a list of input or output files, adding each as a source or target file to the provided node. @param d The DAG being constructed @param n The node that the files are being added to @param filelist The list of files, separated by whitespace @param source a flag for whether the files are source or target files. 1 indicates source files, 0 indicates targets */ int dag_parse_node_filelist(struct lexer_book *bk, struct dag_node *n, char *filelist, int source) { char *filename; char *newname; char **argv; int i, argc; string_split_quotes(filelist, &argc, &argv); for(i = 0; i < argc; i++) { filename = argv[i]; newname = NULL; debug(D_DEBUG, "node %s file=%s", (source ? "input" : "output"), filename); // remote renaming if((newname = strstr(filename, "->"))) { *newname = '\0'; newname += 2; } if(source) dag_node_add_source_file(n, filename, newname); else dag_node_add_target_file(n, filename, newname); } free(argv); return 1; }
static int dag_parse_node_filelist(struct lexer *bk, struct dag_node *n) { int before_colon = 1; char *filename; char *newname; struct token *t, *arrow, *rename; while((t = lexer_next_token(bk))) { filename = NULL; newname = NULL; switch (t->type) { case TOKEN_COLON: before_colon = 0; lexer_free_token(t); break; case TOKEN_NEWLINE: /* Finished reading file list */ lexer_free_token(t); return 1; break; case TOKEN_LITERAL: rename = NULL; arrow = lexer_peek_next_token(bk); if(!arrow) { lexer_report_error(bk, "Rule specification is incomplete."); } else if(arrow->type == TOKEN_REMOTE_RENAME) //Is the arrow really an arrow? { lexer_free_token(lexer_next_token(bk)); //Jump arrow. rename = lexer_next_token(bk); if(!rename) { lexer_report_error(bk, "Remote name specification is incomplete."); } } filename = t->lexeme; newname = rename ? rename->lexeme : NULL; if(before_colon) dag_node_add_target_file(n, filename, newname); else dag_node_add_source_file(n, filename, newname); lexer_free_token(t); if(rename) { lexer_free_token(rename); } break; default: lexer_report_error(bk, "Error reading file list. %s", lexer_print_token(t)); break; } } return 0; }