
BuildCmd       PROTO  :DWORD
MultSrc        PROTO  :DWORD, :DWORD, :DWORD, :DWORD


.data
szResr         db  'bin\rc ',0
;F:\Masm32\Bin\rc /I F:\Masm32\Include Pgm06.rc

szAsmb         db  'bin\ml /c /coff /Cp ',0
szAsmbB        db  'AsmEdit.asm',0
szIPath        db  '/I ',0
;F:\Masm32\Bin\ml /c /coff /Cp /I F:\Masm32\Include Pgm06.asm

szLinkE        db  'bin\link /SUBSYSTEM:WINDOWS ',0
szLinkD        db  'bin\link /SUBSYSTEM:WINDOWS /DLL /DEF:',0
szLinkL        db  'bin\lib ',0
szLinkLO       db  ' /out:',0
szLPath        db  '/RELEASE /VERSION:4.0 /LIBPATH:',0
;F:\Masm32\bin\link /SUBSYSTEM:WINDOWS /DLL /DEF:Pgmo6.def /LIBPATH:F:\Masm32\lib Pgm06.obj Pgm06.res
;F:\masm32\bin\link /SUBSYSTEM:WINDOWS /LIBPATH:F:\masm32\lib AsmEdit5.obj AsmEdit5.res
;F:\masm32\bin\lib Debug.obj /out:Debug.lib

szPathA        db  'Programs\AsmEdit\',0
szIncludeP     db  'Include ',0
szLibP         db  'Lib ',0

ExtObj         db  '.obj',0
ExtRC          db  '.rc',0
ExtRes         db  '.res',0
ExtExe         db  '.exe',0
ExtDll         db  '.dll',0

szQuote        db  '"',0
szSpace        db  ' ',0
szCol          db  ': ',0
szPerL         db  '(',0
szPerR         db  ')',0

szSavBuild     db  '[SaveBuild]',0
szR1E          db  'R1=',0
szA1E          db  'A1=',0
szL1E          db  'L1=',0
szL2E          db  'L2=',0

szAsm          db  'asm',0
szRsc          db  'rc',0
szObj          db  'obj',0
szRes          db  'res',0
szDef          db  'def',0
szInc          db  'inc',0
;szExe          db  'exe',0
szDll          db  'dll',0
szLib          db  'lib',0
szPtr          db  'ptr',0

rsrcrc         db  'rsrc.rc',0
rsrcres        db  'rsrc.res',0
szError        db  'error',0
szQZTest       db  'QZTest.txt',0

szP            db  'p',0
szTitle        db  'P R O J E C T  ',0
szCompile      db  ' Compiling: ',0
szLinking      db  ' Linking: ',0
szOutput       db  ' Output: ',0

BuildDone      db  0dh,'Build done.',0dh,0
szErrors       db  0dh,'Error(s) occured.',0dh,0
NoRC           db  0dh,'No .rc file found.',0dh,0
PipeError      db  'Error creating pipe',0
ProcessError   db  'Error creating process',0dh,0ah,0


.data?
hMult          dd  ?
hList340       dd  ?
swR            dd  ?
swA            dd  ?
swD            dd  ?
BuildCode      dd  ?
ExtractOn      dd  ?
PointerOn      dd  ?
PointOnMult    dd  ?
ErrorCode      dd  ?
Errors         dd  33 dup(?)

szRoot         db  64  dup(?)
CompA          db  25  dup(?)
CompR          db  25  dup(?)
szBuffRes      db  25  dup(?)
szBuffObj      db  256 dup(?)
szBuffDef      db  25  dup(?)
szBuffA        db  256 dup(?)
szBuffL        db  256 dup(?)
szBuffP        db  256 dup(?)
szBuffR        db  256 dup(?)
               
SavNameFull    db  30  dup(?)
szFullName     db  30  dup(?)
ErrorName      db  30  dup(?)

szRC           db  50  dup(?)
SaveDir        db  256 dup(?)
szAsmRoot      db  256 dup(?)
szLink         db  256 dup(?)
szOut          db  50  dup(?)

.code
;=========================================================================
; Build the make output PROCEDURE
;=========================================================================
BuildCreate PROC uses esi uMsg:DWORD, lpFileName
LOCAL    sat:SECURITY_ATTRIBUTES
LOCAL    stin:STARTUPINFO
LOCAL    prin:PROCESS_INFORMATION
LOCAL    ShFileOp:SHFILEOPSTRUCT
LOCAL    ftb:FINDTEXT
LOCAL    hReg:DWORD, hRead, hWrite, hFile, bytesRead, Cnt, Lnum, FirstError, hScroll
LOCAL    szBuff1[256]:BYTE, szBuff2[256]:BYTE, szOutBuff1[1024]:BYTE, PtrBuild[1024*2]:BYTE

      INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
      .if !eax
            xor     eax, eax
            ret
      .endif

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp

         mov     byte ptr szRoot, 0
         mov     lpcbData, sizeof szRoot
      INVOKE     RegQueryValueEx, hReg, addr rDEFb, 0, addr lpType, addr szRoot, addr lpcbData
      .if szRoot == ' ' || !szRoot
         INVOKE     MessageBox, NULL, addr szError4, addr AppName, MB_OK
         INVOKE     RegCloseKey, hReg
            jmp     GetOut
      .endif
         mov     lpcbData, 250
      INVOKE     RegQueryValueEx, hReg, addr rDEFr, 0, addr lpType, addr szAsmRoot, addr lpcbData
      INVOKE     RegCloseKey, hReg

         and     ErrorCode, 0

      INVOKE     LoadCursor, 0, IDC_WAIT
      INVOKE     SetCursor, eax
      INVOKE     SetFocus, hBEdit
         mov     szOutBuff1, 0
         mov     eax, uMsg
         mov     BuildCode, eax
      INVOKE     SendMessage, hREdit, UM_CLEARHILIGHTS, STATE_HILITE5, 0 ;Clear error HiLites

      .if !szProj
         .if !ExtractOn
               mov     szBuffR, 0
               mov     szBuffA, 0
               mov     szBuffL, 0
               mov     szBuffObj, 0
               and     swR, 0
               and     swA, 0
               and     swD, 0
              call     BuildInput
         .endif
         .if BuildCode == IDM_ASSEMBLE || BuildCode == IDM_BUILD
            .if !PointerOn && swA > 1 && !ExtractOn
               INVOKE     lstrcpy, addr szProj, addr szTitle
               INVOKE     SendMessage, hBEdit, WM_SETTEXT, 0, addr szProj
               INVOKE     UpdateWindow, hBEdit
                  mov     ErrorCode, -1
                  jmp     GetOut
            .endif
         .endif
            and     ExtractOn, 0
         INVOKE     GetCurrentDirectory, lengthof SaveDir, addr SaveDir
         INVOKE     lstrcpy, addr szBuff1, addr PathName
         INVOKE     StripFileExt, addr szBuff1
         INVOKE     StripFileName, addr szBuff1
         INVOKE     SetCurrentDirectory, addr szBuff1
         INVOKE     lstrcpy, addr szProj, addr szTitle
         INVOKE     lstrcat, addr szProj, addr ProjName
         INVOKE     lstrcat, addr szProj, addr szCRLF
         INVOKE     lstrcat, addr szProj, addr szCRLF
;         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
;         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szProj
         INVOKE     SendMessage, hBEdit, WM_SETTEXT, 0, addr szProj
         INVOKE     UpdateWindow, hBEdit
      .endif

         mov     eax, uMsg
      .if eax == IDM_COMPILE
         .if !swR
               jmp     GetOut
         .endif
         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szRC
         INVOKE     UpdateWindow, hBEdit
         INVOKE     BuildCmd, addr szBuffR
         .if !ErrorCode
            INVOKE     lstrcpy, addr szBuff1, addr szOutput
            INVOKE     lstrcat, addr szBuff1, addr ProjName
            INVOKE     lstrcat, addr szBuff1, addr ExtRes
            INVOKE     lstrcat, addr szBuff1, addr szCRLF
            INVOKE     lstrcat, addr szBuff1, addr szCRLF
            INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szBuff1
         .endif
jmp     GetOut


      .elseif eax == IDM_ASSEMBLE
         .if !swA
               jmp     GetOut
         .endif
         INVOKE     BuildCmd, addr szBuffA
         .if !ErrorCode
            INVOKE     lstrcpy, addr szBuff1, addr szCRLF
            INVOKE     lstrcat, addr szBuff1, addr szOutput
            INVOKE     lstrcat, addr szBuff1, addr ProjName
            INVOKE     lstrcat, addr szBuff1, addr ExtObj
            INVOKE     lstrcat, addr szBuff1, addr szCRLF
            INVOKE     lstrcat, addr szBuff1, addr szCRLF
            INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szBuff1
         .endif
jmp     GetOut

      .elseif eax == IDM_LINK
         .if !swA
               jmp     GetOut
         .endif
         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szLink
         INVOKE     BuildCmd, addr szBuffL
         .if !ErrorCode
            INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szOut
         .else
            INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
            INVOKE     lstrcpy, addr szBuff1, addr szCRLF
            INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szBuff1
         .endif
jmp     GetOut

      .elseif eax == IDM_BUILD
         .if !swR
               jmp     ChkAsm
         .endif
         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szRC
;         INVOKE     UpdateWindow, hBEdit
         INVOKE     BuildCmd, addr szBuffR
         .if ErrorCode
               jmp     GetOut
         .endif

ChkAsm:
         .if !swA
               jmp     GetOut
         .endif
         INVOKE     BuildCmd, addr szBuffA
         .if ErrorCode
               jmp     GetOut
         .endif

         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
         INVOKE     lstrcpy, addr szBuff1, addr szCRLF
         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szBuff1
         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szLink
         INVOKE     BuildCmd, addr szBuffL
         .if !ErrorCode
            INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szOut
            INVOKE     UpdateWindow, hBEdit

;**********************************************
;---------- [Reclaim physical memory (Dumb way)] ----------
            .if osvID == 1                                   ; Win9x or Win ME
               INVOKE     lstrcpy, addr szBuff1, addr szRoot
               INVOKE     lstrcat, addr szBuff1, addr szAsmb
               INVOKE     lstrcat, addr szBuff1, addr szIPath
               INVOKE     lstrcat, addr szBuff1, addr szRoot
               INVOKE     lstrcat, addr szBuff1, addr szIncludeP
               INVOKE     lstrcat, addr szBuff1, addr szAsmbB
               INVOKE     lstrcpy, addr szBuff2, addr szAsmRoot
               INVOKE     lstrcat, addr szBuff2, addr szPathA
               INVOKE     RtlZeroMemory, addr stin, sizeof STARTUPINFO
                  mov     stin.cb, sizeof STARTUPINFO
               INVOKE     GetStartupInfo, addr stin
                  mov     stin.wShowWindow, SW_HIDE
               INVOKE     CreateProcess, 0, addr szBuff1, 0, 0, FALSE,\
                          NORMAL_PRIORITY_CLASS, 0, addr szBuff2, addr stin, addr prin
               INVOKE     CloseHandle, prin.hThread
               INVOKE     CloseHandle, prin.hProcess
            .endif
            INVOKE     SetFocus, hREdit
;********************************************

            .if !PointerOn ;&& swA > 1
;---------- [Build Pointer file if missing] ----------
               INVOKE     lstrcpy, addr PtrBuild, addr ProjName
               INVOKE     lstrcat, addr PtrBuild, addr szCol
               INVOKE     lstrcpy, addr szBuff1, addr PathName
               INVOKE     StripFileExt, addr szBuff1
               INVOKE     StripFileName, addr szBuff1
               INVOKE     lstrcat, addr PtrBuild, addr szBuff1
               INVOKE     lstrcat, addr PtrBuild, addr szCRLF
               INVOKE     lstrcat, addr PtrBuild, addr szCRLF
               .if swA > 1
                  INVOKE     lstrcat, addr PtrBuild, addr szSavBuild
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szR1E
                  INVOKE     lstrcat, addr PtrBuild, addr szBuffR
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szA1E
                  INVOKE     lstrcat, addr PtrBuild, addr szBuffA
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szL1E
                  INVOKE     lstrcat, addr PtrBuild, addr szBuffL
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szL2E
                  INVOKE     lstrcat, addr PtrBuild, addr szLink
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
               .endif
;               INVOKE     SendMessage, hParent, WM_COMMAND, 6066, 0    ; Undo Redo

               INVOKE     CreateFile, addr szBuffP,\
                          GENERIC_READ or GENERIC_WRITE ,\
                          FILE_SHARE_READ or FILE_SHARE_WRITE,\
                          NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
               .if eax == -1 || swA > 1
                  INVOKE     GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, 100000
                     mov     hpMem, eax
                  INVOKE     GlobalLock, hpMem
                     mov     fpMem, eax
               .else
                  INVOKE     CloseHandle, eax
                     jmp     GetOut
               .endif

               INVOKE     CreateFile, addr szBuffP,\
                          GENERIC_READ or GENERIC_WRITE ,\
                          FILE_SHARE_READ or FILE_SHARE_WRITE,\
                          NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL
               .if !eax
                     jmp     ClearMem
               .endif
                  mov     hFile, eax
               INVOKE     lstrlen, addr PtrBuild
                  mov     ecx, eax
               INVOKE     WriteFile, hFile, addr PtrBuild, ecx, addr bytesRead, NULL
               INVOKE     CloseHandle, hFile

;               INVOKE     lstrcpy, addr szProject, addr ProjName
                  mov     eax, ProjGroup
               INVOKE     lstrcpy, ProjNamArray[eax*4], addr ProjName
.if !PointOnMult
               INVOKE     LoadTreeView, addr ProjName, 0
               .if eax
                     mov     hItem, eax
                  INVOKE     LoadTreeView, addr ProjName, 1
               .endif
.else
   INVOKE     LoadTreeView, addr ProjName, 1
.endif


ClearMem:
               INVOKE     GlobalUnlock, fpMem
               INVOKE     GlobalFree, hpMem
                  jmp     GetOut
            .endif

         .else
            INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
            INVOKE     lstrcpy, addr szBuff1, addr szCRLF
            INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szBuff1
         .endif
jmp     GetOut

      .endif

GetOut:
      .if ErrorCode
         INVOKE     SendMessage, hBEdit, UM_GETHSCROLLHANDLE, 0, 0
            mov     hScroll, eax
            mov     sci.cbSize, sizeof sci
            mov     sci.fMask, SIF_ALL
         INVOKE     GetScrollInfo, hScroll, SB_CTL, addr sci
            mov     sci.nPos, 0
         INVOKE     SetScrollInfo, hScroll, SB_CTL, addr sci, TRUE
            xor     eax, eax
            shl     eax, 16
            mov     ecx, SB_THUMBPOSITION
            mov     ax, cx
         INVOKE     SendMessage, hBEdit, WM_HSCROLL, eax, hScroll

;---------- [Get the Error line number(s)] ----------
            and     Cnt, 0
            and     FirstError, 0
 ;           and     NumErr, 0
 ;           and     hSavEdit, 0
            mov     ft.chrg.cpMin, 0

FindNext:
            mov     ft.chrg.cpMax, -1
            lea     eax, offset szError
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hBEdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax == -1
               jmp     AllDone
         .else
               mov     ft.chrg.cpMax, eax
               sub     eax, 15
               mov     ft.chrg.cpMin, eax
               lea     eax, offset szPerL
               mov     ft.lpstrText, eax
            INVOKE     SendMessage, hBEdit, EM_FINDTEXT, FR_DOWN, addr ft
            .if eax != -1
                  mov     ecx, eax
                  inc     eax
                  mov     cr.cpMin, eax

               INVOKE     SendMessage, hBEdit, EM_LINEFROMCHAR, ecx, 0
                  mov     Lnum, eax
                  mov     word ptr szBuff1, 255
               INVOKE     SendMessage, hBEdit, EM_GETLINE, Lnum, addr szBuff1
                  mov     byte ptr szBuff1[eax], 0
               INVOKE     SendMessage, hBEdit, EM_LINEINDEX, Lnum, 0
                  mov     ecx, cr.cpMin
                  sub     ecx, eax
               INVOKE     lstrcpyn, addr ErrorName, addr szBuff1, ecx
               INVOKE     lstrlen, addr ErrorName
               .if byte ptr szFullName[eax-1] == ' '
                  INVOKE     lstrcpyn, addr ErrorName, addr ErrorName, eax
               .endif

;---------- [Check to see if error is for the displayed file] ----------
               INVOKE     lstrcmpi, addr FileName, addr ErrorName
               .if eax == 0
;---------- [Get the line number] ----------
                     lea     eax, offset szPerR
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hBEdit, EM_FINDTEXT, FR_DOWN, addr ft
                  .if eax != -1
                        mov     cr.cpMax, eax
                     INVOKE     SendMessage, hBEdit, EM_EXSETSEL, 0, addr cr
                     INVOKE     SendMessage, hBEdit, EM_GETSELTEXT, 0, addr szBuff1
                       push     cr.cpMin
                        pop     cr.cpMax
                     INVOKE     SendMessage, hBEdit, EM_EXSETSEL, 0, addr cr
                     INVOKE     AsciiBase, addr szBuff1, addr Lnum, 10
                        dec     Lnum
                     .if !FirstError
                         MOVmd     FirstError, Lnum
                     .endif
                     INVOKE     SendMessage, hREdit, UM_SETHILITELINE, Lnum, 5
                  .endif
               .endif
            .endif
         .endif
           push     ft.chrg.cpMax
            pop     ft.chrg.cpMin
            inc     ft.chrg.cpMin
            jmp     FindNext

AllDone:
         INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
         INVOKE     lstrcpy, addr szBuff1, addr szCRLF
         INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szBuff1
         INVOKE     SendMessage, hBEdit, EM_EXGETSEL, 0, addr cr
            dec     cr.cpMin
            dec     cr.cpMax
         INVOKE     SendMessage, hBEdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hBEdit, EM_SCROLLCARET, 0, 0
;         INVOKE     UpdateWindow, hBuild ;hBEdit

         .if FirstError
            INVOKE     SendMessage, hREdit, EM_LINEINDEX, FirstError, 0
               mov     cr.cpMin, eax
               mov     cr.cpMax, eax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
            INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
              call     CenterSel
         .endif
      .endif

;---------- [Send a dummy SHNotify
      INVOKE     lstrcpy, addr szBuff1, addr PathName
      INVOKE     StripFileExt, addr szBuff1
      INVOKE     StripFileName, addr szBuff1
      INVOKE     lstrcat, addr szBuff1, addr szQZTest

      INVOKE     CreateFile, addr szBuff1,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL
      .if eax == -1 || !eax
            jmp     NoFile
      .endif
         mov     hFile, eax
      INVOKE     CloseHandle, hFile

      INVOKE     lstrlen, addr szBuff1
         inc     eax
         mov     szBuff1[eax], 0        ; Insert additional terminator
         mov     ShFileOp.wFunc, FO_DELETE
         mov     ShFileOp.hwnd, 0       ; If 0, then no parent can task switch away
         lea     eax, szBuff1
         mov     ShFileOp.pFrom, eax
         mov     ShFileOp.pTo, 0
         mov     ShFileOp.fFlags, FOF_SILENT or FOF_NOCONFIRMATION
      INVOKE     SHFileOperation, addr ShFileOp
;----------

NoFile:
      INVOKE     LoadCursor, 0, IDC_ARROW
      INVOKE     SetCursor, eax
         mov     eax, ErrorCode
         ret

BuildCreate ENDP

;=========================================================================
; Executes the batch commands PROCEDURE
;=========================================================================
BuildCmd PROC Input:DWORD
LOCAL    sat:SECURITY_ATTRIBUTES
LOCAL    stin:STARTUPINFO
LOCAL    prin:PROCESS_INFORMATION
LOCAL    ftb:FINDTEXT
LOCAL    hRead:DWORD, hWrite, bytesRead
LOCAL    szOutputB[1024]:BYTE, szBuff1[256]:BYTE

         mov     sat.nLength, sizeof SECURITY_ATTRIBUTES
         mov     sat.lpSecurityDescriptor, NULL
         mov     sat.bInheritHandle, TRUE
      INVOKE     CreatePipe, addr hRead, addr hWrite, addr sat, NULL
      .if eax == NULL
;CreatePipe failed
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
         INVOKE     MessageBox, hWnd, addr PipeError, addr AppName, MB_ICONERROR or MB_OK

      .else
            mov     stin.cb, sizeof STARTUPINFO
         INVOKE     GetStartupInfo, addr stin
            mov     eax, hWrite
            mov     stin.hStdOutput, eax
            mov     stin.hStdError, eax
            mov     stin.dwFlags, STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES
            mov     stin.wShowWindow, SW_HIDE
;Create process
         INVOKE     CreateProcess, NULL, Input, NULL, NULL, TRUE, NULL, NULL,\
                    NULL, addr stin, addr prin
         .if eax == NULL
;CreateProcess failed
            INVOKE     CloseHandle, hRead
            INVOKE     CloseHandle, hWrite
            INVOKE     LoadCursor, 0, IDC_ARROW
            INVOKE     SetCursor, eax
            INVOKE     lstrcpy, addr szBuff1, addr ProcessError
            INVOKE     lstrcat, addr szBuff1, addr Input
            INVOKE     MessageBox, hWnd, addr szBuff1, addr AppName, MB_ICONERROR or MB_OK

         .else
            INVOKE     CloseHandle, prin.hProcess
            INVOKE     CloseHandle, prin.hThread
            INVOKE     CloseHandle, hWrite

            .while (TRUE)
               INVOKE     RtlZeroMemory, addr szOutputB, sizeof szOutputB
               INVOKE     ReadFile, hRead, addr szOutputB, 1023, addr bytesRead, NULL ;1023
               .if eax == NULL
                  .break
               .else
;INVOKE     MessageBox, NULL, addr szOutputB, addr AppName, MB_OK
.if byte ptr szOutputB+3 == 'C' && byte ptr szOutputB+7 == 't'
INVOKE     lstrcat, addr szOutputB, addr szCR
.endif
                  INVOKE     SendMessage, hBEdit, EM_SETSEL, -1, 0
                  INVOKE     SendMessage, hBEdit, EM_REPLACESEL, FALSE, addr szOutputB
                  INVOKE     UpdateWindow, hBEdit
               .endif
            .endw

            INVOKE     CloseHandle, hRead
         .endif

;Check for errors
            mov     ftb.chrg.cpMin, 0
            mov     ftb.chrg.cpMax, -1
            lea     eax, offset szError
            mov     ftb.lpstrText, eax
         INVOKE     SendMessage, hBEdit, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr ftb
         .if eax != -1
               mov     ErrorCode, -1
         .else
         .endif
      .endif

         xor     eax, eax

         ret
BuildCmd ENDP

;=========================================================================
; Build the input buffers PROCEDURE
;=========================================================================
BuildInput PROC uses ebx esi edi
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    hReg:DWORD, hFind, Proj, Cnt
LOCAL    szBuff[64]:BYTE, szBuff0[256]:BYTE, szWork1[256]:BYTE, szWork2[64]:BYTE

      .if !hMult
         INVOKE     CreateDialogParam, hInst, 4804, hWnd, addr MultSrc, 0
            mov     hMult, eax
      .else
         INVOKE     SendMessage, hList340, LB_RESETCONTENT, 0, 0
      .endif

;---------- [See if it's a project] ----------
         and     Proj, 0
         mov     eax, hREdit
         mov     esi, hProjArray
         xor     edi, edi
       MOVmd     Cnt, ProjCnt
      .while (Cnt)
            mov     eax, hREdit
         .if dword ptr[esi+edi] == eax

               mov     ecx, esi
               add     ecx, edi
               add     ecx, 10 ;9
            INVOKE     lstrcpy, addr szWork2, ecx
;            INVOKE     lstrcmpi, addr szWork2, addr szProject
               mov     eax, ProjGroup
            INVOKE     lstrcmpi, addr szWork2, ProjNamArray[eax*4]
            .if eax == 0
                  mov     eax, dword ptr[esi+edi+4]
                  mov     Proj, eax
               .break
            .endif
         .endif
            add     edi, 36
            dec     Cnt
      .endw

;---------- [Get the folder name] ----------
      INVOKE     lstrcpy, addr szBuff0, addr PathName
      INVOKE     StripFileExt, addr szBuff0
      INVOKE     StripFileName, addr szBuff0

      INVOKE     lstrlen, addr szBuff0
        push     eax
         dec     eax
      .while (eax)
            dec     eax
         .if byte ptr szBuff0[eax] == '\'
            .break
         .endif
      .endw
         pop     ecx
         inc     eax
         sub     ecx, eax
      INVOKE     lstrcpyn, addr szFolder, addr szBuff0[eax], ecx
      .if Proj
;         INVOKE     lstrcpy, addr ProjName, addr szProject
            mov     eax, ProjGroup
         INVOKE     lstrcpy, addr ProjName, ProjNamArray[eax*4]
      .else
         INVOKE     lstrcpy, addr ProjName, addr szFolder
      .endif

;---------- [Build the batch command files
      INVOKE     lstrcpy, addr CompA, addr ProjName
      INVOKE     lstrcat, addr CompA, addr szPer
      INVOKE     lstrcat, addr CompA, addr szAsm
      INVOKE     lstrcpy, addr CompR, addr ProjName
      INVOKE     lstrcat, addr CompR, addr szPer
      INVOKE     lstrcat, addr CompR, addr szRsc

      INVOKE     lstrcpy, addr szBuffR, addr szRoot
      INVOKE     lstrcpy, addr szBuffA, addr szRoot
      INVOKE     lstrcpy, addr szBuffL, addr szRoot
      INVOKE     lstrcat, addr szBuffR, addr szResr
      INVOKE     lstrcat, addr szBuffA, addr szAsmb

      INVOKE     lstrcat, addr szBuffR, addr szIPath
      INVOKE     lstrcat, addr szBuffR, addr szRoot
      INVOKE     lstrcat, addr szBuffR, addr szIncludeP

      INVOKE     lstrcat, addr szBuffA, addr szIPath
      INVOKE     lstrcat, addr szBuffA, addr szRoot
      INVOKE     lstrcat, addr szBuffA, addr szIncludeP

      INVOKE     lstrcpy, addr szLink, addr szLinking

         and     PointerOn, 0
         and     PointOnMult, 0
      INVOKE     lstrcpy, addr szBuffP, addr szAsmRoot
;      INVOKE     lstrcat, addr szBuffP, addr szPointer

      .if ProjGroup
         INVOKE     lstrcat, addr szBuffP, addr szPointUser
      .endif
         mov     ecx, ProjGroup
      INVOKE     lstrcat, addr szBuffP, PtrArray[ecx*4]

      INVOKE     lstrcat, addr szBuffP, addr ProjName
      INVOKE     lstrcat, addr szBuffP, addr szPer
      INVOKE     lstrcat, addr szBuffP, addr szPtr
      INVOKE     GetFileAttributes, addr szBuffP
      .if eax != -1
            mov     PointerOn, 1
            mov     PointOnMult, 1
      .endif

      INVOKE     lstrcpy, addr szBuff0, addr PathName
      INVOKE     StripFileExt, addr szBuff0
      INVOKE     StripFileName, addr szBuff0
      INVOKE     lstrcat, addr szBuff0, addr szAll
      INVOKE     FindFirstFile, addr szBuff0, addr FindData
        test     eax, eax
          js     Ret0
         mov     hFind, eax

GetNext:
      INVOKE     FindNextFile, hFind, addr FindData
      .if eax == 0
            jmp     AllDone
      .endif

ChkFile:
      .if byte ptr FindData.cFileName == '.'
            jmp     GetNext
      .else
;         INVOKE     lstrcmpi, addr FindData.cFileName, addr szCallDLL
;         .if eax == 0
;               jmp     GetNext
;         .endif
      .endif
      INVOKE     lstrlen, addr FindData.cFileName
         mov     Cnt, eax
         sub     eax, 3
         lea     esi, FindData.cFileName
         add     esi, eax
         mov     ecx, 3
        call     LowerCase                ; Convert to lowercase for compare

      .while (Cnt)
            dec     Cnt
            mov     eax, Cnt
         .if byte ptr FindData.cFileName[eax] == '.'
            .if byte ptr FindData.cFileName[eax+1] == 'r' && byte ptr FindData.cFileName[eax+2] == 'c'

;**********
;---------- [Remove the comments below if you want the .rc
;            file to have the same name as the pri pgm or project name] ----------

               .if Proj
                  INVOKE     lstrcmpi, addr CompR, addr FindData.cFileName
                  .if eax != 0
                     .break
                  .endif
               .endif

;*********
                  mov     swR, 1
               INVOKE     lstrcat, addr szBuffR, addr FindData.cFileName
               INVOKE     lstrlen, addr FindData.cFileName
                  dec     eax
               INVOKE     lstrcpyn, addr szBuffRes, addr FindData.cFileName, eax
               INVOKE     lstrcat, addr szBuffRes, addr szRes
               INVOKE     lstrcpy, addr szRC, addr szCompile
               INVOKE     lstrcat, addr szRC, addr FindData.cFileName
               INVOKE     lstrcat, addr szRC, addr szCRLF
               INVOKE     lstrcat, addr szRC, addr szCRLF

            .elseif byte ptr FindData.cFileName[eax+1] == 'a' && byte ptr FindData.cFileName[eax+2] == 's'
                  inc     swA
               INVOKE     SendMessage, hList340, LB_ADDSTRING, 0, addr FindData.cFileName
               .if Proj
;                  INVOKE     lstrcmpi, addr CompA, addr FindData.cFileName
;                  .if !eax
;                     .break
;                  .endif
               .endif
               INVOKE     lstrcat, addr szBuffA, addr FindData.cFileName
               INVOKE     lstrcat, addr szBuffA, addr szSpace
               INVOKE     lstrcpy, addr szBuff, addr FindData.cFileName
               INVOKE     lstrlen, addr szBuff
                  sub     eax, 2
               INVOKE     lstrcpyn, addr szBuff, addr szBuff, eax
               INVOKE     lstrcat, addr szBuff, addr szObj
               INVOKE     lstrcat, addr szBuffObj, addr szBuff
               INVOKE     lstrcat, addr szBuffObj, addr szSpace
;DSPValue hWnd, swA, 1, 't'
;INVOKE     MessageBox, NULL, addr szBuffA, addr AppName, MB_OK

            .elseif byte ptr FindData.cFileName[eax+1] == 'd' && byte ptr FindData.cFileName[eax+2] == 'e'
                  mov     swD, 1
               INVOKE     lstrlen, addr FindData.cFileName
                  sub     eax, 2
               INVOKE     lstrcpyn, addr szBuffDef, addr FindData.cFileName, eax
               INVOKE     lstrcat, addr szBuffDef, addr szDef
               INVOKE     lstrcat, addr szBuffDef, addr szSpace
            .else
               .break
            .endif
         .endif
      .endw
         jmp     GetNext

AllDone:
      INVOKE     FindClose, hFind

;---------- [Build the link command
      .if swA && !swD
         INVOKE     lstrcat, addr szBuffL, addr szLinkE
         INVOKE     lstrcat, addr szBuffL, addr szLPath
         INVOKE     lstrcat, addr szBuffL, addr szRoot
         INVOKE     lstrcat, addr szBuffL, addr szLibP
         INVOKE     lstrcat, addr szBuffL, addr szBuffObj
         .if swR
            INVOKE     lstrcat, addr szBuffL, addr szBuffRes
         .endif
      .elseif swD
         INVOKE     lstrcat, addr szBuffL, addr szLinkD
         INVOKE     lstrcat, addr szBuffL, addr szBuffDef
         INVOKE     lstrcat, addr szBuffL, addr szLPath
         INVOKE     lstrcat, addr szBuffL, addr szRoot
         INVOKE     lstrcat, addr szBuffL, addr szLibP
         INVOKE     lstrcat, addr szBuffL, addr szBuffObj
         .if swR
            INVOKE     lstrcat, addr szBuffL, addr szBuffRes
         .endif
      .endif

;---------- [Build the output
      INVOKE     lstrcat, addr szLink, addr szBuffObj
      .if swR
         INVOKE     lstrcat, addr szLink, addr szBuffRes
      .endif
      INVOKE     lstrcat, addr szLink, addr szCRLF
      INVOKE     lstrcat, addr szLink, addr szCRLF
      INVOKE     lstrcpy, addr szOut, addr szCRLF
      INVOKE     lstrcat, addr szOut, addr szOutput
      INVOKE     lstrcat, addr szOut, addr ProjName
      .if swA && !swD
         INVOKE     lstrcat, addr szOut, addr ExtExe
      .elseif swD
         INVOKE     lstrcat, addr szOut, addr ExtDll
      .endif
      INVOKE     lstrcat, addr szOut, addr szCRLF
      INVOKE     lstrcat, addr szOut, addr szCRLF

;INVOKE     MessageBox, NULL, addr szBuffA, addr AppName, MB_OK
;INVOKE     MessageBox, NULL, addr szBuffL, addr AppName, MB_OK
;INVOKE     MessageBox, NULL, addr szLink, addr AppName, MB_OK

;---------- [Overwrite batch commands if pointer file
      .if PointerOn
         INVOKE     GetPrivateProfileString, addr szPtrS, addr szL1, addr szNULL, addr szBuff, 255, addr szBuffP
         .if eax < 2 ;== 0
               and     PointerOn, 0
;               ret
               jmp     ChkMult
         .endif
         INVOKE     GetPrivateProfileString, addr szPtrS, addr szR1, addr szNULL, addr szBuffR, 255, addr szBuffP
         INVOKE     GetPrivateProfileString, addr szPtrS, addr szA1, addr szNULL, addr szBuffA, 255, addr szBuffP
         INVOKE     GetPrivateProfileString, addr szPtrS, addr szL1, addr szNULL, addr szBuffL, 255, addr szBuffP
         INVOKE     GetPrivateProfileString, addr szPtrS, addr szL2, addr szNULL, addr szBuff, 255, addr szBuffP
         INVOKE     lstrcpy, addr szLink, addr szSpace
         INVOKE     lstrcat, addr szLink, addr szBuff
         INVOKE     lstrcat, addr szLink, addr szCRLF
         INVOKE     lstrcat, addr szLink, addr szCRLF

;INVOKE     MessageBox, NULL, addr szBuffA, addr AppName, MB_OK
;INVOKE     MessageBox, NULL, addr szBuffL, addr AppName, MB_OK
;INVOKE     MessageBox, NULL, addr szLink, addr AppName, MB_OK
      .endif

ChkMult:
      .if !PointerOn && swA > 1 && BuildCode == IDM_ASSEMBLE ||\
          !PointerOn && swA > 1 && BuildCode == IDM_BUILD
         INVOKE     GetDlgItem, hMult, 240           ; Get the handle of the Edit
            mov     ecx, eax
         INVOKE     SendMessage, ecx, WM_SETTEXT, 0, addr ProjName
         INVOKE     SendMessage, hList340, LB_SETSEL, TRUE, 0
         INVOKE     ShowWindow, hMult, SW_SHOWNORMAL
      .endif

Ret0:
         xor     eax, eax
         ret

BuildInput ENDP

;=========================================================================
; Multiple Source PROCEDURE                                              *
;=========================================================================
MultSrc  PROC  uses ebx  hdlg:DWORD, wmsg, wparam, lparam
LOCAL    rect:RECT
LOCAL    CntL:DWORD, Num, Val, xPos
LOCAL    szNameL[256]:BYTE, szBuff0[64]:BYTE, szBuff[64]:BYTE

      .if wmsg == WM_INITDIALOG


         INVOKE     GetWindowRect, hdlg, addr rect
            mov     eax, rect.top
            sub     rect.bottom, eax
            mov     eax, rect.left
            sub     rect.right, eax
            mov     eax, rect.right
          MOVmd     xPos, xBuild
            sub     xPos, eax
         INVOKE     MoveWindow, hdlg, xPos, yBuild, rect.right, rect.bottom, TRUE

         INVOKE     GetDlgItem, hdlg, 340           ; Get the handle of the Listbox
            mov     hList340, eax                   ; Save it
         INVOKE     GetDlgItem, hdlg, 240           ; Get the handle of the Edit
            mov     ebx, eax
         INVOKE     SendMessage, ebx, WM_SETTEXT, NULL, addr ProjName
            jmp     MultSrcDone

      .elseif wmsg == WM_CTLCOLORDLG || wmsg == WM_CTLCOLORSTATIC
         .if hBR
            INVOKE     DeleteObject, hBR
         .endif
         INVOKE     SetBkColor, wparam, 00ffffe0h
         INVOKE     SetTextColor, wparam, 00000000h
         INVOKE     CreateSolidBrush, 00ffffe0h
            mov     hBR, eax
            ret

      .elseif wmsg == WM_CTLCOLORLISTBOX ||  wmsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wparam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wparam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wmsg == WM_CLOSE
            jmp     wmclose

GetOut:
         .if BuildCode == IDM_ASSEMBLE
            INVOKE     PostMessage, hWnd, WM_COMMAND, IDM_ASSEMBLE, 0
         .elseif BuildCode == IDM_BUILD
            INVOKE     PostMessage, hWnd, WM_COMMAND, IDM_BUILD, 0
         .endif

wmclose:
            and     hMult, 0
         .if hBR
            INVOKE     DeleteObject, hBR
               and     hBR, 0
         .endif
         INVOKE     EndDialog, hdlg, wparam
            mov     eax, TRUE
            jmp     MultSrcRet

      .elseif wmsg != WM_COMMAND
            jmp     MultSrcDone
      .endif
         mov     eax, wparam
      .if ax == 540
         INVOKE     GetDlgItem, hdlg, 240           ; Get the handle of the Edit
            mov     ebx, eax
         INVOKE     SendMessage, ebx, WM_GETTEXT, 24, addr ProjName ;FileName
         INVOKE     ShowWindow, hMult, SW_HIDE
         INVOKE     lstrcpy, addr CompA, addr ProjName
         INVOKE     lstrcat, addr CompA, addr szPer
         INVOKE     lstrcat, addr CompA, addr szAsm
         INVOKE     lstrcpy, addr CompR, addr ProjName
         INVOKE     lstrcat, addr CompR, addr szPer
         INVOKE     lstrcat, addr CompR, addr szRsc
         INVOKE     lstrcpy, addr szBuffA, addr szRoot
         INVOKE     lstrcat, addr szBuffA, addr szAsmb

         INVOKE     lstrcat, addr szBuffA, addr szIPath
         INVOKE     lstrcat, addr szBuffA, addr szRoot
         INVOKE     lstrcat, addr szBuffA, addr szIncludeP

         INVOKE     lstrcat, addr szBuffA, addr ProjName
         INVOKE     lstrcat, addr szBuffA, addr szPer
         INVOKE     lstrcat, addr szBuffA, addr szAsm
         INVOKE     lstrcat, addr szBuffA, addr szSpace
            mov     byte ptr szBuffObj, 0
         INVOKE     lstrcat, addr szBuffObj, addr ProjName
         INVOKE     lstrcat, addr szBuffObj, addr szPer
         INVOKE     lstrcat, addr szBuffObj, addr szObj
         INVOKE     lstrcat, addr szBuffObj, addr szSpace

         INVOKE     lstrcpy, addr szBuffP, addr szAsmRoot
;         INVOKE     lstrcat, addr szBuffP, addr szPointer

      .if ProjGroup
         INVOKE     lstrcat, addr szBuffP, addr szPointUser
      .endif
         mov     ecx, ProjGroup
      INVOKE     lstrcat, addr szBuffP, PtrArray[ecx*4]

         INVOKE     lstrcat, addr szBuffP, addr ProjName
         INVOKE     lstrcat, addr szBuffP, addr szPer
         INVOKE     lstrcat, addr szBuffP, addr szPtr

         INVOKE     SendMessage, hList340, LB_GETSELCOUNT, 0, 0
         .if !eax
               jmp     MultSrcDone
         .endif
            mov     ebx, eax
         INVOKE     SendMessage, hList340, LB_GETSELITEMS, ebx, addr szNameL
            mov     Num, eax
            mov     Val, eax
            and     CntL, 0
         .while (Num)
               mov     ecx, CntL
            INVOKE     SendMessage, hList340, LB_GETTEXT, dword ptr szNameL[ecx*4], addr szBuff0
            INVOKE     lstrcmpi, addr CompA, addr szBuff0
            .if eax != 0 && Val != 1
               INVOKE     lstrcat, addr szBuffA, addr szBuff0
               INVOKE     lstrcat, addr szBuffA, addr szSpace
               INVOKE     lstrcpy, addr szBuff, addr szBuff0
               INVOKE     lstrlen, addr szBuff
                  sub     eax, 2
               INVOKE     lstrcpyn, addr szBuff, addr szBuff, eax
               INVOKE     lstrcat, addr szBuff, addr szObj
               INVOKE     lstrcat, addr szBuffObj, addr szBuff
               INVOKE     lstrcat, addr szBuffObj, addr szSpace
            .endif
               inc     CntL
               dec     Num
         .endw
            mov     ExtractOn, 1

;---------- [Build the link command
         INVOKE     lstrcpy, addr szBuffL, addr szRoot
         .if swA && !swD
            INVOKE     lstrcat, addr szBuffL, addr szLinkE
            INVOKE     lstrcat, addr szBuffL, addr szLPath
            INVOKE     lstrcat, addr szBuffL, addr szRoot
            INVOKE     lstrcat, addr szBuffL, addr szLibP
            INVOKE     lstrcat, addr szBuffL, addr szBuffObj
            .if swR
               INVOKE     lstrcat, addr szBuffL, addr szBuffRes
            .endif
         .elseif swD
            INVOKE     lstrcat, addr szBuffL, addr szLinkD
            INVOKE     lstrcat, addr szBuffL, addr szBuffDef
            INVOKE     lstrcat, addr szBuffL, addr szLPath
            INVOKE     lstrcat, addr szBuffL, addr szRoot
            INVOKE     lstrcat, addr szBuffL, addr szLibP
            INVOKE     lstrcat, addr szBuffL, addr szBuffObj
            .if swR
               INVOKE     lstrcat, addr szBuffL, addr szBuffRes
            .endif
         .endif

;---------- [Build the output
         INVOKE     lstrcpy, addr szLink, addr szLinking
         INVOKE     lstrcat, addr szLink, addr szBuffObj
         .if swR
            INVOKE     lstrcat, addr szLink, addr szBuffRes
         .endif
         INVOKE     lstrcat, addr szLink, addr szCRLF
         INVOKE     lstrcat, addr szLink, addr szCRLF
         INVOKE     lstrcpy, addr szOut, addr szCRLF
         INVOKE     lstrcat, addr szOut, addr szOutput
         INVOKE     lstrcat, addr szOut, addr ProjName
         .if swA && !swD
            INVOKE     lstrcat, addr szOut, addr ExtExe
         .elseif swD
            INVOKE     lstrcat, addr szOut, addr ExtDll
         .endif
         INVOKE     lstrcat, addr szOut, addr szCRLF
         INVOKE     lstrcat, addr szOut, addr szCRLF
;INVOKE     MessageBox, NULL, addr szBuffA, addr AppName, MB_OK
;INVOKE     MessageBox, NULL, addr szBuffL, addr AppName, MB_OK
            jmp     GetOut
      .endif

MultSrcDone:
         mov     eax, FALSE           ; Return with FALSE

MultSrcRet:
         RET
MultSrc  ENDP

;===================================================
; Build PROCEDURE
;===================================================
BuildProc PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_SIZE
            mov     edx, hwnd
            mov     eax, lparam
            mov     ecx, eax
            shr     ecx, 16
            and     eax, 0ffffh

         INVOKE     MoveWindow, hBEdit, 0, 0, eax, ecx, TRUE

      .elseif wmsg == WM_COMMAND
            mov     eax, wparam
           cwde                        ; Only low word contains command

      .elseif wmsg == WM_CLOSE
         INVOKE     ShowWindow, hBuild, SW_HIDE

      .else
         INVOKE     DefWindowProc, hwnd, wmsg, wparam, lparam
            ret
      .endif

         mov     eax, FALSE            ; Return with FALSE
         ret

BuildProc ENDP

;===================================================
; Build Edit PROCEDURE - Work Edit is a SUB CLASS
;===================================================
BuildEditProc PROC uses ebx esi edi hwnd, wmsg, wparam, lparam
LOCAL    rect:RECT
LOCAL    Cnt:DWORD, Chg, LNumB, LNum
LOCAL    szBuff[256]:BYTE, szBuff0[256]:BYTE, szLineNum[24]:BYTE

      .if wmsg == WM_LBUTTONUP

;---------- [Scroll the error line on the Parent Window into view] ----------
         INVOKE     SendMessage, hBEdit, EM_GETSELTEXT, 0, addr szBuff0
         INVOKE     SendMessage, hBEdit, EM_EXGETSEL, 0, addr cr
         INVOKE     SendMessage, hBEdit, EM_LINEINDEX, -1, 0
           push     eax
         INVOKE     SendMessage, hBEdit, EM_SETSEL, eax, eax
            pop     ecx
         INVOKE     SendMessage, hBEdit, EM_LINEFROMCHAR, ecx, 0
            mov     LNumB, eax
         INVOKE     lstrlen, addr szBuff0
         .if eax > 250
               jmp      ThatsAll
         .endif
            mov     ecx, eax
            xor     eax, eax
            lea     esi, szBuff0
            lea     edi, szLineNum
            lea     edx, ErrorName
         .while (ecx)
            .if byte ptr[esi] == '('
                  inc     esi
                  mov     al, byte ptr[esi]
                  mov     byte ptr[edi], al
                  inc     esi
                  inc     edi
                  sub     ecx, 2
               .while (ecx)
                  .if byte ptr[esi] == ')' && byte ptr[esi]+2 == ':' && byte ptr[esi]+4 == 'e' ||\
                      byte ptr[esi] == ')' && byte ptr[esi]+1 == ':' && byte ptr[esi]+3 == 'e'
                        mov     byte ptr[edi], 0
                        mov     byte ptr[edx], 0
                     INVOKE     SendMessage, hBEdit, UM_SETHILITELINE, LNumB, 6
                        jmp     GotIt
                  .else
                     mov     al, byte ptr[esi]
                     mov     byte ptr[edi], al
                     inc     esi
                     inc     edi
                     dec     ecx
                  .endif
               .endw
                  jmp     ThatsAll
            .else
                  mov     al, byte ptr[esi]
                  mov     byte ptr[edx], al
                  inc     edx
            .endif
            inc     esi
            dec     ecx
         .endw
      .endif
         jmp     ThatsAll

GotIt:
      INVOKE     lstrlen, addr ErrorName
      .if byte ptr ErrorName[eax-1] == ' '
         INVOKE     lstrcpyn, addr ErrorName, addr ErrorName, eax
      .endif

      INVOKE     lstrcmpi, addr FileName, addr ErrorName
      .if eax != 0
         INVOKE     lstrcpy, addr szBuff, addr PathName
         INVOKE     lstrcat, addr szBuff, addr ErrorName
         INVOKE     lstrcpy, addr SavNameFull, addr ErrorName
      .endif

      INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
         mov     Chg, eax
      INVOKE     AsciiBase, addr szLineNum, addr LNum, 10
         dec     LNum
      INVOKE     SendMessage, hREdit, EM_LINEINDEX, LNum, 0
         mov     cr.cpMin, eax
         mov     cr.cpMax, eax
      INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
      INVOKE     SendMessage, hREdit, UM_SETHILITELINE, LNum, 5
      INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
        call     CenterSel
      INVOKE     SendMessage, hREdit, EM_SETMODIFY, Chg, 0

ThatsAll:
      INVOKE     CallWindowProc, lpBuildEdit, hwnd, wmsg, wparam, lparam

         ret
BuildEditProc ENDP
