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

📄 setkeys.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    !strcmp(*argv, "no-arrow")  ||	    !strcmp(*argv, "no_arrow")  ||	    !strcmp(*argv, "noarrows")  ||	    !strcmp(*argv, "no-arrows") ||	    !strcmp(*argv, "no_arrows")   ) {	    noarrows = TRUE;	    continue;	}	if (!strcmp(*argv, "reset")) {	    reset = TRUE;	    continue;	}	if (!strcmp(*argv,"show") 	||	    !strcmp(*argv,"Show")	)  {		show = TRUE;		continue;	}	if (!strcmp(*argv, "-f")) {                remap = TRUE;                if (!--argc) {                        (void)fprintf(stderr, "Must specify filename after -f\n");                        return Fail;                }                fold(*++argv);                remap_filename = *argv;                continue;        } 	(void)fprintf(stderr, "Unknown parameter \"%s\"\n", *argv);	return Fail;    } /* end of while (--argc) */    switch (*type_p) {      case Klunker_kbd:	keybd_info = &klunker;	break;      case Sun1_kbd:	keybd_info = &sun1;	break;      case Sun2_kbd:	keybd_info = &sun2_info;	break;      case Sun3_kbd:      case Sun4_kbd:	keybd_info = &sun3_info;	break;    }    if (lefty) {	if (noarrows) {	    *info_p = keybd_info->lefty_noarrow;	} else {	    *info_p = keybd_info->lefty;	}    } else {	if (noarrows) {	    *info_p = keybd_info->standard_noarrow;	} else {	    *info_p = keybd_info->standard;	}    }    if (limbo) {	if (lefty || noarrows || reset || show) {	    (void)fprintf(stderr, "No other options compatible with no-sunview.\n");	    return Fail;	}	if (*type_p == Klunker_kbd || *type_p == Sun1_kbd) {	    (void)fprintf(stderr,	            "No-sunview is valid only on a Sun-2, Type 3 or Type 4 keyboard.\n");		    return Fail;	}	*info_p = &limbo_info;	return Limbo;    }    if (reset) {	if (lefty || limbo || noarrows || show) {	    (void)fprintf(stderr, "No other options compatible with reset.\n");	    return Fail;	}	return Reset;    }    if (show)  {	if (lefty || limbo || noarrows || reset)  {	    (void)fprintf(stderr, "No other options compatible with show.\n");	    return Fail;	}	return Show;    }    if (remap) {        if (lefty || limbo || noarrows || reset || show) {            (void)fprintf(stderr, "No other options compatible with -f.\n");            return Fail;        }        return Remap;    } else	return Standard;}static voidfold(cp)    register char	*cp;{    register char	 c;    while (c = *cp) {	if (isupper(c))	    *cp = tolower(c);	cp++;    }}extern struct keyboard	*keytables[];		/*  in keytables.c  */extern char		 keystringtab[16][KTAB_STRLEN];  static voidreset_keyboard(keyboard, keybd_type)    int                   keyboard;    Keybd_type            keybd_type;{    register struct keyboard	 *kb;    switch (keybd_type) {      case Klunker_kbd:	kb = keytables[0];	break;      case Sun1_kbd:	kb = keytables[1];	break;      case Sun2_kbd:	kb = keytables[2];	break;      case Sun3_kbd:	kb = keytables[3];	break;      case Sun4_kbd:        kb = keytables[4];        break;    }    set_all_keys(keyboard, kb->k_normal, 0);    set_all_keys(keyboard, kb->k_caps, CAPSMASK);    set_all_keys(keyboard, kb->k_shifted, SHIFTMASK);    set_all_keys(keyboard, kb->k_control, CTRLMASK);    set_all_keys(keyboard, kb->k_up, UPMASK);}static voidset_all_keys(kbd_fd, km, keystate)    register int		  kbd_fd, keystate;    register struct keymap	 *km;{    register int		  i, code;    register char                *str;    for (i = 0; i < 128; i++) {	code = km->keymap[i]; 	if (code >= STRING && code <= STRING + 15)	    str = keystringtab[code - STRING];	else	    str = nullstr;	(void)setkey_local(kbd_fd, keystate, i, code, str);    }}static voidremap_keys(keyboard)        int             keyboard;{        char table_string[16], line[80];        int     cnt, table, key, entry;        FILE *file;        if ((file = fopen(remap_filename, "r")) == NULL) {                fprintf(stderr, "Unable to open %s\n", remap_filename);                lose();        }        while (TRUE) {                fgets(line, 80, file);                if (line[0] == '#')                        continue;       /* ignore comment lines */                cnt = sscanf(line, "%s %d %x\n", table_string, &key, &entry);                if (cnt != 3) {                        fprintf(stderr,                                "setkeys: Improper format (field count = %d) in %s\n",                                                cnt, remap_filename);                        goto close_setkeys;                }                if (!strcmp(table_string, "END")) {close_setkeys:                          if (fclose(file))                                lose();                        return;                } else if (!strcmp(table_string, "BASE"))                        table = 0;                else if (!strcmp(table_string, "CTRL"))                        table = CTRLMASK;                else if (!strcmp(table_string, "SHIFT"))                        table = SHIFTMASK;                else if (!strcmp(table_string, "CAPS"))                        table = CAPSMASK;                else if (!strcmp(table_string, "UP"))                        table = UPMASK;                else if (!strcmp(table_string, "ALTG"))                        table = ALTGRAPHMASK;                else {                        fprintf(stderr,                                "setkeys: Unknown keytable identifier '%s' in %s\n",                                                  table_string, remap_filename);                        goto close_setkeys;                }                if (setkey_local(keyboard, table, key, entry, nullstr)                        == -1)                        lose();        }} static intsetkey_local(keyboard, table, position, code, string)    int             keyboard, table, position, code;    char           *string;{    struct kiockeymap  key;    if (debug_setkeys) {	(void)printf("Set station %d in %s table to 0x%x (%d).\n",	       position,	       ((table == 0)	 	 ? "base"	 :		(table == ALTGRAPHMASK) ? "alt-graph" :		(table == CAPSMASK)	 ? "caps-locked" :		(table == SHIFTMASK) 	 ? "shifted"	 :		(table == CTRLMASK)	 ? "controlled"	 :		(table == UPMASK)	 ? "key-up"	 :  "unknown"),	       code, code);	if (code >= STRING && code <= STRING + 15) {	    (void)printf("\t(string[%d]: \"%s\")\n",code - STRING, string);	} 	return 0;    } else {	key.kio_tablemask = table;	key.kio_station = position;	key.kio_entry = code;	(void)strcpy(key.kio_string, string);	return ((ioctl((keyboard), KIOCSKEY, &key)));    }}staticprint_func_key(keybd_type,lefty)Keybd_type  keybd_type;int  lefty;{    int   result,column;    char  buffer[1024];    int   strt_col,i;    result = tgetent(buffer,"sun");    if (result == -1)  {	(void)printf("Can't open termcap file\n");	exit(1);    }   else   if (result == 0)  {	(void)printf("No entry for sun\n");	exit(1);    }   else   if (result != 1)  {	(void)printf("Unspecified error\n");	exit(1);    }    column = tgetnum("co");    putchar('\n');    for (i = 0; i < column-1; i++)  {	putchar('=');    }    putchar ('\n');    switch (keybd_type)  {	case Sun1_kbd:	(void)printf("Keyboard type is Sun1\n"); 			if ((strt_col = column - RIGHTWIDTH_1 -1) < 0)  {			    too_narrow();			    exit(1);			}   else   {			    print_sun1(lefty,strt_col);			}			break;	case Sun2_kbd:	case Sun3_kbd:        case Sun4_kbd:	if (keybd_type == Sun2_kbd)  {			    (void)printf("Keyboard type is Sun-2\n");			}   else if (keybd_type == Sun3_kbd)  {                            (void)printf("Keyboard type is Type 3\n");                        }   else { 			    (void)printf("Keyboard type is Type 4\n");			}			if (lefty)  {			    if ((strt_col = column - RIGHTWIDTH_OTHR-1)<0)  {				too_narrow();				exit(1);			    } 			    (void)printf("Lefthand setting\n");			}   else   {			    if (column - LEFTWIDTH_SUN < 0)  {				too_narrow();				exit(1);			    }    else   {				strt_col = 0;			    }			    (void)printf("Righthand setting\n");			}			print_sun2(lefty,strt_col);			break;	case Klunker_kbd:	(void)printf("Keyboard type is Klunker\n");			if (lefty)  {			    if ((strt_col = column - RIGHTWIDTH_OTHR-1)<0)  {				too_narrow();				exit(1);			    } 			    (void)printf("Lefthand setting\n");			}   else   {			    if (column - LEFTWIDTH_KLUNK < 0)  {				too_narrow();				exit(1);			    }    else   {				strt_col = 0;			    }			    (void)printf("Righthand setting\n");			}			print_klunk(lefty,strt_col);			break;    }}staticprint_sun1(not_set,strt_col){    int  i,j;    char **left,**right;    int  length;    if (not_set)  {	(void)printf("Function keys have not been set up using 'setkeys'\n");	return;    }    left = rightStr;    right = leftStr;    (void)strcpy(leftStr[0],BLANKS);    length = RIGHTWIDTH_1;    put_blank(strt_col);    for (i = 0; i < length; i++)  {	putchar('-');    }    putchar('\n');    for (i = 0; i < 5; i++)  {	put_blank(strt_col);	putchar('|');	(void)printf("%s",left[i]);	if (i == 4)  {	    putchar(' ');	}   else   {	    putchar('|');	}	(void)printf("%s",BLANKS);	putchar('|');	(void)printf("%s",right[i]);	putchar('|');	(void)printf("%s",BLANKS);	putchar('|');	putchar('\n');	put_blank(strt_col);	if (i == 3)  {	    for (j = 0; j < length - 7; j++)  {		putchar('-');	    }	    (void)printf("%s",BLANKS);	    putchar('|');	}   else   {	    for (j = 0; j < length; j++)  {		putchar('-');	    }	}	putchar('\n');    }     }staticprint_sun2(lefty,strt_col)int  lefty;int  strt_col;{#define  NULLSTR  "\0"    int i, j;    char  **left,**right;    int   length;    if (lefty) {	left = rightStr;	right = leftStr;	length = RIGHTWIDTH_OTHR;    }   else   {	left = leftStr;	right = rightStr;	length = LEFTWIDTH_SUN;    }    put_blank(strt_col);    for (i = 0; i < length; i++)  {	putchar('-');    }    putchar('\n');    for (i = 0; i < 5; i++)  {	put_blank(strt_col);	putchar('|');	(void)printf("%s",left[i]);	putchar('|');	if (lefty)  {	    (void)printf("%s",BLANKS);	    putchar('|');	}	(void)printf("%s",right[i]);	if (!lefty)  {	    (void)printf("%s",BLANKS);	}	putchar('|');	putchar('\n'); 	put_blank(strt_col);  	for (j = 0; j < length; j++)  {	    putchar('-');        }	putchar('\n');    } }staticput_blank(strt_col)int  strt_col;{    int  i;    for (i = 0; i < strt_col; i++)  {	putchar(' ');    }}staticprint_klunk(lefty,strt_col)int  lefty;int  strt_col;{    int i, j;    char  **left,**right;    int   length;    if (lefty)  {	left = rightStr;	right = leftStr;	length = RIGHTWIDTH_OTHR;    }   else   {	left = leftStr;	right = rightStr;	length = LEFTWIDTH_KLUNK;    }    put_blank(strt_col);    for (i = 0; i < length; i++)  {	putchar('-');    }    putchar('\n');    for (i = 0; i < 5; i++)  {	put_blank(strt_col);	putchar('|');	(void)printf("%s",left[i]);	putchar('|');	(void)printf("%s",BLANKS);	putchar('|');	(void)printf("%s",right[i]);	putchar('|');	putchar('\n'); 	put_blank(strt_col);  	for (j = 0; j < length; j++)  {	    putchar('-');        }	putchar('\n');    } }staticis_non_standard(kb_des,type)int	kb_des;Keybd_type type;{    struct kiockeymap key;    /* If the keyboard is Sun1, then find out if the user has set the        function keys already.  Otherwise,       find out whether it's a lefty or righty's keyboard by testing which       key is at the L5 spot for the righty setting, if it's L5, then it's       a regular setting, anything else indicates lefty setting*/     key.kio_tablemask = 0;    if (type == Sun1_kbd)  {	key.kio_station = 55;    }   else   {	key.kio_station = 49;    }    if (ioctl(kb_des,KIOCGKEY,&key)  < 0)  {	(void)printf("IOCTL error, invalid argument\n");	exit(1);	/* NOTREACHED */    }   else   {	if (key.kio_entry == LF(5))  {	    return(STANDARD);	}   else   {	    return(NONSTANDARD);	}    }} statictoo_narrow(){    (void)printf("Increase the width of the window for proper display please\n");}

⌨️ 快捷键说明

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