All pastes #1429831 Raw Edit

Popz

public cpp v1 · immutable
#1429831 ·published 2009-05-21 12:09 UTC
rendered paste body
static const unsigned char *unpackedstring(const unsigned char *lptr,int *flags){  unsigned char *stringize;  int instring=1;  if (*flags & STRINGIZE)                 /* ignore leading spaces after the # */    while (*lptr==' ' || *lptr=='\t')     /* this is as defines with parameters may add them */      lptr++;                             /* when you use a space after , in a match pattern */  while (*lptr!='\0') {    if (*lptr=='\a') {      lptr++;      continue;    } /* if */    if (!instring) {      if (*lptr=='\"') {        instring=1;      } else if (*lptr=='#') {        while (*++lptr==' ' || *lptr=='\t');        lptr--;        instring=1;        *flags |= STRINGIZE;      } else if (*lptr==')' || *lptr==',' || *lptr=='}' || *lptr==';') {        break;      } else if (*lptr!=' ' && *lptr!='\t') {        error(1,"-string end-","-identifier-");        break;      }      lptr++;      continue;    }    if (*flags & STRINGIZE) {      stringize=lptr; /* check we're still in a valid stringize string */      while (*stringize==' ' || *stringize=='\t')        stringize++; /* find next non space */      if (*stringize=='#') { /* new stringize string */        lptr=stringize+1;        while (*lptr==' ' || *lptr=='\t')          lptr++;        continue;      } else if (*stringize=='\"') { /* new string */        lptr=stringize+1;        *flags &= ~STRINGIZE;        continue;      } else if (*stringize==',' || *stringize==')' || *stringize=='}' || *stringize==';') { /* end */        lptr=stringize;        break;      } else if (*stringize=='\0') {        lptr=stringize;        *flags &= ~STRINGIZE; /* shouldn't happen - trigger an error */        break;      }    } else {      if (*lptr=='\"') {        stringize=lptr++;        instring=0;        continue;      } /* if (*flags & STRINGIZE) */    }    litadd(litchar(&lptr,*flags | UTF8MODE));  /* litchar() alters "lptr" */  } /* while */  litadd(0);    if (*lptr==',' || *lptr==')' || *lptr=='}' || *lptr==';')    lptr=stringize;						/* backtrack to end of last string for closing " */  return lptr;}static const unsigned char *packedstring(const unsigned char *lptr,int *flags){  int i;  ucell val,c;  unsigned char *stringize;  int instring=1;  if (*flags & STRINGIZE)                         while (*lptr==' ' || *lptr=='\t')      lptr++;  i=sizeof(ucell)-(sCHARBITS/8); /* start at most significant byte */  val=0;  while (*lptr!='\0') {    if (*lptr=='\a') {          /* ignore '\a' (which was inserted at a line concatenation) */      lptr++;      continue;    } /* if */    if (!instring) {      if (*lptr=='\"') {        instring=1;      } else if (*lptr=='#') {        while (*++lptr==' ' || *lptr=='\t');        lptr--;        instring=1;        *flags |= STRINGIZE;      } else if (*lptr==')' || *lptr==',' || *lptr=='}' || *lptr==';') {        break;      } else if (*lptr!=' ' && *lptr!='\t') {        error(1,"-string end-","-identifier-");        break;      }      lptr++;      continue;    }    if (*flags & STRINGIZE) {      stringize=lptr; /* check we're still in a valid stringize string */      while (*stringize==' ' || *stringize=='\t')        stringize++; /* find next non space */      if (*stringize=='#') { /* new stringize string */        lptr=stringize+1;        while (*lptr==' ' || *lptr=='\t')          lptr++;        continue;      } else if (*stringize=='\"') { /* new string */        lptr=stringize+1;        *flags &= ~STRINGIZE;        continue;      } else if (*stringize==',' || *stringize==')' || *stringize=='}' || *stringize==';') { /* end */        lptr=stringize;        break;      } else if (*stringize=='\0') {        lptr=stringize;        *flags &= ~STRINGIZE; /* shouldn't happen - trigger an error */        break;      }    } else {      if (*lptr=='\"') {        stringize=lptr++;        instring=0;        continue;      } /* if (*flags & STRINGIZE) */    }    c=litchar(&lptr,*flags);     /* litchar() alters "lptr" */    if (c>=(ucell)(1 << sCHARBITS))      error(43);                /* character constant exceeds range */    val |= (c << 8*i);    if (i==0) {      litadd(val);      val=0;    } /* if */    i=(i+sizeof(ucell)-(sCHARBITS/8)) % sizeof(ucell);  } /* while */  /* save last code; make sure there is at least one terminating zero character */  if (i!=(int)(sizeof(ucell)-(sCHARBITS/8)))    litadd(val);        /* at least one zero character in "val" */  else    litadd(0);          /* add full cell of zeros */  if (*lptr==',' || *lptr==')' || *lptr=='}' || *lptr==';')    lptr=stringize;						/* backtrack to end of last string for closing " */  return lptr;}