?? zscreen.c
字號:
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <curses.h>
#include "zlib.h"
#define ZMX_FIELDL 80 /* Max. field size */
#define ISDIGIT(c) (c>='0'&&c<='9')
#define ISXDIGIT(c) (ISDIGIT(c)||c>='A'&&c<='F'||c>='a'&&c<='f')
#define ISALPHA(c) (c>='A'&&c<='Z'||c>='a'&&c<='z')
typedef struct{
void *p;
char b[ZMX_FIELDL + 1];
union{
char c[ZMX_FIELDL + 1];
double d;
float f;
long l;
int i;
} t;
} ZEDIT;
static ZEDIT *B=0;
static int FirstPos( ZFIELD *F, int S )
{
int i;
if( F->t == 'D' || F->t == 'F' || F->t == 'L' || F->t == 'I' ){
if( ( F->t == 'D' || F->t == 'F' ) && F->d != 0 ){
if( S == F->w )
return( S );
if( S < F->w - F->d )
S = F->w - F->d - 2;
}
else{
if( S == F->w )
return( -1 );
S = F->w - 1;
}
for( ; S >= 0; S -- )
if( !ZFfixpic( F->p, S ) )
break;
return( S );
}
else{
if( S == F->w )
return( S );
for( i = S; i < F->w; i ++ )
if( !ZFfixpic( F->p, i ) )
return( i );
return( -1 );
}
}
static int LastPos( ZFIELD *F, int E )
{
int i, r;
r = -1;
for( i = FirstPos( F, 0 ); i < E; i ++ )
if( !ZFfixpic( F->p, i ) ){
r = i;
if( Zideocode( B->b[i] ) )
i ++;
}
return( r );
}
static int FieldPos( ZFIELD *F, int N )
{
int r;
ZWattr( ZA_TEXT );
if( F[N].b && ( *F[N].b )( N, F + N ) != 0 )
return( -1 );
if( ( r = FirstPos( F + N, 0 ) ) < 0 )
return( -1 );
return( r );
}
static void SetAttr( ZFIELD *F, int T )
{
void *p;
if( F->t != 'C' && F->t != 'S' && F->t != 'P' ){
p = F->v;
F->v = ( void * ) &B->t;
ZFtodata( F, B->b );
}
ZFattr( F, T );
if( F->t != 'C' && F->t != 'S' && F->t != 'P' )
F->v = p;
}
static void DispField( ZFIELD *F, int T )
{
SetAttr( F, T );
ZFdispbuf( F, B->b );
}
static void DispCursor( ZFIELD *F, int T, int p )
{
curs_set( 2 - T );
ZWlocate( F->r, F->c + p );
}
static void ToNegative( ZFIELD *F )
{
void *p;
p = F->v;
F->v = ( void * ) &B->t;
ZFtodata( F, B->b );
switch( F->t ){
case 'D':
if( B->t.d > 0 )
B->t.d = -B->t.d;
break;
case 'F':
if( B->t.f > 0 )
B->t.f = -B->t.f;
break;
case 'L':
if( B->t.l > 0 )
B->t.l = -B->t.l;
break;
case 'I':
if( B->t.i > 0 )
B->t.i = -B->t.i;
break;
}
ZFtotext( F, B->b );
F->v = p;
}
static void ToPositive( ZFIELD *F )
{
void *p;
p = F->v;
F->v = ( void * ) &B->t;
ZFtodata( F, B->b );
switch( F->t ){
case 'D':
if( B->t.d < 0 )
B->t.d = -B->t.d;
break;
case 'F':
if( B->t.f < 0 )
B->t.f = -B->t.f;
break;
case 'L':
if( B->t.l < 0 )
B->t.l = -B->t.l;
break;
case 'I':
if( B->t.i < 0 )
B->t.i = -B->t.i;
break;
}
ZFtotext( F, B->b );
F->v = p;
}
static void SpaceEnd( int S, int E )
{
int i;
for( i = S; i < E; i ++ )
if( Zideocode( B->b[i] ) )
if( i < E - 1 )
i ++;
else
B->b[i] = ' ';
}
int Zscreen( ZSCREEN *S )
{
int or, oc, oa;
int ins, dsp, csr;
int key, fld, pos;
int n, l;
void *p;
ZEDIT *t = B;
if( S->bc <= 0 )
return( 0 );
key = 0;
if( ( B = ( ZEDIT * ) malloc( sizeof( ZEDIT ) ) ) != NULL ){
B->p = t;
ZWcursor( &or, &oc );
oa = ZWattr( -1 );
ZBdisplay( S->bs, S->bc );
for( fld = 0; fld < S->fc; fld ++ )
if( ( pos = FieldPos( S->fs, fld ) ) >= 0 )
break;
if( fld < S->fc ){
ZFdisplay( S->fs, S->fc, ZF_NORMAL );
curs_set( 2 );
}
else{
fld = -1;
if( S->fc > 0 )
ZFdisplay( S->fs, S->fc, ZF_DISPLAY );
}
ins = dsp = csr = 1;
while( key == 0 ){
if( fld >= 0 )
ZFtotext( S->fs + fld, B->b );
while( key == 0 ){
if( fld >= 0 ){
if( dsp != 0 ){
DispField( S->fs + fld, ZF_EDIT );
dsp = 0;
}
if( csr != 0 ){
csr = 0;
DispCursor( S->fs + fld, ins, pos );
}
}
key = Zinkey();
if( key != 0 ){
if( ( n = ZBkey( S->bs, S->bc, key ) ) >= 0 )
if( ( S->bs + n )->v != 0 && ( *( S->bs + n )->v )( key, n ) != 0 )
key = 0;
else
ZBhit( S->bs + n );
}
if( key == 0 && S->nk != 0 )
key = ( *S->nk )( fld, pos );
if( fld >= 0 && key != 0 ){
csr = 1;
if( key >= ' ' && key != 0x7F && key < 256 ){
if( pos == S->fs[fld].w )
key = 0;
if( key != 0 && S->fs[fld].p != 0
&& pos < Zstrlen( S->fs[fld].p ) ){
n = S->fs[fld].p[pos];
switch( n ){
case '0':
if( !ISDIGIT( key ) && key != '.' )
key = 0;
break;
case '9':
if( !ISDIGIT( key ) && key != '-' && key != '+' && key != '.' )
key = 0;
break;
case 'A':
case 'a':
if( !ISALPHA( key ) )
key = 0;
break;
case 'N':
case 'n':
if( key != ' ' && !ISDIGIT( key ) && !ISALPHA( key ) )
key = 0;
break;
case 'H':
case 'h':
if( !ISXDIGIT( key ) )
key = 0;
break;
}
if( n == 'A' || n == 'N' || n == 'H' || n == 'X' )
key = toupper( key );
}
if( key != 0 && ( S->fs[fld].t == 'D' || S->fs[fld].t == 'F'
|| S->fs[fld].t == 'L' || S->fs[fld].t == 'I' ) ){
if( ( S->fs[fld].t == 'D' || S->fs[fld].t == 'F' )
&& S->fs[fld].d != 0 ){
if( !ISDIGIT( key ) && key != '-' && key != '+' && key != '.' )
key = 0;
if( key == '.' && pos >= S->fs[fld].w - S->fs[fld].d )
key = 0;
}
else{
if( !ISDIGIT( key ) && key != '-' && key != '+' )
key = 0;
}
}
if( key != 0 ){
if( S->fs[fld].t == 'D' || S->fs[fld].t == 'F'
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -