~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to db/help.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2002-04-13 09:45:06 UTC
  • Revision ID: james.westby@ubuntu.com-20020413094506-t8dhemv41gkeg4kx
Tags: 2.0.3-1
New upstream bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 * 
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of version 2 of the GNU General Public License as
 
6
 * published by the Free Software Foundation.
 
7
 * 
 
8
 * This program is distributed in the hope that it would be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
11
 * 
 
12
 * Further, this software is distributed without any warranty that it is
 
13
 * free of the rightful claim of any third person regarding infringement
 
14
 * or the like.  Any license provided herein, whether implied or
 
15
 * otherwise, applies only to this software file.  Patent licenses, if
 
16
 * any, provided herein do not apply to combinations of this program with
 
17
 * other software, or any other product whatsoever.
 
18
 * 
 
19
 * You should have received a copy of the GNU General Public License along
 
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
 
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
 
22
 * 
 
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 
24
 * Mountain View, CA  94043, or:
 
25
 * 
 
26
 * http://www.sgi.com 
 
27
 * 
 
28
 * For further information regarding this notice, see: 
 
29
 * 
 
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
 
31
 */
 
32
 
 
33
#include <libxfs.h>
 
34
#include "command.h"
 
35
#include "help.h"
 
36
#include "output.h"
 
37
 
 
38
static void     help_all(void);
 
39
static void     help_onecmd(const char *cmd, const cmdinfo_t *ct);
 
40
static int      help_f(int argc, char **argv);
 
41
static void     help_oneline(const char *cmd, const cmdinfo_t *ct);
 
42
 
 
43
static const cmdinfo_t  help_cmd =
 
44
        { "help", "?", help_f, 0, 1, 0, "[command]",
 
45
          "help for one or all commands", NULL };
 
46
 
 
47
static void
 
48
help_all(void)
 
49
{
 
50
        const cmdinfo_t *ct;
 
51
 
 
52
        for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++)
 
53
                help_oneline(ct->name, ct);
 
54
        dbprintf("\nUse 'help commandname' for extended help.\n");
 
55
}
 
56
 
 
57
static int
 
58
help_f(
 
59
        int             argc,
 
60
        char            **argv)
 
61
{
 
62
        const cmdinfo_t *ct;
 
63
 
 
64
        if (argc == 1) {
 
65
                help_all();
 
66
                return 0;
 
67
        }
 
68
        ct = find_command(argv[1]);
 
69
        if (ct == NULL) {
 
70
                dbprintf("command %s not found\n", argv[1]);
 
71
                return 0;
 
72
        }
 
73
        help_onecmd(argv[1], ct);
 
74
        return 0;
 
75
}
 
76
 
 
77
void
 
78
help_init(void)
 
79
{
 
80
        add_command(&help_cmd);
 
81
}
 
82
 
 
83
static void
 
84
help_onecmd(
 
85
        const char      *cmd,
 
86
        const cmdinfo_t *ct)
 
87
{
 
88
        help_oneline(cmd, ct);
 
89
        if (ct->help)
 
90
                ct->help();
 
91
}
 
92
 
 
93
static void
 
94
help_oneline(
 
95
        const char      *cmd,
 
96
        const cmdinfo_t *ct)
 
97
{
 
98
        if (cmd)
 
99
                dbprintf("%s ", cmd);
 
100
        else {
 
101
                dbprintf("%s ", ct->name);
 
102
                if (ct->altname)
 
103
                        dbprintf("(or %s) ", ct->altname);
 
104
        }
 
105
        if (ct->args)
 
106
                dbprintf("%s ", ct->args);
 
107
        dbprintf("-- %s\n", ct->oneline);
 
108
}
 
109