char buf[500]; regerror (n, &re, buf, sizeof (buf)); printf ("regcomp failed: %s\n", buf); exit (1);
n = regcomp (&re, tests[i].pattern, 0); if (n != 0) { char buf[500]; regerror (n, &re, buf, sizeof (buf)); printf ("regcomp %d failed: %s\n", i, buf); ret = 1; continue; }  if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0)) { printf ("regexec %d failed\n", i); ret = 1; regfree (&re); continue; }  for (n = 0; n < tests[i].nmatch; ++n) if (rm[n].rm_so != tests[i].rm[n].rm_so || rm[n].rm_eo != tests[i].rm[n].rm_eo) { if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1) break; printf ("regexec match failure rm[%d] %d..%d\n", n, rm[n].rm_so, rm[n].rm_eo); ret = 1; break; }  regfree (&re);
main (void){  regex_t re;  regmatch_t rm[2];  int n;  mtrace ();  n = regcomp (&re, "[^~]*~", 0);  if (n != 0)    {      char buf[500];      regerror (n, &re, buf, sizeof (buf));      printf ("regcomp failed: %s\n", buf);      exit (1);    }  if (regexec (&re, "\nx~y", 2, rm, 0))    {      puts ("regexec failed");      exit (2);    }  if (rm[0].rm_so != 0 || rm[0].rm_eo != 3)    {      printf ("regexec match failure: %d %d\n",	      rm[0].rm_so, rm[0].rm_eo);      exit (3);    }  regfree (&re);  return 0;}