home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d156 / flex.lha / Flex / CommonFiles / ccl.c next >
C/C++ Source or Header  |  1988-10-02  |  2KB  |  110 lines

  1. /* ccl - routines for character classes */
  2.  
  3. /*
  4.  * Copyright (c) 1987, the University of California
  5.  * 
  6.  * The United States Government has rights in this work pursuant to
  7.  * contract no. DE-AC03-76SF00098 between the United States Department of
  8.  * Energy and the University of California.
  9.  * 
  10.  * This program may be redistributed.  Enhancements and derivative works
  11.  * may be created provided the new works, if made available to the general
  12.  * public, are made available for use by anyone.
  13.  */
  14.  
  15. #include "flexdef.h"
  16.  
  17. /* ccladd - add a single character to a ccl
  18.  *
  19.  * synopsis
  20.  *    int cclp;
  21.  *    char ch;
  22.  *    ccladd( cclp, ch );
  23.  */
  24.  
  25. ccladd( cclp, ch )
  26. int cclp;
  27. char ch;
  28.  
  29.     {
  30.     int ind, len, newpos, i;
  31.  
  32.     len = ccllen[cclp];
  33.     ind = cclmap[cclp];
  34.  
  35.     /* check to see if the character is already in the ccl */
  36.  
  37.     for ( i = 0; i < len; ++i )
  38.     if ( ccltbl[ind + i] == ch )
  39.         return;
  40.  
  41.     newpos = ind + len;
  42.  
  43.     if ( newpos >= current_max_ccl_tbl_size )
  44.     {
  45.     current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;
  46.  
  47.     ++num_reallocs;
  48.  
  49.     ccltbl = reallocate_character_array( ccltbl, current_max_ccl_tbl_size );
  50.     }
  51.  
  52.     ccllen[cclp] = len + 1;
  53.     ccltbl[newpos] = ch;
  54.     }
  55.  
  56.  
  57. /* cclinit - make an empty ccl
  58.  *
  59.  * synopsis
  60.  *    int cclinit();
  61.  *    new_ccl = cclinit();
  62.  */
  63.  
  64. int cclinit()
  65.  
  66.     {
  67.     if ( ++lastccl >= current_maxccls )
  68.     {
  69.     current_maxccls += MAXCCLS_INCREMENT;
  70.  
  71.     ++num_reallocs;
  72.  
  73.     cclmap = reallocate_integer_array( cclmap, current_maxccls );
  74.     ccllen = reallocate_integer_array( ccllen, current_maxccls );
  75.     cclng = reallocate_integer_array( cclng, current_maxccls );
  76.     }
  77.  
  78.     if ( lastccl == 1 )
  79.     /* we're making the first ccl */
  80.     cclmap[lastccl] = 0;
  81.  
  82.     else
  83.     /* the new pointer is just past the end of the last ccl.  Since
  84.      * the cclmap points to the \first/ character of a ccl, adding the
  85.      * length of the ccl to the cclmap pointer will produce a cursor
  86.      * to the first free space
  87.      */
  88.     cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1];
  89.  
  90.     ccllen[lastccl] = 0;
  91.     cclng[lastccl] = 0;    /* ccl's start out life un-negated */
  92.  
  93.     return ( lastccl );
  94.     }
  95.  
  96.  
  97. /* cclnegate - negate a ccl
  98.  *
  99.  * synopsis
  100.  *    int cclp;
  101.  *    cclnegate( ccl );
  102.  */
  103.  
  104. cclnegate( cclp )
  105. int cclp;
  106.  
  107.     {
  108.     cclng[cclp] = 1;
  109.     }
  110.