home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / delay.exe / DELAY.C next >
C/C++ Source or Header  |  1994-07-29  |  5KB  |  135 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. ** Programmers:
  40. **
  41. **    Ini   Who                  Firm
  42. **    -----------------------------------------------------------------------
  43. **    ABJ   Adam B. Jerome       Novell Developer Support.
  44. **    DWH   Dirk W. Howard       Novell Developer Support.
  45. **
  46. ** History:
  47. **
  48. **    When     Who   What
  49. **    -----------------------------------------------------------------------
  50. **    07-20-94 ABJ   First code.
  51. **    07-29-94 DWH   Added Standard Disclaimer
  52. */
  53.  
  54. /****************************************************************************
  55. ** Include headers, macros, function prototypes, etc.
  56. */
  57.    /*------------------------------------------------------------------------
  58.    ** ANSI
  59.    */
  60.    #include <stdlib.h>     /* exit(), atol()       */
  61.    #include <time.h>       /* difftime(), time()   */
  62.    #include <stdio.h>      /* sprintf()            */
  63.  
  64.    /*------------------------------------------------------------------------
  65.    ** NetWare
  66.    */
  67.    #include <process.h>    /* delay()              */
  68.    #include <conio.h>      /* ConsolePrintf()      */
  69.    #include <advanced.h>   /* SynchronizeStart()   */
  70.  
  71. /****************************************************************************
  72. ** Program Start.
  73. */
  74. void main(int argc, char *argv[])
  75.    {
  76.    time_t         sTime;         /* Start time  */
  77.    char           szTemp[100+1];
  78.    double         seconds;
  79.    double         delta;         /* Time shift in seconds.  */
  80.    int            barLen;
  81.    int            barLenOld=0;
  82.    char *bar="▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒";
  83.  
  84.    /*------------------------------------------------------------------------
  85.    ** Check command line args.
  86.    */ 
  87.    if(argc != 2)
  88.       {
  89.       ConsolePrintf("Usage: LOAD %s {delay}\n\r", argv[0]);
  90.       ConsolePrintf("\n\r");      
  91.       ConsolePrintf("     {delay}   This parameter specifies the delay in seconds.\n\r");     
  92.       ConsolePrintf("\n\r");      
  93.       goto EXIT;
  94.       }
  95.  
  96.    /*------------------------------------------------------------------------
  97.    ** Calculate delay time in seconds.
  98.    */ 
  99.    seconds=strtod(argv[1], NULL);
  100.    sTime=time(NULL);
  101.  
  102.    /*------------------------------------------------------------------------
  103.    ** Delay as requested.
  104.    */ 
  105.    delta=difftime(time(NULL), sTime);
  106.    while(delta < (double)seconds)
  107.       {
  108.       barLen=79 - (int)((78.0 / seconds) * (delta));
  109.  
  110.       if(barLenOld != barLen)
  111.          {
  112.          sprintf(szTemp, "%79s", "");
  113.          ConsolePrintf("%s\r", szTemp);
  114.          sprintf(szTemp, "%.*s", barLen, bar);
  115.          ConsolePrintf("%s\r", szTemp);
  116.          barLenOld = barLen;
  117.          }
  118.  
  119.       ThreadSwitch();
  120.       delta=difftime(time(NULL), sTime);
  121.       }
  122.  
  123.    /*------------------------------------------------------------------------
  124.    ** Bye.
  125.    */ 
  126. EXIT:
  127.  
  128.    /*------------------------------------------------------------------------
  129.    ** Release the system prompt.
  130.    */ 
  131.    SynchronizeStart();
  132.  
  133.    exit(0);
  134.    }
  135.