Esempio n. 1
0
int main(int argc, char **argv)
{
	int	ac, ret;
	char	**av, **cpp;
	char	buf[256];

	while (!feof(stdin)) {
		if (fgets(buf, sizeof(buf), stdin) == NULL)
			break;
		ret = argv_parse(buf, &ac, &av);
		if (ret != 0) {
			printf("Argv_parse returned %d!\n", ret);
			continue;
		}
		printf("Argv_parse returned %d arguments...\n", ac);
		for (cpp = av; *cpp; cpp++) {
			if (cpp != av)
				printf(", ");
			printf("'%s'", *cpp);
		}
		printf("\n");
		argv_free(av);
	}
	exit(0);
}
Esempio n. 2
0
File: main.c Progetto: drwebb/ncdu
/* main program */
int main(int argc, char **argv) {
  char *dir;

  setlocale(LC_ALL, "");

  if((dir = argv_parse(argc, argv)) == NULL)
    dir = ".";

  calc_init(dir, NULL);

  initscr();
  cbreak();
  noecho();
  curs_set(0);
  keypad(stdscr, TRUE);
  if(ncresize(min_rows, min_cols))
    min_rows = min_cols = 0;

  while(1) {
    if(pstate == ST_CALC && calc_process())
      break;
    else if(pstate == ST_DEL)
      delete_process();
    else if(input_handle(0))
      break;
  }

  erase();
  refresh();
  endwin();
  exclude_clear();

  return 0;
}
Esempio n. 3
0
// Iptables command.  Essentially the same as the command line version.
static int __lua_iptables(lua_State *L)
{
    int i, r;
    char *rule_copy = NULL;
    const char *table = luaL_checkstring(L, 1);
    const char *rule = luaL_checkstring(L, 2);

    i = find_table(table);

    if(i == -1)
        return eprintf("Invalid table: %s", table);

    if(!tables[i].handle)
        return eprintf("Invalid table: %s", table);

    if(debug) syslog(LOG_DEBUG, "iptables -t %s %s", table, rule);

    rule_copy = strdup(rule);
    argv_parse(table, rule_copy);

    r = do_command(iptc_argc, iptc_argv, &iptc_argv[2], &tables[i].handle);
    if(!r) return eprintf("iptables -t %s %s", table, rule);

    argv_free();
    free(rule_copy);

    return 0;
}
Esempio n. 4
0
static void process_buf(const char *buf)
{
	int i;
	struct argv_buf a;

	argv_set_delim(&a, '\n');
	argv_init(&a);
	argv_strdup(&a, buf);
	argv_parse(&a);
	for (i = 0; i < a.argc; i++)
		process_line(a.argv[i]);
}
Esempio n. 5
0
/* parse: pares input line into cmd
    free with free_cmd() */
struct command *cmd_creat(const char *input)
{
	struct command *cmd;
	char *s, *t;
	int background = 0;	/* 1 if background process */
	
	cmd = Malloc(sizeof(struct command));
	bzero(cmd, sizeof(struct command));

	s = s_dup(input);
	if (*(s+strlen(s)-1) == '&') {
		*(s+strlen(s)-1) = '\0';
		background = 1;
	}

	if (strchr(s, '|') != '\0') {
		if (pipeline_parse(cmd, s) == -1) {
			cmd_free(cmd);
			free(s);
			DP("%s", "pipeline_parse error");
			return (struct command *)0;
		}
	} else {
				/* remove redirection options from s  */
		t = io_parse(cmd, s);

		if (argv_parse(cmd, t) == -1) {
			cmd_free(cmd);
			free(s);
			DP("%s", "argv_parse error");
			return (struct command *)0;
		}
	}
	free(s);
	free(t);
	cmd->background = background;
	return cmd;
}
Esempio n. 6
0
static void t_argv_parse(void)
{
	struct command *cmd;
	char **dp;
	char *data[] = {
		"command",
		"command arg1 arg2",
		NULL
	};
	fprintf(stderr, "\n--- t_argv_parse ---\n");	

	for (dp = data; *dp != NULL; dp++) {
		fprintf(stderr, "line: |%s|\n", *dp);
		if ((cmd = cmd_init()) == (struct command *)0)
			err_quit("cmd_init");
		if (argv_parse(cmd, *dp) == -1)
			err_sys("argv_parse error");
		fprintf(stderr, "argv: ");
		writev_null(cmd->argv);
		fprintf(stderr, "\n");
		cmd_free(cmd);
	}
}