ccl.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* ccl - routines for character classes */
  2. /*-
  3. * Copyright (c) 1990 The Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Vern Paxson.
  8. *
  9. * The United States Government has rights in this work pursuant
  10. * to contract no. DE-AC03-76SF00098 between the United States
  11. * Department of Energy and the University of California.
  12. *
  13. * Redistribution and use in source and binary forms with or without
  14. * modification are permitted provided that: (1) source distributions retain
  15. * this entire copyright notice and comment, and (2) distributions including
  16. * binaries display the following acknowledgement: ``This product includes
  17. * software developed by the University of California, Berkeley and its
  18. * contributors'' in the documentation or other materials provided with the
  19. * distribution and in all advertising materials mentioning features or use
  20. * of this software. Neither the name of the University nor the names of
  21. * its contributors may be used to endorse or promote products derived from
  22. * this software without specific prior written permission.
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  26. */
  27. /* $Header: /opt/vlysenkov/CVSROOT/arcadia/contrib/tools/flex-old/ccl.c,v 1.2 2007-11-30 02:28:15 pg Exp $ */
  28. #include "flexdef.h"
  29. /* ccladd - add a single character to a ccl */
  30. void ccladd( cclp, ch )
  31. int cclp;
  32. int ch;
  33. {
  34. int ind, len, newpos, i;
  35. check_char( ch );
  36. len = ccllen[cclp];
  37. ind = cclmap[cclp];
  38. /* check to see if the character is already in the ccl */
  39. for ( i = 0; i < len; ++i )
  40. if ( ccltbl[ind + i] == ch )
  41. return;
  42. newpos = ind + len;
  43. if ( newpos >= current_max_ccl_tbl_size )
  44. {
  45. current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;
  46. ++num_reallocs;
  47. ccltbl = reallocate_Character_array( ccltbl,
  48. current_max_ccl_tbl_size );
  49. }
  50. ccllen[cclp] = len + 1;
  51. ccltbl[newpos] = ch;
  52. }
  53. /* cclinit - return an empty ccl */
  54. int cclinit()
  55. {
  56. if ( ++lastccl >= current_maxccls )
  57. {
  58. current_maxccls += MAX_CCLS_INCREMENT;
  59. ++num_reallocs;
  60. cclmap = reallocate_integer_array( cclmap, current_maxccls );
  61. ccllen = reallocate_integer_array( ccllen, current_maxccls );
  62. cclng = reallocate_integer_array( cclng, current_maxccls );
  63. }
  64. if ( lastccl == 1 )
  65. /* we're making the first ccl */
  66. cclmap[lastccl] = 0;
  67. else
  68. /* The new pointer is just past the end of the last ccl.
  69. * Since the cclmap points to the \first/ character of a
  70. * ccl, adding the length of the ccl to the cclmap pointer
  71. * will produce a cursor to the first free space.
  72. */
  73. cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1];
  74. ccllen[lastccl] = 0;
  75. cclng[lastccl] = 0; /* ccl's start out life un-negated */
  76. return lastccl;
  77. }
  78. /* cclnegate - negate the given ccl */
  79. void cclnegate( cclp )
  80. int cclp;
  81. {
  82. cclng[cclp] = 1;
  83. }
  84. /* list_character_set - list the members of a set of characters in CCL form
  85. *
  86. * Writes to the given file a character-class representation of those
  87. * characters present in the given CCL. A character is present if it
  88. * has a non-zero value in the cset array.
  89. */
  90. void list_character_set( file, cset )
  91. FILE *file;
  92. int cset[];
  93. {
  94. int i;
  95. putc( '[', file );
  96. for ( i = 0; i < csize; ++i )
  97. {
  98. if ( cset[i] )
  99. {
  100. int start_char = i;
  101. putc( ' ', file );
  102. fputs( readable_form( i ), file );
  103. while ( ++i < csize && cset[i] )
  104. ;
  105. if ( i - 1 > start_char )
  106. /* this was a run */
  107. fprintf( file, "-%s", readable_form( i - 1 ) );
  108. putc( ' ', file );
  109. }
  110. }
  111. putc( ']', file );
  112. }