+
+/* get_defaults picks apart "str" and returns a structure points.
+ * "str" contains up to 4 fields separated by commas.
+ * Any field that is missing is set to blank.
+ */
+struct default_values
+*get_defaults(str)
+ char *str;
+{
+ struct default_values *answer;
+ char *malloc(), *index();
+
+ answer = (struct default_values *)
+ malloc((unsigned)sizeof(struct default_values));
+ if (answer == (struct default_values *) NULL) {
+ fprintf(stderr,
+ "\nUnable to allocate storage in get_defaults!\n");
+ exit(1);
+ }
+ /*
+ * Values if no corresponding string in "str".
+ */
+ answer->name = str;
+ answer->office_num = "";
+ answer->office_phone = "";
+ answer->home_phone = "";
+ str = index(answer->name, ',');
+ if (str == 0)
+ return(answer);
+ *str = '\0';
+ answer->office_num = str + 1;
+ str = index(answer->office_num, ',');
+ if (str == 0)
+ return(answer);
+ *str = '\0';
+ answer->office_phone = str + 1;
+ str = index(answer->office_phone, ',');
+ if (str == 0)
+ return(answer);
+ *str = '\0';
+ answer->home_phone = str + 1;
+ return(answer);
+}
+
+/*
+ * special_case returns true when either the default is accepted
+ * (str = '\n'), or when 'none' is typed. 'none' is accepted in
+ * either upper or lower case (or any combination). 'str' is modified
+ * in these two cases.
+ */
+int special_case(str,default_str)
+ char *str;
+ char *default_str;
+{
+ static char word[] = "none\n";
+ char *ptr, *wordptr;
+
+ /*
+ * If the default is accepted, then change the old string do the
+ * default string.
+ */
+ if (*str == '\n') {
+ (void) strcpy(str, default_str);
+ return(1);
+ }
+ /*
+ * Check to see if str is 'none'. (It is questionable if case
+ * insensitivity is worth the hair).
+ */
+ wordptr = word-1;
+ for (ptr=str; *ptr != '\0'; ++ptr) {
+ ++wordptr;
+ if (*wordptr == '\0') /* then words are different sizes */
+ return(0);
+ if (*ptr == *wordptr)
+ continue;
+ if (isupper(*ptr) && (tolower(*ptr) == *wordptr))
+ continue;
+ /*
+ * At this point we have a mismatch, so we return
+ */
+ return(0);
+ }
+ /*
+ * Make sure that words are the same length.
+ */
+ if (*(wordptr+1) != '\0')
+ return(0);
+ /*
+ * Change 'str' to be the null string
+ */
+ *str = '\0';
+ return(1);
+}