home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp / 12707 < prev    next >
Encoding:
Text File  |  1992-11-09  |  1.9 KB  |  65 lines

  1. Path: sparky!uunet!news.tek.com!uw-beaver!cs.ubc.ca!destroyer!caen!sdd.hp.com!decwrl!olivea!pagesat!spssig.spss.com!news.oc.com!mercury.unt.edu!usenet
  2. From: cpearce@nemesis.acs.unt.edu
  3. Newsgroups: comp.sys.hp
  4. Subject: Problems with regcomp() and regexec()
  5. Message-ID: <1992Nov9.165816.7162@mercury.unt.edu>
  6. Date: 9 Nov 92 16:58:16 GMT
  7. Sender: usenet@mercury.unt.edu (UNT USENet Adminstrator)
  8. Organization: University of North Texas
  9. Lines: 54
  10.  
  11. HPUX 8.0, HP 9000/425
  12.  
  13. I'm currently trying to use the regular expression routines newly provided
  14. in HPUX 8.0. As far as I can tell, I'm using the routines properly, but
  15.  
  16.     * I'm never able to get a full-line match and
  17.     * Subexpressions don't seem to be behaving properly.
  18.  
  19. But it could just be a stupid mistake on my part also. :)
  20.  
  21. Here's the structure of my program...
  22.  
  23. #include <regex.h>
  24.  
  25. regex_t r1, r2;
  26.  
  27. void init()
  28. {
  29.     regcomp (&r1, "^ *#keyword *$", REG_EXTENDED);
  30.     regcomp (&r2, "^ *#keyword +([^ ]+) *$", REG_EXTENDED);
  31. }
  32.  
  33. void match()
  34. {
  35.     f = fopen (args...)
  36.  
  37.     while (!feof (f)) {
  38.         fgets (str, 255, f);
  39.         if (regexec (&r1, str, r1.re_nsub, rm, NULL))
  40.             printf ("Mathced.\n");
  41.         if (regexec (&r2, str, r2.re_nsub, rm, NULL))
  42.             printf (Matched. sp = %x; ep = %x\n", rm [1].sp, rm [2].ep);
  43.     }
  44. }
  45.  
  46. main ()
  47. {
  48.     init ();
  49.     match ();
  50. }
  51.  
  52. I stripped all the error code out... I also forgot to declare some variables
  53. above. str is char [255]. rm is regmatch_t [2].
  54.  
  55. If I use full-line matching (where the regexp is "^...$" I never return any
  56. matches. By removing the full-line matching, I begin to get matches, but
  57. rm [1].sp and rm [1].ep are equal -- no subexpression is returned.
  58.  
  59. The regular expressions themselves are supposed to match a keyword or
  60. a keyword and an argument. Whitespace is ignored.
  61.  
  62. Am I making a fundamental error somewhere?
  63. --
  64. Chris Pearce, cpearce@nemesis.acs.unt.edu
  65.