Sat Jun 22 14:56:05 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[make.git] / vmsfunctions.c
bloba76609c783e484cc3af76691c8aa9833dd54e0ff
1 #define KDEBUG 0
2 /* vmsfunctions.c */
4 #include <stdio.h>
5 #include "make.h"
6 #ifdef __DECC
7 #include <starlet.h>
8 #endif
9 #include <descrip.h>
10 #include <rms.h>
11 #include <iodef.h>
12 #include <atrdef.h>
13 #include <fibdef.h>
14 #include "vmsdir.h"
16 DIR *opendir(char *dspec)
18 static struct FAB *dfab;
19 struct NAM *dnam;
20 char *searchspec;
22 if ((dfab = (struct FAB *)xmalloc(sizeof (struct FAB))) == NULL) {
23 printf("Error mallocing for FAB\n");
24 return(NULL);
26 if ((dnam = (struct NAM *)xmalloc(sizeof (struct NAM))) == NULL) {
27 printf("Error mallocing for NAM\n");
28 free(dfab);
29 return(NULL);
31 if ((searchspec = (char *)xmalloc(MAXNAMLEN+1)) == NULL) {
32 printf("Error mallocing for searchspec\n");
33 free(dfab);
34 free(dnam);
35 return(NULL);
38 sprintf(searchspec,"%s*.*;",dspec);
40 *dfab = cc$rms_fab;
41 dfab->fab$l_fna = searchspec;
42 dfab->fab$b_fns = strlen(searchspec);
43 dfab->fab$l_nam = dnam;
45 *dnam = cc$rms_nam;
46 dnam->nam$l_esa = searchspec;
47 dnam->nam$b_ess = MAXNAMLEN;
49 if (!(sys$parse(dfab) & 1)) {
50 free(dfab);
51 free(dnam);
52 free(searchspec);
53 return(NULL);
56 return(dfab);
59 #include <ctype.h>
60 #define uppercasify(str) { char *tmp; for(tmp = (str); *tmp != '\0'; tmp++) if(islower(*tmp)) *tmp = toupper(*tmp); }
62 struct direct *readdir(DIR *dfd)
64 static struct direct *dentry;
65 static char resultspec[MAXNAMLEN+1];
66 int i;
68 if ((dentry = (struct direct *)xmalloc(sizeof (struct direct))) == NULL) {
69 printf("Error mallocing for direct\n");
70 return(NULL);
73 dfd->fab$l_nam->nam$l_rsa = resultspec;
74 dfd->fab$l_nam->nam$b_rss = MAXNAMLEN;
76 if (debug_flag)
77 printf(".");
79 if (!((i = sys$search(dfd)) & 1)) {
80 if (debug_flag)
81 printf("sys$search failed with %d\n", i);
82 free(dentry);
83 return(NULL);
86 dentry->d_off = 0;
87 if (dfd->fab$l_nam->nam$w_fid == 0)
88 dentry->d_fileno = 1;
89 else dentry->d_fileno = dfd->fab$l_nam->nam$w_fid[0]
90 +dfd->fab$l_nam->nam$w_fid[1]<<16;
91 dentry->d_reclen = sizeof (struct direct);
93 if (!strcmp(dfd->fab$l_nam->nam$l_type,".DIR"))
94 dentry->d_namlen = dfd->fab$l_nam->nam$b_name;
95 else
97 dentry->d_namlen = dfd->fab$l_nam->nam$b_name+dfd->fab$l_nam->nam$b_type;
98 strncpy(dentry->d_name,dfd->fab$l_nam->nam$l_name,dentry->d_namlen);
99 dentry->d_name[dentry->d_namlen] = '\0';
100 uppercasify(dentry->d_name);
101 /* uvUnFixRCSSeparator(dentry->d_name);*/
103 return(dentry);
106 closedir(DIR *dfd)
108 if (dfd != NULL) {
109 if (dfd->fab$l_nam != NULL)
110 free(dfd->fab$l_nam->nam$l_esa);
111 free(dfd->fab$l_nam);
112 free(dfd);
116 char *getwd(char *cwd)
118 static char buf[512];
120 if (cwd)
121 return(getcwd(cwd,512));
122 else
123 return(getcwd(buf,512));
127 vms_stat (name, buf)
128 char *name;
129 struct stat *buf;
131 int status;
132 int i;
134 static struct FAB Fab;
135 static struct NAM Nam;
136 static struct fibdef Fib; /* short fib */
137 static struct dsc$descriptor FibDesc =
138 {sizeof(Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *)&Fib};
139 static struct dsc$descriptor_s DevDesc =
140 {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1]};
141 static char EName[NAM$C_MAXRSS];
142 static char RName[NAM$C_MAXRSS];
143 static struct dsc$descriptor_s FileName =
144 {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
145 static struct dsc$descriptor_s string =
146 {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
147 static unsigned long Rdate[2];
148 static unsigned long Cdate[2];
149 static struct atrdef Atr[] = {
150 {sizeof(Rdate),ATR$C_REVDATE,&Rdate[0]}, /* Revision date */
151 {sizeof(Cdate),ATR$C_CREDATE,&Cdate[0]}, /* Creation date */
152 {0,0,0}
154 static short int DevChan;
155 static short int iosb[4];
157 name = vmsify (name, 0);
159 /* initialize RMS structures, we need a NAM to retrieve the FID */
160 Fab = cc$rms_fab;
161 Fab.fab$l_fna = name ; /* name of file */
162 Fab.fab$b_fns = strlen(name);
163 Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
165 Nam = cc$rms_nam;
166 Nam.nam$l_esa = EName; /* expanded filename */
167 Nam.nam$b_ess = sizeof(EName);
168 Nam.nam$l_rsa = RName; /* resultant filename */
169 Nam.nam$b_rss = sizeof(RName);
171 /* do $PARSE and $SEARCH here */
172 status = sys$parse(&Fab);
173 if (!(status & 1))
174 return -1;
176 DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
177 status = sys$assign(&DevDesc,&DevChan,0,0);
178 if (!(status & 1))
179 return -1;
181 FileName.dsc$a_pointer = Nam.nam$l_name;
182 FileName.dsc$w_length = Nam.nam$b_name+Nam.nam$b_type+Nam.nam$b_ver;
184 /* Initialize the FIB */
185 for (i=0;i<3;i++)
187 #if __DECC
188 Fib.fib$w_fid[i]=Nam.nam$w_fid[i];
189 Fib.fib$w_did[i]=Nam.nam$w_did[i];
190 #else
191 Fib.fib$r_fid_overlay.fib$w_fid[i]=Nam.nam$w_fid[i];
192 Fib.fib$r_did_overlay.fib$w_did[i]=Nam.nam$w_did[i];
193 #endif
196 status = sys$qiow(0,DevChan,IO$_ACCESS,&iosb,0,0,
197 &FibDesc,&FileName,0,0,&Atr,0);
198 if (!(status & 1))
199 return -1;
200 status = iosb[0];
201 if (!(status & 1))
202 return -1;
204 status = stat (name, buf);
205 if (status)
206 return -1;
208 buf->st_mtime = ((Rdate[0]>>24) & 0xff) + ((Rdate[1]<<8) & 0xffffff00);
209 buf->st_ctime = ((Cdate[0]>>24) & 0xff) + ((Cdate[1]<<8) & 0xffffff00);
210 return 0;
213 char *
214 cvt_time(tval)
215 unsigned long tval;
217 static long int date[2];
218 static char str[27];
219 static struct dsc$descriptor date_str =
220 {26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str};
222 date[0] = (tval & 0xff) << 24;
223 date[1] = ((tval>>8) & 0xffffff);
225 if ((date[0]==0) && (date[1]==0))
226 return("never");
228 sys$asctim(0,&date_str,date,0);
229 str[26]='\0';
231 return(str);
234 /* EOF */