void initrules(Bool reload) { int i; char t[64]; const char *tmp; freerules(); rules = ecalloc(64, sizeof(Rule *)); for (i = 0; i < 64; i++) { snprintf(t, sizeof(t), "rule%d", i); tmp = getresource(t, NULL); if (!tmp) continue; rules[nrules] = emallocz(sizeof(Rule)); parserule(tmp, rules[nrules]); nrules++; } // rules = erealloc(rules, nrules * sizeof(Rule *)); compileregs(); }
Rule* readrule(int *eof) { Rule *rp; char *line, *p; char *word; Top: line = getline(); if(line == nil){ /* * if input is from string, and bytes remain (input->end is within string), * morerules() will pop input and save remaining data. otherwise pop * the stack here, and if there's more input, keep reading. */ if((input!=nil && input->end==nil) && popinput()) goto Top; *eof = 1; return nil; } input->lineno++; for(p=line; *p==' ' || *p=='\t'; p++) ; if(*p=='\0' || *p=='#') /* empty or comment line */ return nil; if(include(p)) goto Top; if(assignment(p)) return nil; rp = emalloc(sizeof(Rule)); /* object */ for(word=p; *p!=' ' && *p!='\t'; p++) if(*p == '\0') parseerror("malformed rule"); *p++ = '\0'; rp->obj = lookup(word, objects); if(rp->obj < 0){ if(strcmp(word, "kind") == 0) /* backwards compatibility */ rp->obj = OType; else parseerror("unknown object %s", word); } /* verb */ while(*p==' ' || *p=='\t') p++; for(word=p; *p!=' ' && *p!='\t'; p++) if(*p == '\0') parseerror("malformed rule"); *p++ = '\0'; rp->verb = lookup(word, verbs); if(rp->verb < 0) parseerror("unknown verb %s", word); /* argument */ while(*p==' ' || *p=='\t') p++; if(*p == '\0') parseerror("malformed rule"); rp->arg = estrdup(p); parserule(rp); return rp; }