2 * Copyright (c) Zmanda, Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation.
8 * This library 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 Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 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
21 %module "Amanda::Cmdline"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24 %include "amglue/dumpspecs.swg"
34 Amanda::Cmdline - utilities for handling command lines
40 my $spec = Amanda::Cmdline::dumpspec_t->new($host, $disk, $datestamp, $level);
41 print "host: $spec->{'host'}; disk: $spec->{'disk'}\n";
43 my @specs = Amanda::Cmdline::parse_dumpspecs(["host", "disk", "date"],
44 $Amanda::Cmdline::CMDLINE_PARSE_DATESTAMP);
50 =head1 Amanda::Cmdline::dumpspec_t Objects
52 =head2 Instance Variables
72 Format the dumpspec as a string.
80 =item C<format_dumpspec_components($host, $disk, $datestamp, $level)>
82 This function returns a string representing the formatted form of the given dumpspec. This formatting
83 is the same as performed by C<format_dumpspec_components>, but does not need a C<dumpspec_t>.
85 =item C<parse_dumpspecs(@cmdline, $flags)>
87 This function parses C<@cmdline> into a list of C<dumpspec_t> objects,
88 according to C<$flags>, which is a logical combination of zero or
89 more of C<$CMDLINE_PARSE_DATESTAMP> to recognize datestamps and
90 C<$CMDLINE_PARSE_LEVEL> to recognize levels.
96 L<Amanda::Config> handles C<-o> options itself, through C<config_overwrites>.
101 /* Add a few methods to make this type act like a class */
102 typedef struct dumpspec_t {
112 dumpspec_t(char *host, char *disk, char *datestamp, char *level) {
113 return dumpspec_new(host, disk, datestamp, level);
122 return cmdline_format_dumpspec(self);
127 %rename(format_dumpspec_components) cmdline_format_dumpspec_components;
128 char *cmdline_format_dumpspec_components(char *host, char *disk, char *datestamp, char *level);
130 /* Typemap to convert a perl list of strings to the strv that
131 * cmdline_parse_dumpspecs expects.
133 %typemap(in, numinputs=1) (int argc, char **argv) {
137 if (!SvROK($input) || SvTYPE(SvRV($input)) != SVt_PVAV) {
138 SWIG_exception(SWIG_TypeError, "Expected an arrayref");
140 av = (AV *)SvRV($input);
142 $1 = av_len(av)+1; /* av_len(av) is like $#av */
143 $2 = malloc(sizeof(char *) * $1);
144 for (i = 0; i < $1; i++) {
145 SV **elt = av_fetch(av, i, 0);
146 if (!elt || !SvPOK(*elt)) {
147 SWIG_exception(SWIG_TypeError, "Non-string in arrayref");
149 $2[i] = SvPV_nolen(*elt); /* TODO: handle unicode here */
153 /* Free the space allocated by the previous typemap */
154 %typemap(freearg) (int argc, char **argv) {
158 amglue_add_flag_tag_fns(cmdline_parse_dumpspecs_flags);
159 amglue_add_constant(CMDLINE_PARSE_DATESTAMP, cmdline_parse_dumpspecs_flags);
160 amglue_add_constant(CMDLINE_PARSE_LEVEL, cmdline_parse_dumpspecs_flags);
161 amglue_add_constant(CMDLINE_EMPTY_TO_WILDCARD, cmdline_parse_dumpspecs_flags);
163 %rename(parse_dumpspecs) cmdline_parse_dumpspecs;
164 amglue_dumpspec_list *cmdline_parse_dumpspecs(int argc, char **argv, int flags);
167 * convert AV back to GSList as input, convert resulting GSList into an AV of strings
170 /* amglue_dumpspec_list * cmdline_match_holding(amglue_dumpspec_list *dumpspec_list); */