static void parse_args(gint argc, gchar **argv, FileInfo *fi) { EncArray *encarray; gint i; GError *error = NULL; GOptionContext *context; gchar *opt_codeset = NULL; gint opt_tab_width = 0; gboolean opt_jump = 0; gboolean opt_version = FALSE; GOptionEntry entries[] = { { "codeset", 0, 0, G_OPTION_ARG_STRING, &opt_codeset, "Set codeset to open file", "CODESET" }, { "tab-width", 0, 0, G_OPTION_ARG_INT, &opt_tab_width, "Set tab width", "WIDTH" }, { "jump", 0, 0, G_OPTION_ARG_INT, &opt_jump, "Jump to specified line", "LINENUM" }, { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show version number", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; context = g_option_context_new("[filename]"); g_option_context_add_main_entries(context, entries, PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); g_option_context_set_ignore_unknown_options(context, FALSE); g_option_context_parse(context, &argc, &argv, &error); g_option_context_free(context); if (error) { g_print("%s: %s\n", PACKAGE, error->message); g_error_free(error); exit(-1); } if (opt_version) { g_print("%s\n", PACKAGE_STRING); exit(0); } if (opt_codeset) { g_convert("TEST", -1, "UTF-8", opt_codeset, NULL, NULL, &error); if (error) { g_error_free(error); error = NULL; } else { g_free(fi->charset); fi->charset = g_strdup(opt_codeset); } } if (opt_tab_width) indent_set_default_tab_width(opt_tab_width); if (opt_jump) jump_linenum = opt_jump; if (fi->charset && (g_ascii_strcasecmp(fi->charset, get_default_charset()) != 0) && (g_ascii_strcasecmp(fi->charset, "UTF-8") != 0)) { encarray = get_encoding_items(get_encoding_code()); for (i = 0; i < ENCODING_MAX_ITEM_NUM; i++) if (encarray->item[i]) if (g_ascii_strcasecmp(fi->charset, encarray->item[i]) == 0) break; if (i == ENCODING_MAX_ITEM_NUM) fi->charset_flag = TRUE; } if (argc >= 2) fi->filename = parse_file_uri(argv[1]); }
static gboolean booleanFromValue(gchar* value) { return !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1"); }
static gboolean sendmail_send_to_sync (CamelTransport *transport, CamelMimeMessage *message, CamelAddress *from, CamelAddress *recipients, GCancellable *cancellable, GError **error) { struct _camel_header_raw *header, *savedbcc, *n, *tail; const gchar *from_addr, *addr; GPtrArray *argv_arr; gint i, len, fd[2], nullfd, wstat; CamelStream *filter; CamelMimeFilter *crlf; sigset_t mask, omask; CamelStream *out; CamelSendmailSettings *settings; const gchar *binary = SENDMAIL_PATH; gchar *custom_binary = NULL, *custom_args = NULL; gboolean success; pid_t pid; success = camel_internet_address_get ( CAMEL_INTERNET_ADDRESS (from), 0, NULL, &from_addr); if (!success) return FALSE; settings = CAMEL_SENDMAIL_SETTINGS (camel_service_ref_settings (CAMEL_SERVICE (transport))); if (camel_sendmail_settings_get_use_custom_binary (settings)) { custom_binary = camel_sendmail_settings_dup_custom_binary (settings); if (custom_binary && *custom_binary) binary = custom_binary; } if (camel_sendmail_settings_get_use_custom_args (settings)) { custom_args = camel_sendmail_settings_dup_custom_args (settings); /* means no arguments used */ if (!custom_args) custom_args = g_strdup (""); } g_object_unref (settings); len = camel_address_length (recipients); for (i = 0; i < len; i++) { success = camel_internet_address_get ( CAMEL_INTERNET_ADDRESS (recipients), i, NULL, &addr); if (!success) { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Could not parse recipient list")); g_free (custom_binary); g_free (custom_args); return FALSE; } } argv_arr = parse_sendmail_args ( binary, custom_args ? custom_args : "-i -f %F -- %R", from_addr, recipients); if (!argv_arr) { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Could not parse arguments")); g_free (custom_binary); g_free (custom_args); return FALSE; } /* unlink the bcc headers */ savedbcc = NULL; tail = (struct _camel_header_raw *) &savedbcc; header = (struct _camel_header_raw *) &CAMEL_MIME_PART (message)->headers; n = header->next; while (n != NULL) { if (!g_ascii_strcasecmp (n->name, "Bcc")) { header->next = n->next; tail->next = n; n->next = NULL; tail = n; } else { header = n; } n = header->next; } if (pipe (fd) == -1) { g_set_error ( error, G_IO_ERROR, g_io_error_from_errno (errno), _("Could not create pipe to '%s': %s: " "mail not sent"), binary, g_strerror (errno)); /* restore the bcc headers */ header->next = savedbcc; g_free (custom_binary); g_free (custom_args); g_ptr_array_free (argv_arr, TRUE); return FALSE; } /* Block SIGCHLD so the calling application doesn't notice * sendmail exiting before we do. */ sigemptyset (&mask); sigaddset (&mask, SIGCHLD); sigprocmask (SIG_BLOCK, &mask, &omask); pid = fork (); switch (pid) { case -1: g_set_error ( error, G_IO_ERROR, g_io_error_from_errno (errno), _("Could not fork '%s': %s: " "mail not sent"), binary, g_strerror (errno)); close (fd[0]); close (fd[1]); sigprocmask (SIG_SETMASK, &omask, NULL); /* restore the bcc headers */ header->next = savedbcc; g_free (custom_binary); g_free (custom_args); g_ptr_array_free (argv_arr, TRUE); return FALSE; case 0: /* Child process */ nullfd = open ("/dev/null", O_RDWR); dup2 (fd[0], STDIN_FILENO); if (nullfd != -1) { /*dup2 (nullfd, STDOUT_FILENO); dup2 (nullfd, STDERR_FILENO);*/ close (nullfd); } close (fd[1]); execv (binary, (gchar **) argv_arr->pdata); _exit (255); } g_ptr_array_free (argv_arr, TRUE); /* Parent process. Write the message out. */ close (fd[0]); out = camel_stream_fs_new_with_fd (fd[1]); /* XXX Workaround for lame sendmail implementations * that can't handle CRLF eoln sequences. */ filter = camel_stream_filter_new (out); crlf = camel_mime_filter_crlf_new ( CAMEL_MIME_FILTER_CRLF_DECODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY); camel_stream_filter_add (CAMEL_STREAM_FILTER (filter), crlf); g_object_unref (crlf); g_object_unref (out); out = (CamelStream *) filter; if (camel_data_wrapper_write_to_stream_sync ( CAMEL_DATA_WRAPPER (message), out, cancellable, error) == -1 || camel_stream_close (out, cancellable, error) == -1) { g_object_unref (out); g_prefix_error (error, _("Could not send message: ")); /* Wait for sendmail to exit. */ while (waitpid (pid, &wstat, 0) == -1 && errno == EINTR) ; sigprocmask (SIG_SETMASK, &omask, NULL); /* restore the bcc headers */ header->next = savedbcc; g_free (custom_binary); g_free (custom_args); return FALSE; } g_object_unref (out); /* Wait for sendmail to exit. */ while (waitpid (pid, &wstat, 0) == -1 && errno == EINTR) ; sigprocmask (SIG_SETMASK, &omask, NULL); /* restore the bcc headers */ header->next = savedbcc; if (!WIFEXITED (wstat)) { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("'%s' exited with signal %s: mail not sent."), binary, g_strsignal (WTERMSIG (wstat))); g_free (custom_binary); g_free (custom_args); return FALSE; } else if (WEXITSTATUS (wstat) != 0) { if (WEXITSTATUS (wstat) == 255) { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Could not execute '%s': mail not sent."), binary); } else { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("'%s' exited with status %d: " "mail not sent."), binary, WEXITSTATUS (wstat)); } g_free (custom_binary); g_free (custom_args); return FALSE; } g_free (custom_binary); g_free (custom_args); return TRUE; }
void ctcp_handle (session *sess, char *to, char *nick, char *ip, char *msg, char *word[], char *word_eol[], int id) { char *po; session *chansess; server *serv = sess->server; char outbuf[1024]; int ctcp_offset = 2; if (serv->have_idmsg && (word[4][1] == '+' || word[4][1] == '-') ) ctcp_offset = 3; /* consider DCC to be different from other CTCPs */ if (!g_ascii_strncasecmp (msg, "DCC", 3)) { /* but still let CTCP replies override it */ if (!ctcp_check (sess, nick, word, word_eol, word[4] + ctcp_offset)) { if (!ignore_check (word[1], IG_DCC)) handle_dcc (sess, nick, word, word_eol); } return; } /* consider ACTION to be different from other CTCPs. Check ignore as if it was a PRIV/CHAN. */ if (!g_ascii_strncasecmp (msg, "ACTION ", 7)) { if (is_channel (serv, to)) { /* treat a channel action as a CHAN */ if (ignore_check (word[1], IG_CHAN)) return; } else { /* treat a private action as a PRIV */ if (ignore_check (word[1], IG_PRIV)) return; } /* but still let CTCP replies override it */ if (ctcp_check (sess, nick, word, word_eol, word[4] + ctcp_offset)) goto generic; inbound_action (sess, to, nick, ip, msg + 7, FALSE, id); return; } if (ignore_check (word[1], IG_CTCP)) return; if (!g_ascii_strcasecmp (msg, "VERSION") && !prefs.hex_irc_hide_version) { #ifdef WIN32 snprintf (outbuf, sizeof (outbuf), "VERSION HexChat "PACKAGE_VERSION" [x%d] / %s", get_cpu_arch (), get_sys_str (1)); #else snprintf (outbuf, sizeof (outbuf), "VERSION HexChat "PACKAGE_VERSION" / %s", get_sys_str (1)); #endif serv->p_nctcp (serv, nick, outbuf); } if (!ctcp_check (sess, nick, word, word_eol, word[4] + ctcp_offset)) { if (!g_ascii_strncasecmp (msg, "SOUND", 5)) { po = strchr (word[5], '\001'); if (po) po[0] = 0; if (is_channel (sess->server, to)) { chansess = find_channel (sess->server, to); if (!chansess) chansess = sess; EMIT_SIGNAL (XP_TE_CTCPSNDC, chansess, word[5], nick, to, NULL, 0); } else { EMIT_SIGNAL (XP_TE_CTCPSND, sess->server->front_session, word[5], nick, NULL, NULL, 0); } /* don't let IRCers specify path */ #ifdef WIN32 if (strchr (word[5], '/') == NULL && strchr (word[5], '\\') == NULL) #else if (strchr (word[5], '/') == NULL) #endif sound_play (word[5], TRUE, FALSE); return; } } generic: po = strchr (msg, '\001'); if (po) po[0] = 0; if (!is_channel (sess->server, to)) { EMIT_SIGNAL (XP_TE_CTCPGEN, sess->server->front_session, msg, nick, NULL, NULL, 0); } else { chansess = find_channel (sess->server, to); if (!chansess) chansess = sess; EMIT_SIGNAL (XP_TE_CTCPGENC, chansess, msg, nick, to, NULL, 0); } }
static void load_keys_from_section (const char *terminal, mc_config_t * cfg) { char *section_name; gchar **profile_keys, **keys; gchar **values, **curr_values; char *valcopy, *value; long key_code; gsize len, values_len; if (terminal == NULL) return; section_name = g_strconcat ("terminal:", terminal, (char *) NULL); profile_keys = keys = mc_config_get_keys (cfg, section_name, &len); while (*profile_keys != NULL) { /* copy=other causes all keys from [terminal:other] to be loaded. */ if (g_ascii_strcasecmp (*profile_keys, "copy") == 0) { valcopy = mc_config_get_string (cfg, section_name, *profile_keys, ""); load_keys_from_section (valcopy, cfg); g_free (valcopy); profile_keys++; continue; } curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len); key_code = lookup_key (*profile_keys, NULL); if (key_code != 0) { if (curr_values != NULL) { while (*curr_values != NULL) { valcopy = convert_controls (*curr_values); define_sequence (key_code, valcopy, MCKEY_NOACTION); g_free (valcopy); curr_values++; } } else { value = mc_config_get_string (cfg, section_name, *profile_keys, ""); valcopy = convert_controls (value); define_sequence (key_code, valcopy, MCKEY_NOACTION); g_free (valcopy); g_free (value); } } profile_keys++; g_strfreev (values); } g_strfreev (keys); g_free (section_name); }
int fs_ml_video_create_window(const char *title) { fs_log("fs_ml_video_create_window\n"); g_window_title = g_strdup(title); g_fs_ml_keyboard_input_grab = fs_config_get_boolean( "keyboard_input_grab"); if (g_fs_ml_automatic_input_grab == FS_CONFIG_NONE) { g_fs_ml_keyboard_input_grab = 1; } fs_log("keyboard input grab: %d\n", g_fs_ml_keyboard_input_grab); static int initialized = 0; #ifdef USE_SDL2 SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, g_fs_ml_keyboard_input_grab ? "1" : "0"); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); #endif SDL_Init(SDL_INIT_VIDEO); SDL_version version; SDL_VERSION(&version); fs_log("FS-UAE was compiled for SDL %d.%d.%d\n", version.major, version.minor, version.patch); if (!initialized) { #ifdef USE_SDL2 int display_index = 0; SDL_DisplayMode mode; int error = SDL_GetCurrentDisplayMode(display_index, &mode); if (error) { fs_log("SDL_GetCurrentDisplayMode failed\n"); SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, "Display Error", "SDL_GetCurrentDisplayMode failed.", NULL); exit(1); } fs_emu_monitor_init(); const char *mon = fs_config_get_const_string("monitor"); int mon_flag = -1; if (mon == NULL) { mon = "middle-left"; } if (strcmp(mon, "left") == 0) { mon_flag = FS_EMU_MONITOR_FLAG_LEFT; } else if (strcmp(mon, "middle-left") == 0) { mon_flag = FS_EMU_MONITOR_FLAG_MIDDLE_LEFT; } else if (strcmp(mon, "middle-right") == 0) { mon_flag = FS_EMU_MONITOR_FLAG_MIDDLE_RIGHT; } else if (strcmp(mon, "right") == 0) { mon_flag = FS_EMU_MONITOR_FLAG_RIGHT; } else { mon_flag = FS_EMU_MONITOR_FLAG_MIDDLE_LEFT; } FSEmuMonitor monitor; fs_emu_monitor_get_by_flag(mon_flag, &monitor); fs_log("Monitor \"%s\" (flag %d) => index %d\n", mon, mon_flag, monitor.index); g_display = monitor.index; #else const SDL_VideoInfo* info = SDL_GetVideoInfo(); #endif g_fullscreen_width = fs_config_get_int("fullscreen_width"); if (g_fullscreen_width == FS_CONFIG_NONE) { #ifdef USE_SDL2 g_fullscreen_width = mode.w; #else g_fullscreen_width = info->current_w; #endif } g_fullscreen_height = fs_config_get_int("fullscreen_height"); if (g_fullscreen_height == FS_CONFIG_NONE) { #ifdef USE_SDL2 g_fullscreen_height = mode.h; #else g_fullscreen_height = info->current_h; #endif } if (g_fs_emu_video_fullscreen_mode_string == NULL) { g_fs_emu_video_fullscreen_mode = -1; } else if (g_ascii_strcasecmp(g_fs_emu_video_fullscreen_mode_string, "window") == 0) { g_fs_emu_video_fullscreen_mode = FULLSCREEN_WINDOW; } else if (g_ascii_strcasecmp(g_fs_emu_video_fullscreen_mode_string, "fullscreen") == 0) { g_fs_emu_video_fullscreen_mode = FULLSCREEN_FULLSCREEN; } #ifdef USE_SDL2 else if (g_ascii_strcasecmp(g_fs_emu_video_fullscreen_mode_string, "desktop") == 0) { g_fs_emu_video_fullscreen_mode = FULLSCREEN_DESKTOP; } #endif if (g_fs_emu_video_fullscreen_mode == -1) { #ifdef MACOSX g_fs_emu_video_fullscreen_mode = FULLSCREEN_FULLSCREEN; #else g_fs_emu_video_fullscreen_mode = FULLSCREEN_FULLSCREEN; #endif #ifdef USE_SDL2 fs_log("defaulting to fullscreen_mode = desktop for SDL2\n"); g_fs_emu_video_fullscreen_mode = FULLSCREEN_DESKTOP; #endif } initialized = 1; } if (g_fs_ml_video_sync) { g_fs_ml_vblank_sync = 1; } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); #ifdef USE_SDL2 // setting swap interval after creating OpenGL context #else if (g_fs_ml_vblank_sync) { fs_emu_log("*** Setting swap interval to 1 ***\n"); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); } else { fs_emu_log("*** Setting swap interval to 0 ***\n"); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0); } #endif if (g_fsaa) { fs_log("setting FSAA samples to %d\n", g_fsaa); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, g_fsaa); } g_window_width = fs_config_get_int("window_width"); if (g_window_width == FS_CONFIG_NONE) { g_window_width = 1920 / 2; } g_window_height = fs_config_get_int("window_height"); if (g_window_height == FS_CONFIG_NONE) { g_window_height = 1080/ 2; } #ifdef USE_SDL2 g_window_x = fs_config_get_int("window_x"); if (g_window_x == FS_CONFIG_NONE) { g_window_x = SDL_WINDOWPOS_CENTERED; } g_window_y = fs_config_get_int("window_y"); if (g_window_y == FS_CONFIG_NONE) { g_window_y = SDL_WINDOWPOS_CENTERED; } #endif g_window_resizable = fs_config_get_boolean("window_resizable"); if (g_window_resizable == FS_CONFIG_NONE) { g_window_resizable = 1; } g_fs_ml_automatic_input_grab = fs_config_get_boolean( "automatic_input_grab"); if (g_fs_ml_automatic_input_grab == FS_CONFIG_NONE) { if (fs_ml_mouse_integration()) { g_fs_ml_automatic_input_grab = 0; } else { g_fs_ml_automatic_input_grab = 1; } } fs_log("automatic input grab: %d\n", g_fs_ml_automatic_input_grab); g_initial_input_grab = g_fs_ml_automatic_input_grab; if (fs_config_get_boolean("initial_input_grab") == 1) { g_initial_input_grab = 1; } else if (fs_config_get_boolean("initial_input_grab") == 0 || // deprecated names: fs_config_get_boolean("input_grab") == 0 || fs_config_get_boolean("grab_input") == 0) { g_initial_input_grab = 0; } set_video_mode(); #ifdef USE_SDL2 if (g_fs_ml_vblank_sync) { fs_emu_log("*** Setting swap interval to 1 ***\n"); if (SDL_GL_SetSwapInterval(1) != 0) { fs_emu_warning("SDL_GL_SetSwapInterval(1) failed"); } } else { fs_emu_log("*** Setting swap interval to 0 ***\n"); SDL_GL_SetSwapInterval(0); } #endif // we display a black frame as soon as possible (to reduce flickering on // startup) glClear(GL_COLOR_BUFFER_BIT); #ifdef USE_SDL2 SDL_GL_SwapWindow(g_fs_ml_window); #else SDL_GL_SwapBuffers(); #endif fs_gl_finish(); #ifdef USE_SDL2 // set in SDL_CreateWindow instead #else SDL_WM_SetCaption(g_window_title, fs_get_application_name()); #endif fs_log("initial input grab: %d\n", g_initial_input_grab); if (g_initial_input_grab && !g_has_input_grab) { fs_ml_grab_input(1, 1); } fs_ml_show_cursor(0, 1); // this function must be called from the video thread fs_log("init_opengl\n"); fs_emu_video_init_opengl(); #ifdef WINDOWS #ifdef USE_SDL2 // we use only SDL functions with SDL2 #else fs_ml_init_raw_input(); #endif #else #ifdef USE_SDL2 SDL_StartTextInput(); #else // enable keysym to unicode char translation SDL_EnableUNICODE(1); #endif #endif fs_log("create windows is done\n"); return 1; }
static gboolean check_header_in_message_info (CamelMessageInfo *info, gint argc, struct _CamelSExpResult **argv, camel_search_match_t how, gboolean *matched) { struct _KnownHeaders { const gchar *header_name; guint info_key; } known_headers[] = { { "Subject", CAMEL_MESSAGE_INFO_SUBJECT }, { "From", CAMEL_MESSAGE_INFO_FROM }, { "To", CAMEL_MESSAGE_INFO_TO }, { "Cc", CAMEL_MESSAGE_INFO_CC } }; camel_search_t type = CAMEL_SEARCH_TYPE_ENCODED; const gchar *name, *value; gboolean found = FALSE; gint ii; g_return_val_if_fail (argc > 1, FALSE); g_return_val_if_fail (argv != NULL, FALSE); g_return_val_if_fail (matched != NULL, FALSE); if (!info) return FALSE; name = argv[0]->value.string; g_return_val_if_fail (name != NULL, FALSE); /* test against any header */ if (!*name) { gint jj; for (jj = 0; jj < G_N_ELEMENTS (known_headers); jj++) { value = camel_message_info_get_ptr (info, known_headers[jj].info_key); if (!value) continue; if (known_headers[jj].info_key == CAMEL_MESSAGE_INFO_SUBJECT) type = CAMEL_SEARCH_TYPE_ENCODED; else type = CAMEL_SEARCH_TYPE_ADDRESS_ENCODED; for (ii = 1; ii < argc && !*matched; ii++) { if (argv[ii]->type == CAMEL_SEXP_RES_STRING) *matched = camel_search_header_match (value, argv[ii]->value.string, how, type, NULL); } if (*matched) return TRUE; } return FALSE; } value = NULL; for (ii = 0; ii < G_N_ELEMENTS (known_headers); ii++) { found = g_ascii_strcasecmp (name, known_headers[ii].header_name) == 0; if (found) { value = camel_message_info_get_ptr (info, known_headers[ii].info_key); if (known_headers[ii].info_key != CAMEL_MESSAGE_INFO_SUBJECT) type = CAMEL_SEARCH_TYPE_ADDRESS_ENCODED; break; } } if (!found || !value) return FALSE; for (ii = 1; ii < argc && !*matched; ii++) { if (argv[ii]->type == CAMEL_SEXP_RES_STRING) *matched = camel_search_header_match (value, argv[ii]->value.string, how, type, NULL); } return TRUE; }
static void read_attribute_value (EVCardAttribute *attr, char **p, gboolean quoted_printable) { char *lp = *p; GString *str; /* read in the value */ str = g_string_new (""); for( lp = skip_newline( *p, quoted_printable ); *lp != '\n' && *lp != '\r' && *lp != '\0'; lp = skip_newline( lp, quoted_printable ) ) { if (*lp == '=' && quoted_printable) { char a, b; if ((a = *(++lp)) == '\0') break; if ((b = *(++lp)) == '\0') break; if (isxdigit(a) && isxdigit (b)) { char c; a = tolower (a); b = tolower (b); c = (((a>='a'?a-'a'+10:a-'0')&0x0f) << 4) | ((b>='a'?b-'a'+10:b-'0')&0x0f); g_string_append_c (str, c); /* add decoded byte (this is not a unicode yet) */ } else { g_string_append_c (str, a); g_string_append_c (str, b); } lp++; } else if (*lp == '\\') { /* convert back to the non-escaped version of the characters */ lp = g_utf8_next_char(lp); if (*lp == '\0') { g_string_append_c (str, '\\'); break; } /* beware, there might be a line break due to folding, * need next real character */ lp = skip_newline (lp, quoted_printable); switch (*lp) { case 'n': g_string_append_c (str, '\n'); break; case 'N': g_string_append_c (str, '\n'); break; case 'r': g_string_append_c (str, '\r'); break; case 'R': g_string_append_c (str, '\r'); break; case ';': g_string_append_c (str, ';'); break; case ',': g_string_append_c (str, ','); break; case '\\': g_string_append_c (str, '\\'); break; default: g_warning ("invalid escape, passing it through"); g_string_append_c (str, '\\'); g_string_append_unichar (str, g_utf8_get_char(lp)); break; } lp = g_utf8_next_char(lp); } else if ((*lp == ';') || (*lp == ',' && !g_ascii_strcasecmp (attr->name, "CATEGORIES"))) { e_vcard_attribute_add_value (attr, str->str); g_string_assign (str, ""); lp = g_utf8_next_char(lp); } else { g_string_append_unichar (str, g_utf8_get_char (lp)); lp = g_utf8_next_char(lp); } } if (str) { e_vcard_attribute_add_value (attr, str->str); g_string_free (str, TRUE); } skip_to_next_line( &lp ); *p = lp; }
static void read_attribute_params (EVCardAttribute *attr, char **p, gboolean *quoted_printable) { char *lp; GString *str; EVCardAttributeParam *param = NULL; gboolean in_quote = FALSE; str = g_string_new (""); for( lp = skip_newline( *p, *quoted_printable ); *lp != '\n' && *lp != '\r' && *lp != '\0'; lp = skip_newline( lp, *quoted_printable ) ) { if (*lp == '"') { in_quote = !in_quote; lp = g_utf8_next_char (lp); } else if (in_quote || g_unichar_isalnum (g_utf8_get_char (lp)) || *lp == '-' || *lp == '_') { g_string_append_unichar (str, g_utf8_get_char (lp)); lp = g_utf8_next_char (lp); } /* accumulate until we hit the '=' or ';'. If we hit * a '=' the string contains the parameter name. if * we hit a ';' the string contains the parameter * value and the name is either ENCODING (if value == * QUOTED-PRINTABLE) or TYPE (in any other case.) */ else if (*lp == '=') { if (str->len > 0) { param = e_vcard_attribute_param_new (str->str); g_string_assign (str, ""); lp = g_utf8_next_char (lp); } else { skip_until (&lp, ":;"); if (*lp == ';') { lp = g_utf8_next_char (lp); } else if (*lp == ':') { /* do nothing */ } else { skip_to_next_line( &lp ); break; } } } else if (*lp == ';' || *lp == ':' || *lp == ',') { gboolean colon = (*lp == ':'); gboolean comma = (*lp == ','); if (param) { if (str->len > 0) { e_vcard_attribute_param_add_value (param, str->str); g_string_assign (str, ""); if (!colon) lp = g_utf8_next_char (lp); } else { /* we've got a parameter of the form: * PARAM=(.*,)?[:;] * so what we do depends on if there are already values * for the parameter. If there are, we just finish * this parameter and skip past the offending character * (unless it's the ':'). If there aren't values, we free * the parameter then skip past the character. */ if (!param->values) { e_vcard_attribute_param_free (param); param = NULL; if (!colon) lp = g_utf8_next_char (lp); } } if (param && !g_ascii_strcasecmp (param->name, "encoding") && !g_ascii_strcasecmp (param->values->data, "quoted-printable")) { *quoted_printable = TRUE; e_vcard_attribute_param_free (param); param = NULL; } } else { if (str->len > 0) { char *param_name; if (!g_ascii_strcasecmp (str->str, "quoted-printable")) { param_name = "ENCODING"; *quoted_printable = TRUE; } /* apple's broken addressbook app outputs naked BASE64 parameters, which aren't even vcard 3.0 compliant. */ else if (!g_ascii_strcasecmp (str->str, "base64")) { param_name = "ENCODING"; g_string_assign (str, "b"); } else { param_name = "TYPE"; } if (param_name) { param = e_vcard_attribute_param_new (param_name); e_vcard_attribute_param_add_value (param, str->str); } g_string_assign (str, ""); if (!colon) lp = g_utf8_next_char (lp); } else { /* we've got an attribute with a truly empty attribute parameter. So it's of the form: ATTR;[PARAM=value;]*;[PARAM=value;]*: (note the extra ';') the only thing to do here is, well.. nothing. we skip over the character if it's not a colon, and the rest is handled for us: We'll either continue through the loop again if we hit a ';', or we'll break out correct below if it was a ':' */ if (!colon) lp = g_utf8_next_char (lp); } } if (param && !comma) { e_vcard_attribute_add_param (attr, param); param = NULL; } if (colon) break; } else { g_warning ("invalid character found in parameter spec"); g_string_assign (str, ""); /* skip_until (&lp, ":;"); */ skip_to_next_line( &lp ); } } if (str) g_string_free (str, TRUE); *p = lp; }
static void prefs_custom_header_val_from_file_cb(void) { gchar *filename = NULL; gchar *contents = NULL; const gchar *hdr = gtk_entry_get_text(GTK_ENTRY(customhdr.hdr_entry)); if (!strcmp(hdr, "Face")) filename = filesel_select_file_open(_("Choose a PNG file"), NULL); else if (!strcmp(hdr, "X-Face")) filename = filesel_select_file_open(_("Choose an XBM file"), NULL); else filename = filesel_select_file_open(_("Choose a text file"), NULL); if (!strcmp(hdr, "Face") || !strcmp(hdr, "X-Face")) { if (filename && is_file_exist(filename)) { FILE *fp = NULL; gint len; gchar inbuf[B64_LINE_SIZE], *outbuf; gchar *tmp = NULL; gint w, h; GdkPixbufFormat *format = gdk_pixbuf_get_file_info( filename, &w, &h); if (format == NULL) { alertpanel_error(_("This file isn't an image.")); g_free(filename); return; } if (w != 48 || h != 48) { alertpanel_error(_("The chosen image isn't the correct size (48x48).")); g_free(filename); return; } if (!strcmp(hdr, "Face")) { if (get_file_size(filename) > 725) { alertpanel_error(_("The image is too big; it must be maximum 725 bytes.")); g_free(filename); return; } if (g_ascii_strcasecmp("png", gdk_pixbuf_format_get_name(format))) { alertpanel_error(_("The image isn't in the correct format (PNG).")); g_print("%s\n", gdk_pixbuf_format_get_name(format)); g_free(filename); return; } } else if (!strcmp(hdr, "X-Face")) { gchar *tmp = NULL, *cmd = NULL; int i = 0; if (g_ascii_strcasecmp("xbm", gdk_pixbuf_format_get_name(format))) { alertpanel_error(_("The image isn't in the correct format (XBM).")); g_print("%s\n", gdk_pixbuf_format_get_name(format)); g_free(filename); return; } cmd = g_strdup_printf("compface %s", filename); tmp = get_command_output(cmd); g_free(cmd); if (tmp == NULL || *tmp == '\0') { alertpanel_error(_("Couldn't call `compface`. Make sure it's in your $PATH.")); g_free(filename); g_free(tmp); return; } if (strstr(tmp, "compface:")) { alertpanel_error(_("Compface error: %s"), tmp); g_free(filename); g_free(tmp); return; } while (tmp[i]) { gchar *tmp2 = NULL; if (tmp[i] == ' ') { i++; continue; } if (tmp[i] == '\r' || tmp[i] == '\n') { i++; continue; } tmp2 = contents; contents = g_strdup_printf("%s%c",tmp2?tmp2:"", tmp[i]); g_free(tmp2); i++; } g_free(tmp); goto settext; } fp = g_fopen(filename, "rb"); if (!fp) { g_free(filename); return; } while ((len = fread(inbuf, sizeof(gchar), B64_LINE_SIZE, fp)) == B64_LINE_SIZE) { outbuf = g_base64_encode(inbuf, B64_LINE_SIZE); tmp = contents; contents = g_strconcat(tmp?tmp:"",outbuf, NULL); g_free(outbuf); g_free(tmp); } if (len > 0 && feof(fp)) { tmp = contents; outbuf = g_base64_encode(inbuf, len); contents = g_strconcat(tmp?tmp:"",outbuf, NULL); g_free(outbuf); g_free(tmp); } fclose(fp); } } else { if (!filename) return; contents = file_read_to_str(filename); if (strchr(contents, '\n') || strchr(contents,'\r')) { alertpanel_error(_("This file contains newlines.")); g_free(contents); g_free(filename); return; } } settext: if (contents && strlen(contents)) gtk_entry_set_text(GTK_ENTRY(customhdr.val_entry), contents); g_free(contents); g_free(filename); }
/** * e_vcard_attribute_add_param: * @attr: an #EVCardAttribute * @param: an #EVCardAttributeParam to add * * Adds @param to @attr's list of parameters. * It tests for duplicities, only new parameters are added, * when a new parameter already exists in attr, then those * values are merged, also without creating duplicities. * When we will not add whole param, then it's freed here. **/ void e_vcard_attribute_add_param (EVCardAttribute *attr, EVCardAttributeParam *param) { gboolean contains; GList *params, *p; const char *par_name; g_return_if_fail (attr != NULL); g_return_if_fail (param != NULL); contains = FALSE; params = attr->params; par_name = param->name; for (p = params; p; p = p->next) { EVCardAttributeParam *param2 = p->data; if (g_ascii_strcasecmp (param2->name, par_name) == 0) { /* param2 has same name as our new param; better merge them than have more parameters with same name within one attribute. */ GList *vals,*v; vals = param->values; for (v = vals; v; v = v->next) { const char *my_value; GList *vals2,*v2; my_value = (const char *)v->data; vals2 = param2->values; for (v2 = vals2; v2; v2 = v2->next) { if (g_ascii_strcasecmp ((const char *)v2->data, my_value) == 0) { break; } } if (!v2) { /* we did loop through all values and none of them was my_value */ e_vcard_attribute_param_add_value (param2, my_value); } } contains = TRUE; break; } } if (!contains) { attr->params = g_list_prepend (attr->params, param); } /* we handle our special encoding stuff here */ if (!g_ascii_strcasecmp (param->name, EVC_ENCODING)) { if (attr->encoding_set) { g_warning ("ENCODING specified twice"); if (contains) { e_vcard_attribute_param_free (param); } return; } if (param->values && param->values->data) { if (!g_ascii_strcasecmp ((char*)param->values->data, "b") || !g_ascii_strcasecmp ((char*)param->values->data, "BASE64")) attr->encoding = EVC_ENCODING_BASE64; else if (!g_ascii_strcasecmp ((char*)param->values->data, EVC_QUOTEDPRINTABLE)) attr->encoding = EVC_ENCODING_QP; else { g_warning ("Unknown value `%s' for ENCODING parameter. values will be treated as raw", (char*)param->values->data); } attr->encoding_set = TRUE; } else { g_warning ("ENCODING parameter added with no value"); } } if (contains) { e_vcard_attribute_param_free (param); } }
static gboolean parseOptionEntryCallback(const gchar *optionNameFull, const gchar *value, WebKitSettings *webSettings, GError **error) { if (strlen(optionNameFull) <= 2) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Invalid option %s", optionNameFull); return FALSE; } /* We have two -- in option name so remove them. */ const gchar *optionName = optionNameFull + 2; GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), optionName); if (!spec) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Cannot find web settings for option %s", optionNameFull); return FALSE; } switch (G_PARAM_SPEC_VALUE_TYPE(spec)) { case G_TYPE_BOOLEAN: { gboolean propertyValue = !(value && g_ascii_strcasecmp(value, "true") && strcmp(value, "1")); g_object_set(G_OBJECT(webSettings), optionName, propertyValue, NULL); break; } case G_TYPE_STRING: g_object_set(G_OBJECT(webSettings), optionName, value, NULL); break; case G_TYPE_INT: { glong propertyValue; gchar *end; errno = 0; propertyValue = g_ascii_strtoll(value, &end, 0); if (errno == ERANGE || propertyValue > G_MAXINT || propertyValue < G_MININT) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Integer value '%s' for %s out of range", value, optionNameFull); return FALSE; } if (errno || value == end) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Cannot parse integer value '%s' for %s", value, optionNameFull); return FALSE; } g_object_set(G_OBJECT(webSettings), optionName, propertyValue, NULL); break; } case G_TYPE_FLOAT: { gdouble propertyValue; gchar *end; errno = 0; propertyValue = g_ascii_strtod(value, &end); if (errno == ERANGE || propertyValue > G_MAXFLOAT || propertyValue < G_MINFLOAT) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Float value '%s' for %s out of range", value, optionNameFull); return FALSE; } if (errno || value == end) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Cannot parse float value '%s' for %s", value, optionNameFull); return FALSE; } g_object_set(G_OBJECT(webSettings), optionName, propertyValue, NULL); break; } default: g_assert_not_reached(); } return TRUE; }
static void parse_args (int argc, char **argv) { int iarg = 1; char *arg; while (iarg < argc) { arg = argv[iarg]; if (g_ascii_strncasecmp (arg, "--np", 4) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) _np = tmp; else g_printerr ("Invalid particles number (--np %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "--seed", 6) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) _random_seed = tmp; else g_printerr ("Invalid random seed (--seed %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "--fill", 6) == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (g_ascii_strncasecmp (arg, "random2", 7) == 0) { _fill = _random2_fill; } else if (g_ascii_strncasecmp (arg, "circle2", 7) == 0) { _fill = _circle2_fill; } else if (g_ascii_strncasecmp (arg, "random", 6) == 0) { _fill = _random_fill; } else if (g_ascii_strncasecmp (arg, "circle", 6) == 0) { _fill = _circle_fill; } else { g_printerr ("Invalid fill function name \"%s\"\n", arg); } } else if (g_ascii_strncasecmp (arg, "--dist", 6) == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (g_ascii_strncasecmp (arg, "contiguous", 11) == 0) { _distribute = vsg_prtree2d_distribute_contiguous_leaves; } else if (g_ascii_strncasecmp (arg, "scatter", 7) == 0) { _distribute = vsg_prtree2d_distribute_scatter_leaves; } else { g_printerr ("Invalid distribution function name \"%s\"\n", arg); } } else if (g_ascii_strncasecmp (arg, "--hilbert", 9) == 0) { _hilbert = TRUE; } else if (g_ascii_strncasecmp (arg, "--write", 7) == 0) { _do_write = TRUE; } else if (g_ascii_strncasecmp (arg, "-v", 2) == 0 || g_ascii_strncasecmp (arg, "--verbose", 9) == 0) { _verbose = TRUE; } else if (g_ascii_strncasecmp (arg, "--maxbox", 4) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) _maxbox = tmp; else g_printerr ("Invalid maximum particles / box number " \ "(--maxbox %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "--nc-size", 9) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) nc_padding = MAX (0, tmp - sizeof (NodeCounter)); else g_printerr ("Invalid value for NodeCounter padding " "(--nc-size %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "--far-slowdown", 14) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) _far_slowdown = MAX (0, tmp); else g_printerr ("Invalid value for far interaction slowdown factor " "(--far-slowdown %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "--near-slowdown", 15) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) _near_slowdown = MAX (0, tmp); else g_printerr ("Invalid value for near interaction slowdown factor " "(--near-slowdown %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "--nf-slowdown", 15) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) { _near_slowdown = MAX (0, tmp); _far_slowdown = MAX (0, tmp); } else g_printerr ("Invalid value for near/far interaction slowdown " "factor (--nf-slowdown %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "--version") == 0) { g_printerr ("%s version %s\n", argv[0], PACKAGE_VERSION); exit (0); } else { g_printerr ("Invalid argument \"%s\"\n", arg); } iarg ++; } }
wxFontFamily wxNativeFontInfo::GetFamily() const { wxFontFamily ret = wxFONTFAMILY_UNKNOWN; const char *family_name = pango_font_description_get_family( description ); // note: not passing -1 as the 2nd parameter to g_ascii_strdown to work // around a bug in the 64-bit glib shipped with solaris 10, -1 causes it // to try to allocate 2^32 bytes. if ( !family_name ) return ret; wxGtkString family_text(g_ascii_strdown(family_name, strlen(family_name))); // Check for some common fonts, to salvage what we can from the current // win32 centric wxFont API: if (strncasecmp( family_text, "monospace", 9 ) == 0) ret = wxFONTFAMILY_TELETYPE; // begins with "Monospace" else if (strncasecmp( family_text, "courier", 7 ) == 0) ret = wxFONTFAMILY_TELETYPE; // begins with "Courier" #if defined(__WXGTK20__) || defined(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE) else #ifdef __WXGTK20__ if (!gtk_check_version(2,4,0)) #endif { PangoFontFamily **families; PangoFontFamily *family = NULL; int n_families; pango_context_list_families( #ifdef __WXGTK20__ gtk_widget_get_pango_context( wxGetRootWindow() ), #else wxTheApp->GetPangoContext(), #endif &families, &n_families); for (int i = 0; i < n_families; ++i) { if (g_ascii_strcasecmp(pango_font_family_get_name( families[i] ), pango_font_description_get_family( description )) == 0 ) { family = families[i]; break; } } g_free(families); // Some gtk+ systems might query for a non-existing font from // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) on initialization, // don't assert until wxSystemSettings::GetFont is checked for this - MR // wxASSERT_MSG( family, "No appropriate PangoFontFamily found for ::description" ); if (family != NULL && pango_font_family_is_monospace( family )) ret = wxFONTFAMILY_TELETYPE; // is deemed a monospace font by pango } #endif // GTK+ 2 || HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE if (ret == wxFONTFAMILY_UNKNOWN) { if (strstr( family_text, "sans" ) != NULL || strstr( family_text, "Sans" ) != NULL) // checked before serif, so that "* Sans Serif" fonts are detected correctly ret = wxFONTFAMILY_SWISS; // contains "Sans" else if (strstr( family_text, "serif" ) != NULL || strstr( family_text, "Serif" ) != NULL) ret = wxFONTFAMILY_ROMAN; // contains "Serif" else if (strncasecmp( family_text, "times", 5 ) == 0) ret = wxFONTFAMILY_ROMAN; // begins with "Times" else if (strncasecmp( family_text, "old", 3 ) == 0) ret = wxFONTFAMILY_DECORATIVE; // begins with "Old" - "Old English", "Old Town" } return ret; }
/*********************************************************************** * @todo Maybe invoice checking should be done in gnc_bi_import_fix_bis (...) * rather than in here? But that is more concerned with ensuring the csv is consistent. * @param GtkListStore *store * @param guint *n_invoices_created * @param guint *n_invoices_updated * @return void ***********************************************************************/ void gnc_bi_import_create_bis (GtkListStore * store, QofBook * book, guint * n_invoices_created, guint * n_invoices_updated, gchar * type, gchar * open_mode, GString * info) { gboolean valid; GtkTreeIter iter; gchar *id = NULL, *date_opened = NULL, *owner_id = NULL, *billing_id = NULL, *notes = NULL; gchar *date = NULL, *desc = NULL, *action = NULL, *account = NULL, *quantity = NULL, *price = NULL, *disc_type = NULL, *disc_how = NULL, *discount = NULL, *taxable = NULL, *taxincluded = NULL, *tax_table = NULL; gchar *date_posted = NULL, *due_date = NULL, *account_posted = NULL, *memo_posted = NULL, *accumulatesplits = NULL; guint dummy; GncInvoice *invoice; GncEntry *entry; gint day, month, year; gnc_numeric value; GncOwner *owner; Account *acc; enum update {YES = GTK_RESPONSE_YES, NO = GTK_RESPONSE_NO} update; GtkWidget *dialog; Timespec today; InvoiceWindow *iw; gchar *new_id = NULL; gint64 denom = 0; gnc_commodity *currency; // these arguments are needed g_return_if_fail (store && book); // logic of this function only works for bills or invoices g_return_if_fail ((g_ascii_strcasecmp (type, "INVOICE") == 0) || (g_ascii_strcasecmp (type, "BILL") == 0)); // allow to call this function without statistics if (!n_invoices_created) n_invoices_created = &dummy; if (!n_invoices_updated) n_invoices_updated = &dummy; *n_invoices_created = 0; *n_invoices_updated = 0; invoice = NULL; update = NO; valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); while (valid) { // Walk through the list, reading each row gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &id, DATE_OPENED, &date_opened, DATE_POSTED, &date_posted, // if autoposting requested DUE_DATE, &due_date, // if autoposting requested ACCOUNT_POSTED, &account_posted, // if autoposting requested MEMO_POSTED, &memo_posted, // if autoposting requested ACCU_SPLITS, &accumulatesplits, // if autoposting requested OWNER_ID, &owner_id, BILLING_ID, &billing_id, NOTES, ¬es, DATE, &date, DESC, &desc, ACTION, &action, ACCOUNT, &account, QUANTITY, &quantity, PRICE, &price, DISC_TYPE, &disc_type, DISC_HOW, &disc_how, DISCOUNT, &discount, TAXABLE, &taxable, TAXINCLUDED, &taxincluded, TAX_TABLE, &tax_table, -1); // TODO: Assign a new invoice number if one is absent. BUT we don't want to assign a new invoice for every line!! // so we'd have to flag this up somehow or add an option in the import GUI. The former implies that we make // an assumption about what the importer (person) wants to do. It seems reasonable that a CSV file full of items with // If an invoice exists then we add to it in this current schema. // no predefined invoice number is a new invoice that's in need of a new number. // This was not designed to satisfy the need for repeat invoices however, so maybe we need a another method for this, after all // It should be easier to copy an invoice with a new ID than to go through all this malarky. if (g_ascii_strcasecmp (type, "BILL") == 0) invoice = gnc_search_bill_on_id (book, id); else if (g_ascii_strcasecmp (type, "INVOICE") == 0) invoice = gnc_search_invoice_on_id (book, id); DEBUG( "Existing %s ID: %s\n", type, gncInvoiceGetID(invoice)); // If the search is empty then there is no existing invoice so make a new one if (invoice == NULL) { DEBUG( "Creating a new : %s\n", type ); // new invoice invoice = gncInvoiceCreate (book); /* Protect against thrashing the DB and trying to write the invoice * record prematurely */ gncInvoiceBeginEdit (invoice); gncInvoiceSetID (invoice, id); owner = gncOwnerNew (); if (g_ascii_strcasecmp (type, "BILL") == 0) gncOwnerInitVendor (owner, gnc_search_vendor_on_id (book, owner_id)); else if (g_ascii_strcasecmp (type, "INVOICE") == 0) gncOwnerInitCustomer (owner, gnc_search_customer_on_id (book, owner_id)); gncInvoiceSetOwner (invoice, owner); gncInvoiceSetCurrency (invoice, gncOwnerGetCurrency (owner)); // Set the invoice currency based on the owner if (strlen (date_opened) != 0) // If a date is specified in CSV { // FIXME: Must check for the return value of qof_scan_date! qof_scan_date (date_opened, &day, &month, &year); gncInvoiceSetDateOpened (invoice, gnc_dmy2timespec (day, month, year)); } else // If no date in CSV { time64 now = gnc_time (NULL); Timespec now_timespec; timespecFromTime64 (&now_timespec, now); gncInvoiceSetDateOpened (invoice, now_timespec); } gncInvoiceSetBillingID (invoice, billing_id ? billing_id : ""); notes = un_escape(notes); gncInvoiceSetNotes (invoice, notes ? notes : ""); gncInvoiceSetActive (invoice, TRUE); //if (g_ascii_strcasecmp(type,"INVOICE"))gncInvoiceSetBillTo( invoice, billto ); (*n_invoices_created)++; update = YES; // open new bill / invoice in a tab, if requested if (g_ascii_strcasecmp(open_mode, "ALL") == 0 || (g_ascii_strcasecmp(open_mode, "NOT_POSTED") == 0 && strlen(date_posted) == 0)) { iw = gnc_ui_invoice_edit (invoice); gnc_plugin_page_invoice_new (iw); } gncInvoiceCommitEdit (invoice); } // I want to warn the user that an existing billvoice exists, but not every // time. // An import can contain many lines usually referring to the same invoice. // NB: Posted invoices are NEVER updated. else // if invoice exists { if (gncInvoiceIsPosted (invoice)) // Is it already posted? { valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); continue; // If already posted then never import } if (update != YES) // Pop up a dialog to ask if updates are the expected action { dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, "%s", _("Are you sure you have bills/invoices to update?")); update = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (update == NO) { // Cleanup and leave g_free (id); g_free (date_opened); g_free (owner_id); g_free (billing_id); g_free (notes); g_free (date); g_free (desc); g_free (action); g_free (account); g_free (quantity); g_free (price); g_free (disc_type); g_free (disc_how); g_free (discount); g_free (taxable); g_free (taxincluded); g_free (tax_table); g_free (date_posted); g_free (due_date); g_free (account_posted); g_free (memo_posted); g_free (accumulatesplits); return; } } (*n_invoices_updated)++; } // add entry to invoice/bill entry = gncEntryCreate (book); gncEntryBeginEdit(entry); currency = gncInvoiceGetCurrency(invoice); if (currency) denom = gnc_commodity_get_fraction(currency); // FIXME: Must check for the return value of qof_scan_date! qof_scan_date (date, &day, &month, &year); { GDate *date = g_date_new_dmy(day, month, year); gncEntrySetDateGDate (entry, date); g_date_free (date); } timespecFromTime64 (&today, gnc_time (NULL)); // set today to the current date gncEntrySetDateEntered (entry, today); // Remove escaped quotes desc = un_escape(desc); notes = un_escape(notes); gncEntrySetDescription (entry, desc); gncEntrySetAction (entry, action); value = gnc_numeric_zero(); gnc_exp_parser_parse (quantity, &value, NULL); // Need to set the denom appropriately else we get stupid rounding errors. value = gnc_numeric_convert (value, denom * 100, GNC_HOW_RND_NEVER); //DEBUG("qty = %s",gnc_num_dbg_to_string(value)); gncEntrySetQuantity (entry, value); acc = gnc_account_lookup_for_register (gnc_get_current_root_account (), account); if (g_ascii_strcasecmp (type, "BILL") == 0) { gncEntrySetBillAccount (entry, acc); value = gnc_numeric_zero(); gnc_exp_parser_parse (price, &value, NULL); value = gnc_numeric_convert (value, denom * 100, GNC_HOW_RND_NEVER); gncEntrySetBillPrice (entry, value); gncEntrySetBillTaxable (entry, text2bool (taxable)); gncEntrySetBillTaxIncluded (entry, text2bool (taxincluded)); gncEntrySetBillTaxTable (entry, gncTaxTableLookupByName (book, tax_table)); gncEntryCommitEdit(entry); gncBillAddEntry (invoice, entry); } else if (g_ascii_strcasecmp (type, "INVOICE") == 0) { gncEntrySetNotes (entry, notes); gncEntrySetInvAccount (entry, acc); value = gnc_numeric_zero(); gnc_exp_parser_parse (price, &value, NULL); value = gnc_numeric_convert (value, denom * 100, GNC_HOW_RND_NEVER); //DEBUG("price = %s",gnc_num_dbg_to_string(value)); gncEntrySetInvPrice (entry, value); gncEntrySetInvTaxable (entry, text2bool (taxable)); gncEntrySetInvTaxIncluded (entry, text2bool (taxincluded)); gncEntrySetInvTaxTable (entry, gncTaxTableLookupByName (book, tax_table)); value = gnc_numeric_zero(); gnc_exp_parser_parse (discount, &value, NULL); value = gnc_numeric_convert (value, denom * 100, GNC_HOW_RND_NEVER); gncEntrySetInvDiscount (entry, value); gncEntrySetInvDiscountType (entry, text2disc_type (disc_type)); gncEntrySetInvDiscountHow (entry, text2disc_how (disc_how)); gncEntryCommitEdit(entry); gncInvoiceAddEntry (invoice, entry); } valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); // handle auto posting of invoices new_id = NULL; if (valid) gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &new_id, -1); if (g_strcmp0 (id, new_id) != 0) { // the next invoice id is different => try to autopost this invoice if (qof_scan_date (date_posted, &day, &month, &year)) { // autopost this invoice gboolean auto_pay; Timespec d1, d2; if (g_ascii_strcasecmp (type, "INVOICE") == 0) auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_AUTO_PAY); else auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY); d1 = gnc_dmy2timespec (day, month, year); // FIXME: Must check for the return value of qof_scan_date! qof_scan_date (due_date, &day, &month, &year); // obtains the due date, or leaves it at date_posted d2 = gnc_dmy2timespec (day, month, year); acc = gnc_account_lookup_for_register (gnc_get_current_root_account (), account_posted); gncInvoicePostToAccount (invoice, acc, &d1, &d2, memo_posted, text2bool (accumulatesplits), auto_pay); DEBUG("Invoice %s posted",id); } } } // cleanup g_free (new_id); g_free (id); g_free (date_opened); g_free (owner_id); g_free (billing_id); g_free (notes); g_free (date); g_free (desc); g_free (action); g_free (account); g_free (quantity); g_free (price); g_free (disc_type); g_free (disc_how); g_free (discount); g_free (taxable); g_free (taxincluded); g_free (tax_table); g_free (date_posted); g_free (due_date); g_free (account_posted); g_free (memo_posted); g_free (accumulatesplits); }
static char* e_vcard_to_string_vcard_30 (EVCard *evc) { GList *l; GList *v; GString *str = g_string_new (""); g_string_append (str, "BEGIN:VCARD" CRLF); /* we hardcode the version (since we're outputting to a specific version) and ignore any version attributes the vcard might contain */ g_string_append (str, "VERSION:3.0" CRLF); for (l = evc->priv->attributes; l; l = l->next) { GList *list; EVCardAttribute *attr = l->data; GString *attr_str; glong len; if (!g_ascii_strcasecmp (attr->name, "VERSION")) continue; attr_str = g_string_new (""); /* From rfc2425, 5.8.2 * * contentline = [group "."] name *(";" param) ":" value CRLF */ if (attr->group) { g_string_append (attr_str, attr->group); g_string_append_c (attr_str, '.'); } g_string_append (attr_str, attr->name); /* handle the parameters */ for (list = attr->params; list; list = list->next) { EVCardAttributeParam *param = list->data; /* 5.8.2: * param = param-name "=" param-value *("," param-value) */ g_string_append_c (attr_str, ';'); g_string_append (attr_str, param->name); if (param->values) { g_string_append_c (attr_str, '='); for (v = param->values; v; v = v->next) { char *value = v->data; char *pval = value; gboolean quotes = FALSE; while (*pval) { if (!g_unichar_isalnum (g_utf8_get_char (pval))) { quotes = TRUE; break; } pval = g_utf8_next_char (pval); } if (quotes) { int i; g_string_append_c (attr_str, '"'); for (i = 0; value [i]; i++) { /* skip quotes in quoted string; it is not allowed */ if (value [i] == '\"') continue; g_string_append_c (attr_str, value [i]); } g_string_append_c (attr_str, '"'); } else g_string_append (attr_str, value); if (v->next) g_string_append_c (attr_str, ','); } } } g_string_append_c (attr_str, ':'); for (v = attr->values; v; v = v->next) { char *value = v->data; char *escaped_value = NULL; escaped_value = e_vcard_escape_string (value); g_string_append (attr_str, escaped_value); if (v->next) { /* XXX toshok - i hate you, rfc 2426. why doesn't CATEGORIES use a ; like a normal list attribute? */ if (!g_ascii_strcasecmp (attr->name, "CATEGORIES")) g_string_append_c (attr_str, ','); else g_string_append_c (attr_str, ';'); } g_free (escaped_value); } /* 5.8.2: * When generating a content line, lines longer than 75 * characters SHOULD be folded */ len = g_utf8_strlen (attr_str->str, -1); if (len > 75) { GString *fold_str = g_string_sized_new (attr_str->len + len/74*3); gchar *pos1 = attr_str->str; gchar *pos2 = pos1; pos2 = g_utf8_offset_to_pointer (pos2, 75); do { g_string_append_len (fold_str, pos1, pos2 - pos1); g_string_append (fold_str, CRLF " "); pos1 = pos2; pos2 = g_utf8_offset_to_pointer (pos2, 74); } while (pos2 < attr_str->str + attr_str->len); g_string_append (fold_str, pos1); g_string_free (attr_str, TRUE); attr_str = fold_str; } g_string_append (attr_str, CRLF); g_string_append (str, attr_str->str); g_string_free (attr_str, TRUE); } g_string_append (str, "END:VCARD"); return g_string_free (str, FALSE); }
/** * tifiles_string_to_model: * @str: a calculator model as string like "TI92". * * Do a string to integer conversion. * * Return value: a calculator model. **/ TIEXPORT2 CalcModel TICALL tifiles_string_to_model(const char *str) { if (str != NULL) { if(!g_ascii_strcasecmp(str, "TI73") || !g_ascii_strcasecmp(str, "73")) return CALC_TI73; else if(!g_ascii_strcasecmp(str, "TI80") || !g_ascii_strcasecmp(str, "80")) return CALC_TI80; else if(!g_ascii_strcasecmp(str, "TI82") || !g_ascii_strcasecmp(str, "82")) return CALC_TI82; else if(!g_ascii_strcasecmp(str, "TI83") || !g_ascii_strcasecmp(str, "83")) return CALC_TI83; else if( !g_ascii_strncasecmp(str, "TI83+", 5) || !g_ascii_strncasecmp(str, "TI83p", 5) || !g_ascii_strncasecmp(str, "83+", 3) || !g_ascii_strncasecmp(str, "83p", 3) ) return CALC_TI83P; else if( !g_ascii_strncasecmp(str, "TI84+", 5) || !g_ascii_strncasecmp(str, "TI84p", 5) || !g_ascii_strncasecmp(str, "84+", 3) || !g_ascii_strncasecmp(str, "84p", 3) ) return CALC_TI84P; else if(!g_ascii_strcasecmp(str, "TI85") || !g_ascii_strcasecmp(str, "85")) return CALC_TI85; else if(!g_ascii_strcasecmp(str, "TI86") || !g_ascii_strcasecmp(str, "86")) return CALC_TI86; else if(!g_ascii_strcasecmp(str, "TI89") || !g_ascii_strcasecmp(str, "89")) return CALC_TI89; else if(!g_ascii_strcasecmp(str, "TI89t") || !g_ascii_strcasecmp(str, "89t")) return CALC_TI89T; else if(!g_ascii_strcasecmp(str, "TI92") || !g_ascii_strcasecmp(str, "92")) return CALC_TI92; else if( !g_ascii_strncasecmp(str, "TI92+", 5) || !g_ascii_strncasecmp(str, "TI92p", 5) || !g_ascii_strncasecmp(str, "92+", 3) || !g_ascii_strncasecmp(str, "92p", 3) ) return CALC_TI92P; else if(!g_ascii_strcasecmp(str, "TIV200") || !g_ascii_strcasecmp(str, "V200")) return CALC_V200; else if(!g_ascii_strcasecmp(str, "TI84+ USB") || !g_ascii_strcasecmp(str, "84+ USB")) return CALC_TI84P_USB; else if(!g_ascii_strcasecmp(str, "TI89t USB") || !g_ascii_strcasecmp(str, "89T USB")) return CALC_TI89T_USB; else if(!g_ascii_strncasecmp(str, "TI NSpire", 9) || !g_ascii_strncasecmp(str, "NSpire", 6)) return CALC_NSPIRE; } return CALC_NONE; }
static void xmms_modplug_config_changed (xmms_object_t *obj, xmmsv_t *_value, gpointer udata) { xmms_modplug_data_t *data = udata; xmms_config_property_t *prop = (xmms_config_property_t *) obj; const gchar *name; const gchar *value; gint intvalue; name = xmms_config_property_get_name (prop); if (!g_ascii_strcasecmp (name, "modplug.resample")) { value = xmms_config_property_get_string (prop); if (!g_ascii_strcasecmp (value, "fir")) { data->settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; } else if (!g_ascii_strcasecmp (value, "spline")) { data->settings.mResamplingMode = MODPLUG_RESAMPLE_SPLINE; } else if (!g_ascii_strcasecmp (value, "linear")) { data->settings.mResamplingMode = MODPLUG_RESAMPLE_LINEAR; } else { data->settings.mResamplingMode = MODPLUG_RESAMPLE_NEAREST; } } else { intvalue = xmms_config_property_get_int (prop); if (!g_ascii_strcasecmp (name, "modplug.freq")) { data->settings.mFrequency = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.reverb_depth")) { data->settings.mReverbDepth = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.reverb_delay")) { data->settings.mReverbDelay = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.bass_amount")) { data->settings.mBassAmount = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.bass_range")) { data->settings.mBassRange = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.surround_depth")) { data->settings.mSurroundDepth = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.surround_delay")) { data->settings.mSurroundDelay = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.loop")) { data->settings.mLoopCount = intvalue; } else if (!g_ascii_strcasecmp (name, "modplug.enable_oversampling")) { if (intvalue) { data->settings.mFlags |= MODPLUG_ENABLE_OVERSAMPLING; } else { data->settings.mFlags &= ~MODPLUG_ENABLE_OVERSAMPLING; } } else if (!g_ascii_strcasecmp (name, "modplug.enable_noise_reduction")) { if (intvalue) { data->settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION; } else { data->settings.mFlags &= ~MODPLUG_ENABLE_NOISE_REDUCTION; } } else if (!g_ascii_strcasecmp (name, "modplug.enable_reverb")) { if (intvalue) { data->settings.mFlags |= MODPLUG_ENABLE_REVERB; } else { data->settings.mFlags &= ~MODPLUG_ENABLE_REVERB; } } else if (!g_ascii_strcasecmp (name, "modplug.enable_megabass")) { if (intvalue) { data->settings.mFlags |= MODPLUG_ENABLE_MEGABASS; } else { data->settings.mFlags &= ~MODPLUG_ENABLE_MEGABASS; } } else if (!g_ascii_strcasecmp (name, "modplug.enable_surround")) { if (intvalue) { data->settings.mFlags |= MODPLUG_ENABLE_SURROUND; } else { data->settings.mFlags &= ~MODPLUG_ENABLE_SURROUND; } } } ModPlug_SetSettings (&data->settings); }
static void parse_args (int argc, char **argv) { int iarg = 1; char *arg; while (iarg < argc) { arg = argv[iarg]; if (g_ascii_strcasecmp (arg, "-np") == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) np = tmp; else g_printerr ("Invalid particles number (-np %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-pr") == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1 && tmp > 0) order = tmp; else g_printerr ("Invalid precision order value (-pr %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-s") == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1 && tmp > 0) maxbox = tmp; else g_printerr ("Invalid maximum box size value (-s %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-err") == 0) { gdouble tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%lf", &tmp) == 1 && tmp > 0.) err_lim = tmp; else g_printerr ("Invalid error limit value (-err %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-nocheck") == 0) { check = FALSE; } else if (g_ascii_strcasecmp (arg, "-check") == 0) { check = TRUE; } else if (g_ascii_strcasecmp (arg, "-direct") == 0) { direct = TRUE; } else if (g_ascii_strcasecmp (arg, "-dist") == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (g_ascii_strcasecmp (arg, "circle") == 0) { _distribution = _one_circle_distribution; } else if (g_ascii_strcasecmp (arg, "random") == 0) { _distribution = _random_distribution; } else if (g_ascii_strcasecmp (arg, "grid") == 0) { _distribution = _grid_distribution; } else { g_printerr ("Invalid distribution name (-dist %s)\n", arg); } } else if (g_ascii_strcasecmp (arg, "-translation") == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (g_ascii_strcasecmp (arg, "normal") == 0) { m2m = (AranMultipole2MultipoleFunc3d) aran_development3d_m2m; m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l; l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l; } else if (g_ascii_strcasecmp (arg, "kkylin") == 0) { m2m = (AranMultipole2MultipoleFunc3d) aran_development3d_m2m_kkylin; m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l_kkylin; l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l_kkylin; } else { g_printerr ("Invalid translation name (-translation %s)\n", arg); } } else if (g_ascii_strcasecmp (arg, "--version") == 0) { g_printerr ("%s version %s\n", argv[0], PACKAGE_VERSION); exit (0); } else { g_printerr ("Invalid argument \"%s\"\n", arg); } iarg ++; } }
int cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[]) { int wild = FALSE; int or = FALSE; int off = FALSE; int quiet = FALSE; int erase = FALSE; int i = 0, finds = 0, found; int idx = 2; int prev_numeric; char *var, *val, *prev_string; if (g_ascii_strcasecmp (word[2], "-e") == 0) { idx++; erase = TRUE; } /* turn a bit OFF */ if (g_ascii_strcasecmp (word[idx], "-off") == 0) { idx++; off = TRUE; } /* turn a bit ON */ if (g_ascii_strcasecmp (word[idx], "-or") == 0 || g_ascii_strcasecmp (word[idx], "-on") == 0) { idx++; or = TRUE; } if (g_ascii_strcasecmp (word[idx], "-quiet") == 0) { idx++; quiet = TRUE; } var = word[idx]; val = word_eol[idx+1]; if (!*var) { set_list (sess, tbuf); return TRUE; } if ((strchr (var, '*') || strchr (var, '?')) && !*val) { wild = TRUE; } if (*val == '=') { val++; } do { if (wild) { found = !match (var, vars[i].name); } else { found = g_ascii_strcasecmp (var, vars[i].name); } if (found == 0) { finds++; switch (vars[i].type) { case TYPE_STR: if (erase || *val) { /* save the previous value until we print it out */ prev_string = (char*) malloc (vars[i].len + 1); strncpy (prev_string, (char *) &prefs + vars[i].offset, vars[i].len); /* update the variable */ strncpy ((char *) &prefs + vars[i].offset, val, vars[i].len); ((char *) &prefs)[vars[i].offset + vars[i].len - 1] = 0; if (!quiet) { PrintTextf (sess, "%s set to: %s (was: %s)\n", var, (char *) &prefs + vars[i].offset, prev_string); } free (prev_string); } else { set_showval (sess, &vars[i], tbuf); } break; case TYPE_INT: case TYPE_BOOL: if (*val) { prev_numeric = *((int *) &prefs + vars[i].offset); if (vars[i].type == TYPE_BOOL) { if (atoi (val)) { *((int *) &prefs + vars[i].offset) = 1; } else { *((int *) &prefs + vars[i].offset) = 0; } if (!g_ascii_strcasecmp (val, "YES") || !g_ascii_strcasecmp (val, "ON")) { *((int *) &prefs + vars[i].offset) = 1; } if (!g_ascii_strcasecmp (val, "NO") || !g_ascii_strcasecmp (val, "OFF")) { *((int *) &prefs + vars[i].offset) = 0; } } else { if (or) { *((int *) &prefs + vars[i].offset) |= atoi (val); } else if (off) { *((int *) &prefs + vars[i].offset) &= ~(atoi (val)); } else { *((int *) &prefs + vars[i].offset) = atoi (val); } } if (!quiet) { PrintTextf (sess, "%s set to: %d (was: %d)\n", var, *((int *) &prefs + vars[i].offset), prev_numeric); } } else { set_showval (sess, &vars[i], tbuf); } break; } } i++; } while (vars[i].name); if (!finds && !quiet) { PrintText (sess, "No such variable.\n"); } else if (!save_config ()) { PrintText (sess, "Error saving changes to disk.\n"); } return TRUE; }
static CamelSExpResult * check_header (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms, camel_search_match_t how) { gboolean matched = FALSE; CamelSExpResult *r; gint i; if (argc > 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) { gchar *name = argv[0]->value.string; /* shortcut: a match for "" against any header always matches */ for (i = 1; i < argc && !matched; i++) matched = argv[i]->type == CAMEL_SEXP_RES_STRING && argv[i]->value.string[0] == 0; if (g_ascii_strcasecmp (name, "x-camel-mlist") == 0) { const gchar *list = camel_message_info_get_mlist (fms->info); if (list) { for (i = 1; i < argc && !matched; i++) { if (argv[i]->type == CAMEL_SEXP_RES_STRING) matched = camel_search_header_match (list, argv[i]->value.string, how, CAMEL_SEARCH_TYPE_MLIST, NULL); } } } else if (fms->message || !check_header_in_message_info (fms->info, argc, argv, how, &matched)) { CamelMimeMessage *message; CamelMimePart *mime_part; struct _camel_header_raw *header; const gchar *charset = NULL; camel_search_t type = CAMEL_SEARCH_TYPE_ENCODED; CamelContentType *ct; message = camel_filter_search_get_message (fms, f); mime_part = CAMEL_MIME_PART (message); if (camel_search_header_is_address (name)) type = CAMEL_SEARCH_TYPE_ADDRESS_ENCODED; else if (message) { ct = camel_mime_part_get_content_type (mime_part); if (ct) { charset = camel_content_type_param (ct, "charset"); charset = camel_iconv_charset_name (charset); } } for (header = mime_part->headers; header && !matched; header = header->next) { /* empty name means any header */ if (!name || !*name || !g_ascii_strcasecmp (header->name, name)) { for (i = 1; i < argc && !matched; i++) { if (argv[i]->type == CAMEL_SEXP_RES_STRING) matched = camel_search_header_match (header->value, argv[i]->value.string, how, type, charset); } } } } } r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL); r->value.boolean = matched; return r; }
gint my_comparator(gconstpointer item1, gconstpointer item2) { return g_ascii_strcasecmp(item1, item2); }
/** * g_mime_iconv_open: (skip) * @to: charset to convert to * @from: charset to convert from * * Allocates a coversion descriptor suitable for converting byte * sequences from charset @from to charset @to. The resulting * descriptor can be used with iconv() (or the g_mime_iconv() wrapper) any * number of times until closed using g_mime_iconv_close(). * * See the manual page for iconv_open(3) for further details. * * Returns: a new conversion descriptor for use with g_mime_iconv() on * success or (iconv_t) %-1 on fail as well as setting an appropriate * errno value. **/ iconv_t g_mime_iconv_open (const char *to, const char *from) { IconvCacheNode *node; iconv_t cd; char *key; if (from == NULL || to == NULL) { errno = EINVAL; return (iconv_t) -1; } if (!g_ascii_strcasecmp (from, "x-unknown")) from = g_mime_locale_charset (); from = g_mime_charset_iconv_name (from); to = g_mime_charset_iconv_name (to); key = g_alloca (strlen (from) + strlen (to) + 2); sprintf (key, "%s:%s", from, to); ICONV_CACHE_LOCK (); if ((node = (IconvCacheNode *) cache_node_lookup (iconv_cache, key, TRUE))) { if (node->used) { if ((cd = iconv_open (to, from)) == (iconv_t) -1) goto exception; } else { /* Apparently iconv on Solaris <= 7 segfaults if you pass in * NULL for anything but inbuf; work around that. (NULL outbuf * or NULL *outbuf is allowed by Unix98.) */ size_t inleft = 0, outleft = 0; char *outbuf = NULL; cd = node->cd; node->used = TRUE; /* reset the descriptor */ iconv (cd, NULL, &inleft, &outbuf, &outleft); } node->refcount++; } else { if ((cd = iconv_open (to, from)) == (iconv_t) -1) goto exception; node = iconv_cache_node_new (key, cd); } g_hash_table_insert (iconv_open_hash, cd, ((CacheNode *) node)->key); ICONV_CACHE_UNLOCK (); return cd; exception: ICONV_CACHE_UNLOCK (); #if w(!)0 if (errno == EINVAL) g_warning ("Conversion from '%s' to '%s' is not supported", from, to); else g_warning ("Could not open converter from '%s' to '%s': %s", from, to, strerror (errno)); #endif return cd; }
int irssi_ssl_handshake(GIOChannel *handle) { GIOSSLChannel *chan = (GIOSSLChannel *)handle; int ret, err; const char *errstr = NULL; X509 *cert = NULL; X509_PUBKEY *pubkey = NULL; int pubkey_size = 0; unsigned char *pubkey_der = NULL; unsigned char *pubkey_der_tmp = NULL; unsigned char pubkey_fingerprint[EVP_MAX_MD_SIZE]; unsigned int pubkey_fingerprint_size; unsigned char cert_fingerprint[EVP_MAX_MD_SIZE]; unsigned int cert_fingerprint_size; const char *pinned_cert_fingerprint = chan->server->connrec->tls_pinned_cert; const char *pinned_pubkey_fingerprint = chan->server->connrec->tls_pinned_pubkey; TLS_REC *tls = NULL; ERR_clear_error(); ret = SSL_connect(chan->ssl); if (ret <= 0) { err = SSL_get_error(chan->ssl, ret); switch (err) { case SSL_ERROR_WANT_READ: return 1; case SSL_ERROR_WANT_WRITE: return 3; case SSL_ERROR_ZERO_RETURN: g_warning("SSL handshake failed: %s", "server closed connection"); return -1; case SSL_ERROR_SYSCALL: errstr = ERR_reason_error_string(ERR_get_error()); if (errstr == NULL && ret == -1) errstr = strerror(errno); g_warning("SSL handshake failed: %s", errstr != NULL ? errstr : "server closed connection unexpectedly"); return -1; default: errstr = ERR_reason_error_string(ERR_get_error()); g_warning("SSL handshake failed: %s", errstr != NULL ? errstr : "unknown SSL error"); return -1; } } cert = SSL_get_peer_certificate(chan->ssl); pubkey = X509_get_X509_PUBKEY(cert); if (cert == NULL) { g_warning("TLS server supplied no certificate"); ret = 0; goto done; } if (pubkey == NULL) { g_warning("TLS server supplied no certificate public key"); ret = 0; goto done; } if (! X509_digest(cert, EVP_sha256(), cert_fingerprint, &cert_fingerprint_size)) { g_warning("Unable to generate certificate fingerprint"); ret = 0; goto done; } pubkey_size = i2d_X509_PUBKEY(pubkey, NULL); pubkey_der = pubkey_der_tmp = g_new(unsigned char, pubkey_size); i2d_X509_PUBKEY(pubkey, &pubkey_der_tmp); EVP_Digest(pubkey_der, pubkey_size, pubkey_fingerprint, &pubkey_fingerprint_size, EVP_sha256(), 0); tls = tls_create_rec(); set_cipher_info(tls, chan->ssl); set_pubkey_info(tls, cert, cert_fingerprint, cert_fingerprint_size, pubkey_fingerprint, pubkey_fingerprint_size); set_peer_cert_chain_info(tls, chan->ssl); set_server_temporary_key_info(tls, chan->ssl); /* Emit the TLS rec. */ signal_emit("tls handshake finished", 2, chan->server, tls); ret = 1; if (pinned_cert_fingerprint != NULL && pinned_cert_fingerprint[0] != '\0') { ret = g_ascii_strcasecmp(pinned_cert_fingerprint, tls->certificate_fingerprint) == 0; if (! ret) { g_warning(" Pinned certificate mismatch"); goto done; } } if (pinned_pubkey_fingerprint != NULL && pinned_pubkey_fingerprint[0] != '\0') { ret = g_ascii_strcasecmp(pinned_pubkey_fingerprint, tls->public_key_fingerprint) == 0; if (! ret) { g_warning(" Pinned public key mismatch"); goto done; } } if (chan->verify) { ret = irssi_ssl_verify(chan->ssl, chan->ctx, chan->server->connrec->address, chan->port, cert, chan->server, tls); if (! ret) { /* irssi_ssl_verify emits a warning itself. */ goto done; } } done: tls_rec_free(tls); X509_free(cert); g_free(pubkey_der); return ret ? 0 : -1; }
static void parse_args (int argc, char **argv) { int iarg = 1; char *arg; while (iarg < argc) { arg = argv[iarg]; if (g_ascii_strcasecmp (arg, "-np") == 0) { guint64 tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%lu", &tmp) == 1) np = tmp; else g_printerr ("Invalid particles number (-np %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-pr") == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1 && tmp > 0) order = tmp; else g_printerr ("Invalid precision order value (-pr %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-s") == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1 && tmp > 0) maxbox = tmp; else g_printerr ("Invalid maximum box size value (-s %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "-virtual-maxbox", 15) == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) virtual_maxbox = tmp; else g_printerr ("Invalid virtual maxbox (-virtual-maxbox %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-err") == 0) { gdouble tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%lf", &tmp) == 1) err_lim = tmp; else g_printerr ("Invalid error limit value (-err %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-semifar") == 0) { guint tmp = 0; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (sscanf (arg, "%u", &tmp) == 1) semifar_threshold = tmp; else g_printerr ("Invalid semifar threshold (-semifar %s)\n", arg); } else if (g_ascii_strcasecmp (arg, "-nocheck") == 0) { check = FALSE; } else if (g_ascii_strcasecmp (arg, "-check") == 0) { check = TRUE; } else if (g_ascii_strcasecmp (arg, "-direct") == 0) { direct = TRUE; } else if (g_ascii_strcasecmp (arg, "-dist") == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (g_ascii_strcasecmp (arg, "circle") == 0) { _fill = _one_circle_fill; } else if (g_ascii_strcasecmp (arg, "random2") == 0) { _fill = _random2_fill; } else if (g_ascii_strcasecmp (arg, "unbalanced") == 0) { _fill = _unbalanced_fill; } else if (g_ascii_strcasecmp (arg, "random") == 0) { _fill = _random_fill; } else if (g_ascii_strcasecmp (arg, "grid") == 0) { _fill = _grid_fill; } else if (g_ascii_strcasecmp (arg, "uvsphere") == 0) { _fill = _uvsphere_fill; } else if (g_ascii_strcasecmp (arg, "plummer") == 0) { _fill = _plummer_fill; } else if (g_ascii_strcasecmp (arg, "load") == 0) { _fill = _load_fill; iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; _load_file = g_malloc (1024*sizeof (gchar)); sscanf (arg, "%s", _load_file); } else { g_printerr ("Invalid fill name (-dist %s)\n", arg); } } else if (g_ascii_strcasecmp (arg, "-translation") == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; if (g_ascii_strcasecmp (arg, "normal") == 0) { m2m = (AranMultipole2MultipoleFunc3d) aran_development3d_m2m; m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l; l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l; } else if (g_ascii_strcasecmp (arg, "kkylin") == 0) { m2m = (AranMultipole2MultipoleFunc3d) aran_development3d_m2m_kkylin; m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l_kkylin; l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l_kkylin; } else if (g_ascii_strcasecmp (arg, "rotate") == 0) { m2m = (AranMultipole2MultipoleFunc3d) aran_development3d_m2m_rotate; m2l = (AranMultipole2LocalFunc3d) aran_development3d_m2l_rotate; l2l = (AranLocal2LocalFunc3d) aran_development3d_l2l_rotate; } else { g_printerr ("Invalid translation name (-translation %s)\n", arg); } } else if (g_ascii_strcasecmp (arg, "-hilbert") == 0) { _hilbert = TRUE; } else if (g_ascii_strncasecmp (arg, "--save-fma", 10) == 0) { iarg ++; arg = (iarg<argc) ? argv[iarg] : NULL; _save_fma_filename = arg; if (arg == NULL) g_printerr ("Invalid FMA save file name (--save-fma %s)\n", arg); } else if (g_ascii_strncasecmp (arg, "-v", 2) == 0 || g_ascii_strncasecmp (arg, "--verbose", 9) == 0) { _verbose = TRUE; } else if (g_ascii_strncasecmp (arg, "--write", 9) == 0) { _write = TRUE; } else if (g_ascii_strcasecmp (arg, "--version") == 0) { g_printerr ("%s version %s\n", argv[0], PACKAGE_VERSION); exit (0); } else { g_printerr ("Invalid argument \"%s\"\n", arg); } iarg ++; } }
bool UT_Xpm2Bmp(UT_uint32 maxWidth, UT_uint32 maxHeight, const char ** pIconData, UT_uint32 sizeofData, HDC hdc, UT_RGBColor * pBackgroundColor, HBITMAP * pBitmap) { // convert an XPM into a BMP using a DIB. // return true if successful. UT_ASSERT(pIconData && *pIconData); UT_ASSERT(sizeofData > 0); UT_ASSERT(pBackgroundColor); UT_ASSERT(pBitmap); // first row contains: width height, number of colors, chars per pixel UT_uint32 width, height, xpm_width, xpm_height, nrColors, charsPerPixel; UT_uint32 cut_left, cut_top; UT_uint32 n = sscanf(pIconData[0],"%ld %ld %ld %ld", &xpm_width,&xpm_height,&nrColors,&charsPerPixel); UT_ASSERT(n == 4); UT_ASSERT(xpm_width > 0); UT_ASSERT(xpm_height > 0); UT_ASSERT(charsPerPixel > 0); width = xpm_width < maxWidth ? xpm_width : maxWidth; cut_left = xpm_width - width; cut_left -= cut_left / 2; height = xpm_height < maxHeight ? xpm_height : maxHeight; cut_top = xpm_height - height; cut_top -= cut_top / 2; UT_uint32 sizeofColorData = nrColors * sizeof(RGBQUAD); UT_uint32 widthRoundedUp = _RoundUp(width,sizeof(LONG)); UT_uint32 rowPadding = widthRoundedUp - width; UT_uint32 sizeofPixelData = widthRoundedUp * height; UT_uint32 sizeofStructure = sizeof(BITMAPINFOHEADER) + sizeofColorData + sizeofPixelData; UT_Byte * pInfo = (UT_Byte *)UT_calloc(1,sizeofStructure); if (!pInfo) return false; BITMAPINFO * pbmi = (BITMAPINFO *)pInfo; BITMAPINFOHEADER * pbmih = &pbmi->bmiHeader; RGBQUAD * pRGB = (RGBQUAD *)(pInfo + sizeof(BITMAPINFOHEADER)); UT_Byte * pPixel = (UT_Byte *)(pInfo + sizeof(BITMAPINFOHEADER) + sizeofColorData); pbmih->biSize = sizeof(BITMAPINFOHEADER); pbmih->biWidth = width; pbmih->biHeight = -(LONG)height; // minus height gives us a top-down bitmap pbmih->biPlanes = 1; pbmih->biBitCount = 8; pbmih->biCompression = BI_RGB; pbmih->biSizeImage = 0; pbmih->biXPelsPerMeter = 0; pbmih->biYPelsPerMeter = 0; pbmih->biClrUsed = nrColors; // should we verify that they are all actually used ?? pbmih->biClrImportant = 0; UT_StringPtrMap hash(256); UT_RGBColor color(0,0,0); // walk thru the palette // use a local UT_String, else every call to hash.insert and hash.pick // creates and destroys its own UT_String UT_String sTmp; const char ** pIconDataPalette = &pIconData[1]; for (UT_uint32 k=0; (k < nrColors); k++) { char bufSymbol[10] = { 0 }; char bufKey[10]; char bufColorValue[100]; // we expect something of the form: ".. c #000000" // or we can accpet ".. g #000000" for gray scale // but we allow a space as a character in the symbol, so we // get the first field the hard way. for (UT_uint32 kPx=0; (kPx < charsPerPixel); kPx++) bufSymbol[kPx] = pIconDataPalette[k][kPx]; UT_ASSERT(strlen(bufSymbol) == charsPerPixel); UT_uint32 nf = sscanf(&pIconDataPalette[k][charsPerPixel+1]," %s %s",&bufKey,&bufColorValue); UT_ASSERT(nf == 2); UT_ASSERT(bufKey[0] == 'c' || bufKey[0] == 'g'); // make the ".." a hash key and store our color index as the data. // we add k+1 because the hash code does not like null pointers... sTmp = bufSymbol; hash.insert(sTmp, (void *)(k+1)); // store the actual color value in the rgb quad array with our color index. if (g_ascii_strcasecmp(bufColorValue,"None")==0) { pRGB[k].rgbRed = pBackgroundColor->m_red; pRGB[k].rgbGreen = pBackgroundColor->m_grn; pRGB[k].rgbBlue = pBackgroundColor->m_blu; pRGB[k].rgbReserved = 0; } else { // TODO fix this to also handle #ffffeeeedddd type color references UT_ASSERT((bufColorValue[0] == '#') && strlen(bufColorValue)==7); UT_parseColor(bufColorValue, color); pRGB[k].rgbRed = color.m_red; pRGB[k].rgbGreen = color.m_grn; pRGB[k].rgbBlue = color.m_blu; pRGB[k].rgbReserved = 0; } } // walk thru the image data const char ** pIconDataImage = &pIconDataPalette[nrColors]; for (UT_uint32 kRow=0; (kRow < height); kRow++) { const char * p = pIconDataImage[kRow+cut_top]; p += cut_left * charsPerPixel; for (UT_uint32 kCol=0; (kCol < width); kCol++) { char bufPixel[10] = { 0 }; for (UT_uint32 kPx=0; (kPx < charsPerPixel); kPx++) bufPixel[kPx] = *p++; sTmp = bufPixel; guint32 pEntry = (guint32) hash.pick(sTmp); *pPixel++ = ((UT_Byte)(pEntry)) - 1; } pPixel += rowPadding; } UT_ASSERT(pPixel == (pInfo + sizeofStructure)); pPixel = (UT_Byte *)(pInfo + sizeof(BITMAPINFOHEADER) + sizeofColorData); HBITMAP hBitmap = CreateDIBitmap(hdc,pbmih,CBM_INIT,pPixel,pbmi,DIB_RGB_COLORS); *pBitmap = hBitmap; g_free(pInfo); return (hBitmap != 0); }
static gboolean gst_ks_video_src_open_device (GstKsVideoSrc * self) { GstKsVideoSrcPrivate *priv = GST_KS_VIDEO_SRC_GET_PRIVATE (self); GstKsVideoDevice *device = NULL; GList *devices, *cur; g_assert (priv->device == NULL); devices = ks_enumerate_devices (&KSCATEGORY_VIDEO, &KSCATEGORY_CAPTURE); if (devices == NULL) goto error_no_devices; devices = ks_video_device_list_sort_cameras_first (devices); for (cur = devices; cur != NULL; cur = cur->next) { KsDeviceEntry *entry = cur->data; GST_DEBUG_OBJECT (self, "device %d: name='%s' path='%s'", entry->index, entry->name, entry->path); } for (cur = devices; cur != NULL; cur = cur->next) { KsDeviceEntry *entry = cur->data; gboolean match; if (device != NULL) { ks_device_entry_free (entry); continue; } if (priv->device_path != NULL) { match = g_ascii_strcasecmp (entry->path, priv->device_path) == 0; } else if (priv->device_name != NULL) { match = g_ascii_strcasecmp (entry->name, priv->device_name) == 0; } else if (priv->device_index >= 0) { match = entry->index == priv->device_index; } else { match = TRUE; /* pick the first entry */ } if (match) { priv->ksclock = g_object_new (GST_TYPE_KS_CLOCK, NULL); if (priv->ksclock != NULL && gst_ks_clock_open (priv->ksclock)) { GstClock *clock = GST_ELEMENT_CLOCK (self); if (clock != NULL) gst_ks_clock_provide_master_clock (priv->ksclock, clock); } else { GST_WARNING_OBJECT (self, "failed to create/open KsClock"); g_object_unref (priv->ksclock); priv->ksclock = NULL; } device = gst_ks_video_device_new (entry->path, priv->ksclock, gst_ks_video_src_alloc_buffer, self); } ks_device_entry_free (entry); } g_list_free (devices); if (device == NULL) goto error_no_match; if (!gst_ks_video_device_open (device)) goto error_open; priv->device = device; return TRUE; /* ERRORS */ error_no_devices: { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("No video capture devices found"), (NULL)); return FALSE; } error_no_match: { if (priv->device_path != NULL) { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("Specified video capture device with path '%s' not found", priv->device_path), (NULL)); } else if (priv->device_name != NULL) { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("Specified video capture device with name '%s' not found", priv->device_name), (NULL)); } else { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("Specified video capture device with index %d not found", priv->device_index), (NULL)); } return FALSE; } error_open: { GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, ("Failed to open device"), (NULL)); g_object_unref (device); return FALSE; } }
//! \brief try to fix some common errors in the csv representation of invoices //! * corrects the date format //! * corrects ambigous values in multi line invoices //! * ensures customer exists //! * if quantity is unset, set to 1 //! * if price is unset, delete row void gnc_bi_import_fix_bis (GtkListStore * store, guint * fixed, guint * deleted, GString * info, gchar *type) { GtkTreeIter iter; gboolean valid, row_deleted, row_fixed; gchar *id = NULL, *date_opened = NULL, *date_posted = NULL, *due_date = NULL, *owner_id = NULL, *date = NULL, *quantity = NULL, *price = NULL; GString *prev_id, *prev_date_opened, *prev_date_posted, *prev_owner_id, *prev_date; // needed to fix multi line invoices guint dummy; gint row = 1; const gchar* date_format_string = qof_date_format_get_string (qof_date_format_get()); // Get the user set date format string //date_format_string = qof_date_format_get_string (qof_date_format_get()); DEBUG("date_format_string: %s",date_format_string); // allow the call to this function with only GtkListeStore* specified if (!fixed) fixed = &dummy; if (!deleted) deleted = &dummy; *fixed = 0; *deleted = 0; // init strings prev_id = g_string_new (""); prev_date_opened = g_string_new (""); prev_date_posted = g_string_new (""); prev_owner_id = g_string_new (""); prev_date = g_string_new (""); valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); while (valid) { row_deleted = FALSE; row_fixed = FALSE; // Walk through the list, reading each row gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &id, DATE_OPENED, &date_opened, DATE_POSTED, &date_posted, DUE_DATE, &due_date, OWNER_ID, &owner_id, DATE, &date, QUANTITY, &quantity, PRICE, &price, -1); if (strlen (price) == 0) { // invalid row (no price given) // no fix possible -> delete row valid = gtk_list_store_remove (store, &iter); row_deleted = TRUE; g_string_append_printf (info, _("ROW %d DELETED, PRICE_NOT_SET: id=%s\n"), row, id); } // TODO: QTY get set to 1 later if field is empty. Delete this section? else if (strlen (quantity) == 0) { // invalid row (no quantity given) // no fix possible -> delete row valid = gtk_list_store_remove (store, &iter); row_deleted = TRUE; g_string_append_printf (info, _("ROW %d DELETED, QTY_NOT_SET: id=%s\n"), row, id); } else { // TODO: If id is empty get the next one in the series. Bug 731105 if (strlen (id) == 0) { // no invoice id specified if (prev_id->len == 0) { // cannot fix -> delete row valid = gtk_list_store_remove (store, &iter); row_deleted = TRUE; g_string_append_printf (info, _("ROW %d DELETED, ID_NOT_SET\n"), row); } else { // this is a fixable multi line invoice gtk_list_store_set (store, &iter, ID, prev_id->str, -1); row_fixed = TRUE; } } else { // remember invoice id (to be able to fix multi line invoices) g_string_assign (prev_id, id); // new invoice => reset all other fixable entries g_string_assign (prev_date_opened, ""); g_string_assign (prev_date_posted, ""); g_string_assign (prev_owner_id, ""); g_string_assign (prev_date, ""); } } if (!row_deleted) { // the row is valid (price and id are valid) if(!isDateValid(date_opened)) { if (prev_date_opened->len == 0) { // fix this by using the current date gchar temp[20]; GDate date; g_date_clear (&date, 1); gnc_gdate_set_today (&date); g_date_strftime (temp, 20, date_format_string, &date); // Create a user specified date string. g_string_assign (prev_date_opened, temp); } // fix this by using the previous date_opened value (multi line invoice) gtk_list_store_set (store, &iter, DATE_OPENED, prev_date_opened->str, -1); row_fixed = TRUE; } else { // remember date_opened (to be able to fix multi line invoices) g_string_assign (prev_date_opened, date_opened); } // date_opened is valid if(!isDateValid(date_posted)) { if (prev_date_posted->len == 0) { // this invoice will have to get posted manually } else { // multi line invoice => fix it gtk_list_store_set (store, &iter, DATE_POSTED, prev_date_posted->str, -1); row_fixed = TRUE; } } else { // remember date_opened (to be able to fix multi line invoices) g_string_assign (prev_date_posted, date_posted); } // date_posted is valid /* // Check if due date is valid. Set it to date_posted if not valid or missing. if(!isDateValid(due_date)) { gtk_list_store_set (store, &iter, DUE_DATE, date_posted, -1); row_fixed = TRUE; } // due_date is valid */ if (strlen (quantity) == 0) { // quantity is unset => set to 1 gtk_list_store_set (store, &iter, QUANTITY, "1", -1); row_fixed = TRUE; } // quantity is valid if (strlen (owner_id) == 0) { if (prev_owner_id->len == 0) { // no customer given and not fixable => delete row valid = gtk_list_store_remove (store, &iter); row_deleted = TRUE; g_string_append_printf (info, _("ROW %d DELETED, OWNER_NOT_SET: id=%s\n"), row, id); } else { gtk_list_store_set (store, &iter, owner_id, prev_owner_id->str, -1); row_fixed = TRUE; } } else { // remember owner_id g_string_assign (prev_owner_id, owner_id); } if (g_ascii_strcasecmp (type, "BILL") == 0) { // BILL: check, if vendor exists if (!gnc_search_vendor_on_id (gnc_get_current_book (), prev_owner_id->str)) { // vendor not found => delete row valid = gtk_list_store_remove (store, &iter); row_deleted = TRUE; g_string_append_printf (info, _("ROW %d DELETED, VENDOR_DOES_NOT_EXIST: id=%s\n"), row, id); } } else if (g_ascii_strcasecmp (type, "INVOICE") == 0) { // INVOICE: check, if customer exists if (!gnc_search_customer_on_id (gnc_get_current_book (), prev_owner_id->str)) { // customer not found => delete row valid = gtk_list_store_remove (store, &iter); row_deleted = TRUE; g_string_append_printf (info, _("ROW %d DELETED, CUSTOMER_DOES_NOT_EXIST: id=%s\n"), row, id); } } // owner_id is valid } g_free (id); g_free (date_opened); g_free (date_posted); g_free (owner_id); g_free (date); g_free (quantity); g_free (price); if (row_deleted) { (*deleted)++; // reset all remembered values g_string_assign (prev_id, ""); g_string_assign (prev_date_opened, ""); g_string_assign (prev_date_posted, ""); g_string_assign (prev_owner_id, ""); g_string_assign (prev_date, ""); } else if (row_fixed) (*fixed)++; if (!row_deleted) valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); row++; } // deallocate strings g_string_free (prev_id, TRUE); g_string_free (prev_date_opened, TRUE); g_string_free (prev_date_posted, TRUE); g_string_free (prev_owner_id, TRUE); g_string_free (prev_date, TRUE); if (info && (info->len > 0)) { g_string_prepend (info, "\n\n"); g_string_prepend (info, _("These rows were deleted:")); } }
HTMLStyle * html_style_add_attribute (HTMLStyle *style, const gchar *attr) { gchar **prop; prop = g_strsplit (attr, ";", 100); if (prop) { gint i; for (i = 0; prop[i]; i++) { gchar *text; text = g_strstrip (prop[i]); if (!g_ascii_strncasecmp ("color: ", text, 7)) { GdkColor color; if (html_parse_color (g_strstrip (text + 7), &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strncasecmp ("background: ", text, 12)) { GdkColor color; if (html_parse_color (text + 12, &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_background_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strncasecmp ("background-color: ", text, 18)) { GdkColor color; if (html_parse_color (text + 18, &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_background_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strncasecmp ("background-image: ", text, 18)) { style = html_style_add_background_image (style, text + 18); } else if (!g_ascii_strncasecmp ("border: ", text, 8)) { style = parse_border (style, text + 8); } else if (!g_ascii_strncasecmp ("border-style: ", text, 14)) { style = parse_border_style (style, text + 14); } else if (!g_ascii_strncasecmp ("border-color: ", text, 14)) { style = parse_border_color (style, text + 14); } else if (!g_ascii_strncasecmp ("border-width: ", text, 14)) { style = parse_border_width (style, text + 14); } else if (!g_ascii_strncasecmp ("padding: ", text, 9)) { gchar *value = text + 9; style = html_style_set_padding (style, atoi (value)); } else if (!g_ascii_strncasecmp ("white-space: ", text, 13)) { /* normal, pre, nowrap, pre-wrap, pre-line, inherit */ /* if (!g_ascii_strcasecmp ("normal", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_NORMAL); } else if (!g_ascii_strcasecmp ("pre", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE); } else if (!g_ascii_strcasecmp ("nowrap", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_NOWRAP); } else if (!g_ascii_strcasecmp ("pre-wrap", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE_WRAP); } else if (!g_ascii_strcasecmp ("pre-line", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE_LINE); } else if (!g_ascii_strcasecmp ("inherit", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_INHERIT); } */ } else if (!g_ascii_strncasecmp ("text-decoration: none", text, 21)) { style = html_style_unset_decoration (style, ~GTK_HTML_FONT_STYLE_SIZE_MASK); } else if (!g_ascii_strncasecmp ("display: ", text, 9)) { gchar *value = text + 9; if (!g_ascii_strcasecmp ("block", value)) { style = html_style_set_display (style, DISPLAY_BLOCK); } else if (!g_ascii_strcasecmp ("inline", value)) { style = html_style_set_display (style, DISPLAY_INLINE); } else if (!g_ascii_strcasecmp ("none", value)) { style = html_style_set_display (style, DISPLAY_NONE); } else if (!g_ascii_strcasecmp ("inline-table", value)) { style = html_style_set_display (style, DISPLAY_INLINE_TABLE); } } else if (!g_ascii_strncasecmp ("text-align: center", text, 18)) { style = html_style_add_text_align (style, HTML_HALIGN_CENTER); } else if (!g_ascii_strncasecmp ("width: ", text, 7)) { style = html_style_add_width (style, text + 7); } else if (!g_ascii_strncasecmp ("height: ", text, 8)) { style = html_style_add_height (style, text + 8); } else if (!g_ascii_strncasecmp ("clear: ", text, 7)) { gchar *value = text + 7; if (!g_ascii_strcasecmp ("left", value)) { style = html_style_set_clear (style, HTML_CLEAR_LEFT); } else if (!g_ascii_strcasecmp ("right", value)) { style = html_style_set_clear (style, HTML_CLEAR_RIGHT); } else if (!g_ascii_strcasecmp ("both", value)) { style = html_style_set_clear (style, HTML_CLEAR_ALL); } else if (!g_ascii_strcasecmp ("inherit", value)) { style = html_style_set_clear (style, HTML_CLEAR_INHERIT); } else if (!g_ascii_strcasecmp ("none", value)) { style = html_style_set_clear (style, HTML_CLEAR_NONE); } } } g_strfreev (prop); } return style; }
static void g_vfs_backend_http_init (GVfsBackendHttp *backend) { const char *debug; SoupSessionFeature *proxy_resolver; SoupSessionFeature *cookie_jar; SoupSessionFeature *content_decoder; g_vfs_backend_set_user_visible (G_VFS_BACKEND (backend), FALSE); backend->session = soup_session_sync_new_with_options ("user-agent", "gvfs/" VERSION, NULL); backend->session_async = soup_session_async_new_with_options ("user-agent", "gvfs/" VERSION, NULL); /* SoupRequester seems to depend on use-thread-context */ g_object_set (G_OBJECT (backend->session_async), "use-thread-context", TRUE, NULL); /* Proxy handling */ proxy_resolver = g_object_new (SOUP_TYPE_PROXY_RESOLVER_GNOME, NULL); soup_session_add_feature (backend->session, proxy_resolver); soup_session_add_feature (backend->session_async, proxy_resolver); g_object_unref (proxy_resolver); /* Cookie handling - stored temporarlly in memory, mostly useful for * authentication in WebDAV. */ cookie_jar = g_object_new (SOUP_TYPE_COOKIE_JAR, NULL); soup_session_add_feature (backend->session, cookie_jar); soup_session_add_feature (backend->session_async, cookie_jar); g_object_unref (cookie_jar); /* Send Accept-Language header (see bug 166795) */ g_object_set (backend->session, "accept-language-auto", TRUE, NULL); g_object_set (backend->session_async, "accept-language-auto", TRUE, NULL); /* Handle decompression automatically */ content_decoder = g_object_new (SOUP_TYPE_CONTENT_DECODER, NULL); soup_session_add_feature (backend->session, content_decoder); soup_session_add_feature (backend->session_async, content_decoder); g_object_unref (content_decoder); /* Request API */ soup_session_add_feature_by_type (backend->session, SOUP_TYPE_REQUESTER); soup_session_add_feature_by_type (backend->session_async, SOUP_TYPE_REQUESTER); /* Logging */ debug = g_getenv ("GVFS_HTTP_DEBUG"); if (debug) { SoupLogger *logger; SoupLoggerLogLevel level; if (g_ascii_strcasecmp (debug, "all") || g_ascii_strcasecmp (debug, "body")) level = SOUP_LOGGER_LOG_BODY; else if (g_ascii_strcasecmp (debug, "header")) level = SOUP_LOGGER_LOG_HEADERS; else level = SOUP_LOGGER_LOG_MINIMAL; logger = soup_logger_new (level, DEBUG_MAX_BODY_SIZE); soup_session_add_feature (backend->session, SOUP_SESSION_FEATURE (logger)); soup_session_add_feature (backend->session_async, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } }