rc_t CC KMain(int argc, char *argv[]) { static const char *help[] = { "--help", "-h", "-?", NULL }; static const char *vers[] = { "--version", "-V", NULL }; bool const has_help = has_arg(help, argc, argv); bool const has_vers = has_arg(vers, argc, argv); XMLLogger const *logger = NULL; int argfirst = 0; int arglast = 0; rc_t rc = 0; unsigned load = 0; if (has_help) { argc = 2; argv[1] = "--help"; return main_help_vers(argc, argv); } if (has_vers) { argc = 2; argv[1] = "--version"; return main_help_vers(argc, argv); } logger = make_logger(&argc, argv); memset(&G, 0, sizeof(G)); G.mode = mode_Archive; G.globalMode = mode_Archive; G.maxSeqLen = TableWriterRefSeq_MAX_SEQ_LEN; G.schemaPath = strdup(SCHEMAFILE); G.omit_aligned_reads = true; G.omit_reference_reads = true; G.minMapQual = 0; /* accept all */ G.tmpfs = strdup("/tmp"); G.cache_size = ((size_t)16) << 30; G.maxErrCount = 1000; G.minMatchCount = 10; set_pid(); for (arglast = 1; arglast < argc; ++arglast) { if (strcmp(argv[arglast], "--remap") == 0) { argv[arglast] = argv[0]; G.globalMode = mode_Remap; rc = main_1(arglast - argfirst, argv + argfirst, true, load); if (rc) break; G.mode = mode_Remap; argfirst = arglast; ++load; } } rc = main_1(arglast - argfirst, argv + argfirst, false, load); XMLLogger_Release(logger); cleanupGlobal(); return rc; }
std::string read_format_with_args(const std::string &fmt, size_t &index, bool &width_arg, bool &precision_arg, Format &format) { size_t start = index++, len = fmt.length(); while (index < len && check_flags(fmt[index])) { index++; } if (fmt[index] == '*' || isdigit(fmt[index])) { width_arg = has_arg(fmt, index); } if (fmt[index] == '.') { precision_arg = has_arg(fmt, ++index); } check_specifier(fmt, index); format = get_format(fmt, index); return fmt.substr(start, index - start); }
void column_justify() { vunits height; if (!the_column->is_active()) error("can't justify column - column not active"); else if (get_vunits(&height, 'v')) { justification_spec js(height); symbol nm = get_long_name(1); if (!nm.is_null()) { vunits v; if (get_vunits(&v, 'v')) { js.append(nm, v); int err = 0; while (has_arg()) { nm = get_long_name(1); if (nm.is_null()) { err = 1; break; } if (!get_vunits(&v, 'v')) { err = 1; break; } js.append(nm, v); } if (!err) the_column->justify(js); } } } skip_line(); }
void fcgi_upgrade_2_1_4(void) { rc_ty s; const sx_hashfs_volume_t *vol = NULL; const char *startname, *startrev = NULL; struct rplfiles ctx; if(!has_arg("maxrev")) quit_errmsg(400, "Parameter maxrev is required"); startname = strchr(path, '/'); if(!startname) { s = sx_hashfs_volume_by_name(hashfs, path, &vol); } else { unsigned int vnamelen = startname - path; char *vname = malloc(vnamelen + 1); if(!vname) quit_errmsg(503, "Out of memory"); memcpy(vname, path, vnamelen); vname[vnamelen] = '\0'; s = sx_hashfs_volume_by_name(hashfs, vname, &vol); free(vname); startname++; if(strlen(startname)) startrev = get_arg("startrev"); else startname = NULL; } if(s != OK) quit_errmsg(rc2http(s), msg_get_reason()); if(!sx_hashfs_is_or_was_my_volume(hashfs, vol, 0)) quit_errnum(404); ctx.bytes_sent = 0; ctx.b = sx_blob_new(); if(!ctx.b) quit_errmsg(503, "Out of memory"); s = sx_hashfs_file_find(hashfs, vol, startname, startrev, get_arg("maxrev"), upgrade_2_1_4_cb, &ctx); if(s == FAIL_ETOOMANY || s == ITER_NO_MORE) { sx_blob_reset(ctx.b); if(!sx_blob_add_string(ctx.b, "$FILE$") && !sx_blob_add_string(ctx.b, ctx.lastfile.name) && !sx_blob_add_string(ctx.b, ctx.lastfile.revision)) send_rplfiles_header(&ctx); } if(s == ITER_NO_MORE) { sx_blob_reset(ctx.b); if(!sx_blob_add_string(ctx.b, "$THEEND$")) send_rplfiles_header(&ctx); sx_blob_free(ctx.b); return; } sx_blob_free(ctx.b); if(s != FAIL_ETOOMANY && !ctx.bytes_sent) quit_errmsg(rc2http(s), msg_get_reason()); }
void page_length() { vunits n; if (has_arg() && get_vunits(&n, 'v', topdiv->get_page_length())) topdiv->set_page_length(n); else topdiv->set_page_length(11*units_per_inch); skip_line(); }
void vertical_position_traps() { int n; if (has_arg() && get_integer(&n)) vertical_position_traps_flag = (n != 0); else vertical_position_traps_flag = 1; skip_line(); }
void need_space() { vunits n; if (!has_arg() || !get_vunits(&n, 'v')) n = curenv->get_vertical_spacing(); while (!tok.newline() && !tok.eof()) tok.next(); curdiv->need(n); tok.next(); }
void save_vertical_space() { vunits x; if (!has_arg() || !get_vunits(&x, 'v')) x = curenv->get_vertical_spacing(); if (curdiv->distance_to_next_trap() > x) curdiv->space(x, 1); else saved_space = x; skip_line(); }
void change_trap() { symbol s = get_name(1); if (!s.is_null()) { vunits x; if (has_arg() && get_vunits(&x, 'v')) topdiv->change_trap(s, x); else topdiv->remove_trap(s); } skip_line(); }
void page_number() { int n; // the ps4html register is set if we are using -Tps // to generate images for html reg *r = (reg *)number_reg_dictionary.lookup("ps4html"); if (r == NULL) if (has_arg() && get_integer(&n, topdiv->get_page_number())) topdiv->set_next_page_number(n); skip_line(); }
void begin_page() { int got_arg = 0; int n = 0; /* pacify compiler */ if (has_arg() && get_integer(&n, topdiv->get_page_number())) got_arg = 1; while (!tok.newline() && !tok.eof()) tok.next(); if (curdiv == topdiv) { if (topdiv->before_first_page) { if (!break_flag) { if (got_arg) topdiv->set_next_page_number(n); if (got_arg || !topdiv->no_space_mode) topdiv->begin_page(); } else if (topdiv->no_space_mode && !got_arg) topdiv->begin_page(); else { /* Given this .wh 0 x .de x .tm \\n% .. .bp 3 troff prints 1 3 This code makes groff do the same. */ push_page_ejector(); topdiv->begin_page(); if (got_arg) topdiv->set_next_page_number(n); topdiv->set_ejecting(); } } else { push_page_ejector(); if (break_flag) curenv->do_break(); if (got_arg) topdiv->set_next_page_number(n); if (!(topdiv->no_space_mode && !got_arg)) topdiv->set_ejecting(); } } tok.next(); }
void page_offset() { hunits n; // The troff manual says that the default scaling indicator is v, // but it is in fact m: v wouldn't make sense for a horizontally // oriented request. if (!has_arg() || !get_hunits(&n, 'm', topdiv->page_offset)) n = topdiv->prev_page_offset; topdiv->prev_page_offset = topdiv->page_offset; topdiv->page_offset = n; topdiv->modified_tag.incl(MTSM_PO); skip_line(); }
void diversion_trap() { vunits n; if (has_arg() && get_vunits(&n, 'v')) { symbol s = get_name(); if (!s.is_null()) curdiv->set_diversion_trap(s, n); else curdiv->clear_diversion_trap(); } else curdiv->clear_diversion_trap(); skip_line(); }
void space_request() { postpone_traps(); if (break_flag) curenv->do_break(); vunits n; if (!has_arg() || !get_vunits(&n, 'v')) n = curenv->get_vertical_spacing(); while (!tok.newline() && !tok.eof()) tok.next(); if (!unpostpone_traps() && !curdiv->no_space_mode) curdiv->space(n); else // The line might have had line spacing that was truncated. truncated_space += n; tok.next(); }
void return_request() { vunits dist = curdiv->marked_place - curdiv->get_vertical_position(); if (has_arg()) { if (tok.ch() == '-') { tok.next(); vunits x; if (get_vunits(&x, 'v')) dist = -x; } else { vunits x; if (get_vunits(&x, 'v')) dist = x >= V0 ? x - curdiv->get_vertical_position() : V0; } } if (dist < V0) curdiv->space(dist); skip_line(); }
int main(int argc, char **argv) { int done; t_env *tenv; extern char **environ; if (argc < 1) { ft_putendl("How did you get this far?"); return (1); } done = 0; tenv = get_env(environ); if (has_arg(argv, 'c') == 1) ft_putstr(TRM_CLR); while (done == 0) done = loop(tenv); free_tenv(tenv); return (0); }
void define_number_reg() { symbol nm = get_name(1); if (nm.is_null()) { skip_line(); return; } reg *r = (reg *)number_reg_dictionary.lookup(nm); units v; units prev_value; if (!r || !r->get_value(&prev_value)) prev_value = 0; if (get_number(&v, 'u', prev_value)) { if (r == 0) { r = new number_reg; number_reg_dictionary.define(nm, r); } r->set_value(v); if (tok.space() && has_arg() && get_number(&v, 'u')) r->set_increment(v); } skip_line(); }
int _tmain(int argc, _TCHAR* argv[]) { int i; DWORD failures = 0; ULONGLONG size = 0; DWORD err; TCHAR *f; TCHAR sSize[64]; parsed_args* args = parse_args(argc, argv); BOOL oneVolumeOnly = has_arg(args, TEXT("one-volume-only"), TEXT('\0')); PSID sid = NULL; PACL acl = NULL; BOOL takeownership; EXPLICIT_ACCESS ea[1]; if (!args->file_count) { _ftprintf(stderr, TEXT("Usage: %s [options] file1 [file2 ...]\n\n"), args->program); _ftprintf(stderr, TEXT(" The files can be directories, files, or simple wildcards\n\n")); _ftprintf(stderr, TEXT(" Options:\n")); _ftprintf(stderr, TEXT(" --one-volume-only do not delete files on other volumes when\n junctions/symbolic links/mount points are found")); return 1; } takeownership = EnableTakeOwnershipPriv(); if (!takeownership) { _ftprintf(stderr, TEXT("! Failed to enable the Take Ownership privilege\n")); _ftprintf(stderr, TEXT("Make sure you are an Administrator or elevated\n")); _ftprintf(stderr, TEXT("We will still try to delete the files\n")); } sid = GetCurrentSID(); if (!sid) { _ftprintf(stderr, TEXT("! Failed to get the current user's SID\n")); _ftprintf(stderr, TEXT("We will still try to delete the files\n")); } else { // Explicit Access: All Access ZeroMemory(&ea, 1*sizeof(EXPLICIT_ACCESS)); ea[0].grfAccessPermissions = GENERIC_ALL; ea[0].grfAccessMode = SET_ACCESS; ea[0].grfInheritance = SUB_OBJECTS_ONLY_INHERIT; ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID; ea[0].Trustee.TrusteeType = TRUSTEE_IS_USER; ea[0].Trustee.ptstrName = (LPTSTR)sid; // Create the ACL err = SetEntriesInAcl(1, ea, NULL, &acl); if (err != ERROR_SUCCESS) { LogError(TEXT("SetEntriesInAcl"), err); } } files = vector_create(64); // Find all files to delete for (i = 0; i < args->file_count; i++) { DWORD attrib = GetFileAttributes(args->files[i]); if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)) { vector_append(files, copyStr(args->files[i])); if (oneVolumeOnly && (attrib & FILE_ATTRIBUTE_REPARSE_POINT) && FileChangesVolume(args->files[i])) { continue; } } FindFiles(args->files[i], FALSE, oneVolumeOnly); } // Leave now if there is nothing to delete if (files->length == 0) { _tprintf(TEXT("No files found\n")); vector_destroy(files, TRUE); return 0; } // Correct security and delete files / directories for (i = files->length-1; i >= 0; i--) { WIN32_FILE_ATTRIBUTE_DATA attrib; BY_HANDLE_FILE_INFORMATION info; DWORD volumeSN = 0; f = (TCHAR*)files->x[i]; if (!GetFileAttributesEx(f, GetFileExInfoStandard, &attrib)) continue; CorrectSecurity(f, attrib.dwFileAttributes, takeownership, sid, acl, oneVolumeOnly); if (attrib.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (!RemoveDirectory(f) && (err = DeleteWithSH(f)) != 0) { LogFileError(TEXT("Failed to delete folder"), f, err); failures++; } } else { if (!DeleteFile(f) && (err = DeleteWithSH(f)) != 0) { LogFileError(TEXT("Failed to delete file"), f, GetLastError()); failures++; } else { size += attrib.nFileSizeLow; size += ((ULONGLONG)attrib.nFileSizeHigh) << 32; } } } // Show results if (size < 1000) _sntprintf(sSize, 64, TEXT("%I64d bytes"), size); else if (size < 1000000) _sntprintf(sSize, 64, TEXT("%.2f KB"), size / 1024.0); else if (size < 1000000000) _sntprintf(sSize, 64, TEXT("%.2f MB"), size / 1024 / 1024.0); else _sntprintf(sSize, 64, TEXT("%.2f GB"), size / 1024 / 1024 / 1024.0); _tprintf(TEXT("Deleted %d files (%s)\n"), files->length-failures, sSize); if (failures > 0) _tprintf(TEXT("Failed to delete %d files\n"), failures); // Cleanup vector_destroy(files, TRUE); LocalFree(acl); LocalFree(sid); free_parsed_args(args); return 0; }
void fcgi_create_file(void) { const struct jparse_actions acts = { JPACTS_INT64( JPACT(cb_newfile_size, JPKEY("fileSize")) ), JPACTS_STRING( JPACT(cb_newfile_block, JPKEY("fileData"), JPANYITM), JPACT(cb_newfile_addmeta, JPKEY("fileMeta"), JPANYKEY) ), JPACTS_NULL( JPACT(cb_newfile_delmeta, JPKEY("fileMeta"), JPANYKEY) ) }; struct cb_newfile_ctx yctx; jparse_t *J; int len; rc_ty s; sx_hash_t revid; quit_unless_has(PRIV_CLUSTER); /* Just in case */ if(!has_arg("rev") || !has_arg("revid") || strlen(get_arg("revid")) != SXI_SHA1_TEXT_LEN) quit_errmsg(500, "File revision missing"); if(hex2bin(get_arg("revid"), SXI_SHA1_TEXT_LEN, revid.b, sizeof(revid.b))) quit_errmsg(400, "Failed to parse revision ID"); s = sx_hashfs_createfile_begin(hashfs); switch (s) { case OK: break; case ENOENT: quit_errnum(404); case EINVAL: quit_errnum(400); default: WARN("sx_hashfs_createfile_begin failed: %d", s); quit_errmsg(rc2http(s), "Cannot initialize file upload"); } yctx.filesize = -1; yctx.rc = EINVAL; J = sxi_jparse_create(&acts, &yctx, 0); if(!J) { sx_hashfs_createfile_end(hashfs); quit_errmsg(503, "Cannot create JSON parser"); } while((len = get_body_chunk(hashbuf, sizeof(hashbuf))) > 0) if(sxi_jparse_digest(J, hashbuf, len)) break; if(len || sxi_jparse_done(J)) { send_error(rc2http(yctx.rc), sxi_jparse_geterr(J)); sx_hashfs_createfile_end(hashfs); sxi_jparse_destroy(J); return; } sxi_jparse_destroy(J); auth_complete(); quit_unless_authed(); s = sx_hashfs_createfile_commit(hashfs, volume, path, get_arg("rev"), &revid, yctx.filesize, 0); if(s != OK) quit_errmsg(rc2http(s), msg_get_reason()); CGI_PUTS("\r\n"); }
void Options::parse(int& argc, char**& argv) { int current = 1; int nextKeep = 1; while (current != argc) { std::match_results<const char*> result; std::regex_match(argv[current], result, option_matcher); if (result.empty()) { //not a flag //if true is returned here then it was consumed, otherwise it is //ignored if (consume_positional(argv[current])) { } else { argv[nextKeep] = argv[current]; ++nextKeep; } //if we return from here then it was parsed successfully, so continue } else { //short or long option? if (result[4].length() != 0) { std::string s = result[4]; for (int i = 0; i != s.size(); ++i) { std::string name(1, s[i]); auto iter = m_options.find(name); if (iter == m_options.end()) { throw option_not_exists_exception(name); } auto value = iter->second; //if no argument then just add it if (!value->has_arg()) { parse_option(value, name); } else { //it must be the last argument if (i + 1 == s.size()) { checked_parse_arg(argc, argv, current+1, value, name); ++current; } else { //error throw option_requires_argument_exception(name); } } } } else if (result[1].length() != 0) { std::string name = result[1]; auto iter = m_options.find(name); if (iter == m_options.end()) { throw option_not_exists_exception(name); } auto opt = iter->second; //equals provided for long option? if (result[3].length() != 0) { //parse the option given //but if it doesn't take an argument, this is an error if (!opt->has_arg()) { throw option_not_has_argument_exception(name, result[3]); } parse_option(opt, name, result[3]); } else { if (opt->has_arg()) { //parse the next argument checked_parse_arg(argc, argv, current + 1, opt, name); ++current; } else { //parse with empty argument parse_option(opt, name); } } } } ++current; } argc = nextKeep; }