From 59106c868accfb88d7b545ba88f9b2c8b0e07080 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 29 Mar 2015 00:25:29 +0100 Subject: Don't make myprintf auto append a newline. --- cli/icevault | 62 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'cli') diff --git a/cli/icevault b/cli/icevault index 3c31f1d..5ad8ff2 100755 --- a/cli/icevault +++ b/cli/icevault @@ -47,24 +47,23 @@ my $SOCKET; sub myprintf($@) { my $fh = ref $_[0] eq 'GLOB' ? shift : \*STDOUT; my $format = shift; - chomp $format; $LANGINFO =~ /^utf-?8$/aai ? $format =~ s/C<%s>/\N{U+2018}%s\N{U+2019}/g : $format =~ s/C<%s>/'%s'/g; $format =~ s/I<%s>/%s/g; $format =~ s/B<%s>/%s/g; die "Illegal markup '$1' in message:\n", $format if $format =~ /([A-Z])<%s>/; - printf $fh map {$LOCALE->encode($_)} ($format."\n", @_); + printf $fh map {$LOCALE->encode($_)} ($format, @_); } # error FORMAT, LIST sub error($@) { - myprintf \*STDERR, shift, @_; + myprintf \*STDERR, shift."\n", @_; exit 1; } # warning FORMAT, LIST sub warning($@) { - myprintf \*STDERR, shift, @_; + myprintf \*STDERR, shift."\n", @_; } sub mysystem(@) { @@ -203,7 +202,7 @@ sub connect($) { error "No Firefox profile found under C<%s>", $ffdir unless defined $profile; $sockname = "$$ffdir/$profile/$sockname"; } - myprintf \*STDERR, "Using socket C<%s>", $sockname if $CONFIG{debug}; + myprintf \*STDERR, "Using socket C<%s>\n", $sockname if $CONFIG{debug}; $sockname =~ /\A(\/\p{Print}+)\z/ or error "Insecure C<%s>", $sockname; # untaint $sockname $sockname = $1; @@ -231,7 +230,7 @@ sub connect($) { sub getResponse() { my $buf = $SOCKET->getline; chomp $buf; - myprintf \*STDERR, "S: %s", decode_utf8 $buf if $CONFIG{debug}; + myprintf \*STDERR, "S: %s\n", decode_utf8 $buf if $CONFIG{debug}; my ($code, $msg) = split / /, $buf, 2; # allow $msg to be decoded to a string $msg = JSON->new->utf8->allow_nonref->decode($msg) if defined $msg; @@ -255,7 +254,7 @@ sub getResponse() { # socket, flush the handle, then return the server response. sub sendCommand(@) { my $command = join(' ',@_); - myprintf \*STDERR, "C: %s", Encode::decode_utf8 $command if $CONFIG{debug}; + myprintf \*STDERR, "C: %s\n", Encode::decode_utf8 $command if $CONFIG{debug}; $command .= "\n"; for (my $offset = 0; $offset < length $command;) { $offset += $SOCKET->syswrite($command, length($command) - $offset, $offset); @@ -281,7 +280,7 @@ sub myglob(;$$$) { die "Invalid placeholder %$1" }ge; my $glob = "$store/$template"; - myprintf \*STDERR, "Using glob pattern C<%s>", $glob if $CONFIG{debug}; + myprintf \*STDERR, "Using glob pattern C<%s>\n", $glob if $CONFIG{debug}; return File::Glob::bsd_glob($glob); } @@ -351,7 +350,7 @@ sub complete($;$) { $2 eq 'i' ? quotemeta($1).$pi : die "Invalid placeholder %$1"}ge; my $pattern = qr/\A\Q$store\/\E$template\z/; - myprintf \*STDERR, "Using regexp C<%s>", "$pattern" if $CONFIG{debug}; + myprintf \*STDERR, "Using regexp C<%s>\n", "$pattern" if $CONFIG{debug}; my @matches; foreach my $filename (myglob($gs, $gh, $gi)) { @@ -392,7 +391,7 @@ sub fill($$@) { return if none {defined} @fill; # noop for (my $i = 0; $i <= $#fill; $i++) { - myprintf "Filling field C<%s>, value C<%s>", + myprintf "Filling field C<%s>, value C<%s>\n", $form->{fields}->[$i]->{name}, safeValue($form->{fields}->[$i], $fill[$i]) if defined $fill[$i]; @@ -431,7 +430,7 @@ sub file2Identity($) { $2 eq 'i' ? quotemeta($1).'(?[^\P{Print}\/]+)' : die "Invalid placeholder %$1"}ge; my $pattern = qr/\A\Q$store\/\E$template\z/; - myprintf \*STDERR, "Using regexp C<%s>", "$pattern" if $CONFIG{debug}; + myprintf \*STDERR, "Using regexp C<%s>\n", "$pattern" if $CONFIG{debug}; $filename =~ $pattern or die; return "$+{s}://$+{h}/$+{i}"; } @@ -443,7 +442,7 @@ sub file2Identity($) { open my $NULL, '<', '/dev/null'; sub loadIdentityFile($;$) { my ($filename, $fh) = @_; - myprintf \*STDERR, "Decrypting identity file C<%s>", $filename if $CONFIG{debug}; + myprintf \*STDERR, "Decrypting identity file C<%s>\n", $filename if $CONFIG{debug}; require 'IPC/Open2.pm'; my $pid = IPC::Open2::open2( (defined wantarray ? $fh : ">&".$fh->fileno) @@ -469,7 +468,7 @@ sub loadIdentityFile($;$) { # to gpg(1), and closed afterwards. sub saveIdentityFile($$) { my ($form, $filename) = @_; - myprintf \*STDERR, "Saving identity file C<%s>", $filename if $CONFIG{debug}; + myprintf \*STDERR, "Saving identity file C<%s>\n", $filename if $CONFIG{debug}; require 'File/Copy.pm'; require 'File/Path.pm'; @@ -589,7 +588,7 @@ sub pwgen(@) { (defined $x and $x > 0 and $x < $l) ? $x : $l } @fields); $pwgen =~ s/%d/$l/g; myprintf "Generating $l-char long random value for field".($#fields > 0 ? '(s) ' : ' ') - .join(',', map {'C<%s>'} @fields), + .join(',', map {'C<%s>'} @fields)."\n", map {$_->{name}} @fields; my @pw = `$pwgen`; @@ -611,12 +610,13 @@ sub prompt($;$) { } # Prompt a Yes/No question. -sub promptYN($;$) { +sub promptYN($;$@) { my $prompt = shift; my $default = shift // 0; + my @args = @_; while (1) { - print $LOCALE->encode($prompt), " [", ($default ? 'Y/n' : 'y/N'), "] "; + myprintf "$prompt [".($default ? 'Y/n' : 'y/N')."] ", @args; my $r = ; die "\n" unless defined $r; chomp $r; @@ -627,7 +627,7 @@ sub promptYN($;$) { elsif (lc $r eq 'n' or lc $r eq 'no' or ($r eq '' and !$default)) { return 0 } - myprintf \*STDERR, "Answer: C<%s> or C<%s>", 'y', 'n'; + myprintf \*STDERR, "Answer: C<%s> or C<%s>\n", 'y', 'n'; } } @@ -730,7 +730,7 @@ if ($ARGV[0] eq '--help' or $ARGV[0] eq '-?') { my $usage = shift @USAGE; print " or: $NAME $cmd $usage\n"; } - myprintf "Try C<%s> or consult the manpage for more information.", "$NAME COMMAND --help"; + myprintf "Try C<%s> or consult the manpage for more information.\n", "$NAME COMMAND --help"; exit 0; } @@ -753,7 +753,7 @@ sub usage(@) { printf "Consult the manpage for more information.\n"; exit 0; } else { - myprintf "Try C<%s> or consult the manpage for more information.", "$NAME $COMMAND --help"; + myprintf "Try C<%s> or consult the manpage for more information.\n", "$NAME $COMMAND --help"; exit 1; } } @@ -795,7 +795,7 @@ elsif ($COMMAND eq 'insert') { usage() unless $#ARGV < 1; my $uri = &connect($CONFIG{socket}); - myprintf "Importing HTML form from URI C<%s>", $uri; + myprintf "Importing HTML form from URI C<%s>\n", $uri; my @forms = getForms(); my $formIdx = findForm undef, @forms; @@ -829,10 +829,10 @@ elsif ($COMMAND eq 'insert') { # ask for confirmation my $r = prompt 'Identity name?', $id; if ($r !~ /\A[^\P{Print}\/]+\z/) { - myprintf \*STDERR, "Invalid identity: C<%s>", $r; + myprintf \*STDERR, "Invalid identity: C<%s>\n", $r; } elsif (-e identity2File "$uri/$r" and !$CONFIG{force}) { - myprintf \*STDERR, "Identity C<%s> already exists", "$uri/$r"; + myprintf \*STDERR, "Identity C<%s> already exists\n", "$uri/$r"; } else { $id = $r; @@ -892,7 +892,7 @@ elsif ($COMMAND eq 'insert') { sendCommand 'QUIT'; undef @{$form->{fields}}[@dontsave] if @dontsave; # remove the field we don't want to save - myprintf "Saving identity C<%s>", "$uri/$id"; + myprintf "Saving identity C<%s>\n", "$uri/$id"; saveIdentityFile $form, $filename; commit "Add new identity $uri/$id", $filename; } @@ -941,7 +941,7 @@ elsif ($COMMAND eq 'fill') { delete $fields{$pass->{name}}; if ($mypass->{name} ne $pass->{name}) { # use the new name - myprintf "Renaming field C<%s> as C<%s>", + myprintf "Renaming field C<%s> as C<%s>\n", $mypass->{name}, $pass->{name}; $mypass->{name} = $pass->{name}; $changed = 1; @@ -951,7 +951,7 @@ elsif ($COMMAND eq 'fill') { $fill[$passIdx[0]] = $mypass->{value}; } elsif ($mypass->{value} ne $pass->{value}) { # update the password - myprintf "Updating field C<%s> to C<%s> (former value: C<%s>)", + myprintf "Updating field C<%s> to C<%s> (former value: C<%s>)\n", $mypass->{name}, safeValue($pass), safeValue($mypass); $mypass->{value} = $pass->{value}; $changed = 1; @@ -1003,7 +1003,7 @@ elsif ($COMMAND eq 'fill') { } elsif ($myform->{fields}->[$myidx]->{value} ne $form->{fields}->[$idx]->{value}) { # update the known value with that found in the page - myprintf "Updating field C<%s> to C<%s> (former value: C<%s>)", + myprintf "Updating field C<%s> to C<%s> (former value: C<%s>)\n", $myform->{fields}->[$myidx]->{name}, safeValue($form->{fields}->[$idx]), safeValue($myform->{fields}->[$myidx]); @@ -1024,7 +1024,7 @@ elsif ($COMMAND eq 'fill') { @fieldIdx = @fieldIdx[(0 .. $i)] if $i >= 0; next unless @fieldIdx and $i >= 0; myprintf "Adding field C<%s>, value".($#fieldIdx > 0 ? '(s) ' : ' '). - join(',', map {'C<%s>'} @fieldIdx), + join(',', map {'C<%s>'} @fieldIdx)."\n", $name, map {safeValue $form->{fields}->[$_]} @fieldIdx; push @{$myform->{fields}}, @{$form->{fields}}[@fieldIdx]; $changed = 1; @@ -1033,7 +1033,7 @@ elsif ($COMMAND eq 'fill') { my @fieldIdx = grep defined, @{$myfields{$name}}; next unless @fieldIdx; myprintf "Deleting field C<%s>, value".($#fieldIdx > 0 ? '(s) ' : ' '). - join(',', map {'C<%s>'} @fieldIdx), + join(',', map {'C<%s>'} @fieldIdx)."\n", $name, map {safeValue $myform->{fields}->[$_]} @fieldIdx; undef $myform->{fields}->[$_] foreach @fieldIdx; $changed = 1; @@ -1105,7 +1105,7 @@ elsif ($COMMAND eq 'edit') { if ($h eq $h2) { print "No modification made\n"; } elsif (defined $fh2) { - myprintf "Saving user changes for identity C<%s>", $id; + myprintf "Saving user changes for identity C<%s>\n", $id; saveIdentityFile($fh2, $filename); # use the FH we opened before unlinking commit "Save manual (using $EDITOR) changes for $id", $filename; } else { @@ -1154,7 +1154,7 @@ elsif ($COMMAND eq 'git') { unless (-d $CONFIG{store}) { require 'File/Path.pm'; File::Path::make_path($CONFIG{store}); - myprintf "Created directory C<%s>", $CONFIG{store}; + myprintf "Created directory C<%s>\n", $CONFIG{store}; } for (my $i = 0; $i <= $#ARGV; $i++) { @@ -1174,7 +1174,7 @@ elsif ($COMMAND eq 'reencrypt') { foreach my $filename (@matches) { $filename = $LOCALE->decode($filename); my $id = file2Identity($filename); - myprintf "Reencrypting C<%s>", $id; + myprintf "Reencrypting C<%s>\n", $id; $filename =~ /\A(\/\p{Print}+)\z/ or error "Insecure C<%s>", $filename; $filename = $1; # untaint $filename -- cgit v1.2.3