Changeset 3140 for trunk/src/kmk/vmsfunctions.c
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/vmsfunctions.c
r2591 r3140 1 1 /* VMS functions 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 3 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 2 Copyright (C) 1996-2016 Free Software Foundation, Inc. 4 3 This file is part of GNU Make. 5 4 … … 16 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 17 16 18 #include "make .h"17 #include "makeint.h" 19 18 #include "debug.h" 20 19 #include "job.h" 21 20 21 #include <ctype.h> 22 #include <string.h> 23 22 24 #ifdef __DECC 23 25 #include <starlet.h> 24 26 #endif 25 #include <descrip.h> 27 26 28 #include <rms.h> 27 #include <iodef.h>28 #include <atrdef.h>29 #include <fibdef.h>30 29 #include "vmsdir.h" 31 30 … … 120 119 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam); 121 120 if (dnam != NULL) 122 121 free (dnam->nam$l_esa); 123 122 free (dnam); 124 123 free (dir); … … 129 128 #endif /* compiled for OpenVMS prior to V7.x */ 130 129 131 char * 132 getwd (char *cwd) 133 { 134 static char buf[512]; 135 136 if (cwd) 137 return (getcwd (cwd, 512)); 138 else 139 return (getcwd (buf, 512)); 140 } 141 142 #if 0 143 /* 144 * Is this used? I don't see any reference, so I suggest to remove it. 145 */ 146 int 147 vms_stat (char *name, struct stat *buf) 130 /* Argv0 will be a full vms file specification, like 131 node$dka100:[utils.gnumake]make.exe;47 132 prefix it with "mcr " to make it a vms command, executable for DCL. */ 133 const char * 134 vms_command(const char* argv0) 135 { 136 size_t l = strlen(argv0) + 1; 137 char* s = xmalloc(l + 4); 138 memcpy(s, "mcr ", 4); 139 memcpy(s+4, argv0, l); 140 return s; 141 } 142 143 /* Argv0 aka argv[0] will be a full vms file specification, like 144 node$dka100:[utils.gnumake]make.exe;47, set up by the CRTL. 145 The vms progname should be ^^^^, the file name without 146 file type .exe and ;version. 147 Use sys$parse to get the name part of the file specification. That is 148 in the above example, pick up "make" and return a copy of that string. 149 If something goes wrong in sys$parse (unlikely, this is a VMS/CRTL supplied 150 file specification) or if there is an empty name part (not easy to produce, 151 but it is possible) just return "make". 152 Somes notes ... 153 NAM[L]$M_SYNCHK requests a syntax check, only. 154 NAM is for ODS2 names (shorter parts, output usually converted to UPPERCASE). 155 NAML is for ODS2/ODS5 names (longer parts, output unchanged). 156 NAM$M_NO_SHORT_UPCASE may not be available for older versions of VMS. 157 NAML is not available on older versions of VMS (NAML$C_BID not defined). 158 argv[0] on older versions of VMS (no extended parse style and no 159 CRTL feature DECC$ARGV_PARSE_STYLE) is always in lowercase. */ 160 const char * 161 vms_progname(const char* argv0) 148 162 { 149 163 int status; 150 int i; 151 152 static struct FAB Fab; 153 static struct NAM Nam; 154 static struct fibdef Fib; /* short fib */ 155 static struct dsc$descriptor FibDesc = 156 { sizeof (Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *) &Fib }; 157 static struct dsc$descriptor_s DevDesc = 158 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1] }; 159 static char EName[NAM$C_MAXRSS]; 160 static char RName[NAM$C_MAXRSS]; 161 static struct dsc$descriptor_s FileName = 162 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 }; 163 static struct dsc$descriptor_s string = 164 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 }; 165 static unsigned long Rdate[2]; 166 static unsigned long Cdate[2]; 167 static struct atrdef Atr[] = 168 { 169 #if defined(VAX) 170 /* Revision date */ 171 { sizeof (Rdate), ATR$C_REVDATE, (unsigned int) &Rdate[0] }, 172 /* Creation date */ 173 { sizeof (Cdate), ATR$C_CREDATE, (unsigned int) &Cdate[0] }, 164 static struct FAB fab; 165 char *progname; 166 const char *fallback = "make"; 167 168 #ifdef NAML$C_BID 169 static char esa[NAML$C_MAXRSS]; 170 static struct NAML naml; 174 171 #else 175 /* Revision date */ 176 { sizeof (Rdate), ATR$C_REVDATE, &Rdate[0] }, 177 /* Creation date */ 178 { sizeof (Cdate), ATR$C_CREDATE, &Cdate[0]}, 179 #endif 180 { 0, 0, 0 } 181 }; 182 static short int DevChan; 183 static short int iosb[4]; 184 185 name = vmsify (name, 0); 186 187 /* initialize RMS structures, we need a NAM to retrieve the FID */ 188 Fab = cc$rms_fab; 189 Fab.fab$l_fna = name; /* name of file */ 190 Fab.fab$b_fns = strlen (name); 191 Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */ 192 193 Nam = cc$rms_nam; 194 Nam.nam$l_esa = EName; /* expanded filename */ 195 Nam.nam$b_ess = sizeof (EName); 196 Nam.nam$l_rsa = RName; /* resultant filename */ 197 Nam.nam$b_rss = sizeof (RName); 198 199 /* do $PARSE and $SEARCH here */ 200 status = sys$parse (&Fab); 172 static char esa[NAM$C_MAXRSS]; 173 static struct NAM nam; 174 #endif 175 176 fab = cc$rms_fab; 177 fab.fab$l_fna = (char*)argv0; 178 fab.fab$b_fns = strlen(argv0); 179 180 #ifdef NAML$C_BID 181 fab.fab$l_naml = &naml; 182 naml = cc$rms_naml; 183 naml.naml$l_long_expand = esa; 184 naml.naml$l_long_expand_alloc = NAML$C_MAXRSS; 185 naml.naml$b_nop = NAML$M_SYNCHK; 186 naml.naml$l_input_flags = NAML$M_NO_SHORT_OUTPUT; 187 #else 188 fab.fab$l_nam = &nam; 189 nam = cc$rms_nam; 190 nam.nam$l_esa = esa; 191 nam.nam$b_ess = NAM$C_MAXRSS; 192 # ifdef NAM$M_NO_SHORT_UPCASE 193 nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_NO_SHORT_UPCASE; 194 # else 195 nam.nam$b_nop = NAM$M_SYNCHK; 196 # endif 197 #endif 198 199 status = sys$parse(&fab); 201 200 if (!(status & 1)) 202 return -1; 203 204 DevDesc.dsc$w_length = Nam.nam$t_dvi[0]; 205 status = sys$assign (&DevDesc, &DevChan, 0, 0); 206 if (!(status & 1)) 207 return -1; 208 209 FileName.dsc$a_pointer = Nam.nam$l_name; 210 FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver; 211 212 /* Initialize the FIB */ 213 for (i = 0; i < 3; i++) 214 { 215 #ifndef __VAXC 216 Fib.fib$w_fid[i] = Nam.nam$w_fid[i]; 217 Fib.fib$w_did[i] = Nam.nam$w_did[i]; 201 return fallback; 202 203 #ifdef NAML$C_BID 204 if (naml.naml$l_long_name_size == 0) 205 return fallback; 206 progname = xmalloc(naml.naml$l_long_name_size + 1); 207 memcpy(progname, naml.naml$l_long_name, naml.naml$l_long_name_size); 208 progname[naml.naml$l_long_name_size] = '\0'; 218 209 #else 219 Fib.fib$r_fid_overlay.fib$w_fid[i] = Nam.nam$w_fid[i]; 220 Fib.fib$r_did_overlay.fib$w_did[i] = Nam.nam$w_did[i]; 221 #endif 222 } 223 224 status = sys$qiow (0, DevChan, IO$_ACCESS, &iosb, 0, 0, 225 &FibDesc, &FileName, 0, 0, &Atr, 0); 226 sys$dassgn (DevChan); 227 if (!(status & 1)) 228 return -1; 229 status = iosb[0]; 230 if (!(status & 1)) 231 return -1; 232 233 status = stat (name, buf); 234 if (status) 235 return -1; 236 237 buf->st_mtime = ((Rdate[0] >> 24) & 0xff) + ((Rdate[1] << 8) & 0xffffff00); 238 buf->st_ctime = ((Cdate[0] >> 24) & 0xff) + ((Cdate[1] << 8) & 0xffffff00); 239 240 return 0; 241 } 242 #endif 243 244 char * 245 cvt_time (unsigned long tval) 246 { 247 static long int date[2]; 248 static char str[27]; 249 static struct dsc$descriptor date_str = 250 { 26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str }; 251 252 date[0] = (tval & 0xff) << 24; 253 date[1] = ((tval >> 8) & 0xffffff); 254 255 if ((date[0] == 0) && (date[1] == 0)) 256 return ("never"); 257 258 sys$asctim (0, &date_str, date, 0); 259 str[26] = '\0'; 260 261 return (str); 262 } 210 if (nam.nam$b_name == 0) 211 return fallback; 212 progname = xmalloc(nam.nam$b_name + 1); 213 # ifdef NAM$M_NO_SHORT_UPCASE 214 memcpy(progname, nam.nam$l_name, nam.nam$b_name); 215 # else 216 { 217 int i; 218 for (i = 0; i < nam.nam$b_name; i++) 219 progname[i] = tolower(nam.nam$l_name[i]); 220 } 221 # endif 222 progname[nam.nam$b_name] = '\0'; 223 #endif 224 225 return progname; 226 }
Note:
See TracChangeset
for help on using the changeset viewer.