From c2c6620948cfddc6baf24bbf4cf50176fcdcfd9a Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Thu, 6 May 1999 05:33:48 +0000 Subject: [PATCH] Changed __SETCENTURY to HB_SETCENTURY Changed all internal _SET_xxx to HB_SET_xxx Changed HB_SETCENTURY to modify the HB_SET_DATEFORMAT Changed the name of the set initialization function to InitializeSets Rewrote hb_dtoc to use hb_set_century and to be Clipper compliant Added dates2.prg to test century compliance with Clipper --- harbour/include/set.h | 164 ++++++------- harbour/source/rtl/dates.c | 253 +++++++++---------- harbour/source/rtl/set.c | 408 +++++++++++++++++-------------- harbour/source/vm/hvm.c | 2 +- harbour/tests/working/dates.prg | 22 +- harbour/tests/working/dates2.prg | 36 +++ 6 files changed, 472 insertions(+), 413 deletions(-) create mode 100644 harbour/tests/working/dates2.prg diff --git a/harbour/include/set.h b/harbour/include/set.h index d8cd8f4fac..cefcbc12b9 100644 --- a/harbour/include/set.h +++ b/harbour/include/set.h @@ -8,8 +8,8 @@ #include HARBOUR SET (void); -HARBOUR __SETCENTURY (void); -void HB_init_set (void); +HARBOUR HB_SETCENTURY (void); +void InitializeSets (void); void ReleaseSets (void); typedef enum @@ -34,91 +34,91 @@ typedef enum typedef enum { - _SET_ALTERNATE = 1, - _SET_ALTFILE = 2, - _SET_BELL = 3, - _SET_CANCEL = 4, - _SET_COLOR = 5, - _SET_CONFIRM = 6, - _SET_CONSOLE = 7, - _SET_CURSOR = 8, - _SET_DATEFORMAT = 9, - _SET_DEBUG = 10, - _SET_DECIMALS = 11, - _SET_DEFAULT = 12, - _SET_DELETED = 13, - _SET_DELIMCHARS = 14, - _SET_DELIMITERS = 15, - _SET_DEVICE = 16, - _SET_EPOCH = 17, - _SET_ESCAPE = 18, - _SET_EVENTMASK = 19, - _SET_EXACT = 20, - _SET_EXCLUSIVE = 21, - _SET_EXIT = 22, - _SET_EXTRA = 23, - _SET_EXTRAFILE = 24, - _SET_FIXED = 25, - _SET_INSERT = 26, - _SET_INTENSITY = 27, - _SET_MARGIN = 28, - _SET_MCENTER = 29, - _SET_MESSAGE = 30, - _SET_PATH = 31, - _SET_PRINTER = 32, - _SET_PRINTFILE = 33, - _SET_SCOREBOARD = 34, - _SET_SCROLLBREAK = 35, - _SET_SOFTSEEK = 36, - _SET_TYPEAHEAD = 37, - _SET_UNIQUE = 38, - _SET_WRAP = 39 + HB_SET_ALTERNATE = 1, + HB_SET_ALTFILE = 2, + HB_SET_BELL = 3, + HB_SET_CANCEL = 4, + HB_SET_COLOR = 5, + HB_SET_CONFIRM = 6, + HB_SET_CONSOLE = 7, + HB_SET_CURSOR = 8, + HB_SET_DATEFORMAT = 9, + HB_SET_DEBUG = 10, + HB_SET_DECIMALS = 11, + HB_SET_DEFAULT = 12, + HB_SET_DELETED = 13, + HB_SET_DELIMCHARS = 14, + HB_SET_DELIMITERS = 15, + HB_SET_DEVICE = 16, + HB_SET_EPOCH = 17, + HB_SET_ESCAPE = 18, + HB_SET_EVENTMASK = 19, + HB_SET_EXACT = 20, + HB_SET_EXCLUSIVE = 21, + HB_SET_EXIT = 22, + HB_SET_EXTRA = 23, + HB_SET_EXTRAFILE = 24, + HB_SET_FIXED = 25, + HB_SET_INSERT = 26, + HB_SET_INTENSITY = 27, + HB_SET_MARGIN = 28, + HB_SET_MCENTER = 29, + HB_SET_MESSAGE = 30, + HB_SET_PATH = 31, + HB_SET_PRINTER = 32, + HB_SET_PRINTFILE = 33, + HB_SET_SCOREBOARD = 34, + HB_SET_SCROLLBREAK = 35, + HB_SET_SOFTSEEK = 36, + HB_SET_TYPEAHEAD = 37, + HB_SET_UNIQUE = 38, + HB_SET_WRAP = 39 } HB_set_enum; typedef struct { - BOOL _SET_ALTERNATE; /* Logical */ - char *_SET_ALTFILE; /* Character */ - BOOL _SET_BELL; /* Logical */ - BOOL _SET_CANCEL; /* Logical */ - char *_SET_COLOR; /* Character */ - BOOL _SET_CONFIRM; /* Logical */ - BOOL _SET_CONSOLE; /* Logical */ - HB_cursor_enum _SET_CURSOR; /* Numeric */ - char *_SET_DATEFORMAT; /* Character */ - BOOL _SET_DEBUG; /* Logical */ - int _SET_DECIMALS; /* Numeric */ - char *_SET_DEFAULT; /* Character */ - BOOL _SET_DELETED; /* Logical */ - char *_SET_DELIMCHARS; /* Character */ - BOOL _SET_DELIMITERS; /* Logical */ - char * _SET_DEVICE; /* Character */ - int _SET_EPOCH; /* Numeric */ - BOOL _SET_ESCAPE; /* Logical */ - HB_inkey_enum _SET_EVENTMASK; /* Numeric */ - BOOL _SET_EXACT; /* Logical */ - BOOL _SET_EXCLUSIVE; /* Logical */ - BOOL _SET_EXIT; /* Logical */ - BOOL _SET_EXTRA; /* Logical */ /* QUESTION: What does this do? */ - char *_SET_EXTRAFILE; /* Character */ /* QUESTION: What does this do? */ - BOOL _SET_FIXED; /* Logical */ - BOOL _SET_INSERT; /* Logical */ - BOOL _SET_INTENSITY; /* Logical */ - int _SET_MARGIN; /* Numeric */ - BOOL _SET_MCENTER; /* Logical */ - int _SET_MESSAGE; /* Numeric */ - char *_SET_PATH; /* Character */ - BOOL _SET_PRINTER; /* Logical */ - char *_SET_PRINTFILE; /* Character */ - BOOL _SET_SCOREBOARD; /* Logcial */ - int _SET_SCROLLBREAK; /* Logical */ /* QUESTION: What does this do? */ - BOOL _SET_SOFTSEEK; /* Logical */ - int _SET_TYPEAHEAD; /* Numeric */ - BOOL _SET_UNIQUE; /* Logical */ - BOOL _SET_WRAP; /* Logical */ + BOOL HB_SET_ALTERNATE; /* Logical */ + char *HB_SET_ALTFILE; /* Character */ + BOOL HB_SET_BELL; /* Logical */ + BOOL HB_SET_CANCEL; /* Logical */ + char *HB_SET_COLOR; /* Character */ + BOOL HB_SET_CONFIRM; /* Logical */ + BOOL HB_SET_CONSOLE; /* Logical */ + HB_cursor_enum HB_SET_CURSOR; /* Numeric */ + char *HB_SET_DATEFORMAT; /* Character */ + BOOL HB_SET_DEBUG; /* Logical */ + int HB_SET_DECIMALS; /* Numeric */ + char *HB_SET_DEFAULT; /* Character */ + BOOL HB_SET_DELETED; /* Logical */ + char *HB_SET_DELIMCHARS; /* Character */ + BOOL HB_SET_DELIMITERS; /* Logical */ + char * HB_SET_DEVICE; /* Character */ + int HB_SET_EPOCH; /* Numeric */ + BOOL HB_SET_ESCAPE; /* Logical */ + HB_inkey_enum HB_SET_EVENTMASK; /* Numeric */ + BOOL HB_SET_EXACT; /* Logical */ + BOOL HB_SET_EXCLUSIVE; /* Logical */ + BOOL HB_SET_EXIT; /* Logical */ + BOOL HB_SET_EXTRA; /* Logical */ /* QUESTION: What does this do? */ + char *HB_SET_EXTRAFILE; /* Character */ /* QUESTION: What does this do? */ + BOOL HB_SET_FIXED; /* Logical */ + BOOL HB_SET_INSERT; /* Logical */ + BOOL HB_SET_INTENSITY; /* Logical */ + int HB_SET_MARGIN; /* Numeric */ + BOOL HB_SET_MCENTER; /* Logical */ + int HB_SET_MESSAGE; /* Numeric */ + char *HB_SET_PATH; /* Character */ + BOOL HB_SET_PRINTER; /* Logical */ + char *HB_SET_PRINTFILE; /* Character */ + BOOL HB_SET_SCOREBOARD; /* Logcial */ + int HB_SET_SCROLLBREAK; /* Logical */ /* QUESTION: What does this do? */ + BOOL HB_SET_SOFTSEEK; /* Logical */ + int HB_SET_TYPEAHEAD; /* Numeric */ + BOOL HB_SET_UNIQUE; /* Logical */ + BOOL HB_SET_WRAP; /* Logical */ } HB_set_struct; -extern HB_set_struct HB_set; -extern BOOL HB_set_century; +extern HB_set_struct hb_set; +extern BOOL hb_set_century; #endif diff --git a/harbour/source/rtl/dates.c b/harbour/source/rtl/dates.c index 334ab20e7e..46f5f84ad8 100644 --- a/harbour/source/rtl/dates.c +++ b/harbour/source/rtl/dates.c @@ -38,12 +38,12 @@ HARBOUR CTOD( void ) char * szDate = _parc( 1 ); int d_value = 0, m_value = 0, y_value = 0; int d_pos = 0, m_pos = 0, y_pos = 0; - int count, digit; + int count, digit, size = strlen (hb_set.HB_SET_DATEFORMAT); char szDateFormat[ 9 ]; - for( count = 0; count < strlen (HB_set._SET_DATEFORMAT); count++) + for( count = 0; count < size; count++) { - switch (HB_set._SET_DATEFORMAT [count]) + switch (hb_set.HB_SET_DATEFORMAT [count]) { case 'D': case 'd': @@ -73,7 +73,8 @@ HARBOUR CTOD( void ) } } } - for( count = 0; count < strlen (szDate); count++) + size = strlen (szDate); + for( count = 0; count < size; count++) { digit = szDate [count]; if (isdigit (digit)) @@ -100,8 +101,8 @@ HARBOUR CTOD( void ) } if (y_value < 100) { - count = HB_set._SET_EPOCH % 100; - digit = HB_set._SET_EPOCH / 100; + count = hb_set.HB_SET_EPOCH % 100; + digit = hb_set.HB_SET_EPOCH / 100; if (y_value >= count) y_value += (digit * 100); else y_value += ((digit * 100) + 100); } @@ -111,159 +112,131 @@ HARBOUR CTOD( void ) char * hb_dtoc (char * szDate, char * szDateFormat) { - /* NOTE: szDateFormat must point to a buffer of at least 11 bytes */ - int d_digits = 0, m_digits = 0, y_digits = 0; - int d_pos = 0, m_pos = 0, y_pos = 0; - int add_sep, count, digit, delim_1, delim_2, delim_count; - char szTemp [5]; + /* + * NOTE: szDateFormat must point to a buffer of at least 11 bytes + */ + int digit, digit_count, format_count, size; + BOOL used_d, used_m, used_y; + char *szPtr; - delim_count = 0; - delim_1 = delim_2 = '.'; - for( count = 0; count < strlen (HB_set._SET_DATEFORMAT); count++) + /* + * Determine the maximum size of the formatted date string + */ + size = min (10, strlen (hb_set.HB_SET_DATEFORMAT)); + + format_count = 0; + used_d = used_m = used_y = FALSE; + szPtr = hb_set.HB_SET_DATEFORMAT; + while (format_count < size) { - digit = HB_set._SET_DATEFORMAT [count]; + digit = toupper (*szPtr); + szPtr++; + digit_count = 1; + while (toupper (*szPtr) == digit && format_count < size) + { + szPtr++; + if (format_count + digit_count < size) digit_count++; + } switch (digit) { case 'D': - case 'd': - d_digits++; - if (d_pos == 0) + switch (digit_count) { - if (m_pos == 0 && y_pos == 0) d_pos = 1; - else if (m_pos == 0 || y_pos == 0) d_pos = 2; - else d_pos = 3; + case 4: + if (!used_d && format_count < size) + { + szDateFormat [format_count++] = '0'; + digit_count--; + } + case 3: + if (!used_d && format_count < size) + { + szDateFormat [format_count++] = '0'; + digit_count--; + } + case 2: + if (!used_d && format_count < size) + { + szDateFormat [format_count++] = szDate [6]; + digit_count--; + } + default: + if (!used_d && format_count < size) + { + szDateFormat [format_count++] = szDate [7]; + digit_count--; + } + while (digit_count-- > 0 && format_count < size) szDateFormat [format_count++] = digit; } + used_d = TRUE; break; case 'M': - case 'm': - m_digits++; - if (m_pos == 0) + switch (digit_count) { - if (d_pos == 0 && y_pos == 0) m_pos = 1; - else if (d_pos == 0 || y_pos == 0) m_pos = 2; - else m_pos = 3; + case 4: + if (!used_m && format_count < size) + { + szDateFormat [format_count++] = '0'; + digit_count--; + } + case 3: + if (!used_m && format_count < size) + { + szDateFormat [format_count++] = '0'; + digit_count--; + } + case 2: + if (!used_m && format_count < size) + { + szDateFormat [format_count++] = szDate [4]; + digit_count--; + } + default: + if (!used_m && format_count < size) + { + szDateFormat [format_count++] = szDate [5]; + digit_count--; + } + while (digit_count-- > 0 && format_count < size) szDateFormat [format_count++] = digit; } + used_m = TRUE; break; case 'Y': - case 'y': - y_digits++; - if (y_pos == 0) + switch (digit_count) { - if (m_pos == 0 && d_pos == 0) y_pos = 1; - else if (m_pos == 0 || d_pos == 0) y_pos = 2; - else y_pos = 3; + case 4: + if (!used_y && format_count < size) + { + szDateFormat [format_count++] = szDate [0]; + digit_count--; + } + case 3: + if (!used_y && format_count < size) + { + szDateFormat [format_count++] = szDate [1]; + digit_count--; + } + case 2: + if (!used_y && format_count < size) + { + szDateFormat [format_count++] = szDate [2]; + digit_count--; + } + default: + if (!used_y && format_count < size) + { + szDateFormat [format_count++] = szDate [3]; + digit_count--; + } + while (digit_count-- > 0 && format_count < size) szDateFormat [format_count++] = digit; } + used_y = TRUE; break; default: - delim_count++; - if (delim_count == 1) delim_1 = digit; - else if (delim_count == 2) delim_2 = digit; - break; + while (digit_count-- > 0 && format_count < size) szDateFormat [format_count++] = digit; } } - *szDateFormat = 0; - for (count = 0; count < 3; count++) - { - /* Insert a converted date element. */ - add_sep = 0; - if (d_pos == 1 && d_digits > 0) - { - add_sep = 1; - while (d_digits > 2) - { - strcat (szDateFormat, "0"); - d_digits--; - } - if (d_digits == 1) - { - szTemp [0] = szDate [7]; - szTemp [1] = 0; - } - else - { - szTemp [0] = szDate [6]; - szTemp [1] = szDate [7]; - szTemp [2] = 0; - } - strcat (szDateFormat, szTemp); - } - if (m_pos == 1 && m_digits > 0) - { - add_sep = 1; - while (m_digits > 2) - { - strcat (szDateFormat, "0"); - m_digits--; - } - if (m_digits == 1) - { - szTemp [0] = szDate [5]; - szTemp [1] = 0; - } - else - { - szTemp [0] = szDate [4]; - szTemp [1] = szDate [5]; - szTemp [2] = 0; - } - strcat (szDateFormat, szTemp); - } - if (y_pos == 1 && y_digits > 0) - { - add_sep = 1; - while (y_digits > 4) - { - strcat (szDateFormat, "0"); - y_digits--; - } - if (y_digits == 1) - { - szTemp [0] = szDate [3]; - szTemp [1] = 0; - } - else if (y_digits == 2) - { - szTemp [0] = szDate [2]; - szTemp [1] = szDate [3]; - szTemp [2] = 0; - } - else if (y_digits == 3) - { - szTemp [0] = szDate [1]; - szTemp [1] = szDate [2]; - szTemp [2] = szDate [3]; - szTemp [3] = 0; - } - else - { - szTemp [0] = szDate [0]; - szTemp [1] = szDate [1]; - szTemp [2] = szDate [2]; - szTemp [3] = szDate [3]; - szTemp [4] = 0; - } - strcat (szDateFormat, szTemp); - } - /* Insert a date field separator. */ - if (add_sep && delim_1) - { - szTemp [0] = delim_1; - szTemp [1] = 0; - strcat (szDateFormat, szTemp); - delim_1 = 0; - } - else if (add_sep && delim_2) - { - szTemp [0] = delim_2; - szTemp [1] = 0; - strcat (szDateFormat, szTemp); - delim_2 = 0; - } - /* Get ready for the next date element. */ - d_pos--; - m_pos--; - y_pos--; - } + szDateFormat [format_count] = 0; return (szDateFormat); } diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index 5a18e90e70..cc289d7f80 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -6,8 +6,8 @@ #include #include -HB_set_struct HB_set; -BOOL HB_set_century; +HB_set_struct hb_set; +BOOL hb_set_century; static BOOL set_logical (PITEM pItem) { @@ -27,13 +27,12 @@ static int set_number (PITEM pItem, int old_value) return (number); } -static char * set_string (PITEM pItem, char * old_str, int size_limit) +static char * set_string (PITEM pItem, char * old_str) { char * string; if (IS_STRING (pItem)) { int size = pItem->wLength; - if (size_limit > 0 && size > size_limit) size = size_limit; if (old_str) string = _xrealloc (old_str, size + 1); else string = _xgrab (size + 1); memcpy (string, pItem->value.szText, size); @@ -43,20 +42,71 @@ static char * set_string (PITEM pItem, char * old_str, int size_limit) return (string); } -HARBOUR __SETCENTURY (void) +HARBOUR HB_SETCENTURY (void) { + int digit, count, size, y_size, y_start, y_stop; + int old_century_setting = hb_set_century; + BOOL year; PITEM pItem = _param (1, IT_ANY); + char *szDateFormat, *szNewFormat; - _retl (HB_set_century); - if (IS_LOGICAL (pItem)) HB_set_century = pItem->value.iLogical; + /* Start by returning the current setting */ + _retl (hb_set_century); + /* + * Then change the setting if the parameter is a logical value, or is + * either "ON" or "OFF" (regardless of case) + */ + if (IS_LOGICAL (pItem)) hb_set_century = pItem->value.iLogical; else if (IS_STRING (pItem)) { if (pItem->wLength == 2 && toupper (pItem->value.szText [0]) == 'O' && toupper (pItem->value.szText [1]) == 'N') - HB_set_century = TRUE; + hb_set_century = TRUE; else if (pItem->wLength == 3 && toupper (pItem->value.szText [0]) == 'O' && toupper (pItem->value.szText [1]) == 'F' && toupper (pItem->value.szText [2]) == 'F') - HB_set_century = FALSE; + hb_set_century = FALSE; + } + /* + * Finally, if the setting changed, adjust the current date format to use + * the correct number of year digits. + */ + if (old_century_setting != hb_set_century) + { + /* Convert to upper case and determine where year is */ + y_start = y_stop = -1; + szDateFormat = hb_set.HB_SET_DATEFORMAT; + size = strlen (szDateFormat); + for (count = 0; count < size; count++) + { + digit = toupper (szDateFormat [count]); + if (digit == 'Y') + { + if (y_start == -1) y_start = count; + } + else if (y_start > -1 && y_stop == -1) y_stop = count; + szDateFormat [count] = digit; + } + /* Determine size of year in current format */ + if (y_start < 0) + { + y_start = 0; /* There is no year in the current format */ + y_stop = 0; + } + else if (y_stop < 0) y_stop = size + 1; /* All digits are year digits */ + y_size = y_stop - y_start; + /* Calculate size of new format */ + size -= y_size; + if (hb_set_century) size += 4; + else size += 2; + /* Create the new date format */ + szNewFormat = _xgrab (size + 1); + if (y_start > 0) memcpy (szNewFormat, szDateFormat, y_start); + szNewFormat [y_start] = 0; + strcat (szNewFormat, "YY"); + if (hb_set_century) strcat (szNewFormat, "YY"); + strcat (szNewFormat, szDateFormat + y_stop); + _xfree (szDateFormat); + hb_set.HB_SET_DATEFORMAT = szNewFormat; } } @@ -70,230 +120,230 @@ HARBOUR SET (void) switch (set_specifier) { - case _SET_ALTERNATE : - _retl (HB_set._SET_ALTERNATE); - if (args > 1) HB_set._SET_ALTERNATE = set_logical (pArg2); + case HB_SET_ALTERNATE : + _retl (hb_set.HB_SET_ALTERNATE); + if (args > 1) hb_set.HB_SET_ALTERNATE = set_logical (pArg2); break; - case _SET_ALTFILE : - if (HB_set._SET_ALTFILE) _retc (HB_set._SET_ALTFILE); + case HB_SET_ALTFILE : + if (hb_set.HB_SET_ALTFILE) _retc (hb_set.HB_SET_ALTFILE); else _retc (""); - if (args > 1) HB_set._SET_ALTFILE = set_string (pArg2, HB_set._SET_ALTFILE, 0); + if (args > 1) hb_set.HB_SET_ALTFILE = set_string (pArg2, hb_set.HB_SET_ALTFILE); break; - case _SET_BELL : - _retl (HB_set._SET_BELL); - if (args > 1) HB_set._SET_BELL = set_logical (pArg2); + case HB_SET_BELL : + _retl (hb_set.HB_SET_BELL); + if (args > 1) hb_set.HB_SET_BELL = set_logical (pArg2); break; - case _SET_CANCEL : - _retl (HB_set._SET_CANCEL); - if (args > 1) HB_set._SET_CANCEL = set_logical (pArg2); + case HB_SET_CANCEL : + _retl (hb_set.HB_SET_CANCEL); + if (args > 1) hb_set.HB_SET_CANCEL = set_logical (pArg2); break; - case _SET_COLOR : - if (HB_set._SET_COLOR) _retc (HB_set._SET_COLOR); + case HB_SET_COLOR : + if (hb_set.HB_SET_COLOR) _retc (hb_set.HB_SET_COLOR); else _retc (""); - if (args > 1) HB_set._SET_COLOR = set_string (pArg2, HB_set._SET_COLOR, 0); + if (args > 1) hb_set.HB_SET_COLOR = set_string (pArg2, hb_set.HB_SET_COLOR); break; - case _SET_CONFIRM : - _retl (HB_set._SET_CONFIRM); - if (args > 1) HB_set._SET_CONFIRM = set_logical (pArg2); + case HB_SET_CONFIRM : + _retl (hb_set.HB_SET_CONFIRM); + if (args > 1) hb_set.HB_SET_CONFIRM = set_logical (pArg2); break; - case _SET_CONSOLE : - _retl (HB_set._SET_CONSOLE); - if (args > 1) HB_set._SET_CONSOLE = set_logical (pArg2); + case HB_SET_CONSOLE : + _retl (hb_set.HB_SET_CONSOLE); + if (args > 1) hb_set.HB_SET_CONSOLE = set_logical (pArg2); break; - case _SET_CURSOR : - _retni (HB_set._SET_CURSOR); - if (args > 1) HB_set._SET_CURSOR = set_number (pArg2, HB_set._SET_CURSOR); + case HB_SET_CURSOR : + _retni (hb_set.HB_SET_CURSOR); + if (args > 1) hb_set.HB_SET_CURSOR = set_number (pArg2, hb_set.HB_SET_CURSOR); break; - case _SET_DATEFORMAT : - if (HB_set._SET_DATEFORMAT) _retc (HB_set._SET_DATEFORMAT); + case HB_SET_DATEFORMAT : + if (hb_set.HB_SET_DATEFORMAT) _retc (hb_set.HB_SET_DATEFORMAT); else _retc (""); - if (args > 1) HB_set._SET_DATEFORMAT = set_string (pArg2, HB_set._SET_DATEFORMAT, 10); + if (args > 1) hb_set.HB_SET_DATEFORMAT = set_string (pArg2, hb_set.HB_SET_DATEFORMAT); break; - case _SET_DEBUG : - _retl (HB_set._SET_DEBUG); - if (args > 1) HB_set._SET_DEBUG = set_logical (pArg2); + case HB_SET_DEBUG : + _retl (hb_set.HB_SET_DEBUG); + if (args > 1) hb_set.HB_SET_DEBUG = set_logical (pArg2); break; - case _SET_DECIMALS : - _retni (HB_set._SET_DECIMALS); - if (args > 1) HB_set._SET_DECIMALS = set_number (pArg2, HB_set._SET_DECIMALS); + case HB_SET_DECIMALS : + _retni (hb_set.HB_SET_DECIMALS); + if (args > 1) hb_set.HB_SET_DECIMALS = set_number (pArg2, hb_set.HB_SET_DECIMALS); break; - case _SET_DEFAULT : - if (HB_set._SET_DEFAULT) _retc (HB_set._SET_DEFAULT); + case HB_SET_DEFAULT : + if (hb_set.HB_SET_DEFAULT) _retc (hb_set.HB_SET_DEFAULT); else _retc (""); - if (args > 1) HB_set._SET_DEFAULT = set_string (pArg2, HB_set._SET_DEFAULT, 0); + if (args > 1) hb_set.HB_SET_DEFAULT = set_string (pArg2, hb_set.HB_SET_DEFAULT); break; - case _SET_DELETED : - _retl (HB_set._SET_DELETED); - if (args > 1) HB_set._SET_DELETED = set_logical (pArg2); + case HB_SET_DELETED : + _retl (hb_set.HB_SET_DELETED); + if (args > 1) hb_set.HB_SET_DELETED = set_logical (pArg2); break; - case _SET_DELIMCHARS : - if (HB_set._SET_DELIMCHARS) _retc (HB_set._SET_DELIMCHARS); + case HB_SET_DELIMCHARS : + if (hb_set.HB_SET_DELIMCHARS) _retc (hb_set.HB_SET_DELIMCHARS); else _retc (""); - if (args > 1) HB_set._SET_DELIMCHARS = set_string (pArg2, HB_set._SET_DELIMCHARS, 0); + if (args > 1) hb_set.HB_SET_DELIMCHARS = set_string (pArg2, hb_set.HB_SET_DELIMCHARS); break; - case _SET_DELIMITERS : - _retl (HB_set._SET_DELIMITERS); - if (args > 1) HB_set._SET_DELIMITERS = set_logical (pArg2); + case HB_SET_DELIMITERS : + _retl (hb_set.HB_SET_DELIMITERS); + if (args > 1) hb_set.HB_SET_DELIMITERS = set_logical (pArg2); break; - case _SET_DEVICE : - if (HB_set._SET_DEVICE) _retc (HB_set._SET_DEVICE); + case HB_SET_DEVICE : + if (hb_set.HB_SET_DEVICE) _retc (hb_set.HB_SET_DEVICE); else _retc (""); - if (args > 1) HB_set._SET_DEVICE = set_string (pArg2, HB_set._SET_DEVICE, 0); + if (args > 1) hb_set.HB_SET_DEVICE = set_string (pArg2, hb_set.HB_SET_DEVICE); break; - case _SET_EPOCH : - _retni (HB_set._SET_EPOCH); - if (args > 1) HB_set._SET_EPOCH = set_number (pArg2, HB_set._SET_EPOCH); + case HB_SET_EPOCH : + _retni (hb_set.HB_SET_EPOCH); + if (args > 1) hb_set.HB_SET_EPOCH = set_number (pArg2, hb_set.HB_SET_EPOCH); break; - case _SET_ESCAPE : - _retl (HB_set._SET_ESCAPE); - if (args > 1) HB_set._SET_ESCAPE = set_logical (pArg2); + case HB_SET_ESCAPE : + _retl (hb_set.HB_SET_ESCAPE); + if (args > 1) hb_set.HB_SET_ESCAPE = set_logical (pArg2); break; - case _SET_EVENTMASK : - _retni (HB_set._SET_EVENTMASK); - if (args > 1) HB_set._SET_EVENTMASK = set_number (pArg2, HB_set._SET_EVENTMASK); + case HB_SET_EVENTMASK : + _retni (hb_set.HB_SET_EVENTMASK); + if (args > 1) hb_set.HB_SET_EVENTMASK = set_number (pArg2, hb_set.HB_SET_EVENTMASK); break; - case _SET_EXACT : - _retl (HB_set._SET_EXACT); - if (args > 1) HB_set._SET_EXACT = set_logical (pArg2); + case HB_SET_EXACT : + _retl (hb_set.HB_SET_EXACT); + if (args > 1) hb_set.HB_SET_EXACT = set_logical (pArg2); break; - case _SET_EXCLUSIVE : - _retl (HB_set._SET_EXCLUSIVE); - if (args > 1) HB_set._SET_EXCLUSIVE = set_logical (pArg2); + case HB_SET_EXCLUSIVE : + _retl (hb_set.HB_SET_EXCLUSIVE); + if (args > 1) hb_set.HB_SET_EXCLUSIVE = set_logical (pArg2); break; - case _SET_EXIT : - _retl (HB_set._SET_EXIT); - if (args > 1) HB_set._SET_EXIT = set_logical (pArg2); + case HB_SET_EXIT : + _retl (hb_set.HB_SET_EXIT); + if (args > 1) hb_set.HB_SET_EXIT = set_logical (pArg2); break; - case _SET_EXTRA : - _retl (HB_set._SET_EXTRA); - if (args > 1) HB_set._SET_EXTRA = set_logical (pArg2); + case HB_SET_EXTRA : + _retl (hb_set.HB_SET_EXTRA); + if (args > 1) hb_set.HB_SET_EXTRA = set_logical (pArg2); break; - case _SET_EXTRAFILE : - if (HB_set._SET_EXTRAFILE) _retc (HB_set._SET_EXTRAFILE); + case HB_SET_EXTRAFILE : + if (hb_set.HB_SET_EXTRAFILE) _retc (hb_set.HB_SET_EXTRAFILE); else _retc (""); - if (args > 1) HB_set._SET_EXTRAFILE = set_string (pArg2, HB_set._SET_EXTRAFILE, 0); + if (args > 1) hb_set.HB_SET_EXTRAFILE = set_string (pArg2, hb_set.HB_SET_EXTRAFILE); break; - case _SET_FIXED : - _retl (HB_set._SET_FIXED); - if (args > 1) HB_set._SET_FIXED = set_logical (pArg2); + case HB_SET_FIXED : + _retl (hb_set.HB_SET_FIXED); + if (args > 1) hb_set.HB_SET_FIXED = set_logical (pArg2); break; - case _SET_INSERT : - _retl (HB_set._SET_INSERT); - if (args > 1) HB_set._SET_INSERT = set_logical (pArg2); + case HB_SET_INSERT : + _retl (hb_set.HB_SET_INSERT); + if (args > 1) hb_set.HB_SET_INSERT = set_logical (pArg2); break; - case _SET_INTENSITY : - _retl (HB_set._SET_INTENSITY); - if (args > 1) HB_set._SET_INTENSITY = set_logical (pArg2); + case HB_SET_INTENSITY : + _retl (hb_set.HB_SET_INTENSITY); + if (args > 1) hb_set.HB_SET_INTENSITY = set_logical (pArg2); break; - case _SET_MARGIN : - _retni (HB_set._SET_MARGIN); - if (args > 1) HB_set._SET_MARGIN = set_number (pArg2, HB_set._SET_MARGIN); + case HB_SET_MARGIN : + _retni (hb_set.HB_SET_MARGIN); + if (args > 1) hb_set.HB_SET_MARGIN = set_number (pArg2, hb_set.HB_SET_MARGIN); break; - case _SET_MCENTER : - _retl (HB_set._SET_MCENTER); - if (args > 1) HB_set._SET_MCENTER = set_logical (pArg2); + case HB_SET_MCENTER : + _retl (hb_set.HB_SET_MCENTER); + if (args > 1) hb_set.HB_SET_MCENTER = set_logical (pArg2); break; - case _SET_MESSAGE : - _retni (HB_set._SET_MESSAGE); - if (args > 1) HB_set._SET_MESSAGE = set_number (pArg2, HB_set._SET_MESSAGE); + case HB_SET_MESSAGE : + _retni (hb_set.HB_SET_MESSAGE); + if (args > 1) hb_set.HB_SET_MESSAGE = set_number (pArg2, hb_set.HB_SET_MESSAGE); break; - case _SET_PATH : - if (HB_set._SET_PATH) _retc (HB_set._SET_PATH); - if (args > 1) HB_set._SET_PATH = set_string (pArg2, HB_set._SET_PATH, 0); + case HB_SET_PATH : + if (hb_set.HB_SET_PATH) _retc (hb_set.HB_SET_PATH); + if (args > 1) hb_set.HB_SET_PATH = set_string (pArg2, hb_set.HB_SET_PATH); else _retc (""); break; - case _SET_PRINTER : - _retl (HB_set._SET_PRINTER); - if (args > 1) HB_set._SET_PRINTER = set_logical (pArg2); + case HB_SET_PRINTER : + _retl (hb_set.HB_SET_PRINTER); + if (args > 1) hb_set.HB_SET_PRINTER = set_logical (pArg2); break; - case _SET_PRINTFILE : - if (HB_set._SET_PRINTFILE) _retc (HB_set._SET_PRINTFILE); + case HB_SET_PRINTFILE : + if (hb_set.HB_SET_PRINTFILE) _retc (hb_set.HB_SET_PRINTFILE); else _retc (""); - if (args > 1) HB_set._SET_PRINTFILE = set_string (pArg2, HB_set._SET_PRINTFILE, 0); + if (args > 1) hb_set.HB_SET_PRINTFILE = set_string (pArg2, hb_set.HB_SET_PRINTFILE); break; - case _SET_SCOREBOARD : - _retl (HB_set._SET_SCOREBOARD); - if (args > 1) HB_set._SET_SCOREBOARD = set_logical (pArg2); + case HB_SET_SCOREBOARD : + _retl (hb_set.HB_SET_SCOREBOARD); + if (args > 1) hb_set.HB_SET_SCOREBOARD = set_logical (pArg2); break; - case _SET_SCROLLBREAK: - _retl (HB_set._SET_SCROLLBREAK); - if (args > 1) HB_set._SET_SCROLLBREAK = set_logical (pArg2); + case HB_SET_SCROLLBREAK: + _retl (hb_set.HB_SET_SCROLLBREAK); + if (args > 1) hb_set.HB_SET_SCROLLBREAK = set_logical (pArg2); break; - case _SET_SOFTSEEK : - _retl (HB_set._SET_SOFTSEEK); - if (args > 1) HB_set._SET_SOFTSEEK = set_logical (pArg2); + case HB_SET_SOFTSEEK : + _retl (hb_set.HB_SET_SOFTSEEK); + if (args > 1) hb_set.HB_SET_SOFTSEEK = set_logical (pArg2); break; - case _SET_TYPEAHEAD : - _retni (HB_set._SET_TYPEAHEAD); - if (args > 1) HB_set._SET_TYPEAHEAD = set_logical (pArg2); + case HB_SET_TYPEAHEAD : + _retni (hb_set.HB_SET_TYPEAHEAD); + if (args > 1) hb_set.HB_SET_TYPEAHEAD = set_logical (pArg2); break; - case _SET_UNIQUE : - _retl (HB_set._SET_UNIQUE); - if (args > 1) HB_set._SET_UNIQUE = set_logical (pArg2); + case HB_SET_UNIQUE : + _retl (hb_set.HB_SET_UNIQUE); + if (args > 1) hb_set.HB_SET_UNIQUE = set_logical (pArg2); break; - case _SET_WRAP : - _retl (HB_set._SET_WRAP); - if (args > 1) HB_set._SET_WRAP = set_logical (pArg2); + case HB_SET_WRAP : + _retl (hb_set.HB_SET_WRAP); + if (args > 1) hb_set.HB_SET_WRAP = set_logical (pArg2); break; } } -void HB_init_set (void) +void InitializeSets (void) { - HB_set_century = FALSE; - HB_set._SET_ALTERNATE = FALSE; - HB_set._SET_ALTFILE = 0; /* NULL pointer */ - HB_set._SET_BELL = FALSE; - HB_set._SET_CANCEL = TRUE; - HB_set._SET_COLOR = _xgrab (20); - memcpy (HB_set._SET_COLOR, "W/N,N/W,N/N,N/N,N/W", 20); - HB_set._SET_CONFIRM = FALSE; - HB_set._SET_CONSOLE = TRUE; - HB_set._SET_CURSOR = SC_NORMAL; - HB_set._SET_DATEFORMAT = _xgrab (9); - memcpy (HB_set._SET_DATEFORMAT, "mm/dd/yy", 9); - HB_set._SET_DEBUG = FALSE; - HB_set._SET_DECIMALS = 2; - HB_set._SET_DEFAULT = _xgrab (1); - *HB_set._SET_DEFAULT = 0; - HB_set._SET_DELETED = FALSE; - HB_set._SET_DELIMCHARS = _xgrab (3); - memcpy (HB_set._SET_DELIMCHARS, "::", 3); - HB_set._SET_DELIMITERS = FALSE; - HB_set._SET_DEVICE = _xgrab (7); - memcpy (HB_set._SET_DEVICE, "SCREEN", 7); - HB_set._SET_EPOCH = 1900; - HB_set._SET_ESCAPE = 1; - HB_set._SET_EVENTMASK = INKEY_KEYBOARD; - HB_set._SET_EXACT = FALSE; - HB_set._SET_EXCLUSIVE = TRUE; - HB_set._SET_EXIT = FALSE; - HB_set._SET_EXTRA = FALSE; /* TODO: What is this for? */ - HB_set._SET_EXTRAFILE = 0; /* TODO: What is this for? */ - HB_set._SET_FIXED = FALSE; - HB_set._SET_INSERT = FALSE; - HB_set._SET_INTENSITY = TRUE; - HB_set._SET_MARGIN = 0; - HB_set._SET_MCENTER = FALSE; - HB_set._SET_MESSAGE = 0; - HB_set._SET_PATH = _xgrab (1); - *HB_set._SET_PATH = 0; - HB_set._SET_PRINTER = FALSE; - HB_set._SET_PRINTFILE = 0; /* NULL pointer */ - HB_set._SET_SCOREBOARD = TRUE; - HB_set._SET_SCROLLBREAK = TRUE; - HB_set._SET_SOFTSEEK = FALSE; - HB_set._SET_TYPEAHEAD = 50; - HB_set._SET_UNIQUE = FALSE; - HB_set._SET_WRAP = FALSE; + hb_set_century = FALSE; + hb_set.HB_SET_ALTERNATE = FALSE; + hb_set.HB_SET_ALTFILE = 0; /* NULL pointer */ + hb_set.HB_SET_BELL = FALSE; + hb_set.HB_SET_CANCEL = TRUE; + hb_set.HB_SET_COLOR = _xgrab (20); + memcpy (hb_set.HB_SET_COLOR, "W/N,N/W,N/N,N/N,N/W", 20); + hb_set.HB_SET_CONFIRM = FALSE; + hb_set.HB_SET_CONSOLE = TRUE; + hb_set.HB_SET_CURSOR = SC_NORMAL; + hb_set.HB_SET_DATEFORMAT = _xgrab (9); + memcpy (hb_set.HB_SET_DATEFORMAT, "mm/dd/yy", 9); + hb_set.HB_SET_DEBUG = FALSE; + hb_set.HB_SET_DECIMALS = 2; + hb_set.HB_SET_DEFAULT = _xgrab (1); + *hb_set.HB_SET_DEFAULT = 0; + hb_set.HB_SET_DELETED = FALSE; + hb_set.HB_SET_DELIMCHARS = _xgrab (3); + memcpy (hb_set.HB_SET_DELIMCHARS, "::", 3); + hb_set.HB_SET_DELIMITERS = FALSE; + hb_set.HB_SET_DEVICE = _xgrab (7); + memcpy (hb_set.HB_SET_DEVICE, "SCREEN", 7); + hb_set.HB_SET_EPOCH = 1900; + hb_set.HB_SET_ESCAPE = 1; + hb_set.HB_SET_EVENTMASK = INKEY_KEYBOARD; + hb_set.HB_SET_EXACT = FALSE; + hb_set.HB_SET_EXCLUSIVE = TRUE; + hb_set.HB_SET_EXIT = FALSE; + hb_set.HB_SET_EXTRA = FALSE; /* TODO: What is this for? */ + hb_set.HB_SET_EXTRAFILE = 0; /* TODO: What is this for? */ + hb_set.HB_SET_FIXED = FALSE; + hb_set.HB_SET_INSERT = FALSE; + hb_set.HB_SET_INTENSITY = TRUE; + hb_set.HB_SET_MARGIN = 0; + hb_set.HB_SET_MCENTER = FALSE; + hb_set.HB_SET_MESSAGE = 0; + hb_set.HB_SET_PATH = _xgrab (1); + *hb_set.HB_SET_PATH = 0; + hb_set.HB_SET_PRINTER = FALSE; + hb_set.HB_SET_PRINTFILE = 0; /* NULL pointer */ + hb_set.HB_SET_SCOREBOARD = TRUE; + hb_set.HB_SET_SCROLLBREAK = TRUE; + hb_set.HB_SET_SOFTSEEK = FALSE; + hb_set.HB_SET_TYPEAHEAD = 50; + hb_set.HB_SET_UNIQUE = FALSE; + hb_set.HB_SET_WRAP = FALSE; } void ReleaseSets (void) { - _xfree (HB_set._SET_COLOR); - _xfree (HB_set._SET_DATEFORMAT); - _xfree (HB_set._SET_DEFAULT); - _xfree (HB_set._SET_DELIMCHARS); - _xfree (HB_set._SET_DEVICE); - _xfree (HB_set._SET_PATH); + _xfree (hb_set.HB_SET_COLOR); + _xfree (hb_set.HB_SET_DATEFORMAT); + _xfree (hb_set.HB_SET_DEFAULT); + _xfree (hb_set.HB_SET_DELIMCHARS); + _xfree (hb_set.HB_SET_DEVICE); + _xfree (hb_set.HB_SET_PATH); } diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 048698d2d2..602976f9ac 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -167,7 +167,7 @@ BYTE bErrorLevel = 0; /* application exit errorlevel */ stack.Return.wType = IT_NIL; StackInit(); NewDynSym( &symEval ); /* initialize dynamic symbol for evaluating codeblocks */ - HB_init_set(); /* initialize Sets */ + InitializeSets(); /* initialize Sets */ DoInitFunctions( argc, argv ); /* process defined INIT functions */ PushSymbol( pSymStart ); /* pushes first FS_PUBLIC defined symbol to the stack */ diff --git a/harbour/tests/working/dates.prg b/harbour/tests/working/dates.prg index c38ea0dd5c..596f545ffe 100644 --- a/harbour/tests/working/dates.prg +++ b/harbour/tests/working/dates.prg @@ -9,17 +9,17 @@ local cNewLine := CHR( 10 ) OUTSTD (cNewLine, "Testing Harbour dates management", cNewLine) - OUTSTD (cNewLine, __SETCENTURY ()) - __SETCENTURY ("ON") - OUTSTD (__SETCENTURY ()) - __SETCENTURY ("OFF") - OUTSTD (__SETCENTURY ()) - __SETCENTURY ("GIBBERISH") - OUTSTD (__SETCENTURY ()) - __SETCENTURY (.T.) - OUTSTD (__SETCENTURY ()) - __SETCENTURY (5) - OUTSTD (__SETCENTURY ()) + OUTSTD (cNewLine, HB_SETCENTURY ()) + HB_SETCENTURY ("ON") + OUTSTD (HB_SETCENTURY ()) + HB_SETCENTURY ("OFF") + OUTSTD (HB_SETCENTURY ()) + HB_SETCENTURY ("GIBBERISH") + OUTSTD (HB_SETCENTURY ()) + HB_SETCENTURY (.T.) + OUTSTD (HB_SETCENTURY ()) + HB_SETCENTURY (5) + OUTSTD (HB_SETCENTURY ()) OUTSTD (cNewLine, "") OUTSTD (cNewLine, "dDate = CToD( '02/04/1999' ) => ", dDate := CToD( "02/04/1999" )) diff --git a/harbour/tests/working/dates2.prg b/harbour/tests/working/dates2.prg new file mode 100644 index 0000000000..bd4a3c1470 --- /dev/null +++ b/harbour/tests/working/dates2.prg @@ -0,0 +1,36 @@ +#include "set.ch" +function main() + local newline := CHR(10) + local dDate := CTOD ("04/30/99") + outstd (SET (_SET_DATEFORMAT), dDate, newline) + set (_SET_DATEFORMAT, "yyy/mm/ddd") + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "on" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "off" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + set (_SET_DATEFORMAT, "yyy/m/d/yyy") + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "on" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "off" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + set (_SET_DATEFORMAT, "m/d/y/m/d") + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "on" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "off" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + set (_SET_DATEFORMAT, "mmmm/ddddd") + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "on" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "off" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + set (_SET_DATEFORMAT, "mmmmm/dd") + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "on" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) + hb_setcentury ( "off" ) + outstd (SET (_SET_DATEFORMAT), dDate, newline) +return nil