+#copy symbols in running_as_flags to constants
+push @{$EXPORT_TAGS{"constants"}}, @{$EXPORT_TAGS{"running_as_flags"}};
+
+push @EXPORT_OK, qw(pcontext_t_to_string);
+push @{$EXPORT_TAGS{"pcontext_t"}}, qw(pcontext_t_to_string);
+
+my %_pcontext_t_VALUES;
+#Convert an enum value to a single string
+sub pcontext_t_to_string {
+ my ($enumval) = @_;
+
+ for my $k (keys %_pcontext_t_VALUES) {
+ my $v = $_pcontext_t_VALUES{$k};
+
+ #is this a matching flag?
+ if ($enumval == $v) {
+ return $k;
+ }
+ }
+
+#default, just return the number
+ return $enumval;
+}
+
+push @EXPORT_OK, qw($CONTEXT_DEFAULT);
+push @{$EXPORT_TAGS{"pcontext_t"}}, qw($CONTEXT_DEFAULT);
+
+$_pcontext_t_VALUES{"CONTEXT_DEFAULT"} = $CONTEXT_DEFAULT;
+
+push @EXPORT_OK, qw($CONTEXT_CMDLINE);
+push @{$EXPORT_TAGS{"pcontext_t"}}, qw($CONTEXT_CMDLINE);
+
+$_pcontext_t_VALUES{"CONTEXT_CMDLINE"} = $CONTEXT_CMDLINE;
+
+push @EXPORT_OK, qw($CONTEXT_DAEMON);
+push @{$EXPORT_TAGS{"pcontext_t"}}, qw($CONTEXT_DAEMON);
+
+$_pcontext_t_VALUES{"CONTEXT_DAEMON"} = $CONTEXT_DAEMON;
+
+push @EXPORT_OK, qw($CONTEXT_SCRIPTUTIL);
+push @{$EXPORT_TAGS{"pcontext_t"}}, qw($CONTEXT_SCRIPTUTIL);
+
+$_pcontext_t_VALUES{"CONTEXT_SCRIPTUTIL"} = $CONTEXT_SCRIPTUTIL;
+
+#copy symbols in pcontext_t to constants
+push @{$EXPORT_TAGS{"constants"}}, @{$EXPORT_TAGS{"pcontext_t"}};
+
+=item C<quote_string($str)>
+
+Quote a string using Amanda's quoting algorithm. Strings with no whitespace,
+control, or quote characters are returned unchanged. An empty string is
+represented as the two-character string C<"">. Otherwise, tab, newline,
+carriage return, form-feed, backslash, and double-quote (C<">) characters are
+escaped with a backslash and the string is surrounded by double quotes.
+
+=item C<unquote_string($str)>
+
+Unquote a string as quoted with C<quote_string>.
+
+=item C<skip_quoted_string($str)>
+
+my($q, $remaider) = skip_quoted_string($str)
+
+Return the first quoted string and the remainder of the string.
+
+Both C<quote_string>, C<unquote_string> and C<skip_quoted_string> are
+available under the export tag C<:quoting>.
+
+=cut
+
+sub skip_quoted_string {
+ my $str = shift;
+
+ chomp $str;
+ my $iq = 0;
+ my $i = 0;
+ my $c = substr $str, $i, 1;
+ while ($c ne "" && !($iq == 0 && $c =~ /\s/)) {
+ if ($c eq '"') {
+ $iq = !$iq;
+ } elsif ($c eq '\\') {
+ $i++;
+ }
+ $i++;
+ $c = substr $str, $i, 1;
+ }
+ my $quoted_string = substr $str, 0, $i;
+ my $remainder = substr $str, $i+1;
+
+ return ($quoted_string, $remainder);
+}
+
+
+push @EXPORT_OK, qw(quote_string unquote_string skip_quoted_string sanitise_filename);
+push @{$EXPORT_TAGS{"quoting"}}, qw(quote_string unquote_string skip_quoted_string sanitise_filename);
+
+=item C<generate_timestamp()>
+
+Generate a timestamp from the current time, obeying the 'USETIMESTAMPS'
+config parameter. The Amanda configuration must already be loaded.
+
+=cut
+
+sub generate_timestamp {
+ # this corresponds to common-src/timestamp.c's get_proper_stamp_from_time
+ if (getconf($CNF_USETIMESTAMPS)) {
+ return strftime "%Y%m%d%H%M%S", localtime;
+ } else {
+ return strftime "%Y%m%d", localtime;
+ }
+}
+