diff options
-rw-r--r-- | badroff.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -51,10 +51,22 @@ char* center(char* text){ return str; } +char* cmds[] = {"CT "}; +char* (*call[])(char* txt) = {center}; + char* cmd(void){ char* dat = popstrbuf(inbuf, chrfill('\n')); - if (!strncmp(dat, "CT ", 3)){ - return center(dat+3); + size_t low = 0; size_t high = sizeof(cmds)/sizeof(*cmds); //len + while (high >= low){ + int mid = ((unsigned int)low + (unsigned int)high) >> 1; + char* mval = cmds[mid]; + + int cmp = strncmp(dat, mval, strlen(mval)); + if (cmp < 0) // dat < mval + low = mid + 1; + else if (cmp > 0) + high = mid - 1; + else return call[mid](dat+strlen(mval)); } return NULL; } |