From patchwork Fri Jul 15 13:28:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 978152 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6FDYMBu028302 for ; Fri, 15 Jul 2011 13:34:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751795Ab1GONeS (ORCPT ); Fri, 15 Jul 2011 09:34:18 -0400 Received: from smtp209.alice.it ([82.57.200.105]:57381 "EHLO smtp209.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751203Ab1GONeP (ORCPT ); Fri, 15 Jul 2011 09:34:15 -0400 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 15 Jul 2011 13:34:23 +0000 (UTC) X-Greylist: delayed 363 seconds by postgrey-1.27 at vger.kernel.org; Fri, 15 Jul 2011 09:34:14 EDT Received: from [192.168.7.27] (87.6.209.209) by smtp209.alice.it (8.5.124.08) (authenticated as kreijack@alice.it) id 4DE658F804704796; Fri, 15 Jul 2011 15:28:08 +0200 Message-ID: <4E204073.2060103@inwind.it> Date: Fri, 15 Jul 2011 15:28:19 +0200 From: Goffredo Baroncelli Reply-To: kreijack@inwind.it User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110626 Iceowl/1.0b2 Icedove/3.1.11 MIME-Version: 1.0 To: linux-btrfs CC: Hugo Mills , Hubert Kario , Chris Mason Subject: [RFC][GIT] Move the the text of the man page in the code X-Enigmail-Version: 1.1.2 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 \fBbtrfs\fP \fBfilesystem balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI\fP] \fI\fP @@ -37,7 +35,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices| [...]]\fP .PP -\fBbtrfs\fP \fBdevice show\fP\fI [--all-devices||