static int rts525a_optimize_phy(struct rtsx_pcr *pcr) { int err; err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3, D3_DELINK_MODE_EN, 0x00); if (err < 0) return err; rtsx_pci_write_phy_register(pcr, _PHY_FLD0, _PHY_FLD0_CLK_REQ_20C | _PHY_FLD0_RX_IDLE_EN | _PHY_FLD0_BIT_ERR_RSTN | _PHY_FLD0_BER_COUNT | _PHY_FLD0_BER_TIMER | _PHY_FLD0_CHECK_EN); rtsx_pci_write_phy_register(pcr, _PHY_ANA03, _PHY_ANA03_TIMER_MAX | _PHY_ANA03_OOBS_DEB_EN | _PHY_CMU_DEBUG_EN); if (is_version(pcr, 0x525A, IC_VER_A)) rtsx_pci_write_phy_register(pcr, _PHY_REV0, _PHY_REV0_FILTER_OUT | _PHY_REV0_CDR_BYPASS_PFD | _PHY_REV0_CDR_RX_IDLE_BYPASS); return 0; }
static int rts524a_extra_init_hw(struct rtsx_pcr *pcr) { rts5249_extra_init_hw(pcr); rtsx_pci_write_register(pcr, FUNC_FORCE_CTL, FORCE_ASPM_L1_EN, FORCE_ASPM_L1_EN); rtsx_pci_write_register(pcr, PM_EVENT_DEBUG, PME_DEBUG_0, PME_DEBUG_0); rtsx_pci_write_register(pcr, LDO_VCC_CFG1, LDO_VCC_LMT_EN, LDO_VCC_LMT_EN); rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL); if (is_version(pcr, 0x524A, IC_VER_A)) { rtsx_pci_write_register(pcr, LDO_DV18_CFG, LDO_DV18_SR_MASK, LDO_DV18_SR_DF); rtsx_pci_write_register(pcr, LDO_VCC_CFG1, LDO_VCC_REF_TUNE_MASK, LDO_VCC_REF_1V2); rtsx_pci_write_register(pcr, LDO_VIO_CFG, LDO_VIO_REF_TUNE_MASK, LDO_VIO_REF_1V2); rtsx_pci_write_register(pcr, LDO_VIO_CFG, LDO_VIO_SR_MASK, LDO_VIO_SR_DF); rtsx_pci_write_register(pcr, LDO_DV12S_CFG, LDO_REF12_TUNE_MASK, LDO_REF12_TUNE_DF); rtsx_pci_write_register(pcr, SD40_LDO_CTL1, SD40_VIO_TUNE_MASK, SD40_VIO_TUNE_1V7); } return 0; }
void Parser::parse( const char *str, int len, bool end ) { const char *p = str; const char *pos = p; const char *s = 0;//数据开始位置 const char *e = 0;//数据结束位置 while( len > 0 ) { if( *p == '<' ) { pos = p; if( s ) e = p;//记下数据结束位置 } else if( *p=='>' ) { std::string tag( pos + 1, p - pos - 1 ); reArrange(tag); if( is_version( tag ) ) ;//std::cout << tag << "\n"; else if(is_help(tag)) ; else if( is_end( tag ) ) { if( s && e ) { std::string data( s + 1, e -s - 1 ); on_data( data ); s = e = 0; } on_end( tag ); } else if( is_element( tag ) ) { parse_property( tag ); on_end( tag ); } else { parse_property( tag ); s = p;//记下数据开位置 } } p++; len--; } }
static int rts524a_optimize_phy(struct rtsx_pcr *pcr) { int err; err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3, D3_DELINK_MODE_EN, 0x00); if (err < 0) return err; rtsx_pci_write_phy_register(pcr, PHY_PCR, PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 | PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 | PHY_PCR_RSSI_EN); rtsx_pci_write_phy_register(pcr, PHY_SSCCR3, PHY_SSCCR3_STEP_IN | PHY_SSCCR3_CHECK_DELAY); if (is_version(pcr, 0x524A, IC_VER_A)) { rtsx_pci_write_phy_register(pcr, PHY_SSCCR3, PHY_SSCCR3_STEP_IN | PHY_SSCCR3_CHECK_DELAY); rtsx_pci_write_phy_register(pcr, PHY_SSCCR2, PHY_SSCCR2_PLL_NCODE | PHY_SSCCR2_TIME0 | PHY_SSCCR2_TIME2_WIDTH); rtsx_pci_write_phy_register(pcr, PHY_ANA1A, PHY_ANA1A_TXR_LOOPBACK | PHY_ANA1A_RXT_BIST | PHY_ANA1A_TXR_BIST | PHY_ANA1A_REV); rtsx_pci_write_phy_register(pcr, PHY_ANA1D, PHY_ANA1D_DEBUG_ADDR); rtsx_pci_write_phy_register(pcr, PHY_DIG1E, PHY_DIG1E_REV | PHY_DIG1E_D0_X_D1 | PHY_DIG1E_RX_ON_HOST | PHY_DIG1E_RCLK_REF_HOST | PHY_DIG1E_RCLK_TX_EN_KEEP | PHY_DIG1E_RCLK_TX_TERM_KEEP | PHY_DIG1E_RCLK_RX_EIDLE_ON | PHY_DIG1E_TX_TERM_KEEP | PHY_DIG1E_RX_TERM_KEEP | PHY_DIG1E_TX_EN_KEEP | PHY_DIG1E_RX_EN_KEEP); } rtsx_pci_write_phy_register(pcr, PHY_ANA08, PHY_ANA08_RX_EQ_DCGAIN | PHY_ANA08_SEL_RX_EN | PHY_ANA08_RX_EQ_VAL | PHY_ANA08_SCP | PHY_ANA08_SEL_IPI); return 0; }
static int rts525a_extra_init_hw(struct rtsx_pcr *pcr) { rts5249_extra_init_hw(pcr); rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL); if (is_version(pcr, 0x525A, IC_VER_A)) { rtsx_pci_write_register(pcr, L1SUB_CONFIG2, L1SUB_AUTO_CFG, L1SUB_AUTO_CFG); rtsx_pci_write_register(pcr, RREF_CFG, RREF_VBGSEL_MASK, RREF_VBGSEL_1V25); rtsx_pci_write_register(pcr, LDO_VIO_CFG, LDO_VIO_TUNE_MASK, LDO_VIO_1V7); rtsx_pci_write_register(pcr, LDO_DV12S_CFG, LDO_D12_TUNE_MASK, LDO_D12_TUNE_DF); rtsx_pci_write_register(pcr, LDO_AV12S_CFG, LDO_AV12S_TUNE_MASK, LDO_AV12S_TUNE_DF); rtsx_pci_write_register(pcr, LDO_VCC_CFG0, LDO_VCC_LMTVTH_MASK, LDO_VCC_LMTVTH_2A); rtsx_pci_write_register(pcr, OOBS_CONFIG, OOBS_AUTOK_DIS | OOBS_VAL_MASK, 0x89); } return 0; }
char * unix2vms_path(char *dst, const char *src) { #if !SYS_VMS char tmp2[NFILEN]; #endif char tmp[NFILEN]; char leading[NFILEN]; char *t; char *s = strcpy(tmp, src); /* ... to permit src == dst */ char *d = dst; char c = '?'; int bracket = FALSE; /* true when "[" passed. */ int on_top = FALSE; /* true when no "[." lead */ int node = FALSE; /* true when node found */ int device = FALSE; /* true when device found */ int len; /* * If VMS 'getenv()' is given an upper-case name, it assumes that it * corresponds to a logical device assignment. As a special case, if * we have a leading token of this form, translate it. */ if ((len = leading_uc(leading, s)) != 0) { s += len; len = strlen(strcpy(d, leading)); while (len > 1 && d[len - 1] == ' ') len--; if (*s) { /* text follows leading token */ s++; /* skip (assumed) SLASHC */ if ((len > 1) && (d[len - 1] == COLON)) { on_top = TRUE; } else if (strchr(s, SLASHC)) { /* must do a splice */ if ((len > 2) && (d[len - 1] == R_BLOCK)) { bracket++; if (d[len - 2] == PERIOD) /* rooted-device ? */ len -= 2; else len--; } } } d[len] = EOS; if ((t = strchr(d, COLON)) != NULL) { if (t[1] == COLON) { node = TRUE; if ((t = strchr(t + 2, COLON)) != NULL) device = TRUE; } else device = TRUE; } d += len; } else if (*s == CH_TILDE) { /* process home-directory reference */ char *home = getenv("SYS$LOGIN"); #if !SYS_VMS if (home == 0) home = unix2vms_path(tmp2, getenv("HOME")); #endif node = device = TRUE; s++; len = strlen(strcpy(d, home)); if (d[len - 1] == R_BLOCK) { bracket++; if (strcmp(s, "/")) { /* strip right-bracket to allow new levels */ if (d[len - 2] == PERIOD) len--; d[len - 1] = PERIOD; } else { s++; len--; } } d += len; } /* look for node-name in VMS-format */ if (!node && (t = strchr(s, '!')) != 0 && (t[1] == SLASHC || t[1] == EOS)) { leaf_dot = DotPrefix(s); while (s < t) *d++ = CharToVms(*s++); *d++ = COLON; *d++ = COLON; s++; /* skip over '!' */ } /* look for device-name, indicated by a leading SLASHC */ if (!device && (*s == SLASHC)) { leaf_dot = DotPrefix(++s); if ((t = strchr(s, SLASHC)) == 0) t = skip_string(s); else if (t[1] == EOS) on_top = TRUE; while (s < t) *d++ = CharToVms(*s++); if (d != dst) *d++ = COLON; } /* permit leading "./" to simplify cases in which we concatenate */ if (!strncmp(s, "./", 2)) s += 2; /* translate repeated leading "../" */ while (!strncmp(s, "../", 3)) { s += 3; if (!bracket++) *d++ = L_BLOCK; *d++ = '-'; } if (!strcmp(s, "..")) { s += 2; if (!bracket++) *d++ = L_BLOCK; *d++ = '-'; } if (strchr(s, SLASHC)) { if (!bracket++) *d++ = L_BLOCK; if (*s == SLASHC) { s++; } else if (!on_top) { *d++ = PERIOD; } while ((c = *s++) != EOS) { if (c == PERIOD) { c = '$'; if (*s == SLASHC) /* ignore "./" */ continue; } if (c == SLASHC) { leaf_dot = DotPrefix(s); if (strchr(s, SLASHC)) *d++ = PERIOD; else { break; } } else { *d++ = CharToVms(c); } } } if (bracket) { if (on_top && d[-1] == L_BLOCK) { (void) strcpy(d, RootDir); d += strlen(d); } *d++ = R_BLOCK; } if (c != EOS && *s) { leaf_dot = DotPrefix(s); while ((c = *s) != EOS) { if ((leaf_ver = is_version(s)) == TRUE) { leaf_dot = TRUE; /* no longer pertinent */ (void) strcpy(d, s); *d = SEMICOLON; /* make this unambiguous */ d += strlen(d); break; } else { *d++ = CharToVms(c); } s++; } if (!leaf_dot) *d++ = PERIOD; if (!leaf_ver) *d++ = SEMICOLON; } *d = EOS; return mkupper(dst); }
gint main (gint argc, gchar *argv[]) { G_PASTE_INIT_GETTEXT (); g_set_prgname (argv[0]); struct option long_options[] = { { "decoration", required_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "oneline", no_argument, NULL, 'o' }, { "raw" , no_argument, NULL, 'r' }, { "separator" , required_argument, NULL, 's' }, { "version", no_argument, NULL, 'v' }, { "zero", no_argument, NULL, 'z' }, { NULL, no_argument, NULL, '\0' } }; gboolean help = FALSE, version = FALSE; gboolean oneline = FALSE, raw = FALSE, zero = FALSE; const gchar *decoration = NULL, *separator = NULL; gint c; while ((c = getopt_long(argc, argv, "d:hors:vz", long_options, NULL)) != -1) { switch (c) { case 'd': decoration = optarg; break; case 'h': help = TRUE; break; case 'o': oneline = TRUE; break; case 'r': raw = TRUE; break; case 's': separator = optarg; break; case 'v': version = TRUE; break; case 'z': zero = TRUE; break; default: return EXIT_FAILURE; } } argv += optind; argc -= optind; if (help || (argc > 0 && !g_strcmp0 (argv[0], "help"))) { show_help (); return EXIT_SUCCESS; } else if (version || (argc > 0 && is_version (argv[0]))) { show_version (); return EXIT_SUCCESS; } int status = EXIT_SUCCESS; g_autoptr (GError) error = NULL; g_autoptr (GPasteClient) client = g_paste_client_new_sync (&error); if (!client) failure_exit (error); gboolean was_valid_pipe = FALSE; if (!isatty (fileno (stdin))) { /* We are being piped */ G_PASTE_CLEANUP_STRING_FREE GString *data = g_string_new (NULL); while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, (guchar)c); data->str[data->len - 1] = '\0'; if (!argc) { g_paste_client_add_sync (client, data->str, &error); was_valid_pipe = TRUE; } else if (argc == 2) { const gchar *arg1 = argv[0]; const gchar *arg2 = argv[1]; if (!g_strcmp0 (arg1, "ap") || !g_strcmp0 (arg1, "add-password")) { g_paste_client_add_password_sync (client, arg2, data->str, &error); was_valid_pipe = TRUE; } } } if (was_valid_pipe) {} else if (argc > 0 && (!g_strcmp0 (argv[0], "merge") || !g_strcmp0 (argv[0], "m"))) { --argc; ++argv; guint32 *indexes = alloca (argc * sizeof (guint32)); for (gint i = 0; i < argc; ++i) indexes[i] = _strtoull (argv[i]); g_paste_client_merge_sync (client, decoration, separator, indexes, argc, &error); } else { const gchar *arg1, *arg2, *arg3; switch (argc) { case 0: show_history (client, oneline, raw, zero, &error); break; case 1: arg1 = argv[0]; if (!g_strcmp0 (arg1, "about")) g_paste_client_about_sync (client, &error); else if (!g_strcmp0 (arg1, "dr") || !g_strcmp0 (arg1, "daemon-reexec")) { g_paste_client_reexecute_sync (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); return EXIT_SUCCESS; } } else if (!g_strcmp0 (arg1, "dv") || !g_strcmp0 (arg1, "daemon-version")) { g_autofree gchar *v = g_paste_client_get_version (client); printf ("%s\n", v); } else if (!g_strcmp0 (arg1, "e") || !g_strcmp0 (arg1, "empty")) { g_paste_client_empty_sync (client, &error); } else if (!g_strcmp0 (arg1, "h") || !g_strcmp0 (arg1, "history")) { show_history (client, oneline, raw, zero, &error); } else if (!g_strcmp0 (arg1, "hs") || !g_strcmp0 (arg1, "history-size")) { guint32 size = g_paste_client_get_history_size_sync (client, &error); if (!error) printf ("%u\n", size); } else if (!g_strcmp0 (arg1, "lh") || !g_strcmp0 (arg1, "list-histories")) { g_auto (GStrv) histories = g_paste_client_list_histories_sync (client, &error); if (!error) { for (GStrv h = histories; *h; ++h) printf ("%s\n", *h); } } else if (!g_strcmp0 (arg1, "settings") || !g_strcmp0 (arg1, "p") || !g_strcmp0 (arg1, "preferences")) { if (!g_paste_util_activate_ui_sync ("prefs", NULL, &error)) { g_critical ("%s Ui: %s", _("Couldn't spawn"), error->message); return EXIT_FAILURE; } } else if (!g_strcmp0 (arg1, "show-history")) { g_paste_client_show_history_sync (client, &error); } else if (!g_strcmp0 (arg1, "start") || !g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "daemon")) { g_paste_client_track_sync (client, TRUE, &error); } else if (!g_strcmp0 (arg1, "stop") || !g_strcmp0 (arg1, "q") || !g_strcmp0 (arg1, "quit")) { g_paste_client_track_sync (client, FALSE, &error); } else if (!g_strcmp0 (arg1, "ui")) { status = spawn ("Ui"); } else if (g_paste_util_has_applet () && !g_strcmp0 (arg1, "applet")) { status = spawn ("Applet"); } else if (g_paste_util_has_unity () && !g_strcmp0 (arg1, "app-indicator")) { status = spawn ("AppIndicator"); } else { show_help (); status = EXIT_FAILURE; } break; case 2: arg1 = argv[0]; arg2 = argv[1]; if (!g_strcmp0 (arg1, "a") || !g_strcmp0 (arg1, "add")) { g_paste_client_add_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "bh") || !g_strcmp0 (arg1, "backup-history")) { g_paste_client_backup_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "del") || !g_strcmp0 (arg1, "delete") || !g_strcmp0 (arg1, "rm") || !g_strcmp0 (arg1, "remove")) { g_paste_client_delete_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "dp") || !g_strcmp0 (arg1, "delete-password")) { g_paste_client_delete_password_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "dh") || !g_strcmp0 (arg1, "delete-history")) { g_paste_client_delete_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "f") || !g_strcmp0 (arg1, "file")) { g_paste_client_add_file_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "g") || !g_strcmp0 (arg1, "get")) { const gchar *value = (!raw) ? g_paste_client_get_element_sync (client, _strtoull (arg2), &error) : g_paste_client_get_raw_element_sync (client, _strtoull (arg2), &error); if (!error) printf ("%s", value); } else if (!g_strcmp0 (arg1, "search")) { gsize hits; g_autofree guint32 *results = g_paste_client_search_sync (client, arg2, &hits, &error); if (!error) { if (hits > 0) { for (gsize i = 0; i < hits; ++i) { guint32 index = results[i]; gchar *line = g_paste_client_get_element_sync (client, index, &error); if (error) break; print_history_line (line, index, oneline, raw, zero); } } } } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "set") || !g_strcmp0 (arg1, "select")) { g_paste_client_select_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "sh") || !g_strcmp0 (arg1, "switch-history")) { g_paste_client_switch_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "u") || !g_strcmp0 (arg1, "upload")) { g_paste_client_upload_sync (client, _strtoull (arg2), &error); } else { show_help (); status = EXIT_FAILURE; } break; case 3: arg1 = argv[0]; arg2 = argv[1]; arg3 = argv[2]; if (!g_strcmp0 (arg1, "ap") || !g_strcmp0 (arg1, "add-password")) { g_paste_client_add_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "rp") || !g_strcmp0 (arg1, "rename-password")) { g_paste_client_rename_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "sp") || !g_strcmp0 (arg1, "set-password")) { g_paste_client_set_password_sync (client, _strtoull (arg2), arg3, &error); } else { show_help (); status = EXIT_FAILURE; } break; default: show_help (); status = EXIT_FAILURE; break; } } if (error) failure_exit (error); return status; }
bool DictInfo::save_ifo_file(void) const { if(ifo_file_name.empty()) { g_critical("Fail to save ifo file. ifo file name is not specified."); return false; } std::stringstream str; //str << UTF8_BOM; if(!is_infotype()) { g_critical("Fail to save ifo file. Dict info type is not specified."); return false; } const gchar *magic_data = NULL; if(infotype == DictInfoType_NormDict) magic_data = NORM_DICT_MAGIC_DATA; else if(infotype == DictInfoType_TreeDict) magic_data = TREE_DICT_MAGIC_DATA; else if(infotype == DictInfoType_ResDb) magic_data = RES_DB_MAGIC_DATA; else return false; str << magic_data << '\n'; if(!is_version()) { g_critical("Fail to save ifo file. version is not specified."); return false; } str << "version=" << version << '\n'; if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict) { if(!is_bookname()) { g_critical("Fail to save ifo file. bookname is not specified."); return false; } str << "bookname=" << bookname << '\n'; if(!is_wordcount()) { g_critical("Fail to save ifo file. wordcount is not specified."); return false; } str << "wordcount=" << wordcount << '\n'; } if(infotype == DictInfoType_NormDict) { if(is_synwordcount()) str << "synwordcount=" << synwordcount << '\n'; } if(infotype == DictInfoType_ResDb) { if(is_filecount()) str << "filecount=" << filecount << '\n'; } if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict || infotype == DictInfoType_ResDb) { if(!is_index_file_size()) { g_critical("Fail to save ifo file. index_file_size is not specified."); return false; } if(infotype == DictInfoType_NormDict) str << "idxfilesize=" << index_file_size << '\n'; if(infotype == DictInfoType_TreeDict) str << "tdxfilesize=" << index_file_size << '\n'; if(infotype == DictInfoType_ResDb) str << "ridxfilesize=" << index_file_size << '\n'; } if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict) { if(is_author()) str << "author=" << author << '\n'; if(is_email()) str << "email=" << email << '\n'; if(is_website()) str << "website=" << website << '\n'; if(is_description()) { std::string temp; encode_description(description.c_str(), description.length(), temp); str << "description=" << temp << '\n'; } if(is_date()) str << "date=" << date << '\n'; if(is_sametypesequence()) str << "sametypesequence=" << sametypesequence << '\n'; } if(infotype == DictInfoType_NormDict) { if(is_dicttype()) str << "dicttype=" << dicttype << '\n'; } if(!g_file_set_contents(ifo_file_name.c_str(), str.str().c_str(), -1, NULL)) { g_critical("Fail to save ifo file." open_write_file_err, ifo_file_name.c_str()); return false; } return true; }
bool DictInfo::load_from_ifo_file(const std::string& ifofilename, DictInfoType infotype) { clear(); ifo_file_name=ifofilename; set_infotype(infotype); glib::CharStr buffer; glib::Error error; if (!g_file_get_contents(ifo_file_name.c_str(), get_addr(buffer), NULL, get_addr(error))) { g_critical("Load %s failed. Error: %s.", ifo_file_name.c_str(), error->message); return false; } const gchar *p1 = get_impl(buffer); if(g_str_has_prefix(p1, UTF8_BOM)) p1 += 3; if(!g_utf8_validate(p1, -1, NULL)) { g_critical("Load %s failed: Invalid UTF-8 encoded text.", ifo_file_name.c_str()); return false; } lineno = 1; const gchar *magic_data = NULL; if(infotype == DictInfoType_NormDict) magic_data = NORM_DICT_MAGIC_DATA; else if(infotype == DictInfoType_TreeDict) magic_data = TREE_DICT_MAGIC_DATA; else if(infotype == DictInfoType_ResDb) magic_data = RES_DB_MAGIC_DATA; else return false; if (!g_str_has_prefix(p1, magic_data)) { g_critical("Load %s failed: Incorrect magic data.", ifo_file_name.c_str()); if(g_str_has_prefix(p1, NORM_DICT_MAGIC_DATA)) g_message("File '%s' is an index-based dictionary.", ifo_file_name.c_str()); else if(g_str_has_prefix(p1, TREE_DICT_MAGIC_DATA)) g_message("File '%s' is a tree dictionary.", ifo_file_name.c_str()); else if(g_str_has_prefix(p1, RES_DB_MAGIC_DATA)) g_message("File '%s' is a resource database.", ifo_file_name.c_str()); else g_message("File '%s' is not a StarDict dictionary or it's broken.", ifo_file_name.c_str()); return false; } p1 += strlen(magic_data); p1 = skip_new_line(p1); if(!p1) { g_critical("Load %s failed: Incorrect magic data.", ifo_file_name.c_str()); return false; } std::string key, value; while(true) { ++lineno; p1 = get_key_value(p1, key, value); if(!p1) break; // version must the first option if(!is_version()) { if(key != "version") { g_critical("Load %s failed: \"version\" must be the first option.", ifo_file_name.c_str()); return false; } } if(key == "version") { if(!check_option_duplicate(f_version, "version")) continue; set_version(value); if(infotype == DictInfoType_NormDict) { if(version != "2.4.2" && version != "3.0.0") { g_critical("Load %s failed: Unknown version.", ifo_file_name.c_str()); return false; } } else if(infotype == DictInfoType_TreeDict) { if(version != "2.4.2") { g_critical("Load %s failed: Unknown version.", ifo_file_name.c_str()); return false; } } else if(infotype == DictInfoType_ResDb) { if(version != "3.0.0") { g_critical("Load %s failed: Unknown version.", ifo_file_name.c_str()); return false; } } } else if(key == "idxoffsetbits") { if(!check_option_duplicate(f_idxoffsetbits, "idxoffsetbits")) continue; if(value != "32") { // TODO g_critical("Load %s failed: idxoffsetbits != 32 not supported presently.", ifo_file_name.c_str()); return false; } } else if(key == "wordcount" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_wordcount, "wordcount")) continue; set_wordcount(atol(value.c_str())); } else if(key == "filecount" && infotype == DictInfoType_ResDb) { if(!check_option_duplicate(f_filecount, "filecount")) continue; set_filecount(atol(value.c_str())); } else if(key == "synwordcount" && infotype == DictInfoType_NormDict) { if(!check_option_duplicate(f_synwordcount, "synwordcount")) continue; set_synwordcount(atol(value.c_str())); } else if(key == "tdxfilesize" && infotype == DictInfoType_TreeDict) { if(!check_option_duplicate(f_index_file_size, "tdxfilesize")) continue; set_index_file_size(atol(value.c_str())); } else if(key == "idxfilesize" && infotype == DictInfoType_NormDict) { if(!check_option_duplicate(f_index_file_size, "idxfilesize")) continue; set_index_file_size(atol(value.c_str())); } else if(key == "ridxfilesize" && infotype == DictInfoType_ResDb) { if(!check_option_duplicate(f_index_file_size, "ridxfilesize")) continue; set_index_file_size(atol(value.c_str())); } else if(key == "dicttype" && infotype == DictInfoType_NormDict) { if(!check_option_duplicate(f_dicttype, "dicttype")) continue; set_dicttype(value); } else if(key == "bookname" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_bookname, "bookname")) continue; set_bookname(value); } else if(key == "author" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_author, "author")) continue; set_author(value); } else if(key == "email" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_email, "email")) continue; set_email(value); } else if(key == "website" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_website, "website")) continue; set_website(value); } else if(key == "date" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_date, "date")) continue; set_date(value); } else if(key == "description" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_description, "description")) continue; std::string temp; decode_description(value.c_str(), value.length(), temp); set_description(temp); } else if(key == "sametypesequence" && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { if(!check_option_duplicate(f_sametypesequence, "sametypesequence")) continue; set_sametypesequence(value); } else { g_message("Load %s warning: unknown option %s.", ifo_file_name.c_str(), key.c_str()); } } // check required options if((!is_wordcount() || wordcount == 0) && ((infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict))) { g_critical("Load %s failed: wordcount not specified or 0.", ifo_file_name.c_str()); return false; } if((!is_filecount() || filecount == 0) && infotype == DictInfoType_ResDb) { g_critical("Load %s failed: filecount not specified or 0.", ifo_file_name.c_str()); return false; } if((!is_bookname() || bookname.empty()) && (infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict)) { g_critical("Load %s failed: bookname not specified.", ifo_file_name.c_str()); return false; } if(!is_index_file_size() || index_file_size == 0) { const char* kkey; if(infotype == DictInfoType_NormDict) kkey = "idxfilesize"; else if(infotype == DictInfoType_TreeDict) kkey = "tdxfilesize"; else if(infotype == DictInfoType_ResDb) kkey = "ridxfilesize"; else kkey = ""; g_critical("Load %s failed: %s not specified or 0.", ifo_file_name.c_str(), kkey); return false; } return true; }
gint main (gint argc, gchar *argv[]) { G_PASTE_INIT_GETTEXT (); if (argc > 1) { if (is_help (argv[1])) { show_help (argv[0]); return EXIT_SUCCESS; } else if (is_version (argv[1])) { show_version (); return EXIT_SUCCESS; } } int status = EXIT_SUCCESS; G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL; G_PASTE_CLEANUP_UNREF GPasteClient *client = g_paste_client_new_sync (&error); if (!client) failure_exit (error); if (!isatty (fileno (stdin)) && argc == 1) { /* We are being piped */ G_PASTE_CLEANUP_STRING_FREE GString *data = g_string_new (""); gchar c; while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, c); data->str[data->len - 1] = '\0'; g_paste_client_add_sync (client, data->str, &error); } else { const gchar *arg1, *arg2, *arg3; switch (argc) { case 1: show_history (client, FALSE, FALSE, &error); break; case 2: arg1 = argv[1]; if (!g_strcmp0 (arg1, "about")) g_paste_client_about_sync (client, &error); else if (!g_strcmp0 (arg1, "dr") || !g_strcmp0 (arg1, "daemon-reexec")) { g_paste_client_reexecute_sync (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); return EXIT_SUCCESS; } } else if (!g_strcmp0 (arg1, "dv") || !g_strcmp0 (arg1, "daemon-version")) { G_PASTE_CLEANUP_FREE gchar *v = g_paste_client_get_version (client); printf ("%s\n", v); } else if (!g_strcmp0 (arg1, "e") || !g_strcmp0 (arg1, "empty")) { g_paste_client_empty_sync (client, &error); } else if (!g_strcmp0 (arg1, "h") || !g_strcmp0 (arg1, "history")) { show_history (client, FALSE, FALSE, &error); } else if (!g_strcmp0 (arg1, "hs") || !g_strcmp0 (arg1, "history-size")) { guint32 size = g_paste_client_get_history_size_sync (client, &error); if (!error) printf ("%u\n", size); } else if (!g_strcmp0 (arg1, "lh") || !g_strcmp0 (arg1, "list-histories")) { G_PASTE_CLEANUP_STRFREEV GStrv histories = g_paste_client_list_histories_sync (client, &error); if (!error) { for (GStrv h = histories; *h; ++h) printf ("%s\n", *h); } } else if (!g_strcmp0 (arg1, "rh") || !g_strcmp0 (arg1, "raw-history")) { show_history (client, TRUE, FALSE, &error); } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "settings") || !g_strcmp0 (arg1, "p") || !g_strcmp0 (arg1, "preferences")) { status = spawn ("Settings", &error); } else if (!g_strcmp0 (arg1, "start") || !g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "daemon")) { g_paste_client_track_sync (client, TRUE, &error); } else if (!g_strcmp0 (arg1, "stop") || !g_strcmp0 (arg1, "q") || !g_strcmp0 (arg1, "quit")) { g_paste_client_track_sync (client, FALSE, &error); } else if (!g_strcmp0 (arg1, "zh") || !g_strcmp0 (arg1, "zero-history")) { show_history (client, FALSE, TRUE, &error); } #if G_PASTE_CONFIG_ENABLE_APPLET else if (!g_strcmp0 (arg1, "applet")) { status = spawn ("Applet", &error); } #endif #if G_PASTE_CONFIG_ENABLE_UNITY else if (!g_strcmp0 (arg1, "app-indicator")) { status = spawn ("AppIndicator", &error); } #endif else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 3: arg1 = argv[1]; arg2 = argv[2]; if (!g_strcmp0 (arg1, "a") || !g_strcmp0 (arg1, "add")) { g_paste_client_add_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "bh") || !g_strcmp0 (arg1, "backup-history")) { g_paste_client_backup_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "del") || !g_strcmp0 (arg1, "delete") || !g_strcmp0 (arg1, "rm") || !g_strcmp0 (arg1, "remove")) { g_paste_client_delete_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "dp") || !g_strcmp0 (arg1, "delete-password")) { g_paste_client_delete_password_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "dh") || !g_strcmp0 (arg1, "delete-history")) { g_paste_client_delete_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "f") || !g_strcmp0 (arg1, "file")) { g_paste_client_add_file_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "g") || !g_strcmp0 (arg1, "get")) { printf ("%s", g_paste_client_get_element_sync (client, _strtoull (arg2), &error)); } else if (!g_strcmp0 (arg1, "gr") || !g_strcmp0 (arg1, "get-raw")) { printf ("%s", g_paste_client_get_raw_element_sync (client, _strtoull (arg2), &error)); } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "set") || !g_strcmp0 (arg1, "select")) { g_paste_client_select_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "sh") || !g_strcmp0 (arg1, "switch-history")) { g_paste_client_switch_history_sync (client, arg2, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 4: arg1 = argv[1]; arg2 = argv[2]; arg3 = argv[3]; if (!g_strcmp0 (arg1, "ap") || !g_strcmp0 (arg1, "add-password")) { g_paste_client_add_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "rp") || !g_strcmp0 (arg1, "rename-password")) { g_paste_client_rename_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "sp") || !g_strcmp0 (arg1, "set-password")) { g_paste_client_set_password_sync (client, _strtoull (arg2), arg3, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; default: show_help (argv[0]); status = EXIT_FAILURE; break; } } if (error) failure_exit (error); return status; }
gint main (gint argc, gchar *argv[]) { G_PASTE_INIT_GETTEXT (); if (argc > 1) { if (is_help (argv[1])) { show_help (argv[0]); return EXIT_SUCCESS; } else if (is_version (argv[1])) { show_version (); return EXIT_SUCCESS; } } int status = EXIT_SUCCESS; G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL; G_PASTE_CLEANUP_UNREF GPasteClient *client = g_paste_client_new_sync (&error); if (!client) failure_exit (error); if (!isatty (fileno (stdin))) { /* We are being piped */ G_PASTE_CLEANUP_STRING_FREE GString *data = g_string_new (""); gchar c; while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, c); data->str[data->len - 1] = '\0'; g_paste_client_add_sync (client, data->str, &error); } else { const gchar *arg1, *arg2; switch (argc) { case 1: show_history (client, FALSE, FALSE, &error); break; case 2: arg1 = argv[1]; if (!g_strcmp0 (arg1, "start") || !g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "daemon")) { g_paste_client_track_sync (client, TRUE, &error); } else if (!g_strcmp0 (arg1, "stop") || !g_strcmp0 (arg1, "q") || !g_strcmp0 (arg1, "quit")) { g_paste_client_track_sync (client, FALSE, &error); } else if (!g_strcmp0 (arg1, "e") || !g_strcmp0 (arg1, "empty")) { g_paste_client_empty_sync (client, &error); } #if G_PASTE_CONFIG_ENABLE_APPLET else if (!g_strcmp0 (arg1, "applet")) { g_spawn_command_line_async (PKGLIBEXECDIR "/gpaste-applet", &error); if (error) { g_critical ("%s: %s", _("Couldn't spawn gpaste-applet.\n"), error->message); g_clear_error (&error); status = EXIT_FAILURE; } } #endif else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "settings") || !g_strcmp0 (arg1, "p") || !g_strcmp0 (arg1, "preferences")) { execl (PKGLIBEXECDIR "/gpaste-settings", "GPaste-Settings", NULL); } else if (!g_strcmp0 (arg1, "dr") || !g_strcmp0 (arg1, "daemon-reexec")) { g_paste_client_reexecute_sync (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); return EXIT_SUCCESS; } } else if (!g_strcmp0 (arg1, "h") || !g_strcmp0 (arg1, "history")) { show_history (client, FALSE, FALSE, &error); } else if (!g_strcmp0 (arg1, "hs") || !g_strcmp0 (arg1, "history-size")) { guint32 size = g_paste_client_get_history_size_sync (client, &error); if (!error) printf ("%u\n", size); } else if (!g_strcmp0 (arg1, "rh") || !g_strcmp0 (arg1, "raw-history")) { show_history (client, TRUE, FALSE, &error); } else if (!g_strcmp0 (arg1, "zh") || !g_strcmp0 (arg1, "zero-history")) { show_history (client, FALSE, TRUE, &error); } else if (!g_strcmp0 (arg1, "lh") || !g_strcmp0 (arg1, "list-histories")) { G_PASTE_CLEANUP_STRFREEV GStrv histories = g_paste_client_list_histories_sync (client, &error); if (!error) { for (GStrv h = histories; *h; ++h) printf ("%s\n", *h); } } else if (!g_strcmp0 (argv[1], "about")) { g_paste_client_about_sync (client, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 3: arg1 = argv[1]; arg2 = argv[2]; if (!g_strcmp0 (arg1, "bh")|| !g_strcmp0 (arg1, "backup-history")) { g_paste_client_backup_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "sh") || !g_strcmp0 (arg1, "switch-history")) { g_paste_client_switch_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "dh") || !g_strcmp0 (arg1, "delete-history")) { g_paste_client_delete_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "a") || !g_strcmp0 (arg1, "add")) { g_paste_client_add_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "g")|| !g_strcmp0 (arg1, "get")) { printf ("%s", g_paste_client_get_element_sync (client, g_ascii_strtoull (arg2, NULL, 0), &error)); } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "set") || !g_strcmp0 (arg1, "select")) { g_paste_client_select_sync (client, g_ascii_strtoull (arg2, NULL, 0), &error); } else if (!g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "delete")) { g_paste_client_delete_sync (client, g_ascii_strtoull (arg2, NULL, 0), &error); } else if (!g_strcmp0 (arg1, "f") || !g_strcmp0 (arg1, "file")) { g_paste_client_add_file_sync (client, arg2, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; default: show_help (argv[0]); status = EXIT_FAILURE; break; } } if (error) failure_exit (error); return status; }