home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / sd2.zip / Utility.c < prev    next >
Text File  |  1998-05-17  |  31KB  |  622 lines

  1. /***********************************************************************\
  2.  *                               Utiltiy.c                             *
  3.  *                 Copyright (C) by Stangl Roman, 1993                 *
  4.  *                                                                     *
  5.  * Utility.c    Additional utility procedures for ShutDown/2           *
  6.  *                                                                     *
  7. \***********************************************************************/
  8.  
  9. static char RCSID[]="@(#) $Header: Utility.c Version 1.00 06,1993 $ (LBL)";
  10.  
  11. #include        "ShutDown.h"            /* User include files */
  12.  
  13. /*--------------------------------------------------------------------------------------*\
  14.  * Procedure to initialize a window and its message queue.                              *
  15.  * Req:                                                                                 *
  16.  *      pHab .......... A pointer to be filled with the anchor block of the window      *
  17.  *      pHmq .......... A pointer to be filled with the message queue of the window     *
  18.  * Returns:                                                                             *
  19.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  20. \*--------------------------------------------------------------------------------------*/
  21. BOOL    WinStartUp(HAB *pHab, HMQ *pHmq)
  22. {
  23.                                         /* Initialize handle of anchor block */
  24. if((*pHab=WinInitialize(0))==NULLHANDLE)
  25.     return(FALSE);
  26.                                         /* Initialize handle of message queue */
  27. if((*pHmq=WinCreateMsgQueue(*pHab, 0))==NULLHANDLE)
  28.     return(FALSE);
  29. return(TRUE);
  30. }
  31.  
  32. /*--------------------------------------------------------------------------------------*\
  33.  * Procedure to initialize HELP.                                                        *
  34.  * Req:                                                                                 *
  35.  *      hab ........... Anchor block handle                                             *
  36.  *      pHelpFile ..... A pointer to helppanel filename in SD/2 directory               *
  37.  *      pHwndHelp  .... A pointer to a HWND structure                                   *
  38.  * Returns:                                                                             *
  39.  *      pHwndHelp ..... If called sucessfully/unsucessfully hwnd/NULL                   *
  40. \*--------------------------------------------------------------------------------------*/
  41. BOOL    WinStartHelp(HAB hab, UCHAR *pHelpFile, HWND *pHwndHelp)
  42. {
  43. HELPINIT        HelpInit;
  44.  
  45. HelpInit.cb=sizeof(HELPINIT);           /* Size of HELPINIT structure */
  46. HelpInit.ulReturnCode=0;                /* Returnvalue from HelpManager */
  47. HelpInit.pszTutorialName=NULL;          /* No tutorial */
  48.                                         /* Ressource of Helptable */
  49. HelpInit.phtHelpTable=(PHELPTABLE)MAKEULONG(MAIN_HELP_TABLE, 0xffff);
  50.                                         /* Ressource in .EXE */
  51. HelpInit.hmodHelpTableModule=NULLHANDLE;
  52.                                         /* No handle */
  53. HelpInit.hmodAccelActionBarModule=NULLHANDLE;
  54. HelpInit.idAccelTable=0;                /* None */
  55. HelpInit.idActionBar=0;                 /* None */
  56.                                         /* Window title of help window */
  57. HelpInit.pszHelpWindowTitle="SD/2 - ShutDown/2 Help";
  58. HelpInit.pszHelpLibraryName=pHelpFile;  /* Library name of help panel via SD/2 directory */
  59. HelpInit.fShowPanelId=0;                /* Panel ID not displayed */
  60. /*                                                                                      *\
  61.  * First assume ShutDown.HLP in HELP path and try to create it from there.              *
  62. \*                                                                                      */
  63. *pHwndHelp=WinCreateHelpInstance(       /* Create help */
  64.     hab,                                /* Anchor block */
  65.     &HelpInit);
  66.                                         /* Test for successful help creation */
  67. if((*pHwndHelp) && (!HelpInit.ulReturnCode))
  68.                                         /* Associate HELP with frame window */
  69.     if(WinAssociateHelpInstance(*pHwndHelp, hwndFrame)!=FALSE)
  70.         return(TRUE);
  71. /*                                                                                      *\
  72.  * Second assume ShutDown.HLP in SD/2's directory and try to create it from there.      *
  73. \*                                                                                      */
  74. HelpInit.ulReturnCode=0;                /* Returnvalue from HelpManager */
  75.                                         /* Library name of help panel via HELP path */
  76. HelpInit.pszHelpLibraryName="ShutDown.hlp";
  77. *pHwndHelp=WinCreateHelpInstance(hab, &HelpInit);
  78. if((*pHwndHelp) && (!HelpInit.ulReturnCode))
  79.     if(WinAssociateHelpInstance(*pHwndHelp, hwndFrame)!=FALSE)
  80.         return(TRUE);
  81. *pHwndHelp=NULLHANDLE;
  82. return(FALSE);
  83. }
  84.  
  85. /*--------------------------------------------------------------------------------------*\
  86.  * Procedure to close a window and its message queue.                                   *
  87.  * Req:                                                                                 *
  88.  *      pHwndHelp ..... A pointer to HELP window handle                                 *
  89.  *      pHab .......... A pointer to extract the anchor block of the window             *
  90.  *      pHmq .......... A pointer to extract message queue of the window                *
  91.  * Returns:                                                                             *
  92.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  93. \*--------------------------------------------------------------------------------------*/
  94. BOOL    WinCloseDown(HWND *pHwndHelp, HAB *pHab, HMQ *pHmq)
  95. {
  96. if(!*pHwndHelp)                         /* Release HELP */
  97.     WinDestroyHelpInstance(*pHwndHelp);
  98. if(*pHmq!=NULLHANDLE)                   /* Release handle of message queue */
  99.     WinDestroyMsgQueue(*pHmq);
  100. if(*pHab!=NULLHANDLE)                   /* Release handle of anchor block */
  101.     WinTerminate(*pHab);
  102.                                         /* Any error during WinStartUp */
  103. if((*pHab==NULLHANDLE) || (*pHmq==NULLHANDLE)) return(FALSE);
  104. else return(TRUE);
  105. }
  106.  
  107. /*--------------------------------------------------------------------------------------*\
  108.  * Procedure opens the profile and writes the UPS structure into.                       *
  109.  * Req:                                                                                 *
  110.  *      pHini ......... A pointer to the handle of the profile                          *
  111.  *      pHab .......... A pointer to extract the anchor block of the window             *
  112.  *      pUps .......... A pointer to the UPS structure                                  *
  113.  * Returns:                                                                             *
  114.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  115. \*--------------------------------------------------------------------------------------*/
  116. BOOL    Write_Profile(HINI *pHini, HAB *pHab, UPS *pUps)
  117. {
  118.                                         /* First open the profile */
  119. *pHini=PrfOpenProfile(*pHab, pucSD2Profile);
  120. if(*pHini!=NULLHANDLE)
  121.     {
  122.     PrfWriteProfileData(                /* Write binary data to profile */
  123.         *pHini,                         /* Handle of profile */
  124.         SD2_CLASSNAME,                  /* Application name */
  125.         "IDUBC_Hours",                  /* Key name */
  126.         &pUps->IDUBC_Hours,             /* Value data */
  127.         sizeof(UCHAR));                 /* Size of value data */
  128.     PrfWriteProfileData(
  129.         *pHini,
  130.         SD2_CLASSNAME,
  131.         "IDUBC_Minutes",
  132.         &pUps->IDUBC_Minutes,
  133.         sizeof(UCHAR));
  134.     PrfWriteProfileData(
  135.         *pHini,
  136.         SD2_CLASSNAME,
  137.         "IDUAS_Hours",
  138.         &pUps->IDUAS_Hours,
  139.         sizeof(UCHAR));
  140.     PrfWriteProfileData(
  141.         *pHini,
  142.         SD2_CLASSNAME,
  143.         "IDUAS_Minutes",
  144.         &pUps->IDUAS_Minutes,
  145.         sizeof(UCHAR));
  146.     PrfWriteProfileData(
  147.         *pHini,
  148.         SD2_CLASSNAME,
  149.         "IDUASD_Hours",
  150.         &pUps->IDUASD_Hours,
  151.         sizeof(UCHAR));
  152.     PrfWriteProfileData(
  153.         *pHini,
  154.         SD2_CLASSNAME,
  155.         "IDUASD_Minutes",
  156.         &pUps->IDUASD_Minutes,
  157.         sizeof(UCHAR));
  158.     PrfWriteProfileData(
  159.         *pHini,
  160.         SD2_CLASSNAME,
  161.         "IDUS_Hours",
  162.         &pUps->IDUS_Hours,
  163.         sizeof(UCHAR));
  164.     PrfWriteProfileData(
  165.         *pHini,
  166.         SD2_CLASSNAME,
  167.         "IDUS_Minutes",
  168.         &pUps->IDUS_Minutes,
  169.         sizeof(UCHAR));
  170.     PrfWriteProfileString(
  171.         *pHini,
  172.         SD2_CLASSNAME,
  173.         "IDS_PgmName",
  174.         pUps->IDS_PgmName);
  175.     PrfWriteProfileString(
  176.         *pHini,
  177.         SD2_CLASSNAME,
  178.         "IDS_PgmDirectory",
  179.         pUps->IDS_PgmDirectory);
  180.     PrfWriteProfileString(
  181.         *pHini,
  182.         SD2_CLASSNAME,
  183.         "IDS_PgmInputs",
  184.         pUps->IDS_PgmInputs);
  185.     PrfWriteProfileData(
  186.         *pHini,
  187.         SD2_CLASSNAME,
  188.         "GRP_Mode",
  189.         &pUps->GRP_Mode,
  190.         sizeof(ULONG));
  191.     PrfWriteProfileString(
  192.         *pHini,
  193.         SD2_CLASSNAME,
  194.         "IDS_UserInfo",
  195.         pUps->IDS_UserInfo);
  196.     return(PrfCloseProfile(*pHini));    /* Close and return result */
  197.     }
  198. else
  199.     {                                   /* Profile couldn't be opened successfully */
  200.                                         /* SHUTDOWN.INI defective logging into logfile */
  201.     DosGetDateTime(&UPS_Current);
  202.     UPS_LogfileIO(LF_INIFILE_PROBLEM, MPFROMP(&UPS_Current));
  203.     return(FALSE);
  204.     }
  205. }
  206.  
  207. /*--------------------------------------------------------------------------------------*\
  208.  * Procedure opens the profile and reads the UPS structure from.                        *
  209.  * Req:                                                                                 *
  210.  *      pHini ......... A pointer to the handle of the profile                          *
  211.  *      pHab .......... A pointer to extract the anchor block of the window             *
  212.  *      pUps .......... A pointer to the UPS structure                                  *
  213.  * Returns:                                                                             *
  214.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  215. \*--------------------------------------------------------------------------------------*/
  216. BOOL    Read_Profile(HINI *pHini, HAB *pHab, UPS *pUps)
  217. {
  218. ULONG   ulSize;
  219. UCHAR   *uc='\0';
  220.                                         /* First open the profile */
  221. *pHini=PrfOpenProfile(*pHab, pucSD2Profile);
  222. while(TRUE)
  223.     {
  224.     ulSize=sizeof(UCHAR);
  225.     if(PrfQueryProfileData(             /* Query binary data from profile */
  226.         *pHini,                         /* Handle of profile */
  227.         SD2_CLASSNAME,                  /* Application name */
  228.         "IDUBC_Hours",                  /* Key name */
  229.         &pUps->IDUBC_Hours,             /* Value data */
  230.         &ulSize)==FALSE)                /* Size of value data */
  231.         { *pHini=NULLHANDLE; break; }
  232.     if(PrfQueryProfileData(
  233.         *pHini,
  234.         SD2_CLASSNAME,
  235.         "IDUBC_Minutes",
  236.         &pUps->IDUBC_Minutes,
  237.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  238.     if(PrfQueryProfileData(
  239.         *pHini,
  240.         SD2_CLASSNAME,
  241.         "IDUAS_Hours",
  242.         &pUps->IDUAS_Hours,
  243.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  244.     if(PrfQueryProfileData(
  245.         *pHini,
  246.         SD2_CLASSNAME,
  247.         "IDUAS_Minutes",
  248.         &pUps->IDUAS_Minutes,
  249.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  250.     if(PrfQueryProfileData(
  251.         *pHini,
  252.         SD2_CLASSNAME,
  253.         "IDUASD_Hours",
  254.         &pUps->IDUASD_Hours,
  255.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  256.     if(PrfQueryProfileData(
  257.         *pHini,
  258.         SD2_CLASSNAME,
  259.         "IDUASD_Minutes",
  260.         &pUps->IDUASD_Minutes,
  261.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  262.     if(PrfQueryProfileData(
  263.         *pHini,
  264.         SD2_CLASSNAME,
  265.         "IDUS_Hours",
  266.         &pUps->IDUS_Hours,
  267.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  268.     if(PrfQueryProfileData(
  269.         *pHini,
  270.         SD2_CLASSNAME,
  271.         "IDUS_Minutes",
  272.         &pUps->IDUS_Minutes,
  273.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  274.     ulSize=sizeof(ULONG);
  275.     if(PrfQueryProfileData(
  276.         *pHini,
  277.         SD2_CLASSNAME,
  278.         "GRP_Mode",
  279.         &pUps->GRP_Mode,
  280.         &ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  281.     ulSize=sizeof(Ups.IDS_PgmName);
  282.     if(PrfQueryProfileString(
  283.         *pHini,
  284.         SD2_CLASSNAME,
  285.         "IDS_PgmName",
  286.         uc,
  287.         pUps->IDS_PgmName,
  288.         ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  289.     if(PrfQueryProfileString(
  290.         *pHini,
  291.         SD2_CLASSNAME,
  292.         "IDS_PgmDirectory",
  293.         uc,
  294.         pUps->IDS_PgmDirectory,
  295.         ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  296.     if(PrfQueryProfileString(
  297.         *pHini,
  298.         SD2_CLASSNAME,
  299.         "IDS_PgmInputs",
  300.         uc,
  301.         pUps->IDS_PgmInputs,
  302.         ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  303.     ulSize=sizeof(Ups.IDS_UserInfo);
  304.     if(PrfQueryProfileString(
  305.         *pHini,
  306.         SD2_CLASSNAME,
  307.         "IDS_UserInfo",
  308.         uc,
  309.         pUps->IDS_UserInfo,
  310.         ulSize)==FALSE) { *pHini=NULLHANDLE; break; }
  311.     return(PrfCloseProfile(*pHini));    /* Close and return result */
  312.     }
  313. if(*pHini==NULLHANDLE)
  314.     {
  315.                                         /* SHUTDOWN.INI missing logging into logfile */
  316.     DosGetDateTime(&UPS_Current);
  317.     UPS_LogfileIO(LF_INIFILE_MISSING, MPFROMP(&UPS_Current));
  318.     pUps->IDUBC_Hours=0;                /* Assume default values */
  319.     pUps->IDUBC_Minutes=10;
  320.     pUps->IDUAS_Hours=0;
  321.     pUps->IDUAS_Minutes=1;
  322.     pUps->IDUASD_Hours=0;
  323.     pUps->IDUASD_Minutes=4;
  324.     pUps->IDUS_Hours=0;
  325.     pUps->IDUS_Minutes=7;
  326.     pUps->GRP_Mode=IDM_LPT1;
  327.     strcpy(pUps->IDS_PgmName, "CMD.EXE");
  328.     strcpy(pUps->IDS_PgmDirectory, "");
  329.     strcpy(pUps->IDS_PgmInputs, "");
  330.     strcpy(pUps->IDS_UserInfo, "An error occured accessing SHUTDOWN.INI, please correct "\
  331.         "as soon as possible!");
  332.     return(FALSE);
  333.     }
  334. }
  335.  
  336. /*--------------------------------------------------------------------------------------*\
  337.  * Procedure to copy a DATETIME structure to another.                                   *
  338.  * Req:                                                                                 *
  339.  *      pDestination .. A pointer to the destination DATETIME structure                 *
  340.  *      pSource ....... A pointer to the source DATETIME structure                      *
  341.  * Returns:                                                                             *
  342.  *      TRUE/FALSE .... If pDestination>=pSource/pDestination<pSource                   *
  343. \*--------------------------------------------------------------------------------------*/
  344. BOOL    Copy_DateTime(DATETIME *pDestination, DATETIME *pSource)
  345. {
  346. pDestination->seconds=pSource->seconds;
  347. pDestination->minutes=pSource->minutes;
  348. pDestination->hours=pSource->hours;
  349. pDestination->day=pSource->day;
  350. pDestination->month=pSource->month;
  351. pDestination->year=pSource->year;
  352. return(TRUE);
  353. }
  354.  
  355. /*--------------------------------------------------------------------------------------*\
  356.  * Procedure to add hours/minutes to a DATETIME structure.                              *
  357.  * Req:                                                                                 *
  358.  *      pDestination .. A pointer to the destination DATETIME structure                 *
  359.  *      pucHours ...... Hours to add                                                    *
  360.  *      pucMinutes .... Minutes to add
  361.  * Returns:                                                                             *
  362.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  363. \*--------------------------------------------------------------------------------------*/
  364. BOOL    Add_DateTime(DATETIME *pDestination, UCHAR *pucHours, UCHAR *pucMinutes)
  365. {
  366. ULONG   Days_Month[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  367.  
  368. if((pDestination->minutes+=*pucMinutes)>=60)
  369.     {                                   /* Adjust minutes */
  370.     pDestination->minutes-=60;
  371.     pDestination->hours++;
  372.     }
  373. if((pDestination->hours+=*pucHours)>=24)
  374.     {                                   /* Adjust hours */
  375.     pDestination->hours-=24;
  376.     pDestination->day++;
  377.     }
  378.                                         /* Adjust for calendar adjustments */
  379. if((pDestination->year%4==0) && (pDestination->year%100)!=0) Days_Month[1]=29;
  380. if(pDestination->day>Days_Month[(pDestination->month)-1])
  381.     {                                   /* Adjust days, beware of 0-based months */
  382.     pDestination->day-=Days_Month[(pDestination->month)-1];
  383.     pDestination->month++;
  384.     }
  385. if(pDestination->month>12)
  386.     {                                   /* Adjust months */
  387.     pDestination->month-=12;
  388.     pDestination->year++;
  389.     }
  390. return(TRUE);
  391. }
  392.  
  393. /*--------------------------------------------------------------------------------------*\
  394.  * Procedure to compare a DATETIME structure with another DATETIME structure.           *
  395.  * Req:                                                                                 *
  396.  *      pDestination .. A pointer to the destination DATETIME structure                 *
  397.  *      pSource ....... A pointer to the DATETIME structure to compare                  *
  398.  * Returns:                                                                             *
  399.  *      TRUE/FALSE .... If pDestination>=pSource/pDestination<pSource                   *
  400. \*--------------------------------------------------------------------------------------*/
  401. BOOL    Cmp_DateTime(DATETIME *pDestination, DATETIME *pSource)
  402. {
  403. if(pDestination->year>pSource->year) return(TRUE);
  404. if(pDestination->year<pSource->year) return(FALSE);
  405. if(pDestination->month>pSource->month) return(TRUE);
  406. if(pDestination->month<pSource->month) return(FALSE);
  407. if(pDestination->day>pSource->day) return(TRUE);
  408. if(pDestination->day<pSource->day) return(FALSE);
  409. if(pDestination->hours>pSource->hours) return(TRUE);
  410. if(pDestination->hours<pSource->hours) return(FALSE);
  411. if(pDestination->minutes>pSource->minutes) return(TRUE);
  412. if(pDestination->minutes<pSource->minutes) return(FALSE);
  413. if(pDestination->seconds>pSource->seconds) return(TRUE);
  414. if(pDestination->seconds<pSource->seconds) return(FALSE);
  415. return(TRUE);                           /* Both structures are exactly the same */
  416. }
  417.  
  418. /*--------------------------------------------------------------------------------------*\
  419.  * Procedure to calculate the difference between two DATETIME structures in seconds.    *
  420.  * Req:                                                                                 *
  421.  *      pPrevious .. .. A pointer to the destination DATETIME structure                 *
  422.  *      pLater ........ A pointer to the DATETIME structure to compare                  *
  423.  * Returns:                                                                             *
  424.  *      ulDiff ........ Difference in seconds                                           *
  425. \*--------------------------------------------------------------------------------------*/
  426. ULONG   Diff_DateTime(DATETIME *pPrevious, DATETIME *pLater)
  427. {
  428. ULONG   ulPrevious;
  429. ULONG   ulLater;
  430.                                         /* First date/time */
  431. ulPrevious=pPrevious->hours*60*60+pPrevious->minutes*60+pPrevious->seconds;
  432.                                         /* Last date/time */
  433. ulLater=pLater->hours*60*60+pLater->minutes*60+pLater->seconds;
  434.                                         /* On day wrap around add one day */
  435. if(ulLater<ulPrevious) ulLater+=24*60*60;
  436. return(ulLater-ulPrevious);
  437. }
  438.  
  439. /*--------------------------------------------------------------------------------------*\
  440.  * Procedure to display a message box to the user.                                      *
  441.  * Req:                                                                                 *
  442.  *      pucError ...... Pointer to an error string                                      *
  443.  * Returns:                                                                             *
  444.  *      usResponse .... Response of the user (the button pressed)                       *
  445. \*--------------------------------------------------------------------------------------*/
  446. USHORT  User_Error(UCHAR *pucError)
  447. {
  448. return(WinMessageBox(                   /* Display the error on the screen */
  449.     HWND_DESKTOP,                       /* Handle of parent-window */
  450.     HWND_DESKTOP,                       /* Handle of owner-window */
  451.     pucError,                           /* Message-box window message */
  452.                                         /* Message-box window title */
  453.     "SD/2 - ShutDown/2 Error Information",
  454.     ID_SHUTDOWN,                        /* ID passed to HK_HELP and WM_HELP */
  455.                                         /* Message-box window style */
  456.     MB_OK | MB_ICONEXCLAMATION | MB_DEFBUTTON1));
  457. }
  458.  
  459. /*--------------------------------------------------------------------------------------*\
  460.  * Procedure to create/close a secondary thread.                                        *
  461.  * Req:                                                                                 *
  462.  *      bCreate ....... Create/close a thread                                           *
  463.  *      pUPS_Thread ... Pointer to a function implementing the thread                   *
  464.  * Returns:                                                                             *
  465.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  466. \*--------------------------------------------------------------------------------------*/
  467. BOOL    UPS_ThreadCreate(BOOL bCreate, PFNTHREAD pUPS_Thread)
  468. {
  469. static ULONG    ulThreadArg=0;
  470. static ULONG    ulThreadFlag=0;
  471. static ULONG    ulStackSize=8192;
  472. static TID      tidThread;
  473.  
  474. if(bCreate==TRUE)
  475.     {
  476.     DosCreateThread(                    /* Create a secondary thread */
  477.         &tidThread,                     /* Thread ID of created thread */
  478.         pUPS_Thread,                    /* Pointer to thread */
  479.         ulThreadArg,                    /* Thread arguments */
  480.         ulThreadFlag,                   /* Thread flags */
  481.         ulStackSize);                   /* Thread's stack size */
  482.     return(TRUE);
  483.     }
  484. else
  485.     {
  486.     DosKillThread(                      /* Kill the secondary thread */
  487.         tidThread);                     /* Thread ID of thread to be killed */
  488.     return(TRUE);
  489.     }
  490. }
  491.  
  492. /*--------------------------------------------------------------------------------------*\
  493.  * Procedure to write to logfile.                                                       *
  494.  * Req:                                                                                 *
  495.  *      ulMsg ......... Message ID                                                      *
  496.  *      mpParam ....... Pointer to parameter                                            *
  497.  * Ref:                                                                                 *
  498.  *      pucSD2Logfile . Pointer to name of logfile                                      *
  499.  * Returns:                                                                             *
  500.  *      TRUE/FALSE .... If called sucessfully/unsucessfully                             *
  501. \*--------------------------------------------------------------------------------------*/
  502. BOOL    UPS_LogfileIO(ULONG ulMsg, MPARAM mpParam)
  503. {
  504. FILE            *Logfile;
  505. DATETIME        *pDT=PVOIDFROMMP(mpParam);
  506.  
  507. if((Logfile=fopen(pucSD2Logfile, "a"))==NULL)
  508.     return(FALSE);                      /* Error, couldn't open logfile */
  509. switch(ulMsg)
  510. {
  511. case LF_POWERFAILED:
  512.     {                                   /* Line power failed */
  513.     fprintf(Logfile, "*********************************************************************\n");
  514.     fprintf(Logfile, "*** SD/2 detected: Line power failed at:   %4d/%02d/%02d at %02d:%02d:%02d ***\n",
  515.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  516.     fprintf(Logfile, "*********************************************************************\n");
  517.     break;
  518.     }
  519. case LF_POWERRETURNED:
  520.     {                                   /* Line power returned */
  521.     fprintf(Logfile, "*********************************************************************\n");
  522.     fprintf(Logfile, "*** SD/2 detected: Line power returned at: %4d/%02d/%02d at %02d:%02d:%02d ***\n",
  523.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  524.     fprintf(Logfile, "*********************************************************************\n\n");
  525.     break;
  526.     }
  527. case LF_UPS_ALERTSTARTTIME:
  528.     {                                   /* Planned Alert will start at... */
  529.     fprintf(Logfile, "    Planning Alert start at:               %4d/%02d/%02d at %02d:%02d:%02d\n",
  530.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  531.     break;
  532.     }
  533.  
  534. case LF_UPS_ALERTSHUTDOWNTIME:
  535.     {                                   /* Planned user configurable program will be started at...*/
  536.     fprintf(Logfile, "    Planning User-Application start at:    %4d/%02d/%02d at %02d:%02d:%02d\n",
  537.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  538.     break;
  539.     }
  540.  
  541. case LF_UPS_SHUTDOWNTIME:
  542.     {                                   /* Planned OS/2 DosShutdown will be called at...*/
  543.     fprintf(Logfile, "    Planning OS/2 ShutDown at:             %4d/%02d/%02d at %02d:%02d:%02d\n",
  544.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  545.     break;
  546.     }
  547.  
  548. case LF_UPS_ALERTSTART:
  549.     {                                   /* Alert will start at...*/
  550.     fprintf(Logfile, "    Alert started at:                      %4d/%02d/%02d at %02d:%02d:%02d\n",
  551.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  552.     break;
  553.     }
  554. case LF_UPS_ALERTSHUTDOWN:
  555.     {                                   /* The user configurable program will be started at...*/
  556.     fprintf(Logfile, "    User-Application started at:           %4d/%02d/%02d at %02d:%02d:%02d\n",
  557.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  558.     break;
  559.     }
  560. case LF_UPS_SHUTDOWN:
  561.     {                                   /* OS/2 DosShutdown will be called at...*/
  562.     fprintf(Logfile, "    OS/2 ShutDown started at:              %4d/%02d/%02d at %02d:%02d:%02d\n",
  563.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  564.     break;
  565.     }
  566. case LF_INIFILE_MISSING:
  567.     {                                   /* SD/2 profile is missing or defective */
  568.     fprintf(Logfile, "\n+-------------------------------------------------------------------+\n");
  569.     fprintf(Logfile, "| ! SD/2 detected: Profile defective at:   %4d/%02d/%02d at %02d:%02d:%02d ! |\n",
  570.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  571.     fprintf(Logfile, "| ! Creating default SHUTDOWN.INI - please adjust immediately!    ! |\n");
  572.     fprintf(Logfile, "+-------------------------------------------------------------------+\n\n");
  573.     break;
  574.     }
  575. case LF_INIFILE_PROBLEM:
  576.     {                                   /* SD/2 profile can't be accessed */
  577.     fprintf(Logfile, "\n+-------------------------------------------------------------------+\n");
  578.     fprintf(Logfile, "| ! SD/2 detected: Profile defective at:   %4d/%02d/%02d at %02d:%02d:%02d ! |\n",
  579.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  580.     fprintf(Logfile, "| ! Can't access SHUTDOWN.INI - Serious problem, please correct!  ! |\n");
  581.     fprintf(Logfile, "+-------------------------------------------------------------------+\n\n");
  582.     break;
  583.     }
  584. case LF_PARALLEL_INITIALIZED:
  585.     {                                   /* UPS <-> SD/2 interface at parallel port */
  586.     fprintf(Logfile, "\n*********************************************************************\n");
  587.     fprintf(Logfile, "*** Parallel port initialized for UPS <-> SD/2 communication      ***\n");
  588.     fprintf(Logfile, "*** Current System Date & Time is:         %4d/%02d/%02d at %02d:%02d:%02d ***\n",
  589.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  590.     fprintf(Logfile, "*********************************************************************\n\n");
  591.     break;
  592.     }
  593. case LF_SERIAL_INITIALIZED:
  594.     {                                   /* UPS <-> SD/2 interface at serial port */
  595.     fprintf(Logfile, "\n*********************************************************************\n");
  596.     fprintf(Logfile, "*** Serial port initialized for UPS <-> SD/2 communication        ***\n");
  597.     fprintf(Logfile, "*** Current System Date & Time is:         %4d/%02d/%02d at %02d:%02d:%02d ***\n",
  598.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  599.     fprintf(Logfile, "*********************************************************************\n\n");
  600.     break;
  601.     }
  602. case LF_UPS_PASSWORD_USED:
  603.     {                                   /* The program was invoked with the undocumented
  604.                                            commandline option [-|/]IBMSERVICE */
  605.     fprintf(Logfile, "\n+-------------------------------------------------------------------+\n");
  606.     fprintf(Logfile, "| ! SD/2 detected: Service applied at:     %4d/%02d/%02d at %02d:%02d:%02d ! |\n",
  607.         pDT->year, pDT->month, pDT->day, pDT->hours, pDT->minutes, pDT->seconds);
  608.     fprintf(Logfile, "| !                                                               ! |\n");
  609.     fprintf(Logfile, "| ! The configuration service option is used. Please be sure that ! |\n");
  610.     fprintf(Logfile, "| ! all changes of the configuration correspond to their equiva-  ! |\n");
  611.     fprintf(Logfile, "| ! lent settings of the UPS control logic.                       ! |\n");
  612.     fprintf(Logfile, "| ! Warning! SD/2 and the UPS control logic may not operate       ! |\n");
  613.     fprintf(Logfile, "| ! correctly, if this service isn't performed by IBM!            ! |\n");
  614.     fprintf(Logfile, "+-------------------------------------------------------------------+\n\n");
  615.     break;
  616.     }
  617. }
  618. fclose(Logfile);
  619. return(TRUE);
  620. }
  621.  
  622.