void nemo_main() { string *tags; dprintf(2,"TSF: MaxSetLen = %d\n",MaxSetLen); /* DEBUG - PJT */ instr = stropen(getparam("in"), "r"); maxprec = getbparam("maxprec"); maxline = getiparam("maxline"); indent = getiparam("indent"); #ifdef unix if(!hasvalue("margin")) { struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); margin = w.ws_col; } else #endif margin = getiparam("margin"); allline = getbparam("allline"); if (hasvalue("item")) warning("item= is broken"); testtag = getparam("item"); xml = getbparam("xml"); if (xml) { /* if XML output used, it should print all items */ allline = TRUE; printf("<nemo>\n"); } octal = getbparam("octal"); while ((tags = list_tags(instr)) != NULL) { print_item(*tags); free(*tags); free((char *)tags); } if (xml) printf("</nemo>\n"); }
void print_item(string tag) { string type, *tags, *tp; int *dims; type = get_type(instr, tag); if (streq(type, SetType)) { get_set(instr, tag); print_set(tag); tags = list_tags(instr); for (tp = tags; *tp != NULL; tp++) print_item(*tp); get_tes(instr, tag); print_tes(tag); for (tp = tags; *tp != NULL; tp++) free(*tp); free((char *)tags); } else { dims = get_dims(instr, tag); print_header(tag, type, dims); (void) outstr(" "); print_data(tag, type, dims); end_line(); if (dims != NULL) free((char *)dims); } free(type); }
void nemo_main(void) { stream instr, outstr, nullstr; string item, *items; string *tags, *sels, *cvt; int i, nsel, select[MAXSEL], cntrd, cntwr; bool all; instr = stropen(getparam("in"), "r"); nullstr = stropen("/dev/null","w+"); /* kludge: force write */ item = getparam("item"); sels = burststring(getparam("select"),", "); nsel = xstrlen(sels, sizeof(string)) - 1; for (i=0; i<nsel; i++) { /* note: array should be sorted */ select[i] = atoi(sels[i]); dprintf(1,"#selected #%d\n",select[i]); if (select[i]<1) error("%d: bad number for select=, must be > 0",select[i]); if (i>0 && (select[i]<select[i-1])) error("%d: bad number for select=, array must be sorted",select[i]); } cvt = burststring(getparam("convert"),", "); if (*item == 0) { all = TRUE; items = (string *) allocate(sizeof(string)); /* PPAP */ items[0] = NULL; } else { all = FALSE; items = burststring(item,", "); if (items==NULL) error("error parsing item=%s\n",item); dprintf(1,"selected: "); for (i=0; items[i]!=NULL; i++) dprintf(1," %s",items[i]); dprintf(1,"\n\n"); } outstr = stropen(getparam("out"), "w"); cntrd = 0; /* keep track of items read */ cntwr = 0; /* and written */ while ((tags = list_tags(instr)) != NULL) { if (check(items, *tags)) { cntrd++; dprintf(1," %d: %s",cntrd,*tags); if (nsel==0 || (nsel>0 && select[cntwr] == cntrd)) { copy_item_cvt(outstr, instr, *tags, cvt); cntwr++; dprintf(1," copied\n"); } else { copy_item(nullstr, instr, *tags); dprintf(1," skipped\n"); } } else { dprintf(1," *: %s",*tags); copy_item(nullstr, instr, *tags); dprintf(1," skipped\n"); } free((char *)*tags); free((char *)tags); if (nsel>0 && cntwr >= nsel) /* early bailout ? */ break; } dprintf(0,"On top-level: %d items read, %d items written\n",cntrd,cntwr); strclose(instr); strclose(outstr); }
int main(int argc, char **argv) { char buf[1024]; int set_b = 0; char *log_path, *loc_start_file; const char *env_str; DMALLOC_PNT addr; unsigned long inter, limit_val, loc_start_size, loc_start_iter; long addr_count; int lock_on; int loc_start_line; unsigned int flags; argv_help_string = "Sets dmalloc library env variables. Also try --usage."; argv_version_string = dmalloc_version; argv_process(args, argc, argv); if (help_b) { header(); (void)fprintf(stderr, " For a list of the command-line options enter: %s --usage\n", argv_argv[0]); exit(0); } if (usage_b) { header(); argv_usage(args, ARGV_USAGE_ALL); exit(0); } if (very_verbose_b) { verbose_b = 1; } /* try to figure out the shell we are using */ if ((! bourne_b) && (! cshell_b) && (! gdb_b) && (! rcshell_b)) { choose_shell(); } /* get the current debug information from the env variable */ env_str = getenv(OPTIONS_ENVIRON); if (env_str == NULL) { env_str = ""; } _dmalloc_environ_process(env_str, &addr, &addr_count, &flags, &inter, &lock_on, &log_path, &loc_start_file, &loc_start_line, &loc_start_iter, &loc_start_size, &limit_val); /* * So, if a tag was specified on the command line then we set the * debug from it. If it was not then we see if the debug flags were * set as a hex value from the -d. If this was not used then take * the current value. */ if (tag == NULL) { if (argv_was_used(args, DEBUG_ARG)) { set_b = 1; /* should we clear the rest? */ if (remove_auto_b && (! keep_b)) { clear_b = 1; } } else { debug = flags; } } else { if (argv_was_used(args, DEBUG_ARG)) { (void)fprintf(stderr, "%s: warning -d ignored, processing tag '%s'\n", argv_program, tag); } set_b = 1; debug = find_tag(0L, tag, NULL, 0); /* should we clear the rest? */ if (remove_auto_b && (! keep_b)) { clear_b = 1; } } if (plus.aa_entry_n > 0) { int plus_c; for (plus_c = 0; plus_c < plus.aa_entry_n; plus_c++) { BIT_SET(debug, token_to_value(ARGV_ARRAY_ENTRY(plus, char *, plus_c))); set_b = 1; } } if (minus.aa_entry_n > 0) { int minus_c; for (minus_c = 0; minus_c < minus.aa_entry_n; minus_c++) { BIT_CLEAR(debug, token_to_value(ARGV_ARRAY_ENTRY(minus, char *, minus_c))); set_b = 1; } } if (address != NULL) { _dmalloc_address_break(address, &addr, &addr_count); set_b = 1; } else if (clear_b) { addr = NULL; } if (argv_was_used(args, INTERVAL_ARG)) { inter = interval; set_b = 1; } else if (clear_b) { inter = 0; } /* * NOTE: this should be after the debug setting which this tests. */ if (argv_was_used(args, THREAD_LOCK_ON_ARG)) { lock_on = thread_lock_on; set_b = 1; } else if (clear_b) { lock_on = 0; } if (logpath != NULL) { log_path = logpath; set_b = 1; } else if (clear_b) { log_path = NULL; } if (start_file != NULL) { _dmalloc_start_break(start_file, &loc_start_file, &loc_start_line, &loc_start_iter, &loc_start_size); set_b = 1; } else if (start_iter > 0) { loc_start_file = NULL; loc_start_line = 0; loc_start_iter = start_iter; loc_start_size = 0; set_b = 1; } else if (start_size > 0) { loc_start_file = NULL; loc_start_line = 0; loc_start_iter = 0; loc_start_size = start_size; set_b = 1; } else if (clear_b) { loc_start_file = NULL; loc_start_line = 0; loc_start_iter = 0; loc_start_size = 0; } if (argv_was_used(args, LIMIT_ARG)) { limit_val = limit_arg; set_b = 1; } if (errno_to_print > 0) { (void)fprintf(stderr, "%s: dmalloc_errno value '%d' = \n", argv_program, errno_to_print); (void)fprintf(stderr, " '%s'\n", local_strerror(errno_to_print)); } if (list_tags_b) { list_tags(); } if (debug_tokens_b) { attr_t *attr_p; unsigned int left = 0x7fffffff; (void)fprintf(stderr, "Debug Tokens:\n"); for (attr_p = attributes; attr_p->at_string != NULL; attr_p++) { /* skip any disabled tokens */ if (attr_p->at_value == 0 && strcmp(attr_p->at_string, "none") != 0) { continue; } if (attr_p->at_value != 0 && (! BIT_IS_SET(left, attr_p->at_value))) { /* skip any tokens we've seen before */ continue; } if (very_verbose_b) { (void)fprintf(stderr, "%s -- %s (%#lx)\n", attr_p->at_string, attr_p->at_desc, attr_p->at_value); } else if (verbose_b) { (void)fprintf(stderr, "%s -- %s\n", attr_p->at_string, attr_p->at_desc); } else { (void)fprintf(stderr, "%s\n", attr_p->at_string); } BIT_CLEAR(left, attr_p->at_value); } } if (clear_b || set_b) { _dmalloc_environ_set(buf, sizeof(buf), long_tokens_b, addr, addr_count, debug, inter, lock_on, log_path, loc_start_file, loc_start_line, loc_start_iter, loc_start_size, limit_val); set_variable(OPTIONS_ENVIRON, buf); } else if (errno_to_print == 0 && (! list_tags_b) && (! debug_tokens_b)) { dump_current(); } argv_cleanup(args); exit(0); }
int cmd_tag(int argc, const char **argv, const char *prefix) { struct strbuf buf = STRBUF_INIT; struct strbuf ref = STRBUF_INIT; unsigned char object[20], prev[20]; const char *object_ref, *tag; struct create_tag_options opt; char *cleanup_arg = NULL; int create_reflog = 0; int annotate = 0, force = 0; int cmdmode = 0, create_tag_object = 0; const char *msgfile = NULL, *keyid = NULL; struct msg_arg msg = { 0, STRBUF_INIT }; struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; struct ref_filter filter; static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting; const char *format = NULL; struct option options[] = { OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'), { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"), N_("print <n> lines of each tag message"), PARSE_OPT_OPTARG, NULL, 1 }, OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'), OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'), OPT_GROUP(N_("Tag creation options")), OPT_BOOL('a', "annotate", &annotate, N_("annotated tag, needs a message")), OPT_CALLBACK('m', "message", &msg, N_("message"), N_("tag message"), parse_msg_arg), OPT_FILENAME('F', "file", &msgfile, N_("read message from file")), OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")), OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"), N_("how to strip spaces and #comments from message")), OPT_STRING('u', "local-user", &keyid, N_("key-id"), N_("use another key to sign the tag")), OPT__FORCE(&force, N_("replace the tag if exists")), OPT_BOOL(0, "create-reflog", &create_reflog, N_("create a reflog")), OPT_GROUP(N_("Tag listing options")), OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")), OPT_CONTAINS(&filter.with_commit, N_("print only tags that contain the commit")), OPT_WITH(&filter.with_commit, N_("print only tags that contain the commit")), OPT_MERGED(&filter, N_("print only tags that are merged")), OPT_NO_MERGED(&filter, N_("print only tags that are not merged")), OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"), N_("field name to sort on"), &parse_opt_ref_sorting), { OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"), N_("print only tags of the object"), 0, parse_opt_object_name }, OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")), OPT_END() }; git_config(git_tag_config, sorting_tail); memset(&opt, 0, sizeof(opt)); memset(&filter, 0, sizeof(filter)); filter.lines = -1; argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0); if (keyid) { opt.sign = 1; set_signing_key(keyid); } create_tag_object = (opt.sign || annotate || msg.given || msgfile); if (argc == 0 && !cmdmode) cmdmode = 'l'; if ((create_tag_object || force) && (cmdmode != 0)) usage_with_options(git_tag_usage, options); finalize_colopts(&colopts, -1); if (cmdmode == 'l' && filter.lines != -1) { if (explicitly_enable_column(colopts)) die(_("--column and -n are incompatible")); colopts = 0; } if (!sorting) sorting = ref_default_sorting(); if (cmdmode == 'l') { int ret; if (column_active(colopts)) { struct column_options copts; memset(&copts, 0, sizeof(copts)); copts.padding = 2; run_column_filter(colopts, &copts); } filter.name_patterns = argv; ret = list_tags(&filter, sorting, format); if (column_active(colopts)) stop_column_filter(); return ret; } if (filter.lines != -1) die(_("-n option is only allowed with -l.")); if (filter.with_commit) die(_("--contains option is only allowed with -l.")); if (filter.points_at.nr) die(_("--points-at option is only allowed with -l.")); if (filter.merge_commit) die(_("--merged and --no-merged option are only allowed with -l")); if (cmdmode == 'd') return for_each_tag_name(argv, delete_tag); if (cmdmode == 'v') return for_each_tag_name(argv, verify_tag); if (msg.given || msgfile) { if (msg.given && msgfile) die(_("only one -F or -m option is allowed.")); if (msg.given) strbuf_addbuf(&buf, &(msg.buf)); else { if (!strcmp(msgfile, "-")) { if (strbuf_read(&buf, 0, 1024) < 0) die_errno(_("cannot read '%s'"), msgfile); } else { if (strbuf_read_file(&buf, msgfile, 1024) < 0) die_errno(_("could not open or read '%s'"), msgfile); } } } tag = argv[0]; object_ref = argc == 2 ? argv[1] : "HEAD"; if (argc > 2) die(_("too many params")); if (get_sha1(object_ref, object)) die(_("Failed to resolve '%s' as a valid ref."), object_ref); if (strbuf_check_tag_ref(&ref, tag)) die(_("'%s' is not a valid tag name."), tag); if (read_ref(ref.buf, prev)) hashclr(prev); else if (!force) die(_("tag '%s' already exists"), tag); opt.message_given = msg.given || msgfile; if (!cleanup_arg || !strcmp(cleanup_arg, "strip")) opt.cleanup_mode = CLEANUP_ALL; else if (!strcmp(cleanup_arg, "verbatim")) opt.cleanup_mode = CLEANUP_NONE; else if (!strcmp(cleanup_arg, "whitespace")) opt.cleanup_mode = CLEANUP_SPACE; else die(_("Invalid cleanup mode %s"), cleanup_arg); if (create_tag_object) { if (force_sign_annotate && !annotate) opt.sign = 1; create_tag(object, tag, &buf, &opt, prev, object); } transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, ref.buf, object, prev, create_reflog ? REF_FORCE_CREATE_REFLOG : 0, NULL, &err) || ref_transaction_commit(transaction, &err)) die("%s", err.buf); ref_transaction_free(transaction); if (force && !is_null_sha1(prev) && hashcmp(prev, object)) printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV)); strbuf_release(&err); strbuf_release(&buf); strbuf_release(&ref); return 0; }