summaryrefslogtreecommitdiff
path: root/os2
diff options
context:
space:
mode:
authorLarry Wall <lwall@jpl-devvax.jpl.nasa.gov>1990-10-15 23:06:25 +0000
committerLarry Wall <lwall@jpl-devvax.jpl.nasa.gov>1990-10-15 23:06:25 +0000
commit39c3038ca76b338006c640ae6da52b407dd9e654 (patch)
tree2c2e20583f6b38967167e68b93c17b5381751216 /os2
parentb6ccd89c4e9e943419de0b1846c5d54324a5ed8a (diff)
downloadperl-39c3038ca76b338006c640ae6da52b407dd9e654.tar.gz
perl 3.0 patch #30 patch #29, continued
See patch #29.
Diffstat (limited to 'os2')
-rw-r--r--os2/a2p.cs8
-rw-r--r--os2/a2p.def2
-rw-r--r--os2/config.h5
-rw-r--r--os2/dir.h163
-rw-r--r--os2/director.c200
5 files changed, 375 insertions, 3 deletions
diff --git a/os2/a2p.cs b/os2/a2p.cs
new file mode 100644
index 0000000000..1141c4ff17
--- /dev/null
+++ b/os2/a2p.cs
@@ -0,0 +1,8 @@
+(-W1 -Od -Ocgelt a2p.y{a2py.c})
+(-W1 -Od -Ocgelt hash.c str.c util.c walk.c)
+
+setargv.obj
+a2p.def
+a2p.exe
+
+-AL -LB -S0xA000
diff --git a/os2/a2p.def b/os2/a2p.def
new file mode 100644
index 0000000000..d88c28316e
--- /dev/null
+++ b/os2/a2p.def
@@ -0,0 +1,2 @@
+NAME AWK2PERL WINDOWCOMPAT NEWFILES
+DESCRIPTION 'AWK to PERL translator - for MS-DOS and OS/2'
diff --git a/os2/config.h b/os2/config.h
index 7152503847..e587a5cb74 100644
--- a/os2/config.h
+++ b/os2/config.h
@@ -14,7 +14,6 @@
#define GETPPID
#define GETPRIORITY
#define SETPRIORITY
-#define SYSCALL
#define KILL
#endif /* OS2 */
@@ -435,7 +434,7 @@
* This symbol, if defined, indicates to the C program that it should
* include fcntl.h.
*/
-#define I_FCNTL /**/
+/*#define I_FCNTL /**/
/* I_GRP:
* This symbol, if defined, indicates to the C program that it should
@@ -545,7 +544,7 @@
* execution path, but it should be accessible by the world. The program
* should be prepared to do ^ expansion.
*/
-#define PRIVLIB "/usr/local/lib/perl" /**/
+#define PRIVLIB "c:/bin/perl" /**/
/*
* BUGGY_MSC:
diff --git a/os2/dir.h b/os2/dir.h
new file mode 100644
index 0000000000..92c6923ac3
--- /dev/null
+++ b/os2/dir.h
@@ -0,0 +1,163 @@
+/*
+ * @(#) dir.h 1.4 87/11/06 Public Domain.
+ *
+ * A public domain implementation of BSD directory routines for
+ * MS-DOS. Written by Michael Rendell ({uunet,utai}michael@garfield),
+ * August 1987
+ *
+ * Enhanced and ported to OS/2 by Kai Uwe Rommel; added scandir() prototype
+ * December 1989, February 1990
+ */
+
+
+#define MAXNAMLEN 12
+#define MAXPATHLEN 128
+
+#define A_RONLY 0x01
+#define A_HIDDEN 0x02
+#define A_SYSTEM 0x04
+#define A_LABEL 0x08
+#define A_DIR 0x10
+#define A_ARCHIVE 0x20
+
+
+struct direct
+{
+ ino_t d_ino; /* a bit of a farce */
+ int d_reclen; /* more farce */
+ int d_namlen; /* length of d_name */
+ char d_name[MAXNAMLEN + 1]; /* null terminated */
+ long d_size; /* size in bytes */
+ int d_mode; /* DOS or OS/2 file attributes */
+};
+
+/* The fields d_size and d_mode are extensions by me (Kai Uwe Rommel).
+ * The find_first and find_next calls deliver this data without any extra cost.
+ * If this data is needed, these fields save a lot of extra calls to stat()
+ * (each stat() again performs a find_first call !).
+ */
+
+struct _dircontents
+{
+ char *_d_entry;
+ long _d_size;
+ int _d_mode;
+ struct _dircontents *_d_next;
+};
+
+typedef struct _dirdesc
+{
+ int dd_id; /* uniquely identify each open directory */
+ long dd_loc; /* where we are in directory entry is this */
+ struct _dircontents *dd_contents; /* pointer to contents of dir */
+ struct _dircontents *dd_cp; /* pointer to current position */
+}
+DIR;
+
+
+extern DIR *opendir(char *);
+extern struct direct *readdir(DIR *);
+extern void seekdir(DIR *, long);
+extern long telldir(DIR *);
+extern void closedir(DIR *);
+#define rewinddir(dirp) seekdir(dirp, 0L)
+
+extern int scandir(char *, struct direct ***,
+ int (*)(struct direct *),
+ int (*)(struct direct *, struct direct *));
+
+extern int getfmode(char *);
+extern int setfmode(char *, unsigned);
+
+/*
+NAME
+ opendir, readdir, telldir, seekdir, rewinddir, closedir -
+ directory operations
+
+SYNTAX
+ #include <sys/types.h>
+ #include <sys/dir.h>
+
+ DIR *opendir(filename)
+ char *filename;
+
+ struct direct *readdir(dirp)
+ DIR *dirp;
+
+ long telldir(dirp)
+ DIR *dirp;
+
+ seekdir(dirp, loc)
+ DIR *dirp;
+ long loc;
+
+ rewinddir(dirp)
+ DIR *dirp;
+
+ int closedir(dirp)
+ DIR *dirp;
+
+DESCRIPTION
+ The opendir library routine opens the directory named by
+ filename and associates a directory stream with it. A
+ pointer is returned to identify the directory stream in sub-
+ sequent operations. The pointer NULL is returned if the
+ specified filename can not be accessed, or if insufficient
+ memory is available to open the directory file.
+
+ The readdir routine returns a pointer to the next directory
+ entry. It returns NULL upon reaching the end of the direc-
+ tory or on detecting an invalid seekdir operation. The
+ readdir routine uses the getdirentries system call to read
+ directories. Since the readdir routine returns NULL upon
+ reaching the end of the directory or on detecting an error,
+ an application which wishes to detect the difference must
+ set errno to 0 prior to calling readdir.
+
+ The telldir routine returns the current location associated
+ with the named directory stream. Values returned by telldir
+ are good only for the lifetime of the DIR pointer from which
+ they are derived. If the directory is closed and then reo-
+ pened, the telldir value may be invalidated due to
+ undetected directory compaction.
+
+ The seekdir routine sets the position of the next readdir
+ operation on the directory stream. Only values returned by
+ telldir should be used with seekdir.
+
+ The rewinddir routine resets the position of the named
+ directory stream to the beginning of the directory.
+
+ The closedir routine closes the named directory stream and
+ returns a value of 0 if successful. Otherwise, a value of -1
+ is returned and errno is set to indicate the error. All
+ resources associated with this directory stream are
+ released.
+
+EXAMPLE
+ The following sample code searches a directory for the entry
+ name.
+
+ len = strlen(name);
+
+ dirp = opendir(".");
+
+ for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
+
+ if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
+
+ closedir(dirp);
+
+ return FOUND;
+
+ }
+
+ closedir(dirp);
+
+ return NOT_FOUND;
+
+
+SEE ALSO
+ close(2), getdirentries(2), lseek(2), open(2), read(2),
+ dir(5)
+*/
diff --git a/os2/director.c b/os2/director.c
new file mode 100644
index 0000000000..a360af712b
--- /dev/null
+++ b/os2/director.c
@@ -0,0 +1,200 @@
+/*
+ * @(#)dir.c 1.4 87/11/06 Public Domain.
+ *
+ * A public domain implementation of BSD directory routines for
+ * MS-DOS. Written by Michael Rendell ({uunet,utai}michael@garfield),
+ * August 1897
+ * Ported to OS/2 by Kai Uwe Rommel
+ * December 1989
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/dir.h>
+
+#include <stdio.h>
+#include <malloc.h>
+#include <string.h>
+
+#define INCL_NOPM
+#include <os2.h>
+
+
+int attributes = A_DIR | A_HIDDEN;
+
+
+static char *getdirent(char *);
+static void free_dircontents(struct _dircontents *);
+
+static HDIR hdir;
+static USHORT count;
+static FILEFINDBUF find;
+
+
+DIR *opendir(char *name)
+{
+ struct stat statb;
+ DIR *dirp;
+ char c;
+ char *s;
+ struct _dircontents *dp;
+ char nbuf[MAXPATHLEN + 1];
+
+ strcpy(nbuf, name);
+
+ if ( ((c = nbuf[strlen(nbuf) - 1]) == '\\' || c == '/') &&
+ (strlen(nbuf) > 1) )
+ {
+ nbuf[strlen(nbuf) - 1] = 0;
+
+ if ( nbuf[strlen(nbuf) - 1] == ':' )
+ strcat(nbuf, "\\.");
+ }
+ else
+ if ( nbuf[strlen(nbuf) - 1] == ':' )
+ strcat(nbuf, ".");
+
+ if (stat(nbuf, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR)
+ return NULL;
+
+ if ( (dirp = malloc(sizeof(DIR))) == NULL )
+ return NULL;
+
+ if ( nbuf[strlen(nbuf) - 1] == '.' )
+ strcpy(nbuf + strlen(nbuf) - 1, "*.*");
+ else
+ if ( ((c = nbuf[strlen(nbuf) - 1]) == '\\' || c == '/') &&
+ (strlen(nbuf) == 1) )
+ strcat(nbuf, "*.*");
+ else
+ strcat(nbuf, "\\*.*");
+
+ dirp -> dd_loc = 0;
+ dirp -> dd_contents = dirp -> dd_cp = NULL;
+
+ if ((s = getdirent(nbuf)) == NULL)
+ return dirp;
+
+ do
+ {
+ if (((dp = malloc(sizeof(struct _dircontents))) == NULL) ||
+ ((dp -> _d_entry = malloc(strlen(s) + 1)) == NULL) )
+ {
+ if (dp)
+ free(dp);
+ free_dircontents(dirp -> dd_contents);
+
+ return NULL;
+ }
+
+ if (dirp -> dd_contents)
+ dirp -> dd_cp = dirp -> dd_cp -> _d_next = dp;
+ else
+ dirp -> dd_contents = dirp -> dd_cp = dp;
+
+ strcpy(dp -> _d_entry, s);
+ dp -> _d_next = NULL;
+
+ dp -> _d_size = find.cbFile;
+ dp -> _d_mode = find.attrFile;
+ dp -> _d_time = *(unsigned *) &(find.ftimeLastWrite);
+ dp -> _d_date = *(unsigned *) &(find.fdateLastWrite);
+ }
+ while ((s = getdirent(NULL)) != NULL);
+
+ dirp -> dd_cp = dirp -> dd_contents;
+
+ return dirp;
+}
+
+
+void closedir(DIR * dirp)
+{
+ free_dircontents(dirp -> dd_contents);
+ free(dirp);
+}
+
+
+struct direct *readdir(DIR * dirp)
+{
+ static struct direct dp;
+
+ if (dirp -> dd_cp == NULL)
+ return NULL;
+
+ dp.d_namlen = dp.d_reclen =
+ strlen(strcpy(dp.d_name, dirp -> dd_cp -> _d_entry));
+
+ strlwr(dp.d_name); /* JF */
+ dp.d_ino = 0;
+
+ dp.d_size = dirp -> dd_cp -> _d_size;
+ dp.d_mode = dirp -> dd_cp -> _d_mode;
+ dp.d_time = dirp -> dd_cp -> _d_time;
+ dp.d_date = dirp -> dd_cp -> _d_date;
+
+ dirp -> dd_cp = dirp -> dd_cp -> _d_next;
+ dirp -> dd_loc++;
+
+ return &dp;
+}
+
+
+void seekdir(DIR * dirp, long off)
+{
+ long i = off;
+ struct _dircontents *dp;
+
+ if (off >= 0)
+ {
+ for (dp = dirp -> dd_contents; --i >= 0 && dp; dp = dp -> _d_next);
+
+ dirp -> dd_loc = off - (i + 1);
+ dirp -> dd_cp = dp;
+ }
+}
+
+
+long telldir(DIR * dirp)
+{
+ return dirp -> dd_loc;
+}
+
+
+static void free_dircontents(struct _dircontents * dp)
+{
+ struct _dircontents *odp;
+
+ while (dp)
+ {
+ if (dp -> _d_entry)
+ free(dp -> _d_entry);
+
+ dp = (odp = dp) -> _d_next;
+ free(odp);
+ }
+}
+
+
+static char *getdirent(char *dir)
+{
+ int done;
+
+ if (dir != NULL)
+ { /* get first entry */
+ hdir = HDIR_CREATE;
+ count = 1;
+ done = DosFindFirst(dir, &hdir, attributes,
+ &find, sizeof(find), &count, 0L);
+ }
+ else /* get next entry */
+ done = DosFindNext(hdir, &find, sizeof(find), &count);
+
+ if (done == 0)
+ return find.achName;
+ else
+ {
+ DosFindClose(hdir);
+ return NULL;
+ }
+}