Thread: script to delete certain data from a .c file

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    1

    script to delete certain data from a .c file

    Hi all,
    I need a batch script to delete certain data from a dot 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.there is more data in each file that i dont want removed.
    I was told to try c programming since the script i have is now doing excatly what i want. FYI i dont knwo anything about c programming.




    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!!!

    i have a script thatworks in a way but it delete everything else in the file which i dont want. pasted below.


    After Script:

    ROM_START( appoooh )
    ROM_END


    ROM_START( hooppe )
    ROM_END



    I was using this script but it deletes everything in the each file. which is not what i want. i attached sample of the bat scipt and files to.

    Code:
    @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
      )
      del %%A
      ren temp.txt %%~nxA
    )
    Attached Files Attached Files
    Last edited by daillest319; 01-31-2012 at 10:59 AM.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    I don't understand what you want. Try explaining your problem again.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    You could try:

    Code:
    grep -vE "(ROM_LOAD|ROM_REGION)" your_sourcefile.c
    Obviously try for yourself and determine if it does what you want, I take no responsibility what so ever.



    Edit: Doh, Windows, never mind. I missed that part.
    Last edited by Subsonics; 01-31-2012 at 11:35 AM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,773
    I do NOT think this is the right sub-forum for Windows batch files.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    Mods, please move this thread.

    @daillist319: Please post in the appropriate forum next time. This probably belongs in the Tech Board. My personal suggestion would be to use Linux, but that's probably not an option. The following is a hack, but it may suffice, or at least get you going in the right direction. If that doesn't work, your next best bet would probably to get ahold of something like GnuWin32 (GnuWin32), which has much more powerful tools for this sort of task.

    Code:
    findstr /r "ROM_[SE]" foo.txt

  6. #6
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Quote Originally Posted by Subsonics View Post
    You could try:

    Code:
    grep -vE "(ROM_LOAD|ROM_REGION)" your_sourcefile.c
    Obviously try for yourself and determine if it does what you want, I take no responsibility what so ever.



    Edit: Doh, Windows, never mind. I missed that part.
    The Windows equivalent of that command is

    Code:
    find /V "(ROM_LOAD|ROM_REGION)" your_sourcefile.c
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  7. #7
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    It would be simple to do this in Perl, which is available on windows. I use it all the time for this kind of thing.
    I still don't understand what exactly the OP wants though, and he's not bothering to explicate.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    Quote Originally Posted by Babkockdood View Post
    The Windows equivalent of that command is

    Code:
    find /V "(ROM_LOAD|ROM_REGION)" your_sourcefile.c
    Actually, that doesn't work. You need to use findstr (see my post) with the /r option if you want regular expression support, which you need to include/exclude multiple patterns.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by daillest319 View Post
    Hi all,
    I need a batch script to delete certain data from a dot c file so it needs to be open up with notepad and edited.
    Why don't you just get a better text editor? Like Notepad++.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to delete data
    By Kinshara in forum C Programming
    Replies: 11
    Last Post: 11-03-2009, 08:17 AM
  2. add-delete data
    By mufanz in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2006, 10:49 AM
  3. compare and delete data from file
    By moby in forum C Programming
    Replies: 9
    Last Post: 02-07-2005, 03:08 AM
  4. How to delete data...
    By alan85 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2004, 04:47 PM
  5. file processing, delete certain data
    By alternative in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2003, 09:21 AM