Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

File Convertor: resource.H to resource.EQU

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Convertor: resource.H to resource.EQU

    this isn't an example of any particular programming technique, and it's not especially "brilliant", but i find it to be very useful so i thought i'd pass it along.

    like many people, i use a batch file to convert .rc files to .res files, and then convert the .res files to .pbr files. this thread: http://www.powerbasic.com/support/pb...ad.php?t=22910 contains several techniques that can be used to help automate the conversion.

    i use this program in my rc-to-pbr batch file. it reads the .h file that is associated with the .rc file, and creates a file with the extension .equ that contains #define values that have been converted to powerbasic-compatible equates. then all i have to do is this in my program...

    Code:
    #resource     "c:\(whatever)\myapp.pbr"
    #include      "c:\(whatever)\myapp.equ"
    ...to include all of the equates that are needed for the resource file. change the .rc, run the batch, and the pbr file and the equate list both get updated automatically.

    by the way, i tend to use file base-names that are consistent within a project, like myapp.bas, myapp.rc, myapp.inc, etc. so i use the .equ extension to make sure that it never overwrites any other files. if you already use .equ files for something, you should probably pick another extension.

    i use microsoft visual studio to create my resource files, so this program may not work perfectly with .rc files created in other ways. please let me know about any problems you find by starting a thread in another forum (since this forum is not supposed to contain discussions) and i'll try to update the program as bugs are found.

    -- eric pearson

    Code:
    '============================================================= make_equ.bas
    '
    '(c) 2001 perfect sync, inc.  free for personal use.
    '
    'this program takes the name of a .h file from the command line and creates
    'an .equ file (with the same base name) that contains pb-compatible equates.
    '
    'it was written for pb/cc but could be easily converted to pb/dll by 
    'replacing the print statements with message boxes.
    '
    #compile exe 
    #dim all
    #register none
     
    function pbmain as long
     
          dim sfilename     as local string
          dim soneline      as local string
          dim slastline     as local string
      
          dim llastid       as local long
          dim lresult       as local long
     
          sfilename = command$
     
          if len(sfilename) = 0 then
                print "syntax: make_equ <filename.h>"
                exit function
          elseif ucase$(right$(sfilename,2)) <> ".h" then
                print "make_equ: "+sfilename+" is not a .h file"
                exit function
          elseif len(dir$(sfilename)) = 0 then
                print "make_equ: file "+sfilename+" not found."
                exit function
          end if
           
          open sfilename for input as #1
             
          sfilename = left$(sfilename,len(sfilename)-2) + ".equ"
          open sfilename for output as #2
     
          print#2,"'===============================================================";
          print#2,sfilename
          print#2,"
          print#2,"'created by make_equ.exe at "+time$+" on "+date$
     
          while not eof(1)
                'get one line from the file
                line input #1,soneline
                'typical lines: "#define ids_appname                     1"
                '               "#define _aps_next_resource_value        102"
                'we want to ignore equates that start with underscore 
                'because they are not actually used for resource ids.
                'they are used by the resource editor for tracking 
                '"next" values.
                if left$(soneline,7) = "#define" and mid$(soneline,9,1) <> "_" then
                      'it's a resource id line
                      if slastline <> mid$(soneline,9,4) then
                            'id type change, like from idi_ to idc_, so print blank line
                            print#2,"
                            slastline = mid$(soneline,9,4)
                      end if
                      'trim trailing whitespace        
                      soneline = rtrim$(mid$(soneline,9),any chr$(9,32))
                      'find the last space in the line (i.e. the space before the number)
                      lresult = instr(-1,soneline," ")
                      'insert a marker at that point
                      mid$(soneline, lresult) = $nul
                      'replace the marker...
                      replace $nul with " = " in soneline
                      print#2, $tab;"%";soneline+"&"
                      'check for duplicate values
                      lresult = val(remain$(soneline,"="))
                      if lresult = llastid then
                            beep
                            print "duplicate id ";lresult
                            waitkey$
                      end if
                      llastid = lresult
                             
                end if
     
          wend
     
          print#2,"
          print#2,"'===============================================================";
          print#2,"
          close
          print space$(len(sfilename)+1);sfilename;" created successfully."
          print
      
    end function

    ------------------
    perfect sync: perfect sync development tools
    email: mailto:[email protected][email protected]</a>



    [this message has been edited by eric pearson (edited february 03, 2001).]
    "Not my circus, not my monkeys."

  • #2
    here's one using regular expressions:

    http://www.powerbasic.com/support/pb...ad.php?t=22583

    mcm
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      The functionality is similar, but I posted mine because it is commandline-driven, which is apropos to the other thread I referenced.

      -- Eric

      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>
      "Not my circus, not my monkeys."

      Comment

      Working...
      X