-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathedcdsect.sh
executable file
·114 lines (95 loc) · 2.42 KB
/
edcdsect.sh
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
#!/bin/env bash
#
# EDCDSECT USS invocation. 'edcdsect.sh -h' for help (see below)
#
syntax()
{
printf '%s\n' "edcdsect is a utility for generating C structure mappings for Assembler DSECTs
Usage: edcdsect [OPTION] [PARAMETERS]...
Options:
-h, --help display this help and exit.
-v, --verbose run in verbose mode.
Parameters:
<file> The assembler file to process
Examples:
Process a single macro DCBD into a structure:
echo 'IHADCB DCBD' | edcdsect.sh
Process an assembler file dcbd.s into a structure:
edcdsect.sh dcbd.s
"
}
verbose=false
if [ $# -gt 0 ]; then
if [ "$1" = "-h" ] || [ "$1" = '--help' ]; then
syntax
exit 0
fi
if [ "$1" = "-v" ] || [ "$1" = '--verbose' ]; then
verbose=true
shift
fi
fi
if [ $# -gt 0 ]; then
if [ -e "$1" ]; then
input="$1"
else
printf 'Unable to open %s for read.\n' "$1" >&2
syntax
exit 4
fi
else
if [ -t 0 ]; then
printf 'Need to specify assembler code to process.\n' >&2
syntax
exit 4
fi
fi
struct_name=''
if [ "${input}" != "" ]; then
source=$(cat "${input}")
else
source=""
OLDIFS="$IFS"
IFS=''
while read line; do
source="${source}
${line}"
done </dev/stdin
IFS="$OLDIFS"
fi
compiler="CBC.SCCNCMP"
asm='ASMA90'
asm_opts='SUPRWARN(425,434),GOFF,ADATA,NOTERM,NODECK,NOOBJECT,LIST'
sysadata=$(mvstmp $(hlq))
drm -f "${sysadata}"
if ! dtouch -rvb -l8144 -tseq "${sysadata}" ; then
printf 'Unable to allocate SYSADATA temporary dataset %s' "${sysadata}"
exit 4
fi
listing=$(printf '%s\n' "${source}" | mvscmd --pgm="${asm}" --args="${asm_opts}" --syslib=SYS1.MACLIB --sysadata="${sysadata}" --sysin=stdin --sysprint=* --syspunch=DUMMY --syslin=DUMMY)
rc=$?
if [ $rc -gt 4 ] ; then
printf '%s\n' "${listing}"
exit $rc
fi
if ${verbose} ; then
printf 'Assembler Listing:\n%s\n' "${listing}" >&2
fi
tmp_output=$(mvstmp $(hlq))
drm -f "${tmp_output}"
if ! dtouch -rvb -l137 -tseq "${tmp_output}" ; then
printf 'Unable to allocate DSECT temporary output dataset %s' "${tmp_output}"
exit 4
fi
err=$(mvscmd --pgm=CCNEDSCT --args="SECT(${struct_name}),EQU,NODEF,UNNAMED" --steplib="${compiler}" --sysadata="${sysadata}" --edcdsect="${tmp_output}" --sysprint=stdout --sysout=stdout)
rc=$?
dcat "${tmp_output}"
if [ $rc -gt 0 ]; then
printf '%s\n' "${err}" >&2
exit $rc
fi
if ${verbose} ; then
printf 'CCNEDSCT Listing:\n%s\n' "${err}" >&2
fi
drm -f "${sysadata}"
drm -f "${tmp_output}"