+
+
+void
+add_profile_entry (const char *key, const char *value)
+{
+ struct node *newnode;
+
+ /* This inserts the new node at the beginning of m_defs because
+ that doesn't require traversing it or checking to see if it's
+ empty. */
+ NEW(newnode);
+ newnode->n_name = getcpy (key);
+ newnode->n_field = getcpy (value);
+ newnode->n_context = 0;
+ newnode->n_next = m_defs;
+ m_defs = newnode;
+}
+
+
+/* Check profile for issues to warn about. */
+void
+checkconfig() {
+ /* Check for duplicated non-null profile entries. Except
+ allow multiple profile entries named "#", because that's
+ what mh-profile(5) suggests using for comments.
+
+ Only do this check on the very first call from
+ context_read(), when opp is NULL. That way, entries in
+ mhn.defaults can be overridden without triggering
+ warnings.
+
+ Note that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
+ $MHSTORE all put their entries into just one list, m_defs,
+ the same list that the profile uses. */
+ struct node *np;
+ bool has_post = false;
+ bool post_warning_disabled = false;
+ for (np = m_defs; np; np = np->n_next) {
+ if (*np->n_name) {
+ if (isatty(fileno(stderr))) {
+ /* Check for post component in profile. */
+ if (strcasecmp(np->n_name, "post") == 0) {
+ has_post = true;
+ } else if (strcasecmp(np->n_name, "postproc") == 0 &&
+ np->n_field != NULL) {
+ post_warning_disabled = true;
+ }
+ }
+
+ if (strcmp("#", np->n_name)) {
+ /* Yes, this is O(N^2). The profile should be small enough so
+ that's not a performance problem. */
+ struct node *np2;
+ for (np2 = np->n_next; np2; np2 = np2->n_next) {
+ if (! strcasecmp (np->n_name, np2->n_name)) {
+ inform("multiple \"%s\" profile components in %s, "
+ "ignoring \"%s\", continuing...",
+ np->n_name, defpath, np2->n_field);
+ }
+ }
+ }
+ }
+ }
+
+ if (has_post && ! post_warning_disabled) {
+ inform("post profile component will be ignored. To suppress "
+ "this warning,\n"
+ "either remove it, comment it with #:, or "
+ "add the following to %s:\npostproc: %s\n",
+ defpath, postproc);
+ }
+}