forked from lanl/coNCePTuaL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ncptl-logextract.in
4201 lines (3258 loc) · 157 KB
/
ncptl-logextract.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env perl
########################################################################
#
# Extract various bits of information from a coNCePTuaL log file
#
# By Scott Pakin <[email protected]>
#
# ----------------------------------------------------------------------
#
#
# Copyright (C) 2015, Los Alamos National Security, LLC
# All rights reserved.
#
# Copyright (2015). Los Alamos National Security, LLC. This software
# was produced under U.S. Government contract DE-AC52-06NA25396
# for Los Alamos National Laboratory (LANL), which is operated by
# Los Alamos National Security, LLC (LANS) for the U.S. Department
# of Energy. The U.S. Government has rights to use, reproduce,
# and distribute this software. NEITHER THE GOVERNMENT NOR LANS
# MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY
# FOR THE USE OF THIS SOFTWARE. If software is modified to produce
# derivative works, such modified software should be clearly marked,
# so as not to confuse it with the version available from LANL.
#
# Additionally, redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of Los Alamos National Security, LLC, Los Alamos
# National Laboratory, the U.S. Government, nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY LANS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LANS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
########################################################################
use File::Basename;
use File::Spec;
use File::Find;
use Getopt::Long;
use Pod::Usage;
use Pod::Parser;
use Pod::Html;
use POSIX;
use warnings;
use strict;
###########################################################################
# Get the base name of our executable.
my ($progname, undef, undef) = fileparse $0, '\..*';
# Define the number of header rows we expect to see. This is normally
# 2, but specifying "--merge=all" and either "--showfnames=first" or
# "--showfnames=all" increases the number to 3.
my $numheaderrows = 2;
# Declare some variables that may be set from the command line.
my $want_docs = 0; # 1=output synopsis; 2=output synopsis and options; 3=output man page
my $extract = "data"; # What to extract from the log file
my $format; # Output format for extracted data
my @options; # Additional options for formatting output
my @before; # Text to output before regular output
my @after; # Text to output after regular output
my @keepcolumns; # List of columns to retain (undef=all)
my $forcemerge; # [<filler #>]=try extra hard to merge incompatible log files
my $outfile = "-"; # File to which to write our output
my $unmerge_procs; # Comma-separated ranges of processes to extract from a merged file
my $verbose = 1; # 1=show progress; 0=don't
# Keep track of command-line options we actually used.
my %optsused;
###########################################################################
# Define all of the program's arguments and their descriptions.
my @arguments =
(["data" => ["Extract measurement data",
[["csv" => ["Output each table in comma-separated-value format",
[["noheaders" => ["Do not output column headers"]],
["colbegin=I<string>" => ["Specify the text placed at the beginning of each data column [default: '']"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: ',']"]],
["colend=I<string>" => ["Specify the text placed at the end of each data column [default: '']"]],
["rowbegin=I<string>" => ["Specify the text placed at the beginning of each data row [default: '']"]],
["rowsep=I<string>" => ["Specify the text used to separate data rows [default: '']"]],
["rowend=I<string>" => ["Specify the text placed at the end of each data row [default: '\\n']"]],
["hcolbegin=I<string>" => ["Specify the text placed at the beginning of each header column [default: same as colbegin]"]],
["hcolsep=I<string>" => ["Specify the text used to separate header columns [default: same as colsep]"]],
["hcolend=I<string>" => ["Specify the text placed at the end of each header column [default: same as colend]"]],
["hrowbegin=I<string>" => ["Specify the text placed at the beginning of each header row [default: same as rowbegin]"]],
["hrowsep=I<string>" => ["Specify the text used to separate header rows [default: same as rowsep]"]],
["hrowend=I<string>" => ["Specify the text placed at the end of each header row [default: same as rowend]"]],
["tablebegin=I<string>" => ["Specify the text placed at the beginning of each table [default: '']"]],
["tablesep=I<string>" => ["Specify the text used to separate tables [default: '\\n']"]],
["tableend=I<string>" => ["Specify the text placed at the end of each table [default: '']"]],
["quote=I<string>" => ["Specify the text used to begin quoted text [default: '\"']"]],
["unquote=I<string>" => ["Specify the text used to end quoted text [default: same as quote]"]],
["excel" => ["Output strings in a format readable by Microsoft Excel"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]],
["tsv" => ["Output each table in tab-separated-value format",
[["noheaders" => ["Do not output column headers"]],
["colbegin=I<string>" => ["Specify the text placed at the beginning of each data column [default: '']"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: '\\t']"]],
["colend=I<string>" => ["Specify the text placed at the end of each data column [default: '']"]],
["rowbegin=I<string>" => ["Specify the text placed at the beginning of each data row [default: '']"]],
["rowsep=I<string>" => ["Specify the text used to separate data rows [default: '']"]],
["rowend=I<string>" => ["Specify the text placed at the end of each data row [default: '\\n']"]],
["hcolbegin=I<string>" => ["Specify the text placed at the beginning of each header column [default: same as colbegin]"]],
["hcolsep=I<string>" => ["Specify the text used to separate header columns [default: same as colsep]"]],
["hcolend=I<string>" => ["Specify the text placed at the end of each header column [default: same as colend]"]],
["hrowbegin=I<string>" => ["Specify the text placed at the beginning of each header row [default: same as rowbegin]"]],
["hrowsep=I<string>" => ["Specify the text used to separate header rows [default: same as rowsep]"]],
["hrowend=I<string>" => ["Specify the text placed at the end of each header row [default: same as rowend]"]],
["tablebegin=I<string>" => ["Specify the text placed at the beginning of each table [default: '']"]],
["tablesep=I<string>" => ["Specify the text used to separate tables [default: '\\n']"]],
["tableend=I<string>" => ["Specify the text placed at the end of each table [default: '']"]],
["quote=I<string>" => ["Specify the text used to begin quoted text [default: '\"']"]],
["unquote=I<string>" => ["Specify the text used to end quoted text [default: same as quote]"]],
["excel" => ["Output strings in a format readable by Microsoft Excel"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]],
["html" => ["Output each table in HTML table format",
[["noheaders" => ["Do not output column headers"]],
["colbegin=I<string>" => ["Specify the text placed at the beginning of each data column [default: '<td>']"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: ' ']"]],
["colend=I<string>" => ["Specify the text placed at the end of each data column [default: '</td>']"]],
["rowbegin=I<string>" => ["Specify the text placed at the beginning of each data row [default: '<tr>']"]],
["rowsep=I<string>" => ["Specify the text used to separate data rows [default: '']"]],
["rowend=I<string>" => ["Specify the text placed at the end of each data row [default: '</tr>\\n']"]],
["hcolbegin=I<string>" => ["Specify the text placed at the beginning of each header column [default: '<th>']"]],
["hcolsep=I<string>" => ["Specify the text used to separate header columns [default: same as colsep]"]],
["hcolend=I<string>" => ["Specify the text placed at the end of each header column [default: '</th>']"]],
["hrowbegin=I<string>" => ["Specify the text placed at the beginning of each header row [default: same as rowbegin]"]],
["hrowsep=I<string>" => ["Specify the text used to separate header rows [default: same as rowsep]"]],
["hrowend=I<string>" => ["Specify the text placed at the end of each header row [default: same as rowend]"]],
["tablebegin=I<string>" => ["Specify the text placed at the beginning of each table [default: '<table>\\n']"]],
["tablesep=I<string>" => ["Specify the text used to separate tables [default: '']"]],
["tableend=I<string>" => ["Specify the text placed at the end of each table [default: '</table>\\n']"]],
["quote=I<string>" => ["Specify the text used to begin quoted text [default: '']"]],
["unquote=I<string>" => ["Specify the text used to end quoted text [default: same as quote]"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]],
["gnuplot" => ["Output each table as a gnuplot data file",
[["noheaders" => ["Do not output column headers"]],
["colbegin=I<string>" => ["Specify the text placed at the beginning of each data column [default: '']"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: ' ']"]],
["colend=I<string>" => ["Specify the text placed at the end of each data column [default: '']"]],
["rowbegin=I<string>" => ["Specify the text placed at the beginning of each data row [default: '']"]],
["rowsep=I<string>" => ["Specify the text used to separate data rows [default: '']"]],
["rowend=I<string>" => ["Specify the text placed at the end of each data row [default: '\\n']"]],
["hcolbegin=I<string>" => ["Specify the text placed at the beginning of each header column [default: same as colbegin]"]],
["hcolsep=I<string>" => ["Specify the text used to separate header columns [default: same as colsep]"]],
["hcolend=I<string>" => ["Specify the text placed at the end of each header column [default: same as colend]"]],
["hrowbegin=I<string>" => ["Specify the text placed at the beginning of each header row [default: '# '"]],
["hrowsep=I<string>" => ["Specify the text used to separate header rows [default: same as rowsep]"]],
["hrowend=I<string>" => ["Specify the text placed at the end of each header row [default: same as rowend]"]],
["tablebegin=I<string>" => ["Specify the text placed at the beginning of each table [default: '']"]],
["tablesep=I<string>" => ["Specify the text used to separate tables [default: '\\n\\n']"]],
["tableend=I<string>" => ["Specify the text placed at the end of each table [default: '']"]],
["quote=I<string>" => ["Specify the text used to begin quoted text [default: '\"']"]],
["unquote=I<string>" => ["Specify the text used to end quoted text [default: same as quote]"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]],
["octave" => ["Output each table as an Octave text-format data file",
[["noheaders" => ["Do not output column headers"]],
["colbegin=I<string>" => ["Specify the text placed at the beginning of each data column [default: '']"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: '']"]],
["colend=I<string>" => ["Specify the text placed at the end of each data column [default: '\\n']"]],
["rowbegin=I<string>" => ["Specify the text placed at the beginning of each data row [default: '']"]],
["rowend=I<string>" => ["Specify the text placed at the end of each data row [default: '']"]],
["hcolbegin=I<string>" => ["Specify the text placed at the beginning of each header column [default: '']"]],
["hcolsep=I<string>" => ["Specify the text used to separate header columns [default: '_']"]],
["hcolend=I<string>" => ["Specify the text placed at the end of each header column [default: '']"]],
["hrowbegin=I<string>" => ["Specify the text placed at the beginning of each header row [default: '# ']"]],
["hrowsep=I<string>" => ["Specify the text used to separate header rows [default: '']"]],
["hrowend=I<string>" => ["Specify the text placed at the end of each header row [default: '\\n']"]],
["tablebegin=I<string>" => ["Specify the text placed at the beginning of each table [default: '']"]],
["tablesep=I<string>" => ["Specify the text used to separate tables [default: '\\n']"]],
["tableend=I<string>" => ["Specify the text placed at the end of each table [default: '']"]],
["quote=I<string>" => ["Specify the text used to begin quoted text [default: '']"]],
["unquote=I<string>" => ["Specify the text used to end quoted text [default: same as quote]"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]],
["custom" => ["Output each table in a completely user-specified format",
[["noheaders" => ["Do not output column headers"]],
["colbegin=I<string>" => ["Specify the text placed at the beginning of each data column [default: '']"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: '']"]],
["colend=I<string>" => ["Specify the text placed at the end of each data column [default: '']"]],
["rowbegin=I<string>" => ["Specify the text placed at the beginning of each data row [default: '']"]],
["rowsep=I<string>" => ["Specify the text used to separate data rows [default: '']"]],
["rowend=I<string>" => ["Specify the text placed at the end of each data row [default: '']"]],
["hcolbegin=I<string>" => ["Specify the text placed at the beginning of each header column [default: same as colbegin]"]],
["hcolsep=I<string>" => ["Specify the text used to separate header columns [default: same as colsep]"]],
["hcolend=I<string>" => ["Specify the text placed at the end of each header column [default: same as colend]"]],
["hrowbegin=I<string>" => ["Specify the text placed at the beginning of each header row [default: same as rowbegin]"]],
["hrowsep=I<string>" => ["Specify the text used to separate header rows [default: same as rowsep]"]],
["hrowend=I<string>" => ["Specify the text placed at the end of each header row [default: same as rowend]"]],
["tablebegin=I<string>" => ["Specify the text placed at the beginning of each table [default: '']"]],
["tablesep=I<string>" => ["Specify the text used to separate tables [default: '']"]],
["tableend=I<string>" => ["Specify the text placed at the end of each table [default: '']"]],
["quote=I<string>" => ["Specify the text used to begin quoted text [default: '']"]],
["unquote=I<string>" => ["Specify the text used to end quoted text [default: same as quote]"]],
["excel" => ["Output strings in a format readable by Microsoft Excel"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]],
["latex" => ["Output each table as a LaTeX tabular environment",
[["dcolumn" => ["Use the dcolumn package to align numbers on the decimal point"]],
["booktabs" => ["Use the booktabs package for a more professionally typeset look"]],
["longtable" => ["Use the longtable package to enable multi-page tables"]],
["keep-columns=I<string>" => ["Enumerate the columns that should be included in the output [default: all columns]"]],
["merge=I<function>" => ["Specify how to merge data from multiple files [default: 'mean']"]],
["showfnames=I<option>" => ["Add an extra header row showing the filename the data came from [default: 'none']"]]]]]]]],
["params" => ["Extract the program's run-time parameters and environment variables",
[["text" => ["Output the parameters in plain-text format",
[["include=I<filename>" => ["Read from a file the list of keys to output"]],
["exclude=I<regexp>" => ["Ignore any keys whose name matches a regular expression"]],
["sort" => ["Sort the list of parameters alphabetically by key"]],
["noenv" => ["Exclude environment variables"]],
["noparams" => ["Exclude run-time parameters"]],
["envformat=I<template>" => ["Format environment variable names using the given template [default: '%s (environment variable)']"]],
["columns=I<number>" => ["Output the parameters as a 1-, 2-, or 3-column table [default: 1]"]],
["colsep=I<string>" => ["Specify the text used to separate data columns [default: ': ']"]],
["rowbegin=I<string>" => ["Specify the text that's output at the start of each data row [default: '']"]],
["rowend=I<string>" => ["Specify the text that's output at the end of each data row [default: '\\n']"]]]]],
["dumpkeys" => ["Output a list of the keys only (i.e., no values)",
[["include=I<filename>" => ["Read the list of parameters to output from a given file"]],
["exclude=I<regexp>" => ["Ignore any keys whose name matches a regular expression"]],
["envformat=I<template>" => ["Format environment variable names using the given template [default: '%s (environment variable)']"]],
["sort" => ["Sort the list of parameters alphabetically by key"]],
["noenv" => ["Exclude environment variables"]],
["noparams" => ["Exclude run-time parameters"]]]]],
["latex" => ["Output the parameters as a LaTeX tabular environment",
[["include=I<filename>" => ["Read from a file the list of keys to output"]],
["exclude=I<regexp>" => ["Ignore any keys whose name matches a regular expression"]],
["envformat=I<template>" => ["Format environment variable names using the given template [default: '%s (environment variable)']"]],
["sort" => ["Sort the list of parameters alphabetically by key"]],
["booktabs" => ["Use the booktabs package for a more professionally typeset look"]],
["tabularx" => ["Use the tabularx package to enable line wraps within the value column"]],
["longtable" => ["Use the longtable package to enable multi-page tables"]],
["noenv" => ["Exclude environment variables"]],
["noparams" => ["Exclude run-time parameters"]]]]]]]],
["env" => ["Extract the environment in which the program was run",
[["sh" => ["Use Bourne shell syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]],
["bash" => ["Use Bourne Again shell syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]],
["ksh" => ["Use Korn shell syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]],
["csh" => ["Use C shell syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]],
["zsh" => ["Use Z shell syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]],
["tcsh" => ["Use tcsh syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]],
["ash" => ["Use ash syntax for setting environment variables",
[["newlines" => ["Separate commands with newlines instead of semicolons"]],
["unset" => ["Unset all other environment variables"]],
["chdir" => ["Switch to the program's original working directory"]]]]]]]],
["source" => ["Extract coNCePTuaL source code",
[["text" => ["Output the source code in plain-text format",
[["linebegin=I<string>" => ["Specify the text placed at the beginning of each line [default: '']"]],
["lineend=I<string>" => ["Specify the text placed at the end of each line [default: '\\n']"]],
["kwbegin=I<string>" => ["Specify the text placed before each keyword [default: '']"]],
["kwend=I<string>" => ["Specify the text placed after each keyword [default: '']"]],
["strbegin=I<string>" => ["Specify the text placed before each string [default: '']"]],
["strend=I<string>" => ["Specify the text placed after each string [default: '']"]],
["combegin=I<string>" => ["Specify the text placed before each comment [default: '']"]],
["comend=I<string>" => ["Specify the text placed after each comment [default: '']"]],
["indent=I<number>" => ["Indent each line by a given number of spaces"]],
["wrap=I<number>" => ["Wrap the source code into a paragraph with a given character width"]]]]]]]],
["warnings" => ["Extract a list of warnings the program issued during initialization",
[["text" => ["Output warnings in plain-text format",
[["listbegin=I<string>" => ["Specify text to appear at the beginning of the list [default: '']"]],
["listend=I<string>" => ["Specify text to appear at the end of the list [default: '']"]],
["itembegin=I<string>" => ["Specify text to appear before each warning [default: '* ']"]],
["itemend=I<string>" => ["Specify text to appear after each warning [default: '\\n']"]]]]],
["html" => ["Output warnings as an HTML list",
[["listbegin=I<string>" => ["Specify text to appear at the beginning of the list [default: '<ul>\\n']"]],
["listend=I<string>" => ["Specify text to appear at the end of the list [default: '</ul>\\n']"]],
["itembegin=I<string>" => ["Specify text to appear before each warning [default: ' <li>']"]],
["itemend=I<string>" => ["Specify text to appear after each warning [default: '</li>\\n']"]]]]],
["latex" => ["Output warnings as a LaTeX list",
[["listbegin=I<string>" => ["Specify text to appear at the beginning of the list [default: '\\begin{itemize}\\n']"]],
["listend=I<string>" => ["Specify text to appear at the end of the list [default: '\\end{itemize}\\n']"]],
["itembegin=I<string>" => ["Specify text to appear before each warning [default: ' \\item ']"]],
["itemend=I<string>" => ["Specify text to appear after each warning [default: '\\n']"]]]]]]]]);
###########################################################################
# Define a list of coNCePTuaL keywords. The following was
# automatically inserted into ncptl-logextract by configure.
my @keyword_list = qw (
@LOGEXTRACT_KEYWORDS@
);
###########################################################################
# We'd like our POD documentation to show ncptl-logextract's
# command-line options as a tree because many options are meaningful
# only when another option is also used. The following function
# automatically generates an options tree as a nested list and splices
# it into ncptl-logextract, outputting a modified ncptl-logextract
# file with the updated POD documentation.
sub output_options_tree ()
{
my @newpod;
# Produce a POD version of the tree.
push @newpod, "Z<>Z<>Z<>Z<>Z<>"; # Placeholder
foreach my $extract (@arguments) {
my $ename = $extract->[0];
my $edesc = $extract->[1][0];
push @newpod, "=over 4" if $extract==$arguments[0];
push @newpod, "=item C<--extract=$ename>";
$newpod[$#newpod] .= " [default] " if $extract==$arguments[0];
push @newpod, $edesc;
my @formats = @{$extract->[1][1]};
foreach my $fmt (@formats) {
my $fname = $fmt->[0];
my $fdesc = $fmt->[1][0];
push @newpod, "=over 4" if $fmt==$formats[0];
push @newpod, "=item C<--format=$fname>";
$newpod[$#newpod] .= " [default] " if $fmt==$formats[0];
push @newpod, $fdesc;
my @options = @{$fmt->[1][1]};
foreach my $opt (@options) {
my $oname = $opt->[0];
$oname =~ s/=(I<([^>]+))>/=>$1/;
my $odesc = $opt->[1][0];
$odesc =~ s/</LESSTHAN/g;
$odesc =~ s/>/GREATERTHAN/g;
$odesc =~ s/LESSTHAN/E<lt>/g;
$odesc =~ s/GREATERTHAN/E<gt>/g;
$odesc =~ s/\\[nt]/\\$&/g;
$odesc =~ s/default: \'([^\']*)\'/default: S<\"C<$1>\">/;
push @newpod, "=over 4" if $opt==$options[0];
push @newpod, "=item C<--$oname>";
push @newpod, $odesc;
}
push @newpod, "=back";
}
push @newpod, "=back";
}
push @newpod, "=back";
@newpod = map {($_, "")} @newpod;
push @newpod, "Z<>Z<>Z<>"; # Placeholder
# Read our own source code and replace the old POD with the new POD.
open (SELF, "<$0") || die "${progname}: unable to open $0 ($!)\n";
my $oneline;
while (defined($oneline=<SELF>) &&
(chomp $oneline, $oneline) ne $newpod[0]) {
print $oneline, "\n";
}
while (defined($oneline=<SELF>) &&
(chomp $oneline, $oneline) ne $newpod[$#newpod]) {
}
print join ("\n", @newpod), "\n";
print <SELF>;
close SELF;
}
# ncptl-logextract's tree of options is rather complex. Output a
# poster in AT&T's "dot" format.
sub output_options_as_dot ()
{
my @extractnodes; # Names/labels/shapes corresponding to --extract
my @formatnodes; # Same for --format
my @optionnodes; # Same for options
my $numnodes = 0; # Unique node identifier
# Output a graph header.
open (OUTFILE, ">$outfile") || die "${progname}: unable to write to $outfile ($!)\n";
print OUTFILE "digraph logextract_options
{
/* Select an ISO A0 page size. */
page=\"33,46.75\";
orientation=landscape;
size=\"44.75,31\";
overlap=scale;
center=true;
label=\"ncptl-logextract command-line options\";
fontsize=72;
";
# Walk the arguments tree, building up nodes as we go.
foreach my $extract (@arguments) {
my $ename = $extract->[0];
my $edesc = $extract->[1][0];
my $enode = sprintf "e%d", ++$numnodes;
push @extractnodes, [$enode, $ename,
$extract==$arguments[0] ? "doublecircle" : "circle"];
my @formats = @{$extract->[1][1]};
foreach my $fmt (@formats) {
my $fname = $fmt->[0];
my $fdesc = $fmt->[1][0];
my $fnode = sprintf "f%d", ++$numnodes;
push @formatnodes, [$fnode, $fname,
$fmt==$formats[0] ? "doubleoctagon" : "octagon"];
my @options = @{$fmt->[1][1]};
foreach my $opt (@options) {
my $oname = $opt->[0];
$oname =~ s/=I.*$//;
my $odesc = $opt->[1][0];
$odesc =~ s/ \[default.*//;
my $onode = sprintf "o%d", ++$numnodes;
push @optionnodes, [$onode, $oname, "box"];
}
}
}
# Output all of the nodes.
print OUTFILE " /* Values for --extract */
{
";
foreach my $enode (@extractnodes) {
printf OUTFILE (" %s [label=%s, shape=%s];\n",
$enode->[0], $enode->[1], $enode->[2]);
}
print OUTFILE " }\n\n";
print OUTFILE " /* Values for --format */
{
";
foreach my $fnode (@formatnodes) {
printf OUTFILE (" %s [label=%s, shape=%s];\n",
$fnode->[0], $fnode->[1], $fnode->[2]);
}
print OUTFILE " }\n\n";
print OUTFILE " /* Options */
{
";
foreach my $onode (@optionnodes) {
printf OUTFILE (" %s [label=%s, shape=%s];\n",
$onode->[0], $onode->[1], $onode->[2]);
}
print OUTFILE " }\n\n";
# Walk the arguments tree again, outputting edges as we go.
$numnodes = 0;
print OUTFILE " /* Edges */\n";
foreach my $extract (@arguments) {
my $enode = sprintf "e%d", ++$numnodes;
my @formats = @{$extract->[1][1]};
foreach my $fmt (@formats) {
my $fnode = sprintf "f%d", ++$numnodes;
print OUTFILE " $enode -> $fnode;\n";
my @options = @{$fmt->[1][1]};
foreach my $opt (@options) {
my $onode = sprintf "o%d", ++$numnodes;
print OUTFILE " $fnode -> $onode;\n";
}
}
}
# Create a top-level "command line" node.
print OUTFILE "
/* Top-level node and its edges */
root [label=\"ncptl-logextract\\ncommand line\",
shape=diamond,style=bold,height=3,width=3,fontsize=28];
root -> {",
join("; ", map {$_->[0]} @extractnodes),
"}\n";
# Output a graph trailer.
print OUTFILE "}\n";
close OUTFILE;
}
# Output the ncptl-logextract documentation as a DHTML file
# (ncptl-logextract.html).
sub output_dhtml_documentation ()
{
my $htmlfilename = "${progname}.html";
# Create an initial ncptl-logextract.html file.
pod2html("--infile=$0",
"--outfile=$htmlfilename",
"--noindex");
# Read the HTML file into memory.
open (HTMLFILE, "<$htmlfilename") || die "${progname}: unable to open $htmlfilename ($!)\n";
my $entirefile = join ("", <HTMLFILE>);
close HTMLFILE;
# Remove characters from anchor names that the HTML verifies rejects.
my @substitutions;
while ($entirefile =~ /\"[^\"]*\"/g) {
my $oldname = $&;
my $newname = $oldname;
$newname =~ s/[\%\s]/_/g;
push @substitutions, [$oldname => $newname];
}
foreach my $subst (@substitutions) {
$entirefile =~ s/$subst->[0]/$subst->[1]/g;
}
# Remove the index anchor because it (a) not used and (b) breaks
# compatibility with the XHTML 1.1 Strict standard.
$entirefile =~ s|<A NAME="__index__"></A>||;
# Pretty-print "coNCePTuaL". The trick is that this needs to be
# only within the HTML body and not within a <PRE>...</PRE> block.
my ($header, $bodytag, $body) = split "(<BODY>)", $entirefile;
my @pre_nopre = split m|(<PRE>.*?</PRE>)|s, $body;
for (my $p=0; $p<=$#pre_nopre; $p+=2) {
$pre_nopre[$p] =~ s|coNCePTuaL|<span class="ncptl">coNCePTuaL</span>|gs;
}
$entirefile = $header . $bodytag . join("", @pre_nopre);
# Pretty-print "LaTeX".
$entirefile =~ s|LaTeX|L<span class="highA">a</span>T<span class="lowE">e</span>X|g;
# Replace double quotes with <q>...</q>.
$entirefile =~ s|\`\`|<q>|g;
$entirefile =~ s|\'\'|</q>|g;
# Keep HTML Tidy from removing empty <q></q> pairs. In the future
# we might want to insert a thin space ( ) although some
# browsers render thin spaces as full spaces, which is visually
# confusing in the given context.
$entirefile =~ s|<q><CODE></CODE></q>|<q><!-- Empty --></q>|g;
# Remove the LINK REV tag and insert a META tag for HTML content-type.
$entirefile =~ s|<LINK REV=\"made\".*?>|<META http-equiv="Content-Type" content="text/html; charset=utf-8">|g;
# Insert the core DHTML mechanisms at the end of the HTML header.
$entirefile =~ s|</HEAD>|<<DHTML|e;
<style type="text/css">
//<![CDATA[
body {
background: white;
color: black;
}
h1 {
color: rgb(0, 64, 0);
}
h2 {
color: rgb(80, 60, 15);
}
/* Present a button for expanding or collapsing the entire
* hierarchical list. */
.list_button {
color: rgb(0, 0, 127);
background: rgb(225, 255, 225);
font-weight: bold;
border: medium outset green;
padding: 1ex;
margin: 3ex 1em 2ex 1em;
text-decoration: none;
}
.list_button:hover {
background: yellow;
}
/* Present a hyperlink for toggling the display of sublists. */
.toggleMe {
color: rgb(0, 0, 127);
}
.toggleMe:hover {
background: yellow;
}
/* Help typeset the coNCePTuaL logogram. */
.ncptl {
font-variant: small-caps;
}
/* Typeset the LaTeX logogram. */
.lowE {
position: relative;
top: 0.5ex;
text-transform: uppercase;
margin-left: -0.1667em;
margin-right: -0.125em
}
.highA {
position: relative;
top: -0.5ex;
text-transform: uppercase;
margin-left: -0.40em;
margin-right: -0.15em;
font-size: smaller
}
//]]>
</style>
<script type="text/javascript">
//<![CDATA[
// Given the ID of a <DL> node, make the node visible if it's
// invisible and invisible if it's visible.
function toggleDL (id)
{
dlNode = document.getElementById (id);
if (dlNode.style.display == "none")
dlNode.style.display = "block";
else
dlNode.style.display = "none";
}
var nextId = 0; // Next ID to assign to a DL node.
var linkNode; // Hyperlink to create in a DD node and use in a DT node.
// Given a <DL> node and a flag, make each child <DT> node's contents
// control the visiblility of any <DL> nodes nested within the
// corresponding <DD> node.
function makeListDynamic (node, expandNodes)
{
var kids = node.childNodes; // List of all our child nodes
var oldLinkNode; // Value of linkNode for DL to save/restore
var k;
try {
for (k=0; k<kids.length; k++) {
switch (kids[k].nodeName) {
case "DL":
// We were called initially from the <body> tag's onload script.
if (!kids[k].getAttribute("id")) {
try {
var dlID = "ulId" + ++nextId;
kids[k].setAttribute ("id", dlID);
oldLinkNode = linkNode;
linkNode.setAttribute ("class", "toggleMe");
linkNode.addEventListener ("click", new Function ('toggleDL ("' + dlID + '");'), false);
toggleDL (dlID);
}
catch (problem) {
// Some browsers support style but not getAttribute().
kids[k].style.display = "none";
}
}
else
// We were called initially by "Expand all" or "Collapse all".
if (expandNodes)
kids[k].style.display = "block";
else
kids[k].style.display = "none";
break;
case "#text":
// Store in a global variable because we need to pass the
// <A> node (node.parentNode) from the current <DT> ancestor to
// its <DD> sibling. (If we were passing between parents and
// children, we could use a function parameter instead.)
if (node.nodeName == "CODE" && kids[k].nodeValue.substr(0,2) == "--")
linkNode = node.parentNode;
break;
}
// Invoke ourself recursively for each child node.
makeListDynamic (kids[k], expandNodes);
if (kids[k].nodeName == "DL")
linkNode = oldLinkNode;
}
}
catch (problem) {
// Keep the browser happy.
}
}
//]]>
</script>
</HEAD>
DHTML
# Tell the browser to invoke makeListDynamic() on initialization
# and indicate which list should be made dynamic.
$entirefile =~ s|<BODY>|<BODY onload='javascript:makeListDynamic(document.getElementById("collapseList"), 0)'>|;
$entirefile =~ s|(format-specific options):(.*?)<DL>|<<LISTBUTTONS|se;
$1.
Click on any <code>--extract</code> or <code>--format</code> option
below to toggle the display of the options that depend on it (i.e.,
the options lying deeper in the option hierarchy) or use the <q>Expand
all</q> button to open every level of the hierarchy, making it easy to
search the page; <q>Collapse all</q> resets the hierarchy to its
initial, fully collapsed state. Note that these interactivity
features will not work completely or at all in Web browsers lacking
sufficient support of the <a
href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript</a>,
<a href="http://www.w3.org/Style/CSS/">CSS</a>, and <a
href="http://www.w3.org/DOM/">W3C DOM</a> standards.
<div style="margin-top: 5ex; margin-bottom: 4ex;">
<a class="list_button" href='javascript:makeListDynamic(document.getElementById("collapseList"),1)'>Expand all</a>
<a class="list_button" href='javascript:makeListDynamic(document.getElementById("collapseList"),0)'>Collapse all</a>
</div>
<DL id="collapseList">
LISTBUTTONS
# Write the resulting HTML file to disk.
open (HTMLFILE, ">$htmlfilename") || die "${progname}: unable to open $htmlfilename for writing ($!)\n";
print HTMLFILE $entirefile;
close HTMLFILE;
}
###########################################################################
# Extract the complete coNCePTuaL source program from a log file.
sub extract_source (\@)
{
# Extract the source code from a log file.
my @sourcecode;
my $state = "need title1";
foreach my $oneline (@{$_[0]}) {
$state eq "need title1" && $oneline =~ /^\# coNCePTuaL source code/o && do {
$state = "need title2";
next;
};
$state eq "need title2" && $oneline =~ /^\# ----------------------/o && do {
$state = "need code";
next;
};
$state eq "need code" && $oneline =~ /^\# /o && do {
$oneline = substr($oneline, 6);
push @sourcecode, $oneline;
next;
};
$state eq "need code" && last;
}
# Strip leading and trailing blank lines and return the result.
return () if !@sourcecode;
while ($sourcecode[0] eq "") {
shift @sourcecode;
}
while ($sourcecode[$#sourcecode] eq "") {
pop @sourcecode;
}
return @sourcecode;
}
# Extract all of the program parameters and run-time characteristics
# from a log file. Return environment variables separately from
# non-environment variables.
sub extract_parameters (\@)
{
my @envvars; # List of environment variables
my @parameters; # List of everything else
my $storingenvs = 0; # 1=currently storing environment variables
foreach my $oneline (@{$_[0]}) {
$storingenvs=1, next if $oneline eq "# Environment variables";
next if $oneline =~ /^\# ---------------------$/;
$storingenvs=0, next if $oneline !~ /^\# ([^:]+): (.*)$/o;
next if $1 eq "WARNING"; # For now, always ignore warning messages.
if ($storingenvs) {
push @envvars, [$1, $2];
}
else {
push @parameters, [$1, $2];
}
}
return (\@parameters, \@envvars);
}
# Extract a list of warning messages from a log file.
sub extract_warnings (\@)
{
my @warnings;
foreach my $oneline (@{$_[0]}) {
next if $oneline !~ /^\# ([^:]+): (.*)$/;
push @warnings, $2 if $1 eq "WARNING";
}
return @warnings;
}
# Extract a list of data tables from the log file. Each table is a
# 2-D array, the first two rows of which are headers strings.
sub extract_data (\@)
{
my @datatables; # List of all the tables in the data file
my ($row, $col) = (-1, -1); # Offset into @currenttable
my @entirefile = @{$_[0]}; # All lines of the log file
my $lineno; # Current line number to read
my $oneline; # Contents of line number $lineno
# Skip the log-file prologue.
for ($lineno=0; $lineno<=$#entirefile; $lineno++) {
$oneline = $entirefile[$lineno];
last if $oneline !~ /^#/;
}
# Process the remaining lines in the log file. Although the loop
# progresses line by line, note that the loop body increments the
# loop variable, so the loop is really progressing table-by-table.
while ($lineno <= $#entirefile) {
my @currenttable; # A 2-D array of data values
# Skip the blank lines between tables.
while ($oneline !~ /\S/) {
$oneline = $entirefile[++$lineno];
}
# Process header lines (always a single description line
# followed by a single aggregation-type line).
for (0 .. $numheaderrows-1) {
$row++;
$col = 0;
while ($oneline=~/(?<!\\)\"(.*?)(?<!\\)\"/go) {
$currenttable[$row][$col++] = $1;
}
$oneline = $entirefile[++$lineno]; # Next header line
}
# Process data lines.
$oneline = $entirefile[$lineno]; # First data line
while ($oneline =~ /^[-0-9.,]/o) {
$currenttable[++$row] = [split /,/, $oneline, -1];
$oneline = $entirefile[++$lineno]; # Next data line
}
# Store the current table.
push @datatables, \@currenttable;
$row = -1;
last if $oneline =~ /^\#/; # End of the log file
}
# Return the resulting list of tables.
return @datatables;
}
# Force garbage collection. I don't know if eval necessarily achives
# this goal but it seems to work in Perl v5.8.4, at least.
sub collect_garbage ()
{
print STDERR "Cleaning up ... " if $verbose > 1;
eval 'my $dummy = 123;';
print STDERR "done.\n" if $verbose > 1;
}
# Given a completion fraction in [0, 1], output a progress percentage
# but only if it's changed from before. Given a string, output it
# verbatim followed by a newline character.
my $progress_string = "?????";
sub output_progress ($)
{
my $new_string; # Formatting string to output
my $final_string; # 0=number; 1=final, textual message
if ("$_[0]" =~ /[^-+Ee.\d]/o) {
$final_string = 1;
$new_string = sprintf "%-6s\n", $_[0];
}
else {
$final_string = 0;
$new_string = sprintf "%5.1f%%", 100.0*$_[0];
}
if ($progress_string ne $new_string) {
$progress_string = $new_string;
print STDERR $progress_string;
if ($final_string) {
$progress_string = "?????";
}
else {
print STDERR "\b" x 6;
}
}
}
# Add an extra header row to each data table listing the filename that
# produced it.
sub append_file_header ($\@)
{
# Input parameters include a filename and the file's complete contents.
my $filename = shift;
my @oldfiledata;
# If we have nothing to do, return the input file as is.
my $fileheader = find_option ("showfnames", "first", "none");
return $_[0] if $fileheader eq "none";
if ($fileheader !~ /^all|first$/) {
die "${progname}: unknown filename-header type \"$fileheader\"\n";
}
$numheaderrows = 3;
# Process the file line-by-line.
print STDERR "Appending \"$filename\" to table headers ... " if $verbose;
my @newfiledata; # Modified file contents
my $newtable = 1; # 1=we're at the start of a new table
my $cleanfname = $filename; # Filename with certain characters escaped
$cleanfname =~ s/[\"\\]/\\$&/g;
@oldfiledata = @{$_[0]};
foreach my $lineno (0 .. $#oldfiledata) {
output_progress $lineno/$#oldfiledata if $verbose;
if (substr($oldfiledata[$lineno], 0, 1) ne "#") {
# Add an extra header line if we're at the start of a new table.
if ($newtable) {
# Calculate the number of columns per table.
my $numcols = () = $oldfiledata[$lineno] =~ /(?<!\\)\".*?(?<!\\)\"/go;
# Depending on the value of $fileheader, we prepend a
# header to the top of each column or at the top of
# the first column only.
my @extraheader;
push @extraheader, $cleanfname;
if ($fileheader eq "all") {
push @extraheader, ($cleanfname) x ($numcols-1);
}
else {
push @extraheader, ("") x ($numcols-1);
}
push @newfiledata, join (",",
map {"\"$_\""} @extraheader);
$newtable = 0;
}
$newtable=1 if $oldfiledata[$lineno] !~ /\S/;
}
# Copy the current line from the original file to the modified file.
push @newfiledata, $oldfiledata[$lineno];
}
output_progress "done." if $verbose;
# Return the modified file contents.
return \@newfiledata;
}
# Older versions of Perl (e.g., v5.6.0) lack the File::Temp module.
# Try to compensate.
my @tempdirlist; # List of directories to delete on exit
sub create_temp_dir ($)
{
my $template = $_[0];
# First try the more robust File::Temp::tempdir() call.
eval "use File::Temp qw(tempdir)";
return tempdir ($template, CLEANUP => 1, TMPDIR => 1) if !$@;
# Fall back on POSIX::tmpnam().
my $tmpdirname = tmpnam();
mkdir $tmpdirname || die "${progname}: Unable to create $tmpdirname ($!)\n";
push @tempdirlist, $tmpdirname;
return $tmpdirname;
}
END {
# Remove all temporary directories when the program exits.
foreach my $tmpdirname (@tempdirlist) {
foreach my $fname (glob File::Spec->catfile($tmpdirname, "*")) {
unlink $fname;