Annotation of 43BSDReno/pgrm/lex/ccl.c, revision 1.1

1.1     ! root        1: /*-
        !             2:  * Copyright (c) 1990 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Vern Paxson.
        !             7:  * 
        !             8:  * The United States Government has rights in this work pursuant
        !             9:  * to contract no. DE-AC03-76SF00098 between the United States
        !            10:  * Department of Energy and the University of California.
        !            11:  *
        !            12:  * Redistribution and use in source and binary forms are permitted provided
        !            13:  * that: (1) source distributions retain this entire copyright notice and
        !            14:  * comment, and (2) distributions including binaries display the following
        !            15:  * acknowledgement:  ``This product includes software developed by the
        !            16:  * University of California, Berkeley and its contributors'' in the
        !            17:  * documentation or other materials provided with the distribution and in
        !            18:  * all advertising materials mentioning features or use of this software.
        !            19:  * Neither the name of the University nor the names of its contributors may
        !            20:  * be used to endorse or promote products derived from this software without
        !            21:  * specific prior written permission.
        !            22:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            23:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            24:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            25:  */
        !            26: 
        !            27: #ifndef lint
        !            28: static char sccsid[] = "@(#)ccl.c      5.2 (Berkeley) 6/18/90";
        !            29: #endif /* not lint */
        !            30: 
        !            31: /* ccl - routines for character classes */
        !            32: 
        !            33: #include "flexdef.h"
        !            34: 
        !            35: /* ccladd - add a single character to a ccl
        !            36:  *
        !            37:  * synopsis
        !            38:  *    int cclp;
        !            39:  *    int ch;
        !            40:  *    ccladd( cclp, ch );
        !            41:  */
        !            42: 
        !            43: void ccladd( cclp, ch )
        !            44: int cclp;
        !            45: int ch;
        !            46: 
        !            47:     {
        !            48:     int ind, len, newpos, i;
        !            49: 
        !            50:     len = ccllen[cclp];
        !            51:     ind = cclmap[cclp];
        !            52: 
        !            53:     /* check to see if the character is already in the ccl */
        !            54: 
        !            55:     for ( i = 0; i < len; ++i )
        !            56:        if ( ccltbl[ind + i] == ch )
        !            57:            return;
        !            58: 
        !            59:     newpos = ind + len;
        !            60: 
        !            61:     if ( newpos >= current_max_ccl_tbl_size )
        !            62:        {
        !            63:        current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;
        !            64: 
        !            65:        ++num_reallocs;
        !            66: 
        !            67:        ccltbl = reallocate_character_array( ccltbl, current_max_ccl_tbl_size );
        !            68:        }
        !            69: 
        !            70:     ccllen[cclp] = len + 1;
        !            71:     ccltbl[newpos] = ch;
        !            72:     }
        !            73: 
        !            74: 
        !            75: /* cclinit - make an empty ccl
        !            76:  *
        !            77:  * synopsis
        !            78:  *    int cclinit();
        !            79:  *    new_ccl = cclinit();
        !            80:  */
        !            81: 
        !            82: int cclinit()
        !            83: 
        !            84:     {
        !            85:     if ( ++lastccl >= current_maxccls )
        !            86:        {
        !            87:        current_maxccls += MAX_CCLS_INCREMENT;
        !            88: 
        !            89:        ++num_reallocs;
        !            90: 
        !            91:        cclmap = reallocate_integer_array( cclmap, current_maxccls );
        !            92:        ccllen = reallocate_integer_array( ccllen, current_maxccls );
        !            93:        cclng = reallocate_integer_array( cclng, current_maxccls );
        !            94:        }
        !            95: 
        !            96:     if ( lastccl == 1 )
        !            97:        /* we're making the first ccl */
        !            98:        cclmap[lastccl] = 0;
        !            99: 
        !           100:     else
        !           101:        /* the new pointer is just past the end of the last ccl.  Since
        !           102:         * the cclmap points to the \first/ character of a ccl, adding the
        !           103:         * length of the ccl to the cclmap pointer will produce a cursor
        !           104:         * to the first free space
        !           105:         */
        !           106:        cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1];
        !           107: 
        !           108:     ccllen[lastccl] = 0;
        !           109:     cclng[lastccl] = 0;        /* ccl's start out life un-negated */
        !           110: 
        !           111:     return ( lastccl );
        !           112:     }
        !           113: 
        !           114: 
        !           115: /* cclnegate - negate a ccl
        !           116:  *
        !           117:  * synopsis
        !           118:  *    int cclp;
        !           119:  *    cclnegate( ccl );
        !           120:  */
        !           121: 
        !           122: void cclnegate( cclp )
        !           123: int cclp;
        !           124: 
        !           125:     {
        !           126:     cclng[cclp] = 1;
        !           127:     }
        !           128: 
        !           129: 
        !           130: /* list_character_set - list the members of a set of characters in CCL form
        !           131:  *
        !           132:  * synopsis
        !           133:  *     int cset[CSIZE];
        !           134:  *     FILE *file;
        !           135:  *     list_character_set( cset );
        !           136:  *
        !           137:  * writes to the given file a character-class representation of those
        !           138:  * characters present in the given set.  A character is present if it
        !           139:  * has a non-zero value in the set array.
        !           140:  */
        !           141: 
        !           142: void list_character_set( file, cset )
        !           143: FILE *file;
        !           144: int cset[];
        !           145: 
        !           146:     {
        !           147:     register int i;
        !           148:     char *readable_form();
        !           149: 
        !           150:     putc( '[', file );
        !           151: 
        !           152:     for ( i = 0; i < csize; ++i )
        !           153:        {
        !           154:        if ( cset[i] )
        !           155:            {
        !           156:            register int start_char = i;
        !           157: 
        !           158:            putc( ' ', file );
        !           159: 
        !           160:            fputs( readable_form( i ), file );
        !           161: 
        !           162:            while ( ++i < csize && cset[i] )
        !           163:                ;
        !           164: 
        !           165:            if ( i - 1 > start_char )
        !           166:                /* this was a run */
        !           167:                fprintf( file, "-%s", readable_form( i - 1 ) );
        !           168: 
        !           169:            putc( ' ', file );
        !           170:            }
        !           171:        }
        !           172: 
        !           173:     putc( ']', file );
        !           174:     }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.