Debian Codegraph @

libsrc/os/vms/osatest.c

raw
1 /* @(#)osatest.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 osaTEST
33 .VERSION 1.0 06-Oct-1987: Creation
34 .AUTHOR Francois Ochsenbein [ESO-IPG]
35 .KEYWORDS Test of osa routines
36 .ENVIRONMENT
37 .COMMENTS
38
39 -----------------*/
40
41 #include <atype.h>
42 #include <osfile.h>
43 #include <osdefos.h>
44 #include <macrogen.h>
45
46 char *osmsg();
47
48 #define IO_MAX 8000
49 #define osaflush osawait
50 /* #define osatell(f) osaseek(f,0,1) (defined in osfile.h. tm04.09.89) */
51
52 static char msg[132], charop[132];
53 static char record[IO_MAX] = "abcdefghijklmnopqrstuvwxyz";
54 static int f;
55
56 main()
57 { long int st, n;
58 char *p;
59 int i, l, op;
60
61 puts("==== Testing OSA (Ascii file access) routines ====");
62 puts(" Type ? for Help");
63
64 while(1)
65 { printf("Your choice: "); if (!gets(msg)) break;
66 switch(toupper(msg[0]))
67 { default: puts("*** Uknown Command!");
68 case 'H': case '?': help(); continue;
69
70 case 'C': /* Close */
71 st = osaclose(f); break;
72
73 case 'F': /* Flush */
74 st = osaflush(f); break;
75
76 #if 0
77 case 'i': case 'I': /* Retrieve Info */
78 st = osdinfo(f, &info);
79 printf("Info for: %d (%s)\n\t",
80 f, /* File Number */
81 info.filename); /* file name */
82 printf("\tsize=%d, ",
83 info.filesize); /* file size in BYTES */
84 printf("date=%d, ",
85 info.date); /* creation date */
86 printf("uid=%X,prot=%3o, ss=%d\n",
87 info.owner, /* owner (UID) id */
88 info.protection, /* protection */
89 info.blocksize); /* sector_size */
90 /*
91 printf("Seconds elapsed since creation: %d\n", oshtime(0) - info.date);
92 */
93 break;
94 #endif
95
96 case 'L': /* List File */
97 for (i = atoi(&msg[1]); --i >=0; )
98 { if (osaread(f, record, 1) == 1)
99 osawrite(1, record, 1);
100 }
101 break;
102
103 case 'O': /* Open */
104 i = 1;
105 switch(toupper(msg[i]))
106 { case ' ': op = READ; break;
107 default: op = READ; i = 2; break; /* Read */
108 case EOS: printf("File Name: "); gets(&msg[i]); break;
109 case 'W': op = WRITE; i = 2; break;
110 case 'A': op = APPEND; i = 2; break;
111 case 'M': op = READ_WRITE; i = 2; break;
112 }
113 while (msg[i] == ' ') i++; /* Skip leading blanks */
114 if (msg[i] == EOS){ printf("File Name: "); gets(&msg[i]); }
115 printf("VMS options F n or V n: "); gets(charop);
116 if (charop[0]) osfop(charop[0], atoi(charop+1));
117 st = osaopen(&msg[i], op);
118 if (st >= 0) f = st;
119 break;
120
121 case '@': /* Select File Number */
122 f = atoi(&msg[1]);
123 printf("Selected file is %d\n", f);
124 continue;
125
126 case 'R': /* Read n bytes */
127 n = atoi(&msg[1]); /* n */
128 if (n < 2) n = 81;
129 st = osaread(f, record, n);
130 if (st < 0)
131 { if (*osmsg() == 0) { puts("====EOF===="); continue; }
132 else break; /* Error */
133 }
134 if (st > n) puts("====Truncated Text====");
135 puts(record);
136 break;
137
138 #if 0
139 case 'D': /* Dump n bytes */
140 l = atoi(&msg[1]); /* n */
141 n = osbtell(f);
142 st = osbread(f, record, l);
143 if (st < 0)
144 { if (*osmsg() == 0) { puts("====EOF===="); continue; }
145 else break; /* Error */
146 }
147 if (st > l) puts("====Truncated Text====");
148 dump(n, record, l);
149 break;
150 #endif
151
152 case 'S': /* Seek n */
153 switch(toupper(msg[1]))
154 { default: op = FILE_START; break; /* From Start */
155 case 'E': op = FILE_END; break;
156 case 'C': op = FILE_CURRENT; break;
157 }
158 n = atol(&msg[2]); /* n */
159 st = osaseek(f, n, op);
160 break;
161
162 #if 0
163 case 'M': /* Truncate File */
164 st = osacut(f);
165 break;
166 #endif
167
168 case 'T': /* Tell */
169 st = osatell(f);
170 break;
171
172 case 'W': /* Write text */
173 if (msg[1] == EOS) { printf("Text: ") ; gets(&msg[2]);}
174 st = osawrite(f, &msg[2], strlen(&msg[2]));
175 break;
176
177 case 'Z': /* Benchmark for Read / Write */
178 osaseek(f, 0, FILE_START);
179 n = 0;
180 for (i = 0; i < 80; i++) record[i] = i + '~'- 79;
181 record[80] = EOS;
182 #if 0
183 oshela(INIT_CLOCK);
184 oshcpu(INIT_CLOCK);
185 #endif
186 switch(toupper(msg[1]))
187 {
188 case 'W': /* Writing Test of 80-byte records */
189 record[80] = '\n';
190 printf("Starting writing 1000 records of 80 bytes...\n");
191 for (i=1000, st=0; (--i>=0) && (st>=0); )
192 st = osawrite(f,record,81);
193 n = (999-i)*80;
194 break;
195 case 'R': /* Reading Complete File */
196 for (n=0, st=0; (st>=0); n += st)
197 st = osaread(f,record,81);
198 break;
199 }
200 #if 0
201 printf("Total bytes read/written: %d --- CPU: %d/100s, Elapsed: %ds\n",
202 n, oshcpu(GET_CLOCK), oshela(GET_CLOCK));
203 #endif
204 }
205 printf("Status is %d", st);
206 if (st < 0) printf(": %s",osmsg());
207 puts("");
208 }
209 ospexit(0);
210 }
211
212 help()
213 {
214 printf("Current file is %d\n", f);
215 puts("Possibilities are: ? Help");
216 puts(" @ f select File f");
217 puts(" C Close Current File");
218 #if 0
219 puts(" D n Dump n bytes");
220 #endif
221 puts(" F Flush File");
222 puts(" I Display info about file");
223 puts(" L n List n bytes to stdout");
224 puts(" OR|OW|OA|OM name Open (Read Write Modify Append)");
225 puts(" R n Read n bytes");
226 puts(" SS|SE|SC n Seek Start|End|Current to offset n");
227 puts(" T Tell position of Current file");
228 puts(" W text Write (put) text");
229 puts(" ZR|ZW Benchmark Read/Write/Put/Get");
230 return(0);
231 }
232 dump(pos, str, len)
233 long pos; /* IN: Present file position */
234 char *str; /* IN: Record to dump */
235 int len; /* IN: Length of record to dump */
236 {
237 static char line[80];
238 char *p, *pe;
239 long x;
240 static char xdig[] = {'0','1','2','3','4','5','6','7','8','9',
241 'A','B','C','D','E','F'};
242 int i;
243
244 for (p = str, pe = str + len; p < pe; pos += 20)
245 { for (i = 0; i < sizeof(line)-1; i++) line[i] = ' ';
246 i = 7; line[i] = ':';
247 for (x = pos; (i>0) && (x>0); x /= 10)
248 line[--i] = (x%10) + '0';
249 for (i=0; (i < 20); i++, p++, len--)
250 { if (len <= 0) continue;
251 if (isprint(*p)) line[i+59] = *p;
252 else line[i+59] = '~';
253 line[9 +i*2+i/2] = xdig[(*p&0xf0)>>4];
254 line[10+i*2+i/2] = xdig[(*p&0x0f)];
255 }
256 line[58] = ':';
257 line[79] = '\0';
258 puts(line);
259 }
260 }