setonkey.c

来自「详细介绍了一篇关于pci开发的接口芯片」· C语言 代码 · 共 64 行

C
64
字号
/*  CXL - Copyright (c) 1987-1989 by Mike Smedley - All Rights Reserved  */
/*  SETONKEY.C  - attaches/detaches a key to a function  */

#include <stdlib.h>
#include "cxldef.h"
#include "cxlkey.h"

int setonkey(unsigned keycode,void (*func) (void),unsigned pass)
{
    struct _onkey_t *onkey,*prev,*next;

    /* search for a keycode that is already defined */
    onkey=_kbinfo.onkey;
    while(onkey!=NULL) {
        if( onkey->keycode == keycode ) break;
        onkey=onkey->prev;
    }

    /* check to see if a key detachment is being requested */
    if(func==NULL) {

        /* if no defined onkey was found, then error */
        if(onkey==NULL) return(2);

        /* delete record from linked list */
        prev=onkey->prev;
        next=onkey->next;
        if(prev!=NULL) prev->next=next;
        if(next!=NULL) next->prev=prev;
        if(onkey==_kbinfo.onkey) _kbinfo.onkey=prev;

        /* free memory allocated for deleted record */
        free(onkey);
    }

    else {

        /* if key was found, change func pointer */
        /* otherwise create a new onkey record */
        if(onkey!=NULL)
            onkey->func=func;
        else {

            /* allocate memory for new record */
            onkey=malloc(sizeof(struct _onkey_t));
            if(onkey==NULL) return(1);

            /* add new record to linked list */
            if(_kbinfo.onkey!=NULL) _kbinfo.onkey->next=onkey;
            onkey->prev=_kbinfo.onkey;
            onkey->next=NULL;
            _kbinfo.onkey=onkey;

            /* save info in onkey record */
            _kbinfo.onkey->keycode=keycode;
            _kbinfo.onkey->func=func;
            _kbinfo.onkey->pass=pass;
        }
    }

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

⌨️ 快捷键说明

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