cgmb / guardonce

Utilities for converting from C/C++ include guards to #pragma once and back again.
MIT License
142 stars 3 forks source link

Customize once2guard's #endif output #16

Closed cgmb closed 6 years ago

cgmb commented 7 years ago

Many projects include a comment after each #endif to specify what conditional is ending. It would be nice if you could specify how once2guard did this. For example, from node:

#ifndef SRC_BASE_OBJECT_H_
#define SRC_BASE_OBJECT_H_
...
#endif  // SRC_BASE_OBJECT_H_

A major part of why I built guardonce was to make it easy to convert back from #pragma once if a problem ever arises. If the generated code breaks a style guide and needs manual correction, that's a problem. once2guard and guard2once should be able to round-trip most guard styles.

There are lots of different styles, so perhaps the easiest thing to do would be to allow the user to provide a template. There just needs to be some way to refer to the generated guard symbol from that template.

It would work something like,

once2guard -t '#endif /* % */' file.h

Fancier template languages like jinja seem a bit overkill, so perhaps a single special character to refer to the guard symbol would be sufficient. Or maybe I should use {} to match find and friends?

cgmb commented 7 years ago

It's also a little annoying if you want a blank line between the last line of code and the #endif. Not sure if it's better to correct that with a separate flag or just let you specify newlines in the template.

cgmb commented 7 years ago

The behaviour in my previous comment seems to come from once2guard just appending the #endif to the file, oblivious to whether the file ends in blank line or not. Trying to make a template language that allows you to conditionally decide to add newlines or not seems rather complicated both for users and for me. Perhaps that's best as just a separate flag.