/* Parse a variable assignment line */ static int parse_line(const char* unit, const char *filename, unsigned line, const char *sections, ConfigItemLookup lookup, const void *table, bool relaxed, bool allow_include, char **section, unsigned *section_line, bool *section_ignored, char *l, void *userdata) { char *e; assert(filename); assert(line > 0); assert(lookup); assert(l); l = strstrip(l); if (!*l) return 0; if (strchr(COMMENTS "\n", *l)) return 0; if (startswith(l, ".include ")) { _cleanup_free_ char *fn = NULL; /* .includes are a bad idea, we only support them here * for historical reasons. They create cyclic include * problems and make it difficult to detect * configuration file changes with an easy * stat(). Better approaches, such as .d/ drop-in * snippets exist. * * Support for them should be eventually removed. */ if (!allow_include) { log_syntax(unit, LOG_ERR, filename, line, EBADMSG, ".include not allowed here. Ignoring."); return 0; } fn = file_in_same_dir(filename, strstrip(l+9)); if (!fn) return -ENOMEM; return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, false, userdata); } if (*l == '[') { size_t k; char *n; k = strlen(l); assert(k > 0); if (l[k-1] != ']') { log_syntax(unit, LOG_ERR, filename, line, EBADMSG, "Invalid section header '%s'", l); return -EBADMSG; } n = strndup(l+1, k-2); if (!n) return -ENOMEM; if (sections && !nulstr_contains(sections, n)) { if (!relaxed && !startswith(n, "X-")) log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Unknown section '%s'. Ignoring.", n); free(n); free(*section); *section = NULL; *section_line = 0; *section_ignored = true; } else { free(*section); *section = n; *section_line = line; *section_ignored = false; } return 0; } if (sections && !*section) { if (!relaxed && !*section_ignored) log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Assignment outside of section. Ignoring."); return 0; } e = strchr(l, '='); if (!e) { log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Missing '='."); return -EBADMSG; } *e = 0; e++; return next_assignment(unit, filename, line, lookup, table, *section, *section_line, strstrip(l), strstrip(e), relaxed, userdata); }
/* Parse a variable assignment line */ static int parse_line(const char* unit, const char *filename, unsigned line, const char *sections, ConfigItemLookup lookup, void *table, bool relaxed, bool allow_include, char **section, unsigned *section_line, char *l, void *userdata) { char *e; assert(filename); assert(line > 0); assert(lookup); assert(l); l = strstrip(l); if (!*l) return 0; if (strchr(COMMENTS "\n", *l)) return 0; if (startswith(l, ".include ")) { _cleanup_free_ char *fn = NULL; if (!allow_include) { log_syntax(unit, LOG_ERR, filename, line, EBADMSG, ".include not allowed here. Ignoring."); return 0; } fn = file_in_same_dir(filename, strstrip(l+9)); if (!fn) return -ENOMEM; return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, userdata); } if (*l == '[') { size_t k; char *n; k = strlen(l); assert(k > 0); if (l[k-1] != ']') { log_syntax(unit, LOG_ERR, filename, line, EBADMSG, "Invalid section header '%s'", l); return -EBADMSG; } n = strndup(l+1, k-2); if (!n) return -ENOMEM; if (sections && !nulstr_contains(sections, n)) { if (!relaxed) log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Unknown section '%s'. Ignoring.", n); free(n); free(*section); *section = NULL; *section_line = 0; } else { free(*section); *section = n; *section_line = line; } return 0; } if (sections && !*section) { if (!relaxed) log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Assignment outside of section. Ignoring."); return 0; } e = strchr(l, '='); if (!e) { log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Missing '='."); return -EBADMSG; } *e = 0; e++; return next_assignment(unit, filename, line, lookup, table, *section, *section_line, strstrip(l), strstrip(e), relaxed, userdata); }
/* Parse a variable assignment line */ static int parse_line( const char *filename, unsigned line, const char *sections, ConfigItemLookup lookup, void *table, bool relaxed, char **section, char *l, void *userdata) { char *e; assert(filename); assert(line > 0); assert(lookup); assert(l); l = strstrip(l); if (!*l) return 0; if (strchr(COMMENTS, *l)) return 0; if (startswith(l, ".include ")) { char *fn; int r; fn = file_in_same_dir(filename, strstrip(l+9)); if (!fn) return -ENOMEM; r = config_parse(fn, NULL, sections, lookup, table, relaxed, userdata); free(fn); return r; } if (*l == '[') { size_t k; char *n; k = strlen(l); assert(k > 0); if (l[k-1] != ']') { log_error("[%s:%u] Invalid section header.", filename, line); return -EBADMSG; } n = strndup(l+1, k-2); if (!n) return -ENOMEM; if (sections && !nulstr_contains(sections, n)) { if (!relaxed) log_info("[%s:%u] Unknown section '%s'. Ignoring.", filename, line, n); free(n); *section = NULL; } else { free(*section); *section = n; } return 0; } if (sections && !*section) { if (!relaxed) log_info("[%s:%u] Assignment outside of section. Ignoring.", filename, line); return 0; } e = strchr(l, '='); if (!e) { log_error("[%s:%u] Missing '='.", filename, line); return -EBADMSG; } *e = 0; e++; return next_assignment( filename, line, lookup, table, *section, strstrip(l), strstrip(e), relaxed, userdata); }
/* Parse a single logical line */ static int parse_line( const char* unit, const char *filename, unsigned line, const char *sections, ConfigItemLookup lookup, const void *table, ConfigParseFlags flags, char **section, unsigned *section_line, bool *section_ignored, char *l, void *userdata) { char *e, *include; assert(filename); assert(line > 0); assert(lookup); assert(l); l = strstrip(l); if (!*l) return 0; if (strchr(COMMENTS "\n", *l)) return 0; include = first_word(l, ".include"); if (include) { _cleanup_free_ char *fn = NULL; /* .includes are a bad idea, we only support them here * for historical reasons. They create cyclic include * problems and make it difficult to detect * configuration file changes with an easy * stat(). Better approaches, such as .d/ drop-in * snippets exist. * * Support for them should be eventually removed. */ if (!(flags & CONFIG_PARSE_ALLOW_INCLUDE)) { log_syntax(unit, LOG_ERR, filename, line, 0, ".include not allowed here. Ignoring."); return 0; } log_syntax(unit, LOG_WARNING, filename, line, 0, ".include directives are deprecated, and support for them will be removed in a future version of systemd. " "Please use drop-in files instead."); fn = file_in_same_dir(filename, strstrip(include)); if (!fn) return -ENOMEM; return config_parse(unit, fn, NULL, sections, lookup, table, flags, userdata); } if (!utf8_is_valid(l)) return log_syntax_invalid_utf8(unit, LOG_WARNING, filename, line, l); if (*l == '[') { size_t k; char *n; k = strlen(l); assert(k > 0); if (l[k-1] != ']') { log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid section header '%s'", l); return -EBADMSG; } n = strndup(l+1, k-2); if (!n) return -ENOMEM; if (sections && !nulstr_contains(sections, n)) { if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(n, "X-")) log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n); free(n); *section = mfree(*section); *section_line = 0; *section_ignored = true; } else { free_and_replace(*section, n); *section_line = line; *section_ignored = false; } return 0; } if (sections && !*section) { if (!(flags & CONFIG_PARSE_RELAXED) && !*section_ignored) log_syntax(unit, LOG_WARNING, filename, line, 0, "Assignment outside of section. Ignoring."); return 0; } e = strchr(l, '='); if (!e) { log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing '='."); return -EINVAL; } *e = 0; e++; return next_assignment(unit, filename, line, lookup, table, *section, *section_line, strstrip(l), strstrip(e), flags, userdata); }
static list expandtransition(struct trans_object *trans_el, struct net_object *net, struct net_object *unf_net) { struct trans_object *unf_trans; bool Found; struct lisp_object *lisp; struct arc_object *arc, *new_arc, *prev_arc; guard_exprPTR g; arcPTR *parsedArcs; operandPTR op; list arcs, l=NULL, curr=NULL; int i, j, noarc, otd, vtd; multisetPTR p_MS; AssignmentPTR gamma; status state; char *new_var; init_list(&gListParsedArcs); init_list(&YACCParsedVarList); #if DEBUG_UNFOLD printf("Expand transition %s\n\n", trans_el->tag); #endif new_var = FreeVarName(); for (arc = trans_el->arcs, noarc = 0; arc != NULL; arc = arc->next, noarc++); parsedArcs = (arcPTR *) Ecalloc( noarc , sizeof(arcPTR)); init_list(&YACCParsedVarList); i = 0; for( arc = trans_el->arcs; arc != NULL; arc = arc->next){ init_list(&l); if((find_key(gListDomain, (generic_ptr) (arc->place)->tag , CmpDomainName, &l))==OK) { YACCparsedDomain = ((DomainObjPTR) DATA(l)); Found = FALSE; if ( arc->color != NULL ) { for ( lisp = net->lisps; lisp != NULL; lisp = lisp->next){ if(lisp->type=='f' && (strcmp(arc->color, lisp->tag)==0)) { parsedArcs[i++]= ParseArc(lisp->text); Found = TRUE; } } if(Found == FALSE){ parsedArcs[i++]= ParseArc(arc->color); Found = TRUE; } } else if(Found == FALSE && arc->lisp != NULL) parsedArcs[i++]= ParseArc(arc->lisp->text); else parsedArcs[i++]= ParseNoColoredArc(arc, new_var); } else Error(UNDEF_DOM_ERR, "DefTransitions", (arc->place)->tag); } g = ParseGuard(trans_el, net); create_assignment(&gamma, YACCParsedVarList); otd = atoi(opt_list[OPT_ORIZ_TRANS_DISPLACEMENT].arg_val); vtd = atoi(opt_list[OPT_VERT_TRANS_DISPLACEMENT].arg_val); l = NULL; j = 0; init_list(&l); for(state = first_assignment(gamma) ; state != ERROR ; j++) { #if DEBUG_UNFOLD printf("Assignment %s\n%",print_assignment(gamma)); #endif if(eval_guard_expr(g, gamma) == TRUE){ unf_trans = unfolding_transition(trans_el, j, gamma, &(unf_net->rpars)); unf_trans->center.x += j*otd; unf_trans->center.y += j*vtd; head_insert(&l, (generic_ptr) unf_trans); i = 0; for( arc = trans_el->arcs; arc != NULL; arc = arc->next) { #if DEBUG_UNFOLD printf("Arc %s \n", PrintArcExpression(parsedArcs[i])); #endif eval_arc(parsedArcs[i], gamma, &p_MS); arcs = expand_arc(arc, p_MS, parsedArcs[i++]->domain->create_place, unf_net); // destroy_multiset(p_MS); curr = NULL; while ( (curr = list_iterator(arcs, curr)) != NULL ) { new_arc = (struct arc_object *) DATA(curr); if(unf_trans->arcs == NULL) unf_trans->arcs = new_arc; else prev_arc->next = new_arc; prev_arc = new_arc; } // destroy(&arcs, NULL); } } state = next_assignment(gamma); } return(l); }