Exemple #1
0
/*
 * Help command.
 * Call each command handler with argc == 0 and argv[0] == name.
 */
void
help(int argc, char *argv[])
{
	struct cmd *c;

	if (argc == 1) {
		StringList *buf;

		buf = sl_init();
		fprintf(ttyout, "%sommands may be abbreviated.  Commands are:\n\n",
		    proxy ? "Proxy c" : "C");
		for (c = cmdtab; c < &cmdtab[NCMDS]; c++)
			if (c->c_name && (!proxy || c->c_proxy))
				sl_add(buf, c->c_name);
		list_vertical(buf);
		sl_free(buf, 0);
		return;
	}

#define HELPINDENT ((int) sizeof("disconnect"))

	while (--argc > 0) {
		char *arg;

		arg = *++argv;
		c = getcmd(arg);
		if (c == (struct cmd *)-1)
			fprintf(ttyout, "?Ambiguous help command %s\n", arg);
		else if (c == (struct cmd *)0)
			fprintf(ttyout, "?Invalid help command %s\n", arg);
		else
			fprintf(ttyout, "%-*s\t%s\n", HELPINDENT,
				c->c_name, c->c_help);
	}
}
Exemple #2
0
static int
run_slash_script(request_rec* r, void* stack_top)
{
    sl_vm_t* vm;
    slash_context_t ctx;
    sl_vm_frame_t exit_frame, exception_frame;
    char* last_slash;
    SLVAL error;
    sl_static_init();
    vm = sl_init("apache2");
    sl_gc_set_stack_top(vm->arena, stack_top);
    vm->cwd = sl_alloc_buffer(vm->arena, strlen(r->canonical_filename) + 10);
    strcpy(vm->cwd, r->canonical_filename);
    last_slash = strrchr(vm->cwd, '/');
    if(last_slash) {
        *last_slash = 0;
    }
    SL_TRY(exit_frame, SL_UNWIND_ALL, {
        SL_TRY(exception_frame, SL_UNWIND_EXCEPTION, {
            ctx.headers_sent = 0;
            ctx.vm = vm;
            ctx.r = r;
            vm->data = &ctx;
            setup_request_object(vm, r);
            setup_response_object(vm);
            ap_set_content_type(r, "text/html; charset=utf-8");
            sl_do_file(vm, r->canonical_filename);
        }, error, {
            sl_response_clear(vm);
            sl_render_error_page(vm, error);
        });
Exemple #3
0
unsigned char
complete_ifname(char *word, int list, EditLine *el)
{
	StringList *words;
	size_t wordlen;
	unsigned char rv;   

	words = sl_init();
	wordlen = strlen(word);

	struct if_nameindex *ifn_list, *ifnp;

	if ((ifn_list = if_nameindex()) == NULL)
		return 0;

	for (ifnp = ifn_list; ifnp->if_name != NULL; ifnp++) {
                if (wordlen > strlen(ifnp->if_name))
                        continue;
                if (strncmp(word, ifnp->if_name, wordlen) == 0)
                        sl_add(words, ifnp->if_name);
        }

        rv = complete_ambiguous(word, list, words, el);
	if_freenameindex(ifn_list);
        sl_free(words, 0);
        return (rv);
}
Exemple #4
0
/*ARGSUSED*/
static int
_local_initshells(void *rv, void *cb_data, va_list ap)
{
	char	*sp, *cp;
	FILE	*fp;
	char	 line[MAXPATHLEN + 2];

	if (sl)
		sl_free(sl, 1);
	sl = sl_init();

	if ((fp = fopen(_PATH_SHELLS, "r")) == NULL)
		return NS_UNAVAIL;

	sp = cp = line;
	while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) {
		while (*cp != '#' && *cp != '/' && *cp != '\0')
			cp++;
		if (*cp == '#' || *cp == '\0')
			continue;
		sp = cp;
		while (!isspace(*cp) && *cp != '#' && *cp != '\0')
			cp++;
		*cp++ = '\0';
		sl_add(sl, strdup(sp));
	}
	fclose(fp);
	return NS_SUCCESS;
}
Exemple #5
0
/*
 * Complete a command
 */
static unsigned char
complete_command(char *word, int list, EditLine *el, char **table, int stlen)
{
	char **c;
	struct ghs *ghs;
	StringList *words;
	size_t wordlen;
	unsigned char rv;

	if (table == NULL)
		return(CC_ERROR);

	words = sl_init();
	wordlen = strlen(word);

	for (c = table; *c != NULL; c = (char **)((char *)c + stlen)) {
		ghs = (struct ghs *)c;
		if (wordlen > strlen(ghs->name))
			continue;
		if (strncmp(word, ghs->name, wordlen) == 0)
			sl_add(words, ghs->name);
	}

	rv = complete_ambiguous(word, list, words, el);
	sl_free(words, 0);
	return (rv);
}
Exemple #6
0
/*ARGSUSED*/
static int
_dns_initshells(void *rv, void *cb_data, va_list ap)
{
	char	  shellname[] = "shells-XXXXX";
	int	  hsindex, hpi, r;
	char	**hp;
	void	 *context;

	if (sl)
		sl_free(sl, 1);
	sl = sl_init();
	r = NS_UNAVAIL;
	if (hesiod_init(&context) == -1)
		return (r);

	for (hsindex = 0; ; hsindex++) {
		snprintf(shellname, sizeof(shellname)-1, "shells-%d", hsindex);
		hp = hesiod_resolve(context, shellname, "shells");
		if (hp == NULL) {
			if (errno == ENOENT) {
				if (hsindex == 0)
					r = NS_NOTFOUND;
				else
					r = NS_SUCCESS;
			}
			break;
		} else {
			for (hpi = 0; hp[hpi]; hpi++)
				sl_add(sl, hp[hpi]);
			free(hp);
		}
	}
	hesiod_end(context);
	return (r);
}
Exemple #7
0
Fichier : conf.c Projet : sthen/nsh
void conf_rtables(FILE *output)
{
	int i, rtableid;
	StringList *rtables;

	rtables = sl_init();
	if (db_select_rtable_rtables(rtables) < 0) {
		printf("%% database failure select rtables rtable\n");
		sl_free(rtables, 1);
		return;
	}
	for (i = 0; i < rtables->sl_cur; i++) {
		const char *errmsg = NULL;

		rtableid = strtonum(rtables->sl_str[i], 0, RT_TABLEID_MAX, &errmsg);
		if (rtableid == 0)
			continue;
		if (errmsg) {
			printf("%% Invalid route table (%d) %s: %s\n",  i,
			    rtables->sl_str[i], errmsg);
			continue;
		}
		conf_rtables_rtable(output, rtableid);
	}

	sl_free(rtables, 1);
}
Exemple #8
0
Fichier : ppp.c Projet : sthen/nsh
void
conf_sppp_mh(FILE *output, struct sauthreq *spa, char *ifname, char *pfx)
{
	int i;
	char type[TYPESZ];
	StringList *req;

	if (!(spa->proto | spa->name[0] | spa->secret[0] | (spa->flags &
	    AUTHFLAG_NOCALLOUT) | (spa->flags & AUTHFLAG_NORECHALLENGE)))
		return;
	fprintf(output, " %s", pfx);
	if (spa->proto)
		for (i = 0; i < nitems(spppproto); i++)
			if (spa->proto == spppproto[i].type)
				fprintf(output, " proto %s", spppproto[i].name);
	if (spa->name[0])
		fprintf(output, " name %s", spa->name);

	snprintf(type, TYPESZ, "%skey", pfx);
	req = sl_init();
	if (db_select_flag_x_ctl(req, type, ifname) >= 0) {
		if (req->sl_cur > 0)
			fprintf(output, " key %s", req->sl_str[0]);
	}
	sl_free(req, 1);

	if (spa->flags & AUTHFLAG_NOCALLOUT)
		fprintf(output, " flag callin");
	if (spa->flags & AUTHFLAG_NORECHALLENGE)
		fprintf(output, " flag norechallenge");
	fprintf(output, "\n");
}
Exemple #9
0
int
main(int argc, char *argv[])
{
        printf("Welcome to Shoestrap\n");

        struct sl_interpreter_state *state = sl_init();
        char *input_string = malloc(MAX_INPUT_SIZE * sizeof(char));
        sl_value in, out;

        while (1) {
                printf(">> ");
                fflush(stdin);
                input_string = fgets(input_string, MAX_INPUT_SIZE, stdin);

                if (input_string == NULL) {
                        break;
                }

                struct sl_keep_list *old = state->keep_list;

                in = sl_read(state, input_string);
                out = sl_eval(state, in, state->global_env);

                sl_free_keep_list(state->keep_list, old);
                state->keep_list = old;

                sl_p(state, out);
        }

        free(input_string);
        sl_destroy(state);
        return 0;
}
Exemple #10
0
vio_err_t vio_partition_val(vio_ctx *ctx, vio_val *v, vio_val *q, vio_val **out_rets, vio_val **out_parts) {
    vio_err_t err = 0;
    struct partition *p = NULL;
    struct partition_item *it = NULL;
    vio_val *ret;
    sl_skiplist parts;

    sl_init(&parts, cmp_vals, ctx, NULL, NULL);

    for (uint32_t i = 0; i < v->vlen; ++i) {
        VIO__ERRIF(ctx->sp >= VIO_STACK_SIZE, VE_STACK_OVERFLOW);
        ctx->stack[ctx->sp++] = v->vv[i];
        vio_exec(ctx, q->bc);
        ret = ctx->stack[--ctx->sp];
        if (!sl_find(&parts, ret, &p)) {
            VIO__ERRIF((p = (struct partition *)malloc(sizeof(struct partition))) == NULL, VE_ALLOC_FAIL);
            p->last = NULL;
            p->size = 0;
            sl_insert(&parts, ret, p, NULL);
        }
        VIO__ERRIF((it = (struct partition_item *)malloc(sizeof(struct partition_item))) == NULL, VE_ALLOC_FAIL);
        it->next = p->last;
        it->v = v->vv[i];
        p->last = it;
        ++p->size;
    }

    VIO__CHECK(vio_vec(ctx, out_rets, sl_size(&parts), NULL));
    VIO__CHECK(vio_vec(ctx, out_parts, sl_size(&parts), NULL));
    struct part_data pd = { .i = 0, .rets = *out_rets, .parts = *out_parts, .ctx = ctx };
    sl_iter(&parts, fill_partitions_and_free, &pd);
    sl_free(&parts);
    return 0;

    error:
    sl_iter(&parts, gotta_free_em_all, NULL);
    sl_free(&parts);
    return err;
}

vio_err_t vio_partition(vio_ctx *ctx) {
    vio_err_t err = 0;
    vio_val *q, *vec, *rets, *parts;
    VIO__RAISEIF(ctx->sp < 2, VE_STACK_EMPTY,
                 "Partition context requires a quotation and vector, but the "
                 "stack doesnt't have enough values.");

    VIO__CHECK(vio_coerce(ctx, ctx->stack[--ctx->sp], &q, vv_quot));
    VIO__CHECK(vio_coerce(ctx, ctx->stack[--ctx->sp], &vec, vv_vec));
    VIO__CHECK(vio_partition_val(ctx, vec, q, &rets, &parts));
    ctx->stack[ctx->sp++] = rets;
    ctx->stack[ctx->sp++] = parts;
    return 0;

    error:
    return err;
}
Exemple #11
0
static sl_vm_t*
setup_vm(void* stack_top)
{
    sl_static_init();
    sl_vm_t* vm = sl_init("cli");
    sl_gc_set_stack_top(vm->arena, stack_top);
    setup_vm_request(vm);
    setup_vm_response(vm);
    return vm;
}
Exemple #12
0
static void rs_init(void){
    int fd;
    sl_init(0x3f8);
    hook(IF_WRITE,rs_write);
    hook(IF_INTR,_io);
    hook(IF_OPEN,rs_open);
    regirq(4);
    fd = open("/dev/ttyS0",O_RDONLY);
    run(fd,FIF_MOUNT,getpid(),0,0);
}
Exemple #13
0
Fichier : conf.c Projet : sthen/nsh
void conf_rtables_rtable(FILE *output, int rtableid)
{
	int i;
	StringList *rtable_name, *rtable_daemons;

	rtable_name = sl_init();

	if (db_select_name_rtable(rtable_name, rtableid) < 0) {
		printf("%% database failure select rtables name\n");
		sl_free(rtable_name, 1);
		return;
	} else {
		fprintf(output, "rtable %d %s\n", rtableid,
		    rtable_name->sl_str[0]);
	}

	sl_free(rtable_name, 1);

	/*
	 * Routes must be printed before we attempt to start daemons,
	 * else rtables will not be created in the kernel (Unless an
	 * rdomain is created by specifing one on an interface prior
	 * to this point. An rdomain creates a new corresponding rtable)
	 */
	conf_arp(output, " arp ");
	conf_routes(output, " route ", AF_INET, RTF_STATIC, rtableid);
	conf_routes(output, " route ", AF_INET6, RTF_STATIC, rtableid);

	rtable_daemons = sl_init();

	if (db_select_flag_x_ctl_rtable(rtable_daemons, "ctl", rtableid) < 0) {
		printf("%% database failure select ctl rtable\n");
		sl_free(rtable_daemons, 1);
		return;
	} else {
		for (i = 0; i < rtable_daemons->sl_cur; i++)
			conf_ctl(output, " ", rtable_daemons->sl_str[i], rtableid);
	}

	sl_free(rtable_daemons, 1);

	fprintf(output, "!\n");
}
Exemple #14
0
/*
 * sl_init() with inbuilt error checking
 */
static StringList *
mail_sl_init(void)
{
	StringList *p;

	p = sl_init();
	if (p == NULL)
		err(EXIT_FAILURE, "Unable to allocate memory for stringlist");
	return p;
}
Exemple #15
0
struct sl* sl_init_data(struct generic_data data) {
	struct sl *l = sl_init();
	struct sl_node *n = malloc(sizeof(*n));
	n->data = data;
	n->above = n->below = NULL;
	n->prev = l->lists[0].head;
	n->next = l->lists[0].tail;
	l->lists[0].head->next = n;
	l->lists[0].tail->prev = n;
	return l;
}
Exemple #16
0
/*
 * Retrieve sorted list of system locales (or user locales, if PATH_LOCALE
 * environment variable is set)
 */
void
init_locales_list(void)
{
	DIR *dirp;
	struct dirent *dp;
	size_t i;
	int bogus;

	/* why call this function twice ? */
	if (locales != NULL)
		return;

	/* initialize StringList */
	locales = sl_init();
	if (locales == NULL)
		err(1, "could not allocate memory");

	/* get actual locales directory name */
	if (__detect_path_locale() != 0)
		err(1, "unable to find locales storage");

	/* open locales directory */
	dirp = opendir(_PathLocale);
	if (dirp == NULL)
		err(1, "could not open directory '%s'", _PathLocale);

	/* scan directory and store its contents except "." and ".." */
	while ((dp = readdir(dirp)) != NULL) {
		if (*(dp->d_name) == '.')
			continue;		/* exclude "." and ".." */
		for (bogus = i = 0; i < NBOGUS; i++)
			if (strncmp(dp->d_name, boguslocales[i],
			    strlen(boguslocales[i])) == 0)
				bogus = 1;
		if (!bogus)
			sl_add(locales, strdup(dp->d_name));
	}
	closedir(dirp);

	/* make sure that 'POSIX' and 'C' locales are present in the list.
	 * POSIX 1003.1-2001 requires presence of 'POSIX' name only here, but
	 * we also list 'C' for constistency
	 */
	if (sl_find(locales, "POSIX") == NULL)
		sl_add(locales, "POSIX");

	if (sl_find(locales, "C") == NULL)
		sl_add(locales, "C");

	/* make output nicer, sort the list */
	qsort(locales->sl_str, locales->sl_cur, sizeof(char *), scmp);
}
Exemple #17
0
/*ARGSUSED*/
static int
_nis_initshells(void *rv, void *cb_data, va_list ap)
{
	static char *ypdomain;
	char	*key, *data;
	char	*lastkey;
	int	 keylen, datalen;
	int	 r;

	if (sl)
		sl_free(sl, 1);
	sl = sl_init();

	if (ypdomain == NULL) {
		switch (yp_get_default_domain(&ypdomain)) {
		case 0:
			break;
		case YPERR_RESRC:
			return NS_TRYAGAIN;
		default:
			return NS_UNAVAIL;
		}
	}

	/*
	 * `key' and `data' point to strings dynamically allocated by
	 * the yp_... functions.
	 * `data' is directly put into the stringlist of shells.
	 */
	key = data = NULL;
	if (yp_first(ypdomain, "shells", &key, &keylen, &data, &datalen))
		return NS_UNAVAIL;
	do {
		data[datalen] = '\0';		/* clear trailing \n */
		sl_add(sl, data);

		lastkey = key;
		r = yp_next(ypdomain, "shells", lastkey, keylen,
		    &key, &keylen, &data, &datalen);
		free(lastkey);
	} while (r == 0);

	if (r == YPERR_NOMORE) {
		/*
		 * `data' and `key' ought to be NULL - do not try to free them.
		 */
		return NS_SUCCESS;
	}

	return NS_UNAVAIL;
}
Exemple #18
0
/*
 * Complete a local executable
 */
static unsigned char
complete_executable(EditLine *el, char *word, int dolist)
{
	StringList *words;
	char dir[ MAXPATHLEN ];
	char *fname;
	unsigned char rv;
	size_t len;
	int error;

	if ((fname = strrchr(word, '/')) == NULL) {
		dir[0] = '\0';		/* walk the path */
		fname = word;
	} else {
		if (fname == word) {
			dir[0] = '/';
			dir[1] = '\0';
		} else {
			len = fname - word;
			(void)strncpy(dir, word, len);
			dir[fname - word] = '\0';
		}
		fname++;
	}

	words = sl_init();

	if (*dir == '\0') {		/* walk path */
		char *env;
		char *path;
		env = getenv("PATH");
		len = strlen(env);
		path = salloc(len + 1);
		(void)strcpy(path, env);
		error = find_execs(word, path, words);
	}
	else {		/* check specified dir only */
		error = find_execs(word, dir, words);
	}
	if (error != 0)
		return CC_ERROR;

	rv = complete_ambiguous(el, fname, dolist, words);
	if (rv == CC_REFRESH) {
		if (el_insertstr(el, " ") == -1)
			rv = CC_ERROR;
	}
	sl_free(words, 1);

	return rv;
}
Exemple #19
0
int sl_dialog(OBJECT *tree, int start, SLIDER *slider)
{
	XDINFO info;
	int button;

	sl_init(tree, slider);

	xd_open(tree, &info);
	button = sl_form_do(tree, start, slider, &info) & 0x7FFF;
	xd_change(&info, button, NORMAL, 0);
	xd_close(&info);

	return button;
}
Exemple #20
0
static void
run_slash_script(slash_api_base_t* api, cgi_options* options, void* stack_top)
{
    sl_vm_t* vm;
    slash_context_t ctx;
    sl_vm_frame_t exit_frame, exception_frame;
    char* canonical_filename;
    SLVAL error;

    sl_static_init();
    vm = sl_init("cgi-fcgi");

    bzero(&ctx, sizeof(ctx));
    ctx.api = api;
    ctx.headers_sent = 0;
    ctx.vm = vm;
    vm->data = &ctx;

    sl_gc_set_stack_top(vm->arena, stack_top);

    load_cgi_options(vm, options);
    load_request_info(vm, options, api, &ctx.info);

#ifdef SL_TEST
    register_cgi_test_utils(vm);
#endif

    canonical_filename = ctx.info.real_canonical_filename;
#ifndef SL_TEST
    vm->cwd = ctx.info.real_canonical_dir;
#endif

    if(canonical_filename) {
        SL_TRY(exit_frame, SL_UNWIND_ALL, {
            SL_TRY(exception_frame, SL_UNWIND_EXCEPTION, {
                bool request_valid = setup_request_object(vm, &ctx.info);

                setup_response_object(vm);

                if(!request_valid) {
                    sl_error(vm, vm->lib.Error, "Invalid Request");
                }

                sl_do_file_hashbang(vm, canonical_filename,
                    api->type == SLASH_REQUEST_CGI);
            }, error, {
                sl_response_clear(vm);
                sl_render_error_page(vm, error);
            });
        }, error, {});
/*
 * Complete a local file
 */
static unsigned char
complete_local(char *word, int list)
{
	StringList *words;
	char dir[MAXPATHLEN];
	char *file;
	DIR *dd;
	struct dirent *dp;
	unsigned char rv;

	if ((file = strrchr(word, '/')) == NULL) {
		dir[0] = '.';
		dir[1] = '\0';
		file = word;
	} else {
		if (file == word) {
			dir[0] = '/';
			dir[1] = '\0';
		} else {
			(void)strlcpy(dir, word, (size_t)(file - word) + 1);
		}
		file++;
	}

	if ((dd = opendir(dir)) == NULL)
		return (CC_ERROR);

	words = sl_init();

	for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
		if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
			continue;
		if (strlen(file) > dp->d_namlen)
			continue;
		if (strncmp(file, dp->d_name, strlen(file)) == 0) {
			char *tcp;

			tcp = strdup(dp->d_name);
			if (tcp == NULL)
				errx(1, "Can't allocate memory for local dir");
			sl_add(words, tcp);
		}
	}
	closedir(dd);

	rv = complete_ambiguous(file, list, words);
	sl_free(words, 1);
	return (rv);
}
Exemple #22
0
Fichier : conf.c Projet : sthen/nsh
int conf_dhcrelay(char *ifname, char *server, int serverlen)
{
	StringList *data;
	int alen;

	data = sl_init();
	if ((alen = db_select_flag_x_data_ctl_rtable(data, "dhcrelay", ifname, 0))
	    > 0) {
		strlcpy(server, data->sl_str[0], serverlen);
		alen = strlen(data->sl_str[0]);
	}
	sl_free(data, 1);

	return(alen);
}
Exemple #23
0
Fichier : conf.c Projet : sthen/nsh
void
conf_db_single(FILE *output, char *dbname, char *lookup, char *ifname)
{
	StringList *dbreturn;
	dbreturn = sl_init();

	if (db_select_flag_x_ctl(dbreturn, dbname, ifname) < 0) {
		printf("%% conf_db_single %s database select failed\n", dbname);
	}
	if (dbreturn->sl_cur > 0) {
		if (lookup == NULL)
			fprintf(output, " %s\n", dbname);
		else if (strcmp(dbreturn->sl_str[0], lookup) != 0)
			fprintf(output, " %s %s\n", dbname, dbreturn->sl_str[0]);
	}
	sl_free(dbreturn, 1);
}
Exemple #24
0
static void
handle_request(slash_context_t* ctx, void* dummy)
{
    sl_catch_frame_t frame;
    SLVAL err;
    char* script_filename = "";
    sl_vm_t* vm = sl_init();
    pthread_t me = ctx->thread;
    ctx->vm = vm;
    ctx->vm->data = ctx;
    ctx->sent_headers = 0;
    sl_gc_set_stack_top(ctx->vm->arena, dummy);
    
    setup_request_object(ctx->vm, &ctx->request, &script_filename);
    setup_response_object(ctx->vm);
    SL_TRY(frame, SL_UNWIND_ALL, {
        sl_do_file(ctx->vm, (uint8_t*)script_filename);
    }, err, {
Exemple #25
0
int
main(void)
{
	StringList	*sl;
	char		 teststr[] = "test";

	if ((sl = sl_init()) == NULL)
		return 1;
	if (sl_add(sl, teststr))
		return 2;
	if (sl->sl_cur != 1)
		return 3;
	if (sl->sl_str[0] != teststr)
		return 4;

	sl_free(sl, 0);
	return 0;
}
Exemple #26
0
int
main(int argc, char **argv)
{
	int ch, i;
	int ret = 0;
	int flags = 0;

	includes = sl_init();
	if (includes == NULL)
		err(EXIT_FAILURE, "sl_init()");

	while ((ch = getopt(argc, argv, "CrtvI:")) != -1) {
		switch (ch) {
		case 'C':
			flags |= C_OPTION;
			break;
		case 'r':
		case 'v':
		case 't':
			/* stub compatibility with groff's soelim */
			break;
		case 'I':
			sl_add(includes, optarg);
			break;
		default:
			sl_free(includes, 0);
			usage();
		}
	}

	argc -= optind;
	argv += optind;

	if (argc == 0)
		ret = soelim_file(stdin, flags);

	for (i = 0; i < argc; i++)
		ret = soelim_file(soelim_fopen(argv[i]), flags);

	sl_free(includes, 0);

	return (ret);
}
Exemple #27
0
static unsigned char
complete_alias(EditLine *el, char *word, int dolist)
{
	struct grouphead *gh;
	const char **ap;
	const char **p;
	int h;
	int s;
	size_t len = strlen(word);
	StringList *words;
	unsigned char rv;

	words = sl_init();

	/* allocate space for alias table */
	s = 1;
	for (h = 0; h < HSHSIZE; h++)
		for (gh = groups[h]; gh != NULL; gh = gh->g_link)
			s++;
	ap = salloc(s * sizeof(*ap));

	/* save pointers */
	p = ap;
	for (h = 0; h < HSHSIZE; h++)
		for (gh = groups[h]; gh != NULL; gh = gh->g_link)
			*p++ = gh->g_name;

	*p = NULL;

	sort(ap);
	for (p = ap; *p != NULL; p++)
		if (len == 0 || strncmp(*p, word, len) == 0)
			mail_sl_add(words, estrdup(*p));

	rv = complete_ambiguous(el, word, dolist, words);
	if (rv == CC_REFRESH) {
		if (el_insertstr(el, " ") == -1)
			rv = CC_ERROR;
	}
	sl_free(words, 1);
	return rv;
}
Exemple #28
0
static unsigned char
complete_thread_key(EditLine *el, char *word, int dolist)
{
	const char **ap;
	const char **p;
	const char *name;
	size_t len;
	StringList *words;
	unsigned char rv;
	int cnt;
	const void *cookie;

	len = strlen(word);
	words = sl_init();

	/* count the entries in the table */
	/* XXX - have a function return this rather than counting? */
	cnt = 1;	/* count the NULL terminator */
	cookie = NULL;
	while (thread_next_key_name(&cookie) != NULL)
		cnt++;

	/* allocate sufficient space for the pointers */
	ap = salloc(cnt * sizeof(*ap));

	/* load the array */
	p = ap;
	cookie = NULL;
	while ((name = thread_next_key_name(&cookie)) != NULL)
		*p++ = name;
	*p = NULL;
	sort(ap);
	for (p = ap; *p != NULL; p++)
		if (len == 0 || strncmp(*p, word, len) == 0)
			mail_sl_add(words, estrdup(*p));

	rv = complete_ambiguous(el, word, dolist, words);

	sl_free(words, 1);

	return rv;
}
Exemple #29
0
int main(int argc, char** argv)
{
    sl_static_init();
    sl_vm_t* vm = sl_init("disasm");

    if(argc < 1) {
        fprintf(stderr, "Usage: slash-dis <source file>\n");
        exit(1);
    }

    FILE* f = fopen(argv[1], "r");
    if(!f) {
        fprintf(stderr, "Could not open %s for reading.\n", argv[1]);
        exit(1);
    }

    fseek(f, 0, SEEK_END);
    size_t size = ftell(f);
    fseek(f, 0, SEEK_SET);

    char* source = sl_alloc_buffer(vm->arena, size + 1);
    fread(source, size, 1, f);
    fclose(f);

    SLVAL err;
    sl_vm_frame_t frame;
    SL_TRY(frame, SL_UNWIND_ALL, {

        size_t token_count;
        sl_token_t* tokens = sl_lex(vm, (uint8_t*)argv[1], (uint8_t*)source, size, &token_count, 0);

        sl_node_base_t* ast = sl_parse(vm, tokens, token_count, (uint8_t*)argv[1]);

        sl_vm_section_t* section = sl_compile(vm, ast, (uint8_t*)argv[1]);

        disassemble(vm, section);
        while(section_j < section_i) {
            disassemble(vm, section_queue[++section_j]);
        }

    }, err, {
Exemple #30
0
int locator_pool_init (const POOL_LIMITS *locrefs, const POOL_LIMITS *locators)
{
	const char	*env_str;

	if (mem_blocks [0].md_addr) {	/* Was already initialized -- reset. */
		mds_reset (mem_blocks, MB_END);
		return (LOC_OK);
	}
	if (!locrefs || !locrefs->reserved || !locators || !locators->reserved)
		return (LOC_ERR_PARAM);

	MDS_POOL_TYPE (mem_blocks, MB_LOCREF, *locrefs, sizeof (LocatorRef_t));
	MDS_POOL_TYPE (mem_blocks, MB_LOCATOR, *locators, sizeof (LocatorNode_t));

	/* Allocate all pools in one go. */
	mem_size = mds_alloc (mem_blocks, mem_names, MB_END);
#ifndef FORCE_MALLOC
	if (!mem_size) {
		warn_printf ("locator_pool_init: not enough memory available!\r\n");
		return (LOC_ERR_NOMEM);
	}
	log_printf (LOC_ID, 0, "locator_pool_init: %lu bytes allocated for locators.\r\n", (unsigned long) mem_size);
#endif
	sl_init (&loc_list, sizeof (LocatorNode_t *));
	lock_init_nr (loc_lock, "Locators");

	if ((env_str = config_get_string (DC_IP_NoMCast, NULL)) != NULL) {
		if (!*env_str ||
		    !strcmp (env_str, "any") ||
		    !strcmp (env_str, "ANY")) {
			loc_force_no_mcast = 1;
			loc_no_mcast = NULL;
		}
		else {
			loc_force_no_mcast = 0;
			loc_no_mcast = ip_filter_new (env_str, IPF_DOMAIN | IPF_MASK, 0);
		}
	}
	return (LOC_OK);
}