strspn [was: 0.11.1 debian failures]
David Relson
relson at osagesoftware.com
Sun Mar 16 15:36:03 CET 2003
At 03:27 AM 3/16/03, Clint Adams wrote:
> > I was just mucking around and have a t.strspn test that you can add. It's
> > the usual t.strspn script and a strspn.c code file.
> >
> > Are you interested? Should I send you a patch, add it to cvs? Other?
>
>Whatever's convenient for you. If I can send a small testcase to the
>toolchain guys, it will probably speed things up.
Clint,
Attached is a patch for directory bogofilter/src/tests that adds t.strspn
and strspn.c. As I think about it, what you really want is a standalone
test. I think you can create that by a couple of small changes to
t.strspn. First delete the reference to t.frame, then add the appropriate
gcc command (which you can cut/paste from the S390 test log).
David
-------------- next part --------------
--- tests/Makefile.am 2003-03-16 09:22:15.000000000 -0500
+++ tests-strspn/Makefile.am 2003-03-16 09:27:49.000000000 -0500
@@ -2,13 +2,14 @@
SUBDIRS=. bogoutil bogofilter
-check_PROGRAMS=dehex spam_header_name dumbhead deqp deb64 escnp abortme
+check_PROGRAMS=dehex spam_header_name dumbhead deqp deb64 escnp abortme strspn
dehex_SOURCES=dehex.c
dumbhead_SOURCES=dumbhead.c
deqp_SOURCES=deqp.c
deb64_SOURCES=deb64.c
escnp_SOURCES=escnp.c
spam_header_name_SOURCES=spam_header_name.c
+strspn_SOURCES=strspn.c
AM_CPPFLAGS = -I$(srcdir)/..
AM_LDFLAGS = -L..
@@ -20,7 +21,8 @@
t.lexer t.abort \
t.lock1 t.lock2 \
t.nullstatsprefix \
- t.score1 t.score2
+ t.score1 t.score2 \
+ t.strspn
TESTS=$(TESTSCRIPTS)
--- tests/strspn.c 1969-12-31 19:00:00.000000000 -0500
+++ tests-strspn/strspn.c 2003-03-13 13:42:37.000000000 -0500
@@ -0,0 +1,135 @@
+/* $Id: deqp.c,v 1.2 2003/02/06 17:19:46 relson Exp $ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "common.h"
+
+#define MAXBUFFLEN 200
+
+bool simple_test(const char *fname);
+bool read_config_file(const char *fname); /* , bool tilde_expand, bool warn_on_error */
+
+bool simple_test(const char *fname)
+{
+ bool error = false;
+ int lineno = 0;
+ FILE *fp;
+ char *arg = NULL, *val = NULL;
+
+ fp = fopen(fname, "r");
+
+ if (fp == NULL) {
+ fprintf(dbgout, "Cannot open %s: %s\n", fname, strerror(errno));
+ return false;
+ }
+
+ fprintf(dbgout, "Reading %s\n", fname);
+
+ while (!feof(fp))
+ {
+ const char delim[] = " \t=";
+ size_t len;
+ char buff[MAXBUFFLEN];
+
+ memset(buff, '\0', sizeof(buff)); /* for debugging */
+
+ lineno += 1;
+ if (fgets(buff, sizeof(buff), fp) == NULL)
+ break;
+ len = strlen(buff);
+
+ fprintf(dbgout, "Testing: %s\n", buff);
+
+ arg = buff;
+ if (strcspn(arg, delim) < strlen(arg)) { /* if delimiter present */
+ val = arg + strcspn(arg, delim);
+ *val++ = '\0';
+ val += strspn(val, delim);
+ }
+
+ }
+
+ (void)fclose(fp); /* we're just reading, so fclose should succeed */
+
+ return (error);
+}
+
+bool read_config_file(const char *fname) /* , bool tilde_expand, bool warn_on_error */
+{
+ bool error = false;
+ int lineno = 0;
+ FILE *fp;
+ char *filename;
+ char *arg = NULL, *val = NULL;
+
+ filename = strdup(fname);
+
+ fp = fopen(filename, "r");
+
+ if (fp == NULL) {
+ if (DEBUG_CONFIG(0)) {
+ fprintf(dbgout, "Cannot open %s: %s\n", filename, strerror(errno));
+ }
+ free(filename);
+ return false;
+ }
+
+ if (DEBUG_CONFIG(0))
+ fprintf(dbgout, "Reading %s\n", filename);
+
+ while (!feof(fp))
+ {
+ const char delim[] = " \t=";
+ size_t len;
+ char buff[MAXBUFFLEN];
+
+ memset(buff, '\0', sizeof(buff)); /* for debugging */
+
+ lineno += 1;
+ if (fgets(buff, sizeof(buff), fp) == NULL)
+ break;
+ len = strlen(buff);
+ if ( buff[0] == '#' || buff[0] == ';' || buff[0] == '\n' )
+ continue;
+ while (iscntrl((unsigned char)buff[len-1]) || isspace((unsigned char)buff[len-1]))
+ buff[--len] = '\0';
+
+ if (DEBUG_CONFIG(1))
+ fprintf(dbgout, "Testing: %s\n", buff);
+
+ arg = buff;
+ if (strcspn(arg, delim) < strlen(arg)) { /* if delimiter present */
+ val = arg + strcspn(arg, delim);
+ *val++ = '\0';
+ val += strspn(val, delim);
+ } else {
+ val = NULL;
+ }
+
+ }
+
+ if (ferror(fp)) {
+ fprintf(stderr, "Read error while reading file \"%s\".", filename);
+ error = true;
+ }
+
+ (void)fclose(fp); /* we're just reading, so fclose should succeed */
+ free(filename);
+
+ return (error);
+}
+
+int main( int argc, char **argv)
+{
+ dbgout = stdout;
+
+ if (argc == 1)
+ simple_test( "strspn.cf" );
+ else
+ read_config_file( argv[1] ); /* , true, false */
+ return 0;
+}
--- tests/t.strspn 1969-12-31 19:00:00.000000000 -0500
+++ tests-strspn/t.strspn 2003-03-11 20:51:02.000000000 -0500
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+. ${srcdir:=.}/t.frame
+
+CONFIG=strspn.cf
+
+cat <<EOF > ${CONFIG}
+robx=0.415
+min_dev=1.0
+replace_nonascii_characters=Y
+EOF
+
+strspn
+strspn ${CONFIG}
More information about the bogofilter-dev
mailing list