Debian Codegraph @

libsrc/os/vms/osdtest.c

raw
1 /* @(#)osdtest.c 19.1 (ES0-DMD) 02/25/03 13:56:11 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*+++++++++++
30 .TYPE Program
31 .LANGUAGE C
32 .IDENTIFICATION osdTEST.c
33 .VERSION 1.0 06-Oct-1987: Creation
34 .AUTHOR Francois Ochsenbein [ESO-IPG]
35 .KEYWORDS Test of osd routines
36 .ENVIRONMENT
37 .COMMENTS
38
39 -----------------*/
40
41 #include <osdefos.h>
42 #include <osfile.h>
43 #include <macrogen.h>
44
45 char *osmsg();
46
47 #include <atype.h>
48
49 /* #define osdtell(f) osdseek(f,0,1) (defined in osfile.h. tm5.09.89) */
50 /* #define osdflush(f) osdwait(f) (defined in osfile.h. tm5.09.89) */
51
52 static char msg[132], charop[132];
53 static char record[8192] = "abcdefghijklmnopqrstuvwxyz";
54 static int f;
55
56 #if 0
57 static struct filestatus info;
58 #endif
59
60 main()
61 { long int st, n;
62 char *p;
63 int i, l, op, large_buffer = 0;
64
65 puts("==== Testing OSD (disk file access) routines ====");
66 printf("Do you want LARGE buffering [no]? " ); gets(msg);
67 if (msg[0] == 'Y' || msg[0] == 'y') large_buffer = LARGE_BUFFER;
68
69 puts(" Type ? for Help");
70
71
72 while(1)
73 { printf("Your choice: "); if (!gets(msg)) break;
74 switch(toupper(msg[0]))
75 { default: puts("*** Uknown Command!");
76 case 'H': case '?': help(); continue;
77
78 case 'C': /* Close */
79 st = osdclose(f); break;
80
81 case 'F': /* Flush */
82 st = osdflush(f); break;
83
84 #if 0
85 case 'i': case 'I': /* Retrieve Info */
86 st = osdinfo(f, &info);
87 printf("Info for: %d (%s)\n\t",
88 f, /* File Number */
89 info.filename); /* file name */
90 printf("\tsize=%d, ",
91 info.filesize); /* file size in BYTES */
92 printf("date=%d, ",
93 info.date); /* creation date */
94 printf("uid=%X,prot=%3o, ss=%d\n",
95 info.owner, /* owner (UID) id */
96 info.protection, /* protection */
97 info.blocksize); /* sector_size */
98 /*
99 printf("Seconds elapsed since creation: %d\n", oshtime(0) - info.date);
100 */
101 break;
102 #endif
103
104 case 'L': /* List File */
105 for (i = atoi(&msg[1]); --i >=0; )
106 { if (osdread(f, record, 1) == 1)
107 osdwrite(1, record, 1);
108 }
109 break;
110
111 case 'O': /* Open */
112 i = 1;
113 switch(toupper(msg[i]))
114 { case ' ': op = READ; break;
115 default: op = READ; i = 2; break; /* Read */
116 case EOS: printf("File Name: "); gets(&msg[i]); break;
117 case 'W': op = WRITE; i = 2; break;
118 case 'A': op = APPEND; i = 2; break;
119 case 'M': op = READ_WRITE; i = 2; break;
120 }
121 op |= large_buffer;
122 while (msg[i] == ' ') i++; /* Skip leading blanks */
123 if (msg[i] == EOS){ printf("File Name: "); gets(&msg[i]); }
124 printf("VMS options F n or V n: "); gets(charop);
125 if (charop[0]) osfop(charop[0], atoi(charop+1));
126 st = osdopen(&msg[i], op);
127 if (st >= 0) f = st;
128 break;
129
130 case '@': /* Select File Number */
131 f = atoi(&msg[1]);
132 printf("Selected file is %d\n", f);
133 continue;
134
135 case 'P': /* Puts text */
136 if (msg[1] == EOS) { printf("Text: ") ; gets(&msg[2]);}
137 st = osdputs(f, &msg[2]);
138 break;
139
140 case 'D': /* Dump n bytes */
141 l = atoi(&msg[1]); /* n */
142 n = osdtell(f);
143 st = osdread(f, record, l);
144 if (st < 0)
145 { if (*osmsg() == 0) { puts("====EOF===="); continue; }
146 else break; /* Error */
147 }
148 if (st > l) puts("====Truncated Text====");
149 dump(n, record, l);
150 break;
151
152 case 'R': /* Read n bytes */
153 n = atoi(&msg[1]); /* n */
154 if (n == 0) n = 80;
155 if (n > sizeof(record) -1) n = sizeof(record)-1;
156 st = osdread(f, record, n);
157 if (st < 0)
158 { if (*osmsg() == 0) { puts("====EOF===="); continue; }
159 else break; /* Error */
160 }
161 record[st] = EOS;
162 write(1, record, st);
163 puts("");
164 break;
165
166 case 'S': /* Seek n */
167 switch(toupper(msg[1]))
168 { default: op = FILE_START; break; /* From Start */
169 case 'E': op = FILE_END; break;
170 case 'C': op = FILE_CURRENT; break;
171 }
172 n = atol(&msg[2]); /* n */
173 st = osdseek(f, n, op);
174 break;
175
176 case 'T': /* Tell */
177 st = osdtell(f);
178 break;
179
180 case 'W': /* Write text */
181 if (msg[1] == EOS) { printf("Text: ") ; gets(&msg[2]);}
182 st = osdput(f, &msg[2]);
183 break;
184
185 case 'Z': /* Benchmark for Read / Write */
186 osdseek(f, 0, FILE_START);
187 n = 0;
188 for (i = 0; i < 80; i++) record[i] = i + '~'- 79;
189 record[80] = EOS;
190 #if 0
191 oshela(INIT_CLOCK);
192 oshcpu(INIT_CLOCK);
193 #endif
194 switch(toupper(msg[1]))
195 { case 'P': /* Writing Test of 80-byte records */
196 printf("Starting writing 1000 records of 80 bytes...\n");
197 for (i=1000, st=0; (--i>=0) && (st>=0); )
198 st = osdputs(f,record);
199 n = (999-i)*80;
200 break;
201 case 'W': /* Writing Test of 80-byte records */
202 record[80] = '\n';
203 printf("Starting writing 1000 records of 80 bytes...\n");
204 for (i=1000, st=0; (--i>=0) && (st>=0); )
205 st = osdwrite(f,record,81);
206 n = (999-i)*80;
207 break;
208 case 'R': /* Reading Complete File */
209 for (n=0, st=0; (st>=0); n += st)
210 st = osdread(f,record,81);
211 break;
212 }
213 #if 0
214 printf("Total bytes read/written: %d --- CPU: %d/100s, Elapsed: %ds\n",
215 n, oshcpu(GET_CLOCK), oshela(GET_CLOCK));
216 #endif
217 }
218 printf("Status is %d", st);
219 if (st < 0) printf(": %s",osmsg());
220 puts("");
221 }
222 ospexit(0);
223 }
224
225 help()
226 {
227 printf("Current file is %d\n", f);
228 puts("Possibilities are: ? Help");
229 puts(" @ f select File f");
230 puts(" C Close Current File");
231 puts(" D n Dump n bytes");
232 puts(" F Flush File");
233 /* puts(" I Display info about file"); */
234 puts(" L n List n bytes to stdout");
235 puts(" M Mark EOF (Truncate) File at current pos.");
236 puts(" OR|OW|OA|OM name Open (Read Write Modify Append)");
237 puts(" P text Puts text");
238 puts(" R n Read n bytes");
239 puts(" SS|SE|SC n Seek Start|End|Current to offset n");
240 puts(" T Tell position of Current file");
241 puts(" W text Write (put) text");
242 puts(" ZR|ZW|ZP Benchmark Read/Write/Put");
243 return(0);
244 }
245 dump(pos, str, len)
246 long pos; /* IN: Present file position */
247 char *str; /* IN: Record to dump */
248 int len; /* IN: Length of record to dump */
249 {
250 static char line[80];
251 char *p, *pe;
252 long x;
253 static char xdig[] = {'0','1','2','3','4','5','6','7','8','9',
254 'A','B','C','D','E','F'};
255 int i;
256
257 for (p = str, pe = str + len; p < pe; pos += 20)
258 { for (i = 0; i < sizeof(line)-1; i++) line[i] = ' ';
259 i = 7; line[i] = ':';
260 for (x = pos; (i>0) && (x>0); x /= 10)
261 line[--i] = (x%10) + '0';
262 for (i=0; (i < 20); i++, p++, len--)
263 { if (len <= 0) continue;
264 if (isprint(*p)) line[i+59] = *p;
265 else line[i+59] = '~';
266 line[9 +i*2+i/2] = xdig[(*p&0xf0)>>4];
267 line[10+i*2+i/2] = xdig[(*p&0x0f)];
268 }
269 line[58] = ':';
270 line[79] = '\0';
271 puts(line);
272 }
273 }