I think i'm having a problem with re_cmp and re_exec

Charles Shub cdash at mumm.colorado.edu
Wed Feb 20 16:13:51 AEST 1991


Have I found a bug in re_cmp and re_exec?  If so, is there a fix??
if not, what am I doing wrong
please respond by mail as I do not subscribe to this group.
The problem seems to be in matching files with an input of <letter>*
I get a random match in this case.

charlie shub  cdash at boulder.Colorado.EDU  -or-  ..!{ucar|nbires}!boulder!cdash
  or even     cdash at colospgs (BITNET)     -or-  (719) 593-3492

Execution output
------------------------------
bug m*
enter a string >u*
'u*' 'u.*'  'moutgoing'  found 1
------------------------------
 ^    ^      ^
 |    |      -------  file matched by re_exec
 |    --------------  string fed to re_comp
 -------------------  input string

The directory has  42 entries including the following:

bulgren   
csu 
moutgoing
upe

Source code below (culled from huge program, recompiled, and run)

it is running on a microvax with 4.3 + nfs
------------------------------
#include <pwd.h>
#include <sys/types.h>
#include <strings.h>
#include <sys/dir.h>
main()
{
        DIR *dirp;
        struct direct *dp;
        char com[256], lstr[256];
        char *re_comp(), *ap, *lp;
        int found = 0;

        printf("enter a string >");
        gets(com);
        ap = com;
        lp = lstr;
        while (*ap) {
                if(*ap == '*') {
                        *lp++ = '.';
                        *lp++ = *ap++;
                }
                else {
                        *lp++ = *ap++;
                }
        }
        *lp = '\0';
        printf("'%s' '%s' ",com, lstr);
        if(ap = re_comp(lstr)) {
            printf("'%s' error %s",lp,ap);
        }
        else {
            int zz;
            dirp = opendir(".");
            while ((dp = readdir(dirp)) != NULL && !found) {
                if((zz = re_exec(dp->d_name)) < 0) {
                    printf("re_exec error");
                    break;
                }
                else if (zz) {
                    found = 1;
                    printf(" '%s' ",dp->d_name);
                }
            }
            closedir(dirp);
        }
        printf(" found %d\n",found);
}
------------------------------
-- 

charlie shub  cdash at boulder.Colorado.EDU  -or-  ..!{ucar|nbires}!boulder!cdash
  or even     cdash at colospgs (BITNET)     -or-  (719) 593-3492



More information about the Comp.unix.wizards mailing list