+amglue_copy_to_tag(running_as_flags, constants);
+
+amglue_add_enum_tag_fns(pcontext_t);
+amglue_add_constant(CONTEXT_DEFAULT, pcontext_t);
+amglue_add_constant(CONTEXT_CMDLINE, pcontext_t);
+amglue_add_constant(CONTEXT_DAEMON, pcontext_t);
+amglue_add_constant(CONTEXT_SCRIPTUTIL, pcontext_t);
+amglue_copy_to_tag(pcontext_t, constants);
+
+%perlcode %{
+=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);
+}
+
+%}
+
+char *sanitise_filename(char *inp);
+char *quote_string(char *);
+char *unquote_string(char *);
+amglue_export_tag(quoting, quote_string unquote_string skip_quoted_string sanitise_filename);
+
+%perlcode %{
+=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;
+ }
+}
+%}