本文整理汇总了C++中sl_init函数的典型用法代码示例。如果您正苦于以下问题:C++ sl_init函数的具体用法?C++ sl_init怎么用?C++ sl_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sl_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: help
/*
* 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);
}
}
示例2: run_slash_script
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);
});
示例3: complete_ifname
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);
}
示例4: _local_initshells
/*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;
}
示例5: complete_command
/*
* 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);
}
示例6: _dns_initshells
/*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);
}
示例7: conf_rtables
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);
}
示例8: conf_sppp_mh
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");
}
示例9: main
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;
}
示例10: vio_partition_val
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;
}
示例11: setup_vm
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;
}
示例12: rs_init
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);
}
示例13: conf_rtables_rtable
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");
}
示例14: mail_sl_init
/*
* 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;
}
示例15: sl_init_data
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;
}