new vers.
This commit is contained in:
@ -2,9 +2,8 @@
|
||||
|
||||
character*(*) reserved
|
||||
|
||||
integer dmax, nmax, nmenu, chartperiod, naux, nwin
|
||||
parameter (dmax=1024, nmax=12, nmenu=13, nwin=4
|
||||
1 , chartperiod=5, naux=1)
|
||||
integer dmax, nmax, nmenu, naux, nwin
|
||||
parameter (dmax=1024, nmax=12, nmenu=13, nwin=4, naux=1)
|
||||
! dmax*nmax*4 should be less than COC_RES_LEN in coc_util.h
|
||||
integer minRange, maxRange, oneDay
|
||||
parameter (minRange=60, maxRange=7*24*3600, oneDay=24*3600)
|
||||
@ -28,6 +27,7 @@
|
||||
integer im ! 1...nmax
|
||||
integer first,last,step,tbase,lastj
|
||||
integer retLen(nmax)
|
||||
integer chartperiod/5/
|
||||
logical focus(nmax)/3*.true.,9*.false./
|
||||
logical omit(nmax)/12*.false./
|
||||
logical fixleft/.false./
|
||||
@ -87,6 +87,10 @@
|
||||
read(reserved, *, iostat=iostat) fact
|
||||
if (fact .lt. 1) fact=1
|
||||
if (window .eq. 0) window=1800.
|
||||
iret = tecs_get_mult(' logperiod ', t, 1, dx)
|
||||
if (iret .lt. 0) goto 99
|
||||
chartperiod = nint(dx)
|
||||
if (chartperiod .lt. 1) chartperiod=5
|
||||
saveit=.false.
|
||||
mode=live
|
||||
yzoom=.false.
|
||||
@ -209,7 +213,7 @@
|
||||
else if (step .gt. 20) then
|
||||
step=30
|
||||
else
|
||||
step=(step+4)/5*5
|
||||
step=(step+chartperiod-1)/chartperiod*chartperiod
|
||||
endif
|
||||
first=last-(last-first+step-1)/step*step ! round first
|
||||
! print *,step,last-first
|
||||
|
222
tecs/term.c
222
tecs/term.c
@ -14,10 +14,10 @@
|
||||
#define REF_TMO 100
|
||||
#define HISTORY_LINES 256
|
||||
|
||||
#define L_ARROW '\200'
|
||||
#define R_ARROW '\201'
|
||||
#define U_ARROW '\202'
|
||||
#define D_ARROW '\203'
|
||||
#define L_ARROW 0200
|
||||
#define R_ARROW 0201
|
||||
#define U_ARROW 0202
|
||||
#define D_ARROW 0203
|
||||
#define EVT_CHAR '\0'
|
||||
#define DEL_CHAR '\b'
|
||||
#define RET_CHAR '\n'
|
||||
@ -26,6 +26,9 @@ static char esc_key='\0';
|
||||
|
||||
static fd_set regMask;
|
||||
static int minReg=0, maxReg=0;
|
||||
static char filehead[256]="";
|
||||
|
||||
static char *func[256]={NULL};
|
||||
|
||||
void term_reg_socket(int socket) {
|
||||
FD_SET(socket, ®Mask);
|
||||
@ -41,7 +44,7 @@ void term_unr_socket(int socket) {
|
||||
FD_CLR(socket, ®Mask);
|
||||
}
|
||||
|
||||
int term_raw_key(char *key, int msecTmo) {
|
||||
int term_raw_key(int *key, int msecTmo) {
|
||||
fd_set mask;
|
||||
|
||||
mask=regMask;
|
||||
@ -81,9 +84,10 @@ int term_wait_socket(int socket, int msecTmo) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int term_get_key(char *key, int msecTmo) {
|
||||
int term_get_key(int *key, int msecTmo) {
|
||||
int iret;
|
||||
char k;
|
||||
int k;
|
||||
int kode;
|
||||
|
||||
if (esc_key==0) {
|
||||
iret=term_raw_key(&k, msecTmo);
|
||||
@ -93,8 +97,8 @@ int term_get_key(char *key, int msecTmo) {
|
||||
while (k==27) { /* esc */
|
||||
iret=term_raw_key(&k, ESC_TMO);
|
||||
switch (k) {
|
||||
case 'O': k='\217'; break; /* ss3 */
|
||||
case '[': k='\233'; break; /* csi */
|
||||
case 'O': k=0217; break; /* ss3 */
|
||||
case '[': k=0233; break; /* csi */
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -104,9 +108,11 @@ int term_get_key(char *key, int msecTmo) {
|
||||
return(iret);
|
||||
}
|
||||
switch (k) {
|
||||
case '\233': /* csi */
|
||||
case 0233: /* csi */
|
||||
iret=term_raw_key(&k, ESC_TMO);
|
||||
kode=0;
|
||||
while (k>='0' && k <='9') {
|
||||
kode=kode*10+(k-'0');
|
||||
iret=term_raw_key(&k, ESC_TMO);
|
||||
}
|
||||
if (iret!=STDIN_FILENO) {
|
||||
@ -119,10 +125,16 @@ int term_get_key(char *key, int msecTmo) {
|
||||
case 'C': k=R_ARROW; break;
|
||||
case 'A': k=U_ARROW; break;
|
||||
case 'B': k=D_ARROW; break;
|
||||
default: k='?';
|
||||
default:
|
||||
if (k=='~') {
|
||||
k = 128 + kode;
|
||||
} else {
|
||||
k += 128;
|
||||
}
|
||||
if (k>255) k='?';
|
||||
}
|
||||
break;
|
||||
case '\217': /* ss3 */
|
||||
case 0217: /* ss3 */
|
||||
iret=term_raw_key(&k, ESC_TMO);
|
||||
if (iret!=STDIN_FILENO) {
|
||||
esc_key=k;
|
||||
@ -139,11 +151,11 @@ int term_get_key(char *key, int msecTmo) {
|
||||
case 'C': k=R_ARROW; break;
|
||||
case 'A': k=U_ARROW; break;
|
||||
case 'B': k=D_ARROW; break;
|
||||
default: k='?';
|
||||
default: k += 128; if (k>255) k='?';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '\177': /* del */
|
||||
case 0177: /* del */
|
||||
case '\b': /* bs */
|
||||
k=DEL_CHAR;
|
||||
break;
|
||||
@ -154,7 +166,9 @@ int term_get_key(char *key, int msecTmo) {
|
||||
case EVT_CHAR: /* time out*/
|
||||
break;
|
||||
default:
|
||||
if (k<' ' || k>'\176') k='?';
|
||||
if (k>0176) {
|
||||
k='?';
|
||||
}
|
||||
}
|
||||
*key=k;
|
||||
esc_key='\0';
|
||||
@ -168,34 +182,56 @@ static char *history[HISTORY_LINES]={NULL};
|
||||
|
||||
static int hist_pos=0; /* position when scrolling through the history */
|
||||
static int hist_end=0; /* end of history. Always history[hist_end]==NULL */
|
||||
static char filehead[256]="";
|
||||
|
||||
FILE *term_open_pref(char *head, char *mode) {
|
||||
char buf[PATH_MAX], hom[PATH_MAX];
|
||||
char *cret, *home, usr[256];
|
||||
FILE *term_open_pref(int temp, char *head, char *mode) {
|
||||
char buf[PATH_MAX+1], wd[PATH_MAX];
|
||||
char *usr, *home, *p;
|
||||
int l;
|
||||
|
||||
cret=getenv("USER");
|
||||
if (cret == NULL || *cret == '\0') return NULL;
|
||||
str_copy(usr, cret);
|
||||
if (strcmp(usr, "lnsg") == 0) { /* special case lnsg */
|
||||
cret=getcwd(buf, sizeof(buf));
|
||||
if (cret == NULL) return NULL;
|
||||
usr = getenv("USER");
|
||||
if (temp && usr==NULL) return NULL;
|
||||
if (usr != NULL && *usr != '\0' && strstr(usr, "lnsg") != 0) {
|
||||
if (! getcwd(wd, sizeof wd)) return NULL;
|
||||
home=getenv("HOME");
|
||||
realpath(home, hom);
|
||||
cret=strstr(buf,hom);
|
||||
if (cret == buf) { /* cwd starts with HOME, take subdirectory as usr */
|
||||
cret+=strlen(hom)+1;
|
||||
str_copy(usr, "lnsg_");
|
||||
str_append(usr, cret);
|
||||
cret=strchr(usr, '/');
|
||||
if (cret != NULL) *cret='\0';
|
||||
}
|
||||
}
|
||||
/* usr is now the username, or lnsg_<subdirectory> */
|
||||
if (!home) return NULL;
|
||||
realpath(home, buf);
|
||||
l = strlen(buf);
|
||||
buf[l] = '/'; l++;
|
||||
buf[l]= '\0';
|
||||
if (wd[l] != '\0' && strncmp(wd, buf, l) == 0) { /* wd starts with $HOME */
|
||||
p = strchr(wd+l, '/');
|
||||
if (p) *p='\0'; /* determine 1st subdirectory of $HOME */
|
||||
if (temp) {
|
||||
str_append(wd, "_lnsg");
|
||||
usr = wd+l;
|
||||
} else {
|
||||
home = wd;
|
||||
}
|
||||
} else {
|
||||
home = buf;
|
||||
|
||||
str_copy(buf, head);
|
||||
str_append(buf, usr);
|
||||
return fopen(buf, mode);
|
||||
}
|
||||
} else {
|
||||
home=getenv("HOME");
|
||||
if (!home) return NULL;
|
||||
}
|
||||
if (temp) {
|
||||
/* usr is now the username, or lnsg_<subdirectory> */
|
||||
str_copy(buf, "/tmp/");
|
||||
str_append(buf, head);
|
||||
str_append(buf, ".");
|
||||
str_append(buf, usr);
|
||||
} else {
|
||||
str_copy(buf, home);
|
||||
str_append(buf, "/");
|
||||
str_append(buf, head);
|
||||
}
|
||||
if (*mode == 'd') {
|
||||
unlink(buf);
|
||||
return NULL;
|
||||
} else {
|
||||
return fopen(buf, mode);
|
||||
}
|
||||
}
|
||||
|
||||
char *term_fgets(char *buf, int size, FILE *fil) {
|
||||
@ -226,7 +262,7 @@ void term_save_hist(int trimlast) {
|
||||
FILE *fil;
|
||||
int i,n;
|
||||
if (filehead[0]=='\0') return;
|
||||
fil=term_open_pref(filehead, "w");
|
||||
fil=term_open_pref(1, filehead, "w");
|
||||
if (fil==NULL) return;
|
||||
n=HISTORY_LINES-1;
|
||||
if (trimlast) {
|
||||
@ -248,10 +284,9 @@ void term_read_hist(char *id) {
|
||||
int i;
|
||||
char buf[1024], *lin;
|
||||
|
||||
str_copy(filehead, "/tmp/");
|
||||
str_append(filehead, id);
|
||||
str_copy(filehead, id);
|
||||
str_append(filehead, "_hist.");
|
||||
fil=term_open_pref(filehead, "r");
|
||||
fil=term_open_pref(1, filehead, "r");
|
||||
if (fil==NULL) return;
|
||||
hist_end=0;
|
||||
while (hist_end<HISTORY_LINES-1 && !feof(fil)) {
|
||||
@ -285,7 +320,8 @@ void term_off(void) {
|
||||
}
|
||||
|
||||
int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
char key, *lin;
|
||||
char *lin;
|
||||
int key;
|
||||
int i,l,iret,buflen;
|
||||
char tmp[512];
|
||||
static char back[128]="";
|
||||
@ -304,7 +340,7 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
while (1) {
|
||||
if (iret==-1 || key == RET_CHAR || key==EVT_CHAR) { /* refresh after a short timeout */
|
||||
snprintf(tmp, sizeof tmp, "%s%s%s%s%s%.*s",
|
||||
"\r\033[1m", /* bold */
|
||||
"\r\033[0m\033[1m", /* no color, bold */
|
||||
prompt, "\033[34m", /* blue */
|
||||
buf, "\033[K\033[0m", /* clear to end of line, clear colors */
|
||||
l - *pos, back);
|
||||
@ -377,7 +413,21 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
}
|
||||
*pos=l;
|
||||
break;
|
||||
case 1: /* ctrl-A: jump to begin of line */
|
||||
*pos = 0;
|
||||
break;
|
||||
case 5: /* ctrl-E: jump to end of line */
|
||||
*pos = strlen(buf);
|
||||
break;
|
||||
default:
|
||||
if (key <' ' || key > 0176) { /* untreated special key */
|
||||
if (func[key] != NULL) {
|
||||
snprintf(buf, size, "%s", func[key]);
|
||||
key = RET_CHAR;
|
||||
continue;
|
||||
}
|
||||
key = '?';
|
||||
}
|
||||
if (l<size-1) {
|
||||
for (i=l; i>*pos; i--) {
|
||||
buf[i]=buf[i-1];
|
||||
@ -392,3 +442,85 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
}
|
||||
}
|
||||
|
||||
void term_define_key(char *cmd, int keyArg) {
|
||||
int iret;
|
||||
int key;
|
||||
|
||||
if (keyArg) {
|
||||
key = keyArg;
|
||||
} else {
|
||||
if (*cmd) {
|
||||
printf("\n# press key for command '%s' or return", cmd);
|
||||
} else {
|
||||
printf("\n# press key for which to remove command");
|
||||
}
|
||||
iret = term_get_key(&key, 5000);
|
||||
}
|
||||
switch (key) {
|
||||
case EVT_CHAR:
|
||||
case DEL_CHAR:
|
||||
case L_ARROW:
|
||||
case R_ARROW:
|
||||
case U_ARROW:
|
||||
case D_ARROW:
|
||||
break;
|
||||
case RET_CHAR:
|
||||
printf("\n# canceled\n");
|
||||
default:
|
||||
if (key <' ' || key > 0176) { /* special key */
|
||||
if (*cmd) {
|
||||
if (func[key]) free(func[key]);
|
||||
func[key] = strdup(cmd);
|
||||
if (!keyArg) {
|
||||
printf("\n# programmed key %d\n", key);
|
||||
}
|
||||
} else {
|
||||
if (func[key]) {
|
||||
if (!keyArg) {
|
||||
printf("\n# removed command '%s' from key %d\n", func[key], key);
|
||||
}
|
||||
free(func[key]);
|
||||
} else {
|
||||
if (!keyArg) {
|
||||
printf("\n# no command on key %d\n", key);
|
||||
}
|
||||
}
|
||||
func[key] = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("\n# key %d is not programmable\n", key);
|
||||
}
|
||||
|
||||
void term_save_keys(FILE *fil, void (*out)(char *)) {
|
||||
int key;
|
||||
char buf[128];
|
||||
|
||||
for (key=0; key<256; key++) {
|
||||
if (func[key]) {
|
||||
fprintf(fil, "%d %s\n", key, func[key]);
|
||||
if (out) {
|
||||
snprintf(buf, sizeof buf, " key %d defined as '%s'\n", key, func[key]);
|
||||
out(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void term_load_keys(FILE *fil, void (*out)(char *)) {
|
||||
char line[136], buf[128];
|
||||
int key, l;
|
||||
|
||||
while (term_fgets(line, sizeof line, fil)) {
|
||||
key = 0;
|
||||
sscanf(line, "%d %n", &key, &l);
|
||||
if (key != 0) {
|
||||
term_define_key(line+l, key);
|
||||
if (out) {
|
||||
snprintf(buf, sizeof buf, " key %d defined as '%s'\n", key, line+l);
|
||||
out(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user