/* Read energy spectrum parameters */ void read_espe_params_file(char *file_name) { FILE *fp; char *fcomb; char buf[LINE]; int c; fcomb = (char *)calloc( strlen(g_locale_from_utf8( file_name, -1, NULL, NULL, NULL )) + strlen(FESPE) + 1, sizeof(char) ); strcat(fcomb, g_locale_from_utf8( file_name, -1, NULL, NULL, NULL )); strcat(fcomb, FESPE); fp = fopen(fcomb,"r"); if(fp == NULL){ error_dialog_open(fcomb); free(fcomb); return; } fgets(buf,LINE,fp); c = sscanf(buf,"%i %lf %i",&(espe.virtual),&(espe.vsize),&(espe.vnum)); if(c!=3){ espe.virtual = FALSE; espe.vsize = 0; espe.vnum = 0; error = 1; }
/** * g_win32_locale_filename_from_utf8: * @utf8filename: a UTF-8 encoded filename. * * Converts a filename from UTF-8 to the system codepage. * * On NT-based Windows, on NTFS file systems, file names are in * Unicode. It is quite possible that Unicode file names contain * characters not representable in the system codepage. (For instance, * Greek or Cyrillic characters on Western European or US Windows * installations, or various less common CJK characters on CJK Windows * installations.) * * In such a case, and if the filename refers to an existing file, and * the file system stores alternate short (8.3) names for directory * entries, the short form of the filename is returned. Note that the * "short" name might in fact be longer than the Unicode name if the * Unicode name has very short pathname components containing * non-ASCII characters. If no system codepage name for the file is * possible, %NULL is returned. * * The return value is dynamically allocated and should be freed with * g_free() when no longer needed. * * Returns: The converted filename, or %NULL on conversion * failure and lack of short names. * * Since: 2.8 */ gchar * g_win32_locale_filename_from_utf8 (const gchar *utf8filename) { gchar *retval = g_locale_from_utf8 (utf8filename, -1, NULL, NULL, NULL); if (retval == NULL) { /* Conversion failed, so convert to wide chars, check if there * is a 8.3 version, and use that. */ wchar_t *wname = g_utf8_to_utf16 (utf8filename, -1, NULL, NULL, NULL); if (wname != NULL) { wchar_t wshortname[MAX_PATH + 1]; if (GetShortPathNameW (wname, wshortname, G_N_ELEMENTS (wshortname))) { gchar *tem = g_utf16_to_utf8 (wshortname, -1, NULL, NULL, NULL); retval = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL); g_free (tem); } g_free (wname); } } return retval; }
char* FileDialog(int type,GtkWidget* parent_window) { GtkWidget* dialog=NULL; char* filename=NULL; char* tmp=NULL; char* path=NULL; switch(type) { case OPEN_DIALOG: dialog=gtk_file_chooser_dialog_new(_("Open File"),GTK_WINDOW(parent_window),GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL); break; case SAVE_DIALOG: dialog=gtk_file_chooser_dialog_new(_("Save File"),GTK_WINDOW(parent_window),GTK_FILE_CHOOSER_ACTION_SAVE,GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_SAVE,GTK_RESPONSE_ACCEPT,NULL); break; } gtk_widget_show(dialog); if(gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_ACCEPT) { filename=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); } if(filename) { // Handle with different encoding filename tmp=filename; filename=g_locale_from_utf8(filename,-1,NULL,NULL,NULL); free(tmp); } path=gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); // Handle with different encoding path tmp=path; path=g_locale_from_utf8(path,-1,NULL,NULL,NULL); free(tmp); gtk_widget_destroy(dialog); chdir(path); free(path); return filename; }
void fs_send_file_and_debug_info(const gchar *filename) { const gchar *ext; FileContent *metadata; fs_send_file(filename); ext = strrchr(filename, '.'); if (ext) { gchar *temp; *(char *)ext = 0; temp = g_strconcat(filename, ".dbg", NULL); #ifdef WIN32 symfile = g_locale_from_utf8(temp,-1,NULL,NULL,NULL); g_free(temp); #else symfile = temp; #endif *(char *)ext = '.'; } metadata = tifiles_content_create_regular(CALC_TI89); if (!tifiles_file_read_regular(filename, metadata)) { if (metadata->num_entries > 0) { int handle = sym_find_handle (metadata->entries[0]->folder, metadata->entries[0]->name); if (handle) ti68k_bkpt_add_pgmentry (handle); } } tifiles_content_delete_regular(metadata); }
NOTIFYICONDATA systray_init(GdkPixbuf *pixbuf, char* text) { GdkPixmap *pm; GdkBitmap *mask; gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pm, &mask, 128); char* locenc=NULL; ZeroMemory(&nid,sizeof(nid)); systray_hicon = pixmap_to_hicon (pm, mask); systray_hwnd = systray_create_hiddenwin(); nid.cbSize=sizeof(NOTIFYICONDATA); nid.hWnd=systray_hwnd; nid.uID=0; nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP ; nid.uCallbackMessage=WM_TRAYMESSAGE; nid.hIcon=systray_hicon; if(text) { locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL); lstrcpy(nid.szTip, locenc); g_free(locenc); } Shell_NotifyIcon(NIM_ADD,&nid); return nid; }
static void StdLoggerLog(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer data) { gchar *local; FILE *dest = (level < G_LOG_LEVEL_MESSAGE) ? stderr : stdout; #if defined(_WIN32) StdLogger *sdata = data; if (!sdata->attached) { g_static_mutex_lock(&gConsoleLock); if (gRefCount != 0 || GlibUtils_AttachConsole()) { gRefCount++; sdata->attached = TRUE; } g_static_mutex_unlock(&gConsoleLock); } if (!sdata->attached) { return; } #endif local = g_locale_from_utf8(message, -1, NULL, NULL, NULL); if (local != NULL) { fputs(local, dest); g_free(local); } else { fputs(message, dest); } }
void syl_init_gettext(const gchar *package, const gchar *dirname) { #ifdef ENABLE_NLS if (g_path_is_absolute(dirname)) bindtextdomain(package, dirname); else { gchar *locale_dir; locale_dir = g_strconcat(get_startup_dir(), G_DIR_SEPARATOR_S, dirname, NULL); #ifdef G_OS_WIN32 { gchar *locale_dir_; locale_dir_ = g_locale_from_utf8(locale_dir, -1, NULL, NULL, NULL); if (locale_dir_) { g_free(locale_dir); locale_dir = locale_dir_; } } #endif /* G_OS_WIN32 */ bindtextdomain(package, locale_dir); g_free(locale_dir); } bind_textdomain_codeset(package, CS_UTF_8); #endif /* ENABLE_NLS */ }
// // Set image info from a file // bool CCCDFile::Open(const gchar *filepath, CmpackOpenMode mode, GError **error) { Close(); // Check file path if (mode != CMPACK_OPEN_CREATE) { if (!filepath || !g_file_test(filepath, G_FILE_TEST_IS_REGULAR)) { g_set_error(error, g_AppError, 0, "The file does not exists."); return false; } } else { if (!filepath) { g_set_error(error, g_AppError, 0, "Invalid file path."); return false; } } // Open file char *f = g_locale_from_utf8(filepath, -1, NULL, NULL, NULL); int res = cmpack_ccd_open(&m_Handle, f, mode, 0); if (res!=0) { char *msg = cmpack_formaterror(res); g_set_error(error, g_AppError, res, msg); cmpack_free(msg); } InvalidateCache(); g_free(f); return res==0; }
// Save CCD file as... bool CCCDFile::SaveAs(const gchar *fpath, GError **error) const { assert (m_Handle!=NULL); CmpackCcdFile *file; char *f = g_locale_from_utf8(fpath, -1, NULL, NULL, NULL); int res = cmpack_ccd_open(&file, f, CMPACK_OPEN_CREATE, 0); g_free(f); if (res!=0) { char *msg = cmpack_formaterror(res); g_set_error(error, g_AppError, res, msg); cmpack_free(msg); return false; } res = cmpack_ccd_copy(file, m_Handle, NULL); if (res==0) res = cmpack_ccd_close(file); if (res!=0) { char *msg = cmpack_formaterror(res); g_set_error(error, g_AppError, res, msg); cmpack_free(msg); cmpack_ccd_destroy(file); return false; } return res==0; }
std::string FileNameFromUTF8(const std::string& fileNameInUTF8) { std::string fileName; gsize bytesWritten = 0; // On Windows GLib uses UTF-8 for filenames, but as well as we operate // on native Windows API, conversion to the encoding used in current // locale is required. #if defined(G_OS_WIN32) gchar *pFileName = g_locale_from_utf8(fileNameInUTF8.c_str(), -1, 0, &bytesWritten, 0); #else gchar *pFileName = g_filename_from_utf8(fileNameInUTF8.c_str(), -1, 0, &bytesWritten, 0); #endif if (!pFileName) { // In case of error leave the string intact and hope for the best. fileName = fileNameInUTF8; } else{ fileName = pFileName; g_free(pFileName); } return fileName; }
void fsender() { gchar *path_utf8 = my_choose_file(); if (path_utf8 == NULL) return; filename = g_path_get_basename(path_utf8); gchar *path_local = g_locale_from_utf8(path_utf8, -1, NULL, NULL, NULL); fp = fopen(path_local, "rb"); g_free(path_local); if (!fp) { msgbox("Can't open file!"); goto bad; } int nb = get_file_size(fp); if (nb > 512 * 1024) { msgbox("File is too big! (> 500kB)"); goto bad2; } nbytes_remain = nb; nblk_sent = 0; nblk_total = (nb + BLKSIZE - 1) / BLKSIZE; start_sending(); return; bad2: fclose(fp); bad: g_free(filename); }
int get_stamp_str (char *fmt, time_t tim, char **ret) { char dest[128]; gsize len_locale; gsize len_utf8; /* strftime requires the format string to be in locale encoding. */ fmt = g_locale_from_utf8 (fmt, -1, NULL, NULL, NULL); len_locale = strftime_validated (dest, sizeof (dest), fmt, localtime (&tim)); g_free (fmt); if (len_locale == 0) { return 0; } *ret = g_locale_to_utf8 (dest, len_locale, NULL, &len_utf8, NULL); if (*ret == NULL) { return 0; } return len_utf8; }
gboolean mu_util_fputs_encoded (const char *str, FILE *stream) { int rv; char *conv; g_return_val_if_fail (stream, FALSE); /* g_get_charset return TRUE when the locale is UTF8 */ if (mu_util_locale_is_utf8()) return fputs (str, stream) == EOF ? FALSE : TRUE; /* charset is _not_ utf8, so we need to convert it */ conv = NULL; if (g_utf8_validate (str, -1, NULL)) conv = g_locale_from_utf8 (str, -1, NULL, NULL, NULL); /* conversion failed; this happens because is some cases GMime may gives * us non-UTF-8 strings from e.g. wrongly encoded message-subjects; if * so, we escape the string */ conv = conv ? conv : g_strescape (str, "\n\t"); rv = conv ? fputs (conv, stream) : EOF; g_free (conv); return (rv == EOF) ? FALSE : TRUE; }
gchar * g_win32_get_package_installation_directory (const gchar *package, const gchar *dll_name) { gchar *utf8_package = NULL, *utf8_dll_name = NULL; gchar *utf8_retval, *retval; if (package != NULL) utf8_package = g_locale_to_utf8 (package, -1, NULL, NULL, NULL); if (dll_name != NULL) utf8_dll_name = g_locale_to_utf8 (dll_name, -1, NULL, NULL, NULL); utf8_retval = g_win32_get_package_installation_directory_utf8 (utf8_package, utf8_dll_name); retval = g_locale_from_utf8 (utf8_retval, -1, NULL, NULL, NULL); g_free (utf8_package); g_free (utf8_dll_name); g_free (utf8_retval); return retval; }
void set_TagField (ID3Tag * myTag, char *data, ID3_FrameID id) { ID3Frame *myFrame; ID3Frame *pFrame; char *conv_str = NULL; myFrame = ID3Frame_NewID (id); pFrame = ID3Tag_FindFrameWithID (myTag, id); if (pFrame != NULL) { ID3Tag_RemoveFrame (myTag, pFrame); } conv_str = g_locale_from_utf8 (data, -1, NULL, NULL, NULL); ID3Field_SetASCII (ID3Frame_GetField (myFrame, ID3FN_TEXT), conv_str); ID3Tag_AttachFrame (myTag, myFrame); g_free (conv_str); return; }
// WIN32 static const gchar* create_fsel_3(const gchar *dirname, const gchar *filename, const gchar *ext, gboolean save) { #ifdef WIN32 OPENFILENAME_MAYALIAS o; char lpstrFile[2048] = "\0"; char lpstrFilter[512]; char *p; gchar **sarray; int i, n; int have_widechar = G_WIN32_HAVE_WIDECHAR_API(); void *sdirname; // clear structure memset (&o, 0, sizeof(OPENFILENAME)); // set default filename if(filename) { void *temp; if (have_widechar) { temp = g_utf8_to_utf16(filename,-1,NULL,NULL,NULL); if(!temp) return NULL; wcsncpy((wchar_t *)lpstrFile, temp, sizeof(lpstrFile)>>1); } else { temp = g_locale_from_utf8(filename,-1,NULL,NULL,NULL); if(!temp) return NULL; strncpy(lpstrFile, temp, sizeof(lpstrFile)); } g_free(temp); }
static void SysLoggerLog(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer data) { gchar *local; int priority; /* glib and syslog disagree about critical / error. */ if (level & G_LOG_LEVEL_ERROR) { priority = LOG_CRIT; } else if (level & G_LOG_LEVEL_CRITICAL) { priority = LOG_ERR; } else if (level & G_LOG_LEVEL_WARNING) { priority = LOG_WARNING; } else if (level & G_LOG_LEVEL_MESSAGE) { priority = LOG_NOTICE; } else if (level & G_LOG_LEVEL_INFO) { priority = LOG_INFO; } else { priority = LOG_DEBUG; } local = g_locale_from_utf8(message, -1, NULL, NULL, NULL); if (local != NULL) { syslog(priority, "%s", local); g_free(local); } else { syslog(priority, "%s", message); } }
/** * @param cmd The cmd to execute * @param run_in_term Indicate if command should be run in a terminal * * Execute command and add to history. */ static void exec_cmd ( const char *cmd, int run_in_term ) { GError *error = NULL; if ( !cmd || !cmd[0] ) { return; } gsize lf_cmd_size = 0; gchar *lf_cmd = g_locale_from_utf8 ( cmd, -1, NULL, &lf_cmd_size, &error ); if ( error != NULL ) { fprintf ( stderr, "Failed to convert command to locale encoding: %s\n", error->message ); g_error_free ( error ); return; } if ( execsh ( lf_cmd, run_in_term ) ) { /** * This happens in non-critical time (After launching app) * It is allowed to be a bit slower. */ char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL ); history_set ( path, cmd ); g_free ( path ); } g_free ( lf_cmd ); }
int filename_to_win32 (char *targ, const char *src) { GError *gerr = NULL; gsize bytes; int err = 0; *targ = '\0'; if (string_is_utf8((const unsigned char *) src)) { gchar *tr = g_locale_from_utf8(src, -1, NULL, &bytes, &gerr); if (gerr != NULL) { fprintf(stderr, "Couldn't handle '%s': %s\n", src, gerr->message); g_error_free(gerr); err = 1; } else { strncat(targ, tr, MAXLEN - 1); g_free(tr); } } else { strncat(targ, src, MAXLEN - 1); } if (!err) { slash_convert(targ, TO_BACKSLASH); } return err; }
void SludgeProjectManager::on_files_tree_selection_changed(GtkTreeSelection *theSelection) { GList * selectedRows; GtkTreeIter iter; GtkTreeModel *model; gchar *tx, *tx1; clearFileList(resourceList, &numResources); if (currentFilename[0] == 0) return; getSourceDirFromName(currentFilename); selectedRows = gtk_tree_selection_get_selected_rows(theSelection, &model); for (int j = 0; j < g_list_length(selectedRows); j++) { gtk_tree_model_get_iter(model, &iter, (GtkTreePath *)g_list_nth(selectedRows, j)->data); gtk_tree_model_get(model, &iter, 0, &tx1, -1); tx = g_locale_from_utf8(tx1, -1, NULL, NULL, NULL); g_free(tx1); populateResourceList(tx, resourceList, &numResources); g_free(tx); gtk_widget_set_sensitive(removeFileButton, TRUE); } if (g_list_length(selectedRows) == 0) { gtk_widget_set_sensitive(removeFileButton, FALSE); } g_list_foreach(selectedRows, (GFunc) gtk_tree_path_free, NULL); g_list_free(selectedRows); listChanged(RESOURCE_TREEVIEW); }
static gchar *get_output_str(gchar *str, gboolean is_utf8) { gchar *out; if(str == NULL) return NULL; if(envir_utf8) { if(is_utf8) out = g_strdup(str); else { if(!(out = g_locale_to_utf8(str, -1, NULL, NULL, NULL))) { p_verbose("Cannot convert string from locale charset to UTF-8.\n"); out = g_strdup(str); } } } else { if(is_utf8) { if(!(out = g_locale_from_utf8(str, -1, NULL, NULL, NULL))) { p_verbose("Cannot convert string from UTF-8 to locale charset.\n"); out = g_strdup(str); } } else out = g_strdup(str); } return out; }
void cb_save (GtkWidget *p_widget, gpointer user_data) { if (docs.actif) { if (!docs.actif->sauve) { /* Le fichier n'a pas encore ete enregistre */ if (!docs.actif->path) { GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Sauvegarder le fichier", NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { docs.actif->path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); } gtk_widget_destroy (dialog); } /* Soit le fichier a deja ete enregistre, soit l'utilisateur vient de nous fournir son nouvel emplacement, on peut donc l'enregistrer */ if (docs.actif->path) { FILE *fichier; fichier = fopen (docs.actif->path, "w"); if (fichier) { gchar *contents; gchar *locale; GtkTextIter start; GtkTextIter end; GtkTextBuffer *text_buffer; text_buffer = gtk_text_view_get_buffer (docs.actif->text_view); gtk_text_buffer_get_bounds (text_buffer, &start, &end); contents = gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE); locale = g_locale_from_utf8 (contents, -1, NULL, NULL, NULL); g_free (contents), contents = NULL; fprintf (fichier, "%s", locale); g_free (locale), locale = NULL; fclose (fichier), fichier = NULL; docs.actif->sauve = TRUE; } else print_warning ("Impossible de sauvegarder le fichier %s", docs.actif->path); } } } else print_warning ("Aucun document ouvert"); /* Parametres inutilises */ (void)p_widget; (void)user_data; }
/** * \brief utf8 version of remove (see remove for more detail about mode) * * convert utf8 file path into the locale OS charset before calling remove * * \param utf8filename file to remove path coded using utf8 charset * * \return remove returned value */ gint utf8_remove ( const gchar *utf8filename ) { #ifdef _MSC_VER return remove ( g_locale_from_utf8 ( utf8filename, -1, NULL, NULL, NULL ) ); #else return remove ( g_filename_from_utf8 ( utf8filename,-1,NULL,NULL,NULL ) ); #endif }
/** * \brief utf8 version of fopen (see fopen for more detail about mode) * * convert utf8 file path into the locale OS charset before calling fopen * * \param utf8filename file to open path coded using utf8 charset * \param mode fopen mode argument * * \return file descriptor returned by fopen */ G_MODULE_EXPORT FILE* utf8_fopen (const gchar *utf8filename, gchar *mode ) { #ifdef _MSC_VER return fopen ( g_locale_from_utf8 ( utf8filename, -1, NULL, NULL, NULL ), mode ); #else return fopen ( g_filename_from_utf8 ( utf8filename, -1, NULL, NULL, NULL ), mode ); #endif }
void print_term(const gchar *text_utf8) { gchar *text_l; text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL); printf((text_l) ? text_l : text_utf8); g_free(text_l); }
static void set_key_event_string (GdkEventKey *event) { gunichar c = 0; if (event->keyval != GDK_KEY_VoidSymbol) c = gdk_keyval_to_unicode (event->keyval); if (c) { gchar buf[7]; gint len; gsize bytes_written; /* Apply the control key - Taken from Xlib */ if (event->state & GDK_CONTROL_MASK) { if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F; else if (c == '2') { event->string = g_memdup ("\0\0", 2); event->length = 1; buf[0] = '\0'; return; } else if (c >= '3' && c <= '7') c -= ('3' - '\033'); else if (c == '8') c = '\177'; else if (c == '/') c = '_' & 0x1F; } len = g_unichar_to_utf8 (c, buf); buf[len] = '\0'; event->string = g_locale_from_utf8 (buf, len, NULL, &bytes_written, NULL); if (event->string) event->length = bytes_written; } else if (event->keyval == GDK_KEY_Escape) { event->length = 1; event->string = g_strdup ("\033"); } else if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) { event->length = 1; event->string = g_strdup ("\r"); } if (!event->string) { event->length = 0; event->string = g_strdup (""); } }
void vorbistag (char *ogg_file, char *artist, char *album, char *date, char *title, unsigned char style, unsigned char track) { char cmd[MAX_COMMAND_LENGTH]; char temp[MAX_TITLE_LENGTH]; char *tagfile; FILE *f; char *conv_artist = NULL; char *conv_album = NULL; char *conv_title = NULL; conv_artist = g_locale_from_utf8 (artist, -1, NULL, NULL, NULL); conv_album = g_locale_from_utf8 (album, -1, NULL, NULL, NULL); conv_title = g_locale_from_utf8 (title, -1, NULL, NULL, NULL); tagfile = g_strdup_printf ("%s.tags", ogg_file); f = fopen (tagfile, "w"); snprintf (temp, sizeof (temp) - 1, "ARTIST=%s\n", conv_artist); fputs (temp, f); snprintf (temp, sizeof (temp) - 1, "ALBUM=%s\n", conv_album); fputs (temp, f); snprintf (temp, sizeof (temp) - 1, "DATE=%s\n", date); fputs (temp, f); snprintf (temp, sizeof (temp) - 1, "TITLE=%s\n", conv_title); fputs (temp, f); snprintf (temp, sizeof (temp) - 1, "GENRE=%s\n", id3_findstyle (style)); fputs (temp, f); snprintf (temp, sizeof (temp) - 1, "TRACKNUMBER=%d\n", track); fputs (temp, f); fclose (f); snprintf (cmd, sizeof (cmd) - 1, "vorbiscomment -a -c '%s' '%s'", tagfile, ogg_file); system (cmd); unlink (tagfile); free (tagfile); g_free (conv_artist); g_free (conv_album); g_free (conv_title); }
/*! * \fn G_MODULE_EXPORT void endAssistantNewCsu(GtkWidget *widget, gpointer data) * End the assistant for a new csu file * \param[in] widget the widget which send the signal * \param[in] data the globalData */ G_MODULE_EXPORT void endAssistantNewCsu(GtkWidget *widget, gpointer data) { globalData *user_data = (globalData*) data; gchar name[SIZE_MAX_FILE_NAME]; gchar *folder; /* Read the game configuration list */ char home_path[SIZE_MAX_FILE_NAME]=""; #ifndef PORTABLE readHomePathSlash(home_path); #endif // PORTABLE /* Get the filename */ GtkWidget *grid = getWidgetFromBuilder(user_data->ptr_builder,"grid_new_csu_file_assistant_1"); folder = g_locale_from_utf8(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtk_grid_get_child_at(GTK_GRID(grid),1,1))),-1,NULL,NULL,NULL); strncpy(name,g_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(gtk_grid_get_child_at(GTK_GRID(grid),1,0))),-1,NULL,NULL,NULL),SIZE_MAX_NAME-1); sprintf(user_data->csu_filename,"%s/%s",folder,name); addFileCsuExtension(user_data->csu_filename); /* Save the game configuration if ask */ if (user_data->save_new_game_config) newConfigFile(user_data->config,home_path); /* Update the information of the global data */ if (user_data->ptr_csu_struct != NULL) closeCsuStruct(user_data->ptr_csu_struct); user_data->ptr_csu_struct = user_data->ptr_csu_struct_tmp; user_data->ptr_csu_struct_tmp = NULL; updateMainWindow(user_data,!exceedMaxNumber(user_data->ptr_csu_struct)); if (writeCsuFile(user_data->csu_filename,user_data->ptr_csu_struct) == false) saveFileError(user_data); deleteAllLastCsuStruct(user_data); addLastCsuStruct(user_data); deleteAssistantNewCsu(NULL,user_data); setButtonMainWindow(user_data); fillCalculatorNames(user_data); g_free(folder); }
/** * nmt_newt_locale_from_utf8: * @str_utf8: a UTF-8 string * * Convenience wrapper around g_locale_from_utf8(). * * Note that libnewt works in terms of the user's locale character * set, NOT UTF-8, so all strings from nmt-newt must be converted to * locale encoding before being passed to libnewt. * * Returns: @str_utf8, converted to the user's locale encoding. */ char * nmt_newt_locale_from_utf8 (const char *str_utf8) { char *str_lc; str_lc = g_locale_from_utf8 (str_utf8, -1, NULL, NULL, NULL); if (!str_lc) str_lc = g_strdup (""); return str_lc; }
/** * convertUtf8ToCharLen() \n * convert UTF-8 to Char \n * @param source \n * @param len length \n * @return char* the converted Msg \n */ char* convertUtf8ToCharLen(const char* source, uint16_t len) { gchar* destination; GError* error_ptr; gsize bytes_read; gsize bytes_written; destination = g_locale_from_utf8(source, len, &bytes_read, &bytes_written, &error_ptr); return (char*) destination; }