2 * Copyright (c) 2007,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. Mathilda 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 {
46 char *write_timestamp;
50 * Dumpspec list management
53 /* Create a new dumpspec with the given components
55 * @param host: host name
56 * @param disk: disk name
57 * @param datestamp: datestamp
58 * @param level: level (as a string, allowing regexes)
59 * @param write_timestamp: timestamp written to tape.
60 * @returns: dumpspec, or NULL on error
68 char *write_timestamp);
70 /* Free memory associated with a single dumpspec. (Does not chase
73 * @param dumpspec: the dumpspec to free
77 dumpspec_t *dumpspec);
79 /* Free memory associated with a list of dumpspecs. CAUTION: do not
80 * use glib's g_slist_free directly on a dumpspec list, as it will not
81 * free the elements themselves.
83 * @param dumpspec_list: the GSList of dumpspecs to free
87 GSList *dumpspec_list);
93 /* Parse a command line matching the following syntax, and return
94 * the results as a linked list.
96 * [ host [ disk [ datestamp [ host [ disk [ datestamp .. ] ] ] ] ] ]
98 * If no results are specified, the function either returns NULL (an
99 * empty list) or, if CMDLINE_EMPTY_TO_WILDCARD is given, a list
100 * containing a single dumpspec with all fields set to "".
102 * Calls error() with any fatal errors, e.g., invalid regexes.
104 * @param argc: count of command line arguments
105 * @param argv: command line arguments
106 * @param flags: bitmask of the CMDLINE_* flags
107 * @returns: dumpspec list
110 cmdline_parse_dumpspecs(
114 /* flags values (bitmask): */
115 /* parse datestamps after disks */
116 # define CMDLINE_PARSE_DATESTAMP (1<<0)
117 /* parse levels after datestamps or disks */
118 # define CMDLINE_PARSE_LEVEL (1<<1)
119 /* an empty argv should result in a wildcard dumpspec */
120 # define CMDLINE_EMPTY_TO_WILDCARD (1<<2)
126 /* Format a dumpspec into a string, with shell-compatible quoting.
128 * Caller is responsible for freeing the string.
130 * @param dumpspec: the dumpspec to format
131 * @returns: newly allocated string, or NULL on error
134 cmdline_format_dumpspec(
135 dumpspec_t *dumpspec);
137 /* Like cmdline_format_dumpspec, but with components supplied
138 * individually. Caller is responsible for freeing the
141 * @param host: host name
142 * @param disk: disk name
143 * @param datestamp: datestamp
144 * @returns: newly allocated string, or NULL on error
147 cmdline_format_dumpspec_components(
157 /* Find all holding files matching the dumpspec list. If
158 * the dumpspec list contains a dumpspec with all blank
159 * entries, all holding files are returned.
161 * Free the resulting list with slist_free_full()
163 * @param dumpspec_list: a list of dumpspecs
164 * @returns: a list of holding disk filenames.
167 cmdline_match_holding(
168 GSList *dumpspec_list);
170 #endif /* CMDLINE_H */