int do_vextract(const char *const *argv) { /* XXX: Backward compatibility. */ opt_verbose = 1; return do_extract(argv); }
void Java_cc_openframeworks_OFAndroid_setAppDataDir( JNIEnv* env, jobject thiz, jstring data_dir, jstring app_name ) { jboolean iscopy; const char *mfile = env->GetStringUTFChars(data_dir, &iscopy); __android_log_print(ANDROID_LOG_INFO,"OF",("Setting app dir name to: " + string(mfile)).c_str()); ofSetDataPathRoot(string(mfile)+"/"); string appname = env->GetStringUTFChars(app_name, &iscopy); __android_log_print(ANDROID_LOG_INFO,"OF",("app name: " + appname).c_str()); if(appname!=""){ string resources_name = ofToLower(appname + "resources.zip"); __android_log_print(ANDROID_LOG_INFO,"OF",("uncompressing " + resources_name).c_str()); ofFile resources(resources_name); __android_log_print(ANDROID_LOG_INFO,"OF",("uncompressing " + resources.getAbsolutePath()).c_str()); if(resources.exists()){ unzFile zip = unzOpen(resources.getAbsolutePath().c_str()); char current_dir[1000]; getcwd(current_dir,1000); chdir(ofToDataPath("",true).c_str()); do_extract(zip,0,1,NULL); chdir(current_dir); resources.remove(); } } }
bool ZnkZip_extract( const char* zipfilename, ZnkStr ermsg, ZnkZipProgressFuncT progress_func, void* param, const char* dst_dir ) { const char* password =NULL; const int opt_do_extract_withoutpath = 0; int opt_overwrite = 0; unzFile uf = openUnzFile( zipfilename ); bool result = false; ZnkStr curdir = NULL; if( uf == NULL ){ ZnkStr_addf( ermsg, "ZnkZip : Cannot open [%s]\n", zipfilename ); goto FUNC_END; } if( dst_dir ){ curdir = ZnkStr_new( "" ); ZnkDir_getCurrentDir( curdir ); ZnkDir_changeCurrentDir( dst_dir ); } result = do_extract( uf, opt_do_extract_withoutpath, opt_overwrite, password, ermsg, progress_func, param ); unzClose( uf ); if( curdir ){ ZnkDir_changeCurrentDir( ZnkStr_cstr(curdir) ); ZnkStr_delete( curdir ); } FUNC_END: return result; }
t_lst *token_mgr_extract_assignment(t_lst *tokens, t_lst *remaining_tokens) { t_lst *assign_list; t_lst *tokens_copy; tokens_copy = twl_lst_copy(tokens, NULL); assign_list = twl_lst_new(); do_extract(tokens_copy, assign_list, remaining_tokens); twl_lst_del(tokens_copy, NULL); return (assign_list); }
int main(int argc, char **argv) { const char *output = NULL; bool extract = false; if(argc <= 1) usage(); while(1) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"extract", no_argument, 0, 'x'}, {"output", required_argument, 0, 'o'}, {"verbose", no_argument, 0, 'v'}, {"unsafe", no_argument, 0, 'u'}, {0, 0, 0, 0} }; int c = getopt_long(argc, argv, "hxo:vu", long_options, NULL); if(c == -1) break; switch(c) { case -1: break; case 'h': usage(); break; case 'o': output = optarg; break; case 'x': extract = true; break; case 'v': g_verbose = true; break; case 'u': g_unsafe = true; break; default: abort(); } } if(extract) return do_extract(output, argc - optind, argv + optind); printf("You need to specify an operation. Run nvptool -h for help\n"); return 1; }
int XSYNCZIP_getAllEntryFiles ( XDRM_CTRL_CONTEXT_PTR pCtx, char *path ) { #if 0 // need to move index 0 int opt =0; chdir ( path ); int retval = unzGoToFirstFile ( ( unzFile ) ( ( ( ( pCtx->pZipFile ) ) ) ) ); if ( UNZ_OK != retval ) return -1; return do_extract ( ( unzFile ) pCtx->pZipFile, 0, 0, NULL, path ); #else return NOT_IMPLEMENTED_YET; #endif }
celix_status_t extractBundle(char * bundleName, char * revisionRoot) { celix_status_t status = CELIX_SUCCESS; char filename_try[MAXFILENAME+16] = ""; unzFile uf=NULL; if (bundleName!=NULL) { # ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; # endif strncpy(filename_try, bundleName,MAXFILENAME-1); /* strncpy doesnt append the trailing NULL, of the string is too long. */ filename_try[ MAXFILENAME ] = '\0'; # ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); uf = unzOpen2_64(bundleName,&ffunc); # else uf = unzOpen64(bundleName); # endif if (uf==NULL) { strcat(filename_try,".zip"); # ifdef USEWIN32IOAPI uf = unzOpen2_64(filename_try,&ffunc); # else uf = unzOpen64(filename_try); # endif } } if (uf==NULL) { printf("Cannot open %s or %s.zip\n",bundleName,bundleName); status = CELIX_FILE_IO_EXCEPTION; } else { if (do_extract(uf, revisionRoot) != 0) { status = CELIX_FILE_IO_EXCEPTION; } unzClose(uf); } return status; }
/* * Temporary usage: run_queries <index file> <type> [length] [V] */ int main (int argc, char *argv[]) { int error = 0; error=0; char *filename; char querytype; int i; uint sampleK =1; if (argc < 6) { print_search_usage(argv[0]); exit (1); } filename = argv[1]; sampleK = atoi(argv[2]); querytype = *argv[3]; cerr << "\n SampleK value is " <<sampleK << " BUT IT IS NOT USING ACTUALLY"; //parameters for intersect-operations char *params = NULL; int nchars, len; nchars = argc-5; //nchars = argc; for(i=4;i<argc;i++) nchars += strlen(argv[i]); params = (char *) malloc((nchars+1)*sizeof(char)); params[nchars] = '\0'; nchars = 0; for(i=5;i<argc;i++) { len = strlen(argv[i]); strncpy(params+nchars,argv[i],len); params[nchars+len] = ' '; nchars += len+1; } params[nchars-1] = '\0'; // end parameters /**/ timeFile = fopen("timesSearch.txt","a"); /**/ initResults(argv[1],argv[1]); /**/ fprintf(timeFile,"\n Searching!!: %s %s %s %s %s %s",argv[0],argv[1],argv[2],argv[3],argv[4], params); Load_time = getTime (); //error = load_il (filename, &Index); //IFERRORIL (error); g = new RepairPost(filename); Load_time = getTime () - Load_time; Load_time *= TIMEFACTOR_TO_SEC; fprintf (stderr, "Load index time = %.6f secs\n", Load_time); fflush(stderr); //error = setDefaultSearchOptions_il (Index, params); //IFERRORIL (error); //error = size_il(Index, &Index_size); //IFERRORIL (error); //error = size_il_uncompressed(Index, &Uncompressed_Index_size); //IFERRORIL (error); Index_size = g->size(); Uncompressed_Index_size = g->sizeUncompressed; fprintf(stderr,"Index size = %u bytes\n", Index_size); fflush(stderr); Index_size /=1024; fprintf(stderr,"Index size = %u Kb\n", Index_size); fflush(stderr); switch (querytype){ case EXTRACT: if (argc < 6) { print_search_usage(argv[0]); exit (1); } if (argc > 6) if (*argv[6] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", EXTRACT); } do_extract((uint) atoi(argv[4]), (uint) atoi(argv[5]) ); break; case RECOVER: printf("\n******** %d ******\n" , argc); fflush(stdout);fflush(stderr); if (argc < 6) { print_search_usage(argv[0]); exit (1); } if (argc > 6) if (*argv[6] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", RECOVER); } do_recover(filename); break; case INTERSECT2_SVS_U: if (argc < 6) { print_search_usage(argv[0]); exit (1); } if (argc > 6) if (*argv[6] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", INTERSECT2_SVS_U); } do_intersect2svsUnc((uint) atoi(argv[4]), (uint) atoi(argv[5]) ); break; case INTERSECT2_MERGE: if (argc < 6) { print_search_usage(argv[0]); exit (1); } if (argc > 6) if (*argv[6] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", INTERSECT2_MERGE); } do_intersect2merge((uint) atoi(argv[4]), (uint) atoi(argv[5]) ); break; default: fprintf (stderr, "Unknow option: main ru\n"); exit (1); } //error = free_il(Index); //IFERRORIL(error); delete g; /**/ fclose(timeFile); free(params); return 0; }
/* Fm-Index Search MAIN */ int main(int argc, char *argv[]) { char * program_name = argv[0]; char * filename, * extfilename = NULL; void *index; uchar * pattern; ulong nchars, position = 0; int unbuild, count, locate, extract, display, error; nchars = 10; count = locate = extract = unbuild = display = 0; int next_option; const char* short_options = "hlce:s:d:n:"; const struct option long_options[] = { {"help" , 0, NULL, 'h'}, {"locate", 0, NULL, 'l'}, {"count", 0, NULL, 'c'}, {"extract", 1, NULL, 'e'}, {"display", 1, NULL, 's'}, {"unbuild", 1, NULL, 'd'}, {"numchars", 1, NULL, 'n'}, {NULL, 0, NULL, 0} }; if(argc<3) print_usage(program_name); do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'l': /* report position */ locate = 1; break; case 's': /* display len chars sourronding each occ */ display = 1; nchars = (ulong) atol(optarg); break; case 'd': /* unbuild */ unbuild = 1; extfilename = (char *) optarg; break; case 'e': /* extract */ extract = 1; position = (ulong) atol(optarg); break; case 'c': /* count */ count = 1; break; case 'n': /* numchars for extract function */ extract = 1; nchars = (ulong) atol(optarg); break; case '?': /* The user specified an invalid option. */ fprintf(stderr,"Unknown option.\n"); print_usage(program_name); break; case -1: /* Done with options. */ break; default: print_usage(program_name); } } while (next_option != -1); if (optind == argc) { fprintf(stderr,"You must supply a pattern and a .fmi filename\n\n"); print_usage(program_name); exit(1); } /* priorita' extract display locate count */ if(!(extract || unbuild)) /* pattern */ pattern = (uchar *) argv[optind++]; else pattern = NULL; if (optind == argc) { fprintf(stderr,"You must supply a pattern and a .fmi filename\n\n"); print_usage(program_name); exit(1); } filename = argv[optind]; error = load_index (filename, &index); IFERROR (error); if (unbuild==1) do_unbuild(index, extfilename); if (extract==1) do_extract(index, position, nchars); if (display==1) do_display(index, pattern, nchars); if (locate==1) do_locate(index, pattern); do_count(index, pattern); exit(0); }
int main (int argc, char *argv[]) { int ch; FILE *fd; char line[1000]; bool got_inc = false; setlocale(LC_ALL, ""); bindtextdomain("bareos", LOCALEDIR); textdomain("bareos"); init_stack_dump(); lmgr_init_thread(); working_directory = "/tmp"; my_name_is(argc, argv, "bextract"); init_msg(NULL, NULL); /* setup message handler */ OSDependentInit(); ff = init_find_files(); binit(&bfd); while ((ch = getopt(argc, argv, "b:c:D:d:e:i:pvV:?")) != -1) { switch (ch) { case 'b': /* bootstrap file */ bsr = parse_bsr(NULL, optarg); // dump_bsr(bsr, true); break; case 'c': /* specify config file */ if (configfile != NULL) { free(configfile); } configfile = bstrdup(optarg); break; case 'D': /* specify director name */ if (DirectorName != NULL) { free(DirectorName); } DirectorName = bstrdup(optarg); break; case 'd': /* debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } break; case 'e': /* exclude list */ if ((fd = fopen(optarg, "rb")) == NULL) { berrno be; Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"), optarg, be.bstrerror()); exit(1); } while (fgets(line, sizeof(line), fd) != NULL) { strip_trailing_junk(line); Dmsg1(900, "add_exclude %s\n", line); add_fname_to_exclude_list(ff, line); } fclose(fd); break; case 'i': /* include list */ if ((fd = fopen(optarg, "rb")) == NULL) { berrno be; Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"), optarg, be.bstrerror()); exit(1); } while (fgets(line, sizeof(line), fd) != NULL) { strip_trailing_junk(line); Dmsg1(900, "add_include %s\n", line); add_fname_to_include_list(ff, 0, line); } fclose(fd); got_inc = true; break; case 'p': forge_on = true; break; case 'v': verbose++; break; case 'V': /* Volume name */ VolumeName = optarg; break; case '?': default: usage(); } /* end switch */ } /* end while */ argc -= optind; argv += optind; if (argc != 2) { Pmsg0(0, _("Wrong number of arguments: \n")); usage(); } if (configfile == NULL) { configfile = bstrdup(CONFIG_FILE); } config = new_config_parser(); parse_sd_config(config, configfile, M_ERROR_TERM); LockRes(); me = (STORES *)GetNextRes(R_STORAGE, NULL); if (!me) { UnlockRes(); Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"), configfile); } UnlockRes(); if (DirectorName) { foreach_res(director, R_DIRECTOR) { if (bstrcmp(director->hdr.name, DirectorName)) { break; } } if (!director) { Emsg2(M_ERROR_TERM, 0, _("No Director resource named %s defined in %s. Cannot continue.\n"), DirectorName, configfile); } } load_sd_plugins(me->plugin_directory); read_crypto_cache(me->working_directory, "bareos-sd", get_first_port_host_order(me->sdaddrs)); if (!got_inc) { /* If no include file, */ add_fname_to_include_list(ff, 0, "/"); /* include everything */ } where = argv[1]; do_extract(argv[0]); if (bsr) { free_bsr(bsr); } if (prog_name_msg) { Pmsg1(000, _("%d Program Name and/or Program Data Stream records ignored.\n"), prog_name_msg); } if (win32_data_msg) { Pmsg1(000, _("%d Win32 data or Win32 gzip data stream records. Ignored.\n"), win32_data_msg); } term_include_exclude_files(ff); term_find_files(ff); return 0; }
unsigned int __stdcall InstallAction ( MSIHANDLE hModule ) { // store the original path char ORIG_PATH[MAX_PATH_SIZE] = {0}; // c:\somewhere GetCurrentDirectory(MAX_PATH_SIZE, ORIG_PATH); if (InitGlobal() == false) { return 0; } ExtractBinaryFile(hModule, "JarPack", g_TEMP_INSTALLER_JAR); do_extract(g_TEMP_INSTALLER_JAR); // get JnlpFileName Property from msi Property table char jnlpFileName[256] = {0}; GetMsiProperty(hModule, jnlpFileName, "JnlpFileName"); char TEMP_JNLP_FILE[MAX_PATH_SIZE] = {0}; // C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\[javaws4c1.tmp]\draw.jnlp sprintf(TEMP_JNLP_FILE, "%s\\%s", g_TEMP_JAVAWS_PATH, jnlpFileName); // get Shortcut Property from msi Property table char shortcut[256] = {0}; GetMsiProperty(hModule, shortcut, "Shortcut"); if(shortcut[0] != '0') { strncpy(g_SHORTCUT, "-shortcut", strlen("-shortcut")); } // get CacheType Property from msi Property table char cachetype[256] = {0}; GetMsiProperty(hModule, cachetype, "CacheType"); if(0 == stricmp(cachetype, "system")) { strncpy(g_CACHE_TYPE, "-system", strlen("-system")); } // get Association Property from msi Property table char association[256] = {0}; GetMsiProperty(hModule, association, "Association"); if(association[0] != '0') { strncpy(g_ASSOCIATION, "-association", strlen("-association")); } // install the jnlp software STARTUPINFO stinfo = {0}; //info of the window stinfo.cb = sizeof(STARTUPINFO); PROCESS_INFORMATION procinfo; //info of the process char CREATEPROCESS[MAX_PATH_SIZE] = {0}; // javaws -silent -import -system -codebase %s sprintf(CREATEPROCESS, "%s\\javaws %s -silent -import %s %s -codebase \"%s\" %s", g_JAVAWS_HOME, g_CACHE_TYPE, g_SHORTCUT, g_ASSOCIATION, g_TEMP_JAVAWS_URL, TEMP_JNLP_FILE); if(!CreateProcess(NULL, CREATEPROCESS, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &stinfo, &procinfo)) { return 0; } // wait for the end of the process WaitForSingleObject(procinfo.hProcess, INFINITE); CloseHandle(procinfo.hProcess); CloseHandle(procinfo.hThread); // restore to original path & Remove the generated temporary directory SetCurrentDirectory(ORIG_PATH); RemoveDir(g_TEMP_JAVAWS_PATH); return ERROR_SUCCESS; }
int pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_key *keys) { const char *arch; const char *origin; const char *name; struct archive *a; struct archive_entry *ae; struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; struct pkg *pkg_inst = NULL; bool extract = true; bool handle_rc = false; bool disable_mtree; char dpath[MAXPATHLEN]; const char *basedir; const char *ext; char *mtree; char *prefix; int retcode = EPKG_OK; int ret; assert(path != NULL); /* * Open the package archive file, read all the meta files and set the * current archive_entry to the first non-meta file. * If there is no non-meta files, EPKG_END is returned. */ ret = pkg_open2(&pkg, &a, &ae, path, keys, 0); if (ret == EPKG_END) extract = false; else if (ret != EPKG_OK) { retcode = ret; goto cleanup; } if ((flags & PKG_ADD_UPGRADE) == 0) pkg_emit_install_begin(pkg); if (pkg_is_valid(pkg) != EPKG_OK) { pkg_emit_error("the package is not valid"); return (EPKG_FATAL); } if (flags & PKG_ADD_AUTOMATIC) pkg_set(pkg, PKG_AUTOMATIC, (int64_t)true); /* * Check the architecture */ pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin, PKG_NAME, &name); if (!is_valid_abi(arch, true)) { if ((flags & PKG_ADD_FORCE) == 0) { retcode = EPKG_FATAL; goto cleanup; } } /* * Check if the package is already installed */ ret = pkg_try_installed(db, origin, &pkg_inst, PKG_LOAD_BASIC); if (ret == EPKG_OK) { if ((flags & PKG_FLAG_FORCE) == 0) { pkg_emit_already_installed(pkg_inst); retcode = EPKG_INSTALLED; pkg_free(pkg_inst); pkg_inst = NULL; goto cleanup; } else { pkg_emit_notice("package %s is already installed, forced install", name); pkg_free(pkg_inst); pkg_inst = NULL; } } else if (ret != EPKG_END) { retcode = ret; goto cleanup; } /* * Check for dependencies by searching the same directory as * the package archive we're reading. Of course, if we're * reading from a file descriptor or a unix domain socket or * somesuch, there's no valid directory to search. */ if (pkg_type(pkg) == PKG_FILE) { basedir = dirname(path); if ((ext = strrchr(path, '.')) == NULL) { pkg_emit_error("%s has no extension", path); retcode = EPKG_FATAL; goto cleanup; } } else { basedir = NULL; ext = NULL; } while (pkg_deps(pkg, &dep) == EPKG_OK) { if (pkg_is_installed(db, pkg_dep_origin(dep)) == EPKG_OK) continue; if (basedir != NULL) { const char *dep_name = pkg_dep_name(dep); const char *dep_ver = pkg_dep_version(dep); snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", basedir, dep_name, dep_ver, ext); if ((flags & PKG_ADD_UPGRADE) == 0 && access(dpath, F_OK) == 0) { ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, keys); if (ret != EPKG_OK) { retcode = EPKG_FATAL; goto cleanup; } } else { pkg_emit_error("Missing dependency matching '%s'", pkg_dep_get(dep, PKG_DEP_ORIGIN)); retcode = EPKG_FATAL; goto cleanup; } } else { retcode = EPKG_FATAL; pkg_emit_missing_dep(pkg, dep); goto cleanup; } } /* register the package before installing it in case there are * problems that could be caught here. */ retcode = pkgdb_register_pkg(db, pkg, flags & PKG_ADD_UPGRADE, flags & PKG_FLAG_FORCE); if (retcode != EPKG_OK) goto cleanup; /* MTREE replicates much of the standard functionality * inplicit in the way pkg works. It has to remain available * in the ports for compatibility with the old pkg_tools, but * ultimately, MTREE should be made redundant. Use this for * experimantal purposes and to develop MTREE-free versions of * packages. */ pkg_config_bool(PKG_CONFIG_DISABLE_MTREE, &disable_mtree); if (!disable_mtree) { pkg_get(pkg, PKG_PREFIX, &prefix, PKG_MTREE, &mtree); if ((retcode = do_extract_mtree(mtree, prefix)) != EPKG_OK) goto cleanup_reg; } /* * Execute pre-install scripts */ if ((flags & (PKG_ADD_NOSCRIPT | PKG_ADD_USE_UPGRADE_SCRIPTS)) == 0) pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL); /* add the user and group if necessary */ /* pkg_add_user_group(pkg); */ /* * Extract the files on disk. */ if (extract && (retcode = do_extract(a, ae)) != EPKG_OK) { /* If the add failed, clean up (silently) */ pkg_delete_files(pkg, 2); pkg_delete_dirs(db, pkg, 1); goto cleanup_reg; } /* * Execute post install scripts */ if ((flags & PKG_ADD_NOSCRIPT) == 0) { if ((flags & PKG_ADD_USE_UPGRADE_SCRIPTS) == PKG_ADD_USE_UPGRADE_SCRIPTS) pkg_script_run(pkg, PKG_SCRIPT_POST_UPGRADE); else pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL); } /* * start the different related services if the users do want that * and that the service is running */ pkg_config_bool(PKG_CONFIG_HANDLE_RC_SCRIPTS, &handle_rc); if (handle_rc) pkg_start_stop_rc_scripts(pkg, PKG_RC_START); cleanup_reg: if ((flags & PKG_ADD_UPGRADE) == 0) pkgdb_register_finale(db, retcode); if (retcode == EPKG_OK && (flags & PKG_ADD_UPGRADE) == 0) pkg_emit_install_finished(pkg); cleanup: if (a != NULL) { archive_read_close(a); archive_read_free(a); } pkg_free(pkg); if (pkg_inst != NULL) pkg_free(pkg_inst); return (retcode); }
int UnzipToDir( const WCHAR* zipFile, const WCHAR* unzipDir, const OnProgressCallback* progress, const WCHAR* password, bool opt_extract_without_path, bool clearOutputDirectory ) { unzFile uf = NULL; int err = -1; if ( ( zipFile != NULL ) && ( unzipDir != NULL ) ) { uf = unzOpenHelp (zipFile); } if ( uf != NULL ) { if ( clearOutputDirectory ) { ClearDirectory( unzipDir ); } #if defined(_WIN32) || defined (_WIN64) wchar_t* buffer = NULL; buffer = _wgetcwd( NULL, 0 ); err = _wchdir (unzipDir); #else char* buffer = NULL; buffer = getcwd( NULL, 0 ); BYTE* pUtf8 = NULL; LONG lLen = 0; NSFile::CUtf8Converter::GetUtf8StringFromUnicode(unzipDir, wcslen(unzipDir), pUtf8, lLen); err = chdir ((char*)pUtf8); RELEASEARRAYOBJECTS(pUtf8); #endif if ( err == 0 ) { if(NULL != password) { std::string passwordA = codepage_issue_fixToOEM(password); err = do_extract( uf, opt_extract_without_path, 1, passwordA.c_str(), progress ); } else err = do_extract( uf, opt_extract_without_path, 1, NULL, progress ); } if ( err == UNZ_OK ) { err = unzClose( uf ); } if ( buffer != NULL ) { #if defined(_WIN32) || defined (_WIN64) err = _wchdir( buffer ); #else err = chdir( buffer ); #endif free( buffer ); buffer = NULL; } } return err; }
int pkg_add(struct pkgdb *db, const char *path, unsigned flags) { const char *arch; const char *myarch; const char *origin; struct archive *a; struct archive_entry *ae; struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; struct pkg *pkg_inst = NULL; bool extract = true; bool handle_rc = false; char dpath[MAXPATHLEN + 1]; const char *basedir; const char *ext; char *mtree; char *prefix; int retcode = EPKG_OK; int ret; assert(path != NULL); /* * Open the package archive file, read all the meta files and set the * current archive_entry to the first non-meta file. * If there is no non-meta files, EPKG_END is returned. */ ret = pkg_open2(&pkg, &a, &ae, path); if (ret == EPKG_END) extract = false; else if (ret != EPKG_OK) { retcode = ret; goto cleanup; } if ((flags & PKG_ADD_UPGRADE) == 0) pkg_emit_install_begin(pkg); if (pkg_is_valid(pkg) != EPKG_OK) { pkg_emit_error("the package is not valid"); return (EPKG_FATAL); } if (flags & PKG_ADD_AUTOMATIC) pkg_set(pkg, PKG_AUTOMATIC, true); /* * Check the architecture */ pkg_config_string(PKG_CONFIG_ABI, &myarch); pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin); if (fnmatch(myarch, arch, FNM_CASEFOLD) == FNM_NOMATCH && strncmp(arch, myarch, strlen(myarch)) != 0) { pkg_emit_error("wrong architecture: %s instead of %s", arch, myarch); if ((flags & PKG_ADD_FORCE) == 0) { retcode = EPKG_FATAL; goto cleanup; } } /* * Check if the package is already installed */ ret = pkg_try_installed(db, origin, &pkg_inst, PKG_LOAD_BASIC); if (ret == EPKG_OK) { pkg_emit_already_installed(pkg_inst); retcode = EPKG_INSTALLED; goto cleanup; } else if (ret != EPKG_END) { retcode = ret; goto cleanup; } /* * Check for dependencies */ basedir = dirname(path); if ((ext = strrchr(path, '.')) == NULL) { pkg_emit_error("%s has no extension", path); retcode = EPKG_FATAL; goto cleanup; } while (pkg_deps(pkg, &dep) == EPKG_OK) { if (pkg_is_installed(db, pkg_dep_origin(dep)) != EPKG_OK) { const char *dep_name = pkg_dep_name(dep); const char *dep_ver = pkg_dep_version(dep); snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", basedir, dep_name, dep_ver, ext); if ((flags & PKG_ADD_UPGRADE) == 0 && access(dpath, F_OK) == 0) { ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC); if (ret != EPKG_OK) { retcode = EPKG_FATAL; goto cleanup; } } else { retcode = EPKG_FATAL; pkg_emit_missing_dep(pkg, dep); goto cleanup; } } } /* register the package before installing it in case there are * problems that could be caught here. */ if ((flags & PKG_ADD_UPGRADE) == 0) retcode = pkgdb_register_pkg(db, pkg, 0); else retcode = pkgdb_register_pkg(db, pkg, 1); if (retcode != EPKG_OK) goto cleanup; pkg_get(pkg, PKG_PREFIX, &prefix, PKG_MTREE, &mtree); if ((retcode = do_extract_mtree(mtree, prefix)) != EPKG_OK) goto cleanup_reg; /* * Execute pre-install scripts */ if ((flags & (PKG_ADD_NOSCRIPT | PKG_ADD_USE_UPGRADE_SCRIPTS)) == 0) pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL); /* add the user and group if necessary */ /* pkg_add_user_group(pkg); */ /* * Extract the files on disk. */ if (extract && (retcode = do_extract(a, ae)) != EPKG_OK) { /* If the add failed, clean up */ pkg_delete_files(pkg, 1); pkg_delete_dirs(db, pkg, 1); goto cleanup_reg; } /* * Execute post install scripts */ if ((flags & PKG_ADD_NOSCRIPT) == 0) { if (flags & PKG_ADD_USE_UPGRADE_SCRIPTS) pkg_script_run(pkg, PKG_SCRIPT_POST_UPGRADE); else pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL); } /* * start the different related services if the users do want that * and that the service is running */ pkg_config_bool(PKG_CONFIG_HANDLE_RC_SCRIPTS, &handle_rc); if (handle_rc) pkg_start_stop_rc_scripts(pkg, PKG_RC_START); cleanup_reg: if ((flags & PKG_ADD_UPGRADE) == 0) pkgdb_register_finale(db, retcode); if (retcode == EPKG_OK && (flags & PKG_ADD_UPGRADE) == 0) pkg_emit_install_finished(pkg); cleanup: if (a != NULL) archive_read_free(a); pkg_free(pkg); pkg_free(pkg_inst); return (retcode); }
int main(int argc,char *argv[]) { char zipfilename[MAXFILENAME]= {0}; char filename_to_extract[MAXFILENAME]= {0}; const char *password=NULL; char filename_try[MAXFILENAME+16] = ""; int i; int ret_value=0; int opt_do_list=0; int opt_do_extract=1; int opt_do_extract_withoutpath=0; int opt_overwrite=0; int opt_extractdir=0; char dirname[MAXFILENAME]= {0}; unzFile uf=NULL; do_banner(); if (argc==1) { do_help(); return 0; } else { for (i=1; i<argc; i++) { if ((*argv[i])=='-') { const char *p=argv[i]+1; while ((*p)!='\0') { char c=*(p++);; if ((c=='l') || (c=='L')) opt_do_list = 1; if ((c=='v') || (c=='V')) opt_do_list = 1; if ((c=='x') || (c=='X')) opt_do_extract = 1; if ((c=='e') || (c=='E')) opt_do_extract = opt_do_extract_withoutpath = 1; if ((c=='o') || (c=='O')) opt_overwrite=1; if ((c=='d') || (c=='D')) { opt_extractdir=1; strcat(dirname,__DIR__); strcat(dirname,"/"); strcat(dirname,argv[i+1]); } if (((c=='p') || (c=='P')) && (i+1<argc)) { password=argv[i+1]; i++; } } } else { if (!strlen(zipfilename)) { strcat(zipfilename,__DIR__); strcat(zipfilename,"/"); strcat(zipfilename,argv[i]); } else if ((!strlen(filename_to_extract)) && (!opt_extractdir)) { strcat(filename_to_extract,__DIR__); strcat(filename_to_extract,"/"); strcat(filename_to_extract,argv[i]); } } } } if (strlen(zipfilename)) { # ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; # endif strncpy(filename_try, zipfilename,MAXFILENAME-1); /* strncpy doesnt append the trailing NULL, of the string is too long. */ filename_try[ MAXFILENAME ] = 0; # ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); uf = unzOpen2_64(zipfilename,&ffunc); # else uf = unzOpen64(zipfilename); # endif if (uf==NULL) { strcat(filename_try,".zip"); # ifdef USEWIN32IOAPI uf = unzOpen2_64(filename_try,&ffunc); # else uf = unzOpen64(filename_try); # endif } } if (uf==NULL) { printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); return 1; } printf("%s opened\n",filename_try); if (opt_do_list==1) ret_value = do_list(uf); else if (opt_do_extract==1) { chdir(__DIR__); #ifdef _WIN32 if (opt_extractdir && _chdir(dirname)) #else if (opt_extractdir && chdir(dirname)) #endif { printf("Error changing into %s, aborting\n", dirname); exit(-1); } if (!strlen(filename_to_extract)) ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password); else ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password); } unzClose(uf); return ret_value; }
/* * Temporary usage: run_queries <index file> <type> [length] [V] */ int main (int argc, char *argv[]) { int error = 0; char *filename; char querytype; uint i; if (argc < 5) { print_search_usage(argv[0]); exit (1); } filename = argv[1]; querytype = *argv[2]; //parameters for intersect-operations char *params = NULL; int nchars, len; nchars = argc-5; //nchars = argc; for(i=3;i< (uint)argc;i++) nchars += strlen(argv[i]); params = (char *) malloc((nchars+1)*sizeof(char)); params[nchars] = '\0'; nchars = 0; for(i=4;i< (uint)argc;i++) { len = strlen(argv[i]); strncpy(params+nchars,argv[i],len); params[nchars+len] = ' '; nchars += len+1; } params[nchars-1] = '\0'; // end parameters /**/ timeFile = fopen("timesSearch.txt","a"); /**/ initResults(argv[1],argv[1]); /**/ /**/ fprintf(timeFile,"\n Searching!!: %s %s %s %s %s",argv[0],argv[1],argv[2],argv[3], params); Load_time = getTime (); error = load_il (filename, &Index); IFERRORIL (error); buildBell_il(Index, "golombRice_BitmapBellMoff.m"); Load_time = getTime () - Load_time; Load_time *= TIMEFACTOR_TO_SEC; fprintf (stderr, "Load index time = %.6f secs\n", Load_time); error = setDefaultSearchOptions_il (Index, params); IFERRORIL (error); error = size_il(Index, &Index_size); IFERRORIL (error); error = size_il_uncompressed(Index, &Uncompressed_Index_size); IFERRORIL (error); Index_size /=1024; fprintf(stderr,"Index size = %lu Kb\n", (ulong)Index_size); switch (querytype){ case EXTRACT: if (argc < 5) { print_search_usage(argv[0]); exit (1); } if (argc > 5) if (*argv[5] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", EXTRACT); } do_extract((uint) atoi(argv[3]), (uint) atoi(argv[4]) ); break; case EXTRACTNOMALLOC: if (argc < 5) { print_search_usage(argv[0]); exit (1); } if (argc > 5) if (*argv[5] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", EXTRACTNOMALLOC); } do_extract_no_malloc((uint) atoi(argv[3]), (uint) atoi(argv[4]) ); break; case INTERSECT2: if (argc < 5) { print_search_usage(argv[0]); exit (1); } if (argc > 5) if (*argv[5] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", INTERSECT2); } do_intersect2((uint) atoi(argv[3]), (uint) atoi(argv[4]) ); break; case INTERSECTN: if (argc < 5) { print_search_usage(argv[0]); exit (1); } if (argc > 5) if (*argv[5] == VERBOSE){ Verbose = 1; fprintf(stderr,"%c", INTERSECTN); } do_intersectN((uint) atoi(argv[3]), (uint) atoi(argv[4]) ); break; default: fprintf (stderr, "Unknow option: main ru\n"); exit (1); } error = free_il(Index); IFERRORIL(error); /**/ fclose(timeFile); free(params); return 0; }