segment* t_search(seg_n* cur, seg2d_t qSeg) { if(t->size==0) return NULL; float cp = cross_product(cur->segment, qSeg); if(cp==0) return cur->segment; if(cp>0) return t_search(cur->left, qSeg); else return t_search(cur->right, qSeg); }
void call_kickoff(chatcontext * pthis, const char *arg) { /* kick ID off BBS, by Luzi, 97.11.1 */ char msg[STRLEN]; struct user_info *uin; if (!HAS_PERM(getCurrentUser(), PERM_SYSOP)) { printchatline(pthis, "*** 你不是站长 ***"); return; } if (!*arg) { printchatline(pthis, "*** 请输入你要踢下站的 ID ***"); return; } else if (!strcasecmp(arg, getCurrentUser()->userid)) sprintf(msg, "*** Faint!你要把自己踢下站啊?***"); else { uin = t_search(arg, false); if (uin == NULL) { sprintf(msg, "%s 并没有上站", arg); } else { bbslog("user", "kick %s out of bbs", uin->userid); kill(uin->pid, SIGHUP); return; } } printchatline(pthis, msg); }
//{{{int t_b_search(int key, int *D, int D_size, int *T, int T_size) int t_b_search(int key, int *D, int D_size, int *T, int T_size) { int hi, lo; int region = t_search(key, T, T_size, D_size, &hi, &lo); //printf("t:%d,%d,%d\n",region,lo,hi); int r = b_search(key, D, D_size, lo, hi); return r; }
void chat_sendmsg(chatcontext * pthis, const char *arg) { /* send msg in chatroom , by alex, 96.9.5 */ char userid[IDLEN + 1]; char msg[STRLEN * 2]; struct user_info *uin; int state; nextword(&arg, userid, sizeof(userid)); if (!userid[0]) { printchatline(pthis, "\x1b[37m*** \x1b[32m请输入你要发消息的 ID\x1b[37m ***\x1b[m"); return; } else if (!*arg) { printchatline(pthis, "\x1b[37m*** \x1b[32m请输入你要发的消息\x1b[37m ***\x1b[m"); return; } else if (!HAS_PERM(getCurrentUser(), PERM_PAGE)) { /* Leeward 98.07.30 */ sprintf(msg, "\x1b[32m你没有发信息的权限\x1b[m"); } else { uin = t_search(userid, false); if (uin == NULL) { sprintf(msg, "\x1b[32m%s\x1b[37m 并没有上站\x1b[m", userid); } else if (LOCKSCREEN == uin->mode) /* Leeward 98.02.28 */ sprintf(msg, "\x1b[32m%s\x1b[37m已经锁定屏幕,请稍候再发或给他(她)写信.\n", uin->userid); else { if (!canmsg(getCurrentUser(), uin)) sprintf(msg, "\x1b[32m%s\x1b[37m已经关闭接受讯息的呼叫器.\n", uin->userid); else if (false == canIsend2(getCurrentUser(),uin->userid)) sprintf(msg, "\x1b[32m%s\x1b[37m拒绝接受你的讯息.\n", uin->userid); /*Haohmaru.99.6.6,检查是否被ignore */ else { if (get_unreadcount(uin->userid) > MAXMESSAGE) sprintf(msg, "对方尚有一些讯息未处理,请稍候再发或给他(她)写信...\n"); else { /* 保存所发msg的目的uid 1998.7.5 by dong */ strcpy(getSession()->MsgDesUid, uin->userid); state = do_sendmsg(uin, arg, 2); if (state == 1) sprintf(msg, "\x1b[37m已经发消息给 \x1b[32m%s\x1b[37m 了\x1b[m", uin->userid); else if (state == -2) sprintf(msg, "\x1b[37m对方已经离线了...\x1b[m"); else sprintf(msg, "\033[37对方不接受你的消息...\033[m"); } } } } printchatline(pthis, msg); }
void call_user(chatcontext * pthis, const char *arg) { /* invite user online to chatroom */ char msg[STRLEN * 2]; struct user_info *uin; int state; if (!*arg) { printchatline(pthis, "\033[37m*** \033[32m请输入你要邀请的 ID\033[37m ***\033[m"); return; } if (!strcasecmp(arg, getCurrentUser()->userid)) sprintf(msg, "\033[32m你不用邀请自己啊\033[m"); else if (!HAS_PERM(getCurrentUser(), PERM_PAGE)) /* Leeward 98.07.30 */ sprintf(msg, "\033[32m你没有发信息的权限\033[m"); else { uin = t_search(arg, false); if (uin == NULL) sprintf(msg, "\033[32m%s\033[37m 并没有上站\033[m", arg); else if (LOCKSCREEN == uin->mode) /* Leeward 98.02.28 */ sprintf(msg, "\033[32m%s\033[37m已经锁定屏幕,请稍候再邀请或给他(她)写信.\n", uin->userid); else if (!canmsg(getCurrentUser(), uin)) sprintf(msg, "%s 已经关闭接受讯息的呼叫器.\n", uin->userid); else { if (get_unreadcount(uin->userid) > MAXMESSAGE) sprintf(msg, "对方尚有一些讯息未处理,请稍候再邀请或给他(她)写信...\n"); else { sprintf(msg, "到聊天广场的 %s 聊天室 聊聊天", pthis->chatroom); /* 保存所发msg的目的uid 1998.7.5 by dong */ strcpy(getSession()->MsgDesUid, uin->userid); state = do_sendmsg(uin, msg, 1); if (state == 1) sprintf(msg, "\033[37m已经帮你邀请 %s 了\033[m", uin->userid); else if (state == -2) sprintf(msg, "\033[37m对方已经离线了...\033[m"); else sprintf(msg, "\033[37对方不接受你的消息...\033[m"); } } } printchatline(pthis, msg); }
int main(){ /* construct tree by hand */ struct tree_node *tp, *root_p = 0; int i; /* we ingore the return value of t_insert */ t_insert(&root_p, 4); t_insert(&root_p, 2); t_insert(&root_p, 60); t_insert(&root_p, 10); t_insert(&root_p, 3); t_insert(&root_p, 5); t_insert(&root_p, 7); /* try the search */ for(i = 1; i < 9; i++){ tp = t_search(root_p, i); if(tp) printf("%d found\n", i); else printf("%d not found\n", i); } exit(EXIT_SUCCESS); }
/*ARGSUSED*/ void dolist(Char **v, struct command *c) { Char **globbed; int i, k, ret = 0; struct stat st; USE(c); if (*++v == NULL) { struct Strbuf word = Strbuf_INIT; Strbuf_terminate(&word); cleanup_push(&word, Strbuf_cleanup); (void) t_search(&word, LIST, TW_ZERO, 0, STRNULL, 0); cleanup_until(&word); return; } v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); for (k = 0; v[k] != NULL && v[k][0] != '-'; k++) continue; if (v[k]) { /* * We cannot process a flag therefore we let ls do it right. */ Char *lspath; struct command *t; struct wordent cmd, *nextword, *lastword; Char *cp; struct varent *vp; if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } if (seterr) { xfree(seterr); seterr = NULL; } lspath = STRls; STRmCF[1] = 'C'; STRmCF[3] = '\0'; /* Look at listflags, to add -A to the flags, to get a path of ls if necessary */ if ((vp = adrof(STRlistflags)) != NULL && vp->vec != NULL && vp->vec[0] != STRNULL) { if (vp->vec[1] != NULL && vp->vec[1][0] != '\0') lspath = vp->vec[1]; for (cp = vp->vec[0]; *cp; cp++) switch (*cp) { case 'x': STRmCF[1] = 'x'; break; case 'a': STRmCF[3] = 'a'; break; case 'A': STRmCF[3] = 'A'; break; default: break; } } cmd.word = STRNULL; lastword = &cmd; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(lspath); lastword->next = nextword; nextword->prev = lastword; lastword = nextword; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(STRmCF); lastword->next = nextword; nextword->prev = lastword; #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) if (dspmbyte_ls) { lastword = nextword; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(STRmmliteral); lastword->next = nextword; nextword->prev = lastword; } #endif #ifdef COLOR_LS_F if (color_context_ls) { lastword = nextword; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(STRmmcolormauto); lastword->next = nextword; nextword->prev = lastword; } #endif /* COLOR_LS_F */ lastword = nextword; for (cp = *v; cp; cp = *++v) { nextword = xcalloc(1, sizeof cmd); nextword->word = quote(Strsave(cp)); lastword->next = nextword; nextword->prev = lastword; lastword = nextword; } lastword->next = &cmd; cmd.prev = lastword; cleanup_push(&cmd, lex_cleanup); /* build a syntax tree for the command. */ t = syntax(cmd.next, &cmd, 0); cleanup_push(t, syntax_cleanup); if (seterr) stderror(ERR_OLD); /* expand aliases like process() does */ /* alias(&cmd); */ /* execute the parse tree. */ execute(t, tpgrp > 0 ? tpgrp : -1, NULL, NULL, FALSE); /* done. free the lex list and parse tree. */ cleanup_until(&cmd); if (setintr) cleanup_until(&pintr_disabled); } else { Char *dp, *tmp; struct Strbuf buf = Strbuf_INIT; cleanup_push(&buf, Strbuf_cleanup); for (k = 0, i = 0; v[k] != NULL; k++) { tmp = dnormalize(v[k], symlinks == SYM_IGNORE); cleanup_push(tmp, xfree); dp = Strend(tmp) - 1; if (*dp == '/' && dp != tmp) #ifdef apollo if (dp != &tmp[1]) #endif /* apollo */ *dp = '\0'; if (stat(short2str(tmp), &st) == -1) { int err; err = errno; if (k != i) { if (i != 0) xputchar('\n'); print_by_column(STRNULL, &v[i], k - i, FALSE); } haderr = 1; xprintf("%S: %s.\n", tmp, strerror(err)); haderr = 0; i = k + 1; ret = 1; } else if (S_ISDIR(st.st_mode)) { Char *cp; if (k != i) { if (i != 0) xputchar('\n'); print_by_column(STRNULL, &v[i], k - i, FALSE); } if (k != 0 && v[1] != NULL) xputchar('\n'); xprintf("%S:\n", tmp); buf.len = 0; for (cp = tmp; *cp; cp++) Strbuf_append1(&buf, (*cp | QUOTE)); Strbuf_terminate(&buf); dp = &buf.s[buf.len - 1]; if ( #ifdef WINNT_NATIVE (*dp != (Char) (':' | QUOTE)) && #endif /* WINNT_NATIVE */ (*dp != (Char) ('/' | QUOTE))) { Strbuf_append1(&buf, '/'); Strbuf_terminate(&buf); } else *dp &= TRIM; (void) t_search(&buf, LIST, TW_ZERO, 0, STRNULL, 0); i = k + 1; } cleanup_until(tmp); } cleanup_until(&buf); if (k != i) { if (i != 0) xputchar('\n'); print_by_column(STRNULL, &v[i], k - i, FALSE); } if (ret) stderror(ERR_SILENT); } cleanup_until(globbed); }