static int parse_user_color_line(char *filename, char *line, int ln, struct user_color_entry *e) { int rc; unsigned int r, g, b; char name[100], ui_component[100], colorname[100]; if (line[0] == '#') return 1; /* comment */ clean_spaces(line); remove_trailing_whitespace(line); if (strcmp(line, "") == 0) return 1; /* comment (blank line) */ memset(name, 0, sizeof(name)); rc = sscanf(line, "color %[^ ] #%02x%02x%02x", name, &r, &g, &b); if (rc == 4) { name[19] = '\0'; memcpy(e->name, name, 20); e->index = sng_add_user_color(r, g, b); if (e->index < 0) { fprintf(stderr, "%s:%d Failed to add user color '%s'\n", filename, ln, name); return -1; } return 0; } else { rc = sscanf(line, "%[^ ] #%02x%02x%02x", ui_component, &r, &g, &b); if (rc == 4) { e->index = sng_add_user_color(r, g, b); if (e->index < 0) { fprintf(stderr, "%s:%d Failed to modify ui component color '%s'\n", filename, ln, line); return -1; } modify_ui_color(ui_component, e->index); return 0; } else { rc = sscanf(line, "%[^ ] %[^ ]", ui_component, colorname); if (rc == 2) { e->index = lookup_user_color(colorname); if (e->index < 0) { fprintf(stderr, "%s:%d Failed to modify ui component color '%s'\n", filename, ln, line); return -1; } modify_ui_color(ui_component, e->index); return 0; } } } fprintf(stderr, "%s:%d: Syntax error: '%s'\n", filename, ln, line); return -1; }
int test_remove_whitespace() { char test_string[] = " \tHello | World< \t!>& "; printf("%s\n", test_string); remove_leading_whitespace(test_string); remove_middle_whitespace(test_string); add_middle_whitespace(test_string); remove_trailing_whitespace(test_string); printf("%s\n", test_string); return 1; }
event_location_up new_linespec_location (char **linespec) { struct event_location *location; location = XCNEW (struct event_location); EL_TYPE (location) = LINESPEC_LOCATION; if (*linespec != NULL) { char *p; char *orig = *linespec; linespec_lex_to_end (linespec); p = remove_trailing_whitespace (orig, *linespec); if ((p - orig) > 0) EL_LINESPEC (location) = savestring (orig, p - orig); } return event_location_up (location); }
event_location_up new_linespec_location (const char **linespec, symbol_name_match_type match_type) { struct event_location *location; location = XCNEW (struct event_location); EL_TYPE (location) = LINESPEC_LOCATION; EL_LINESPEC (location)->match_type = match_type; if (*linespec != NULL) { const char *p; const char *orig = *linespec; linespec_lex_to_end (linespec); p = remove_trailing_whitespace (orig, *linespec); if ((p - orig) > 0) EL_LINESPEC (location)->spec_string = savestring (orig, p - orig); } return event_location_up (location); }
/* * The authentication conversation function. * Like a PAM conversation function, this accepts multiple messages in a single * round. It then splits them into individual messages for display on the * passwd dialog. A message sequence of info or error followed by a prompt will * be reduced into a single dialog window. * * Returns 0 on success or -1 if some problem occurred (canceled auth, OOM, ...) */ int gui_auth_conv(int num_msg, const struct auth_message auth_msgs[], struct auth_response **resp, saver_info *si) { int i; const char *info_msg, *prompt; struct auth_response *responses; if (si->unlock_state == ul_cancel || si->unlock_state == ul_time) /* If we've already canceled or timed out in this PAM conversation, don't prompt again even if PAM asks us to! */ return -1; if (!(responses = calloc(num_msg, sizeof(struct auth_response)))) goto fail; for (i = 0; i < num_msg; ++i) { info_msg = prompt = NULL; /* See if there is a following message that can be shown at the same * time */ if (auth_msgs[i].type == AUTH_MSGTYPE_INFO && i+1 < num_msg && ( auth_msgs[i+1].type == AUTH_MSGTYPE_PROMPT_NOECHO || auth_msgs[i+1].type == AUTH_MSGTYPE_PROMPT_ECHO) ) { info_msg = auth_msgs[i].msg; prompt = auth_msgs[++i].msg; } else { if ( auth_msgs[i].type == AUTH_MSGTYPE_INFO || auth_msgs[i].type == AUTH_MSGTYPE_ERROR) info_msg = auth_msgs[i].msg; else prompt = auth_msgs[i].msg; } { char *info_msg_trimmed, *prompt_trimmed; /* Trailing whitespace looks bad in a GUI */ info_msg_trimmed = remove_trailing_whitespace(info_msg); prompt_trimmed = remove_trailing_whitespace(prompt); if (make_passwd_window(si, info_msg_trimmed, prompt_trimmed, auth_msgs[i].type == AUTH_MSGTYPE_PROMPT_ECHO ? True : False) < 0) goto fail; if (info_msg_trimmed) free(info_msg_trimmed); if (prompt_trimmed) free(prompt_trimmed); } compose_status = calloc (1, sizeof (*compose_status)); if (!compose_status) goto fail; si->unlock_state = ul_read; handle_typeahead (si); passwd_event_loop (si); if (si->unlock_state == ul_cancel) goto fail; responses[i].response = strdup(si->pw_data->typed_passwd); /* Cache the first response to a PROMPT_NOECHO to save prompting for * each auth mechanism. */ if (si->cached_passwd == NULL && auth_msgs[i].type == AUTH_MSGTYPE_PROMPT_NOECHO) si->cached_passwd = strdup(responses[i].response); free (compose_status); compose_status = 0; } *resp = responses; return (si->unlock_state == ul_finished) ? 0 : -1; fail: if (compose_status) free (compose_status); if (responses) { for (i = 0; i < num_msg; ++i) if (responses[i].response) free (responses[i].response); free (responses); } return -1; }