No announcement yet.

c header to PB converter in-progress

  • Filter
  • Time
  • Show
Clear All
new posts

  • c header to PB converter in-progress

    Howdy y'all!

    Many of us would like an easy way to convert 'c' headers
    to PowerBasic. I, for one, would love to use ISource
    from Smaller Animals that I just registered, but don't
    want to have to deal with conversion issues on each update,
    I decided to jump in both feet first and write a converter.

    At this point, the program is not complete, yet does quite
    a bit. My purpose of posting here is four-fold:[list=1][*]To document what I'm attempting to establish interest.
    [*]To document that I do not intend on profiting personally
    on this and at some point, will release this to the PB
    community in exchange for all of the help y'all provided over
    the years. (However, my Oreo and Dr Pepper reserves are
    getting kinda low...)

    [*]To enlist the help of those who are knowledgeable in this
    area. For one, I'd really like some header files that people
    have converted manually to help refine the conversion. Also,
    I'd hope that someone would be willing to work with me via
    direct email or on the phone to help resolve specific
    conversion issues.
    [*]Finally, how do I say this... I <U>want</U> a 100% conversion, and
    with some headers, it just might happen. My goal is to make it
    convert the ISource headers as best as possible.
    Then I'll take other headers and see where it goes. I figure for
    something headers, the conversion will be 100%.[/list=a]
    Current Status and notes, in no particular order:
    • #includes are processed and combined into one file without
      comments. I removed the comments to make life easier. Maybe
      one day in the future, I'll put them back in, but right now I'm
      concerned mostly with the function code itself.
    • #define directives are processed and substituted
    • typedef <type> <stuff>; instructions are processed and subtituted (I think that's what I'm supposed to do)
    • declare and external (adding LIB) statements are well parsed
    • builds a FUNCTION (non-VOID) or SUB (VOID)
    • builds the parameter list with common c types that I know about (mostly from the PB docs)

    Now, maybe I'm doing something wrong. I suppose I'll find
    out soon enough as I'm sure there is much to learn.

    Like I said, the basic structure seems to be in place. I've got
    some nice parsing routines written, and while it's probably not
    Mr Z would do, it seems to work and pretty quickly. At this
    point, the ISource files (~9600 lines) processes in about six
    seconds on my laptop.

    So, are there any takers to assist me when I get to a problem
    line or those with c headers they've already converted? There
    may even be a few dumb questions through in there for good

    I love these kinds of programs. In fact, I wrote a CBASIC
    to PowerBasic converter many moons ago after using MDM7 to
    transfer files from a Cromemco CP/M machine to a DOS machine.

    Well, I hope to hear from y'all and let's see where this
    puppy wants to roam.


    [email protected]


    [This message has been edited by Dan Ginzel (edited May 19, 2003).]

  • #2
    Originally posted by Dan Ginzel:
    (Also, if anyone has a bit of web space
    they'd like to donate to the project for status and updates...)
    Sounds like a worthwhile project. I belive someone did something like this before, but its still worth refining. I have some web space I can donate (I don't know C so I can't help there). However, I would have one problem. Since and are the source of 84% of the spam coming into my email servers, I block both domains. So unless you have another account you can use, we won't be able to converse via email

    Joe Byrne
    mailto:[email protected]
    [email protected]
    Software makes Hardware Happen


    • #3
      Well, here's the latest.

      hConv version 0.10 seems to be processing Type...End Type
      structures now. Also, numeric constants seem to be working

      I've been using the sample including with Kev Peel's HDR2INC
      and can say that my program has basically all his functionality,
      sans the comment removal mentioned above.

      The differences are in how data types are handled. For example,
      according to the PB docs, char translates as byte, but Kev's
      program converts it to an asciiz.

      This is where I need help.

      How can give I give my logic the "knowledge" of which to use.

      Also, for the moment, I've stuck with the basic types in the
      PB docs. Again, to add more, this is where I'll need help.

      I've ordered some web space that will be up in the next couple
      of days with a dedicated email address for this project. I'll
      post that here when that is up.

      I'll likely post the source with it, although I wrote this
      quickly and I'm sure my programming style won't meet with
      everyones approval. It's just a program that kinda came together
      without much preplanning. Y'all know how that goes... It surely
      won't be a clean "compiler" like The PowerBasic Team would
      have written.

      Here's how I plan to proceed.

      I would still like to get some 'c' headers that have been
      sucessfully converted to PB. I can run those 'c' headers
      and compare the results and tweak the program until I get
      positive results.

      After I have a couple converting well, then I'll post the EXE
      so that y'all can try it out on your own and provide me
      feedback on the quality of conversion.

      Next, I'll tackle something more complicated, like the ISource
      headers. Those who wish to help, when I come into a stumbling
      block, I'll send everyone an email with the relevant lines
      (only those as referred pertaining to a particular conversion)
      and hope to receive back examples of how to convert it.

      Well, I guess that's about it. I think I'm going to hold off
      on any further development until I start to hear from people,
      either via email (temporarily at) [email protected] or
      in this post.

      Thanks a bunch!




      • #4
        Count me in Dan. This is a very interesting project.

        Paul Squires
        Cheetah Database System - "Nothing runs like a Cheetah"
        JellyFish Pro Editor - "Custom code editor for PowerBasic"
        mailto:[email protected][email protected]</A>
        Paul Squires
        FireFly Visual Designer (for PowerBASIC Windows 10+)
        Version 3 now available.


        • #5
          Well, I've been working hard and am now out of Oreo's,
          which isn't such a bad thing, I suppose.

          Anyhow, I've been working with the converter and have made
          lots of progress swatting some nastly little bugs and little
          pecularities. Hey, it's version 0.11 right now.

          I've purchased some web space and have developed a web site
          documenting what this program does, step-by-step, and has a
          section for posting code that I don't know how to handle for
          y'all to email me your input. I'll post the URL when the DNS
          servers update in a couple of days.

          I'll also post the source and PB/Win 7 compiled EXE there as
          soon as I pretty up the user-interface just a tad, probably
          by the end of the week.

          Well, I've used the example.h included with Kev Peel's HDR2INC
          and added a #define and a couple of typedef's that I assume
          have to be substituted.

          Here's the example.h file that I used for my initial tests:
          #define CONSTANT1         0
          #define CONSTANT2         1
          #define CONSTANT3         2
          #define CONSTANT4         3
          #define CONSTANT5         4
          typedef LPCSTR ARRAYTYPE;
          #define _IS3EXP_ extern
          typedef UINT32 HISSRC;
          typedef IS3CALL __stdcall;
          typedef void Mysubroutine (
               const char *Param1,
               Int Param2);
          typedef uint Test (
               byte *value);
          typedef Int MyFunction (
               Long Param1,
               Dword Param2,
               Long *Pointer1,
               Long *Pointer2);
          #define MYCONST1                1
          #define MYCONST2                2
          #define MYCONST3                3
          #define MYCONST4                4
          #define MYCONST5                5
          #define MYSTRINGLEN_A        10
          #define MYSTRINGLEN_B        50
          _IS3EXP_ HISSRC IS3CALL IS3FunctionName(const char * pFileName);
          typedef struct st_MyStruct {
           char stringmember1[32];
           char stringmember2[MYSTRINGLEN_A];
           Dword numarray1[32];
           Dword numarray2[MYSTRINGLEN_B];
           LPCSTR stringptrarray[32];
           ARRAYTYPE anotherstringptrarray[32];
           const char MYCONST1mychars[4500];
          } MyStruct;
          And (drum-roll, please) here's the code hConv created:
               %CONSTANT1 = 0 
               %CONSTANT2 = 1
               %CONSTANT3 = 2
               %CONSTANT4 = 3
               %CONSTANT5 = 4
               Declare Sub Mysubroutine Alias "Mysubroutine" ( _
                    Param1 As BYTE Ptr, _
                    ByVal Param2 As LONG)
               Declare Function Test Alias "Test" ( _
                    value As BYTE Ptr)
                         As DWORD
               Declare Function MyFunction Alias "MyFunction" ( _
                    ByVal Param1 As LONG, _
                    ByVal Param2 As DWORD, _
                    Pointer1 As LONG Ptr, _
                    Pointer2 As LONG Ptr)
                         As LONG
               %MYCONST1 = 1
               %MYCONST2 = 2
               %MYCONST3 = 3
               %MYCONST4 = 4
               %MYCONST5 = 5
               %MYSTRINGLEN_A = 10
               %MYSTRINGLEN_B = 50
               Declare Function IS3FunctionName Lib "nameof.dll" Alias "IS3FunctionName" ( _
                    pFileName As BYTE Ptr)
                         As DWORD
               Type st_MyStruct
                    stringmember1 as ASCIIZ * 32
                    stringmember2 as ASCIIZ * %MYSTRINGLEN_A
                    numarray1(32) as DWORD
                    numarray2(%MYSTRINGLEN_B) as DWORD
                    stringptrarray(32) as ASCIIZ PTR
                    anotherstringptrarray(32) as ASCIIZ PTR
                    MYCONST1mychars as ASCIIZ * 4500
               End Type
          Please take a look at it. If I've got something wrong in this
          simple example, please, by all means, let me know either here
          at [email protected] (removing the cap letters).

          (Not demonstrated here is that hConv merges in
          #include "filename.h" files, too, thus creating one large INC
          file out of multiple files.)

          Remember, if you've got experience in converting c headers to
          PowerBasic, I really need your help so that I can attempt to
          make this as complete of a conversion as possible. (Yes, I'm
          sure there'll be some situations it won't be able to handle.
          I just want to cover as much ground as possible.)

          Again, I'll post right here, same channel, the web site
          URL when it's up.

          See 'ya

          [email protected]
          (remove the cap letters)

          (p.s. I added the comment ' to the generated code as the BBS
          removed all my blank lines.)


          [This message has been edited by Dan Ginzel (edited May 18, 2003).]