file_transfer_ptr file_transfer_parser_impl::parse(std::string spec) const { std::string left, right; saga::adaptors::file_transfer_operator mode; if (!parse_file_transfer_specification(spec, left, mode, right)) { SAGA_OSSTREAM strm; strm << "Parse failed: " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); throw; } #if 0 if (!check_filename(left) || !check_filename(right)) { SAGA_OSSTREAM strm; strm << "Cannot handle the specified URL " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::IncorrectURL); } #endif file_transfer_ptr p; switch (mode) { case saga::adaptors::copy_local_remote: p = file_transfer_ptr(new file_transfer_impl(left, right, file_transfer::in)); break; case saga::adaptors::copy_remote_local: p = file_transfer_ptr(new file_transfer_impl(right, left, file_transfer::out)); break; case saga::adaptors::append_local_remote: case saga::adaptors::append_remote_local: { SAGA_OSSTREAM strm; strm << "Append operation is unsupported " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::NotImplemented); } break; case saga::adaptors::unknown_mode: default: { // from condor SAGA_OSSTREAM strm; strm << "Unknown FileTransfer operator " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } break; } return p; }
void on_cvs_add_response(GtkDialog* dialog, gint response, CVSData* data) { if (is_busy(data->plugin, dialog)) return; switch (response) { case GTK_RESPONSE_OK: { GtkWidget* binary = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_binary")); GtkWidget* fileentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_add_filename")); const gchar* filename = gtk_entry_get_text(GTK_ENTRY(fileentry)); if (!check_filename(dialog, filename)) break; anjuta_cvs_add(ANJUTA_PLUGIN(data->plugin), filename, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(binary)), NULL); gtk_widget_destroy(GTK_WIDGET(dialog)); cvs_data_free(data); break; } default: gtk_widget_destroy (GTK_WIDGET(dialog)); cvs_data_free(data); } }
/* * Verify a filename that we got as an argument for a pathspec * entry. Note that a filename that begins with "-" never verifies * as true, because even if such a filename were to exist, we want * it to be preceded by the "--" marker (or we want the user to * use a format like "./-filename") */ void verify_filename(const char *prefix, const char *arg) { if (*arg == '-') die("bad flag '%s' used after filename", arg); if (check_filename(prefix, arg)) return; die_verify_filename(prefix, arg); }
void on_cvs_commit_response(GtkDialog* dialog, gint response, CVSData* data) { if (is_busy(data->plugin, dialog)) return; switch (response) { case GTK_RESPONSE_OK: { gchar* log; const gchar* rev; GtkWidget* logtext; GtkWidget* revisionentry; GtkWidget* norecurse; GtkWidget* fileentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_commit_filename")); const gchar* filename = gtk_entry_get_text(GTK_ENTRY(fileentry)); logtext = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_commit_log")); log = get_log_from_textview(logtext); if (!g_utf8_strlen(log, -1)) { gint result; GtkWidget* dlg = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_YES_NO, _("Are you sure that you want to pass an empty log message?")); result = gtk_dialog_run(GTK_DIALOG(dlg)); if (result == GTK_RESPONSE_NO) { gtk_widget_hide(dlg); gtk_widget_destroy(dlg); break; } gtk_widget_destroy(dlg); } revisionentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_commit_revision")); rev = gtk_entry_get_text(GTK_ENTRY(revisionentry)); norecurse = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_commit_norecurse")); if (!check_filename(dialog, filename)) break; anjuta_cvs_commit(ANJUTA_PLUGIN(data->plugin), filename, log, rev, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(norecurse)), NULL); cvs_data_free(data); gtk_widget_destroy(GTK_WIDGET(dialog)); break; } default: gtk_widget_destroy (GTK_WIDGET(dialog)); cvs_data_free(data); break; } }
/* * Verify a filename that we got as an argument for a pathspec * entry. Note that a filename that begins with "-" never verifies * as true, because even if such a filename were to exist, we want * it to be preceded by the "--" marker (or we want the user to * use a format like "./-filename") */ void verify_filename(const char *prefix, const char *arg) { if (*arg == '-') die("bad flag '%s' used after filename", arg); if (check_filename(prefix, arg)) return; die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" "Use '--' to separate paths from revisions", arg); }
/* * Verify a filename that we got as an argument for a pathspec * entry. Note that a filename that begins with "-" never verifies * as true, because even if such a filename were to exist, we want * it to be preceded by the "--" marker (or we want the user to * use a format like "./-filename") * * The "diagnose_misspelt_rev" is used to provide a user-friendly * diagnosis when dying upon finding that "name" is not a pathname. * If set to 1, the diagnosis will try to diagnose "name" as an * invalid object name (e.g. HEAD:foo). If set to 0, the diagnosis * will only complain about an inexisting file. * * This function is typically called to check that a "file or rev" * argument is unambiguous. In this case, the caller will want * diagnose_misspelt_rev == 1 when verifying the first non-rev * argument (which could have been a revision), and * diagnose_misspelt_rev == 0 for the next ones (because we already * saw a filename, there's not ambiguity anymore). */ void verify_filename(const char *prefix, const char *arg, int diagnose_misspelt_rev) { if (*arg == '-') die("bad flag '%s' used after filename", arg); if (check_filename(prefix, arg)) return; die_verify_filename(prefix, arg, diagnose_misspelt_rev); }
void on_cvs_diff_response(GtkDialog* dialog, gint response, CVSData* data) { if (is_busy(data->plugin, dialog)) return; switch (response) { case GTK_RESPONSE_OK: { const gchar* rev; int diff_type_nr; gboolean unified = FALSE; gboolean patch_style = FALSE; GtkWidget* norecurse; GtkWidget* revisionentry; GtkWidget* diff_type; GtkWidget* unified_diff; GtkWidget* fileentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_diff_filename")); const gchar* filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(fileentry))); revisionentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_diff_revision")); rev = gtk_entry_get_text(GTK_ENTRY(revisionentry)); norecurse = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_diff_norecurse")); diff_type = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_diff_type")); unified_diff = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_unified")); diff_type_nr = gtk_combo_box_get_active(GTK_COMBO_BOX(diff_type)); if (diff_type_nr == DIFF_PATCH) { unified = TRUE; /* FIXME: rdiff do not take -u in my cvs */ /* diff = "rdiff"; */ } if (!check_filename(dialog, filename)) break; anjuta_cvs_diff(ANJUTA_PLUGIN(data->plugin), filename, rev, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(norecurse)), patch_style, unified, NULL); cvs_data_free(data); gtk_widget_destroy (GTK_WIDGET(dialog)); break; } default: cvs_data_free(data); gtk_widget_destroy (GTK_WIDGET(dialog)); break; } }
/* * Opposite of the above: the command line did not have -- marker * and we parsed the arg as a refname. It should not be interpretable * as a filename. */ void verify_non_filename(const char *prefix, const char *arg) { if (!is_inside_work_tree() || is_inside_git_dir()) return; if (*arg == '-') return; /* flag */ if (!check_filename(prefix, arg)) return; die("ambiguous argument '%s': both revision and filename\n" "Use '--' to separate filenames from revisions", arg); }
/* * Opposite of the above: the command line did not have -- marker * and we parsed the arg as a refname. It should not be interpretable * as a filename. */ void verify_non_filename(const char *prefix, const char *arg) { if (!is_inside_work_tree() || is_inside_git_dir()) return; if (*arg == '-') return; /* flag */ if (!check_filename(prefix, arg)) return; die("ambiguous argument '%s': both revision and filename\n" "Use '--' to separate paths from revisions, like this:\n" "'git <command> [<revision>...] -- [<file>...]'", arg); }
int savegame::show_save_dialog(CVideo& video, const std::string& message, bool ok_cancel) { int res = 0; std::string filename = filename_; if (ok_cancel){ gui2::tgame_save dlg(filename, title_); dlg.show(video); res = dlg.get_retval(); } else { gui2::tgame_save_message dlg(title_, filename, message); dlg.show(video); res = dlg.get_retval(); } check_filename(filename, video); set_filename(filename); check_filename(filename, video); set_filename(filename); return res; }
void on_cvs_update_response(GtkDialog* dialog, gint response, CVSData* data) { if (is_busy(data->plugin, dialog)) return; switch (response) { case GTK_RESPONSE_OK: { const gchar* revision; GtkWidget* createdir; GtkWidget* removedir; GtkWidget* norecurse; GtkWidget* removesticky; GtkWidget* revisionentry; GtkWidget* fileentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_update_filename")); const gchar* filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(fileentry))); norecurse = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_update_norecurse")); removedir = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_removedir")); createdir = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_createdir")); revisionentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_update_revision")); revision = gtk_entry_get_text(GTK_ENTRY(revisionentry)); removesticky = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_removesticky")); if (!check_filename(dialog, filename)) break; anjuta_cvs_update(ANJUTA_PLUGIN(data->plugin), filename, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(norecurse)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(removedir)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(createdir)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(removesticky)), revision, NULL); cvs_data_free(data); gtk_widget_destroy(GTK_WIDGET(dialog)); break; } default: gtk_widget_destroy(GTK_WIDGET(dialog)); cvs_data_free(data); break; } }
int oos_savegame::show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE /*dialog_type*/) { static bool ignore_all = false; int res = 0; std::string filename = this->filename(); if (!ignore_all){ gui2::tgame_save_oos dlg(ignore_all, filename, title(), message); dlg.show(video); res = dlg.get_retval(); } check_filename(filename, video); set_filename(filename); return res; }
/******************************************************************************* * Name: gen_validate_path * Purpose: validate full path * Input: * pszPath: path name * Output: * Return: * success: 0 * failed : -1 * Note: ******************************************************************************/ int gen_validate_path(char *pszPath) { char **ppNameArr = NULL; unsigned long nCnt = 0; int i = 0; int nRet = 0; if (NULL == pszPath) { return -1; } if (sal_strlen(pszPath) > M_FULLPATH_MAX_LEN) { return -1; } if (NULL != sal_strstr(pszPath, "//")) { return -1; } if (split_tokens(pszPath, sal_strlen(pszPath), M_FULLPATH_DEPTH_MAX, "/", &nCnt, &ppNameArr) != 0) { return -1; } for (i = 0; i < nCnt; i++) { if (NULL == ppNameArr[i]) { continue; } if (check_filename(ppNameArr[i]) != 0) { nRet = -1; break; } } free_tokens(&ppNameArr); return nRet; }
int savegame::show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type) { int res = 0; std::string filename = filename_; if (dialog_type == gui::OK_CANCEL){ gui2::tgame_save dlg(filename, title_); dlg.show(video); res = dlg.get_retval(); } else if (dialog_type == gui::YES_NO){ gui2::tgame_save_message dlg(filename, title_, message); dlg.show(video); res = dlg.get_retval(); } check_filename(filename, video); set_filename(filename); return res; }
void on_cvs_remove_response(GtkDialog* dialog, gint response, CVSData* data) { GFile* file; if (is_busy(data->plugin, dialog)) return; switch (response) { case GTK_RESPONSE_OK: { GtkWidget* fileentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_remove_filename")); const gchar* filename = gtk_entry_get_text(GTK_ENTRY(fileentry)); if (!check_filename(dialog, filename)) break; file = g_file_new_for_uri(gtk_entry_get_text(GTK_ENTRY(fileentry))); if (!g_file_delete(file, NULL, NULL)) { anjuta_util_dialog_error (GTK_WINDOW(dialog),_("Unable to delete file"), NULL); gtk_widget_destroy(GTK_WIDGET(dialog)); cvs_data_free(data); break; } g_object_unref(G_OBJECT(file)); anjuta_cvs_remove(ANJUTA_PLUGIN(data->plugin), filename, NULL); gtk_widget_destroy (GTK_WIDGET(dialog)); cvs_data_free(data); break; } default: cvs_data_free(data); gtk_widget_destroy (GTK_WIDGET(dialog)); } }
bool ChecksumCounter::Process(const std::string& filename) { if (!check_filename(filename)) { return false; } std::fstream in_stream(filename, std::ios_base::binary | std::ios_base::in); if (!in_stream) { std::cout << "Error occurred while opening file: " << filename << std::endl; return false; } CounterType counter = 0, buffer; while(true) { // fill buffer with 0 if file_size % 4 != 0 buffer = 0x0; in_stream.read((char*)&buffer, sizeof(buffer)); if (in_stream.eof()) { if (in_stream.gcount() != 0) { counter += buffer; } break; } counter += buffer; if (!in_stream.good()) { std::cout << "Error occurred while reading from file: " << filename << std::endl; return false; } } _counter += buffer; return true; }
static int handle_parsed_line(const PARSE_ENTRY_DATA_T *parseData, META_FILE_T *pMetaFile, const char *path, int *pmatch) { int rc = 0; int matchDev = 0; int matchProf = 0; int match = 0; char buf[128]; // // Check if we the key 'profile=' on this line item, and if so, attempt to match the // input profilefilterstr to the listed profile // if((parseData->flags & PARSE_FLAG_HAVE_PROFILE) && parseData->profile[0] != '\0') { if(strncasecmp(parseData->profile, pMetaFile->profilefilterstr, MAX( strlen(pMetaFile->profilefilterstr), strlen(parseData->profile)))) { matchProf = -1; } else { matchProf = 1; } } // // Check if we the key 'device=' on this line item, and if so, attempt to match the // input devicefilterstr to the listed profile // if((parseData->flags & PARSE_FLAG_HAVE_DEVNAME) && parseData->devname[0] != '\0') { if(strncasecmp(parseData->devname, pMetaFile->devicefilterstr, MAX( strlen(pMetaFile->devicefilterstr), strlen(parseData->devname)))) { matchDev = -1; match = 0; } else { matchDev = 1; } } // // If the device matched and the profile is matched or missing // If the profile matched and the device is matched or missing // Or if there was no attempt to match anything and there are no specified device/profile filters, and the // line item is not a device/profile specific item // if((matchDev == 1 && matchProf != -1) || (matchProf == 1 && matchDev != -1) || (matchDev != -1 && matchProf != -1 && pMetaFile->devicefilterstr[0] == '\0' && pMetaFile->profilefilterstr[0] == '\0' && parseData->devname[0] == '\0' && parseData->profile[0] == '\0')) { match = 1; } VSX_DEBUG_METAFILE( LOG(X_DEBUG("META - handle_parsed_line flags:0x%x, file:'%s', devname:'%s', profile:'%s', methods:'%s', " "xcode: '%s', digestauth: '%s', token: '%s', matchProf: %d, matchDev: %d, match: %d, pmatch: 0x%x, " "meta-devicefilter:'%s', meta-profilefilter: '%s'"), parseData->flags, parseData->filename, parseData->devname, parseData->profile, devtype_dump_methods(parseData->methodBits, buf, sizeof(buf)), parseData->xcodestr, parseData->userpass, parseData->tokenId, matchProf, matchDev, match, *pmatch, pMetaFile->devicefilterstr, pMetaFile->profilefilterstr)); if((parseData->flags & PARSE_FLAG_HAVE_FILENAME) && ((matchDev == 1 && (matchProf == 1 || parseData->profile[0] == '\0')) || !(*pmatch & MATCH_HAVE_FILENAME))) { VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line mite set file '%s'..."), parseData->filename)); if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { check_filename(parseData->filename, path, pMetaFile); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set filename: '%s', path: '%s', *pmatch: 0x%x"), parseData->filename, path, *pmatch)); if(match && (matchProf == 1 || matchDev == 1)) { *pmatch |= MATCH_HAVE_FILENAME; VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_HAVE_FILENAME"))); } } } if((parseData->flags & PARSE_FLAG_HAVE_RTMP_PROXY) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->rtmpproxy, parseData->rtmpproxy, sizeof(pMetaFile->rtmpproxy)); } } if((parseData->flags & PARSE_FLAG_HAVE_RTSP_PROXY) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->rtspproxy, parseData->rtspproxy, sizeof(pMetaFile->rtspproxy)); } } if((parseData->flags & PARSE_FLAG_HAVE_HTTP_PROXY) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->httpproxy, parseData->httpproxy, sizeof(pMetaFile->httpproxy)); } } if((parseData->flags & PARSE_FLAG_HAVE_HTTPLINK) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->linkstr, parseData->link, sizeof(pMetaFile->linkstr)); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set link: '%s', *pmatch: 0x%x"), parseData->link, *pmatch)); } } if((parseData->flags & PARSE_FLAG_HAVE_ID) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->id, parseData->id, sizeof(pMetaFile->id)); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set id: '%s', *pmatch: 0x%x"), parseData->id, *pmatch)); } } if((parseData->flags & PARSE_FLAG_HAVE_SHARED) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { pMetaFile->shared = parseData->shared; } } if((parseData->flags & PARSE_FLAG_HAVE_SECURE) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { pMetaFile->secure = parseData->secure; } } if((parseData->flags & PARSE_FLAG_HAVE_INPUT) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->instr, parseData->input, sizeof(pMetaFile->instr)); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set input: '%s', *pmatch: 0x%x"), parseData->input, *pmatch)); } } if((parseData->flags & PARSE_FLAG_HAVE_METHODS) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_METHODS))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { pMetaFile->methodBits = parseData->methodBits; VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set methods: '%s', *pmatch: 0x%x"), devtype_dump_methods(pMetaFile->methodBits, buf, sizeof(buf)), *pmatch)); if(match) { *pmatch |= MATCH_HAVE_METHODS; VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_HAVE_METHODS"))); } } } if((parseData->flags & PARSE_FLAG_HAVE_DIGESTAUTH) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_DIGESTAUTH))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->userpass, parseData->userpass, sizeof(pMetaFile->userpass)); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set digestauth: '%s', *pmatch: 0x%x"), pMetaFile->userpass, *pmatch)); if(match) { *pmatch |= MATCH_HAVE_DIGESTAUTH; VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_HAVE_DIGESTAUTH"))); } } } if((parseData->flags & PARSE_FLAG_HAVE_TOKEN) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_TOKEN))) { if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->tokenId, parseData->tokenId, sizeof(pMetaFile->tokenId)); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set digestauth: '%s', *pmatch: 0x%x"), pMetaFile->tokenId, *pmatch)); if(match) { *pmatch |= MATCH_HAVE_TOKEN; VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_HAVE_TOKEN"))); } } } if((parseData->flags & PARSE_FLAG_HAVE_XCODEARGS) && ((matchDev == 1 && matchProf == 1) || !(*pmatch & MATCH_HAVE_XCODE))) { VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line mite set xcode: '%s', id: '%s', *pmatch: 0x%x"), parseData->xcodestr, parseData->id, *pmatch)); if(match || (matchDev >= 0 && matchProf >= 0 && !((*pmatch & MATCH_BY_PROFILE) || (*pmatch & MATCH_BY_DEVICE)))) { strncpy(pMetaFile->xcodestr, parseData->xcodestr, sizeof(pMetaFile->xcodestr)); strncpy(pMetaFile->id, parseData->id, sizeof(pMetaFile->id)); VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set xcode: '%s', id: '%s', *pmatch: 0x%x"), parseData->xcodestr, parseData->id, *pmatch)); if(match) { *pmatch |= MATCH_HAVE_XCODE; VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_HAVE_XCODE"))); } } } // // exact match for specified profile and device name // if((matchProf == 1 && matchDev == 1) || ((matchDev >= 0 && matchProf >= 0) && ((matchProf == 1 && matchDev >= 0) || (matchDev == 1 && matchDev >= 0)))) { if(matchDev == 1) { VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_BY_DEVICE"))); *pmatch |= MATCH_BY_DEVICE; } if(matchProf == 1) { VSX_DEBUG_METAFILE(LOG(X_DEBUG("META - handle_parsed_line set MATCH_BY_PROFILE"))); *pmatch |= MATCH_BY_PROFILE; } } return rc; }
int main(int argc, char *argv[]) { const struct flashchip *chip = NULL; /* Probe for up to eight flash chips. */ struct flashctx flashes[8] = {{0}}; struct flashctx *fill_flash; const char *name; int namelen, opt, i, j; int startchip = -1, chipcount = 0, option_index = 0, force = 0, ifd = 0, fmap = 0; #if CONFIG_PRINT_WIKI == 1 int list_supported_wiki = 0; #endif int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0; int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0; struct flashrom_layout *layout = NULL; enum programmer prog = PROGRAMMER_INVALID; enum { OPTION_IFD = 0x0100, OPTION_FMAP, OPTION_FMAP_FILE, OPTION_FLASH_CONTENTS, }; int ret = 0; static const char optstring[] = "r:Rw:v:nNVEfc:l:i:p:Lzho:"; static const struct option long_options[] = { {"read", 1, NULL, 'r'}, {"write", 1, NULL, 'w'}, {"erase", 0, NULL, 'E'}, {"verify", 1, NULL, 'v'}, {"noverify", 0, NULL, 'n'}, {"noverify-all", 0, NULL, 'N'}, {"chip", 1, NULL, 'c'}, {"verbose", 0, NULL, 'V'}, {"force", 0, NULL, 'f'}, {"layout", 1, NULL, 'l'}, {"ifd", 0, NULL, OPTION_IFD}, {"fmap", 0, NULL, OPTION_FMAP}, {"fmap-file", 1, NULL, OPTION_FMAP_FILE}, {"image", 1, NULL, 'i'}, {"flash-contents", 1, NULL, OPTION_FLASH_CONTENTS}, {"list-supported", 0, NULL, 'L'}, {"list-supported-wiki", 0, NULL, 'z'}, {"programmer", 1, NULL, 'p'}, {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'R'}, {"output", 1, NULL, 'o'}, {NULL, 0, NULL, 0}, }; char *filename = NULL; char *referencefile = NULL; char *layoutfile = NULL; char *fmapfile = NULL; #ifndef STANDALONE char *logfile = NULL; #endif /* !STANDALONE */ char *tempstr = NULL; char *pparam = NULL; flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb); print_version(); print_banner(); if (selfcheck()) exit(1); setbuf(stdout, NULL); /* FIXME: Delay all operation_specified checks until after command * line parsing to allow --help overriding everything else. */ while ((opt = getopt_long(argc, argv, optstring, long_options, &option_index)) != EOF) { switch (opt) { case 'r': if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } filename = strdup(optarg); read_it = 1; break; case 'w': if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } filename = strdup(optarg); write_it = 1; break; case 'v': //FIXME: gracefully handle superfluous -v if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } if (dont_verify_it) { fprintf(stderr, "--verify and --noverify are mutually exclusive. Aborting.\n"); cli_classic_abort_usage(); } filename = strdup(optarg); verify_it = 1; break; case 'n': if (verify_it) { fprintf(stderr, "--verify and --noverify are mutually exclusive. Aborting.\n"); cli_classic_abort_usage(); } dont_verify_it = 1; break; case 'N': dont_verify_all = 1; break; case 'c': chip_to_probe = strdup(optarg); break; case 'V': verbose_screen++; if (verbose_screen > FLASHROM_MSG_DEBUG2) verbose_logfile = verbose_screen; break; case 'E': if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } erase_it = 1; break; case 'f': force = 1; break; case 'l': if (layoutfile) { fprintf(stderr, "Error: --layout specified " "more than once. Aborting.\n"); cli_classic_abort_usage(); } if (ifd) { fprintf(stderr, "Error: --layout and --ifd both specified. Aborting.\n"); cli_classic_abort_usage(); } if (fmap) { fprintf(stderr, "Error: --layout and --fmap-file both specified. Aborting.\n"); cli_classic_abort_usage(); } layoutfile = strdup(optarg); break; case OPTION_IFD: if (layoutfile) { fprintf(stderr, "Error: --layout and --ifd both specified. Aborting.\n"); cli_classic_abort_usage(); } if (fmap) { fprintf(stderr, "Error: --fmap-file and --ifd both specified. Aborting.\n"); cli_classic_abort_usage(); } ifd = 1; break; case OPTION_FMAP_FILE: if (fmap) { fprintf(stderr, "Error: --fmap or --fmap-file specified " "more than once. Aborting.\n"); cli_classic_abort_usage(); } if (ifd) { fprintf(stderr, "Error: --fmap-file and --ifd both specified. Aborting.\n"); cli_classic_abort_usage(); } if (layoutfile) { fprintf(stderr, "Error: --fmap-file and --layout both specified. Aborting.\n"); cli_classic_abort_usage(); } fmapfile = strdup(optarg); fmap = 1; break; case OPTION_FMAP: if (fmap) { fprintf(stderr, "Error: --fmap or --fmap-file specified " "more than once. Aborting.\n"); cli_classic_abort_usage(); } if (ifd) { fprintf(stderr, "Error: --fmap and --ifd both specified. Aborting.\n"); cli_classic_abort_usage(); } if (layoutfile) { fprintf(stderr, "Error: --layout and --fmap both specified. Aborting.\n"); cli_classic_abort_usage(); } fmap = 1; break; case 'i': tempstr = strdup(optarg); if (register_include_arg(tempstr)) { free(tempstr); cli_classic_abort_usage(); } break; case OPTION_FLASH_CONTENTS: referencefile = strdup(optarg); break; case 'L': if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } list_supported = 1; break; case 'z': #if CONFIG_PRINT_WIKI == 1 if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } list_supported_wiki = 1; #else fprintf(stderr, "Error: Wiki output was not compiled " "in. Aborting.\n"); cli_classic_abort_usage(); #endif break; case 'p': if (prog != PROGRAMMER_INVALID) { fprintf(stderr, "Error: --programmer specified " "more than once. You can separate " "multiple\nparameters for a programmer " "with \",\". Please see the man page " "for details.\n"); cli_classic_abort_usage(); } for (prog = 0; prog < PROGRAMMER_INVALID; prog++) { name = programmer_table[prog].name; namelen = strlen(name); if (strncmp(optarg, name, namelen) == 0) { switch (optarg[namelen]) { case ':': pparam = strdup(optarg + namelen + 1); if (!strlen(pparam)) { free(pparam); pparam = NULL; } break; case '\0': break; default: /* The continue refers to the * for loop. It is here to be * able to differentiate between * foo and foobar. */ continue; } break; } } if (prog == PROGRAMMER_INVALID) { fprintf(stderr, "Error: Unknown programmer \"%s\". Valid choices are:\n", optarg); list_programmers_linebreak(0, 80, 0); msg_ginfo(".\n"); cli_classic_abort_usage(); } break; case 'R': /* print_version() is always called during startup. */ if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } exit(0); break; case 'h': if (++operation_specified > 1) { fprintf(stderr, "More than one operation " "specified. Aborting.\n"); cli_classic_abort_usage(); } cli_classic_usage(argv[0]); exit(0); break; case 'o': #ifdef STANDALONE fprintf(stderr, "Log file not supported in standalone mode. Aborting.\n"); cli_classic_abort_usage(); #else /* STANDALONE */ logfile = strdup(optarg); if (logfile[0] == '\0') { fprintf(stderr, "No log filename specified.\n"); cli_classic_abort_usage(); } #endif /* STANDALONE */ break; default: cli_classic_abort_usage(); break; } } if (optind < argc) { fprintf(stderr, "Error: Extra parameter found.\n"); cli_classic_abort_usage(); } if ((read_it | write_it | verify_it) && check_filename(filename, "image")) { cli_classic_abort_usage(); } if (layoutfile && check_filename(layoutfile, "layout")) { cli_classic_abort_usage(); } if (fmapfile && check_filename(fmapfile, "fmap")) { cli_classic_abort_usage(); } if (referencefile && check_filename(referencefile, "reference")) { cli_classic_abort_usage(); } #ifndef STANDALONE if (logfile && check_filename(logfile, "log")) cli_classic_abort_usage(); if (logfile && open_logfile(logfile)) cli_classic_abort_usage(); #endif /* !STANDALONE */ #if CONFIG_PRINT_WIKI == 1 if (list_supported_wiki) { print_supported_wiki(); goto out; } #endif if (list_supported) { if (print_supported()) ret = 1; goto out; } #ifndef STANDALONE start_logging(); #endif /* !STANDALONE */ print_buildinfo(); msg_gdbg("Command line (%i args):", argc - 1); for (i = 0; i < argc; i++) { msg_gdbg(" %s", argv[i]); } msg_gdbg("\n"); if (layoutfile && read_romlayout(layoutfile)) { ret = 1; goto out; } if (!ifd && !fmap && process_include_args(get_global_layout())) { ret = 1; goto out; } /* Does a chip with the requested name exist in the flashchips array? */ if (chip_to_probe) { for (chip = flashchips; chip && chip->name; chip++) if (!strcmp(chip->name, chip_to_probe)) break; if (!chip || !chip->name) { msg_cerr("Error: Unknown chip '%s' specified.\n", chip_to_probe); msg_gerr("Run flashrom -L to view the hardware supported in this flashrom version.\n"); ret = 1; goto out; } /* Keep chip around for later usage in case a forced read is requested. */ } if (prog == PROGRAMMER_INVALID) { if (CONFIG_DEFAULT_PROGRAMMER != PROGRAMMER_INVALID) { prog = CONFIG_DEFAULT_PROGRAMMER; /* We need to strdup here because we free(pparam) unconditionally later. */ pparam = strdup(CONFIG_DEFAULT_PROGRAMMER_ARGS); msg_pinfo("Using default programmer \"%s\" with arguments \"%s\".\n", programmer_table[CONFIG_DEFAULT_PROGRAMMER].name, pparam); } else { msg_perr("Please select a programmer with the --programmer parameter.\n" "Previously this was not necessary because there was a default set.\n" #if CONFIG_INTERNAL == 1 "To choose the mainboard of this computer use 'internal'. " #endif "Valid choices are:\n"); list_programmers_linebreak(0, 80, 0); msg_ginfo(".\n"); ret = 1; goto out; } } /* FIXME: Delay calibration should happen in programmer code. */ myusec_calibrate_delay(); if (programmer_init(prog, pparam)) { msg_perr("Error: Programmer initialization failed.\n"); ret = 1; goto out_shutdown; } tempstr = flashbuses_to_text(get_buses_supported()); msg_pdbg("The following protocols are supported: %s.\n", tempstr); free(tempstr); for (j = 0; j < registered_master_count; j++) { startchip = 0; while (chipcount < ARRAY_SIZE(flashes)) { startchip = probe_flash(®istered_masters[j], startchip, &flashes[chipcount], 0); if (startchip == -1) break; chipcount++; startchip++; } } if (chipcount > 1) { msg_cinfo("Multiple flash chip definitions match the detected chip(s): \"%s\"", flashes[0].chip->name); for (i = 1; i < chipcount; i++) msg_cinfo(", \"%s\"", flashes[i].chip->name); msg_cinfo("\nPlease specify which chip definition to use with the -c <chipname> option.\n"); ret = 1; goto out_shutdown; } else if (!chipcount) { msg_cinfo("No EEPROM/flash device found.\n"); if (!force || !chip_to_probe) { msg_cinfo("Note: flashrom can never write if the flash chip isn't found " "automatically.\n"); } if (force && read_it && chip_to_probe) { struct registered_master *mst; int compatible_masters = 0; msg_cinfo("Force read (-f -r -c) requested, pretending the chip is there:\n"); /* This loop just counts compatible controllers. */ for (j = 0; j < registered_master_count; j++) { mst = ®istered_masters[j]; /* chip is still set from the chip_to_probe earlier in this function. */ if (mst->buses_supported & chip->bustype) compatible_masters++; } if (!compatible_masters) { msg_cinfo("No compatible controller found for the requested flash chip.\n"); ret = 1; goto out_shutdown; } if (compatible_masters > 1) msg_cinfo("More than one compatible controller found for the requested flash " "chip, using the first one.\n"); for (j = 0; j < registered_master_count; j++) { mst = ®istered_masters[j]; startchip = probe_flash(mst, 0, &flashes[0], 1); if (startchip != -1) break; } if (startchip == -1) { // FIXME: This should never happen! Ask for a bug report? msg_cinfo("Probing for flash chip '%s' failed.\n", chip_to_probe); ret = 1; goto out_shutdown; } if (map_flash(&flashes[0]) != 0) { free(flashes[0].chip); ret = 1; goto out_shutdown; } msg_cinfo("Please note that forced reads most likely contain garbage.\n"); ret = read_flash_to_file(&flashes[0], filename); unmap_flash(&flashes[0]); free(flashes[0].chip); goto out_shutdown; } ret = 1; goto out_shutdown; } else if (!chip_to_probe) { /* repeat for convenience when looking at foreign logs */ tempstr = flashbuses_to_text(flashes[0].chip->bustype); msg_gdbg("Found %s flash chip \"%s\" (%d kB, %s).\n", flashes[0].chip->vendor, flashes[0].chip->name, flashes[0].chip->total_size, tempstr); free(tempstr); } fill_flash = &flashes[0]; print_chip_support_status(fill_flash->chip); unsigned int limitexceeded = count_max_decode_exceedings(fill_flash); if (limitexceeded > 0 && !force) { enum chipbustype commonbuses = fill_flash->mst->buses_supported & fill_flash->chip->bustype; /* Sometimes chip and programmer have more than one bus in common, * and the limit is not exceeded on all buses. Tell the user. */ if ((bitcount(commonbuses) > limitexceeded)) { msg_pdbg("There is at least one interface available which could support the size of\n" "the selected flash chip.\n"); } msg_cerr("This flash chip is too big for this programmer (--verbose/-V gives details).\n" "Use --force/-f to override at your own risk.\n"); ret = 1; goto out_shutdown; } if (!(read_it | write_it | verify_it | erase_it)) { msg_ginfo("No operations were specified.\n"); goto out_shutdown; } if (layoutfile) { layout = get_global_layout(); } else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) || process_include_args(layout))) { ret = 1; goto out_shutdown; } else if (fmap && fmapfile) { struct stat s; if (stat(fmapfile, &s) != 0) { msg_gerr("Failed to stat fmapfile \"%s\"\n", fmapfile); ret = 1; goto out_shutdown; } size_t fmapfile_size = s.st_size; uint8_t *fmapfile_buffer = malloc(fmapfile_size); if (!fmapfile_buffer) { ret = 1; goto out_shutdown; } if (read_buf_from_file(fmapfile_buffer, fmapfile_size, fmapfile)) { ret = 1; free(fmapfile_buffer); goto out_shutdown; } if (flashrom_layout_read_fmap_from_buffer(&layout, fill_flash, fmapfile_buffer, fmapfile_size) || process_include_args(layout)) { ret = 1; free(fmapfile_buffer); goto out_shutdown; } free(fmapfile_buffer); } else if (fmap && (flashrom_layout_read_fmap_from_rom(&layout, fill_flash, 0, fill_flash->chip->total_size * 1024) || process_include_args(layout))) { ret = 1; goto out_shutdown; } flashrom_layout_set(fill_flash, layout); flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE, !!force); #if CONFIG_INTERNAL == 1 flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE_BOARDMISMATCH, !!force_boardmismatch); #endif flashrom_flag_set(fill_flash, FLASHROM_FLAG_VERIFY_AFTER_WRITE, !dont_verify_it); flashrom_flag_set(fill_flash, FLASHROM_FLAG_VERIFY_WHOLE_CHIP, !dont_verify_all); /* FIXME: We should issue an unconditional chip reset here. This can be * done once we have a .reset function in struct flashchip. * Give the chip time to settle. */ programmer_delay(100000); if (read_it) ret = do_read(fill_flash, filename); else if (erase_it) ret = do_erase(fill_flash); else if (write_it) ret = do_write(fill_flash, filename, referencefile); else if (verify_it) ret = do_verify(fill_flash, filename); flashrom_layout_release(layout); out_shutdown: programmer_shutdown(); out: for (i = 0; i < chipcount; i++) free(flashes[i].chip); layout_cleanup(); free(filename); free(fmapfile); free(referencefile); free(layoutfile); free(pparam); /* clean up global variables */ free((char *)chip_to_probe); /* Silence! Freeing is not modifying contents. */ chip_to_probe = NULL; #ifndef STANDALONE free(logfile); ret |= close_logfile(); #endif /* !STANDALONE */ return ret; }
int OnionServer::updateSetting(onion_request *req, onion_response *res){ int actionid = atoi( onion_request_get_queryd(req,"actionid","0") ); printf("Actionid: %i \n", actionid); switch(actionid){ case 8:{ //quit programm m_psettingKinectGrid->setMode(QUIT); } break; case 7:{ //load masks m_psettingKinectGrid->setMode(LOAD_MASKS); } break; case 6:{ //save masks m_psettingKinectGrid->setMode(SAVE_MASKS); } break; case 5:{ //select view //m_view = atoi( onion_request_get_queryd(req,"view","-1") ); m_view = atoi( onion_request_get_post(req,"view") ); printf("Set view to %i.\n",m_view); } break; case 4:{ //repoke printf("Repoke\n"); m_psettingKinectGrid->setMode(REPOKE_DETECTION); } break; case 3:{ // area detection int start = atoi( onion_request_get_queryd(req,"start","1") ); if( start == 1) m_psettingKinectGrid->setMode(AREA_DETECTION_START); else{ m_psettingKinectGrid->setMode(AREA_DETECTION_END); } } break; case 2:{ const char* filename = onion_request_get_post(req,"filename"); printf("Save new settingKinectGrid: %s\n",filename); if( check_filename(filename ) == 1){ m_psettingKinect->saveConfigFile(filename); m_psettingKinectGrid->setString("lastSetting",filename); m_psettingKinectGrid->saveConfigFile("settingKinectGrid.ini"); }else{ printf("Filename not allowed\n"); } /* force reload of website */ return 0; } break; case 1:{ const char* filename = onion_request_get_post(req,"filename"); printf("Load new settingKinectGrid: %s\n",filename); if( check_filename(filename ) == 1){ m_psettingKinect->loadConfigFile(filename); }else{ printf("Filename not allowed\n"); } return -1; } break; case 0: default:{ printf("update settingKinect values\n"); const char* json_str = onion_request_get_post(req,"settingKinect"); if( json_str != NULL){ //printf("Get new settingKinect: %s\n",json_str); m_psettingKinect->setConfig(json_str, NO); }else{ return -1; } } break; } return 0; }
void execution(int argc,char* argv[]) { int in=0 ,io=0 ,copy_flag=0 , flag_fname=0; char f[6]; in_len=argc; flag_h=0; flag_d=0; d_value=0; flag_f=0; for(in=0; in< in_len ;in++) { strcpy(input_arra[in],argv[in]); } // printf("val of srgasdc is %d \n",in_len); flag_f=check_f(in_len); flag_h=check_h(in_len); flag_d=check_d(in_len); // printf("h is %d\n",flag_h); if(flag_h == 1) { printf("help karo\n"); return ; } if(in_len < 2) { printf("\n usage ./a.out inputfile<test.cap>\n"); return ; } if(flag_d == 0) { strcpy(inputfile,argv[in_len-1]); } else { d_value=atoi(argv[in_len-1]); //printf("d_value is %d \n\n",d_value); strcpy(inputfile,argv[in_len-3]); } //check filename exists or not //printf("filename is %s",inputfile); flag_fname=check_filename(); if(flag_fname == 1 ) { printf("\n input file name is wrong\n"); return; } for(in=0;in<30;in++) strcpy(runtimecmd[in]," "); cmd_flag=0; int len=0; //printf("number is %d \n\n",in_len); if(flag_d==1) len=in_len-3; else len=in_len-1; if(flag_f != 0) { cmd_flag=1; // printf("cmd is jgjnade %d us %d jhkj \n",flag_f,in_len); io=0; for(in=flag_f;in<len;in++) { //printf("insied "); strcpy(runtimecmd[io],input_arra[in]); io++; } // for(in=0;in<in_len;in++) // printf("runtime is %s ",runtimecmd[in]); }// printf("\n"); int ret, check_ret=0; check_ret=get_data(); //return 1; if(check_ret==1) return; int checkt =-1, checkf=0; int checkfst=0; //number of words in input int inputsize=in_len; strcpy(user_input,input_arra[1]); printdata(); while(1) { //printf("inside while"); checkt=-1; checkf=0; //checkf=check_f(inputsize); if(checkfst==1) { strcpy(user_input,""); //checkfst=1; printf(" \n enter the new commnad \n "); //scanf(" %s ",input_value); int j=0,m=0; for(m=0;m<100;m++) { for(j=0;j<100;j++) input_arra[m][j]='\0'; } char c; for (m=0;m<100;) { for(j=0;j<100;j++) { scanf("%c",&c); if(c==' ') { m++; break; } if(c=='\n') break; input_arra[m][j]=c; } if(c=='\n')break; } inputsize=m; //for( j=0;j<=m;j++) // printf("in put is %s \n",input_arra[j]); strcpy(user_input,input_arra[0]); } checkt=check_t(inputsize); if(!strcmp(user_input,"exit")) break; else if(!strcmp(user_input,"help")) { printf("\n am in help \n"); } else if(checkt !=-1 && checkfst == 1) { // printf("t is present at pos %ddsf and in put size is %d \n",checkt , inputsize); testcase(checkt,inputsize); } else { if(checkfst==1) { printf("wrong command entered \n"); } } checkfst=1; } }
int main(int argc, char **argv) { /* System variables */ int option; /* Command line option character */ int output_device; /* Descriptor of output device */ FILE *input_file; /* Input file stream */ unsigned char cmp_name[NAME_LEN]; /* File name to look for */ unsigned char chk_name[NAME_LEN+1]; /* File from input file to check */ int data_length; /* length of input file in bytes without header */ int num_blocks; /* size of input file in blocks */ int physical_flag; /* Option to use a physical device */ int lax; /* option to relax file name checking */ struct blocktype { int startblock; int filelength; } *blocklist, tempentry; /* list of blocks */ int dir_entry_count; /* number of directory enries (including deleted) */ int blocklist_count; /* number of entries in block list */ int last_data_block; /* last data block in medium */ int free_space; /* size of contiguous free blocks */ int extend_dir; /* flag if end of dir marker has to be moved */ int fbytes; /* file length of current directory entry */ int fblocks; /* file length in blocks of current directory entry */ int fstart; /* start block of file of current directory entry */ int i,j,n,t; /* LIF disk values */ unsigned int dir_start; /* first block of the directory */ unsigned int dir_length; /* length of directory in blocks */ unsigned int medium_size; /* number of data blocks of medium */ unsigned int tracks, surfaces, blocks; /* Directory search values */ unsigned int dir_end; /* Set at end of directory */ unsigned int found_file; /* Set when file found */ unsigned int dir_entry; /* Directory entry within current block */ unsigned int dir_block; /* Current block offset from start of directory */ unsigned int file_type; /* file type word */ unsigned char dir_data[SECTOR_SIZE]; /* Current directory block data */ /* new file entry values */ int free_dir_entry; /* number of the new directory entry */ int file_start; /* Start block number of the new file */ unsigned char new_dir_entry[ENTRY_SIZE]; /* Directory Entry of new file */ char typestring[10]; /* Process command line options */ physical_flag=0; lax=0; optind=1; while ((option=getopt(argc,argv,"pl?"))!=-1) { switch(option) { case 'p' : physical_flag=1; break; case 'l' : lax=1; break; case '?' : usage(); break; } } /* Are the right number of names specified ? */ if( (optind != argc-1) && (optind != argc-2) ) { /* No, give an error */ usage(); } /* Open output device */ if((output_device=lif_open(argv[optind],O_RDWR| O_BINARY,0,physical_flag))==-1) { fprintf(stderr,"Error opening %s\n",argv[optind]); exit(1); } /* Now read block 0 to find where the directory is */ lif_read_block(output_device,0,dir_data); /* Make sure it's a LIF disk */ if(get_lif_int(dir_data+0,2)!=0x8000) { fprintf(stderr,"This is not a LIF disk!\n"); exit(1); } /* Find the directory */ dir_start=get_lif_int(dir_data+8,4); dir_length=get_lif_int(dir_data+16,4); /* get medium information */ tracks=get_lif_int(dir_data+24,4); surfaces=get_lif_int(dir_data+28,4); blocks=get_lif_int(dir_data+32,4); medium_size= tracks*surfaces*blocks; if((tracks == surfaces) && (surfaces == blocks)) { fprintf(stderr,"Medium was not initialized properly\n"); exit(1); } debug_print("%s\n","medium Information"); debug_print("medium size %d\n",medium_size); debug_print("dir_start %d dir_length %d\n\n",dir_start,dir_length); /* open input file, if none specified use standard input */ if ( optind == argc -2) { input_file= fopen(argv[optind+1],"rb"); if (input_file == (FILE *) NULL ) { fprintf(stderr,"can't open File %s\n",argv[optind+1]); exit(2); } } else { SETMODE_STDIN_BINARY; input_file= stdin; } /* read lif entry from input file header */ fread(new_dir_entry,sizeof(unsigned char),ENTRY_SIZE,input_file); data_length= file_length(new_dir_entry,typestring); num_blocks= filelength_in_blocks(data_length); file_type= get_lif_int(&new_dir_entry[10],2); /* check file type */ if(typestring[0]== '?') { fprintf(stderr,"illegal file type\n"); exit(2); } /* set address to zero */ new_dir_entry[12]=0; new_dir_entry[13]=0; new_dir_entry[14]=0; new_dir_entry[15]=0; /* get file name */ for (i=0; i<NAME_LEN; i++) cmp_name[i]= new_dir_entry[i]; /* check the file name */ for (i=0; i<NAME_LEN; i++) if (new_dir_entry[i]==' ') chk_name[i]= '\0'; else chk_name[i]= new_dir_entry[i]; chk_name[NAME_LEN]='\0'; debug_print("File name to check: %s\n",chk_name); if (check_filename(chk_name,lax)==0) { fprintf(stderr,"illegal file name\n"); exit(2); } debug_print("%s","input file: "); for (i=0; i<NAME_LEN; i++) debug_print("%c",cmp_name[i]); debug_print("%s","\n"); debug_print("file type %x\n",file_type); debug_print("data_length %d\n",data_length); debug_print("num_blocks %d\n\n",num_blocks); /* Scan the directory, look for free diretory entries and build block list */ dir_end=0; found_file=0; free_dir_entry=-1; dir_entry_count=0; blocklist_count=0; blocklist= malloc(8*dir_length*sizeof(struct blocktype)); extend_dir= FALSE; debug_print("%s\n","directory scan"); for(dir_block=0; dir_block<dir_length; dir_block++) { lif_read_block(output_device,dir_block+dir_start,dir_data); for(dir_entry=0; dir_entry<8; dir_entry++) { debug_print("dir entry no: %d\n",dir_entry_count); file_type=get_lif_int(dir_data+(dir_entry<<5)+10,2); /* Deleted file */ if(file_type==0) { if(free_dir_entry== -1) free_dir_entry= dir_entry_count; debug_print("%s\n","deleted file"); } else if(file_type==0xFFFF) { /* End of directory */ debug_print("%s\n\n","end of dir mark"); dir_end=1; if(free_dir_entry== -1) { free_dir_entry= dir_entry_count; /* do not move end of dir mark if we are in the last entry */ if(! (dir_entry_count == ((dir_length*8)-1))) extend_dir= TRUE; } break; } else { fbytes=file_length(dir_data+(dir_entry<<5),NULL) ; fstart=get_lif_int(dir_data+(dir_entry<<5)+12,4); fblocks= filelength_in_blocks(fbytes); debug_print("Entry file type %04x startblock %d filelength %d (%d)\n",file_type, fstart,fbytes,fblocks); blocklist[blocklist_count].startblock= fstart; blocklist[blocklist_count].filelength= fblocks; blocklist_count++; if(compare_names((char *) dir_data+(dir_entry<<5),cmp_name)) { /* Found the file */ found_file=1; break; } } dir_entry_count+=1; } if(dir_end) { break; }; /* Quit at end */ } if(found_file) { /* Give duplicate file error */ fprintf(stderr,"Duplicate filename: "); for (i=0; i<NAME_LEN; i++) fprintf(stderr,"%c",cmp_name[i]); fprintf(stderr,"\n"); free(blocklist); exit(2); } /* insert pseudo file entry as end of file */ blocklist[blocklist_count].startblock= medium_size+1; blocklist[blocklist_count].filelength=0; blocklist_count++; /* no free directory entry ? */ if (free_dir_entry == -1) { fprintf(stderr,"Directory full\n"); free(blocklist); exit(2); } /* sort blocklist */ j=1; t=1; n= blocklist_count; while (n-- && t) { for (j=t = 0; j < n; j++) { if (blocklist[j].startblock <= blocklist[j+1].startblock) continue; tempentry= blocklist [j]; blocklist[j]= blocklist[j+1]; blocklist[j+1]=tempentry; t=1; } } debug_print("%s","sorted blocklist\n"); for (i=0; i< blocklist_count; i++) debug_print("start %d length %d\n",blocklist[i].startblock, blocklist[i].filelength); debug_print("%s\n",""); /* find fist contigous block, which is large enough */ file_start=-1; last_data_block=dir_start+dir_length; for (i=0; i< blocklist_count; i++) { free_space= blocklist[i].startblock - last_data_block; debug_print("free space %d at %d\n",free_space,last_data_block); if (num_blocks <= free_space) { file_start= last_data_block; break; } last_data_block= blocklist[i].startblock + blocklist[i].filelength; } if ( file_start == -1 ) { fprintf(stderr,"No room\n"); free(blocklist); exit(2); } debug_print("%s\n","New file"); debug_print("dir entry at: %d\n",free_dir_entry); debug_print("file starts at block %d\n",file_start); debug_print("free space %d (blocks)\n", free_space); debug_print("move end of dir mark %d\n\n",extend_dir); /* Modify start of file in new directory entry */ put_lif_int(new_dir_entry+12,4,file_start); /* Actually copy the file */ debug_print("%s\n","copy file"); file_copy(output_device,input_file,file_start,data_length); /* write directory record */ debug_print("%s\n","write directory"); lif_write_dir_entry(output_device,dir_start,free_dir_entry,new_dir_entry); if(extend_dir) { debug_print("%s\n","write end of directory mark"); for(i=0;i<ENTRY_SIZE;i++) new_dir_entry[i]=0; new_dir_entry[10]= (unsigned char) 0xFF; new_dir_entry[11]= (unsigned char) 0xFF; lif_write_dir_entry(output_device,dir_start,free_dir_entry+1,new_dir_entry); } /* tidy up and quit */ free(blocklist); fclose(input_file); lif_close(output_device); debug_print("%s\n","finished"); exit(0); }
int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "Usage: %s <command> [<args>]\n", argv[0]); return 2; } // TODO: If students aren't going to write this themselves, replace by clean // implementation using function pointers. if (strcmp(argv[1], "init") == 0) { if (check_initialized()) { fprintf(stderr, "ERROR: Repository is already initialized\n"); return 1; } return beargit_init(); } else { if (!check_initialized()) { fprintf(stderr, "ERROR: Repository is not initialized\n"); return 1; } if (strcmp(argv[1], "add") == 0 || strcmp(argv[1], "rm") == 0) { if (argc < 3 || !check_filename(argv[2])) { fprintf(stderr, "ERROR: No or invalid filename given\n"); return 1; } if (strcmp(argv[1], "rm") == 0) { return beargit_rm(argv[2]); } else { return beargit_add(argv[2]); } } else if (strcmp(argv[1], "commit") == 0) { if (argc < 4 || strcmp(argv[2], "-m") != 0) { fprintf(stderr, "ERROR: Need a commit message (-m <msg>)\n"); return 1; } if (strlen(argv[3]) > MSG_SIZE-1) { fprintf(stderr, "ERROR: Message is too long!\n"); return 1; } return beargit_commit(argv[3]); } else if (strcmp(argv[1], "status") == 0) { return beargit_status(); } else if (strcmp(argv[1], "log") == 0) { return beargit_log(); } else if (strcmp(argv[1], "branch") == 0) { return beargit_branch(); } else if (strcmp(argv[1], "checkout") == 0) { int branch_new = 0; char* arg = NULL; for (int i = 2; i < argc; i++) { if (argv[i][0] == '-') { if (strcmp(argv[i], "-b") == 0) { branch_new = 1; continue; } else { fprintf(stderr, "ERROR: Invalid argument: %s", argv[i]); return 1; } } if (arg) { fprintf(stderr, "ERROR: Too many arguments for checkout!"); return 1; } arg = argv[i]; } return beargit_checkout(arg, branch_new); } else { fprintf(stderr, "ERROR: Unknown command \"%s\"\n", argv[1]); return 1; } } }
int main(int argc, char **argv) { int i, n; static struct option const long_opts[] = { {"out", required_argument, NULL, 1}, {"report", required_argument, NULL, 2}, {"dotasref", no_argument, NULL, 3}, {"help", no_argument, NULL, 0}, {"version", no_argument, NULL, 4}, {"export_uncov", no_argument, NULL, 5} }; bool help = FALSE; bool report_version = FALSE; while ((n = getopt_long(argc, argv, "1:2:304", long_opts, NULL)) >= 0) { switch (n) { case 1 : outfile = strdup(optarg); break; case 2 : report = strdup(optarg); break; case 3 : dotasref = TRUE; break; case 0 : help = TRUE; break; case 4 : report_version = TRUE; break; case 5 : export_uncover = TRUE; break; default : return 1; } if ( help ) return usage(); if ( report_version ) return show_version(); } n = argc - optind; if ( n > 1 ) errabort("only accept one input vcf"); if ( export_uncover == TRUE && outfile == FALSE) { warnings("export uncove region only used with option --out"); export_uncover = FALSE; } char * input; if ( n == 0 ) input = strdup("-"); else input = strdup(argv[optind]); htsFile * fp = read_vcf_file(input); enum htsExactFormat fmt = hts_get_format(fp)->format; if ( fmt != vcf && fmt != bcf ) errabort("This is not a VCF/BCF file : %s", input); bcf_hdr_t * hdr = bcf_hdr_read(fp); int n_samples = bcf_hdr_nsamples(hdr); if ( n_samples != 2 ) errabort("the input VCF/BCF file must contain only two samples! %d", n_samples); LOG("Using sample %s as ref ...", hdr->samples[0]); LOG("Using sample %s as test ...", hdr->samples[1]); uint32_t matrix[4][4] = { {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} }; bcf1_t * v = bcf_init1(); kstring_t str = { 0, 0, 0 }; uint32_t line = 0; htsFile *out = NULL; if ( outfile && !check_filename(outfile) ) out = hts_open(outfile, mode); if ( out != NULL ) bcf_hdr_write(out, hdr); while ( bcf_read1(fp, hdr, v) >= 0 ) { bcf_unpack(v, BCF_UN_STR|BCF_UN_FMT); int k; str.l = 0; int tag_id = bcf_hdr_id2int(hdr, BCF_DT_ID, "GT"); if ( !bcf_hdr_idinfo_exists(hdr, BCF_HL_FMT, tag_id) ) warnings("There is no 'GT' in the header!"); for ( i = 0; i < v->n_fmt; ++i ) if ( v->d.fmt[i].id == tag_id ) break; if ( i == v->n_fmt ) { vcf_format1(hdr, v, &str); LOG("There is no tag GT in this line : %s", str.s); continue; } corr_t xy[2] = { {-1, -2, -2}, {-1, -2, -2} }; bcf_fmt_t * fmt = &v->d.fmt[i]; for ( i = 0; i < 2; ++i ) { int corr = i; if ( fmt == NULL ) { if ( dotasref == TRUE ) xy[corr].alt = ALT_IS_REF; else xy[corr].alt = ALT_IS_UNC; continue; } int last = -2; uint8_t *d = (uint8_t*)((char*)fmt->p + fmt->size*i); for ( k = 0; k < fmt->n && d[k] != (uint8_t)bcf_int8_vector_end; ++k ) { int curr = d[k]>>1; if ( last != curr ) { if ( curr ) { if ( last == -2 ) xy[corr].alt = curr > 1 ? ALT_IS_HOM : ALT_IS_REF; else xy[corr].alt = ALT_IS_HET; } else { xy[corr].alt = dotasref == TRUE ? ALT_IS_REF : ALT_IS_UNC; } } else { if ( curr ) { xy[corr].alt = curr > 1 ? ALT_IS_HOM : ALT_IS_REF; } else { xy[corr].alt = dotasref == TRUE ? ALT_IS_REF : ALT_IS_UNC; } } if (last == -2 ) { xy[corr].min = xy[corr].max = curr; } else { if ( curr < xy[corr].min ) xy[corr].min = curr; else if ( curr > xy[corr].max ) xy[corr].max = curr; } last = curr; } } matrix[xy[0].alt][xy[1].alt]++; if ( xy[0].alt != xy[1].alt && out != NULL) { if ( xy[0].alt == ALT_IS_UNC || xy[1].alt == ALT_IS_UNC ) { if ( export_uncover == TRUE ) { str.l = 0; vcf_format1(hdr, v, &str); vcf_write(out, hdr, v); } } else { str.l = 0; vcf_format1(hdr, v, &str); vcf_write(out, hdr, v); } } if ( xy[0].alt == ALT_IS_HET && xy[1].alt == ALT_IS_HET && (xy[0].min != xy[1].min || xy[0].max != xy[1].max ) ) { bias++; matrix[ALT_IS_HET][ALT_IS_HET]--; if ( out != NULL ) { str.l = 0; vcf_format1(hdr, v, &str); vcf_write(out, hdr, v); } } line++; } if ( out ) hts_close(out); if ( str.m ) free(str.s); write_report(matrix, hdr); bcf_hdr_destroy(hdr); free(input); bcf_destroy1(v); if ( outfile ) free(outfile); if ( report ) free(report); if ( hts_close(fp) ) warnings("hts_close returned non-zero status: %s", input); return 0; }
/* fills the fields by reading entries in the global arrays */ void product_edit_fill_fields() { XmString xmstr, preview_xtr; char *str, *datastr, buf[200], preview_str[40]; int pid, *dataptr, data; /* first, find the product ID of the current product */ XtVaGetValues(id_label, XmNlabelString, &xmstr, NULL); XmStringGetLtoR(xmstr, XmFONTLIST_DEFAULT_TAG, &str); pid = atoi(str); free(str); XmStringFree(xmstr); /* DEBUG */ /* fprintf(stderr,"DEBUG - entering product_edit_fill_fields \n"); */ if( !((pid >=0) && (pid <= 1999)) ) fprintf(stderr,"ERROR in Product ID (%d) This value is outside of the\n" " range of values produced by the radar (1-1999).\n", pid); /* now, fill the rest of the fields */ /****************************************************************/ dataptr = assoc_access_i(msg_type_list, pid); if(dataptr != NULL) data = *dataptr; else data = -1; if(data==0) { msgt_but_set = msgt_but0; temp_msg_type = 0; } else if(data==1) { msgt_but_set = msgt_but1; temp_msg_type = 1; } else if(data==2) { msgt_but_set = msgt_but2; temp_msg_type = 2; } else if(data==3) { msgt_but_set = msgt_but3; temp_msg_type = 3; } else if(data==4) { msgt_but_set = msgt_but4; temp_msg_type = 4; } else if(data==999) { msgt_but_set = msgt_but999; temp_msg_type = 999; } else if(data==-1) { msgt_but_set = msgt_but1neg; temp_msg_type = -1; } else { fprintf(stderr,"ERROR message type (%d) for ID %d is not\n" " valid, reset to default value '-1'.\n", data, pid); msgt_but_set = msgt_but1neg; temp_msg_type = -1; } XtVaSetValues(msgtype_opt, XmNmenuHistory, msgt_but_set, NULL); /* CVG 9.1 - added packet 1 coord override for geographic products */ /****************************************************************/ /* DEBUG */ /*fprintf(stderr,"DEBUG product_edit_fill_fields - reading pkt1 flag / " */ /* "setting temp_pkt1_flag, pid is %d\n", pid); */ dataptr = assoc_access_i(packet_1_geo_coord_flag, pid); if(dataptr != NULL) data = *dataptr; else data = 0; if(data==0) { pkt1_but_set = pkt1_but0; temp_pkt1_flag = 0; } else if(data==1) { pkt1_but_set = pkt1_but1; temp_pkt1_flag = 1; } else { fprintf(stderr,"ERROR packet 1 override (%d) for ID %d is not\n" " valid, reset to default value '0'.\n", data, pid); pkt1_but_set = pkt1_but0; temp_pkt1_flag = 0; } XtVaSetValues(packet_1_opt, XmNmenuHistory, pkt1_but_set, NULL); /* DEBUG */ /*fprintf(stderr,"DEBUG product_edit_fill_fields - reading product res / " */ /* "setting resi_but_set\n"); */ /****************************************************************/ dataptr = assoc_access_i(product_res, pid); if(dataptr != NULL) data = *dataptr; else data = -1; if(data==0) { resi_but_set = resi_but0; temp_resindex = 0; } else if(data==1) { resi_but_set = resi_but1; temp_resindex = 1; } else if(data==2) { resi_but_set = resi_but2; temp_resindex = 2; } else if(data==3) { resi_but_set = resi_but3; temp_resindex = 3; } else if(data==4) { resi_but_set = resi_but4; temp_resindex = 4; } else if(data==5) { resi_but_set = resi_but5; temp_resindex = 5; } else if(data==6) { resi_but_set = resi_but6; temp_resindex = 6; } else if(data==7) { resi_but_set = resi_but7; temp_resindex = 7; } else if(data==8) { resi_but_set = resi_but8; temp_resindex = 8; } else if(data==9) { resi_but_set = resi_but9; temp_resindex = 9; } else if(data==10) { resi_but_set = resi_but10; temp_resindex = 10; } else if(data==11) { resi_but_set = resi_but11; temp_resindex = 11; } else if(data==12) { resi_but_set = resi_but12; temp_resindex = 12; } else if(data==13) { resi_but_set = resi_but13; temp_resindex = 13; } else if(data==-1) { resi_but_set = resi_but1neg; temp_resindex = -1; } else { fprintf(stderr,"ERROR product resolution (%d) for ID %d is not\n" " valid, reset to default value '-1'.\n", data, pid); resi_but_set = resi_but1neg; temp_resindex = -1; } XtVaSetValues(resindex_opt, XmNmenuHistory, resi_but_set, NULL); /**************************************************************************/ /* CVG 9.1 - added override of colors for non-2d array packets */ datastr = assoc_access_s(override_palette, pid); if(datastr != NULL) strcpy(buf, datastr); else strcpy(buf, ".plt"); if(check_filename("plt", buf)==FALSE) { fprintf(stderr,"ERROR palette filename (%s) for ID %d is not\n" " valid, reset to default value '.plt'\n", buf, pid); strcpy(buf, ".plt"); } XtVaSetValues(override_palette_text, XmNvalue, buf, NULL); /***************************************************************************/ /* CVG 9.1 - added override of colors for non-2d array packets */ dataptr = assoc_access_i(override_packet, pid); if(dataptr != NULL) data = *dataptr; else data = 0; if(data==0) { over_but_set = over_but0; temp_overridepacket = 0; } else if(data==4) { over_but_set = over_but4; temp_overridepacket = 4; } else if(data==6) { over_but_set = over_but6; temp_overridepacket = 6; } else if(data==8) { over_but_set = over_but8; temp_overridepacket = 8; } else if(data==9) { over_but_set = over_but9; temp_overridepacket = 9; } else if(data==10) { over_but_set = over_but10; temp_overridepacket = 10; } else if(data==20) { /* SHOULD THIS BE INCLUDED? */ over_but_set = over_but20; temp_overridepacket = 20; } else if(data==43) { over_but_set = over_but43; temp_overridepacket = 43; } else if(data==51) { /* contour IT'S BACK */ over_but_set = over_but51; temp_overridepacket = 51; } else { fprintf(stderr,"ERROR associated packet (%d) for ID %d is not\n" " valid/supported, reset to default value '0'.\n", data, pid); over_but_set = over_but0; temp_overridepacket = 0; } XtVaSetValues(overridepacket_opt, XmNmenuHistory, over_but_set, NULL); /* DEBUG */ /*fprintf(stderr,"DEBUG product_edit_fill_fields - setting override_palette_text ,%s, "*/ /* "and temp_overridepacket %d \n", */ /* buf, temp_overridepacket); */ /****************************************************************/ dataptr = assoc_access_i(digital_legend_flag, pid); if(dataptr != NULL) data = *dataptr; else data = -1; if(data==0) { digf_but_set = digf_but0; temp_digflag = 0; } else if(data==1) { digf_but_set = digf_but1; temp_digflag = 1; } else if(data==2) { digf_but_set = digf_but2; temp_digflag = 2; } else if(data==3) { digf_but_set = digf_but3; temp_digflag = 3; } else if(data==4) { digf_but_set = digf_but4; temp_digflag = 4; } else if(data==5) { digf_but_set = digf_but5; temp_digflag = 5; } else if(data==6) { digf_but_set = digf_but6; temp_digflag = 6; } else if(data==-1) { digf_but_set = digf_but1neg; temp_digflag = -1; } else { fprintf(stderr,"ERROR legend flag (%d) for ID %d is not\n" " valid, reset to default value '-1'.\n", data, pid); digf_but_set = digf_but1neg; temp_digflag = -1; } /* DEBUG */ /* fprintf(stderr,"DEBUG product_edit_fill_fields - setting dig flag button\n"); */ XtVaSetValues(digflag_opt, XmNmenuHistory, digf_but_set, NULL); /****************************************************************/ datastr = assoc_access_s(digital_legend_file, pid); if(datastr != NULL) strcpy(buf, datastr); else strcpy(buf, ".lgd"); if(check_filename("lgd", buf)==FALSE) { fprintf(stderr,"ERROR legend filename (%s) for ID %d is not\n" " valid, reset to default value '.lgd'\n", buf, pid); strcpy(buf, ".lgd"); } XtVaSetValues(diglegfile_text, XmNvalue, buf, NULL); /****************************************************************/ datastr = assoc_access_s(dig_legend_file_2, pid); if(datastr != NULL) strcpy(buf, datastr); else strcpy(buf, ".lgd"); if(check_filename("lgd", buf)==FALSE) { fprintf(stderr,"ERROR legend filename (%s) for ID %d is not\n" " valid, reset to default value '.lgd'\n", buf, pid); strcpy(buf, ".lgd"); } XtVaSetValues(diglegfile2_text, XmNvalue, buf, NULL); /****************************************************************/ datastr = assoc_access_s(configured_palette, pid); if(datastr != NULL) strcpy(buf, datastr); else strcpy(buf, ".plt"); if(check_filename("plt", buf)==FALSE) { fprintf(stderr,"ERROR palette filename (%s) for ID %d is not\n" " valid, reset to default value '.plt'\n", buf, pid); strcpy(buf, ".plt"); } XtVaSetValues(confpalette_text, XmNvalue, buf, NULL); /****************************************************************/ datastr = assoc_access_s(config_palette_2, pid); if(datastr != NULL) strcpy(buf, datastr); else strcpy(buf, ".plt"); if(check_filename("plt", buf)==FALSE) { fprintf(stderr,"ERROR palette filename (%s) for ID %d is not\n" " valid, reset to default value '.plt'\n", buf, pid); strcpy(buf, ".plt"); } XtVaSetValues(confpalette2_text, XmNvalue, buf, NULL); /****************************************************************/ dataptr = assoc_access_i(associated_packet, pid); if(dataptr != NULL) data = *dataptr; else data = 0; if(data==0) { assp_but_set = assp_but0; temp_assocpacket = 0; } else if(data==4) { assp_but_set = assp_but4; temp_assocpacket = 4; } else if(data==6) { assp_but_set = assp_but6; temp_assocpacket = 6; } else if(data==8) { assp_but_set = assp_but8; temp_assocpacket = 8; } else if(data==9) { assp_but_set = assp_but9; temp_assocpacket = 9; } else if(data==10) { assp_but_set = assp_but10; temp_assocpacket = 10; } else if(data==16) { assp_but_set = assp_but16; temp_assocpacket = 16; } else if(data==17) { assp_but_set = assp_but17; temp_assocpacket = 17; /* cvg 9.0 - removed */ /* } else if(data==18) { */ /* assp_but_set = assp_but18;*/ /* temp_assocpacket = 18; */ } else if(data==20) { assp_but_set = assp_but20; temp_assocpacket = 20; } else if(data==41) { assp_but_set = assp_but41; temp_assocpacket = 41; } else if(data==42) { assp_but_set = assp_but42; temp_assocpacket = 42; } else if(data==43) { assp_but_set = assp_but43; temp_assocpacket = 43; } else if(data==51) { /* contour IIIIIIIIT'S BAAAAAAAAAACK */ assp_but_set = assp_but51; temp_assocpacket = 51; } else if(data==53) { assp_but_set = assp_but53; temp_assocpacket = 53; } else if(data==54) { assp_but_set = assp_but54; temp_assocpacket = 54; } else if(data==55) { assp_but_set = assp_but55; temp_assocpacket = 55; } else { fprintf(stderr,"ERROR associated packet (%d) for ID %d is not\n" " valid/supported, reset to default value '0'.\n", data, pid); assp_but_set = assp_but0; temp_assocpacket = 0; } XtVaSetValues(assocpacket_opt, XmNmenuHistory, assp_but_set, NULL); /****************************************************************/ datastr = assoc_access_s(legend_units, pid); if(datastr != NULL) strcpy(buf, datastr); else strcpy(buf, ""); XtVaSetValues(unit_text, XmNvalue, buf, NULL); set_sensitivity(); pref_legend_grey_pixmap(); pref_legend_show_pixmap(); /* CVG 9.1 */ /* update the sample legend display if assocpaket is a 2-d array */ if(temp_assocpacket == 16 || temp_assocpacket == 17 || temp_assocpacket == 41 || temp_assocpacket == 42 || temp_assocpacket == 53 || temp_assocpacket == 54 || temp_assocpacket == 55) { if(temp_digflag != 0) pref_legend_clear_pixmap(); display_legend_blocks(pref_legend_pix, 5, 5, TRUE, PREFS_FRAME); pref_legend_show_pixmap(); if( (temp_digflag == 1) || (temp_digflag == 2) || (temp_digflag == 3) ) sprintf(preview_str, "Digital Legend \nPreview"); else if( (temp_digflag==4) || (temp_digflag==5) || (temp_digflag==6) ) sprintf(preview_str, "Generic Legend \nPreview"); else /* not digital / generic product */ sprintf(preview_str, "Color Palette \nPreview"); } else { /* end if assoc packet is a 2-d array */ sprintf(preview_str, " \n "); } preview_xtr = XmStringCreateLtoR(preview_str, XmFONTLIST_DEFAULT_TAG); XtVaSetValues(ledg_label, XmNlabelString, preview_xtr, NULL); XmStringFree(preview_xtr); /* CVG 9.3 - added elevation flag */ /****************************************************************/ dataptr = assoc_access_i(elev_flag, pid); if(dataptr != NULL) data = *dataptr; else data = -1; if(data==0) { elf_but_set = elf_but0; temp_elflag = 0; } else if(data==1) { elf_but_set = elf_but1; temp_elflag = 1; } else { fprintf(stderr,"ERROR elevation flag (%d) for ID %d is not\n" " valid, reset to default value '0'.\n", data, pid); elf_but_set = elf_but0; temp_elflag = 0; } /* DEBUG */ /* fprintf(stderr,"DEBUG product_edit_fill_fields - setting elevation flag\n"); */ XtVaSetValues(elflag_opt, XmNmenuHistory, elf_but_set, NULL); /* DEBUG */ /* fprintf(stderr,"DEBUG - leaving product_edit_fill_fields \n"); */ } /* end product_edit_fill_fields() */
// parsing parameters int CLP::parse(int argc, char *argv[], void (*help)()) { // if (argc<=1) { i_v3d.openV3D = true; } else { vector<char *> parList; // read from configuration file // command arguments parsing char* key; // ------ parsing aguements here --------------------- if(argc<=2) { key = argv[1]; if (*key == OPTION_CHAR) { while(*++key) { if (*key == '?' || !strcmp(key, "h") || !strcmp(key, "H")) { help(); i_v3d.clp_finished = true; } // CMB Dec 7, 2010 // Mac app launcher adds a command line argument // like "-psn_0_7989150" // Ignore it. else if (string(argv[1]).find("-psn_") == 0) { v3d_msg("Apparently a mac bundle", 0); v3d_msg(argv[1], 0); i_v3d.openV3D = true; return true; } else if(!strcmp(key, "M")) //must be capital { i_v3d.clp_finished = true; return true; } else if(!strcmp(key, "na")) { key++; // skip "na" i_v3d.openV3D = true; i_v3d.openNeuronAnnotator = true; break; } } } else if( check_filename(QString(key)) ) { // load and visualize file in V3D char *filename = argv[1]; i_v3d.fileList.push_back(filename); // open V3D i_v3d.openV3D = true; } else { i_v3d.clp_finished = true; return error(help); } } else { for (int i=1;i<argc;i++) { if (string(argv[i])=="-cmd") { i_v3d.openV3D = false; while (i+1<argc) { i_v3d.cmdArgList.push_back(argv[++i]); } #ifdef _ALLOW_WORKMODE_MENU_ CommandManager commandManager(&(i_v3d.cmdArgList)); commandManager.execute(); #endif i_v3d.clp_finished=true; return true; } } // find -h and -x combination int flagh = 0, flagx = 0; for(int i=1; i<argc; i++) { key = argv[i]; if (*key == OPTION_CHAR) { while(*++key) { if (*key == '?' || !strcmp(key, "h") || !strcmp(key, "H")) { flagh++; } } } key = argv[i]; if(*key == OPTION_CHAR) { while (*++key) { if(!strcmp(key, "x")) { flagx++; if(i+1>=argc) return error(help); // launch V3D i_v3d.openV3D = true; // plugin command i_v3d.pluginname = argv[i+1]; } } } if(flagh && flagx) { i_v3d.hideV3D = true; // do not open v3d GUI i_v3d.pluginhelp = true; return true; } } for(int i=1; i<argc; i++) { key = argv[i]; if (*key == OPTION_CHAR) { while(*++key) { if (!strcmp(key, "v")) { i_v3d.open3Dviewer = true; } } } } // parsing arguments in other cases for(int i=1; i<argc; i++) { if(i+1 != argc) // check that we haven't finished parsing yet { key = argv[i]; qDebug()<<">>key ..."<<key; if (*key == OPTION_CHAR) { while(*++key) { if (!strcmp(key, "i")) { // open V3D i_v3d.openV3D = true; while(i+1<argc && !QString(argv[i+1]).startsWith(OPTION_CHAR) ) { char *filename = argv[i+1]; if( check_filename(QString(filename)) ) // do not check name in order to use any extension file in -i?? Jianlong Zhou 2012-05-04 { i_v3d.fileList.push_back(filename); i++; } else { cout << "The file format is not supported for Vaa3D -i option."<<endl; return false; } } } else if (!strcmp(key, "o")) { while(i+1<argc && !QString(argv[i+1]).startsWith(OPTION_CHAR) ) { char *filename = argv[i+1]; // allow all kinds of file format i_v3d.outputList.push_back(filename); i++; } } else if (!strcmp(key, "v")) { i_v3d.open3Dviewer = true; } else if (!strcmp(key, "x")) { // launch V3D i_v3d.openV3D = true; // plugin command i_v3d.pluginname = argv[i+1]; i++; qDebug()<<"call plugin ..."<<i_v3d.pluginname; } else if (!strcmp(key, "m")) { // plugin method i_v3d.pluginmethod = argv[i+1]; i++; qDebug()<<"call plugin method ..."<<i_v3d.pluginmethod; } else if (!strcmp(key, "f")) { // plugin function i_v3d.pluginfunc = argv[i+1]; i++; i_v3d.hideV3D = true; // do not open v3d GUI qDebug()<<"call plugin function ..."<<i_v3d.pluginfunc; } else if(!strcmp(key, "p")) { // plugin function parameters while(i+1<argc && !QString(argv[i+1]).startsWith(OPTION_CHAR) ) { char *strparameters = argv[i+1]; i_v3d.cmdArgList.push_back(strparameters); i++; } } else if(!strcmp(key, "pf")) { key++; // skip "pf" // plugin function parameters from configuration file if(i+1<argc) { char *fn = argv[i+1]; ifstream pConfigFile(fn); string str; if(pConfigFile.is_open()) { while( !pConfigFile.eof() ) { while( getline(pConfigFile, str) ) { //istringstream iss(str); parList.push_back((char *)(str.c_str())); } } } else { cout << "Unable to open the file"<<endl; return false; } pConfigFile.close(); } i++; } else { qDebug()<<"parsing ..."<<key<<i<<"Unknown command. Type 'vaa3d -h' for usage"; i_v3d.clp_finished = true; return error(help); } } } else { return error(help); } } } // for(int i=0; i<parList.size(); i++) { i_v3d.cmdArgList.push_back(parList.at(i)); } } } return true; }
/* and updates the sample legend display if appropriate */ void product_edit_commit_callback(Widget w, XtPointer client_data, XtPointer call_data) { XmString xmstr; char *str = NULL, *buf; int pid; int the_msgtype, the_resindex, the_digflag, the_asocpacket, the_elflag; /* CVG 9.1 - added packet 1 coord override for geographic products */ int the_pkt1_flag; /* CVG 9.1 - added override of colors for non-2d array packets */ int the_overridepacket; /* first, find the product ID of the current product */ XtVaGetValues(id_label, XmNlabelString, &xmstr, NULL); XmStringGetLtoR(xmstr, XmFONTLIST_DEFAULT_TAG, &str); XmStringFree(xmstr); /* if there's nothing currently being edited, we don't have to do anything */ if(str == NULL || str[0] == '\0') return; else /* this is reasonably safe since this value originally comes from preferences */ /* would be better to use isspace and isdigit to determine if really a number */ pid = atoi(str); free(str); /* legend filenames must have the ".lgd" extension * and palette filenames must have the ".plt" extension. * If a user enters the original default (not configured) filename * ".", it is converted to the new defaults ".lgd" and ".plt". */ errno = 0; the_msgtype = temp_msg_type; /* CVG 9.1 - added packet 1 coord override for geographic products */ the_pkt1_flag = temp_pkt1_flag; the_resindex = temp_resindex; /* CVG 9.1 - added ovrride of colors for non-2d array packets */ the_overridepacket = temp_overridepacket; the_digflag = temp_digflag; the_asocpacket = temp_assocpacket; /* CVG 9.3 - added elevation flag */ the_elflag = temp_elflag; /* now, fill the data from whatever's in the fields right now */ assoc_insert_i(msg_type_list, pid, the_msgtype); /* CVG 9.1 - added packet 1 coord override for geographic products */ assoc_insert_i(packet_1_geo_coord_flag, pid, the_pkt1_flag); assoc_insert_i(product_res, pid, the_resindex); assoc_insert_i(override_packet, pid, the_overridepacket); assoc_insert_i(digital_legend_flag, pid, the_digflag); assoc_insert_i(associated_packet, pid, the_asocpacket); /* CVG 9.3 - added elevation flag */ assoc_insert_i(elev_flag, pid, the_elflag); /* CVG 9.1 - added packet 1 coord override for geographic products */ XtVaGetValues(override_palette_text, XmNvalue, &buf, NULL); if(check_filename("plt", buf)==FALSE) { /* also prevents blank entry */ assoc_insert_s(override_palette, pid, ".plt"); } else /* convert original default "." entry to the new default ".plt" */ if((strcmp(buf, ".")==0)) assoc_insert_s(override_palette, pid, ".plt"); else assoc_insert_s(override_palette, pid, buf); free(buf); /* CVG 9.1 - added packet 1 coord override for geographic products */ XtVaGetValues(diglegfile_text, XmNvalue, &buf, NULL); if(check_filename("lgd", buf)==FALSE) { /* also prevents blank entry */ assoc_insert_s(digital_legend_file, pid, ".lgd"); /* BUG - WHY DOESN'T THE FOLOWING WORK? - called fill_fields() instead */ XtVaSetValues(diglegfile_text, XmNvalue, ".lgd", NULL); } else /* convert original default "." entry to the new default ".lgd" */ if((strcmp(buf, ".")==0)) assoc_insert_s(digital_legend_file, pid, ".lgd"); else assoc_insert_s(digital_legend_file, pid, buf); free(buf); XtVaGetValues(diglegfile2_text, XmNvalue, &buf, NULL); if(check_filename("lgd", buf)==FALSE) { /* also prevents blank entry */ assoc_insert_s(dig_legend_file_2, pid, ".lgd"); } else /* convert original default "." entry to the new default ".lgd" */ if((strcmp(buf, ".")==0)) assoc_insert_s(dig_legend_file_2, pid, ".lgd"); else assoc_insert_s(dig_legend_file_2, pid, buf); free(buf); XtVaGetValues(confpalette_text, XmNvalue, &buf, NULL); if(check_filename("plt", buf)==FALSE) { /* also prevents blank entry */ assoc_insert_s(configured_palette, pid, ".plt"); } else /* convert original default "." entry to the new default ".plt" */ if((strcmp(buf, ".")==0)) assoc_insert_s(configured_palette, pid, ".plt"); else assoc_insert_s(configured_palette, pid, buf); free(buf); XtVaGetValues(confpalette2_text, XmNvalue, &buf, NULL); if(check_filename("plt", buf)==FALSE) { /* also prevents blank entry */ assoc_insert_s(config_palette_2, pid, ".plt"); } else /* convert original default "." entry to the new default ".plt" */ if((strcmp(buf, ".")==0)) assoc_insert_s(config_palette_2, pid, ".plt"); else assoc_insert_s(config_palette_2, pid, buf); free(buf); XtVaGetValues(unit_text, XmNvalue, &buf, NULL); /* future improvement: could define a list of standard units but */ /* permit using other values */ assoc_insert_s(legend_units, pid, buf); free(buf); /* only reason for this is to enter corrected filename entries */ product_edit_fill_fields(); } /* end product_edit_commit_callback() */
int main(int argc, char **argv) { /* System variables */ int option; /* Command line option character */ int physical_flag; /* Option to use a physical device */ int lax; /* Option to relax file name checking */ int lif_device; /* Descriptor of input device */ char cmp_name[10]; /* File name to look for */ int i; /* LIF disk values */ unsigned int dir_start; /* first block of the directory */ unsigned int dir_length; /* length of directory in blocks */ /* Directory search values */ unsigned int dir_end; /* Set at end of directory */ unsigned int found_file; /* Set when file found */ unsigned int dir_entry; /* Directory entry within current block */ unsigned int dir_block; /* Current block offset from start of directory */ unsigned int abs_entry; /* entry number of file in directory */ unsigned int file_type; /* file type word */ unsigned char dir_data[SECTOR_SIZE]; /* Current directory block data */ /* File values */ int file_start; /* Starting block number of the file to purge */ int file_len; /* Length of file in bytes */ unsigned char filedata[SECTOR_SIZE]; for(i=0;i<SECTOR_SIZE;i++) filedata[i]=0xFF; /* Process command line options */ physical_flag=0; lax=0; optind=1; while ((option=getopt(argc,argv,"pl?"))!=-1) { switch(option) { case 'p' : physical_flag=1; break; case 'l' : lax=1; break; case '?' : usage(); break; } } /* Are the right number of names specified ? */ if( optind != argc-2 ) { /* No, give an error */ usage(); } /* Check file name */ if(check_filename(argv[optind+1],lax)==0) { fprintf(stderr,"Illegal file name\n"); exit(1); } /* Open lif device */ if((lif_device=lif_open(argv[optind],O_RDWR | O_BINARY,0,physical_flag))==-1) { fprintf(stderr,"Error opening %s\n",argv[optind]); exit(1); } /* Now read block 0 to find where the directory is */ lif_read_block(lif_device,0,dir_data); /* Make sure it's a LIF disk */ if(get_lif_int(dir_data+0,2)!=0x8000) { fprintf(stderr,"This is not a LIF disk!\n"); exit(1); } /* Find the directory */ dir_start=get_lif_int(dir_data+8,4); dir_length=get_lif_int(dir_data+16,4); /* Pad the filename with spaces to enable comparison */ pad_name(argv[optind+1],cmp_name); /* Scan the directory */ dir_end=0; found_file=0; abs_entry=-1; for(dir_block=0; dir_block<dir_length; dir_block++) { lif_read_block(lif_device,dir_block+dir_start,dir_data); for(dir_entry=0; dir_entry<8; dir_entry++) { file_type=get_lif_int(dir_data+(dir_entry<<5)+10,2); abs_entry++; if(file_type==0) { continue; } /* Skip deleted files */ if(file_type==0xFFFF) { /* End of directory */ dir_end=1; break; } if(compare_names((char *)dir_data+(dir_entry<<5),cmp_name)) { /* Found the file */ found_file=1; break; } } if(dir_end || found_file) { break; }; /* Quit at end or if file found */ } if(!found_file) { /* Give file not found error */ fprintf(stderr,"File %s not found\n",argv[optind+1]); exit(2); } /* Find the file start and length */ file_start=get_lif_int(dir_data+(dir_entry<<5)+12,4); file_len=get_lif_int(dir_data+(dir_entry<<5)+16,4); debug_print("file_start %d\n",file_start); debug_print("file_len %d\n",file_len); debug_print("abs_entry %d\n",abs_entry); debug_print("dir_block %d\n",dir_block); debug_print("dir_start %d\n",dir_start); /* Actually zero the file */ for(i=0; i< file_len; i++) lif_write_block(lif_device,file_start+i, filedata); /* Actually delete the directory entry */ dir_data[(dir_entry<<5)+10]=0x0; dir_data[(dir_entry<<5)+11]=0x0; lif_write_dir_entry(lif_device,dir_start,abs_entry, dir_data+(dir_entry<<5)); /* tidy up and quit */ lif_close(lif_device); exit(0); }
/***************************************************************************** 函 数 名 : ws__removeOperationLog 功能描述 : web service实现函数,删除日志 输入参数 : soap ---- web service执行环境 输出参数 : ret ---- 返回结果 返 回 值 : WS_OK ---- 执行成功 soapFault ---- 执行失败 调用函数 : 被调函数 : ============================================================================ 修改历史 : 1.日 期 : 2008年8月8日 修改内容 : 新生成函数 *****************************************************************************/ int ws__removeOperationLog(WS_ENV* ws_env, char *fileName, char * vrfid, int *ret) { // int ws_err; int sys_error_code = ERROR_SUCCESS; char file_to_del[100]; char command[200]; int deleted = 0; FILE * fp = NULL; int i; /* 检查参数$vFileName的合法性 */ sys_error_code = check_filename(fileName); if (ERROR_SUCCESS != sys_error_code) { return ws_new_soap_fault(ws_env, sys_error_code); } /* 调用库函数ulink执行删除命令,删除日志主文件以及以.x结尾的日志文件, * 如删除oper-current.log及oper-current.log.1 至 oper-current.log.x,日志文 * 件如果不连续默认也要删除 */ /* 查找符合条件的日志文件*/ if(strcmp("0", vrfid) == 0) { sprintf(command, "%s%s.l*", CMD_LS " " OPERA_LOG_PATH "/" FLAG_OPER, fileName); } else { sprintf(command, "%s%s%s%s.l*", CMD_LS " " OPERA_LOG_PATH "/",vrfid, "_" FLAG_OPER, fileName); } /* 保护局部变量 */ command[sizeof(command) - 1 ] = '\0'; fp = cmd_run(command); if (NULL == fp) { WEB_SEND_DEBUG_ss("ls log file failed:", command); return ws_send_soap_error(ws_env, "Deleting log file error!"); } while (!feof(fp) && ERROR_SUCCESS == sys_error_code) { if (NULL == fgets(file_to_del, sizeof(file_to_del), fp)) { // end of file break; } // 去掉结尾换行符 for (i = (int)strlen(file_to_del) -1; i >=0; i--) { if ('\n' == file_to_del[i] || '\r' == file_to_del[i]) { file_to_del[i] = '\0'; } else { break; } } if (NULL != strstr(file_to_del, "Today")) { /* 清空当天日志 */ /* ":>data.xx",该命令可以清空data.xx文件 */ sprintf(command, ": > %s", file_to_del); } else { //生成删除命令 sprintf(command, "rm %s", file_to_del); } /* 保护局部变量 */ command[sizeof(command) - 1 ] = '\0'; if (ERROR_SUCCESS != system(command)) { WEB_SEND_DEBUG_ss("rm log file failed:", command); return ws_send_soap_error(ws_env, "Deleting log file error!"); } deleted++; } cmd_closeio(fp); /* 如果函数glob获取的文件数目为0,报找不到文件 */ if (0 == deleted) { return ws_send_soap_error(ws_env, "Current log file not exists!"); } /* 记录操作日志 */ WEB_SEND_EX_OPERLOG_QUICK(sys_error_code, REMOVE_OPERLOG_LOG, fileName); *ret = 0; return WS_OK; }
/***************************************************************************** 函 数 名 : ws__backupOperationLog 功能描述 : web service实现函数,日志备份 本函数由search函数简化而来 输入参数 : soap ---- web service执行环境 输出参数 : ret ---- 返回结果 返 回 值 : WS_OK ---- 执行成功 soapFault ---- 执行失败 调用函数 : 被调函数 : ============================================================================ 修改历史 : 1.日 期 : 2008年8月8日 修改内容 : 新生成函数 *****************************************************************************/ int ws__backupOperationLog(WS_ENV* ws_env, char *fileName, char* vrfid, struct ws__backupOperationLog_Response *ret) { // int ws_err; int count; int sys_error_code = ERROR_SUCCESS; char *file_pos, command[500]; int cmd_start_len, cmd_len; int file_count; struct OperLogContent *log_content; int saved_log = 0; FILE * fp = NULL; int k; MEMBUFF * buff; long exporting; /* 获得是否正在导出的标记 */ exporting = (long)ws_get_private_data(ws_env); /* 检查参数$vFileName的合法性 */ sys_error_code = check_filename(fileName); if (ERROR_SUCCESS != sys_error_code) { return ws_new_soap_fault(ws_env, sys_error_code); } if (DISK_LOG_EXPORTING == exporting) { // 正在导出配置 /* 查找符合条件的日志文件, 不用计算总行数 */ if(strcmp("0", vrfid) == 0) { sprintf(command, "%s%s.l*", CMD_LS_EXPORT " " OPERA_LOG_PATH "/" FLAG_OPER, fileName); } else { sprintf(command, "%s%s%s%s.l*", CMD_LS_EXPORT " " OPERA_LOG_PATH "/" , vrfid, "_" FLAG_OPER, fileName); } } else { /* 查找符合条件的日志文件, 最后一行同时计算总行数 */ if(strcmp("0", vrfid) == 0) { sprintf(command, "%s `%s%s.l*`", "wc -l", CMD_LS " " OPERA_LOG_PATH "/" FLAG_OPER, fileName); } else { sprintf(command, "%s `%s%s%s%s.l*`", "wc -l", CMD_LS " " OPERA_LOG_PATH "/", vrfid, "_" FLAG_OPER, fileName); } } /* 保护局部变量 */ command[sizeof(command) - 1 ] = '\0'; //printf("---1-%s--\n", command); fp = cmd_run(command); if (NULL == fp) { WEB_SEND_DEBUG_ss("ls log file failed:", command); return ws_send_soap_error(ws_env, "Current log file not exists!"); } buff = membuff_readfile(fp); cmd_closeio(fp); if(NULL == buff) { return ws_new_soap_fault(ws_env, ERROR_SYSTEM); } membuff_tolineformat(buff, FORMAT_NOTRIM); //printf("--11--%d, %s, %d\n", buff->len, buff->array[0]->buff, buff->array[0]->len); if(buff->len <1 || buff->array[0]->len <1 || buff->array[0]->buff[0] == '0') //如果没找到文件wc统计为0 { //文件未找到 membuff_free(buff); return ws_send_soap_error(ws_env, "Current log file not exists!"); } if (DISK_LOG_EXPORTING == exporting) { // 正在导出配置,只分配一条记录的空间 count = 1; saved_log = 1; } else { /* 正常执行,最后一行是count */ count = atoi(buff->array[buff->len-1]->buff); } /* 分配内存 */ log_content = (struct OperLogContent*)ws_malloc(ws_env, (u_int32_t)count*sizeof(struct OperLogContent)); if (NULL == log_content) { return ws_new_soap_fault(ws_env, ERROR_SYSTEM); } // 构造初始命令 cmd_start_len = sprintf(command, "("); for (k = 0; k < buff->len; k++) { file_pos = strchr(buff->array[k]->buff, '/'); //printf("--line test:%s %s--\n", buff->array[k]->buff, file_pos); if (NULL == file_pos) { // 文件名不合法或者最后一行total continue; } cmd_len = cmd_start_len + make_file_search_cmd(file_pos, FILE_NAME_CHK_PASS, NULL, NULL,NULL, 0, 0, command + cmd_start_len); /* 得到显示具体信息的命令 */ sprintf(command + cmd_len, ")"); /* 保护局部变量 */ command[sizeof(command) - 1 ] = '\0'; if (DISK_LOG_EXPORTING == exporting) { sys_error_code = make_opera_log_result(ws_env, command, log_content, 1, exporting, vrfid); } else { /* 本文件的行数 */ file_count = atoi(buff->array[k]->buff); sys_error_code = make_opera_log_result(ws_env, command, log_content + saved_log, file_count, exporting, vrfid); saved_log += file_count; } } membuff_free(buff); /* 记录操作日志 */ WEB_SEND_EX_OPERLOG_QUICK(sys_error_code, BACKUP_OPERLOG_LOG, fileName); if (ERROR_SUCCESS != sys_error_code) { return ws_new_soap_fault(ws_env, sys_error_code); } if(DISK_LOG_EXPORTING == exporting) { saved_log = 0; } ret->ret.sum = count; ret->ret.res_USCOREcount = ret->ret.__size = saved_log; ret->ret.__ptrres = log_content; return WS_OK; }
static int parse_branchname_arg(int argc, const char **argv, int dwim_new_local_branch_ok, struct branch_info *new_branch_info, struct checkout_opts *opts, struct object_id *rev, int *dwim_remotes_matched) { struct tree **source_tree = &opts->source_tree; const char **new_branch = &opts->new_branch; int argcount = 0; struct object_id branch_rev; const char *arg; int dash_dash_pos; int has_dash_dash = 0; int i; /* * case 1: git checkout <ref> -- [<paths>] * * <ref> must be a valid tree, everything after the '--' must be * a path. * * case 2: git checkout -- [<paths>] * * everything after the '--' must be paths. * * case 3: git checkout <something> [--] * * (a) If <something> is a commit, that is to * switch to the branch or detach HEAD at it. As a special case, * if <something> is A...B (missing A or B means HEAD but you can * omit at most one side), and if there is a unique merge base * between A and B, A...B names that merge base. * * (b) If <something> is _not_ a commit, either "--" is present * or <something> is not a path, no -t or -b was given, and * and there is a tracking branch whose name is <something> * in one and only one remote (or if the branch exists on the * remote named in checkout.defaultRemote), then this is a * short-hand to fork local <something> from that * remote-tracking branch. * * (c) Otherwise, if "--" is present, treat it like case (1). * * (d) Otherwise : * - if it's a reference, treat it like case (1) * - else if it's a path, treat it like case (2) * - else: fail. * * case 4: git checkout <something> <paths> * * The first argument must not be ambiguous. * - If it's *only* a reference, treat it like case (1). * - If it's only a path, treat it like case (2). * - else: fail. * */ if (!argc) return 0; arg = argv[0]; dash_dash_pos = -1; for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "--")) { dash_dash_pos = i; break; } } if (dash_dash_pos == 0) return 1; /* case (2) */ else if (dash_dash_pos == 1) has_dash_dash = 1; /* case (3) or (1) */ else if (dash_dash_pos >= 2) die(_("only one reference expected, %d given."), dash_dash_pos); opts->count_checkout_paths = !opts->quiet && !has_dash_dash; if (!strcmp(arg, "-")) arg = "@{-1}"; if (get_oid_mb(arg, rev)) { /* * Either case (3) or (4), with <something> not being * a commit, or an attempt to use case (1) with an * invalid ref. * * It's likely an error, but we need to find out if * we should auto-create the branch, case (3).(b). */ int recover_with_dwim = dwim_new_local_branch_ok; int could_be_checkout_paths = !has_dash_dash && check_filename(opts->prefix, arg); if (!has_dash_dash && !no_wildcard(arg)) recover_with_dwim = 0; /* * Accept "git checkout foo" and "git checkout foo --" * as candidates for dwim. */ if (!(argc == 1 && !has_dash_dash) && !(argc == 2 && has_dash_dash)) recover_with_dwim = 0; if (recover_with_dwim) { const char *remote = unique_tracking_name(arg, rev, dwim_remotes_matched); if (remote) { if (could_be_checkout_paths) die(_("'%s' could be both a local file and a tracking branch.\n" "Please use -- (and optionally --no-guess) to disambiguate"), arg); *new_branch = arg; arg = remote; /* DWIMmed to create local branch, case (3).(b) */ } else { recover_with_dwim = 0; } } if (!recover_with_dwim) { if (has_dash_dash) die(_("invalid reference: %s"), arg); return argcount; } } /* we can't end up being in (2) anymore, eat the argument */ argcount++; argv++; argc--; new_branch_info->name = arg; setup_branch_path(new_branch_info); if (!check_refname_format(new_branch_info->path, 0) && !read_ref(new_branch_info->path, &branch_rev)) oidcpy(rev, &branch_rev); else new_branch_info->path = NULL; /* not an existing branch */ new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1); if (!new_branch_info->commit) { /* not a commit */ *source_tree = parse_tree_indirect(rev); } else { parse_commit_or_die(new_branch_info->commit); *source_tree = get_commit_tree(new_branch_info->commit); } if (!*source_tree) /* case (1): want a tree */ die(_("reference is not a tree: %s"), arg); if (!has_dash_dash) { /* case (3).(d) -> (1) */ /* * Do not complain the most common case * git checkout branch * even if there happen to be a file called 'branch'; * it would be extremely annoying. */ if (argc) verify_non_filename(opts->prefix, arg); } else { argcount++; argv++; argc--; } return argcount; }