🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Charles Shub Wed, 20 Feb 1991 05:13
I think i'm having a problem with re_cmp and re_exec
#328
Author: Charles Shub
Date: Wed, 20 Feb 1991 05:13
83 lines
2867 bytes
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@boulder.Colorado.EDU  -or-  ..!{ucar|nbires}!boulder!cdash
  or even     cdash@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@boulder.Colorado.EDU  -or-  ..!{ucar|nbires}!boulder!cdash
  or even     cdash@colospgs (BITNET)     -or-  (719) 593-3492
re_comp and re_exec problem solved
#329
Author: Charles Shub
Date: Wed, 20 Feb 1991 17:42
30 lines
1806 bytes
In article <1991Feb20.051351.970@csn.org> I wrote...
=>  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.
=>  
=>  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

There were 3 mail messages this am pointing out the regular expression
was not anchored and the correct expression to pass to re_comp should
be '^u.*' 
Ah the joys of terminal brain fade when you've been hard at it for
some 14 hours, have discovered a bug in some old code, and are thinking
about pattern matching in the context of globbing instead of regular
expression matching.  Thanks to all, and sorry to have wasted the net
bandwidth on something that should have been so obvious.
-- 

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

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads