From: <enl...@li...> - 2001-05-08 02:18:02
|
Enlightenment CVS committal Author : mej Project : eterm Module : libast Dir : eterm/libast Modified Files: ChangeLog Makefile.am configure.in strings.c Log Message: Mon May 7 19:08:45 PDT 2001 Michael Jennings <me...@et...> I have created a testbed for libast. You can now run "make test" to run a series of tests which will test some of the functionality of the library. I didn't finish all the tests I'll eventually have; I just wanted to get the stuff that's immediately important. I also added a new split() function, which functions somewhat like its Perl counterpart, although there are differences. This function will be used in the remaining Eterm work I must do before release. =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/ChangeLog,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- ChangeLog 2001/01/03 02:23:30 1.4 +++ ChangeLog 2001/05/08 02:18:01 1.5 @@ -30,3 +30,15 @@ systems, they will be addressed here. ------------------------------------------------------------------------------- +Mon May 7 19:08:45 PDT 2001 Michael Jennings <me...@et...> + + I have created a testbed for libast. You can now run "make test" to + run a series of tests which will test some of the functionality of the + library. I didn't finish all the tests I'll eventually have; I just + wanted to get the stuff that's immediately important. + + I also added a new split() function, which functions somewhat like its + Perl counterpart, although there are differences. This function will + be used in the remaining Eterm work I must do before release. + +------------------------------------------------------------------------------- =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- Makefile.am 2001/05/07 07:54:39 1.3 +++ Makefile.am 2001/05/08 02:18:01 1.4 @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.3 2001/05/07 07:54:39 mej Exp $ +# $Id: Makefile.am,v 1.4 2001/05/08 02:18:01 mej Exp $ AUTOMAKE_OPTIONS = foreign SUBDIRS = . test @@ -11,7 +11,7 @@ LIBS = -lm -libast_la_LDFLAGS = -version-info 1:0:0 +libast_la_LDFLAGS = -version-info 1:1:0 EXTRA_DIST = README =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/configure.in,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- configure.in 2001/05/07 07:54:39 1.2 +++ configure.in 2001/05/08 02:18:01 1.3 @@ -1,7 +1,7 @@ -dnl# $Id: configure.in,v 1.2 2001/05/07 07:54:39 mej Exp $ +dnl# $Id: configure.in,v 1.3 2001/05/08 02:18:01 mej Exp $ AC_INIT(configure.in) -AM_INIT_AUTOMAKE(libast, 0.1) +AM_INIT_AUTOMAKE(libast, 0.2) AC_DEFINE_UNQUOTED(LIBAST_VERSION, "$VERSION") dnl# Set some basic variables =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/strings.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- strings.c 2001/05/07 07:54:39 1.3 +++ strings.c 2001/05/08 02:18:01 1.4 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: strings.c,v 1.3 2001/05/07 07:54:39 mej Exp $"; +static const char cvs_ident[] = "$Id: strings.c,v 1.4 2001/05/08 02:18:01 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -145,7 +145,7 @@ if (pattern) { if ((result = regcomp(rexp, pattern, REG_EXTENDED)) != 0) { regerror(result, rexp, errbuf, 256); - fprintf(stderr, "Unable to compile regexp %s -- %s.\n", pattern, errbuf); + print_error("Unable to compile regexp %s -- %s.\n", pattern, errbuf); return (FALSE); } } @@ -153,7 +153,7 @@ if (((result = regexec(rexp, str, (size_t) 0, (regmatch_t *) NULL, 0)) != 0) && (result != REG_NOMATCH)) { regerror(result, rexp, errbuf, 256); - fprintf(stderr, "Error testing input string %s -- %s.\n", str, errbuf); + print_error("Error testing input string %s -- %s.\n", str, errbuf); return (FALSE); } return (!result); @@ -173,7 +173,7 @@ if (pattern) { if ((result = regcomp(*rexp, pattern, REG_EXTENDED)) != 0) { regerror(result, *rexp, errbuf, 256); - fprintf(stderr, "Unable to compile regexp %s -- %s.\n", pattern, errbuf); + print_error("Unable to compile regexp %s -- %s.\n", pattern, errbuf); FREE(*rexp); return (FALSE); } @@ -182,7 +182,7 @@ if (((result = regexec(*rexp, str, (size_t) 0, (regmatch_t *) NULL, 0)) != 0) && (result != REG_NOMATCH)) { regerror(result, *rexp, errbuf, 256); - fprintf(stderr, "Error testing input string %s -- %s.\n", str, errbuf); + print_error("Error testing input string %s -- %s.\n", str, errbuf); return (FALSE); } return (!result); @@ -204,21 +204,20 @@ REQUIRE_RVAL(str != NULL, (char **) NULL); - if ((slist = (char **) MALLOC(1)) == NULL) { + if ((slist = (char **) MALLOC(sizeof(char *))) == NULL) { print_error("split(): Unable to allocate memory -- %s\n", strerror(errno)); return ((char **) NULL); } /* Before we do anything, skip leading "whitespace." */ - for (; IS_DELIM(*pstr); pstr++); + for (pstr = str; *pstr && IS_DELIM(*pstr); pstr++); /* The outermost for loop is where we traverse the string. Each new word brings us back to the top where we resize our string list. */ - for (pstr = str; *pstr; cnt++) { - + for (; *pstr; cnt++) { /* First, resize the list to two bigger than our count. Why two? One for the string we're about to do, and one for a trailing NULL. */ - if ((slist = (char **) REALLOC(slist, cnt + 2)) == NULL) { + if ((slist = (char **) REALLOC(slist, sizeof(char *) * (cnt + 2))) == NULL) { print_error("split(): Unable to allocate memory -- %s\n", strerror(errno)); return ((char **) NULL); } @@ -227,15 +226,22 @@ of the string we have yet to parse, so allocate that much space to start. */ len = strlen(pstr) + 1; if ((slist[cnt] = (char *) MALLOC(len)) == NULL) { - fprintf(stderr, "split(): Unable to allocate memory -- %s.\n", strerror(errno)); + print_error("split(): Unable to allocate memory -- %s.\n", strerror(errno)); return ((char **) NULL); } pdest = slist[cnt]; - for (; *pstr && !IS_QUOTE(*pstr) && !IS_DELIM(*pstr); pdest++, pstr++) { + /* This for loop is where we process each character. */ + for (; *pstr && (quote || !IS_DELIM(*pstr));) { if (*pstr == '\"' || *pstr == '\'') { + /* It's a quote character, so set or reset the quote variable. */ if (quote) { - quote = 0; + if (quote == *pstr) { + quote = 0; + } else { + /* It's a single quote inside double quotes, or vice versa. Leave it alone. */ + *pdest++ = *pstr++; + } } else { quote = *pstr; } @@ -247,15 +253,20 @@ below will copy the next character to the new token, no questions asked. */ pstr++; } - *pdest = *pstr; + *pdest++ = *pstr++; } } + /* Add the trailing \0 to terminate the new string. */ *pdest = 0; + + /* Reallocate the new string to be just the right size. */ + len = strlen(slist[cnt]) + 1; + slist[cnt] = (char *) REALLOC(slist[cnt], len); - len = strlen(pdest) + 1; - slist[cnt] = (char *) REALLOC(pdest, len); - for (; IS_DELIM(*pstr); pstr++); + /* Move past any trailing "whitespace." */ + for (; *pstr && IS_DELIM(*pstr); pstr++); } + /* The last element of slist[] should be NULL. */ slist[cnt] = 0; return slist; } @@ -279,7 +290,7 @@ k = strlen(str) + 1; if ((tmpstr = (char *) MALLOC(k)) == NULL) { - fprintf(stderr, "get_word(%lu, %s): Unable to allocate memory -- %s.\n", + print_error("get_word(%lu, %s): Unable to allocate memory -- %s.\n", index, str, strerror(errno)); return ((char *) NULL); } @@ -656,19 +667,19 @@ register unsigned char *ptr; unsigned char buffr[9]; - fprintf(stderr, " Address | Size | Offset | 00 01 02 03 04 05 06 07 | ASCII \n"); - fprintf(stderr, "---------+--------+---------+-------------------------+---------\n"); + print_error(" Address | Size | Offset | 00 01 02 03 04 05 06 07 | ASCII \n"); + print_error("---------+--------+---------+-------------------------+---------\n"); for (ptr = (unsigned char *) buff, j = 0; j < count; j += 8) { - fprintf(stderr, " %8p | %06lu | %07x | ", buff, (unsigned long) count, (unsigned int) j); + print_error(" %8p | %06lu | %07x | ", buff, (unsigned long) count, (unsigned int) j); l = ((count - j < 8) ? (count - j) : (8)); memset(buffr, 0, 9); memcpy(buffr, ptr + j, l); for (k = 0; k < l; k++) { - fprintf(stderr, "%02x ", buffr[k]); + print_error("%02x ", buffr[k]); } for (; k < 8; k++) { - fprintf(stderr, " "); + print_error(" "); } - fprintf(stderr, "| %-8s\n", safe_str((char *) buffr, l)); + print_error("| %-8s\n", safe_str((char *) buffr, l)); } } |