"Fossies" - the Fresh Open Source Software Archive

Member "scalpel-2.0/tre-0.7.5-win32/tests/randtest.c" (20 Apr 2011, 2047 Bytes) of archive /linux/misc/scalpel-2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "randtest.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2   randtest.c - tests with random regexps
    3 
    4   Copyright (c) 2001-2006 Ville Laurikari <vl@iki.fi>.
    5 
    6   This software is free; you can redistribute it and/or modify it
    7   under the terms of the GNU Lesser General Public License as
    8   published by the Free Software Foundation; either version 2.1 of the
    9   License, or (at your option) any later version.
   10 
   11   This software is distributed in the hope that it will be useful,
   12   but WITHOUT ANY WARRANTY; without even the implied warranty of
   13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14   Lesser General Public License for more details.
   15 
   16   You should have received a copy of the GNU Lesser General Public
   17   License along with this software; if not, write to the Free Software
   18   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19 
   20 */
   21 
   22 #ifdef HAVE_CONFIG_H
   23 #include <config.h>
   24 #endif /* HAVE_CONFIG_H */
   25 
   26 #include <stdio.h>
   27 #include <stdlib.h>
   28 #include <string.h>
   29 #include <regex.h>
   30 #include <time.h>
   31 
   32 #undef MALLOC_DEBUGGING
   33 #ifdef MALLOC_DEBUGGING
   34 #include "xmalloc.h"
   35 #endif /* MALLOC_DEBUGGING */
   36 
   37 #define REGEXP_MAX_LEN 16
   38 
   39 int
   40 main(int argc, char **argv)
   41 {
   42   int len, i, flags, n;
   43   char regex[50];
   44   char *buf;
   45   regex_t preg;
   46   int status, seed;
   47 
   48   seed = time(NULL);
   49   seed = 1028358583;
   50   printf("seed = %d\n", seed);
   51   srand(seed);
   52   n = 0;
   53 
   54   for (n = 0; n < 0; n++)
   55     rand();
   56 
   57   while (1)
   58     {
   59       printf("*");
   60       fflush(stdout);
   61 
   62       printf("n = %d\n", n);
   63       len = 1 + (int)(REGEXP_MAX_LEN * (rand() / (RAND_MAX + 1.0)));
   64       n++;
   65 
   66       for (i = 0; i < len; i++)
   67     {
   68       regex[i] = 1 + (int)(255 * (rand() / (RAND_MAX + 1.0)));
   69       n++;
   70     }
   71       regex[i] = L'\0';
   72 
   73       printf("len = %d, regexp = \"%s\"\n", len, regex);
   74 
   75       for (flags = 0;
   76        flags < (REG_EXTENDED | REG_ICASE | REG_NEWLINE | REG_NOSUB);
   77        flags++)
   78     {
   79       buf = malloc(sizeof(*buf) * len);
   80       strncpy(buf, regex, len - 1);
   81       status = regncomp(&preg, buf, len, flags);
   82       if (status == REG_OK)
   83         regfree(&preg);
   84     }
   85       printf("\n");
   86     }
   87 
   88   return 0;
   89 }