* Implement GNU gettext internationalization support in GNU make.
[make.git] / vmsfunctions.c
blob69ba28c2e26894de854d04f64160b7e79fd04ae8
1 /* vmsfunctions.c */
3 #include "make.h"
4 #include "debug.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 #ifdef HAVE_VMSDIR_H
18 DIR *
19 opendir (dspec)
20 char *dspec;
22 struct DIR *dir = (struct DIR *)xmalloc (sizeof (struct DIR));
23 struct NAM *dnam = (struct NAM *)xmalloc (sizeof (struct NAM));
24 struct FAB *dfab = &dir->fab;
25 char *searchspec = (char *)xmalloc (MAXNAMLEN + 1);
27 memset (dir, 0, sizeof *dir);
29 *dfab = cc$rms_fab;
30 *dnam = cc$rms_nam;
31 sprintf (searchspec, "%s*.*;", dspec);
33 dfab->fab$l_fna = searchspec;
34 dfab->fab$b_fns = strlen (searchspec);
35 dfab->fab$l_nam = dnam;
37 *dnam = cc$rms_nam;
38 dnam->nam$l_esa = searchspec;
39 dnam->nam$b_ess = MAXNAMLEN;
41 if (! (sys$parse (dfab) & 1))
43 free (dir);
44 free (dnam);
45 free (searchspec);
46 return (NULL);
49 return dir;
52 #define uppercasify(str) \
53 do \
54 { \
55 char *tmp; \
56 for (tmp = (str); *tmp != '\0'; tmp++) \
57 if (islower ((unsigned char)*tmp)) \
58 *tmp = toupper ((unsigned char)*tmp); \
59 } \
60 while (0)
62 struct direct *
63 readdir (dir)
64 DIR * dir;
66 struct FAB *dfab = &dir->fab;
67 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
68 struct direct *dentry = &dir->dir;
69 int i;
71 memset (dentry, 0, sizeof *dentry);
73 dnam->nam$l_rsa = dir->d_result;
74 dnam->nam$b_rss = MAXNAMLEN;
76 if (debug_flag)
77 printf (".");
79 if (!((i = sys$search (dfab)) & 1))
81 if (debug_flag)
82 printf ("sys$search failed with %d\n", i);
83 return (NULL);
86 dentry->d_off = 0;
87 if (dnam->nam$w_fid == 0)
88 dentry->d_fileno = 1;
89 else
90 dentry->d_fileno = dnam->nam$w_fid[0] + (dnam->nam$w_fid[1] << 16);
92 dentry->d_reclen = sizeof (struct direct);
93 dentry->d_namlen = dnam->nam$b_name + dnam->nam$b_type;
94 strncpy (dentry->d_name, dnam->nam$l_name, dentry->d_namlen);
95 dentry->d_name[dentry->d_namlen] = '\0';
96 uppercasify (dentry->d_name);
98 return (dentry);
102 closedir (dir)
103 DIR *dir;
105 if (dir != NULL)
107 struct FAB *dfab = &dir->fab;
108 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
109 if (dnam != NULL)
110 free (dnam->nam$l_esa);
111 free (dnam);
112 free (dir);
115 return 0;
117 #endif /* compiled for OpenVMS prior to V7.x */
119 char *
120 getwd (cwd)
121 char *cwd;
123 static char buf[512];
125 if (cwd)
126 return (getcwd (cwd, 512));
127 else
128 return (getcwd (buf, 512));
132 vms_stat (name, buf)
133 char *name;
134 struct stat *buf;
136 int status;
137 int i;
139 static struct FAB Fab;
140 static struct NAM Nam;
141 static struct fibdef Fib; /* short fib */
142 static struct dsc$descriptor FibDesc =
143 { sizeof (Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *) &Fib };
144 static struct dsc$descriptor_s DevDesc =
145 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1] };
146 static char EName[NAM$C_MAXRSS];
147 static char RName[NAM$C_MAXRSS];
148 static struct dsc$descriptor_s FileName =
149 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
150 static struct dsc$descriptor_s string =
151 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
152 static unsigned long Rdate[2];
153 static unsigned long Cdate[2];
154 static struct atrdef Atr[] =
156 #if defined(VAX)
157 /* Revision date */
158 { sizeof (Rdate), ATR$C_REVDATE, (unsigned int) &Rdate[0] },
159 /* Creation date */
160 { sizeof (Cdate), ATR$C_CREDATE, (unsigned int) &Cdate[0] },
161 #else
162 /* Revision date */
163 { sizeof (Rdate), ATR$C_REVDATE, &Rdate[0] },
164 /* Creation date */
165 { sizeof (Cdate), ATR$C_CREDATE, &Cdate[0]},
166 #endif
167 { 0, 0, 0 }
169 static short int DevChan;
170 static short int iosb[4];
172 name = vmsify (name, 0);
174 /* initialize RMS structures, we need a NAM to retrieve the FID */
175 Fab = cc$rms_fab;
176 Fab.fab$l_fna = name; /* name of file */
177 Fab.fab$b_fns = strlen (name);
178 Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
180 Nam = cc$rms_nam;
181 Nam.nam$l_esa = EName; /* expanded filename */
182 Nam.nam$b_ess = sizeof (EName);
183 Nam.nam$l_rsa = RName; /* resultant filename */
184 Nam.nam$b_rss = sizeof (RName);
186 /* do $PARSE and $SEARCH here */
187 status = sys$parse (&Fab);
188 if (!(status & 1))
189 return -1;
191 DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
192 status = sys$assign (&DevDesc, &DevChan, 0, 0);
193 if (!(status & 1))
194 return -1;
196 FileName.dsc$a_pointer = Nam.nam$l_name;
197 FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;
199 /* Initialize the FIB */
200 for (i = 0; i < 3; i++)
202 #ifndef __VAXC
203 Fib.fib$w_fid[i] = Nam.nam$w_fid[i];
204 Fib.fib$w_did[i] = Nam.nam$w_did[i];
205 #else
206 Fib.fib$r_fid_overlay.fib$w_fid[i] = Nam.nam$w_fid[i];
207 Fib.fib$r_did_overlay.fib$w_did[i] = Nam.nam$w_did[i];
208 #endif
211 status = sys$qiow (0, DevChan, IO$_ACCESS, &iosb, 0, 0,
212 &FibDesc, &FileName, 0, 0, &Atr, 0);
213 sys$dassgn (DevChan);
214 if (!(status & 1))
215 return -1;
216 status = iosb[0];
217 if (!(status & 1))
218 return -1;
220 status = stat (name, buf);
221 if (status)
222 return -1;
224 buf->st_mtime = ((Rdate[0] >> 24) & 0xff) + ((Rdate[1] << 8) & 0xffffff00);
225 buf->st_ctime = ((Cdate[0] >> 24) & 0xff) + ((Cdate[1] << 8) & 0xffffff00);
227 return 0;
230 char *
231 cvt_time (tval)
232 unsigned long tval;
234 static long int date[2];
235 static char str[27];
236 static struct dsc$descriptor date_str =
237 { 26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str };
239 date[0] = (tval & 0xff) << 24;
240 date[1] = ((tval >> 8) & 0xffffff);
242 if ((date[0] == 0) && (date[1] == 0))
243 return ("never");
245 sys$asctim (0, &date_str, date, 0);
246 str[26] = '\0';
248 return (str);
253 strcmpi (s1, s2)
254 const char *s1;
255 const char *s2;
257 while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
259 s1++;
260 s2++;
263 return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
268 strcmpi (s1, s2)
269 const char *s1;
270 const char *s2;
272 while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
274 s1++;
275 s2++;
278 return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);