static char * eat_string(int starting_line) { int c; char buffer[500]; char *ptr = buffer; for (;;) { /* * Get the next input character, handling EOF: */ c = input(); if (!c) { unput(c); report_parse_error("unterminated string found beginning", starting_line); return(0); } /* * Deal with special characters ('\\', '"', and '\n'): */ if (c=='\\') { c = eat_escape_code(); if (!c) continue; } else if (c == '"') { *ptr = 0; return(string_Copy(buffer)); } else if (c == '\n') { unput(c); /* fix line # reference to right line # */ report_parse_error("carriage return found in string", yylineno); return(0); } /* * Add the character c to the current string: */ *ptr = c; ptr++; /* * If out of buffer space, do a recursive call then * concatanate the result to the string read in so far to get the * entire string and return that: */ if (ptr>buffer+sizeof(buffer)-20) { string rest_of_string, result; rest_of_string = eat_string(starting_line); if (!rest_of_string) return(0); *ptr = 0; result = string_Concat(buffer, rest_of_string); free(rest_of_string); return(result); } } }
FILE *locate_file(char *override_filename, char *home_dir_filename, char *fallback_filename) { char *filename; FILE *result; errno = 0; if (override_filename) { if (string_Eq(override_filename, "-")) return(stdin); result = fopen(override_filename, "r"); if (!(result = fopen(override_filename, "r"))) { /* <<<>>> */ fprintf(stderr, "zwgc: error while opening %s for reading: ", override_filename); perror(""); } return(result); } if (home_dir_filename) { filename = get_home_directory(); if (filename) { filename = string_Concat(filename, "/"); filename = string_Concat2(filename, home_dir_filename); result = fopen(filename, "r"); if (result) { free(filename); return(result); } if (errno != ENOENT) { /* <<<>>> */ fprintf(stderr, "zwgc: error while opening %s for reading: ", filename); perror(""); free(filename); return(result); } free(filename); } else ERROR("unable to find your home directory.\n"); } if (fallback_filename) { if (!(result = fopen(fallback_filename, "r"))) { /* <<<>>> */ fprintf(stderr, "zwgc: error while opening %s for reading: ", fallback_filename); perror(""); } return(result); } return(NULL); }
static char * eat_show_line(int test_for_endshow) { int c; int saw_escape_code = 0; int starting_line = yylineno; char buffer[200]; /* This must be large enough to hold "endshow" */ char *ptr = buffer; while (yylineno == starting_line) { c = input(); if (!c) { unput(c); *ptr = '\0'; return(string_Copy(buffer)); } else if (c == '\\') { saw_escape_code = 1; c = eat_escape_code(); if (!c) continue; } *ptr = c; ptr++; if ((ptr==buffer+strlen("endshow")) && test_for_endshow) if (!strncmp(buffer, "endshow", strlen("endshow")) && !saw_escape_code) { c = input(); unput(c); if (!is_identifier_char(c)) return(0); } if (ptr>buffer+sizeof(buffer)-2) { string the_line; string rest_of_line = eat_show_line(0); *ptr = '\0'; the_line = string_Concat(buffer, rest_of_line); free(rest_of_line); return(the_line); } } *ptr = '\0'; return(string_Copy(buffer)); }
} /* * */ char * get_string_resource(string name, string class) { string full_name, full_class; int status; char *type; XrmValue value; full_name = string_Concat(APPNAME, "."); full_name = string_Concat2(full_name, name); full_class = string_Concat(APPCLASS, "."); full_class = string_Concat2(full_class, class); status = XrmGetResource(x_resources, full_name, full_class, &type, &value); free(full_name); free(full_class); if (status != True) return(NULL); if (string_Neq(type, "String")) return(NULL); return(value.addr);
char * decode_notice(ZNotice_t *notice, char *hostname) { char *temp; string when, notyear, year, date_string, time_string; /* * Convert useful notice fields to ascii and store away in * description language variables for later use by the * the user's program: */ var_set_variable("zephyr_version", notice->z_version); var_set_variable("class", notice->z_class); var_set_variable("instance", notice->z_class_inst); var_set_variable("opcode", notice->z_opcode); var_set_variable("default", notice->z_default_format); var_set_variable("notice_charset", (char *)ZCharsetToString(notice->z_charset)); /*XXX const*/ var_set_variable("recipient", (notice->z_recipient[0] ? notice->z_recipient : "*")); var_set_variable("fullsender", notice->z_sender); var_set_variable_to_number("port", (int)ntohs(notice->z_port)); var_set_variable_then_free_value("kind", z_kind_to_ascii(notice->z_kind)); var_set_variable_then_free_value("auth", z_auth_to_ascii(notice->z_auth)); #ifdef CMU_ZWGCPLUS if ((temp=getSelectedText()) != 0) var_set_variable("selection", temp); var_set_variable("delete_window", "none"); var_set_variable("event_time", "none"); var_set_variable("event_name", "event"); #endif /* * Set $sender to the name of the notice sender except first strip off the * realm name if it is the local realm: */ if ( (temp=strchr(notice->z_sender,'@')) && string_Eq(temp+1, ZGetRealm()) ) var_set_variable_then_free_value("sender", string_CreateFromData(notice->z_sender, temp-notice->z_sender)); else var_set_variable("sender", notice->z_sender); #ifdef CMU_ZWGCPLUS if (get_full_names) { struct passwd *pwnam = getpwnam(var_get_variable("sender")); if (pwnam) { temp = string_Copy(pwnam->pw_gecos); var_set_variable_then_free_value("sendername", temp); } else { var_set_variable("sendername", "unknown"); } } #endif /* * Convert time & date notice was sent to ascii. The $time * has the format "01:03:52" while $date has the format * "Sun Sep 16 1973". */ { /* the fields of struct timeval might not be the right type to pass to ctime, so use a temporary */ time_t sec = notice->z_time.tv_sec; when = ctime(&sec); } time_string = string_CreateFromData(when+11,8); var_set_variable_then_free_value("time", time_string); date_string = string_Concat(notyear=string_CreateFromData(when,11), year=string_CreateFromData(when+20,4)); var_set_variable_then_free_value("date", date_string); free(notyear); free(year); /* * Convert host notice sent from to ascii: */ var_set_variable("fromhost", hostname ? hostname : inet_ntoa(notice->z_sender_addr)); /* * Set $message to the message field of the notice with nulls changed * to newlines: */ var_set_variable_then_free_value("message", convert_nulls_to_newlines(notice->z_message, notice->z_message_len)); /* * Decide if its a control notice. If so, return the notice's * opcode. Otherwise, return NULL: */ if ((strcasecmp(notice->z_class, WG_CTL_CLASS)==0) && /* <<<>>> */ (strcasecmp(notice->z_class_inst, WG_CTL_USER)==0)) return(notice->z_opcode); return(0); }