File: rtest.c

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (30 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>

int match(char *string, char *pattern)
{
  int i;
  regex_t re;
  char buf[256];

  i=regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB);
  if (i != 0) {
    (void)regerror(i,&re,buf,sizeof buf);
    printf("%s\n",buf);
    return(0);                       /* report error */
  }
  i = regexec(&re, string, (size_t) 0, NULL, 0);
  regfree(&re);
  if (i != 0) {
    (void)regerror(i,&re,buf,sizeof buf);
    printf("%s\n",buf);
    return(0);                       /* report error */
  }
  return(1);
}

void main()
{
  printf("%s\n", match("ABCDE", "[A-Z]*") ? "success" : "failure");
}