X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fseq_read.c;h=4cc42233c2629b70d9b10a5ec83cb8d293b7bb0c;hp=141c1a2e66b3aedc35b88ad82470ca0fb85b3945;hb=a4ff68e851c0931ced437f73a1acb0fedb28bec3;hpb=714b5c530ece27ea2835a313013f5b770163403c diff --git a/sbr/seq_read.c b/sbr/seq_read.c index 141c1a2..4cc4223 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -7,6 +7,7 @@ ** complete copyright information. */ +#include #include #include @@ -29,9 +30,9 @@ seq_read(struct msgs *mp) { /* ** Initialize the list of sequence names. Go ahead and - ** add the "cur" sequence to the list of sequences. + ** add the cur sequence to the list of sequences. */ - mp->msgattrs[0] = getcpy(current); + mp->msgattrs[0] = mh_xstrdup(seq_cur); mp->msgattrs[1] = NULL; make_all_public(mp); /* initially, make all public */ @@ -54,16 +55,14 @@ seq_read(struct msgs *mp) static void seq_public(struct msgs *mp) { - int state; - char *cp, seqfile[PATH_MAX]; - char name[NAMESZ], field[BUFSIZ]; + enum state state; + struct field f = {{0}}; + char seqfile[PATH_MAX]; FILE *fp; /* - ** If mh_seq == NULL (such as if nmh been compiled with - ** NOPUBLICSEQ), or if *mh_seq == '\0' (the user has defined - ** the "mh-sequences" profile entry, but left it empty), - ** then just return, and do not initialize any public sequences. + ** If public sequences are disabled (e.g. the user has defined + ** an empty `Mh-Sequences' profile entry), then just return. */ if (mh_seq == NULL || *mh_seq == '\0') return; @@ -75,38 +74,27 @@ seq_public(struct msgs *mp) return; /* Use m_getfld to scan sequence file */ - for (state = FLD;;) { - switch (state = m_getfld(state, name, field, sizeof(field), fp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - if (state == FLDPLUS) { - cp = getcpy(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); - } else { - seq_init(mp, getcpy(name), trimcpy(field)); - } - if (state == FLDEOF) - break; - continue; - - case BODY: - case BODYEOF: - adios(NULL, "no blank lines are permitted in %s", seqfile); - /* fall */ - - case FILEEOF: - break; + for (state = FLD2;;) { + switch (state = m_getfld2(state, &f, fp)) { + case LENERR2: + state = FLD2; + /* FALL */ + case FLD2: + seq_init(mp, mh_xstrdup(f.name), trimcpy(f.value)); + continue; + + case BODY2: + adios(EX_CONFIG, NULL, "no blank lines are permitted in %s", + seqfile); + /* FALL */ + + case FILEEOF2: + break; - default: - adios(NULL, "%s is poorly formatted", seqfile); + default: + adios(EX_CONFIG, NULL, "%s is poorly formatted", seqfile); } - break; /* break from for loop */ + break; } lkfclose(fp, seqfile); @@ -131,14 +119,13 @@ seq_private(struct msgs *mp) plen = strlen(mp->foldpath) + 1; for (np = m_defs; np; np = np->n_next) { - if (ssequal("atr-", np->n_name) - && (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); + if (strncmp(np->n_name, "atr-", alen)==0 && + (j = strlen(np->n_name) - plen) > alen && + *(np->n_name + j) == '-' && + strcmp(mp->foldpath, np->n_name + j + 1)==0) { + 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,14 +145,15 @@ 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; /* - ** Check if this is "cur" sequence, + ** Check if this is the cur sequence, ** so we can do some special things. */ - is_current = !strcmp(current, name); + is_current = (strcmp(seq_cur, name)==0); /* ** Search for this sequence name to see if we've seen @@ -174,7 +162,7 @@ seq_init(struct msgs *mp, char *name, char *field) ** mesages in this folder. */ for (i = 0; mp->msgattrs[i]; i++) { - if (!strcmp(mp->msgattrs[i], name)) { + if (strcmp(mp->msgattrs[i], name)==0) { for (j = mp->lowmsg; j <= mp->hghmsg; j++) clear_sequence(mp, i, j); break; @@ -183,8 +171,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 +181,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; @@ -209,7 +197,7 @@ seq_init(struct msgs *mp, char *name, char *field) k = cp ? m_atoi(cp) : j; /* - ** Keep mp->curmsg and "cur" sequence in synch. Unlike + ** Keep mp->curmsg and cur sequence in sync. Unlike ** other sequences, this message doesn't need to exist. ** Think about the series of command (rmm; next) to ** understand why this can be the case. But if it does @@ -222,14 +210,19 @@ seq_init(struct msgs *mp, char *name, char *field) ** We iterate through messages in this range ** and flip on bit for this sequence. */ + if (k > mp->hghoff) { + if (!(mp = folder_realloc(mp, mp->lowoff, k))) { + adios(EX_OSERR, NULL, "unable to allocate folder storage"); + } + mp->hghoff = k; + } for (; j <= k; j++) { - if (j >= mp->lowmsg && j <= mp->hghmsg && - does_exist(mp, j)) + if (j >= mp->lowmsg && j <= mp->hghoff) add_sequence(mp, i, j); } } } - free(field); /* free string containing message ranges */ + mh_free0(&field); /* free string containing message ranges */ return i; }