Branch: Tag:

2015-04-28

2015-04-28 14:36:20 by Martin Nilsson <nilsson@opera.com>

Formatting changes.

347:       /*    * If there's something expensive in the r.e., find the longest -  * literal string that must appear and make it the regmust. Resolve -  * ties in favor of later strings, since the regstart check works -  * with the beginning of the r.e. and avoiding duplication -  * strengthens checking. Not a strong reason, but sufficient in the -  * absence of others. +  * literal string that must appear and make it the regmust. +  * Resolve ties in favor of later strings, since the regstart +  * check works with the beginning of the r.e. and avoiding +  * duplication strengthens checking. Not a strong reason, but +  * sufficient in the absence of others.    */    if (flags & SPSTART) {    char *longest = NULL;
369:       exit_regcomp:    free(exp2); -  return (r); +  return r;   }      /*
377:    *    * Caller must absorb opening parenthesis.    * -  * Combining parenthesis handling with the base level of regular expression -  * is a trifle forced, but the need to tie the tails of the branches to what -  * follows makes it hard to avoid. +  * Combining parenthesis handling with the base level of regular +  * expression is a trifle forced, but the need to tie the tails of the +  * branches to what follows makes it hard to avoid.    */   static char *reg(int paren,int *flagp)   {
392:    *flagp = HASWIDTH; /* Tentatively. */       /* Make an OPEN node, if parenthesized. */ -  if (paren) { +  if (paren) +  {    if (regnpar >= NSUBEXP)    FAIL("too many ()");    parno = regnpar;    regnpar++;    ret = regnode((char)(OPEN + parno)); -  } else +  } +  else    ret = NULL;       /* Pick up the branches, linking them together. */    br = regbranch(&flags);    if (br == NULL) -  return (NULL); +  return NULL;    if (ret != NULL)    regtail(ret, br); /* OPEN -> first. */    else
418:    regparse++;    br = regbranch(&flags);    if (br == NULL) -  return (NULL); +  return NULL;    regtail(ret, br); /* BRANCH -> BRANCH. */    if (!(flags & HASWIDTH))    *flagp &= ~HASWIDTH;
434:    regoptail(br, ender);       /* Check for proper termination. */ -  if (paren && *regparse++ != RBRAC) { +  if (paren && *regparse++ != RBRAC) +  {    FAIL("unmatched ()"); -  } else if (!paren && *regparse != '\0') { -  if (*regparse == RBRAC) { +  } +  else if (!paren && *regparse != '\0') +  { +  if (*regparse == RBRAC) +  {    FAIL("unmatched ()"); -  } else +  } +  else    FAIL("junk on end");/* "Can't happen". */    /* NOTREACHED */    }    -  return (ret); +  return ret;   }      /*
466:    while (*regparse != '\0' && *regparse != OR_OP && *regparse != RBRAC) {    latest = regpiece(&flags);    if (latest == NULL) -  return (NULL); +  return NULL;    *flagp |= flags & HASWIDTH;    if (chain == NULL) /* First piece. */    *flagp |= flags & SPSTART;
477:    if (chain == NULL) /* Loop ran zero times. */    regnode(NOTHING);    -  return (ret); +  return ret;   }      /*    - regpiece - something followed by possible [*] or [+]    * -  * Note that the branching code sequence used for * is somewhat optimized: -  * they use the same NOTHING node as both the endmarker for their branch -  * list and the body of the last branch. It might seem that this node could -  * be dispensed with entirely, but the endmarker role is not redundant. +  * Note that the branching code sequence used for * is somewhat +  * optimized: they use the same NOTHING node as both the endmarker for +  * their branch list and the body of the last branch. It might seem +  * that this node could be dispensed with entirely, but the endmarker +  * role is not redundant.    */   static char *regpiece(int *flagp)   {
496:       ret = regatom(&flags);    if (ret == NULL) -  return (NULL); +  return NULL;       op = *regparse;    if (!ISMULT(op)) {    *flagp = flags; -  return (ret); +  return ret;    }       /* FIXME: + can not be empty */
553:    if (ISMULT(*regparse))    FAIL("nested * or +");    -  return (ret); +  return ret;   }         /*    - regatom - the lowest level    * -  * Optimization: gobbles an entire sequence of ordinary characters so that -  * it can turn them into a single node, which is smaller to store and -  * faster to run. +  * Optimization: gobbles an entire sequence of ordinary characters so +  * that it can turn them into a single node, which is smaller to store +  * and faster to run.    */   static char *regatom(int *flagp)   {
571:       *flagp = WORST; /* Tentatively. */    -  switch (*regparse++) { +  switch (*regparse++) +  {    case CARET:    ret = regnode(BOL);    break;
588:    case RSHBRAC:    ret = regnode(WORDEND);    break; -  case LSQBRAC:{ -  int range; -  int rangeend; +  case LSQBRAC: +  { +  int range; +  int rangeend;    -  if (*regparse == CARET) { /* Complement of range. */ +  if (*regparse == CARET) +  { +  /* Complement of range. */    ret = regnode(ANYBUT);    regparse++; -  } else +  } +  else    ret = regnode(ANYOF);       if (*regparse == RSQBRAC || *regparse == '-')    regc((char)(*regparse++));    -  while (*regparse != '\0' && *regparse != RSQBRAC) { -  if (*regparse == '-') { +  while (*regparse != '\0' && *regparse != RSQBRAC) +  { +  if (*regparse == '-') +  {    regparse++;    if (*regparse == RSQBRAC || *regparse == '\0')    regc('-'); -  else { +  else +  {    range = (CHARBITS & *(regparse - 2));    rangeend = (CHARBITS & *(regparse));    if (range > rangeend)
615:    regc((char)range);    regparse++;    } -  } else +  } +  else    regc((char)(*regparse++));    }    regc('\0');
625:    *flagp |= HASWIDTH | SIMPLE;    }    break; +     case LBRAC:    ret = reg(1, &flags);    if (ret == NULL) -  return (NULL); +  return NULL;    *flagp |= flags & (HASWIDTH | SPSTART);    break; -  +     case '\0':    case OR_OP:    case RBRAC:    FAIL("internal urp"); /* Supposed to be caught earlier. */ -  +  break;       case PLUS:    case ASTERIX:    FAIL("*/+ follows nothing\n"); -  +  break;    -  default:{ +  default: +  {    size_t len;    short ender;   
664:    break;    }    -  return (ret); +  return ret;   }      /*
677:       if (ret == regdummy) {    regsize += 3; -  return (ret); +  return ret;    }       ptr = ret;
686:    *ptr++ = '\0';    regcode = ptr;    -  return (ret); +  return ret;   }      /*
707:    */   static void reginsert(char op, char *opnd)   { -  char *place; +  char *place;    -  if (regcode == regdummy) { +  if (regcode == regdummy) +  {    regsize += 3;    return;    }
773:   /*    * Forwards.    */ - static int regtry(regexp *, char *); - static int regmatch(char *); - static size_t regrepeat(const char *); + static int regtry(regexp *, char *); + static int regmatch(char *); + static size_t regrepeat(const char *);      #ifdef PIKE_DEBUG - int regnarrate = 0; - void regdump(regexp *); - static char *regprop(char *op); + int regnarrate = 0; + void regdump(regexp *); + static char *regprop(char *op);   #endif      /*
793:    /* Be paranoid... */    if (prog == NULL || string == NULL) {    regerror("NULL parameter"); -  return (0); +  return 0;    }       /* If there is a "must appear" string, look for it. */    if (prog->regmust != NULL && strstr(string, prog->regmust) == NULL) -  return(0); +  return 0;       /* Mark beginning of line for ^ . */    regbol = string;       /* Simplest case: anchored match need be tried only once. */    if (prog->reganch) -  return (regtry(prog, string)); +  return regtry(prog, string);       /* Messy cases: unanchored match. */    s = string;
814:    /* We know what char it must start with. */    for (s = string; s != NULL; s = strchr(s+1, prog->regstart))    if (regtry(prog, s)) -  return(1); -  return(0); +  return 1; +  return 0;    }    else    {    /* We don't -- general case. */    for (s = string; !regtry(prog, s); s++)    if (*s == '\0') -  return(0); -  return(1); +  return 0; +  return 1;    }       /* NOTREACHED */ -  return (0); +  return 0;   }      /*
845:       stp = prog->startp;    enp = prog->endp; -  for (i = NSUBEXP; i > 0; i--) { +  for (i = NSUBEXP; i > 0; i--) +  {    *stp++ = NULL;    *enp++ = NULL;    } -  if (regmatch(prog->program)) { +  if (regmatch(prog->program)) +  {    prog->startp[0] = string;    prog->endp[0] = reginput; -  return (1); -  } else -  return (0); +  return 1;    }    -  +  return 0; + } +    /*    - regmatch - main matching routine    *
879: Inside #if defined(PIKE_DEBUG)
   if (scan != NULL && regnarrate)    fprintf(stderr, "%s(\n", regprop(scan));   #endif -  while (scan != NULL) { +  +  while (scan != NULL) +  {   #ifdef PIKE_DEBUG    if (regnarrate)    fprintf(stderr, "%s...\n", regprop(scan));   #endif    next = regnext(scan);    -  switch (OP(scan)) { +  switch (OP(scan)) +  {    case BOL:    if (reginput != regbol) -  return (0); +  return 0;    break; -  +     case EOL:    if (*reginput != '\0') -  return (0); +  return 0;    break; -  +     case ANY:    if (*reginput == '\0') -  return (0); +  return 0;    reginput++;    break; -  +     case WORDSTART:    if (reginput == regbol)    break;    if (*reginput == '\0' ||    ISWORDPART( *((unsigned char *)reginput-1) ) ||    !ISWORDPART( *((unsigned char *)reginput) ) ) -  return (0); +  return 0;    break; -  +     case WORDEND:    if (*reginput == '\0')    break;    if ( reginput == regbol ||    !ISWORDPART( *((unsigned char *)reginput-1) ) ||    ISWORDPART( *((unsigned char *)reginput) ) ) -  return (0); +  return 0;    break; -  case EXACTLY:{ +  +  case EXACTLY: +  {    ptrdiff_t len;    char *opnd;       opnd = OPERAND(scan);    /* Inline the first character, for speed. */    if (*opnd != *reginput) -  return (0); +  return 0;    len = strlen(opnd);    if (len > 1 && strncmp(opnd, reginput, len) != 0) -  return (0); +  return 0;    reginput += len;    }    break; -  +     case ANYOF:    if (*reginput == '\0' ||    strchr(OPERAND(scan), *reginput) == NULL) -  return (0); +  return 0;    reginput++;    break; -  +     case ANYBUT:    if (*reginput == '\0' ||    strchr(OPERAND(scan), *reginput) != NULL) -  return (0); +  return 0;    reginput++;    break; -  +     case NOTHING:    break;    case BACK:    break;    -  case BRANCH:{ +  case BRANCH: +  {    if (OP(next) != BRANCH) /* No choice. */    next = OPERAND(scan); /* Avoid recursion. */ -  else { +  else +  {    /* FIXME: This loop is different upstream. */    char *save = reginput; -  do { +  do +  {    if (regmatch(OPERAND(scan))) -  return (1); +  return 1;    reginput = save;    scan = regnext(scan);    } while (scan != NULL && OP(scan) == BRANCH); -  return (0); +  return 0;    /* NOTREACHED */    }    }    break; -  +     case KPLUS: -  case STAR:{ +  case STAR: +  {    char nextch =    (OP(next) == EXACTLY) ? *OPERAND(next) : '\0';    size_t no;
977:    /* If it could work, try it. */    if (nextch == '\0' || *reginput == nextch)    if (regmatch(next)) -  return (1); +  return 1;    } -  return (0); +  return 0;    }       case END: -  return (1); /* Success! */ +  return 1; /* Success! */       default:    if(OP(scan) >= OPEN && OP(scan)<OPEN+NSUBEXP)
991:    int no = OP(scan) - OPEN;    char *input = reginput;    -  if (regmatch(next)) { +  if (regmatch(next)) +  {    /*    * Don't set startp if some later invocation of the same    * parentheses already has.    */    if (regstartp[no] == NULL)    regstartp[no] = input; -  return (1); +  return 1;    } else -  return (0); +  return 0;    }       if(OP(scan) >= CLOSE && OP(scan)<CLOSE+NSUBEXP)
1008:    int no = OP(scan) - CLOSE;    char *input = reginput;    -  if (regmatch(next)) { +  if (regmatch(next)) +  {    /*    * Don't set endp if some later invocation of the same    * parentheses already has.    */    if (regendp[no] == NULL)    regendp[no] = input; -  return (1); -  } else -  return (0); +  return 1;    } -  +  else +  return 0; +  }    regerror("memory corruption"); -  return (0); -  +  return 0;    } -  +     scan = next;    }   
1032:    * terminating point.    */    regerror("corrupted pointers"); -  return (0); +  return 0;   }      /*
1040:    */   static size_t regrepeat(const char *node)   { -  switch (OP(node)) { +  switch (OP(node)) +  {    case ANY:    return(strlen(reginput));    break; -  +     case EXACTLY:    {    char *scan;
1052:       for (scan = reginput; *scan == ch; scan++)    count++; -  return(count); +  return count;    }    break; -  +     case ANYOF: -  return(strspn(reginput, OPERAND(node))); +  return strspn(reginput, OPERAND(node));    break; -  +     case ANYBUT: -  return(strcspn(reginput, OPERAND(node))); +  return strcspn(reginput, OPERAND(node));    break; -  +     default: /* Oh dear. Called inappropriately. */    regerror("internal foulup"); -  return(0); /* Best compromise. */ +  return 0; /* Best compromise. */    break;    }    /* NOREACHED */
1075:    */   static char *regnext(char *p)   { -  int offset = NEXT(p); +  int offset = NEXT(p);       if (offset == 0) -  return (NULL); +  return NULL;       if (OP(p) == BACK)    return (p - offset);
1088: Inside #if defined(PIKE_DEBUG)
     #ifdef PIKE_DEBUG    - static char *regprop(char *); + static char *regprop(char *);      /*    - regdump - dump a regexp onto stdout in vaguely comprehensible form