From mboxrd@z Thu Jan 1 00:00:00 1970 From: Goffredo Baroncelli Subject: [RFC][GIT] Move the the text of the man page in the code Date: Fri, 15 Jul 2011 15:28:19 +0200 Message-ID: <4E204073.2060103@inwind.it> Reply-To: kreijack@inwind.it Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020203000604020109090104" Cc: Hugo Mills , Hubert Kario , Chris Mason To: linux-btrfs Return-path: List-ID: This is a multi-part message in MIME format. --------------020203000604020109090104 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi all, after the discussion of the thread " [PATCH 2/2] add detailed help messages to btrfs command", I coded a solution for moving the help information of the btrfs sub-commands in the code. Actually we have three source of information about the btrfs sub-commands: 1) btrfs help this show the command syntax, and a brief help (often 1 line) about the command purpose 2) btrfs --help this show the command syntax, and a detailed (if available ) explanation of the command 3) the man page This cause a lot of information duplicated. Very often these information are incoherent or outdated. My idea is to code these information in the comment before the relevant function. Then a tool will parse these files and generate both a man page and the text showed in the "btrfs *help" commands. The information are store in a comment like this: /**** man: btrfs subvolume delete * * \Bbtrfs\b \Bsubvolume delete\b\I \i * * Delete the subvolume . * * Delete the subvolume \I\i. If \I\i is not a * subvolume, \Bbtrfs\b returns an error. ****/ The first part ("/**** man: ") is a marker line is a marker. So the tool knows that it should extract the information from the comment. * After the marker (first line) there is the name of the btrfs sub command. * Then there is a empty line. * Then there is the command line syntax (1 line only) * Then there is a empty line. * Then there is the short description (the one used in the command "btrfs help"). Multiple line allowed. * Then there is a empty line. * Then there is the detailed description (the one used in the command "btrfs --help", and in the man page). Multiple line allowed. Note: the \B are marker to highlight that it should start the bold font. (\b->end bold font, \I->start italic font, \i->end italic font....) For the help command these information are sufficient. For the man page, there is two more section (which I named "btrfs introduction" and "btrfs notes") which detail in a more general way the btrfs commands. Think about these section as a header and a footer. Technical details: The tool which extract the information is called "helpextract". It is a C program which analyzes the files passed on the command line, and generate the C array and the man page. C-Array The Makefile generates the file helpmsg.c, which contains an array with all the information extracted from the comment. The code which process the help uses these information to show the normal and the detailed help. Man page The man page generation is a bit more complicated. There is a footer, there is header, there is an introduction, there is a section which contains the notes (I hope to permit the access about these two section from the command line; something like "btrfs help introduction") and some template. You can generate the man page via $ make man/btrfs.8.2.in $ man man/btrfs.8.2.in The man page is quite good. You can download at http://cassiopea.homelinux.net/tmp/btrfs.8.2.in Where are the information. For simplicity I put the comment with the information in two files: "btrfs.8+1.in.c" and "btrfs.8.in.c". These two files are temporary. I hope to integrate the text in the source. Repository You can download the source from http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git and/or browse the code at http://cassiopea.homelinux.net/git/?p=btrfs-progs-unstable.git $ git diff --stat integration-20110705 Makefile | 22 +++- btrfs.8+1.in.c | 331 ++++++++++++++++++++++++++++++++ btrfs.8.in.c | 116 +++++++++++++ btrfs.c | 34 ++++- extract_from_man_page.py | 249 ++++++++++++++++++++++++++++ helpextract.c | 403 ++++++++++++++++++++++++++++++++++++++ man/btrfs.8.in | 27 ++-- 7 files changed, 1163 insertions(+), 19 deletions(-) Escape sequence As stated before, in the comment it is possible to use some escape sequence to format the text. When the man page is generate, the tools replace the escape sequence (the left one) with a "troff" macro on the basis of the following table: \B \fB /* bold */ \b \fP /* end bold */ \I \fI /* italic */ \i \fP /* end italic */ \c .\" /* comment */ \P .PP /* start paragraph */ \p .TP /* indented paragraph */ \h .SH /* header */ \d .BR /* bold regular */ \e .B /* bold */ \t .IP /* indented paragraph */ \w .RS /* move the left margin */ \q .RE /* move the left margin back */ For example the \P sequence is used to start a paragraph. Next step If there no is major complaints and/or issues I will move the comments with the information near the functions which perform the command, and I will add some documentation. Comments are welcome BR G.Baroncelli Enclosed the code for the comment diff --git a/Makefile b/Makefile index edee1a0..f089ca7 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,9 @@ all: version $(progs) manpages version: bash version.sh -btrfs: $(objects) btrfs.o btrfs_cmds.o scrub.o +btrfs: $(objects) btrfs.o btrfs_cmds.o scrub.o helpmsg.o $(CC) -lpthread $(CFLAGS) -o btrfs btrfs.o btrfs_cmds.o scrub.o \ + helpmsg.o \ $(objects) $(LDFLAGS) $(LIBS) btrfsctl: $(objects) btrfsctl.o @@ -84,6 +85,25 @@ convert: $(objects) convert.o ioctl-test: $(objects) ioctl-test.o $(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS) +helpextract: helpextract.o + $(CC) $(CFLAGS) -o $@ helpextract.o + +man/btrfs.8.2.in: helpextract + ./helpextract --man-page btrfs.8*.c >$@ + +helpmsg.c: helpextract + echo >$@ "/*" + echo >>$@ " * this file contains the help messages. It is " + echo >>$@ " * automatically generated. do not edit ! " + echo >>$@ " */" + echo >>$@ + echo >>$@ "#define NULL 0" + echo >>$@ + + echo -n "char * help_messages[] = " >>$@ + ./helpextract --c-array btrfs.8*.c >>$@ + echo >>$@ ";" + manpages: cd man; make diff --git a/btrfs.8+1.in.c b/btrfs.8+1.in.c new file mode 100644 index 0000000..49855d4 --- /dev/null +++ b/btrfs.8+1.in.c @@ -0,0 +1,331 @@ +/**** man: btrfs subvolume delete + * + * \Bbtrfs\b \Bsubvolume delete\b\I \i + * + * Delete the subvolume . + * + * Delete the subvolume \I\i. If \I\i is not a + * subvolume, \Bbtrfs\b returns an error. + ****/ + +/**** man: btrfs scrub start + * + * \Bbtrfs\b \Bscrub start\b [-Bdqru] {\I\i|\I\i} + * + * Start a new scrub. + * + * Start a scrub on all devices of the filesystem identified by \I\i or on + * a single \I\i. Without options, scrub is started as a background + * process. Progress can be obtained with the \Bscrub status\b command. Scrubbing + * involves reading all data from all disks and verifying checksums. Errors are + * corrected along the way if possible. + * \w + * + * \IOptions\i + * \t -B 5 + * Do not background and print scrub statistics when finished. + * \t -d 5 + * Print separate statistics for each device of the filesystem (-B only). + * \t -q 5 + * Quiet. Omit error messages and statistics. + * \t -r 5 + * Read only mode. Do not attempt to correct anything. + * \t -u 5 + * Scrub unused space as well. (NOT IMPLEMENTED) + * \q + ****/ + +/**** man: btrfs filesystem show + * + * \Bbtrfs\b \Bfilesystem show\b [--all-devices||