diff --git a/source/src/command.cpp b/source/src/command.cpp index 9def120e..82ef699e 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -747,7 +747,10 @@ bool deletecfg() void identnames(vector &names, bool builtinonly) { - enumerateht(*idents) if(!builtinonly || idents->enumc->data.type != ID_ALIAS) names.add(idents->enumc->key); + enumeratekt(*idents, const char *, name, ident, id, + { + if(!builtinonly || id.type != ID_ALIAS) names.add(name); + }); } vector contextstack; @@ -767,15 +770,11 @@ int popscontext() if(execcontext < old && old >= IEXC_MAPCFG) // clean up aliases created in the old (map cfg) context { - enumerateht(*idents) + enumeratekt(*idents, const char *, name, ident, id, { - ident *id = &idents->enumc->data; - if(id->type == ID_ALIAS && id->context > execcontext) - { - idents->remove(idents->enumc->key); - i--; - } - } + if(id.type == ID_ALIAS && id.context > execcontext) + idents->remove(name); + }); } return execcontext; } diff --git a/source/src/docs.cpp b/source/src/docs.cpp index 1e4f66fe..f5af9865 100644 --- a/source/src/docs.cpp +++ b/source/src/docs.cpp @@ -171,15 +171,17 @@ void docinvalid() vector inames; identnames(inames, true); inames.sort(stringsort); - enumerateht(docidents) if(!strchr(docidents.enumc->data.name, ' ') && !identexists(docidents.enumc->data.name)) - conoutf(docidents.enumc->data.name); + enumerate(docidents, docident, d, + { + if(!strchr(d.name, ' ') && !identexists(d.name)) + conoutf(d.name); + }); } void docfind(char *search) { - enumerateht(docidents) + enumerate(docidents, docident, i, { - docident &i = docidents.enumc->data; cvector srch; srch.add(i.name); srch.add(i.desc); @@ -194,7 +196,7 @@ void docfind(char *search) s_strncpy(match, r-srch[rline] > matchchars/2 ? r-matchchars/2 : srch[rline], matchchars/2); conoutf("%-20s%s", i.name, match); } - } + }); } char *xmlstringenc(char *d, const char *s, size_t len) @@ -242,9 +244,8 @@ void docwritebaseref(char *ref, char *schemalocation, char *transformation) fprintf(f, "\t\t\t\n"); string name; - enumerateht(*idents) + enumerate(*idents, ident, id, { - ident &id = idents->enumc->data; if(id.type != ID_COMMAND) continue; fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id.name, _MAXDEFSTR)); fprintf(f, "\t\t\t\t\t%s\n", desc); @@ -260,16 +261,15 @@ void docwritebaseref(char *ref, char *schemalocation, char *transformation) fprintf(f, "\t\t\t\t\t\n"); } fprintf(f, "\t\t\t\t\n"); - } - enumerateht(*idents) + }); + enumerate(*idents, ident, id, { - ident &id = idents->enumc->data; if(id.type != ID_VAR) continue; fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id.name, _MAXDEFSTR)); fprintf(f, "\t\t\t\t\tTODO\n"); fprintf(f, "\t\t\t\t\t\n", id.minval>id.maxval ? "" : "token=\"N\"", id.minval, id.maxval, *id.storage.i, id.minval>id.maxval ? "readOnly=\"true\"" : ""); fprintf(f, "\t\t\t\t\n"); - } + }); fprintf(f, "\t\t\t\n\t\t\n\t\n\n"); fclose(f); diff --git a/source/src/tools.h b/source/src/tools.h index 9f88f2f2..19aa4376 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -497,9 +497,8 @@ template struct hashtable #define itoa(s, i) sprintf(s, "%d", i) -#define enumeratekt(ht,k,e,t,f,b) loopi((ht).size) for(hashtable::chain *enumc = (ht).table[i]; enumc; enumc = enumc->next) { hashtable::const_key &e = enumc->key; t &f = enumc->data; b; } -#define enumerate(ht,t,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc; (ht).enumc = (ht).enumc->next) { t &e = (ht).enumc->data; b; } -#define enumerateht(ht) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc; (ht).enumc = (ht).enumc->next) +#define enumeratekt(ht,k,e,t,f,b) loopi((ht).size) for(hashtable::chain *enumc = (ht).table[i]; enumc;) { hashtable::const_key &e = enumc->key; t &f = enumc->data; enumc = enumc->next; b; } +#define enumerate(ht,t,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc;) { t &e = (ht).enumc->data; (ht).enumc = (ht).enumc->next; b; } inline char *newstring(size_t l) { return new char[l+1]; } inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), s, l+1); }