-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation #48
Comments
Here is a tentative (i.e. braindump) mockup that demonstrates what this could look like. Given the function /* -- NAME
* initialize the wayland compositor
*
* -- DESCRIPTION
* wlc_init() initializes the `interface` along with passing `argc` and
* `argv` from main(), so wlc can rename the process it forks to cleanup
* crashed parent process and do FD passing (non-logind).
*
* -- RETURN VALUE
* Upon successful execution wlc_init() will return true.
*
* -- ERRORS
* All errors encountered in wlc_init() are considered fatal and thus should
* never really return false.
*
* -- NOTES
* Avoid running unverified code before wlc_init() as wlc compositor may be run
* with higher privileges on non logind systems where compositor binary needs
* to be suid.
*
* -- ALSO SEE
* wlc_interface(3)
*/
WLC_NONULLV(1) bool wlc_init(const struct wlc_interface *interface, int argc, char *argv[]); The converstion to groff_man(7) should yeild something like this: The Any reference to a function name in the form of Note that the entire .TH WLC_INIT 3 2015-09-30 WLC "WLC API Functions"
.SH NAME
wlc_init \- initialize the wayland compositor
.SH SYNOPSIS
.B #include <wlc/wlc.h>
.BI "bool wlc_init(const struct wlc_interface " *interface ", int " argc ", char " *argv[] ");"
.SH DESCRIPTION
.BR wlc_init ()
initializes the
.I interface
along with passing
.I argc
and
.I argv
from
.BR main ()
, so wlc can rename the process it forks to cleanup crashed parent process and do FD passing (non-logind).
.SH RETURN VALUE
Upon successful execution
.BR wlc_init ()
will return true.
.SH ERRORS
All errors encountered in
.BR wlc_init ()
are considered fatal and thus should never really return false.
.SH NOTES
Avoid running unverified code before
.BR wlc_init ()
as wlc compositor may be run with higher privileges on non logind systems where compositor binary needs to be suid.
.SH ALSO SEE
.BR wlc_interface (3) Which would should render something like this on the users screen via the normal
|
This is not bad at all, and doesn't look too complicated to write generator for (apart from understanding bit of C for the function prototypes). If escaping is desired, it should be in way that is simplest for the parser. That is, do not provide many ways to escape things. |
I wonder if clang can do it |
Clang was bit troubling with python at least. I've never used the C api though. Ragel can parse C nicely, but won't "understand" it. I think most documentation generators don't actually understand C, but I can see that becoming problematic in some scenarios, like having preprocessor definitions (often for symbol visibility, or compiler attributes) front of function declarations, or even worse libpng style macro function declarations. |
There are several limitations to this approach. The main one is you're essentially locking yourself to
When doing parsing of semantic elements like the backticks one has to consider how it could be represented. For example consider the text:
If we define backticks as .I foo
.BI bar () This immediately presents lots of edge cases which would be ugly to parse. The first is that
Would become the following groff without inlining the macros: .I foo
.BR bar () "" ,
.I baz The use of However there is a rather nice solution to both of these issues but generally produces slightly less than pretty looking manuals. This is the use of inline macros via the Consider again the first example of bold being used inside italics. The inline solution (from a parsers perspective) to this would be: \fIfoo \fBbar\fR\fI()\fR And for the second example: \fIfoo \Bbar\fR\fI(), bar\fR Notice how we can allow unbalanced pairs, the first That is to say, Things to consider would be if you want this format to be more general. This would almost certainly require the use of an IR, which the prompts the question of why not just use a well supported markup like restructed text or asciidoc directly? These formats can both generate manuals fairly comfortably, all the tool here would need to do is parse the comment block and C definition below it. If the manual generation isn't perfectly like |
This is quite nice too https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt |
Heh, regex poorly all the things: (but as proof of concept it seems to work for the simple stuff I've thrown at, including some edge cases.)
gman() { italic | embold | mkref | mksec }
italic() { sed 's/`\([^`\]*\)`/\\fI\1\\fR/g'; }
embold() { sed 's/\b\([^ ]*\)()/\\fB\1\\fR()/g'; }
mkref() { sed 's/\b\([^ ]*\)(\([0-9]\))/\\fB\1\\fR(\2)/g'; }
mksec() { sed 's/^-- \(.*\)/.SH \1/'; } |
That's nice proof of concept.
This is fine too, as long as the output is high quality. The only downside might be that the comment blocks might become more markup heavy. I don't think most documentation derives too much from what you have done with wlc_init here. Though I can't consider other projects here. |
It would be nice to have documentation syntax in code so we can generate for example man pages for wlc API. Doxygen has been used before, but it may be worth to resee what are the options nowadays.
The text was updated successfully, but these errors were encountered: