diff --git a/pscat/pscat.c b/pscat/pscat.c index 7f85356..e1c22c5 100644 --- a/pscat/pscat.c +++ b/pscat/pscat.c @@ -23,17 +23,10 @@ static char *program_name = "pscat"; /* Test string containing { c, '\0' } without iteration. * Theoretically saves a little bit of time compared to strcmp(3). */ -int -scmpflat(char *s, int c){ - return - s[0] != '\0' - && s[1] == '\0' - && s[0] == c - ; -} +#define SCMPFLAT(a, b) (*(a) != '\0' && *((a)+1) == '\0' && *(a) == (b)) /* Verifies arguments to pscat are sensible. */ -int +static int check_arg(char **argv){ enum { UNINITIALIZED = 0, @@ -45,16 +38,16 @@ check_arg(char **argv){ for(s = UNINITIALIZED, terms = 0; *argv != NULL; ++argv) switch(s){ case UNINITIALIZED: case NORMAL: - if(scmpflat(*argv, L_PAREN)) + if(SCMPFLAT(*argv, L_PAREN)) s = INLPAREN; else return 0; /* syntax error */ break; default: /* >= INLPAREN */ - if(scmpflat(*argv, R_PAREN)){ + if(SCMPFLAT(*argv, R_PAREN)){ --s; terms += s == NORMAL; - }else if(scmpflat(*argv, L_PAREN)) /* ineligant */ + }else if(SCMPFLAT(*argv, L_PAREN)) /* ineligant */ ++s; break; } @@ -89,9 +82,9 @@ int main(int argc, char *argv[]){ /* branching here potentially saves a comparison. * this seems like the most optimal way to do this, * maybe it isn't, i don't care too much */ - if(scmpflat(*argv, L_PAREN)) + if(SCMPFLAT(*argv, L_PAREN)) ++p; - else if(scmpflat(*argv, R_PAREN)) + else if(SCMPFLAT(*argv, R_PAREN)) --p; } /* *argv -> the corresponding R_PAREN. turn it into NULL to