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

📄 gram.y

📁 最简单的窗口管理器
💻 Y
📖 第 1 页 / 共 2 页
字号:
 * return -1. */int keyexprlookup(string)char *string;{    int i;    for (i = 0; KeyExprTbl[i].name; i++) {        if (!strcmp(KeyExprTbl[i].name, string)) {            free(string);            return(KeyExprTbl[i].mask);        }    }    sprintf(msg,"key expression error: \"%s\"", string);    yyerror(msg);    free(string);    return(-1);}/* * Look up a string in the context expression table and return its mask, else * return -1. */contexprlookup(string)char *string;{    int i;    for (i = 0; ContExprTbl[i].name; i++) {        if (!strcmp(ContExprTbl[i].name, string)) {            free(string);            return(ContExprTbl[i].mask);        }    }    sprintf(msg,"context expression error: \"%s\"", string);    yyerror(msg);    free(string);    return(-1);}/* * Look up a string in the button expression table and return its mask, else * return -1. */buttexprlookup(string)char *string;{    int i;    for (i = 0; ButtModTbl[i].name; i++) {        if (!strcmp(ButtModTbl[i].name, string)) {            free(string);            return(ButtModTbl[i].mask);        }    }    sprintf(msg,"button modifier error: \"%s\"", string);    yyerror(msg);    free(string);    return(-1);}/* * Scan a string and return an integer.  Report an error if any * non-numeric characters are found. */y_atoi(s)char *s;{    int n = 0;    while (*s) {        if (*s >= '0' && *s <= '9')            n = 10 * n + *s - '0';        else {            yyerror("non-numeric argument");            return(-1);        }        s++;    }    return(n);}/* * Append s2 to s1, extending s1 as necessary. */char *strconcat(s1, s2)char *s1, *s2;{    char *p;    p = (char *)malloc(strlen(s1) + strlen(s2) + 2);    sprintf(p, "%s %s", s1, s2);    free(s1);    free(s2);    s1 = p;    return(s1);}/* * Check a button expression for errors. */intCheckButtonState(expr)int expr;{    /*     * Check for one (and only one) button.     */    switch (expr & (LeftMask | MiddleMask | RightMask)) {    case 0:        yyerror("no button specified");        break;    case LeftMask:        break;    case MiddleMask:        break;    case RightMask:        break;    default:        yyerror("more than one button specified");    }    /*     * Check for one (and only one) up/down/motion modifier.     */    switch (expr & (ButtonUp | ButtonDown | DeltaMotion)) {    case 0:        yyerror("no button action specified");        break;    case ButtonUp:        break;    case ButtonDown:        break;    case DeltaMotion:        break;    default:        yyerror("only one of up/down/motion may be specified");    }    return(expr);}/* * Bind button/key/context to a function. */bindtofunc(index, mask, context, name)int index;		/* Index into keyword table. */int mask;		/* Button/key/modifier mask. */int context;		/* ROOT, WINDOW, or ICON. */char *name;		/* Menu, if needed. */{    if (context & ROOT)        setbinding(ROOT, index, mask, name);    if (context & ICON)        setbinding(ICON, index, mask, name);    if (context & WINDOW)        setbinding(WINDOW, index, mask, name);}/* * Allocate a Binding type and return a pointer. */Binding *AllocBinding(){    Binding *ptr;    if (!(ptr = (Binding *)calloc(1, sizeof(Binding)))) {        fprintf(stderr, "Can't allocate binding--out of space\n");        exit(1);    }    return(ptr);}/* * Stash the data in a Binding. */setbinding(cont, i, m, mname)int cont;		/* Context: ROOT, WINDOW, or ICON. */int i;			/* Keyword table index. */int m;		/* Key/button/modifier mask. */char *mname;		/* Pointer to menu name, if needed. */{    Binding *ptr;    ptr = AllocBinding();    ptr->context = cont;    ptr->mask = m;    ptr->func = KeywordTable[i].fptr;    ptr->menuname = mname;    switch (m & (LeftMask | MiddleMask | RightMask)) {    case LeftMask:        ptr->button = LeftButton;        break;    case MiddleMask:        ptr->button = MiddleButton;        break;    case RightMask:        ptr->button = RightButton;        break;    }    appendbinding(ptr);}/* * Append a Binding to the Bindings list. */appendbinding(binding)Binding *binding;{    Binding *ptr;    if (Blist == NULL)        Blist = binding;    else {        for(ptr = Blist; ptr->next; ptr = ptr->next) /* NULL */;        ptr->next = binding;        ptr = ptr->next;        ptr->next = NULL;    }}/* * Allocate a menu line and return a pointer. */MenuLine *AllocMenuLine(){    MenuLine *ptr;    if (!(ptr = (MenuLine *)calloc(1, sizeof(MenuLine)))) {        fprintf(stderr, "Can't allocate menu line--out of space\n");        exit(1);    }    return(ptr);}/* * Allocate a MenuInfo structure and return a pointer. */MenuInfo *AllocMenuInfo(){    MenuInfo *ptr;    if (!(ptr = (MenuInfo *)calloc(1, sizeof(MenuInfo)))) {        fprintf(stderr, "Can't allocate menu storage--out of space\n");        exit(1);    }    return(ptr);}/* * Allocate a MenuLink structure and return a pointer. */MenuLink *AllocMenuLink(){    MenuLink *ptr;    if (!(ptr = (MenuLink *)calloc(1, sizeof(MenuLink)))) {        fprintf(stderr, "Can't allocate menu linked list storage--out of space\n");        exit(1);    }    return(ptr);}/* * Stash the data in a menu line. */MenuLine *StashMenuLine(type, string)int type;char *string;{    MenuLine *ptr;    ptr = AllocMenuLine();    ptr->type = type;    ptr->text = string;    return(ptr);}/* * Stash menu data in a MenuInfo structure; */MenuInfo *stashmenuinfo(name, line, colors)char *name;MenuLine *line;char *colors[];{    MenuInfo *ptr;    ptr = AllocMenuInfo();    ptr->name = name;    ptr->line = line;    ptr->foreground = colors[1];    ptr->background = colors[0];    ptr->fghighlight = colors[2];    ptr->bghighlight = colors[3];    return(ptr);}/* * Stash menu info data in a MenuLink structure; */MenuLink *stashmenulink(menuinfo)MenuInfo *menuinfo;{    MenuLink *ptr;    ptr = AllocMenuLink();    ptr->next = NULL;    ptr->menu = menuinfo;    return(ptr);}/* * Append a menu line to a linked list of menu lines. */MenuLine *appendmenuline(list, line)MenuLine *list;MenuLine *line;{    MenuLine *ptr;    if (list == NULL)        list = line;    else {        for(ptr = list; ptr->next; ptr = ptr->next) /* NULL */;        ptr->next = line;        ptr = ptr->next;        ptr->next = NULL;    }    return(list);}/* * Append a menu to a linked list of menus. */MenuLink *appendmenulink(list, link)MenuLink *list;MenuLink *link;{    MenuLink *ptr;    if (list == NULL)        list = link;    else {        for(ptr = list; ptr->next; ptr = ptr->next) /* NULL */;        ptr->next = link;        ptr = ptr->next;        ptr->next = NULL;    }    return(list);}/* * Reset all previous bindings and free the space allocated to them. */Bool ResetBindings(){    Binding *ptr, *nextptr;    for(ptr = Blist; ptr; ptr = nextptr) {        if(ptr->menuname) free(ptr->menuname);        nextptr = ptr->next;        free(ptr);    }    Blist = NULL;}/* * De-allocate all menus. */Bool ResetMenus(){    MenuLink *mptr, *next_mptr;    register MenuLine *lptr, *next_lptr;    for(mptr = Menus; mptr; mptr = next_mptr) {        free(mptr->menu->name);        for(lptr = mptr->menu->line; lptr; lptr = next_lptr) {            free(lptr->name);            if (lptr->text) free(lptr->text);            next_lptr = lptr->next;            free(lptr);        }        next_mptr = mptr->next;        free(mptr);    }    Menus = NULL;}/* * Set all numeric variables to zero and all boolean variables to FALSE. */Bool ResetVariables(){    register int i;    for (i = 0; KeywordTable[i].name; i++) {        switch (KeywordTable[i].type) {        case IsBoolTrue:        case IsBoolFalse:            *(KeywordTable[i].bptr) = FALSE;            break;        case IsNumeric:            *(KeywordTable[i].nptr) = 0;            break;        default:            break;        }    }    SetVarDefaults();}

⌨️ 快捷键说明

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