Changeset 21
- Timestamp:
- Oct 28, 2014, 12:30:20 PM (11 years ago)
- Location:
- rxutilex/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
rxutilex/trunk/FUNCTIONS
r20 r21 9 9 Sys2DisconnectNamedPipe - Acknowledge that a named pipe session has ended 10 10 Sys2DropFuncs - Deregister all functions 11 Sys2FormatNumber - Format a number with thousands-grouping characters 11 12 Sys2FormatTime - Format calender time (strftime wrapper) 12 13 Sys2GetClipboardText - Retrieve the current clipboard text … … 146 147 REXX ARGUMENTS: None 147 148 REXX RETURN VALUE: "" 149 150 151 ------------------------------------------------------------------------- 152 Sys2FormatNumber 153 154 Formats a number to use thousands-grouping characters. The system values 155 for the current locale are used for the thousands-grouping character and 156 the decimal place, if any. Note that the IBM C runtime's built-in locale 157 definitions are used; these may not correspond precisely to the system 158 locales as defined in the OS/2 Locale object. 159 160 The input number may be a positive or negative integer or floating point 161 value. It must be a simple, non-localized number value; in other words, 162 it must not contain any thousands-grouping characters, and any decimal 163 point which it contains must be a period (rather than any localized 164 decimal symbol). 165 166 REXX ARGUMENTS: 167 1. Number to be formatted. (REQUIRED) 168 2. Number of decimal places to use for floating point values. 169 Ignored for integer values. (DEFAULT: 2) 170 171 REXX RETURN VALUE: The formatted number, or '' on error. 148 172 149 173 -
rxutilex/trunk/TODO
r17 r21 2 2 3 3 * Sys2ReplaceModule - A wrapper for DosReplaceModule() 4 * Named pipe management functions5 * Open/Close/Seek/Read/Write functions with large file support6 4 - Sys2TokenizeString - A string tokenizer 7 - Sys2FormatNumber - Format a number according to locale8 5 - Sys2FormatCurrency - A strfmon wrapper 9 6 - Sys2GetResource - DosGetResource wrapper … … 26 23 ? Query/extract an object's icon <-- exists in RWS? 27 24 28 * = Implemented, needs testing25 * = Implemented, needs more testing 29 26 ? = Suggestion only 30 27 -
rxutilex/trunk/rxutilex.c
r20 r21 83 83 #define US_PIDSTR_MAXZ ( CCHMAXPATH + 100 ) // ...of a process information string 84 84 #define US_TIMESTR_MAXZ 256 // ...of a formatted time string 85 #define US_NUMSTR_MAXZ 256 // ...of a formatted number string 85 86 #define US_PIPESTATUS_MAXZ 128 // ...of a pipe status string 86 87 … … 103 104 "Sys2QueryForegroundProcess", 104 105 "Sys2QueryPhysicalMemory", 106 "Sys2FormatNumber", 105 107 "Sys2FormatTime", 106 108 "Sys2GetEpochTime", … … 127 129 RexxFunctionHandler Sys2Version; 128 130 131 RexxFunctionHandler Sys2FormatNumber; 129 132 RexxFunctionHandler Sys2FormatTime; 130 133 RexxFunctionHandler Sys2GetEpochTime; … … 903 906 904 907 /* ------------------------------------------------------------------------- * 908 * Sys2FormatNumber * 909 * * 910 * Format a number using locale-specific thousands separators. The input * 911 * number may be a positive or negative integer or floating point value. It * 912 * must not contain any separators already, and any decimal point which it * 913 * contains must be a period (rather than any localized decimal symbol). * 914 * * 915 * REXX ARGUMENTS: * 916 * 1. Number to be formatted. (REQUIRED) * 917 * 2. Number of decimal places to use for floating point values. Ignored * 918 * for integer values. Defaults to 2 if not specified. * 919 * * 920 * REXX RETURN VALUE: The formatted number, or '' on error. * 921 * ------------------------------------------------------------------------- */ 922 ULONG APIENTRY Sys2FormatNumber( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) 923 { 924 CHAR achNumber[ US_NUMSTR_MAXZ ]; // Formatted output string 925 PSZ pszTZ, // Pointer to TZ environment var 926 pszSetTZ; 927 float fVal; 928 int iVal; 929 int iPrec; 930 931 // Make sure we have at least one valid argument (the input number) 932 if ( argc < 1 || ( !RXVALIDSTRING(argv[0]) )) return ( 40 ); 933 934 935 /* These next 4 lines really shouldn't be necessary, but without them 936 * getenv() and (apparently) tzset() may see the value of TZ as NULL 937 * if the environment variable was changed in the REXX script. 938 */ 939 DosScanEnv("TZ", &pszTZ ); 940 pszSetTZ = (PSZ) malloc( strlen( pszTZ ) + 5 ); 941 if ( pszSetTZ ) { 942 sprintf( pszSetTZ, "TZ=%s", pszTZ ); 943 putenv( pszSetTZ ); 944 } 945 946 // Use the locale and timezone settings from the environment 947 tzset(); 948 setlocale( LC_ALL, ""); 949 950 // Check for a decimal place and treat as float or integer accordingly 951 if ( strchr( argv[0].strptr, '.') != NULL ) { 952 if (( sscanf( argv[0].strptr, "%f", &fVal )) != 1 ) return ( 40 ); 953 if ( argc >= 2 && ( RXVALIDSTRING(argv[1]) ) && 954 (( sscanf( argv[1].strptr, "%d", &iPrec )) == 1 )) 955 { 956 // Use user-specified precision 957 sprintf( achNumber, "%'.*f", iPrec, fVal ); 958 } 959 else 960 sprintf( achNumber, "%'.2f", fVal ); 961 } 962 else { 963 if (( sscanf( argv[0].strptr, "%d", &iVal )) != 1 ) return ( 40 ); 964 sprintf( achNumber, "%'d", iVal ); 965 } 966 967 // Return the formatted number 968 MAKERXSTRING( *prsResult, achNumber, strlen( achNumber )); 969 970 if ( pszSetTZ ) free( pszSetTZ ); 971 return ( 0 ); 972 } 973 974 975 /* ------------------------------------------------------------------------- * 905 976 * Sys2FormatTime * 906 977 * * … … 979 1050 DosScanEnv("TZ", &pszTZ ); 980 1051 pszSetTZ = (PSZ) malloc( strlen( pszTZ ) + 5 ); 981 sprintf( pszSetTZ, "TZ=%s", pszTZ ); 982 putenv( pszSetTZ ); 1052 if ( pszSetTZ ) { 1053 sprintf( pszSetTZ, "TZ=%s", pszTZ ); 1054 putenv( pszSetTZ ); 1055 } 983 1056 984 1057 // Use the locale and timezone settings from the environment … … 991 1064 WriteErrorCode( ttSeconds, "time"); 992 1065 MAKERXSTRING( *prsResult, "", 0 ); 1066 if ( pszSetTZ ) free( pszSetTZ ); 993 1067 return 0; 994 1068 } … … 1000 1074 WriteErrorCode( 1, "gmtime"); 1001 1075 MAKERXSTRING( *prsResult, "0", 1 ); 1076 if ( pszSetTZ ) free( pszSetTZ ); 1002 1077 return 0; 1003 1078 } … … 1008 1083 WriteErrorCode( 1, "localtime"); 1009 1084 MAKERXSTRING( *prsResult, "0", 1 ); 1085 if ( pszSetTZ ) free( pszSetTZ ); 1010 1086 return 0; 1011 1087 } … … 1032 1108 WriteErrorCode( stRC, "strftime"); 1033 1109 MAKERXSTRING( *prsResult, "", 0 ); 1110 if ( pszSetTZ ) free( pszSetTZ ); 1034 1111 return ( 0 ); 1035 1112 } … … 1038 1115 MAKERXSTRING( *prsResult, szTime, strlen(szTime) ); 1039 1116 1040 free( pszSetTZ );1117 if ( pszSetTZ ) free( pszSetTZ ); 1041 1118 return ( 0 ); 1042 1119 } -
rxutilex/trunk/rxutilex.def
r20 r21 1 1 LIBRARY RXUTILEX INITINSTANCE TERMINSTANCE 2 2 DATA MULTIPLE NONSHARED 3 DESCRIPTION '@#Alex Taylor:0.1.0#@##1## 7 Oct 2014 22:42:18 REINFORCE::::::@@ExtraREXX Utility Functions'3 DESCRIPTION '@#Alex Taylor:0.1.0#@##1## 28 Oct 2014 20:00:26 REINFORCE::::::@@Extended REXX Utility Functions' 4 4 5 5 EXPORTS Sys2LoadFuncs 6 6 Sys2DropFuncs 7 7 Sys2Version 8 Sys2FormatNumber 8 9 Sys2FormatTime 9 10 Sys2GetEpochTime -
rxutilex/trunk/testlib.cmd
r20 r21 33 33 say 'Current local time is "'Sys2FormatTime(et, 'l')'"' 34 34 say 'Current UTC time is "'Sys2FormatTime(et, 'l', 'u')'"' 35 36 35 say 37 36 38 37 say Sys2LocateDLL('ehxdlmri') 39 38 39 say Sys2FormatNumber('100') 40 say Sys2FormatNumber('10000') 41 say Sys2FormatNumber('5003.543', 1) 42 40 43 call Sys2DropFuncs 41 44 return 0
Note:
See TracChangeset
for help on using the changeset viewer.