aboutsummaryrefslogtreecommitdiff
path: root/badroff.c
diff options
context:
space:
mode:
Diffstat (limited to 'badroff.c')
-rw-r--r--badroff.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/badroff.c b/badroff.c
index 3d715fb..522b305 100644
--- a/badroff.c
+++ b/badroff.c
@@ -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;
}