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

📄 winp.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* search for first space to right of decimal */
    for(p=right;*p!=' '&&p<last;p++);

    if(p<last) {

        /* while q <= last position in field */
        q=p;
        while(q<=last) {
            for(;*q==' '&&q<=last;q++);
            while(q<=last&&*q!=' ') {
                *p++=*q;
                *q++=' ';
            }
        }
    }

    /* change trailing blanks to zeros */
    for(p=last;*p==' '&&p>=right;p--) *p='0';
}

/*---------------------------------------------------------------------------*/

/* this function deletes a character and shifts following text left */

static void del_char(struct _form_t *cform)
{
    /* shift characters in buffer left 1 position */
    strshl(cform->pbuf,1);

    /* re-display field */
    disp_field(cform,cform->pbuf,1);
}

/*---------------------------------------------------------------------------*/

/* this function is used to delete characters to the end of the field */

static void del_field(struct _form_t *cform,char *start,int high)
{
    /* blank out field from start position */
    strset(start,' ');

    /* re-display field */
    disp_field(cform,start,high);
}

/*---------------------------------------------------------------------------*/

/* this functions deletes the word to the left */

static void del_left_word(struct _form_t *cform)
{
    char *buf;
    int back=0;

    /* abbreviate pointer to start of field's buffer */
    buf=cform->cfield->buf;

    /* see if at 1st position in field.  */
    /* if so, just do a normal backspace */
    if(cform->pbuf==buf) {
        back_space(cform);
        return;
    }

    /* start 1 position back */
    prev_pos(cform);
    back++;

    /* skip over any spaces */
    while(cform->pbuf>buf&&*cform->pbuf==' ') {
        prev_pos(cform);
        back++;
    }

    /* find beginning of word under cursor */
    while(cform->pbuf>buf&&*cform->pbuf!=' ') {
        *cform->pbuf=' ';
        prev_pos(cform);
        back++;
    }
    if(cform->pbuf==buf) {
        *cform->pbuf=' ';
    }
    else {
        next_pos(cform);
        back--;
    }

    /* skip over any spaces */
    while(cform->pbuf>buf&&*cform->pbuf==' ') {
        prev_pos(cform);
        back++;
    }
    if(*cform->pbuf!=' ') {
        next_pos(cform);
        back--;
    }

    /* if Insert mode is on, shift text after cursor to the left */
    if(cform->insert&&cform->pbuf>=buf) strshl(cform->pbuf,back);

    /* re-display field */
    disp_field(cform,cform->pbuf,1);
}

/*---------------------------------------------------------------------------*/

/* this function deletes from current position through rest of the fields */

static void del_rest(struct _form_t *cform)
{
    register struct _field_t *temp;

    /* save pointer to current field */
    temp=cform->cfield;

    /* delete to end of current field */
    del_field(cform,cform->pbuf,1);

    /* while not last field, find next field, and erase it */
    while(cform->cfield!=last_rec(cform)) {
        cform->cfield=next_rec(cform);
        del_field(cform,cform->cfield->buf,0);
    }

    /* restore pointer to current field */
    cform->cfield=temp;
}

/*---------------------------------------------------------------------------*/

/* this function deletes the word to the right of the cursor */

static void del_word(struct _form_t *cform)
{
    register char *p,*q;

    /* find end of word under cursor */
    p=q=cform->pbuf;
    while(*q && *q!=' ') q++;

    /* find end of spaces */
    while(*q==' ') q++;

    /* move characters from right to left */
    while(*q) *p++=*q++;

    /* delete trailing characters */
    if(*p) del_field(cform,p,1);

    /* display the field */
    disp_field(cform,cform->pbuf,1);
}

/*---------------------------------------------------------------------------*/

/* this function displays a character and advances to next position */

static void disp_char(struct _form_t *cform,int ch,int advance)
{
    struct _field_t *temp;

    temp=cform->cfield;
    if(cform->insert) insert_char(cform);
    wprintc(cform->cwrow,cform->cwcol,cform->textattr,
            (*cform->pformat=='P'||cform->cfield->fconv=='P')?' ':ch);
    *cform->pbuf=ch;
    if(advance) {
        cform->pbuf++;
        if( cform->pbuf >= (cform->cfield->buf+cform->cfield->lenbuf) ) {
            if(!goto_field(cform,FLD_NR)) beg_pos(cform);
        }
        else {
            cform->cwcol++;
            cform->pformat++;
            next_fchar(cform);
        }
        if(temp!=cform->cfield&&cform->cfield->mode==2&&!strblank(cform->pbuf))
            end_line(cform);
    }
}

/*---------------------------------------------------------------------------*/

/* this function displays the field of the specified window record */

static void disp_field(struct _form_t *cform,char *start,int high)
{
    register struct _field_t *cfield;
    register int ccol;
    int crow,attr,disp;
    char *pf,*pb,ch;

    /* initialize position */
    cfield = cform->cfield;
    crow   = cfield->wrow;
    ccol   = cfield->wcol;
    pb     = cfield->buf;
    pf     = cfield->format;

    /* set starting point */
    if(start==NULL) start=cfield->buf;

    while(*pf) {

        /* select character attribute depending on input hilite flag */
        attr=high?cform->textattr:cform->fieldattr;

        /* see if we are at starting point yet */
        disp=(pb>=start)?YES:NO;

        /* test current format character */
        switch(*pf) {

            case '\"':
            case '\'':

                /* display all text inside quotes */
                ch=*pf++;
                while(*pf!=ch) {
                    if(disp) wprintc(crow,ccol,attr,*pf);
                    ccol++;
                    pf++;
                }
                break;
            
            case ' ':

                /* skip readability spaces */
                break;

            case '<':

                /* find right angle bracket, and    */
                /* display current buffer character */
                while(*pf!='>') pf++;
                if(disp) wprintc(crow,ccol,attr,*pb);
                ccol++;
                pb++;
                break;

            case '[':

                /* find right square bracket, and   */
                /* display current buffer character */
                while(*pf!=']') pf++;
                if(disp) wprintc(crow,ccol,attr,*pb);
                ccol++;
                pb++;
                break;

            case '.':

                /* display decimal point */
                if(disp) wprintc(crow,ccol,attr,*pf);
                ccol++;
                break;

            default:

                /* if current format character is a password character, */
                /* or field is a password field, then display a blank.  */
                /* otherwise, display the current buffer character.     */
                if(disp)
                    wprintc(crow,ccol,attr,(*pf=='P'||cfield->fconv=='P')
                      ?' ':*pb);
                ccol++;
                pb++;
        }
        pf++;
    }
}

/*---------------------------------------------------------------------------*/

/* this function sets the cursor at next field down from current field */

static void down_field(struct _form_t *cform)
{
    struct _field_t *best,*temp;
    int tcol,brow,bcol,tdist,bdist,trow,crow,ccol;

    /* initialize best record to NULL */
    best = NULL;
    brow = bcol = 32767;

    /* find the closest field downwards */
    crow=(int)cform->cwrow;
    ccol=(int)cform->cwcol;
    for(temp=cform->field;temp!=NULL;temp=temp->prev) {
        trow=(int)temp->wrow;
        tcol=closest_column(cform,temp);
        if(trow>crow) {
            tdist=abs(ccol-tcol);
            bdist=abs(ccol-bcol);
            if((trow<brow)||((trow==brow&&tdist<bdist))) {
                best  = temp;
                brow  = trow;
                bcol  = tcol;
            }
        }
    }

    /* if a field was found, then set current field to found */
    /* field, and advance to the matching column position    */
    if(best!=NULL) {
        cform->cfield=best;
        adv_column(cform,bcol);
    }
}

/*---------------------------------------------------------------------------*/

/* this function sets current position to end of line in field */

static void end_line(struct _form_t *cform)
{
    char *temp;

    /* save current position */
    temp=cform->pbuf;

    /* initialize to last position in field */
    end_pos(cform);

    /* if field is empty, stay on last position of field */
    if(strblank(cform->cfield->buf) || *cform->pbuf!=' ') return;

    /* search backwards for non-space or beginning of field */
    while(*cform->pbuf==' ') {
        if(cform->pbuf<=cform->cfield->buf) {
            end_pos(cform);
            return;
        }
        prev_pos(cform);
    }
    next_pos(cform);

    /* if position didn't change go to end of field */
    if(temp==cform->pbuf) end_pos(cform);
}

/*---------------------------------------------------------------------------*/

/* this function sets current position to the end of the field */

static void end_pos(struct _form_t *cform)
{
    struct _field_t *cfield;

    cfield         = cform->cfield;
    cform->cwrow   = cfield->wrow;
    cform->cwcol   = cfield->wcol   + cfield->lenfld - 1;
    cform->pbuf    = cfield->buf    + cfield->lenbuf - 1;
    cform->pformat = cfield->format + cfield->lenfmt - 1;
    prev_fchar(cform);
}

/*---------------------------------------------------------------------------*/

/* this function finds the first defined field */

static struct _field_t *first_rec(struct _form_t *cform)
{
    struct _field_t *temp;

    for(temp=cform->field;temp->prev!=NULL;temp=temp->prev) ;
    return(temp);
}

/*---------------------------------------------------------------------------*/

/* this function frees memory held by all of the input definitions */

static void free_fields(struct _form_t *cform)
{
    struct _form_t  *form;
    struct _field_t *field;

    /* do while more fields */
    while(cform->field!=NULL) {

        /* free temp string buffer */
        free(cform->field->buf);

        /* free input field record and update linked list */
        field=cform->field->prev;
        free(cform->field);
        cform->field=field;
        if(cform->field!=NULL) cform->field->next=NULL;
    }

    /* free input form record and update linked list */
    form=cform->prev;
    free(cform);
    _winfo.active->form=form;
    if(_winfo.active->form!=NULL) _winfo.active->form->next=NULL;
}

/*---------------------------------------------------------------------------*/

/* this function will validate the current field, then move the cursor */
/* to a new field, calling the after and before functions if defined.  */

static int goto_field(struct _form_t *cform,int which)
{
    int err;

    /* validate current field */
    if((err=validate_field(cform))!=0) return(err);

    /* display field, call 'after' function, and turn off Insert mode */
    after_edit(cform);

    /* call function which does the move to the new field */
    if(which==FLD_UP)       up_field(cform);
    else if(which==FLD_DN)  down_field(cform);
    else                    cform->cfield=(*funcs[which])(cform);

    /* set help category */
    _winfo.help=cform->cfield->help;

    /* display field in current field attribute */
    disp_field(cform,NULL,1);

    /* if a 'before' function was defined, call it */
    call_func(cform->cfield->before);

    /* return normally */
    return(0);
}

/*---------------------------------------------------------------------------*/

/* this function inserts a character, shifting text right one position */

static void insert_char(struct _form_t *cform)
{
    /* shift characters right 1 place starting with current position */
    strshr(cform->pbuf,1);

    /* re-display the field */
    disp_field(cform,cform->pbuf,1);
}

⌨️ 快捷键说明

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