📄 comment.cpp
字号:
/**************************//*修改日期: 2000年12月26日*//*版 本 号: Version 1.1.2*//**************************/#include <unistd.h>#include <stdio.h> #include <stdlib.h>#include <signal.h>#include <netinet/in.h>#include <arpa/inet.h>#include <time.h>#include <math.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/fcntl.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <errno.h>#include <sys/time.h>#include <curses.h>#include <varargs.h>#include <stdlib.h>#include "comment.h"#include "xia.h"#include <string.h>#include <ctype.h>/*删除字符串头部空格\TAB\回车符*/void strheadcut(char *str){ int i, len; char tmp[512]; char *stmp; stmp=tmp; strcpy(stmp,str); len = strlen(stmp); for (i = 0; i < len; i++,stmp++) if ( ( (*stmp) != ' ') && ( (*stmp) != '\n') && ( (*stmp) != '\t') ) break; strcpy(str,stmp);}/*删除字符串空格\TAB\回车符*/void strallcut(char *str){ int i, len, j = 0; char sp[512]; for (i = 0; *(str + i) != '\0'; i++) { if ( *(str + i) == ' ' || *(str + i) == '\n' || *(str + i) == '\t') continue; sp[j++] = *(str + i); } sp[j] = 0; strcpy(str, sp);}/*截断字符串尾部空格\TAB\回车符*/void strendcut(char *str){ int i, len; len = strlen(str); for (i = len - 1; i > -1; i--) if ( (str[i] == ' ') || (str[i] == '\n') || (str[i] == '\t') ) str[i] = 0; else break;}/* 返回字符第一次出现的位置 */int posch(char *str, char ch){ int i; for (i = 0; i < strlen(str) && str[i] != ch; i++); if (i == strlen(str)) return(-1) ; else return(i);}/*在窗口中某位置接收选择一字符,必须包含头文件ctype.h*//*#define inchar(x,y,charset) winchar(stdscr,x,y,charset)*/char winchar(WINDOW *win, int y, int x, char *chset){ int posch(char *, char); int ch = 0; int f, pos = 0; mvwaddch(win, y, x, chset[pos]); wmove(win, y, x); wrefresh(win); keypad(win, 1); do { ch = wgetch(win); wrefresh(win); if ((f = posch(chset, ch)) >= 0) { pos = f; mvwaddch(win, y, x, chset[pos]); wmove(win, y, x); wrefresh(win); ch = 0; } else switch (ch) { case 10: return(chset[pos]); case 4: return(4); case 27: return(27); case 258: if (pos < strlen(chset) - 1) pos++; else pos = 0; mvwaddch(win, y, x, chset[pos]); wmove(win, y, x); wrefresh(win); ch = 0; break; case 259: if (pos > 0) --pos; else pos = strlen(chset) - 1; mvwaddch(win, y, x, chset[pos]); wmove(win, y, x); wrefresh(win); ch = 0; break; case 260: if (pos > 0) --pos; else pos = strlen(chset) - 1; mvwaddch(win, y, x, chset[pos]); wmove(win, y, x); wrefresh(win); ch = 0; break; case 261: if (pos < strlen(chset) - 1) pos++; else pos = 0; mvwaddch(win, y, x, chset[pos]); wmove(win, y, x); wrefresh(win); ch = 0; break; default: if (iscntrl(ch)) return(ch); else ch = 0; } } while (!ch); return(chset[pos]);}/* 【注意】: 以下程序段落的窗口宽度为 4*n *//*画窗口边框*/void framewin(WINDOW *win, int colorf, char *title, int colort){ int i, j, x, y; chtype oldattr; getmaxyx(win, y, x); oldattr = getattrs(win); if (colorf != 0) wattron(win, COLOR_PAIR(colorf)); else wstandout(win); mvwaddstr(win, 0, 0, "┏"); for (i = 0; i < (x - 4) / 2; i++) waddstr(win, "━"); waddstr(win, "┓"); for (i = 1; i <= y - 2; i++) { mvwaddstr(win, i, 0, "┃"); mvwaddstr(win, i, x - 2, "┃"); } mvwaddstr(win, y - 1, 0, "┗"); for (i = 0; i < (x - 4) / 2; i++) waddstr(win, "━"); waddstr(win, "┛"); wrefresh(win); if (colorf == 0) wstandend(win); if (strlen(title) > 0) { if (colort == 0) wstandout(win); else wattron(win, A_STANDOUT | COLOR_PAIR(colort)); i = (x - strlen(title)) / 2 - 1; if (i % 2 != 0) i++; mvwaddstr(win, 0, i, title); wrefresh(win); if (colort == 0) wstandend(win); } wattrset(win, oldattr);}/*在屏幕上某位置输出一个某长度的字符串*/void outstr(WINDOW *win, int y, int x, int maxlen, char *str){ int len, i; char tmp[255] = ""; strncpy(tmp, str, maxlen); len = strlen(tmp); for (i = len; i < maxlen; i++) tmp[i] = ' '; tmp[maxlen] = 0; mvwaddstr(win, y, x, tmp);}/*窗口清屏(包括边框)*/void wclrscr(WINDOW *win){ /*u_short x,y,j,i;*/ int x, y, j, i; getmaxyx(win, y, x); for (i = 0; i < y; i++) for (j = 0; j < x - 1; j += 2) mvwaddstr(win, i, j, " "); wmove(win, 0, 0); wrefresh(win);}/*窗口清屏(不包括边框)*/void wclrscr1(WINDOW *win){ /*u_short x,y,j,i;*/ int x, y, j, i; getmaxyx(win, y, x); for (i = 1; i < y - 1; i++) for (j = 2; j < x - 3; j += 2) mvwaddstr(win, i, j, " "); wmove(win, 1, 2); wrefresh(win);}/*从一个含\n的字符串中找到最长的长度和\n的数目*/int maxstrlen(char *str){ int i, j = 0, c = 1, len = 0; for (i = 0; i < strlen(str); i++) { if (str[i] == 10) { c++; if (j > len) len = j; j = 0; } else j++; if (j > len) len = j; } return(c * 1000 + len);}/*输出汉字字符串*/void waddstrhz(WINDOW *win, char *msg){ char hz[3] = ""; int i, l = 1; for (i = 0; i < strlen(msg); i++) if (msg[i] == 10) { l++; wmove(win, l, 2); wrefresh(win); } else if (msg[i] < 161) waddch(win, msg[i]); else { hz[0] = msg[i]; hz[1] = msg[++i]; hz[2] = '\0'; waddstr(win, hz); wrefresh(win); wgetch(win); }}/*显示提示信息框(加提头)*/#define showtmessage(y,x,title,msg) _showtmessage( y,x,title,msg,0) /* Modify by Zhangcf */void _showtmessage(int y, int x, char *title, char *msg, int color){ /**** int maxstrlen(char *); void framewin(WINDOW *,int,char *,int); void wclrscr1(WINDOW *); void wclrscr(WINDOW *); ****/ int j, i, l = 1, k, len; WINDOW * win; char str[80]; len = maxstrlen(msg); if ((k = len % 1000) < 20) k = 20; else if ((k % 2) != 0) k++; win = newwin(len / 1000 + 2, k + 4, y, x); wstandout(win); framewin(win, color, title, color); if (color == 0) wstandout(win); else wattron(win, A_STANDOUT | COLOR_PAIR(color)); wclrscr1(win); wmove(win, l, 2); for (i = 0, j = 0; i < strlen(msg); i++, j++) if (msg[i] == 10) { str[j] = 0; waddstr(win, str); j = -1; l++; wmove(win, l, 2); } else str[j] = msg[i]; str[j] = 0; waddstr(win, str); wrefresh(win); keypad(win, 1); beep(); wgetch(win); if (color == 0) wstandend(win); else wattroff(win, A_STANDOUT | COLOR_PAIR(color)); wclrscr(win); wrefresh(win);}/*显示提示信息框(不加提头)*/ #define showmessage(y,x,msg) _showmessage( y,x,msg,0) void _showmessage(int y, int x, char *msg, int color){ /*** int maxstrlen(char *); void framewin(WINDOW *,int,char *,int); void wclrscr1(WINDOW *); void wclrscr(WINDOW *); ***/ int j, i, l = 1, k, len; WINDOW * win; char str[80]; len = maxstrlen(msg); if ((k = len % 1000) < 20) k = 20; else if ((k % 2) != 0) k++; win = newwin(len / 1000 + 4, k + 4, y, x); wstandout(win); framewin(win, color, "[提 示]", color); if (color == 0) wstandout(win); else wattron(win, A_STANDOUT | COLOR_PAIR(color)); wclrscr1(win); wmove(win, l, 2); for (i = 0, j = 0; i < strlen(msg); i++, j++) if (msg[i] == 10) { str[j] = 0; waddstr(win, str); j = -1; l++; wmove(win, l, 2); } else str[j] = msg[i]; str[j] = 0; waddstr(win, str); l += 2; wmove(win, l, (k + 4 - strlen("按任意键继续")) / 2); waddstr(win, "按任意键继续"); wrefresh(win); keypad(win, 1); beep(); wgetch(win); if (color == 0) wstandend(win); else wattroff(win, A_STANDOUT | COLOR_PAIR(color)); wclrscr(win); wrefresh(win);}/*显示一个对话框*/int showdialog1(int y, int x, char *title, char *msg){ /*** void framewin(WINDOW *,int,char *,int); void wclrscr1(WINDOW *); void wclrscr(WINDOW *); ***/ int k, g, i, j , l = 1, len; WINDOW * win; char str[80]; len = maxstrlen(msg); if ((k = (len % 1000 + 4)) >= 20) { if (k % 2 != 0) k++; win = newwin(len / 1000 + 4, k, y, x); } else win = newwin(len / 1000 + 4, 20, y, x); if (win == (WINDOW * )0) return(-2); framewin(win, 0, title, '\071'); wattron(win, A_STANDOUT); wclrscr1(win); wmove(win, 1, 2); for (i = 0, j = 0; i < strlen(msg); i++, j++) if (msg[i] == 10) { str[j] = 0; waddstr(win, str); j = -1; l++; wmove(win, l, 2); } else str[j] = msg[i]; str[j] = 0; waddstr(win, str); wattroff(win, A_STANDOUT); getmaxyx(win, g, k); k = k / 2; keypad(win, 1); l = 1; wattron(win, COLOR_PAIR('\071')); do { if (i == 4) { wattroff(win, COLOR_PAIR('\071')); wclrscr(win); wrefresh(win); return(-1); } l = !l; if (l) { wattron(win, A_STANDOUT); mvwaddstr(win, g - 2, k + 2, "确认"); wattroff(win, A_STANDOUT); wattron(win, COLOR_PAIR('\071')); mvwaddstr(win, g - 2, k - 6, "放弃"); } else { wattron(win, A_STANDOUT); mvwaddstr(win, g - 2, k - 6, "放弃"); wattroff(win, A_STANDOUT); wattron(win, COLOR_PAIR('\071')); mvwaddstr(win, g - 2, k + 2, "确认"); } } while ((i = wgetch(win)) != 10); wattron(win, COLOR_PAIR('\070')); wclrscr(win); wrefresh(win); return(l);}/*显示一个对话框*/int showdialog(int y, int x, char *title, char *msg){ /*** void framewin(WINDOW *,int,char *,int); void wclrscr1(WINDOW *); void wclrscr(WINDOW *); ***/ int k, g, i, j , l = 1, len; WINDOW * win; char str[80]; len = maxstrlen(msg); if ((k = (len % 1000 + 4)) >= 20) { if (k % 2 != 0) k++; win = newwin(len / 1000 + 4, k, y, x); } else win = newwin(len / 1000 + 4, 20, y, x); if (win == (WINDOW * )0) return(-2); framewin(win, 0, title, '\071'); wattron(win, A_STANDOUT); wclrscr1(win); wmove(win, 1, 2); for (i = 0, j = 0; i < strlen(msg); i++, j++) if (msg[i] == 10) { str[j] = 0; waddstr(win, str); j = -1; l++; wmove(win, l, 2); } else str[j] = msg[i]; str[j] = 0; waddstr(win, str); wattroff(win, A_STANDOUT); getmaxyx(win, g, k); k = k / 2; keypad(win, 1); l = 1; wattron(win, COLOR_PAIR('\071')); do { if (i == 4) { wattroff(win, COLOR_PAIR('\071')); wclrscr(win); wrefresh(win); return(-1); } l = !l; if (!l) { wattron(win, A_STANDOUT); mvwaddstr(win, g - 2, k + 2, "确认"); wattroff(win, A_STANDOUT); wattron(win, COLOR_PAIR('\071')); mvwaddstr(win, g - 2, k - 6, "放弃"); } else { wattron(win, A_STANDOUT); mvwaddstr(win, g - 2, k - 6, "放弃"); wattroff(win, A_STANDOUT); wattron(win, COLOR_PAIR('\071')); mvwaddstr(win, g - 2, k + 2, "确认"); } } while ((i = wgetch(win)) != 10); wattron(win, COLOR_PAIR('\070')); wclrscr(win); wrefresh(win); return(l);}/*在字符串的某位置上插入某字符,字符串长度增1*/void inschstr(char ch, int pos, char *str){ char i, len; if (pos < 0 ) return; len = strlen(str); if (pos < len) { str[len+1] = 0; for (i = len; i > pos; i--) str[i] = str[i-1]; str[pos] = ch; } else { str[len] = ch; str[len+1] = 0; }}/*在字符串的某位置上插入某字符,字符串长度不变*/void inschstrover(char ch, int pos, char *str){ int i, len; len = strlen(str); if (pos < 0 || pos >= len) return; for (i = len - 1; i > pos; i--) str[i] = str[i-1]; str[pos] = ch;}/*覆盖字符串中某一位置的字符*/void covchstr(char ch, int pos, char *str){ if ( (pos >= 0) && (pos < ( strlen(str) ) ) ) *(str + pos) = ch;}/*用DEL键的方式删除字符串中某位置的字符*/void delchstr(char *str, int pos){ int i, len; len = strlen(str); if (pos < 0 || pos >= len) return; for (i = pos; i < len - 1; i++) str[i] = str[i+1]; str[i++] = ' '; str[i] = '\0';}/*用BACKSPACE键的方式删除字符串中某位置的字符*/void bkspchstr(char *str, int pos){ int i, len; len = strlen(str); if (pos < 0 || pos >= len) return; for (i = pos; i < len; i++) str[i-1] = str[i]; str[i-1] = ' '; str[i] = '\0';}/*行编辑控件*//*#define geteditstr(a,b,c,d,e) _geteditstr(a,b,c,d,e,0,0,"")*/int _geteditstr(WINDOW *win, int y, int x, int len, char *value, int hlpy, int hlpx, char *hlp){ /*** void inschstr(char,int,char *); void showtmessage(int,int,char *,char *); void delchstr(char *,int) ***/ int modi = 0, key, ins = 0, pos = 0, i, rlen, eflag = 1; rlen = strlen(value); keypad(win, 1); while (eflag == 1) { rlen = strlen(value); mvwaddstr(win, y, x, value ); for (i = rlen; i < len; i++, waddch(win, ' '), value[i] = 0); wmove(win, y, pos + x); wrefresh(win); key = wgetch(win); if ((key > 31) && (key < 256)) if (ins) if (rlen < len) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -