home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cidsam.zip / CIDLOG.C < prev    next >
C/C++ Source or Header  |  1993-06-28  |  5KB  |  115 lines

  1.                   /*********************************/
  2.                   /*              NOTE             */
  3.                   /*                               */
  4.                   /* This sample code has been     */
  5.                   /* provided by IBM.  It is not   */
  6.                   /* warranted for any particular  */
  7.                   /* use or purpose.               */
  8.                   /*                               */
  9.                   /* IBM releases this code into   */
  10.                   /* the public domain.  You may   */
  11.                   /* use it, modify it, or         */
  12.                   /* incorporate it into other     */
  13.                   /* products without restriction. */
  14.                   /*********************************/
  15.  
  16.  /*********************************************************************/
  17.  /*                                                                   */
  18.  /* MODULE  NAME:    cidlog.c                                         */
  19.  /*                                                                   */
  20.  /* DESCRIPTIVE NAME: Contains routine CID_log()                      */
  21.  /*                                                                   */
  22.  /* LINKAGE:   This is a linkable subroutine. It requires no other    */
  23.  /*            linkages.                                              */
  24.  /*                                                                   */
  25.  /*********************************************************************/
  26. #pragma page (1)
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <stdarg.h>
  31. #define INCL_BASE
  32. #include <os2.h>
  33. #include "cidlog.h"
  34. /****************************************************************************/
  35. /*                             C I D _ L o g                                */
  36. /*                                                                          */
  37. /*  Calling sequence                                                        */
  38. /*                                                                          */
  39. /*      void CID_Log(int msgno, ...);    // function prototype              */
  40. /*                                                                          */
  41. /*      CID_Log(12, "first arg", "second arg", "third arg");                */
  42. /*                                                                          */
  43. /*  The arguments (other than the message number) passed to this        @C1a*/
  44. /*  routine must all be character pointers.                             @C1a*/
  45. /****************************************************************************/
  46.  
  47. void CID_Log(UINT uiMsgno, ...)
  48. {
  49.      va_list marker;
  50.      PCHAR apszArglist[10];                                          /*@C1c*/
  51.      int   rc;
  52. #ifdef I16                                                           /*@A1a*/
  53.      USHORT i, msglen;
  54. #else                                                                /*@A1a*/ 
  55.      ULONG  i, msglen;                                               /*@A1a*/ 
  56. #endif                                                               /*@A1a*/ 
  57.      char szMsgarea[256];
  58.      char logmsgfile[CCHMAXPATH];
  59.      char logfilename[CCHMAXPATH];
  60.      char *p;
  61.      FILE *f;
  62.  
  63.  
  64.      va_start(marker, uiMsgno);
  65.      f = (FILE *)NULL;
  66.      for (i = 0; i < 10; apszArglist[i++] = NULL);  /* initialize array */
  67.      for (i = 0; i < 10; i++)
  68.         {
  69.           apszArglist[i] = va_arg(marker, char *);
  70.           if (apszArglist[i] == NULL)
  71.             break;
  72.         }
  73.      if (i >= 10)
  74.        i = 9;
  75.  
  76.      if ( (p = getenv(LOGMSGFILEEVAR)) == NULL)
  77.        strcpy(logmsgfile, DEFAULTLOGMSGFILE);
  78.      else
  79.        strcpy(logmsgfile, p);
  80.  
  81.      if ( (p = getenv(LOGFILEEVAR)) == NULL)
  82.        *logfilename = '\0';
  83.      else
  84.        strcpy(logfilename, p);
  85.  
  86.      if (*logfilename)
  87.        f = fopen(logfilename, "a+");
  88.  
  89.      msglen = 255;
  90.      rc = DosGetMessage(apszArglist, i, (PCHAR)szMsgarea, 255,     /*@C1c*/
  91.                         uiMsgno, logmsgfile, &msglen);             /*@C1c*/
  92.      if (rc == NO_ERROR)
  93.        {                                                           /*@C1a*/
  94.          *(szMsgarea+msglen) = '\0';                               /*@C1c*/
  95.          if (f)
  96.            fprintf(f, "%s\n", szMsgarea);
  97.          else
  98.            printf("%s\n", szMsgarea);
  99.        }                                                           /*@C1a*/
  100.      else
  101.        if (rc == ERROR_MR_UN_ACC_MSGF)
  102.          if (f)
  103.              fprintf(f, "Message file %s not found\n", logmsgfile);
  104.          else
  105.              printf("Message file %s not found\n", logmsgfile);
  106.        else
  107.          if (f)
  108.            fprintf(f, "DosGetMessage failed.  rc = %d\n", rc);
  109.          else
  110.            printf("DosGetMessage failed.  rc = %d\n", rc);
  111.  
  112.      if (f)
  113.        fclose(f);
  114. }
  115.