⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cflib.c

📁 CForms, by Lars Berntzon (Stockholm, Sweden), is a tool for building interactive forms-driven applic
💻 C
📖 第 1 页 / 共 3 页
字号:
    vsprintf(field_name, fmt, arg);    va_end(arg);        if (p = (char*)strchr(field_name, ':')) {    	*p++ = 0;    	pic = picture(field_name);    }    else {    	pic = _cf_globals.picture;    	p = field_name;    }        if (pic == NULL) return NULL;        for(i = 0; i < pic->n_fields; i++) {    	if(strequ(p, pic->field[i].name) == 0) return &pic->field[i];    }    return NULL;}/******************************************************************************* * *		S T R E Q U *		----------- * * Description: *	Case insensitive strcmp. * ******************************************************************************/intstrequ(const char *s1, const char *s2){    while(*s1 && toupper(*s1) == toupper(*s2))	s1++, s2++;    return toupper(*s1) - toupper(*s2);}/******************************************************************************* * *		F L D _ L E F T *		--------------- * * Description: *	Return pointer to a field left of 'fld'. * ******************************************************************************/struct field *fld_left(const struct field *fld){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;        if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) fld = fld_first();    if (fld == NULL) return NULL;        for(i = 0; i < _cf_globals.picture->n_fields; i++)    {    	if (fld != &_cf_globals.picture->field[i] &&    	    _cf_globals.picture->field[i].pos.x < fld->pos.x)    	{	    if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	    dist = (fld->pos.x - _cf_globals.picture->field[i].pos.x) << 9;	    dist += abs(fld->pos.y - _cf_globals.picture->field[i].pos.y);	    if (dist < min_dist)	    {	    	min_dist = dist;	    	found = &_cf_globals.picture->field[i];	    }	}    }    return found;}/******************************************************************************* * *		F L D _ R I G H T *		----------------- * * Description: *	Return pointer to a field right of 'fld'. * ******************************************************************************/struct field *fld_right(const struct field *fld){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;        if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) fld = fld_first();    if (fld == NULL) return NULL;        for(i = 0; i < _cf_globals.picture->n_fields; i++)    {    	if (fld != &_cf_globals.picture->field[i] &&    	    _cf_globals.picture->field[i].pos.x > fld->pos.x)    	{	    if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	    dist = (_cf_globals.picture->field[i].pos.x - fld->pos.x) << 9;	    dist += abs(fld->pos.y - _cf_globals.picture->field[i].pos.y);	    if (dist < min_dist)	    {	    	min_dist = dist;	    	found = &_cf_globals.picture->field[i];	    }	}    }    return found;}/******************************************************************************* * *		F L D _ D O W N *		--------------- * * Description: *	Return a pointer to field below 'fld'. * ******************************************************************************/struct field *fld_down(const struct field *fld){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;        if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) fld = fld_first();    if (fld == NULL) return NULL;        for(i = 0; i < _cf_globals.picture->n_fields; i++)    {    	if (fld != &_cf_globals.picture->field[i] &&    	    _cf_globals.picture->field[i].pos.y > fld->pos.y)    	{	    if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	    dist = (_cf_globals.picture->field[i].pos.y - fld->pos.y) << 9;	    dist += abs(_cf_globals.picture->field[i].pos.x - fld->pos.x);	    if (dist < min_dist)	    {	    	min_dist = dist;	    	found = &_cf_globals.picture->field[i];	    }	}    }    return found;}/******************************************************************************* * *		F L D _ U P  *		----------- * * Description: *	Return pointer to field above 'fld'. * ******************************************************************************/struct field *fld_up(const struct field *fld){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;        if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) fld = fld_first();    if (fld == NULL) return NULL;        for(i = 0; i < _cf_globals.picture->n_fields; i++)    {    	if (fld != &_cf_globals.picture->field[i] &&    	    _cf_globals.picture->field[i].pos.y < fld->pos.y)    	{	    if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	    dist = (fld->pos.y - _cf_globals.picture->field[i].pos.y) << 9;	    dist += abs(_cf_globals.picture->field[i].pos.x - fld->pos.x);	    if (dist < min_dist)	    {	    	min_dist = dist;	    	found = &_cf_globals.picture->field[i];	    }	}    }    return found;}/******************************************************************************* * *		F L D _ F I R S T *		----------------- * * Description: *	Find first field in picture. * ******************************************************************************/struct field *fld_first(void){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;        for(i = 0; i < _cf_globals.picture->n_fields; i++)    {	if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	dist = _cf_globals.picture->field[i].pos.y << 9;	dist += _cf_globals.picture->field[i].pos.x;	if (dist < min_dist)	{	    min_dist = dist;	    found = &_cf_globals.picture->field[i];	}    }    return found;}/******************************************************************************* * *		F L D _ L A S T *		--------------- * * Description: *	Find last field in picture. * ******************************************************************************/struct field *fld_last(void){    int i;    int max_dist = -1;    int dist;    struct field *found = NULL;    for(i = 0; i < _cf_globals.picture->n_fields; i++)    {	if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	dist = _cf_globals.picture->field[i].pos.y << 9;	dist += _cf_globals.picture->field[i].pos.x;	if (dist > max_dist)	{	    max_dist = dist;	    found = &_cf_globals.picture->field[i];	}    }    return found;}/******************************************************************************* * *		F L D _ N E X T *		--------------- * * Description: *	Find next field in picture. * ******************************************************************************/struct field *fld_next(const struct field *fld){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;    if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) fld = fld_first();    if (fld == NULL) return NULL;        for(i = 0; i < _cf_globals.picture->n_fields; i++)    {	if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	dist = (_cf_globals.picture->field[i].pos.y - fld->pos.y)<< 9;	dist += _cf_globals.picture->field[i].pos.x - fld->pos.x;		if (dist > 0 && dist < min_dist)	{	    min_dist = dist;	    found = &_cf_globals.picture->field[i];	}    }    return found;}/******************************************************************************* * *		F L D _ P R E V I O U S *		----------------------- * * Description: *	Find previoud field in picture. * ******************************************************************************/struct field *fld_previous(const struct field *fld){    int i;    int min_dist = 1000000;    int dist;    struct field *found = NULL;        if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) fld = fld_first();    if (fld == NULL) return NULL;    for(i = 0; i < _cf_globals.picture->n_fields; i++)    {	if (_cf_globals.picture->field[i].flags & FLD_FORBIDDEN) continue;	dist = (fld->pos.y - _cf_globals.picture->field[i].pos.y) << 9;	dist += fld->pos.x - _cf_globals.picture->field[i].pos.x;		if (dist > 0 && dist < min_dist)	{	    min_dist = dist;	    found = &_cf_globals.picture->field[i];	}    }    return found;}/******************************************************************************* * *		F L D _ I S E M P T Y *		--------------------- * * Description: *	Return true if field contains only space or nulls. * ******************************************************************************/intfld_isempty(const struct field *fld){    int i;        if (fld == NULL) fld = _cf_globals.field;    if (fld == NULL) return TRUE;        for(i = 0; i < fld->len; i++)    {    	if (fld->data[i] == 0) return TRUE;    	if (!isspace(fld->data[i])) return FALSE;    }    return TRUE;}/******************************************************************************* * *		D R A W _ P I C T U R E *		----------------------- * * Description: *	Draw all literals and fields in a picture. * ******************************************************************************/static intdraw_picture(struct picture *pic){    int n;    int r;    int c;    char space[400];    if (pic == NULL) return FAIL;        /*     * Calculate blank it first.     */    memset(space, ' ', pic->width);    space[pic->width] = 0;         for(r = pic->y; r < pic->y + pic->height; r++) {	move(r, pic->x);	addstr(space);    }	    debug("$cleared window size");    if (pic->flags & PIC_FRAME)    {	for(r = pic->y; r < pic->y + pic->height; r++) {	    move(r, pic->x);	    addch(ACS_VLINE);	    move(r, pic->x + pic->width - 1);	    addch(ACS_VLINE);	}	for(c = pic->x; c < pic->x + pic->width; c++) {	    move(pic->y, c);	    addch(ACS_HLINE);	    move(pic->y + pic->height - 1, c);	    addch(ACS_HLINE);	}	move(pic->y, pic->x); addch(ACS_ULCORNER);	move(pic->y, pic->x + pic->width - 1); addch(ACS_URCORNER);	move(pic->y + pic->height - 1, pic->x); addch(ACS_LLCORNER);	move(pic->y + pic->height - 1, pic->x + pic->width - 1); addch(ACS_LRCORNER);    }    debug("$drawn frame");    for(n = 0; n < pic->n_literals; n++)    {	move(pic->literal[n].pos.y + pic->y, pic->literal[n].pos.x + pic->x);	addstr(pic->literal[n].value);    }    debug("$drawn %d literals", n);        for(n = 0; n < pic->n_fields; n++)    {	draw_field(&pic->field[n]);    }    debug("$drawn %d fields", n);    message_nr(NULL);    return OK;}/****************************************************************************** * *                        S I G C A T C H *                        --------------- * Description: *        Catches a signal, cleans up and exits. * *****************************************************************************/#ifdef SIGNAL_INTstatic int#elsestatic void#endifsigcatch(int sig){    cforms_end();    exit(1);#ifdef SIGNAL_INT    return 0;	/* Just to shut up compiler */#endif}/****************************************************************** *		D R A W _ F I E L D *		------------------- * Decription: *	Write field to screen. * * Arguments: *	fld	- Pointer to field. * * Return: *	none * ******************************************************************/static voiddraw_field(struct field *fld){    if (fld == NULL || fld->picture == NULL) {	message("(internal error: field with unknown picture)");	return;    }    if (fld->lvalue)    {	move(fld->pos.y + fld->picture->y,	     fld->pos.x - strlen(fld->lvalue) + fld->picture->x);	addstr(fld->lvalue);    }    if (fld->rvalue) {	move(fld->pos.y + fld->picture->y,	     fld->pos.x + fld->len + fld->picture->x);	addstr(fld->rvalue);    }    if ((fld->flags & FLD_INVISIBLE) == 0)    {	if (fld->flags & FLD_HIGHLIGHT) {	    standout();	}	move(fld->pos.y + fld->picture->y, fld->pos.x + fld->picture->x);	addstr(fld->data);	if (fld->flags & FLD_HIGHLIGHT) {	    standend();	}    }}static voiddebug(char *fmt, ...){    static char init;	/* This is just a dummy address holder */    static char *env = &init;    static FILE *log;    va_list arg;    extern unsigned sleep(unsigned);    /*     * Get environment first time.     */    if (env == &init) {	env = getenv("CFDEBUG");	/*	 * Open file first time.	 */	if (env) {	    if ((log = fopen("CForms.log", "w")) != NULL) {		message("(started debug in CForms.log)");	    }	}    }    /*     * Print debug message if env set.     */    if (env && log)    {	/*	 * Write message.	 */	if (fmt[0] == '$') {	    sleep (1);	    refresh();	    fmt++;	}	va_start(arg, fmt);	vfprintf(log, fmt, arg);	fprintf(log, "\n");	fflush(log);	va_end(arg);    }}/****************************************************************** *		M O V E _ T O _ F I E L D *		------------------------- * Description: *	Internal function to do the actual move of the field. * * Arguments: *	fld	- Pointer to field to move to. * ******************************************************************/static voidmove_to_field(struct field *fld){    if (fld == NULL)    {	fld = _cf_globals.field;    }    /*     * Repeat moving from and to fields while their event routines     * calles the fld_move.     */    do    {	/*	 * First move from a field.	 */	_cf_globals.move_field = NULL;	if (_cf_globals.field) {	    raw_event(EVENT_EXIT, 0, 0);	    if (_cf_globals.move_field != NULL)	    {		fld = _cf_globals.move_field;	    }	}	/*	 * Then move to a field.	 */	_cf_globals.field = fld;	_cf_globals.move_field = NULL;	raw_event(EVENT_ENTRY, 0, 0);	fld = _cf_globals.move_field;    } while (_cf_globals.move_field != NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -