jed-users mailing list

[2009 Date Index] [2009 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[PATCH 2/2] Use constant for size of buffer in all places


Make the code more readable and use only one place for the real
definition of the buffer size of the table of the equivalence classes.
---
 src/dfasyntx.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/dfasyntx.c b/src/dfasyntx.c
index ee9c0b0..5f5c968 100644
--- a/src/dfasyntx.c
+++ b/src/dfasyntx.c
@@ -23,6 +23,8 @@
  */
 #define SET_SIZE ((UCHAR_MAX+CHAR_BIT) / CHAR_BIT)
 
+#define EQUIV_TABLE_SIZE UCHAR_MAX+1
+
 typedef struct NFA NFA;
 typedef struct Accept Accept;
 typedef struct DFA DFA;
@@ -66,7 +68,7 @@ struct DFA
    int number;
    unsigned char *nfa_set;	       /* the corresp. set of NFA states */
    Accept *accept, *accept_end;
-   DFA *where_to[UCHAR_MAX+1];
+   DFA *where_to[EQUIV_TABLE_SIZE];
 };
 
 /*
@@ -87,7 +89,7 @@ struct Highlight
 {
    int nfa_states, dfa_states;
    NFA *nfa;
-   unsigned char equiv[UCHAR_MAX+1];
+   unsigned char equiv[EQUIV_TABLE_SIZE];
    Accept *accept;
    DFA *dfa;
    char *filename;
@@ -446,7 +448,7 @@ static void add_nfa_trans (Highlight *h, int from, int to, Set set)
 {
    NFA *trans;
    int i;
-   unsigned char other[UCHAR_MAX+1], in[UCHAR_MAX+1];
+   unsigned char other[EQUIV_TABLE_SIZE], in[EQUIV_TABLE_SIZE];
    
    {
        void *tmp_ptr = SLmalloc (sizeof(*trans));
@@ -473,7 +475,7 @@ static void add_nfa_trans (Highlight *h, int from, int to, Set set)
      */
    if (set != NULL) 
      {
-	for (i=0; i<=UCHAR_MAX; i++) 
+	for (i=0; i<EQUIV_TABLE_SIZE; i++)
 	  {
 	     int j = h->equiv[i];
 	     if (j == i) 
@@ -617,7 +619,7 @@ static void make_dfa (Highlight *h)
 	 * transitions. Of course we need only consider transitions
 	 * on a representative member of each equivalence class.
 	 */
-	for (c = 0; c <= UCHAR_MAX; c++) 
+	for (c = 0; c < EQUIV_TABLE_SIZE; c++)
 	  {
 	     if (h->equiv[c] == c) 
 	       {
@@ -765,7 +767,7 @@ static int load_dfa (Highlight *h, char *name)
 {
    FILE *fp;
    char buffer[2048], buf2[2048];
-   unsigned char equiv[UCHAR_MAX+1];
+   unsigned char equiv[EQUIV_TABLE_SIZE];
    int i, j;
    Accept *accept = NULL;
    int accepts;
@@ -798,7 +800,7 @@ static int load_dfa (Highlight *h, char *name)
      * Read in the equivalence classes.
      */
    i = 0;
-   while (i <= UCHAR_MAX) 
+   while (i < EQUIV_TABLE_SIZE)
      {
 	char *p, *q, *r;
 	unsigned int e;
@@ -806,7 +808,7 @@ static int load_dfa (Highlight *h, char *name)
 	get(buffer);
 	
 	p = q = buffer;
-	while (*p && i <= UCHAR_MAX) 
+	while (*p && i < EQUIV_TABLE_SIZE)
 	  {
 	     q = p + strcspn(p, " ");
 	     r = q + strspn(q, " ");
@@ -881,7 +883,7 @@ static int load_dfa (Highlight *h, char *name)
 	  goto error;
 	p++;
 	p += strspn(p, " ");
-	for (j=0; j<=UCHAR_MAX; j++) 
+	for (j=0; j<EQUIV_TABLE_SIZE; j++)
 	  {
 	     if (equiv[j] == j) 
 	       {
@@ -987,7 +989,7 @@ static void save_dfa (Highlight *h, char *name)
    fprintf(fp, "DFA cache: %s\nequiv\n", name);
    
     /* write the equivalence classes */
-   for (i=0; i<=UCHAR_MAX; i++) 
+   for (i=0; i<EQUIV_TABLE_SIZE; i++)
      {
 	fprintf(fp, "%02X%c", h->equiv[i], ((i+1) % 16 ? ' ' : '\n'));
      }
@@ -1008,7 +1010,7 @@ static void save_dfa (Highlight *h, char *name)
 	fprintf(fp, "%d %d %d:", d->number,
 		d->accept ? d->accept->state : -1,
 		d->accept_end ? d->accept_end->state : -1);
-	for (i=0; i<=UCHAR_MAX; i++)
+	for (i=0; i<EQUIV_TABLE_SIZE; i++)
 	  if (h->equiv[i] == i)
 	    fprintf(fp, " %d",
 		    d->where_to[i] ? d->where_to[i]->number : -1);
@@ -1028,7 +1030,7 @@ static void dump_it (Highlight *h)
    int c, d;
    
    printf("Equivalence classes:\n");
-   for (c=1; c<=UCHAR_MAX; c++) 
+   for (c=1; c<EQUIV_TABLE_SIZE; c++)
      {
 	if (h->equiv[c] == c) 
 	  {
@@ -1038,7 +1040,7 @@ static void dump_it (Highlight *h)
 	     else
 	       printf("\\x%02X", c);
 	     printf(": ");
-	     for (d=c; d<=UCHAR_MAX; d++) 
+	     for (d=c; d<EQUIV_TABLE_SIZE; d++)
 	       {
 		  if (h->equiv[d] == c) 
 		    {
@@ -1059,7 +1061,7 @@ static void dump_it (Highlight *h)
 	if (n->is_empty)
 	  printf("epsilon");
 	else
-	  for (c=0; c<=UCHAR_MAX; c++)
+	  for (c=0; c<EQUIV_TABLE_SIZE; c++)
 	    if (h->equiv[c] == c)
 	      if (is_in_set (n->set, c)) 
 	  {
@@ -1082,7 +1084,7 @@ static void dump_it (Highlight *h)
 	  if (is_in_set (df->nfa_set, c))
 	    printf(" %d", c);
 	printf(" ]");
-	for (c=0; c<=UCHAR_MAX; c++)
+	for (c=0; c<EQUIV_TABLE_SIZE; c++)
 	  if (h->equiv[c] == c) 
 	  {
 	     printf(", to %d on ",
-- 
1.6.0.6


--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2009 date index] [2009 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]