~ubuntu-branches/debian/sid/eso-midas/sid

« back to all changes in this revision

Viewing changes to .pc/writting.patch/test/os/testosu.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-sl34juxohmn4aty4
Tags: 13.09pl1.2+dfsg-1
Initial release. (Closes: #740702)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)testosu.c        19.1 (ESO-IPG) 02/25/03 14:33:06 */
 
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: midas@eso.org
 
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
 * Define _POSIX_SOURCE to indicate
 
30
 * that this is a POSIX program
 
31
 */
 
32
#define _POSIX_SOURCE 1
 
33
 
 
34
#include <sys/types.h>
 
35
#include <stdio.h>
 
36
#include <stdlib.h>
 
37
#include <setjmp.h>
 
38
#include <signal.h>
 
39
#include <osparms.h>
 
40
 
 
41
 /* 6: Unit status      */
 
42
 
 
43
 struct unistat{
 
44
        char *name;             /* Unit Name    */
 
45
        long int usize;         /* Size in blocks, non meaningful for tapes */
 
46
        int  blocksize;         /* Density / Sector size  */
 
47
        int  density;           /* Density / Sector size  */
 
48
        char device_type;       /* ? D T        */
 
49
 };
 
50
 
 
51
int opentape(), closetape(), skiptape();
 
52
int wfmtape(), readtape(), writetape(), quit(), nothing();
 
53
int gfilenum(), skipblk(), gblknum(); 
 
54
void returnhere();
 
55
 
 
56
static char name[80] = "ns2!/dev/nrst2";
 
57
 
 
58
static int fd=0xffff;
 
59
static jmp_buf env;
 
60
static int verbose = 0;
 
61
 
 
62
struct msg_cmd {
 
63
        char *msg;
 
64
        int (*cmd)();
 
65
        } msg_cmd[] = {
 
66
        "\n0-   *****  MENU *****\n",           nothing,
 
67
        "1-     Open a tape device\n",          opentape,
 
68
        "2-     Close a tape device\n",         closetape,
 
69
        "3-     Read a sector\n",               readtape,
 
70
        "4-     Write a sector\n",              writetape,
 
71
        "5-     Close a file\n",                wfmtape,
 
72
        "6-     File seek \n",                  skiptape,
 
73
        "7-     Get current file number\n",     gfilenum,
 
74
        "8-     Exit\n",                        quit,
 
75
        (char *)0,                              nothing
 
76
        };
 
77
 
 
78
main(argc, argv)
 
79
int argc;
 
80
char **argv;
 
81
{
 
82
        struct msg_cmd *m_c;
 
83
        int opt;
 
84
        char buff[80];
 
85
 
 
86
        if ( argc == 2 && strcmp(argv[1],"-v"))  verbose =1;
 
87
        /*
 
88
         * I check now for DEVCAPFILE otherwise it will fail later in the
 
89
         * osuopen. 
 
90
         * A default place for DEVCAPFILE used to be:
 
91
         *  $MIDASHOME/$MIDVERS/incl/devcap.dat
 
92
         */
 
93
        if ( ! oshenv("DEVCAPFILE", (char *)0) ) {
 
94
                printf("Warning: variable DEVCAPFILE is undefined\n");
 
95
                /* ospexit(1); */
 
96
            }
 
97
 
 
98
        setjmp(env);
 
99
        signal(SIGINT,returnhere);
 
100
        while(1) {
 
101
                m_c = msg_cmd;
 
102
                while(m_c->msg != (char *)0)
 
103
                        printf(m_c++->msg);
 
104
                printf("\nOption: ");
 
105
                if (!gets(buff))        break;
 
106
                if ((opt=atoi(buff)) >= (sizeof(msg_cmd)/sizeof(struct msg_cmd))) 
 
107
                        printf("Bad option\n");
 
108
                else
 
109
                        (*msg_cmd[opt].cmd)();
 
110
                }
 
111
        ospexit(0);
 
112
}
 
113
 
 
114
opentape()
 
115
{
 
116
        char aname[80], input[8];
 
117
        int den, mode;
 
118
        int pfd;
 
119
 
 
120
        printf("\nOPEN TAPE\n");
 
121
        printf("Enter name of device (%s): ",name);
 
122
        gets(aname);
 
123
 
 
124
        if (strlen(aname) != 0)
 
125
                strcpy(name,aname);
 
126
 
 
127
        printf("Enter open mode (2:READ_WRITE): ");
 
128
        mode=atoi(gets(input));
 
129
        if (strlen(input) == 0)
 
130
                mode=READ_WRITE;
 
131
 
 
132
        printf("Enter density of device (0): ");
 
133
        den=atoi(gets(input));
 
134
 
 
135
        if ((pfd = osuopen(name,mode,den)) == -1) {
 
136
                printf("Error opening %s, %s\n",
 
137
                        name,osmsg());
 
138
                return;
 
139
                }
 
140
        fd=pfd;
 
141
        printf("OPEN %s succeded. \n",name);
 
142
}
 
143
 
 
144
closetape()
 
145
{
 
146
        printf("\nCLOSE TAPE\n");
 
147
        if (osuclose(fd) == -1) {
 
148
                printf("Error closing device, %s\n",osmsg());
 
149
                return;
 
150
                }
 
151
        printf("CLOSE succeded\n");
 
152
}
 
153
 
 
154
skiptape()
 
155
{
 
156
        char name[80];
 
157
        int ntm;
 
158
        long offset;
 
159
        int mode;
 
160
        int file_no;
 
161
 
 
162
        printf("Enter mode of addressing (0=FILE_START):");
 
163
        mode = atoi(gets(name));
 
164
 
 
165
        printf("Enter file to seek (0):");
 
166
        offset = atoi(gets(name));
 
167
 
 
168
        printf("\nSKIPPING TO FILE:%d IN MODE:%d\n",offset,mode);
 
169
        if ((file_no = osufseek(fd,offset,mode)) == -1) {
 
170
                printf("Error skipping to file %d in mode %d. %s\n",
 
171
                        offset,mode,osmsg());
 
172
                return;
 
173
                }
 
174
        printf("SKIP succeded. Current file: %d\n",file_no);
 
175
}
 
176
 
 
177
wfmtape()
 
178
{
 
179
        printf("\nCLOSING A FILE\n");
 
180
        if (osufclose(fd) == -1) {
 
181
                printf("Error closing a file: %s\n",
 
182
                        osmsg());
 
183
                return;
 
184
                }
 
185
        printf("CLOSING A FILE succeded\n");
 
186
}
 
187
 
 
188
writetape()
 
189
{
 
190
        char *pbuf;
 
191
        char name[80];
 
192
        int n_bytes;
 
193
        char pattern;
 
194
        int i;
 
195
 
 
196
        printf("\nWRITE A BUFFER\n");
 
197
        printf("Enter number of bytes to be written (1024): ");
 
198
        n_bytes = atoi(gets(name));
 
199
        if ( strlen(name) == 0)
 
200
                n_bytes=1024;
 
201
 
 
202
        if ((pbuf = malloc(n_bytes)) == (char *)0 ) { 
 
203
                printf("Max. memory allocation: %d bytes\n",n_bytes);
 
204
                return;
 
205
                }
 
206
 
 
207
        printf("Buffer allocated\n");
 
208
        printf("Enter pattern for buffer ('A'): ");
 
209
        if (strlen(gets(name)) == 0)
 
210
                pattern='A';
 
211
        else
 
212
                pattern=name[0];
 
213
 
 
214
        printf("Pattern=%c\n",pattern);
 
215
 
 
216
        for (i=0; i<n_bytes; i++)
 
217
                pbuf[i]=pattern;
 
218
 
 
219
/*      for(i=0; i<n_bytes; i++) 
 
220
/*              printf("%c ",pbuf[i]);
 
221
/*      getchar();
 
222
*/
 
223
        if (osuwrite(fd,pbuf,n_bytes) == -1) {
 
224
                printf("Error writting %d bytes, %s\n",
 
225
                        n_bytes,osmsg());
 
226
                return;
 
227
                }
 
228
        printf("WRITE %d bytes succeded\n",n_bytes);
 
229
        free(pbuf);
 
230
}
 
231
 
 
232
readtape()
 
233
{
 
234
        char *pbuf;
 
235
        char name[80];
 
236
        int n_bytes, length;
 
237
        char pattern;
 
238
        int i;
 
239
 
 
240
        printf("\nREAD A BUFFER\n");
 
241
        printf("Enter number of bytes to be read (1024): ");
 
242
        n_bytes = atoi(gets(name));
 
243
        if ( strlen(name) == 0)
 
244
                n_bytes=1024;
 
245
 
 
246
        if ((pbuf = malloc(n_bytes)) == (char *)0 ) { 
 
247
                printf("Max. memory allocation: %d bytes\n",n_bytes);
 
248
                return;
 
249
                }
 
250
 
 
251
        printf("Buffer allocated\n");
 
252
 
 
253
        if ((length = osuread(fd,pbuf,n_bytes)) == -1) {
 
254
                printf("Error reading %d bytes, %s\n",
 
255
                        n_bytes,osmsg());
 
256
                return;
 
257
                }
 
258
 
 
259
        printf("\nREAD %d bytes succeded.\n",length);
 
260
        if (length > 0) {
 
261
                printf("Pattern=%c\n",pbuf[0]);
 
262
                pattern=pbuf[0];
 
263
                if ( verbose )
 
264
                   for(i=0; i<length; i++) 
 
265
                        if (pattern != pbuf[i])
 
266
                                printf("Byte %d (%c) differs of pattern(%c)\n",
 
267
                                        i,pbuf[i],pattern);
 
268
                }
 
269
        free(pbuf);
 
270
}
 
271
 
 
272
gfilenum()
 
273
{
 
274
        int file_no;
 
275
        printf("\nGETTING CURRENT FILE NUMBER\n");
 
276
        if ((file_no = osuftell(fd)) == -1) {
 
277
                printf("Error getting current file number\n",
 
278
                        osmsg());
 
279
                return;
 
280
                }
 
281
        printf("CURRENT FILE NUMBER: %d\n",file_no);
 
282
}
 
283
 
 
284
nothing()
 
285
{
 
286
}
 
287
 
 
288
void returnhere()
 
289
{
 
290
        longjmp(env,0);
 
291
}
 
292
 
 
293
quit()
 
294
{
 
295
        ospexit(0);
 
296
}