home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xsnc1.exe / DELAY.C next >
Text File  |  1994-09-12  |  5KB  |  139 lines

  1. /****************************************************************************
  2. **    File:    DELAY.C
  3. **
  4. **    Desc:    Delay's (the System prompt) a specified amount of time.
  5. **
  6. **        Being that NetWare is multi-threaded, this NLM (once loaded)
  7. **        would run in it's own thread and the system prompt (colon) would
  8. **        become available for a new command.  To prevent this, the Link
  9. **        directive "SYNCHRONIZE" has been implemented.  It is described in
  10. **        the NLM Development Tools manual, page 118, as follows:
  11. **
  12. **        "When an NLM    that includes this option is loaded, the load process
  13. **        goes to sleep until the NLM calls the SynchronizeStart function.
  14. **        This prevents any other console command from being processed
  15. **        (particularly other LOAD commands) while the NLM is being loaded.
  16. **        NOTE: It is imperative that the NLM call the SynchronizeStart
  17. **        function as soon as possible after being loaded, so that the
  18. **        console command process will be started."
  19. **
  20. **    Disclaimer:
  21. **
  22. **        Novell, Inc. makes no representations or warranties with respect to
  23. **        any NetWare software, and specifically disclaims any express or
  24. **        implied warranties of merchantability, title, or fitness for a
  25. **        particular purpose.  
  26. **
  27. **        Distribution of any NetWare software is forbidden without the
  28. **        express written consent of Novell, Inc.  Further, Novell reserves
  29. **        the right to discontinue distribution of any NetWare software.
  30. **
  31. **        Novell is not responsible for lost profits or revenue, loss of use
  32. **        of the software, loss of data, costs of re-creating lost data, the
  33. **        cost of any substitute equipment or program, or claims by any party
  34. **        other than you.  Novell strongly recommends a backup be made before
  35. **        any software is installed.   Technical support for this software
  36. **        may be provided at the discretion of Novell.
  37. **
  38. **
  39. **    QMK386 options used:
  40. **
  41. **        /ns - Synchronize start.
  42. **        /x  - no default screen for NLM
  43. **
  44. **    Programmers:
  45. **
  46. **        Ini    Who                        Firm
  47. **        -----------------------------------------------------------------------
  48. **        ABJ    Adam B. Jerome            Novell Developer Support.
  49. **
  50. **    History:
  51. **
  52. **        When        Who    What
  53. **        -----------------------------------------------------------------------
  54. **        07-20-94    ABJ    First code.
  55. */
  56.  
  57. /****************************************************************************
  58. **    Include headers, macros, function prototypes, etc.
  59. */
  60.     /*------------------------------------------------------------------------
  61.     **    ANSI
  62.     */
  63.     #include <stdlib.h>        /* exit(), atol()            */
  64.     #include <time.h>            /* difftime(), time()    */
  65.     #include    <stdio.h>        /* sprintf()                */
  66.  
  67.     /*------------------------------------------------------------------------
  68.     **    NetWare
  69.     */
  70.     #include <process.h>        /* delay()                    */
  71.     #include <conio.h>        /*    ConsolePrintf()        */
  72.     #include <advanced.h>    /*    SynchronizeStart()    */
  73.  
  74. /****************************************************************************
  75. **    Program Start.
  76. */
  77. void main(int argc, char *argv[])
  78.     {
  79.     time_t             sTime;            /* Start time    */
  80.     char                 szTemp[100+1];
  81.     double             seconds;
  82.     double            delta;            /* Time shift in seconds.    */
  83.     int                barLen;
  84.     int                barLenOld=0;
  85.     char *bar="▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒";
  86.  
  87.     /*------------------------------------------------------------------------
  88.     **    Check command line args.
  89.     */    
  90.     if(argc != 2)
  91.         {
  92.         ConsolePrintf("Usage: LOAD %s {delay}\n\r", argv[0]);
  93.         ConsolePrintf("\n\r");         
  94.         ConsolePrintf("     {delay}   This parameter specifies the delay in seconds.\n\r");         
  95.         ConsolePrintf("\n\r");         
  96.         goto EXIT;
  97.         }
  98.  
  99.     /*------------------------------------------------------------------------
  100.     **    Calculate delay time in seconds.
  101.     */    
  102.     seconds=strtod(argv[1], NULL);
  103.     sTime=time(NULL);
  104.  
  105.     /*------------------------------------------------------------------------
  106.     **    Delay as requested.
  107.     */    
  108.     delta=difftime(time(NULL), sTime);
  109.     while(delta < (double)seconds)
  110.         {
  111.         barLen=79 - (int)((78.0 / seconds) * (delta));
  112.  
  113.         if(barLenOld != barLen)
  114.             {
  115.             sprintf(szTemp, "%79s", "");
  116.             ConsolePrintf("%s\r", szTemp);
  117.             sprintf(szTemp, "%.*s", barLen, bar);
  118.             ConsolePrintf("%s\r", szTemp);
  119.             barLenOld = barLen;
  120.             }
  121.  
  122.         ThreadSwitch();
  123.         delta=difftime(time(NULL), sTime);
  124.         }
  125.  
  126.     /*------------------------------------------------------------------------
  127.     **    Bye.
  128.     */    
  129. EXIT:
  130.  
  131.     /*------------------------------------------------------------------------
  132.     **    Release the system prompt.
  133.     */    
  134.     SynchronizeStart();
  135.  
  136.     exit(0);
  137.     }
  138.  
  139.