home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / bsd / 2520 < prev    next >
Encoding:
Text File  |  1992-07-21  |  10.5 KB  |  443 lines

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!sdd.hp.com!think.com!cayman!brad
  2. From: brad@Cayman.COM (Brad Parker)
  3. Newsgroups: comp.unix.bsd
  4. Subject: new ioctl for keyboard flags
  5. Message-ID: <BRAD.92Jul21095535@haiti.Cayman.COM>
  6. Date: 21 Jul 92 13:55:35 GMT
  7. Sender: news@cayman.COM
  8. Organization: Cayman Systems Inc., Cambridge, MA
  9. Lines: 431
  10. Nntp-Posting-Host: haiti
  11.  
  12.  
  13. I was tired of the caps lock key not being a control key and the shift key
  14. makeing "control+'-'" not work, so I added to ioctl's and a wrote a little
  15. program to wack the "keyboard flags".  It also allows you to change the
  16. cursor from "fat" to "slim".  This was the simplest way I could find to
  17. affect the desired result.
  18.  
  19. I have heard to SCO and other 386 unixes have up to three (3!) levels of
  20. keyboard mapping which makes doing things like this easier.
  21. The kern/pccons.c code looks like it wants to go this direction, but is not
  22. quite there yet.
  23.  
  24. oh yes, this also fixes a bug where "control+'2'" would not produce the
  25. desired "0x0" code.  Since 0x0 is overloaded already in the map to mean
  26. "end of string", I overload 0xff to mean "send 0x0". hi ho.
  27.  
  28. -brad
  29.  
  30.  
  31. --- cut here ---
  32. #!/bin/sh
  33. # This is a shell archive (shar 3.47)
  34. # made 07/21/1992 13:42 UTC by brad@haiti
  35. # Source directory /tmp_mnt/home/caicos/brad/pccons
  36. #
  37. # existing files will NOT be overwritten unless -c is specified
  38. #
  39. # This shar contains:
  40. # length  mode       name
  41. # ------ ---------- ------------------------------------------
  42. #    105 -rw-r--r-- Makefile
  43. #   4472 -rw-r--r-- diffs
  44. #   1044 -r--r--r-- pccons.8
  45. #   1604 -rw-r--r-- pccons.c
  46. #
  47. # ============= Makefile ==============
  48. if test -f 'Makefile' -a X"$1" != X"-c"; then
  49.     echo 'x - skipping Makefile (File already exists)'
  50. else
  51. echo 'x - extracting Makefile (Text)'
  52. sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
  53. #
  54. X
  55. PROG=    pccons
  56. MAN8=    pccons.0
  57. BINDIR=    /usr/local/bin
  58. MANDIR=    /usr/local/man/man
  59. X
  60. .include <bsd.prog.mk>
  61. SHAR_EOF
  62. chmod 0644 Makefile ||
  63. echo 'restore of Makefile failed'
  64. Wc_c="`wc -c < 'Makefile'`"
  65. test 105 -eq "$Wc_c" ||
  66.     echo 'Makefile: original size 105, current size' "$Wc_c"
  67. fi
  68. # ============= diffs ==============
  69. if test -f 'diffs' -a X"$1" != X"-c"; then
  70.     echo 'x - skipping diffs (File already exists)'
  71. else
  72. echo 'x - extracting diffs (Text)'
  73. sed 's/^X//' << 'SHAR_EOF' > 'diffs' &&
  74. *** pccons.c.orig    Sun Jul 19 05:22:34 1992
  75. --- pccons.c    Sun Jul 19 07:27:25 1992
  76. ***************
  77. *** 99,108 ****
  78. X      pcprobe, pcattach, "pc",
  79. X  };
  80. X  
  81. - /* block cursor so wfj does not go blind on laptop hunting for
  82. -     the verdamnt cursor -wfj */
  83. - #define    FAT_CURSOR
  84. X  #define    COL        80
  85. X  #define    ROW        25
  86. X  #define    CHR        2
  87. --- 99,104 ----
  88. ***************
  89. *** 120,125 ****
  90. --- 116,126 ----
  91. X  static    char    *more_chars;
  92. X  static    int    char_count;
  93. X  
  94. + static    int    keybd_flags;
  95. + #define IGNORE_SHIFT        (!(keybd_flags & TIOCKEYBD_SHIFT))
  96. + #define IGNORE_CAPS_LOCK    (keybd_flags & TIOCKEYBD_CAPSLOCK)
  97. + #define FAT_CURSOR        (keybd_flags & TIOCKEYBD_CURSOR_BLOCK)
  98. X  /*
  99. X   * We check the console periodically to make sure
  100. X   * that it hasn't wedged.  Unfortunately, if an XOFF
  101. ***************
  102. *** 280,287 ****
  103. X  #endif
  104. X      if (!openf)
  105. X          return;
  106. !     while (*cp)
  107. !         (*linesw[pccons.t_line].l_rint)(*cp++ & 0xff, &pccons);
  108. X  }
  109. X  
  110. X  pcioctl(dev, cmd, data, flag)
  111. --- 281,290 ----
  112. X  #endif
  113. X      if (!openf)
  114. X          return;
  115. !     while (c = *cp++ & 0xff) {
  116. !         if (c == 0xff) c = 0;
  117. !         (*linesw[pccons.t_line].l_rint)(c, &pccons);
  118. !     }
  119. X  }
  120. X  
  121. X  pcioctl(dev, cmd, data, flag)
  122. ***************
  123. *** 297,302 ****
  124. --- 300,313 ----
  125. X      error = ttioctl(tp, cmd, data, flag);
  126. X      if (error >= 0)
  127. X          return (error);
  128. +     switch (cmd) {
  129. +     case TIOCKEYBDG:
  130. +       *(int *)data = keybd_flags;
  131. +       return 0;
  132. +     case TIOCKEYBDS:
  133. +       keybd_flags = *(int *)data;
  134. +       return 0;
  135. +     }
  136. X      return (ENOTTY);
  137. X  }
  138. X  
  139. ***************
  140. *** 470,481 ****
  141. X      outb(addr_6845+1, pos>> 8);
  142. X      outb(addr_6845, 15);
  143. X      outb(addr_6845+1, pos);
  144. ! #ifdef    FAT_CURSOR
  145. X      outb(addr_6845, 10);
  146. X      outb(addr_6845+1, 0);
  147. X      outb(addr_6845, 11);
  148. X      outb(addr_6845+1, 18);
  149. ! #endif    FAT_CURSOR
  150. X      if (a == 0)
  151. X          timeout(cursor, 0, hz/10);
  152. X  }
  153. --- 481,494 ----
  154. X      outb(addr_6845+1, pos>> 8);
  155. X      outb(addr_6845, 15);
  156. X      outb(addr_6845+1, pos);
  157. !     if (FAT_CURSOR) {
  158. X      outb(addr_6845, 10);
  159. X      outb(addr_6845+1, 0);
  160. X      outb(addr_6845, 11);
  161. X      outb(addr_6845+1, 18);
  162. !     }
  163. X      if (a == 0)
  164. X          timeout(cursor, 0, hz/10);
  165. X  }
  166. ***************
  167. *** 1095,1101 ****
  168. X      NONE,    "",        "",        "",        /* 0 unused */
  169. X      ASCII,    "\033",        "\033",        "\033",        /* 1 ESCape */
  170. X      ASCII,    "1",        "!",        "!",        /* 2 1 */
  171. !     ASCII,    "2",        "@",        "\000",        /* 3 2 */
  172. X      ASCII,    "3",        "#",        "#",        /* 4 3 */
  173. X      ASCII,    "4",        "$",        "$",        /* 5 4 */
  174. X      ASCII,    "5",        "%",        "%",        /* 6 5 */
  175. --- 1108,1114 ----
  176. X      NONE,    "",        "",        "",        /* 0 unused */
  177. X      ASCII,    "\033",        "\033",        "\033",        /* 1 ESCape */
  178. X      ASCII,    "1",        "!",        "!",        /* 2 1 */
  179. !     ASCII,    "2",        "@",        "\377",        /* 3 2 */
  180. X      ASCII,    "3",        "#",        "#",        /* 4 3 */
  181. X      ASCII,    "4",        "$",        "$",        /* 5 4 */
  182. X      ASCII,    "5",        "%",        "%",        /* 6 5 */
  183. ***************
  184. *** 1301,1306 ****
  185. --- 1314,1323 ----
  186. X              case CTL:
  187. X                  ctrl_down = 0;
  188. X                  break;
  189. +             case CAPS:
  190. +                 if (IGNORE_CAPS_LOCK)
  191. +                   ctrl_down = 0;
  192. +                 break;
  193. X          }
  194. X      }
  195. X      else
  196. ***************
  197. *** 1319,1326 ****
  198. X                  update_led();
  199. X                  break;
  200. X              case CAPS:
  201. !                 caps ^= 1;
  202. !                 update_led();
  203. X                  break;
  204. X              case SCROLL:
  205. X                  scroll ^= 1;
  206. --- 1336,1346 ----
  207. X                  update_led();
  208. X                  break;
  209. X              case CAPS:
  210. !                 if (!IGNORE_CAPS_LOCK) {
  211. !                   caps ^= 1;
  212. !                   update_led();
  213. !                 } else
  214. !                   ctrl_down = 1;
  215. X                  break;
  216. X              case SCROLL:
  217. X                  scroll ^= 1;
  218. ***************
  219. *** 1342,1349 ****
  220. X              case ASCII:
  221. X              case NONE:
  222. X              case FUNC:
  223. !                 if (shift_down)
  224. !                     more_chars = scan_codes[dt].shift;
  225. X                  else if (ctrl_down)
  226. X                      more_chars = scan_codes[dt].ctrl;
  227. X                  else
  228. --- 1362,1369 ----
  229. X              case ASCII:
  230. X              case NONE:
  231. X              case FUNC:
  232. !                 if (shift_down && (IGNORE_SHIFT || !ctrl_down))
  233. !                         more_chars = scan_codes[dt].shift;
  234. X                  else if (ctrl_down)
  235. X                      more_chars = scan_codes[dt].ctrl;
  236. X                  else
  237. *** ioctl.h.orig    Sun Jul 19 05:25:29 1992
  238. --- ioctl.h    Sun Jul 19 05:55:05 1992
  239. ***************
  240. *** 146,151 ****
  241. --- 146,157 ----
  242. X  #define    TIOCSIG        _IO('t', 95)        /* pty: generate signal */
  243. X  #define TIOCDRAIN    _IO('t', 94)        /* wait till output drained */
  244. X  
  245. + #define    TIOCKEYBDG    _IOR('t', 90, int)    /* get keyboard flags */
  246. + #define    TIOCKEYBDS    _IOW('t', 90, int)    /* set keyboard flags */
  247. + #define        TIOCKEYBD_SHIFT        0x01    /* shift looses to cntrl */
  248. + #define        TIOCKEYBD_CAPSLOCK    0x02    /* caps lock becomes shift */
  249. + #define        TIOCKEYBD_CURSOR_BLOCK    0x10    /* cursor is block */
  250. X  #define TTYDISC        0        /* termios tty line discipline */
  251. X  #define    TABLDISC    3        /* tablet discipline */
  252. X  #define    SLIPDISC    4        /* serial IP discipline */
  253. SHAR_EOF
  254. chmod 0644 diffs ||
  255. echo 'restore of diffs failed'
  256. Wc_c="`wc -c < 'diffs'`"
  257. test 4472 -eq "$Wc_c" ||
  258.     echo 'diffs: original size 4472, current size' "$Wc_c"
  259. fi
  260. # ============= pccons.8 ==============
  261. if test -f 'pccons.8' -a X"$1" != X"-c"; then
  262.     echo 'x - skipping pccons.8 (File already exists)'
  263. else
  264. echo 'x - extracting pccons.8 (Text)'
  265. sed 's/^X//' << 'SHAR_EOF' > 'pccons.8' &&
  266. .\"
  267. .\"    @(#)pccons.8
  268. .\"
  269. .Dd July 19, 1992
  270. .Dt PCCONS 8
  271. .Os
  272. .Sh NAME
  273. .Nm pccons
  274. .Nd set PC console attributes
  275. .Sh SYNOPSIS
  276. .Nm pccons
  277. .Op Ar options ...
  278. .Sh DESCRIPTION
  279. .Pp
  280. .Nm pccons
  281. allows the user to set, reset and view various PC console attributes
  282. by name.
  283. .Ar options
  284. are words describing each attribute.  If an option is "negated" with
  285. a "-",  the option is turned off.
  286. .Pp
  287. The following options are available:
  288. .Bl -tag -width flag
  289. .It shift
  290. Ignore the shift key if the control key is pressed.  Helpful for
  291. hitting keys like "control+shift+underscore".
  292. .It caps-lock
  293. Turn the "CapsLock" key into a substitute for the "control" key.
  294. .It block-cursor
  295. Make the cursor into a large block.  Helpful for LCD screens with poor
  296. contrast.
  297. .El
  298. .Sh ERRORS
  299. .Pp
  300. If /dev/console does not support the proper ioctl() calls, 
  301. .Er ENOTTY
  302. will be returned and 
  303. .Nm pccons
  304. will return 1.
  305. .Sh DIAGNOSTICS
  306. .Pp
  307. The
  308. .Nm pccons
  309. utility exits 0 on success, and >0 if an error occurs.
  310. .Sh SEE ALSO
  311. .Xr console 4
  312. .Sh BUGS
  313. does not handle partial matches of keywords
  314. SHAR_EOF
  315. chmod 0444 pccons.8 ||
  316. echo 'restore of pccons.8 failed'
  317. Wc_c="`wc -c < 'pccons.8'`"
  318. test 1044 -eq "$Wc_c" ||
  319.     echo 'pccons.8: original size 1044, current size' "$Wc_c"
  320. fi
  321. # ============= pccons.c ==============
  322. if test -f 'pccons.c' -a X"$1" != X"-c"; then
  323.     echo 'x - skipping pccons.c (File already exists)'
  324. else
  325. echo 'x - extracting pccons.c (Text)'
  326. sed 's/^X//' << 'SHAR_EOF' > 'pccons.c' &&
  327. /*
  328. X  pccons.c - get/set/clear pc console and keyboard attributes
  329. X
  330. X  Brad Parker <brad@cayman.com>
  331. */
  332. X
  333. #include <stdio.h>
  334. #include <fcntl.h>
  335. #include <sys/ioctl.h>
  336. X
  337. struct {
  338. X    char    *word;
  339. X    int    bits;
  340. } flag_words[] = {
  341. X    "shift",    TIOCKEYBD_SHIFT,
  342. X    "caps-lock",    TIOCKEYBD_CAPSLOCK,
  343. X    "block-cursor",    TIOCKEYBD_CURSOR_BLOCK,
  344. X    "", 0
  345. X    };
  346. X
  347. main(argc, argv)
  348. int argc;
  349. char *argv[];
  350. {
  351. X    int fd, result, i, j;
  352. X    int flags;
  353. X
  354. X    if ((fd = open("/dev/console", O_RDWR)) < 0) {
  355. X        perror("/dev/console");
  356. X        exit(1);
  357. X    }
  358. X
  359. X    result = ioctl(fd, TIOCKEYBDG, &flags);
  360. X    if (result != 0) {
  361. X        perror("TIOCKEYBDG");
  362. X        exit(1);
  363. X    }
  364. X
  365. X    if (argc == 1)
  366. X        show(flags);
  367. X    else {
  368. X        for (i = 1; i < argc; i++) {
  369. X            int set = 1;
  370. X
  371. X            if (argv[i][0] == '-') {
  372. X                set = 0;
  373. X                argv[i]++;
  374. X            }
  375. X
  376. X            for (j = 0; flag_words[j].word[0]; j++) {
  377. X                if (strcmp(argv[i], flag_words[j].word) == 0) {
  378. X                    if (set)
  379. X                        flags |= flag_words[j].bits;
  380. X                    else
  381. X                        flags &= ~flag_words[j].bits;
  382. X                    break;
  383. X                }
  384. X            }
  385. X
  386. X            if (flag_words[j].word[0] == 0)
  387. X                help();
  388. X        }
  389. X
  390. X        result = ioctl(fd, TIOCKEYBDS, &flags);
  391. X        if (result != 0) {
  392. X            perror("TIOCKEYBDS");
  393. X            exit(1);
  394. X        }
  395. X    }
  396. X
  397. X    return 0;
  398. }
  399. X
  400. help()
  401. {
  402. X    int j;
  403. X
  404. X    printf("set/clear/view pc console flags\n");
  405. X    printf("usage: pccons [ <flags> ]\n");
  406. X    printf("valid flags: ");
  407. X    for (j = 0; flag_words[j].word[0]; j++)
  408. X        printf("%s ", flag_words[j].word);
  409. X    printf("\n");
  410. }
  411. X
  412. show(flags)
  413. int flags;
  414. {
  415. X    int j;
  416. X
  417. X    printf("pc console flags: ");
  418. X    if (flags == 0)
  419. X        printf("<none>");
  420. X    else
  421. X        for (j = 0; flag_words[j].word[0]; j++)
  422. X            if (flags & flag_words[j].bits)
  423. X                printf("%s ", flag_words[j].word);
  424. X    printf("\n");
  425. }
  426. SHAR_EOF
  427. chmod 0644 pccons.c ||
  428. echo 'restore of pccons.c failed'
  429. Wc_c="`wc -c < 'pccons.c'`"
  430. test 1604 -eq "$Wc_c" ||
  431.     echo 'pccons.c: original size 1604, current size' "$Wc_c"
  432. fi
  433. exit 0
  434. --
  435. A metaphor is like a simile.
  436.  
  437. Brad Parker    Cayman Systems, Inc., Cambridge, Ma.    brad@cayman.com
  438.