/** Parse qualifiers to convert attrname into a value_pair_tmpl_t. * * VPTs are used in various places where we need to pre-parse configuration * sections into attribute mappings. * * @param[in] ctx for talloc * @param[in] name attribute name including qualifiers. * @param[in] request_def The default request to insert unqualified * attributes into. * @param[in] list_def The default list to insert unqualified attributes into. * @return pointer to a value_pair_tmpl_t struct (must be freed with * tmpl_free) or NULL on error. */ value_pair_tmpl_t *tmpl_afrom_attr_str(TALLOC_CTX *ctx, char const *name, request_refs_t request_def, pair_lists_t list_def) { value_pair_tmpl_t *vpt; char const *copy; vpt = talloc(ctx, value_pair_tmpl_t); /* parse_attr zeroes it */ copy = talloc_typed_strdup(vpt, name); if (tmpl_from_attr_str(vpt, copy, request_def, list_def) < 0) { ERROR("%s", fr_strerror()); tmpl_free(&vpt); return NULL; } return vpt; }
int m_template() { int i; POINT *pts; struct _select_def grouplist_conf; if (!chk_currBM(currBM, getCurrentUser())) { return DONOTHING; } if (tmpl_init(1) < 0) return FULLUPDATE; if (template_num == 0) { char ans[3]; clear(); getdata(t_lines - 1, 0, "本版现在没有模板,需要现在增加吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true); if (ans[0] != 'Y' && ans[0] != 'y') { tmpl_free(); return FULLUPDATE; } if (tmpl_add() < 0) { tmpl_free(); return FULLUPDATE; } } pts = (POINT *) malloc(sizeof(POINT) * BBS_PAGESIZE); for (i = 0; i < BBS_PAGESIZE; i++) { pts[i].x = 2; pts[i].y = i + 3; } bzero(&grouplist_conf, sizeof(struct _select_def)); grouplist_conf.item_count = template_num; grouplist_conf.item_per_page = BBS_PAGESIZE; /* * 加上 LF_VSCROLL 才能用 LEFT 键退出 */ grouplist_conf.flag = LF_VSCROLL | LF_BELL | LF_LOOP | LF_MULTIPAGE; grouplist_conf.prompt = "◆"; grouplist_conf.item_pos = pts; grouplist_conf.title_pos.x = 0; grouplist_conf.title_pos.y = 0; grouplist_conf.pos = 1; /* initialize cursor on the first mailgroup */ grouplist_conf.page_pos = 1; /* initialize page to the first one */ grouplist_conf.show_data = tmpl_show; grouplist_conf.pre_key_command = tmpl_prekey; grouplist_conf.key_command = tmpl_key; grouplist_conf.show_title = tmpl_refresh; grouplist_conf.get_data = tmpl_getdata; grouplist_conf.on_select = tmpl_select; list_select_loop(&grouplist_conf); free(pts); tmpl_free(); return FULLUPDATE; }
int choose_tmpl(char *title, char *fname) { POINT *pts; struct _select_def grouplist_conf; int i; if (tmpl_init(0) < 0) return -1; if (template_num == 0) { clear(); move(3,0); prints("本版没有模板可供使用"); pressanykey(); tmpl_free(); return -1; } t_now = 0; pts = (POINT *) malloc(sizeof(POINT) * BBS_PAGESIZE); for (i = 0; i < BBS_PAGESIZE; i++) { pts[i].x = 2; pts[i].y = i + 3; } bzero(&grouplist_conf, sizeof(struct _select_def)); grouplist_conf.arg = fname; grouplist_conf.item_count = template_num; grouplist_conf.item_per_page = BBS_PAGESIZE; grouplist_conf.flag = LF_VSCROLL | LF_BELL | LF_LOOP | LF_MULTIPAGE; grouplist_conf.prompt = "◆"; grouplist_conf.item_pos = pts; grouplist_conf.title_pos.x = 0; grouplist_conf.title_pos.y = 0; grouplist_conf.pos = 1; grouplist_conf.page_pos = 1; grouplist_conf.show_data = tmpl_show; grouplist_conf.pre_key_command = tmpl_prekey; grouplist_conf.key_command = choose_tmpl_key; grouplist_conf.show_title = choose_tmpl_refresh; grouplist_conf.get_data = choose_tmpl_getdata; grouplist_conf.on_select = choose_tmpl_select; list_select_loop(&grouplist_conf); if (t_now > 0) { if (choose_tmpl_post(title, fname) < 0) t_now = 0; } free(pts); tmpl_free(); if (t_now > 0) { t_now = 0; return 0; } return -1; }