home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / zfamily.zip / zfamily / ZISFUNCS / SAMPLE / TSTFUNCS.C < prev    next >
Text File  |  1993-09-01  |  12KB  |  456 lines

  1. /*
  2. ** /----------------------------------------------------------------------\
  3. ** |             IBM Z Family Reusable Libraries/2 (5641-504)             |
  4. ** |----------------------------------------------------------------------|
  5. ** | (C) Copyright International Business Machines Corporation 1993, 1994 |
  6. ** |----------------------------------------------------------------------|
  7. ** |                       DISCLAIMER OF WARRANTIES                       |
  8. ** |                       ------------------------                       |
  9. ** | The following code is sample code created by IBM Corporation.        |
  10. ** | Such a code is provided to you solely for the purpose of assisting   |
  11. ** | you in the development of your applications. The code is provided    |
  12. ** | "AS IS", without warranty of any kind.  IBM shall not be liable for  |
  13. ** | any damages arising out of your use of the following code, even if   |
  14. ** | they have been advised of the possibility of such damages.           |                                                                         *
  15. ** \----------------------------------------------------------------------/
  16. **
  17. **  Header  : TSTFUNCS.C
  18. **  Authors : Alessandro Cavallini (CAVALLI at ROMEPPC)
  19. **            Pino Venturella (VENTUREL at ROMEPPC)
  20. **  Reviewer: Dario de Judicibus (DEJUDICI at ROMEPPC)
  21. **  Created : 06 Jul 1992
  22. **  Updated : 31 Aug 1993
  23. **  Version : 3.12
  24. **  Content : Utility functions
  25. **
  26. */
  27.  #define INCL_PM
  28.  #define INCL_DOS
  29.  
  30.  #include <os2.h>
  31.  #include <stdio.h>
  32.  #include <stdlib.h>
  33.  #include <string.h>
  34.  
  35.  #include "tstall.h"
  36.  
  37. /* ------------------------------------------------------------------------ */
  38.  
  39. /*
  40. **  Load strings in the specified table
  41. **
  42. **  Input: tblID  : ID of table (Type or Notation)
  43. **         typeID : ID of type selected
  44. **         gbl    : Address of global data
  45. **         tbl    : Address of the table to be filled
  46. */
  47.  void  tstLoadTbl
  48.  (
  49.    USHORT   tblID,
  50.    USHORT   typeID,
  51.    PGLBL    gbl,
  52.    PLIST    tbl
  53.  )
  54.  {
  55.    int i = 0 ;
  56.  
  57.    switch (tblID)
  58.    {
  59.      case TST_TYPE:
  60.      {
  61.       /*
  62.       **  Load strings from resource file
  63.       */
  64.        WinLoadString(*(gbl->data), 0,
  65.                      TST_ID_TYPE_NAT, tbl->dim, tbl->psz) ;
  66.        WinLoadString(*(gbl->data), 0,
  67.                      TST_ID_TYPE_INT, tbl->dim, tbl->psz+tbl->dim) ;
  68.        WinLoadString(*(gbl->data), 0,
  69.                      TST_ID_TYPE_REAL, tbl->dim,tbl->psz+2*tbl->dim) ;
  70.  
  71.       /*
  72.       **  Set to null all the other fields
  73.       */
  74.        for (i = 3; i < 16; i++)
  75.          memset(tbl->psz+i*tbl->dim, 0x00, tbl->dim) ;
  76.      }
  77.      break ;
  78.  
  79.      case TST_NOTATION:
  80.      {
  81.        switch (typeID)
  82.        {
  83.          case TST_ID_TYPE_NAT:
  84.          case TST_ID_TYPE_INT:
  85.          {
  86.            WinLoadString(*(gbl->data), 0,
  87.                          TST_ID_NTN_FLAT, tbl->dim, tbl->psz) ;
  88.            WinLoadString(*(gbl->data), 0,
  89.                          TST_ID_NTN_THS, tbl->dim, tbl->psz+tbl->dim) ;
  90.            WinLoadString(*(gbl->data), 0,
  91.                          TST_ID_NTN_ANY, tbl->dim, tbl->psz+2*tbl->dim) ;
  92.  
  93.         /*
  94.         **  Set to null all the other fields
  95.         */
  96.          for (i = 3; i < 16; i++)
  97.            memset(tbl->psz+i*tbl->dim, 0x00, tbl->dim) ;
  98.          }
  99.          break ;
  100.  
  101.          case TST_ID_TYPE_REAL:
  102.          {
  103.            WinLoadString(*(gbl->data), 0,
  104.                          TST_ID_NTN_FLAT, tbl->dim, tbl->psz) ;
  105.            WinLoadString(*(gbl->data), 0,
  106.                          TST_ID_NTN_THS, tbl->dim, tbl->psz+tbl->dim) ;
  107.            WinLoadString(*(gbl->data), 0,
  108.                          TST_ID_NTN_SCI, tbl->dim, tbl->psz+2*tbl->dim) ;
  109.            WinLoadString(*(gbl->data), 0,
  110.                          TST_ID_NTN_EXP, tbl->dim, tbl->psz+3*tbl->dim) ;
  111.            WinLoadString(*(gbl->data), 0,
  112.                          TST_ID_NTN_ANY, tbl->dim, tbl->psz+4*tbl->dim) ;
  113.  
  114.         /*
  115.         **  Set to null all the other fields
  116.         */
  117.          for (i = 5; i < 16; i++)
  118.            memset(tbl->psz+i*tbl->dim, 0x00, tbl->dim) ;
  119.          }
  120.          break ;
  121.  
  122.          default:
  123.          {
  124.         /*
  125.         **  Set to null all the other fields
  126.         */
  127.          for (i = 0; i < 16; i++)
  128.            memset(tbl->psz+i*tbl->dim, 0x00, tbl->dim) ;
  129.          }
  130.          break ;
  131.        }
  132.      }
  133.      break ;
  134.  
  135.      default:
  136.      {
  137.       /*
  138.       **  Set to null all the other fields
  139.       */
  140.        for (i = 0; i < 16; i++)
  141.          memset(tbl->psz+i*tbl->dim, 0x00, tbl->dim) ;
  142.      }
  143.      break ;
  144.    }
  145.  }
  146.  
  147. /* ------------------------------------------------------------------------ */
  148.  
  149. /*
  150. **  Returns the ID of the selected function
  151. **
  152. **  Input:
  153. **         gbl     : Address of global data
  154. **         type    : Address of the field containing the selected type
  155. **         notation: Address of the field containing the selected notation
  156. **  Output:
  157. **         funcID  : ID of the function corresponding to the selected type
  158. **                   and notation
  159. */
  160.  USHORT tstGetFunctionID
  161.  (
  162.    PGLBL   gbl ,
  163.    PFIELD  type,
  164.    PFIELD  notation
  165.  )
  166.  {
  167.    USHORT funcID ;
  168.    USHORT typeID ;
  169.    USHORT notationID ;
  170.    char   psz[tstMAX_STR_LEN] ;
  171.  
  172.   /*
  173.   ** Get type and notation ID
  174.   */
  175.    typeID = tstGetTypeID (gbl,type) ;
  176.    notationID = tstGetNotationID (gbl,notation) ;
  177.  
  178.   /*
  179.   ** Set function ID according to the selected type and notation ID
  180.   */
  181.    switch (typeID)
  182.    {
  183.      case TST_ID_TYPE_NAT:
  184.      {
  185.        switch (notationID)
  186.        {
  187.          case TST_ID_NTN_FLAT:
  188.               funcID = TST_FLAT_NAT ;
  189.               break ;
  190.  
  191.          case TST_ID_NTN_THS:
  192.               funcID = TST_THS_NAT ;
  193.               break ;
  194.  
  195.          case TST_ID_NTN_ANY:
  196.               funcID = TST_ANY_NAT ;
  197.               break ;
  198.  
  199.          default :
  200.               break ;
  201.        }
  202.      }
  203.      break ;
  204.  
  205.      case TST_ID_TYPE_INT:
  206.      {
  207.        switch (notationID )
  208.        {
  209.          case TST_ID_NTN_FLAT:
  210.               funcID = TST_FLAT_INT ;
  211.               break ;
  212.  
  213.          case TST_ID_NTN_THS:
  214.               funcID = TST_THS_INT ;
  215.               break ;
  216.  
  217.          case TST_ID_NTN_ANY:
  218.               funcID = TST_ANY_INT ;
  219.               break ;
  220.  
  221.          default :
  222.               break ;
  223.        }
  224.      }
  225.      break ;
  226.  
  227.      case TST_ID_TYPE_REAL:
  228.      {
  229.        switch (notationID )
  230.        {
  231.          case TST_ID_NTN_FLAT:
  232.               funcID = TST_FLAT_REAL ;
  233.               break ;
  234.  
  235.          case TST_ID_NTN_THS:
  236.               funcID = TST_THS_REAL ;
  237.               break ;
  238.  
  239.          case TST_ID_NTN_ANY:
  240.               funcID = TST_ANY_REAL ;
  241.               break ;
  242.  
  243.          case TST_ID_NTN_SCI:
  244.               funcID = TST_SCI_REAL ;
  245.               break ;
  246.  
  247.          case TST_ID_NTN_EXP:
  248.               funcID = TST_EXP_REAL ;
  249.               break ;
  250.  
  251.          default :
  252.               break ;
  253.        }
  254.      }
  255.      break ;
  256.  
  257.      default :
  258.           break ;
  259.    }
  260.    return(funcID) ;
  261.  }
  262.  
  263. /* ------------------------------------------------------------------------ */
  264.  
  265. /*
  266. **  Get type ID from an input string
  267. **
  268. **  Input :
  269. **         gbl     : Address of global data
  270. **         type    : Address of the field containing the selected type
  271. **  Output:
  272. **         ID of the selected type, or 0 if doesn't match
  273. */
  274.  USHORT tstGetTypeID
  275.  (
  276.    PGLBL   gbl ,
  277.    PFIELD  type
  278.  )
  279.  {
  280.    char   psz[tstMAX_STR_LEN] ;
  281.  
  282.    WinLoadString(*(gbl->data), 0, TST_ID_TYPE_NAT, tstMAX_STR_LEN, psz) ;
  283.    if (!strcmp(psz,type->psz)) return (TST_ID_TYPE_NAT) ;
  284.  
  285.    WinLoadString(*(gbl->data), 0, TST_ID_TYPE_INT, tstMAX_STR_LEN, psz) ;
  286.    if (!strcmp(psz,type->psz)) return (TST_ID_TYPE_INT) ;
  287.  
  288.    WinLoadString(*(gbl->data), 0, TST_ID_TYPE_REAL, tstMAX_STR_LEN, psz) ;
  289.    if (!strcmp(psz,type->psz)) return (TST_ID_TYPE_REAL) ;
  290.  
  291.    return (0) ;
  292.  }
  293.  
  294. /* ------------------------------------------------------------------------ */
  295.  
  296. /*
  297. **  Get notation ID from an input string
  298. **
  299. **  Input :
  300. **         gbl     : Address of global data
  301. **         notation: Address of the field containing the selected notation
  302. **  Output:
  303. **         ID of the selected notation, or 0 if doesn't match
  304. */
  305.  USHORT tstGetNotationID
  306.  (
  307.    PGLBL   gbl ,
  308.    PFIELD  notation
  309.  )
  310.  {
  311.    char   psz[tstMAX_STR_LEN] ;
  312.  
  313.    WinLoadString(*(gbl->data), 0, TST_ID_NTN_FLAT, tstMAX_STR_LEN, psz) ;
  314.    if (!strcmp(psz,notation->psz)) return (TST_ID_NTN_FLAT) ;
  315.  
  316.    WinLoadString(*(gbl->data), 0, TST_ID_NTN_THS, tstMAX_STR_LEN, psz) ;
  317.    if (!strcmp(psz,notation->psz)) return (TST_ID_NTN_THS) ;
  318.  
  319.    WinLoadString(*(gbl->data), 0, TST_ID_NTN_ANY, tstMAX_STR_LEN, psz) ;
  320.    if (!strcmp(psz,notation->psz)) return (TST_ID_NTN_ANY) ;
  321.  
  322.    WinLoadString(*(gbl->data), 0, TST_ID_NTN_EXP, tstMAX_STR_LEN, psz) ;
  323.    if (!strcmp(psz,notation->psz)) return (TST_ID_NTN_EXP) ;
  324.  
  325.    WinLoadString(*(gbl->data), 0, TST_ID_NTN_SCI, tstMAX_STR_LEN, psz) ;
  326.    if (!strcmp(psz,notation->psz)) return (TST_ID_NTN_SCI) ;
  327.  
  328.    return (0) ;
  329.  }
  330.  
  331. /* ------------------------------------------------------------------------ */
  332.  
  333. /*
  334. **  Build and Display sample for any selected function
  335. **
  336. **  Input:
  337. **        funcID : ID of the function
  338. **        fld    : Address of the entry field to be filled with the sample
  339. */
  340. void tstDisplSample
  341. (
  342.   USHORT  funcID ,
  343.   PFIELD  fld
  344. )
  345. {
  346.   COUNTRYCODE  CtryCode ;  // Country
  347.   COUNTRYINFO  CtryInfo ;  // Country Information
  348.   ULONG        ulLen    ;
  349.   APIRET       apirc ;     // Return code from DosQueryCtryInfo
  350.   char         thsSep[2] ; // thousand separator
  351.   char         decSep[2] ; // decimal separator
  352.   char         tmp[tstMAX_STR_LEN] ;  // temporary string
  353.  
  354.  /*
  355.  **  Get country information from COUNTRY.SYS file
  356.  */
  357.   CtryCode.country = 0 ;
  358.   CtryCode.codepage = 0 ;
  359.  
  360.   apirc = DosQueryCtryInfo(sizeof(COUNTRYINFO), &(CtryCode), &(CtryInfo), &ulLen) ;
  361.   strcpy(thsSep, CtryInfo.szThousandsSeparator) ;
  362.   strcpy(decSep, CtryInfo.szDecimal) ;
  363.  
  364.  /*
  365.  **  Create sample according to function id
  366.  */
  367.   switch (funcID)
  368.   {
  369.     case TST_FLAT_NAT:
  370.          strcpy(tmp,"+123456789") ;
  371.          break ;
  372.  
  373.     case TST_THS_NAT:
  374.          strcpy(tmp,"+123") ;
  375.          strcat(tmp,thsSep) ;
  376.          strcat(tmp,"456") ;
  377.          strcat(tmp,thsSep) ;
  378.          strcat(tmp,"789") ;
  379.          break ;
  380.  
  381.     case TST_ANY_NAT:
  382.          strcpy(tmp,"+1234 or +1") ;
  383.          strcat(tmp,thsSep) ;
  384.          strcat(tmp,"234") ;
  385.          break ;
  386.  
  387.     case TST_FLAT_INT:
  388.          strcpy(tmp,"-123456789") ;
  389.          break ;
  390.  
  391.     case TST_THS_INT:
  392.          strcpy(tmp,"-123") ;
  393.          strcat(tmp,thsSep) ;
  394.          strcat(tmp,"456") ;
  395.          strcat(tmp,thsSep) ;
  396.          strcat(tmp,"789") ;
  397.          break ;
  398.  
  399.     case TST_ANY_INT:
  400.          strcpy(tmp,"-1234 or +1") ;
  401.          strcat(tmp,thsSep) ;
  402.          strcat(tmp,"234") ;
  403.          break ;
  404.  
  405.     case TST_FLAT_REAL:
  406.         strcpy(tmp,"-1234") ;
  407.         strcat(tmp,decSep) ;
  408.         strcat(tmp,"4567") ;
  409.         break ;
  410.  
  411.     case TST_THS_REAL:
  412.          strcpy(tmp,"-1") ;
  413.          strcat(tmp,thsSep) ;
  414.          strcat(tmp,"234") ;
  415.          strcat(tmp,decSep) ;
  416.          strcat(tmp,"456") ;
  417.          strcat(tmp,thsSep) ;
  418.          strcat(tmp,"7") ;
  419.          break ;
  420.  
  421.     case TST_SCI_REAL:
  422.          strcpy(tmp,"-0") ;
  423.          strcat(tmp,decSep) ;
  424.          strcat(tmp,"123E+32") ;
  425.          break ;
  426.  
  427.     case TST_EXP_REAL:
  428.          strcpy(tmp,"-1234") ;
  429.          strcat(tmp,decSep) ;
  430.          strcat(tmp,"567E+32") ;
  431.          break ;
  432.  
  433.     case TST_ANY_REAL:
  434.          strcpy(tmp,"1") ;
  435.          strcat(tmp,decSep) ;
  436.          strcat(tmp,"2 or 1") ;
  437.          strcat(tmp,thsSep) ;
  438.          strcat(tmp,"234") ;
  439.          strcat(tmp,decSep) ;
  440.          strcat(tmp,"5 or 0") ;
  441.          strcat(tmp,decSep) ;
  442.          strcat(tmp,"1e2 or 1") ;
  443.          strcat(tmp,decSep) ;
  444.          strcat(tmp,"2E3") ;
  445.          break ;
  446.  
  447.     default :
  448.          break ;
  449.   }
  450.  
  451.   strncpy (fld->psz, tmp, fld->dim)  ;
  452. }
  453.  
  454. /* ------------------------------------------------------------------------ */
  455.  
  456.