예제 #1
0
파일: keys.c 프로젝트: jlsandell/tig
bool
add_run_request(struct keymap *keymap, int key, const char **argv, enum run_request_flag flags)
{
	bool force = flags & RUN_REQUEST_FORCE;
	struct run_request *req;

	if (!force && get_keybinding(keymap, key) != key)
		return TRUE;

	if (!realloc_run_requests(&run_request, run_requests, 1))
		return FALSE;

	if (!argv_copy(&run_request[run_requests].argv, argv))
		return FALSE;

	req = &run_request[run_requests++];
	req->silent = flags & RUN_REQUEST_SILENT;
	req->confirm = flags & RUN_REQUEST_CONFIRM;
	req->exit = flags & RUN_REQUEST_EXIT;
	req->internal = flags & RUN_REQUEST_INTERNAL;
	req->keymap = keymap;
	req->key = key;

	add_keybinding(keymap, REQ_RUN_REQUESTS + run_requests, key);
	return TRUE;
}
예제 #2
0
파일: options.c 프로젝트: jlsandell/tig
static enum status_code
parse_args(const char ***args, const char *argv[])
{
	if (!argv_copy(args, argv))
		return ERROR_OUT_OF_MEMORY;
	return SUCCESS;
}
예제 #3
0
void *
echo_open(int argc, char *argv[])
{
    char *p;

    if (argc < 2)
        return (NULL);

    if ((p = argv_copy(argv + 1)) == NULL)
        return (NULL);

    return (p);
}
예제 #4
0
파일: main.c 프로젝트: jrepan/rhombus
struct pipe_list *pipe_list_add(struct pipe_list *list, int argc, char **argv) {
	struct pipe_list *node;

	if (list) {
		list->next = pipe_list_add(list->next, argc, argv);
		return list;
	}
	else {
		node = malloc(sizeof(struct pipe_list));
		node->next = NULL;
		node->argv = argv_copy(argc, argv);

		return node;
	}
}
예제 #5
0
TEST(gtest_par_xml_output, main)
{
    // Sample command line initializer
    const std::string argv_init[]={
        std::string("program_name"),  // 0
        std::string("--some_option"), // 1
        std::string("--gtest_other=abc"), // 2
        std::string("--gtest_output=xmlsome-other-type"), // 3
        std::string("--gtest_output=xml"), // 4
        std::string("--gtest_output=xml:/some/dirname/"), // 5
        std::string("--gtest_output=xml:/some/filename"), // 6
        std::string("--gtest_output=xml:/some/filename.ext"), // 7
        std::string("--gtest_output=xml:/some/filename."), // 8
        std::string("--some_more_options") // 9
    };
    const int argc=sizeof(argv_init)/sizeof(*argv_init);

    // Copy of the command line
    std::vector<std::string> argv_copy(argc);
    std::copy(argv_init, argv_init+argc, argv_copy.begin());
    
    // Command line to be scanned
    char** argv=new char*[argc];
    for (int i=0; i<argc; ++i) {
        argv[i]=const_cast<char*>(argv_copy[i].c_str()); // dirty, but would work here
    }

    alps::gtest_par_xml_output tweak; // hold memory
    tweak(123, argc, argv); // do tweaking

    {
        // These arguments should stay intact
        int idx[]={0, 1, 2, 3, 9};
        for (int i=0; i<sizeof(idx)/sizeof(*idx); ++i) {
            int ii=idx[i];
            EXPECT_EQ(argv_init[ii], argv[ii]) << "Unexpected change in argv[" << ii << "]";
        }
    }
    
    // These arguments should change:
    EXPECT_EQ("--gtest_output=xml:test_details123.xml",   std::string(argv[4])) << "Wrong \"=xml\"";
    EXPECT_EQ("--gtest_output=xml:/some/dirname123/",     std::string(argv[5])) << "wrong xml=dir/";
    EXPECT_EQ("--gtest_output=xml:/some/filename123",     std::string(argv[6])) << "wrong xml=file";
    EXPECT_EQ("--gtest_output=xml:/some/filename123.ext", std::string(argv[7])) << "wrong xml=file.ext";
    EXPECT_EQ("--gtest_output=xml:/some/filename123.", std::string(argv[8])) << "wrong xml=file.";

    delete[] argv;
}
예제 #6
0
파일: options.c 프로젝트: MarkTseng/tig
int
load_options(void)
{
	const char *tigrc_user = getenv("TIGRC_USER");
	const char *tigrc_system = getenv("TIGRC_SYSTEM");
	const char *tig_diff_opts = getenv("TIG_DIFF_OPTS");
	const bool diff_opts_from_args = !!opt_diff_options;
	bool custom_tigrc_system = !!tigrc_system;

	opt_file_filter = TRUE;
	if (!find_option_info_by_value(&opt_diff_context)->seen)
		opt_diff_context = -3;

	if (!custom_tigrc_system)
		tigrc_system = SYSCONFDIR "/tigrc";

	if (!*tigrc_system ||
	    (load_option_file(tigrc_system) == ERROR_FILE_DOES_NOT_EXIST && !custom_tigrc_system)) {
		struct config_state config = { "<built-in>", 0, FALSE };
		struct io io;

		if (!io_from_string(&io, builtin_config))
			die("Failed to get built-in config");
		if (!io_load_span(&io, " \t", &config.lineno, read_option, &config) == ERR || config.errors == TRUE)
			die("Error in built-in config");
	}

	if (!tigrc_user)
		tigrc_user = "******";
	load_option_file(tigrc_user);

	if (!diff_opts_from_args && tig_diff_opts && *tig_diff_opts) {
		static const char *diff_opts[SIZEOF_ARG] = { NULL };
		char buf[SIZEOF_STR];
		int argc = 0;

		if (!string_format(buf, "%s", tig_diff_opts) ||
		    !argv_from_string(diff_opts, &argc, buf))
			die("TIG_DIFF_OPTS contains too many arguments");
		else if (!argv_copy(&opt_diff_options, diff_opts))
			die("Failed to format TIG_DIFF_OPTS arguments");
	}

	return OK;
}
예제 #7
0
파일: keys.c 프로젝트: bbolli/tig
enum status_code
add_run_request(struct keymap *keymap, struct key_input *input, const char **argv)
{
	struct run_request *req;
	struct run_request_flags flags = {};

	if (!strchr(":!?@<", *argv[0]))
		return error("Unknown request name: %s", argv[0]);

	while (*argv[0]) {
		if (*argv[0] == ':') {
			flags.internal = 1;
			argv[0]++;
			break;
		} else if (*argv[0] == '@') {
			flags.silent = 1;
		} else if (*argv[0] == '?') {
			flags.confirm = 1;
		} else if (*argv[0] == '<') {
			flags.exit = 1;
		} else if (*argv[0] != '!') {
			break;
		}
		argv[0]++;
	}

	if (!realloc_run_requests(&run_request, run_requests, 1))
		return ERROR_OUT_OF_MEMORY;

	if (!argv_copy(&run_request[run_requests].argv, argv))
		return ERROR_OUT_OF_MEMORY;

	req = &run_request[run_requests++];
	req->flags = flags;
	req->keymap = keymap;

	return add_keybinding(keymap, REQ_RUN_REQUESTS + run_requests, input);
}
예제 #8
0
파일: keys.c 프로젝트: acklinr/tig
enum status_code
add_run_request(struct keymap *keymap, const struct key key[],
		size_t keys, const char **argv)
{
	struct run_request *req;
	struct run_request_flags flags = {0};
	enum status_code code = parse_run_request_flags(&flags, argv);

	if (code != SUCCESS)
		return code;

	if (!realloc_run_requests(&run_request, run_requests, 1))
		return ERROR_OUT_OF_MEMORY;

	if (!argv_copy(&run_request[run_requests].argv, argv))
		return ERROR_OUT_OF_MEMORY;

	req = &run_request[run_requests++];
	req->flags = flags;
	req->keymap = keymap;

	return add_keybinding(keymap, REQ_RUN_REQUESTS + run_requests, key, keys);
}
예제 #9
0
파일: prompt.c 프로젝트: gonzus/tig
static enum status_code
prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
		     struct prompt_toggle *toggle, enum view_flag *flags)
{
	char name[SIZEOF_STR];

	if (!enum_name_prefixed(name, sizeof(name), prefix, toggle->name))
		return error("Failed to toggle option %s", toggle->name);

	*flags = toggle->flags;

	if (!strcmp(toggle->type, "bool")) {
		bool *opt = toggle->opt;

		*opt = !*opt;
		if (opt == &opt_mouse)
			enable_mouse(*opt);
		return success("set %s = %s", name, *opt ? "yes" : "no");

	} else if (!strncmp(toggle->type, "enum", 4)) {
		const char *type = toggle->type + STRING_SIZE("enum ");
		enum author *opt = toggle->opt;
		const struct enum_map *map = find_enum_map(type);

		*opt = (*opt + 1) % map->size;
		return success("set %s = %s", name, enum_name(map->entries[*opt].name));

	} else if (!strcmp(toggle->type, "int")) {
		const char *arg = argv[2] ? argv[2] : "1";
		int diff = atoi(arg);
		int *opt = toggle->opt;

		if (!diff)
			diff = *arg == '-' ? -1 : 1;

		if (opt == &opt_diff_context && *opt < 0)
			*opt = -*opt;
		if (opt == &opt_diff_context && diff < 0) {
			if (!*opt)
				return error("Diff context cannot be less than zero");
			if (*opt < -diff)
				diff = -*opt;
		}

		if (strstr(name, "commit-title-overflow")) {
			*opt = *opt ? -*opt : 50;
			if (*opt < 0)
				return success("set %s = no", name);
			diff = 0;
		}

		*opt += diff;
		return success("set %s = %d", name, *opt);

	} else if (!strcmp(toggle->type, "double")) {
		const char *arg = argv[2] ? argv[2] : "1.0";
		double *opt = toggle->opt;
		int sign = 1;
		double diff;

		if (*arg == '-') {
			sign = -1;
			arg++;
		}

		if (parse_step(&diff, arg) != SUCCESS)
			diff = strtod(arg, NULL);

		*opt += sign * diff;
		return success("set %s = %.2f", name, *opt);

	} else if (!strcmp(toggle->type, "const char **")) {
		const char ***opt = toggle->opt;
		bool found = TRUE;
		int i;

		if (argv_size(argv) <= 2) {
			argv_free(*opt);
			(*opt)[0] = NULL;
			return SUCCESS;
		}

		for (i = 2; argv[i]; i++) {
			if (!find_arg(*opt, argv[i])) {
				found = FALSE;
				break;
			}
		}

		if (found) {
			int next, pos;

			for (next = 0, pos = 0; (*opt)[pos]; pos++) {
				const char *arg = (*opt)[pos];

				if (find_arg(argv + 2, arg)) {
					free((void *) arg);
					continue;
				}
				(*opt)[next++] = arg;
			}

			(*opt)[next] = NULL;

		} else if (!argv_copy(opt, argv + 2)) {
			return ERROR_OUT_OF_MEMORY;
		}
		return SUCCESS;

	} else {
		return error("Unsupported `:toggle %s` (%s)", name, toggle->type);
	}
}
예제 #10
0
파일: prompt.c 프로젝트: bbolli/tig
static enum view_flag
prompt_toggle_option(struct view *view, const char *argv[],
		     struct prompt_toggle *toggle, char msg[SIZEOF_STR])
{
	char name[SIZEOF_STR];

	enum_name_copy(name, toggle->name, strlen(toggle->name));

	if (!strcmp(toggle->type, "bool")) {
		bool *opt = toggle->opt;

		*opt = !*opt;
		string_format_size(msg, SIZEOF_STR, "set %s = %s", name, *opt ? "yes" : "no");

	} else if (!strncmp(toggle->type, "enum", 4)) {
		const char *type = toggle->type + STRING_SIZE("enum ");
		enum author *opt = toggle->opt;
		const struct enum_map *map = find_enum_map(type);

		*opt = (*opt + 1) % map->size;
		string_format_size(msg, SIZEOF_STR, "set %s = %s", name,
				   enum_name(map->entries[*opt]));

	} else if (!strcmp(toggle->type, "int")) {
		const char *arg = argv[2] ? argv[2] : "1";
		int diff = atoi(arg);
		int *opt = toggle->opt;

		if (!diff)
			diff = *arg == '-' ? -1 : 1;

		if (opt == &opt_diff_context && diff < 0) {
			if (!*opt) {
				report("Diff context cannot be less than zero");
				return VIEW_NO_FLAGS;
			}
			if (*opt < -diff)
				diff = -*opt;
		}

		if (opt == &opt_title_overflow) {
			*opt = *opt ? -*opt : 50;
			if (*opt < 0) {
				string_format_size(msg, SIZEOF_STR, "set %s = no", name);
				return toggle->flags;
			}
		}

		*opt += diff;
		string_format_size(msg, SIZEOF_STR, "set %s = %d", name, *opt);

	} else if (!strcmp(toggle->type, "double")) {
		const char *arg = argv[2] ? argv[2] : "1.0";
		double *opt = toggle->opt;
		int sign = 1;
		double diff;

		if (*arg == '-') {
			sign = -1;
			arg++;
		}

		if (parse_step(&diff, arg) != SUCCESS)
			diff = strtod(arg, NULL);

		*opt += sign * diff;
		string_format_size(msg, SIZEOF_STR, "set %s = %.2f", name, *opt);

	} else if (!strcmp(toggle->type, "const char **")) {
		const char ***opt = toggle->opt;
		bool found = TRUE;
		int i;

		for (i = 2; argv[i]; i++) {
			if (!find_arg(*opt, argv[i])) {
				found = FALSE;
				break;
			}
		}

		if (found) {
			int next, pos;

			for (next = 0, pos = 0; (*opt)[pos]; pos++) {
				const char *arg = (*opt)[pos];

				if (find_arg(argv + 2, arg)) {
					free((void *) arg);
					continue;
				}
				(*opt)[next++] = arg;
			}

			(*opt)[next] = NULL;

		} else if (!argv_copy(opt, argv + 2)) {
			report("Failed to append arguments");
			return VIEW_NO_FLAGS;
		}

	} else {
		die("Unsupported `:toggle %s` (%s)", name, toggle->type);
	}

	return toggle->flags;
}