Changeset 13 for trunk/txlib
- Timestamp:
- 05/13/06 20:33:09 (3 years ago)
- Location:
- trunk/txlib
- Files:
-
- 9 modified
-
include/txcon.h (modified) (3 diffs)
-
include/txlib.h (modified) (3 diffs)
-
txcon.c (modified) (3 diffs)
-
txlib.c (modified) (1 diff)
-
txlogfil.c (modified) (6 diffs)
-
txparse.c (modified) (2 diffs)
-
txstdcmd.c (modified) (4 diffs)
-
txtrace.c (modified) (1 diff)
-
txvers.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/txlib/include/txcon.h
r11 r13 1183 1183 BOOL TxAppendToLogFile // RET logfile opened 1184 1184 ( 1185 char *fname // IN name of (new) logfile 1185 char *fname, // IN name of (new) logfile 1186 BOOL verbose // IN Show the action 1186 1187 ); 1187 1188 … … 1214 1215 ); 1215 1216 1217 // Construct name for new logfile based upon a sequence number 0..n 1218 char *TxBuildLogName // RET filename 1219 ( 1220 ULONG seq, // IN sequence number 1221 TXLN buf // IN filename buffer 1222 ); 1216 1223 1217 1224 // Output textual information in array of char-pointers … … 1235 1242 ); 1236 1243 1244 // Set logfile maximum size per file 1245 void TxSetLogMaxSize 1246 ( 1247 ULONG size // IN maximum size, bytes 1248 ); 1249 1250 // Set logfile number of files to retain on cycle, #files besides .log itself 1251 void TxSetLogRetain 1252 ( 1253 ULONG retain // IN retain count 1254 ); 1237 1255 1238 1256 // Make ascii-dump of data area on TxPrint output -
trunk/txlib/include/txlib.h
r11 r13 1092 1092 #define TxaOptStr(o,e,d) TxaOptionStr( TXA_CUR,o,e,d) 1093 1093 #define TxaOptNum(o,e,d) TxaOptionNum( TXA_CUR,o,e,d) 1094 #define TxaOptBkmg(o,d,m) TxaOptionBkmg( TXA_CUR,o,d,m) 1094 1095 #define TxaOptValue(o) TxaGetOption( TXA_CUR,o) 1095 1096 #define TxaOptCount() TxaGetOptc( TXA_CUR ) … … 1105 1106 #define TxaExeSwitchStr(o,e,d) TxaOptionStr( TXA_1ST,o,e,d) 1106 1107 #define TxaExeSwitchNum(o,e,d) TxaOptionNum( TXA_1ST,o,e,d) 1108 #define TxaExeSwitchBkmg(o,d,m) TxaOptionBkmg( TXA_1ST,o,d,m) 1107 1109 #define TxaExeSwitchValue(o) TxaGetOption( TXA_1ST,o) 1108 1110 #define TxaExeOptc() TxaGetOptc( TXA_1ST ) … … 1280 1282 char *error, // IN error text or NULL 1281 1283 ULONG deflt // IN default value 1284 ); 1285 1286 // Get option value num/string, with bytes/kilo/mega/giga modifier and default 1287 ULONG TxaOptionBkmg // RET number value in bytes 1288 ( 1289 TXHANDLE txh, // IN TXA handle 1290 char option, // IN option character 1291 ULONG def, // IN default value 1292 BYTE mod // IN b,kb,mb,gb modifier 1282 1293 ); 1283 1294 -
trunk/txlib/txcon.c
r11 r13 75 75 static char txc_ansi = A_ON; 76 76 77 //- logfile cycling and size control 78 static ULONG log_written = 0; // bytes written on this file 79 static ULONG log_maxsize = 0; // maximum size per logfile 80 static ULONG log_seq_num = 0; // sequence number 0..n 81 static ULONG log_retain = 0; // log recycle retain count 77 82 78 83 //- Note: 256 color strings sorted in default PC order … … 460 465 461 466 /*****************************************************************************/ 467 // Set logfile maximum size per file 468 /*****************************************************************************/ 469 void TxSetLogMaxSize 470 ( 471 ULONG size // IN maximum size, bytes 472 ) 473 { 474 log_maxsize = size; 475 } // end 'TxSetLogMaxSize' 476 /*---------------------------------------------------------------------------*/ 477 478 479 /*****************************************************************************/ 480 // Set logfile number of files to retain on cycle, #files besides .log itself 481 /*****************************************************************************/ 482 void TxSetLogRetain 483 ( 484 ULONG retain // IN retain count 485 ) 486 { 487 log_retain = retain; 488 } // end 'TxSetLogRetain' 489 /*---------------------------------------------------------------------------*/ 490 491 492 /*****************************************************************************/ 462 493 // printf-like print on stdout, LOG filehandle and raw/clean copy hooks 463 494 /*****************************************************************************/ … … 528 559 TxAscii827( txm_buff, TXASCII827_TRANS); 529 560 } 561 562 if ((log_maxsize > size) && (log_written > (log_maxsize - size))) 563 { 564 TXLN fname; 565 566 log_written = 0; // avoid recursive cycling 567 fprintf( log_handle, "\nClosing logfile at size limit\n"); 568 569 TxAppendToLogFile( NULL, FALSE); // close current log, quiet 570 if (log_seq_num >= log_retain) // need to delete one 571 { 572 TxBuildLogName( log_seq_num - log_retain, fname); 573 remove( fname); // delete a logfile (cycle) 574 } 575 TxBuildLogName( (log_retain) ? ++log_seq_num : 0, fname); 576 TxAppendToLogFile( fname, FALSE); // open next logfile, quiet 577 log_handle = TxQueryLogFile( &log7bit, &logreopen); 578 fprintf( log_handle, "Start next logfile: '%s'\n", fname); 579 } 580 else 581 { 582 log_written += size; // maintain total size in log 583 } 584 530 585 fprintf( log_handle, "%s", txm_buff); 531 586 if (logreopen) -
trunk/txlib/txlib.c
r11 r13 139 139 ) 140 140 { 141 TxAppendToLogFile("" );141 TxAppendToLogFile("", TRUE); 142 142 #if defined (USEWINDOWING) 143 143 TxInputTerminate(); // stop windowed KBD/MOU input -
trunk/txlib/txlogfil.c
r11 r13 39 39 #include <txlib.h> 40 40 41 static FILE *log_handle= 0;42 static TXLN log_fname;43 static BOOL log_7bit= TRUE;44 static BOOL log_reopen = FALSE;// reopen on each line41 static FILE *log_handle = 0; 42 static TXLN log_fname = "logfile"; 43 static BOOL log_7bit = TRUE; 44 static BOOL log_reopen = FALSE; // reopen on each line 45 45 46 46 /*****************************************************************************/ … … 49 49 BOOL TxAppendToLogFile // RET logfile opened 50 50 ( 51 char *fname // IN name of (new) logfile 51 char *fname, // IN name of (new) logfile 52 BOOL verbose // IN Show the action 52 53 ) 53 54 { 54 55 if (log_handle != 0) // close old one 55 56 { 56 TxPrint("Closing logfile : '%s'\n", log_fname); 57 if (verbose) 58 { 59 TxPrint("Closing logfile : '%s'\n", log_fname); 60 } 57 61 fclose(log_handle); 58 62 log_handle = 0; … … 65 69 TxFnameExtension( log_fname, "log"); 66 70 } 67 if (( log_handle = fopen(log_fname, "a" TXFMODE)) == 0)71 if (((log_handle = fopen(log_fname, "a" TXFMODE)) == 0) && (verbose)) 68 72 { 69 73 TxPrint("Error opening log : '%s'\n", log_fname); … … 72 76 { 73 77 TxLogfileState( DEVICE_ON); // always ON for new file 74 if (TxaOptUnSet('7')) // NO strip to 7-bit ASCII 75 { 76 log_7bit = FALSE; 77 } 78 if (TxaExeArgc() != 0) // Switches already parsed ? 79 { // (-q = quiet switch to come) 80 TxPrint("Appending to log : '%s' (%s-bit ASCII)\n", 81 log_fname, (log_7bit) ? "7" : "8"); 78 if (verbose) // avoid any TxPrint when 79 { // working in quiet mode 80 if (TxaOptUnSet('7')) // NO strip to 7-bit ASCII 81 { 82 log_7bit = FALSE; 83 } 84 if (TxaExeArgc() != 0) // Switches already parsed ? 85 { // (-q = quiet switch to come) 86 TxPrint("Appending to log : '%s' (%s-bit ASCII)\n", 87 log_fname, (log_7bit) ? "7" : "8"); 88 } 82 89 } 83 90 } … … 148 155 /*---------------------------------------------------------------------------*/ 149 156 157 150 158 /*****************************************************************************/ 151 159 // Get name for current logfile, if any … … 166 174 /*---------------------------------------------------------------------------*/ 167 175 176 177 /*****************************************************************************/ 178 // Construct name for new logfile based upon a sequence number 0..n 179 /*****************************************************************************/ 180 char *TxBuildLogName // RET filename or NULL 181 ( 182 ULONG seq, // IN sequence number 183 TXLN buf // IN filename buffer 184 ) 185 { 186 char *rc = buf; 187 TXTS ext; 188 189 if (seq == 0) // first will be .log 190 { 191 strcpy( ext, "log"); 192 } 193 else 194 { 195 sprintf( ext, "l%02lu", seq); 196 } 197 strcpy( rc, log_fname); 198 199 TxStripExtension( rc); // remove current extension 200 TxFnameExtension( rc, ext); // and add new one 201 202 return (rc); 203 } // end 'TxBuildLogName' 204 /*---------------------------------------------------------------------------*/ 205 -
trunk/txlib/txparse.c
r11 r13 249 249 250 250 /*****************************************************************************/ 251 // Get option value num/string, with bytes/kilo/mega/giga modifier and default 252 /*****************************************************************************/ 253 ULONG TxaOptBkmg // RET number value in bytes 254 ( 255 TXHANDLE txh, // IN TXA handle 256 char option, // IN option character 257 ULONG def, // IN default value 258 BYTE mod // IN b,kb,mb,gb modifier 259 ) 260 { 261 ULONG rc = 0; // function return 262 BYTE unit = TXA_DFUNIT; 263 TXA_OPTION *opt; // option pointer 264 265 ENTER(); 266 TRACES(("Option: '%c' default: %8.8lx mod:%2.2hx = '%c'\n", 267 option, def, mod, mod)); 268 269 if ((opt = TxaOptValue( option)) != NULL) // get the option details 270 { 271 switch (opt->type) 272 { 273 case TXA_STRING: 274 rc = TxaParseNumber( opt->value.string, TX_RADIX_STD_CLASS, &unit); 275 case TXA_NO_VAL: 276 rc = def; 277 break; 278 279 default: // convert, default is MiB! 280 rc = opt->value.number; 281 unit = opt->unit; 282 break; 283 } 284 } 285 if (unit == TXA_DFUNIT) 286 { 287 unit = mod; 288 } 289 switch (tolower(unit)) 290 { 291 case 'g': 292 if (rc >= 4) 293 { 294 rc = 0xffffffff; 295 break; 296 } 297 else 298 { 299 rc *= 1024; // Giga 300 } 301 case 'm': rc *= 1024; // Mega 302 case 'k': rc *= 1024; // Kilo 303 default: break; // Bytes, OK 304 } 305 RETURN (rc); 306 } // end 'TxaParseBkmgNumber' 307 /*---------------------------------------------------------------------------*/ 308 309 310 /*****************************************************************************/ 251 311 // Read one item (option or argument) and store it in the txa element 252 312 /*****************************************************************************/ … … 680 740 681 741 /*****************************************************************************/ 742 // Get option value num/string, with bytes/kilo/mega/giga modifier and default 743 /*****************************************************************************/ 744 ULONG TxaOptionBkmg // RET number value in bytes 745 ( 746 TXHANDLE txh, // IN TXA handle 747 char option, // IN option character 748 ULONG def, // IN default value 749 BYTE mod // IN b,kb,mb,gb modifier 750 ) 751 { 752 ULONG rc = 0; // function return 753 BYTE unit = TXA_DFUNIT; 754 TXA_OPTION *opt; // option pointer 755 756 ENTER(); 757 TRACES(("Option: '%c' default: %8.8lx mod:%2.2hx = '%c'\n", 758 option, def, mod, mod)); 759 760 if ((opt = TxaOptValue( option)) != NULL) // get the option details 761 { 762 switch (opt->type) 763 { 764 case TXA_STRING: 765 rc = TxaParseNumber( opt->value.string, TX_RADIX_STD_CLASS, &unit); 766 case TXA_NO_VAL: 767 rc = def; 768 break; 769 770 default: // convert, default is MiB! 771 rc = opt->value.number; 772 unit = opt->unit; 773 break; 774 } 775 } 776 if (unit == TXA_DFUNIT) 777 { 778 unit = mod; 779 } 780 switch (tolower(unit)) 781 { 782 case 'g': rc *= 1024; // Giga 783 case 'm': rc *= 1024; // Mega 784 case 'k': rc *= 1024; // Kilo 785 default: break; // Bytes, OK 786 } 787 RETURN (rc); 788 } // end 'TxaOptionBkmg' 789 /*---------------------------------------------------------------------------*/ 790 791 792 /*****************************************************************************/ 682 793 // Get reference to specified argument-string 683 794 /*****************************************************************************/ -
trunk/txlib/txstdcmd.c
r11 r13 101 101 TxSetLogReOpen( TxaOption('r')); 102 102 } 103 TxAppendToLogFile( c1); 103 if (TxaOptSet('m')) 104 { 105 TxSetLogMaxSize( TxaOptBkmg( 'm', 2047, 'k')); 106 } 107 if (TxaOptSet('f')) 108 { 109 TxSetLogRetain( TxaOptNum('f', NULL, 1)); 110 } 111 TxAppendToLogFile( c1, TRUE); 104 112 } 105 113 else if (stricmp(c0, "trace" ) == 0) … … 110 118 "Usage: trace [-r] [-s] [-t] [level | filename]\n\n" 111 119 " -d[:xx] add xx ms delay for each trace line, slowdown\n" 120 " -f[:ff] retain ff numbered logfiles when cycling\n" 121 " -m[:mm] cycle to next logfile after size mm\n" 112 122 " -r close and reopen log on each line (slow)\n" 113 123 " -r- open log just once (this is the default)\n" … … 139 149 TxTrLogOnly = !TxaOption('s'); // to screen with -s 140 150 } 151 if (TxaOptSet('m')) 152 { 153 TxSetLogMaxSize( TxaOptBkmg( 'm', 2047, 'k')); 154 } 155 if (TxaOptSet('f')) 156 { 157 TxSetLogRetain( TxaOptNum('f', NULL, 1)); 158 } 141 159 if (isdigit( c1[0])) // setting a level 142 160 { … … 147 165 if (strlen( c1)) 148 166 { 149 TxAppendToLogFile( c1 );167 TxAppendToLogFile( c1, TRUE); 150 168 TxTrLevel = 100; 151 169 } -
trunk/txlib/txtrace.c
r1 r13 125 125 126 126 sprintf( trcfile, "%s-%lu", prefix, TxTrLevel); 127 TxAppendToLogFile( trcfile );127 TxAppendToLogFile( trcfile, TRUE); 128 128 } 129 129 } -
trunk/txlib/txvers.h
r11 r13 40 40 // Originally developed for LPTool/DFSee utilities, open-sourced in 2005 41 41 // 42 #define TXLIB_V "1.07 04-05-2006" // JvW Avoid (history) popup from other list 42 #define TXLIB_V "1.08 12-05-2006" // JvW Logfile maximum size and auto-cycling 43 //efine TXLIB_V "1.07 04-05-2006" // JvW Avoid (history) popup from other list 43 44 //efine TXLIB_V "1.07 02-05-2006" // JvW Ctrl-D on cmdline, auto NEXT history 44 45 //efine TXLIB_V "1.07 30-04-2006" // JvW Ctrl-D, delete history-item from popup