5
Nov

Online c function prototype header generator tool

Note: latest code on my laptop. Refactoring and improving for code release.

Really simple concept: scan an input c file, find the functions that need prototype declarations, and then output the prototype declarations for you to copy and paste into a header or at the top of your file.

I use this simple tool when quickly prototyping microcontroller c code. Just write your code without worrying about declaring function prototypes, then copy and paste the code into this tool and it will create the declarations for all functions that have not been declared yet. No rocket science going on, just saves you some time.

You can also use this tool to merge additions to your header file if you have a number of functions that you forgot to declare. Just paste the header and source files together in here and let the script spit out the missing declarations to add to the header.

Keep in mind that this tool is intended for quick prototyping. If you are making something complicated, best plan out your headers. Don't blame me for helping you be lazy :)

pre load brushes

not empty
not empty
NOTE! this script is a proof of concept hacked together with a bunch of large regex patterns so be realistic with what you expect from it! Performance could be drastically improved if javascript had possessive quantifiers (sad face).

OPTIONS:
Sort by: then by: then by:

include guard: append: wtf?

Existing declarations/header (so we can skip identical declarations):


INPUT C CODE:

get larger example c | get huge/complex example

OUTPUT HEADER:
//click the button!

LOG:
nothing yet



Use at your own risk... blah blah... however you see fit (license).

Notes:

  • Because the tool uses regular expressions and not full parsing, I'm sure occasional errors will occur (especially around funky macro usage). Keep an eye out, but it should be helpful in many cases.
  • Captured comments must follow the doxygen format . We also accept a single "///" line instead of requiring "at least two C++ comment lines" for the truley lazy :)

TODO:

  • TODO: compile regular expressions once
  • TODO: better support for additional keywords like 'static'
  • TODO: better general parsing respecting strings
  • TODO (maybe): support for old c function definitions "int main(argc, argv) int argc; char *argv[]; {"
  • TODO (maybe): use a ported regex engine (perl? python?). Possessive quantifiers would make a HUGE difference while parsing strings and block comments (otherwise we can have catastrophic backtracking).
  • TODO (mabye): improve function signature matching for strings with "," in them, and extern keyword...
  • TODO (maybe): ability to extract/remove existing declarations (in case you sloppily declared them throughout your source), so that you can move them to the top of your code or to a header file...
  • TODO (maybe): improve function detection. Wouldn't find multiple declarations on the same line right now.
  • done: improve general parsing to respect block comments (don't want to accidentally find function declarations/definitions in large block comments)
  • done: copy doxygen style comments

Comments

  1. Tony Zampini says:

    Hi Adam,
    I just used your function prototype tool, and it saved me a ton of time!!. Thank you for sharing. If you are looking for suggestions, I have one. My C project has about 20 source files, so I had to cut/paste 20 times. It would unbelievably great if, instead of using the source as input, a list of C filenames could be used as input. Then your script could upload the files create prototypes for the entire project at once. Just a suggestion. Thanks again for your effort in developing this. Tony

    1. Adam Fraser-Kruck says:

      Hi Tony!

      glad you like it. I actually find my self using it quite a bit.

      I'm hesitant to upload files because I don't want to handle people's code or have them question the security of it. This current generator doesn't send your code anywhere. All the processing is done right in your browser with no transmission anywhere.

      That said, I am slowing working away on an offline tool that we can use to take care of things like this. It will be like a code assistant. Generate prototypes, create "toString" methods for enums, create validators/iterators for enums, all the monotonous things that are simple but time consuming and error prone to maintain.

      The tool will also be written in Typescript (a form of Javascript) to make customization and editing easier.

      Adam

Leave a Reply

Your email address will not be published. Required fields are marked *