Esempio n. 1
0
static void
gimp_dialog_help (GObject *dialog)
{
  GimpHelpFunc  help_func = g_object_get_data (dialog, "gimp-dialog-help-func");

  if (help_func)
    help_func (g_object_get_data (dialog, "gimp-dialog-help-id"), dialog);
}
Esempio n. 2
0
int rtelnet_port_cmd(int type, char *in, int inlen, char *out, int outlen)
{
	int ret = 0;
	char buf[OSIZE] = {0};

	if(out == NULL) {
		out = (char *)malloc(OSIZE);

		if(NULL == out) {
			return EMALLOC;
		}
	}

	memset(out, 0, outlen);

	if(!strncmp(in, "get_", 4)) {
		ret = get_func(in, inlen, buf, sizeof(buf));
	} else if(!strncmp(in, "set_", 4)) {
		ret = set_func(in, inlen, buf, sizeof(buf));
	} else if(!strncmp(in, "save", 4)) {
		ret = save_func(in, inlen, buf, sizeof(buf));
	} else if(!strncmp(in, "help", 4)) {
		ret = help_func(in, inlen, buf, sizeof(buf));
	} else {
		ret = ENOFIND;
	}

	if(ret >= 0) {
		snprintf(out, outlen,  "%s cmd success %s\r\n>", in, buf);
		ret = strlen(out) + 1;
	} else if(ret == ENOFIND) {
		snprintf(out, outlen,  "%s cmd not found!\r\n>", in);
		ret = strlen(out) + 1;
	} else if(ret == ENOPARAM) {
		snprintf(buf, outlen,  "%s failed param wrong!\r\n>", in);
		ret = strlen(out) + 1;
	} else {
		snprintf(out, outlen, "%s cmd faild, %s\r\n>", in, buf);
		ret = strlen(out) + 1;
	}

	return ret;
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
	int opt, i;
	const struct cmdtab *match, *cc, *tab;

#ifndef RESCUE
	snmp_client_init(&snmp_client);
	snmp_client.trans = SNMP_TRANS_LOC_STREAM;
	snmp_client_set_host(&snmp_client, PATH_ILMI_SOCK);
#endif

#ifdef RESCUE
#define OPTSTR	"htv"
#else
#define	OPTSTR	"htvs:"
#endif

	while ((opt = getopt(argc, argv, OPTSTR)) != -1)
		switch (opt) {

		  case 'h':
			help_func(0, argv);

#ifndef RESCUE
		  case 's':
			parse_server(optarg);
			break;
#endif

		  case 'v':
			verbose++;
			break;

		  case 't':
			notitle = 1;
			break;
		}

	if (argv[optind] == NULL)
		help_func(0, argv);

	argc -= optind;
	argv += optind;

	if ((main_tab = malloc(sizeof(static_main_tab))) == NULL)
		err(1, NULL);
	memcpy(main_tab, static_main_tab, sizeof(static_main_tab));

#ifndef RESCUE
	/* XXX while this is compiled in */
	device_register();
#endif

	cc = main_tab;
	i = 0;
	for (;;) {
		/*
		 * Scan the table for a match
		 */
		tab = cc;
		match = NULL;
		while (cc->string != NULL) {
			if (substr(argv[i], cc->string)) {
				if (match != NULL) {
					printf("Ambiguous option '%s'",
					    argv[i]);
					cc = tab;
					goto subopts;
				}
				match = cc;
			}
			cc++;
		}
		if ((cc = match) == NULL) {
			printf("Unknown option '%s'", argv[i]);
			cc = tab;
			goto subopts;
		}

		/*
		 * Have a match. If there is no subtable, there must
		 * be either a handler or the command is only a help entry.
		 */
		if (cc->sub == NULL) {
			if (cc->func != NULL)
				break;
			printf("Unknown option '%s'", argv[i]);
			cc = tab;
			goto subopts;
		}

		/*
		 * Look at the next argument. If it doesn't exist or it
		 * looks like a switch, terminate the scan here.
		 */
		if (argv[i + 1] == NULL || argv[i + 1][0] == '-') {
			if (cc->func != NULL)
				break;
			printf("Need sub-option for '%s'", argv[i]);
			cc = cc->sub;
			goto subopts;
		}

		cc = cc->sub;
		i++;
	}

	argc -= i + 1;
	argv += i + 1;

	(*cc->func)(argc, argv);

	return (0);

  subopts:
	printf(". Select one of:\n");
	while (cc->string != NULL) {
		if (cc->func != NULL || cc->sub != NULL)
			printf("%s ", cc->string);
		cc++;
	}
	printf("\n");

	return (1);
}