static int dag_parse_node(struct lexer *bk) { struct token *t = lexer_next_token(bk); if(t->type != TOKEN_FILES) { lexer_report_error(bk, "Error reading rule."); } lexer_free_token(t); struct dag_node *n; n = dag_node_create(bk->d, bk->line_number); if(verbose_parsing && bk->d->nodeid_counter % parsing_rule_mod_counter == 0) { fprintf(stdout, "\rRules parsed: %d", bk->d->nodeid_counter + 1); fflush(stdout); } n->category = bk->category; list_push_tail(n->category->nodes, n); dag_parse_node_filelist(bk, n); bk->environment->node = n; /* Read variables, if any */ while((t = lexer_peek_next_token(bk)) && t->type != TOKEN_COMMAND) { switch (t->type) { case TOKEN_VARIABLE: dag_parse_variable(bk, n); break; default: lexer_report_error(bk, "Expected COMMAND or VARIABLE, got: %s", lexer_print_token(t)); break; } } if(!t) { lexer_report_error(bk, "Rule does not have a command.\n"); } dag_parse_node_command(bk, n); bk->environment->node = NULL; n->next = bk->d->nodes; bk->d->nodes = n; itable_insert(bk->d->node_table, n->nodeid, n); debug(D_MAKEFLOW_PARSER, "Setting resource category '%s' for rule %d.\n", n->category->label, n->nodeid); dag_node_fill_resources(n); dag_node_print_debug_resources(n); return 1; }
int dag_parse_node(struct lexer_book *bk, char *line_org) { struct dag *d = bk->d; char *line; char *outputs = NULL; char *inputs = NULL; struct dag_node *n; n = dag_node_create(bk->d, bk->line_number); n->category = bk->category; list_push_tail(n->category->nodes, n); line = xxstrdup(line_org); outputs = line; inputs = strchr(line, ':'); *inputs = 0; inputs = inputs + 1; inputs = string_trim_spaces(inputs); outputs = string_trim_spaces(outputs); dag_parse_node_filelist(bk, n, outputs, 0); dag_parse_node_filelist(bk, n, inputs, 1); int ok; char *comment; //parse variables and comments while((line = dag_parse_readline(bk, n)) != NULL) { if(line[0] == '@' && strchr(line, '=')) { ok = dag_parse_variable(bk, n, line); free(line); if(ok) { continue; } else { dag_parse_error(bk, "node variable"); free(line); return 0; } } comment = strchr(line, '#'); if(comment) { *comment = '\0'; int n = strspn(line, " \t"); int m = strlen(line); *comment = '#'; /* make sure that only spaces and tabs appear before the hash */ if(n == m) { continue; } } /* not a comment or a variable, so we break to parse the command */ break; } ok = dag_parse_node_command(bk, n, line); free(line); if(ok) { n->next = d->nodes; d->nodes = n; itable_insert(d->node_table, n->nodeid, n); } else { dag_parse_error(bk, "node command"); return 0; } debug(D_DEBUG, "Setting resource category '%s' for rule %d.\n", n->category->label, n->nodeid); dag_task_fill_resources(n); dag_task_print_debug_resources(n); return 1; }