(mh_context_read): Allow for empty lines and
conventional comment characters (#) in the context file.
Showing
1 changed file
with
19 additions
and
5 deletions
... | @@ -85,10 +85,12 @@ int | ... | @@ -85,10 +85,12 @@ int |
85 | mh_context_read (mh_context_t *ctx) | 85 | mh_context_read (mh_context_t *ctx) |
86 | { | 86 | { |
87 | int status; | 87 | int status; |
88 | char *blurb; | 88 | char *blurb, *p; |
89 | struct stat st; | 89 | struct stat st; |
90 | FILE *fp; | 90 | FILE *fp; |
91 | 91 | char *buf = NULL; | |
92 | size_t size = 0; | ||
93 | |||
92 | if (!ctx) | 94 | if (!ctx) |
93 | return MU_ERR_OUT_NULL; | 95 | return MU_ERR_OUT_NULL; |
94 | 96 | ||
... | @@ -106,10 +108,22 @@ mh_context_read (mh_context_t *ctx) | ... | @@ -106,10 +108,22 @@ mh_context_read (mh_context_t *ctx) |
106 | return errno; | 108 | return errno; |
107 | } | 109 | } |
108 | 110 | ||
109 | fread (blurb, st.st_size, 1, fp); | 111 | p = blurb; |
112 | while (getline (&buf, &size, fp) > 0) | ||
113 | { | ||
114 | char *q; | ||
115 | |||
116 | for (q = buf; *q && isspace (*q); q++) | ||
117 | ; | ||
118 | if (!*q || *q == '#') | ||
119 | continue; | ||
120 | |||
121 | while ((*p = *q++)) | ||
122 | p++; | ||
123 | } | ||
110 | fclose (fp); | 124 | fclose (fp); |
111 | 125 | ||
112 | if ((status = mu_header_create (&ctx->header, blurb, st.st_size, NULL)) != 0) | 126 | if ((status = mu_header_create (&ctx->header, blurb, p - blurb, NULL)) != 0) |
113 | free (blurb); | 127 | free (blurb); |
114 | 128 | ||
115 | return status; | 129 | return status; | ... | ... |
-
Please register or sign in to post a comment