|
Answer» Hi all, I need a batch script to delete certain data from a .c file so it needs to be open up with notepad and edited. i have multiply .c files all different names so i was wonder if someone can help me create a script to delete the following from each text file.
Before Script:
ROM_START( appoooh ) ROM_REGION( 0x14000, REGION_CPU1, 0 ) /* 64k for code + 16k bank */ ROM_LOAD( "epr-5906.bin", 0x00000, 0x2000, 0xfffae7fe ) ROM_LOAD( "epr-5907.bin", 0x02000, 0x2000, 0x57696cd6 ) ROM_LOAD( "epr-5908.bin", 0x04000, 0x2000, 0x4537cddc ) ROM_LOAD( "epr-5909.bin", 0x06000, 0x2000, 0xcf82718d ) ROM_LOAD( "epr-5910.bin", 0x08000, 0x2000, 0x312636da ) ROM_LOAD( "epr-5911.bin", 0x0a000, 0x2000, 0x0bc2acaa ) /* bank0 */ ROM_LOAD( "epr-5913.bin", 0x0c000, 0x2000, 0xf5a0e6a7 ) /* a000-dfff */ ROM_LOAD( "epr-5912.bin", 0x10000, 0x2000, 0x3c3915ab ) /* bank1 */ ROM_LOAD( "epr-5914.bin", 0x12000, 0x2000, 0x58792d4a ) /* a000-dfff */
ROM_REGION( 0x0c000, REGION_GFX1, ROMREGION_DISPOSE ) ROM_LOAD( "epr-5895.bin", 0x00000, 0x4000, 0x4b0d4294 ) /* playfield #1 chars */ ROM_LOAD( "epr-5896.bin", 0x04000, 0x4000, 0x7bc84d75 ) ROM_LOAD( "epr-5897.bin", 0x08000, 0x4000, 0x745f3ffa )
ROM_REGION( 0x0c000, REGION_GFX2, ROMREGION_DISPOSE ) ROM_LOAD( "epr-5898.bin", 0x00000, 0x4000, 0xcf01644d ) /* playfield #2 chars */ ROM_LOAD( "epr-5899.bin", 0x04000, 0x4000, 0x885ad636 ) ROM_LOAD( "epr-5900.bin", 0x08000, 0x4000, 0xa8ed13f3 )
ROM_REGION( 0x0220, REGION_PROMS, 0 ) ROM_LOAD( "pr5921.prm", 0x0000, 0x020, 0xf2437229 ) /* palette */ ROM_LOAD( "pr5922.prm", 0x0020, 0x100, 0x85c542bf ) /* charset #1 lookup table */ ROM_LOAD( "pr5923.prm", 0x0120, 0x100, 0x16acbd53 ) /* charset #2 lookup table */
ROM_REGION( 0xa000, REGION_SOUND1, 0 ) /* adpcm voice data */ ROM_LOAD( "epr-5901.bin", 0x0000, 0x2000, 0x170a10a4 ) ROM_LOAD( "epr-5902.bin", 0x2000, 0x2000, 0xf6981640 ) ROM_LOAD( "epr-5903.bin", 0x4000, 0x2000, 0x0439df50 ) ROM_LOAD( "epr-5904.bin", 0x6000, 0x2000, 0x9988f2ae ) ROM_LOAD( "epr-5905.bin", 0x8000, 0x2000, 0xfb5cd70e ) ROM_END
ROM_START( hooppe ) ROM_REGION( 0x14000, REGION_CPU1, 0 ) /* 64k for code + 16k bank */ ROM_LOAD( "epr-5906.bin", 0x00000, 0x2000, 0xfffae7fe ) ROM_LOAD( "epr-5907.bin", 0x02000, 0x2000, 0x57696cd6 ) ROM_LOAD( "epr-5908.bin", 0x04000, 0x2000, 0x4537cddc ) ROM_LOAD( "epr-5909.bin", 0x06000, 0x2000, 0xcf82718d ) ROM_LOAD( "epr-5910.bin", 0x08000, 0x2000, 0x312636da ) ROM_END
I need to delete all the following except for what below. So it should look like what i have underneath once done. the name in the parenthesis is always different fyi. Thanks!!!
After Script:
ROM_START( appoooh ) ROM_END
ROM_START( hooppe ) ROM_END
Two questions to start with:
1. Is this:
Code: [Select]ROM_START( appoooh ) ROM_END
ROM_START( hooppe ) ROM_ENDall that is going to be left in the file? (i.e. Is that the entire file you are showing, or only PART of it?)
2. Where did the ( hooppe ) come from? I don't see that anywhere in your starting text.
1. no there more data within the file. Basically i need to find ROM_START( appoooh ) and delete all the data between ROM_START( appoooh ) and ROM_END and collapse so there near each other like i wrote above. The thing is the words are always different for example can ROM_START( hooppe ) or something random.
2. (hooppe) was the last group of lines at the bottom on the original post
i attached two files that need it to be done. i have about 100 more . also i made these .txt there originally .c
[year+ old attachment deleted by admin]Then try this:
Code: [Select]echo off setlocal enabledelayedexpansion
for /f "delims=" %%A in ('dir /s /b *.c') do ( set count=1 for /f "delims=^( tokens=1,2" %%B in (%%A) do ( if "%%B"=="ROM_START" ( set out!count!=%%C set /a count+=1 ) ) set /a stopcount=!count!-1 set printcount=1 for /l %%D in (1,1,!stopcount!) do ( CALL set out=%%out!printcount!%% (echo ROM_START(!out! echo ROM_END echo. echo.) >>temp.txt set /a printcount+=1 ) echo del %%A echo ren temp.txt %%~nxA pause ) Check the temp.txt file and ensure that the DEL and REN commands line up like you WANT them too, then remove the pause and the last two echos and let her run. I haven't tried this with subfolders, but it did work on the test file that I used within the same folder. It might be as simple as moving the file to the correct location once it is renamed. That would look like this
Code: [Select]move %%~nxA %%~dpA and this line would be added in under the REN command before the final closing parenthesis. Run the code as it is first and see if that modification is needed.
Let us know if it doesn't work as expected.nothing happens not sure why. its says continue but it doesn't do anything. But at the the top it says
The system cannot find the file Jr\Downloads\mame\aeroboto.c
it DELETING the data between the lines but its also deleting everything in the file INSTEAD of only removing only whats between those two lines. otherwise it would be perfect Another method. Do it is bite size jobs. A short BAT file removes all line that start withe "ROM_LOAD" first try this on a file: find "ROM_LOAD" aeroboto.c OK? Now try this: find /V "ROM_LOAD" aeroboto.c Did you like that? Now: find /V R"OM_LOAD" aeroboto.c >> aerobot.c2 Will that work for you? Thing is it has to be after the parentheses and the word in the parentheses ROM_START( appoooh ) is always different. So the appoooh is always different but in each file it always look just lik what i wrote in my first post.
The first code above would be perfect if it didnt delete eveything else in the file because its doing excatly what i need to be done but i need it not to delete everything else in the file.Just looking at your text file examples it looks like we could delete any line that begins with ROM_LOAD, ROM_REGION or ROM_LOAD16_BYTE.theres also ROM_COPY in some but i was looking throught more the files ands there also other data in alot of the file that between ROM_START( ) and ROM_END that need to be deleted as well so it wouldnt work right. Seems like it would be easier for you to write a C program to do this. We have a dedicated C programmer on staff. If there is something we can't do with our data processing software that is very specific we have him write a C program. And even before that I usually try something with batch but batch is very slow at processing very large files so I will usually resort to having the program written in C. im going to keep trying to figure something out. i dont know anything about C programming and im new to writing scripts in genral. so hopefully there a way to edit what i have to not delete everytihg else in the text file. thanks for everyone thats been helping meI didn't see your edit. Yes the batch was only going to have the ROM_START in it and would delete everything else. C programming would probably be a more effecient way of doing this, but batch would allow for it to happen, it is just going to take more processing time and it's a lot different code. I'll work on something today that hopefully will get you on the right track.THANK YOU I REALLY APPERCIATE ITHey Raven, here is some code I worked out. I just wanted to get the code working for one file right now and it seems to work fine. The reason I am doing it this way was to preserve the blank lines otherwise the FOR LOOP will discard the blank lines.
Just need to wrap another loop around this to iterate all the input files. I gotta get going for the day.
Code: [Select]echo off SETLOCAL ENABLEDELAYEDEXPANSION set _FILE=argus.txt set _WRITE=ON FOR /F "USEBACKQ delims=" %%A IN (`TYPE "%_FILE%" ^| FIND.exe /V /N ""`) DO ( SET "LN=%%A" SET "LN=!LN:*]=!" IF "!LN:~0,7!"=="ROM_END" set _WRITE=ON IF "!_WRITE!"=="ON" ECHO(!LN!>>"%_FILE%.tmp" IF "!LN:~0,9!"=="ROM_START" set _WRITE=OFF )
|