Replace getcpy() and strdup() with mh_xstrdup()
[mmh] / sbr / seq_read.c
index 5707dae..e76bcc6 100644 (file)
@@ -7,6 +7,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/utils.h>
 
@@ -31,7 +32,7 @@ seq_read(struct msgs *mp)
        ** Initialize the list of sequence names.  Go ahead and
        ** add the cur sequence to the list of sequences.
        */
-       mp->msgattrs[0] = getcpy(seq_cur);
+       mp->msgattrs[0] = mh_xstrdup(seq_cur);
        mp->msgattrs[1] = NULL;
        make_all_public(mp);  /* initially, make all public */
 
@@ -78,26 +79,22 @@ seq_public(struct msgs *mp)
                                fp)) {
                case FLD:
                case FLDPLUS:
-               case FLDEOF:
                        if (state == FLDPLUS) {
-                               cp = getcpy(field);
+                               cp = mh_xstrdup(field);
                                while (state == FLDPLUS) {
                                        state = m_getfld(state, name, field,
                                                        sizeof(field), fp);
                                        cp = add(field, cp);
                                }
-                               seq_init(mp, getcpy(name), trimcpy(cp));
-                               free(cp);
+                               seq_init(mp, mh_xstrdup(name), trimcpy(cp));
+                               mh_free0(&cp);
                        } else {
-                               seq_init(mp, getcpy(name), trimcpy(field));
+                               seq_init(mp, mh_xstrdup(name), trimcpy(field));
                        }
-                       if (state == FLDEOF)
-                               break;
                        continue;
 
                case BODY:
-               case BODYEOF:
-                       adios(NULL, "no blank lines are permitted in %s",
+                       adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        seqfile);
                        /* fall */
 
@@ -105,7 +102,7 @@ seq_public(struct msgs *mp)
                        break;
 
                default:
-                       adios(NULL, "%s is poorly formatted", seqfile);
+                       adios(EX_CONFIG, NULL, "%s is poorly formatted", seqfile);
                }
                break;  /* break from for loop */
        }
@@ -136,9 +133,9 @@ seq_private(struct msgs *mp)
                                (j = strlen(np->n_name) - plen) > alen &&
                                *(np->n_name + j) == '-' &&
                                strcmp(mp->foldpath, np->n_name + j + 1)==0) {
-                       cp = getcpy(np->n_name + alen);
+                       cp = mh_xstrdup(np->n_name + alen);
                        *(cp + j - alen) = '\0';
-                       if ((i = seq_init(mp, cp, getcpy(np->n_field))) != -1)
+                       if ((i = seq_init(mp, cp, mh_xstrdup(np->n_field))) != -1)
                                make_seq_private(mp, i);
                }
        }
@@ -158,7 +155,8 @@ seq_private(struct msgs *mp)
 static int
 seq_init(struct msgs *mp, char *name, char *field)
 {
-       int i, j, k, is_current;
+       unsigned int i;
+       int j, k, is_current;
        char *cp, **ap;
 
        /*
@@ -183,8 +181,8 @@ seq_init(struct msgs *mp, char *name, char *field)
 
        /* Return error, if too many sequences */
        if (i >= NUMATTRS) {
-               free(name);
-               free(field);
+               mh_free0(&name);
+               mh_free0(&field);
                return -1;
        }
 
@@ -193,7 +191,7 @@ seq_init(struct msgs *mp, char *name, char *field)
        ** name string.  Else add it to the list of sequence names.
        */
        if (mp->msgattrs[i]) {
-               free(name);
+               mh_free0(&name);
        } else {
                mp->msgattrs[i] = name;
                mp->msgattrs[i + 1] = NULL;
@@ -230,6 +228,6 @@ seq_init(struct msgs *mp, char *name, char *field)
                }
        }
 
-       free(field);  /* free string containing message ranges */
+       mh_free0(&field);  /* free string containing message ranges */
        return i;
 }