void CloudPinyinAddCandidateWord(void* arg) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudpinyin->initialized == false) return; /* check whether the current im is pinyin */ if (CHECK_VALID_IM) { /* there is something pending input */ if (FcitxInputStateGetRawInputBufferSize(input) >= cloudpinyin->config.iMinimumPinyinLength) { char* strToFree = NULL, *inputString; strToFree = GetCurrentString(cloudpinyin); inputString = SplitHZAndPY(strToFree); if (inputString) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, inputString); FcitxLog(LOGLEVEL, "%s", inputString); if (cacheEntry == NULL) CloudPinyinAddInputRequest(cloudpinyin, inputString); _CloudPinyinAddCandidateWord(cloudpinyin, inputString); } if (strToFree) free(strToFree); } } return; }
static void ShowLeverPositionAlert() { gchar* position_alert_msg; gchar* msg_buf; const static gchar* _alert_str = "_alert"; gchar* alert_msg = LookupText(g_keytext_list, "move_lever_position_alert"); gchar* position_key = ValueToKey(CNCL_MESS_THICK, GetCurrentnValue(CNCL_MESS_THICK)); // Make the key for the position string on the alert. gchar* position_alert_key = g_malloc(strlen(position_key) + strlen(_alert_str) + 1); strcpy(position_alert_key, position_key); strcat(position_alert_key, _alert_str); // Get the position string on the alert. position_alert_msg = LookupText(g_keytext_list, position_alert_key); // If not exist, use the current position string instead. if( position_alert_msg == NULL ) position_alert_msg = GetCurrentString(CNCL_MESS_THICK); msg_buf = (gchar*)g_malloc(strlen(alert_msg) + strlen(position_alert_msg)); sprintf(msg_buf, alert_msg, position_alert_msg); UtilMessageBox(msg_buf, g_window_title, MB_OK | MB_ICON_INFORMATION); g_free(position_alert_key); g_free(msg_buf); }
void LanguagesDlg::OnSelchangeListThemes() { // TODO: Add your control notification handler code here m_listLanguages.ResetContent(); RString sTheme = GetCurrentString( m_listThemes ); if( !sTheme.empty() ) { RString sLanguagesDir = SpecialFiles::THEMES_DIR + sTheme + "/" + SpecialFiles::LANGUAGES_SUBDIR; vector<RString> vs; GetDirListing( sLanguagesDir+"*.ini", vs, false ); FOREACH_CONST( RString, vs, s ) { RString sIsoCode = GetFileNameWithoutExtension(*s); RString sLanguage = SMPackageUtil::GetLanguageDisplayString(sIsoCode); m_listLanguages.AddString( ConvertUTF8ToACP(sLanguage) ); }
static void CloudSetClientPreedit(FcitxCloudPinyin *cloudpinyin, const char *str) { FcitxInputState *input = FcitxInstanceGetInputState(cloudpinyin->owner); FcitxMessages *message = FcitxInputStateGetClientPreedit(input); char *py; char *string = GetCurrentString(cloudpinyin, &py); FcitxMessagesSetMessageCount(message, 0); if (py) { *py = '\0'; FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s%s", string, str); } else { FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s", str); } fcitx_utils_free(string); FcitxInstanceUpdateClientSideUI( cloudpinyin->owner, FcitxInstanceGetCurrentIC(cloudpinyin->owner)); }
static void confirm_media_supply_change(short old_supply_value) { int ret; gchar* alert_msg = LookupText(g_keytext_list, "paper_supply_change_alert"); gchar* supply_str = GetCurrentString(CNCL_MEDIASUPPLY); gchar* message = (gchar*)g_malloc(strlen(alert_msg) + strlen(supply_str)); sprintf(message, alert_msg, supply_str); ret = UtilMessageBox(message, g_window_title, MB_OK | MB_CANCEL | MB_ICON_INFORMATION); g_free(message); if( ret == ID_CANCEL ) { UpdateMenuLink(CNCL_MEDIASUPPLY, old_supply_value); } }
INPUT_RETURN_VALUE CloudPinyinGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; CloudCandWord* cloudCand = candWord->priv; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudCand->filled) { char *py; char *string = GetCurrentString(cloudpinyin, &py); if (py) { *py = 0; snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); if (im) { char *output_string = FcitxInputStateGetOutputString(input); FCITX_DEF_MODULE_ARGS(args, output_string); if (strcmp(im->uniqueName, "sunpinyin") == 0) { FcitxSunPinyinInvokeAddWord(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0) { FcitxPinyinInvokeAddUserPhrase(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "pinyin-libpinyin") == 0 || strcmp(im->uniqueName, "shuangpin-libpinyin") == 0) { FcitxLibPinyinInvokeAddWord(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "sogou-pinyin") == 0) { FcitxSogouPinyinInvokeAddWord(cloudpinyin->owner, args); } } } if (string) free(string); return IRV_COMMIT_STRING; } else { return IRV_DO_NOTHING; } }
INPUT_RETURN_VALUE CloudPinyinGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; CloudCandWord* cloudCand = candWord->priv; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudCand->filled) { char* string = GetCurrentString(cloudpinyin); char* py = SplitHZAndPY(string); if (py) { *py = 0; snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); FcitxModuleFunctionArg args; args.args[0] = FcitxInputStateGetOutputString(input); if (im) { if (strcmp(im->uniqueName, "sunpinyin") == 0) { //InvokeModuleFunctionWithName(cloudpinyin->owner, "fcitx-sunpinyin", 1, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0) { FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-pinyin", 7, args); } } } if (string) free(string); return IRV_COMMIT_STRING; } else return IRV_DO_NOTHING; }
void DrawPrinterDrawingArea(GtkWidget* window, GtkWidget* area) { GdkWindow* area_window = area->window; GdkPixmap* pixmap; GdkBitmap* mask; gchar* xpm_name; gchar* key_str; gchar* message_str; GdkGC* gc = gdk_gc_new(window->window); // Background pattern. pixmap = LoadPixmap(window, NULL, "bg.xpm"); DrawPixmap(area_window, gc, 0, 0, pixmap, NULL); FreePixmap(pixmap, NULL); // Printer body. pixmap = LoadPixmap(window, &mask, "printer.xpm"); DrawPixmap(area_window, gc, BODY_PIXMAP_X, BODY_PIXMAP_Y, pixmap, mask); FreePixmap(pixmap, mask); // Paper set and out. // Right guide(Paper set). { gchar* in_xpm_name; gchar* out_xpm_name; gchar* guide_xpm_name; short supply = GetCurrentnValue(CNCL_MEDIASUPPLY); #ifdef SUPPORT_BANNER short media = GetCurrentnValue(CNCL_MEDIATYPE); #endif short size = GetCurrentnValue(CNCL_PAPERSIZE); if( supply == CND_SUPPLY_MANUAL ) in_xpm_name = "in_m.xpm"; else in_xpm_name = NULL; #ifdef SUPPORT_BANNER if( media == CND_MEDIA_BANNER ) guide_xpm_name = "guide_a3.xpm"; else #endif guide_xpm_name = NULL; if( GetPaperWidth(size) > GetPaperHeight(size) ) { if( in_xpm_name == NULL ) in_xpm_name = "in_l.xpm"; if( guide_xpm_name == NULL ) guide_xpm_name = "guide_a2.xpm"; out_xpm_name = "out_ph.xpm"; } else { if( in_xpm_name == NULL ) in_xpm_name = "in_p.xpm"; if( guide_xpm_name == NULL ) guide_xpm_name = "guide_a1.xpm"; out_xpm_name = "out_pv.xpm"; } pixmap = LoadPixmap(window, &mask, in_xpm_name); DrawPixmap(area_window, gc, BODY_PIXMAP_X, BODY_PIXMAP_Y, pixmap, mask); FreePixmap(pixmap, mask); pixmap = LoadPixmap(window, &mask, out_xpm_name); DrawPixmap(area_window, gc, BODY_PIXMAP_X, BODY_PIXMAP_Y, pixmap, mask); FreePixmap(pixmap, mask); pixmap = LoadPixmap(window, &mask, guide_xpm_name); DrawPixmap(area_window, gc, R_GUIDE_PIXMAP_X, R_GUIDE_PIXMAP_Y, pixmap, mask); FreePixmap(pixmap, mask); } // Left guide(Thickness). { short thick = GetCurrentnValue(CNCL_MESS_THICK); switch( thick ) { case CND_TMESSAGE_UPPER2: xpm_name = "guide_b1.xpm"; break; default: xpm_name = "guide_b3.xpm"; break; } pixmap = LoadPixmap(window, &mask, xpm_name); DrawPixmap(area_window, gc, L_GUIDE_PIXMAP_X, L_GUIDE_PIXMAP_Y, pixmap, mask); FreePixmap(pixmap, mask); } // Media type message. message_str = GetCurrentString(CNCL_MEDIATYPE); DrawString(area_window, g_main_font, gc, MEDIA_TEXT_X, MEDIA_TEXT_Y, message_str); { if( IsGrayPrint(g_main_window) ) { xpm_name = "print_mono.xpm"; key_str = "print_mono_message"; } else { xpm_name = "print_color.xpm"; key_str = "print_color_message"; } #ifndef NO_PRINT_COLOR_ICON // Print color icon. pixmap = LoadPixmap(window, &mask, xpm_name); DrawPixmap(area_window, gc, COLOR_PIXMAP_X, COLOR_PIXMAP_Y, pixmap, mask); FreePixmap(pixmap, mask); #endif // Color type message. message_str = LookupText(g_keytext_list, key_str); DrawString(area_window, g_main_font, gc, COLOR_TEXT_X, COLOR_TEXT_Y, message_str); } gdk_gc_unref(gc); }
void UpdateWidgets(GtkWidget* window, gchar* except_name) { char *current_comb_supply = NULL; char *current_comb_supply_local = NULL; short len = 0; short current_comb_supply_id = 0; #ifdef _PRINTUI_DEBUG_ fprintf(stderr,"\n### UpdateWidgets :except_name = %s ###\n",except_name); #endif /* Ver.2.70: for "Front for Plain" */ if( except_name!=NULL ){ /* Store "media_supply_entry" setting(UI strings) */ /* Ver.2.80 */ GtkWidget* combo = LookupWidget(window, "media_supply_combo"); current_comb_supply = (char*)gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo)); len = strlen(current_comb_supply) + 1; current_comb_supply_local = malloc( len ); memset(current_comb_supply_local,0x00, len ); strncpy( current_comb_supply_local , current_comb_supply , len ); current_comb_supply_local[len-1] = '\0'; #ifdef _PRINTUI_DEBUG_ fprintf(stderr,"current_comb_supply_local = %s\n",current_comb_supply_local); #endif } // Print bw button if( !SameName(except_name, "print_bw_button") ) { gboolean sensitive = TRUE; switch( GetCurrentnValue(CNCL_GRAYSCALE) ) { case CND_BJGRAYSCALE_OFF: break; case CND_BJGRAYSCALE_ON: break; case CND_BJGRAYSCALE_GRAY: sensitive = FALSE; break; default: break; } gtk_widget_set_sensitive( LookupWidget(window, "print_bw_button1"), sensitive); gtk_widget_set_sensitive( LookupWidget(window, "print_bw_button2"), sensitive); } // Media type combo if( !SameName(except_name, "media_type_combo") ) { #ifdef _PRINTUI_DEBUG_ fprintf(stderr,"UpdateWidgets:media_type_combo\n"); #endif SetItemsToComboBox(window, "media_type_combo", CNCL_MEDIATYPE, GetCurrentnValue(CNCL_MEDIATYPE));/* Ver.2.80 */ } // Media supply combo if( !SameName(except_name, "media_supply_combo") ) { GList* glist = GetComboList(CNCL_MEDIASUPPLY); /* iP3300,MP510:Add "Front for Plain" (This value is always available) */ { char *str; //GetAllFlags:If CND_SUPPLY_CASSETTE_04 exist --> str > 0 if( GetAllFlags( CNCL_MEDIASUPPLY , CND_SUPPLY_CASSETTE_04 ) >= 0 ){ str = ValueToName( CNCL_MEDIASUPPLY , CND_SUPPLY_FRONT_FOR_PLAIN ); glist = g_list_append(glist, str); } } /* Ver.2.70: for "Front for Plain" */ if( except_name!=NULL ){ /* UI setting at the top of this function is not disable on CNCLDB --> use it (to UI) */ /* UI setting at the top of this function is disable on CNCLDB --> use current value of CNCLDB (to UI) */ current_comb_supply_id = NameToValue( CNCL_MEDIASUPPLY , current_comb_supply_local ); /* Replace "CND_SUPPLY_FRONT_FOR_PLAIN" with "CND_SUPPLY_ASF" before check */ if( current_comb_supply_id == CND_SUPPLY_FRONT_FOR_PLAIN ) current_comb_supply_id = CND_SUPPLY_ASF; if( IsAvailableValue( CNCL_MEDIASUPPLY , current_comb_supply_id ) ){ /* UI setting is not disable on CNCLDB */ SetGListToComboBox(window, "media_supply_combo",glist, current_comb_supply_local , CNCL_MEDIASUPPLY );/* Ver.2.80 */ }else{ /* UI setting is disable on CNCLDB */ #ifdef _PRINTUI_DEBUG_ fprintf(stderr," IsAvailableValue(%s,ID=%d): not Available!!\n",current_comb_supply_local,current_comb_supply_id); #endif SetGListToComboBox(window, "media_supply_combo",glist, GetCurrentString(CNCL_MEDIASUPPLY) , CNCL_MEDIASUPPLY );/* Ver.2.80 */ } } else{ //NULL --> Select "CNCLDB current value" on UI SetGListToComboBox(window, "media_supply_combo",glist, GetCurrentString(CNCL_MEDIASUPPLY) , CNCL_MEDIASUPPLY);/* Ver.2.80 */ } } // Cartridge type combo if( !SameName(except_name, "cartridge_type_combo") ) { #ifdef _PRINTUI_DEBUG_ fprintf(stderr,"UpdateWidgets:cartridge_type_combo\n"); #endif SetItemsToComboBox(window, "cartridge_type_combo", CNCL_CARTRIDGE, GetCurrentnValue(CNCL_CARTRIDGE));/* Ver.2.80 */ } // Quality radio button { gboolean custom_active = GTK_TOGGLE_BUTTON( LookupWidget(window, "quality_custom_button"))->active; GtkWidget* custom_button = LookupWidget(window, "quality_dialog_button"); short quality = GetCurrentnValue(CNCL_PRINTQUALITY); GtkWidget* button; short value[3]; int i; for( i = 0 ; i < 3 ; i++ ) { button = LookupWidget(window, g_quality_button_name[i]); value[i] = GetCurrentnValue(g_mess_map[i]); if( !custom_active && value[i] == quality ) { // activate button gtk_widget_set_sensitive(custom_button, FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } if( value[i] != CND_QUALITY_ABSOLUTE_NA ) gtk_widget_set_sensitive(button, TRUE); else gtk_widget_set_sensitive(button, FALSE); } if( custom_active ){ // activate custom button gtk_widget_set_sensitive(custom_button, TRUE); } } // Color auto radio button { GtkWidget* button = LookupWidget(window, "color_auto_button"); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), g_main_window->color_auto ); } // Color adjust radio button { GtkWidget* button = LookupWidget(window, "color_dialog_button"); if( GTK_TOGGLE_BUTTON( LookupWidget(window, "color_manual_button"))->active ) gtk_widget_set_sensitive(button, TRUE); else gtk_widget_set_sensitive(button, FALSE); } // Guide(Thickness etc...) { GtkWidget* label = LookupWidget(window, "thick_msg_label"); char* position_msg = GetCurrentString(CNCL_MESS_THICK); gtk_label_set_text(GTK_LABEL(label), (gchar*)position_msg); } #ifdef _PRINTUI_DEBUG_ fprintf(stderr,"UpdateWidgets:8\n"); #endif // Paper gap combo if( !SameName(except_name, "paper_gap_combo") ) { #ifdef _PRINTUI_DEBUG_ fprintf(stderr,"UpdateWidgets:paper_gap_combo\n"); #endif SetItemsToComboBox(window, "paper_gap_combo", CNCL_PAPERGAP_COMMAND, GetCurrentnValue(CNCL_PAPERGAP_COMMAND));/* Ver.2.80 */ } ///////////////////////////////////////////////////////////////// // Media size combo if( !SameName(except_name, "media_size_combo") ) { //Ver.3.00 SetItemsToComboBox(window, "media_size_combo", CNCL_PAPERSIZE, GetCurrentnValue(CNCL_PAPERSIZE)); } // Printing type combo if( !SameName(except_name, "printing_type_combo") ) { SetTextArrayToComboBox(window, "printing_type_combo", (const gchar**)g_printing_type_name, (const short*)g_printing_type_value, g_main_window->printing_type); } // Printing scaling hbox. { GtkWidget* hbox = LookupWidget(window, "scaling_hbox"); if( g_main_window->printing_type == PRINTING_TYPE_SCALE ) gtk_widget_show(hbox); else gtk_widget_hide(hbox); } // Printing scaling spin. if( !SameName(except_name, "printing_scaling_button") ) { GtkSpinButton* scaling_spin = (GtkSpinButton*)LookupWidget(window, "printing_scaling_spin"); gtk_adjustment_set_value(scaling_spin->adjustment, (gfloat)g_main_window->scaling); } // Centering button. if( !SameName(except_name, "centering_button") ) { gboolean active = (g_main_window->centering == LOCATION_CENTER)? TRUE : FALSE; gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(LookupWidget(UI_DIALOG(g_main_window)->window, "centering_button")), active); } if( IsAvailableBorderless() ) { short margin_type = GetCurrentnValue(CNCL_MARGINTYPE); gboolean active = (margin_type == CND_MARGIN_MINUS)? TRUE : FALSE; // Borderless hbox. GtkWidget* hbox = LookupWidget(window, "borderless_hbox"); // gtk_widget_set_sensitive(hbox, active); if( active == TRUE ) gtk_widget_show(hbox); else gtk_widget_hide(hbox); // Borderless button. if( !SameName(except_name, "borderless_button") ) { GtkWidget* button = LookupWidget(window, "borderless_button"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); } // Border ext button. if( !SameName(except_name, "border_ext_button") ) { gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(LookupWidget(UI_DIALOG(g_main_window)->window, g_border_ext_button_name[g_main_window->ext_border])), TRUE); } } if( IsAvailableDuplex() ) { GtkWidget* duplex_vbox; GtkWidget* duplex_hbox; gboolean active; // Duplex vbox. duplex_vbox = LookupWidget(window, "duplex_vbox"); gtk_widget_set_sensitive(duplex_vbox, IsAvailableValue(CNCL_DUPLEX_PRINTING, CND_DUPLEX_AUTO)); // Duplex hbox. active = (CND_DUPLEX_AUTO == GetCurrentnValue(CNCL_DUPLEX_PRINTING))? TRUE : FALSE; /* Ver.2.70 */ duplex_hbox = LookupWidget(window, "duplex_hbox"); gtk_widget_set_sensitive(duplex_hbox, active); // Auto Duplex button. if( !SameName(except_name, "auto_duplex_button") ) { // GtkWidget* button = LookupWidget(window, "auto_duplex_button"); // not in use... } // Stapleside if( !SameName(except_name, "stapleside_button") ) { gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(LookupWidget(UI_DIALOG(g_main_window)->window, g_staple_button_name[g_main_window->stapleside])), TRUE); } } // Copies spin. if( !SameName(except_name, "copies_spin") ) { GtkSpinButton* copies_spin = (GtkSpinButton*)LookupWidget(window, "copies_spin"); gtk_adjustment_set_value(copies_spin->adjustment, (gfloat)g_main_window->copies); } if(current_comb_supply_local){ free(current_comb_supply_local); current_comb_supply_local = NULL; } // Ver.2.90:Custom Paper Size dialog button { GtkWidget* hbox_user = LookupWidget(window, "hbox_user"); // GtkWidget* space_user = LookupWidget(window, "usersize_space_label"); //Ver.3.10テスト中 if( CND_SIZE_USER == GetCurrentnValue(CNCL_PAPERSIZE) ) { gtk_widget_show(hbox_user); // gtk_widget_show(space_user); }else { gtk_widget_hide(hbox_user); // gtk_widget_hide(space_user); } } /* Ver.3.00: Show supply position */ { GtkWidget* supply_mes_label2 = LookupWidget(window, "supply_label2"); short media,size; media = GetCurrentnValue(CNCL_MEDIATYPE); size = GetCurrentnValue(CNCL_PAPERSIZE); if( GetCurrentnValue(CNCL_MEDIASUPPLY) == CND_SUPPLY_AUTO_SELECT ) { if( ( media==CND_MEDIA_PLAIN ) && ( size==CND_SIZE_A4 || size==CND_SIZE_A5 || size==CND_SIZE_B5 || size==CND_SIZE_LETTER ) ){ gtk_widget_hide(supply_mes_label2); } else{ gtk_label_set_text(GTK_LABEL(supply_mes_label2), (gchar*)ValueToName( CNCL_MEDIASUPPLY , CND_SUPPLY_ASF )); gtk_widget_show(supply_mes_label2); } } else{ gtk_widget_hide(supply_mes_label2); } } }
void CloudPinyinHandleRequest(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue) { if (queue->type == RequestKey) { cloudpinyin->isrequestkey = false; if (queue->source != cloudpinyin->config.source) return; if (queue->http_code == 200) { if (engine[cloudpinyin->config.source].ParseKey) engine[cloudpinyin->config.source].ParseKey(cloudpinyin, queue); } } else if (queue->type == RequestPinyin) { if (queue->http_code == 200 && cloudpinyin->config.source == queue->source) { char *realstring = engine[cloudpinyin->config.source].ParsePinyin(cloudpinyin, queue); if (realstring) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, queue->pinyin); if (cacheEntry == NULL) cacheEntry = CloudPinyinAddToCache(cloudpinyin, queue->pinyin, realstring); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); char* strToFree = NULL, *inputString; strToFree = GetCurrentString(cloudpinyin); inputString = SplitHZAndPY(strToFree); if (inputString) { FcitxLog(LOGLEVEL, "fill: %s %s", inputString, queue->pinyin); if (strcmp(inputString, queue->pinyin) == 0) { if (CHECK_VALID_IM) { CloudPinyinFillCandidateWord(cloudpinyin, inputString); } } } if (strToFree) free(strToFree); free(realstring); } } if (queue->http_code != 200) { cloudpinyin->errorcount ++; if (cloudpinyin->errorcount > MAX_ERROR) { cloudpinyin->initialized = false; cloudpinyin->key[0] = '\0'; cloudpinyin->errorcount = 0; } } } CloudPinyinReleaseCurlHandle(cloudpinyin, queue->curl); if (queue->str) free(queue->str); if (queue->pinyin) free(queue->pinyin); free(queue); }
tokens JSONScanner::ScanString() { char16 ch; this->currentIndex = 0; this->currentString = const_cast<char16*>(currentChar); bool endFound = false; bool isStringDirectInputTextMapped = true; LPCWSTR bulkStart = currentChar; uint bulkLength = 0; while (currentChar < inputText + inputLen) { ch = ReadNextChar(); int tempHex; if (ch == '"') { //end of the string endFound = true; break; } else if (ch <= 0x1F) { //JSON doesn't accept \u0000 - \u001f range, LS(\u2028) and PS(\u2029) are ok ThrowSyntaxError(JSERR_JsonIllegalChar); } else if ( 0 == ch ) { currentChar--; ThrowSyntaxError(JSERR_JsonNoStrEnd); } else if ('\\' == ch) { //JSON escape sequence in a string \", \/, \\, \b, \f, \n, \r, \t, unicode seq // unlikely V5.8 regular chars are not escaped, i.e '\g'' in a string is illegal not 'g' if (currentChar >= inputText + inputLen ) { ThrowSyntaxError(JSERR_JsonNoStrEnd); } ch = ReadNextChar(); switch (ch) { case 0: currentChar--; ThrowSyntaxError(JSERR_JsonNoStrEnd); case '"': case '/': case '\\': //keep ch break; case 'b': ch = 0x08; break; case 'f': ch = 0x0C; break; case 'n': ch = 0x0A; break; case 'r': ch = 0x0D; break; case 't': ch = 0x09; break; case 'u': { int chcode; // 4 hex digits if (currentChar + 3 >= inputText + inputLen) { //no room left for 4 hex chars ThrowSyntaxError(JSERR_JsonNoStrEnd); } if (!Js::NumberUtilities::FHexDigit((WCHAR)ReadNextChar(), &tempHex)) { ThrowSyntaxError(JSERR_JsonBadHexDigit); } chcode = tempHex * 0x1000; if (!Js::NumberUtilities::FHexDigit((WCHAR)ReadNextChar(), &tempHex)) { ThrowSyntaxError(JSERR_JsonBadHexDigit); } chcode += tempHex * 0x0100; if (!Js::NumberUtilities::FHexDigit((WCHAR)ReadNextChar(), &tempHex)) { ThrowSyntaxError(JSERR_JsonBadHexDigit); } chcode += tempHex * 0x0010; if (!Js::NumberUtilities::FHexDigit((WCHAR)ReadNextChar(), &tempHex)) { ThrowSyntaxError(JSERR_JsonBadHexDigit); } chcode += tempHex; AssertMsg(chcode == (chcode & 0xFFFF), "Bad unicode code"); ch = (char16)chcode; } break; default: // Any other '\o' is an error in JSON ThrowSyntaxError(JSERR_JsonIllegalChar); } // flush this->GetCurrentRangeCharacterPairList()->Add(RangeCharacterPair((uint)(bulkStart - inputText), bulkLength, ch)); uint oldIndex = currentIndex; currentIndex += bulkLength; currentIndex++; if (currentIndex < oldIndex) { // Overflow Js::Throw::OutOfMemory(); } // mark the mode as 'string transformed' (no direct mapping in inputText possible) isStringDirectInputTextMapped = false; // reset (to next char) bulkStart = currentChar; bulkLength = 0; } else { // continue bulkLength++; } } if (!endFound) { // no ending '"' found ThrowSyntaxError(JSERR_JsonNoStrEnd); } if (isStringDirectInputTextMapped == false) { // If the last bulk is not ended with an escape character, make sure that is // not built into the final unescaped string bool shouldSkipLastCharacter = false; if (bulkLength > 0) { shouldSkipLastCharacter = true; this->GetCurrentRangeCharacterPairList()->Add(RangeCharacterPair((uint)(bulkStart - inputText), bulkLength, _u('\0'))); uint oldIndex = currentIndex; currentIndex += bulkLength; if (currentIndex < oldIndex) { // Overflow Js::Throw::OutOfMemory(); } } this->BuildUnescapedString(shouldSkipLastCharacter); this->GetCurrentRangeCharacterPairList()->Clear(); this->currentString = this->stringBuffer; } else { // make currentIndex the length (w/o the \0) currentIndex = bulkLength; OUTPUT_TRACE_DEBUGONLY(Js::JSONPhase, _u("ScanString(): direct-mapped string as '%.*s'\n"), GetCurrentStringLen(), GetCurrentString()); } return (pToken->tk = tkStrCon); }