home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xkey1.exe / UNGETCH.C next >
Text File  |  1995-02-09  |  7KB  |  235 lines

  1. /****************************************************************************
  2. **    File:    UNGETCH.c
  3. **
  4. **    Desc:    Tests ability to ungetch() an extended key character.
  5. **
  6. **    Disclaimer:
  7. **
  8. **        Novell, Inc. makes no representations or warranties with respect to
  9. **        any NetWare software, and specifically disclaims any express or
  10. **        implied warranties of merchantability, title, or fitness for a
  11. **        particular purpose.  
  12. **
  13. **        Distribution of any NetWare software is forbidden without the
  14. **        express written consent of Novell, Inc.  Further, Novell reserves
  15. **        the right to discontinue distribution of any NetWare software.
  16. **
  17. **        Novell is not responsible for lost profits or revenue, loss of use
  18. **        of the software, loss of data, costs of re-creating lost data, the
  19. **        cost of any substitute equipment or program, or claims by any party
  20. **        other than you.  Novell strongly recommends a backup be made before
  21. **        any software is installed.   Developer support for this software
  22. **        may be provided at the discretion of Novell.
  23. **
  24. **    QMK386 options used:
  25. **
  26. **        None
  27. **
  28. **    Notes:
  29. **
  30. **        As compiled, this source code is specific to NetWare 4.10, and it is
  31. **        assumed that the MONITOR.NLM has been loaded previously.  The program
  32. **        searches for the monitor screen and then simulates an F1 keystroke to
  33. **        that screen.  If successful, the monitor screen will bring up a help
  34. **        screen.
  35. **
  36. **        In main(), there is an auto (char *) variable called screenName.  You
  37. **        will notice that the 3.12 definition of screen name is commented out.
  38. **        To run the application on 3.12, the program may be recompiled after
  39. **        commenting out the 4.10 version and uncommenting the 3.12 version.  Or,
  40. **        the screenName may simply be specified on the LOAD command line:
  41. **
  42. **            LOAD UNGETCH "Monitor Screen"
  43. **
  44. **        Keep in mind that the double quotes are required.
  45. **
  46. **    Programmers:
  47. **
  48. **        Ini    Who                            Firm
  49. **        -----------------------------------------------------------------------
  50. **        ABJ    Adam B. Jerome                Novell Developer Support.
  51. **
  52. **    History:
  53. **
  54. **        When        Who    What
  55. **        -----------------------------------------------------------------------
  56. **        01-31-95    ABJ    First Code.
  57. **
  58. */
  59.  
  60. /****************************************************************************
  61. **    Compiler setup.
  62. */
  63.     /*------------------------------------------------------------------------
  64.     **    ANSI
  65.     */
  66.     #include <stdlib.h>
  67.     #include <stdio.h>
  68.     #include <errno.h>
  69.     #include <string.h>
  70.  
  71.     /*------------------------------------------------------------------------
  72.     **    NetWare CLIB
  73.     */
  74.     #include <niterror.h>
  75.     #include <conio.h>
  76.  
  77. /****************************************************************************
  78. **    Get a handle to an existing screen, or return EFAILURE.
  79. */
  80. int NLM_GetScreenHandle(char *screenName)
  81.     {
  82.     int nextScreenID;
  83.     int screenHandle;
  84.     char name[80+1];
  85.     LONG attr;
  86.  
  87.     /*------------------------------------------------------------------------
  88.     **    Scan through the screens of all NLMs looking for the specified
  89.     **    screenName.  If not found, return EFAILURE.
  90.     */
  91.     nextScreenID=ScanScreens(
  92.         /* I-    LastScreenID    */    NULL,
  93.         /*    -O    name                */    name,
  94.         /*    -O    attrib            */    &attr
  95.         );
  96.  
  97.     while(nextScreenID != NULL)
  98.         {
  99.         if(strcmp(screenName, name) == 0)
  100.             break;
  101.  
  102.         nextScreenID=ScanScreens(
  103.             /* I-    LastScreenID    */    nextScreenID,
  104.             /*    -O    name                */    name,
  105.             /*    -O    attrib            */    &attr
  106.             );
  107.         }
  108.  
  109.     if(nextScreenID == NULL)
  110.         return(EFAILURE);
  111.  
  112.     /*------------------------------------------------------------------------
  113.     **    Build a duplicate handle to the specified screenName.  CreateScreen
  114.     **    returns EFAILURE if not successful.
  115.     */
  116.     screenHandle=CreateScreen((char *)nextScreenID, 0);
  117.  
  118.     return(screenHandle);
  119.     }
  120.  
  121. /****************************************************************************
  122. **    Program start.
  123. */
  124. void main(int argC, char *argV[])
  125.     {
  126.     int    screenHandle = EFAILURE;
  127.     int    rVal;
  128.     int    currentScreen = NULL;
  129.  
  130.     char *screenName = "NetWare 4.10 Console Monitor";        /* NetWare 4.10    */
  131. /*    char *screenName = "Monitor Screen";                    */    /* NetWare 3.12    */
  132.  
  133.     /*------------------------------------------------------------------------
  134.     **    Sign-on.
  135.     */
  136.     fprintf(stderr, "UNGETCH() Testcase / Adam Jerome / Novell Developer Support / x7402\n");
  137.     fprintf(stderr, "\n");
  138.  
  139.     /*------------------------------------------------------------------------
  140.     **    Parse command-line.
  141.     */
  142.     if(argC > 1) screenName = argV[1];
  143.  
  144.     /*------------------------------------------------------------------------
  145.     **    Obtain a reference to the current screen.
  146.     */
  147.     currentScreen=GetCurrentScreen();
  148.     if(currentScreen == NULL)
  149.         {
  150.         fprintf(stderr, "ERROR: GetCurrentScreen() indicates NULL.");
  151.         goto END_ERR;
  152.         }
  153.  
  154.     /*------------------------------------------------------------------------
  155.     **    Get a handle to the specified screen.
  156.     */
  157.     screenHandle=NLM_GetScreenHandle(screenName);
  158.     if(screenHandle == EFAILURE)
  159.         {
  160.         fprintf(stderr, "ERROR: NLM_GetScreenHandle() indicates FAILURE.");
  161.         goto END_ERR;
  162.         }
  163.  
  164.     /*------------------------------------------------------------------------
  165.     **    Current screen is the specified screen.
  166.     */
  167.     rVal=SetCurrentScreen(screenHandle);
  168.     switch(rVal)
  169.         {
  170.         case ESUCCESS:
  171.             break;
  172.  
  173.         case EBADHNDL:
  174.             fprintf(stderr, "ERROR: SetCurrentScreen() indicates BAD HANDLE\n");
  175.             goto END_ERR;
  176.  
  177.         default:
  178.             fprintf(stderr, "ERROR: SetCurrentScreen() indicates %d\n", rVal);
  179.             goto END_ERR;
  180.         }
  181.  
  182.     /*------------------------------------------------------------------------
  183.     **    Send an extended keystroke (F1) to the specified screen.
  184.     */
  185.     ungetch(0x3B00);
  186.  
  187. END_ERR:
  188.  
  189.     /*------------------------------------------------------------------------
  190.     **    Restore our screen.
  191.     */
  192.     if(currentScreen != NULL)
  193.         {
  194.         rVal=SetCurrentScreen(currentScreen);
  195.         switch(rVal)
  196.             {
  197.             case ESUCCESS:
  198.                 break;
  199.  
  200.             case EBADHNDL:
  201.                 fprintf(stderr, "ERROR: SetCurrentScreen() indicates BAD HANDLE\n");
  202.                 break;
  203.  
  204.             default:
  205.                 fprintf(stderr, "ERROR: SetCurrentScreen() indicates %d\n", rVal);
  206.                 break;
  207.             }
  208.         }
  209.  
  210.     /*------------------------------------------------------------------------
  211.     **    Destroy reference to the specified screen.
  212.     */
  213.     if(screenHandle != EFAILURE)
  214.         {
  215.         rVal=DestroyScreen(screenHandle);
  216.         switch(rVal)
  217.             {
  218.             case ESUCCESS:
  219.                 break;
  220.  
  221.             case EBADHNDL:
  222.                 fprintf(stderr, "ERROR: DestroyScreen() indicates BAD HANDLE\n");
  223.                 break;
  224.  
  225.             default:
  226.                 fprintf(stderr, "ERROR: DestroyScreen() indicates %d\n", rVal);
  227.                 break;
  228.             }
  229.         }
  230.  
  231.     exit(0);
  232.     }
  233.     
  234.  
  235.