1 /* HETINIT.C (c) Copyright Leland Lucius, 2000-2009 */
2 /* Creates IEHINITT or NL format Hercules Emulated Tapes*/
3
4 /*
5 || ----------------------------------------------------------------------------
6 ||
7 || HETINIT.C (c) Copyright Leland Lucius, 2000-2009
8 || Released under terms of the Q Public License.
9 ||
10 || Creates IEHINITT or NL format Hercules Emulated Tapes.
11 ||
12 || ----------------------------------------------------------------------------
13 */
14
15 #include "hstdinc.h"
16
17 #include "hercules.h"
18 #include "hetlib.h"
19 #include "sllib.h"
20 #include "herc_getopt.h"
21
22 /*
23 || Local constant data
24 */
25 static const char help[] =
26 "%s - Initialize a tape\n\n"
27 "Usage: %s [options] filename [volser] [owner]\n\n"
28 "Options:\n"
29 " -d disable compression\n"
30 " -h display usage summary\n"
31 " -i create an IEHINITT formatted tape (default: on)\n"
32 " -n create an NL tape\n";
33
34 /*
35 || Prints usage information
36 */
37 static void
usage(char * name)38 usage( char *name )
39 {
40 printf( help, name, name );
41 }
42
43 /*
44 || Subroutine to convert a null-terminated string to upper case
45 */
het_string_to_upper(char * source)46 void het_string_to_upper (char *source)
47 {
48 int i;
49
50 for (i = 0; source[i] != '\0'; i++)
51 source[i] = toupper(source[i]);
52 }
53
54 /*
55 || Standard main() function
56 */
57 int
main(int argc,char * argv[])58 main( int argc, char *argv[] )
59 {
60 int rc;
61 SLLABEL lab;
62 HETB *hetb;
63 int o_iehinitt;
64 int o_nl;
65 int o_compress;
66 char *o_filename;
67 char *o_owner;
68 char *o_volser;
69
70 INITIALIZE_UTILITY("hetinit");
71
72 hetb = NULL;
73
74 o_filename = NULL;
75 o_iehinitt = TRUE;
76 o_nl = FALSE;
77 o_compress = TRUE;
78 o_owner = NULL;
79 o_volser = NULL;
80
81 /* Display the program identification message */
82 display_version (stderr, "Hercules HET IEHINITT program ", FALSE);
83
84 while( TRUE )
85 {
86 rc = getopt( argc, argv, "dhin" );
87 if( rc == -1 )
88 {
89 break;
90 }
91
92 switch( rc )
93 {
94 case 'd':
95 o_compress = FALSE;
96 break;
97
98 case 'h':
99 usage( argv[ 0 ] );
100 goto exit;
101 break;
102
103 case 'i':
104 o_iehinitt = TRUE;
105 o_nl = FALSE;
106 break;
107
108 case 'n':
109 o_iehinitt = FALSE;
110 o_nl = TRUE;
111 break;
112
113 default:
114 usage( argv[ 0 ] );
115 goto exit;
116 break;
117 }
118 }
119
120 argc -= optind;
121
122 if( argc < 1 )
123 {
124 usage( argv[ 0 ] );
125 goto exit;
126 }
127 o_filename = argv[ optind ];
128
129 if( o_iehinitt )
130 {
131 if( argc == 2 )
132 {
133 o_volser = argv[ optind + 1 ];
134 }
135 else if( argc == 3 )
136 {
137 o_volser = argv[ optind + 1 ];
138 o_owner = argv[ optind + 2 ];
139 }
140 else
141 {
142 usage( argv[ 0 ] );
143 goto exit;
144 }
145 }
146
147 if( o_nl )
148 {
149 if( argc != 1 )
150 {
151 usage( argv[ 0 ] );
152 goto exit;
153 }
154 }
155
156 if( o_volser )
157 het_string_to_upper( o_volser );
158
159 if( o_owner )
160 het_string_to_upper( o_owner );
161
162 rc = het_open( &hetb, o_filename, HETOPEN_CREATE );
163 if( rc < 0 )
164 {
165 printf( "het_open() returned %d\n", rc );
166 goto exit;
167 }
168
169 rc = het_cntl( hetb, HETCNTL_SET | HETCNTL_COMPRESS, o_compress );
170 if( rc < 0 )
171 {
172 printf( "het_cntl() returned %d\n", rc );
173 goto exit;
174 }
175
176 if( o_iehinitt )
177 {
178 rc = sl_vol1( &lab, o_volser, o_owner );
179 if( rc < 0 )
180 {
181 printf( "%s\n", sl_error(rc) );
182 goto exit;
183 }
184
185 rc = het_write( hetb, &lab, sizeof( lab ) );
186 if( rc < 0 )
187 {
188 printf( "het_write() for VOL1 returned %d\n", rc );
189 goto exit;
190 }
191
192 rc = sl_hdr1( &lab, SL_INITDSN, NULL, 0, 0, NULL, 0 );
193 if( rc < 0 )
194 {
195 printf( "%s\n", sl_error(rc) );
196 goto exit;
197 }
198
199 rc = het_write( hetb, &lab, sizeof( lab ) );
200 if( rc < 0 )
201 {
202 printf( "het_write() for HDR1 returned %d\n", rc );
203 goto exit;
204 }
205
206 }
207 else if( o_nl )
208 {
209 rc = het_tapemark( hetb );
210 if( rc < 0 )
211 {
212 printf( "het_tapemark() returned %d\n", rc );
213 goto exit;
214 }
215 }
216
217 rc = het_tapemark( hetb );
218 if( rc < 0 )
219 {
220 printf( "het_tapemark() returned %d\n", rc );
221 goto exit;
222 }
223
224 exit:
225 het_close( &hetb );
226
227 return( rc < 0 );
228 }
229