aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-03-30 18:26:23 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-03-30 18:26:23 -0400
commit969e678287771bab0a34ca44396a721ade715720 (patch)
treea74fe8b95ab908c0feb65d3d4ff6b60d5a548d4b
parent4b28d69cb526c7730c8e7cb0ab14e2a77e732211 (diff)
general fn call interface
-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;
}