RPA Toolkit
Added rexgrep to Windows build
authorMartin Stoilov <martin@rpasearch.com>
Wed, 22 Feb 2012 07:49:18 +0000 (23:49 -0800)
committerMartin Stoilov <martin@rpasearch.com>
Wed, 22 Feb 2012 07:49:18 +0000 (23:49 -0800)
build/windows/x64/makefile
rexgrep/build/windows/x64/makefile
rexgrep/rexgrep.c
rexgrep/win32/rexgrepdep.c
rexgrep/win32/rexgrepdep.h
rlib/build/windows/rlib.mk

index 172a2f9..2d4470a 100644 (file)
@@ -29,6 +29,7 @@ SUBPROJECTS= \
        $(RPATK_DIR)\rex\build\$(PORT)\$(ARCH)+ \
        $(RPATK_DIR)\rpagrep\build\$(PORT)\$(ARCH)+ \
        $(RPATK_DIR)\rjs\build\$(PORT)\$(ARCH)+ \
+       $(RPATK_DIR)\rexgrep\build\$(PORT)\$(ARCH)+ \
 
 
 ALL : $(SUBPROJECTS)
index aabfe34..0c0d122 100644 (file)
@@ -38,13 +38,13 @@ INCLUDE_DIRS=/I"$(SRC_DIR)" /I"$(SRC_DIR)\win32" /I"$(RPATK_DIR)" /I"$(RPATK_DIR
 !IF "$(BLDCFG)" == "release"
 
 OUTDIR=.\out
-CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /ML /W3 /EHsc /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /YX /Fo"$(OUTDIR)\\" /FD /c
+CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /ML /W3 /EHsc /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /Fo"$(OUTDIR)\\" /FD /c
 LINK_DEBUG=
 
 !ELSEIF  "$(BLDCFG)" == "debug"
 
 OUTDIR=.\out
-CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /MLd  /Zi /W3  /EHsc  /Od /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /YX /Fo"$(OUTDIR)\\" /FD  /c
+CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /MLd  /Zi /W3  /EHsc  /Od /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "_CONSOLE" /YX /Fo"$(OUTDIR)\\" /FD  /c
 LINK_DEBUG=/DEBUG
 
 !ENDIF
@@ -62,8 +62,7 @@ RGREP_OBJS= \
        "$(OUTDIR)\main.obj" \
        "$(OUTDIR)\fsenumwin.obj" \
        "$(OUTDIR)\rexgrep.obj" \
-
-#      "$(OUTDIR)\rexgrepdep.obj" \
+       "$(OUTDIR)\rexgrepdep.obj" \
 
 
 ALL : "$(OUTDIR)\$(RGREP)"
@@ -100,6 +99,6 @@ SOURCE="$(DEPSRC_DIR)\fsenumwin.c"
 "$(OUTDIR)\fsenumwin.obj" : $(SOURCE) "$(OUTDIR)"
        $(CPP) $(CPP_FLAGS) $(SOURCE)
 
-SOURCE="$(DEPSRC_DIR)\main.c"
+SOURCE="$(SRC_DIR)\main.c"
 "$(OUTDIR)\main.obj" : $(SOURCE) "$(OUTDIR)"
        $(CPP) $(CPP_FLAGS) $(SOURCE)
index 12b6206..a15ea3b 100644 (file)
 #include <string.h>
 #include <time.h>
 
-/*
- * Temporary here. Need to fix the encoding definitions.
- */
-#include "rpa/rpastat.h"
-
 #include "rlib/rutf.h"
 #include "rlib/rmem.h"
 #include "rex/rextransition.h"
@@ -39,7 +34,6 @@
 #define MAX_STACK 256000
 
 
-
 rexgrep_t *rex_grep_create()
 {
        rexgrep_t *pGrep;
@@ -106,7 +100,7 @@ int rex_grep_match(rexgrep_t *pGrep, const char* input, const char *end)
                        input += inc;
                        s = REX_DFA_STATE(dfa, nstate);
                        if (s->type == REX_STATETYPE_ACCEPT)
-                               ret = input - start;
+                               ret = (int)(input - start);
                }
                return ret;
        }
@@ -222,39 +216,12 @@ void rex_grep_scan_buffer(rexgrep_t *pGrep, rbuffer_t *buf)
 
 void rex_grep_output(rexgrep_t *pGrep, const char *s, unsigned long size, unsigned int encoding)
 {
-       const unsigned char *input = (const unsigned char*)s;
-       const unsigned char *end = input + size;
-       unsigned int wc;
-       int ret;
-
-       if (encoding == RPA_ENCODING_UTF16LE || encoding == RPA_ENCODING_ICASE_UTF16LE) {
-               while ((ret = (int)r_utf16_mbtowc(&wc, input, end)) != 0) {
-                       rex_grep_output_char(wc);
-                       input += ret;
-               }
-       } else {
-               while ((ret = (int)r_utf8_mbtowc(&wc, input, end)) != 0) {
-                       rex_grep_output_char(wc);
-                       input += ret;
-               }
-       }
+       fwrite(s, 1, size, stdout);
 }
 
 
 void rex_grep_output_utf8_string(rexgrep_t *pGrep, const char *s)
 {
-       rex_grep_output(pGrep, s, r_strlen(s), RPA_ENCODING_UTF8);
+       rex_grep_output(pGrep, s, r_strlen(s), 0);
 }
 
-
-void rex_grep_output_utf16_string(rexgrep_t *pGrep, const unsigned short *s)
-{
-       unsigned long size = 0;
-       const unsigned short *pstr = s;
-
-       while (*pstr) {
-               size += sizeof(unsigned short);
-               pstr += 1;
-       }
-       rex_grep_output(pGrep, (const char*)s, size, RPA_ENCODING_UTF16LE);
-}
index 03d7d71..de7dc92 100644 (file)
 #include <windows.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "rlib/rbuffer.h"
 #include "rexgrep.h"
 #include "rexgrepdep.h"
 #include "fsenumwin.h"
 
 
-void rex_buffer_unmap_file(rex_buffer_t *buf)
+void rex_buffer_unmap_file(rbuffer_t *buf)
 {
        HANDLE hFile = INVALID_HANDLE_VALUE;
        HANDLE hMapping = 0;
@@ -46,16 +47,16 @@ void rex_buffer_unmap_file(rex_buffer_t *buf)
 }
 
 
-rex_buffer_t * rex_buffer_map_file(const wchar_t *pFileName)
+rbuffer_t * rex_buffer_map_file(LPCTSTR pFileName)
 {
-       rex_buffer_t *buf;
+       rbuffer_t *buf;
        char *pMappedView = 0;
        HANDLE hFile = INVALID_HANDLE_VALUE;
        HANDLE hMapping = 0;
        unsigned __int64 fileSize;
        DWORD sizeLo, sizeHi;
 
-       buf = (rex_buffer_t *)malloc(sizeof(rex_buffer_t));
+       buf = (rbuffer_t *)malloc(sizeof(rbuffer_t));
        if (!buf)
                goto error;
        hFile = CreateFile(pFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
@@ -73,7 +74,7 @@ rex_buffer_t * rex_buffer_map_file(const wchar_t *pFileName)
        buf->userdata1 = (void*)hMapping;
        buf->s = pMappedView;
        buf->size = (unsigned long)fileSize;
-       buf->destroy = rex_buffer_unmap_file;
+       buf->alt_destroy = rex_buffer_unmap_file;
        return buf;
 
 error:
@@ -84,58 +85,14 @@ error:
        if (pMappedView)
                UnmapViewOfFile(pMappedView);
        free(buf);
-       return (rex_buffer_t*)0;
+       return (rbuffer_t*)0;
 }
 
 
-rex_buffer_t * rex_buffer_from_wchar(const wchar_t *wstr)
-{
-       rex_buffer_t *buf;
-       int ret;
-       int wideLen = (int)wcslen(wstr) + 1;
-       int sizeNeeded = WideCharToMultiByte(
-               CP_UTF8,
-               0,
-               wstr,
-               wideLen,
-               NULL,
-               0,
-               NULL,
-               NULL);
-       if (!(buf = rex_buffer_alloc(sizeNeeded)))
-               return (rex_buffer_t*)0;
-       ret = WideCharToMultiByte(
-                               CP_UTF8,
-                               0,
-                               wstr,
-                               wideLen,
-                               buf->s,
-                               sizeNeeded,
-                               NULL,
-                               NULL);
-       if (ret <= 0) {
-               rex_buffer_destroy(buf);
-               return NULL;
-       }
-       return buf;
-
-}
-
-
-void rex_grep_print_filename(rexgrep_t *pGrep)
-{
-       if (pGrep->filename) {
-               rex_grep_output_utf16_string(pGrep, pGrep->filename);
-               rex_grep_output_utf16_string(pGrep, L":\n");
-       }
-       
-}
-
-
-void rex_grep_scan_path(rexgrep_t *pGrep, const wchar_t *path)
+void rex_grep_scan_path(rexgrep_t *pGrep, LPCTSTR path)
 {
        fs_enum_ptr pFSE;
-       rex_buffer_t *buf;
+       rbuffer_t *buf;
 
        if ((pFSE = fse_create(path))) {
        while (fse_next_file(pFSE)) {
@@ -144,7 +101,7 @@ void rex_grep_scan_path(rexgrep_t *pGrep, const wchar_t *path)
                if (buf) {
                                rex_grep_scan_buffer(pGrep, buf);
                                pGrep->scsize += buf->size;
-                               rex_buffer_destroy(buf);
+                               r_buffer_destroy(buf);
                        }
                } 
                fse_destroy(pFSE);
@@ -154,28 +111,7 @@ void rex_grep_scan_path(rexgrep_t *pGrep, const wchar_t *path)
                if (buf) {
                        rex_grep_scan_buffer(pGrep, buf);
                        pGrep->scsize += buf->size;
-                       rex_buffer_destroy(buf);
+                       r_buffer_destroy(buf);
                }
        }
 }
-
-
-void rex_grep_output_char(int c)
-{
-       int ret;
-       int garbage = 0;
-       wchar_t output[3];
-
-       if ((unsigned char)c < 32 && !(c == '\t' || c == '\n' || c == '\r')) {
-               c = garbage;
-       } else if (c >= 127 && c <= 255) {
-               c = garbage;
-       }
-
-       output[0] = output[1] = output[2] = 0;
-       ret = rex_grep_utf16_wctomb(c, (unsigned char*)output, sizeof(output));
-       if (ret > 0) {
-               fwprintf(stdout, L"%s", output);
-       }
-       return;
-}
index 6cc24b0..13ddb38 100644 (file)
@@ -27,8 +27,8 @@ extern "C" {
 #endif
 
 
-rbuffer_t * rex_buffer_map_file(const wchar_t *filename);
-void rex_grep_scan_path(rexgrep_t *pGrep, const wchar_t *path);
+rbuffer_t * rex_buffer_map_file(LPCTSTR filename);
+void rex_grep_scan_path(rexgrep_t *pGrep, LPCTSTR path);
 
 
 #ifdef __cplusplus
index a9153e4..83bc0d1 100644 (file)
@@ -16,6 +16,7 @@ LINK32_OBJS= \
        "$(OUTDIR)\rstring.obj" \\r
        "$(OUTDIR)\rlist.obj" \\r
        "$(OUTDIR)\rutf.obj" \\r
+       "$(OUTDIR)\rbuffer.obj" \\r
 \r
 \r
 ALL : "$(OUTDIR)\$(TARGET)"\r
@@ -103,3 +104,6 @@ SOURCE="$(SRC_DIR)\rutf.c"
 "$(OUTDIR)\rutf.obj" : $(SOURCE) "$(OUTDIR)"\r
        $(CPP) $(CPP_FLAGS) $(SOURCE)\r
 \r
+SOURCE="$(SRC_DIR)\rbuffer.c"\r
+"$(OUTDIR)\rbuffer.obj" : $(SOURCE) "$(OUTDIR)"\r
+       $(CPP) $(CPP_FLAGS) $(SOURCE)\r