static int fs_cmd_cd(struct fs_info *session) { /* Usage: cd <remote-directory> */ int ret; char *tmp, *arg_remotedir; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_remotedir = tmp; split_word(arg_remotedir); if (*arg_remotedir == '\0') { fprintf(stderr, "Remote directory is not specified.\n"); errno = EINVAL; return FTP_RET_ERROR; } /* --- END OF Get args --- */ ret = fs_execute(session, "CWD %s\r\n", arg_remotedir); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
static int fs_cmd_rm(struct fs_info *session) { /* Usage: rm <remote-file> */ int ret; char *tmp, *arg_remotefile; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_remotefile = tmp; split_word(arg_remotefile); if (*arg_remotefile == '\0') { fprintf(stderr, "File name is not specified.\n"); errno = EINVAL; return FTP_RET_ERROR; } /* --- END OF Get args --- */ ret = fs_execute(session, "DELE %s\r\n", arg_remotefile); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
/********************************************************************** * split_and_recog_word * * Split the word into 2 smaller pieces at the largest gap. * Recognize the pieces and stick the results back together. **********************************************************************/ void Tesseract::split_and_recog_word(WERD_RES *word) { // Find the biggest blob gap in the chopped_word. int bestgap = -MAX_INT32; int split_index = 0; for (int b = 1; b < word->chopped_word->NumBlobs(); ++b) { TBOX prev_box = word->chopped_word->blobs[b - 1]->bounding_box(); TBOX blob_box = word->chopped_word->blobs[b]->bounding_box(); int gap = blob_box.left() - prev_box.right(); if (gap > bestgap) { bestgap = gap; split_index = b; } } ASSERT_HOST(split_index > 0); WERD_RES *word2 = NULL; BlamerBundle *orig_bb = NULL; split_word(word, split_index, &word2, &orig_bb); // Recognize the first part of the word. recog_word_recursive(word); // Recognize the second part of the word. recog_word_recursive(word2); join_words(word, word2, orig_bb); }
static int fs_cmd_mv(struct fs_info *session) { /* Usage: mv <from-name> <to-name> */ int ret; char *tmp, *arg_fromname, *arg_toname; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_fromname = tmp; skip_word(tmp); skip_spaces(tmp); arg_toname = tmp; split_word(arg_fromname); split_word(arg_toname); if ((*arg_fromname == '\0') || (*arg_toname == '\0')) { fprintf(stderr, "Please specify source and destonation names.\n"); errno = EINVAL; return FTP_RET_ERROR; } /* --- END OF Get args --- */ fprintf(stdout, "from: '%s`, to: '%s`\n", arg_fromname, arg_toname); ret = fs_execute(session, "RNFR %s\r\n", arg_fromname); if (ret != FTP_RET_OK) { return ret; } ret = fs_execute(session, "RNTO %s\r\n", arg_toname); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
static int fs_cmd_ls(struct fs_info *session) { /* Usage: ls [remote-directory] */ int ret, data_sock; char *tmp, *arg_remotedir; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_remotedir = tmp; split_word(arg_remotedir); if (*arg_remotedir == '\0') { arg_remotedir = NULL; } /* --- END OF Get args --- */ ret = make_data_socket(session, &data_sock); if (ret != FTP_RET_OK) { return ret; } ret = (arg_remotedir == NULL) ? fs_execute(session, "LIST\r\n") : fs_execute(session, "LIST %s\r\n", arg_remotedir); if (ret != FTP_RET_OK) { close(data_sock); return ret; } ret = fill_file_from_socket(stdout, data_sock, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { close(data_sock); return ret; } close(data_sock); if (FTP_STAT_TYPE_POSITIVE_PRELIMINARY == FTP_STAT_TYPE(session->stat_code)) { ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { return ret; } } return FTP_RET_OK; }
static int fs_cmd_user(struct fs_info *session) { /* Usage: user <user-name> */ int ret; char *tmp, *arg_username, *password; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_username = tmp; split_word(arg_username); if (*arg_username == '\0') { fprintf(stderr, "User name is not specified.\n"); errno = EINVAL; return FTP_RET_ERROR; } /* --- END OF Get args --- */ ret = fs_execute(session, "USER %s\r\n", arg_username); if (ret != FTP_RET_OK) { return ret; } password = getpass("Password: "******"Cant get password for %s.\n", arg_username); errno = EINVAL; return FTP_RET_ERROR; } ret = fs_execute(session, "PASS %s\r\n", password); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
// Split a line at suitable positions to make it shorter than // maxWidth. The line should not contain embedded line breaks. static void split_line(const TextInfo& info, const utf8_string& string, coord maxWidth, text_lines_t& result) { size_t wordStart = 0; size_t wordEnd = 0; utf8_string line; do { wordEnd = string.find(chars::space, wordStart); if (wordEnd == std::string::npos){ wordEnd = string.size(); } utf8_string word = slice(string, wordStart, wordEnd); const coord width = info.GetWidth(line + chars::space + word); if (!line.empty() && width > maxWidth){ result.push_back(TextLine::SoftBreak(width, line + chars::space)); line.clear(); } if (info.GetWidth(word) > maxWidth){ word = split_word(info, word, result); } if (!line.empty()){ line += chars::space; } line += word; wordStart = wordEnd + 1; } while (wordEnd != string.size()); if (line.size() > 1){ const utf8_string last(line + chars::space); const coord width = info.GetWidth(last); result.push_back(TextLine::SoftBreak(width, last)); } }
static int fs_cmd_put(struct fs_info *session) { /* Usage: put <local-file> <remote-file> */ int ret, data_sock; char *tmp, *arg_localfile, *arg_remotefile; FILE *file; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_localfile = tmp; skip_word(tmp); skip_spaces(tmp); arg_remotefile = tmp; split_word(arg_localfile); split_word(arg_remotefile); if ((*arg_localfile == '\0') && (*arg_remotefile == '\0')) { fprintf(stderr, "Please specify names of local and remote files.\n"); errno = EINVAL; return FTP_RET_ERROR; } /* --- END OF Get args --- */ fprintf(stdout, "local: '%s`, remote: '%s`\n", arg_localfile, arg_remotefile); file = fopen(arg_localfile, "r"); if (file == NULL) { fprintf(stderr, "Can't open file '%s` for reading.\n", arg_localfile); return FTP_RET_ERROR; } ret = make_data_socket(session, &data_sock); if (ret != FTP_RET_OK) { fclose(file); return ret; } ret = fs_execute(session, "STOR %s\r\n", arg_remotefile); if (ret != FTP_RET_OK) { fclose(file); close(data_sock); return ret; } ret = flush_file_to_socket(file, data_sock, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { fclose(file); close(data_sock); return ret; } fclose(file); close(data_sock); ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
static int fs_cmd_get(struct fs_info *session) { /* Usage: get <remote-file> [local-file] */ int ret, data_sock; char *tmp, *arg_remotefile, *arg_localfile; FILE *file; if (!session->is_connected) { fprintf(stderr, "Not connected.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_remotefile = tmp; skip_word(tmp); skip_spaces(tmp); arg_localfile = tmp; split_word(arg_remotefile); split_word(arg_localfile); if (*arg_remotefile == '\0') { fprintf(stderr, "Remote file name is not specified.\n"); errno = EINVAL; return FTP_RET_ERROR; } if (*arg_localfile == '\0') { arg_localfile = strchr(arg_remotefile, '/'); if (arg_localfile != NULL) { arg_localfile += 1; /* skip '/' character */ } else { arg_localfile = arg_remotefile; } } /* --- END OF Get args --- */ fprintf(stdout, "remote: '%s`, local: '%s`\n", arg_remotefile, arg_localfile); file = fopen(arg_localfile, "w"); if (file == NULL) { fprintf(stderr, "Can't open file '%s` for writing.\n", arg_localfile); return FTP_RET_ERROR; } ret = make_data_socket(session, &data_sock); if (ret != FTP_RET_OK) { fclose(file); return ret; } ret = fs_execute(session, "RETR %s\r\n", arg_remotefile); if (ret != FTP_RET_OK) { fclose(file); close(data_sock); return ret; } ret = fill_file_from_socket(file, data_sock, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { fclose(file); close(data_sock); return ret; } fclose(file); close(data_sock); ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
static int fs_cmd_open(struct fs_info *session) { /* Usage: open <host-name> [port] */ int ret; char *tmp, *arg_hostname, *arg_port; struct in_addr remote_ip; unsigned int remote_port; if (session->is_connected) { fprintf(stderr, "Already connected, use close first.\n"); return FTP_RET_FAIL; } /* Get args */ tmp = &session->cmd_buff[0]; skip_spaces(tmp); skip_word(tmp); skip_spaces(tmp); arg_hostname = tmp; skip_word(tmp); skip_spaces(tmp); arg_port = tmp; split_word(arg_hostname); split_word(arg_port); if (*arg_hostname == '\0') { fprintf(stderr, "Remote address is not specified.\n"); errno = EINVAL; return FTP_RET_ERROR; } if (*arg_port == '\0') { arg_port = NULL; } /* --- END OF Get args --- */ if (!inet_aton(arg_hostname, &remote_ip)) { fprintf(stderr, "Can't parse IP address.\n"); errno = EINVAL; return FTP_RET_ERROR; } if (arg_port == NULL) { remote_port = FTP_PORT; /* Use default settings */ } else { if (sscanf(arg_port, "%u", &remote_port) != 1) { fprintf(stderr, "Can't parse port '%s`.\n", arg_port); errno = EINVAL; return FTP_RET_ERROR; } } ret = make_active_socket(remote_ip.s_addr, (uint16_t)remote_port, &session->cmd_sock); if (ret != FTP_RET_OK) { return ret; } fprintf(stdout, "Connected to %s:%u.\n", arg_hostname, remote_port); session->is_connected = 1; ret = fs_rcv_reply(session, &session->buff[0], sizeof session->buff); if (ret != FTP_RET_OK) { return ret; } return FTP_RET_OK; }
int main() { g1 = 3; g2 = 4; n = 5; gen_g1(g1map, g1); gen_g2(g2map, g2); gen_big(smap, n); /*map<string, G1>::iterator it; for(it = g1map.begin(); it != g1map.end(); ++it) { cout<< it->first << endl; }*/ while(true) { string str; cin >> str; if(str == "bye") break; string mid_str = after_equal(str); string val = before_equal(str); string d = split_word(mid_str); queue<string> mid; queue<string> rpn; string word; istringstream istr(d); while(!istr.eof()) { istr >> word; mid.push(word); } rpn_convert(mid, rpn); double time = 0; if(val.substr(0,2) == "gt") { time = calcu_gt(rpn, g1map, g2map, smap, gtmap, val); } else if(val.substr(0,2) == "g1") { time = calcu_g1(rpn, g1map, smap, val); } else if(val.substr(0,2) == "g2") { time = calcu_g2(rpn, g2map, smap, val); } cout<< str + " " << time << endl; } /* string str = "g1_3 = g1_0 * g1_1"; string mid_str = after_equal(str); string val = before_equal(str); string d = split_word(mid_str); queue<string> mid; queue<string> rpn; string word; istringstream istr(d); while(!istr.eof()) { istr >> word; mid.push(word); } rpn_convert(mid, rpn); double time = 0; if(val.substr(0,2) == "gt") { time = calcu_gt(rpn, g1map, g2map, smap, gtmap, val); } else if(val.substr(0,2) == "g1") { time = calcu_g1(rpn, g1map, smap, val); } else if(val.substr(0,2) == "g2") { time = calcu_g2(rpn, g2map, smap, val); } cout<< str + " " << time << endl; */ return 0; }
/** * Try splitting off the given number of (chopped) blobs from the front and * back of the given word and recognizing the pieces. * * @param[in] num_chopped_leading how many chopped blobs from the left * end of the word to chop off and try recognizing as a * superscript (or subscript) * @param[in] leading_certainty the (minimum) certainty had by the * characters in the original leading section. * @param[in] leading_pos "super" or "sub" (for debugging) * @param[in] num_chopped_trailing how many chopped blobs from the right * end of the word to chop off and try recognizing as a * superscript (or subscript) * @param[in] trailing_certainty the (minimum) certainty had by the * characters in the original trailing section. * @param[in] trailing_pos "super" or "sub" (for debugging) * @param[in] word the word to try to chop up. * @param[out] is_good do we believe our result? * @param[out] retry_rebuild_leading, retry_rebuild_trailing * If non-zero, and !is_good, then the caller may have luck trying * to split the returned word with this number of (rebuilt) leading * and trailing blobs / unichars. * @return A word which is the result of re-recognizing as asked. */ WERD_RES *Tesseract::TrySuperscriptSplits( int num_chopped_leading, float leading_certainty, ScriptPos leading_pos, int num_chopped_trailing, float trailing_certainty, ScriptPos trailing_pos, WERD_RES *word, bool *is_good, int *retry_rebuild_leading, int *retry_rebuild_trailing) { int num_chopped = word->chopped_word->NumBlobs(); *retry_rebuild_leading = *retry_rebuild_trailing = 0; // Chop apart the word into up to three pieces. BlamerBundle *bb0 = NULL; BlamerBundle *bb1 = NULL; WERD_RES *prefix = NULL; WERD_RES *core = NULL; WERD_RES *suffix = NULL; if (num_chopped_leading > 0) { prefix = new WERD_RES(*word); split_word(prefix, num_chopped_leading, &core, &bb0); } else { core = new WERD_RES(*word); } if (num_chopped_trailing > 0) { int split_pt = num_chopped - num_chopped_trailing - num_chopped_leading; split_word(core, split_pt, &suffix, &bb1); } // Recognize the pieces in turn. int saved_cp_multiplier = classify_class_pruner_multiplier; int saved_im_multiplier = classify_integer_matcher_multiplier; if (prefix) { // Turn off Tesseract's y-position penalties for the leading superscript. classify_class_pruner_multiplier.set_value(0); classify_integer_matcher_multiplier.set_value(0); // Adjust our expectations about the baseline for this prefix. if (superscript_debug >= 3) { tprintf(" recognizing first %d chopped blobs\n", num_chopped_leading); } recog_word_recursive(prefix); if (superscript_debug >= 2) { tprintf(" The leading bits look like %s %s\n", ScriptPosToString(leading_pos), prefix->best_choice->unichar_string().string()); } // Restore the normal y-position penalties. classify_class_pruner_multiplier.set_value(saved_cp_multiplier); classify_integer_matcher_multiplier.set_value(saved_im_multiplier); } if (superscript_debug >= 3) { tprintf(" recognizing middle %d chopped blobs\n", num_chopped - num_chopped_leading - num_chopped_trailing); } if (suffix) { // Turn off Tesseract's y-position penalties for the trailing superscript. classify_class_pruner_multiplier.set_value(0); classify_integer_matcher_multiplier.set_value(0); if (superscript_debug >= 3) { tprintf(" recognizing last %d chopped blobs\n", num_chopped_trailing); } recog_word_recursive(suffix); if (superscript_debug >= 2) { tprintf(" The trailing bits look like %s %s\n", ScriptPosToString(trailing_pos), suffix->best_choice->unichar_string().string()); } // Restore the normal y-position penalties. classify_class_pruner_multiplier.set_value(saved_cp_multiplier); classify_integer_matcher_multiplier.set_value(saved_im_multiplier); } // Evaluate whether we think the results are believably better // than what we already had. bool good_prefix = !prefix || BelievableSuperscript( superscript_debug >= 1, *prefix, superscript_bettered_certainty * leading_certainty, retry_rebuild_leading, NULL); bool good_suffix = !suffix || BelievableSuperscript( superscript_debug >= 1, *suffix, superscript_bettered_certainty * trailing_certainty, NULL, retry_rebuild_trailing); *is_good = good_prefix && good_suffix; if (!*is_good && !*retry_rebuild_leading && !*retry_rebuild_trailing) { // None of it is any good. Quit now. delete core; delete prefix; delete suffix; return NULL; } recog_word_recursive(core); // Now paste the results together into core. if (suffix) { suffix->SetAllScriptPositions(trailing_pos); join_words(core, suffix, bb1); } if (prefix) { prefix->SetAllScriptPositions(leading_pos); join_words(prefix, core, bb0); core = prefix; prefix = NULL; } if (superscript_debug >= 1) { tprintf("%s superscript fix: %s\n", *is_good ? "ACCEPT" : "REJECT", core->best_choice->unichar_string().string()); } return core; }
/* * A generic complete routine for the mail command line. */ static unsigned char mail_complete(EditLine *el, int ch) { LineInfo *li; const LineInfo *lf; const char *cmplarray; int dolist; int cmpltype; char *word; lf = el_line(el); #ifdef EMACS_CTRL_D_BINDING_HACK { int cc_ret; if ((cc_ret = emacs_ctrl_d(el, lf, ch)) != -1) return cc_ret; } #endif /* EMACS_CTRL_D_BINDING_HACK */ if ((dolist = get_dolist(lf)) == -1) return CC_ERROR; if ((li = split_line(&cmplarray, lf)) == NULL) return CC_ERROR; if ((word = split_word(&cmpltype, cmplarray, li)) == NULL) return CC_ERROR; switch (cmpltype) { case 'a': /* alias complete */ case 'A': return complete_alias(el, word, dolist); case 'c': /* command complete */ case 'C': return complete_command(el, word, dolist); case 'f': /* filename complete */ case 'F': return complete_filename(el, word, dolist); case 'm': case 'M': return complete_smopts(el, word, dolist); case 'n': /* no complete */ case 'N': /* no complete */ return CC_ERROR; case 's': case 'S': return complete_set(el, word, dolist); #ifdef THREAD_SUPPORT case 't': case 'T': return complete_thread_key(el, word, dolist); #endif case 'x': /* executable complete */ case 'X': return complete_executable(el, word, dolist); default: warnx("unknown complete type `%c'", cmpltype); #if 0 assert(/*CONSTCOND*/0); #endif return CC_ERROR; } /* NOTREACHED */ }