Re: message formatting and i18n
Oswald Buddenhagen wrote: On Sun, Feb 06, 2005 at 04:18:51PM +0100, Roland Illig wrote: + g_string_sprintf (errmsg, _(" Cannot open pip for reading: %s "), p); somehow "pip" looks wrong to me. :) - catstrs (_(" Not an ordinary file: "), filename, + _(" %s is not an ordinary file "), filename); i'm wondering why on earth "ordinary" was used, when the proper terminology is "regular" and in no way less (i mean, even less :)) obvious to the uninitiated. Fixed the spelling errors and committed the rest. Roland ___ Mc-devel mailing list http://mail.gnome.org/mailman/listinfo/mc-devel
separating interface and implementation
Hi all, I would like to have some clean interfaces in the Midnight Commander. To realize this, I would like to split some headers (dialog.h, widget.h) into an interface part, which exports only the type names (WButton), but not the implementation (struct WButton). It would look like: widget.h: typedef struct WButton WButton; widget-impl.h: struct WButton { ... }; Then we can encourage ourselves not to use the *-impl.h headers where it is not necessary. And when only a few files do use the implementation, we can change it more easily, if that ever becomes necessary. Roland ___ Mc-devel mailing list http://mail.gnome.org/mailman/listinfo/mc-devel
Re: message formatting and i18n
On Sun, Feb 06, 2005 at 04:18:51PM +0100, Roland Illig wrote: > + g_string_sprintf (errmsg, _(" Cannot open pip for reading: %s "), > p); > somehow "pip" looks wrong to me. :) > -catstrs (_(" Not an ordinary file: "), filename, > + _(" %s is not an ordinary file "), filename); > i'm wondering why on earth "ordinary" was used, when the proper terminology is "regular" and in no way less (i mean, even less :)) obvious to the uninitiated. -- Hi! I'm a .signature virus! Copy me into your ~/.signature, please! -- Chaos, panic, and disorder - my work here is done. ___ Mc-devel mailing list http://mail.gnome.org/mailman/listinfo/mc-devel
message formatting and i18n
Hi all, some messages in the Midnight Commander don't translate well to other languages because the string is concatenated manually, like in src/ext.c, line 486. I started to fix some of these in mcedit. How do you feel about the new code? Well, one thing is not too nice about it: The assignment of errmsg = ... while passing it as a function argument. But I don't want to allocate memory that I don't need. Roland ? mc.qpg ? rillig ? edit/editcommands.c ? maint/template.c Index: configure.ac === RCS file: /cvsroot/mc/mc/configure.ac,v retrieving revision 1.20 diff -u -p -u -r1.20 configure.ac --- configure.ac30 Jan 2005 05:06:13 - 1.20 +++ configure.ac6 Feb 2005 15:11:18 - @@ -565,6 +565,12 @@ if test x"$USE_MAINTAINER_MODE" = x"yes" fi fi +AC_ARG_ENABLE([fast-moves], + [ --disable-fast-moves Disable fast cursor movement in the internal editor]) +if test x"$enable_fast_moves" != x"no"; then + AC_DEFINE([FAST_MOVE_CURSOR], [1], [Define to enable fast cursor movement in mcedit]) +fi + ri_GCC_WARNINGS AC_SUBST(CFLAGS) Index: edit/edit.c === RCS file: /cvsroot/mc/mc/edit/edit.c,v retrieving revision 1.93 diff -u -p -u -r1.93 edit.c --- edit/edit.c 30 Jan 2005 20:34:58 - 1.93 +++ edit/edit.c 6 Feb 2005 15:11:18 - @@ -138,11 +138,10 @@ edit_load_file_fast (WEdit *edit, const if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) { /* The file-name is printed after the ':' */ - edit_error_dialog (_("Error"), - get_sys_error (catstrs - (_ - (" Cannot open file for reading: "), - filename, " ", (char *) NULL))); + GString *errmsg = g_string_new(NULL); + g_string_sprintf(errmsg, _(" Cannot open %s for reading "), filename); + edit_error_dialog (_("Error"), get_sys_error (errmsg->str)); + g_string_free (errmsg, TRUE); return 1; } @@ -268,19 +267,18 @@ edit_insert_file (WEdit *edit, const cha edit_insert_stream (edit, f); edit_cursor_move (edit, current - edit->curs1); if (pclose (f) > 0) { - edit_error_dialog (_("Error"), - catstrs (_ - (" Error reading from pipe: "), - p, " ", (char *) NULL)); + GString *errmsg = g_string_new (NULL); + g_string_sprintf (errmsg, _(" Error reading from pipe: %s "), p); + edit_error_dialog (_("Error"), errmsg->str); + g_string_free (errmsg, TRUE); g_free (p); return 0; } } else { - edit_error_dialog (_("Error"), - get_sys_error (catstrs - (_ - (" Cannot open pipe for reading: "), - p, " ", (char *) NULL))); + GString *errmsg = g_string_new (NULL); + g_string_sprintf (errmsg, _(" Cannot open pip for reading: %s "), p); + edit_error_dialog (_("Error"), errmsg->str); + g_string_free (errmsg, TRUE); g_free (p); return 0; } @@ -310,6 +308,7 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st) { int file; +GString *errmsg = (GString *) 0; /* Try opening an existing file */ file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY, 0666); @@ -324,12 +323,9 @@ check_file_access (WEdit *edit, const ch O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 0666); if (file < 0) { - edit_error_dialog (_("Error"), - get_sys_error (catstrs - (_ - (" Cannot open file for reading: "), - filename, " ", (char *) NULL))); - return 1; + g_string_sprintf (errmsg = g_string_new (NULL), + _(" Cannot open %s for reading "), filename); + goto cleanup; } else { /* New file, delete it if it's not modified or saved */ edit->delete_file = 1; @@ -338,22 +334,16 @@ check_file_access (WEdit *edit, const ch /* Check what we have opened */ if (mc_fstat (file, st) < 0) { - mc_close (file); - edit_error_dialog (_("Error"), - get_sys_error (catstrs - (_ - (" Cannot get size/permissions info for file: "), -
Missing quoting in extfs in pre3
Hi, Attached quote fixing hunks are missing from pre3. The urar hunks should definitely be committed. Not sure if we need the fixes to uzip in pre. Leonard. -- mount -t life -o ro /dev/dna /genetic/research diff -pruN tmp1/urar.in tmp2/urar.in --- tmp1/urar.in 2004-08-23 15:44:20.0 +0200 +++ tmp2/urar.in 2005-02-06 13:02:49.0 +0100 @@ -16,8 +16,8 @@ save_IFS="$IFS"; IFS=: for dir in $PATH; do IFS="$save_IFS" test -z "$dir" && dir=. -if test -x $dir/unrar -a -f $dir/unrar; then - UNRAR=$dir/unrar +if test -x "$dir/unrar" -a -f "$dir/unrar"; then + UNRAR="$dir/unrar" break fi done @@ -58,12 +58,12 @@ mcrarfs_copyin () cd "$3.dir" di="${2%/*}" # if file is to be written upper in the archive tree, make fake dir -if test "$di" != "${2##*/}" ; then -mkdir -p "$di" +if test x"$di" != x"${2##*/}" ; then +mkdir -p "$di" fi cp -fp "$3" "$3.dir/$2" $RAR a "$1" "$2" >/dev/null -cd $pwd +cd "$pwd" rm -rf "$3.dir" } @@ -77,15 +77,15 @@ mcrarfs_mkdir () # preserve pwd. It is clean, but is it necessary? pwd=`pwd` # Create a directory and create in it a tmp directory with the good name -dir=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-urar.XX` || exit 1 -cd $dir +dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-urar.XX"` || exit 1 +cd "$dir" mkdir -p "$2" # rar cannot create an empty directory touch "$2"/.rarfs $RAR a -r "$1" "$2" >/dev/null $RAR d "$1" "$2/.rarfs" >/dev/null -cd $pwd -rm -rf $dir +cd "$pwd" +rm -rf "$dir" } mcrarfs_rm () diff -pruN tmp1/uzip.in tmp2/uzip.in --- tmp1/uzip.in 2004-09-03 14:40:11.0 +0200 +++ tmp2/uzip.in 2005-02-06 13:02:49.0 +0100 @@ -34,6 +34,14 @@ my $cmd_delete = "$app_zip -d"; # Command used to extract a file to standard out my $cmd_extract = "$app_unzip -p"; +# -rw-r--r-- 2.2 unx 2891 tx 1435 defN 2330.211927 ./edit.html +# (perm) (?) (?) (size) (?) (zippedsize) (method) ()(mm)(dd)(HH)(MM) (fname) +my $regex_zipinfo_line = qr"^(\S{10})\s+(\d+\.\d+)\s+(\S+)\s+(\d+)\s+(\S\S)\s+(\d+)\s+(\S{4})\s+(\d{4})(\d\d)(\d\d)\.(\d\d)(\d\d)(\d\d)\s(.*)$"; + +# 2891 Defl:N 1435 50% 03-30-00 21:19 50cbaaf8 ./edit.html +# (size) (method) (zippedsize) (zipratio) (mm)(dd)(yy)(HH)(MM) (cksum) (fname) +my $regex_nonzipinfo_line = qr"^\s*(\d+)\s+(\S+)\s+(\d+)\s+(-?\d+\%)\s+(\d?\d)-(\d?\d)-(\d\d)\s+(\d?\d):(\d\d)\s+([0-9a-f]+)\s\s(.*)$"; + # # Main code # @@ -50,6 +58,50 @@ my $aarchive = absolutize($archive, $old my $cmd_list = ($op_has_zipinfo ? $cmd_list_zi : $cmd_list_nzi); my ($qarchive, $aqarchive) = map (quotemeta, $archive, $aarchive); +# Strip all "." and ".." path components from a pathname. +sub zipfs_canonicalize_pathname($) { + my ($fname) = @_; + $fname =~ s,/+,/,g; + $fname =~ s,(^|/)(?:\.?\./)+,$1,; + return $fname; +} + +# The Midnight Commander never calls this script with archive pathnames +# starting with either "./" or "../". Some ZIP files contain such names, +# so we need to build a translation table for them. +my $zipfs_realpathname_table = undef; +sub zipfs_realpathname($) { +my ($fname) = @_; + +if (!defined($zipfs_realpathname_table)) { +$zipfs_realpathname_table = {}; + if (!open(ZIP, "$cmd_list $qarchive |")) { + return $fname; + } + foreach my $line () { + $line =~ s/\r*\n*$//; + if ($op_has_zipinfo) { + if ($line =~ $regex_zipinfo_line) { + my ($fname) = ($14); + $zipfs_realpathname_table->{zipfs_canonicalize_pathname($fname)} = $fname; + } + } else { + if ($line =~ $regex_nonzipinfo_line) { + my ($fname) = ($11); + $zipfs_realpathname_table->{zipfs_canonicalize_pathname($fname)} = $fname; + } + } + } + if (!close(ZIP)) { + return $fname; + } +} +if (exists($zipfs_realpathname_table->{$fname})) { + return $zipfs_realpathname_table->{$fname}; +} +return $fname; +} + if ($cmd eq 'list'){ &mczipfs_list(@ARGV); } if ($cmd eq 'rm') { &mczipfs_rm(@ARGV); } if ($cmd eq 'rmdir') { &mczipfs_rmdir(@ARGV); } @@ -63,7 +115,12 @@ exit 1; # Remove a file from the archive. sub mczipfs_rm { - my ($qfile) = map { &zipquotemeta($_) } @_; + my ($qfile) = map { &zipquotemeta(zipfs_realpathname($_)) } @_; + + # "./" at the beginning of pathnames is stripped by Info-ZIP, + # so convert it to "[.]/" to prevent stripping. + $qfile =~ s/^\\\./[.]/; + &checkargs(1, 'archive file', @_); &safesystem("$cmd_delete $qarchive $qfile >/dev/null"); exit; @@ -74,7 +131,7 @@ sub mczipfs_rm { # additional slash to the directory name to remove. I am not # sure this is absolutely necessary, but it doesn't hurt. sub mczipfs_rmdir { - my ($qfile) = map { &zipquotemeta($_) } @_; + my ($qfile) = map { &zipquotemeta(zipfs_realpathname($_)) } @_; &checkargs(1, 'archive directory', @_); &safesystem("$cmd_delete $qarchive $qfile/ >/dev/null", 12); exit; @@ -84,