home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_6.ZIP / DOSSRC.ZIP / MISC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  2.8 KB  |  127 lines

  1. //    Zinc Interface Library - MISC.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #pragma inline
  6.  
  7. #include "ui_gen.hpp"
  8. #include <dos.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. int _countryCode;
  13. struct ui_country_info near _countryInfo;        // Make "near" to force into DGROUP.
  14.  
  15. struct dos2_country
  16. {
  17.     int date_format;
  18.     char currency[2];
  19.     char thousands[2];
  20.     char decimal[2];
  21.     char reserved[24];
  22. };
  23.  
  24. void ui_getcountryinfo()
  25. {
  26.     static int gotInfo = FALSE;
  27.     static struct dos2_country near dos2_country;
  28.  
  29.     if (!gotInfo)
  30.     {
  31.         gotInfo = TRUE;
  32.         if (_osmajor == 2)
  33.             _DX = (USHORT) &dos2_country;
  34.         else
  35.             _DX = (USHORT) &_countryInfo;
  36.         _AX = 0x3800;
  37.         geninterrupt(0x21);
  38.         _countryCode = (_AL == 0xFF) ? _BX : _AL;
  39.         if (_osmajor == 2)
  40.         {
  41.             memset( &_countryInfo, '\0', sizeof(_countryInfo) );
  42.             _countryInfo.co_date = dos2_country.date_format;
  43.             strcpy(_countryInfo.co_curr, dos2_country.currency);
  44.             strcpy(_countryInfo.co_thsep, dos2_country.thousands);
  45.             strcpy(_countryInfo.co_desep, dos2_country.decimal);
  46.             _countryInfo.co_dtsep[0] = '/';
  47.             _countryInfo.co_tmsep[0] = ':';
  48.             /* Leave co_currstyle set to 0. */
  49.             _countryInfo.co_digits = 2;
  50.             /* Leave co_time set to 0. */
  51.             /* Leave co_case set to 0. */
  52.             _countryInfo.co_dasep[0] = ',';
  53.         }
  54.     }
  55. }
  56.  
  57. int ui_parse_range(char *buffer, int offset, char *minValue, char *maxValue)
  58. {
  59.     // Get the minimum value.
  60.     int position = 0;
  61.     while (buffer[offset] != '\0' &&
  62.         (buffer[offset] != '.' || buffer[offset+1] != '.') &&
  63.         buffer[offset] != '/')
  64.         minValue[position++] = buffer[offset++];
  65.     minValue[position] = '\0';
  66.  
  67.     // See if it is a standalone value.
  68.     if (buffer[offset] == '/' || buffer[offset] == '\0')
  69.     {
  70.         strcpy(maxValue, minValue);
  71.         return(++offset);
  72.     }
  73.  
  74.     // Increment the offset.
  75.     while (buffer[offset] && buffer[offset] == '.')
  76.         offset++;
  77.  
  78.     // Get the maximum value.
  79.     position = 0;
  80.     while (buffer[offset] != '\0' && buffer[offset] != '/')
  81.         maxValue[position++] = buffer[offset++];
  82.     maxValue[position] = '\0';
  83.  
  84.     // Return the offset.
  85.     return(++offset);
  86. }
  87.  
  88. char *ui_strdup(const char *srcString)
  89. {
  90.     // strdup using new instead of malloc.
  91.     if (!srcString || srcString[0] == '\0')
  92.         return (NULL);
  93.     char *destString = new char[strlen(srcString) + 1];
  94.     strcpy(destString, srcString);
  95.     return (destString);
  96. }
  97.  
  98. int ui_strlen(const char *string)
  99. {
  100.     int index = 0;
  101.  
  102.     // strlen that checks for null.
  103.     while (*string)
  104.     {
  105.         index++;
  106.         string++;
  107.     }
  108.     return (index);
  109. }
  110.  
  111. void ui_strrepc(char *str, int c, int repc)
  112. {
  113.     // Replace a character (c) in a string (str) to a new character (repc).
  114.     while (*str)
  115.     {
  116.         if (*str == c)
  117.             *str = repc;
  118.         str++;
  119.     }
  120. }
  121.  
  122. USHORT ui_time()
  123. {
  124.     return(*((USHORT far *)0x46CL));
  125. }
  126.  
  127.