~ubuntu-branches/ubuntu/wily/styx/wily

« back to all changes in this revision

Viewing changes to libbase/scn_base.c

  • Committer: Package Import Robot
  • Author(s): Frederik Schüler
  • Date: 2013-12-28 18:20:37 UTC
  • mfrom: (0.1.5)
  • Revision ID: package-import@ubuntu.com-20131228182037-ihsf1de5y1oe24nf
Tags: 2.0.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
  symbol     cIndentSym;
162
162
  symbol     cDedentSym;
163
163
  /* pattern token */
 
164
  short      cPatCnt;
164
165
  short      cPatTok;
165
166
  short      cPatGrp;
166
167
  symbol     cPatSym;
706
707
    Sink_printf(snk,"%c",(c_byte)c1);
707
708
    if( *(p+i+3) == '.' )
708
709
    {
709
 
      assert0(i + 9 < len,"invalid start pattern or quotient token ID");
 
710
      assert0(i + 9 <= len,"invalid start pattern or quotient token ID");
710
711
      i += 6;
711
712
      buf[0] = p[i];
712
713
      buf[1] = p[i+1];
907
908
  s->cIndentStack = (ROW(int))NULL;
908
909
  s->cIndentSym   = (symbol)NULL;
909
910
  s->cDedentSym   = (symbol)NULL;
 
911
  s->cPatCnt      = 0;
910
912
  s->cPatTok      = -1;
911
913
  s->cPatGrp      = -1;
912
914
  s->cPatSym      = (symbol)NULL;
1472
1474
  bug2(False,"\'Scn_defTokId(\"%s\",%d)\': Token not seen",Name,tid);
1473
1475
}
1474
1476
 
 
1477
c_bool Stream_hasTokId(Scn_Stream t, string Name)
 
1478
/* whether 'Name' is a token in scan stream 't' */
 
1479
{ int cnt, i, j, g = -1; Scn_Stream_IMP s = (Scn_Stream_IMP)t;
 
1480
  size_t len = strlen(Name);
 
1481
  if( s->cScanner->Groups == 0 )
 
1482
  {
 
1483
    for (i = 1; i < s->cScanner->Tokens; i++)
 
1484
      if (
 
1485
          !strncmp(Name,s->cScanner->TokId[i],len) && 
 
1486
          (s->cScanner->TokId[i][len] == '\0' ||
 
1487
           s->cScanner->TokId[i][len] == SCN_SEP_TOK_ID_PATTERN))
 
1488
      {
 
1489
        return C_True;
 
1490
      }
 
1491
  }
 
1492
  else
 
1493
  { Scn_Stream_IMP x = (Scn_Stream_IMP)Stream_current(t);
 
1494
    if( x->cEmbeds == (ROW(Any_T))NULL || x->Group < 0 )
 
1495
    {
 
1496
      i = 0; cnt = s->cScanner->Groups;
 
1497
      if( (g=s->Group) >= 0 )
 
1498
      {
 
1499
        for (j = 1; j < s->cScanner->GrpScn[g]->Tokens; j++)
 
1500
          if (!strncmp(Name,s->cScanner->GrpScn[g]->TokId[j],len) && 
 
1501
              (s->cScanner->GrpScn[g]->TokId[j][len] == '\0' ||
 
1502
               s->cScanner->GrpScn[g]->TokId[j][len] == SCN_SEP_TOK_ID_PATTERN))
 
1503
          {
 
1504
            return C_True;
 
1505
          }
 
1506
      }
 
1507
    }
 
1508
    else
 
1509
    {
 
1510
      i = x->Group; cnt = x->Group + 1;
 
1511
    }
 
1512
    for ( ; i < cnt; i++)
 
1513
    {
 
1514
      if( i == g ) continue;
 
1515
      for (j = 1; j < s->cScanner->GrpScn[i]->Tokens; j++)
 
1516
        if (
 
1517
            !strncmp(Name,s->cScanner->GrpScn[i]->TokId[j],len) && 
 
1518
            (s->cScanner->GrpScn[i]->TokId[j][len] == '\0' ||
 
1519
             s->cScanner->GrpScn[i]->TokId[j][len] == SCN_SEP_TOK_ID_PATTERN))
 
1520
        {
 
1521
          return C_True;
 
1522
        }
 
1523
    }
 
1524
  }
 
1525
  return C_False;
 
1526
}
 
1527
 
1475
1528
static void setIndTokKey(Scn_Stream t, symbol keysym)
1476
1529
{ Scn_Stream_IMP s = (Scn_Stream_IMP)t;
1477
1530
  long           klen, dlen, ilen;
1522
1575
  }
1523
1576
}
1524
1577
 
 
1578
c_bool Stream_defDynKeyId(Scn_Stream t, symbol keysym, short tid)
 
1579
/* defines 'tid' as number for dynamic keyword 'keysym' in scan stream 't' */
 
1580
{ Scn_Stream_IMP s = (Scn_Stream_IMP)t;
 
1581
  if( !MAP_defined(s->cdefkey,keysym) )
 
1582
  {
 
1583
    MAP_dfndom(s->cdefkey,keysym,(long)tid);
 
1584
    return C_True;
 
1585
  }
 
1586
  return C_False;
 
1587
}
 
1588
 
1525
1589
void Stream_defKeyId(Scn_Stream t, string Text, short tid)
1526
1590
/* defines 'tid' as number for keyword 'Text' in scan stream 't' */
1527
1591
{ Scn_Stream_IMP s      = (Scn_Stream_IMP)t;
1936
2000
      t->cPatGrp = s->Group;
1937
2001
    /* get pattern set */
1938
2002
    pat = symbolToString(MAP_apply(symbol,t->cPatMap,idx));
 
2003
    t->cPatCnt = 0;
1939
2004
    /* get pattern */
1940
2005
    if( *pat != '\0' )
1941
2006
    {
 
2007
      if( pat[1] == '\0' ) t->cPatCnt = 1;
1942
2008
      snk = Sink_open();
1943
2009
      if( s->wc2mb == (string (*)(wc_string wc))NULL )
1944
2010
      { 
1988
2054
    else
1989
2055
    if( s->wc2mb == (string (*)(wc_string wc))NULL )
1990
2056
    {
1991
 
      if( s->cC_eof == 0 && strstr(s->cBuf,pat) != (c_string)NULL )
1992
 
      { /* single byte text mode, pattern found */
1993
 
        s->cTok = t->cPatTok;
1994
 
        if( s->cScanner->Groups > 0 )
1995
 
          Stream_switch_group(t,t->cPatGrp,C_True);
1996
 
        t->cPatSym = (symbol)NULL;
 
2057
      c_string p = NULL;
 
2058
      if( s->cC_eof == 0 && (p=strstr(s->cBuf,pat)) != (c_string)NULL )
 
2059
      { 
 
2060
        if( t->cPatCnt != 1 || *(p+strlen(pat)) != pat[0] )
 
2061
        { /* single byte text mode, pattern found */
 
2062
          s->cTok = t->cPatTok;
 
2063
          if( s->cScanner->Groups > 0 )
 
2064
            Stream_switch_group(t,t->cPatGrp,C_True);
 
2065
          t->cPatSym = (symbol)NULL;
 
2066
        }
1997
2067
      }
1998
2068
      else
1999
2069
      if( s->cC_eof < 0 ) /* binary mode */
2014
2084
              if( flg && s->cBuf[j] != pat[0] ) i=j;
2015
2085
              else flg = C_False;
2016
2086
            }
2017
 
            if( len == k ) /* pattern found */
 
2087
            if( len == k ) 
2018
2088
            {
2019
 
              s->cTok = t->cPatTok;
2020
 
              if( s->cScanner->Groups > 0 )
2021
 
                Stream_switch_group(t,t->cPatGrp,C_True);
2022
 
              t->cPatSym = (symbol)NULL;
2023
 
              break;
 
2089
              if( t->cPatCnt != 1 || j >= s->cLen || s->cBuf[j] != pat[0] )
 
2090
              { /* pattern found */
 
2091
                s->cTok = t->cPatTok;
 
2092
                if( s->cScanner->Groups > 0 )
 
2093
                  Stream_switch_group(t,t->cPatGrp,C_True);
 
2094
                t->cPatSym = (symbol)NULL;
 
2095
                break;
 
2096
              }
2024
2097
            }
2025
2098
          }
2026
2099
        }
2045
2118
            if( flg && c != pat[0] ) i=j;
2046
2119
            else flg = C_False;
2047
2120
          }
2048
 
          if( len == k ) /* pattern found */
 
2121
          if( len == k ) 
2049
2122
          {
2050
 
            s->cTok = t->cPatTok;
2051
 
            if( s->cScanner->Groups > 0 )
2052
 
              Stream_switch_group(t,t->cPatGrp,C_True);
2053
 
            t->cPatSym = (symbol)NULL;
2054
 
            break;
 
2123
            if( t->cPatCnt != 1 || j >= s->cLen || ((char)s->cWBuf[j]) != pat[0] )
 
2124
            { /* pattern found */
 
2125
              s->cTok = t->cPatTok;
 
2126
              if( s->cScanner->Groups > 0 )
 
2127
                Stream_switch_group(t,t->cPatGrp,C_True);
 
2128
              t->cPatSym = (symbol)NULL;
 
2129
              break;
 
2130
            }
2055
2131
          }
2056
2132
        }
2057
2133
      }
2541
2617
      return x->cdeftok[0];
2542
2618
  }
2543
2619
  else
 
2620
  {
 
2621
    if( s->cScanner->Groups > 0 && !strncmp("tok_",s->cScanner->GrpScn[s->Group]->Name,4) )
 
2622
      return x->cdeftok[s->cTok];
2544
2623
    return MAP_defined(x->cdefkey,s->cSym)
2545
2624
           ? MAP_apply_short(x->cdefkey,s->cSym)
2546
2625
           : x->cdeftok[s->cTok];
 
2626
  }
2547
2627
}
2548
2628
 
2549
2629
short Stream_ctid_nokey(Scn_Stream t)