home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / KBFLIP.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  89 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  KBFLIP.C
  5. **
  6. **  a public domain demo by: Bob Stout
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <process.h>
  13.  
  14. #ifdef __TURBOC__
  15.  #define FAR far
  16. #else
  17.  #define FAR _far
  18. #endif
  19.  
  20. #define SHOW(str) fputs(str"\n", stderr)
  21.  
  22. #define BitSet(arg,posn) ((arg) | (1L << (posn)))
  23. #define BitClr(arg,posn) ((arg) & ~(1L << (posn)))
  24.  
  25. #define LOCKS_POSN 4
  26. #define BYTE unsigned char
  27.  
  28. BYTE FAR *kb_status = (BYTE FAR *) 0x00400017L;
  29.  
  30. /*
  31. **  Tell the folks how this works
  32. */
  33.  
  34. void usage(void)
  35. {
  36.       SHOW("Usage: KBFLIP {+|-}[switches] [...{+|-}[switches]]");
  37.       SHOW("Where \"switches\" are one or more of:");
  38.       SHOW(" +/-C - Turn Caps Lock on/off");
  39.       SHOW(" +/-N - Turn Num Lock on/off");
  40.       SHOW(" +/-S - Turn Scroll Lock on/off");
  41.       SHOW("Note switches may be upper or lower case\n");
  42.       SHOW("Example: \"KBFLIP +Cn -S\" turns Caps Lock and Num Lock on "
  43.             "and Scroll lock off");
  44.       exit(-1);
  45. }
  46.  
  47. /*
  48. **  The real works starts here
  49. **
  50. **  This works by checking the user input against a string containing the
  51. **  allowable switch characters in the same relative positions they
  52. **  occupy in the BIOS data area, offset by 4 (LOCKS_POSN).
  53. **
  54. **  Note that all changes are made to a copy of the BIOS data so any
  55. **  input errors will not cause incomplete changes to be applied.
  56. */
  57.  
  58. int main(int argc, char *argv[])
  59. {
  60.       int i, j;
  61.       char *args = "SNC";
  62.       BYTE template = *kb_status;              /* Make changes to copy */
  63.  
  64.       if (2 > argc)                             /* Help 'em             */
  65.             usage();
  66.       for (i = 1; i < argc; ++i)
  67.       {
  68.             if (NULL == strchr("+-", *argv[i]))
  69.                   usage();
  70.  
  71.             for (j = 1; argv[i][j]; ++j)
  72.             {
  73.                   char *found;
  74.  
  75.                   if (NULL != (found = strchr(args, toupper(argv[i][j]))))
  76.                   {
  77.                         int posn = LOCKS_POSN + (found - args);
  78.  
  79.                         if ('+' == *argv[i])
  80.                               template = (BYTE)BitSet(template, posn);
  81.                         else  template = (BYTE)BitClr(template, posn);
  82.                   }
  83.                   else  usage();
  84.             }
  85.       }
  86.       *kb_status = template;                    /* Apply all changes    */
  87.       return(0);
  88. }
  89.