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