2 * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 * Author: Dustin J. Mitchell <dustin@zmanda.com>
25 * Utility routines for handling command lines.
32 #include "glib-util.h"
34 /* A dumpspec can specify a particular dump (combining host, disk, and
35 * datestamp), or can be less specific by leaving out some components.
36 * Missing components are NULL, except in the special case of an
37 * "wildcard" dumpspec, as detailed below.
39 * All strings in this struct are independently malloc()ed.
41 typedef struct dumpspec_s {
49 * Dumpspec list management
52 /* Create a new dumpspec with the given components
54 * @param host: host name
55 * @param disk: disk name
56 * @param datestamp: datestamp
57 * @param level: level (as a string, allowing regexes)
58 * @returns: dumpspec, or NULL on error
67 /* Free memory associated with a single dumpspec. (Does not chase
70 * @param dumpspec: the dumpspec to free
74 dumpspec_t *dumpspec);
76 /* Free memory associated with a list of dumpspecs. CAUTION: do not
77 * use glib's g_slist_free directly on a dumpspec list, as it will not
78 * free the elements themselves.
80 * @param dumpspec_list: the GSList of dumpspecs to free
84 GSList *dumpspec_list);
90 /* Parse a command line matching the following syntax, and return
91 * the results as a linked list.
93 * [ host [ disk [ datestamp [ host [ disk [ datestamp .. ] ] ] ] ] ]
95 * If no results are specified, the function either returns NULL (an
96 * empty list) or, if CMDLINE_EMPTY_TO_WILDCARD is given, a list
97 * containing a single dumpspec with all fields set to "".
99 * Calls error() with any fatal errors, e.g., invalid regexes.
101 * @param argc: count of command line arguments
102 * @param argv: command line arguments
103 * @param flags: bitmask of the CMDLINE_* flags
104 * @returns: dumpspec list
107 cmdline_parse_dumpspecs(
111 /* flags values (bitmask): */
112 /* parse datestamps after disks */
113 # define CMDLINE_PARSE_DATESTAMP (1<<0)
114 /* parse levels after datestamps or disks */
115 # define CMDLINE_PARSE_LEVEL (1<<1)
116 /* an empty argv should result in a wildcard dumpspec */
117 # define CMDLINE_EMPTY_TO_WILDCARD (1<<2)
123 /* Format a dumpspec into a string, with shell-compatible quoting.
125 * Caller is responsible for freeing the string.
127 * @param dumpspec: the dumpspec to format
128 * @returns: newly allocated string, or NULL on error
131 cmdline_format_dumpspec(
132 dumpspec_t *dumpspec);
134 /* Like cmdline_format_dumpspec, but with components supplied
135 * individually. Caller is responsible for freeing the
138 * @param host: host name
139 * @param disk: disk name
140 * @param datestamp: datestamp
141 * @returns: newly allocated string, or NULL on error
144 cmdline_format_dumpspec_components(
154 /* Find all holding files matching the dumpspec list. If
155 * the dumpspec list contains a dumpspec with all blank
156 * entries, all holding files are returned.
158 * Free the resulting list with g_slist_free_full()
160 * @param dumpspec_list: a list of dumpspecs
161 * @returns: a list of holding disk filenames.
164 cmdline_match_holding(
165 GSList *dumpspec_list);
167 #endif /* CMDLINE_H */