📄 agrepwin.dif
字号:
+ * August 1897
+ * Ported to OS/2 by Kai Uwe Rommel
+ * December 1989, February 1990
+ * Ported to Windows NT 22 May 91
+ * other mods Summer '92 brianmo@microsoft.com
+ * opendirx() was horribly written, very inefficient, and did not take care
+ * of all cases. It is still not too clean, but it is far more efficient.
+ * Changes made by Gordon Chaffee (chaffee@bugs-bunny.cs.berkeley.edu)
+ */
+
+
+/*Includes:
+ * crt
+ */
+#include <windows.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys\types.h>
+#include <sys\stat.h>
+#include "ntdirent.h"
+
+#define stat _stat
+
+/*
+ * NT specific
+ */
+#include <stdio.h>
+
+/*
+ * random typedefs
+ */
+#define HDIR HANDLE
+#define HFILE HANDLE
+#define PHFILE PHANDLE
+
+/*
+ * local functions
+ */
+static char *getdirent(char *);
+static void free_dircontents(struct _dircontents *);
+
+static HDIR FindHandle;
+static WIN32_FIND_DATA FileFindData;
+
+static struct dirent dp;
+
+DIR *opendirx(char *name, char *pattern)
+{
+ struct stat statb;
+ DIR *dirp;
+ char c;
+ char *s;
+ struct _dircontents *dp;
+ int len;
+ int unc;
+ char path[ OFS_MAXPATHNAME ];
+ register char *ip, *op;
+
+ for (ip = name, op = path; ; op++, ip++) {
+ *op = *ip;
+ if (*ip == '\0') {
+ break;
+ }
+ }
+ len = ip - name;
+ if (len > 0) {
+ unc = ((path[0] == '\\' || path[0] == '/') &&
+ (path[1] == '\\' || path[1] == '/'));
+ c = path[len - 1];
+ if (unc) {
+ if (c != '\\' && c != '/') {
+ path[len] = '/';
+ len++;
+ path[len] ='\0';
+ }
+ } else {
+ if ((c == '\\' || c == '/') && (len > 1)) {
+ len--;
+ path[len] = '\0';
+
+ if (path[len - 1] == ':' ) {
+ path[len] = '/'; len++;
+ path[len] = '.'; len++;
+ path[len] = '\0';
+ }
+ } else if (c == ':' ) {
+ path[len] = '.';
+ len++;
+ path[len] ='\0';
+ }
+ }
+ } else {
+ unc = 0;
+ path[0] = '.';
+ path[1] = '\0';
+ len = 1;
+ }
+
+ if (stat(path, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR) {
+ return NULL;
+ }
+
+ dirp = malloc(sizeof(DIR));
+ if (dirp == NULL) {
+ return dirp;
+ }
+
+ c = path[len - 1];
+ if (c == '.' ) {
+ if (len == 1) {
+ len--;
+ } else {
+ c = path[len - 2];
+ if (c == '\\' || c == ':') {
+ len--;
+ } else {
+ path[len] = '/';
+ len++;
+ }
+ }
+ } else if (!unc && ((len != 1) || (c != '\\' && c != '/'))) {
+ path[len] = '/';
+ len++;
+ }
+ strcpy(path + len, pattern);
+
+ dirp -> dd_loc = 0;
+ dirp -> dd_contents = dirp -> dd_cp = NULL;
+
+ if ((s = getdirent(path)) == 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;
+
+ }
+ while ((s = getdirent(NULL)) != NULL);
+
+ dirp -> dd_cp = dirp -> dd_contents;
+ return dirp;
+}
+
+DIR *opendir(char *name)
+{
+ return opendirx(name, "*");
+}
+
+void closedir(DIR * dirp)
+{
+ free_dircontents(dirp -> dd_contents);
+ free(dirp);
+}
+
+struct dirent *readdir(DIR * dirp)
+{
+ /* static struct dirent dp; */
+ if (dirp -> dd_cp == NULL)
+ return NULL;
+
+ /*strcpy(dp.d_name,dirp->dd_cp->_d_entry); */
+
+ dp.d_name = dirp->dd_cp->_d_entry;
+
+ dp.d_namlen = dp.d_reclen =
+ strlen(dp.d_name);
+
+ dp.d_ino = dirp->dd_loc+1; /* fake the inode */
+
+ 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);
+ }
+}
+/* end of "free_dircontents" */
+
+static char *getdirent(char *dir)
+{
+ int got_dirent;
+
+ if (dir != NULL)
+ { /* get first entry */
+ if ((FindHandle = FindFirstFile( dir, &FileFindData ))
+ == (HDIR)0xffffffff)
+ {
+ return NULL;
+ }
+ got_dirent = 1;
+ }
+ else /* get next entry */
+ got_dirent = FindNextFile( FindHandle, &FileFindData );
+
+ if (got_dirent)
+ return FileFindData.cFileName;
+ else
+ {
+ FindClose(FindHandle);
+ return NULL;
+ }
+}
+/* end of getdirent() */
+
+struct passwd * _cdecl
+getpwnam(char *name)
+{
+ return NULL;
+}
+
+struct passwd * _cdecl
+getpwuid(int uid)
+{
+ return NULL;
+}
+
+int
+getuid()
+{
+ return 0;
+}
+
+void _cdecl
+endpwent(void)
+{
+}
+
+/* #endif */
diff -u -r --new-file agrep.335/ntdirent.h agrep.win/ntdirent.h
--- agrep.335/ntdirent.h Wed Dec 31 19:00:00 1969
+++ agrep.win/ntdirent.h Mon Dec 29 15:38:21 1997
@@ -0,0 +1,56 @@
+/*
+ * @(#) dirent.h 2.0 17 Jun 91 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
+ * Change of MAXPATHLEN for HPFS, October 1990
+ *
+ * Unenhanced and ported to Windows NT by Bill Gallagher
+ * 17 Jun 91
+ * changed d_name to char * instead of array, removed non-std extensions
+ *
+ * Cleanup, other hackery, Summer '92, Brian Moran , brianmo@microsoft.com
+ */
+
+#ifndef _DIRENT
+#define _DIRENT
+
+#include <direct.h>
+
+struct dirent
+{
+ ino_t d_ino; /* a bit of a farce */
+ short d_reclen; /* more farce */
+ short d_namlen; /* length of d_name */
+ char *d_name;
+};
+
+struct _dircontents
+{
+ char *_d_entry;
+ struct _dircontents *_d_next;
+};
+
+typedef struct _dirdesc
+{
+ int dd_id; /* uniquely identify each open directory*/
+ long dd_loc; /* where we are in directory entry */
+ struct _dircontents *dd_contents; /* pointer to contents of dir */
+ struct _dircontents *dd_cp; /* pointer to current position */
+}
+DIR;
+
+extern DIR *opendir(char *);
+extern struct dirent *readdir(DIR *);
+extern void seekdir(DIR *, long);
+extern long telldir(DIR *);
+extern void closedir(DIR *);
+#define rewinddir(dirp) seekdir(dirp, 0L)
+
+#endif /* _DIRENT */
+
+/* end of dirent.h */
diff -u -r --new-file agrep.335/parse.c agrep.win/parse.c
--- agrep.335/parse.c Tue Apr 08 00:50:01 1997
+++ agrep.win/parse.c Tue Dec 30 11:35:09 1997
@@ -4,6 +4,11 @@
a regular expression, and return a pointer to a syntax
tree for that regular expression. */
+#ifdef _WIN32
+#include <memory.h>
+#include <stdlib.h>
+#endif
+
#include <stdio.h>
#include "re.h"
diff -u -r --new-file agrep.335/preproce.c agrep.win/preproce.c
--- agrep.335/preproce.c Tue Apr 08 00:50:01 1997
+++ agrep.win/preproce.c Tue Dec 30 11:09:45 1997
@@ -39,6 +39,14 @@
extern char FREQ_FILE[MAX_LINE_LEN], HASH_FILE[MAX_LINE_LEN], STRING_FILE[MAX_LINE_LEN]; /* interfacing with tcompress */
extern int AComplexBoolean;
+#ifdef _WIN32
+int asplit_pattern(); /* asplit.c */
+int asplit_terminal(); /* asplit.c */
+int init(); /* follow.c */
+void destroy_tree(); /* putils.c */
+int quick_tcompress(); /* preproce.c */
+#endif
+
int
preprocess(D_pattern, Pattern) /* need two parameters */
CHAR D_pattern[], Pattern[];
diff -u -r --new-file agrep.335/recursiv.c agrep.win/recursiv.c
--- agrep.335/recursiv.c Tue Apr 08 00:50:01 1997
+++ agrep.win/recursiv.c Tue Dec 30 11:56:15 1997
@@ -30,7 +30,11 @@
#if HAVE_DIRENT_H
+#ifndef _WIN32
# include <dirent.h>
+#else
+# include "ntdirent.h"
+#endif
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
# define dirent direct
@@ -50,6 +54,14 @@
#endif
+#ifdef _WIN32
+#include "config.h"
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+int exec(); /* agrep.c */
+#endif
#include <sys/stat.h>
#include <fcntl.h>
@@ -140,11 +152,15 @@
printf(" In treewalk. name= %s\n",name);
#endif
+#ifndef _WIN32
if(lstat(name, &stbuf) == -1) {
+#else
+ if(stat(name, &stbuf) != 0) {
+#endif
fprintf(stderr, "permission denied or non-existent: %s\n", name);
return;
}
-
+#ifndef _WIN32
if ((stbuf.st_mode & S_IFMT) == S_IFLNK) {
#ifdef REC_DIAG
@@ -153,7 +169,7 @@
return;
}
-
+#endif
if (( stbuf.st_mode & S_IFMT) == S_IFDIR) {
#ifdef REC_DIAG
diff -u -r --new-file agrep.335/sgrep.c agrep.win/sgrep.c
--- agrep.335/sgrep.c Tue Apr 08 00:50:01 1997
+++ agrep.win/sgrep.c Tue Dec 30 11:20:45 1997
@@ -71,7 +71,11 @@
#define W_DELIM 128
#endif
+#ifndef _WIN32
#include <sys/time.h>
+#else
+#include <sys/timeb.h>
+#endif
extern int tuncompressible();
extern int quick_tcompress();
@@ -111,6 +115,18 @@
extern int EASYSEARCH;
extern char FREQ_FILE[MAX_LINE_LEN], HASH_FILE[MAX_LINE_LEN], STRING_FILE[MAX_LINE_LEN];
+#ifdef _WIN32
+int fill_buf(); /* bitap.c */
+int a_monkey(); /* sgrep.c */
+int agrep(); /* sgrep.c */
+int bm(); /* sgrep.c */
+int blog(); /* sgrep.c */
+int monkey(); /* sgrep.c */
+int monkey4(); /* sgrep.c */
+int s_output(); /* sgrep.c */
+int verify(); /* sgrep.c */
+#endif
+
#if MEASURE_TIMES
/* timing variables */
extern int OUTFILTER_ms;
@@ -951,6 +967,9 @@
/* shift = 1; [del] [TG] */
shift = SHIFT[*text]; /* [new] [TG] */
CONT: /* now here to restart the skip-loop */
+#ifdef _WIN32
+;
+#endif
}
else shift = d1;
}
diff -u -r --new-file agrep.335/target agrep.win/target
--- agrep.335/target Mon Dec 08 22:22:07 1997
+++ agrep.win/target Fri Jan 02 14:14:47 1998
@@ -6,4 +6,4 @@
teletubbies
coat nail
happy xmas
-
\ No newline at end of file
+
diff -u -r --new-file agrep.335/utilitie.c agrep.win/utilitie.c
--- agrep.335/utilitie.c Tue Apr 08 00:50:01 1997
+++ agrep.win/utilitie.c Tue Dec 30 11:22:39 1997
@@ -6,6 +6,12 @@
#include <ctype.h>
#include "re.h"
+#ifdef _WIN32
+#include <malloc.h>
+#include <process.h>
+#include <string.h>
+#endif
+
/************************************************************************/
/* */
/* the following routines implement an abstract data type "stack". */
diff -u -r --new-file agrep.335/version.h agrep.win/version.h
--- agrep.335/version.h Thu Dec 11 01:55:57 1997
+++ agrep.win/version.h Fri Jan 02 14:14:47 1998
@@ -53,4 +53,8 @@
#define AGREP_OS "VPMI"
#endif
+#ifdef _WIN32
+#define AGREP_OS "WIN32"
+#endif
+
#define AGREP_DATE __DATE__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -