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
|
include <error.h>
# TXTABLE -- Extract 2D tables from 3D table rows.
# Input tables are given by a filename template list. All row/column
# selection on input tables is performed by bracket-enclosed selectors
# appended to the file name. The output is either a matching list of
# tables or a directory. Output table names cannot have row/column
# selectors. Since one input table specification can generate multiple
# output tables, a naming scheme for these is defined as follows:
#
# - if output name is a directory:
# output table names are built from input table names appended with
# a _rXXX suffix, where XXX is the row number in the input file
# where the data comes from.
#
# - if output file name comes from a paired root file name list:
# same suffixing scheme as above, but using the root file name
# extracted from the list.
#
# - if only one row is selected:
# no suffixing takes place.
#
#
# This code is a re-use of B.Simon's 04-Nov-94 version of tcopy.
#
#
#
# Revision history:
# ----------------
#
# 22-Nov-96 - Task created (I.Busko)
# 03-Jan-97 - Revised after code review (IB)
procedure t_txtable()
char tablist1[SZ_LINE] # Input table list
char tablist2[SZ_LINE] # Output table list
bool compact # Put scalars in header ?
bool verbose # Print operations ?
char table1[SZ_PATHNAME] # Input table name
char table2[SZ_PATHNAME] # Output table name
char rootname[SZ_PATHNAME] # Root name
char dirname[SZ_PATHNAME] # Directory name
int list1, list2, root_len
pointer sp
int imtopen(), imtgetim(), imtlen()
int fnldir(), isdirectory()
bool clgetb(), streq()
begin
# Get input and output table template lists.
call clgstr ("intable", tablist1, SZ_LINE)
call clgstr ("outtable", tablist2, SZ_LINE)
compact = clgetb ("compact")
verbose = clgetb ("verbose")
# Check if the output string is a directory.
if (isdirectory (tablist2, dirname, SZ_PATHNAME) > 0 &&
!streq (tablist2, "STDOUT")) {
list1 = imtopen (tablist1)
while (imtgetim (list1, table1, SZ_PATHNAME) != EOF) {
call smark (sp)
# Place the input table name without a directory in
# string rootname.
call get_root (table1, table2, SZ_PATHNAME)
root_len = fnldir (table2, rootname, SZ_PATHNAME)
call strcpy (table2[root_len + 1], rootname, SZ_PATHNAME)
call strcpy (dirname, table2, SZ_PATHNAME)
call strcat (rootname, table2, SZ_PATHNAME)
iferr (call txtone (table1, table2, verbose, compact))
call erract (EA_WARN)
call sfree (sp)
}
call imtclose (list1)
} else {
# Expand the input and output table lists.
list1 = imtopen (tablist1)
list2 = imtopen (tablist2)
if (imtlen (list1) != imtlen (list2)) {
call imtclose (list1)
call imtclose (list2)
call error (1, "Number of input and output tables not the same")
}
# Expand each table.
while ((imtgetim (list1, table1, SZ_PATHNAME) != EOF) &&
(imtgetim (list2, table2, SZ_PATHNAME) != EOF)) {
call smark (sp)
if (streq (table1, table2)) {
call eprintf ("can't expand table to itself: %s\n")
call pargstr (table1)
next
}
iferr (call txtone (table1, table2, verbose, compact))
call erract (EA_WARN)
call sfree (sp)
}
call imtclose (list1)
call imtclose (list2)
}
end
|