/usr/include/nih/command.h is in libnih-dev 1.0.3-6ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | /* libnih
*
* Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
* Copyright © 2009 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef NIH_COMMAND_H
#define NIH_COMMAND_H
/**
* Builds on the command-line option and arguments parser to provide an
* application interface where the first non-option argument is the name
* of a command. Both global and command-specific options are permitted,
* and global options may appear both before and after the command.
*
* Description your commands using an array of NihCommand members,
* with each describing its options using an array of NihOption members.
* Pass this all to nih_command_parser().
*
* Commands are implemented with a handler function that is called,
* when nih_command_parser returns it has completed its work.
**/
#include <nih/macros.h>
#include <nih/option.h>
/**
* NihCommandAction;
* @command: NihCommand invoked,
* @args: command-line arguments.
*
* A command action is a function called when a command is found in the
* command-line arguments. It is passed the list of arguments that
* follow as an array allocated with nih_alloc().
*
* The return value of the function is returned from nih_command_parser().
**/
typedef struct nih_command NihCommand;
typedef int (*NihCommandAction) (NihCommand *command, char * const *args);
/**
* NihCommandGroup:
* @title: descriptive help message.
*
* This structure is used to define a group of commands that are collated
* together when help is given.
**/
typedef struct nih_command_group {
char *title;
} NihCommandGroup;
/**
* NihCommand:
* @command: command name,
* @usage: usage string,
* @synopsis: synopsis string,
* @help: help string,
* @group: group option is member of,
* @options: command-specific options,
* @action: function to call when found.
*
* This structure defines a command that may be found in the command-line
* arguments after any application-specific options, and before any
* command-specific options. @command must be specified which is the
* string looked for.
*
* After @command is found in the arguments, following options are
* considered specific to the command. These are specified in @options,
* which should be an array of NihOption structures terminated by
* NIH_OPTION_LAST. This may be NULL, in which case it is treated the same
* as an empty list.
*
* Any remaining command-line arguments are placed in an array and given
* as an argument to the @action function.
*
* Help for the command is built from @usage, @synopsis and @help as if
* they were passed to nih_option_set_usage(), etc. for this command.
**/
struct nih_command {
char *command;
char *usage;
char *synopsis;
char *help;
NihCommandGroup *group;
NihOption *options;
NihCommandAction action;
};
/**
* NIH_COMMAND_LAST:
*
* This macro may be used as the last command in the list to avoid typing
* all those NULLs yourself.
**/
#define NIH_COMMAND_LAST { NULL, NULL, NULL, NULL, NULL, NULL, NULL }
NIH_BEGIN_EXTERN
int nih_command_parser (const void *parent, int argc, char *argv[],
NihOption *options, NihCommand *commands);
NihCommand *nih_command_join (const void *parent,
const NihCommand *a, const NihCommand *b)
__attribute__ ((warn_unused_result));
NIH_END_EXTERN
#endif /* NIH_COMMAND_H */
|