Debian Codegraph @

libsrc/os/unix/osftest.c

raw
1 /* @(#)osftest.c 19.1 (ES0-DMD) 02/25/03 13:55:50 */
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 osfTEST.c
33 .VERSION 1.0 23-Oct-1987: Creation
34 .AUTHOR Francois Ochsenbein [ESO-IPG]
35 .KEYWORDS Test of osd routines
36 .ENVIRONMENT
37 .COMMENTS
38 .VERSION 2.3 19-Feb-1992: osfinfo: filestatus modified. CG.
39 -------------------------------------------------------------------------*/
40
41 #include <osfile.h>
42 #include <osdefos.h> /* Needs to know which Operating System */
43
44 static char msg[80];
45 static char c1[80], c2[80];
46
47 static struct filestatus info;
48
49 main()
50 { int i, n, n1, l, n2;
51 long int ll;
52 int recsize;
53 char addctrl = 0;
54
55 puts("Test of osf (File Management) Routines");
56
57 while (1)
58 { printf("Operation: Creat / Del / Rename / Mode / Info / Parse / Supply / Unix: ");
59 if (gets(msg) == 0) break;
60 switch(msg[0])
61 { case 'c': case 'C': /* Create a File */
62 printf("File to Create: "); gets(c1);
63 printf("VMS options F n or V n: "); gets(msg);
64 if (msg[0]) osfop(msg[0], atoi(msg+1));
65 printf("Number of bytes: ");
66 gets(msg); ll = atol(msg);
67 printf("Protection (3xoctal): ");
68 gets(msg);
69 i = (msg[0]-'0') *64 + (msg[1]-'0') *8 + (msg[2]-'0');
70 printf("Statut create=%d\n", osfcreate(c1, ll, i));
71 puts(osmsg());
72 break;
73
74 case 'd': case 'D': /* Delete File */
75 printf("File to Delete: "); gets(c1);
76 printf("Statut Delete=%d\n", osfdelete(c1));
77 puts(osmsg());
78 break;
79
80 case 'r': case 'R': /* Rename File */
81 printf("Old Name: "); gets(c1);
82 printf("New Name: "); gets(c2);
83 printf("Statut Rename=%d\n", osfrename(c1, c2));
84 puts(osmsg());
85 break;
86
87 case 'p': case 'P': /* Find Elements */
88 printf("File to parse: "); gets(c1);
89 printf("Path: %s\n", osfparse(c1,_PATH_));
90 printf("File: %s\n", osfparse(c1,_FILE_));
91 printf("Type: %s\n", osfparse(c1,_TYPE_));
92 printf("Vers: %s\n", osfparse(c1,_VERSION_));
93 break;
94
95 case 's': case 'S': /* Change Protection */
96 printf("File Name with missing items: "); gets(c1);
97 printf("Give File Name Template : "); gets(c2);
98 printf("Resulting Name: %s\n", osfsupply(c1, c2));
99 break;
100
101 case 'm': case 'M': /* Change Protection */
102 printf("File to Change: "); gets(c1);
103 printf("Protection (3xoctal): ");
104 gets(msg);
105 i = (msg[0]-'0') *64 + (msg[1]-'0') *8 + (msg[2]-'0');
106 printf("Statut chg prot=%d\n", osfcontrol(c1, CHMOD, i, 0));
107 puts(osmsg());
108 break;
109
110 case 'u': case 'U': /* Check Unix compatible */
111 printf("File to Check: "); gets(c1);
112 printf("Unix code: %d\n", osfunix(c1));
113 puts(osmsg());
114 break;
115
116 case 'i': case 'I': /* Retrieve Info */
117 printf("File to get Info: "); gets(c1);
118 i = osfinfo(c1, &info);
119 printf("Statut Info=%d\n", i);
120 if (i < 0) { puts(osmsg()); break; }
121 printf("Info for: %s\n\tsize=%d",
122 c1, /* file name */
123 info.filesize); /* file size in BYTES */
124 printf(" date=%d",
125 info.date); /* creation date */
126 printf(" uid=%X,prot=%3o, ss=%d\n",
127 info.owner, /* owner (UID) id */
128 info.protection); /* protection */
129 printf("Seconds elapsed since creation: %d\n",
130 oshtime(0) - info.date);
131 break;
132
133 default: puts("***BAD***");
134 }
135 }
136 ospexit(0);
137 }