home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2003 February / PCWFEB03.iso / software / dantzretrospect / English / Installer / Data.Cab / F4110_sample_c.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-22  |  18.4 KB  |  716 lines

  1. /*
  2.  * sample_c.cpp
  3.  *
  4.  *     Sample event handler for Retrospect(R).
  5.  *
  6.  *
  7.  * Copyright 1999-2002 Dantz Development Corporation
  8.  *
  9.  */
  10.  
  11. #include <windows.h>
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "resource.h"
  16.  
  17. enum eReturnErrors {
  18.     noErr                        = 0,
  19.     abortTask                    = 1,
  20. };
  21.  
  22. #define MAX_CHARS                1024                        // The maximum length of the error message
  23. #define MAX_ARGS                18                            // Maximum number of command line arguments we accept
  24.  
  25.  
  26. // globals
  27. char gszTitle[MAX_CHARS];
  28.  
  29.  
  30. // prototypes for event handlers
  31. void StartApp(HINSTANCE hInst, PSTR started, PSTR autolaunched, PSTR interventionFile);
  32. void EndApp(HINSTANCE hInst, PSTR stopped);
  33. void StartBackupServer(HINSTANCE hInst, PSTR started, PSTR interventionFile);
  34. void StopBackupServer(HINSTANCE hInst, PSTR stopped);
  35. void StartScript(HINSTANCE hInst, PSTR scriptName, PSTR started, PSTR interventionFile);
  36. void EndScript(HINSTANCE hInst, PSTR scriptName, PSTR numErrors, PSTR fatalErrCode, PSTR fatalErrMsg);
  37. void StartSource(HINSTANCE hInst, PSTR sourceName, PSTR sourcePath, PSTR clientName, PSTR interventionFile);
  38. void EndSource(
  39.     HINSTANCE hInst, 
  40.     PSTR sourceName,
  41.     PSTR sourcePath,
  42.     PSTR KBTrans,
  43.     PSTR filesTrans,
  44.     PSTR duration,
  45.     PSTR scriptStart,
  46.     PSTR sourceStart,
  47.     PSTR sourceEnd,
  48.     PSTR backupSet,
  49.     PSTR clientName,
  50.     PSTR scriptName,
  51.     PSTR action,
  52.     PSTR parentVol,
  53.     PSTR numErrors,
  54.     PSTR fatalErrCode,
  55.     PSTR fatalErrMsg);
  56. void MediaRequest(HINSTANCE hInst, PSTR labelName, PSTR mediaName, PSTR known, PSTR secsWaited, PSTR interventionFile);
  57. void TimedOutMediaRequest(HINSTANCE hInst, PSTR labelName, PSTR mediaName, PSTR secsWaited, PSTR interventionFile);
  58. void PasswordEntry(HINSTANCE hInst, PSTR action, PSTR attempts, PSTR errCode, PSTR errMsg);
  59. void StopSched(HINSTANCE hInst, PSTR scriptName, PSTR stopTime, PSTR interventionFile);
  60. void ScriptCheckFailed(HINSTANCE hInst, PSTR scriptName, PSTR scriptStart, PSTR errCode, PSTR errMsg);
  61. void NextExec(HINSTANCE hInst, PSTR scriptName, PSTR scriptStart, PSTR interventionFile);
  62. void FatalErrorBackup(HINSTANCE hInst, PSTR scriptName, PSTR reason, PSTR errCode, PSTR errMsg, PSTR errZone, PSTR interventionFile);
  63.  
  64.  
  65. int getCmdArgs(PSTR szCmdLine, char cmdArgs[MAX_ARGS][MAX_CHARS]);
  66. void formatSeconds(PSTR seconds, PSTR formatedSecs);
  67.  
  68.  
  69. // functions
  70.  
  71. /*
  72.  * ReturnResult
  73.  *
  74.  *        Creates a file that contains the error messages
  75.  *
  76.  */
  77. void
  78. ReturnResult(HINSTANCE hInst, int errmsgid, PSTR interventionFile)
  79. {
  80.     FILE *fp;
  81.     char errMsg[MAX_CHARS];
  82.  
  83.     if ((fp = fopen(interventionFile, "w")) != NULL)
  84.     {
  85.         LoadString(hInst, errmsgid, errMsg, MAX_CHARS);
  86.         fprintf(fp, errMsg);
  87.         fclose(fp);
  88.     }
  89.     else
  90.     {
  91.         fprintf(stderr, "Can't open file: %s", interventionFile);
  92.         exit(1);
  93.     }
  94. }
  95.  
  96.  
  97. /*
  98.  * StartApp
  99.  *
  100.  *     Sent when Retrospect launches. wasAutoLaunched is true if Retrospect was
  101.  * launched automatically to run a scheduled script.
  102.  *
  103.  */
  104.  
  105. void 
  106. StartApp(HINSTANCE hInst, PSTR started, PSTR autolaunched, PSTR interventionFile)
  107. {
  108.     int result=noErr;
  109.  
  110.     char resStr[MAX_CHARS];
  111.     char msg[MAX_CHARS];
  112.  
  113.     if (strcmp(autolaunched, "true") == 0)
  114.         LoadString(hInst, IDS_AUTOLAUNCHED, resStr, MAX_CHARS);
  115.     else
  116.         LoadString(hInst, IDS_LAUNCHED, resStr, MAX_CHARS);
  117.  
  118.     sprintf(msg, resStr, started);
  119.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  120.     if (result != IDOK)
  121.         ReturnResult(hInst, IDS_ABORT_STARTAPP, interventionFile);
  122. }
  123.  
  124.  
  125. /*
  126.  * EndApp
  127.  *
  128.  *     Sent when Retrospect is quiting.
  129.  *
  130.  */
  131.  
  132. void EndApp(HINSTANCE hInst, PSTR stopped)
  133. {
  134.     char resStr[MAX_CHARS];
  135.     char msg[MAX_CHARS];
  136.  
  137.     LoadString(hInst, IDS_END_APP, resStr, MAX_CHARS);
  138.     sprintf(msg, resStr, stopped);
  139.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  140. }
  141.  
  142.  
  143. /*
  144.  * StartBackupServer
  145.  *
  146.  *     Sent when the BackupServer is started via either a script or manually.
  147.  * Return true to prevent backup server starting.
  148.  *
  149.  */
  150.  
  151. void StartBackupServer(HINSTANCE hInst, PSTR started, PSTR interventionFile)
  152. {
  153.     int result = noErr;
  154.  
  155.     char resStr[MAX_CHARS];
  156.     char msg[MAX_CHARS];
  157.  
  158.     LoadString(hInst, IDS_START_SERVER, resStr, MAX_CHARS);
  159.     sprintf(msg, resStr, started);
  160.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  161.     if (result != IDOK)
  162.         ReturnResult(hInst, IDS_ABORT_STARTBACKUPSERVER, interventionFile);
  163.  
  164. }
  165.  
  166.  
  167. /*
  168.  * StopBackupServer
  169.  *
  170.  *     Sent when Backup Server stops.
  171.  *
  172.  */
  173.  
  174. void StopBackupServer(HINSTANCE hInst, PSTR stopped)
  175. {
  176.     char resStr[MAX_CHARS];
  177.     char msg[MAX_CHARS];
  178.  
  179.     LoadString(hInst, IDS_STOP_SERVER, resStr, MAX_CHARS);
  180.     sprintf(msg, resStr, stopped);
  181.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  182. }
  183.  
  184.  
  185. /*
  186.  * StartScript
  187.  *
  188.  *     Sent when a script is run, either manually or as part of a scheduled
  189.  * execution. Return true to prevent script starting.
  190.  *
  191.  */
  192.  
  193. void StartScript(HINSTANCE hInst, PSTR scriptName, PSTR started, PSTR interventionFile)
  194. {
  195.     int result = noErr;
  196.  
  197.     char resStr[MAX_CHARS];
  198.     char msg[MAX_CHARS];
  199.  
  200.     LoadString(hInst, IDS_START_SCRIPT, resStr, MAX_CHARS);
  201.     sprintf(msg, resStr, scriptName, started);
  202.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  203.     if (result != IDOK)
  204.         ReturnResult(hInst, IDS_ABORT_STARTSCRIPT, interventionFile);
  205. }
  206.  
  207.  
  208. /*
  209.  * EndScript
  210.  *
  211.  *     Sent when a script finishes.
  212.  * numErrors is the total number of errors that occured. fatalErrCode is zero if
  213.  * the script was able to complete, otherwise it is a negative number for the
  214.  * error that caused the script to abort execution. errMsg is "successful" if
  215.  * there was no fatal error, otherwise it is the description of the error.
  216.  *
  217.  */
  218.  
  219. void EndScript(HINSTANCE hInst, PSTR scriptName, PSTR numErrors, PSTR fatalErrCode, PSTR fatalErrMsg)
  220. {
  221.     char resStr[MAX_CHARS];
  222.     char errStr[MAX_CHARS];
  223.     char msg[MAX_CHARS];
  224.  
  225.     if (*fatalErrCode != '0')
  226.         LoadString(hInst, IDS_FATAL_ERROR, resStr, MAX_CHARS);
  227.     else if (*numErrors == '0')
  228.         LoadString(hInst, IDS_SUCCESSFUL, resStr, MAX_CHARS);
  229.     else if (*numErrors == '1' && numErrors[1] == '\0')
  230.         LoadString(hInst, IDS_ONE_ERROR, resStr, MAX_CHARS);
  231.     else
  232.         LoadString(hInst, IDS_MANY_ERRORS, resStr, MAX_CHARS);
  233.     if (*fatalErrCode != '0')
  234.         sprintf(errStr, resStr, fatalErrCode, fatalErrMsg);
  235.     else
  236.         sprintf(errStr, resStr, numErrors);
  237.     LoadString(hInst, IDS_END_SCRIPT, resStr, MAX_CHARS);
  238.  
  239.     sprintf(msg, resStr, scriptName, errStr);
  240.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  241. }
  242.  
  243.  
  244. /*
  245.  * StartSource
  246.  *
  247.  *     Sent immediately before a script backs up a source volume.
  248.  * sourceName is the volume name that is being backed up, it will be prefaced
  249.  * with "My Computer\" if it is a local volume or the clientName otherwise.
  250.  * sourcePath is the file system path of the volume.
  251.  *
  252.  */
  253.  
  254. void StartSource(HINSTANCE hInst, PSTR scriptName,PSTR sourceName, PSTR sourcePath, PSTR clientName, PSTR interventionFile)
  255. {
  256.     int result = noErr;
  257.  
  258.     char resStr[MAX_CHARS];
  259.     char msg[MAX_CHARS];
  260.  
  261.     LoadString(hInst, IDS_START_SOURCE, resStr, MAX_CHARS);
  262.     sprintf(msg, resStr, scriptName,sourceName, sourcePath, clientName);
  263.  
  264.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  265.     if (result != IDOK)
  266.         ReturnResult(hInst, IDS_ABORT_STARTSOURCE, interventionFile);
  267.  
  268. }
  269.  
  270.  
  271. /*
  272.  * EndSource
  273.  *
  274.  *     Sent after a script has completed backing up a source. As above, sourceName
  275.  * is prefaced with either the client name or "My Computer\".
  276.  *
  277.  */
  278.  
  279. void EndSource(
  280.     HINSTANCE hInst, 
  281.     PSTR scriptName,
  282.     PSTR sourceName,
  283.     PSTR sourcePath,
  284.     PSTR clientName,
  285.     PSTR KBTrans,
  286.     PSTR filesTrans,
  287.     PSTR duration,
  288.     PSTR sourceStart,
  289.     PSTR sourceEnd,
  290.     PSTR scriptStart,
  291.     PSTR backupSet,
  292.     PSTR action,
  293.     PSTR parentVol,
  294.     PSTR numErrors,
  295.     PSTR fatalErrCode,
  296.     PSTR fatalErrMsg)
  297. {
  298.     char resStr[MAX_CHARS];
  299.     char errStr[MAX_CHARS];
  300.     char msg[MAX_CHARS];
  301.     char durStr[MAX_CHARS];
  302.     double trans;
  303.  
  304.     if (*fatalErrCode != '0')
  305.         LoadString(hInst, IDS_FATAL_ERROR, resStr, MAX_CHARS);
  306.     else if (*numErrors == '0')
  307.         LoadString(hInst, IDS_SUCCESSFUL, resStr, MAX_CHARS);
  308.     else if (*numErrors == '1' && numErrors[1] == '\0')
  309.         LoadString(hInst, IDS_ONE_ERROR, resStr, MAX_CHARS);
  310.     else
  311.         LoadString(hInst, IDS_MANY_ERRORS, resStr, MAX_CHARS);
  312.     if (*fatalErrCode != '0')
  313.         sprintf(errStr, resStr,fatalErrCode, fatalErrMsg);
  314.     else
  315.         sprintf(errStr, resStr, numErrors);
  316.  
  317.     LoadString(hInst, IDS_END_SOURCE, resStr, MAX_CHARS);
  318.     formatSeconds(duration, durStr);
  319.  
  320.     trans = atof(KBTrans);
  321.     if (trans > 1024 * 1024)
  322.         sprintf(KBTrans, "%.2fGB", trans / (1024 * 1024));
  323.     else if (trans > 1024)
  324.         sprintf(KBTrans, "%.2fMB", trans / 1024);
  325.     else
  326.         sprintf(KBTrans, "%.0fKB", trans);
  327.  
  328.     sprintf(msg, resStr, 
  329.         sourceName,
  330.         sourcePath,
  331.         clientName,
  332.         errStr,
  333.         scriptName,
  334.         action,
  335.         backupSet,
  336.         filesTrans,
  337.         KBTrans,
  338.         durStr,
  339.         scriptStart,
  340.         sourceStart,
  341.         sourceEnd);
  342.         // don't use parentVol
  343.  
  344.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  345. }
  346.  
  347.  
  348. /*
  349.  * MediaRequest
  350.  *
  351.  *     Sent before Retrospect requests media needed for a backup.
  352.  *
  353.  *     Return true to fail media request.
  354.  */
  355.  
  356. void MediaRequest(HINSTANCE hInst, PSTR labelName, PSTR mediaName, PSTR known, PSTR minsWaited, PSTR interventionFile)
  357. {
  358.     int result = noErr;
  359.     char resStr[MAX_CHARS];
  360.     char msg[MAX_CHARS];
  361.     char knownStr[MAX_CHARS];
  362.     char waitedStr[MAX_CHARS];
  363.     char secsWaited[MAX_CHARS];
  364.     int mins;
  365.     
  366.     if (*known == 't')
  367.         LoadString(hInst, IDS_MEDIA_KNOWN, knownStr, MAX_CHARS);
  368.     else
  369.         LoadString(hInst, IDS_MEDIA_UNKNOWN, knownStr, MAX_CHARS);
  370.  
  371.     
  372.     mins=atol(minsWaited);
  373.     sprintf(secsWaited, "%d", mins * 60);
  374.     formatSeconds(secsWaited, waitedStr);
  375.     LoadString(hInst, IDS_MEDIA_REQUEST, resStr, MAX_CHARS);
  376.     sprintf(msg, resStr, mediaName, labelName, knownStr, waitedStr);
  377.  
  378.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  379.     if (result != IDOK)
  380.         ReturnResult(hInst, IDS_ABORT_MEDIAREQUEST, interventionFile);
  381. }
  382.  
  383.  
  384. /*
  385.  * TimedOutMediaRequest
  386.  *
  387.  *     Sent before Retrospect times out on waiting for a media request. Note that
  388.  * the "Media Request Timeout" option in the preferences must be turned on to
  389.  * receive this event.
  390.  *
  391.  *     Return true to reset timeout request.
  392.  *
  393.  */
  394.  
  395. void TimedOutMediaRequest(HINSTANCE hInst, PSTR labelName, PSTR mediaName, PSTR known, PSTR minsWaited, PSTR interventionFile)
  396. {
  397.     int result = noErr;
  398.     char resStr[MAX_CHARS];
  399.     char msg[MAX_CHARS];
  400.     char waitedStr[MAX_CHARS];
  401.     char secsWaited[MAX_CHARS];
  402.     int mins;
  403.  
  404.     mins = atol(minsWaited);
  405.     sprintf(secsWaited, "%d", mins * 60);
  406.     formatSeconds(secsWaited, waitedStr);
  407.     LoadString(hInst, IDS_TO_MEDIA_REQUEST, resStr, MAX_CHARS);
  408.     sprintf(msg, resStr, mediaName, labelName, waitedStr);
  409.  
  410.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  411.     if (result != IDOK)
  412.         ReturnResult(hInst, IDS_ABORT_TIMEOUTMEDIAREQUEST, interventionFile);
  413.  
  414. }
  415.  
  416.  
  417. /*
  418.  * PasswordEntry
  419.  *
  420.  *     Sent when a password is entered.
  421.  *
  422.  */
  423.  
  424. void PasswordEntry(HINSTANCE hInst, PSTR action, PSTR attempts, PSTR errCode, PSTR errMsg)
  425. {
  426.     char resStr[MAX_CHARS];
  427.     char msg[MAX_CHARS];
  428.  
  429.     if (*errCode != '0')
  430.     {    
  431.         LoadString(hInst, IDS_PASSWORD_FAILED, resStr, MAX_CHARS);
  432.         sprintf(msg, resStr, attempts, errCode, errMsg, action);
  433.     }
  434.     else if (attempts[0] == '1' && attempts[1] == '\0')  
  435.     {    
  436.         LoadString(hInst, IDS_PASSWORD_ONE, resStr, MAX_CHARS);
  437.         sprintf(msg, resStr, action);
  438.     }
  439.     else
  440.     {    
  441.         LoadString(hInst, IDS_PASSWORD_MANY, resStr, MAX_CHARS);
  442.         sprintf(msg, resStr, attempts, action);
  443.     }
  444.         
  445.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  446. }
  447.  
  448.  
  449. /*
  450.  * StopSched
  451.  *
  452.  *     Sent when an unattended script is scheduled to stop. Return true to keep
  453.  * script running.
  454.  *
  455.  */
  456.  
  457. void StopSched(HINSTANCE hInst, PSTR scriptName, PSTR stopTime, PSTR interventionFile)
  458. {
  459.     int result = noErr;
  460.     char resStr[MAX_CHARS];
  461.     char msg[MAX_CHARS];
  462.  
  463.     LoadString(hInst, IDS_STOPSCHED, resStr, MAX_CHARS);
  464.     sprintf(msg, resStr, scriptName, stopTime);
  465.  
  466.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  467.     if (result != IDOK)
  468.         ReturnResult(hInst, IDS_ABORT_STOPSCHED, interventionFile);
  469.  
  470. }
  471.  
  472.  
  473. /*
  474.  * ScriptCheckFailed
  475.  *
  476.  *     Sent before Retrospect quits when the next script to execute will not be
  477.  * able to run. "Check validity of next script" must be checked in Retrospect's
  478.  * preferences (Notification:Alerts) to receive this event.
  479.  *
  480.  */
  481.  
  482. void ScriptCheckFailed(HINSTANCE hInst, PSTR scriptName, PSTR scriptStart, PSTR reason, PSTR errCode, PSTR errMsg)
  483. {
  484.     char resStr[MAX_CHARS];
  485.     char msg[MAX_CHARS];
  486.  
  487.     LoadString(hInst, IDS_SCRIPT_CHECK_FAILED, resStr, MAX_CHARS);
  488.  
  489.     sprintf(msg, resStr, scriptName, scriptStart, errCode, errMsg, reason);
  490.  
  491.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  492. }
  493.  
  494.  
  495. /*
  496.  * NextExec
  497.  *
  498.  *     Sent before Retrospect quits when the next script to execute is able to
  499.  * run. "Check validity of next script" must be checked in Retrospect's
  500.  * preferences (Notification:Alerts) to receive this event.
  501.  *
  502.  */
  503.  
  504. void NextExec(HINSTANCE hInst, PSTR scriptName, PSTR scriptStart)
  505. {
  506.     char resStr[MAX_CHARS];
  507.     char msg[MAX_CHARS];
  508.  
  509.     LoadString(hInst, IDS_NEXT_EXEC, resStr, MAX_CHARS);
  510.  
  511.     sprintf(msg, resStr, scriptName, scriptStart);
  512.  
  513.     MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OK);
  514. }
  515.  
  516.  
  517. /*
  518.  * FatalBackupError
  519.  *
  520.  *     Sent when a unrecoverable error is detected, such as a hardware
  521.  * failure
  522.  *
  523.  */
  524.  
  525. void FatalBackupError(HINSTANCE hInst, PSTR scriptName, PSTR reason, PSTR errCode, PSTR errMsg, PSTR errZone, PSTR interventionFile)
  526. {
  527.     int result = noErr;
  528.     char resStr[MAX_CHARS];
  529.     char msg[MAX_CHARS];
  530.  
  531.     LoadString(hInst, IDS_FATALERROR, resStr, MAX_CHARS);
  532.     sprintf(msg, resStr, scriptName, errZone, errCode, errMsg, reason);
  533.  
  534.     result = MessageBox(NULL, msg, gszTitle, MB_ICONINFORMATION | MB_OKCANCEL);
  535.     if (result != IDOK)
  536.         ReturnResult(hInst, IDS_ABORT_FATALBACKUPERROR, interventionFile);
  537.  
  538. }
  539.  
  540.  
  541. /*
  542.  * WinMain
  543.  *
  544.  *     Dispatch the event specified in the first command line argument to the
  545.  * appropriate function above.
  546.  *
  547.  */
  548.  
  549. int WINAPI
  550. WinMain(HINSTANCE hInst, HINSTANCE hNotUsed, PSTR szCmdLine, int iCmdShow)
  551. {
  552.     char szMsg[MAX_CHARS];
  553.     char *szTempPtr = szMsg;
  554.     int numArgs;
  555.     char args[MAX_ARGS][MAX_CHARS];
  556.     
  557.     // Form caption (the text of the title bar)
  558.     LoadString(hInst, IDS_APP_TITLE, gszTitle, MAX_CHARS);
  559.  
  560.     szCmdLine = GetCommandLine();                            // get entire command line
  561.     if ((numArgs = getCmdArgs(szCmdLine, args)) < 2)
  562.     {
  563.         LoadString(hInst, IDS_APP_MESSAGE, szMsg, MAX_CHARS);
  564.         MessageBox(NULL, szMsg, gszTitle, MB_ICONINFORMATION | MB_OK);
  565.         return (noErr);                                        // need <appname> <eventName> at least
  566.     }
  567.     
  568. #ifdef _DEBUG
  569.     // debug arguments
  570.     for (--numArgs; numArgs > 0; --numArgs)
  571.         MessageBox(NULL, args[numArgs], gszTitle, MB_ICONINFORMATION | MB_OK);
  572. #endif
  573.  
  574.     if (strcmp(args[1], "StartApp") == 0)
  575.         StartApp(hInst, args[2], args[3], args[4]);
  576.     else if (strcmp(args[1], "EndApp") == 0)
  577.         EndApp(hInst, args[2]);
  578.     else if (strcmp(args[1], "StartBackupServer") == 0)
  579.         StartBackupServer(hInst, args[2], args[3]);
  580.     else if (strcmp(args[1], "StopBackupServer") == 0)
  581.         StopBackupServer(hInst, args[2]);
  582.     else if (strcmp(args[1], "StartScript") == 0)
  583.         StartScript(hInst, args[2], args[3], args[4]);
  584.     else if (strcmp(args[1], "EndScript") == 0)
  585.         EndScript(hInst, args[2], args[3], args[4], args[5]);
  586.     else if (strcmp(args[1], "StartSource") == 0)
  587.         StartSource(hInst, args[2], args[3], args[4], args[5], args[6]);
  588.     else if (strcmp(args[1], "EndSource") == 0)
  589.         EndSource(hInst, args[2], args[3], args[4], args[5], args[6], args[7], 
  590.         args[8], args[9], args[10], args[11], args[12], args[13], args[14], 
  591.         args[15], args[16], args[17]);
  592.     else if (strcmp(args[1], "MediaRequest") == 0)
  593.         MediaRequest(hInst, args[2], args[3], args[4], args[5], args[6]);
  594.     else if (strcmp(args[1], "TimedOutMediaRequest") == 0)
  595.         TimedOutMediaRequest(hInst, args[2], args[3], args[4], args[5], args[6]);
  596.     else if (strcmp(args[1], "PasswordEntry") == 0)
  597.         PasswordEntry(hInst, args[2], args[3], args[4], args[5]);
  598.     else if (strcmp(args[1], "StopSched") == 0)
  599.         StopSched(hInst, args[2], args[3], args[4]);
  600.     else if (strcmp(args[1], "ScriptCheckFailed") == 0)
  601.         ScriptCheckFailed(hInst, args[2], args[3], args[4], args[5], args[6]);
  602.     else if (strcmp(args[1], "NextExec") == 0)
  603.         NextExec(hInst, args[2], args[3]);
  604.     else if (strcmp(args[1], "FatalBackupError") == 0)    
  605.         FatalBackupError(hInst, args[2], args[3], args[4], args[5], args[6], args[7]);
  606.  
  607.     return (0);
  608. }
  609.  
  610.  
  611. /*
  612.  * getCmdArgs
  613.  *
  614.  *     Return the space or quote delimited args in cmdArgs.
  615.  * Return the number of arguments parsed. The delimiting quotes, if any, are 
  616.  * stripped off.
  617.  *
  618.  */
  619.  
  620. int
  621. getCmdArgs(PSTR szCmdLine, char cmdArgs[MAX_ARGS][MAX_CHARS])
  622. {
  623.     int numArgs = 0;
  624.     char delim = 0;
  625.     char next;
  626.     char *argp = 0;
  627.  
  628.     while ((next = *szCmdLine++) != 0)
  629.     {
  630.         if (argp == 0)
  631.         {
  632.             if (delim == 0 && next == '"')
  633.                 delim = next;
  634.             else if (next != ' ' || delim == '"')
  635.             {
  636.                 if (delim == 0)
  637.                     delim = ' ';
  638.                 argp = cmdArgs[numArgs++];
  639.             }
  640.         }
  641.         
  642.         if (argp != 0)
  643.         {
  644.             if (next == delim)                                // done with this arg
  645.             {
  646.                 *argp = '\0';
  647.                 argp = 0;
  648.                 delim = 0;
  649.             }
  650.             else
  651.             {
  652.                 *argp++ = next;
  653.             }
  654.         }
  655.     }
  656.  
  657.     if (argp != 0)
  658.         *argp = 0;                                            // didn't terminate last arg
  659.  
  660.     return (numArgs);
  661. }
  662.  
  663. void
  664. formatSeconds(PSTR seconds, PSTR formatedSecs)
  665. {
  666.     long int secs, mins, hrs, days;
  667.  
  668.     secs = atol(seconds);
  669.  
  670.     if (secs == 0)
  671.         formatedSecs += sprintf(formatedSecs, "0 seconds ");
  672.     
  673.     days = secs / 86400;
  674.     secs = secs % 86400;
  675.  
  676.     hrs = secs / 3600;
  677.     secs = secs % 3600;
  678.  
  679.     mins = secs / 60;
  680.     secs = secs % 60;
  681.  
  682.     if (days > 0)
  683.     {
  684.         if (days == 1)
  685.             formatedSecs += sprintf(formatedSecs, "1 day ");
  686.         else
  687.             formatedSecs += sprintf(formatedSecs, "%d days ", days);
  688.     }
  689.  
  690.     if (hrs > 0)
  691.     {
  692.         if (hrs == 1)
  693.             formatedSecs += sprintf(formatedSecs, "1 hour ");
  694.         else
  695.             formatedSecs += sprintf(formatedSecs, "%d hours ", hrs);
  696.     }
  697.  
  698.     if (mins > 0)
  699.     {
  700.         if (mins == 1)
  701.             formatedSecs += sprintf(formatedSecs, "1 minute ");
  702.         else
  703.             formatedSecs += sprintf(formatedSecs, "%d minutes ", mins);
  704.     }
  705.  
  706.     if (secs > 0)
  707.     {
  708.         if (secs == 1)
  709.             formatedSecs += sprintf(formatedSecs, "1 second ");
  710.         else
  711.             formatedSecs += sprintf(formatedSecs, "%d seconds ", secs);
  712.     }
  713.  
  714.     --formatedSecs;                                            // back up over the terminating space
  715.     *formatedSecs = '\0';
  716. }