int add_help(int mode, int num) { struct helps pn; char ans[501]; extern bool enableESC; bzero(&pn, sizeof(pn)); clear(); prints("%s帮助,模式: %s\n", num==-1?"增加":"修改",mode==0?"菜单":helpmodestr[mode-1]); pn.modeid = mode; if (num == -1) ans[0] = 0; else strcpy(ans, s_help[num].index); getdata(2,0,"索引(10字节最多):",ans,11,DOECHO,NULL,false); if (! ans[0]) return -1; strncpy(pn.index, ans, 10); pn.index[10]=0; if (num == -1) ans[0] = 0; else strcpy(ans, s_help[num].desc); enableESC = true; getdata(3,0,"简单描述(40字节最多):",ans,41,DOECHO,NULL,false); enableESC = false; if (! ans[0]) return -1; strncpy(pn.desc, ans, 40); pn.desc[40]=0; if (num != -1 && s_help[num].content!=NULL) { strncpy(ans, s_help[num].content, 500); ans[500]=0; } else ans[0]=0; move(4,0); prints("请输入具体描述,15行500字内:"); multi_getdata(5, 0, 79, NULL, ans, 500, 15, false, 0); if (add_new_help(mode, &pn, ans, num) == 0) { prints("\n%s成功\n", (num == -1) ? "增加" : "修改"); pressanykey(); return 0; } else return -1; }
int get_msg(char * uid, char * msg, int line, int sms) { char genbuf[3]; int i; int gdataret; move(line, 0); clrtoeol(); if(sms) prints("发短信给:%-12s 请输入短信内容,Ctrl+Q 换行:", uid); else prints("送音信给:%-12s 请输入音信内容,Ctrl+Q 换行:", uid); msg[0] = 0; while (1) { i = multi_getdata(line+1, 0, 79, NULL, msg, MAX_MSG_SIZE, 11, false,0); if (msg[0] == '\0') return false; if(sms){ char tmp[100]; sprintf(tmp,"确定要送出吗(共%d字节,不包括前后缀)(Y)是的 (N)不要 (E)再编辑? [Y]: ", (int)strlen(msg)); gdataret = getdata(line + i + 1, 0, tmp, genbuf, 2, DOECHO, NULL, 1); }else gdataret = getdata(line + i + 1, 0, "确定要送出吗(Y)是的 (N)不要 (E)再编辑? [Y]: ", genbuf, 2, DOECHO, NULL, 1); if(gdataret == -1) return false; if (genbuf[0] == 'e' || genbuf[0] == 'E') continue; if (genbuf[0] == 'n' || genbuf[0] == 'N') return false; if (genbuf[0] == 'G') { if (HAS_PERM(getCurrentUser(), PERM_SYSOP)) return 2; else return true; } else return true; } }
static int set_smsg_key(struct _select_def *conf, int key) { switch (key) { case 'd': { char sql[100]; MYSQL s; char ans[4]; move(2,0); clrtoeol(); ans[0]=0; getdata(2, 0, "删除这条消息(Y/N) [N]: ", ans, 3, DOECHO, NULL, true); if (ans[0] != 'y' && ans[0]!='Y') return SHOW_REFRESH; mysql_init(&s); if (! my_connect_mysql(&s)) { clear(); prints("%s\n",mysql_error(&s)); pressanykey(); mysql_close(&s); return SHOW_REFRESH; } sprintf(sql,"DELETE FROM smsmsg WHERE id=%d;",s_m[conf->pos-conf->page_pos].id); if (mysql_real_query(&s, sql, strlen(sql))) { clear(); prints("%s\n",mysql_error(&s)); pressanykey(); mysql_close(&s); return SHOW_REFRESH; } mysql_close(&s); return SHOW_DIRCHANGE; } case 's': { char ans[40]; clear(); move(0,0); ans[0]=0; prints(" 超级短信选择\n"); prints("\033[1;31m------------------------------------------------------------------------\033[m\n"); getdata(2, 0, "选择全部短信请按\033[1;32m1\033[m,输入条件选择请按\033[1;32m2\033[m,取消直接回车(1/2/0) [0]: ", ans, 3, DOECHO, NULL, true); if (ans[0] == '1') { conf->page_pos = 0; sm_dest[0]=0; sm_type = -1; sm_msgtxt[0]=0; return SHOW_DIRCHANGE; } else if (ans[0] == '2') { move(3,0); getdata(3,0,"请输入要选择的短信来源(回车选择所有):",ans,15, DOECHO,NULL,true); strncpy(sm_dest, ans, 13); sm_dest[12]=0; move(4,0); getdata(4,0,"请输入要选择的短信类别(1表示发,2表示收,回车所有) [0]:",ans,3, DOECHO,NULL,true); if (ans[0] == '1') sm_type = 1; else if (ans[0] == '2') sm_type = 0; else sm_type = -1; move(5,0); getdata(5,0,"请输入开始显示的短信序号 [0]:",ans,5, DOECHO,NULL,true); conf->page_pos = atoi(ans); if (conf->page_pos <= 0) conf->page_pos=1; conf->pos=conf->page_pos; move(6,0); getdata(6,0,"请输入要短信内容包含文字(回车选择所有):",ans,21, DOECHO,NULL,true); strncpy(sm_msgtxt, ans, 21); sm_msgtxt[20]=0; return SHOW_DIRCHANGE; } else { return SHOW_REFRESH; } break; } case 'a': { conf->page_pos = 0; sm_dest[0]=0; sm_type = -1; sm_msgtxt[0]=0; return SHOW_DIRCHANGE; } case 'S': { if (! isdigit(s_m[conf->pos-conf->page_pos].dest[0])) return SHOW_CONTINUE; clear(); do_send_sms_func(s_m[conf->pos-conf->page_pos].dest, NULL); pressanykey(); return SHOW_REFRESH; } case 'r': { sm_desc = ! sm_desc; return SHOW_DIRCHANGE; } case 'z': { char ans[42]; clear(); prints("修改短消息前缀/后缀,这些会在发送的短消息内容前/后显示,占短消息字节"); if (getSession()->currentmemo->ud.smsprefix[0]) strcpy(ans, getSession()->currentmemo->ud.smsprefix); else ans[0]=0; move(2,0); prints("请输入新的前缀:"); multi_getdata(3, 0, 79, NULL, ans, 41, 6, false, 0); if (ans[0]) { strncpy(getSession()->currentmemo->ud.smsprefix, ans, 40); getSession()->currentmemo->ud.smsprefix[40]=0; } else getSession()->currentmemo->ud.smsprefix[0]=0; if (getSession()->currentmemo->ud.smsend[0]) strcpy(ans, getSession()->currentmemo->ud.smsend); else ans[0]=0; move(10,0); prints("请输入新的后缀:"); multi_getdata(11, 0, 79, NULL, ans, 41, 6, false, 0); if (ans[0]) { strncpy(getSession()->currentmemo->ud.smsend, ans, 40); getSession()->currentmemo->ud.smsend[40]=0; } else getSession()->currentmemo->ud.smsend[0]=0; write_userdata(getCurrentUser()->userid, &(getSession()->currentmemo->ud)); move(18,0); prints("修改成功"); pressreturn(); return SHOW_REFRESH; } case 'h': { clear(); prints(" 短信管理器帮助\n\n"); prints(" d 删除短信\n"); prints(" s 超级选择\n"); prints(" a 显示所有短信\n"); prints(" S 回复短信\n"); prints(" r 倒序排列\n"); prints(" z 更改短信前/后缀\n"); pressreturn(); return SHOW_REFRESH; } default: break; } return SHOW_CONTINUE; }
int calc_main() { char cmd[1005]; char history[HIST][1005]; char einfo[20][30]={ "", "", "矩阵太大", "矩阵宽度不一致", "矩阵长度不一致", "矩阵大小不一致", "除数不能为0", "底数必须为正数", "必须为正方矩阵", "越界错", "矩阵长度必须为1", "表达式出错", "操作数必须不为矩阵", "该矩阵无法求逆", "变量名称错", "变量数目过多", "矩阵输入错误", "单步值不能为0", "表达式出错", ""}; int y,x,res,i,ch,hi,oldmode; oldmode=uinfo.mode; modify_user_mode(CALC); for(i=0;i<HIST;i++) history[i][0]=0; res = get_var("res"); set_var(vars+get_var("%pi"), Pi); set_var(vars+get_var("%e"), exp(1)); clear(); outline("欢迎使用超级计算器1.0 作者:[email protected]\n"); outline("输入exit退出,输入help帮助\n\n"); while(1) { hi=0; getyx(&y, &x); cmd[0]=0; do{ UPDOWN = true; ch = multi_getdata(y, x, scr_cols-1, "> ", cmd, 995, 13, 0,0 ); UPDOWN = false; if(ch==-KEY_UP) { if(hi==HIST) cmd[0]=0; else strncpy(cmd, history[hi], 1000); hi++; if(hi>HIST) hi=0; } else if(ch==-KEY_DOWN) { hi--; if(hi<0) hi=HIST; if(hi==HIST) cmd[0]=0; else strncpy(cmd, history[hi], 1000); } } while(ch<0); y = y-1+ch; if(y>=scr_lns) y = scr_lns-1; move(y, 0); outline("\n"); if(!cmd[0]) continue; if(!strncasecmp(cmd, "exit", 5)) break; if(!strncasecmp(cmd, "quit", 5)) break; for(i=HIST-1;i>0;i--) strncpy(history[i],history[i-1],1000); strncpy(history[0],cmd,1000); if(!strncasecmp(cmd, "help", 5)||!strncasecmp(cmd, "?", 2)) { outline("变量: 1到6个字母,例如x=3\n"); outline("常量: %pi, %e\n"); outline("矩阵: [3,4;5,6] a(3:4,1:5:2) 1:5:0.5\n"); outline("函数: sin,cos,tan,asin,acos,atan,log,exp,ln,fact,\n"); outline(" sinh,cosh,tanh,asinh,acosh,atanh\n"); outline(" abs,sign,sqr,sqrt,round,floor,ceil\n"); outline(" det,inv\n"); outline("操作: + - * / ^ '(转置) .*(矩阵乘) ./(矩阵除) \n"); continue; } if(strchr(cmd, '=')) { i=strchr(cmd, '=')-cmd; if(i<=0||!check_var_name(cmd, i)) { calcerr=19; goto checkcalcerr; } cmd[i]=0; res = get_var(cmd); i++; } else { res = get_var("res"); i=0; } eval(vars+res, cmd+i, 0, strlen(cmd+i)-1); checkcalcerr: if(calcerr) { outline(einfo[calcerr]); outline("\n"); calcerr=0; continue; } else print_var(vars+res); } for(i=0;i<vart;i++) del(vars+i); modify_user_mode(oldmode); return 0; }
int add_addresslist( struct addresslist * oldal ){ struct addresslist al; char ans[110]; char anss[4]; bzero(&al,sizeof(al)); if( oldal ){ memcpy(&al, oldal, sizeof(al)); } clear(); move(0,0); ans[0]=0; prints(" 增加通讯录条目\n"); prints("\033[1;31m------------------------------------------------------------------------\033[m\n"); if(oldal) strcpy(ans, oldal->name); else ans[0]=0; getdata(2, 0, "请输入姓名(不可空):", ans, 16, DOECHO, NULL, false); if( ans[0] == '\n' || ( ans[0] == 0 && oldal == NULL ) || ans[0]=='\r' || !isprint2(ans[0])){ prints("\n取消..."); pressanykey(); return 0; } if( ans[0] == 0 ) strcpy(al.name, oldal->name); else strncpy(al.name, ans, 15); al.name[14]=0; if(oldal) strcpy(ans, oldal->bbsid); else ans[0]=0; getdata(3, 0, "请输入bbsid:", ans, 15, DOECHO, NULL, false); strncpy(al.bbsid, ans, 15); al.bbsid[14]=0; if(oldal) strcpy(ans, oldal->mobile); else ans[0]=0; getdata(4, 0, "请输入移动电话:", ans, 15, DOECHO, NULL, false); strncpy(al.mobile, ans, 15); al.mobile[14]=0; if(oldal) strcpy(ans, oldal->group); else ans[0]=0; getdata(5, 0, "请输入分组名称:", ans, 10, DOECHO, NULL, false); strncpy(al.group, ans, 10); al.group[9]=0; if(oldal) strcpy(ans, oldal->school); else ans[0]=0; getdata(6, 0, "请输入学校:", ans, 100, DOECHO, NULL, false); strncpy(al.school, ans, 100); al.school[99]=0; if(oldal) strcpy(ans, oldal->zipcode); else ans[0]=0; getdata(7, 0, "请输入邮政编码:", ans, 7, DOECHO, NULL, false); strncpy(al.zipcode, ans, 7); al.zipcode[6]=0; if(oldal) strcpy(ans, oldal->homeaddr); else ans[0]=0; getdata(8, 0, "请输入家庭地址:", ans, 100, DOECHO, NULL, false); strncpy(al.homeaddr, ans, 100); al.homeaddr[99]=0; if(oldal) strcpy(ans, oldal->companyaddr); else ans[0]=0; getdata(9, 0, "请输入工作地址:", ans, 100, DOECHO, NULL, false); strncpy(al.companyaddr, ans, 100); al.companyaddr[99]=0; if(oldal) strcpy(ans, oldal->tel_h); else ans[0]=0; getdata(10, 0, "请输入家庭电话:", ans, 20, DOECHO, NULL, false); strncpy(al.tel_h, ans, 20); al.tel_h[19]=0; if(oldal) strcpy(ans, oldal->tel_o); else ans[0]=0; getdata(11, 0, "请输入工作电话:", ans, 20, DOECHO, NULL, false); strncpy(al.tel_o, ans, 20); al.tel_o[19]=0; if(oldal) strcpy(ans, oldal->email); else ans[0]=0; getdata(12, 0, "请输入电子邮箱:", ans, 30, DOECHO, NULL, false); strncpy(al.email, ans, 30); al.email[29]=0; if(oldal) strcpy(ans, oldal->qq); else ans[0]=0; getdata(13, 0, "请输入qq:", ans, 10, DOECHO, NULL, false); strncpy(al.qq, ans, 10); al.qq[9]=0; if(oldal) sprintf(ans,"%d", oldal->birth_year); else ans[0]=0; getdata(14, 0, "请输入生日年份:", ans, 5, DOECHO, NULL, false); al.birth_year = atoi(ans); if(al.birth_year <= 0) al.birth_year = 1; if(al.birth_year < 1000) al.birth_year += 1000; if(al.birth_year > 9000) al.birth_year = 9000; if(oldal) sprintf(ans,"%d", oldal->birth_month); else ans[0]=0; getdata(15, 0, "请输入生日月份:", ans, 3, DOECHO, NULL, false); al.birth_month = atoi(ans); if(al.birth_month <= 0) al.birth_month = 1; if(al.birth_month >12) al.birth_month = 12; if(oldal) sprintf(ans,"%d", oldal->birth_day); else ans[0]=0; getdata(16, 0, "请输入生日日期:", ans, 3, DOECHO, NULL, false); al.birth_day = atoi(ans); if(al.birth_day <= 0) al.birth_day = 1; if(al.birth_day >31) al.birth_day = 31; if(oldal) strcpy(ans, oldal->memo); else ans[0]=0; move(17,0); prints("请输入备注:\n"); multi_getdata(18, 0, 79, NULL, ans, 100, 4, false, 0); ans[99]=0; if( oldal ) getdata(t_lines-1, 0, "确定修改? (Y/N) [Y]:", anss, 3, DOECHO, NULL, true); else getdata(t_lines-1, 0, "确定增加? (Y/N) [Y]:", anss, 3, DOECHO, NULL, true); if( anss[0] != 'N' && anss[0] != 'n' ) return add_sql_al( getCurrentUser()->userid, &al, ans ); return 0; }
static int choose_tmpl_post(char * title, char *fname) { FILE *fp; FILE *fpsrc; char filepath[STRLEN]; int i, ret=1; int write_ok = 0; char * tmp[ MAX_CONTENT ]; char newtitle[STRLEN], oldtitle[STRLEN]; int oldmode = uinfo.mode; bool modifying=false, loop=true; if (t_now <= 0 || t_now > MAX_TEMPLATE) return -1; if (ptemplate[t_now-1].tmpl->content_num <= 0) return -1; strncpy(oldtitle, title, STRLEN); while (loop) { if ((fp = fopen(fname, "w"))==NULL) { return -1; } modify_user_mode(POSTTMPL); for (i=0; i< ptemplate[t_now-1].tmpl->content_num; i++) { char *ans; if (modifying) ans = tmp[i]; else { ans = (char *)malloc(ptemplate[t_now-1].cont[i].length + 2); ans[0] = '\0'; } if (ans == NULL) { modify_user_mode(oldmode); fclose(fp); return -1; } clear(); move(1,0); prints("Ctrl+Q 换行, ENTER 发送"); move(3,0); prints("模板问题:%s",ptemplate[t_now-1].cont[i].text); move(4,0); prints("模板回答(最长%d字符):",ptemplate[t_now-1].cont[i].length); multi_getdata(6, 0, 79, NULL, ans, ptemplate[t_now-1].cont[i].length+1, 11, false, 0); tmp[i] = ans; } modify_user_mode(oldmode); if (ptemplate[t_now-1].tmpl->filename[0]) { struct stat st; setbfile(filepath,currboard->filename, ptemplate[t_now-1].tmpl->filename); if (stat(filepath, &st) == 0 && S_ISREG(st.st_mode) && st.st_size>2) { if ((fpsrc = fopen(filepath,"r"))!=NULL) { char buf[256]; while (fgets(buf,255,fpsrc)) { int l; int linex = 0; char *pn,*pe; #ifdef ENHANCED_TEMPLATE int sign, fmtlen, sysdef; char tmpbuf[STRLEN]; #endif for (pn = buf; *pn!='\0'; pn++) { if (*pn != '[' || *(pn+1)!='$') { fputc(*pn, fp); linex++; } else { pe = strchr(pn,']'); if (pe == NULL) { fputc(*pn, fp); continue; } #ifdef ENHANCED_TEMPLATE /* 获得[]中间的内容 */ strncpy(tmpbuf, pn+2, pe-pn-2); tmpbuf[pe-pn-2]='\0'; sysdef = 0; sign = get_parameter_index_len(tmpbuf, &l, &fmtlen, &sysdef); #else l = atoi(pn+2); #endif if (l<=0 || l > ptemplate[t_now-1].tmpl->content_num) { fputc('[', fp); continue; } #ifdef ENHANCED_TEMPLATE char *p; if (sysdef == 0) { p = malloc(strlen(tmp[l-1])+1); strcpy(p, tmp[l-1]); } else { p = malloc(STRLEN); if (!strcmp(tmpbuf, "USER")) strcpy(p, getCurrentUser()->userid); else if (!strcmp(tmpbuf, "BOARD")) strcpy(p, currboard->filename); else if (!strcmp(tmpbuf, "BNAME")) strcpy(p, currboard->title+13); else if (!strcmp(tmpbuf, "BMS")) strcpy(p, currboard->BM); else if (!strcmp(tmpbuf, "DATE")) { time_t t=time(0); struct tm *mytm; mytm = localtime(&t); sprintf(p, "%d-%02d-%02d", mytm->tm_year + 1900, mytm->tm_mon+1, mytm->tm_mday); } else strcpy(p, "未定义"); } if (fmtlen>0) { int t1, t2; t1=strlen(p); if (t1 >= fmtlen) fprintf(fp,"%s",p); else { if (sign == -1) { /* 左对齐 */ fprintf(fp, "%-*s", fmtlen, p); } else if (sign == 1) { /* 右对齐 */ fprintf(fp, "%*s", fmtlen, p); } else { /* 居中对齐 */ t2 = (fmtlen - t1)/2; fprintf(fp,"%*s%*s",t2+t1,p,t2 + t1%2, ""); } } } else fprintf(fp,"%s",p); free(p); #else fprintf(fp,"%s",tmp[l-1]); #endif pn = pe; continue; } } } fclose(fpsrc); write_ok = 1; } } } if (write_ok == 0) { for (i=0; i< ptemplate[t_now-1].tmpl->content_num; i++) fprintf(fp,"\033[1;32m%s:\033[m\n%s\n\n",ptemplate[t_now-1].cont[i].text, tmp[i]); } fclose(fp); if (ptemplate[t_now-1].tmpl->title_tmpl[0]) { char *pn,*pe; char *buf; int l; int newl = 0; #ifdef ENHANCED_TEMPLATE int sysdef; char tmpbuf[STRLEN]; #endif newtitle[0]='\0'; buf = ptemplate[t_now-1].tmpl->title_tmpl; for (pn = buf; *pn!='\0' && newl < STRLEN-1; pn++) { if (*pn != '[' || *(pn+1)!='$') { if (newl < STRLEN - 1) { newtitle[newl] = *pn ; newtitle[newl+1]='\0'; newl ++; } } else { pe = strchr(pn,']'); if (pe == NULL) { if (newl < STRLEN - 1) { newtitle[newl] = *pn ; newtitle[newl+1]='\0'; newl ++; } continue; } #ifdef ENHANCED_TEMPLATE /* 获得[]中间的内容 */ strncpy(tmpbuf, pn+2, pe-pn-2); tmpbuf[pe-pn-2]='\0'; sysdef = 0; get_parameter_index_len(tmpbuf, &l, NULL, &sysdef); #else l = atoi(pn+2); #endif if (l<0 || l > ptemplate[t_now-1].tmpl->content_num) { if (newl < STRLEN - 1) { newtitle[newl] = *pn ; newtitle[newl+1]='\0'; newl ++; } continue; } if (l == 0) { int ti; for (ti=0; oldtitle[ti]!='\0' && newl < STRLEN - 1; ti++, newl++) { newtitle[newl] = oldtitle[ti] ; newtitle[newl+1]='\0'; } } else { int ti; #ifdef ENHANCED_TEMPLATE char *p; if (sysdef == 0) { p = malloc(strlen(tmp[l-1])+1); strcpy(p, tmp[l-1]); } else { p = malloc(STRLEN); if (!strcmp(tmpbuf, "USER")) strcpy(p, getCurrentUser()->userid); else if (!strcmp(tmpbuf, "BOARD")) strcpy(p, currboard->filename); else if (!strcmp(tmpbuf, "BNAME")) strcpy(p, currboard->title+13); else if (!strcmp(tmpbuf, "BMS")) strcpy(p, currboard->BM); else if (!strcmp(tmpbuf, "DATE")) { time_t t=time(0); struct tm *mytm; mytm = localtime(&t); sprintf(p, "%d-%02d-%02d", mytm->tm_year + 1900, mytm->tm_mon+1, mytm->tm_mday); } else strcpy(p, "未定义"); } for (ti=0; p[ti]!='\0' && p[ti]!='\n' && p[ti]!='\r' && newl < STRLEN - 1; ti++, newl++) { newtitle[newl] = p[ti] ; newtitle[newl+1]='\0'; } free(p); #else for (ti=0; tmp[l-1][ti]!='\0' && tmp[l-1][ti]!='\n' && tmp[l-1][ti]!='\r' && newl < STRLEN - 1; ti++, newl++) { newtitle[newl] = tmp[l-1][ti] ; newtitle[newl+1]='\0'; } #endif } pn = pe; continue; } } strncpy(title, newtitle, STRLEN); title[STRLEN-1]='\0'; } do { char ans[4]; clear(); ansimore2(fname,false,0,19); move(21,0); clrtobot(); prints("标题: %s",title); getdata(t_lines-1,0,"确认发表 (Y)发表 (N)退出 (E)重新编辑 [Y]: ",ans,2,DOECHO,NULL,true); switch (toupper(ans[0])) { case 'N': loop=false; ret=-1; break; case 'E': modifying=true; break; default: loop=false; ret=1; break; } } while (0); } for (i=0; i< ptemplate[t_now-1].tmpl->content_num; i++) free(tmp[i]); return ret; }