From: Fabian K. <fab...@us...> - 2012-07-23 12:46:20
|
Update of /cvsroot/ijbswa/current In directory vz-cvs-4.sog:/tmp/cvs-serv9754 Modified Files: ssplit.c Log Message: Use an enum to replace a couple of magic numbers in ssplit() Index: ssplit.c =================================================================== RCS file: /cvsroot/ijbswa/current/ssplit.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ssplit.c 23 Jul 2012 12:44:30 -0000 1.17 --- ssplit.c 23 Jul 2012 12:46:18 -0000 1.18 *************** *** 71,74 **** --- 71,80 ---- unsigned char char_type; int vec_count = 0; + enum char_type { + WANTED = 0, + SEPARATOR = 1, + TERMINATOR = 2, + }; + if (!str) *************** *** 89,97 **** while (*delim) { ! is_delim[(unsigned)(unsigned char)*delim++] = 1; /* separator */ } ! is_delim[(unsigned)(unsigned char)'\0'] = 2; /* terminator */ ! is_delim[(unsigned)(unsigned char)'\n'] = 2; /* terminator */ --- 95,103 ---- while (*delim) { ! is_delim[(unsigned)(unsigned char)*delim++] = SEPARATOR; } ! is_delim[(unsigned)(unsigned char)'\0'] = TERMINATOR; ! is_delim[(unsigned)(unsigned char)'\n'] = TERMINATOR; *************** *** 99,103 **** /* Skip leading separators. XXX: Why do they matter? */ ! while (is_delim[(unsigned)(unsigned char)*str] == 1) { str++; --- 105,109 ---- /* Skip leading separators. XXX: Why do they matter? */ ! while (is_delim[(unsigned)(unsigned char)*str] == SEPARATOR) { str++; *************** *** 105,109 **** /* The first pointer is the beginning of string */ ! if (is_delim[(unsigned)(unsigned char)*str] == 0) { /* --- 111,115 ---- /* The first pointer is the beginning of string */ ! if (is_delim[(unsigned)(unsigned char)*str] == WANTED) { /* *************** *** 118,124 **** } ! while ((char_type = is_delim[(unsigned)(unsigned char)*str]) != 2) { ! if (char_type == 1) { /* the char is a separator */ --- 124,130 ---- } ! while ((char_type = is_delim[(unsigned)(unsigned char)*str]) != TERMINATOR) { ! if (char_type == SEPARATOR) { /* the char is a separator */ *************** *** 128,132 **** /* Check if we want to save this field */ ! if (is_delim[(unsigned)(unsigned char)*str] == 0) { /* --- 134,138 ---- /* Check if we want to save this field */ ! if (is_delim[(unsigned)(unsigned char)*str] == WANTED) { /* |