From 95b180caa01f3ed3084a056a0240c37bd70dcb89 Mon Sep 17 00:00:00 2001 From: sebastid Date: Fri, 4 Nov 2005 08:16:24 +0000 Subject: [PATCH] Don't use strlen to check if a string is empty. SVN revision: 18270 --- legacy/embryo/src/bin/embryo_cc_sc1.c | 31 ++++++++++++--------------- legacy/embryo/src/bin/embryo_cc_sc2.c | 6 +++--- legacy/embryo/src/bin/embryo_cc_sc6.c | 10 ++++----- legacy/embryo/src/bin/embryo_cc_sc7.c | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/legacy/embryo/src/bin/embryo_cc_sc1.c b/legacy/embryo/src/bin/embryo_cc_sc1.c index 23c0a4fe9f..4b55ed5346 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc1.c +++ b/legacy/embryo/src/bin/embryo_cc_sc1.c @@ -342,7 +342,7 @@ sc_compile(int argc, char *argv[]) sc_status = statFIRST; /* do the first pass through the file */ inpfmark = sc_getpossrc(inpf); - if (strlen(incfname) > 0) + if (incfname[0] != '\0') { if (strcmp(incfname, sDEF_PREFIX) == 0) { @@ -390,7 +390,7 @@ sc_compile(int argc, char *argv[]) * by resetglobals() */ writeleader(); setfile(inpfname, fnumber); - if (strlen(incfname) > 0) + if (incfname[0] != '\0') { if (strcmp(incfname, sDEF_PREFIX) == 0) plungefile(incfname, FALSE, TRUE); /* parse "default.inc" (again) */ @@ -601,19 +601,16 @@ parseoptions(int argc, char **argv, char *iname, char *oname, { /* include directory */ i++; - snprintf(str, sizeof(str), "%s", argv[i]); + strncpy(str, argv[i], sizeof(str)); len = strlen(str); - if (len > 0) + if (str[len - 1] != DIRSEP_CHAR) { - if (str[len - 1] != DIRSEP_CHAR) - { - str[len] = DIRSEP_CHAR; - str[len + 1] = '\0'; - } - - insert_path(str); + str[len] = DIRSEP_CHAR; + str[len + 1] = '\0'; } + + insert_path(str); } else if (!strcmp (argv[i], "-o") && *argv[i + 1]) { @@ -640,7 +637,7 @@ parseoptions(int argc, char **argv, char *iname, char *oname, else { /* only allow one input filename */ - about (); + about(); } } } @@ -656,7 +653,7 @@ setopt(int argc, char **argv, char *iname, char *oname, strcpy(pname, sDEF_PREFIX); parseoptions(argc, argv, iname, oname, pname, rname); - if (strlen(iname) == 0) + if (iname[0] == '\0') about(); } @@ -1668,7 +1665,7 @@ decl_enum(int vclass) matchtoken(';'); /* eat an optional ; */ /* set the enum name to the last value plus one */ - if (strlen(enumname) > 0) + if (enumname[0] != '\0') add_constant(enumname, value, vclass, tag); } @@ -1884,7 +1881,7 @@ operatoradjust(int opertok, symbol * sym, char *opername, int resulttag) error(64); /* cannot change predefined operators */ /* change the operator name */ - assert(strlen(opername) > 0); + assert(opername[0] != '\0'); operator_symname(tmpname, opername, tags[0], tags[1], count, resulttag); if ((oldsym = findglb(tmpname)) != NULL) { @@ -1919,7 +1916,7 @@ operatoradjust(int opertok, symbol * sym, char *opername, int resulttag) static int check_operatortag(int opertok, int resulttag, char *opername) { - assert(opername != NULL && strlen(opername) > 0); + assert(opername != NULL && opername[0] != '\0'); switch (opertok) { case '!': @@ -2891,7 +2888,7 @@ testsymbols(symbol * root, int level, int testlabs, int testconst) if ((sym->usage & (uDEFINE | uREAD | uNATIVE | uSTOCK)) == uDEFINE) { funcdisplayname(symname, sym->name); - if (strlen(symname) > 0) + if (symname[0] != '\0') error(203, symname); /* symbol isn't used ... * (and not native/stock) */ } /* if */ diff --git a/legacy/embryo/src/bin/embryo_cc_sc2.c b/legacy/embryo/src/bin/embryo_cc_sc2.c index 0f0ff23939..60b2e47002 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc2.c +++ b/legacy/embryo/src/bin/embryo_cc_sc2.c @@ -931,7 +931,7 @@ command(void) char pathname[_MAX_PATH]; lptr = getstring(pathname, sizeof pathname, lptr); - if (strlen(pathname) > 0) + if (pathname[0] != '\0') { free(inpfname); inpfname = strdup(pathname); @@ -1000,7 +1000,7 @@ command(void) name[i] = *lptr; name[i] = '\0'; } /* if */ - if (strlen(name) == 0) + if (name[0] == '\0') { curlibrary = NULL; } @@ -1308,7 +1308,7 @@ command(void) delete_subst(pattern, prefixlen); } /* if */ /* add the pattern/substitution pair to the list */ - assert(strlen(pattern) > 0); + assert(pattern[0] != '\0'); insert_subst(pattern, substitution, prefixlen); free(pattern); free(substitution); diff --git a/legacy/embryo/src/bin/embryo_cc_sc6.c b/legacy/embryo/src/bin/embryo_cc_sc6.c index dc50cfdc98..f620ebda82 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc6.c +++ b/legacy/embryo/src/bin/embryo_cc_sc6.c @@ -710,7 +710,7 @@ assemble(FILE * fout, FILE * fin) } /* if */ if (match) { - assert(strlen(alias) > 0); + assert(alias[0] != '\0'); nametablesize += strlen(alias) + 1; } /* if */ } /* for */ @@ -723,7 +723,7 @@ assemble(FILE * fout, FILE * fin) { if (constptr->value > 0) { - assert(strlen(constptr->name) > 0); + assert(constptr->name[0] != '\0'); numlibraries++; nametablesize += strlen(constptr->name) + 1; } /* if */ @@ -736,7 +736,7 @@ assemble(FILE * fout, FILE * fin) { if ((constptr->value & PUBLICTAG) != 0) { - assert(strlen(constptr->name) > 0); + assert(constptr->name[0] != '\0'); numtags++; nametablesize += strlen(constptr->name) + 1; } /* if */ @@ -892,7 +892,7 @@ assemble(FILE * fout, FILE * fin) { if (constptr->value > 0) { - assert(strlen(constptr->name) > 0); + assert(constptr->name[0] != '\0'); func.address = 0; func.nameofs = nameofs; #ifdef WORDS_BIGENDIAN @@ -938,7 +938,7 @@ assemble(FILE * fout, FILE * fin) { if ((constptr->value & PUBLICTAG) != 0) { - assert(strlen(constptr->name) > 0); + assert(constptr->name[0] != '\0'); func.address = constptr->value & TAGMASK; func.nameofs = nameofs; #ifdef WORDS_BIGENDIAN diff --git a/legacy/embryo/src/bin/embryo_cc_sc7.c b/legacy/embryo/src/bin/embryo_cc_sc7.c index 766d2b5ccc..67a7f1c2ae 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc7.c +++ b/legacy/embryo/src/bin/embryo_cc_sc7.c @@ -360,7 +360,7 @@ stgset(int onoff) /* write any contents that may be put in the buffer by stgwrite() * when "staging" was 0 */ - if (strlen(stgbuf) > 0) + if (stgbuf[0] != '\0') filewrite(stgbuf); } /* if */ stgbuf[0] = '\0';