|
|
1.1 ! root 1: ! 2: #define IDM_ABOUT 100 ! 3: #define IDM_DEFGREP 101 ! 4: #define IDM_INSTALL 102 ! 5: #define IDM_STRINGEDIT 103 ! 6: #define IDM_TERMBOX 104 ! 7: #define IDM_STARTGREP 105 ! 8: #define IDM_UNINSTALL 106 ! 9: #define IDM_SORTBOX 107 ! 10: #define IDM_CASESENS 108 ! 11: #define IDM_CANCEL 109 ! 12: ! 13: #define WM_INQUIREFILES WM_USER+0xc001 ! 14: #define WM_LAUNCH WM_USER+0xc002 ! 15: #define WM_FREEAGAIN WM_USER+0xc003 ! 16: #define WM_ADDITEM WM_USER+0xc004 ! 17: #define WM_TELLHANDLE WM_USER+0xc005 ! 18: #define WM_STARTSYNC WM_USER+0xc006 ! 19: ! 20: ! 21: #define MAXLINELEN 256 ! 22: #define FILBUFSIZE 16384 ! 23: #define MAX_CONCURRENT_THREADS 30 ! 24: ! 25: ! 26: BOOL InitApplication(HANDLE); ! 27: BOOL InitInstance(HANDLE, int); ! 28: long FAR PASCAL MainWndProc(HWND, UINT, UINT, LONG); ! 29: BOOL FAR PASCAL About(HWND, UINT, UINT, LONG); ! 30: ! 31: ! 32: typedef struct tagTHREADPBLOCK ! 33: { ! 34: int iLoop; ! 35: HWND hWndGlobal; ! 36: HWND hWndFileBox; ! 37: } THREADPBLOCK, *LPTHREADPBLOCK; ! 38: ! 39: ! 40: /*********************************************************************/ ! 41: /* */ ! 42: /* C++ declarations here */ ! 43: /* */ ! 44: /*********************************************************************/ ! 45: ! 46: /*********************************************************************/ ! 47: /* */ ! 48: /* The memory class is a simple fast allocator. It provides */ ! 49: /* one static memory block from which little chunks are */ ! 50: /* allocated by each thread. */ ! 51: /* */ ! 52: /*********************************************************************/ ! 53: ! 54: class memory ! 55: { ! 56: private: LPSTR lpBasePointer; /* Probably don't need this one at all... */ ! 57: LPSTR lpCurrentPointer; ! 58: LPSTR lpReturnPointer; ! 59: int iCurrentPointer; ! 60: int iActualBlockSize; ! 61: HANDLE hBlock; ! 62: CRITICAL_SECTION csAllocGuard; ! 63: public: memory(int); ! 64: ~memory(void); ! 65: LPSTR Alloc (int iSize) ! 66: { EnterCriticalSection(&csAllocGuard); ! 67: #ifdef MIPS ! 68: /* MIPS requires all DWORDs to be aligned on DWORD boundaries. ! 69: That's why under MIPS, we round up all alignments to ! 70: multiples of sizeof(DWORD). */ ! 71: if (iSize != (int)((iSize / sizeof (DWORD)) * sizeof (DWORD))) ! 72: iSize = (1 + (iSize / sizeof (DWORD))) * sizeof (DWORD); ! 73: #endif ! 74: if (iSize + iCurrentPointer > iActualBlockSize) ! 75: { MessageBox(GetFocus(),"No memory left", ! 76: "Grepper",MB_OK); ! 77: return((LPSTR)0); ! 78: }; ! 79: iCurrentPointer+= iSize; ! 80: lpReturnPointer = lpCurrentPointer; ! 81: _try { ! 82: lpCurrentPointer = &lpCurrentPointer[iSize]; ! 83: } ! 84: _except (EXCEPTION_EXECUTE_HANDLER) { ! 85: MessageBox(GetFocus(),"Access Violation","Memory Allocator",MB_OK); ! 86: }; ! 87: LeaveCriticalSection(&csAllocGuard); ! 88: return (lpReturnPointer); ! 89: }; ! 90: void Reset() ! 91: {lpCurrentPointer = lpBasePointer; ! 92: iCurrentPointer = 0; ! 93: }; ! 94: void Free (LPSTR lpBlockPt) ! 95: {}; ! 96: }; ! 97: ! 98: memory::memory(int iSize) ! 99: { ! 100: hBlock = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,iSize); ! 101: lpBasePointer = (LPSTR) LocalLock(hBlock); ! 102: lpCurrentPointer = lpBasePointer; ! 103: iActualBlockSize = iSize; ! 104: iCurrentPointer = 0; ! 105: InitializeCriticalSection(&csAllocGuard); ! 106: } ! 107: ! 108: memory::~memory() ! 109: { LocalUnlock(hBlock); ! 110: LocalFree(hBlock); ! 111: DeleteCriticalSection(&csAllocGuard); ! 112: } ! 113: ! 114: /*********************************************************************/ ! 115: /* */ ! 116: /* GrowMemory provides a growable block of memory. */ ! 117: /* It is used for the local handle of the edit box that */ ! 118: /* accomodates the hits. ! 119: /* */ ! 120: /*********************************************************************/ ! 121: ! 122: class growmemory ! 123: { ! 124: private: int iCurrentSize,iCurrentPt,iIncrement; ! 125: HANDLE hCurrentBlock; ! 126: LPSTR lpStartPt; ! 127: CRITICAL_SECTION csAllocGuard; ! 128: char lpszCRLF[3]; ! 129: int ilpszCRLF; ! 130: ! 131: public: growmemory(int iInitSize, int iInc); ! 132: ~growmemory(void); ! 133: BOOL add(LPSTR lpSource, int iSize) ! 134: /* watch out here: We assume that the requested size is never bigger than ! 135: the increment. This is safe with the hardcoded values but may fail in ! 136: the general case. */ ! 137: ! 138: { int iSizeOld = iSize; ! 139: EnterCriticalSection(&csAllocGuard); ! 140: /* adjust the size for the line feed to follow */ ! 141: iSize+=ilpszCRLF; ! 142: if (iCurrentPt+iSize > iCurrentSize) ! 143: {iCurrentSize+=iIncrement; ! 144: hCurrentBlock = LocalReAlloc(hCurrentBlock,iCurrentSize,LMEM_MOVEABLE); ! 145: }; ! 146: lpStartPt = (LPSTR)LocalLock(hCurrentBlock); ! 147: if (!lpStartPt) ! 148: { MessageBeep(0); ! 149: return(FALSE); }; ! 150: strncpy(&lpStartPt[iCurrentPt],lpSource,iSizeOld); ! 151: /* add the CRLF at the end. */ ! 152: strncpy(&lpStartPt[iCurrentPt+iSizeOld],lpszCRLF,ilpszCRLF); ! 153: LocalUnlock(hCurrentBlock); ! 154: iCurrentPt+=iSize; ! 155: LeaveCriticalSection(&csAllocGuard); ! 156: return(TRUE); ! 157: }; ! 158: HANDLE GetHandle(void) ! 159: { return (hCurrentBlock); ! 160: }; ! 161: }; ! 162: ! 163: growmemory::growmemory(int iInitSize, int iInc) ! 164: { iIncrement=iInc; ! 165: iCurrentPt=0; ! 166: iCurrentSize=iInitSize; ! 167: hCurrentBlock = LocalAlloc(LMEM_MOVEABLE,iCurrentSize); ! 168: InitializeCriticalSection(&csAllocGuard); ! 169: strcpy(lpszCRLF,"\r\n"); ! 170: ilpszCRLF=strlen(lpszCRLF); ! 171: } ! 172: growmemory::~growmemory(void) ! 173: {DeleteCriticalSection(&csAllocGuard); ! 174: LocalFree(hCurrentBlock); ! 175: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.