예제 #1
0
	/****************************************************************
	 * cli_process_qualifier:
	 ****************************************************************/
static int   cli_process_qualifier(	/* Return: status		*/
    char  **pp			/* <m> current pos within cmdstring	*/
   )

   {
    int   opt;
    char  *p;
    struct cduQualifier  *qual;
    struct cduVerb  *v;

    v = currentSyntax;
    if (!currentQualifiers)
        return(cli_error(CLI_STS_IVVERB,"No qualifiers defined"));

    opt = cmd_lookup(pp,cmdQual,0,NOMSG,0);
    if (opt)
       {
        qual = currentQualifiers + (opt-1);
        qual->qualL_status = CLI_STS_PRESENT;
       }
    else
       {		/* Not found:  check for negated qualifier ...	*/
        if (toupper(**pp)=='N' && toupper(*(*pp+1))=='O')
           {
            p = *pp + 2;
            opt = cmd_lookup(&p,cmdQual,0,NOMSG,0);
            if (opt > 0)
               {
                qual = currentQualifiers + (opt-1);
                if (qual->qualL_flags & QUAL_M_NONNEGATABLE)
                   {		/* default for qualifiers is NEGATABLE	*/
                    return(cli_error(CLI_STS_BADLINE,"not negatable"));
                   }
                qual->qualL_status = CLI_STS_NEGATED;
                *pp = p;
               }
           }
        if (!opt)
            return(CLI_STS_IVQUAL);
			/* Note: this can be a legitimate return value if
			 *  the same verb appears in more than one table.
			 *  Therefore, don't print warning message.
			 *-----------------------------------------------*/
       }

    if (cliDebug)
        printf("--> qualifier %s%s\n\r",qual->qualA_name,
                (qual->qualL_status==CLI_STS_NEGATED)?" (NEGATED)":"");
    if (qual->qualA_syntax)
        setCurrentSyntax(FALSE,qual->qualA_syntax);
    if (qual->qualA_value && (qual->qualL_status&1) && *pp && **pp=='=')
       {
        (*pp)++;
        qual->qualL_status = set_value(pp,qual->qualA_value);
		/* Note: currentSyntax may have changed inside set_value */
		/* .. we're ignoring this problem for now ...		*/
       }
    return(1);
   }
예제 #2
0
int cmd_help(FILE *f, int argc, char ** argv)
{
	const struct shell_cmd * cmd;

	if (argc > 2)
		return -1;

	if (argc > 1) {
		if ((cmd = cmd_lookup(shell_cmd_tab, argv[1])) == NULL) {
			fprintf(f, " Not found: '%s'\n", argv[1]);
			return -1;
		}

		fprintf(f, "  %s, %s - %s\n", cmd->name, cmd->alias, cmd->desc);
		fprintf(f, "  usage: %s %s\n\n", argv[1], cmd->usage);

		return 0;
	}

	fprintf(f, "\n COMMAND:   ALIAS:  DESCIPTION: \n");
	for (cmd = shell_cmd_tab; cmd->callback != NULL; cmd++) {
		fprintf(f, "  %-10s %-4s   %s\n", cmd->name, cmd->alias, cmd->desc);
	}

	return 0;
}
예제 #3
0
int exec_call(void) {
	int ecode;
	struct task *task = task_self();
	const char *path = task_resource_argv_path(task);
	const char *cmd_name = exec_cmd_name(path);
	const struct shell *sh = shell_lookup(cmd_name);
	int c;
	char **v;

	if (strcmp(cmd_name, path))
		task_resource_argv_insert(task, cmd_name, 0);

	c = task_resource_argv_argc(task);
	v = task_resource_argv_argv(task);

	/* FIXME pass argv to shell_exec */
	if (sh) {
		ecode = shell_run(sh);
	} else {
		const struct cmd *cmd;

		cmd = cmd_lookup(cmd_name);

		if (cmd) {
			task_self_module_ptr_set(cmd2mod(cmd));
			ecode = cmd_exec(cmd, c, v);
		} else {
			ecode = ENOENT;
		}
	}

	return ecode;
}
예제 #4
0
파일: shell.c 프로젝트: powertang/yard-ice
int cmd_help(FILE *f, int argc, char ** argv)
{
	struct shell_cmd * cmd;

	if (argc > 2)
		return -1;

	if (argc > 1) {
		if ((cmd = cmd_lookup(cmd_tab, argv[1])) == NULL) {
			fprintf(f, " Not found: '%s'\n", argv[1]);
			return -1;
		}

		fprintf(f, "  %s, %s - %s\n", cmd->name, cmd->alias, cmd->desc);
		fprintf(f, "  usage: %s %s\n\n", argv[1], cmd->usage);
		return 0;
	}

	fprintf(f, "\n Command:   Alias:  Desciption: \n");
	for (cmd = (struct shell_cmd *)cmd_tab; cmd->callback != NULL; cmd++) {
		fprintf(f, "  %-10s %-4s   %s\n", cmd->name, cmd->alias, cmd->desc);
	}

	return 0;
}
int system_start(void) {
	const char *command;
	char *argv[10];
	int argc;
	const struct cmd *cmd;

	setup_tty(OPTION_STRING_GET(tty_dev));

	array_foreach(command, script_commands, ARRAY_SIZE(script_commands)) {
		argc = cmdline_tokenize((char *)command, argv);
		if (0 == strncmp(argv[0], "pthread", 7)) {
			cmd = cmd_lookup(argv[1]);
			continue;
		}
		cmd = cmd_lookup(argv[0]);
		cmd_exec(cmd, argc, argv);
	}
예제 #6
0
파일: obj-ui.c 프로젝트: kaypy/FAangband
/*
 * Find the "first" inventory object with the given "tag".
 *
 * A "tag" is a char "n" appearing as "@n" anywhere in the
 * inscription of an object.
 *
 * Also, the tag "@xn" will work as well, where "n" is a tag-char,
 * and "x" is the action that tag will work for.
 */
static int get_tag(int *cp, char tag, cmd_code cmd, bool quiver_tags)
{
    int i;
    const char *s;

    /* (f)ire is handled differently from all others, due to the quiver */
    if (quiver_tags) {
	i = QUIVER_START + tag - '0';
	if (p_ptr->inventory[i].k_idx) {
	    *cp = i;
	    return (TRUE);
	}
	return (FALSE);
    }

    /* Check every object */
    for (i = 0; i < ALL_INVEN_TOTAL; ++i) {
	object_type *o_ptr = &p_ptr->inventory[i];

	/* Skip non-objects */
	if (!o_ptr->k_idx)
	    continue;

	/* Skip empty inscriptions */
	if (!o_ptr->note)
	    continue;

	/* Find a '@' */
	s = strchr(quark_str(o_ptr->note), '@');

	/* Process all tags */
	while (s) {
	    /* Check the normal tags */
	    if (s[1] == tag) {
		/* Save the actual inventory ID */
		*cp = i;

		/* Success */
		return (TRUE);
	    }

	    /* Check the special tags */
	    if ((cmd_lookup(s[1], KEYMAP_MODE_ORIG) == cmd) && (s[2] == tag)) {
		/* Save the actual inventory ID */
		*cp = i;

		/* Success */
		return (TRUE);
	    }

	    /* Find another '@' */
	    s = strchr(s + 1, '@');
	}
    }

    /* No such tag */
    return (FALSE);
}
예제 #7
0
파일: shell.c 프로젝트: powertang/yard-ice
int shell(FILE * f, const char * (* prompt)(void), 
		  void (* greeting)(FILE *), 
		  const struct shell_cmd * cmd_tab)
{
	char hist_buf[SIZEOF_CMD_HISTORY + SHELL_HISTORY_MAX * SHELL_LINE_MAX];
	char line[SHELL_LINE_MAX];
	struct cmd_history * history;
	int ret = 0;

	DCC_LOG(LOG_TRACE, "history_init()");
	history = history_init(hist_buf, sizeof(hist_buf), SHELL_LINE_MAX);

	if (greeting)
		greeting(f);

	do {
		char * stat;
		char * cp;

		fprintf(f, "%s", prompt());

		if (history_readline(history, f, line, SHELL_LINE_MAX) == NULL)
			return -1;

		if ((cp = shell_stripline(line)) == NULL)
			continue;

		history_add(history, cp);

		cp = line;

		ret = 0;

		while ((stat = cmd_get_next(&cp)) != NULL) {
			struct shell_cmd * cmd;

			if ((cmd = cmd_lookup(cmd_tab, stat)) == NULL) {
				fprintf(f, "Command not found!\n");
				break;
			}

			ret = cmd_exec(f, cmd, stat);

			if ((ret < 0) && (ret !=  SHELL_ABORT)) {
				fprintf(f, "Error: %d\n", -ret);
				break;
			}
			
		}
	} while (ret != SHELL_ABORT); 

	return 0;
}
예제 #8
0
파일: shell.c 프로젝트: powertang/yard-ice
int exec(FILE * f, char * line, const struct shell_cmd * cmd_tab)
{
	char * argv[SHELL_ARG_MAX];
	struct shell_cmd * cmd;
	value_t val;
	int argc;
	int n;

/* if ((s = shell_stripline(line)) == NULL) {
		return 0;
	} */

	if ((argc = shell_parseline(line, argv, SHELL_ARG_MAX)) == 0) {
		return 0;
	}

#if 0
	for (n = 0; n < argc; n++) {
		printf(" '%s'", argv[n]);
	}
	printf("\n");
#endif

	/* */
	if (argc > 2) {
		if (strcmp(argv[1], "=") == 0) {
			argv[1] = argv[0];
			argv[0] = "let";
		}
	}

	if ((cmd = cmd_lookup(cmd_tab, argv[0])) == NULL) {

		DCC_LOG(LOG_TRACE, "cmd_lookup() == NULL");

		if ((n = eval_uint32(&val, argc, argv)) < 0) {
			DCC_LOG(LOG_WARNING, "eval_uint32()");
			return n;
		}

		if (n != argc) {
			DCC_LOG(LOG_WARNING, "parse error");
			return -2;
		}

		show_uint32(f, val.uint32);
		return 0;
	}

	return cmd->callback(f, argc, argv);
}
예제 #9
0
int main(int argc, char *argv[]) {
	/* parse params */
	const struct cmd *c_cmd;
	int c_argc = argc, opt, argnum = 1;
	FILE *out = NULL;

	getopt_init();

	while (-1 != (opt = getopt(argc, argv, "chn:ed"))) {
		argnum++;
		switch (opt) {
			case 'c':
				/* execute command */
				c_cmd = cmd_lookup(argv[argnum]);
				run_cmd(c_cmd, c_argc - argnum, argv + argnum, out);
				return 0;
				break;
			case 'n':
				sscanf(optarg, "%d", &run_count);
				argnum++;
				break;
			case 'e':
				initialize_hashtable();
				set_profiling_mode(CYG_PROFILING);
				printf("cyg_profiling enabled.\n");
				return 0;
				break;
			case 'd':
				set_profiling_mode(DISABLED);
				printf("cyg_profiling disabled.\n");
				return 0;
				break;
			case 'h':
				printf("Example: tbprof [-n count] -c [cmd]\nUse man tbprof for more info.\n");
				return 0;
				break;
		}
	}
	printf("Wrong arguments. tbprof -h for usage.\n");
	return 0;
}
예제 #10
0
static int fuse_fill_dentry(struct super_block *sb, char *dest) {
	struct dentry *d;
	struct lookup lookup;

	dvfs_lookup(dest, &lookup);

	if (lookup.item == NULL)
		return -ENOENT;

	assert(lookup.item->flags & S_IFDIR);

	if (!(lookup.item->flags & DVFS_DIR_VIRTUAL)) {
		/* Hide dentry of the directory */
		dlist_del(&lookup.item->children_lnk);
		dvfs_cache_del(lookup.item);

		d = dvfs_alloc_dentry();

		dentry_fill(sb, NULL, d, lookup.parent);
		strcpy(d->name, lookup.item->name);
	} else {
		d = lookup.item;
		/* TODO free related inode */
	}
	d->flags |= S_IFDIR | DVFS_MOUNT_POINT;
	d->d_sb = sb, d->d_ops = sb ? sb->sb_dops : NULL, dentry_ref_inc(d);
	sb->root = d;

	d->d_inode = dvfs_alloc_inode(sb);
	*d->d_inode = (struct inode ) {
		.flags = S_IFDIR,
		.i_ops = sb->sb_iops,
		.i_sb = sb,
		.i_dentry = d,
	};

	return 0;
}

static void *fuse_module_mount_process(void *arg) {
	struct fuse_mount_params *params;
	const struct cmd *cmd;
	struct super_block *sb;
	struct dumb_fs_driver *fs_drv;
	char *argv[3];
	char argv0[0x20];
	char argv1[0x20];
	char argv2[0x20];

	params = arg;

	cmd = cmd_lookup(params->fm->fuse_module_cmd_mount);
	assert(cmd);

	fs_drv = dumb_fs_driver_find(params->fm->fuse_module_cmd_mount);
	assert(fs_drv);

	strncpy(argv0, params->fm->fuse_module_cmd_mount, sizeof(argv0));
	strncpy(argv1, params->dev, sizeof(argv1));
	strncpy(argv2, params->dest, sizeof(argv2));

	argv[0] = argv0;
	argv[1] = argv1;
	argv[2] = argv2;

	params->fm = NULL;

	sb = dvfs_alloc_sb(fs_drv, NULL);
	fuse_fill_dentry(sb, argv2);

	cmd_exec(cmd, 3, argv); /* will not return */

	return NULL;
}

int fuse_module_mount(struct fuse_module *fm, char *dev, char *dest) {
	int res;
	struct fuse_mount_params params = {fm, dev, dest};

	assert(fm);

	res = new_task(fm->fuse_module_cmd_mount, fuse_module_mount_process, &params);
	if (res) {

		return res;
	}
	while (params.fm) {
		sleep(0);
	}

	return 0;
}
예제 #11
0
파일: shell.c 프로젝트: wjrsonic/openwrt
static a_uint32_t *
cmd_parse(char *cmd_str, int *cmd_index, int *cmd_index_sub)
{
    int cmd_nr = 0;
    a_uint32_t *arg_val = ioctl_argp;
    char *tmp_str[CMDSTR_ARGS_MAX];

    if (cmd_str == NULL)
        return NULL;

    memset(arg_val, 0, CMDSTR_ARGS_MAX * sizeof (a_uint32_t));

    /* split string into array */
    if ((tmp_str[cmd_nr] = (void *) strtok(cmd_str, " ")) == NULL)
        return NULL;

    /*handle help */
    if (!strcasecmp(tmp_str[cmd_nr], "help"))
    {
        dprintf("input ? get help\n\n");
        return NULL;
    }

    while (tmp_str[cmd_nr])
    {
        if (++cmd_nr == 3)
            break;
        tmp_str[cmd_nr] = (void *) strtok(NULL, " ");
    }

    /*commond string lookup */
    int cmd_depth = cmd_lookup(tmp_str, cmd_index, cmd_index_sub);

    if (*cmd_index == GCMD_DESC_NO_MATCH || *cmd_index_sub == GCMD_DESC_NO_MATCH)
    {
        dprintf("invalid or incomplete command.\n\n");
        return NULL;
    }

    /*parse param */
    cmd_nr = 0;
    if (cmd_depth == 2)
    {
        tmp_str[cmd_nr] = tmp_str[2];
        cmd_nr++;
    }

    tmp_str[cmd_nr] = (void *) strtok(NULL, " ");
    while (tmp_str[cmd_nr])
    {
        if (++cmd_nr == CMDSTR_ARGS_MAX)
            break;
        tmp_str[cmd_nr] = (void *) strtok(NULL, " ");
    }

    arg_val[0] = GCMD_SUB_API(*cmd_index, *cmd_index_sub);
    arg_val[1] = (a_uint32_t) ioctl_buf;

    int rtn_code;
    if (arg_val[0] < SW_API_MAX)
    {
        /*api command parse */
        rtn_code = cmd_parse_api(tmp_str, arg_val);

    }
    else if (arg_val[0] > SW_API_MAX)
    {
        /*user command parse */
        rtn_code = cmd_parse_sw(tmp_str, arg_val);

    }
    else
    {
        rtn_code = SW_BAD_PARAM;
    }

    if(rtn_code != SW_OK)
    {
        cmd_print_error(rtn_code);

        if(rtn_code == SW_BAD_PARAM)
            cmd_print_usage(*cmd_index, *cmd_index_sub);

        return NULL;
    }

    return arg_val;
}
예제 #12
0
static int
ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp)
{
	const struct afswtch *afp, *nafp;
	const struct cmd *p;
	struct callback *cb;
	int s;

	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
	afp = uafp != NULL ? uafp : af_getbyname("inet");
top:
	ifr.ifr_addr.sa_family =
		afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
		AF_LOCAL : afp->af_af;

	if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
	    (uafp != NULL || errno != EPROTONOSUPPORT ||
	     (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
		err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family);

	while (argc > 0) {
		p = cmd_lookup(*argv, iscreate);
		if (iscreate && p == NULL) {
			/*
			 * Push the clone create callback so the new
			 * device is created and can be used for any
			 * remaining arguments.
			 */
			cb = callbacks;
			if (cb == NULL)
				errx(1, "internal error, no callback");
			callbacks = cb->cb_next;
			cb->cb_func(s, cb->cb_arg);
			iscreate = 0;
			/*
			 * Handle any address family spec that
			 * immediately follows and potentially
			 * recreate the socket.
			 */
			nafp = af_getbyname(*argv);
			if (nafp != NULL) {
				argc--, argv++;
				if (nafp != afp) {
					close(s);
					afp = nafp;
					goto top;
				}
			}
			/*
			 * Look for a normal parameter.
			 */
			continue;
		}
		if (p == NULL) {
			/*
			 * Not a recognized command, choose between setting
			 * the interface address and the dst address.
			 */
			p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
		}
		if (p->c_u.c_func || p->c_u.c_func2) {
			if (p->c_parameter == NEXTARG) {
				if (argv[1] == NULL)
					errx(1, "'%s' requires argument",
					    p->c_name);
				p->c_u.c_func(argv[1], 0, s, afp);
				argc--, argv++;
			} else if (p->c_parameter == OPTARG) {
				p->c_u.c_func(argv[1], 0, s, afp);
				if (argv[1] != NULL)
					argc--, argv++;
			} else if (p->c_parameter == NEXTARG2) {
				if (argc < 3)
					errx(1, "'%s' requires 2 arguments",
					    p->c_name);
				p->c_u.c_func2(argv[1], argv[2], s, afp);
				argc -= 2, argv += 2;
			} else
				p->c_u.c_func(*argv, p->c_parameter, s, afp);
		}
		argc--, argv++;
	}

	/*
	 * Do any post argument processing required by the address family.
	 */
	if (afp->af_postproc != NULL)
		afp->af_postproc(s, afp);
	/*
	 * Do deferred callbacks registered while processing
	 * command-line arguments.
	 */
	for (cb = callbacks; cb != NULL; cb = cb->cb_next)
		cb->cb_func(s, cb->cb_arg);
	/*
	 * Do deferred operations.
	 */
	if (clearaddr) {
		if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
			warnx("interface %s cannot change %s addresses!",
			      name, afp->af_name);
			clearaddr = 0;
		}
	}
	if (clearaddr) {
		int ret;
		strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
		ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
		if (ret < 0) {
			if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
				/* means no previous address for interface */
			} else
				Perror("ioctl (SIOCDIFADDR)");
		}
	}
	if (newaddr) {
		if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
			warnx("interface %s cannot change %s addresses!",
			      name, afp->af_name);
			newaddr = 0;
		}
	}
	if (newaddr && (setaddr || setmask)) {
		strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
		if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
			Perror("ioctl (SIOCAIFADDR)");
	}

	close(s);
	return(0);
}
예제 #13
0
static int
ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp)
{
	const struct afswtch *afp, *nafp;
	const struct cmd *p;
	struct callback *cb;
	int s;

	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
	afp = NULL;
	if (uafp != NULL)
		afp = uafp;
	/*
	 * This is the historical "accident" allowing users to configure IPv4
	 * addresses without the "inet" keyword which while a nice feature has
	 * proven to complicate other things.  We cannot remove this but only
	 * make sure we will never have a similar implicit default for IPv6 or
	 * any other address familiy.  We need a fallback though for
	 * ifconfig IF up/down etc. to work without INET support as people
	 * never used ifconfig IF link up/down, etc. either.
	 */
#ifndef RESCUE
#ifdef INET
	if (afp == NULL && feature_present("inet"))
		afp = af_getbyname("inet");
#endif
#endif
	if (afp == NULL)
		afp = af_getbyname("link");
	if (afp == NULL) {
		warnx("Please specify an address_family.");
		usage();
	}
top:
	ifr.ifr_addr.sa_family =
		afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
		AF_LOCAL : afp->af_af;

	if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
	    (uafp != NULL || errno != EPROTONOSUPPORT ||
	     (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
		err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family);

	while (argc > 0) {
		p = cmd_lookup(*argv, iscreate);
		if (iscreate && p == NULL) {
			/*
			 * Push the clone create callback so the new
			 * device is created and can be used for any
			 * remaining arguments.
			 */
			cb = callbacks;
			if (cb == NULL)
				errx(1, "internal error, no callback");
			callbacks = cb->cb_next;
			cb->cb_func(s, cb->cb_arg);
			iscreate = 0;
			/*
			 * Handle any address family spec that
			 * immediately follows and potentially
			 * recreate the socket.
			 */
			nafp = af_getbyname(*argv);
			if (nafp != NULL) {
				argc--, argv++;
				if (nafp != afp) {
					close(s);
					afp = nafp;
					goto top;
				}
			}
			/*
			 * Look for a normal parameter.
			 */
			continue;
		}
		if (p == NULL) {
			/*
			 * Not a recognized command, choose between setting
			 * the interface address and the dst address.
			 */
			p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
		}
		if (p->c_u.c_func || p->c_u.c_func2) {
			if (p->c_parameter == NEXTARG) {
				if (argv[1] == NULL)
					errx(1, "'%s' requires argument",
					    p->c_name);
				p->c_u.c_func(argv[1], 0, s, afp);
				argc--, argv++;
			} else if (p->c_parameter == OPTARG) {
				p->c_u.c_func(argv[1], 0, s, afp);
				if (argv[1] != NULL)
					argc--, argv++;
			} else if (p->c_parameter == NEXTARG2) {
				if (argc < 3)
					errx(1, "'%s' requires 2 arguments",
					    p->c_name);
				p->c_u.c_func2(argv[1], argv[2], s, afp);
				argc -= 2, argv += 2;
			} else
				p->c_u.c_func(*argv, p->c_parameter, s, afp);
		}
		argc--, argv++;
	}

	/*
	 * Do any post argument processing required by the address family.
	 */
	if (afp->af_postproc != NULL)
		afp->af_postproc(s, afp);
	/*
	 * Do deferred callbacks registered while processing
	 * command-line arguments.
	 */
	for (cb = callbacks; cb != NULL; cb = cb->cb_next)
		cb->cb_func(s, cb->cb_arg);
	/*
	 * Do deferred operations.
	 */
	if (clearaddr) {
		if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
			warnx("interface %s cannot change %s addresses!",
			      name, afp->af_name);
			clearaddr = 0;
		}
	}
	if (clearaddr) {
		int ret;
		strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
		ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
		if (ret < 0) {
			if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
				/* means no previous address for interface */
			} else
				Perror("ioctl (SIOCDIFADDR)");
		}
	}
	if (newaddr) {
		if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
			warnx("interface %s cannot change %s addresses!",
			      name, afp->af_name);
			newaddr = 0;
		}
	}
	if (newaddr && (setaddr || setmask)) {
		strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
		if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
			Perror("ioctl (SIOCAIFADDR)");
	}

	close(s);
	return(0);
}
예제 #14
0
	/*****************************************************************
	 * cli_dcl_parse:
	 *****************************************************************/
int   cli_dcl_parse(		/* Returns: status			*/
    void  *command_string	/* <r:opt> descr or c-string		*/
   ,struct cduVerb  *table	/* <r> addr of command table		*/
   ,int   (*param_routine)()	/* <r:opt> routine to read req'd params	*/
   ,int   (*prompt_routine)()	/* <r:opt> routine to read command string*/
   ,void  *uprompt		/* <r:opt> descr or c-string		*/
   )
   {
    int   k;
    int   opt;
    int   sts;
    char  *p;
    char  prompt[48];
    struct cduParam  *prm;
    struct cduValue  *val;
    struct descriptor  *dsc;
    static DYNAMIC_DESCRIPTOR(dsc_parameter);

    if (USE_HYPHEN_CONTINUATION == -1)
      USE_HYPHEN_CONTINUATION = getenv("VMS_SEMANTICS") ? 0 : 1;


    clearCurrentSyntax();
    init_table(table);
    if (!uprompt)
        strcpy(prompt,"Command> ");
    else
       {
        if (is_cdescr(uprompt))
           {
            dsc = uprompt;
            p = dsc->dscA_pointer;
            k = dsc->dscW_length;
           }
        else if (is_ddescr(uprompt))
           {
            dsc = uprompt;
            p = dsc->dscA_pointer;
            k = dsc->dscW_length;
            if (!p && !k)
               {			/* null descriptor		*/
                p = "Command> ";
                k = strlen(p);
              }
           }
        else
           {
            p = uprompt;
            k = strlen(uprompt);
           }
        if (k >= sizeof(prompt))
            k = sizeof(prompt) - 1;
        strncpy(prompt,p,k);
        prompt[k] = '\0';
       }

		/*======================================================
		 * Set 'p' to start of command line ...
		 *=====================================================*/
    if (p = command_string)
       {
        if (is_cdescr(command_string) || is_ddescr(command_string))
           {
            dsc = command_string;
            p = dsc->dscA_pointer;
           }
       }
    if (!p)
       {
        sts = prompt_routine(prompt,&dsc_cmdline);
        if (~sts & 1)
            return(sts);		/*--------------------> return	*/
        p = nonblank(dsc_cmdline.dscA_pointer);
        if (!p)
            return(CLI_STS_NOCOMD);	/*---------> return: blank line	*/
       }

		/*=====================================================
		 * Get the command verb ...
		 *====================================================*/
    opt = cmd_lookup(&p,cmdVerb,0,NOMSG|NO_BEMORESPECIFIC,0);
    if (!opt)
        sts = CLI_STS_IVVERB;
    else
       {
        paramId = 0;
        setCurrentSyntax(TRUE,currentTable+(opt-1));
        sts = cli_process_verb(&p,prompt);
       }
    if (~sts & 1)
        return(sts);			/*---------------> return: err	*/

		/*======================================================
		 * "paramId" indicates number of parameters on line.
		 * Check that all required parameters are present ...
		 *=====================================================*/
    for ( ; (prm=currentParameters+paramId) && prm->prmA_value ; )
       {
        val = prm->prmA_value;
        if (!(val->valL_flags & VAL_M_REQUIRED))
            break;		/* done:  required params come first	*/
        sprintf(prompt,"_%s: ",
            prm->prmA_prompt ? prm->prmA_prompt :
            (prm->prmA_label ? prm->prmA_label : prm->prmA_name));

        for (p=0 ; !p ; )
           {
            sts = param_routine(prompt,&dsc_parameter);
            if (~sts & 1)
                return(sts);		/*--------------------> return	*/
            p = nonblank(dsc_parameter.dscA_pointer);
           }
        str_append(&dsc_cmdline," ");
        str_append(&dsc_cmdline,&dsc_parameter);
        sts = cli_process_verb(&p,"...");
       }
    return(sts);
   }
예제 #15
0
	/*****************************************************************
	 * set_value:
	 *****************************************************************/
static int   set_value(		/* Return: CLI_STS_xxxx			*/
    char  **pp			/* <m> current location in cmd line	*/
   ,struct cduValue  *val	/* <m> the value struct			*/
   )
   {
    int   keycnt;
    int   opt;
    int   sts;
    char  *p;
    struct cmd_struct  *cmd;
    struct cduKeyword  *key;
    static DYNAMIC_DESCRIPTOR(dsc_temp);

    if ((val->valL_flags & VAL_M_LIST) && **pp=='(')
        sts = readCliValueList(pp,val);
    else
        sts = cliToken(pp,&val->val_dsc,val->valL_flags);

    if (~sts & 1)
        return(cli_error(CLI_STS_BADLINE,"Invalid data in line"));

    val->valA_substring = val->val_dsc.dscA_pointer;

		/*=======================================================
		 * Keywords ?
		 *======================================================*/
    if (!val->valA_userType)
        return(CLI_STS_PRESENT);	/*--------------- Nope: return	*/

		/*-------------------------------------------------------
		 *...yes: check each input for keyword ...
		 *------------------------------------------------------*/
    cmd = make_lookup_keyword(val->valA_userType);
    p = val->val_dsc.dscA_pointer;
    str_free1_dx(&dsc_temp);
    keycnt = 0;
    for ( ; p ; keycnt++)
       {
        if (keycnt)
           {			/* skip separator character		*/
            if (*p=='\01' || *p=='\02')
               {
                str_append(&dsc_temp,(*p=='\01')?"\01":"\02");
                p++;
               }
            else
               {
                fprintf(stderr,"Illegal separator character!\n");
#ifdef vms
                lib$signal(SS$_DEBUG);
#endif
               }
           }
        opt = cmd_lookup(&p,cmd,0,NOMSG,0);
        if (opt)
           {
            key = val->valA_userType + (opt-1);
            key->keyL_status = CLI_STS_PRESENT;
            str_append(&dsc_temp,key->keyA_name);
            continue;			/* back to top of loop ...	*/
           }

		/*-------------------------------------------------------
		 * Check for negated keyword ...
		 *------------------------------------------------------*/
        if (toupper(p[0])=='N' && toupper(p[1])=='O')
           {
            p += 2;
            opt = cmd_lookup(&p,cmd,0,NOMSG,0);
            if (opt)
               {
                key = val->valA_userType + (opt-1);
                if (!(key->keyL_flags & KEY_M_NEGATABLE))
                   {
                    free(cmd);
                    return(cli_error(CLI_STS_NOTNEGATABLE,"not negatable"));
                   }
                key->keyL_status = CLI_STS_NEGATED;
                str_append(&dsc_temp,key->keyA_name);
                continue;		/* back to top of loop ...	*/
               }
           }

        free(cmd);
        return(CLI_STS_IVKEYW);		/*---> return: Invalid keyword	*/
		/* Note: this can be a legal sts.  For example "DEFINE"'s
		 *  P2 might be the keyword "SERVER" or a macro name.
		 *  The latter would appear as an "invalid keyword".
		 *------------------------------------------------------*/
       }

		/*========================================================
		 * Ok -- all keywords were checked ...
		 *=======================================================*/
    free(cmd);
    str_copy_dx(&val->val_dsc,&dsc_temp);
    str_free1_dx(&dsc_temp);
    if (key->keyA_syntax)
       {
        if (keycnt == 1)
           {
            sts = key->keyL_status;		/* save status		*/
            setCurrentSyntax(FALSE,key->keyA_syntax);
            key->keyL_status = sts;
           }
        else
            fprintf(stderr,"Keyword syntax specified, but keycnt=%d\n",
                keycnt);
       }
    return((keycnt==1) ? key->keyL_status : CLI_STS_PRESENT);
   }