Here is a second version of my patch from last night. It uses the provided ctype function isspace and does the same readdir(). I remove the rosh_issp() function. I admit to being a bit liberal with my use of braces and spaces. We all of the habit of knowing we can invent a more perfect wheel. Let me know if you have any questions. Keith -------------- next part -------------- A non-text attachment was scrubbed... Name: rosh.c.patch Type: text/x-patch Size: 1840 bytes Desc: not available URL: <http://www.zytor.com/pipermail/syslinux/attachments/20090306/07b7f333/attachment.bin> -------------- next part -------------- A non-text attachment was scrubbed... Name: rosh.h.patch Type: text/x-patch Size: 361 bytes Desc: not available URL: <http://www.zytor.com/pipermail/syslinux/attachments/20090306/07b7f333/attachment-0001.bin>
Keith Schincke wrote:> Here is a second version of my patch from last night. > > It uses the provided ctype function isspace and does the same readdir(). > I remove the rosh_issp() function. I admit to being a bit liberal with my > use of braces and spaces. >> - de = readdir(d); > - while (de != NULL) { > + while ( de = readdir(d) ) { > filepos++;Stylistic note: it is stylistically considered appropriate to put an extra set of parens around an assignment used in the context of a boolean expression. gcc will warn if you don't. This thus should be: while ( (de = readdir(d)) ) { filepos++; -hpa -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Op 20090306 om 21:41 schreef Keith Schincke:> Here is a second version of my patch from last night. > > It uses the provided ctype function isspace and does the same readdir(). > I remove the rosh_issp() function. I admit to being a bit liberal with my > use of braces and spaces. > > We all of the habit of knowing we can invent a more perfect wheel. > > Let me know if you have any questions. > > KeithAs reminder, the isspace part diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c index 5eaa47d..b42af58 100644 --- a/com32/rosh/rosh.c +++ b/com32/rosh/rosh.c @@ -54,21 +54,6 @@ void rosh_help(int type) } } -/* Determine if a character is whitespace - * inc input character - * returns 0 if not whitespace - */ -int rosh_issp(char inc) -{ - int rv; - switch (inc){ - case ' ': case '\t': - rv = 1; break; - default: rv = 0; - } - return rv; -} /* ros_issp */ - /* Search a string for first non-space (' ') character, starting at ipos * istr input string to parse * ipos input position to start at @@ -80,7 +65,7 @@ int rosh_search_nonsp(const char *istr, const int ipos) curpos = ipos; c = istr[curpos]; - while (rosh_issp(c) && c != 0) + while (isspace(c) && c != 0) c = istr[++curpos]; return curpos; } @@ -97,7 +82,7 @@ int rosh_search_sp(const char *istr, const int ipos) curpos = ipos; c = istr[curpos]; - while (!(rosh_issp(c)) && c != 0) + while (!(isspace(c)) && c != 0) c = istr[++curpos]; return curpos; } diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h index d7296e1..1eb03cc 100644 --- a/com32/rosh/rosh.h +++ b/com32/rosh/rosh.h @@ -37,6 +37,7 @@ #include <unistd.h> /* getcwd() */ #include <errno.h> /* errno; error macros */ #include <netinet/in.h> /* For htonl/ntohl/htons/ntohs */ +#include <ctype.h> /* needed for charecter checking */ #include <getkey.h> #include <consoles.h>
Op 20090306 om 21:41 schreef Keith Schincke:> Here is a second version of my patch from last night. > > It uses the provided ctype function isspace and does the same readdir(). > I remove the rosh_issp() function. I admit to being a bit liberal with my > use of braces and spaces. > > We all of the habit of knowing we can invent a more perfect wheel. > > Let me know if you have any questions. > > Keithas reminder, the while readdir part diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c index b42af58..dc3f64d 100644 --- a/com32/rosh/rosh.c +++ b/com32/rosh/rosh.c @@ -369,8 +369,7 @@ ROSH_DEBUG("--'%s'\n", filestr); if (S_ISDIR(fdstat.st_mode)) { ROSH_DEBUG("PATH '%s' is a directory\n", ifilstr); d = fdopendir(fd); - de = readdir(d); - while (de != NULL) { + while ( de = readdir(d) ) { #ifdef DO_DEBUG filestr2[0] = 0; file2pos = strlen(filestr); @@ -386,7 +385,6 @@ ROSH_DEBUG("--'%s'\n", filestr); #ifdef DO_DEBUG // inchar = fgetc(stdin); #endif /* DO_DEBUG */ - de = readdir(d); } closedir(d); } else if (S_ISREG(fdstat.st_mode)) { @@ -404,8 +402,7 @@ ROSH_DEBUG("--'%s'\n", filestr); d = opendir(filestr); if (d != NULL) { printf("DIR:'%s' %8d %8d\n", d->dd_name, d->dd_fd, d->dd_sect); - de = readdir(d); - while (de != NULL) { + while ( de = readdir(d) ) { filepos++; #ifdef DO_DEBUG // if (strlen(de->d_name) > 25) de->d_name[25] = 0; @@ -423,7 +420,6 @@ printf("'%s'\n", de->d_name); // fgets(instr, ROSH_CMD_SZ, stdin); #endif /* DO_DEBUG */ free(de); - de = readdir(d); // if(filepos>15){ de = NULL; printf("Force Break\n");} } printf("Dir.dd_fd: '%8d'\n", d->dd_fd);