summaryrefslogtreecommitdiff
path: root/vmsfunctions.c
diff options
context:
space:
mode:
Diffstat (limited to 'vmsfunctions.c')
-rw-r--r--vmsfunctions.c138
1 files changed, 70 insertions, 68 deletions
diff --git a/vmsfunctions.c b/vmsfunctions.c
index 4e0cb34..a36630e 100644
--- a/vmsfunctions.c
+++ b/vmsfunctions.c
@@ -1,7 +1,5 @@
/* vmsfunctions.c */
-#define KDEBUG 0
-
#include "make.h"
#include "debug.h"
@@ -21,37 +19,17 @@ DIR *
opendir (dspec)
char *dspec;
{
- static struct FAB *dfab;
- struct NAM *dnam;
- char *searchspec;
-
- dfab = (struct FAB *) xmalloc (sizeof (struct FAB));
- if (! dfab)
- {
- printf ("Error mallocing for FAB\n");
- return (NULL);
- }
+ struct DIR *dir = (struct DIR *)xmalloc (sizeof (struct DIR));
+ struct NAM *dnam = (struct NAM *)xmalloc (sizeof (struct NAM));
+ struct FAB *dfab = &dir->fab;
+ char *searchspec = (char *)xmalloc (MAXNAMLEN + 1);
- dnam = (struct NAM *) xmalloc (sizeof (struct NAM));
- if (! dnam)
- {
- printf ("Error mallocing for NAM\n");
- free (dfab);
- return (NULL);
- }
-
- searchspec = (char *) xmalloc (MAXNAMLEN + 1);
- if (! searchspec)
- {
- printf ("Error mallocing for searchspec\n");
- free (dfab);
- free (dnam);
- return (NULL);
- }
+ memset (dir, 0, sizeof *dir);
+ *dfab = cc$rms_fab;
+ *dnam = cc$rms_nam;
sprintf (searchspec, "%s*.*;", dspec);
- *dfab = cc$rms_fab;
dfab->fab$l_fna = searchspec;
dfab->fab$b_fns = strlen (searchspec);
dfab->fab$l_nam = dnam;
@@ -62,13 +40,13 @@ opendir (dspec)
if (! (sys$parse (dfab) & 1))
{
- free (dfab);
+ free (dir);
free (dnam);
free (searchspec);
return (NULL);
}
- return (dfab);
+ return dir;
}
#define uppercasify(str) \
@@ -82,65 +60,59 @@ opendir (dspec)
while (0)
struct direct *
-readdir (dfd)
- DIR * dfd;
+readdir (dir)
+ DIR * dir;
{
- static struct direct *dentry;
- static char resultspec[MAXNAMLEN + 1];
+ struct FAB *dfab = &dir->fab;
+ struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
+ struct direct *dentry = &dir->dir;
int i;
- dentry = (struct direct *) xmalloc (sizeof (struct direct));
- if (! dentry)
- {
- printf ("Error mallocing for direct\n");
- return (NULL);
- }
+ memset (dentry, 0, sizeof *dentry);
- dfd->fab$l_nam->nam$l_rsa = resultspec;
- dfd->fab$l_nam->nam$b_rss = MAXNAMLEN;
+ dnam->nam$l_rsa = dir->d_result;
+ dnam->nam$b_rss = MAXNAMLEN;
- DB (DB_EXTRA, ("."));
+ if (debug_flag)
+ printf (".");
- if (!((i = sys$search (dfd)) & 1))
+ if (!((i = sys$search (dfab)) & 1))
{
- DB (DB_EXTRA, ("sys$search failed with %d\n", i));
- free (dentry);
+ if (debug_flag)
+ printf ("sys$search failed with %d\n", i);
return (NULL);
}
dentry->d_off = 0;
- if (dfd->fab$l_nam->nam$w_fid == 0)
+ if (dnam->nam$w_fid == 0)
dentry->d_fileno = 1;
else
- dentry->d_fileno = dfd->fab$l_nam->nam$w_fid[0]
- + dfd->fab$l_nam->nam$w_fid[1] << 16;
+ dentry->d_fileno = dnam->nam$w_fid[0] + (dnam->nam$w_fid[1] << 16);
+
dentry->d_reclen = sizeof (struct direct);
-#if 0
- if (!strcmp(dfd->fab$l_nam->nam$l_type, ".DIR"))
- dentry->d_namlen = dfd->fab$l_nam->nam$b_name;
- else
-#endif
- dentry->d_namlen = dfd->fab$l_nam->nam$b_name + dfd->fab$l_nam->nam$b_type;
- strncpy (dentry->d_name, dfd->fab$l_nam->nam$l_name, dentry->d_namlen);
+ dentry->d_namlen = dnam->nam$b_name + dnam->nam$b_type;
+ strncpy (dentry->d_name, dnam->nam$l_name, dentry->d_namlen);
dentry->d_name[dentry->d_namlen] = '\0';
uppercasify (dentry->d_name);
-#if 0
- uvUnFixRCSSeparator(dentry->d_name);
-#endif
return (dentry);
}
-closedir (dfd)
- DIR *dfd;
+int
+closedir (dir)
+ DIR *dir;
{
- if (dfd)
+ if (dir != NULL)
{
- if (dfd->fab$l_nam)
- free (dfd->fab$l_nam->nam$l_esa);
- free (dfd->fab$l_nam);
- free (dfd);
+ struct FAB *dfab = &dir->fab;
+ struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
+ if (dnam != NULL)
+ free (dnam->nam$l_esa);
+ free (dnam);
+ free (dir);
}
+
+ return 0;
}
#endif /* compiled for OpenVMS prior to V7.x */
@@ -227,7 +199,7 @@ vms_stat (name, buf)
/* Initialize the FIB */
for (i = 0; i < 3; i++)
{
-#if __DECC
+#ifndef __VAXC
Fib.fib$w_fid[i] = Nam.nam$w_fid[i];
Fib.fib$w_did[i] = Nam.nam$w_did[i];
#else
@@ -275,3 +247,33 @@ cvt_time (tval)
return (str);
}
+
+
+int
+strcmpi (s1, s2)
+ const char *s1;
+ const char *s2;
+{
+ while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
+ {
+ s1++;
+ s2++;
+ }
+
+ return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
+}
+
+
+int
+strcmpi (s1, s2)
+ const char *s1;
+ const char *s2;
+{
+ while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
+ {
+ s1++;
+ s2++;
+ }
+
+ return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
+}