| :: CONV2BAT.BAT - this batch converts HLL source or an |
| :: existing file (<40K) into equivalent batch code. |
| :: Required components... (assumed to be on the path) |
| :: for ASIC (asi): ASICC |
| :: for BASM (bas): BASM ASM FREELINK |
| :: for Moonrock (moo): MRC (plus asm/link in mrc.cfg) |
| :: for Tokiwa (tok): TBC |
| :: Compresses com with PKLITE, uses Dos6+ FC and FIND to |
| :: determine if compressed for comments. Disable below. |
| :: The temp variable must point to a writable directory. |
| :: This batch is designed to operate by drag-drop, from |
| :: Windows' right-click menus, or from a dos prompt. |
| :: Usage: CONV2BAT [path\]filename.ext |
| :: If extension is asi bas moo or tok then produces |
| :: filename.bat containing batch-encoded binary with |
| :: attached source, in addition to compiler output. |
| :: If ext not supported then encodes binary to batch. |
| :: Tested in Win95, should be dos and NT-tolerent except |
| :: for compression test (see comments) but maybe more. |
| :: This is free software and comes with no guarantee, |
| :: test thoroughly before distributing the output code. |
| :: Last major mod 12/08/01, last mod 1/03/02 |
| :: (C) Copyright 2002 Terry Newton |
| :: EncBin encoder, DecBin decoder and Basm helpers |
| :: are public domain, use as you wish. |
| @echo off |
| if .%1==.Shell goto %1 |
| if not .%1==. if exist %1 goto fileexists |
| echo Compiles HLL source and converts to batch |
| echo Usage: CONV2BAT [path\]filename.ext |
| echo Compiles .asi .bas .moo and .tok files |
| echo encodes other types directly to batch |
| goto end |
| :fileexists |
| :: shell with lots of environment space |
| %comspec% /e:30000 /c %0 Shell %1 |
| goto end |
| :Shell |
| ::**** options, edit as needed... |
| :: usepklite=yes to compress with pklite |
| set usepklite=yes |
| :: usetempdir=yes to use temp dir in output code |
| set usetempdir=no |
| :: decname=filename used for decoder |
| set decname=_d.com |
| :: tempname=filename used for temp file |
| set tempname=_t.tmp |
| :: extension to output batch code to |
| set outputext=bat |
| :: callconv2cfg=yes to put variables in conv2cfg.bat |
| set callconv2cfg=no |
| :: temp filenames... |
| set dec=%temp%.\_decbin.com |
| set enc=%temp%.\_encbin.com |
| set file2bat=%temp%.\_2bat.com |
| set cmntsrc=%temp%.\_cmntsrc.com |
| set sepname=%temp%.\_sepname.com |
| set replace=%temp%.\_replace.com |
| set tf=%temp%.\_tf.tmp |
| set tf1=%temp%.\_tf1.tmp |
| set tf2=%temp%.\_tf2.tmp |
| :: override variables if configured... |
| if .%callconv2cfg%==.yes call conv2cfg.bat |
| :: double check... |
| set xyz=0123456789012345678901234567890123456789 |
| if not .%xyz%==.0123456789012345678901234567890123456789 goto end |
| set xyz= |
| echo. |
| echo **** CONV2BAT **** 12/8/01 WTN |
| echo Checking file support... |
| ::----------------------- |
| :: CM3-encoded DecBin decoder... |
| ECHO:`h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>%dec% |
| ECHO:fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZ$:NvN$>>%dec% |
| ECHO:9AyroNB-)dOKwK0rRkfTbi)ws_~[[q9wE'sqlu1sY*Bsfe=@ziNS1a)88e>>%dec% |
| ECHO:f9RTL)9Z{3INBD?o6@MDLO{Zz4Q23E-'09NX9@Vz(42A7c8zMS:u$w6k5Q>>%dec% |
| ECHO:N,h:le)~gF?tutTyxoe5UiIdtn';0rJ1q:{7;lAl']y:yTjZBbOo?QRIdN>>%dec% |
| ECHO:$Bp@P/nAp_r0*4f'XcF4q3o?$_t5lx$Q-OxSfUNQ__Gd~$Q-Oxgkx=LGHU>>%dec% |
| ECHO:S)$C6P8 |
| ::---- EncBin-encoded binary ---- |
| :: sepname.com made with BASM ASM FREELINK |
| ECHO:AEPPr64U2y00tD61O0AAj7CDXn28A5S5D7JeRkl5Ll00xG47uvgmv5gl[5>%tf% |
| ECHO:gGC0v]U[2uY7213301EBu1Je13dnJDrX5OIZO5QZO5ibr1Vbj3AxS5Ayv6>>%tf% |
| ECHO:Zb02ibf3Axv6Rbf2RbC2Ayv6Jbf3abb3Axv62yK6ebr12rK6ZbC2ib42Ay>>%tf% |
| ECHO:v6ab[3Axv6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b]p857>>%tf% |
| ECHO:ZYv7WVK186K5y3hXW6s3uyhXW6ryr0gGv6hXW6rnuyhXW6r1C0lyQX3bva>>%tf% |
| ECHO:xxQX2yPG3bvUxxPG3bvWxyPG2BF83rpA603u9yCBF0M819DFZsn0Vhy3hX>>%tf% |
| ECHO:W6uruxhXC6F9l0CWTo16D1ZsLHVn6sK02yK6Fvv]E[m786K5013yG6K5t3>>%tf% |
| ECHO:DKb55ov4vELK2tLO2nn9jXtB5Ib5ZJexlBGUK5EAyxFEFRAn3DCGkLlBtB>>%tf% |
| ECHO:Hp2yPG2BPE3vRmA[0ml8n5N2041LlBt3Bf0ma0X6ixXpW4t8ix9606I9s6>>%tf% |
| ECHO:vw001wW6f1[0X6yxgGO6j5f0Xpv4gGC61puxIs1H0esEyvRmA[0ml8f5Z\>>%tf% |
| ECHO:9Tj4v0iyC5F0M933xxv5mbFxF3LGmbuyyvgGW6K3ujHPRmA[N600N3MBif>>%tf% |
| ECHO:XpW4r\ixZ86u00QBK42nJDnXN202014000070DGA8D0A07000000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:00000000whOW5jPl1g0000000000j0K00h000000001mH\SW1]TXXnOwC0>>%tf% |
| ECHO:T\1n9]5YPmo\C0LmPnOWP\HrSwn0}>>%tf% |
| :: BASM source... |
| :: rem separate specified name into fpath,fbase,fext |
| :: rem outputs sets to stdout |
| :: $com |
| :: a$=command$:a$=trim$(a$):a$=lcase$(a$) |
| :: if a$="" then |
| :: print "no parm":end |
| :: endif |
| :: rem loop through string, mark last \ and . |
| :: slash=0:dot=0:ilen=len(a$) |
| :: for i=1 to ilen |
| :: c$=mid$(a$,i,1):if c$="\" then slash=i |
| :: if c$="." then dot=i |
| :: next i |
| :: rem not an extension if \ after . |
| :: if slash>dot then dot=0 |
| :: fpath$="":fbase$=a$:fext$="" |
| :: if dot>1 then |
| :: d=dot-1:fbase$=left$(a$,d) |
| :: d=ilen-dot:fext$=right$(a$,d) |
| :: endif |
| :: if slash>1 then |
| :: rem includes trailing \ |
| :: d=slash:fpath$=left$(a$,d) |
| :: d=len(fbase$):d=d-slash |
| :: fbase$=right$(fbase$,d) |
| :: endif |
| :: output "set fpath=";fpath$ |
| :: output "set fbase=";fbase$ |
| :: output "set fext=";fext$ |
| ::------------------------------- |
| :: decode and use _sepname.com to parse input (in %2) |
| %dec% < %tf% > %sepname% |
| if errorlevel 1 goto binerror |
| %sepname% %2 > %temp%.\_sep_tmp.bat |
| call %temp%.\_sep_tmp.bat |
| del %temp%.\_sep_tmp.bat |
| if .%fpath%==. goto incurrent |
| :: change to source directory |
| %fpath% |
| cd %fpath% |
| :incurrent |
| if exist %fbase%.%fext% goto curdirok |
| echo Could not change to directory |
| goto cleanup |
| :curdirok |
| :: ******* |
| :: ******* compiler support, edit as needed |
| :: ******* |
| if .%fext%==.asi goto asifile |
| if .%fext%==.bas goto basfile |
| if .%fext%==.moo goto moofile |
| if .%fext%==.tok goto tokfile |
| echo Unknown filetype, encoding as-is |
| set compname= |
| set madewith=???? |
| set binfile=%fbase%.%fext% |
| goto conv2batch |
| :asifile |
| set compname=ASIC |
| set madewith=ASICC |
| if exist %fbase%.com del %fbase%.com |
| call asicc %fbase%.asi C |
| goto checkcom |
| :basfile |
| set compname=BASM |
| set madewith=BASM ASM FREELINK |
| if exist %fbase%.com del %fbase%.com |
| call basm %fbase%.bas |
| if exist %fbase%.asm call asm %fbase%.asm ; |
| if exist %fbase%.obj call freelink /c %fbase%.obj |
| goto checkcom |
| :moofile |
| set compname=Moonrock |
| set madewith=MRC ASM MRLINK |
| if exist %fbase%.com del %fbase%.com |
| call mrc %fbase%.moo |
| goto checkcom |
| :tokfile |
| set compname=Tokiwa |
| set madewith=TBC |
| if exist %fbase%.com del %fbase%.com |
| call tbc /c %fbase%.tok |
| goto checkcom |
| :: ******* end compiler commands |
| :checkcom |
| set binfile=%fbase%.com |
| if exist %binfile% goto comexists |
| echo. |
| echo ======================================= |
| echo Compile failed, debug and try again |
| echo ======================================= |
| echo. |
| goto cleanup |
| :comexists |
| if exist %fbase%.obj del %fbase%.obj |
| :: try to pklite it (if option enabled) |
| if not .%usepklite%==.yes goto conv2batch |
| copy %binfile% %tf1% >nul |
| call pklite %binfile% |
| fc /b %binfile% %tf1% > %tf2% |
| find "00" < %tf2% > nul |
| ::reset var for docs if not changed by pklite... |
| ::note--not NT compatible here, PkLite status won't |
| ::be properly indicated in the output batch comments |
| if errorlevel 1 set usepklite=no |
| del %tf1% |
| del %tf2% |
| :conv2batch |
| echo. |
| echo Converting to batch code... |
| ::--------------------- |
| :: the EncBin encoder, encodes stdin to stdout, encoded by itself... |
| ECHO:AALIxnCmeRf0\Uf0pWjXYBlxr0MyG02u022nc1Z5Z0r4G2ldMAj[8F34dd>%tf% |
| ECHO:Z1Z0r4G2ld6Aj[8F34Ed3EmbG02lJpNl0jjjCt9v0407ZvjtS3I0j7rvLv>>%tf% |
| ECHO:G203l0wUDv20F42eD3ZujTS6fmprbD2e4uwp39gwYdfDfAdng0f1f0ZF2t>>%tf% |
| ECHO:04bemDCXj0C0LHtA2701ZsG0SFdfW]6630Jf36S6W1f0rJ2fMfQYW1YAoO>>%tf% |
| ECHO:EAt0y[36S6W1[8LRi3}>>%tf% |
| ::--------------------- |
| :: decode encoder... |
| %dec% < %tf% > %enc% |
| if errorlevel 1 goto binerror |
| ::---- EncBin-encoded binary ---- |
| :: 2bat.com made with BASM ASM FREELINK |
| ECHO:AFDJr64U2y00tD61O0AAj7CDXn28p5j5D7JeRkl5ND00xG47uviEv5iD[5>%tf% |
| ECHO:gGC0v]U[2ues213301EBu1Je13dnJDrX5OhZf5pZf5JbC2qb04pxj56yb8>>%tf% |
| ECHO:ybC27b046xb8ubv2qbO26yb8ebv3ybr36xb8qbf2ibK26yb8Zbr36xb8ty>>%tf% |
| ECHO:46RbK2Do3c7j0mF0e5v5hXr8fYW6sQC206N52ZO[23Gx86v0S37c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>%tf% |
| ECHO:2yUk3bwOxxUk3bwQxyUk2BF83rpA603u9yCBF0M819DFZsn0Vhy3fcW8rl>>%tf% |
| ECHO:uyfcC8F9l0CWTo16D1ZsLrVnYsS06yf7Fvv]E[kWYBps3y2tOs2nnyjXol>>%tf% |
| ECHO:KBJ0TPDGLI8ULV2BpxMi2u022BihJvMBxfdBmlMhSQ6BpBFBx]gn03isBu>>%tf% |
| ECHO:Cuoqiar8hGBuXFye02asxBq6070VgQLOXl63B70eVtKeV7yOhPZ867pr81>>%tf% |
| ECHO:JDWXNe0Fabuuy7C6j5012BRQj740R3gLZfQBS46yf7tBG6Fvv]E[F0M81T>>%tf% |
| ECHO:J200gLZfl3r20ml9s6xBHp3bssveP610Q9Jx0w00Pw2r0129s6xyUk3605>>%tf% |
| ECHO:2BHp2yUk03spwEYsS0reJxFvv]E[F0M82Bq\N2042ySs0ma0W5u3fsW7rg>>%tf% |
| ECHO:FxlnnxjXabVxF3KmF0e3G5fw7DBbsewRU9331IKma9WEN32nnvjXZbNx\R>>%tf% |
| ECHO:W7YBpnnxjXmbJx1Qf1pnFDWXs2Fxj14000070DGA8D0A07000000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:00000000000000000W000000000000000x15X3HF0t0x0x0g}>>%tf% |
| :: BASM source... |
| :: '2bat infile outfile tmpfile |
| :: 'reads infile, surrounds each line with |
| :: '"ECHO:" and ">>tmpfile" (one > 1st line) |
| :: 'and outputs results to outfile |
| :: $com |
| :: $string 120 |
| :: a$=command$:a$=ltrim$(a$):a$=rtrim$(a$) |
| :: if a$<>"" then |
| :: b=instr(a$," ") |
| :: if b>0 then |
| :: infile$=left$(a$,b) |
| :: infile$=rtrim$(infile$) |
| :: c=len(a$):c=c-b |
| :: tmpfile$=right$(a$,c) |
| :: b=instr(tmpfile$," ") |
| :: if b>0 then |
| :: outfile$=left$(tmpfile$,b) |
| :: outfile$=rtrim$(outfile$) |
| :: c=len(tmpfile$):c=c-b |
| :: tmpfile$=right$(tmpfile$,c) |
| :: open infile$ for input as 1 |
| :: if err=0 then |
| :: open outfile$ for output as 2 |
| :: if err=0 then |
| :: done=0:b$=">" |
| :: while done=0 |
| :: line input #1,a$:done=eof |
| :: if done=0 then |
| :: print #2,"ECHO:",a$,b$,tmpfile$ |
| :: b$=">>" |
| :: end if |
| :: wend |
| :: close 2 |
| :: close 1 |
| :: end if |
| :: end if |
| :: end if |
| :: end if |
| :: end if |
| ::------------------------------- |
| :: decode 2bat utility... |
| %dec% < %tf% > %file2bat% |
| if errorlevel 1 goto binerror |
| ::---- EncBin-encoded binary ---- |
| :: cmntsrc.com made with BASM ASM FREELINK |
| ECHO:ADLNr64U2y00tD61O0AAj7CDXn28h5G4D7JeRkl5HB00xG47uvgCv4gB[4>%tf% |
| ECHO:gGC0v]U[2uS1213301EBu1Je13dnJDrX5O]ZC4hZC4ybb0Zb[2hxG42yf6>>%tf% |
| ECHO:mbj0mbW22xf6ebO1ebv02yf6NbW22xf6ly[4Nbv0Dn3e0J]xIU3b413b2H>>%tf% |
| ECHO:3b8j2jG0gC7DAtQj2uI]3b9e2XGq2ZIb23Wxb4v0S3Fe6Gdxb4Rbn0RbO0>>%tf% |
| ECHO:Nb022j2noCjXR62j062GQXb4VbS1pxf42yf6ebK06XG4YZb4t3Eb041nf3>>%tf% |
| ECHO:rLYGQsW4riW2QjW6rcW2OjW4rZf2u7tB6]W4r1G2gC0lmDGXf3vlyDCGF0>>%tf% |
| ECHO:AAmxF0bab4Z63xlZGc33QB4ar4yA]X842AyxJEf23D73mvdd0AkoFtkHTM>>%tf% |
| ECHO:MBBxF0xsyyBvxh7qo96BkV\UN3THLMTMLU7buyYBoUibqyYBk1wUK3muym>>%tf% |
| ECHO:G]cPu3fEv6hwW5uRFykGPNNvtfcob430XowUXVN3Dm2ZGq3rZ3td3yMBF8>>%tf% |
| ECHO:Zsr0SutB4e44bcf4WxGa0UW6HFx3v09y0meygGS0yYW3yHZaf0tjZ0xn3D>>%tf% |
| ECHO:jGC7Ln2rW0hEm0x[W]WT97urv75OO10aC4lyPV3bwJxxPV3b0y2xOE2yPV>>%tf% |
| ECHO:3bw4xxPV3b0133xyK6VbFyxxK6ty06ubBytx063bFyty06YBj3erWTh0vW>>%tf% |
| ECHO:gy0mZ0W5w9I33s1wFhlyPV3bv8xxPV0m39WvKWS756I37sLoangHv0fEj6>>%tf% |
| ECHO:ymG]e3gWZOxsv0ptf4xnFD8XTT0Bkn1PLJsI5IgVZGpx84Au00tBsBivZo>>%tf% |
| ECHO:hfZAulcofQZHhBmmI]SB[3veiuFJTque08[eyuJrBe2GisZVV600bVLR9O>>%tf% |
| ECHO:SOU3j2bewNSemqaO]BV8ZH6r127D9Oye2G7bqxR7114400dBq6071XV3j6>>%tf% |
| ECHO:Ga01v0v6Gc23[x84KQS4uy0cb4fgG4f97DABSU84EAqxiAWUGc2AumyEfm>>%tf% |
| ECHO:pnn2jGy3hwC5F0M933pxf5ybBxJ3fx7DBbsuy3DJF06ZG4pnFDWXsgixM9>>%tf% |
| ECHO:C7kLlBtBHp3brKxBi8f1f0XMG4g07D9TB2000101S000bD0[bD00070000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:000000000000000000001h1i9j9XTg0000001]kcP\rWPi1n9]LiTh1[0t>>%tf% |
| ECHO:0t80jt}>>%tf% |
| :: BASM source... |
| :: rem open file specified on command line and write |
| :: rem to stdout with ":: " prefixed to each line |
| :: $com |
| :: a$=command$:a$=trim$(a$) |
| :: if a$="" then |
| :: print "no parm":end |
| :: endif |
| :: open a$ for input as 1:e=err |
| :: if e>0 then |
| :: print "file not found":end |
| :: endif |
| :: fileloop: |
| :: line input #1,a$:e=eof |
| :: if e=0 then |
| :: output ":: ";a$:goto fileloop: |
| :: endif |
| :: close 1 |
| ::------------------------------- |
| :: decode cmntsrc utility... |
| %dec% < %tf% > %cmntsrc% |
| if errorlevel 1 goto binerror |
| ::---- EncBin-encoded binary ---- |
| :: replace.com made with BASM ASM FREELINK |
| ECHO:AGINr64U2y00tD61O0AAj7CDXn28Q587D7JeRkl5S]00xG47uvfav7f][7>%tf% |
| ECHO:gGC0v]U[2uMDA13301EBu1Je13dnJDrX5OYZ47dZ47Fbv2ibO5pyW9dr00>>%tf% |
| ECHO:M90maRXTW1s3v3hDWJs[W5sIv5hDW9fD[0W5fmp95T3bCd2yMD7bLB3bKs>>%tf% |
| ECHO:2y]D2r0Y29C5FRp9K17b43pyWNBbC53b85Qx87pyWPNbj2Jb45pxWPabK4>>%tf% |
| ECHO:Fbv2pyWPJb45Bb05pxWPZb447br2pyWPBb053bv45d1b]D7bI93bBD2yhD>>%tf% |
| ECHO:7bJh2xhD6yUD7bB81of3r4]Gr7C2F0tZ47pxWPabS2O30UC7cqv7vETq3b>>%tf% |
| ECHO:Io3ySpS7obWPJbO43b[2pyWP7bf40mlZSU2y]D6xUD7bC]03r647]ZS7t3>>%tf% |
| ECHO:Ds871vf3r1xGvETs3bHv3y[pS7obWPFb44VbK2pyWTZbS4Q31s870mF0bU>>%tf% |
| ECHO:r7hDWPrFC206SU2ZTq0mF006Tq0e[6S7hZS7BbG4RyDuW7QDWPukW3rTv2>>%tf% |
| ECHO:hDWVrxW4rfr4hDWVskW3rBv2hDWVrfW4rQb4O1obWVFbf3Vbv1pyWRZb44>>%tf% |
| ECHO:pxWRpyWNBbv1Do3e04ac4k3bFo1dW1QDWVt]W3uIv1hDWRumr3hDvRhDWN>>%tf% |
| ECHO:uDK1S3Je2Gmc010mlZSU2xxD7b5x03r647UZS7t3Dq871vf3r4]GugC0Wx>>%tf% |
| ECHO:Tq02Dy3e0raySES7Fbb3RyDqW7QDWVsIW3sxv1hDWVtVv3vETq3bE93ySp>>%tf% |
| ECHO:S7obWV3b83JbO1pyWVNbW3qe2G3bS3pxS7pyWVNb41JbO3xxS7pyWXab01>>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5yx>>%tf% |
| ECHO:hDf9Z8W3xA0TZuvWSB0ml8[5HF]3v0swu3pyWBqbNxpxWB[ml00v9oO8H1>>%tf% |
| ECHO:]1v0K2Vm2s02pyW9Fvv]E[m7O607013yW607t3C8b75ov4vES82tSC2nn9>>%tf% |
| ECHO:jXtB46b7ZJexlBWU07EAyxFEFRAn3DCGkLlBtBHp2y]D2BPE3vRmA[0ml8>>%tf% |
| ECHO:n5N2041LlBt3Bf0ma0X6ixXpW4ufiw9606I9s6vw001wW6f1[0X6yxhDO9>>%tf% |
| ECHO:j5f0Xpv4hDC91puxIs800esEyvRmA[0ml8f5Z\9Tj4v0hDC7F0M933pyW7>>%tf% |
| ECHO:ubiwu3hDW7tPFwkLlBtBHp3bpNxBi8f1f0XMG4g07D9TB200gLZfR62D09>>%tf% |
| ECHO:2GQn2lqyjX\n2Y]D36r6W900]Bq\N30101S000bD0[bD00070000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf% |
| ECHO:00000000000000000000000000009\Tl9iS08j}>>%tf% |
| :: BASM source... |
| :: 'typical usage: type file | _replace "abc" "def" > newfile |
| :: 'replace all occurences of string "abc" with string "def" |
| :: 'read from standard input, write to standard output |
| :: $com |
| :: $string 512 'max line len |
| :: chr10$=chr$(10) |
| :: chr13$=chr$(13) |
| :: quote$=chr$(34) |
| :: 'parse command line... |
| :: c$=command$ |
| :: c$=ltrim$(c$) 'get rid of surrounding spaces |
| :: c$=rtrim$(c$) |
| :: d$=left$(c$,1) |
| :: if d$<>quote$ then goto clerror |
| :: clen=len(c$) |
| :: clen=clen-1 |
| :: c$=right$(c$,clen) 'remove 1st quote |
| :: qpos=instr(c$,quote$) 'get position of 2nd quote |
| :: if qpos<2 goto clerror 'must be at least 1 char |
| :: qpos=qpos-1 |
| :: str1$=left$(c$,qpos) 'slice off match string |
| :: qpos=qpos+2 |
| :: clen=len(c$) |
| :: rlen=clen-qpos |
| :: str2$=right$(c$,rlen) 'raw second half |
| :: str2$=ltrim$(str2$) 'no extra spaces |
| :: d$=left$(str2$,1) 'check for quotes |
| :: if d$<>quote$ then goto clerror |
| :: d$=right$(str2$,1) |
| :: if d$<>quote$ then goto clerror |
| :: clen=len(str2$) 'make sure valid string |
| :: if clen<2 then goto clerror 'too short |
| :: if clen>2 then 'at least 1 char |
| :: clen=clen-1 |
| :: str2$=right$(str2$,clen) 'remove quotes |
| :: clen=clen-1 |
| :: str2$=left$(str2$,clen) |
| :: else |
| :: str2$="" 'otherwise empty replace |
| :: end if |
| :: oneline$="" 'initialise main processing loop |
| :: linelen=0 'count chars to avoid overrun |
| :: mainloop: 'loop until no more... |
| :: a$=stdin$ 'get one character |
| :: if a$="" then goto nomore 'done with input |
| :: if a$=chr13$ then goto mainloop 'skip cr |
| :: if a$=chr10$ then 'if lf process line |
| :: gosub process 'replace and output |
| :: oneline$="" 'reset string |
| :: linelen=0 |
| :: goto mainloop 'and loop for more |
| :: end if 'if not lf |
| :: if linelen<512 then 'if not overflow |
| :: oneline$=oneline$+a$ 'add to line |
| :: linelen=linelen+1 'bump length count |
| :: end if |
| :: goto mainloop |
| :: nomore: |
| :: if linelen>0 then 'if extra chars w/ no crlf |
| :: gosub process 'process as one line |
| :: endif |
| :: end 'exit to dos |
| :: clerror: 'command line error |
| :: print "error" |
| :: end |
| :: process: 'subroutine... |
| :: replace str1$ with str2$ in oneline$ 'nice |
| :: output oneline$ 'write to stdout+crlf |
| :: return |
| ::------------------------------- |
| :: decode replace helper... |
| %dec% < %tf% > %replace% |
| if errorlevel 1 goto binerror |
| :: everything is in place to convert com into batch code... |
| :: %dec% - the decoder program |
| :: %enc% - encodes binary to text, stdin to stdout |
| :: %file2bat% infile outfile tmpfile - turns into echo code |
| :: %cmntsrc% file - outputs stdout with commented file |
| :: %replace% "search" "replace" - stdin to stdout |
| :: %compname% = the compiler name |
| :: %madewith% = utilities used to compile |
| :: %usetempdir% = yes if tempdir to be used |
| :: %decname% = decoder filename to use |
| :: %tempname% = temp filename to use |
| :: %fbase%.%outputext% = output filename |
| :: determine temp names... |
| set t= |
| if .%usetempdir%==.yes set t=%%temp%%.\ |
| :: create output file... |
| set outfile=%fbase%.%outputext% |
| echo @echo off>%outfile% |
| echo>>%outfile% ::---- Generated by CONV2BAT ---- |
| :: attach decoder... |
| echo>>%outfile% :: CM3-encoded DecBin decoder... |
| %file2bat% %dec% %tf1% %t%%decname% |
| type>>%outfile% %tf1% |
| :: attach encoded com file... |
| echo>>%outfile% ::---- EncBin-encoded binary ---- |
| echo>>%outfile% :: %binfile% made with %madewith% |
| %enc% < %binfile% > %tf% |
| %file2bat% %tf% %tf1% %t%%tempname% |
| type>>%outfile% %tf1% |
| :: attach source code... |
| if not .%compname%==. echo>>%outfile% :: %compname% source... |
| if not .%compname%==. %cmntsrc% %fbase%.%fext% >>%outfile% |
| echo>>%outfile% ::------------------------------- |
| :: attach decode/run/delete lines... |
| echo>>%outfile% :: decode/run/delete, modify as needed... |
| echo>%tf1% %t%%decname% {{.lt{{ %t%%tempname% }}.gt}} %t%%binfile% |
| %replace% "{{.lt{{" "<" < %tf1% > %tf2% |
| %replace% "}}.gt}}" ">" < %tf2% >>%outfile% |
| if not .%compname%==. echo>>%outfile% %t%%binfile% %%1 %%2 %%3 |
| if not .%compname%==. echo>>%outfile% del %t%%binfile% |
| if .%compname%==. echo>>%outfile% :: use %t%%binfile% as needed |
| echo>>%outfile% del %t%%tempname% |
| echo>>%outfile% del %t%%decname% |
| echo. |
| echo =========================================================== |
| echo Done! %binfile% is the raw binary |
| if exist %fbase%.asm echo intermediate assembly is in %fbase%.asm |
| echo %outfile% batch code recreates %binfile% when run |
| echo =========================================================== |
| echo. |
| goto cleanup |
| :binerror |
| echo Error in encoded binary |
| :cleanup |
| if exist %tf% del %tf% |
| if exist %tf1% del %tf1% |
| if exist %tf2% del %tf2% |
| if exist %enc% del %enc% |
| if exist %dec% del %dec% |
| if exist %replace% del %replace% |
| if exist %sepname% del %sepname% |
| if exist %cmntsrc% del %cmntsrc% |
| if exist %file2bat% del %file2bat% |
| :endCOPY |