diff --git a/lib/tty/color-internal.h b/lib/tty/color-internal.h index a7fc6d210..fbfe90b00 100644 --- a/lib/tty/color-internal.h +++ b/lib/tty/color-internal.h @@ -19,7 +19,8 @@ extern gboolean use_colors; extern gboolean mc_tty_color_disable; -typedef struct mc_color_pair_struct { +typedef struct mc_color_pair_struct +{ const char *cfg; const char *cbg; int ifg; @@ -28,12 +29,14 @@ typedef struct mc_color_pair_struct { gboolean is_temp; } tty_color_pair_t; +/* *INDENT-OFF* */ typedef enum { SPEC_A_REVERSE = -100, SPEC_A_BOLD = -101, SPEC_A_BOLD_REVERSE = -102, SPEC_A_UNDERLINE = -103 } tty_special_color_t; +/* *INDENT-ON* */ const char *tty_color_get_valid_name (const char *); int tty_color_get_index_by_name (const char *); diff --git a/lib/tty/color.c b/lib/tty/color.c index 1f2f9f88c..8a7fc407b 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -1,13 +1,13 @@ /* Color setup. - Interface functions. + Interface functions. Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. - + Written by: Andrew Borodin , 2009. Slava Zanko , 2009. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -96,7 +96,7 @@ static void tty_color_free_all (gboolean is_temp_color) { g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_condition_cb, - (is_temp_color)? (gpointer) 1 : NULL); + (is_temp_color) ? (gpointer) 1 : NULL); } /* --------------------------------------------------------------------------------------------- */ @@ -125,7 +125,8 @@ tty_color_get_next__color_pair_number () size_t cp_count = g_hash_table_size (mc_tty_color__hashtable); size_t cp = 0; - for (cp = 0; cp < cp_count; cp++) { + for (cp = 0; cp < cp_count; cp++) + { if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb, (gpointer) cp) == NULL) return cp; @@ -178,7 +179,8 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo if (fg == NULL) fg = tty_color_defaults__fg; - if (bg == NULL) { + if (bg == NULL) + { bg = tty_color_defaults__bg; } c_fg = tty_color_get_valid_name (fg); @@ -191,13 +193,15 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo mc_color_pair = (tty_color_pair_t *) g_hash_table_lookup (mc_tty_color__hashtable, (gpointer) color_pair); - if (mc_color_pair != NULL) { + if (mc_color_pair != NULL) + { g_free (color_pair); return mc_color_pair->pair_index; } mc_color_pair = g_try_new0 (tty_color_pair_t, 1); - if (mc_color_pair == NULL) { + if (mc_color_pair == NULL) + { g_free (color_pair); return 0; } diff --git a/lib/util.c b/lib/util.c index 73fe599ec..26d1e6885 100644 --- a/lib/util.c +++ b/lib/util.c @@ -12,7 +12,7 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -41,7 +41,7 @@ #include #include "lib/global.h" -#include "lib/tty/win.h" /* xterm_flag */ +#include "lib/tty/win.h" /* xterm_flag */ #include "lib/search.h" #include "lib/mcconfig.h" #include "lib/timefmt.h" @@ -50,9 +50,9 @@ #include "lib/strutil.h" #include "src/filegui.h" -#include "src/file.h" /* copy_file_file() */ +#include "src/file.h" /* copy_file_file() */ #ifndef HAVE_CHARSET -#include "src/main.h" /* eight_bit_clean */ +#include "src/main.h" /* eight_bit_clean */ #endif int easy_patterns = 1; @@ -64,12 +64,14 @@ int easy_patterns = 1; */ int kilobyte_si = 0; -char *user_recent_timeformat = NULL; /* time format string for recent dates */ -char *user_old_timeformat = NULL; /* time format string for older dates */ +char *user_recent_timeformat = NULL; /* time format string for recent dates */ +char *user_old_timeformat = NULL; /* time format string for older dates */ -extern void str_replace(char *s, char from, char to) +extern void +str_replace (char *s, char from, char to) { - for (; *s != '\0'; s++) { + for (; *s != '\0'; s++) + { if (*s == from) *s = to; } @@ -92,7 +94,7 @@ is_8bit_printable (unsigned char c) { /* "Full 8 bits output" doesn't work on xterm */ if (xterm_flag) - return is_iso_printable (c); + return is_iso_printable (c); return (c > 31 && c != 127 && c != 155); } @@ -108,32 +110,38 @@ is_printable (int c) return is_8bit_printable (c); #else if (!eight_bit_clean) - return is_7bit_printable (c); + return is_7bit_printable (c); - if (full_eight_bits) { - return is_8bit_printable (c); - } else - return is_iso_printable (c); -#endif /* !HAVE_CHARSET */ + if (full_eight_bits) + { + return is_8bit_printable (c); + } + else + return is_iso_printable (c); +#endif /* !HAVE_CHARSET */ } /* Calculates the message dimensions (lines and columns) */ void msglen (const char *text, int *lines, int *columns) { - int nlines = 1; /* even the empty string takes one line */ + int nlines = 1; /* even the empty string takes one line */ int ncolumns = 0; int colindex = 0; - for (; *text != '\0'; text++) { - if (*text == '\n') { - nlines++; - colindex = 0; - } else { - colindex++; - if (colindex > ncolumns) - ncolumns = colindex; - } + for (; *text != '\0'; text++) + { + if (*text == '\n') + { + nlines++; + colindex = 0; + } + else + { + colindex++; + if (colindex > ncolumns) + ncolumns = colindex; + } } *lines = nlines; @@ -154,21 +162,26 @@ trim (const char *s, char *d, int len) len = max (len, 0); source_len = strlen (s); - if (source_len > len) { - /* Cannot fit the whole line */ - if (len <= 3) { - /* We only have room for the dots */ - memset (d, '.', len); - d[len] = 0; - return d; - } else { - /* Begin with ... and add the rest of the source string */ - memset (d, '.', 3); - strcpy (d + 3, s + 3 + source_len - len); - } - } else - /* We can copy the whole line */ - strcpy (d, s); + if (source_len > len) + { + /* Cannot fit the whole line */ + if (len <= 3) + { + /* We only have room for the dots */ + memset (d, '.', len); + d[len] = 0; + return d; + } + else + { + /* Begin with ... and add the rest of the source string */ + memset (d, '.', 3); + strcpy (d + 3, s + 3 + source_len - len); + } + } + else + /* We can copy the whole line */ + strcpy (d, s); return d; } @@ -183,49 +196,52 @@ name_quote (const char *s, int quote_percent) char *ret, *d; d = ret = g_malloc (strlen (s) * 2 + 2 + 1); - if (*s == '-') { - *d++ = '.'; - *d++ = '/'; + if (*s == '-') + { + *d++ = '.'; + *d++ = '/'; } - for (; *s; s++, d++) { - switch (*s) { - case '%': - if (quote_percent) - *d++ = '%'; - break; - case '\'': - case '\\': - case '\r': - case '\n': - case '\t': - case '"': - case ';': - case ' ': - case '?': - case '|': - case '[': - case ']': - case '{': - case '}': - case '<': - case '>': - case '`': - case '!': - case '$': - case '&': - case '*': - case '(': - case ')': - *d++ = '\\'; - break; - case '~': - case '#': - if (d == ret) - *d++ = '\\'; - break; - } - *d = *s; + for (; *s; s++, d++) + { + switch (*s) + { + case '%': + if (quote_percent) + *d++ = '%'; + break; + case '\'': + case '\\': + case '\r': + case '\n': + case '\t': + case '"': + case ';': + case ' ': + case '?': + case '|': + case '[': + case ']': + case '{': + case '}': + case '<': + case '>': + case '`': + case '!': + case '$': + case '&': + case '*': + case '(': + case ')': + *d++ = '\\'; + break; + case '~': + case '#': + if (d == ret) + *d++ = '\\'; + break; + } + *d = *s; } *d = '\0'; return ret; @@ -255,7 +271,8 @@ name_trunc (const char *txt, size_t trunc_len) * reasons. */ const char * -path_trunc (const char *path, size_t trunc_len) { +path_trunc (const char *path, size_t trunc_len) +{ char *secure_path = strip_password (g_strdup (path), 1); const char *ret = str_trunc (secure_path, trunc_len); @@ -267,27 +284,29 @@ path_trunc (const char *path, size_t trunc_len) { const char * size_trunc (double size) { - static char x [BUF_TINY]; + static char x[BUF_TINY]; long int divisor = 1; const char *xtra = ""; - - if (size > 999999999L){ - divisor = kilobyte_si?1000:1024; - xtra = kilobyte_si?"k":"K"; - if (size/divisor > 999999999L){ - divisor = kilobyte_si?(1000*1000):(1024*1024); - xtra = kilobyte_si?"m":"M"; - } + + if (size > 999999999L) + { + divisor = kilobyte_si ? 1000 : 1024; + xtra = kilobyte_si ? "k" : "K"; + if (size / divisor > 999999999L) + { + divisor = kilobyte_si ? (1000 * 1000) : (1024 * 1024); + xtra = kilobyte_si ? "m" : "M"; + } } - g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); + g_snprintf (x, sizeof (x), "%.0f%s", (size / divisor), xtra); return x; } const char * size_trunc_sep (double size) { - static char x [60]; - int count; + static char x[60]; + int count; const char *p, *y; char *d; @@ -296,17 +315,19 @@ size_trunc_sep (double size) d = x + sizeof (x) - 1; *d-- = 0; while (p >= y && isalpha ((unsigned char) *p)) - *d-- = *p--; - for (count = 0; p >= y; count++){ - if (count == 3){ - *d-- = ','; - count = 0; - } - *d-- = *p--; + *d-- = *p--; + for (count = 0; p >= y; count++) + { + if (count == 3) + { + *d-- = ','; + count = 0; + } + *d-- = *p--; } d++; if (*d == ',') - d++; + d++; return d; } @@ -323,58 +344,66 @@ void size_trunc_len (char *buffer, unsigned int len, off_t size, int units) { /* Avoid taking power for every file. */ - static const off_t power10 [] = - {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, - 1000000000}; - static const char * const suffix [] = - {"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL}; - static const char * const suffix_lc [] = - {"", "k", "m", "g", "t", "p", "e", "z", "y", NULL}; + static const off_t power10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, + 1000000000 + }; + static const char *const suffix[] = { "", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL }; + static const char *const suffix_lc[] = { "", "k", "m", "g", "t", "p", "e", "z", "y", NULL }; int j = 0; int size_remain; if (len == 0) - len = 9; + len = 9; /* * recalculate from 1024 base to 1000 base if units>0 * We can't just multiply by 1024 - that might cause overflow * if off_t type is too small */ - if (units && kilobyte_si) { - for (j = 0; j < units; j++) { - size_remain=((size % 125)*1024)/1000; /* size mod 125, recalculated */ - size = size / 125; /* 128/125 = 1024/1000 */ - size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */ - size += size_remain; /* Re-add remainder lost by division/multiplication */ - } + if (units && kilobyte_si) + { + for (j = 0; j < units; j++) + { + size_remain = ((size % 125) * 1024) / 1000; /* size mod 125, recalculated */ + size = size / 125; /* 128/125 = 1024/1000 */ + size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */ + size += size_remain; /* Re-add remainder lost by division/multiplication */ + } } - for (j = units; suffix [j] != NULL; j++) { - if (size == 0) { - if (j == units) { - /* Empty files will print "0" even with minimal width. */ - g_snprintf (buffer, len + 1, "0"); - break; - } + for (j = units; suffix[j] != NULL; j++) + { + if (size == 0) + { + if (j == units) + { + /* Empty files will print "0" even with minimal width. */ + g_snprintf (buffer, len + 1, "0"); + break; + } - /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */ - g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", - (j > 1) ? (kilobyte_si ? suffix_lc[j - 1] : suffix[j - 1]) : "B"); - break; - } + /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */ + g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", + (j > 1) ? (kilobyte_si ? suffix_lc[j - 1] : suffix[j - 1]) : "B"); + break; + } - if (size < power10 [len - (j > 0)]) { - g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, kilobyte_si ? suffix_lc[j] : suffix[j]); - break; - } + if (size < power10[len - (j > 0)]) + { + g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, + kilobyte_si ? suffix_lc[j] : suffix[j]); + break; + } - /* Powers of 1000 or 1024, with rounding. */ - if (kilobyte_si) { - size = (size + 500) / 1000; - } else { - size = (size + 512) >> 10; - } + /* Powers of 1000 or 1024, with rounding. */ + if (kilobyte_si) + { + size = (size + 500) / 1000; + } + else + { + size = (size + 512) >> 10; + } } } @@ -382,7 +411,7 @@ int is_exe (mode_t mode) { if ((S_IXUSR & mode) || (S_IXGRP & mode) || (S_IXOTH & mode)) - return 1; + return 1; return 0; } @@ -395,129 +424,145 @@ string_perm (mode_t mode_bits) strcpy (mode, "----------"); if (S_ISDIR (mode_bits)) - mode[0] = 'd'; + mode[0] = 'd'; if (S_ISCHR (mode_bits)) - mode[0] = 'c'; + mode[0] = 'c'; if (S_ISBLK (mode_bits)) - mode[0] = 'b'; + mode[0] = 'b'; if (S_ISLNK (mode_bits)) - mode[0] = 'l'; + mode[0] = 'l'; if (S_ISFIFO (mode_bits)) - mode[0] = 'p'; + mode[0] = 'p'; if (S_ISNAM (mode_bits)) - mode[0] = 'n'; + mode[0] = 'n'; if (S_ISSOCK (mode_bits)) - mode[0] = 's'; + mode[0] = 's'; if (S_ISDOOR (mode_bits)) - mode[0] = 'D'; + mode[0] = 'D'; if (ismode (mode_bits, S_IXOTH)) - mode[9] = 'x'; + mode[9] = 'x'; if (ismode (mode_bits, S_IWOTH)) - mode[8] = 'w'; + mode[8] = 'w'; if (ismode (mode_bits, S_IROTH)) - mode[7] = 'r'; + mode[7] = 'r'; if (ismode (mode_bits, S_IXGRP)) - mode[6] = 'x'; + mode[6] = 'x'; if (ismode (mode_bits, S_IWGRP)) - mode[5] = 'w'; + mode[5] = 'w'; if (ismode (mode_bits, S_IRGRP)) - mode[4] = 'r'; + mode[4] = 'r'; if (ismode (mode_bits, S_IXUSR)) - mode[3] = 'x'; + mode[3] = 'x'; if (ismode (mode_bits, S_IWUSR)) - mode[2] = 'w'; + mode[2] = 'w'; if (ismode (mode_bits, S_IRUSR)) - mode[1] = 'r'; + mode[1] = 'r'; #ifdef S_ISUID if (ismode (mode_bits, S_ISUID)) - mode[3] = (mode[3] == 'x') ? 's' : 'S'; -#endif /* S_ISUID */ + mode[3] = (mode[3] == 'x') ? 's' : 'S'; +#endif /* S_ISUID */ #ifdef S_ISGID if (ismode (mode_bits, S_ISGID)) - mode[6] = (mode[6] == 'x') ? 's' : 'S'; -#endif /* S_ISGID */ + mode[6] = (mode[6] == 'x') ? 's' : 'S'; +#endif /* S_ISGID */ #ifdef S_ISVTX if (ismode (mode_bits, S_ISVTX)) - mode[9] = (mode[9] == 'x') ? 't' : 'T'; -#endif /* S_ISVTX */ + mode[9] = (mode[9] == 'x') ? 't' : 'T'; +#endif /* S_ISVTX */ return mode; } /* p: string which might contain an url with a password (this parameter is - modified in place). + modified in place). has_prefix = 0: The first parameter is an url without a prefix - (user[:pass]@]machine[:port][remote-dir). Delete - the password. + (user[:pass]@]machine[:port][remote-dir). Delete + the password. has_prefix = 1: Search p for known url prefixes. If found delete - the password from the url. - Caveat: only the first url is found -*/ + the password from the url. + Caveat: only the first url is found + */ char * strip_password (char *p, int has_prefix) { - static const struct { - const char *name; + static const struct + { + const char *name; size_t len; - } prefixes[] = { {"/#ftp:", 6}, - {"ftp://", 6}, - {"/#mc:", 5}, - {"mc://", 5}, - {"/#smb:", 6}, - {"smb://", 6}, - {"/#sh:", 5}, - {"sh://", 5}, - {"ssh://", 6} + } prefixes[] = + { + { + "/#ftp:", 6}, + { + "ftp://", 6}, + { + "/#mc:", 5}, + { + "mc://", 5}, + { + "/#smb:", 6}, + { + "smb://", 6}, + { + "/#sh:", 5}, + { + "sh://", 5}, + { + "ssh://", 6} }; char *at, *inner_colon, *dir; size_t i; char *result = p; - - for (i = 0; i < sizeof (prefixes)/sizeof (prefixes[0]); i++) { - char *q; - if (has_prefix) { - if((q = strstr (p, prefixes[i].name)) == 0) - continue; + for (i = 0; i < sizeof (prefixes) / sizeof (prefixes[0]); i++) + { + char *q; + + if (has_prefix) + { + if ((q = strstr (p, prefixes[i].name)) == 0) + continue; else - p = q + prefixes[i].len; - } + p = q + prefixes[i].len; + } if ((dir = strchr (p, PATH_SEP)) != NULL) - *dir = '\0'; + *dir = '\0'; /* search for any possible user */ at = strrchr (p, '@'); if (dir) - *dir = PATH_SEP; + *dir = PATH_SEP; /* We have a username */ - if (at) { - inner_colon = memchr (p, ':', at - p); + if (at) + { + inner_colon = memchr (p, ':', at - p); if (inner_colon) - memmove (inner_colon, at, strlen(at) + 1); + memmove (inner_colon, at, strlen (at) + 1); } - break; + break; } return (result); } const char * -strip_home_and_password(const char *dir) +strip_home_and_password (const char *dir) { size_t len; - static char newdir [MC_MAXPATHLEN]; + static char newdir[MC_MAXPATHLEN]; - if (home_dir && !strncmp (dir, home_dir, len = strlen (home_dir)) && - (dir[len] == PATH_SEP || dir[len] == '\0')){ - newdir [0] = '~'; - g_strlcpy (&newdir [1], &dir [len], sizeof(newdir) - 1); - return newdir; - } + if (home_dir && !strncmp (dir, home_dir, len = strlen (home_dir)) && + (dir[len] == PATH_SEP || dir[len] == '\0')) + { + newdir[0] = '~'; + g_strlcpy (&newdir[1], &dir[len], sizeof (newdir) - 1); + return newdir; + } /* We do not strip homes in /#ftp tree, I do not like ~'s there (see ftpfs.c why) */ - g_strlcpy (newdir, dir, sizeof(newdir)); + g_strlcpy (newdir, dir, sizeof (newdir)); strip_password (newdir, 1); return newdir; } @@ -538,19 +583,20 @@ exist_file (const char *name) int check_for_default (const char *default_file, const char *file) { - if (!exist_file (file)) { - FileOpContext *ctx; - FileOpTotalContext *tctx; + if (!exist_file (file)) + { + FileOpContext *ctx; + FileOpTotalContext *tctx; - if (!exist_file (default_file)) - return -1; + if (!exist_file (default_file)) + return -1; - ctx = file_op_context_new (OP_COPY); - tctx = file_op_total_context_new (); - file_op_context_create_ui (ctx, 0, FALSE); - copy_file_file (tctx, ctx, default_file, file); - file_op_total_context_destroy (tctx); - file_op_context_destroy (ctx); + ctx = file_op_context_new (OP_COPY); + tctx = file_op_total_context_new (); + file_op_context_create_ui (ctx, 0, FALSE); + copy_file_file (tctx, ctx, default_file, file); + file_op_total_context_destroy (tctx); + file_op_context_destroy (ctx); } return 0; @@ -565,29 +611,33 @@ load_file (const char *filename) struct stat s; char *data; long read_size; - - if ((data_file = fopen (filename, "r")) == NULL){ - return 0; + + if ((data_file = fopen (filename, "r")) == NULL) + { + return 0; } - if (fstat (fileno (data_file), &s) != 0){ - fclose (data_file); - return 0; + if (fstat (fileno (data_file), &s) != 0) + { + fclose (data_file); + return 0; } - data = g_malloc (s.st_size+1); + data = g_malloc (s.st_size + 1); read_size = fread (data, 1, s.st_size, data_file); - data [read_size] = 0; + data[read_size] = 0; fclose (data_file); if (read_size > 0) - return data; - else { - g_free (data); - return 0; + return data; + else + { + g_free (data); + return 0; } } char * -load_mc_home_file (const char *_mc_home, const char *_mc_home_alt, const char *filename, char **allocated_filename) +load_mc_home_file (const char *_mc_home, const char *_mc_home_alt, const char *filename, + char **allocated_filename) { char *hintfile_base, *hintfile; char *lang; @@ -599,38 +649,41 @@ load_mc_home_file (const char *_mc_home, const char *_mc_home_alt, const char *f hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); data = load_file (hintfile); - if (!data) { - g_free (hintfile); - g_free (hintfile_base); - hintfile_base = concat_dir_and_file (_mc_home_alt, filename); + if (!data) + { + g_free (hintfile); + g_free (hintfile_base); + hintfile_base = concat_dir_and_file (_mc_home_alt, filename); - hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); - data = load_file (hintfile); + hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); + data = load_file (hintfile); - if (!data) { - /* Fall back to the two-letter language code */ - if (lang[0] && lang[1]) - lang[2] = 0; - hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); - data = load_file (hintfile); + if (!data) + { + /* Fall back to the two-letter language code */ + if (lang[0] && lang[1]) + lang[2] = 0; + hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); + data = load_file (hintfile); - if (!data) { - g_free (hintfile); - hintfile = hintfile_base; - data = load_file (hintfile_base); - } - } + if (!data) + { + g_free (hintfile); + hintfile = hintfile_base; + data = load_file (hintfile_base); + } + } } g_free (lang); if (hintfile != hintfile_base) - g_free (hintfile_base); + g_free (hintfile_base); if (allocated_filename) - *allocated_filename = hintfile; + *allocated_filename = hintfile; else - g_free (hintfile); + g_free (hintfile); return data; } @@ -642,27 +695,30 @@ i18n_checktimelength (void) { size_t length; time_t testtime = time (NULL); - struct tm* lt = localtime(&testtime); + struct tm *lt = localtime (&testtime); - if (lt == NULL) { - /* huh, localtime() doesnt seem to work ... falling back to "(invalid)" */ - length = str_term_width1 (_(INVALID_TIME_TEXT)); - } else { - char buf [MB_LEN_MAX * MAX_I18NTIMELENGTH + 1]; - size_t a, b; + if (lt == NULL) + { + /* huh, localtime() doesnt seem to work ... falling back to "(invalid)" */ + length = str_term_width1 (_(INVALID_TIME_TEXT)); + } + else + { + char buf[MB_LEN_MAX * MAX_I18NTIMELENGTH + 1]; + size_t a, b; - strftime (buf, sizeof(buf) - 1, user_recent_timeformat, lt); - a = str_term_width1 (buf); - strftime (buf, sizeof(buf) - 1, user_old_timeformat, lt); - b = str_term_width1 (buf); + strftime (buf, sizeof (buf) - 1, user_recent_timeformat, lt); + a = str_term_width1 (buf); + strftime (buf, sizeof (buf) - 1, user_old_timeformat, lt); + b = str_term_width1 (buf); - length = max (a, b); - length = max ((size_t)str_term_width1 (_(INVALID_TIME_TEXT)), length); + length = max (a, b); + length = max ((size_t) str_term_width1 (_(INVALID_TIME_TEXT)), length); } /* Don't handle big differences. Use standard value (email bug, please) */ if (length > MAX_I18NTIMELENGTH || length < MIN_I18NTIMELENGTH) - length = STD_I18NTIMELENGTH; + length = STD_I18NTIMELENGTH; return length; } @@ -670,24 +726,24 @@ i18n_checktimelength (void) const char * file_date (time_t when) { - static char timebuf [MB_LEN_MAX * MAX_I18NTIMELENGTH + 1]; + static char timebuf[MB_LEN_MAX * MAX_I18NTIMELENGTH + 1]; time_t current_time = time ((time_t) 0); const char *fmt; - if (current_time > when + 6L * 30L * 24L * 60L * 60L /* Old. */ - || current_time < when - 60L * 60L) /* In the future. */ - /* The file is fairly old or in the future. - POSIX says the cutoff is 6 months old; - approximate this by 6*30 days. - Allow a 1 hour slop factor for what is considered "the future", - to allow for NFS server/client clock disagreement. - Show the year instead of the time of day. */ + if (current_time > when + 6L * 30L * 24L * 60L * 60L /* Old. */ + || current_time < when - 60L * 60L) /* In the future. */ + /* The file is fairly old or in the future. + POSIX says the cutoff is 6 months old; + approximate this by 6*30 days. + Allow a 1 hour slop factor for what is considered "the future", + to allow for NFS server/client clock disagreement. + Show the year instead of the time of day. */ - fmt = user_old_timeformat; + fmt = user_old_timeformat; else - fmt = user_recent_timeformat; + fmt = user_recent_timeformat; - FMT_LOCALTIME(timebuf, sizeof (timebuf), fmt, when); + FMT_LOCALTIME (timebuf, sizeof (timebuf), fmt, when); return timebuf; } @@ -695,11 +751,11 @@ file_date (time_t when) const char * extract_line (const char *s, const char *top) { - static char tmp_line [BUF_MEDIUM]; + static char tmp_line[BUF_MEDIUM]; char *t = tmp_line; - - while (*s && *s != '\n' && (size_t) (t - tmp_line) < sizeof (tmp_line)-1 && s < top) - *t++ = *s++; + + while (*s && *s != '\n' && (size_t) (t - tmp_line) < sizeof (tmp_line) - 1 && s < top) + *t++ = *s++; *t = 0; return tmp_line; } @@ -708,7 +764,7 @@ extract_line (const char *s, const char *top) const char * x_basename (const char *s) { - const char *where; + const char *where; return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s; } @@ -716,13 +772,12 @@ x_basename (const char *s) const char * unix_error_string (int error_num) { - static char buffer [BUF_LARGE]; + static char buffer[BUF_LARGE]; gchar *strerror_currentlocale; - strerror_currentlocale = g_locale_from_utf8(g_strerror (error_num), -1, NULL, NULL, NULL); - g_snprintf (buffer, sizeof (buffer), "%s (%d)", - strerror_currentlocale, error_num); - g_free(strerror_currentlocale); + strerror_currentlocale = g_locale_from_utf8 (g_strerror (error_num), -1, NULL, NULL, NULL); + g_snprintf (buffer, sizeof (buffer), "%s (%d)", strerror_currentlocale, error_num); + g_free (strerror_currentlocale); return buffer; } @@ -732,8 +787,9 @@ skip_separators (const char *s) { const char *su = s; - for (;*su; str_cnext_char (&su)) - if (*su != ' ' && *su != '\t' && *su != ',') break; + for (; *su; str_cnext_char (&su)) + if (*su != ' ' && *su != '\t' && *su != ',') + break; return su; } @@ -743,8 +799,9 @@ skip_numbers (const char *s) { const char *su = s; - for (;*su; str_cnext_char (&su)) - if (!str_isdigit (su)) break; + for (; *su; str_cnext_char (&su)) + if (!str_isdigit (su)) + break; return su; } @@ -753,7 +810,7 @@ skip_numbers (const char *s) * "control sequence", in a sort of pidgin BNF, as follows: * * control-seq = Esc non-'[' - * | Esc '[' (0 or more digits or ';' or '?') (any other char) + * | Esc '[' (0 or more digits or ';' or '?') (any other char) * * This scheme works for all the terminals described in my termcap / * terminfo databases, except the Hewlett-Packard 70092 and some Wyse @@ -765,65 +822,70 @@ skip_numbers (const char *s) char * strip_ctrl_codes (char *s) { - char *w; /* Current position where the stripped data is written */ - char *r; /* Current position where the original data is read */ + char *w; /* Current position where the stripped data is written */ + char *r; /* Current position where the original data is read */ char *n; if (!s) - return 0; + return 0; - for (w = s, r = s; *r; ) { - if (*r == ESC_CHAR) { - /* Skip the control sequence's arguments */ ; - /* '(' need to avoid strange 'B' letter in *Suse (if mc runs under root user) */ - if (*(++r) == '[' || *r == '(') { - /* strchr() matches trailing binary 0 */ - while (*(++r) && strchr ("0123456789;?", *r)); - } else - if (*r == ']') { - /* - * Skip xterm's OSC (Operating System Command) - * http://www.xfree86.org/current/ctlseqs.html - * OSC P s ; P t ST - * OSC P s ; P t BEL - */ - char * new_r = r; + for (w = s, r = s; *r;) + { + if (*r == ESC_CHAR) + { + /* Skip the control sequence's arguments */ ; + /* '(' need to avoid strange 'B' letter in *Suse (if mc runs under root user) */ + if (*(++r) == '[' || *r == '(') + { + /* strchr() matches trailing binary 0 */ + while (*(++r) && strchr ("0123456789;?", *r)); + } + else if (*r == ']') + { + /* + * Skip xterm's OSC (Operating System Command) + * http://www.xfree86.org/current/ctlseqs.html + * OSC P s ; P t ST + * OSC P s ; P t BEL + */ + char *new_r = r; - for (; *new_r; ++new_r) - { - switch (*new_r) - { - /* BEL */ - case '\a': - r = new_r; - goto osc_out; - case ESC_CHAR: - /* ST */ - if (*(new_r + 1) == '\\') - { - r = new_r + 1; - goto osc_out; - } - } - } - osc_out:; - } + for (; *new_r; ++new_r) + { + switch (*new_r) + { + /* BEL */ + case '\a': + r = new_r; + goto osc_out; + case ESC_CHAR: + /* ST */ + if (*(new_r + 1) == '\\') + { + r = new_r + 1; + goto osc_out; + } + } + } + osc_out:; + } - /* - * Now we are at the last character of the sequence. - * Skip it unless it's binary 0. - */ - if (*r) - r++; - continue; - } + /* + * Now we are at the last character of the sequence. + * Skip it unless it's binary 0. + */ + if (*r) + r++; + continue; + } - n = str_get_next_char (r); - if (str_isprint (r)) { - memmove (w, r, n - r); - w+= n - r; - } - r = n; + n = str_get_next_char (r); + if (str_isprint (r)) + { + memmove (w, r, n - r); + w += n - r; + } + r = n; } *w = 0; return s; @@ -838,11 +900,12 @@ get_current_wd (char *buffer, int size) int len; p = g_get_current_dir (); - len = strlen(p) + 1; + len = strlen (p) + 1; - if (len > size) { - g_free (p); - return NULL; + if (len > size) + { + g_free (p); + return NULL; } memcpy (buffer, p, len); @@ -853,87 +916,79 @@ get_current_wd (char *buffer, int size) #endif /* !ENABLE_VFS */ enum compression_type -get_compression_type (int fd, const char * name) +get_compression_type (int fd, const char *name) { unsigned char magic[16]; size_t str_len; /* Read the magic signature */ if (mc_read (fd, (char *) magic, 4) != 4) - return COMPRESSION_NONE; + return COMPRESSION_NONE; /* GZIP_MAGIC and OLD_GZIP_MAGIC */ - if (magic[0] == 037 && (magic[1] == 0213 || magic[1] == 0236)) { - return COMPRESSION_GZIP; + if (magic[0] == 037 && (magic[1] == 0213 || magic[1] == 0236)) + { + return COMPRESSION_GZIP; } /* PKZIP_MAGIC */ - if (magic[0] == 0120 && magic[1] == 0113 && magic[2] == 003 - && magic[3] == 004) { - /* Read compression type */ - mc_lseek (fd, 8, SEEK_SET); - if (mc_read (fd, (char *) magic, 2) != 2) - return COMPRESSION_NONE; + if (magic[0] == 0120 && magic[1] == 0113 && magic[2] == 003 && magic[3] == 004) + { + /* Read compression type */ + mc_lseek (fd, 8, SEEK_SET); + if (mc_read (fd, (char *) magic, 2) != 2) + return COMPRESSION_NONE; - /* Gzip can handle only deflated (8) or stored (0) files */ - if ((magic[0] != 8 && magic[0] != 0) || magic[1] != 0) - return COMPRESSION_NONE; + /* Gzip can handle only deflated (8) or stored (0) files */ + if ((magic[0] != 8 && magic[0] != 0) || magic[1] != 0) + return COMPRESSION_NONE; - /* Compatible with gzip */ - return COMPRESSION_GZIP; + /* Compatible with gzip */ + return COMPRESSION_GZIP; } /* PACK_MAGIC and LZH_MAGIC and compress magic */ - if (magic[0] == 037 - && (magic[1] == 036 || magic[1] == 0240 || magic[1] == 0235)) { - /* Compatible with gzip */ - return COMPRESSION_GZIP; + if (magic[0] == 037 && (magic[1] == 036 || magic[1] == 0240 || magic[1] == 0235)) + { + /* Compatible with gzip */ + return COMPRESSION_GZIP; } /* BZIP and BZIP2 files */ - if ((magic[0] == 'B') && (magic[1] == 'Z') && - (magic[3] >= '1') && (magic[3] <= '9')) { - switch (magic[2]) { - case '0': - return COMPRESSION_BZIP; - case 'h': - return COMPRESSION_BZIP2; - } + if ((magic[0] == 'B') && (magic[1] == 'Z') && (magic[3] >= '1') && (magic[3] <= '9')) + { + switch (magic[2]) + { + case '0': + return COMPRESSION_BZIP; + case 'h': + return COMPRESSION_BZIP2; + } } /* Support for LZMA (only utils format with magic in header). * This is the default format of LZMA utils 4.32.1 and later. */ - if (mc_read(fd, (char *) magic+4, 2) != 2) - return COMPRESSION_NONE; + if (mc_read (fd, (char *) magic + 4, 2) != 2) + return COMPRESSION_NONE; /* LZMA utils format */ - if ( - magic[0] == 0xFF - && magic[1] == 'L' - && magic[2] == 'Z' - && magic[3] == 'M' - && magic[4] == 'A' - && magic[5] == 0x00 - ) - return COMPRESSION_LZMA; + if (magic[0] == 0xFF + && magic[1] == 'L' + && magic[2] == 'Z' && magic[3] == 'M' && magic[4] == 'A' && magic[5] == 0x00) + return COMPRESSION_LZMA; /* XZ compression magic */ - if ( - magic[0] == 0xFD - && magic[1] == 0x37 - && magic[2] == 0x7A - && magic[3] == 0x58 - && magic[4] == 0x5A - && magic[5] == 0x00 - ) - return COMPRESSION_XZ; + if (magic[0] == 0xFD + && magic[1] == 0x37 + && magic[2] == 0x7A && magic[3] == 0x58 && magic[4] == 0x5A && magic[5] == 0x00) + return COMPRESSION_XZ; - str_len = strlen(name); - /* HACK: we must belive to extention of LZMA file :) ...*/ - if ( (str_len > 5 && strcmp(&name[str_len-5],".lzma") == 0) || - (str_len > 4 && strcmp(&name[str_len-4],".tlz") == 0)) - return COMPRESSION_LZMA; + str_len = strlen (name); + /* HACK: we must belive to extention of LZMA file :) ... */ + if ((str_len > 5 && strcmp (&name[str_len - 5], ".lzma") == 0) || + (str_len > 4 && strcmp (&name[str_len - 4], ".tlz") == 0)) + return COMPRESSION_LZMA; return COMPRESSION_NONE; } @@ -941,33 +996,39 @@ get_compression_type (int fd, const char * name) const char * decompress_extension (int type) { - switch (type){ - case COMPRESSION_GZIP: return "#ugz"; - case COMPRESSION_BZIP: return "#ubz"; - case COMPRESSION_BZIP2: return "#ubz2"; - case COMPRESSION_LZMA: return "#ulzma"; - case COMPRESSION_XZ: return "#uxz"; - } - /* Should never reach this place */ - fprintf (stderr, "Fatal: decompress_extension called with an unknown argument\n"); - return 0; + switch (type) + { + case COMPRESSION_GZIP: + return "#ugz"; + case COMPRESSION_BZIP: + return "#ubz"; + case COMPRESSION_BZIP2: + return "#ubz2"; + case COMPRESSION_LZMA: + return "#ulzma"; + case COMPRESSION_XZ: + return "#uxz"; + } + /* Should never reach this place */ + fprintf (stderr, "Fatal: decompress_extension called with an unknown argument\n"); + return 0; } /* Hooks */ void -add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data) +add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data) { Hook *new_hook = g_new (Hook, 1); new_hook->hook_fn = hook_fn; - new_hook->next = *hook_list; + new_hook->next = *hook_list; new_hook->hook_data = data; - + *hook_list = new_hook; } void -execute_hooks (Hook *hook_list) +execute_hooks (Hook * hook_list) { Hook *new_hook = 0; Hook *p; @@ -975,50 +1036,54 @@ execute_hooks (Hook *hook_list) /* We copy the hook list first so tahat we let the hook * function call delete_hook */ - - while (hook_list){ - add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data); - hook_list = hook_list->next; + + while (hook_list) + { + add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data); + hook_list = hook_list->next; } p = new_hook; - - while (new_hook){ - (*new_hook->hook_fn)(new_hook->hook_data); - new_hook = new_hook->next; + + while (new_hook) + { + (*new_hook->hook_fn) (new_hook->hook_data); + new_hook = new_hook->next; } - - for (hook_list = p; hook_list;){ - p = hook_list; - hook_list = hook_list->next; - g_free (p); + + for (hook_list = p; hook_list;) + { + p = hook_list; + hook_list = hook_list->next; + g_free (p); } } void -delete_hook (Hook **hook_list, void (*hook_fn)(void *)) +delete_hook (Hook ** hook_list, void (*hook_fn) (void *)) { Hook *current, *new_list, *next; new_list = 0; - - for (current = *hook_list; current; current = next){ - next = current->next; - if (current->hook_fn == hook_fn) - g_free (current); - else - add_hook (&new_list, current->hook_fn, current->hook_data); + + for (current = *hook_list; current; current = next) + { + next = current->next; + if (current->hook_fn == hook_fn) + g_free (current); + else + add_hook (&new_list, current->hook_fn, current->hook_data); } *hook_list = new_list; } int -hook_present (Hook *hook_list, void (*hook_fn)(void *)) +hook_present (Hook * hook_list, void (*hook_fn) (void *)) { Hook *p; - + for (p = hook_list; p; p = p->next) - if (p->hook_fn == hook_fn) - return 1; + if (p->hook_fn == hook_fn) + return 1; return 0; } @@ -1026,10 +1091,10 @@ void wipe_password (char *passwd) { char *p = passwd; - + if (!p) - return; - for (;*p ; p++) + return; + for (; *p; p++) *p = 0; g_free (passwd); } @@ -1043,29 +1108,39 @@ convert_controls (const char *p) char *q; /* Parse the escape special character */ - for (q = valcopy; *p;){ - if (*p == '\\'){ - p++; - if ((*p == 'e') || (*p == 'E')){ - p++; - *q++ = ESC_CHAR; - } - } else { - if (*p == '^'){ - p++; - if (*p == '^') - *q++ = *p++; - else { - char c = (*p | 0x20); - if (c >= 'a' && c <= 'z') { - *q++ = c - 'a' + 1; - p++; - } else if (*p) - p++; - } - } else - *q++ = *p++; - } + for (q = valcopy; *p;) + { + if (*p == '\\') + { + p++; + if ((*p == 'e') || (*p == 'E')) + { + p++; + *q++ = ESC_CHAR; + } + } + else + { + if (*p == '^') + { + p++; + if (*p == '^') + *q++ = *p++; + else + { + char c = (*p | 0x20); + if (c >= 'a' && c <= 'z') + { + *q++ = c - 'a' + 1; + p++; + } + else if (*p) + p++; + } + } + else + *q++ = *p++; + } } *q = 0; return valcopy; @@ -1078,140 +1153,158 @@ resolve_symlinks (const char *path) int len; struct stat mybuf; const char *p; - + if (*path != PATH_SEP) return NULL; r = buf = g_malloc (MC_MAXPATHLEN); - buf2 = g_malloc (MC_MAXPATHLEN); + buf2 = g_malloc (MC_MAXPATHLEN); *r++ = PATH_SEP; *r = 0; p = path; - for (;;) { - q = strchr (p + 1, PATH_SEP); - if (!q) { - q = strchr (p + 1, 0); - if (q == p + 1) - break; - } - c = *q; - *q = 0; - if (mc_lstat (path, &mybuf) < 0) { - g_free (buf); - g_free (buf2); - *q = c; - return NULL; - } - if (!S_ISLNK (mybuf.st_mode)) - strcpy (r, p + 1); - else { - len = mc_readlink (path, buf2, MC_MAXPATHLEN - 1); - if (len < 0) { - g_free (buf); - g_free (buf2); - *q = c; - return NULL; - } - buf2 [len] = 0; - if (*buf2 == PATH_SEP) - strcpy (buf, buf2); - else - strcpy (r, buf2); - } - canonicalize_pathname (buf); - r = strchr (buf, 0); - if (!*r || *(r - 1) != PATH_SEP) { - *r++ = PATH_SEP; - *r = 0; - } - *q = c; - p = q; - if (!c) - break; + for (;;) + { + q = strchr (p + 1, PATH_SEP); + if (!q) + { + q = strchr (p + 1, 0); + if (q == p + 1) + break; + } + c = *q; + *q = 0; + if (mc_lstat (path, &mybuf) < 0) + { + g_free (buf); + g_free (buf2); + *q = c; + return NULL; + } + if (!S_ISLNK (mybuf.st_mode)) + strcpy (r, p + 1); + else + { + len = mc_readlink (path, buf2, MC_MAXPATHLEN - 1); + if (len < 0) + { + g_free (buf); + g_free (buf2); + *q = c; + return NULL; + } + buf2[len] = 0; + if (*buf2 == PATH_SEP) + strcpy (buf, buf2); + else + strcpy (r, buf2); + } + canonicalize_pathname (buf); + r = strchr (buf, 0); + if (!*r || *(r - 1) != PATH_SEP) + { + *r++ = PATH_SEP; + *r = 0; + } + *q = c; + p = q; + if (!c) + break; } if (!*buf) - strcpy (buf, PATH_SEP_STR); + strcpy (buf, PATH_SEP_STR); else if (*(r - 1) == PATH_SEP && r != buf + 1) - *(r - 1) = 0; + *(r - 1) = 0; g_free (buf2); return buf; } static gboolean -mc_util_write_backup_content(const char *from_file_name, const char *to_file_name) +mc_util_write_backup_content (const char *from_file_name, const char *to_file_name) { FILE *backup_fd; char *contents; gsize length; if (!g_file_get_contents (from_file_name, &contents, &length, NULL)) - return FALSE; + return FALSE; backup_fd = fopen (to_file_name, "w"); - if (backup_fd == NULL) { - g_free(contents); - return FALSE; + if (backup_fd == NULL) + { + g_free (contents); + return FALSE; } - fwrite ( (const void *) contents, length, 1, backup_fd); + fwrite ((const void *) contents, length, 1, backup_fd); - fflush(backup_fd); - fclose(backup_fd); - g_free(contents); + fflush (backup_fd); + fclose (backup_fd); + g_free (contents); return TRUE; } /* Finds out a relative path from first to second, i.e. goes as many .. * as needed up in first and then goes down using second */ char * -diff_two_paths (const char *first, const char *second) +diff_two_paths (const char *first, const char *second) { char *p, *q, *r, *s, *buf = NULL; int i, j, prevlen = -1, currlen; char *my_first = NULL, *my_second = NULL; - + my_first = resolve_symlinks (first); if (my_first == NULL) return NULL; my_second = resolve_symlinks (second); - if (my_second == NULL) { - g_free (my_first); - return NULL; + if (my_second == NULL) + { + g_free (my_first); + return NULL; } - for (j = 0; j < 2; j++) { - p = my_first; - q = my_second; - for (;;) { - r = strchr (p, PATH_SEP); - s = strchr (q, PATH_SEP); - if (!r || !s) - break; - *r = 0; *s = 0; - if (strcmp (p, q)) { - *r = PATH_SEP; *s = PATH_SEP; - break; - } else { - *r = PATH_SEP; *s = PATH_SEP; - } - p = r + 1; - q = s + 1; - } - p--; - for (i = 0; (p = strchr (p + 1, PATH_SEP)) != NULL; i++); - currlen = (i + 1) * 3 + strlen (q) + 1; - if (j) { - if (currlen < prevlen) - g_free (buf); - else { - g_free (my_first); - g_free (my_second); - return buf; - } - } - p = buf = g_malloc (currlen); - prevlen = currlen; - for (; i >= 0; i--, p += 3) - strcpy (p, "../"); - strcpy (p, q); + for (j = 0; j < 2; j++) + { + p = my_first; + q = my_second; + for (;;) + { + r = strchr (p, PATH_SEP); + s = strchr (q, PATH_SEP); + if (!r || !s) + break; + *r = 0; + *s = 0; + if (strcmp (p, q)) + { + *r = PATH_SEP; + *s = PATH_SEP; + break; + } + else + { + *r = PATH_SEP; + *s = PATH_SEP; + } + p = r + 1; + q = s + 1; + } + p--; + for (i = 0; (p = strchr (p + 1, PATH_SEP)) != NULL; i++); + currlen = (i + 1) * 3 + strlen (q) + 1; + if (j) + { + if (currlen < prevlen) + g_free (buf); + else + { + g_free (my_first); + g_free (my_second); + return buf; + } + } + p = buf = g_malloc (currlen); + prevlen = currlen; + for (; i >= 0; i--, p += 3) + strcpy (p, "../"); + strcpy (p, q); } g_free (my_first); g_free (my_second); @@ -1223,16 +1316,16 @@ char * concat_dir_and_file (const char *dir, const char *file) { int i = strlen (dir); - - if (dir [i-1] == PATH_SEP) - return g_strconcat (dir, file, (char *) NULL); + + if (dir[i - 1] == PATH_SEP) + return g_strconcat (dir, file, (char *) NULL); else - return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL); + return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL); } /* Append text to GList, remove all entries with the same text */ GList * -list_append_unique (GList *list, char *text) +list_append_unique (GList * list, char *text) { GList *lc_link; @@ -1245,18 +1338,20 @@ list_append_unique (GList *list, char *text) list = g_list_last (list); lc_link = g_list_previous (list); - while (lc_link != NULL) { - GList *newlink; + while (lc_link != NULL) + { + GList *newlink; - newlink = g_list_previous (lc_link); - if (strcmp ((char *) lc_link->data, text) == 0) { - GList *tmp; + newlink = g_list_previous (lc_link); + if (strcmp ((char *) lc_link->data, text) == 0) + { + GList *tmp; - g_free (lc_link->data); - tmp = g_list_remove_link (list, lc_link); - g_list_free_1 (lc_link); - } - lc_link = newlink; + g_free (lc_link->data); + tmp = g_list_remove_link (list, lc_link); + g_list_free_1 (lc_link); + } + lc_link = newlink; } return list; @@ -1283,8 +1378,7 @@ list_append_unique (GList *list, char *text) int mc_mkstemps (char **pname, const char *prefix, const char *suffix) { - static const char letters[] - = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static unsigned long value; struct timeval tv; char *tmpbase; @@ -1292,11 +1386,14 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) char *XXXXXX; int count; - if (strchr (prefix, PATH_SEP) == NULL) { - /* Add prefix first to find the position of XXXXXX */ - tmpbase = concat_dir_and_file (mc_tmpdir (), prefix); - } else { - tmpbase = g_strdup (prefix); + if (strchr (prefix, PATH_SEP) == NULL) + { + /* Add prefix first to find the position of XXXXXX */ + tmpbase = concat_dir_and_file (mc_tmpdir (), prefix); + } + else + { + tmpbase = g_strdup (prefix); } tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, (char *) NULL); @@ -1308,34 +1405,35 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) gettimeofday (&tv, NULL); value += (tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); - for (count = 0; count < TMP_MAX; ++count) { - unsigned long v = value; - int fd; + for (count = 0; count < TMP_MAX; ++count) + { + unsigned long v = value; + int fd; - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; - fd = open (tmpname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, - S_IRUSR | S_IWUSR); - if (fd >= 0) { - /* Successfully created. */ - return fd; - } + fd = open (tmpname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR); + if (fd >= 0) + { + /* Successfully created. */ + return fd; + } - /* This is a random value. It is only necessary that the next - TMP_MAX values generated by adding 7777 to VALUE are different - with (module 2^32). */ - value += 7777; + /* This is a random value. It is only necessary that the next + TMP_MAX values generated by adding 7777 to VALUE are different + with (module 2^32). */ + value += 7777; } /* Unsuccessful. Free the filename. */ @@ -1350,7 +1448,7 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) * If there is no stored data, return line 1 and col 0. */ void -load_file_position (const char *filename, long *line, long *column, off_t *offset) +load_file_position (const char *filename, long *line, long *column, off_t * offset) { char *fn; FILE *f; @@ -1363,50 +1461,57 @@ load_file_position (const char *filename, long *line, long *column, off_t *offse *offset = 0; /* open file with positions */ - fn = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEPOS_FILE, NULL); + fn = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEPOS_FILE, NULL); f = fopen (fn, "r"); g_free (fn); if (!f) - return; + return; len = strlen (filename); - while (fgets (buf, sizeof (buf), f)) { - const char *p; - gchar **pos_tokens; + while (fgets (buf, sizeof (buf), f)) + { + const char *p; + gchar **pos_tokens; - /* check if the filename matches the beginning of string */ - if (strncmp (buf, filename, len) != 0) - continue; + /* check if the filename matches the beginning of string */ + if (strncmp (buf, filename, len) != 0) + continue; - /* followed by single space */ - if (buf[len] != ' ') - continue; + /* followed by single space */ + if (buf[len] != ' ') + continue; - /* and string without spaces */ - p = &buf[len + 1]; - if (strchr (p, ' ')) - continue; - - pos_tokens = g_strsplit_set (p, ";", 3); - if (pos_tokens[0] != NULL) { - *line = strtol (pos_tokens[0], NULL, 10); - if (pos_tokens[1] != NULL) { - *column = strtol (pos_tokens[1], NULL, 10); - if (pos_tokens[2] != NULL) - *offset = strtoll (pos_tokens[2], NULL, 10); - else - *offset = 0; - } else { - *column = 0; - *offset = 0; - } - } else { - *line = 1; - *column = 0; - *offset = 0; - } - g_strfreev(pos_tokens); + /* and string without spaces */ + p = &buf[len + 1]; + if (strchr (p, ' ')) + continue; + + pos_tokens = g_strsplit_set (p, ";", 3); + if (pos_tokens[0] != NULL) + { + *line = strtol (pos_tokens[0], NULL, 10); + if (pos_tokens[1] != NULL) + { + *column = strtol (pos_tokens[1], NULL, 10); + if (pos_tokens[2] != NULL) + *offset = strtoll (pos_tokens[2], NULL, 10); + else + *offset = 0; + } + else + { + *column = 0; + *offset = 0; + } + } + else + { + *line = 1; + *column = 0; + *offset = 0; + } + g_strfreev (pos_tokens); } fclose (f); } @@ -1424,9 +1529,11 @@ save_file_position (const char *filename, long line, long column, off_t offset) gsize len; if (filepos_max_saved_entries == 0) - filepos_max_saved_entries = mc_config_get_int(mc_main_config, CONFIG_APP_SECTION, "filepos_max_saved_entries", 1024); + filepos_max_saved_entries = + mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, "filepos_max_saved_entries", + 1024); - fn = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEPOS_FILE, NULL); + fn = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEPOS_FILE, NULL); if (fn == NULL) goto early_error; @@ -1439,31 +1546,30 @@ save_file_position (const char *filename, long line, long column, off_t offset) if (f == NULL) goto open_target_error; - tmp_fn = g_strdup_printf("%s" TMP_SUFFIX ,fn); + tmp_fn = g_strdup_printf ("%s" TMP_SUFFIX, fn); tmp_f = fopen (tmp_fn, "r"); if (tmp_f == NULL) goto open_source_error; /* put the new record */ - if (line != 1 || column != 0) { - if (fprintf (f, "%s %ld;%ld;%llu\n", filename, line, column, (unsigned long long) offset) < 0) + if (line != 1 || column != 0) + { + if (fprintf (f, "%s %ld;%ld;%llu\n", filename, line, column, (unsigned long long) offset) < + 0) goto write_position_error; } - while (fgets (buf, sizeof (buf), tmp_f)) { - if ( - buf[len] == ' ' && - strncmp (buf, filename, len) == 0 && - !strchr (&buf[len + 1], ' ') - ) - continue; + while (fgets (buf, sizeof (buf), tmp_f)) + { + if (buf[len] == ' ' && strncmp (buf, filename, len) == 0 && !strchr (&buf[len + 1], ' ')) + continue; - fprintf (f, "%s", buf); - if (++i > filepos_max_saved_entries) - break; + fprintf (f, "%s", buf); + if (++i > filepos_max_saved_entries) + break; } fclose (tmp_f); - g_free(tmp_fn); + g_free (tmp_fn); fclose (f); mc_util_unlink_backup_if_possible (fn, TMP_SUFFIX); g_free (fn); @@ -1472,7 +1578,7 @@ save_file_position (const char *filename, long line, long column, off_t offset) write_position_error: fclose (tmp_f); open_source_error: - g_free(tmp_fn); + g_free (tmp_fn); fclose (f); mc_util_restore_from_backup_if_possible (fn, TMP_SUFFIX); open_target_error: @@ -1480,6 +1586,7 @@ save_file_position (const char *filename, long line, long column, off_t offset) early_error: return; } + #undef TMP_SUFFIX extern const char * cstrcasestr (const char *haystack, const char *needle) @@ -1493,7 +1600,7 @@ cstrcasestr (const char *haystack, const char *needle) const char * cstrstr (const char *haystack, const char *needle) { - return strstr(haystack, needle); + return strstr (haystack, needle); } extern char * @@ -1510,9 +1617,9 @@ str_unconst (const char *s) extern int ascii_alpha_to_cntrl (int ch) { - if ((ch >= ASCII_A && ch <= ASCII_Z) - || (ch >= ASCII_a && ch <= ASCII_z)) { - ch &= 0x1f; + if ((ch >= ASCII_A && ch <= ASCII_Z) || (ch >= ASCII_a && ch <= ASCII_z)) + { + ch &= 0x1f; } return ch; } @@ -1523,7 +1630,7 @@ Q_ (const char *s) const char *result, *sep; result = _(s); - sep = strchr(result, '|'); + sep = strchr (result, '|'); return (sep != NULL) ? sep + 1 : result; } @@ -1535,24 +1642,25 @@ mc_util_make_backup_if_possible (const char *file_name, const char *backup_suffi char *backup_path; gboolean ret; if (!exist_file (file_name)) - return FALSE; + return FALSE; - backup_path = g_strdup_printf("%s%s",file_name,backup_suffix); + backup_path = g_strdup_printf ("%s%s", file_name, backup_suffix); if (backup_path == NULL) - return FALSE; + return FALSE; ret = mc_util_write_backup_content (file_name, backup_path); - if (ret) { - /* Backup file will have same ownership with main file. */ - if (stat (file_name, &stat_buf) == 0) - chmod (backup_path, stat_buf.st_mode); - else - chmod (backup_path, S_IRUSR | S_IWUSR); + if (ret) + { + /* Backup file will have same ownership with main file. */ + if (stat (file_name, &stat_buf) == 0) + chmod (backup_path, stat_buf.st_mode); + else + chmod (backup_path, S_IRUSR | S_IWUSR); } - g_free(backup_path); + g_free (backup_path); return ret; } @@ -1563,12 +1671,12 @@ mc_util_restore_from_backup_if_possible (const char *file_name, const char *back gboolean ret; char *backup_path; - backup_path = g_strdup_printf("%s%s",file_name,backup_suffix); + backup_path = g_strdup_printf ("%s%s", file_name, backup_suffix); if (backup_path == NULL) - return FALSE; + return FALSE; ret = mc_util_write_backup_content (backup_path, file_name); - g_free(backup_path); + g_free (backup_path); return ret; } @@ -1578,45 +1686,47 @@ mc_util_unlink_backup_if_possible (const char *file_name, const char *backup_suf { char *backup_path; - backup_path = g_strdup_printf("%s%s",file_name,backup_suffix); + backup_path = g_strdup_printf ("%s%s", file_name, backup_suffix); if (backup_path == NULL) - return FALSE; + return FALSE; if (exist_file (backup_path)) - mc_unlink (backup_path); + mc_unlink (backup_path); - g_free(backup_path); + g_free (backup_path); return TRUE; } /* partly taken from dcigettext.c, returns "" for default locale */ /* value should be freed by calling function g_free() */ -char *guess_message_value (void) +char * +guess_message_value (void) { - static const char * const var[] = { - /* Setting of LC_ALL overwrites all other. */ - /* Do not use LANGUAGE for check user locale and drowing hints */ - "LC_ALL", - /* Next comes the name of the desired category. */ - "LC_MESSAGES", + static const char *const var[] = { + /* Setting of LC_ALL overwrites all other. */ + /* Do not use LANGUAGE for check user locale and drowing hints */ + "LC_ALL", + /* Next comes the name of the desired category. */ + "LC_MESSAGES", /* Last possibility is the LANG environment variable. */ - "LANG", - /* NULL exit loops */ - NULL + "LANG", + /* NULL exit loops */ + NULL }; unsigned i = 0; const char *locale = NULL; - while (var[i] != NULL) { - locale = getenv (var[i]); - if (locale != NULL && locale[0] != '\0') - break; - i++; + while (var[i] != NULL) + { + locale = getenv (var[i]); + if (locale != NULL && locale[0] != '\0') + break; + i++; } if (locale == NULL) - locale = ""; + locale = ""; return g_strdup (locale); } diff --git a/lib/vfs/mc-vfs/extfs.c b/lib/vfs/mc-vfs/extfs.c index 94b6c35a1..752ec99a1 100644 --- a/lib/vfs/mc-vfs/extfs.c +++ b/lib/vfs/mc-vfs/extfs.c @@ -49,25 +49,26 @@ #include "lib/global.h" #include "lib/fileloc.h" -#include "src/wtools.h" /* message() */ -#include "src/main.h" /* print_vfs_message */ -#include "src/execute.h" /* For shell_execute */ +#include "src/wtools.h" /* message() */ +#include "src/main.h" /* print_vfs_message */ +#include "src/execute.h" /* For shell_execute */ #include "utilvfs.h" #include "vfs.h" #include "vfs-impl.h" -#include "gc.h" /* vfs_rmstamp */ +#include "gc.h" /* vfs_rmstamp */ #undef ERRNOR #define ERRNOR(x,y) do { my_errno = x; return y; } while(0) -struct inode { +struct inode +{ nlink_t nlink; - struct entry *first_in_subdir; /* only used if this is a directory */ + struct entry *first_in_subdir; /* only used if this is a directory */ struct entry *last_in_subdir; - ino_t inode; /* This is inode # */ - dev_t dev; /* This is an internal identification of the extfs archive */ - struct archive *archive; /* And this is an archive structure */ + ino_t inode; /* This is inode # */ + dev_t dev; /* This is an internal identification of the extfs archive */ + struct archive *archive; /* And this is an archive structure */ dev_t rdev; mode_t mode; uid_t uid; @@ -80,21 +81,24 @@ struct inode { char *local_filename; }; -struct entry { +struct entry +{ struct entry *next_in_dir; struct entry *dir; char *name; struct inode *inode; }; -struct pseudofile { +struct pseudofile +{ struct archive *archive; gboolean has_changed; int local_handle; struct entry *entry; }; -struct archive { +struct archive +{ int fstype; char *name; char *local_name; @@ -106,7 +110,8 @@ struct archive { struct archive *next; }; -typedef struct { +typedef struct +{ char *path; char *prefix; gboolean need_archive; @@ -118,7 +123,7 @@ static gboolean notadir; static void extfs_remove_entry (struct entry *e); static void extfs_free (vfsid id); static void extfs_free_entry (struct entry *e); -static struct entry * extfs_resolve_symlinks_int (struct entry *entry, GSList *list); +static struct entry *extfs_resolve_symlinks_int (struct entry *entry, GSList * list); static struct vfs_class vfs_extfs_ops; static struct archive *first_archive = NULL; @@ -146,23 +151,26 @@ extfs_make_dots (struct entry *ent) entry->name = g_strdup (".."); inode->last_in_subdir = entry; entry->next_in_dir = NULL; - if (parent != NULL) { + if (parent != NULL) + { entry->inode = parent; entry->dir = parentry; parent->nlink++; - } else { - entry->inode = inode; - entry->dir = ent; - inode->nlink++; + } + else + { + entry->inode = inode; + entry->dir = ent; + inode->nlink++; } } static struct entry * extfs_generate_entry (struct archive *archive, - const char *name, struct entry *parentry, mode_t mode) + const char *name, struct entry *parentry, mode_t mode) { mode_t myumask; - struct inode *inode, *parent; + struct inode *inode, *parent; struct entry *entry; parent = (parentry != NULL) ? parentry->inode : NULL; @@ -171,9 +179,10 @@ extfs_generate_entry (struct archive *archive, entry->name = g_strdup (name); entry->next_in_dir = NULL; entry->dir = parentry; - if (parent != NULL) { - parent->last_in_subdir->next_in_dir = entry; - parent->last_in_subdir = entry; + if (parent != NULL) + { + parent->last_in_subdir->next_in_dir = entry; + parent->last_in_subdir = entry; } inode = g_new (struct inode, 1); entry->inode = inode; @@ -201,17 +210,18 @@ extfs_generate_entry (struct archive *archive, } static struct entry * -extfs_find_entry_int (struct entry *dir, char *name, GSList *list, - gboolean make_dirs, gboolean make_file) +extfs_find_entry_int (struct entry *dir, char *name, GSList * list, + gboolean make_dirs, gboolean make_file) { struct entry *pent, *pdir; char *p, *q, *name_end; char c = PATH_SEP; - if (g_path_is_absolute (name)) { - /* Handle absolute paths */ - name = (char *) g_path_skip_root (name); - dir = dir->inode->archive->root_entry; + if (g_path_is_absolute (name)) + { + /* Handle absolute paths */ + name = (char *) g_path_skip_root (name); + dir = dir->inode->archive->root_entry; } pent = dir; @@ -220,58 +230,65 @@ extfs_find_entry_int (struct entry *dir, char *name, GSList *list, q = strchr (p, PATH_SEP); if (q == '\0') - q = strchr (p, '\0'); + q = strchr (p, '\0'); - while ((pent != NULL) && (c != '\0') && (*p != '\0')) { - c = *q; - *q = '\0'; + while ((pent != NULL) && (c != '\0') && (*p != '\0')) + { + c = *q; + *q = '\0'; - if (strcmp (p, ".") != 0) { - if (strcmp (p, "..") == 0) - pent = pent->dir; - else { - pent = extfs_resolve_symlinks_int (pent, list); - if (pent == NULL) { - *q = c; - return NULL; - } - if (!S_ISDIR (pent->inode->mode)) { - *q = c; - notadir = TRUE; - return NULL; - } + if (strcmp (p, ".") != 0) + { + if (strcmp (p, "..") == 0) + pent = pent->dir; + else + { + pent = extfs_resolve_symlinks_int (pent, list); + if (pent == NULL) + { + *q = c; + return NULL; + } + if (!S_ISDIR (pent->inode->mode)) + { + *q = c; + notadir = TRUE; + return NULL; + } - pdir = pent; - for (pent = pent->inode->first_in_subdir; pent != NULL; pent = pent->next_in_dir) - /* Hack: I keep the original semanthic unless - q+1 would break in the strchr */ - if (strcmp (pent->name, p) == 0) { - if (q + 1 > name_end) { - *q = c; - notadir = !S_ISDIR (pent->inode->mode); - return pent; - } - break; - } + pdir = pent; + for (pent = pent->inode->first_in_subdir; pent != NULL; pent = pent->next_in_dir) + /* Hack: I keep the original semanthic unless + q+1 would break in the strchr */ + if (strcmp (pent->name, p) == 0) + { + if (q + 1 > name_end) + { + *q = c; + notadir = !S_ISDIR (pent->inode->mode); + return pent; + } + break; + } - /* When we load archive, we create automagically - * non-existant directories - */ - if (pent == NULL && make_dirs) - pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFDIR | 0777); - if (pent == NULL && make_file) - pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFREG | 0666); - } - } - /* Next iteration */ - *q = c; - p = q + 1; - q = strchr (p, PATH_SEP); - if (q == '\0') - q = strchr (p, '\0'); + /* When we load archive, we create automagically + * non-existant directories + */ + if (pent == NULL && make_dirs) + pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFDIR | 0777); + if (pent == NULL && make_file) + pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFREG | 0666); + } + } + /* Next iteration */ + *q = c; + p = q + 1; + q = strchr (p, PATH_SEP); + if (q == '\0') + q = strchr (p, '\0'); } if (pent == NULL) - my_errno = ENOENT; + my_errno = ENOENT; return pent; } @@ -284,11 +301,12 @@ extfs_find_entry (struct entry *dir, char *name, gboolean make_dirs, gboolean ma notadir = FALSE; res = extfs_find_entry_int (dir, name, NULL, make_dirs, make_file); - if (res == NULL) { - if (errloop) - my_errno = ELOOP; - else if (notadir) - my_errno = ENOTDIR; + if (res == NULL) + { + if (errloop) + my_errno = ELOOP; + else if (notadir) + my_errno = ENOTDIR; } return res; } @@ -300,15 +318,16 @@ extfs_fill_names (struct vfs_class *me, fill_names_f func) (void) me; - while (a != NULL) { - extfs_plugin_info_t *info; - char *name; + while (a != NULL) + { + extfs_plugin_info_t *info; + char *name; - info = &g_array_index (extfs_plugins, extfs_plugin_info_t, a->fstype); - name = g_strconcat (a->name ? a->name : "", "#", info->prefix, (char *) NULL); - func (name); - g_free (name); - a = a->next; + info = &g_array_index (extfs_plugins, extfs_plugin_info_t, a->fstype); + name = g_strconcat (a->name ? a->name : "", "#", info->prefix, (char *) NULL); + func (name); + g_free (name); + a = a->next; } } @@ -316,13 +335,14 @@ static void extfs_free_archive (struct archive *archive) { extfs_free_entry (archive->root_entry); - if (archive->local_name != NULL) { + if (archive->local_name != NULL) + { struct stat my; mc_stat (archive->local_name, &my); - mc_ungetlocalcopy (archive->name, archive->local_name, - archive->local_stat.st_mtime != my.st_mtime); - g_free(archive->local_name); + mc_ungetlocalcopy (archive->name, archive->local_name, + archive->local_stat.st_mtime != my.st_mtime); + g_free (archive->local_name); } g_free (archive->name); g_free (archive); @@ -343,33 +363,37 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) info = &g_array_index (extfs_plugins, extfs_plugin_info_t, fstype); - if (info->need_archive) { - if (mc_stat (name, &mystat) == -1) - return NULL; + if (info->need_archive) + { + if (mc_stat (name, &mystat) == -1) + return NULL; - if (!vfs_file_is_local (name)) { - local_name = mc_getlocalcopy (name); - if (local_name == NULL) - return NULL; - } + if (!vfs_file_is_local (name)) + { + local_name = mc_getlocalcopy (name); + if (local_name == NULL) + return NULL; + } - tmp = name_quote (name, 0); + tmp = name_quote (name, 0); } cmd = g_strconcat (info->path, info->prefix, " list ", - local_name != NULL ? local_name : tmp, (char *) NULL); + local_name != NULL ? local_name : tmp, (char *) NULL); g_free (tmp); open_error_pipe (); result = popen (cmd, "r"); g_free (cmd); - if (result == NULL) { - close_error_pipe (D_ERROR, NULL); - if (local_name != NULL) { - mc_ungetlocalcopy (name, local_name, 0); - g_free (local_name); - } - return NULL; + if (result == NULL) + { + close_error_pipe (D_ERROR, NULL); + if (local_name != NULL) + { + mc_ungetlocalcopy (name, local_name, 0); + g_free (local_name); + } + return NULL; } #ifdef ___QNXNTO__ @@ -382,7 +406,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) current_archive->local_name = local_name; if (local_name != NULL) - mc_stat (local_name, ¤t_archive->local_stat); + mc_stat (local_name, ¤t_archive->local_stat); current_archive->inode_counter = 0; current_archive->fd_usage = 0; current_archive->rdev = archive_counter++; @@ -390,11 +414,11 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) first_archive = current_archive; mode = mystat.st_mode & 07777; if (mode & 0400) - mode |= 0100; + mode |= 0100; if (mode & 0040) - mode |= 0010; + mode |= 0010; if (mode & 0004) - mode |= 0001; + mode |= 0001; mode |= S_IFDIR; root_entry = extfs_generate_entry (current_archive, PATH_SEP_STR, NULL, mode); root_entry->inode->uid = mystat.st_uid; @@ -426,118 +450,129 @@ extfs_read_archive (int fstype, const char *name, struct archive **pparc) extfsd = extfs_open_archive (fstype, name, ¤t_archive); - if (extfsd == NULL) { - message (D_ERROR, MSG_ERROR, _("Cannot open %s archive\n%s"), - info->prefix, name); - return -1; + if (extfsd == NULL) + { + message (D_ERROR, MSG_ERROR, _("Cannot open %s archive\n%s"), info->prefix, name); + return -1; } buffer = g_malloc (BUF_4K); - while (fgets (buffer, BUF_4K, extfsd) != NULL) { - struct stat hstat; + while (fgets (buffer, BUF_4K, extfsd) != NULL) + { + struct stat hstat; - current_link_name = NULL; - if (vfs_parse_ls_lga (buffer, &hstat, - ¤t_file_name, ¤t_link_name)) { - struct entry *entry, *pent; - struct inode *inode; - char *p, *q, *cfn = current_file_name; + current_link_name = NULL; + if (vfs_parse_ls_lga (buffer, &hstat, ¤t_file_name, ¤t_link_name)) + { + struct entry *entry, *pent; + struct inode *inode; + char *p, *q, *cfn = current_file_name; - if (*cfn != '\0') { - if (*cfn == PATH_SEP) - cfn++; - p = strchr (cfn, '\0'); - if (p != cfn && *(p - 1) == PATH_SEP) - *(p - 1) = '\0'; - p = strrchr (cfn, PATH_SEP); - if (p == NULL) { - p = cfn; - q = strchr (cfn, '\0'); - } else { - *(p++) = '\0'; - q = cfn; - } - if (S_ISDIR (hstat.st_mode) - && (strcmp (p, ".") || !strcmp (p, "..") == 0)) - goto read_extfs_continue; - pent = extfs_find_entry (current_archive->root_entry, - q, TRUE, FALSE); - if (pent == NULL) { - /* FIXME: Should clean everything one day */ - g_free (buffer); - pclose (extfsd); - close_error_pipe (D_ERROR, _("Inconsistent extfs archive")); - return -1; - } - entry = g_new (struct entry, 1); - entry->name = g_strdup (p); - entry->next_in_dir = NULL; - entry->dir = pent; - if (pent->inode->last_in_subdir) { - pent->inode->last_in_subdir->next_in_dir = entry; - pent->inode->last_in_subdir = entry; - } - if (!S_ISLNK (hstat.st_mode) && (current_link_name != NULL)) { - pent = extfs_find_entry (current_archive->root_entry, - current_link_name, FALSE, FALSE); - if (pent == NULL) { - /* FIXME: Should clean everything one day */ - g_free (buffer); - pclose (extfsd); - close_error_pipe (D_ERROR, - _("Inconsistent extfs archive")); - return -1; - } + if (*cfn != '\0') + { + if (*cfn == PATH_SEP) + cfn++; + p = strchr (cfn, '\0'); + if (p != cfn && *(p - 1) == PATH_SEP) + *(p - 1) = '\0'; + p = strrchr (cfn, PATH_SEP); + if (p == NULL) + { + p = cfn; + q = strchr (cfn, '\0'); + } + else + { + *(p++) = '\0'; + q = cfn; + } + if (S_ISDIR (hstat.st_mode) && (strcmp (p, ".") || !strcmp (p, "..") == 0)) + goto read_extfs_continue; + pent = extfs_find_entry (current_archive->root_entry, q, TRUE, FALSE); + if (pent == NULL) + { + /* FIXME: Should clean everything one day */ + g_free (buffer); + pclose (extfsd); + close_error_pipe (D_ERROR, _("Inconsistent extfs archive")); + return -1; + } + entry = g_new (struct entry, 1); + entry->name = g_strdup (p); + entry->next_in_dir = NULL; + entry->dir = pent; + if (pent->inode->last_in_subdir) + { + pent->inode->last_in_subdir->next_in_dir = entry; + pent->inode->last_in_subdir = entry; + } + if (!S_ISLNK (hstat.st_mode) && (current_link_name != NULL)) + { + pent = extfs_find_entry (current_archive->root_entry, + current_link_name, FALSE, FALSE); + if (pent == NULL) + { + /* FIXME: Should clean everything one day */ + g_free (buffer); + pclose (extfsd); + close_error_pipe (D_ERROR, _("Inconsistent extfs archive")); + return -1; + } - entry->inode = pent->inode; - pent->inode->nlink++; - } else { - inode = g_new (struct inode, 1); - entry->inode = inode; - inode->local_filename = NULL; - inode->inode = (current_archive->inode_counter)++; - inode->nlink = 1; - inode->dev = current_archive->rdev; - inode->archive = current_archive; - inode->mode = hstat.st_mode; + entry->inode = pent->inode; + pent->inode->nlink++; + } + else + { + inode = g_new (struct inode, 1); + entry->inode = inode; + inode->local_filename = NULL; + inode->inode = (current_archive->inode_counter)++; + inode->nlink = 1; + inode->dev = current_archive->rdev; + inode->archive = current_archive; + inode->mode = hstat.st_mode; #ifdef HAVE_STRUCT_STAT_ST_RDEV - inode->rdev = hstat.st_rdev; + inode->rdev = hstat.st_rdev; #else - inode->rdev = 0; + inode->rdev = 0; #endif - inode->uid = hstat.st_uid; - inode->gid = hstat.st_gid; - inode->size = hstat.st_size; - inode->mtime = hstat.st_mtime; - inode->atime = hstat.st_atime; - inode->ctime = hstat.st_ctime; - inode->first_in_subdir = NULL; - inode->last_in_subdir = NULL; - if (current_link_name != NULL - && S_ISLNK (hstat.st_mode)) { - inode->linkname = current_link_name; - current_link_name = NULL; - } else { - if (S_ISLNK (hstat.st_mode)) - inode->mode &= ~S_IFLNK; /* You *DON'T* want to do this always */ - inode->linkname = NULL; - } - if (S_ISDIR (hstat.st_mode)) - extfs_make_dots (entry); - } - } -read_extfs_continue: - g_free (current_file_name); - g_free (current_link_name); - } + inode->uid = hstat.st_uid; + inode->gid = hstat.st_gid; + inode->size = hstat.st_size; + inode->mtime = hstat.st_mtime; + inode->atime = hstat.st_atime; + inode->ctime = hstat.st_ctime; + inode->first_in_subdir = NULL; + inode->last_in_subdir = NULL; + if (current_link_name != NULL && S_ISLNK (hstat.st_mode)) + { + inode->linkname = current_link_name; + current_link_name = NULL; + } + else + { + if (S_ISLNK (hstat.st_mode)) + inode->mode &= ~S_IFLNK; /* You *DON'T* want to do this always */ + inode->linkname = NULL; + } + if (S_ISDIR (hstat.st_mode)) + extfs_make_dots (entry); + } + } + read_extfs_continue: + g_free (current_file_name); + g_free (current_link_name); + } } g_free (buffer); /* Check if extfs 'list' returned 0 */ - if (pclose (extfsd) != 0) { - extfs_free (current_archive); - close_error_pipe (D_ERROR, _("Inconsistent extfs archive")); - return -1; + if (pclose (extfsd) != 0) + { + extfs_free (current_archive); + close_error_pipe (D_ERROR, _("Inconsistent extfs archive")); + return -1; } close_error_pipe (D_ERROR, NULL); @@ -552,7 +587,8 @@ extfs_which (struct vfs_class *me, const char *path) (void) me; - for (i = 0; i < extfs_plugins->len; i++) { + for (i = 0; i < extfs_plugins->len; i++) + { extfs_plugin_info_t *info; info = &g_array_index (extfs_plugins, extfs_plugin_info_t, i); @@ -568,7 +604,7 @@ extfs_which (struct vfs_class *me, const char *path) */ static char * extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **archive, - gboolean do_not_open) + gboolean do_not_open) { char *local, *op; const char *archive_name; @@ -582,28 +618,29 @@ extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **arch fstype = extfs_which (me, op); if (fstype == -1) - return NULL; + return NULL; if (local == NULL) - local = inname + strlen (inname); + local = inname + strlen (inname); /* * All filesystems should have some local archive, at least * it can be PATH_SEP ('/'). */ for (parc = first_archive; parc != NULL; parc = parc->next) - if (parc->name != NULL) { - if (strcmp (parc->name, archive_name) == 0) { - vfs_stamp (&vfs_extfs_ops, (vfsid) parc); - goto return_success; - } - } + if (parc->name != NULL) + { + if (strcmp (parc->name, archive_name) == 0) + { + vfs_stamp (&vfs_extfs_ops, (vfsid) parc); + goto return_success; + } + } - result = do_not_open ? -1 : extfs_read_archive (fstype, archive_name, - &parc); + result = do_not_open ? -1 : extfs_read_archive (fstype, archive_name, &parc); if (result == -1) - ERRNOR (EIO, NULL); + ERRNOR (EIO, NULL); -return_success: + return_success: *archive = parc; return local; } @@ -614,7 +651,7 @@ return_success: */ static char * extfs_get_path (struct vfs_class *me, const char *inname, - struct archive **archive, gboolean do_not_open) + struct archive **archive, gboolean do_not_open) { char *buf, *res, *res2; @@ -633,37 +670,40 @@ extfs_get_path_from_entry (struct entry *entry) localpath = g_string_new (""); - while (entry->dir != NULL) { - g_string_prepend (localpath, entry->name); - if (entry->dir->dir != NULL) - g_string_prepend_c (localpath, PATH_SEP); - entry = entry->dir; + while (entry->dir != NULL) + { + g_string_prepend (localpath, entry->name); + if (entry->dir->dir != NULL) + g_string_prepend_c (localpath, PATH_SEP); + entry = entry->dir; } return g_string_free (localpath, FALSE); } static struct entry * -extfs_resolve_symlinks_int (struct entry *entry, GSList *list) +extfs_resolve_symlinks_int (struct entry *entry, GSList * list) { struct entry *pent = NULL; if (!S_ISLNK (entry->inode->mode)) - return entry; + return entry; - if (g_slist_find (list, entry) != NULL) { - /* Here we protect us against symlink looping */ - errloop = TRUE; - } else { - GSList *looping; + if (g_slist_find (list, entry) != NULL) + { + /* Here we protect us against symlink looping */ + errloop = TRUE; + } + else + { + GSList *looping; - looping = g_slist_prepend (list, entry); - pent = extfs_find_entry_int (entry->dir, entry->inode->linkname, - looping, FALSE, FALSE); - g_free (looping); /* It is OK here, no any leaks */ + looping = g_slist_prepend (list, entry); + pent = extfs_find_entry_int (entry->dir, entry->inode->linkname, looping, FALSE, FALSE); + g_free (looping); /* It is OK here, no any leaks */ - if (pent == NULL) - my_errno = ENOENT; + if (pent == NULL) + my_errno = ENOENT; } return pent; @@ -677,11 +717,12 @@ extfs_resolve_symlinks (struct entry *entry) errloop = FALSE; notadir = FALSE; res = extfs_resolve_symlinks_int (entry, NULL); - if (res == NULL) { - if (errloop) - my_errno = ELOOP; - else if (notadir) - my_errno = ENOTDIR; + if (res == NULL) + { + if (errloop) + my_errno = ELOOP; + else if (notadir) + my_errno = ENOTDIR; } return res; } @@ -692,20 +733,20 @@ extfs_get_archive_name (struct archive *archive) const char *archive_name; if (archive->local_name) - archive_name = archive->local_name; + archive_name = archive->local_name; else - archive_name = archive->name; + archive_name = archive->name; if (!archive_name || !*archive_name) - return "no_archive_name"; + return "no_archive_name"; else - return archive_name; + return archive_name; } /* Don't pass localname as NULL */ static int extfs_cmd (const char *str_extfs_cmd, struct archive *archive, - struct entry *entry, const char *localname) + struct entry *entry, const char *localname) { char *file; char *quoted_file; @@ -723,8 +764,7 @@ extfs_cmd (const char *str_extfs_cmd, struct archive *archive, quoted_localname = name_quote (localname, 0); info = &g_array_index (extfs_plugins, extfs_plugin_info_t, archive->fstype); cmd = g_strconcat (info->path, info->prefix, str_extfs_cmd, - archive_name, " ", quoted_file, " ", - quoted_localname, (char *) NULL); + archive_name, " ", quoted_file, " ", quoted_localname, (char *) NULL); g_free (quoted_file); g_free (quoted_localname); g_free (archive_name); @@ -746,14 +786,13 @@ extfs_run (struct vfs_class *me, const char *file) p = extfs_get_path (me, file, &archive, FALSE); if (p == NULL) - return; + return; q = name_quote (p, 0); g_free (p); archive_name = name_quote (extfs_get_archive_name (archive), 0); info = &g_array_index (extfs_plugins, extfs_plugin_info_t, archive->fstype); - cmd = g_strconcat (info->path, info->prefix, - " run ", archive_name, " ", q, (char *) NULL); + cmd = g_strconcat (info->path, info->prefix, " run ", archive_name, " ", q, (char *) NULL); g_free (archive_name); g_free (q); shell_execute (cmd, 0); @@ -772,53 +811,57 @@ extfs_open (struct vfs_class *me, const char *file, int flags, int mode) q = extfs_get_path (me, file, &archive, FALSE); if (q == NULL) - return NULL; + return NULL; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); - if ((entry == NULL) && ((flags & O_CREAT) != 0)) { - /* Create new entry */ - entry = extfs_find_entry (archive->root_entry, q, FALSE, TRUE); - created = (entry != NULL); + if ((entry == NULL) && ((flags & O_CREAT) != 0)) + { + /* Create new entry */ + entry = extfs_find_entry (archive->root_entry, q, FALSE, TRUE); + created = (entry != NULL); } g_free (q); if (entry == NULL) - return NULL; + return NULL; entry = extfs_resolve_symlinks (entry); if (entry == NULL) - return NULL; + return NULL; if (S_ISDIR (entry->inode->mode)) - ERRNOR (EISDIR, NULL); + ERRNOR (EISDIR, NULL); - if (entry->inode->local_filename == NULL) { - char *local_filename; + if (entry->inode->local_filename == NULL) + { + char *local_filename; - local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name); + local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name); - if (local_handle == -1) - return NULL; - close (local_handle); + if (local_handle == -1) + return NULL; + close (local_handle); - if (!created && ((flags & O_TRUNC) == 0) - && extfs_cmd (" copyout ", archive, entry, local_filename)) { - unlink (local_filename); - g_free (local_filename); - my_errno = EIO; - return NULL; - } - entry->inode->local_filename = local_filename; + if (!created && ((flags & O_TRUNC) == 0) + && extfs_cmd (" copyout ", archive, entry, local_filename)) + { + unlink (local_filename); + g_free (local_filename); + my_errno = EIO; + return NULL; + } + entry->inode->local_filename = local_filename; } local_handle = open (entry->inode->local_filename, NO_LINEAR (flags), mode); - if (local_handle == -1) { - /* file exists(may be). Need to drop O_CREAT flag and truncate file content */ - flags = ~O_CREAT & (NO_LINEAR (flags)|O_TRUNC); - local_handle = open (entry->inode->local_filename, flags, mode); + if (local_handle == -1) + { + /* file exists(may be). Need to drop O_CREAT flag and truncate file content */ + flags = ~O_CREAT & (NO_LINEAR (flags) | O_TRUNC); + local_handle = open (entry->inode->local_filename, flags, mode); } if (local_handle == -1) - ERRNOR (EIO, NULL); + ERRNOR (EIO, NULL); extfs_info = g_new (struct pseudofile, 1); extfs_info->archive = archive; @@ -850,27 +893,27 @@ extfs_close (void *data) close (file->local_handle); /* Commit the file if it has changed */ - if (file->has_changed) { - struct stat file_status; + if (file->has_changed) + { + struct stat file_status; - if (extfs_cmd (" copyin ", file->archive, file->entry, - file->entry->inode->local_filename)) - errno_code = EIO; + if (extfs_cmd (" copyin ", file->archive, file->entry, file->entry->inode->local_filename)) + errno_code = EIO; - if (stat (file->entry->inode->local_filename, &file_status) != 0) - errno_code = EIO; - else - file->entry->inode->size = file_status.st_size; + if (stat (file->entry->inode->local_filename, &file_status) != 0) + errno_code = EIO; + else + file->entry->inode->size = file_status.st_size; - file->entry->inode->mtime = time (NULL); + file->entry->inode->mtime = time (NULL); } if (--file->archive->fd_usage == 0) - vfs_stamp_create (&vfs_extfs_ops, file->archive); + vfs_stamp_create (&vfs_extfs_ops, file->archive); g_free (data); if (errno_code != 0) - ERRNOR (EIO, -1); + ERRNOR (EIO, -1); return 0; } @@ -891,16 +934,16 @@ extfs_opendir (struct vfs_class *me, const char *dirname) q = extfs_get_path (me, dirname, &archive, FALSE); if (q == NULL) - return NULL; + return NULL; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); g_free (q); if (entry == NULL) - return NULL; + return NULL; entry = extfs_resolve_symlinks (entry); if (entry == NULL) - return NULL; + return NULL; if (!S_ISDIR (entry->inode->mode)) - ERRNOR (ENOTDIR, NULL); + ERRNOR (ENOTDIR, NULL); info = g_new (struct entry *, 2); info[0] = entry->inode->first_in_subdir; @@ -910,13 +953,13 @@ extfs_opendir (struct vfs_class *me, const char *dirname) } static void * -extfs_readdir(void *data) +extfs_readdir (void *data) { static union vfs_dirent dir; struct entry **info = (struct entry **) data; if (*info == NULL) - return NULL; + return NULL; g_strlcpy (dir.dent.d_name, (*info)->name, MC_MAXPATHLEN); @@ -960,8 +1003,7 @@ extfs_stat_move (struct stat *buf, const struct inode *inode) } static int -extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, - gboolean resolve) +extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, gboolean resolve) { struct archive *archive; char *q, *mpath; @@ -976,14 +1018,15 @@ extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); if (entry == NULL) goto cleanup; - if (resolve) { - entry = extfs_resolve_symlinks (entry); - if (entry == NULL) - goto cleanup; + if (resolve) + { + entry = extfs_resolve_symlinks (entry); + if (entry == NULL) + goto cleanup; } extfs_stat_move (buf, entry->inode); result = 0; -cleanup: + cleanup: g_free (mpath); return result; } @@ -1021,22 +1064,23 @@ extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) mpath = g_strdup (path); q = extfs_get_path_mangle (me, mpath, &archive, FALSE); - if (q == NULL) - goto cleanup; + if (q == NULL) + goto cleanup; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); if (entry == NULL) goto cleanup; - if (!S_ISLNK (entry->inode->mode)) { - me->verrno = EINVAL; - goto cleanup; + if (!S_ISLNK (entry->inode->mode)) + { + me->verrno = EINVAL; + goto cleanup; } len = strlen (entry->inode->linkname); if (size < len) - len = size; + len = size; /* readlink() does not append a NUL character to buf */ result = len; memcpy (buf, entry->inode->linkname, result); -cleanup: + cleanup: g_free (mpath); return result; } @@ -1081,24 +1125,26 @@ extfs_unlink (struct vfs_class *me, const char *file) q = extfs_get_path_mangle (me, mpath, &archive, FALSE); if (q == NULL) - goto cleanup; + goto cleanup; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); if (entry == NULL) goto cleanup; entry = extfs_resolve_symlinks (entry); if (entry == NULL) goto cleanup; - if (S_ISDIR (entry->inode->mode)) { - me->verrno = EISDIR; - goto cleanup; + if (S_ISDIR (entry->inode->mode)) + { + me->verrno = EISDIR; + goto cleanup; } - if (extfs_cmd (" rm ", archive, entry, "")) { + if (extfs_cmd (" rm ", archive, entry, "")) + { my_errno = EIO; goto cleanup; } extfs_remove_entry (entry); result = 0; -cleanup: + cleanup: g_free (mpath); return result; } @@ -1117,11 +1163,12 @@ extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode) q = extfs_get_path_mangle (me, mpath, &archive, FALSE); if (q == NULL) - goto cleanup; + goto cleanup; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); - if (entry != NULL) { - me->verrno = EEXIST; - goto cleanup; + if (entry != NULL) + { + me->verrno = EEXIST; + goto cleanup; } entry = extfs_find_entry (archive->root_entry, q, TRUE, FALSE); if (entry == NULL) @@ -1129,18 +1176,20 @@ extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode) entry = extfs_resolve_symlinks (entry); if (entry == NULL) goto cleanup; - if (!S_ISDIR (entry->inode->mode)) { - me->verrno = ENOTDIR; - goto cleanup; + if (!S_ISDIR (entry->inode->mode)) + { + me->verrno = ENOTDIR; + goto cleanup; } - if (extfs_cmd (" mkdir ", archive, entry, "")) { - my_errno = EIO; - extfs_remove_entry (entry); - goto cleanup; + if (extfs_cmd (" mkdir ", archive, entry, "")) + { + my_errno = EIO; + extfs_remove_entry (entry); + goto cleanup; } result = 0; -cleanup: + cleanup: g_free (mpath); return result; } @@ -1157,25 +1206,27 @@ extfs_rmdir (struct vfs_class *me, const char *path) q = extfs_get_path_mangle (me, mpath, &archive, FALSE); if (q == NULL) - goto cleanup; + goto cleanup; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); if (entry == NULL) - goto cleanup; + goto cleanup; entry = extfs_resolve_symlinks (entry); if (entry == NULL) - goto cleanup; - if (!S_ISDIR (entry->inode->mode)) { - me->verrno = ENOTDIR; - goto cleanup; + goto cleanup; + if (!S_ISDIR (entry->inode->mode)) + { + me->verrno = ENOTDIR; + goto cleanup; } - if (extfs_cmd (" rmdir ", archive, entry, "")) { + if (extfs_cmd (" rmdir ", archive, entry, "")) + { my_errno = EIO; goto cleanup; } extfs_remove_entry (entry); result = 0; -cleanup: + cleanup: g_free (mpath); return result; } @@ -1190,14 +1241,14 @@ extfs_chdir (struct vfs_class *me, const char *path) my_errno = ENOTDIR; q = extfs_get_path (me, path, &archive, FALSE); if (q == NULL) - return -1; + return -1; entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); g_free (q); if (entry == NULL) - return -1; + return -1; entry = extfs_resolve_symlinks (entry); if ((entry == NULL) || (!S_ISDIR (entry->inode->mode))) - return -1; + return -1; my_errno = 0; return 0; } @@ -1218,7 +1269,7 @@ extfs_getid (struct vfs_class *me, const char *path) p = extfs_get_path (me, path, &archive, TRUE); if (p == NULL) - return NULL; + return NULL; g_free (p); return (vfsid) archive; } @@ -1235,29 +1286,32 @@ extfs_remove_entry (struct entry *e) int i = --e->inode->nlink; struct entry *pe, *ent, *prev; - if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) { + if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) + { struct entry *f = e->inode->first_in_subdir; e->inode->first_in_subdir = NULL; - extfs_remove_entry (f); + extfs_remove_entry (f); } pe = e->dir; if (e == pe->inode->first_in_subdir) - pe->inode->first_in_subdir = e->next_in_dir; + pe->inode->first_in_subdir = e->next_in_dir; prev = NULL; - for (ent = pe->inode->first_in_subdir; ent && ent->next_in_dir; - ent = ent->next_in_dir) - if (e == ent->next_in_dir) { - prev = ent; - break; - } + for (ent = pe->inode->first_in_subdir; ent && ent->next_in_dir; ent = ent->next_in_dir) + if (e == ent->next_in_dir) + { + prev = ent; + break; + } if (prev) - prev->next_in_dir = e->next_in_dir; + prev->next_in_dir = e->next_in_dir; if (e == pe->inode->last_in_subdir) - pe->inode->last_in_subdir = prev; + pe->inode->last_in_subdir = prev; - if (i <= 0) { - if (e->inode->local_filename != NULL) { + if (i <= 0) + { + if (e->inode->local_filename != NULL) + { unlink (e->inode->local_filename); g_free (e->inode->local_filename); } @@ -1274,14 +1328,17 @@ extfs_free_entry (struct entry *e) { int i = --e->inode->nlink; - if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) { + if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) + { struct entry *f = e->inode->first_in_subdir; e->inode->first_in_subdir = NULL; extfs_free_entry (f); } - if (i <= 0) { - if (e->inode->local_filename != NULL) { + if (i <= 0) + { + if (e->inode->local_filename != NULL) + { unlink (e->inode->local_filename); g_free (e->inode->local_filename); } @@ -1299,12 +1356,16 @@ extfs_free (vfsid id) { struct archive *archive = (struct archive *) id; - if (archive == first_archive) { + if (archive == first_archive) + { first_archive = archive->next; - } else { + } + else + { struct archive *parc; for (parc = first_archive; parc != NULL; parc = parc->next) - if (parc->next == archive) { + if (parc->next == archive) + { parc->next = archive->next; break; } @@ -1320,10 +1381,11 @@ extfs_getlocalcopy (struct vfs_class *me, const char *path) fp = (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0); if (fp == NULL) - return NULL; - if (fp->entry->inode->local_filename == NULL) { - extfs_close ((void *) fp); - return NULL; + return NULL; + if (fp->entry->inode->local_filename == NULL) + { + extfs_close ((void *) fp); + return NULL; } p = g_strdup (fp->entry->inode->local_filename); fp->archive->fd_usage++; @@ -1332,25 +1394,27 @@ extfs_getlocalcopy (struct vfs_class *me, const char *path) } static int -extfs_ungetlocalcopy (struct vfs_class *me, const char *path, - const char *local, int has_changed) +extfs_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed) { struct pseudofile *fp; fp = (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0); if (fp == NULL) - return 0; + return 0; - if (strcmp (fp->entry->inode->local_filename, local) == 0) { - fp->archive->fd_usage--; - if (has_changed != 0) - fp->has_changed = TRUE; - extfs_close ((void *) fp); - return 0; - } else { - /* Should not happen */ - extfs_close ((void *) fp); - return 0; + if (strcmp (fp->entry->inode->local_filename, local) == 0) + { + fp->archive->fd_usage--; + if (has_changed != 0) + fp->has_changed = TRUE; + extfs_close ((void *) fp); + return 0; + } + else + { + /* Should not happen */ + extfs_close ((void *) fp); + return 0; } } @@ -1367,73 +1431,81 @@ extfs_get_plugins (const char *where, gboolean silent) /* We may not use vfs_die() message or message or similar, * UI is not initialized at this time and message would not * appear on screen. */ - if (dir == NULL) { - if (!silent) - fprintf (stderr, _("Warning: cannot open %s directory\n"), dirname); - g_free (dirname); - return FALSE; + if (dir == NULL) + { + if (!silent) + fprintf (stderr, _("Warning: cannot open %s directory\n"), dirname); + g_free (dirname); + return FALSE; } if (extfs_plugins == NULL) - extfs_plugins = g_array_sized_new (FALSE, TRUE, sizeof (extfs_plugin_info_t), 32); + extfs_plugins = g_array_sized_new (FALSE, TRUE, sizeof (extfs_plugin_info_t), 32); - while ((filename = g_dir_read_name (dir)) != NULL) { - char fullname[MC_MAXPATHLEN]; - struct stat s; + while ((filename = g_dir_read_name (dir)) != NULL) + { + char fullname[MC_MAXPATHLEN]; + struct stat s; - g_snprintf (fullname, sizeof (fullname), "%s" PATH_SEP_STR "%s", dirname, filename); + g_snprintf (fullname, sizeof (fullname), "%s" PATH_SEP_STR "%s", dirname, filename); - if ((stat (fullname, &s) == 0) - && S_ISREG (s.st_mode) && !S_ISDIR (s.st_mode) - && (((s.st_mode & S_IXOTH) != 0) || - ((s.st_mode & S_IXUSR) != 0) || - ((s.st_mode & S_IXGRP) != 0))) { - int f; + if ((stat (fullname, &s) == 0) + && S_ISREG (s.st_mode) && !S_ISDIR (s.st_mode) + && (((s.st_mode & S_IXOTH) != 0) || + ((s.st_mode & S_IXUSR) != 0) || ((s.st_mode & S_IXGRP) != 0))) + { + int f; - f = open (fullname, O_RDONLY); + f = open (fullname, O_RDONLY); - if (f > 0) { - size_t len, i; - extfs_plugin_info_t info; - gboolean found = FALSE; + if (f > 0) + { + size_t len, i; + extfs_plugin_info_t info; + gboolean found = FALSE; - close (f); + close (f); - /* Handle those with a trailing '+', those flag that the - * file system does not require an archive to work - */ - len = strlen (filename); - if (filename [len - 1] != '+') - info.need_archive = TRUE; - else { - info.need_archive = FALSE; - len--; - } + /* Handle those with a trailing '+', those flag that the + * file system does not require an archive to work + */ + len = strlen (filename); + if (filename[len - 1] != '+') + info.need_archive = TRUE; + else + { + info.need_archive = FALSE; + len--; + } - info.path = g_strconcat (dirname, PATH_SEP_STR, (char *) NULL); - info.prefix = g_strndup (filename, len); + info.path = g_strconcat (dirname, PATH_SEP_STR, (char *) NULL); + info.prefix = g_strndup (filename, len); - /* don't overload already found plugin */ - for (i = 0; i < extfs_plugins->len; i++) { - extfs_plugin_info_t *p; + /* don't overload already found plugin */ + for (i = 0; i < extfs_plugins->len; i++) + { + extfs_plugin_info_t *p; - p = &g_array_index (extfs_plugins, extfs_plugin_info_t, i); + p = &g_array_index (extfs_plugins, extfs_plugin_info_t, i); - /* 2 files with same names cannot be in a directory */ - if ((strcmp (info.path, p->path) != 0) - && (strcmp (info.prefix, p->prefix) == 0)) { - found = TRUE; - break; - } - } + /* 2 files with same names cannot be in a directory */ + if ((strcmp (info.path, p->path) != 0) + && (strcmp (info.prefix, p->prefix) == 0)) + { + found = TRUE; + break; + } + } - if (found) { - g_free (info.path); - g_free (info.prefix); - } else - g_array_append_val (extfs_plugins, info); - } - } + if (found) + { + g_free (info.path); + g_free (info.prefix); + } + else + g_array_append_val (extfs_plugins, info); + } + } } g_dir_close (dir); @@ -1453,7 +1525,7 @@ extfs_init (struct vfs_class *me) /* 1st: scan user directory */ dirname = g_build_path (PATH_SEP_STR, home_dir, MC_USERCONF_DIR, (char *) NULL); - d1 = extfs_get_plugins (dirname, TRUE); /* silent about user dir */ + d1 = extfs_get_plugins (dirname, TRUE); /* silent about user dir */ g_free (dirname); /* 2nd: scan system dir */ d2 = extfs_get_plugins (LIBEXECDIR, d1); @@ -1469,17 +1541,19 @@ extfs_done (struct vfs_class *me) (void) me; - for (ar = first_archive; ar != NULL;) { - extfs_free ((vfsid) ar); - ar = first_archive; + for (ar = first_archive; ar != NULL;) + { + extfs_free ((vfsid) ar); + ar = first_archive; } - for (i = 0; i < extfs_plugins->len; i++) { - extfs_plugin_info_t *info; + for (i = 0; i < extfs_plugins->len; i++) + { + extfs_plugin_info_t *info; - info = &g_array_index (extfs_plugins, extfs_plugin_info_t, i); - g_free (info->path); - g_free (info->prefix); + info = &g_array_index (extfs_plugins, extfs_plugin_info_t, i); + g_free (info->path); + g_free (info->prefix); } g_array_free (extfs_plugins, TRUE); } @@ -1489,9 +1563,10 @@ extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg) { (void) arg; - if (ctlop == VFS_SETCTL_RUN) { - extfs_run (me, path); - return 1; + if (ctlop == VFS_SETCTL_RUN) + { + extfs_run (me, path); + return 1; } return 0; } diff --git a/lib/vfs/mc-vfs/undelfs.c b/lib/vfs/mc-vfs/undelfs.c index e460ee3b9..fba0f83cb 100644 --- a/lib/vfs/mc-vfs/undelfs.c +++ b/lib/vfs/mc-vfs/undelfs.c @@ -5,18 +5,18 @@ Parts of this program were taken from the lsdel.c and dump.c files written by Ted Ts'o (tytso@mit.edu) for the ext2fs package. - + Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. Written by: 1995 Miguel de Icaza. - 1997 Norbert Warmuth. - 2000 Pavel Machek - + 1997 Norbert Warmuth. + 2000 Pavel Machek + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -37,7 +37,7 @@ * because we would have to provide an io_manager for the ext2fs tools, * and I don't think it would be too useful to undelete files */ - + #include #include @@ -57,35 +57,37 @@ #include #include "lib/global.h" -#include "src/wtools.h" /* message() */ -#include "src/main.h" /* print_vfs_message */ +#include "src/wtools.h" /* message() */ +#include "src/main.h" /* print_vfs_message */ #include "utilvfs.h" #include "vfs.h" #include "vfs-impl.h" -struct deleted_info { - ext2_ino_t ino; +struct deleted_info +{ + ext2_ino_t ino; unsigned short mode; unsigned short uid; unsigned short gid; unsigned long size; - time_t dtime; - int num_blocks; - int free_blocks; + time_t dtime; + int num_blocks; + int free_blocks; }; -struct lsdel_struct { - ext2_ino_t inode; - int num_blocks; - int free_blocks; - int bad_blocks; +struct lsdel_struct +{ + ext2_ino_t inode; + int num_blocks; + int free_blocks; + int bad_blocks; }; /* We only allow one opened ext2fs */ static char *ext2_fname; static ext2_filsys fs = NULL; -static struct lsdel_struct lsd; -static struct deleted_info *delarray; +static struct lsdel_struct lsd; +static struct deleted_info *delarray; static int num_delarray, max_delarray; static char *block_buf; static const char *undelfserr = N_(" undelfs: error "); @@ -100,7 +102,7 @@ static void undelfs_shutdown (void) { if (fs) - ext2fs_close (fs); + ext2fs_close (fs); fs = NULL; g_free (ext2_fname); ext2_fname = NULL; @@ -118,39 +120,41 @@ undelfs_get_path (const char *dirname, char **fsname, char **file) /* To look like filesystem, we have virtual directories /#undel:XXX, which have no subdirectories. XXX is replaced with hda5, sdb8 etc, which is assumed to live under /dev. - -- pavel@ucw.cz */ + -- pavel@ucw.cz */ *fsname = NULL; if (strncmp (dirname, "/#undel:", 8)) - return; + return; dirname += 8; /* Since we don't allow subdirectories, it's easy to get a filename, * just scan backwards for a slash */ if (*dirname == 0) - return; - + return; + p = dirname + strlen (dirname); #if 0 /* Strip trailing ./ */ - if (p - dirname > 2 && *(p-1) == '/' && *(p-2) == '.') - *(p = p-2) = 0; + if (p - dirname > 2 && *(p - 1) == '/' && *(p - 2) == '.') + *(p = p - 2) = 0; #endif - - while (p > dirname){ - if (*p == '/'){ - char *tmp; - *file = g_strdup (p+1); - tmp = g_strndup (dirname, p - dirname); - *fsname = g_strconcat ("/dev/", tmp, (char *) NULL); - g_free (tmp); - return; - } - p--; + while (p > dirname) + { + if (*p == '/') + { + char *tmp; + + *file = g_strdup (p + 1); + tmp = g_strndup (dirname, p - dirname); + *fsname = g_strconcat ("/dev/", tmp, (char *) NULL); + g_free (tmp); + return; + } + p--; } *file = g_strdup (""); *fsname = g_strconcat ("/dev/", dirname, (char *) NULL); @@ -158,21 +162,21 @@ undelfs_get_path (const char *dirname, char **fsname, char **file) } static int -undelfs_lsdel_proc(ext2_filsys _fs, blk_t *block_nr, int blockcnt, void *private) +undelfs_lsdel_proc (ext2_filsys _fs, blk_t * block_nr, int blockcnt, void *private) { struct lsdel_struct *_lsd = (struct lsdel_struct *) private; (void) blockcnt; _lsd->num_blocks++; - - if (*block_nr < _fs->super->s_first_data_block || - *block_nr >= _fs->super->s_blocks_count) { - _lsd->bad_blocks++; - return BLOCK_ABORT; + + if (*block_nr < _fs->super->s_first_data_block || *block_nr >= _fs->super->s_blocks_count) + { + _lsd->bad_blocks++; + return BLOCK_ABORT; } - - if (!ext2fs_test_block_bitmap(_fs->block_map,*block_nr)) - _lsd->free_blocks++; - + + if (!ext2fs_test_block_bitmap (_fs->block_map, *block_nr)) + _lsd->free_blocks++; + return 0; } @@ -191,84 +195,84 @@ undelfs_loaddel (void) max_delarray = 100; num_delarray = 0; delarray = g_try_malloc (sizeof (struct deleted_info) * max_delarray); - if (!delarray) { - message (D_ERROR, undelfserr, _(" not enough memory ")); - return 0; + if (!delarray) + { + message (D_ERROR, undelfserr, _(" not enough memory ")); + return 0; } block_buf = g_try_malloc (fs->blocksize * 3); - if (!block_buf) { - message (D_ERROR, undelfserr, _(" while allocating block buffer ")); - goto free_delarray; + if (!block_buf) + { + message (D_ERROR, undelfserr, _(" while allocating block buffer ")); + goto free_delarray; } - if ((retval = ext2fs_open_inode_scan (fs, 0, &scan))) { - message (D_ERROR, undelfserr, _(" open_inode_scan: %d "), retval); - goto free_block_buf; + if ((retval = ext2fs_open_inode_scan (fs, 0, &scan))) + { + message (D_ERROR, undelfserr, _(" open_inode_scan: %d "), retval); + goto free_block_buf; } - if ((retval = ext2fs_get_next_inode (scan, &ino, &inode))) { - message (D_ERROR, undelfserr, _(" while starting inode scan %d "), - retval); - goto error_out; + if ((retval = ext2fs_get_next_inode (scan, &ino, &inode))) + { + message (D_ERROR, undelfserr, _(" while starting inode scan %d "), retval); + goto error_out; } count = 0; - while (ino) { - if ((count++ % 1024) == 0) - print_vfs_message (_ - ("undelfs: loading deleted files information %d inodes"), - count); - if (inode.i_dtime == 0) - goto next; + while (ino) + { + if ((count++ % 1024) == 0) + print_vfs_message (_("undelfs: loading deleted files information %d inodes"), count); + if (inode.i_dtime == 0) + goto next; - if (S_ISDIR (inode.i_mode)) - goto next; + if (S_ISDIR (inode.i_mode)) + goto next; - lsd.inode = ino; - lsd.num_blocks = 0; - lsd.free_blocks = 0; - lsd.bad_blocks = 0; + lsd.inode = ino; + lsd.num_blocks = 0; + lsd.free_blocks = 0; + lsd.bad_blocks = 0; - retval = - ext2fs_block_iterate (fs, ino, 0, block_buf, - undelfs_lsdel_proc, &lsd); - if (retval) { - message (D_ERROR, undelfserr, - _(" while calling ext2_block_iterate %d "), retval); - goto next; - } - if (lsd.free_blocks && !lsd.bad_blocks) { - if (num_delarray >= max_delarray) { - struct deleted_info *delarray_new = - g_try_realloc (delarray, - sizeof (struct deleted_info) * - (max_delarray + 50)); - if (!delarray_new) { - message (D_ERROR, undelfserr, - _ - (" no more memory while reallocating array ")); - goto error_out; - } - delarray = delarray_new; - max_delarray += 50; - } + retval = ext2fs_block_iterate (fs, ino, 0, block_buf, undelfs_lsdel_proc, &lsd); + if (retval) + { + message (D_ERROR, undelfserr, _(" while calling ext2_block_iterate %d "), retval); + goto next; + } + if (lsd.free_blocks && !lsd.bad_blocks) + { + if (num_delarray >= max_delarray) + { + struct deleted_info *delarray_new = g_try_realloc (delarray, + sizeof (struct deleted_info) * + (max_delarray + 50)); + if (!delarray_new) + { + message (D_ERROR, undelfserr, _(" no more memory while reallocating array ")); + goto error_out; + } + delarray = delarray_new; + max_delarray += 50; + } - delarray[num_delarray].ino = ino; - delarray[num_delarray].mode = inode.i_mode; - delarray[num_delarray].uid = inode.i_uid; - delarray[num_delarray].gid = inode.i_gid; - delarray[num_delarray].size = inode.i_size; - delarray[num_delarray].dtime = inode.i_dtime; - delarray[num_delarray].num_blocks = lsd.num_blocks; - delarray[num_delarray].free_blocks = lsd.free_blocks; - num_delarray++; - } + delarray[num_delarray].ino = ino; + delarray[num_delarray].mode = inode.i_mode; + delarray[num_delarray].uid = inode.i_uid; + delarray[num_delarray].gid = inode.i_gid; + delarray[num_delarray].size = inode.i_size; + delarray[num_delarray].dtime = inode.i_dtime; + delarray[num_delarray].num_blocks = lsd.num_blocks; + delarray[num_delarray].free_blocks = lsd.free_blocks; + num_delarray++; + } next: - retval = ext2fs_get_next_inode (scan, &ino, &inode); - if (retval) { - message (D_ERROR, undelfserr, _(" while doing inode scan %d "), - retval); - goto error_out; - } + retval = ext2fs_get_next_inode (scan, &ino, &inode); + if (retval) + { + message (D_ERROR, undelfserr, _(" while doing inode scan %d "), retval); + goto error_out; + } } readdir_ptr = READDIR_PTR_INIT; ext2fs_close_inode_scan (scan); @@ -300,8 +304,7 @@ com_err (const char *whoami, long err_code, const char *fmt, ...) str = g_strdup_vprintf (fmt, ap); va_end (ap); - message (D_ERROR, _(" Ext2lib error "), " %s (%s: %ld) ", str, whoami, - err_code); + message (D_ERROR, _(" Ext2lib error "), " %s (%s: %ld) ", str, whoami, err_code); g_free (str); } @@ -309,46 +312,50 @@ static void * undelfs_opendir (struct vfs_class *me, const char *dirname) { char *file, *f; - + undelfs_get_path (dirname, &file, &f); if (!file) - return 0; + return 0; /* We don't use the file name */ g_free (f); - - if (!ext2_fname || strcmp (ext2_fname, file)){ - undelfs_shutdown (); - ext2_fname = file; - } else { - /* To avoid expensive re-scannings */ - readdir_ptr = READDIR_PTR_INIT; - g_free (file); - return fs; + + if (!ext2_fname || strcmp (ext2_fname, file)) + { + undelfs_shutdown (); + ext2_fname = file; + } + else + { + /* To avoid expensive re-scannings */ + readdir_ptr = READDIR_PTR_INIT; + g_free (file); + return fs; } - if (ext2fs_open (ext2_fname, 0, 0, 0, unix_io_manager, &fs)){ - message (D_ERROR, undelfserr, _(" Cannot open file %s "), ext2_fname); - return 0; + if (ext2fs_open (ext2_fname, 0, 0, 0, unix_io_manager, &fs)) + { + message (D_ERROR, undelfserr, _(" Cannot open file %s "), ext2_fname); + return 0; } print_vfs_message (_("undelfs: reading inode bitmap...")); - if (ext2fs_read_inode_bitmap (fs)){ - message (D_ERROR, undelfserr, - _(" Cannot load inode bitmap from: \n %s \n"), ext2_fname); - goto quit_opendir; + if (ext2fs_read_inode_bitmap (fs)) + { + message (D_ERROR, undelfserr, _(" Cannot load inode bitmap from: \n %s \n"), ext2_fname); + goto quit_opendir; } print_vfs_message (_("undelfs: reading block bitmap...")); - if (ext2fs_read_block_bitmap (fs)){ - message (D_ERROR, undelfserr, - _(" Cannot load block bitmap from: \n %s \n"), ext2_fname); - goto quit_opendir; + if (ext2fs_read_block_bitmap (fs)) + { + message (D_ERROR, undelfserr, _(" Cannot load block bitmap from: \n %s \n"), ext2_fname); + goto quit_opendir; } /* Now load the deleted information */ if (!undelfs_loaddel ()) - goto quit_opendir; + goto quit_opendir; print_vfs_message (_("%s: done."), me->name); return fs; -quit_opendir: + quit_opendir: print_vfs_message (_("%s: failure"), me->name); ext2fs_close (fs); fs = NULL; @@ -357,26 +364,26 @@ quit_opendir: static void * -undelfs_readdir(void *vfs_info) +undelfs_readdir (void *vfs_info) { static union vfs_dirent undelfs_readdir_data; static char *const dirent_dest = undelfs_readdir_data.dent.d_name; - if (vfs_info != fs) { - message (D_ERROR, undelfserr, _(" vfs_info is not fs! ")); - return NULL; + if (vfs_info != fs) + { + message (D_ERROR, undelfserr, _(" vfs_info is not fs! ")); + return NULL; } if (readdir_ptr == num_delarray) - return NULL; + return NULL; if (readdir_ptr < 0) - strcpy (dirent_dest, readdir_ptr == -2 ? "." : ".."); + strcpy (dirent_dest, readdir_ptr == -2 ? "." : ".."); else - g_snprintf(dirent_dest, MC_MAXPATHLEN, "%ld:%d", - (long) delarray[readdir_ptr].ino, - delarray[readdir_ptr].num_blocks); + g_snprintf (dirent_dest, MC_MAXPATHLEN, "%ld:%d", + (long) delarray[readdir_ptr].ino, delarray[readdir_ptr].num_blocks); readdir_ptr++; - compute_namelen(&undelfs_readdir_data.dent); + compute_namelen (&undelfs_readdir_data.dent); return &undelfs_readdir_data; } @@ -388,20 +395,21 @@ undelfs_closedir (void *vfs_info) return 0; } -typedef struct { - int f_index; /* file index into delarray */ +typedef struct +{ + int f_index; /* file index into delarray */ char *buf; - int error_code; /* */ - int pos; /* file position */ - int current; /* used to determine current position in itereate */ - int finished; + int error_code; /* */ + int pos; /* file position */ + int current; /* used to determine current position in itereate */ + int finished; ext2_ino_t inode; - int bytes_read; + int bytes_read; long size; - + /* Used by undelfs_read: */ - char *dest_buffer; /* destination buffer */ - int count; /* bytes to read */ + char *dest_buffer; /* destination buffer */ + int count; /* bytes to read */ } undelfs_file; /* We do not support lseek */ @@ -418,42 +426,45 @@ undelfs_open (struct vfs_class *me, const char *fname, int flags, int mode) /* Only allow reads on this file system */ undelfs_get_path (fname, &file, &f); if (!file) - return 0; + return 0; - if (!ext2_fname || strcmp (ext2_fname, file)) { - message (D_ERROR, undelfserr, - _(" You have to chdir to extract files first ")); - g_free (file); - g_free (f); - return 0; + if (!ext2_fname || strcmp (ext2_fname, file)) + { + message (D_ERROR, undelfserr, _(" You have to chdir to extract files first ")); + g_free (file); + g_free (f); + return 0; } inode = atol (f); /* Search the file into delarray */ - for (i = 0; i < (ext2_ino_t) num_delarray; i++) { - if (inode != delarray[i].ino) - continue; + for (i = 0; i < (ext2_ino_t) num_delarray; i++) + { + if (inode != delarray[i].ino) + continue; - /* Found: setup all the structures needed by read */ - p = (undelfs_file *) g_try_malloc (((gsize) sizeof (undelfs_file))); - if (!p) { - g_free (file); - g_free (f); - return 0; - } - p->buf = g_try_malloc (fs->blocksize); - if (!p->buf) { - g_free (p); - g_free (file); - g_free (f); - return 0; - } - p->inode = inode; - p->finished = 0; - p->f_index = i; - p->error_code = 0; - p->pos = 0; - p->size = delarray[i].size; + /* Found: setup all the structures needed by read */ + p = (undelfs_file *) g_try_malloc (((gsize) sizeof (undelfs_file))); + if (!p) + { + g_free (file); + g_free (f); + return 0; + } + p->buf = g_try_malloc (fs->blocksize); + if (!p->buf) + { + g_free (p); + g_free (file); + g_free (f); + return 0; + } + p->inode = inode; + p->finished = 0; + p->f_index = i; + p->error_code = 0; + p->pos = 0; + p->size = delarray[i].size; } g_free (file); g_free (f); @@ -461,7 +472,7 @@ undelfs_open (struct vfs_class *me, const char *fname, int flags, int mode) return p; } -static int +static int undelfs_close (void *vfs_info) { undelfs_file *p = vfs_info; @@ -472,58 +483,71 @@ undelfs_close (void *vfs_info) } static int -undelfs_dump_read(ext2_filsys param_fs, blk_t *blocknr, int blockcnt, void *private) +undelfs_dump_read (ext2_filsys param_fs, blk_t * blocknr, int blockcnt, void *private) { - int copy_count; + int copy_count; undelfs_file *p = (undelfs_file *) private; - - if (blockcnt < 0) - return 0; - - if (*blocknr) { - p->error_code = io_channel_read_blk(param_fs->io, *blocknr, - 1, p->buf); - if (p->error_code) - return BLOCK_ABORT; - } else - memset(p->buf, 0, param_fs->blocksize); - if (p->pos + p->count < p->current){ - p->finished = 1; - return BLOCK_ABORT; + if (blockcnt < 0) + return 0; + + if (*blocknr) + { + p->error_code = io_channel_read_blk (param_fs->io, *blocknr, 1, p->buf); + if (p->error_code) + return BLOCK_ABORT; } - if ((size_t) p->pos > p->current + param_fs->blocksize){ - p->current += param_fs->blocksize; - return 0; /* we have not arrived yet */ + else + memset (p->buf, 0, param_fs->blocksize); + + if (p->pos + p->count < p->current) + { + p->finished = 1; + return BLOCK_ABORT; + } + if ((size_t) p->pos > p->current + param_fs->blocksize) + { + p->current += param_fs->blocksize; + return 0; /* we have not arrived yet */ } /* Now, we know we have to extract some data */ - if (p->pos >= p->current){ + if (p->pos >= p->current) + { - /* First case: starting pointer inside this block */ - if ( (size_t)(p->pos + p->count) <= p->current + param_fs->blocksize){ - /* Fully contained */ - copy_count = p->count; - p->finished = p->count; - } else { - /* Still some more data */ - copy_count = param_fs->blocksize-(p->pos-p->current); - } - memcpy (p->dest_buffer, p->buf + (p->pos-p->current), copy_count); - } else { - /* Second case: we already have passed p->pos */ - if ((size_t) (p->pos + p->count) < p->current+param_fs->blocksize){ - copy_count = (p->pos + p->count) - p->current; - p->finished = p->count; - } else { - copy_count = param_fs->blocksize; - } - memcpy (p->dest_buffer, p->buf, copy_count); + /* First case: starting pointer inside this block */ + if ((size_t) (p->pos + p->count) <= p->current + param_fs->blocksize) + { + /* Fully contained */ + copy_count = p->count; + p->finished = p->count; + } + else + { + /* Still some more data */ + copy_count = param_fs->blocksize - (p->pos - p->current); + } + memcpy (p->dest_buffer, p->buf + (p->pos - p->current), copy_count); + } + else + { + /* Second case: we already have passed p->pos */ + if ((size_t) (p->pos + p->count) < p->current + param_fs->blocksize) + { + copy_count = (p->pos + p->count) - p->current; + p->finished = p->count; + } + else + { + copy_count = param_fs->blocksize; + } + memcpy (p->dest_buffer, p->buf, copy_count); } p->dest_buffer += copy_count; p->current += param_fs->blocksize; - if (p->finished){ - return BLOCK_ABORT; + if (p->finished) + { + return BLOCK_ABORT; } return 0; } @@ -535,21 +559,22 @@ undelfs_read (void *vfs_info, char *buffer, int count) int retval; p->dest_buffer = buffer; - p->current = 0; - p->finished = 0; - p->count = count; + p->current = 0; + p->finished = 0; + p->count = count; - if (p->pos + p->count > p->size){ - p->count = p->size - p->pos; + if (p->pos + p->count > p->size) + { + p->count = p->size - p->pos; } - retval = ext2fs_block_iterate(fs, p->inode, 0, NULL, - undelfs_dump_read, p); - if (retval){ - message (D_ERROR, undelfserr, _(" while iterating over blocks ")); - return -1; + retval = ext2fs_block_iterate (fs, p->inode, 0, NULL, undelfs_dump_read, p); + if (retval) + { + message (D_ERROR, undelfserr, _(" while iterating over blocks ")); + return -1; } if (p->error_code && !p->finished) - return 0; + return 0; p->pos = p->pos + (p->dest_buffer - buffer); return p->dest_buffer - buffer; } @@ -560,9 +585,10 @@ undelfs_getindex (char *path) ext2_ino_t inode = atol (path); int i; - for (i = 0; i < num_delarray; i++){ - if (delarray [i].ino == inode) - return i; + for (i = 0; i < num_delarray; i++) + { + if (delarray[i].ino == inode) + return i; } return -1; } @@ -570,16 +596,16 @@ undelfs_getindex (char *path) static int undelfs_stat_int (int inode_index, struct stat *buf) { - buf->st_dev = 0; - buf->st_ino = delarray [inode_index].ino; - buf->st_mode = delarray [inode_index].mode; + buf->st_dev = 0; + buf->st_ino = delarray[inode_index].ino; + buf->st_mode = delarray[inode_index].mode; buf->st_nlink = 1; - buf->st_uid = delarray [inode_index].uid; - buf->st_gid = delarray [inode_index].gid; - buf->st_size = delarray [inode_index].size; - buf->st_atime = delarray [inode_index].dtime; - buf->st_ctime = delarray [inode_index].dtime; - buf->st_mtime = delarray [inode_index].dtime; + buf->st_uid = delarray[inode_index].uid; + buf->st_gid = delarray[inode_index].gid; + buf->st_size = delarray[inode_index].size; + buf->st_atime = delarray[inode_index].dtime; + buf->st_ctime = delarray[inode_index].dtime; + buf->st_mtime = delarray[inode_index].dtime; return 0; } @@ -592,32 +618,34 @@ undelfs_lstat (struct vfs_class *me, const char *path, struct stat *buf) undelfs_get_path (path, &file, &f); if (!file) - return 0; + return 0; /* When called from save_cwd_stats we get an incorrect file and f here: e.g. incorrect correct - path = "undel:/dev/sda1" path="undel:/dev/sda1/401:1" - file = "/dev" file="/dev/sda1" - f = "sda1" f ="401:1" + path = "undel:/dev/sda1" path="undel:/dev/sda1/401:1" + file = "/dev" file="/dev/sda1" + f = "sda1" f ="401:1" If the first char in f is no digit -> return error */ - if (!isdigit (*f)) { - g_free (file); - g_free (f); - return -1; + if (!isdigit (*f)) + { + g_free (file); + g_free (f); + return -1; } - - if (!ext2_fname || strcmp (ext2_fname, file)){ - message (D_ERROR, undelfserr, _(" You have to chdir to extract files first ")); - g_free (file); - g_free (f); - return 0; + + if (!ext2_fname || strcmp (ext2_fname, file)) + { + message (D_ERROR, undelfserr, _(" You have to chdir to extract files first ")); + g_free (file); + g_free (f); + return 0; } inode_index = undelfs_getindex (f); g_free (file); g_free (f); if (inode_index == -1) - return -1; + return -1; return undelfs_stat_int (inode_index, buf); } @@ -628,12 +656,12 @@ static int undelfs_fstat (void *vfs_info, struct stat *buf) { undelfs_file *p = vfs_info; - + return undelfs_stat_int (p->f_index, buf); } static int -undelfs_chdir(struct vfs_class *me, const char *path) +undelfs_chdir (struct vfs_class *me, const char *path) { char *file, *f; int fd; @@ -641,16 +669,17 @@ undelfs_chdir(struct vfs_class *me, const char *path) undelfs_get_path (path, &file, &f); if (!file) - return -1; + return -1; /* We may use access because ext2 file systems are local */ /* this could be fixed by making an ext2fs io manager to use */ /* our vfs, but that is left as an excercise for the reader */ - if ((fd = open (file, O_RDONLY)) == -1){ - message (D_ERROR, undelfserr, _(" Cannot open file %s "), file); - g_free (f); - g_free (file); - return -1; + if ((fd = open (file, O_RDONLY)) == -1) + { + message (D_ERROR, undelfserr, _(" Cannot open file %s "), file); + g_free (f); + g_free (file); + return -1; } close (fd); g_free (f); @@ -660,7 +689,7 @@ undelfs_chdir(struct vfs_class *me, const char *path) /* this has to stay here for now: vfs layer does not know how to emulate it */ static off_t -undelfs_lseek(void *vfs_info, off_t offset, int whence) +undelfs_lseek (void *vfs_info, off_t offset, int whence) { (void) vfs_info; (void) offset; @@ -678,14 +707,14 @@ undelfs_getid (struct vfs_class *me, const char *path) undelfs_get_path (path, &fsname, &fname); if (!fsname) - return NULL; + return NULL; g_free (fname); g_free (fsname); return (vfsid) fs; } static int -undelfs_nothingisopen(vfsid id) +undelfs_nothingisopen (vfsid id) { (void) id; @@ -693,7 +722,7 @@ undelfs_nothingisopen(vfsid id) } static void -undelfs_free(vfsid id) +undelfs_free (vfsid id) { (void) id; @@ -702,7 +731,8 @@ undelfs_free(vfsid id) #ifdef ENABLE_NLS static int -undelfs_init(struct vfs_class *me) { +undelfs_init (struct vfs_class *me) +{ (void) me; undelfserr = _(undelfserr); diff --git a/src/chown.c b/src/chown.c index c1c80b124..775910af2 100644 --- a/src/chown.c +++ b/src/chown.c @@ -44,12 +44,12 @@ /* Needed for the extern declarations of integer parameters */ #include "dir.h" -#include "panel.h" /* Needed for the externs */ +#include "panel.h" /* Needed for the externs */ #include "chmod.h" -#include "main.h" /* update_panels() */ -#include "layout.h" /* repaint_screen() */ +#include "main.h" /* update_panels() */ +#include "layout.h" /* repaint_screen() */ #include "chown.h" -#include "wtools.h" /* For init_box_colors */ +#include "wtools.h" /* For init_box_colors */ #define UX 5 #define UY 2 @@ -74,6 +74,7 @@ static int current_file; static int single_set; static WListbox *l_user, *l_group; +/* *INDENT-OFF* */ static struct { int ret_cmd, flags, y, x; const char *text; @@ -96,9 +97,10 @@ static struct { { TY+8, TX+2, NULL }, { TY+10,TX+2, NULL } }; +/* *INDENT-ON* */ static void -chown_refresh (Dlg_head *h) +chown_refresh (Dlg_head * h) { common_dialog_repaint (h); @@ -118,7 +120,7 @@ chown_refresh (Dlg_head *h) tty_print_string (_(" Size ")); dlg_move (h, TY + 9, TX + 1); tty_print_string (_(" Permission ")); - + tty_setcolor (COLOR_HOT_NORMAL); dlg_move (h, UY, UX + 1); tty_print_string (_(" User name ")); @@ -132,22 +134,22 @@ static char * next_file (void) { while (!current_panel->dir.list[current_file].f.marked) - current_file++; + current_file++; return current_panel->dir.list[current_file].fname; } static cb_ret_t -chown_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { - switch (msg) { + switch (msg) + { case DLG_DRAW: - chown_refresh (h); - return MSG_HANDLED; + chown_refresh (h); + return MSG_HANDLED; default: - return default_dlg_callback (h, sender, msg, parm, data); + return default_dlg_callback (h, sender, msg, parm, data); } } @@ -164,20 +166,19 @@ init_chown (void) single_set = (current_panel->marked < 2) ? 3 : 0; ch_dlg = - create_dlg (0, 0, 18, 74, dialog_colors, chown_callback, "[Chown]", - _(" Chown command "), DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, 18, 74, dialog_colors, chown_callback, "[Chown]", + _(" Chown command "), DLG_CENTER | DLG_REVERSE); for (i = 0; i < BUTTONS - single_set; i++) - add_widget (ch_dlg, - button_new (BY + chown_but[i].y, BX + chown_but[i].x, - chown_but[i].ret_cmd, chown_but[i].flags, - _(chown_but[i].text), 0)); + add_widget (ch_dlg, + button_new (BY + chown_but[i].y, BX + chown_but[i].x, + chown_but[i].ret_cmd, chown_but[i].flags, _(chown_but[i].text), 0)); /* Add the widgets for the file information */ - for (i = 0; i < LABELS; i++) { - chown_label[i].l = - label_new (chown_label[i].y, chown_label[i].x, ""); - add_widget (ch_dlg, chown_label[i].l); + for (i = 0; i < LABELS; i++) + { + chown_label[i].l = label_new (chown_label[i].y, chown_label[i].x, ""); + add_widget (ch_dlg, chown_label[i].l); } /* get new listboxes */ @@ -190,15 +191,17 @@ init_chown (void) /* get and put user names in the listbox */ setpwent (); - while ((l_pass = getpwent ())) { - listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL); + while ((l_pass = getpwent ())) + { + listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL); } endpwent (); /* get and put group names in the listbox */ setgrent (); - while ((l_grp = getgrent ())) { - listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL); + while ((l_grp = getgrent ())) + { + listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL); } endgrent (); @@ -213,16 +216,16 @@ static void chown_done (void) { if (need_update) - update_panels (UP_OPTIMIZE, UP_KEEPSEL); + update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); } static void do_chown (uid_t u, gid_t g) { - if (mc_chown (current_panel->dir.list [current_file].fname, u, g) == -1) - message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "), - current_panel->dir.list [current_file].fname, unix_error_string (errno)); + if (mc_chown (current_panel->dir.list[current_file].fname, u, g) == -1) + message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "), + current_panel->dir.list[current_file].fname, unix_error_string (errno)); do_file_mark (current_panel, current_file, 0); } @@ -231,15 +234,17 @@ static void apply_chowns (uid_t u, gid_t g) { char *fname; - + need_update = end_chown = 1; - do_chown (u,g); - - do { - fname = next_file (); - - do_chown (u,g); - } while (current_panel->marked); + do_chown (u, g); + + do + { + fname = next_file (); + + do_chown (u, g); + } + while (current_panel->marked); } #define chown_label(n,txt) label_set_text (chown_label [n].l, txt) @@ -252,96 +257,105 @@ chown_cmd (void) Dlg_head *ch_dlg; uid_t new_user; gid_t new_group; - char buffer [BUF_TINY]; + char buffer[BUF_TINY]; - do { /* do while any files remaining */ - ch_dlg = init_chown (); - new_user = new_group = -1; + do + { /* do while any files remaining */ + ch_dlg = init_chown (); + new_user = new_group = -1; - if (current_panel->marked) - fname = next_file (); /* next marked file */ - else - fname = selection (current_panel)->fname; /* single file */ - - if (mc_stat (fname, &sf_stat) != 0) { /* get status of file */ - destroy_dlg (ch_dlg); - break; - } - - /* select in listboxes */ - listbox_select_entry (l_user, listbox_search_text (l_user, get_owner(sf_stat.st_uid))); - listbox_select_entry (l_group, listbox_search_text (l_group, get_group(sf_stat.st_gid))); + if (current_panel->marked) + fname = next_file (); /* next marked file */ + else + fname = selection (current_panel)->fname; /* single file */ - chown_label (0, str_trunc (fname, 15)); - chown_label (1, str_trunc (get_owner (sf_stat.st_uid), 15)); - chown_label (2, str_trunc (get_group (sf_stat.st_gid), 15)); - size_trunc_len (buffer, 15, sf_stat.st_size, 0); - chown_label (3, buffer); - chown_label (4, string_perm (sf_stat.st_mode)); + if (mc_stat (fname, &sf_stat) != 0) + { /* get status of file */ + destroy_dlg (ch_dlg); + break; + } - switch (run_dlg (ch_dlg)) { - case B_CANCEL: - end_chown = 1; - break; + /* select in listboxes */ + listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid))); + listbox_select_entry (l_group, listbox_search_text (l_group, get_group (sf_stat.st_gid))); - case B_SETUSR: - { - struct passwd *user; - char *text; + chown_label (0, str_trunc (fname, 15)); + chown_label (1, str_trunc (get_owner (sf_stat.st_uid), 15)); + chown_label (2, str_trunc (get_group (sf_stat.st_gid), 15)); + size_trunc_len (buffer, 15, sf_stat.st_size, 0); + chown_label (3, buffer); + chown_label (4, string_perm (sf_stat.st_mode)); - listbox_get_current (l_user, &text, NULL); - user = getpwnam (text); - if (user){ - new_user = user->pw_uid; - apply_chowns (new_user, new_group); - } - break; - } - case B_SETGRP: - { - struct group *grp; - char *text; + switch (run_dlg (ch_dlg)) + { + case B_CANCEL: + end_chown = 1; + break; - listbox_get_current (l_group, &text, NULL); - grp = getgrnam (text); - if (grp){ - new_group = grp->gr_gid; - apply_chowns (new_user, new_group); - } - break; - } - case B_SETALL: - case B_ENTER: - { - struct group *grp; - struct passwd *user; - char *text; + case B_SETUSR: + { + struct passwd *user; + char *text; - listbox_get_current (l_group, &text, NULL); - grp = getgrnam (text); - if (grp) - new_group = grp->gr_gid; - listbox_get_current (l_user, &text, NULL); - user = getpwnam (text); - if (user) - new_user = user->pw_uid; - if (ch_dlg->ret_value == B_ENTER) { - need_update = 1; - if (mc_chown (fname, new_user, new_group) == -1) - message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "), - fname, unix_error_string (errno)); - } else - apply_chowns (new_user, new_group); - break; - } - } /* switch */ + listbox_get_current (l_user, &text, NULL); + user = getpwnam (text); + if (user) + { + new_user = user->pw_uid; + apply_chowns (new_user, new_group); + } + break; + } + case B_SETGRP: + { + struct group *grp; + char *text; + + listbox_get_current (l_group, &text, NULL); + grp = getgrnam (text); + if (grp) + { + new_group = grp->gr_gid; + apply_chowns (new_user, new_group); + } + break; + } + case B_SETALL: + case B_ENTER: + { + struct group *grp; + struct passwd *user; + char *text; + + listbox_get_current (l_group, &text, NULL); + grp = getgrnam (text); + if (grp) + new_group = grp->gr_gid; + listbox_get_current (l_user, &text, NULL); + user = getpwnam (text); + if (user) + new_user = user->pw_uid; + if (ch_dlg->ret_value == B_ENTER) + { + need_update = 1; + if (mc_chown (fname, new_user, new_group) == -1) + message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "), + fname, unix_error_string (errno)); + } + else + apply_chowns (new_user, new_group); + break; + } + } /* switch */ + + if (current_panel->marked && ch_dlg->ret_value != B_CANCEL) + { + do_file_mark (current_panel, current_file, 0); + need_update = 1; + } + destroy_dlg (ch_dlg); + } + while (current_panel->marked && !end_chown); - if (current_panel->marked && ch_dlg->ret_value != B_CANCEL){ - do_file_mark (current_panel, current_file, 0); - need_update = 1; - } - destroy_dlg (ch_dlg); - } while (current_panel->marked && !end_chown); - chown_done (); } diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index f7e224b5a..81331e93a 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ + */ /** \file * \brief Source: editor high level editing commands @@ -47,18 +47,18 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/tty/key.h" /* XCTRL */ +#include "lib/tty/key.h" /* XCTRL */ #include "lib/mcconfig.h" #include "lib/skin.h" -#include "lib/strutil.h" /* utf string functions */ +#include "lib/strutil.h" /* utf string functions */ #include "lib/vfs/mc-vfs/vfs.h" #include "src/history.h" -#include "src/widget.h" /* listbox_new() */ -#include "src/layout.h" /* clr_scr() */ -#include "src/main.h" /* mc_home source_codepage */ -#include "src/help.h" /* interactive_display() */ -#include "src/wtools.h" /* message() */ +#include "src/widget.h" /* listbox_new() */ +#include "src/layout.h" /* clr_scr() */ +#include "src/main.h" /* mc_home source_codepage */ +#include "src/help.h" /* interactive_display() */ +#include "src/wtools.h" /* message() */ #include "src/charsets.h" #include "src/selcodepage.h" #include "src/cmddef.h" @@ -78,12 +78,11 @@ int search_create_bookmark = 0; /* queries on a save */ int edit_confirm_save = 1; -static int edit_save_cmd (WEdit *edit); -static unsigned char *edit_get_block (WEdit *edit, long start, - long finish, int *l); +static int edit_save_cmd (WEdit * edit); +static unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l); static void -edit_search_cmd_search_create_bookmark(WEdit * edit) +edit_search_cmd_search_create_bookmark (WEdit * edit) { int found = 0, books = 0; long l = 0, l_last = -1; @@ -93,36 +92,42 @@ edit_search_cmd_search_create_bookmark(WEdit * edit) search_create_bookmark = 0; book_mark_flush (edit, -1); - for (;;) { - if (!mc_search_run(edit->search, (void *) edit, q, edit->last_byte, &len)) - break; - if (found == 0) - edit->search_start = edit->search->normal_offset; - found++; - l += edit_count_lines (edit, q, edit->search->normal_offset); - if (l != l_last) { - book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR); - books++; - } - l_last = l; - q = edit->search->normal_offset + 1; + for (;;) + { + if (!mc_search_run (edit->search, (void *) edit, q, edit->last_byte, &len)) + break; + if (found == 0) + edit->search_start = edit->search->normal_offset; + found++; + l += edit_count_lines (edit, q, edit->search->normal_offset); + if (l != l_last) + { + book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR); + books++; + } + l_last = l; + q = edit->search->normal_offset + 1; } - if (found == 0) { - edit_error_dialog (_ ("Search"), _ (" Search string not found ")); - } else { - edit_cursor_move (edit, edit->search_start - edit->curs1); - edit_scroll_screen_over_cursor (edit); + if (found == 0) + { + edit_error_dialog (_("Search"), _(" Search string not found ")); + } + else + { + edit_cursor_move (edit, edit->search_start - edit->curs1); + edit_scroll_screen_over_cursor (edit); } } static int -edit_search_cmd_callback(const void *user_data, gsize char_offset) +edit_search_cmd_callback (const void *user_data, gsize char_offset) { - return edit_get_byte ((WEdit * )user_data, (long) char_offset); + return edit_get_byte ((WEdit *) user_data, (long) char_offset); } -void edit_help_cmd (WEdit * edit) +void +edit_help_cmd (WEdit * edit) { interactive_display (NULL, "[Internal File Editor]"); edit->force |= REDRAW_COMPLETELY; @@ -147,16 +152,16 @@ edit_refresh_cmd (WEdit * edit) } /* If 0 (quick save) then a) create/truncate file, - b) save to ; - if 1 (safe save) then a) save to , - b) rename to ; - if 2 (do backups) then a) save to , - b) rename to , - c) rename to . */ + b) save to ; + if 1 (safe save) then a) save to , + b) rename to ; + if 2 (do backups) then a) save to , + b) rename to , + c) rename to . */ /* returns 0 on error, -1 on abort */ static int -edit_save_file (WEdit *edit, const char *filename) +edit_save_file (WEdit * edit, const char *filename) { char *p; gchar *tmp; @@ -166,226 +171,253 @@ edit_save_file (WEdit *edit, const char *filename) int this_save_mode, fd = -1; if (!filename) - return 0; + return 0; if (!*filename) - return 0; + return 0; - if (*filename != PATH_SEP && edit->dir) { - real_filename = concat_dir_and_file (edit->dir, filename); - } else { - real_filename = g_strdup(filename); + if (*filename != PATH_SEP && edit->dir) + { + real_filename = concat_dir_and_file (edit->dir, filename); + } + else + { + real_filename = g_strdup (filename); } this_save_mode = option_save_mode; - if (this_save_mode != EDIT_QUICK_SAVE) { - if (!vfs_file_is_local (real_filename) || - (fd = mc_open (real_filename, O_RDONLY | O_BINARY)) == -1) { - /* - * The file does not exists yet, so no safe save or - * backup are necessary. - */ - this_save_mode = EDIT_QUICK_SAVE; - } - if (fd != -1) - mc_close (fd); + if (this_save_mode != EDIT_QUICK_SAVE) + { + if (!vfs_file_is_local (real_filename) || + (fd = mc_open (real_filename, O_RDONLY | O_BINARY)) == -1) + { + /* + * The file does not exists yet, so no safe save or + * backup are necessary. + */ + this_save_mode = EDIT_QUICK_SAVE; + } + if (fd != -1) + mc_close (fd); } - if (this_save_mode == EDIT_QUICK_SAVE && - !edit->skip_detach_prompt) { - int rv; - struct stat sb; + if (this_save_mode == EDIT_QUICK_SAVE && !edit->skip_detach_prompt) + { + int rv; + struct stat sb; - rv = mc_stat (real_filename, &sb); - if (rv == 0 && sb.st_nlink > 1) { - rv = edit_query_dialog3 (_("Warning"), - _(" File has hard-links. Detach before saving? "), - _("&Yes"), _("&No"), _("&Cancel")); - switch (rv) { - case 0: - this_save_mode = EDIT_SAFE_SAVE; - /* fallthrough */ - case 1: - edit->skip_detach_prompt = 1; - break; - default: - g_free(real_filename); - return -1; - } - } + rv = mc_stat (real_filename, &sb); + if (rv == 0 && sb.st_nlink > 1) + { + rv = edit_query_dialog3 (_("Warning"), + _(" File has hard-links. Detach before saving? "), + _("&Yes"), _("&No"), _("&Cancel")); + switch (rv) + { + case 0: + this_save_mode = EDIT_SAFE_SAVE; + /* fallthrough */ + case 1: + edit->skip_detach_prompt = 1; + break; + default: + g_free (real_filename); + return -1; + } + } - /* Prevent overwriting changes from other editor sessions. */ - if (rv == 0 && edit->stat1.st_mtime != 0 && edit->stat1.st_mtime != sb.st_mtime) { + /* Prevent overwriting changes from other editor sessions. */ + if (rv == 0 && edit->stat1.st_mtime != 0 && edit->stat1.st_mtime != sb.st_mtime) + { - /* The default action is "Cancel". */ - query_set_sel(1); + /* The default action is "Cancel". */ + query_set_sel (1); - rv = edit_query_dialog2 ( - _("Warning"), - _("The file has been modified in the meantime. Save anyway?"), - _("&Yes"), - _("&Cancel")); - if (rv != 0){ - g_free(real_filename); - return -1; - } - } + rv = edit_query_dialog2 (_("Warning"), + _("The file has been modified in the meantime. Save anyway?"), + _("&Yes"), _("&Cancel")); + if (rv != 0) + { + g_free (real_filename); + return -1; + } + } } - if (this_save_mode != EDIT_QUICK_SAVE) { - char *savedir, *saveprefix; - const char *slashpos; - slashpos = strrchr (real_filename, PATH_SEP); - if (slashpos) { - savedir = g_strdup (real_filename); - savedir[slashpos - real_filename + 1] = '\0'; - } else - savedir = g_strdup ("."); - saveprefix = concat_dir_and_file (savedir, "cooledit"); - g_free (savedir); - fd = mc_mkstemps (&savename, saveprefix, NULL); - g_free (saveprefix); - if (!savename){ - g_free(real_filename); - return 0; - } - /* FIXME: - * Close for now because mc_mkstemps use pure open system call - * to create temporary file and it needs to be reopened by - * VFS-aware mc_open(). - */ - close (fd); - } else - savename = g_strdup (real_filename); + if (this_save_mode != EDIT_QUICK_SAVE) + { + char *savedir, *saveprefix; + const char *slashpos; + slashpos = strrchr (real_filename, PATH_SEP); + if (slashpos) + { + savedir = g_strdup (real_filename); + savedir[slashpos - real_filename + 1] = '\0'; + } + else + savedir = g_strdup ("."); + saveprefix = concat_dir_and_file (savedir, "cooledit"); + g_free (savedir); + fd = mc_mkstemps (&savename, saveprefix, NULL); + g_free (saveprefix); + if (!savename) + { + g_free (real_filename); + return 0; + } + /* FIXME: + * Close for now because mc_mkstemps use pure open system call + * to create temporary file and it needs to be reopened by + * VFS-aware mc_open(). + */ + close (fd); + } + else + savename = g_strdup (real_filename); mc_chown (savename, edit->stat1.st_uid, edit->stat1.st_gid); mc_chmod (savename, edit->stat1.st_mode); if ((fd = - mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, - edit->stat1.st_mode)) == -1) - goto error_save; + mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, edit->stat1.st_mode)) == -1) + goto error_save; -/* pipe save */ - if ((p = edit_get_write_filter (savename, real_filename))) { - FILE *file; + /* pipe save */ + if ((p = edit_get_write_filter (savename, real_filename))) + { + FILE *file; - mc_close (fd); - file = (FILE *) popen (p, "w"); + mc_close (fd); + file = (FILE *) popen (p, "w"); - if (file) { - filelen = edit_write_stream (edit, file); + if (file) + { + filelen = edit_write_stream (edit, file); #if 1 - pclose (file); + pclose (file); #else - if (pclose (file) != 0) { - tmp = g_strconcat (_(" Error writing to pipe: "), - p, " ", (char *) NULL); - edit_error_dialog (_("Error"), tmp); - g_free(tmp); - g_free (p); - goto error_save; - } + if (pclose (file) != 0) + { + tmp = g_strconcat (_(" Error writing to pipe: "), p, " ", (char *) NULL); + edit_error_dialog (_("Error"), tmp); + g_free (tmp); + g_free (p); + goto error_save; + } #endif - } else { - tmp = g_strconcat (_(" Cannot open pipe for writing: "), - p, " ", (char *) NULL); + } + else + { + tmp = g_strconcat (_(" Cannot open pipe for writing: "), p, " ", (char *) NULL); - edit_error_dialog (_("Error"), - get_sys_error (tmp)); - g_free (p); - g_free(tmp); - goto error_save; - } - g_free (p); - } else if (edit->lb == LB_ASIS) { /* do not change line breaks */ - long buf; - buf = 0; - filelen = edit->last_byte; - while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) { - if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) - != EDIT_BUF_SIZE) { - mc_close (fd); - goto error_save; - } - buf++; - } - if (mc_write - (fd, (char *) edit->buffers1[buf], - edit->curs1 & M_EDIT_BUF_SIZE) != - (edit->curs1 & M_EDIT_BUF_SIZE)) { - filelen = -1; - } else if (edit->curs2) { - edit->curs2--; - buf = (edit->curs2 >> S_EDIT_BUF_SIZE); - if (mc_write - (fd, - (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, - 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != - 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) { - filelen = -1; - } else { - while (--buf >= 0) { - if (mc_write - (fd, (char *) edit->buffers2[buf], - EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { - filelen = -1; - break; - } - } - } - edit->curs2++; - } - if (mc_close (fd)) - goto error_save; + edit_error_dialog (_("Error"), get_sys_error (tmp)); + g_free (p); + g_free (tmp); + goto error_save; + } + g_free (p); + } + else if (edit->lb == LB_ASIS) + { /* do not change line breaks */ + long buf; + buf = 0; + filelen = edit->last_byte; + while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) + { + if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) + { + mc_close (fd); + goto error_save; + } + buf++; + } + if (mc_write + (fd, (char *) edit->buffers1[buf], + edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) + { + filelen = -1; + } + else if (edit->curs2) + { + edit->curs2--; + buf = (edit->curs2 >> S_EDIT_BUF_SIZE); + if (mc_write + (fd, + (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - + (edit->curs2 & M_EDIT_BUF_SIZE) - 1, + 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) + { + filelen = -1; + } + else + { + while (--buf >= 0) + { + if (mc_write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) + { + filelen = -1; + break; + } + } + } + edit->curs2++; + } + if (mc_close (fd)) + goto error_save; - /* Update the file information, especially the mtime. */ - if (mc_stat (savename, &edit->stat1) == -1) - goto error_save; - } else { /* change line breaks */ - FILE *file; + /* Update the file information, especially the mtime. */ + if (mc_stat (savename, &edit->stat1) == -1) + goto error_save; + } + else + { /* change line breaks */ + FILE *file; - mc_close (fd); + mc_close (fd); - file = (FILE *) fopen (savename, "w"); + file = (FILE *) fopen (savename, "w"); - if (file) { - filelen = edit_write_stream (edit, file); - fclose (file); - } else { - char *msg; + if (file) + { + filelen = edit_write_stream (edit, file); + fclose (file); + } + else + { + char *msg; - msg = g_strdup_printf (_(" Cannot open file for writing: %s "), savename); - edit_error_dialog (_("Error"), msg); - g_free (msg); - goto error_save; - } + msg = g_strdup_printf (_(" Cannot open file for writing: %s "), savename); + edit_error_dialog (_("Error"), msg); + g_free (msg); + goto error_save; + } } if (filelen != edit->last_byte) - goto error_save; + goto error_save; - if (this_save_mode == EDIT_DO_BACKUP) { - assert (option_backup_ext != NULL); - tmp = g_strconcat (real_filename, option_backup_ext, (char *) NULL); - if (mc_rename (real_filename, tmp) == -1){ - g_free(tmp); - goto error_save; - } + if (this_save_mode == EDIT_DO_BACKUP) + { + assert (option_backup_ext != NULL); + tmp = g_strconcat (real_filename, option_backup_ext, (char *) NULL); + if (mc_rename (real_filename, tmp) == -1) + { + g_free (tmp); + goto error_save; + } } if (this_save_mode != EDIT_QUICK_SAVE) - if (mc_rename (savename, real_filename) == -1) - goto error_save; + if (mc_rename (savename, real_filename) == -1) + goto error_save; g_free (savename); - g_free(real_filename); + g_free (real_filename); return 1; error_save: -/* FIXME: Is this safe ? - * if (this_save_mode != EDIT_QUICK_SAVE) - * mc_unlink (savename); - */ - g_free(real_filename); + /* FIXME: Is this safe ? + * if (this_save_mode != EDIT_QUICK_SAVE) + * mc_unlink (savename); + */ + g_free (real_filename); g_free (savename); return 0; } @@ -399,32 +431,29 @@ menu_save_mode_cmd (void) char *str_result; - const char *str[] = - { - N_("&Quick save"), - N_("&Safe save"), - N_("&Do backups with following extension:") + const char *str[] = { + N_("&Quick save"), + N_("&Safe save"), + N_("&Do backups with following extension:") }; - QuickWidget widgets[] = - { - /* 0 */ - QUICK_BUTTON (18, DLG_X, DLG_Y - 3, DLG_Y, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ - QUICK_BUTTON ( 6, DLG_X, DLG_Y - 3, DLG_Y, N_("&OK"), B_ENTER, NULL), - /* 2 */ - QUICK_CHECKBOX ( 4, DLG_X, 8, DLG_Y, N_("Check &POSIX new line"), &option_check_nl_at_eof), - /* 3 */ - QUICK_INPUT ( 8, DLG_X, 6, DLG_Y, option_backup_ext, 9, 0, "edit-backup-ext", &str_result), - /* 4 */ - QUICK_RADIO ( 4, DLG_X, 3, DLG_Y, 3, str, &option_save_mode), - QUICK_END + QuickWidget widgets[] = { + /* 0 */ + QUICK_BUTTON (18, DLG_X, DLG_Y - 3, DLG_Y, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ + QUICK_BUTTON (6, DLG_X, DLG_Y - 3, DLG_Y, N_("&OK"), B_ENTER, NULL), + /* 2 */ + QUICK_CHECKBOX (4, DLG_X, 8, DLG_Y, N_("Check &POSIX new line"), &option_check_nl_at_eof), + /* 3 */ + QUICK_INPUT (8, DLG_X, 6, DLG_Y, option_backup_ext, 9, 0, "edit-backup-ext", &str_result), + /* 4 */ + QUICK_RADIO (4, DLG_X, 3, DLG_Y, 3, str, &option_save_mode), + QUICK_END }; - QuickDialog dialog = - { - DLG_X, DLG_Y, -1, -1, N_(" Edit Save Mode "), - "[Edit Save Mode]", widgets, FALSE + QuickDialog dialog = { + DLG_X, DLG_Y, -1, -1, N_(" Edit Save Mode "), + "[Edit Save Mode]", widgets, FALSE }; size_t i; @@ -435,17 +464,18 @@ menu_save_mode_cmd (void) /* OK/Cancel buttons */ w0 = str_term_width1 (_(widgets[0].u.button.text)) + 3; - w1 = str_term_width1 (_(widgets[1].u.button.text)) + 5; /* default button */ + w1 = str_term_width1 (_(widgets[1].u.button.text)) + 5; /* default button */ b_len = w0 + w1 + 3; maxlen = max (b_len, (size_t) str_term_width1 (_(dialog.title)) + 2); w3 = 0; - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) + { #ifdef ENABLE_NLS - str[i] = _(str[i]); + str[i] = _(str[i]); #endif - w3 = max (w3, (size_t) str_term_width1 (str[i])); + w3 = max (w3, (size_t) str_term_width1 (str[i])); } maxlen = max (maxlen, w3 + 4); @@ -453,45 +483,46 @@ menu_save_mode_cmd (void) dialog.xlen = min ((size_t) COLS, maxlen + 8); widgets[3].u.input.len = w3; - widgets[1].relative_x = (dialog.xlen - b_len)/2; + widgets[1].relative_x = (dialog.xlen - b_len) / 2; widgets[0].relative_x = widgets[1].relative_x + w0 + 2; - for (i = 0; i < sizeof (widgets)/sizeof (widgets[0]); i++) - widgets[i].x_divisions = dialog.xlen; + for (i = 0; i < sizeof (widgets) / sizeof (widgets[0]); i++) + widgets[i].x_divisions = dialog.xlen; - if (quick_dialog (&dialog) != B_CANCEL) { - g_free (option_backup_ext); - option_backup_ext = str_result; + if (quick_dialog (&dialog) != B_CANCEL) + { + g_free (option_backup_ext); + option_backup_ext = str_result; } } void -edit_set_filename (WEdit *edit, const char *f) +edit_set_filename (WEdit * edit, const char *f) { g_free (edit->filename); if (!f) - f = ""; + f = ""; edit->filename = g_strdup (f); if (edit->dir == NULL && *f != PATH_SEP) #ifdef ENABLE_VFS - edit->dir = g_strdup (vfs_get_current_dir ()); + edit->dir = g_strdup (vfs_get_current_dir ()); #else /* ENABLE_VFS */ - edit->dir = g_get_current_dir (); + edit->dir = g_get_current_dir (); #endif /* ENABLE_VFS */ } static gboolean -edit_check_newline (WEdit *edit) +edit_check_newline (WEdit * edit) { return !(option_check_nl_at_eof && edit->last_byte > 0 - && edit_get_byte (edit, edit->last_byte - 1) != '\n' - && edit_query_dialog2 (_("Warning"), - _("The file you are saving is not finished with a newline"), - _("C&ontinue"), _("&Cancel"))); + && edit_get_byte (edit, edit->last_byte - 1) != '\n' + && edit_query_dialog2 (_("Warning"), + _("The file you are saving is not finished with a newline"), + _("C&ontinue"), _("&Cancel"))); } static char * -edit_get_save_file_as (WEdit *edit) +edit_get_save_file_as (WEdit * edit) { #define DLG_WIDTH 64 #define DLG_HEIGHT 14 @@ -500,35 +531,34 @@ edit_get_save_file_as (WEdit *edit) char *filename = edit->filename; - const char *lb_names[LB_NAMES] = - { + const char *lb_names[LB_NAMES] = { N_("&Do not change"), N_("&Unix format (LF)"), N_("&Windows/DOS format (CR LF)"), N_("&Macintosh format (CR)") }; - QuickWidget quick_widgets[] = - { - QUICK_BUTTON (6, 10, DLG_HEIGHT - 3, DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), - QUICK_BUTTON (2, 10, DLG_HEIGHT - 3, DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), - QUICK_RADIO (5, DLG_WIDTH, DLG_HEIGHT - 8, DLG_HEIGHT, LB_NAMES, lb_names, (int *) &cur_lb), - QUICK_LABEL (3, DLG_WIDTH, DLG_HEIGHT - 9, DLG_HEIGHT, N_("Change line breaks to:")), - QUICK_INPUT (3, DLG_WIDTH, DLG_HEIGHT - 11, DLG_HEIGHT, filename, DLG_WIDTH - 6, 0, "save-as", &filename), - QUICK_LABEL (2, DLG_WIDTH, DLG_HEIGHT - 12, DLG_HEIGHT, N_(" Enter file name: ")), - QUICK_END + QuickWidget quick_widgets[] = { + QUICK_BUTTON (6, 10, DLG_HEIGHT - 3, DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), + QUICK_BUTTON (2, 10, DLG_HEIGHT - 3, DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), + QUICK_RADIO (5, DLG_WIDTH, DLG_HEIGHT - 8, DLG_HEIGHT, LB_NAMES, lb_names, (int *) &cur_lb), + QUICK_LABEL (3, DLG_WIDTH, DLG_HEIGHT - 9, DLG_HEIGHT, N_("Change line breaks to:")), + QUICK_INPUT (3, DLG_WIDTH, DLG_HEIGHT - 11, DLG_HEIGHT, filename, DLG_WIDTH - 6, 0, + "save-as", &filename), + QUICK_LABEL (2, DLG_WIDTH, DLG_HEIGHT - 12, DLG_HEIGHT, N_(" Enter file name: ")), + QUICK_END }; - QuickDialog Quick_options = - { - DLG_WIDTH, DLG_HEIGHT, -1, -1, - N_(" Save As "), "[Save File As]", - quick_widgets, FALSE + QuickDialog Quick_options = { + DLG_WIDTH, DLG_HEIGHT, -1, -1, + N_(" Save As "), "[Save File As]", + quick_widgets, FALSE }; - if (quick_dialog (&Quick_options) != B_CANCEL) { - edit->lb = cur_lb; - return filename; + if (quick_dialog (&Quick_options) != B_CANCEL) + { + edit->lb = cur_lb; + return filename; } return NULL; @@ -541,7 +571,7 @@ edit_get_save_file_as (WEdit *edit) but only if they have made a change to the filename */ /* returns 1 on success */ int -edit_save_as_cmd (WEdit *edit) +edit_save_as_cmd (WEdit * edit) { /* This heads the 'Save As' dialog box */ char *exp; @@ -554,85 +584,98 @@ edit_save_as_cmd (WEdit *edit) exp = edit_get_save_file_as (edit); edit_push_action (edit, KEY_PRESS + edit->start_display); - if (exp) { - if (!*exp) { - g_free (exp); - edit->force |= REDRAW_COMPLETELY; - return 0; - } else { - int rv; - if (strcmp (edit->filename, exp)) { - int file; - different_filename = 1; - if ((file = mc_open (exp, O_RDONLY | O_BINARY)) != -1) { - /* the file exists */ - mc_close (file); - /* Overwrite the current file or cancel the operation */ - if (edit_query_dialog2 - (_("Warning"), - _(" A file already exists with this name. "), - _("&Overwrite"), _("&Cancel"))) { - edit->force |= REDRAW_COMPLETELY; - g_free (exp); - return 0; - } - } else { - edit->stat1.st_mode |= S_IWUSR; - } - save_lock = edit_lock_file (exp); - } else { - /* filenames equal, check if already locked */ - if (!edit->locked && !edit->delete_file) - save_lock = edit_lock_file (exp); - } + if (exp) + { + if (!*exp) + { + g_free (exp); + edit->force |= REDRAW_COMPLETELY; + return 0; + } + else + { + int rv; + if (strcmp (edit->filename, exp)) + { + int file; + different_filename = 1; + if ((file = mc_open (exp, O_RDONLY | O_BINARY)) != -1) + { + /* the file exists */ + mc_close (file); + /* Overwrite the current file or cancel the operation */ + if (edit_query_dialog2 + (_("Warning"), + _(" A file already exists with this name. "), + _("&Overwrite"), _("&Cancel"))) + { + edit->force |= REDRAW_COMPLETELY; + g_free (exp); + return 0; + } + } + else + { + edit->stat1.st_mode |= S_IWUSR; + } + save_lock = edit_lock_file (exp); + } + else + { + /* filenames equal, check if already locked */ + if (!edit->locked && !edit->delete_file) + save_lock = edit_lock_file (exp); + } - if (different_filename) - { - /* - * Allow user to write into saved (under another name) file - * even if original file had r/o user permissions. - */ - edit->stat1.st_mode |= S_IWRITE; - } + if (different_filename) + { + /* + * Allow user to write into saved (under another name) file + * even if original file had r/o user permissions. + */ + edit->stat1.st_mode |= S_IWRITE; + } - rv = edit_save_file (edit, exp); - switch (rv) { - case 1: - /* Succesful, so unlock both files */ - if (different_filename) { - if (save_lock) - edit_unlock_file (exp); - if (edit->locked) - edit->locked = edit_unlock_file (edit->filename); - } else { - if (edit->locked || save_lock) - edit->locked = edit_unlock_file (edit->filename); - } + rv = edit_save_file (edit, exp); + switch (rv) + { + case 1: + /* Succesful, so unlock both files */ + if (different_filename) + { + if (save_lock) + edit_unlock_file (exp); + if (edit->locked) + edit->locked = edit_unlock_file (edit->filename); + } + else + { + if (edit->locked || save_lock) + edit->locked = edit_unlock_file (edit->filename); + } - edit_set_filename (edit, exp); - if (edit->lb != LB_ASIS) - edit_reload(edit, exp); - g_free (exp); - edit->modified = 0; - edit->delete_file = 0; - if (different_filename) - edit_load_syntax (edit, NULL, option_syntax_type); - edit->force |= REDRAW_COMPLETELY; - return 1; - default: - edit_error_dialog (_(" Save As "), - get_sys_error (_ - (" Cannot save file. "))); - /* fallthrough */ - case -1: - /* Failed, so maintain modify (not save) lock */ - if (save_lock) - edit_unlock_file (exp); - g_free (exp); - edit->force |= REDRAW_COMPLETELY; - return 0; - } - } + edit_set_filename (edit, exp); + if (edit->lb != LB_ASIS) + edit_reload (edit, exp); + g_free (exp); + edit->modified = 0; + edit->delete_file = 0; + if (different_filename) + edit_load_syntax (edit, NULL, option_syntax_type); + edit->force |= REDRAW_COMPLETELY; + return 1; + default: + edit_error_dialog (_(" Save As "), get_sys_error (_(" Cannot save file. "))); + /* fallthrough */ + case -1: + /* Failed, so maintain modify (not save) lock */ + if (save_lock) + edit_unlock_file (exp); + g_free (exp); + edit->force |= REDRAW_COMPLETELY; + return 0; + } + } } edit->force |= REDRAW_COMPLETELY; return 0; @@ -641,19 +684,21 @@ edit_save_as_cmd (WEdit *edit) /* {{{ Macro stuff starts here */ /* creates a macro file if it doesn't exist */ -static FILE *edit_open_macro_file (const char *r) +static FILE * +edit_open_macro_file (const char *r) { gchar *filename; FILE *fd; int file; filename = concat_dir_and_file (home_dir, EDIT_MACRO_FILE); - if ((file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1){ - g_free(filename); - return 0; + if ((file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) + { + g_free (filename); + return 0; } close (file); fd = fopen (filename, r); - g_free(filename); + g_free (filename); return fd; } @@ -670,8 +715,8 @@ macro_exists (int k) { int i; for (i = 0; i < MAX_MACROS && saved_macro[i]; i++) - if (saved_macro[i] == k) - return i; + if (saved_macro[i] == k) + return i; return -1; } @@ -687,84 +732,90 @@ edit_delete_macro (WEdit * edit, int k) (void) edit; if (saved_macros_loaded) - if ((j = macro_exists (k)) < 0) - return 0; + if ((j = macro_exists (k)) < 0) + return 0; tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE); - g = fopen (tmp , "w"); - g_free(tmp); - if (!g) { - edit_error_dialog (_(" Delete macro "), - get_sys_error (_(" Cannot open temp file "))); - return 1; + g = fopen (tmp, "w"); + g_free (tmp); + if (!g) + { + edit_error_dialog (_(" Delete macro "), get_sys_error (_(" Cannot open temp file "))); + return 1; } f = edit_open_macro_file ("r"); - if (!f) { - edit_error_dialog (_(" Delete macro "), - get_sys_error (_(" Cannot open macro file "))); - fclose (g); - return 1; + if (!f) + { + edit_error_dialog (_(" Delete macro "), get_sys_error (_(" Cannot open macro file "))); + fclose (g); + return 1; } - for (;;) { - n = fscanf (f, ("key '%d 0': "), &s); - if (!n || n == EOF) - break; - n = 0; - while (fscanf (f, "%lu %d, ", ¯o[n].command, ¯o[n].ch)) - n++; - fscanf (f, ";\n"); - if (s != k) { - fprintf (g, ("key '%d 0': "), s); - for (i = 0; i < n; i++) - fprintf (g, "%lu %d, ", macro[i].command, macro[i].ch); - fprintf (g, ";\n"); - } + for (;;) + { + n = fscanf (f, ("key '%d 0': "), &s); + if (!n || n == EOF) + break; + n = 0; + while (fscanf (f, "%lu %d, ", ¯o[n].command, ¯o[n].ch)) + n++; + fscanf (f, ";\n"); + if (s != k) + { + fprintf (g, ("key '%d 0': "), s); + for (i = 0; i < n; i++) + fprintf (g, "%lu %d, ", macro[i].command, macro[i].ch); + fprintf (g, ";\n"); + } } fclose (f); fclose (g); tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE); tmp2 = concat_dir_and_file (home_dir, EDIT_MACRO_FILE); - if (rename ( tmp, tmp2) == -1) { - edit_error_dialog (_(" Delete macro "), - get_sys_error (_(" Cannot overwrite macro file "))); - g_free(tmp); - g_free(tmp2); - return 1; + if (rename (tmp, tmp2) == -1) + { + edit_error_dialog (_(" Delete macro "), get_sys_error (_(" Cannot overwrite macro file "))); + g_free (tmp); + g_free (tmp2); + return 1; } - g_free(tmp); - g_free(tmp2); + g_free (tmp); + g_free (tmp2); if (saved_macros_loaded) - memmove (saved_macro + j, saved_macro + j + 1, sizeof (int) * (MAX_MACROS - j - 1)); + memmove (saved_macro + j, saved_macro + j + 1, sizeof (int) * (MAX_MACROS - j - 1)); return 0; } /* returns 0 on error */ -int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n) +int +edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n) { FILE *f; int s, i; edit_push_action (edit, KEY_PRESS + edit->start_display); - s = editcmd_dialog_raw_key_query (_(" Save macro "), - _(" Press the macro's new hotkey: "), 1); + s = editcmd_dialog_raw_key_query (_(" Save macro "), _(" Press the macro's new hotkey: "), 1); edit->force |= REDRAW_COMPLETELY; - if (s) { - if (edit_delete_macro (edit, s)) - return 0; - f = edit_open_macro_file ("a+"); - if (f) { - fprintf (f, ("key '%d 0': "), s); - for (i = 0; i < n; i++) - fprintf (f, "%lu %d, ", macro[i].command, macro[i].ch); - fprintf (f, ";\n"); - fclose (f); - if (saved_macros_loaded) { - for (i = 0; i < MAX_MACROS && saved_macro[i]; i++); - saved_macro[i] = s; - } - return 1; - } else - edit_error_dialog (_(" Save macro "), get_sys_error (_(" Cannot open macro file "))); + if (s) + { + if (edit_delete_macro (edit, s)) + return 0; + f = edit_open_macro_file ("a+"); + if (f) + { + fprintf (f, ("key '%d 0': "), s); + for (i = 0; i < n; i++) + fprintf (f, "%lu %d, ", macro[i].command, macro[i].ch); + fprintf (f, ";\n"); + fclose (f); + if (saved_macros_loaded) + { + for (i = 0; i < MAX_MACROS && saved_macro[i]; i++); + saved_macro[i] = s; + } + return 1; + } + else + edit_error_dialog (_(" Save macro "), get_sys_error (_(" Cannot open macro file "))); } return 0; } @@ -774,15 +825,15 @@ edit_delete_macro_cmd (WEdit * edit) { int command; - command = editcmd_dialog_raw_key_query (_ (" Delete macro "), - _ (" Press macro hotkey: "), 1); + command = editcmd_dialog_raw_key_query (_(" Delete macro "), _(" Press macro hotkey: "), 1); if (command != 0) - edit_delete_macro (edit, command); + edit_delete_macro (edit, command); } /* return 0 on error */ -int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k) +int +edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k) { FILE *f; int s, i = 0, found = 0; @@ -790,58 +841,69 @@ int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k) (void) edit; if (saved_macros_loaded) - if (macro_exists (k) < 0) - return 0; + if (macro_exists (k) < 0) + return 0; - if ((f = edit_open_macro_file ("r"))) { - struct macro dummy; - do { - int u; - u = fscanf (f, ("key '%d 0': "), &s); - if (!u || u == EOF) - break; - if (!saved_macros_loaded) - saved_macro[i++] = s; - if (!found) { - *n = 0; - while (*n < MAX_MACRO_LENGTH && 2 == fscanf (f, "%lu %d, ", ¯o[*n].command, ¯o[*n].ch)) - (*n)++; - } else { - while (2 == fscanf (f, "%lu %d, ", &dummy.command, &dummy.ch)); - } - fscanf (f, ";\n"); - if (s == k) - found = 1; - } while (!found || !saved_macros_loaded); - if (!saved_macros_loaded) { - saved_macro[i] = 0; - saved_macros_loaded = 1; - } - fclose (f); - return found; - } else - edit_error_dialog (_(" Load macro "), - get_sys_error (_(" Cannot open macro file "))); + if ((f = edit_open_macro_file ("r"))) + { + struct macro dummy; + do + { + int u; + u = fscanf (f, ("key '%d 0': "), &s); + if (!u || u == EOF) + break; + if (!saved_macros_loaded) + saved_macro[i++] = s; + if (!found) + { + *n = 0; + while (*n < MAX_MACRO_LENGTH + && 2 == fscanf (f, "%lu %d, ", ¯o[*n].command, ¯o[*n].ch)) + (*n)++; + } + else + { + while (2 == fscanf (f, "%lu %d, ", &dummy.command, &dummy.ch)); + } + fscanf (f, ";\n"); + if (s == k) + found = 1; + } + while (!found || !saved_macros_loaded); + if (!saved_macros_loaded) + { + saved_macro[i] = 0; + saved_macros_loaded = 1; + } + fclose (f); + return found; + } + else + edit_error_dialog (_(" Load macro "), get_sys_error (_(" Cannot open macro file "))); return 0; } /* }}} Macro stuff starts here */ /* returns 1 on success */ -int edit_save_confirm_cmd (WEdit * edit) +int +edit_save_confirm_cmd (WEdit * edit) { gchar *f = NULL; if (!edit_check_newline (edit)) return 0; - if (edit_confirm_save) { - f = g_strconcat (_(" Confirm save file? : "), edit->filename, " ", (char *) NULL); - if (edit_query_dialog2 (_(" Save file "), f, _("&Save"), _("&Cancel"))){ - g_free(f); - return 0; - } - g_free(f); + if (edit_confirm_save) + { + f = g_strconcat (_(" Confirm save file? : "), edit->filename, " ", (char *) NULL); + if (edit_query_dialog2 (_(" Save file "), f, _("&Save"), _("&Cancel"))) + { + g_free (f); + return 0; + } + g_free (f); } return edit_save_cmd (edit); } @@ -849,23 +911,24 @@ int edit_save_confirm_cmd (WEdit * edit) /* returns 1 on success */ static int -edit_save_cmd (WEdit *edit) +edit_save_cmd (WEdit * edit) { int res, save_lock = 0; if (!edit->locked && !edit->delete_file) - save_lock = edit_lock_file (edit->filename); + save_lock = edit_lock_file (edit->filename); res = edit_save_file (edit, edit->filename); /* Maintain modify (not save) lock on failure */ if ((res > 0 && edit->locked) || save_lock) - edit->locked = edit_unlock_file (edit->filename); + edit->locked = edit_unlock_file (edit->filename); /* On failure try 'save as', it does locking on its own */ if (!res) - return edit_save_as_cmd (edit); + return edit_save_as_cmd (edit); edit->force |= REDRAW_COMPLETELY; - if (res > 0) { + if (res > 0) + { edit->delete_file = 0; edit->modified = 0; } @@ -875,17 +938,24 @@ edit_save_cmd (WEdit *edit) /* returns 1 on success */ -int edit_new_cmd (WEdit * edit) +int +edit_new_cmd (WEdit * edit) { - if (edit->modified) { - if (edit_query_dialog2 (_ ("Warning"), _ (" Current text was modified without a file save. \n Continue discards these changes. "), _ ("C&ontinue"), _ ("&Cancel"))) { - edit->force |= REDRAW_COMPLETELY; - return 0; - } + if (edit->modified) + { + if (edit_query_dialog2 + (_("Warning"), + _ + (" Current text was modified without a file save. \n Continue discards these changes. "), + _("C&ontinue"), _("&Cancel"))) + { + edit->force |= REDRAW_COMPLETELY; + return 0; + } } edit->force |= REDRAW_COMPLETELY; - return edit_renew (edit); /* if this gives an error, something has really screwed up */ + return edit_renew (edit); /* if this gives an error, something has really screwed up */ } /* returns 1 on error */ @@ -895,13 +965,14 @@ edit_load_file_from_filename (WEdit * edit, char *exp) int prev_locked = edit->locked; char *prev_filename = g_strdup (edit->filename); - if (!edit_reload (edit, exp)) { - g_free (prev_filename); - return 1; + if (!edit_reload (edit, exp)) + { + g_free (prev_filename); + return 1; } if (prev_locked) - edit_unlock_file (prev_filename); + edit_unlock_file (prev_filename); g_free (prev_filename); return 0; } @@ -912,27 +983,31 @@ edit_load_syntax_file (WEdit * edit) char *extdir; int dir = 0; - if (geteuid () == 0) { - dir = query_dialog (_("Syntax file edit"), - _(" Which syntax file you want to edit? "), D_NORMAL, 2, - _("&User"), _("&System Wide")); + if (geteuid () == 0) + { + dir = query_dialog (_("Syntax file edit"), + _(" Which syntax file you want to edit? "), D_NORMAL, 2, + _("&User"), _("&System Wide")); } extdir = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); - if (!exist_file(extdir)) { - g_free (extdir); - extdir = concat_dir_and_file (mc_home_alt, "syntax" PATH_SEP_STR "Syntax"); + if (!exist_file (extdir)) + { + g_free (extdir); + extdir = concat_dir_and_file (mc_home_alt, "syntax" PATH_SEP_STR "Syntax"); } - if (dir == 0) { - char *buffer; + if (dir == 0) + { + char *buffer; - buffer = concat_dir_and_file (home_dir, EDIT_SYNTAX_FILE); - check_for_default (extdir, buffer); - edit_load_file_from_filename (edit, buffer); - g_free (buffer); - } else if (dir == 1) - edit_load_file_from_filename (edit, extdir); + buffer = concat_dir_and_file (home_dir, EDIT_SYNTAX_FILE); + check_for_default (extdir, buffer); + edit_load_file_from_filename (edit, buffer); + g_free (buffer); + } + else if (dir == 1) + edit_load_file_from_filename (edit, extdir); g_free (extdir); } @@ -944,42 +1019,43 @@ edit_load_menu_file (WEdit * edit) char *menufile; int dir = 0; - dir = query_dialog ( - _(" Menu edit "), - _(" Which menu file do you want to edit? "), D_NORMAL, - geteuid() ? 2 : 3, _("&Local"), _("&User"), _("&System Wide") - ); + dir = query_dialog (_(" Menu edit "), + _(" Which menu file do you want to edit? "), D_NORMAL, + geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide")); menufile = concat_dir_and_file (mc_home, EDIT_GLOBAL_MENU); - if (!exist_file (menufile)) { - g_free (menufile); - menufile = concat_dir_and_file (mc_home_alt, EDIT_GLOBAL_MENU); + if (!exist_file (menufile)) + { + g_free (menufile); + menufile = concat_dir_and_file (mc_home_alt, EDIT_GLOBAL_MENU); } - switch (dir) { - case 0: - buffer = g_strdup (EDIT_LOCAL_MENU); - check_for_default (menufile, buffer); - chmod (buffer, 0600); - break; + switch (dir) + { + case 0: + buffer = g_strdup (EDIT_LOCAL_MENU); + check_for_default (menufile, buffer); + chmod (buffer, 0600); + break; - case 1: - buffer = concat_dir_and_file (home_dir, EDIT_HOME_MENU); - check_for_default (menufile, buffer); - break; - - case 2: - buffer = concat_dir_and_file (mc_home, EDIT_GLOBAL_MENU); - if (!exist_file (buffer)) { - g_free (buffer); - buffer = concat_dir_and_file (mc_home_alt, EDIT_GLOBAL_MENU); - } - break; + case 1: + buffer = concat_dir_and_file (home_dir, EDIT_HOME_MENU); + check_for_default (menufile, buffer); + break; - default: - g_free (menufile); - return; + case 2: + buffer = concat_dir_and_file (mc_home, EDIT_GLOBAL_MENU); + if (!exist_file (buffer)) + { + g_free (buffer); + buffer = concat_dir_and_file (mc_home_alt, EDIT_GLOBAL_MENU); + } + break; + + default: + g_free (menufile); + return; } edit_load_file_from_filename (edit, buffer); @@ -989,42 +1065,44 @@ edit_load_menu_file (WEdit * edit) } int -edit_load_cmd (WEdit *edit, edit_current_file_t what) +edit_load_cmd (WEdit * edit, edit_current_file_t what) { char *exp; if (edit->modified - && (edit_query_dialog2 - (_("Warning"), - _(" Current text was modified without a file save. \n" - " Continue discards these changes. "), - _("C&ontinue"), _("&Cancel")) == 1)) { - edit->force |= REDRAW_COMPLETELY; - return 0; - } + && (edit_query_dialog2 + (_("Warning"), + _(" Current text was modified without a file save. \n" + " Continue discards these changes. "), _("C&ontinue"), _("&Cancel")) == 1)) + { + edit->force |= REDRAW_COMPLETELY; + return 0; + } - switch (what) { + switch (what) + { case EDIT_FILE_COMMON: - exp = input_expand_dialog (_(" Load "), _(" Enter file name: "), - MC_HISTORY_EDIT_LOAD, edit->filename); + exp = input_expand_dialog (_(" Load "), _(" Enter file name: "), + MC_HISTORY_EDIT_LOAD, edit->filename); - if (exp) { - if (*exp) - edit_load_file_from_filename (edit, exp); - g_free (exp); - } - break; + if (exp) + { + if (*exp) + edit_load_file_from_filename (edit, exp); + g_free (exp); + } + break; case EDIT_FILE_SYNTAX: - edit_load_syntax_file (edit); - break; + edit_load_syntax_file (edit); + break; case EDIT_FILE_MENU: - edit_load_menu_file (edit); - break; + edit_load_menu_file (edit); + break; default: - break; + break; } edit->force |= REDRAW_COMPLETELY; @@ -1036,24 +1114,30 @@ edit_load_cmd (WEdit *edit, edit_current_file_t what) Otherwise its between the markers. This handles this. Returns 1 if no text is marked. */ -int eval_marks (WEdit * edit, long *start_mark, long *end_mark) +int +eval_marks (WEdit * edit, long *start_mark, long *end_mark) { - if (edit->mark1 != edit->mark2) { + if (edit->mark1 != edit->mark2) + { long start_bol, start_eol; long end_bol, end_eol; long col1, col2; long diff1, diff2; - if (edit->mark2 >= 0) { + if (edit->mark2 >= 0) + { *start_mark = min (edit->mark1, edit->mark2); *end_mark = max (edit->mark1, edit->mark2); - } else { + } + else + { *start_mark = min (edit->mark1, edit->curs1); *end_mark = max (edit->mark1, edit->curs1); edit->column2 = edit->curs_col + edit->over_col; } if (column_highlighting && (((edit->mark1 > edit->curs1) && (edit->column1 < edit->column2)) - || ((edit->mark1 < edit->curs1) && (edit->column1 > edit->column2)))) { + || ((edit->mark1 < edit->curs1) && (edit->column1 > edit->column2)))) + { start_bol = edit_bol (edit, *start_mark); start_eol = edit_eol (edit, start_bol - 1) + 1; @@ -1062,8 +1146,12 @@ int eval_marks (WEdit * edit, long *start_mark, long *end_mark) col1 = min (edit->column1, edit->column2); col2 = max (edit->column1, edit->column2); - diff1 = edit_move_forward3 (edit, start_bol, col2, 0) - edit_move_forward3 (edit, start_bol, col1, 0); - diff2 = edit_move_forward3 (edit, end_bol, col2, 0) - edit_move_forward3 (edit, end_bol, col1, 0); + diff1 = + edit_move_forward3 (edit, start_bol, col2, 0) - edit_move_forward3 (edit, start_bol, + col1, 0); + diff2 = + edit_move_forward3 (edit, end_bol, col2, 0) - edit_move_forward3 (edit, end_bol, + col1, 0); *start_mark -= diff1; *end_mark += diff2; @@ -1071,7 +1159,9 @@ int eval_marks (WEdit * edit, long *start_mark, long *end_mark) *end_mark = min (*end_mark, end_eol); } return 0; - } else { + } + else + { *start_mark = *end_mark = 0; edit->column2 = edit->column1 = 0; return 1; @@ -1087,38 +1177,46 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid int i, col; cursor = edit->curs1; col = edit_get_col (edit); - for (i = 0; i < size; i++) { - if (data[i] == '\n') { /* fill in and move to next line */ - int l; - long p; - if (edit_get_byte (edit, edit->curs1) != '\n') { - l = width - (edit_get_col (edit) - col); - while (l > 0) { - edit_insert (edit, ' '); - l -= space_width; - } - } - for (p = edit->curs1;; p++) { - if (p == edit->last_byte) { - edit_cursor_move (edit, edit->last_byte - edit->curs1); - edit_insert_ahead (edit, '\n'); - p++; - break; - } - if (edit_get_byte (edit, p) == '\n') { - p++; - break; - } - } - edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); - l = col - edit_get_col (edit); - while (l >= space_width) { - edit_insert (edit, ' '); - l -= space_width; - } - continue; - } - edit_insert (edit, data[i]); + for (i = 0; i < size; i++) + { + if (data[i] == '\n') + { /* fill in and move to next line */ + int l; + long p; + if (edit_get_byte (edit, edit->curs1) != '\n') + { + l = width - (edit_get_col (edit) - col); + while (l > 0) + { + edit_insert (edit, ' '); + l -= space_width; + } + } + for (p = edit->curs1;; p++) + { + if (p == edit->last_byte) + { + edit_cursor_move (edit, edit->last_byte - edit->curs1); + edit_insert_ahead (edit, '\n'); + p++; + break; + } + if (edit_get_byte (edit, p) == '\n') + { + p++; + break; + } + } + edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); + l = col - edit_get_col (edit); + while (l >= space_width) + { + edit_insert (edit, ' '); + l -= space_width; + } + continue; + } + edit_insert (edit, data[i]); } edit_cursor_move (edit, cursor - edit->curs1); } @@ -1135,37 +1233,47 @@ edit_insert_column_of_text_from_file (WEdit * edit, int file) cursor = edit->curs1; col = edit_get_col (edit); data = g_malloc0 (TEMP_BUF_LEN); - while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0) { - for (width = 0; width < blocklen; width++) { + while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0) + { + for (width = 0; width < blocklen; width++) + { if (data[width] == '\n') break; } - for (i = 0; i < blocklen; i++) { - if (data[i] == '\n') { /* fill in and move to next line */ + for (i = 0; i < blocklen; i++) + { + if (data[i] == '\n') + { /* fill in and move to next line */ int l; long p; - if (edit_get_byte (edit, edit->curs1) != '\n') { + if (edit_get_byte (edit, edit->curs1) != '\n') + { l = width - (edit_get_col (edit) - col); - while (l > 0) { + while (l > 0) + { edit_insert (edit, ' '); l -= space_width; } } - for (p = edit->curs1;; p++) { - if (p == edit->last_byte) { + for (p = edit->curs1;; p++) + { + if (p == edit->last_byte) + { edit_cursor_move (edit, edit->last_byte - edit->curs1); edit_insert_ahead (edit, '\n'); p++; break; } - if (edit_get_byte (edit, p) == '\n') { + if (edit_get_byte (edit, p) == '\n') + { p++; break; } } edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); l = col - edit_get_col (edit); - while (l >= space_width) { + while (l >= space_width) + { edit_insert (edit, ' '); l -= space_width; } @@ -1175,13 +1283,13 @@ edit_insert_column_of_text_from_file (WEdit * edit, int file) } } edit_cursor_move (edit, cursor - edit->curs1); - g_free(data); + g_free (data); edit->force |= REDRAW_PAGE; return blocklen; } void -edit_block_copy_cmd (WEdit *edit) +edit_block_copy_cmd (WEdit * edit) { long start_mark, end_mark, current = edit->curs1; int size; @@ -1189,7 +1297,7 @@ edit_block_copy_cmd (WEdit *edit) edit_update_curs_col (edit); if (eval_marks (edit, &start_mark, &end_mark)) - return; + return; copy_buf = edit_get_block (edit, start_mark, end_mark, &size); @@ -1197,31 +1305,34 @@ edit_block_copy_cmd (WEdit *edit) edit_push_markers (edit); - if (column_highlighting) { - edit_insert_column_of_text (edit, copy_buf, size, - abs (edit->column2 - edit->column1)); - } else { - while (size--) - edit_insert_ahead (edit, copy_buf[size]); + if (column_highlighting) + { + edit_insert_column_of_text (edit, copy_buf, size, abs (edit->column2 - edit->column1)); + } + else + { + while (size--) + edit_insert_ahead (edit, copy_buf[size]); } g_free (copy_buf); edit_scroll_screen_over_cursor (edit); - if (column_highlighting) { - edit_set_markers (edit, 0, 0, 0, 0); - edit_push_action (edit, COLUMN_ON); - column_highlighting = 0; - } else if (start_mark < current && end_mark > current) - edit_set_markers (edit, start_mark, - end_mark + end_mark - start_mark, 0, 0); + if (column_highlighting) + { + edit_set_markers (edit, 0, 0, 0, 0); + edit_push_action (edit, COLUMN_ON); + column_highlighting = 0; + } + else if (start_mark < current && end_mark > current) + edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0); edit->force |= REDRAW_PAGE; } void -edit_block_move_cmd (WEdit *edit) +edit_block_move_cmd (WEdit * edit) { long count; long current; @@ -1231,80 +1342,84 @@ edit_block_move_cmd (WEdit *edit) int x = 0; if (eval_marks (edit, &start_mark, &end_mark)) - return; - if (column_highlighting) { - edit_update_curs_col (edit); - x = edit->curs_col; - if (start_mark <= edit->curs1 && end_mark >= edit->curs1) - if ((x > edit->column1 && x < edit->column2) - || (x > edit->column2 && x < edit->column1)) - return; - } else if (start_mark <= edit->curs1 && end_mark >= edit->curs1) - return; + return; + if (column_highlighting) + { + edit_update_curs_col (edit); + x = edit->curs_col; + if (start_mark <= edit->curs1 && end_mark >= edit->curs1) + if ((x > edit->column1 && x < edit->column2) + || (x > edit->column2 && x < edit->column1)) + return; + } + else if (start_mark <= edit->curs1 && end_mark >= edit->curs1) + return; if ((end_mark - start_mark) > option_max_undo / 2) - if (edit_query_dialog2 - (_("Warning"), - _ - (" Block is large, you may not be able to undo this action. "), - _("C&ontinue"), _("&Cancel"))) - return; + if (edit_query_dialog2 + (_("Warning"), + _ + (" Block is large, you may not be able to undo this action. "), + _("C&ontinue"), _("&Cancel"))) + return; edit_push_markers (edit); current = edit->curs1; - if (column_highlighting) { - long line; - int size, c1, c2; - line = edit->curs_line; - if (edit->mark2 < 0) - edit_mark_cmd (edit, 0); - c1 = min (edit->column1, edit->column2); - c2 = max (edit->column1, edit->column2); - copy_buf = edit_get_block (edit, start_mark, end_mark, &size); - if (x < c2) { - edit_block_delete_cmd (edit); - deleted = 1; - } - edit_move_to_line (edit, line); - edit_cursor_move (edit, - edit_move_forward3 (edit, - edit_bol (edit, edit->curs1), - x, 0) - edit->curs1); - edit_insert_column_of_text (edit, copy_buf, size, c2 - c1); - if (!deleted) { - line = edit->curs_line; - edit_update_curs_col (edit); - x = edit->curs_col; - edit_block_delete_cmd (edit); - edit_move_to_line (edit, line); - edit_cursor_move (edit, - edit_move_forward3 (edit, - edit_bol (edit, - edit->curs1), - x, 0) - edit->curs1); - } - edit_set_markers (edit, 0, 0, 0, 0); - edit_push_action (edit, COLUMN_ON); - column_highlighting = 0; - } else { - copy_buf = g_malloc0 (end_mark - start_mark); - edit_cursor_move (edit, start_mark - edit->curs1); - edit_scroll_screen_over_cursor (edit); - count = start_mark; - while (count < end_mark) { - copy_buf[end_mark - count - 1] = edit_delete (edit, 1); - count++; - } - edit_scroll_screen_over_cursor (edit); - edit_cursor_move (edit, - current - edit->curs1 - - (((current - edit->curs1) > - 0) ? end_mark - start_mark : 0)); - edit_scroll_screen_over_cursor (edit); - while (count-- > start_mark) - edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); - edit_set_markers (edit, edit->curs1, - edit->curs1 + end_mark - start_mark, 0, 0); + if (column_highlighting) + { + long line; + int size, c1, c2; + line = edit->curs_line; + if (edit->mark2 < 0) + edit_mark_cmd (edit, 0); + c1 = min (edit->column1, edit->column2); + c2 = max (edit->column1, edit->column2); + copy_buf = edit_get_block (edit, start_mark, end_mark, &size); + if (x < c2) + { + edit_block_delete_cmd (edit); + deleted = 1; + } + edit_move_to_line (edit, line); + edit_cursor_move (edit, + edit_move_forward3 (edit, + edit_bol (edit, edit->curs1), x, 0) - edit->curs1); + edit_insert_column_of_text (edit, copy_buf, size, c2 - c1); + if (!deleted) + { + line = edit->curs_line; + edit_update_curs_col (edit); + x = edit->curs_col; + edit_block_delete_cmd (edit); + edit_move_to_line (edit, line); + edit_cursor_move (edit, + edit_move_forward3 (edit, + edit_bol (edit, + edit->curs1), x, 0) - edit->curs1); + } + edit_set_markers (edit, 0, 0, 0, 0); + edit_push_action (edit, COLUMN_ON); + column_highlighting = 0; + } + else + { + copy_buf = g_malloc0 (end_mark - start_mark); + edit_cursor_move (edit, start_mark - edit->curs1); + edit_scroll_screen_over_cursor (edit); + count = start_mark; + while (count < end_mark) + { + copy_buf[end_mark - count - 1] = edit_delete (edit, 1); + count++; + } + edit_scroll_screen_over_cursor (edit); + edit_cursor_move (edit, + current - edit->curs1 - + (((current - edit->curs1) > 0) ? end_mark - start_mark : 0)); + edit_scroll_screen_over_cursor (edit); + while (count-- > start_mark) + edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); + edit_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0); } edit_scroll_screen_over_cursor (edit); g_free (copy_buf); @@ -1324,30 +1439,32 @@ edit_delete_column_of_text (WEdit * edit) b = max (min (c, d), min (edit->column1, edit->column2)); c = max (c, max (edit->column1, edit->column2)); - while (n--) { - r = edit_bol (edit, edit->curs1); - p = edit_move_forward3 (edit, r, b, 0); - q = edit_move_forward3 (edit, r, c, 0); - if (p < m1) - p = m1; - if (q > m2) - q = m2; - edit_cursor_move (edit, p - edit->curs1); - while (q > p) { - /* delete line between margins */ - if (edit_get_byte (edit, edit->curs1) != '\n') - edit_delete (edit, 1); - q--; - } - if (n) - /* move to next line except on the last delete */ - edit_cursor_move (edit, edit_move_forward (edit, edit->curs1, 1, 0) - edit->curs1); + while (n--) + { + r = edit_bol (edit, edit->curs1); + p = edit_move_forward3 (edit, r, b, 0); + q = edit_move_forward3 (edit, r, c, 0); + if (p < m1) + p = m1; + if (q > m2) + q = m2; + edit_cursor_move (edit, p - edit->curs1); + while (q > p) + { + /* delete line between margins */ + if (edit_get_byte (edit, edit->curs1) != '\n') + edit_delete (edit, 1); + q--; + } + if (n) + /* move to next line except on the last delete */ + edit_cursor_move (edit, edit_move_forward (edit, edit->curs1, 1, 0) - edit->curs1); } } /* if success return 0 */ static int -edit_block_delete (WEdit *edit) +edit_block_delete (WEdit * edit) { long count; long start_mark, end_mark; @@ -1355,18 +1472,20 @@ edit_block_delete (WEdit *edit) long curs_line, c1, c2; if (eval_marks (edit, &start_mark, &end_mark)) - return 0; + return 0; if (column_highlighting && edit->mark2 < 0) - edit_mark_cmd (edit, 0); - if ((end_mark - start_mark) > option_max_undo / 2) { - /* Warning message with a query to continue or cancel the operation */ - if (edit_query_dialog2 - (_("Warning"), - _ - (" Block is large, you may not be able to undo this action. "), - _("C&ontinue"), _("&Cancel"))) { - return 1; - } + edit_mark_cmd (edit, 0); + if ((end_mark - start_mark) > option_max_undo / 2) + { + /* Warning message with a query to continue or cancel the operation */ + if (edit_query_dialog2 + (_("Warning"), + _ + (" Block is large, you may not be able to undo this action. "), + _("C&ontinue"), _("&Cancel"))) + { + return 1; + } } c1 = min (edit->column1, edit->column2); c2 = max (edit->column1, edit->column2); @@ -1386,24 +1505,29 @@ edit_block_delete (WEdit *edit) edit_cursor_move (edit, start_mark - edit->curs1); edit_scroll_screen_over_cursor (edit); count = start_mark; - if (start_mark < end_mark) { - if (column_highlighting) { - if (edit->mark2 < 0) - edit_mark_cmd (edit, 0); - edit_delete_column_of_text (edit); - /* move cursor to the saved position */ - edit_move_to_line (edit, curs_line); - /* calculate line width after cut */ - line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, + if (start_mark < end_mark) + { + if (column_highlighting) + { + if (edit->mark2 < 0) + edit_mark_cmd (edit, 0); + edit_delete_column_of_text (edit); + /* move cursor to the saved position */ + edit_move_to_line (edit, curs_line); + /* calculate line width after cut */ + line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit_eol (edit, edit->curs1)); - if (option_cursor_beyond_eol && curs_pos > line_width) - edit->over_col = curs_pos - line_width; - } else { - while (count < end_mark) { - edit_delete (edit, 1); - count++; - } - } + if (option_cursor_beyond_eol && curs_pos > line_width) + edit->over_col = curs_pos - line_width; + } + else + { + while (count < end_mark) + { + edit_delete (edit, 1); + count++; + } + } } edit_set_markers (edit, 0, 0, 0, 0); edit->force |= REDRAW_PAGE; @@ -1411,12 +1535,14 @@ edit_block_delete (WEdit *edit) } /* returns 1 if canceelled by user */ -int edit_block_delete_cmd (WEdit * edit) +int +edit_block_delete_cmd (WEdit * edit) { long start_mark, end_mark; - if (eval_marks (edit, &start_mark, &end_mark)) { - edit_delete_line (edit); - return 0; + if (eval_marks (edit, &start_mark, &end_mark)) + { + edit_delete_line (edit); + return 0; } return edit_block_delete (edit); } @@ -1424,7 +1550,7 @@ int edit_block_delete_cmd (WEdit * edit) #define INPUT_INDEX 9 static gboolean -editcmd_find (WEdit *edit, gsize *len) +editcmd_find (WEdit * edit, gsize * len) { off_t search_start = edit->search_start; off_t search_end; @@ -1432,42 +1558,57 @@ editcmd_find (WEdit *edit, gsize *len) long end_mark = edit->last_byte; int mark_res = 0; - if (edit_search_options.only_in_selection) { - mark_res = eval_marks(edit, &start_mark, &end_mark); - if (mark_res != 0) { + if (edit_search_options.only_in_selection) + { + mark_res = eval_marks (edit, &start_mark, &end_mark); + if (mark_res != 0) + { edit->search->error = MC_SEARCH_E_NOTFOUND; - edit->search->error_str = g_strdup(_(" Search string not found ")); + edit->search->error_str = g_strdup (_(" Search string not found ")); return FALSE; } - if (edit_search_options.backwards) { - if (search_start > end_mark || search_start <= start_mark) { + if (edit_search_options.backwards) + { + if (search_start > end_mark || search_start <= start_mark) + { search_start = end_mark; } - } else { - if (search_start < start_mark || search_start >= end_mark) { + } + else + { + if (search_start < start_mark || search_start >= end_mark) + { search_start = start_mark; } } - } else { - if (edit_search_options.backwards) - end_mark = max(1, edit->curs1) - 1; } - if (edit_search_options.backwards) { + else + { + if (edit_search_options.backwards) + end_mark = max (1, edit->curs1) - 1; + } + if (edit_search_options.backwards) + { search_end = end_mark; - while ((int) search_start >= start_mark) { + while ((int) search_start >= start_mark) + { if (search_end > (off_t) (search_start + edit->search->original_len) && - mc_search_is_fixed_search_str(edit->search)) { + mc_search_is_fixed_search_str (edit->search)) + { search_end = search_start + edit->search->original_len; } - if (mc_search_run(edit->search, (void *) edit, search_start, search_end, len) - && edit->search->normal_offset == search_start ) { + if (mc_search_run (edit->search, (void *) edit, search_start, search_end, len) + && edit->search->normal_offset == search_start) + { return TRUE; } search_start--; } - edit->search->error_str = g_strdup(_(" Search string not found ")); - } else { - return mc_search_run(edit->search, (void *) edit, search_start, end_mark, len); + edit->search->error_str = g_strdup (_(" Search string not found ")); + } + else + { + return mc_search_run (edit->search, (void *) edit, search_start, end_mark, len); } return FALSE; } @@ -1485,37 +1626,40 @@ edit_replace_cmd__conv_to_display (char *str) GString *tmp; tmp = str_convert_to_display (str); - if (tmp && tmp->len){ - return g_string_free (tmp, FALSE); + if (tmp && tmp->len) + { + return g_string_free (tmp, FALSE); } g_string_free (tmp, TRUE); #endif - return g_strdup(str); + return g_strdup (str); } static char * -edit_replace_cmd__conv_to_input(char *str) +edit_replace_cmd__conv_to_input (char *str) { #ifdef HAVE_CHARSET GString *tmp; tmp = str_convert_to_input (str); - if (tmp && tmp->len){ - return g_string_free (tmp, FALSE); + if (tmp && tmp->len) + { + return g_string_free (tmp, FALSE); } g_string_free (tmp, TRUE); - return g_strdup(str); + return g_strdup (str); #endif - return g_strdup(str); + return g_strdup (str); } + /* call with edit = 0 before shutdown to close memory leaks */ void -edit_replace_cmd (WEdit *edit, int again) +edit_replace_cmd (WEdit * edit, int again) { /* 1 = search string, 2 = replace with */ - static char *saved1 = NULL; /* saved default[123] */ + static char *saved1 = NULL; /* saved default[123] */ static char *saved2 = NULL; - char *input1 = NULL; /* user input from the dialog */ + char *input1 = NULL; /* user input from the dialog */ char *input2 = NULL; char *disp1 = NULL; char *disp2 = NULL; @@ -1523,10 +1667,11 @@ edit_replace_cmd (WEdit *edit, int again) long times_replaced = 0, last_search; gboolean once_found = FALSE; - if (!edit) { - g_free (saved1), saved1 = NULL; - g_free (saved2), saved2 = NULL; - return; + if (!edit) + { + g_free (saved1), saved1 = NULL; + g_free (saved2), saved2 = NULL; + return; } last_search = edit->last_byte; @@ -1534,173 +1679,195 @@ edit_replace_cmd (WEdit *edit, int again) edit->force |= REDRAW_COMPLETELY; if (again && !saved1 && !saved2) - again = 0; + again = 0; - if (again) { - input1 = g_strdup (saved1 ? saved1 : ""); - input2 = g_strdup (saved2 ? saved2 : ""); - } else { - char *tmp_inp1, *tmp_inp2; - disp1 = edit_replace_cmd__conv_to_display (saved1 ? saved1 : (char *) ""); - disp2 = edit_replace_cmd__conv_to_display (saved2 ? saved2 : (char *) ""); + if (again) + { + input1 = g_strdup (saved1 ? saved1 : ""); + input2 = g_strdup (saved2 ? saved2 : ""); + } + else + { + char *tmp_inp1, *tmp_inp2; + disp1 = edit_replace_cmd__conv_to_display (saved1 ? saved1 : (char *) ""); + disp2 = edit_replace_cmd__conv_to_display (saved2 ? saved2 : (char *) ""); - edit_push_action (edit, KEY_PRESS + edit->start_display); + edit_push_action (edit, KEY_PRESS + edit->start_display); - editcmd_dialog_replace_show (edit, disp1, disp2, &input1, &input2 ); + editcmd_dialog_replace_show (edit, disp1, disp2, &input1, &input2); - g_free (disp1); - g_free (disp2); + g_free (disp1); + g_free (disp2); - if (input1 == NULL || *input1 == '\0') { - edit->force = REDRAW_COMPLETELY; - goto cleanup; - } + if (input1 == NULL || *input1 == '\0') + { + edit->force = REDRAW_COMPLETELY; + goto cleanup; + } - tmp_inp1 = input1; tmp_inp2 = input2; - input1 = edit_replace_cmd__conv_to_input(input1); - input2 = edit_replace_cmd__conv_to_input(input2); - g_free(tmp_inp1); g_free(tmp_inp2); + tmp_inp1 = input1; + tmp_inp2 = input2; + input1 = edit_replace_cmd__conv_to_input (input1); + input2 = edit_replace_cmd__conv_to_input (input2); + g_free (tmp_inp1); + g_free (tmp_inp2); - g_free (saved1), saved1 = g_strdup (input1); - g_free (saved2), saved2 = g_strdup (input2); + g_free (saved1), saved1 = g_strdup (input1); + g_free (saved2), saved2 = g_strdup (input2); - if (edit->search) { - mc_search_free(edit->search); - edit->search = NULL; - } + if (edit->search) + { + mc_search_free (edit->search); + edit->search = NULL; + } } - if (!edit->search) { - edit->search = mc_search_new(input1, -1); - if (edit->search == NULL) { - edit->search_start = edit->curs1; - return; - } - edit->search->search_type = edit_search_options.type; - edit->search->is_all_charsets = edit_search_options.all_codepages; - edit->search->is_case_sentitive = edit_search_options.case_sens; - edit->search->whole_words = edit_search_options.whole_words; - edit->search->search_fn = edit_search_cmd_callback; + if (!edit->search) + { + edit->search = mc_search_new (input1, -1); + if (edit->search == NULL) + { + edit->search_start = edit->curs1; + return; + } + edit->search->search_type = edit_search_options.type; + edit->search->is_all_charsets = edit_search_options.all_codepages; + edit->search->is_case_sentitive = edit_search_options.case_sens; + edit->search->whole_words = edit_search_options.whole_words; + edit->search->search_fn = edit_search_cmd_callback; } if (edit->found_len && edit->search_start == edit->found_start + 1 - && edit_search_options.backwards) - edit->search_start--; + && edit_search_options.backwards) + edit->search_start--; if (edit->found_len && edit->search_start == edit->found_start - 1 - && !edit_search_options.backwards) - edit->search_start++; + && !edit_search_options.backwards) + edit->search_start++; - do { - gsize len = 0; - long new_start; - - if (! editcmd_find(edit, &len)) { - if (!(edit->search->error == MC_SEARCH_E_OK || - (once_found && edit->search->error == MC_SEARCH_E_NOTFOUND))) { - edit_error_dialog (_ ("Search"), edit->search->error_str); - } - break; - } - once_found = TRUE; - new_start = edit->search->normal_offset; + do + { + gsize len = 0; + long new_start; - edit->search_start = new_start = edit->search->normal_offset; - /*returns negative on not found or error in pattern */ + if (!editcmd_find (edit, &len)) + { + if (!(edit->search->error == MC_SEARCH_E_OK || + (once_found && edit->search->error == MC_SEARCH_E_NOTFOUND))) + { + edit_error_dialog (_("Search"), edit->search->error_str); + } + break; + } + once_found = TRUE; + new_start = edit->search->normal_offset; - if (edit->search_start >= 0) { - guint i; + edit->search_start = new_start = edit->search->normal_offset; + /*returns negative on not found or error in pattern */ - edit->found_start = edit->search_start; - i = edit->found_len = len; + if (edit->search_start >= 0) + { + guint i; - edit_cursor_move (edit, edit->search_start - edit->curs1); - edit_scroll_screen_over_cursor (edit); + edit->found_start = edit->search_start; + i = edit->found_len = len; - replace_yes = 1; + edit_cursor_move (edit, edit->search_start - edit->curs1); + edit_scroll_screen_over_cursor (edit); - if (edit->replace_mode == 0) { - int l; - l = edit->curs_row - edit->num_widget_lines / 3; - if (l > 0) - edit_scroll_downward (edit, l); - if (l < 0) - edit_scroll_upward (edit, -l); + replace_yes = 1; - edit_scroll_screen_over_cursor (edit); - edit->force |= REDRAW_PAGE; - edit_render_keypress (edit); + if (edit->replace_mode == 0) + { + int l; + l = edit->curs_row - edit->num_widget_lines / 3; + if (l > 0) + edit_scroll_downward (edit, l); + if (l < 0) + edit_scroll_upward (edit, -l); - /*so that undo stops at each query */ - edit_push_key_press (edit); - /* and prompt 2/3 down */ - disp1 = edit_replace_cmd__conv_to_display (saved1); - disp2 = edit_replace_cmd__conv_to_display (saved2); - switch (editcmd_dialog_replace_prompt_show (edit, disp1, disp2, -1, -1)) { - case B_ENTER: - replace_yes = 1; - break; - case B_SKIP_REPLACE: - replace_yes = 0; - break; - case B_REPLACE_ALL: - edit->replace_mode=1; - break; - case B_CANCEL: - replace_yes = 0; - edit->replace_mode = -1; - break; - } - g_free (disp1); - g_free (disp2); - } - if (replace_yes) { /* delete then insert new */ - GString *repl_str, *tmp_str; - tmp_str = g_string_new(input2); - - repl_str = mc_search_prepare_replace_str (edit->search, tmp_str); - g_string_free(tmp_str, TRUE); - if (edit->search->error != MC_SEARCH_E_OK) - { - edit_error_dialog (_ ("Replace"), edit->search->error_str); - break; - } + edit_scroll_screen_over_cursor (edit); + edit->force |= REDRAW_PAGE; + edit_render_keypress (edit); - while (i--) - edit_delete (edit, 1); + /*so that undo stops at each query */ + edit_push_key_press (edit); + /* and prompt 2/3 down */ + disp1 = edit_replace_cmd__conv_to_display (saved1); + disp2 = edit_replace_cmd__conv_to_display (saved2); + switch (editcmd_dialog_replace_prompt_show (edit, disp1, disp2, -1, -1)) + { + case B_ENTER: + replace_yes = 1; + break; + case B_SKIP_REPLACE: + replace_yes = 0; + break; + case B_REPLACE_ALL: + edit->replace_mode = 1; + break; + case B_CANCEL: + replace_yes = 0; + edit->replace_mode = -1; + break; + } + g_free (disp1); + g_free (disp2); + } + if (replace_yes) + { /* delete then insert new */ + GString *repl_str, *tmp_str; + tmp_str = g_string_new (input2); - while (++i < repl_str->len) - edit_insert (edit, repl_str->str[i]); - - g_string_free(repl_str, TRUE); - edit->found_len = i; - } - /* so that we don't find the same string again */ - if (edit_search_options.backwards) { - last_search = edit->search_start; - edit->search_start--; - } else { - edit->search_start += i; - last_search = edit->last_byte; - } - edit_scroll_screen_over_cursor (edit); - } else { - const char *msg = _(" Replace "); - /* try and find from right here for next search */ - edit->search_start = edit->curs1; - edit_update_curs_col (edit); + repl_str = mc_search_prepare_replace_str (edit->search, tmp_str); + g_string_free (tmp_str, TRUE); + if (edit->search->error != MC_SEARCH_E_OK) + { + edit_error_dialog (_("Replace"), edit->search->error_str); + break; + } - edit->force |= REDRAW_PAGE; - edit_render_keypress (edit); - if (times_replaced) { - message (D_NORMAL, msg, _(" %ld replacements made. "), - times_replaced); - } else - query_dialog (msg, _(" Search string not found "), - D_NORMAL, 1, _("&OK")); - edit->replace_mode = -1; - } - } while (edit->replace_mode >= 0); + while (i--) + edit_delete (edit, 1); + + while (++i < repl_str->len) + edit_insert (edit, repl_str->str[i]); + + g_string_free (repl_str, TRUE); + edit->found_len = i; + } + /* so that we don't find the same string again */ + if (edit_search_options.backwards) + { + last_search = edit->search_start; + edit->search_start--; + } + else + { + edit->search_start += i; + last_search = edit->last_byte; + } + edit_scroll_screen_over_cursor (edit); + } + else + { + const char *msg = _(" Replace "); + /* try and find from right here for next search */ + edit->search_start = edit->curs1; + edit_update_curs_col (edit); + + edit->force |= REDRAW_PAGE; + edit_render_keypress (edit); + if (times_replaced) + { + message (D_NORMAL, msg, _(" %ld replacements made. "), times_replaced); + } + else + query_dialog (msg, _(" Search string not found "), D_NORMAL, 1, _("&OK")); + edit->replace_mode = -1; + } + } + while (edit->replace_mode >= 0); edit->force = REDRAW_COMPLETELY; edit_scroll_screen_over_cursor (edit); @@ -1710,23 +1877,28 @@ edit_replace_cmd (WEdit *edit, int again) } -void edit_search_cmd (WEdit * edit, int again) +void +edit_search_cmd (WEdit * edit, int again) { char *search_string = NULL, *search_string_dup = NULL; gsize len = 0; if (!edit) - return; + return; - if (edit->search != NULL) { - search_string = g_strndup(edit->search->original, edit->search->original_len); - search_string_dup = search_string; - } else { + if (edit->search != NULL) + { + search_string = g_strndup (edit->search->original, edit->search->original_len); + search_string_dup = search_string; + } + else + { GList *history; history = history_get (MC_HISTORY_SHARED_SEARCH); - if (history != NULL && history->data != NULL) { - search_string_dup = search_string = (char *) g_strdup(history->data); + if (history != NULL && history->data != NULL) + { + search_string_dup = search_string = (char *) g_strdup (history->data); history = g_list_first (history); g_list_foreach (history, (GFunc) g_free, NULL); g_list_free (history); @@ -1734,87 +1906,100 @@ void edit_search_cmd (WEdit * edit, int again) edit->search_start = edit->curs1; } - if (!again) { + if (!again) + { #ifdef HAVE_CHARSET - GString *tmp; - if (search_string && *search_string) { - tmp = str_convert_to_display (search_string); + GString *tmp; + if (search_string && *search_string) + { + tmp = str_convert_to_display (search_string); - g_free(search_string_dup); - search_string_dup = NULL; + g_free (search_string_dup); + search_string_dup = NULL; - if (tmp && tmp->len) - search_string = search_string_dup = tmp->str; - g_string_free (tmp, FALSE); - } + if (tmp && tmp->len) + search_string = search_string_dup = tmp->str; + g_string_free (tmp, FALSE); + } #endif /* HAVE_CHARSET */ - editcmd_dialog_search_show (edit, &search_string); + editcmd_dialog_search_show (edit, &search_string); #ifdef HAVE_CHARSET - if (search_string && *search_string) { - tmp = str_convert_to_input (search_string); - if (tmp && tmp->len) - search_string = tmp->str; + if (search_string && *search_string) + { + tmp = str_convert_to_input (search_string); + if (tmp && tmp->len) + search_string = tmp->str; - g_string_free (tmp, FALSE); + g_string_free (tmp, FALSE); - if (search_string_dup) - g_free(search_string_dup); - } + if (search_string_dup) + g_free (search_string_dup); + } #endif /* HAVE_CHARSET */ - edit_push_action (edit, KEY_PRESS + edit->start_display); + edit_push_action (edit, KEY_PRESS + edit->start_display); - if (!search_string) { - edit->force |= REDRAW_COMPLETELY; - edit_scroll_screen_over_cursor (edit); - return; - } + if (!search_string) + { + edit->force |= REDRAW_COMPLETELY; + edit_scroll_screen_over_cursor (edit); + return; + } - if (edit->search) { - mc_search_free(edit->search); - edit->search = NULL; - } + if (edit->search) + { + mc_search_free (edit->search); + edit->search = NULL; + } } - if (!edit->search) { - edit->search = mc_search_new(search_string, -1); - if (edit->search == NULL) { - edit->search_start = edit->curs1; - return; - } - edit->search->search_type = edit_search_options.type; - edit->search->is_all_charsets = edit_search_options.all_codepages; - edit->search->is_case_sentitive = edit_search_options.case_sens; - edit->search->whole_words = edit_search_options.whole_words; - edit->search->search_fn = edit_search_cmd_callback; + if (!edit->search) + { + edit->search = mc_search_new (search_string, -1); + if (edit->search == NULL) + { + edit->search_start = edit->curs1; + return; + } + edit->search->search_type = edit_search_options.type; + edit->search->is_all_charsets = edit_search_options.all_codepages; + edit->search->is_case_sentitive = edit_search_options.case_sens; + edit->search->whole_words = edit_search_options.whole_words; + edit->search->search_fn = edit_search_cmd_callback; } - if (search_create_bookmark) { - edit_search_cmd_search_create_bookmark(edit); - } else { - if (edit->found_len && edit->search_start == edit->found_start + 1 - && edit_search_options.backwards) - edit->search_start--; + if (search_create_bookmark) + { + edit_search_cmd_search_create_bookmark (edit); + } + else + { + if (edit->found_len && edit->search_start == edit->found_start + 1 + && edit_search_options.backwards) + edit->search_start--; - if (edit->found_len && edit->search_start == edit->found_start - 1 - && !edit_search_options.backwards) - edit->search_start++; + if (edit->found_len && edit->search_start == edit->found_start - 1 + && !edit_search_options.backwards) + edit->search_start++; - if (editcmd_find(edit, &len)) { - edit->found_start = edit->search_start = edit->search->normal_offset; - edit->found_len = len; - edit->over_col = 0; - edit_cursor_move (edit, edit->search_start - edit->curs1); - edit_scroll_screen_over_cursor (edit); - if (edit_search_options.backwards) - edit->search_start--; - else - edit->search_start++; - } else { - edit->search_start = edit->curs1; - if (edit->search->error_str) - edit_error_dialog (_ ("Search"), edit->search->error_str); - } + if (editcmd_find (edit, &len)) + { + edit->found_start = edit->search_start = edit->search->normal_offset; + edit->found_len = len; + edit->over_col = 0; + edit_cursor_move (edit, edit->search_start - edit->curs1); + edit_scroll_screen_over_cursor (edit); + if (edit_search_options.backwards) + edit->search_start--; + else + edit->search_start++; + } + else + { + edit->search_start = edit->curs1; + if (edit->search->error_str) + edit_error_dialog (_("Search"), edit->search->error_str); + } } edit->force |= REDRAW_COMPLETELY; @@ -1827,28 +2012,29 @@ void edit_search_cmd (WEdit * edit, int again) * ask user. Return 1 if it's OK to exit, 0 to continue editing. */ int -edit_ok_to_exit (WEdit *edit) +edit_ok_to_exit (WEdit * edit) { if (!edit->modified) - return 1; + return 1; if (!edit_check_newline (edit)) return 0; switch (edit_query_dialog3 - (_("Quit"), _(" File was modified, Save with exit? "), - _("&Cancel quit"), _("&Yes"), _("&No"))) { + (_("Quit"), _(" File was modified, Save with exit? "), + _("&Cancel quit"), _("&Yes"), _("&No"))) + { case 1: - edit_push_markers (edit); - edit_set_markers (edit, 0, 0, 0, 0); - if (!edit_save_cmd (edit)) - return 0; - break; + edit_push_markers (edit); + edit_set_markers (edit, 0, 0, 0, 0); + if (!edit_save_cmd (edit)) + return 0; + break; case 2: - break; + break; case 0: case -1: - return 0; + return 0; } return 1; @@ -1856,30 +2042,34 @@ edit_ok_to_exit (WEdit *edit) /* Return a null terminated length of text. Result must be g_free'd */ static unsigned char * -edit_get_block (WEdit *edit, long start, long finish, int *l) +edit_get_block (WEdit * edit, long start, long finish, int *l) { unsigned char *s, *r; r = s = g_malloc0 (finish - start + 1); - if (column_highlighting) { - *l = 0; - /* copy from buffer, excluding chars that are out of the column 'margins' */ - while (start < finish) { - int c; - long x; - x = edit_move_forward3 (edit, edit_bol (edit, start), 0, - start); - c = edit_get_byte (edit, start); - if ((x >= edit->column1 && x < edit->column2) - || (x >= edit->column2 && x < edit->column1) || c == '\n') { - *s++ = c; - (*l)++; - } - start++; - } - } else { - *l = finish - start; - while (start < finish) - *s++ = edit_get_byte (edit, start++); + if (column_highlighting) + { + *l = 0; + /* copy from buffer, excluding chars that are out of the column 'margins' */ + while (start < finish) + { + int c; + long x; + x = edit_move_forward3 (edit, edit_bol (edit, start), 0, start); + c = edit_get_byte (edit, start); + if ((x >= edit->column1 && x < edit->column2) + || (x >= edit->column2 && x < edit->column1) || c == '\n') + { + *s++ = c; + (*l)++; + } + start++; + } + } + else + { + *l = finish - start; + while (start < finish) + *s++ = edit_get_byte (edit, start++); } *s = 0; return r; @@ -1887,102 +2077,115 @@ edit_get_block (WEdit *edit, long start, long finish, int *l) /* save block, returns 1 on success */ int -edit_save_block (WEdit * edit, const char *filename, long start, - long finish) +edit_save_block (WEdit * edit, const char *filename, long start, long finish) { int len, file; if ((file = - mc_open (filename, O_CREAT | O_WRONLY | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY)) == -1) - return 0; + mc_open (filename, O_CREAT | O_WRONLY | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY)) == -1) + return 0; - if (column_highlighting) { - int r; - r = mc_write (file, VERTICAL_MAGIC, sizeof(VERTICAL_MAGIC)); - if (r > 0) { - unsigned char *block, *p; - p = block = edit_get_block (edit, start, finish, &len); - while (len) { - r = mc_write (file, p, len); - if (r < 0) - break; - p += r; - len -= r; - } - g_free (block); - } - } else { - unsigned char *buf; - int i = start, end; - len = finish - start; - buf = g_malloc0 (TEMP_BUF_LEN); - while (start != finish) { - end = min (finish, start + TEMP_BUF_LEN); - for (; i < end; i++) - buf[i - start] = edit_get_byte (edit, i); - len -= mc_write (file, (char *) buf, end - start); - start = end; - } - g_free (buf); + if (column_highlighting) + { + int r; + r = mc_write (file, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)); + if (r > 0) + { + unsigned char *block, *p; + p = block = edit_get_block (edit, start, finish, &len); + while (len) + { + r = mc_write (file, p, len); + if (r < 0) + break; + p += r; + len -= r; + } + g_free (block); + } + } + else + { + unsigned char *buf; + int i = start, end; + len = finish - start; + buf = g_malloc0 (TEMP_BUF_LEN); + while (start != finish) + { + end = min (finish, start + TEMP_BUF_LEN); + for (; i < end; i++) + buf[i - start] = edit_get_byte (edit, i); + len -= mc_write (file, (char *) buf, end - start); + start = end; + } + g_free (buf); } mc_close (file); if (len) - return 0; + return 0; return 1; } /* copies a block to clipboard file */ -static int edit_save_block_to_clip_file (WEdit * edit, long start, long finish) +static int +edit_save_block_to_clip_file (WEdit * edit, long start, long finish) { int ret; gchar *tmp; tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE); ret = edit_save_block (edit, tmp, start, finish); - g_free(tmp); + g_free (tmp); return ret; } -void edit_paste_from_history (WEdit *edit) +void +edit_paste_from_history (WEdit * edit) { (void) edit; edit_error_dialog (_(" Error "), _(" This function is not implemented. ")); } -int edit_copy_to_X_buf_cmd (WEdit * edit) +int +edit_copy_to_X_buf_cmd (WEdit * edit) { long start_mark, end_mark; if (eval_marks (edit, &start_mark, &end_mark)) - return 0; - if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { - edit_error_dialog (_(" Copy to clipboard "), get_sys_error (_(" Unable to save to file. "))); - return 1; + return 0; + if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) + { + edit_error_dialog (_(" Copy to clipboard "), + get_sys_error (_(" Unable to save to file. "))); + return 1; } edit_mark_cmd (edit, 1); return 0; } -int edit_cut_to_X_buf_cmd (WEdit * edit) +int +edit_cut_to_X_buf_cmd (WEdit * edit) { long start_mark, end_mark; if (eval_marks (edit, &start_mark, &end_mark)) - return 0; - if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { - edit_error_dialog (_(" Cut to clipboard "), _(" Unable to save to file. ")); - return 1; + return 0; + if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) + { + edit_error_dialog (_(" Cut to clipboard "), _(" Unable to save to file. ")); + return 1; } edit_block_delete_cmd (edit); edit_mark_cmd (edit, 1); return 0; } -void edit_paste_from_X_buf_cmd (WEdit * edit) +void +edit_paste_from_X_buf_cmd (WEdit * edit) { gchar *tmp; tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE); edit_insert_file (edit, tmp); - g_free(tmp); + g_free (tmp); } @@ -1991,34 +2194,36 @@ void edit_paste_from_X_buf_cmd (WEdit * edit) * Negative numbers mean line from the end (i.e. -1 is the last line). */ void -edit_goto_cmd (WEdit *edit) +edit_goto_cmd (WEdit * edit) { char *f; - static long line = 0; /* line as typed, saved as default */ + static long line = 0; /* line as typed, saved as default */ long l; char *error; char s[32]; g_snprintf (s, sizeof (s), "%ld", line); f = input_dialog (_(" Goto line "), _(" Enter line: "), MC_HISTORY_EDIT_GOTO_LINE, - line ? s : ""); + line ? s : ""); if (!f) - return; + return; - if (!*f) { - g_free (f); - return; + if (!*f) + { + g_free (f); + return; } l = strtol (f, &error, 0); - if (*error) { - g_free (f); - return; + if (*error) + { + g_free (f); + return; } line = l; if (l < 0) - l = edit->total_lines + l + 2; + l = edit->total_lines + l + 2; edit_move_display (edit, l - edit->num_widget_lines / 2 - 1); edit_move_to_line (edit, l - 1); edit->force |= REDRAW_COMPLETELY; @@ -2028,37 +2233,41 @@ edit_goto_cmd (WEdit *edit) /* Return 1 on success */ int -edit_save_block_cmd (WEdit *edit) +edit_save_block_cmd (WEdit * edit) { long start_mark, end_mark; char *exp, *tmp; if (eval_marks (edit, &start_mark, &end_mark)) - return 1; + return 1; tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE); exp = - input_expand_dialog (_(" Save Block "), _(" Enter file name: "), - MC_HISTORY_EDIT_SAVE_BLOCK, - tmp); - g_free(tmp); + input_expand_dialog (_(" Save Block "), _(" Enter file name: "), + MC_HISTORY_EDIT_SAVE_BLOCK, tmp); + g_free (tmp); edit_push_action (edit, KEY_PRESS + edit->start_display); - if (exp) { - if (!*exp) { - g_free (exp); - return 0; - } else { - if (edit_save_block (edit, exp, start_mark, end_mark)) { - g_free (exp); - edit->force |= REDRAW_COMPLETELY; - return 1; - } else { - g_free (exp); - edit_error_dialog (_(" Save Block "), - get_sys_error (_ - (" Cannot save file. "))); - } - } + if (exp) + { + if (!*exp) + { + g_free (exp); + return 0; + } + else + { + if (edit_save_block (edit, exp, start_mark, end_mark)) + { + g_free (exp); + edit->force |= REDRAW_COMPLETELY; + return 1; + } + else + { + g_free (exp); + edit_error_dialog (_(" Save Block "), get_sys_error (_(" Cannot save file. "))); + } + } } edit->force |= REDRAW_COMPLETELY; return 0; @@ -2067,88 +2276,97 @@ edit_save_block_cmd (WEdit *edit) /* returns 1 on success */ int -edit_insert_file_cmd (WEdit *edit) +edit_insert_file_cmd (WEdit * edit) { gchar *tmp; char *exp; tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE); exp = input_expand_dialog (_(" Insert File "), _(" Enter file name: "), - MC_HISTORY_EDIT_INSERT_FILE, - tmp); - g_free(tmp); + MC_HISTORY_EDIT_INSERT_FILE, tmp); + g_free (tmp); edit_push_action (edit, KEY_PRESS + edit->start_display); - if (exp) { - if (!*exp) { - g_free (exp); - return 0; - } else { - if (edit_insert_file (edit, exp)) { - g_free (exp); - edit->force |= REDRAW_COMPLETELY; - return 1; - } else { - g_free (exp); - edit_error_dialog (_(" Insert File "), - get_sys_error (_ - (" Cannot insert file. "))); - } - } + if (exp) + { + if (!*exp) + { + g_free (exp); + return 0; + } + else + { + if (edit_insert_file (edit, exp)) + { + g_free (exp); + edit->force |= REDRAW_COMPLETELY; + return 1; + } + else + { + g_free (exp); + edit_error_dialog (_(" Insert File "), get_sys_error (_(" Cannot insert file. "))); + } + } } edit->force |= REDRAW_COMPLETELY; return 0; } /* sorts a block, returns -1 on system fail, 1 on cancel and 0 on success */ -int edit_sort_cmd (WEdit * edit) +int +edit_sort_cmd (WEdit * edit) { static char *old = 0; char *exp, *tmp; long start_mark, end_mark; int e; - if (eval_marks (edit, &start_mark, &end_mark)) { - edit_error_dialog (_(" Sort block "), _(" You must first highlight a block of text. ")); - return 0; + if (eval_marks (edit, &start_mark, &end_mark)) + { + edit_error_dialog (_(" Sort block "), _(" You must first highlight a block of text. ")); + return 0; } tmp = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE); edit_save_block (edit, tmp, start_mark, end_mark); - g_free(tmp); + g_free (tmp); exp = input_dialog (_(" Run Sort "), - _(" Enter sort options (see manpage) separated by whitespace: "), - MC_HISTORY_EDIT_SORT, (old != NULL) ? old : ""); + _(" Enter sort options (see manpage) separated by whitespace: "), + MC_HISTORY_EDIT_SORT, (old != NULL) ? old : ""); if (!exp) - return 1; + return 1; g_free (old); old = exp; tmp = g_strconcat (" sort ", exp, " ", home_dir, PATH_SEP_STR EDIT_BLOCK_FILE, " > ", - home_dir, PATH_SEP_STR EDIT_TEMP_FILE, (char *) NULL); + home_dir, PATH_SEP_STR EDIT_TEMP_FILE, (char *) NULL); e = system (tmp); - g_free(tmp); - if (e) { - if (e == -1 || e == 127) { - edit_error_dialog (_(" Sort "), - get_sys_error (_(" Cannot execute sort command "))); - } else { - char q[8]; - sprintf (q, "%d ", e); - tmp = g_strconcat (_(" Sort returned non-zero: "), q, (char *) NULL); - edit_error_dialog (_(" Sort "), tmp); - g_free(tmp); - } - return -1; + g_free (tmp); + if (e) + { + if (e == -1 || e == 127) + { + edit_error_dialog (_(" Sort "), get_sys_error (_(" Cannot execute sort command "))); + } + else + { + char q[8]; + sprintf (q, "%d ", e); + tmp = g_strconcat (_(" Sort returned non-zero: "), q, (char *) NULL); + edit_error_dialog (_(" Sort "), tmp); + g_free (tmp); + } + return -1; } edit->force |= REDRAW_COMPLETELY; if (edit_block_delete_cmd (edit)) - return 1; + return 1; tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE); edit_insert_file (edit, tmp); - g_free(tmp); + g_free (tmp); return 0; } @@ -2157,34 +2375,33 @@ int edit_sort_cmd (WEdit * edit) * editor. */ int -edit_ext_cmd (WEdit *edit) +edit_ext_cmd (WEdit * edit) { char *exp, *tmp; int e; exp = - input_dialog (_("Paste output of external command"), - _("Enter shell command(s):"), - MC_HISTORY_EDIT_PASTE_EXTCMD, NULL); + input_dialog (_("Paste output of external command"), + _("Enter shell command(s):"), MC_HISTORY_EDIT_PASTE_EXTCMD, NULL); if (!exp) - return 1; + return 1; tmp = g_strconcat (exp, " > ", home_dir, PATH_SEP_STR EDIT_TEMP_FILE, (char *) NULL); e = system (tmp); - g_free(tmp); + g_free (tmp); g_free (exp); - if (e) { - edit_error_dialog (_("External command"), - get_sys_error (_("Cannot execute command"))); - return -1; + if (e) + { + edit_error_dialog (_("External command"), get_sys_error (_("Cannot execute command"))); + return -1; } edit->force |= REDRAW_COMPLETELY; tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE); edit_insert_file (edit, tmp); - g_free(tmp); + g_free (tmp); return 0; } @@ -2192,7 +2409,7 @@ edit_ext_cmd (WEdit *edit) processes it. If block is 0 the shell command is a straight system command, that just produces some output which is to be inserted */ void -edit_block_process_cmd (WEdit *edit, const char *shell_cmd, int block) +edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block) { long start_mark, end_mark; char buf[BUFSIZ]; @@ -2201,85 +2418,93 @@ edit_block_process_cmd (WEdit *edit, const char *shell_cmd, int block) gchar *o, *h, *b, *tmp; char *quoted_name = NULL; - o = g_strconcat (mc_home, shell_cmd, (char *) NULL); /* original source script */ - h = g_strconcat (home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, (char *) NULL); /* home script */ - b = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE); /* block file */ + o = g_strconcat (mc_home, shell_cmd, (char *) NULL); /* original source script */ + h = g_strconcat (home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, (char *) NULL); /* home script */ + b = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE); /* block file */ script_home = fopen (h, "r"); - if (script_home == NULL) { - FILE *script_src = NULL; + if (script_home == NULL) + { + FILE *script_src = NULL; - script_home = fopen (h, "w"); - if (script_home == NULL) { - tmp = g_strconcat (_("Error creating script:"), h, (char *) NULL); - edit_error_dialog ("", get_sys_error (tmp)); - g_free(tmp); - goto edit_block_process_cmd__EXIT; - } + script_home = fopen (h, "w"); + if (script_home == NULL) + { + tmp = g_strconcat (_("Error creating script:"), h, (char *) NULL); + edit_error_dialog ("", get_sys_error (tmp)); + g_free (tmp); + goto edit_block_process_cmd__EXIT; + } - script_src = fopen (o, "r"); - if (script_src == NULL) { - o = g_strconcat (mc_home_alt, shell_cmd, (char *) NULL); - script_src = fopen (o, "r"); - if (script_src == NULL) { - fclose (script_home); - unlink (h); - tmp = g_strconcat (_("Error reading script:"), o, (char *) NULL); - edit_error_dialog ("", get_sys_error (tmp)); - g_free(tmp); - goto edit_block_process_cmd__EXIT; - } - } - while (fgets (buf, sizeof (buf), script_src)) - fputs (buf, script_home); - fclose (script_src); + script_src = fopen (o, "r"); + if (script_src == NULL) + { + o = g_strconcat (mc_home_alt, shell_cmd, (char *) NULL); + script_src = fopen (o, "r"); + if (script_src == NULL) + { + fclose (script_home); + unlink (h); + tmp = g_strconcat (_("Error reading script:"), o, (char *) NULL); + edit_error_dialog ("", get_sys_error (tmp)); + g_free (tmp); + goto edit_block_process_cmd__EXIT; + } + } + while (fgets (buf, sizeof (buf), script_src)) + fputs (buf, script_home); + fclose (script_src); - if (fclose (script_home)) { - tmp = g_strconcat (_("Error closing script:"), h, (char *) NULL); - edit_error_dialog ("", get_sys_error (tmp)); - g_free(tmp); - goto edit_block_process_cmd__EXIT; - } - chmod (h, 0700); - tmp = g_strconcat (_("Script created:"), h, (char *) NULL); - edit_error_dialog ("", get_sys_error (tmp)); - g_free(tmp); + if (fclose (script_home)) + { + tmp = g_strconcat (_("Error closing script:"), h, (char *) NULL); + edit_error_dialog ("", get_sys_error (tmp)); + g_free (tmp); + goto edit_block_process_cmd__EXIT; + } + chmod (h, 0700); + tmp = g_strconcat (_("Script created:"), h, (char *) NULL); + edit_error_dialog ("", get_sys_error (tmp)); + g_free (tmp); } open_error_pipe (); - if (block) { /* for marked block run indent formatter */ - if (eval_marks (edit, &start_mark, &end_mark)) { - edit_error_dialog (_("Process block"), - _ - (" You must first highlight a block of text. ")); - goto edit_block_process_cmd__EXIT; - } - edit_save_block (edit, b, start_mark, end_mark); - quoted_name = name_quote (edit->filename, 0); - /* - * Run script. - * Initial space is to avoid polluting bash history. - * Arguments: - * $1 - name of the edited file (to check its extension etc). - * $2 - file containing the current block. - * $3 - file where error messages should be put - * (for compatibility with old scripts). - */ - tmp = g_strconcat (" ", home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, " ", quoted_name, - " ", home_dir, PATH_SEP_STR EDIT_BLOCK_FILE " /dev/null", (char *) NULL); - system (tmp); - g_free(tmp); - } else { - /* - * No block selected, just execute the command for the file. - * Arguments: - * $1 - name of the edited file. - */ - tmp = g_strconcat (" ", home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, " ", - quoted_name, (char *) NULL); - system (tmp); - g_free(tmp); + if (block) + { /* for marked block run indent formatter */ + if (eval_marks (edit, &start_mark, &end_mark)) + { + edit_error_dialog (_("Process block"), + _(" You must first highlight a block of text. ")); + goto edit_block_process_cmd__EXIT; + } + edit_save_block (edit, b, start_mark, end_mark); + quoted_name = name_quote (edit->filename, 0); + /* + * Run script. + * Initial space is to avoid polluting bash history. + * Arguments: + * $1 - name of the edited file (to check its extension etc). + * $2 - file containing the current block. + * $3 - file where error messages should be put + * (for compatibility with old scripts). + */ + tmp = g_strconcat (" ", home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, " ", quoted_name, + " ", home_dir, PATH_SEP_STR EDIT_BLOCK_FILE " /dev/null", (char *) NULL); + system (tmp); + g_free (tmp); + } + else + { + /* + * No block selected, just execute the command for the file. + * Arguments: + * $1 - name of the edited file. + */ + tmp = g_strconcat (" ", home_dir, PATH_SEP_STR EDIT_DIR, shell_cmd, " ", + quoted_name, (char *) NULL); + system (tmp); + g_free (tmp); } g_free (quoted_name); close_error_pipe (D_NORMAL, NULL); @@ -2288,14 +2513,15 @@ edit_block_process_cmd (WEdit *edit, const char *shell_cmd, int block) edit->force |= REDRAW_COMPLETELY; /* insert result block */ - if (block && !edit_block_delete_cmd (edit)) { - edit_insert_file (edit, b); - block_file = fopen (b, "w"); - if (block_file != NULL) - fclose (block_file); + if (block && !edit_block_delete_cmd (edit)) + { + edit_insert_file (edit, b); + block_file = fopen (b, "w"); + if (block_file != NULL) + fclose (block_file); } -edit_block_process_cmd__EXIT: + edit_block_process_cmd__EXIT: g_free (b); g_free (h); g_free (o); @@ -2303,18 +2529,20 @@ edit_block_process_cmd__EXIT: /* prints at the cursor */ /* returns the number of chars printed */ -int edit_print_string (WEdit * e, const char *s) +int +edit_print_string (WEdit * e, const char *s) { size_t i = 0; while (s[i] != '\0') - edit_execute_cmd (e, CK_Insert_Char, (unsigned char) s[i++]); + edit_execute_cmd (e, CK_Insert_Char, (unsigned char) s[i++]); e->force |= REDRAW_COMPLETELY; edit_update_screen (e); return i; } -static void pipe_mail (WEdit *edit, char *to, char *subject, char *cc) +static void +pipe_mail (WEdit * edit, char *to, char *subject, char *cc) { FILE *p = 0; char *s; @@ -2322,27 +2550,30 @@ static void pipe_mail (WEdit *edit, char *to, char *subject, char *cc) to = name_quote (to, 0); subject = name_quote (subject, 0); cc = name_quote (cc, 0); - s = g_strconcat ("mail -s ", subject, *cc ? " -c " : "" , cc, " ", to, (char *) NULL); + s = g_strconcat ("mail -s ", subject, *cc ? " -c " : "", cc, " ", to, (char *) NULL); g_free (to); g_free (subject); g_free (cc); - if (s) { - p = popen (s, "w"); - g_free (s); + if (s) + { + p = popen (s, "w"); + g_free (s); } - if (p) { - long i; - for (i = 0; i < edit->last_byte; i++) - fputc (edit_get_byte (edit, i), p); - pclose (p); + if (p) + { + long i; + for (i = 0; i < edit->last_byte; i++) + fputc (edit_get_byte (edit, i), p); + pclose (p); } } #define MAIL_DLG_HEIGHT 12 -void edit_mail_dialog (WEdit * edit) +void +edit_mail_dialog (WEdit * edit) { char *tmail_to; char *tmail_subject; @@ -2352,38 +2583,38 @@ void edit_mail_dialog (WEdit * edit) static char *mail_subject_last = 0; static char *mail_to_last = 0; - QuickWidget quick_widgets[] = - { - /* 0 */ QUICK_BUTTON (6, 10, 9, MAIL_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ QUICK_BUTTON (2, 10, 9, MAIL_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), - /* 2 */ QUICK_INPUT (3, 50, 8, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input", &tmail_cc), - /* 3 */ QUICK_LABEL (2, 50, 7, MAIL_DLG_HEIGHT, N_(" Copies to")), - /* 4 */ QUICK_INPUT (3, 50, 6, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input-2", &tmail_subject), - /* 5 */ QUICK_LABEL (2, 50, 5, MAIL_DLG_HEIGHT, N_(" Subject")), - /* 6 */ QUICK_INPUT (3, 50, 4, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input-3", &tmail_to), - /* 7 */ QUICK_LABEL (2, 50, 3, MAIL_DLG_HEIGHT, N_(" To")), - /* 8 */ QUICK_LABEL (2, 50, 2, MAIL_DLG_HEIGHT, N_(" mail -s -c ")), - QUICK_END + QuickWidget quick_widgets[] = { + /* 0 */ QUICK_BUTTON (6, 10, 9, MAIL_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ QUICK_BUTTON (2, 10, 9, MAIL_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), + /* 2 */ QUICK_INPUT (3, 50, 8, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input", &tmail_cc), + /* 3 */ QUICK_LABEL (2, 50, 7, MAIL_DLG_HEIGHT, N_(" Copies to")), + /* 4 */ QUICK_INPUT (3, 50, 6, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input-2", + &tmail_subject), + /* 5 */ QUICK_LABEL (2, 50, 5, MAIL_DLG_HEIGHT, N_(" Subject")), + /* 6 */ QUICK_INPUT (3, 50, 4, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input-3", &tmail_to), + /* 7 */ QUICK_LABEL (2, 50, 3, MAIL_DLG_HEIGHT, N_(" To")), + /* 8 */ QUICK_LABEL (2, 50, 2, MAIL_DLG_HEIGHT, N_(" mail -s -c ")), + QUICK_END }; - QuickDialog Quick_input = - { - 50, MAIL_DLG_HEIGHT, -1, -1, N_(" Mail "), - "[Input Line Keys]", quick_widgets, FALSE + QuickDialog Quick_input = { + 50, MAIL_DLG_HEIGHT, -1, -1, N_(" Mail "), + "[Input Line Keys]", quick_widgets, FALSE }; quick_widgets[2].u.input.text = mail_cc_last ? mail_cc_last : ""; quick_widgets[4].u.input.text = mail_subject_last ? mail_subject_last : ""; quick_widgets[6].u.input.text = mail_to_last ? mail_to_last : ""; - if (quick_dialog (&Quick_input) != B_CANCEL) { - g_free (mail_cc_last); - g_free (mail_subject_last); - g_free (mail_to_last); - mail_cc_last = tmail_cc; - mail_subject_last = tmail_subject; - mail_to_last = tmail_to; - pipe_mail (edit, mail_to_last, mail_subject_last, mail_cc_last); + if (quick_dialog (&Quick_input) != B_CANCEL) + { + g_free (mail_cc_last); + g_free (mail_subject_last); + g_free (mail_to_last); + mail_cc_last = tmail_cc; + mail_subject_last = tmail_subject; + mail_to_last = tmail_to; + pipe_mail (edit, mail_to_last, mail_subject_last, mail_cc_last); } } @@ -2392,56 +2623,59 @@ void edit_mail_dialog (WEdit * edit) /* Word Completion */ /*******************/ -static gboolean is_break_char(char c) +static gboolean +is_break_char (char c) { - return (isspace(c) || strchr("{}[]()<>=|/\\!?~'\",.;:#$%^&*", c)); + return (isspace (c) || strchr ("{}[]()<>=|/\\!?~'\",.;:#$%^&*", c)); } /* find first character of current word */ -static int edit_find_word_start (WEdit *edit, long *word_start, gsize *word_len) +static int +edit_find_word_start (WEdit * edit, long *word_start, gsize * word_len) { int c, last; gsize i; -/* return if at begin of file */ + /* return if at begin of file */ if (edit->curs1 <= 0) - return 0; + return 0; c = (unsigned char) edit_get_byte (edit, edit->curs1 - 1); -/* return if not at end or in word */ - if (is_break_char(c)) - return 0; + /* return if not at end or in word */ + if (is_break_char (c)) + return 0; -/* search start of word to be completed */ - for (i = 2;; i++) { -/* return if at begin of file */ - if ((gsize)edit->curs1 < i) - return 0; + /* search start of word to be completed */ + for (i = 2;; i++) + { + /* return if at begin of file */ + if ((gsize) edit->curs1 < i) + return 0; - last = c; - c = (unsigned char) edit_get_byte (edit, edit->curs1 - i); + last = c; + c = (unsigned char) edit_get_byte (edit, edit->curs1 - i); - if (is_break_char(c)) { -/* return if word starts with digit */ - if (isdigit (last)) - return 0; + if (is_break_char (c)) + { + /* return if word starts with digit */ + if (isdigit (last)) + return 0; - *word_start = edit->curs1 - (i - 1); /* start found */ - *word_len = i - 1; - break; - } + *word_start = edit->curs1 - (i - 1); /* start found */ + *word_len = i - 1; + break; + } } -/* success */ + /* success */ return 1; } -#define MAX_WORD_COMPLETIONS 100 /* in listbox */ +#define MAX_WORD_COMPLETIONS 100 /* in listbox */ /* collect the possible completions */ static gsize -edit_collect_completions (WEdit *edit, long start, gsize word_len, - char *match_expr, struct selection *compl, - gsize *num) +edit_collect_completions (WEdit * edit, long start, gsize word_len, + char *match_expr, struct selection *compl, gsize * num) { gsize len = 0; gsize max_len = 0; @@ -2452,13 +2686,17 @@ edit_collect_completions (WEdit *edit, long start, gsize word_len, long last_byte; - srch = mc_search_new(match_expr, -1); + srch = mc_search_new (match_expr, -1); if (srch == NULL) return 0; - if (mc_config_get_bool(mc_main_config, CONFIG_APP_SECTION, "editor_wordcompletion_collect_entire_file", 0)){ + if (mc_config_get_bool + (mc_main_config, CONFIG_APP_SECTION, "editor_wordcompletion_collect_entire_file", 0)) + { last_byte = edit->last_byte; - } else { + } + else + { last_byte = start; } @@ -2468,73 +2706,80 @@ edit_collect_completions (WEdit *edit, long start, gsize word_len, /* collect max MAX_WORD_COMPLETIONS completions */ start = -1; - while (1) { - /* get next match */ - if (mc_search_run (srch, (void *) edit, start+1, last_byte, &len) == FALSE) - break; - start = srch->normal_offset; + while (1) + { + /* get next match */ + if (mc_search_run (srch, (void *) edit, start + 1, last_byte, &len) == FALSE) + break; + start = srch->normal_offset; - /* add matched completion if not yet added */ - temp = g_string_new(""); - for (i = 0; i < len; i++){ - skip = edit_get_byte(edit, start+i); - if (isspace(skip)) - continue; - g_string_append_c (temp, skip); - } + /* add matched completion if not yet added */ + temp = g_string_new (""); + for (i = 0; i < len; i++) + { + skip = edit_get_byte (edit, start + i); + if (isspace (skip)) + continue; + g_string_append_c (temp, skip); + } - skip = 0; + skip = 0; - for (i = 0; i < (gsize) *num; i++) { - if (strncmp - ( - (char *) &compl[i].text[word_len], - (char *) &temp->str[word_len], - max (len, compl[i].len) - (gsize)word_len - ) == 0) { - struct selection this = compl[i]; - for (++i; i < *num; i++) { - compl[i - 1] = compl[i]; - } - compl[*num - 1] = this; - skip = 1; - break; /* skip it, already added */ - } - } - if (skip) { - g_string_free(temp, TRUE); - continue; - } - if (*num == MAX_WORD_COMPLETIONS && MAX_WORD_COMPLETIONS) { - g_free(compl[0].text); - for (i = 1; i < *num; i++) { - compl[i - 1] = compl[i]; - } - (*num)--; - } + for (i = 0; i < (gsize) * num; i++) + { + if (strncmp + ((char *) &compl[i].text[word_len], + (char *) &temp->str[word_len], max (len, compl[i].len) - (gsize) word_len) == 0) + { + struct selection this = compl[i]; + for (++i; i < *num; i++) + { + compl[i - 1] = compl[i]; + } + compl[*num - 1] = this; + skip = 1; + break; /* skip it, already added */ + } + } + if (skip) + { + g_string_free (temp, TRUE); + continue; + } + if (*num == MAX_WORD_COMPLETIONS && MAX_WORD_COMPLETIONS) + { + g_free (compl[0].text); + for (i = 1; i < *num; i++) + { + compl[i - 1] = compl[i]; + } + (*num)--; + } #ifdef HAVE_CHARSET - { - GString *recoded; - recoded = str_convert_to_display (temp->str); + { + GString *recoded; + recoded = str_convert_to_display (temp->str); - if (recoded && recoded->len){ - g_string_free(temp,TRUE); - temp = recoded; - } else - g_string_free(recoded , TRUE); - } + if (recoded && recoded->len) + { + g_string_free (temp, TRUE); + temp = recoded; + } + else + g_string_free (recoded, TRUE); + } #endif - compl[*num].text = temp->str; - compl[*num].len = temp->len; - (*num)++; - start += len; - g_string_free(temp, FALSE); + compl[*num].text = temp->str; + compl[*num].len = temp->len; + (*num)++; + start += len; + g_string_free (temp, FALSE); - /* note the maximal length needed for the completion dialog */ - if (len > max_len) - max_len = len; + /* note the maximal length needed for the completion dialog */ + if (len > max_len) + max_len = len; } - mc_search_free(srch); + mc_search_free (srch); return max_len; } @@ -2543,78 +2788,84 @@ edit_collect_completions (WEdit *edit, long start, gsize word_len, * backwards beginning at the current cursor position. */ void -edit_complete_word_cmd (WEdit *edit) +edit_complete_word_cmd (WEdit * edit) { gsize i, max_len, word_len = 0, num_compl = 0; long word_start = 0; unsigned char *bufpos; char *match_expr; - struct selection compl[MAX_WORD_COMPLETIONS]; /* completions */ + struct selection compl[MAX_WORD_COMPLETIONS]; /* completions */ /* search start of word to be completed */ if (!edit_find_word_start (edit, &word_start, &word_len)) - return; + return; /* prepare match expression */ - bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE] - [word_start & M_EDIT_BUF_SIZE]; + bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE][word_start & M_EDIT_BUF_SIZE]; /* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */ - match_expr = g_strdup_printf ("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+", (int)word_len, bufpos); + match_expr = + g_strdup_printf + ("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+", + (int) word_len, bufpos); /* collect the possible completions */ /* start search from begin to end of file */ max_len = - edit_collect_completions (edit, word_start, word_len, match_expr, - (struct selection *) &compl, &num_compl); + edit_collect_completions (edit, word_start, word_len, match_expr, + (struct selection *) &compl, &num_compl); - if (num_compl > 0) { - /* insert completed word if there is only one match */ - if (num_compl == 1) { - for (i = word_len; i < compl[0].len; i++) - edit_insert (edit, *(compl[0].text + i)); - } - /* more than one possible completion => ask the user */ - else { - /* !!! usually only a beep is expected and when is !!! */ - /* !!! pressed again the selection dialog pops up, but that !!! */ - /* !!! seems to require a further internal state !!! */ - /*tty_beep (); */ + if (num_compl > 0) + { + /* insert completed word if there is only one match */ + if (num_compl == 1) + { + for (i = word_len; i < compl[0].len; i++) + edit_insert (edit, *(compl[0].text + i)); + } + /* more than one possible completion => ask the user */ + else + { + /* !!! usually only a beep is expected and when is !!! */ + /* !!! pressed again the selection dialog pops up, but that !!! */ + /* !!! seems to require a further internal state !!! */ + /*tty_beep (); */ - /* let the user select the preferred completion */ - editcmd_dialog_completion_show (edit, max_len, word_len, - (struct selection *) &compl, - num_compl); - } + /* let the user select the preferred completion */ + editcmd_dialog_completion_show (edit, max_len, word_len, + (struct selection *) &compl, num_compl); + } } g_free (match_expr); /* release memory before return */ for (i = 0; i < num_compl; i++) - g_free (compl[i].text); + g_free (compl[i].text); } void -edit_select_codepage_cmd (WEdit *edit) +edit_select_codepage_cmd (WEdit * edit) { #ifdef HAVE_CHARSET const char *cp_id = NULL; - if (do_select_codepage ()) { - cp_id = get_codepage_id (source_codepage >= 0 ? - source_codepage : display_codepage); + if (do_select_codepage ()) + { + cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage); - if (cp_id != NULL) { + if (cp_id != NULL) + { GIConv conv; conv = str_crt_conv_from (cp_id); - if (conv != INVALID_CONV) { + if (conv != INVALID_CONV) + { if (edit->converter != str_cnv_from_term) str_close_conv (edit->converter); edit->converter = conv; } } - if (cp_id != NULL) - edit->utf8 = str_isutf8 (cp_id); + if (cp_id != NULL) + edit->utf8 = str_isutf8 (cp_id); } edit->force = REDRAW_COMPLETELY; @@ -2625,22 +2876,19 @@ edit_select_codepage_cmd (WEdit *edit) } void -edit_insert_literal_cmd (WEdit *edit) +edit_insert_literal_cmd (WEdit * edit) { - int char_for_insertion = - editcmd_dialog_raw_key_query (_(" Insert Literal "), - _(" Press any key: "), 0); - edit_execute_key_command (edit, -1, - ascii_alpha_to_cntrl (char_for_insertion)); + int char_for_insertion = editcmd_dialog_raw_key_query (_(" Insert Literal "), + _(" Press any key: "), 0); + edit_execute_key_command (edit, -1, ascii_alpha_to_cntrl (char_for_insertion)); } void -edit_execute_macro_cmd (WEdit *edit) +edit_execute_macro_cmd (WEdit * edit) { int command = - CK_Macro (editcmd_dialog_raw_key_query - (_(" Execute Macro "), _(" Press macro hotkey: "), - 1)); + CK_Macro (editcmd_dialog_raw_key_query (_(" Execute Macro "), _(" Press macro hotkey: "), + 1)); if (command == CK_Macro (0)) command = CK_Insert_Char; @@ -2648,75 +2896,90 @@ edit_execute_macro_cmd (WEdit *edit) } void -edit_begin_end_macro_cmd (WEdit *edit) +edit_begin_end_macro_cmd (WEdit * edit) { /* edit is a pointer to the widget */ - if (edit) { - unsigned long command = edit->macro_i < 0 - ? CK_Begin_Record_Macro : CK_End_Record_Macro; - edit_execute_key_command (edit, command, -1); + if (edit) + { + unsigned long command = edit->macro_i < 0 ? CK_Begin_Record_Macro : CK_End_Record_Macro; + edit_execute_key_command (edit, command, -1); } } int -edit_load_forward_cmd (WEdit *edit) +edit_load_forward_cmd (WEdit * edit) { - if (edit->modified) { + if (edit->modified) + { if (edit_query_dialog2 (_("Warning"), _(" Current text was modified without a file save. \n" - " Continue discards these changes. "), _("C&ontinue"), - _("&Cancel"))) { + " Continue discards these changes. "), _("C&ontinue"), _("&Cancel"))) + { edit->force |= REDRAW_COMPLETELY; return 0; } } - if ( edit_stack_iterator + 1 < MAX_HISTORY_MOVETO ) { - if ( edit_history_moveto[edit_stack_iterator + 1].line < 1 ) { + if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO) + { + if (edit_history_moveto[edit_stack_iterator + 1].line < 1) + { return 1; } edit_stack_iterator++; - if ( edit_history_moveto[edit_stack_iterator].filename ) { + if (edit_history_moveto[edit_stack_iterator].filename) + { edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename, edit_history_moveto[edit_stack_iterator].line); return 0; - } else { + } + else + { return 1; } - } else { + } + else + { return 1; } } int -edit_load_back_cmd (WEdit *edit) +edit_load_back_cmd (WEdit * edit) { - if (edit->modified) { + if (edit->modified) + { if (edit_query_dialog2 (_("Warning"), _(" Current text was modified without a file save. \n" - " Continue discards these changes. "), _("C&ontinue"), - _("&Cancel"))) { + " Continue discards these changes. "), _("C&ontinue"), _("&Cancel"))) + { edit->force |= REDRAW_COMPLETELY; return 0; } } - if ( edit_stack_iterator > 0 ) { + if (edit_stack_iterator > 0) + { edit_stack_iterator--; - if ( edit_history_moveto[edit_stack_iterator].filename ) { + if (edit_history_moveto[edit_stack_iterator].filename) + { edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename, edit_history_moveto[edit_stack_iterator].line); return 0; - } else { + } + else + { return 1; } - } else { + } + else + { return 1; } } void -edit_get_match_keyword_cmd (WEdit *edit) +edit_get_match_keyword_cmd (WEdit * edit) { gsize word_len = 0, max_len = 0; int num_def = 0; @@ -2730,7 +2993,8 @@ edit_get_match_keyword_cmd (WEdit *edit) etags_hash_t def_hash[MAX_DEFINITIONS]; - for ( i = 0; i < MAX_DEFINITIONS; i++) { + for (i = 0; i < MAX_DEFINITIONS; i++) + { def_hash[i].filename = NULL; } @@ -2739,36 +3003,40 @@ edit_get_match_keyword_cmd (WEdit *edit) return; /* prepare match expression */ - bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE] - [word_start & M_EDIT_BUF_SIZE]; - match_expr = g_strdup_printf ("%.*s", (int)word_len, bufpos); + bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE][word_start & M_EDIT_BUF_SIZE]; + match_expr = g_strdup_printf ("%.*s", (int) word_len, bufpos); ptr = g_get_current_dir (); path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL); g_free (ptr); /* Recursive search file 'TAGS' in parent dirs */ - do { - ptr = g_path_get_dirname (path); - g_free(path); path = ptr; - g_free (tagfile); - tagfile = g_build_filename (path, TAGS_NAME, (char *) NULL); - if ( exist_file (tagfile) ) - break; - } while (strcmp( path, G_DIR_SEPARATOR_S) != 0); + do + { + ptr = g_path_get_dirname (path); + g_free (path); + path = ptr; + g_free (tagfile); + tagfile = g_build_filename (path, TAGS_NAME, (char *) NULL); + if (exist_file (tagfile)) + break; + } + while (strcmp (path, G_DIR_SEPARATOR_S) != 0); - if (tagfile){ - num_def = etags_set_definition_hash(tagfile, path, match_expr, (etags_hash_t *) &def_hash); - g_free (tagfile); + if (tagfile) + { + num_def = + etags_set_definition_hash (tagfile, path, match_expr, (etags_hash_t *) & def_hash); + g_free (tagfile); } g_free (path); max_len = MAX_WIDTH_DEF_DIALOG; word_len = 0; - if ( num_def > 0 ) { + if (num_def > 0) + { editcmd_dialog_select_definition_show (edit, match_expr, max_len, word_len, - (etags_hash_t *) &def_hash, - num_def); + (etags_hash_t *) & def_hash, num_def); } g_free (match_expr); } @@ -2779,28 +3047,37 @@ edit_move_block_to_right (WEdit * edit) long start_mark, end_mark; long cur_bol, start_bol; - if ( eval_marks (edit, &start_mark, &end_mark) ) + if (eval_marks (edit, &start_mark, &end_mark)) return; start_bol = edit_bol (edit, start_mark); cur_bol = edit_bol (edit, end_mark - 1); - do { + do + { edit_cursor_move (edit, cur_bol - edit->curs1); - if ( option_fill_tabs_with_spaces ) { - if ( option_fake_half_tabs ) { + if (option_fill_tabs_with_spaces) + { + if (option_fake_half_tabs) + { insert_spaces_tab (edit, 1); - } else { + } + else + { insert_spaces_tab (edit, 0); } - } else { + } + else + { edit_insert (edit, '\t'); } edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->curs1); - if ( cur_bol == 0 ) { + if (cur_bol == 0) + { break; } cur_bol = edit_bol (edit, cur_bol - 1); - } while (cur_bol >= start_bol) ; + } + while (cur_bol >= start_bol); edit->force |= REDRAW_PAGE; } @@ -2812,33 +3089,44 @@ edit_move_block_to_left (WEdit * edit) int i, del_tab_width; int next_char; - if ( eval_marks (edit, &start_mark, &end_mark) ) + if (eval_marks (edit, &start_mark, &end_mark)) return; start_bol = edit_bol (edit, start_mark); cur_bol = edit_bol (edit, end_mark - 1); - do { + do + { edit_cursor_move (edit, cur_bol - edit->curs1); - if (option_fake_half_tabs) { + if (option_fake_half_tabs) + { del_tab_width = HALF_TAB_SIZE; - } else { + } + else + { del_tab_width = option_tab_spacing; } next_char = edit_get_byte (edit, edit->curs1); - if ( next_char == '\t' ) { + if (next_char == '\t') + { edit_delete (edit, 1); - } else if ( next_char == ' ' ) { - for (i = 1; i <= del_tab_width; i++) { - if ( next_char == ' ' ) { + } + else if (next_char == ' ') + { + for (i = 1; i <= del_tab_width; i++) + { + if (next_char == ' ') + { edit_delete (edit, 1); } next_char = edit_get_byte (edit, edit->curs1); } } - if ( cur_bol == 0 ) { + if (cur_bol == 0) + { break; } cur_bol = edit_bol (edit, cur_bol - 1); - } while (cur_bol >= start_bol) ; + } + while (cur_bol >= start_bol); edit->force |= REDRAW_PAGE; } diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index 486a50adc..be77d7680 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -28,7 +28,7 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/skin.h" /* INPUT_COLOR */ +#include "lib/skin.h" /* INPUT_COLOR */ #include "lib/tty/key.h" #include "lib/search.h" #include "lib/strutil.h" @@ -47,8 +47,7 @@ /*** global variables **************************************************/ -edit_search_options_t edit_search_options = -{ +edit_search_options_t edit_search_options = { .type = MC_SEARCH_T_NORMAL, .case_sens = FALSE, .backwards = FALSE, @@ -74,10 +73,11 @@ edit_search_options_t edit_search_options = /*** file scope functions **********************************************/ static cb_ret_t -editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender, + dlg_msg_t msg, int parm, void *data) { - switch (msg) { + switch (msg) + { case DLG_KEY: h->ret_value = parm; dlg_stop (h); @@ -97,52 +97,61 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha search_default = INPUT_LAST_TEXT; { - size_t num_of_types; - gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); - int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY; + size_t num_of_types; + gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); + int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY; - QuickWidget quick_widgets[] = - { - /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), + QuickWidget quick_widgets[] = { + /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), #ifdef HAVE_CHARSET - /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"), - &edit_search_options.all_codepages), + /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, + N_("All charsets"), + &edit_search_options.all_codepages), #endif - /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"), - &edit_search_options.whole_words), - /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"), - &edit_search_options.only_in_selection), - /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"), - &edit_search_options.backwards), - /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), - &edit_search_options.case_sens), - /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, - num_of_types, (const char **) list_of_types, - (int *) &edit_search_options.type), - /* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:")), - /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT, - replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", replace_text), - /* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, N_(" Enter search string:")), - /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT, - search_default, REPLACE_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text), - QUICK_END - }; + /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, + N_("&Whole words"), + &edit_search_options.whole_words), + /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, + N_("In se&lection"), + &edit_search_options.only_in_selection), + /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"), + &edit_search_options.backwards), + /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, + N_("case &Sensitive"), + &edit_search_options.case_sens), + /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, + num_of_types, (const char **) list_of_types, + (int *) &edit_search_options.type), + /* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, + N_(" Enter replacement string:")), + /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT, + replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", + replace_text), + /* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, + N_(" Enter search string:")), + /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT, + search_default, REPLACE_DLG_WIDTH - 6, 0, + MC_HISTORY_SHARED_SEARCH, search_text), + QUICK_END + }; - QuickDialog Quick_input = - { - REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "), - "[Input Line Keys]", quick_widgets, FALSE - }; + QuickDialog Quick_input = { + REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "), + "[Input Line Keys]", quick_widgets, FALSE + }; - if (quick_dialog (&Quick_input) != B_CANCEL) { - edit->replace_mode = 0; - } else { - *replace_text = NULL; - *search_text = NULL; - } + if (quick_dialog (&Quick_input) != B_CANCEL) + { + edit->replace_mode = 0; + } + else + { + *replace_text = NULL; + *search_text = NULL; + } - g_strfreev (list_of_types); + g_strfreev (list_of_types); } } @@ -157,139 +166,138 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text) *search_text = INPUT_LAST_TEXT; { - size_t num_of_types; - gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); - int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY; - size_t i; + size_t num_of_types; + gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); + int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY; + size_t i; - int dialog_result; + int dialog_result; - QuickWidget quick_widgets[] = - { - /* 0 */ - QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ - QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL), - /* 2 */ - QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), + QuickWidget quick_widgets[] = { + /* 0 */ + QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ + QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL), + /* 2 */ + QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), #ifdef HAVE_CHARSET - /* 3 */ - QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"), - &edit_search_options.all_codepages), + /* 3 */ + QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"), + &edit_search_options.all_codepages), #endif - /* 4 */ - QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"), - &edit_search_options.whole_words), - /* 5 */ - QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), - &edit_search_options.only_in_selection), - /* 6 */ - QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), - &edit_search_options.backwards), - /* 7 */ - QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), - &edit_search_options.case_sens), - /* 8 */ - QUICK_RADIO ( 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, - num_of_types, (const char **) list_of_types, - (int *) &edit_search_options.type), - /* 9 */ - QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, - *search_text, SEARCH_DLG_WIDTH - 6, 0, - MC_HISTORY_SHARED_SEARCH, search_text), - /* 10 */ - QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")), - QUICK_END - }; + /* 4 */ + QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"), + &edit_search_options.whole_words), + /* 5 */ + QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), + &edit_search_options.only_in_selection), + /* 6 */ + QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), + &edit_search_options.backwards), + /* 7 */ + QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), + &edit_search_options.case_sens), + /* 8 */ + QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, + num_of_types, (const char **) list_of_types, + (int *) &edit_search_options.type), + /* 9 */ + QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, + *search_text, SEARCH_DLG_WIDTH - 6, 0, + MC_HISTORY_SHARED_SEARCH, search_text), + /* 10 */ + QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")), + QUICK_END + }; #ifdef HAVE_CHARSET - size_t last_checkbox = 7; + size_t last_checkbox = 7; #else - size_t last_checkbox = 6; + size_t last_checkbox = 6; #endif - QuickDialog Quick_input = - { - SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"), - "[Input Line Keys]", quick_widgets, TRUE - }; + QuickDialog Quick_input = { + SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"), + "[Input Line Keys]", quick_widgets, TRUE + }; #ifdef ENABLE_NLS - char **list_of_types_nls; + char **list_of_types_nls; - /* header title */ - Quick_input.title = _(Quick_input.title); - /* buttons */ - for (i = 0; i < 3; i++) - quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text); - /* checkboxes */ - for (i = 3; i <= last_checkbox; i++) - quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text); - /* label */ - quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text); + /* header title */ + Quick_input.title = _(Quick_input.title); + /* buttons */ + for (i = 0; i < 3; i++) + quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text); + /* checkboxes */ + for (i = 3; i <= last_checkbox; i++) + quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text); + /* label */ + quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text); - /* radiobuttons */ - /* create copy of radio items to avoid memory leak */ - list_of_types_nls = g_new0 (char *, num_of_types + 1); - for (i = 0; i < num_of_types; i++) - list_of_types_nls[i] = g_strdup (_(list_of_types[i])); - g_strfreev (list_of_types); - list_of_types = list_of_types_nls; - quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types; + /* radiobuttons */ + /* create copy of radio items to avoid memory leak */ + list_of_types_nls = g_new0 (char *, num_of_types + 1); + for (i = 0; i < num_of_types; i++) + list_of_types_nls[i] = g_strdup (_(list_of_types[i])); + g_strfreev (list_of_types); + list_of_types = list_of_types_nls; + quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types; #endif - /* calculate widget coordinates */ - { - int len = 0; - int dlg_width; - gchar **radio = list_of_types; - int b0_len, b1_len, b2_len; - const int button_gap = 2; + /* calculate widget coordinates */ + { + int len = 0; + int dlg_width; + gchar **radio = list_of_types; + int b0_len, b1_len, b2_len; + const int button_gap = 2; - /* length of radiobuttons */ - while (*radio != NULL) { - len = max (len, str_term_width1 (*radio)); - radio++; - } - /* length of checkboxes */ - for (i = 3; i <= last_checkbox; i++) - len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4); + /* length of radiobuttons */ + while (*radio != NULL) + { + len = max (len, str_term_width1 (*radio)); + radio++; + } + /* length of checkboxes */ + for (i = 3; i <= last_checkbox; i++) + len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4); - /* preliminary dialog width */ - dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4; + /* preliminary dialog width */ + dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4; - /* length of buttons */ - b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; - b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3; - b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */ - len = b0_len + b1_len + b2_len + button_gap * 2; + /* length of buttons */ + b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; + b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3; + b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */ + len = b0_len + b1_len + b2_len + button_gap * 2; - /* dialog width */ - Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6)); + /* dialog width */ + Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6)); - /* correct widget coordinates */ - for (i = 0; i < sizeof (quick_widgets)/sizeof (quick_widgets[0]); i++) - quick_widgets[i].x_divisions = Quick_input.xlen; + /* correct widget coordinates */ + for (i = 0; i < sizeof (quick_widgets) / sizeof (quick_widgets[0]); i++) + quick_widgets[i].x_divisions = Quick_input.xlen; - /* checkbox positions */ - for (i = 3; i <= last_checkbox; i++) - quick_widgets[i].relative_x = Quick_input.xlen/2 + 2; - /* input length */ - quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6; - /* button positions */ - quick_widgets[2].relative_x = Quick_input.xlen/2 - len/2; - quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap; - quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap; - } + /* checkbox positions */ + for (i = 3; i <= last_checkbox; i++) + quick_widgets[i].relative_x = Quick_input.xlen / 2 + 2; + /* input length */ + quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6; + /* button positions */ + quick_widgets[2].relative_x = Quick_input.xlen / 2 - len / 2; + quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap; + quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap; + } - dialog_result = quick_dialog (&Quick_input); + dialog_result = quick_dialog (&Quick_input); - g_strfreev (list_of_types); + g_strfreev (list_of_types); - if (dialog_result == B_CANCEL) - *search_text = NULL; - else if (dialog_result == B_USER) - search_create_bookmark = 1; + if (dialog_result == B_CANCEL) + *search_text = NULL; + else if (dialog_result == B_USER) + search_create_bookmark = 1; } } @@ -314,7 +322,8 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0)); w = run_dlg (raw_dlg); destroy_dlg (raw_dlg); - if (cancel) { + if (cancel) + { if (w == XCTRL ('g') || w == XCTRL ('c') || w == ESC_CHAR || w == B_CANCEL) return 0; } @@ -341,7 +350,7 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len, compl_dlg_h = num_compl + 2; compl_dlg_w = max_len + 4; start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) + - EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1; if (start_x < 0) @@ -370,30 +379,33 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len, add_widget (compl_dlg, compl_list); /* fill the listbox with the completions */ - for (i = num_compl - 1; i >= 0; i--) /* reverse order */ + for (i = num_compl - 1; i >= 0; i--) /* reverse order */ listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL); /* pop up the dialog and apply the choosen completion */ - if (run_dlg (compl_dlg) == B_ENTER) { + if (run_dlg (compl_dlg) == B_ENTER) + { listbox_get_current (compl_list, &curr, NULL); - if (curr) { + if (curr) + { #ifdef HAVE_CHARSET - GString *temp, *temp2; - temp = g_string_new(""); - for (curr += word_len; *curr; curr++) - g_string_append_c(temp, *curr); + GString *temp, *temp2; + temp = g_string_new (""); + for (curr += word_len; *curr; curr++) + g_string_append_c (temp, *curr); - temp2 = str_convert_to_input (temp->str); + temp2 = str_convert_to_input (temp->str); - if (temp2 && temp2->len){ - g_string_free(temp, TRUE); - temp = temp2; - } - else - g_string_free(temp2, TRUE); - for (curr = temp->str; *curr; curr++) - edit_insert (edit, *curr); - g_string_free(temp, TRUE); + if (temp2 && temp2->len) + { + g_string_free (temp, TRUE); + temp = temp2; + } + else + g_string_free (temp2, TRUE); + for (curr = temp->str; *curr; curr++) + edit_insert (edit, *curr); + g_string_free (temp, TRUE); #else for (curr += word_len; *curr; curr++) edit_insert (edit, *curr); @@ -427,7 +439,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l def_dlg_h = num_lines + 2; def_dlg_w = max_len + 4; start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) + - EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1; if (start_x < 0) @@ -455,7 +467,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l add_widget (def_dlg, def_list); /* fill the listbox with the completions */ - for (i = 0; i < num_lines; i++) { + for (i = 0; i < num_lines; i++) + { label_def = g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename, def_hash[i].line); @@ -464,31 +477,41 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l } /* pop up the dialog and apply the choosen completion */ - if (run_dlg (def_dlg) == B_ENTER) { + if (run_dlg (def_dlg) == B_ENTER) + { char *tmp_curr_def = (char *) curr_def; int do_moveto = 0; listbox_get_current (def_list, &curr, (void **) &tmp_curr_def); curr_def = (etags_hash_t *) tmp_curr_def; - if (edit->modified) { + if (edit->modified) + { if (!edit_query_dialog2 (_("Warning"), _(" Current text was modified without a file save. \n" - " Continue discards these changes. "), _("C&ontinue"), _("&Cancel"))) { + " Continue discards these changes. "), _("C&ontinue"), _("&Cancel"))) + { edit->force |= REDRAW_COMPLETELY; do_moveto = 1; } - } else { + } + else + { do_moveto = 1; } - if (curr && do_moveto) { - if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO) { + if (curr && do_moveto) + { + if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO) + { g_free (edit_history_moveto[edit_stack_iterator].filename); - if (edit->dir) { + if (edit->dir) + { edit_history_moveto[edit_stack_iterator].filename = g_strdup_printf ("%s/%s", edit->dir, edit->filename); - } else { + } + else + { edit_history_moveto[edit_stack_iterator].filename = g_strdup (edit->filename); } edit_history_moveto[edit_stack_iterator].line = edit->start_line + @@ -505,7 +528,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l } /* clear definition hash */ - for (i = 0; i < MAX_DEFINITIONS; i++) { + for (i = 0; i < MAX_DEFINITIONS; i++) + { g_free (def_hash[i].filename); } @@ -516,7 +540,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l /* --------------------------------------------------------------------------------------------- */ int -editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos, int ypos) +editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos, + int ypos) { /* dialog sizes */ int dlg_height = 9; @@ -527,75 +552,74 @@ editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text int btn_pos; char *repl_from, *repl_to; - char tmp [BUF_MEDIUM]; + char tmp[BUF_MEDIUM]; - QuickWidget quick_widgets[] = - { - /* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL), - /* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL), - /* 3 */ QUICK_BUTTON ( 4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL), - /* 4 */ QUICK_LABEL ( 3, dlg_width, 2, dlg_height, NULL), - /* 5 */ QUICK_LABEL ( 2, dlg_width, 3, dlg_height, N_(" Replace with: ")), - /* 6 */ QUICK_LABEL ( 3, dlg_width, 4, dlg_height, NULL), - QUICK_END + QuickWidget quick_widgets[] = { + /* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL), + /* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL), + /* 3 */ QUICK_BUTTON (4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL), + /* 4 */ QUICK_LABEL (3, dlg_width, 2, dlg_height, NULL), + /* 5 */ QUICK_LABEL (2, dlg_width, 3, dlg_height, N_(" Replace with: ")), + /* 6 */ QUICK_LABEL (3, dlg_width, 4, dlg_height, NULL), + QUICK_END }; #ifdef ENABLE_NLS - for (i = 0; i < 4; i++) - quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text); + for (i = 0; i < 4; i++) + quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text); #endif /* calculate button positions */ btn_pos = 4; - for (i = 3; i > -1; i--) { + for (i = 3; i > -1; i--) + { quick_widgets[i].relative_x = btn_pos; btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5; - if (i == 3) /* default button */ + if (i == 3) /* default button */ btn_pos += 2; } dlg_width = btn_pos + 2; /* correct widget coordinates */ - for (i = 0; i < 7; i++) - quick_widgets[i].x_divisions = dlg_width; + for (i = 0; i < 7; i++) + quick_widgets[i].x_divisions = dlg_width; g_snprintf (tmp, sizeof (tmp), " '%s'", from_text); repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT)); g_snprintf (tmp, sizeof (tmp), " '%s'", to_text); - repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT)); + repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT)); quick_widgets[4].u.label.text = repl_from; quick_widgets[6].u.label.text = repl_to; if (xpos == -1) - xpos = (edit->num_widget_columns - dlg_width) / 2; + xpos = (edit->num_widget_columns - dlg_width) / 2; if (ypos == -1) - ypos = edit->num_widget_lines * 2 / 3; + ypos = edit->num_widget_lines * 2 / 3; { - QuickDialog Quick_input = - { - dlg_width, dlg_height, 0, 0, N_ (" Confirm replace "), - "[Input Line Keys]", quick_widgets, FALSE - }; + QuickDialog Quick_input = { + dlg_width, dlg_height, 0, 0, N_(" Confirm replace "), + "[Input Line Keys]", quick_widgets, FALSE + }; - /* Sometimes menu can hide replaced text. I don't like it */ - if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1)) - ypos -= dlg_height; + /* Sometimes menu can hide replaced text. I don't like it */ + if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1)) + ypos -= dlg_height; - Quick_input.ypos = ypos; - Quick_input.xpos = xpos; + Quick_input.ypos = ypos; + Quick_input.xpos = xpos; - retval = quick_dialog (&Quick_input); - g_free (repl_from); - g_free (repl_to); + retval = quick_dialog (&Quick_input); + g_free (repl_from); + g_free (repl_to); - return retval; + return retval; } } diff --git a/src/filegui.c b/src/filegui.c index d997544e9..0fbae3002 100644 --- a/src/filegui.c +++ b/src/filegui.c @@ -7,8 +7,8 @@ * 1994, 1995 Fred Leeflang * 1994, 1995, 1996 Miguel de Icaza * 1995, 1996 Jakub Jelinek - * 1997 Norbert Warmuth - * 1998 Pavel Machek + * 1997 Norbert Warmuth + * 1998 Pavel Machek * 2009 Slava Zanko * * The copy code was based in GNU's cp, and was written by: @@ -78,24 +78,25 @@ #include "lib/global.h" -#include "lib/tty/key.h" /* tty_get_event */ +#include "lib/tty/key.h" /* tty_get_event */ #include "lib/mcconfig.h" #include "lib/search.h" #include "lib/vfs/mc-vfs/vfs.h" #include "lib/strescape.h" #include "lib/strutil.h" -#include "setup.h" /* verbose */ -#include "dialog.h" /* do_refresh() */ -#include "widget.h" /* WLabel */ +#include "setup.h" /* verbose */ +#include "dialog.h" /* do_refresh() */ +#include "widget.h" /* WLabel */ #include "main-widgets.h" -#include "main.h" /* the_hint */ -#include "wtools.h" /* QuickDialog */ -#include "panel.h" /* current_panel */ -#include "fileopctx.h" /* FILE_CONT */ +#include "main.h" /* the_hint */ +#include "wtools.h" /* QuickDialog */ +#include "panel.h" /* current_panel */ +#include "fileopctx.h" /* FILE_CONT */ #include "filegui.h" /* }}} */ +/* *INDENT-OFF* */ typedef enum { MSDOS_SUPER_MAGIC = 0x4d44, NTFS_SB_MAGIC = 0x5346544e, @@ -105,12 +106,14 @@ typedef enum { NCP_SUPER_MAGIC = 0x564c, USBDEVICE_SUPER_MAGIC = 0x9fa2 } filegui_nonattrs_fs_t; +/* *INDENT-ON* */ /* Hack: the vfs code should not rely on this */ #define WITH_FULL_PATHS 1 /* Used for button result values */ -typedef enum { +typedef enum +{ REPLACE_YES = B_USER, REPLACE_NO, REPLACE_APPEND, @@ -125,7 +128,8 @@ typedef enum { /* This structure describes the UI and internal data required by a file * operation context. */ -typedef struct { +typedef struct +{ /* ETA and bps */ gboolean showing_eta; gboolean showing_bps; @@ -186,19 +190,17 @@ filegui__check_attrs_on_fs (const char *fs_path) } # elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \ || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) - if (!strcmp(stfs.f_fstypename, "msdos") - || !strcmp(stfs.f_fstypename, "msdosfs") - || !strcmp(stfs.f_fstypename, "ntfs") - || !strcmp(stfs.f_fstypename, "procfs") - || !strcmp(stfs.f_fstypename, "smbfs") - || strstr(stfs.f_fstypename, "fusefs")) + if (!strcmp (stfs.f_fstypename, "msdos") + || !strcmp (stfs.f_fstypename, "msdosfs") + || !strcmp (stfs.f_fstypename, "ntfs") + || !strcmp (stfs.f_fstypename, "procfs") + || !strcmp (stfs.f_fstypename, "smbfs") || strstr (stfs.f_fstypename, "fusefs")) return FALSE; # elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE) - if (!strcmp(stfs.f_basetype, "pcfs") - || !strcmp(stfs.f_basetype, "ntfs") - || !strcmp(stfs.f_basetype, "proc") - || !strcmp(stfs.f_basetype, "smbfs") - || !strcmp(stfs.f_basetype, "fuse")) + if (!strcmp (stfs.f_basetype, "pcfs") + || !strcmp (stfs.f_basetype, "ntfs") + || !strcmp (stfs.f_basetype, "proc") + || !strcmp (stfs.f_basetype, "smbfs") || !strcmp (stfs.f_basetype, "fuse")) return FALSE; # endif #endif /* STATFS */ @@ -207,45 +209,47 @@ filegui__check_attrs_on_fs (const char *fs_path) } FileProgressStatus -check_progress_buttons (FileOpContext *ctx) +check_progress_buttons (FileOpContext * ctx) { int c; Gpm_Event event; FileOpContextUI *ui; if (ctx->ui == NULL) - return FILE_CONT; + return FILE_CONT; ui = ctx->ui; - event.x = -1; /* Don't show the GPM cursor */ + event.x = -1; /* Don't show the GPM cursor */ c = tty_get_event (&event, FALSE, FALSE); if (c == EV_NONE) - return FILE_CONT; + return FILE_CONT; /* Reinitialize to avoid old values after events other than selecting a button */ ui->op_dlg->ret_value = FILE_CONT; dlg_process_event (ui->op_dlg, c, &event); - switch (ui->op_dlg->ret_value) { + switch (ui->op_dlg->ret_value) + { case FILE_SKIP: - return FILE_SKIP; + return FILE_SKIP; case B_CANCEL: case FILE_ABORT: - return FILE_ABORT; + return FILE_ABORT; default: - return FILE_CONT; + return FILE_CONT; } } /* {{{ File progress display routines */ void -file_op_context_create_ui_without_init (FileOpContext *ctx, gboolean with_eta, filegui_dialog_type_t dialog_type) +file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta, + filegui_dialog_type_t dialog_type) { FileOpContextUI *ui; - int minus, total_reserve=0; + int minus, total_reserve = 0; const char *abort_button_label = N_("&Abort"); const char *skip_button_label = N_("&Skip"); int abort_button_width, skip_button_width, buttons_width; @@ -271,16 +275,17 @@ file_op_context_create_ui_without_init (FileOpContext *ctx, gboolean with_eta, f ctx->dialog_type = dialog_type; minus = verbose ? 0 : 3; - switch (dialog_type) { - case FILEGUI_DIALOG_ONE_ITEM: - total_reserve = 0; - break; - case FILEGUI_DIALOG_MULTI_ITEM: - total_reserve = 5; - break; - case FILEGUI_DIALOG_DELETE_ITEM: - total_reserve = -5; - break; + switch (dialog_type) + { + case FILEGUI_DIALOG_ONE_ITEM: + total_reserve = 0; + break; + case FILEGUI_DIALOG_MULTI_ITEM: + total_reserve = 5; + break; + case FILEGUI_DIALOG_DELETE_ITEM: + total_reserve = -5; + break; } ctx->recursive_result = RECURSIVE_YES; @@ -290,67 +295,60 @@ file_op_context_create_ui_without_init (FileOpContext *ctx, gboolean with_eta, f ui->showing_bps = with_eta; ui->op_dlg = - create_dlg (0, 0, WY - minus + 1 + total_reserve, dlg_width, - dialog_colors, NULL, NULL, op_names[ctx->operation], - DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, WY - minus + 1 + total_reserve, dlg_width, + dialog_colors, NULL, NULL, op_names[ctx->operation], DLG_CENTER | DLG_REVERSE); last_hint_line = the_hint->widget.y; if ((ui->op_dlg->y + ui->op_dlg->lines) > last_hint_line) - the_hint->widget.y = ui->op_dlg->y + ui->op_dlg->lines + 1; + the_hint->widget.y = ui->op_dlg->y + ui->op_dlg->lines + 1; add_widget (ui->op_dlg, - button_new (WY - minus - 2 + total_reserve, - dlg_width/2 + 1, FILE_ABORT, - NORMAL_BUTTON, abort_button_label, NULL)); + button_new (WY - minus - 2 + total_reserve, + dlg_width / 2 + 1, FILE_ABORT, + NORMAL_BUTTON, abort_button_label, NULL)); add_widget (ui->op_dlg, - button_new (WY - minus - 2 + total_reserve, - dlg_width/2 - 1 - skip_button_width, FILE_SKIP, - NORMAL_BUTTON, skip_button_label, NULL)); + button_new (WY - minus - 2 + total_reserve, + dlg_width / 2 - 1 - skip_button_width, FILE_SKIP, + NORMAL_BUTTON, skip_button_label, NULL)); - if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM) { - add_widget (ui->op_dlg, hline_new (8, 1, dlg_width - 2)); + if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM) + { + add_widget (ui->op_dlg, hline_new (8, 1, dlg_width - 2)); - add_widget (ui->op_dlg, ui->total_bytes_label = - label_new (8, FCOPY_LABEL_X + 15, "")); + add_widget (ui->op_dlg, ui->total_bytes_label = label_new (8, FCOPY_LABEL_X + 15, "")); - add_widget (ui->op_dlg, ui->progress_total_gauge = - gauge_new (9, FCOPY_LABEL_X + 3, 0, 100, 0)); + add_widget (ui->op_dlg, ui->progress_total_gauge = + gauge_new (9, FCOPY_LABEL_X + 3, 0, 100, 0)); - add_widget (ui->op_dlg, ui->total_files_processed_label = - label_new (11, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->total_files_processed_label = + label_new (11, FCOPY_LABEL_X, "")); - add_widget (ui->op_dlg, ui->time_label = - label_new (12, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->time_label = label_new (12, FCOPY_LABEL_X, "")); } - add_widget (ui->op_dlg, ui->progress_file_label = - label_new (7, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->progress_file_label = label_new (7, FCOPY_LABEL_X, "")); - add_widget (ui->op_dlg, ui->progress_file_gauge = - gauge_new (6, FCOPY_LABEL_X + 3, 0, 100, 0)); + add_widget (ui->op_dlg, ui->progress_file_gauge = gauge_new (6, FCOPY_LABEL_X + 3, 0, 100, 0)); - add_widget (ui->op_dlg, ui->file_string[1] = - label_new (5, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->file_string[1] = label_new (5, FCOPY_LABEL_X, "")); - add_widget (ui->op_dlg, ui->file_label[1] = - label_new (4, FCOPY_LABEL_X, "")); - add_widget (ui->op_dlg, ui->file_string[0] = - label_new (3, FCOPY_LABEL_X, "")); - add_widget (ui->op_dlg, ui->file_label[0] = - label_new (2, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->file_label[1] = label_new (4, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->file_string[0] = label_new (3, FCOPY_LABEL_X, "")); + add_widget (ui->op_dlg, ui->file_label[0] = label_new (2, FCOPY_LABEL_X, "")); if ((right_panel == current_panel) - && !mc_config_get_bool (mc_main_config,"Layout", - "classic_progressbar", TRUE)) { - ui->progress_file_gauge->from_left_to_right = FALSE; - if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM) - ui->progress_total_gauge->from_left_to_right = FALSE; + && !mc_config_get_bool (mc_main_config, "Layout", "classic_progressbar", TRUE)) + { + ui->progress_file_gauge->from_left_to_right = FALSE; + if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM) + ui->progress_total_gauge->from_left_to_right = FALSE; } } void -file_op_context_create_ui (FileOpContext *ctx, gboolean with_eta, filegui_dialog_type_t dialog_type) +file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta, + filegui_dialog_type_t dialog_type) { FileOpContextUI *ui; @@ -367,18 +365,19 @@ file_op_context_create_ui (FileOpContext *ctx, gboolean with_eta, filegui_dialog } void -file_op_context_destroy_ui (FileOpContext *ctx) +file_op_context_destroy_ui (FileOpContext * ctx) { FileOpContextUI *ui; g_return_if_fail (ctx != NULL); - if (ctx->ui) { - ui = ctx->ui; + if (ctx->ui) + { + ui = ctx->ui; - dlg_run_done (ui->op_dlg); - destroy_dlg (ui->op_dlg); - g_free (ui); + dlg_run_done (ui->op_dlg); + destroy_dlg (ui->op_dlg); + g_free (ui); } the_hint->widget.y = last_hint_line; @@ -400,12 +399,13 @@ static void file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show) { char _fmt_buff[BUF_TINY]; - if (eta_secs <= 0.5 && !always_show) { - *buffer = '\0'; - return; + if (eta_secs <= 0.5 && !always_show) + { + *buffer = '\0'; + return; } - if (eta_secs <= 0.5) - eta_secs = 1; + if (eta_secs <= 0.5) + eta_secs = 1; file_frmt_time (_fmt_buff, eta_secs); g_snprintf (buffer, BUF_TINY, _("ETA %s"), _fmt_buff); } @@ -413,25 +413,28 @@ file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show) static void file_bps_prepare_for_show (char *buffer, long bps) { - if (bps > 1024 * 1024) { - g_snprintf (buffer, BUF_TINY, _("%.2f MB/s"), - bps / (1024 * 1024.0)); - } else if (bps > 1024) { - g_snprintf (buffer, BUF_TINY, _("%.2f KB/s"), - bps / 1024.0); - } else if (bps > 1) { - g_snprintf (buffer, BUF_TINY, _("%ld B/s"), - bps); - } else - *buffer = 0; + if (bps > 1024 * 1024) + { + g_snprintf (buffer, BUF_TINY, _("%.2f MB/s"), bps / (1024 * 1024.0)); + } + else if (bps > 1024) + { + g_snprintf (buffer, BUF_TINY, _("%.2f KB/s"), bps / 1024.0); + } + else if (bps > 1) + { + g_snprintf (buffer, BUF_TINY, _("%ld B/s"), bps); + } + else + *buffer = 0; } /* - show progressbar for file -*/ + show progressbar for file + */ void -file_progress_show (FileOpContext *ctx, off_t done, off_t total, - const char *stalled_msg, gboolean force_update) +file_progress_show (FileOpContext * ctx, off_t done, off_t total, + const char *stalled_msg, gboolean force_update) { FileOpContextUI *ui; char buffer[BUF_TINY]; @@ -441,37 +444,41 @@ file_progress_show (FileOpContext *ctx, off_t done, off_t total, g_return_if_fail (ctx != NULL); if (ctx->ui == NULL) - return; + return; ui = ctx->ui; if (!verbose) - return; + return; - if (total == 0) { - gauge_show (ui->progress_file_gauge, 0); - return; + if (total == 0) + { + gauge_show (ui->progress_file_gauge, 0); + return; } gauge_set_value (ui->progress_file_gauge, 1024, (int) (1024 * done / total)); gauge_show (ui->progress_file_gauge, 1); if (!force_update) - return; + return; - if (ui->showing_eta && ctx->eta_secs > 0.5) { - file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE); - file_bps_prepare_for_show (buffer3, ctx->bps); - g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg); - } else { - g_snprintf (buffer, BUF_TINY, "%s",stalled_msg); + if (ui->showing_eta && ctx->eta_secs > 0.5) + { + file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE); + file_bps_prepare_for_show (buffer3, ctx->bps); + g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg); + } + else + { + g_snprintf (buffer, BUF_TINY, "%s", stalled_msg); } label_set_text (ui->progress_file_label, buffer); } void -file_progress_show_count (FileOpContext *ctx, off_t done, off_t total) +file_progress_show_count (FileOpContext * ctx, off_t done, off_t total) { char buffer[BUF_TINY]; FileOpContextUI *ui; @@ -479,23 +486,22 @@ file_progress_show_count (FileOpContext *ctx, off_t done, off_t total) g_return_if_fail (ctx != NULL); if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL) - return; + return; ui = ctx->ui; if (!verbose) - return; + return; g_snprintf (buffer, BUF_TINY, _("Files processed: %llu of %llu"), - (unsigned long long) done, - (unsigned long long) total); + (unsigned long long) done, (unsigned long long) total); label_set_text (ui->total_files_processed_label, buffer); } void -file_progress_show_total (FileOpTotalContext *tctx, FileOpContext *ctx, double copyed_bytes, - gboolean need_show_total_summary) +file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx, double copyed_bytes, + gboolean need_show_total_summary) { char buffer[BUF_TINY]; char buffer2[BUF_TINY]; @@ -505,19 +511,22 @@ file_progress_show_total (FileOpTotalContext *tctx, FileOpContext *ctx, double c FileOpContextUI *ui; if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL) - return; + return; ui = ctx->ui; - if (ctx->progress_bytes > 0 ){ - gauge_set_value (ui->progress_total_gauge, 1024, (int) (1024 * copyed_bytes/ ctx->progress_bytes)); - gauge_show (ui->progress_total_gauge, 1); - } else - gauge_show (ui->progress_total_gauge, 0); + if (ctx->progress_bytes > 0) + { + gauge_set_value (ui->progress_total_gauge, 1024, + (int) (1024 * copyed_bytes / ctx->progress_bytes)); + gauge_show (ui->progress_total_gauge, 1); + } + else + gauge_show (ui->progress_total_gauge, 0); if (!need_show_total_summary && tctx->bps == 0) - return; + return; gettimeofday (&tv_current, NULL); file_frmt_time (buffer2, tv_current.tv_sec - tctx->transfer_start.tv_sec); @@ -526,13 +535,13 @@ file_progress_show_total (FileOpTotalContext *tctx, FileOpContext *ctx, double c - g_snprintf (buffer, BUF_TINY, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4); + g_snprintf (buffer, BUF_TINY, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4); label_set_text (ui->time_label, buffer); size_trunc_len (buffer2, 5, tctx->copyed_bytes, 0); size_trunc_len (buffer3, 5, ctx->progress_bytes, 0); - g_snprintf (buffer, BUF_TINY, _(" Total: %s of %s "), buffer2, buffer3); + g_snprintf (buffer, BUF_TINY, _(" Total: %s of %s "), buffer2, buffer3); label_set_text (ui->total_bytes_label, buffer); @@ -544,66 +553,73 @@ file_progress_show_total (FileOpTotalContext *tctx, FileOpContext *ctx, double c #define truncFileStringSecure(ui, s) path_trunc (s, 52) void -file_progress_show_source (FileOpContext *ctx, const char *s) +file_progress_show_source (FileOpContext * ctx, const char *s) { FileOpContextUI *ui; g_return_if_fail (ctx != NULL); if (ctx->ui == NULL) - return; + return; ui = ctx->ui; - if (s != NULL) { + if (s != NULL) + { #ifdef WITH_FULL_PATHS - int i = strlen (current_panel->cwd); + int i = strlen (current_panel->cwd); - /* We remove the full path we have added before */ - if (!strncmp (s, current_panel->cwd, i)) { - if (s[i] == PATH_SEP) - s += i + 1; - } -#endif /* WITH_FULL_PATHS */ + /* We remove the full path we have added before */ + if (!strncmp (s, current_panel->cwd, i)) + { + if (s[i] == PATH_SEP) + s += i + 1; + } +#endif /* WITH_FULL_PATHS */ - label_set_text (ui->file_label[0], _("Source")); - label_set_text (ui->file_string[0], truncFileString (ui, s)); - } else { - label_set_text (ui->file_label[0], ""); - label_set_text (ui->file_string[0], ""); + label_set_text (ui->file_label[0], _("Source")); + label_set_text (ui->file_string[0], truncFileString (ui, s)); + } + else + { + label_set_text (ui->file_label[0], ""); + label_set_text (ui->file_string[0], ""); } } void -file_progress_show_target (FileOpContext *ctx, const char *s) +file_progress_show_target (FileOpContext * ctx, const char *s) { FileOpContextUI *ui; g_return_if_fail (ctx != NULL); if (ctx->ui == NULL) - return; + return; ui = ctx->ui; - if (s != NULL) { - label_set_text (ui->file_label[1], _("Target")); - label_set_text (ui->file_string[1], truncFileStringSecure (ui, s)); - } else { - label_set_text (ui->file_label[1], ""); - label_set_text (ui->file_string[1], ""); + if (s != NULL) + { + label_set_text (ui->file_label[1], _("Target")); + label_set_text (ui->file_string[1], truncFileStringSecure (ui, s)); + } + else + { + label_set_text (ui->file_label[1], ""); + label_set_text (ui->file_string[1], ""); } } void -file_progress_show_deleting (FileOpContext *ctx, const char *s) +file_progress_show_deleting (FileOpContext * ctx, const char *s) { FileOpContextUI *ui; g_return_if_fail (ctx != NULL); if (ctx->ui == NULL) - return; + return; ui = ctx->ui; label_set_text (ui->file_label[0], _("Deleting")); @@ -616,7 +632,7 @@ file_progress_show_deleting (FileOpContext *ctx, const char *s) * alex */ static replace_action_t -overwrite_query_dialog (FileOpContext *ctx, enum OperationMode mode) +overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode) { #define ADD_RD_BUTTON(i)\ add_widget (ui->replace_dlg,\ @@ -632,31 +648,67 @@ overwrite_query_dialog (FileOpContext *ctx, enum OperationMode mode) const int rd_ylen = 17; int rd_xlen = 60; - struct { - const char *text; - int ypos, xpos; - int value; /* 0 for labels */ - } rd_widgets[] = { - /* 0 */ { N_("Target file already exists!"), 3, 4, 0 }, - /* 1 */ { "%s", 4, 4, 0 }, + struct + { + const char *text; + int ypos, xpos; + int value; /* 0 for labels */ + } rd_widgets[] = + { + /* 0 */ + { + N_("Target file already exists!"), 3, 4, 0}, + /* 1 */ + { + "%s", 4, 4, 0}, #if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || (defined _LARGE_FILES && _LARGE_FILES) - /* 2 */ { N_("Source date: %s, size %llu"), 6, 4, 0 }, - /* 3 */ { N_("Target date: %s, size %llu"), 7, 4, 0 }, + /* 2 */ + { + N_("Source date: %s, size %llu"), 6, 4, 0}, + /* 3 */ + { + N_("Target date: %s, size %llu"), 7, 4, 0}, #else - /* 2 */ { N_("Source date: %s, size %u"), 6, 4, 0 }, - /* 3 */ { N_("Target date: %s, size %u"), 7, 4, 0 }, + /* 2 */ + { + N_("Source date: %s, size %u"), 6, 4, 0}, + /* 3 */ + { + N_("Target date: %s, size %u"), 7, 4, 0}, #endif - /* 4 */ { N_("&Abort"), 14, 25, REPLACE_ABORT }, - /* 5 */ { N_("If &size differs"), 12, 28, REPLACE_SIZE }, - /* 6 */ { N_("Non&e"), 11, 47, REPLACE_NEVER }, - /* 7 */ { N_("&Update"), 11, 36, REPLACE_UPDATE }, - /* 8 */ { N_("A&ll"), 11, 28, REPLACE_ALWAYS }, - /* 9 */ { N_("Overwrite all targets?"), 11, 4, 0 }, - /* 10 */ { N_("&Reget"), 10, 28, REPLACE_REGET }, - /* 11 */ { N_("A&ppend"), 9, 45, REPLACE_APPEND }, - /* 12 */ { N_("&No"), 9, 37, REPLACE_NO }, - /* 13 */ { N_("&Yes"), 9, 28, REPLACE_YES }, - /* 14 */ { N_("Overwrite this target?"), 9, 4, 0 } + /* 4 */ + { + N_("&Abort"), 14, 25, REPLACE_ABORT}, + /* 5 */ + { + N_("If &size differs"), 12, 28, REPLACE_SIZE}, + /* 6 */ + { + N_("Non&e"), 11, 47, REPLACE_NEVER}, + /* 7 */ + { + N_("&Update"), 11, 36, REPLACE_UPDATE}, + /* 8 */ + { + N_("A&ll"), 11, 28, REPLACE_ALWAYS}, + /* 9 */ + { + N_("Overwrite all targets?"), 11, 4, 0}, + /* 10 */ + { + N_("&Reget"), 10, 28, REPLACE_REGET}, + /* 11 */ + { + N_("A&ppend"), 9, 45, REPLACE_APPEND}, + /* 12 */ + { + N_("&No"), 9, 37, REPLACE_NO}, + /* 13 */ + { + N_("&Yes"), 9, 28, REPLACE_YES}, + /* 14 */ + { + N_("Overwrite this target?"), 9, 4, 0} }; const int num = sizeof (rd_widgets) / sizeof (rd_widgets[0]); @@ -674,106 +726,106 @@ overwrite_query_dialog (FileOpContext *ctx, enum OperationMode mode) widgets_len = g_new0 (int, num); if (mode == Foreground) - title = _(" File exists "); + title = _(" File exists "); else - title = _(" Background process: File exists "); + title = _(" Background process: File exists "); stripped_name_len = str_term_width1 (stripped_name); { - int i, l1, l2, l, row; + int i, l1, l2, l, row; - for (i = 0; i < num; i++) { + for (i = 0; i < num; i++) + { #ifdef ENABLE_NLS - if (i != 1) /* skip filename */ - rd_widgets[i].text = _(rd_widgets[i].text); -#endif /* ENABLE_NLS */ - widgets_len [i] = str_term_width1 (rd_widgets[i].text); - } + if (i != 1) /* skip filename */ + rd_widgets[i].text = _(rd_widgets[i].text); +#endif /* ENABLE_NLS */ + widgets_len[i] = str_term_width1 (rd_widgets[i].text); + } - /* - * longest of "Overwrite..." labels - * (assume "Target date..." are short enough) - */ - l1 = max (widgets_len[9], widgets_len[14]); + /* + * longest of "Overwrite..." labels + * (assume "Target date..." are short enough) + */ + l1 = max (widgets_len[9], widgets_len[14]); - /* longest of button rows */ - i = num; - for (row = l = l2 = 0; i--;) - if (rd_widgets[i].value != 0) { - if (row != rd_widgets[i].ypos) { - row = rd_widgets[i].ypos; - l2 = max (l2, l); - l = 0; - } - l += widgets_len[i] + 4; - } + /* longest of button rows */ + i = num; + for (row = l = l2 = 0; i--;) + if (rd_widgets[i].value != 0) + { + if (row != rd_widgets[i].ypos) + { + row = rd_widgets[i].ypos; + l2 = max (l2, l); + l = 0; + } + l += widgets_len[i] + 4; + } - l2 = max (l2, l); /* last row */ - rd_xlen = max (rd_xlen, l1 + l2 + 8); - rd_xlen = max (rd_xlen, str_term_width1 (title) + 2); - rd_xlen = max (rd_xlen, min (COLS, stripped_name_len + 8)); + l2 = max (l2, l); /* last row */ + rd_xlen = max (rd_xlen, l1 + l2 + 8); + rd_xlen = max (rd_xlen, str_term_width1 (title) + 2); + rd_xlen = max (rd_xlen, min (COLS, stripped_name_len + 8)); - /* Now place widgets */ - l1 += 5; /* start of first button in the row */ - i = num; - for (l = l1, row = 0; --i > 1;) - if (rd_widgets[i].value != 0) { - if (row != rd_widgets[i].ypos) { - row = rd_widgets[i].ypos; - l = l1; - } - rd_widgets[i].xpos = l; - l += widgets_len[i] + 4; - } + /* Now place widgets */ + l1 += 5; /* start of first button in the row */ + i = num; + for (l = l1, row = 0; --i > 1;) + if (rd_widgets[i].value != 0) + { + if (row != rd_widgets[i].ypos) + { + row = rd_widgets[i].ypos; + l = l1; + } + rd_widgets[i].xpos = l; + l += widgets_len[i] + 4; + } - /* Abort button is centered */ - rd_widgets[4].xpos = (rd_xlen - widgets_len[4] - 3) / 2; + /* Abort button is centered */ + rd_widgets[4].xpos = (rd_xlen - widgets_len[4] - 3) / 2; } /* FIXME - missing help node */ ui->replace_dlg = - create_dlg (0, 0, rd_ylen, rd_xlen, alarm_colors, NULL, "[Replace]", - title, DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, rd_ylen, rd_xlen, alarm_colors, NULL, "[Replace]", + title, DLG_CENTER | DLG_REVERSE); /* prompt -- centered */ add_widget (ui->replace_dlg, - label_new (rd_widgets [0].ypos, - (rd_xlen - widgets_len [0]) / 2, - rd_widgets [0].text)); + label_new (rd_widgets[0].ypos, (rd_xlen - widgets_len[0]) / 2, rd_widgets[0].text)); /* file name -- centered */ stripped_name = str_trunc (stripped_name, rd_xlen - 8); stripped_name_len = str_term_width1 (stripped_name); add_widget (ui->replace_dlg, - label_new (rd_widgets [1].ypos, - (rd_xlen - stripped_name_len) / 2, - stripped_name)); + label_new (rd_widgets[1].ypos, (rd_xlen - stripped_name_len) / 2, stripped_name)); /* source date */ - ADD_RD_LABEL (2, file_date (ui->s_stat->st_mtime), - (off_t) ui->s_stat->st_size); + ADD_RD_LABEL (2, file_date (ui->s_stat->st_mtime), (off_t) ui->s_stat->st_size); /* destination date */ - ADD_RD_LABEL (3, file_date (ui->d_stat->st_mtime), - (off_t) ui->d_stat->st_size); + ADD_RD_LABEL (3, file_date (ui->d_stat->st_mtime), (off_t) ui->d_stat->st_size); - ADD_RD_BUTTON (4); /* Abort */ - ADD_RD_BUTTON (5); /* If size differs */ - ADD_RD_BUTTON (6); /* None */ - ADD_RD_BUTTON (7); /* Update */ - ADD_RD_BUTTON (8); /* All" */ - ADD_RD_LABEL (9, 0, 0); /* Overwrite all targets? */ + ADD_RD_BUTTON (4); /* Abort */ + ADD_RD_BUTTON (5); /* If size differs */ + ADD_RD_BUTTON (6); /* None */ + ADD_RD_BUTTON (7); /* Update */ + ADD_RD_BUTTON (8); /* All" */ + ADD_RD_LABEL (9, 0, 0); /* Overwrite all targets? */ /* "this target..." widgets */ - if (!S_ISDIR (ui->d_stat->st_mode)) { - if ((ctx->operation == OP_COPY) && (ui->d_stat->st_size != 0) - && (ui->s_stat->st_size > ui->d_stat->st_size)) - ADD_RD_BUTTON (10); /* Reget */ + if (!S_ISDIR (ui->d_stat->st_mode)) + { + if ((ctx->operation == OP_COPY) && (ui->d_stat->st_size != 0) + && (ui->s_stat->st_size > ui->d_stat->st_size)) + ADD_RD_BUTTON (10); /* Reget */ - ADD_RD_BUTTON (11); /* Append */ + ADD_RD_BUTTON (11); /* Append */ } - ADD_RD_BUTTON (12); /* No */ - ADD_RD_BUTTON (13); /* Yes */ - ADD_RD_LABEL (14, 0, 0); /* Overwrite this target? */ + ADD_RD_BUTTON (12); /* No */ + ADD_RD_BUTTON (13); /* Yes */ + ADD_RD_LABEL (14, 0, 0); /* Overwrite this target? */ result = run_dlg (ui->replace_dlg); destroy_dlg (ui->replace_dlg); @@ -786,10 +838,9 @@ overwrite_query_dialog (FileOpContext *ctx, enum OperationMode mode) } FileProgressStatus -file_progress_real_query_replace (FileOpContext *ctx, - enum OperationMode mode, const char *destname, - struct stat *_s_stat, - struct stat *_d_stat) +file_progress_real_query_replace (FileOpContext * ctx, + enum OperationMode mode, const char *destname, + struct stat * _s_stat, struct stat * _d_stat) { FileOpContextUI *ui; @@ -798,66 +849,69 @@ file_progress_real_query_replace (FileOpContext *ctx, ui = ctx->ui; - if (ui->replace_result < REPLACE_ALWAYS) { - ui->replace_filename = destname; - ui->s_stat = _s_stat; - ui->d_stat = _d_stat; - ui->replace_result = overwrite_query_dialog (ctx, mode); + if (ui->replace_result < REPLACE_ALWAYS) + { + ui->replace_filename = destname; + ui->s_stat = _s_stat; + ui->d_stat = _d_stat; + ui->replace_result = overwrite_query_dialog (ctx, mode); } - switch (ui->replace_result) { + switch (ui->replace_result) + { case REPLACE_UPDATE: - do_refresh (); - if (_s_stat->st_mtime > _d_stat->st_mtime) - return FILE_CONT; - else - return FILE_SKIP; + do_refresh (); + if (_s_stat->st_mtime > _d_stat->st_mtime) + return FILE_CONT; + else + return FILE_SKIP; case REPLACE_SIZE: - do_refresh (); - if (_s_stat->st_size == _d_stat->st_size) - return FILE_SKIP; - else - return FILE_CONT; + do_refresh (); + if (_s_stat->st_size == _d_stat->st_size) + return FILE_SKIP; + else + return FILE_CONT; case REPLACE_REGET: - /* Careful: we fall through and set do_append */ - ctx->do_reget = _d_stat->st_size; + /* Careful: we fall through and set do_append */ + ctx->do_reget = _d_stat->st_size; case REPLACE_APPEND: - ctx->do_append = TRUE; + ctx->do_append = TRUE; case REPLACE_YES: case REPLACE_ALWAYS: - do_refresh (); - return FILE_CONT; + do_refresh (); + return FILE_CONT; case REPLACE_NO: case REPLACE_NEVER: - do_refresh (); - return FILE_SKIP; + do_refresh (); + return FILE_SKIP; case REPLACE_ABORT: default: - return FILE_ABORT; + return FILE_ABORT; } } static gboolean is_wildcarded (char *p) { - for (; *p; p++) { - if (*p == '*') - return TRUE; - if (*p == '\\' && p[1] >= '1' && p[1] <= '9') - return TRUE; + for (; *p; p++) + { + if (*p == '*') + return TRUE; + if (*p == '\\' && p[1] >= '1' && p[1] <= '9') + return TRUE; } return FALSE; } char * -file_mask_dialog (FileOpContext *ctx, FileOperation operation, - gboolean only_one, - const char *format, const void *text, - const char *def_text, gboolean *do_background) +file_mask_dialog (FileOpContext * ctx, FileOperation operation, + gboolean only_one, + const char *format, const void *text, + const char *def_text, gboolean * do_background) { const size_t FMDY = 13; const size_t FMDX = 68; @@ -870,41 +924,42 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, int source_easy_patterns = easy_patterns; size_t i, len; - char fmd_buf [BUF_MEDIUM]; + char fmd_buf[BUF_MEDIUM]; char *source_mask, *orig_mask, *dest_dir, *tmp; char *def_text_secure; int val; - QuickWidget fmd_widgets[] = - { - /* 0 */ QUICK_BUTTON (42, 64, 10, FMDY, N_("&Cancel"), B_CANCEL, NULL), + QuickWidget fmd_widgets[] = { + /* 0 */ QUICK_BUTTON (42, 64, 10, FMDY, N_("&Cancel"), B_CANCEL, NULL), #ifdef WITH_BACKGROUND - /* 1 */ QUICK_BUTTON (25, 64, 10, FMDY, N_("&Background"), B_USER, NULL), + /* 1 */ QUICK_BUTTON (25, 64, 10, FMDY, N_("&Background"), B_USER, NULL), #define OFFSET 0 #else #define OFFSET 1 -#endif /* WITH_BACKGROUND */ - /* 2 - OFFSET */ - QUICK_BUTTON (14, FMDX, 10, FMDY, N_("&OK"), B_ENTER, NULL), - /* 3 - OFFSET */ - QUICK_CHECKBOX (42, FMDX, 8, FMDY, N_("&Stable Symlinks"), &ctx->stable_symlinks), - /* 4 - OFFSET */ - QUICK_CHECKBOX (31, FMDX, 7, FMDY, N_("di&Ve into subdir if exists"), &ctx->dive_into_subdirs), - /* 5 - OFFSET */ - QUICK_CHECKBOX (3, FMDX, 8, FMDY, N_("preserve &Attributes"), &ctx->op_preserve), - /* 6 - OFFSET */ - QUICK_CHECKBOX (3, FMDX, 7, FMDY, N_("follow &Links"), &ctx->follow_links), - /* 7 - OFFSET */ - QUICK_INPUT (3, FMDX, 6, FMDY, "", 58, 0, "input2", &dest_dir), - /* 8 - OFFSET */ - QUICK_LABEL (3, FMDX, 5, FMDY, N_("to:")), - /* 9 - OFFSET */ - QUICK_CHECKBOX (37, FMDX, 4, FMDY, N_("&Using shell patterns"), &source_easy_patterns), - /* 10 - OFFSET */ - QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^\\(.*\\)$", 58, 0, "input-def", &source_mask), - /* 11 - OFFSET */ - QUICK_LABEL (3, FMDX, 2, FMDY, fmd_buf), - QUICK_END +#endif /* WITH_BACKGROUND */ + /* 2 - OFFSET */ + QUICK_BUTTON (14, FMDX, 10, FMDY, N_("&OK"), B_ENTER, NULL), + /* 3 - OFFSET */ + QUICK_CHECKBOX (42, FMDX, 8, FMDY, N_("&Stable Symlinks"), &ctx->stable_symlinks), + /* 4 - OFFSET */ + QUICK_CHECKBOX (31, FMDX, 7, FMDY, N_("di&Ve into subdir if exists"), + &ctx->dive_into_subdirs), + /* 5 - OFFSET */ + QUICK_CHECKBOX (3, FMDX, 8, FMDY, N_("preserve &Attributes"), &ctx->op_preserve), + /* 6 - OFFSET */ + QUICK_CHECKBOX (3, FMDX, 7, FMDY, N_("follow &Links"), &ctx->follow_links), + /* 7 - OFFSET */ + QUICK_INPUT (3, FMDX, 6, FMDY, "", 58, 0, "input2", &dest_dir), + /* 8 - OFFSET */ + QUICK_LABEL (3, FMDX, 5, FMDY, N_("to:")), + /* 9 - OFFSET */ + QUICK_CHECKBOX (37, FMDX, 4, FMDY, N_("&Using shell patterns"), &source_easy_patterns), + /* 10 - OFFSET */ + QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^\\(.*\\)$", 58, 0, "input-def", + &source_mask), + /* 11 - OFFSET */ + QUICK_LABEL (3, FMDX, 2, FMDY, fmd_buf), + QUICK_END }; g_return_val_if_fail (ctx != NULL, NULL); @@ -912,49 +967,51 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, #ifdef ENABLE_NLS /* buttons */ for (i = 0; i <= 2 - OFFSET; i++) - fmd_widgets[i].u.button.text = _(fmd_widgets[i].u.button.text); + fmd_widgets[i].u.button.text = _(fmd_widgets[i].u.button.text); /* checkboxes */ for (i = 3 - OFFSET; i <= 9 - OFFSET; i++) - if (i != 7 - OFFSET) - fmd_widgets[i].u.checkbox.text = _(fmd_widgets[i].u.checkbox.text); -#endif /* !ENABLE_NLS */ + if (i != 7 - OFFSET) + fmd_widgets[i].u.checkbox.text = _(fmd_widgets[i].u.checkbox.text); +#endif /* !ENABLE_NLS */ - fmd_xlen = max (FMDX, (size_t) COLS * 2/3); + fmd_xlen = max (FMDX, (size_t) COLS * 2 / 3); len = str_term_width1 (fmd_widgets[6 - OFFSET].u.checkbox.text) - + str_term_width1 (fmd_widgets[4 - OFFSET].u.checkbox.text) + 15; + + str_term_width1 (fmd_widgets[4 - OFFSET].u.checkbox.text) + 15; fmd_xlen = max (fmd_xlen, len); len = str_term_width1 (fmd_widgets[5 - OFFSET].u.checkbox.text) - + str_term_width1 (fmd_widgets[3 - OFFSET].u.checkbox.text) + 15; + + str_term_width1 (fmd_widgets[3 - OFFSET].u.checkbox.text) + 15; fmd_xlen = max (fmd_xlen, len); /* buttons */ b2_len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) + 6 + gap; /* OK */ #ifdef WITH_BACKGROUND - b1_len = str_term_width1 (fmd_widgets[1].u.button.text) + 4 + gap; /* Background */ + b1_len = str_term_width1 (fmd_widgets[1].u.button.text) + 4 + gap; /* Background */ #endif - b0_len = str_term_width1 (fmd_widgets[0].u.button.text) + 4; /* Cancel */ + b0_len = str_term_width1 (fmd_widgets[0].u.button.text) + 4; /* Cancel */ len = b0_len + b1_len + b2_len; fmd_xlen = min (max (fmd_xlen, len + 6), (size_t) COLS); - if (only_one) { - int flen; + if (only_one) + { + int flen; - flen = str_term_width1 (format); - i = fmd_xlen - flen - 4; /* FIXME */ - g_snprintf (fmd_buf, sizeof (fmd_buf), - format, str_trunc ((const char *) text, i)); - } else { - g_snprintf (fmd_buf, sizeof (fmd_buf), format, *(const int *) text); - fmd_xlen = max (fmd_xlen, (size_t) str_term_width1 (fmd_buf) + 6); + flen = str_term_width1 (format); + i = fmd_xlen - flen - 4; /* FIXME */ + g_snprintf (fmd_buf, sizeof (fmd_buf), format, str_trunc ((const char *) text, i)); + } + else + { + g_snprintf (fmd_buf, sizeof (fmd_buf), format, *(const int *) text); + fmd_xlen = max (fmd_xlen, (size_t) str_term_width1 (fmd_buf) + 6); } - for (i = sizeof (fmd_widgets) / sizeof (fmd_widgets[0]); i > 0; ) - fmd_widgets[--i].x_divisions = fmd_xlen; + for (i = sizeof (fmd_widgets) / sizeof (fmd_widgets[0]); i > 0;) + fmd_widgets[--i].x_divisions = fmd_xlen; - i = (fmd_xlen - len)/2; + i = (fmd_xlen - len) / 2; /* OK button */ fmd_widgets[2 - OFFSET].relative_x = i; i += b2_len; @@ -974,8 +1031,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, #undef chkbox_xpos /* inputs */ - fmd_widgets[ 7 - OFFSET].u.input.len = - fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6; + fmd_widgets[7 - OFFSET].u.input.len = fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6; /* unselect checkbox if target filesystem don't support attributes */ ctx->op_preserve = filegui__check_attrs_on_fs (def_text); @@ -995,93 +1051,98 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, *do_background = FALSE; { - struct stat buf; + struct stat buf; - QuickDialog Quick_input = - { - fmd_xlen, FMDY, -1, -1, op_names [operation], - "[Mask Copy/Rename]", fmd_widgets, TRUE - }; + QuickDialog Quick_input = { + fmd_xlen, FMDY, -1, -1, op_names[operation], + "[Mask Copy/Rename]", fmd_widgets, TRUE + }; - ask_file_mask: - val = quick_dialog_skip (&Quick_input, 4); + ask_file_mask: + val = quick_dialog_skip (&Quick_input, 4); - if (val == B_CANCEL) { - g_free (def_text_secure); - return NULL; - } + if (val == B_CANCEL) + { + g_free (def_text_secure); + return NULL; + } - if (ctx->follow_links) - ctx->stat_func = mc_stat; - else - ctx->stat_func = mc_lstat; + if (ctx->follow_links) + ctx->stat_func = mc_stat; + else + ctx->stat_func = mc_lstat; - if (ctx->op_preserve) { - ctx->preserve = TRUE; - ctx->umask_kill = 0777777; - ctx->preserve_uidgid = (geteuid () == 0); - } else { - int i2; - ctx->preserve = ctx->preserve_uidgid = FALSE; - i2 = umask (0); - umask (i2); - ctx->umask_kill = i2 ^ 0777777; - } + if (ctx->op_preserve) + { + ctx->preserve = TRUE; + ctx->umask_kill = 0777777; + ctx->preserve_uidgid = (geteuid () == 0); + } + else + { + int i2; + ctx->preserve = ctx->preserve_uidgid = FALSE; + i2 = umask (0); + umask (i2); + ctx->umask_kill = i2 ^ 0777777; + } - if ((dest_dir == NULL) || (*dest_dir == '\0')) { - g_free (def_text_secure); - g_free (source_mask); - return dest_dir; - } + if ((dest_dir == NULL) || (*dest_dir == '\0')) + { + g_free (def_text_secure); + g_free (source_mask); + return dest_dir; + } - ctx->search_handle = mc_search_new(source_mask,-1); + ctx->search_handle = mc_search_new (source_mask, -1); - if (ctx->search_handle == NULL) { - message (D_ERROR, MSG_ERROR, _("Invalid source pattern `%s'"), - source_mask); - g_free (dest_dir); - g_free (source_mask); - goto ask_file_mask; - } + if (ctx->search_handle == NULL) + { + message (D_ERROR, MSG_ERROR, _("Invalid source pattern `%s'"), source_mask); + g_free (dest_dir); + g_free (source_mask); + goto ask_file_mask; + } - g_free (def_text_secure); - g_free (source_mask); + g_free (def_text_secure); + g_free (source_mask); - ctx->search_handle->is_case_sentitive = TRUE; - if (source_easy_patterns) - ctx->search_handle->search_type = MC_SEARCH_T_GLOB; - else - ctx->search_handle->search_type = MC_SEARCH_T_REGEX; + ctx->search_handle->is_case_sentitive = TRUE; + if (source_easy_patterns) + ctx->search_handle->search_type = MC_SEARCH_T_GLOB; + else + ctx->search_handle->search_type = MC_SEARCH_T_REGEX; - tmp = dest_dir; - dest_dir = tilde_expand (tmp); - g_free (tmp); + tmp = dest_dir; + dest_dir = tilde_expand (tmp); + g_free (tmp); - ctx->dest_mask = strrchr (dest_dir, PATH_SEP); - if (ctx->dest_mask == NULL) - ctx->dest_mask = dest_dir; - else - ctx->dest_mask++; - orig_mask = ctx->dest_mask; - if (!*ctx->dest_mask - || (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask) - && (!only_one - || (!mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode)))) - || (ctx->dive_into_subdirs - && ((!only_one && !is_wildcarded (ctx->dest_mask)) - || (only_one && !mc_stat (dest_dir, &buf) - && S_ISDIR (buf.st_mode))))) - ctx->dest_mask = g_strdup ("\\0"); - else { - ctx->dest_mask = g_strdup (ctx->dest_mask); - *orig_mask = '\0'; - } - if (!*dest_dir) { - g_free (dest_dir); - dest_dir = g_strdup ("./"); - } - if (val == B_USER) - *do_background = TRUE; + ctx->dest_mask = strrchr (dest_dir, PATH_SEP); + if (ctx->dest_mask == NULL) + ctx->dest_mask = dest_dir; + else + ctx->dest_mask++; + orig_mask = ctx->dest_mask; + if (!*ctx->dest_mask + || (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask) + && (!only_one + || (!mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode)))) + || (ctx->dive_into_subdirs + && ((!only_one && !is_wildcarded (ctx->dest_mask)) + || (only_one && !mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode))))) + ctx->dest_mask = g_strdup ("\\0"); + else + { + ctx->dest_mask = g_strdup (ctx->dest_mask); + *orig_mask = '\0'; + } + if (!*dest_dir) + { + g_free (dest_dir); + dest_dir = g_strdup ("./"); + } + if (val == B_USER) + *do_background = TRUE; } return dest_dir; diff --git a/src/fileopctx.c b/src/fileopctx.c index 1fdac2700..5356c77fe 100644 --- a/src/fileopctx.c +++ b/src/fileopctx.c @@ -4,7 +4,7 @@ Free Software Foundation, Inc. Authors: Federico Mena - Miguel de Icaza + Miguel de Icaza This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -75,14 +75,14 @@ file_op_context_new (FileOperation op) * it exists. */ void -file_op_context_destroy (FileOpContext *ctx) +file_op_context_destroy (FileOpContext * ctx) { g_return_if_fail (ctx != NULL); if (ctx->ui) - file_op_context_destroy_ui (ctx); + file_op_context_destroy_ui (ctx); - mc_search_free(ctx->search_handle); + mc_search_free (ctx->search_handle); /** \todo FIXME: do we need to free ctx->dest_mask? */ @@ -100,7 +100,7 @@ file_op_total_context_new (void) } void -file_op_total_context_destroy (FileOpTotalContext *tctx) +file_op_total_context_destroy (FileOpTotalContext * tctx) { g_return_if_fail (tctx != NULL); g_free (tctx); diff --git a/src/screen.c b/src/screen.c index 4a17af188..e158312c4 100644 --- a/src/screen.c +++ b/src/screen.c @@ -13,7 +13,7 @@ GNU General Public License for more details. Written by: 1995 Miguel de Icaza - 1997, 1999 Timur Bakeyev + 1997, 1999 Timur Bakeyev You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software @@ -36,8 +36,8 @@ #include "lib/tty/tty.h" #include "lib/skin.h" #include "lib/strescape.h" -#include "lib/tty/mouse.h" /* For Gpm_Event */ -#include "lib/tty/key.h" /* XCTRL and ALT macros */ +#include "lib/tty/mouse.h" /* For Gpm_Event */ +#include "lib/tty/key.h" /* XCTRL and ALT macros */ #include "lib/filehighlight.h" #include "lib/mcconfig.h" #include "lib/vfs/mc-vfs/vfs.h" @@ -47,23 +47,23 @@ #include "panel.h" #include "boxes.h" #include "tree.h" -#include "ext.h" /* regexp_command */ -#include "layout.h" /* Most layout variables are here */ -#include "wtools.h" /* for message (...) */ +#include "ext.h" /* regexp_command */ +#include "layout.h" /* Most layout variables are here */ +#include "wtools.h" /* for message (...) */ #include "cmd.h" -#include "command.h" /* cmdline */ -#include "setup.h" /* For loading/saving panel options */ +#include "command.h" /* cmdline */ +#include "setup.h" /* For loading/saving panel options */ #include "user.h" #include "execute.h" #include "widget.h" -#include "menu.h" /* menubar_visible */ +#include "menu.h" /* menubar_visible */ #include "main-widgets.h" #include "main.h" -#include "mountlist.h" /* my_statfs */ -#include "selcodepage.h" /* select_charset () */ -#include "charsets.h" /* get_codepage_id () */ -#include "cmddef.h" /* CK_ cmd name const */ -#include "keybind.h" /* global_keymap_t */ +#include "mountlist.h" /* my_statfs */ +#include "selcodepage.h" /* select_charset () */ +#include "charsets.h" /* get_codepage_id () */ +#include "cmddef.h" /* CK_ cmd name const */ +#include "keybind.h" /* global_keymap_t */ #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) ) @@ -77,15 +77,16 @@ * This describes a format item. The parse_display_format routine parses * the user specified format and creates a linked list of format_e structures. */ -typedef struct format_e { +typedef struct format_e +{ struct format_e *next; - int requested_field_len; - int field_len; + int requested_field_len; + int field_len; align_crt_t just_mode; - int expand; - const char *(*string_fn)(file_entry *, int len); - char *title; - const char *id; + int expand; + const char *(*string_fn) (file_entry *, int len); + char *title; + const char *id; } format_e; /* If true, show the mini-info on the panel */ @@ -112,10 +113,10 @@ Hook *select_file_hook = 0; const global_keymap_t *panel_map; static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm); -static int panel_event (Gpm_Event *event, void *); -static void paint_frame (WPanel *panel); -static const char *panel_format (WPanel *panel); -static const char *mini_status_format (WPanel *panel); +static int panel_event (Gpm_Event * event, void *); +static void paint_frame (WPanel * panel); +static const char *panel_format (WPanel * panel); +static const char *mini_status_format (WPanel * panel); static char *panel_sort_up_sign = NULL; static char *panel_sort_down_sign = NULL; @@ -130,7 +131,7 @@ static char *panel_history_show_list_sign = NULL; #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0)) static void -set_colors (WPanel *panel) +set_colors (WPanel * panel) { (void) panel; tty_set_normal_attrs (); @@ -139,95 +140,109 @@ set_colors (WPanel *panel) /* Delete format string, it is a linked list */ static void -delete_format (format_e *format) +delete_format (format_e * format) { - while (format != NULL) { + while (format != NULL) + { format_e *next = format->next; g_free (format->title); g_free (format); format = next; - } + } } /* This code relies on the default justification!!! */ static void -add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal) +add_permission_string (char *dest, int width, file_entry * fe, int attr, int color, int is_octal) { int i, r, l; l = get_user_permissions (&fe->st); - if (is_octal){ - /* Place of the access bit in octal mode */ + if (is_octal) + { + /* Place of the access bit in octal mode */ l = width + l - 3; - r = l + 1; - } else { - /* The same to the triplet in string mode */ + r = l + 1; + } + else + { + /* The same to the triplet in string mode */ l = l * 3 + 1; - r = l + 3; + r = l + 3; } - for(i = 0; i < width; i++){ - if (i >= l && i < r){ + for (i = 0; i < width; i++) + { + if (i >= l && i < r) + { if (attr == SELECTED || attr == MARKED_SELECTED) tty_setcolor (MARKED_SELECTED_COLOR); else tty_setcolor (MARKED_COLOR); - } else if (color >= 0) + } + else if (color >= 0) tty_setcolor (color); - else + else tty_lowlevel_setcolor (-color); - tty_print_char (dest[i]); + tty_print_char (dest[i]); } } /* String representations of various file attributes */ /* name */ static const char * -string_file_name (file_entry *fe, int len) +string_file_name (file_entry * fe, int len) { - static char buffer [MC_MAXPATHLEN * MB_LEN_MAX + 1]; + static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1]; (void) len; - g_strlcpy (buffer, fe->fname, sizeof(buffer)); + g_strlcpy (buffer, fe->fname, sizeof (buffer)); return buffer; } -static unsigned int ilog10(dev_t n) +static unsigned int +ilog10 (dev_t n) { unsigned int digits = 0; - do { - digits++, n /= 10; - } while (n != 0); + do + { + digits++, n /= 10; + } + while (n != 0); return digits; } -static void format_device_number (char *buf, size_t bufsize, dev_t dev) +static void +format_device_number (char *buf, size_t bufsize, dev_t dev) { - dev_t major_dev = major(dev); - dev_t minor_dev = minor(dev); - unsigned int major_digits = ilog10(major_dev); - unsigned int minor_digits = ilog10(minor_dev); + dev_t major_dev = major (dev); + dev_t minor_dev = minor (dev); + unsigned int major_digits = ilog10 (major_dev); + unsigned int minor_digits = ilog10 (minor_dev); - g_assert(bufsize >= 1); - if (major_digits + 1 + minor_digits + 1 <= bufsize) { - g_snprintf(buf, bufsize, "%lu,%lu", (unsigned long) major_dev, - (unsigned long) minor_dev); - } else { - g_strlcpy(buf, _("[dev]"), bufsize); + g_assert (bufsize >= 1); + if (major_digits + 1 + minor_digits + 1 <= bufsize) + { + g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev); + } + else + { + g_strlcpy (buf, _("[dev]"), bufsize); } } /* size */ static const char * -string_file_size (file_entry *fe, int len) +string_file_size (file_entry * fe, int len) { - static char buffer [BUF_TINY]; + static char buffer[BUF_TINY]; /* Don't ever show size of ".." since we don't calculate it */ - if (!strcmp (fe->fname, "..")) { - return _("UP--DIR"); + if (!strcmp (fe->fname, "..")) + { + return _("UP--DIR"); } #ifdef HAVE_STRUCT_STAT_ST_RDEV @@ -236,21 +251,23 @@ string_file_size (file_entry *fe, int len) else #endif { - size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0); + size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0); } return buffer; } /* bsize */ static const char * -string_file_size_brief (file_entry *fe, int len) +string_file_size_brief (file_entry * fe, int len) { - if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir) { - return _("SYMLINK"); + if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir) + { + return _("SYMLINK"); } - if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, "..")) { - return _("SUB-DIR"); + if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, "..")) + { + return _("SUB-DIR"); } return string_file_size (fe, len); @@ -259,45 +276,47 @@ string_file_size_brief (file_entry *fe, int len) /* This functions return a string representation of a file entry */ /* type */ static const char * -string_file_type (file_entry *fe, int len) +string_file_type (file_entry * fe, int len) { static char buffer[2]; (void) len; if (S_ISDIR (fe->st.st_mode)) - buffer[0] = PATH_SEP; - else if (S_ISLNK (fe->st.st_mode)) { - if (fe->f.link_to_dir) - buffer[0] = '~'; - else if (fe->f.stale_link) - buffer[0] = '!'; - else - buffer[0] = '@'; - } else if (S_ISCHR (fe->st.st_mode)) - buffer[0] = '-'; + buffer[0] = PATH_SEP; + else if (S_ISLNK (fe->st.st_mode)) + { + if (fe->f.link_to_dir) + buffer[0] = '~'; + else if (fe->f.stale_link) + buffer[0] = '!'; + else + buffer[0] = '@'; + } + else if (S_ISCHR (fe->st.st_mode)) + buffer[0] = '-'; else if (S_ISSOCK (fe->st.st_mode)) - buffer[0] = '='; + buffer[0] = '='; else if (S_ISDOOR (fe->st.st_mode)) - buffer[0] = '>'; + buffer[0] = '>'; else if (S_ISBLK (fe->st.st_mode)) - buffer[0] = '+'; + buffer[0] = '+'; else if (S_ISFIFO (fe->st.st_mode)) - buffer[0] = '|'; + buffer[0] = '|'; else if (S_ISNAM (fe->st.st_mode)) - buffer[0] = '#'; + buffer[0] = '#'; else if (!S_ISREG (fe->st.st_mode)) - buffer[0] = '?'; /* non-regular of unknown kind */ + buffer[0] = '?'; /* non-regular of unknown kind */ else if (is_exe (fe->st.st_mode)) - buffer[0] = '*'; + buffer[0] = '*'; else - buffer[0] = ' '; + buffer[0] = ' '; buffer[1] = '\0'; return buffer; } /* mtime */ static const char * -string_file_mtime (file_entry *fe, int len) +string_file_mtime (file_entry * fe, int len) { (void) len; return file_date (fe->st.st_mtime); @@ -305,7 +324,7 @@ string_file_mtime (file_entry *fe, int len) /* atime */ static const char * -string_file_atime (file_entry *fe, int len) +string_file_atime (file_entry * fe, int len) { (void) len; return file_date (fe->st.st_atime); @@ -313,7 +332,7 @@ string_file_atime (file_entry *fe, int len) /* ctime */ static const char * -string_file_ctime (file_entry *fe, int len) +string_file_ctime (file_entry * fe, int len) { (void) len; return file_date (fe->st.st_ctime); @@ -321,7 +340,7 @@ string_file_ctime (file_entry *fe, int len) /* perm */ static const char * -string_file_permission (file_entry *fe, int len) +string_file_permission (file_entry * fe, int len) { (void) len; return string_perm (fe->st.st_mode); @@ -329,9 +348,9 @@ string_file_permission (file_entry *fe, int len) /* mode */ static const char * -string_file_perm_octal (file_entry *fe, int len) +string_file_perm_octal (file_entry * fe, int len) { - static char buffer [10]; + static char buffer[10]; (void) len; g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode); @@ -340,7 +359,7 @@ string_file_perm_octal (file_entry *fe, int len) /* nlink */ static const char * -string_file_nlinks (file_entry *fe, int len) +string_file_nlinks (file_entry * fe, int len) { static char buffer[BUF_TINY]; @@ -351,43 +370,40 @@ string_file_nlinks (file_entry *fe, int len) /* inode */ static const char * -string_inode (file_entry *fe, int len) +string_inode (file_entry * fe, int len) { - static char buffer [10]; + static char buffer[10]; (void) len; - g_snprintf (buffer, sizeof (buffer), "%lu", - (unsigned long) fe->st.st_ino); + g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino); return buffer; } /* nuid */ static const char * -string_file_nuid (file_entry *fe, int len) +string_file_nuid (file_entry * fe, int len) { - static char buffer [10]; + static char buffer[10]; (void) len; - g_snprintf (buffer, sizeof (buffer), "%lu", - (unsigned long) fe->st.st_uid); + g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid); return buffer; } /* ngid */ static const char * -string_file_ngid (file_entry *fe, int len) +string_file_ngid (file_entry * fe, int len) { - static char buffer [10]; + static char buffer[10]; (void) len; - g_snprintf (buffer, sizeof (buffer), "%lu", - (unsigned long) fe->st.st_gid); + g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid); return buffer; } /* owner */ static const char * -string_file_owner (file_entry *fe, int len) +string_file_owner (file_entry * fe, int len) { (void) len; return get_owner (fe->st.st_uid); @@ -395,7 +411,7 @@ string_file_owner (file_entry *fe, int len) /* group */ static const char * -string_file_group (file_entry *fe, int len) +string_file_group (file_entry * fe, int len) { (void) len; return get_group (fe->st.st_gid); @@ -403,7 +419,7 @@ string_file_group (file_entry *fe, int len) /* mark */ static const char * -string_marked (file_entry *fe, int len) +string_marked (file_entry * fe, int len) { (void) len; return fe->f.marked ? "*" : " "; @@ -411,7 +427,7 @@ string_marked (file_entry *fe, int len) /* space */ static const char * -string_space (file_entry *fe, int len) +string_space (file_entry * fe, int len) { (void) fe; (void) len; @@ -420,7 +436,7 @@ string_space (file_entry *fe, int len) /* dot */ static const char * -string_dot (file_entry *fe, int len) +string_dot (file_entry * fe, int len) { (void) fe; (void) len; @@ -429,199 +445,224 @@ string_dot (file_entry *fe, int len) #define GT 1 -panel_field_t panel_fields [] = { +/* *INDENT-OFF* */ +panel_field_t panel_fields[] = { { - "unsorted", 12, 1, J_LEFT_FIT, - /* TRANSLATORS: one single character to represent 'unsorted' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|u"), - N_("&Unsorted"), TRUE, FALSE, - string_file_name, - (sortfn *) unsorted - }, + "unsorted", 12, 1, J_LEFT_FIT, + /* TRANSLATORS: one single character to represent 'unsorted' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|u"), + N_("&Unsorted"), TRUE, FALSE, + string_file_name, + (sortfn *) unsorted + } + , { - "name", 12, 1, J_LEFT_FIT, - /* TRANSLATORS: one single character to represent 'name' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|n"), - N_("&Name"), TRUE, TRUE, - string_file_name, - (sortfn *) sort_name - }, + "name", 12, 1, J_LEFT_FIT, + /* TRANSLATORS: one single character to represent 'name' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|n"), + N_("&Name"), TRUE, TRUE, + string_file_name, + (sortfn *) sort_name + } + , { - "version", 12, 1, J_LEFT_FIT, - /* TRANSLATORS: one single character to represent 'version' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|v"), - N_("&Version"), TRUE, FALSE, - string_file_name, - (sortfn *) sort_vers - }, + "version", 12, 1, J_LEFT_FIT, + /* TRANSLATORS: one single character to represent 'version' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|v"), + N_("&Version"), TRUE, FALSE, + string_file_name, + (sortfn *) sort_vers + } + , { - "extension", 12, 1, J_LEFT_FIT, - /* TRANSLATORS: one single character to represent 'extension' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|e"), - N_("&Extension"), TRUE, FALSE, - string_file_name, /* TODO: string_file_ext*/ - (sortfn *) sort_ext - }, + "extension", 12, 1, J_LEFT_FIT, + /* TRANSLATORS: one single character to represent 'extension' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|e"), + N_("&Extension"), TRUE, FALSE, + string_file_name, /* TODO: string_file_ext */ + (sortfn *) sort_ext + } + , { - "size", 7, 0, J_RIGHT, - /* TRANSLATORS: one single character to represent 'size' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|s"), - N_("&Size"), TRUE,TRUE, - string_file_size, - (sortfn *) sort_size - }, + "size", 7, 0, J_RIGHT, + /* TRANSLATORS: one single character to represent 'size' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|s"), + N_("&Size"), TRUE, TRUE, + string_file_size, + (sortfn *) sort_size + } + , { - "bsize", 7, 0, J_RIGHT, - "", - N_("Block Size"), FALSE, FALSE, - string_file_size_brief, - (sortfn *) sort_size - }, + "bsize", 7, 0, J_RIGHT, + "", + N_("Block Size"), FALSE, FALSE, + string_file_size_brief, + (sortfn *) sort_size + } + , { - "type", GT, 0, J_LEFT, - "", - "", FALSE, TRUE, - string_file_type, - NULL - }, + "type", GT, 0, J_LEFT, + "", + "", FALSE, TRUE, + string_file_type, + NULL + } + , { - "mtime", 12, 0, J_RIGHT, - /* TRANSLATORS: one single character to represent 'Modify time' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|m"), - N_("&Modify time"), TRUE,TRUE, - string_file_mtime, - (sortfn *) sort_time - }, + "mtime", 12, 0, J_RIGHT, + /* TRANSLATORS: one single character to represent 'Modify time' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|m"), + N_("&Modify time"), TRUE, TRUE, + string_file_mtime, + (sortfn *) sort_time + } + , { - "atime", 12, 0, J_RIGHT, - /* TRANSLATORS: one single character to represent 'Access time' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|a"), - N_("&Access time"), TRUE,TRUE, - string_file_atime, - (sortfn *) sort_atime - }, + "atime", 12, 0, J_RIGHT, + /* TRANSLATORS: one single character to represent 'Access time' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|a"), + N_("&Access time"), TRUE, TRUE, + string_file_atime, + (sortfn *) sort_atime + } + , { - "ctime", 12, 0, J_RIGHT, - /* TRANSLATORS: one single character to represent 'Change time' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|h"), - N_("C&Hange time"), TRUE,TRUE, - string_file_ctime, - (sortfn *) sort_ctime - }, + "ctime", 12, 0, J_RIGHT, + /* TRANSLATORS: one single character to represent 'Change time' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|h"), + N_("C&Hange time"), TRUE, TRUE, + string_file_ctime, + (sortfn *) sort_ctime + } + , { - "perm", 10, 0, J_LEFT, - "", - N_("Permission"), FALSE,TRUE, - string_file_permission, - NULL - }, + "perm", 10, 0, J_LEFT, + "", + N_("Permission"), FALSE, TRUE, + string_file_permission, + NULL + } + , { - "mode", 6, 0, J_RIGHT, - "", - N_("Perm"), FALSE,TRUE, - string_file_perm_octal, - NULL - }, + "mode", 6, 0, J_RIGHT, + "", + N_("Perm"), FALSE, TRUE, + string_file_perm_octal, + NULL + } + , { - "nlink", 2, 0, J_RIGHT, - "", - N_("Nl"), FALSE,TRUE, - string_file_nlinks, NULL - }, + "nlink", 2, 0, J_RIGHT, + "", + N_("Nl"), FALSE, TRUE, + string_file_nlinks, NULL + } + , { - "inode", 5, 0, J_RIGHT, - /* TRANSLATORS: one single character to represent 'inode' sort mode */ - /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ - N_("sort|i"), - N_("&Inode"), TRUE,TRUE, - string_inode, - (sortfn *) sort_inode - }, + "inode", 5, 0, J_RIGHT, + /* TRANSLATORS: one single character to represent 'inode' sort mode */ + /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */ + N_("sort|i"), + N_("&Inode"), TRUE, TRUE, + string_inode, + (sortfn *) sort_inode + } + , { - "nuid", 5, 0, J_RIGHT, - "", - N_("UID"), FALSE,FALSE, - string_file_nuid, - NULL - }, + "nuid", 5, 0, J_RIGHT, + "", + N_("UID"), FALSE, FALSE, + string_file_nuid, + NULL + } + , { - "ngid", 5, 0, J_RIGHT, - "", - N_("GID"), FALSE,FALSE, - string_file_ngid, - NULL - }, + "ngid", 5, 0, J_RIGHT, + "", + N_("GID"), FALSE, FALSE, + string_file_ngid, + NULL + } + , { - "owner", 8, 0, J_LEFT_FIT, - "", - N_("Owner"), FALSE,TRUE, - string_file_owner, - NULL - }, + "owner", 8, 0, J_LEFT_FIT, + "", + N_("Owner"), FALSE, TRUE, + string_file_owner, + NULL + } + , { - "group", 8,0, J_LEFT_FIT, - "", - N_("Group"), FALSE,TRUE, - string_file_group, - NULL - }, + "group", 8, 0, J_LEFT_FIT, + "", + N_("Group"), FALSE, TRUE, + string_file_group, + NULL + } + , { - "mark", 1, 0, J_RIGHT, - "", - " ", FALSE,TRUE, - string_marked, - NULL - }, + "mark", 1, 0, J_RIGHT, + "", + " ", FALSE, TRUE, + string_marked, + NULL + } + , { - "|", 1, 0, J_RIGHT, - "", - " ", FALSE,TRUE, - NULL, - NULL - }, + "|", 1, 0, J_RIGHT, + "", + " ", FALSE, TRUE, + NULL, + NULL + } + , { - "space", 1, 0, J_RIGHT, - "", - " ", FALSE,TRUE, - string_space, - NULL - }, + "space", 1, 0, J_RIGHT, + "", + " ", FALSE, TRUE, + string_space, + NULL + } + , { - "dot", 1, 0, J_RIGHT, - "", - " ", FALSE,FALSE, - string_dot, - NULL - }, + "dot", 1, 0, J_RIGHT, + "", + " ", FALSE, FALSE, + string_dot, + NULL + } + , { - NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL - }, + NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL + } }; +/* *INDENT-ON* */ static int -file_compute_color (int attr, file_entry *fe) +file_compute_color (int attr, file_entry * fe) { - switch (attr) { + switch (attr) + { case SELECTED: - return (SELECTED_COLOR); + return (SELECTED_COLOR); case MARKED: - return (MARKED_COLOR); + return (MARKED_COLOR); case MARKED_SELECTED: - return (MARKED_SELECTED_COLOR); + return (MARKED_SELECTED_COLOR); case STATUS: - return (NORMAL_COLOR); + return (NORMAL_COLOR); case NORMAL: default: - if (!filetype_mode) - return (NORMAL_COLOR); + if (!filetype_mode) + return (NORMAL_COLOR); } return mc_fhl_get_color (mc_filehighlight, fe); @@ -629,201 +670,217 @@ file_compute_color (int attr, file_entry *fe) /* Formats the file number file_index of panel in the buffer dest */ static void -format_file (char *dest, int limit, WPanel *panel, int file_index, int width, int attr, int isstatus) +format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr, + int isstatus) { - int color, length, empty_line; + int color, length, empty_line; const char *txt; format_e *format, *home; file_entry *fe; (void) dest; (void) limit; - length = 0; + length = 0; empty_line = (file_index >= panel->count); - home = (isstatus) ? panel->status_format : panel->format; - fe = &panel->dir.list [file_index]; + home = (isstatus) ? panel->status_format : panel->format; + fe = &panel->dir.list[file_index]; if (!empty_line) - color = file_compute_color (attr, fe); + color = file_compute_color (attr, fe); else - color = NORMAL_COLOR; + color = NORMAL_COLOR; - for (format = home; format; format = format->next){ - if (length == width) - break; + for (format = home; format; format = format->next) + { + if (length == width) + break; - if (format->string_fn){ + if (format->string_fn) + { int len, perm; char *preperad_text; - if (empty_line) - txt = " "; - else - txt = (*format->string_fn)(fe, format->field_len); + if (empty_line) + txt = " "; + else + txt = (*format->string_fn) (fe, format->field_len); - len = format->field_len; - if (len + length > width) - len = width - length; - if (len <= 0) - break; + len = format->field_len; + if (len + length > width) + len = width - length; + if (len <= 0) + break; perm = 0; - if (permission_mode) { - if (!strcmp(format->id, "perm")) + if (permission_mode) + { + if (!strcmp (format->id, "perm")) perm = 1; - else if (!strcmp(format->id, "mode")) + else if (!strcmp (format->id, "mode")) perm = 2; } - if (color >= 0) - tty_setcolor (color); - else - tty_lowlevel_setcolor (-color); + if (color >= 0) + tty_setcolor (color); + else + tty_lowlevel_setcolor (-color); - preperad_text = (char*) str_fit_to_term(txt, len, format->just_mode); + preperad_text = (char *) str_fit_to_term (txt, len, format->just_mode); if (perm) - add_permission_string (preperad_text, format->field_len, fe, - attr, color, perm - 1); + add_permission_string (preperad_text, format->field_len, fe, attr, color, perm - 1); else tty_print_string (preperad_text); - length+= len; - } else { + length += len; + } + else + { if (attr == SELECTED || attr == MARKED_SELECTED) tty_setcolor (SELECTED_COLOR); else tty_setcolor (NORMAL_COLOR); - tty_print_one_vline (); - length++; - } + tty_print_one_vline (); + length++; + } } if (length < width) - tty_draw_hline (-1, -1, ' ', width - length); + tty_draw_hline (-1, -1, ' ', width - length); } static void -repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus) +repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) { int second_column = 0; int width; int offset = 0; - char buffer [BUF_MEDIUM]; + char buffer[BUF_MEDIUM]; gboolean panel_is_split = !isstatus && panel->split; width = panel->widget.cols - 2; - if (panel_is_split) { - second_column = (file_index - panel->top_file) / llines (panel); - width = width/2 - 1; + if (panel_is_split) + { + second_column = (file_index - panel->top_file) / llines (panel); + width = width / 2 - 1; - if (second_column != 0) { - offset = 1 + width; - /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/ - width = panel->widget.cols - offset - 2; - } + if (second_column != 0) + { + offset = 1 + width; + /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */ + width = panel->widget.cols - offset - 2; + } } /* Nothing to paint */ if (width <= 0) - return; + return; - if (mv){ - if (panel_is_split) - widget_move (&panel->widget, - (file_index - panel->top_file) % llines (panel) + 2, - offset + 1); - else - widget_move (&panel->widget, file_index - panel->top_file + 2, 1); + if (mv) + { + if (panel_is_split) + widget_move (&panel->widget, + (file_index - panel->top_file) % llines (panel) + 2, offset + 1); + else + widget_move (&panel->widget, file_index - panel->top_file + 2, 1); } - format_file (buffer, sizeof(buffer), panel, file_index, width, attr, isstatus); + format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus); - if (panel_is_split) { - if (second_column) - tty_print_char (' '); - else { - tty_setcolor (NORMAL_COLOR); - tty_print_one_vline (); - } + if (panel_is_split) + { + if (second_column) + tty_print_char (' '); + else + { + tty_setcolor (NORMAL_COLOR); + tty_print_one_vline (); + } } } static void -display_mini_info (WPanel *panel) +display_mini_info (WPanel * panel) { if (!show_mini_info) - return; + return; widget_move (&panel->widget, llines (panel) + 3, 1); - if (panel->searching) { - tty_setcolor (INPUT_COLOR); - tty_print_char ('/'); - tty_print_string (str_fit_to_term (panel->search_buffer, - panel->widget.cols - 3, J_LEFT)); - return; + if (panel->searching) + { + tty_setcolor (INPUT_COLOR); + tty_print_char ('/'); + tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT)); + return; } /* Status resolves links and show them */ set_colors (panel); - if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)){ - char *lc_link, link_target [MC_MAXPATHLEN]; - int len; + if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode)) + { + char *lc_link, link_target[MC_MAXPATHLEN]; + int len; - lc_link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname); - len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1); - g_free (lc_link); - if (len > 0){ - link_target[len] = 0; + lc_link = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname); + len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1); + g_free (lc_link); + if (len > 0) + { + link_target[len] = 0; tty_print_string ("-> "); - tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, - J_LEFT_FIT)); - } else + tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT)); + } + else tty_print_string (str_fit_to_term (_(""), - panel->widget.cols - 2, J_LEFT)); - } else if (strcmp (panel->dir.list [panel->selected].fname, "..") == 0) { - /* FIXME: - * while loading directory (do_load_dir() and do_reload_dir()), - * the actual stat info about ".." directory isn't got; - * so just don't display incorrect info about ".." directory */ - tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT)); - } else - /* Default behavior */ - repaint_file (panel, panel->selected, 0, STATUS, 1); + panel->widget.cols - 2, J_LEFT)); + } + else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0) + { + /* FIXME: + * while loading directory (do_load_dir() and do_reload_dir()), + * the actual stat info about ".." directory isn't got; + * so just don't display incorrect info about ".." directory */ + tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT)); + } + else + /* Default behavior */ + repaint_file (panel, panel->selected, 0, STATUS, 1); } static void -paint_dir (WPanel *panel) +paint_dir (WPanel * panel) { int i; - int color; /* Color value of the line */ - int items; /* Number of items */ + int color; /* Color value of the line */ + int items; /* Number of items */ items = llines (panel) * (panel->split ? 2 : 1); - for (i = 0; i < items; i++){ - if (i+panel->top_file >= panel->count) - color = 0; - else { - color = 2 * (panel->dir.list [i+panel->top_file].f.marked); - color += (panel->selected==i+panel->top_file && panel->active); - } - repaint_file (panel, i+panel->top_file, 1, color, 0); + for (i = 0; i < items; i++) + { + if (i + panel->top_file >= panel->count) + color = 0; + else + { + color = 2 * (panel->dir.list[i + panel->top_file].f.marked); + color += (panel->selected == i + panel->top_file && panel->active); + } + repaint_file (panel, i + panel->top_file, 1, color, 0); } tty_set_normal_attrs (); } static void -display_total_marked_size (WPanel *panel, int y, int x, gboolean size_only) +display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only) { char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf; int cols; if (panel->marked <= 0) - return; + return; buf = size_only ? b_bytes : buffer; cols = panel->widget.cols - 2; @@ -833,19 +890,19 @@ display_total_marked_size (WPanel *panel, int y, int x, gboolean size_only) * First make "N bytes", then insert it into "X in M files". */ g_snprintf (b_bytes, sizeof (b_bytes), - ngettext("%s byte", "%s bytes", (unsigned long) panel->total), - size_trunc_sep (panel->total)); + ngettext ("%s byte", "%s bytes", (unsigned long) panel->total), + size_trunc_sep (panel->total)); if (!size_only) g_snprintf (buffer, sizeof (buffer), - ngettext("%s in %d file", "%s in %d files", panel->marked), - b_bytes, panel->marked); + ngettext ("%s in %d file", "%s in %d files", panel->marked), + b_bytes, panel->marked); /* don't forget spaces around buffer content */ buf = (char *) str_trunc (buf, cols - 4); if (x < 0) - /* center in panel */ - x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1; + /* center in panel */ + x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1; /* * y == llines (panel) + 2 for mini_info_separator @@ -857,22 +914,23 @@ display_total_marked_size (WPanel *panel, int y, int x, gboolean size_only) } static void -mini_info_separator (WPanel *panel) +mini_info_separator (WPanel * panel) { - if (show_mini_info) { - const int y = llines (panel) + 2; + if (show_mini_info) + { + const int y = llines (panel) + 2; - tty_setcolor (NORMAL_COLOR); - tty_draw_hline (panel->widget.y + y, panel->widget.x + 1, - ACS_HLINE, panel->widget.cols - 2); - /* Status displays total marked size. - * Centered in panel, full format. */ - display_total_marked_size (panel, y, -1, FALSE); + tty_setcolor (NORMAL_COLOR); + tty_draw_hline (panel->widget.y + y, panel->widget.x + 1, + ACS_HLINE, panel->widget.cols - 2); + /* Status displays total marked size. + * Centered in panel, full format. */ + display_total_marked_size (panel, y, -1, FALSE); } } static void -show_free_space (WPanel *panel) +show_free_space (WPanel * panel) { /* Used to figure out how many free space we have */ static struct my_statfs myfs_stats; @@ -881,115 +939,122 @@ show_free_space (WPanel *panel) /* Don't try to stat non-local fs */ if (!vfs_file_is_local (panel->cwd) || !free_space) - return; + return; - if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0) { - char rpath[PATH_MAX]; + if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0) + { + char rpath[PATH_MAX]; - init_my_statfs (); - g_free (old_cwd); - old_cwd = g_strdup (panel->cwd); + init_my_statfs (); + g_free (old_cwd); + old_cwd = g_strdup (panel->cwd); - if (mc_realpath (panel->cwd, rpath) == NULL) - return; + if (mc_realpath (panel->cwd, rpath) == NULL) + return; - my_statfs (&myfs_stats, rpath); + my_statfs (&myfs_stats, rpath); } - if (myfs_stats.avail > 0 || myfs_stats.total > 0) { - char buffer1[6], buffer2[6], tmp[BUF_SMALL]; - size_trunc_len (buffer1, sizeof(buffer1) - 1, myfs_stats.avail, 1); - size_trunc_len (buffer2, sizeof(buffer2) - 1, myfs_stats.total, 1); - g_snprintf (tmp, sizeof(tmp), " %s/%s (%d%%) ", buffer1, buffer2, - myfs_stats.total > 0 ? - (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0); - widget_move (&panel->widget, panel->widget.lines - 1, - panel->widget.cols - 2 - (int) strlen (tmp)); - tty_setcolor (NORMAL_COLOR); - tty_print_string (tmp); + if (myfs_stats.avail > 0 || myfs_stats.total > 0) + { + char buffer1[6], buffer2[6], tmp[BUF_SMALL]; + size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1); + size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1); + g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2, + myfs_stats.total > 0 ? + (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0); + widget_move (&panel->widget, panel->widget.lines - 1, + panel->widget.cols - 2 - (int) strlen (tmp)); + tty_setcolor (NORMAL_COLOR); + tty_print_string (tmp); } } static void -show_dir (WPanel *panel) +show_dir (WPanel * panel) { gchar *tmp; set_colors (panel); draw_box (panel->widget.parent, - panel->widget.y, panel->widget.x, - panel->widget.lines, panel->widget.cols); + panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols); - if (show_mini_info) { - widget_move (&panel->widget, llines (panel) + 2, 0); - tty_print_alt_char (ACS_LTEE); - widget_move (&panel->widget, llines (panel) + 2, - panel->widget.cols - 1); - tty_print_alt_char (ACS_RTEE); + if (show_mini_info) + { + widget_move (&panel->widget, llines (panel) + 2, 0); + tty_print_alt_char (ACS_LTEE); + widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1); + tty_print_alt_char (ACS_RTEE); } widget_move (&panel->widget, 0, 1); tty_print_string (panel_history_prev_item_sign); tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide; - tmp = g_strdup_printf("%s[%s]%s",tmp,panel_history_show_list_sign,panel_history_next_item_sign); + tmp = + g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign, + panel_history_next_item_sign); widget_move (&panel->widget, 0, panel->widget.cols - 6); tty_print_string (tmp); - g_free(tmp); + g_free (tmp); if (panel->active) - tty_setcolor (REVERSE_COLOR); + tty_setcolor (REVERSE_COLOR); widget_move (&panel->widget, 0, 3); tty_printf (" %s ", - str_term_trim (strip_home_and_password (panel->cwd), - min (max (panel->widget.cols - 12, 0), - panel->widget.cols))); + str_term_trim (strip_home_and_password (panel->cwd), + min (max (panel->widget.cols - 12, 0), panel->widget.cols))); - if (!show_mini_info) { - if (panel->marked == 0) { - /* Show size of curret file in the bottom of panel */ - if (S_ISREG (panel->dir.list [panel->selected].st.st_mode)) { - char buffer[BUF_SMALL]; + if (!show_mini_info) + { + if (panel->marked == 0) + { + /* Show size of curret file in the bottom of panel */ + if (S_ISREG (panel->dir.list[panel->selected].st.st_mode)) + { + char buffer[BUF_SMALL]; - g_snprintf (buffer, sizeof (buffer), " %s ", - size_trunc_sep (panel->dir.list [panel->selected].st.st_size)); - tty_setcolor (NORMAL_COLOR); - widget_move (&panel->widget, panel->widget.lines - 1, 4); - tty_print_string (buffer); - } - } else { - /* Show total size of marked files - * In the bottom of panel, display size only. */ - display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE); - } + g_snprintf (buffer, sizeof (buffer), " %s ", + size_trunc_sep (panel->dir.list[panel->selected].st.st_size)); + tty_setcolor (NORMAL_COLOR); + widget_move (&panel->widget, panel->widget.lines - 1, 4); + tty_print_string (buffer); + } + } + else + { + /* Show total size of marked files + * In the bottom of panel, display size only. */ + display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE); + } } show_free_space (panel); if (panel->active) - tty_set_normal_attrs (); + tty_set_normal_attrs (); } /* To be used only by long_frame and full_frame to adjust top_file */ static void -adjust_top_file (WPanel *panel) +adjust_top_file (WPanel * panel) { int old_top = panel->top_file; if (panel->selected - old_top > llines (panel)) - panel->top_file = panel->selected; + panel->top_file = panel->selected; if (old_top - panel->count > llines (panel)) - panel->top_file = panel->count - llines (panel); + panel->top_file = panel->count - llines (panel); } /* Repaint everything, including frame and separator */ static void -paint_panel (WPanel *panel) +paint_panel (WPanel * panel) { - paint_frame (panel); /* including show_dir */ + paint_frame (panel); /* including show_dir */ paint_dir (panel); mini_info_separator (panel); display_mini_info (panel); @@ -1001,8 +1066,8 @@ paint_panel (WPanel *panel) * #enc: is appended * retun new string */ -static char -*add_encoding_to_path (const char *path, const char *encoding) +static char * +add_encoding_to_path (const char *path, const char *encoding) { char *result; char *semi; @@ -1010,16 +1075,22 @@ static char semi = g_strrstr (path, "#enc:"); - if (semi != NULL) { + if (semi != NULL) + { slash = strchr (semi, PATH_SEP); - if (slash != NULL) { + if (slash != NULL) + { result = g_strconcat (path, "/#enc:", encoding, (char *) NULL); - } else { + } + else + { *semi = 0; result = g_strconcat (path, "/#enc:", encoding, (char *) NULL); *semi = '#'; } - } else { + } + else + { result = g_strconcat (path, "/#enc:", encoding, (char *) NULL); } @@ -1035,34 +1106,37 @@ remove_encoding_from_path (const char *path) const char *enc; GIConv converter; - ret = g_string_new(""); - tmp_conv = g_string_new(""); + ret = g_string_new (""); + tmp_conv = g_string_new (""); - tmp_path = g_string_new(path); + tmp_path = g_string_new (path); - while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL){ - enc = vfs_get_encoding ((const char *) tmp); - converter = enc ? str_crt_conv_to (enc): str_cnv_to_term; - if (converter == INVALID_CONV) converter = str_cnv_to_term; + while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL) + { + enc = vfs_get_encoding ((const char *) tmp); + converter = enc ? str_crt_conv_to (enc) : str_cnv_to_term; + if (converter == INVALID_CONV) + converter = str_cnv_to_term; - tmp2=tmp+1; - while (*tmp2 && *tmp2 != '/') - tmp2++; + tmp2 = tmp + 1; + while (*tmp2 && *tmp2 != '/') + tmp2++; - if (*tmp2){ - str_vfs_convert_from (converter, tmp2, tmp_conv); - g_string_prepend(ret, tmp_conv->str); - g_string_set_size(tmp_conv,0); - } - g_string_set_size(tmp_path,tmp - tmp_path->str); - str_close_conv (converter); + if (*tmp2) + { + str_vfs_convert_from (converter, tmp2, tmp_conv); + g_string_prepend (ret, tmp_conv->str); + g_string_set_size (tmp_conv, 0); + } + g_string_set_size (tmp_path, tmp - tmp_path->str); + str_close_conv (converter); } - g_string_prepend(ret, tmp_path->str); - g_string_free(tmp_path,TRUE); - g_string_free(tmp_conv,TRUE); + g_string_prepend (ret, tmp_path->str); + g_string_free (tmp_path, TRUE); + g_string_free (tmp_conv, TRUE); tmp = ret->str; - g_string_free(ret, FALSE); + g_string_free (ret, FALSE); return tmp; } @@ -1076,82 +1150,93 @@ void update_dirty_panels (void) { if (current_panel->dirty) - paint_panel (current_panel); + paint_panel (current_panel); if ((get_other_type () == view_listing) && other_panel->dirty) - paint_panel (other_panel); + paint_panel (other_panel); } static void -do_select (WPanel *panel, int i) +do_select (WPanel * panel, int i) { - if (i != panel->selected) { - panel->dirty = 1; - panel->selected = i; - panel->top_file = panel->selected - (panel->widget.lines - 2) / 2; - if (panel->top_file < 0) - panel->top_file = 0; + if (i != panel->selected) + { + panel->dirty = 1; + panel->selected = i; + panel->top_file = panel->selected - (panel->widget.lines - 2) / 2; + if (panel->top_file < 0) + panel->top_file = 0; } } static void -do_try_to_select (WPanel *panel, const char *name) +do_try_to_select (WPanel * panel, const char *name) { int i; char *subdir; - if (!name) { - do_select(panel, 0); - return; + if (!name) + { + do_select (panel, 0); + return; } /* We only want the last component of the directory, * and from this only the name without suffix. */ - subdir = vfs_strip_suffix_from_filename (x_basename(name)); + subdir = vfs_strip_suffix_from_filename (x_basename (name)); /* Search that subdirectory, if found select it */ - for (i = 0; i < panel->count; i++){ - if (strcmp (subdir, panel->dir.list [i].fname) == 0) { - do_select (panel, i); + for (i = 0; i < panel->count; i++) + { + if (strcmp (subdir, panel->dir.list[i].fname) == 0) + { + do_select (panel, i); g_free (subdir); - return; + return; } } /* Try to select a file near the file that is missing */ if (panel->selected >= panel->count) - do_select (panel, panel->count-1); + do_select (panel, panel->count - 1); g_free (subdir); } void -try_to_select (WPanel *panel, const char *name) +try_to_select (WPanel * panel, const char *name) { do_try_to_select (panel, name); select_item (panel); } void -panel_update_cols (Widget *widget, int frame_size) +panel_update_cols (Widget * widget, int frame_size) { int cols, origin; - if (horizontal_split){ - widget->cols = COLS; - return; + if (horizontal_split) + { + widget->cols = COLS; + return; } - if (frame_size == frame_full){ - cols = COLS; - origin = 0; - } else { - if (widget == get_panel_widget (0)){ - cols = first_panel_size; - origin = 0; - } else { - cols = COLS-first_panel_size; - origin = first_panel_size; - } + if (frame_size == frame_full) + { + cols = COLS; + origin = 0; + } + else + { + if (widget == get_panel_widget (0)) + { + cols = first_panel_size; + origin = 0; + } + else + { + cols = COLS - first_panel_size; + origin = first_panel_size; + } } widget->cols = cols; @@ -1160,17 +1245,17 @@ panel_update_cols (Widget *widget, int frame_size) extern int saving_setup; static char * -panel_save_name (WPanel *panel) +panel_save_name (WPanel * panel) { /* If the program is shuting down */ if ((midnight_shutdown && auto_save_setup) || saving_setup) - return g_strdup (panel->panel_name); + return g_strdup (panel->panel_name); else - return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL); + return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL); } void -panel_clean_dir (WPanel *panel) +panel_clean_dir (WPanel * panel) { int count = panel->count; @@ -1188,7 +1273,7 @@ panel_clean_dir (WPanel *panel) } static void -panel_destroy (WPanel *p) +panel_destroy (WPanel * p) { size_t i; @@ -1198,12 +1283,13 @@ panel_destroy (WPanel *p) panel_clean_dir (p); /* save and clean history */ - if (p->dir_history) { - history_put (p->hist_name, p->dir_history); + if (p->dir_history) + { + history_put (p->hist_name, p->dir_history); - p->dir_history = g_list_first (p->dir_history); - g_list_foreach (p->dir_history, (GFunc) g_free, NULL); - g_list_free (p->dir_history); + p->dir_history = g_list_first (p->dir_history); + g_list_foreach (p->dir_history, (GFunc) g_free, NULL); + g_list_free (p->dir_history); } g_free (p->hist_name); @@ -1213,14 +1299,14 @@ panel_destroy (WPanel *p) g_free (p->user_format); for (i = 0; i < LIST_TYPES; i++) - g_free (p->user_status_format[i]); + g_free (p->user_status_format[i]); g_free (p->dir.list); g_free (p->panel_name); g_free (name); } static void -panel_format_modified (WPanel *panel) +panel_format_modified (WPanel * panel) { panel->format_modified = 1; } @@ -1230,7 +1316,7 @@ panel_format_modified (WPanel *panel) WPanel * panel_new (const char *panel_name) { - return panel_new_with_dir(panel_name, NULL); + return panel_new_with_dir (panel_name, NULL); } /* Panel creation for specified directory */ @@ -1253,11 +1339,13 @@ panel_new_with_dir (const char *panel_name, const char *wpath) /* We do not want the cursor */ widget_want_cursor (panel->widget, 0); - if (wpath) { - g_strlcpy(panel->cwd, wpath, sizeof (panel->cwd)); - mc_get_current_wd (curdir, sizeof (curdir) - 2); - } else - mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); + if (wpath) + { + g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd)); + mc_get_current_wd (curdir, sizeof (curdir) - 2); + } + else + mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); strcpy (panel->lwd, "."); @@ -1287,14 +1375,15 @@ panel_new_with_dir (const char *panel_name, const char *wpath) panel->user_format = g_strdup (DEFAULT_USER_FORMAT); for (i = 0; i < LIST_TYPES; i++) - panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); + panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); panel->search_buffer[0] = 0; panel->frame_size = frame_half; section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL); - if (!mc_config_has_group (mc_main_config, section)) { - g_free (section); - section = g_strdup (panel->panel_name); + if (!mc_config_has_group (mc_main_config, section)) + { + g_free (section); + section = g_strdup (panel->panel_name); } panel_load_setup (panel, section); g_free (section); @@ -1302,176 +1391,191 @@ panel_new_with_dir (const char *panel_name, const char *wpath) /* Load format strings */ err = set_panel_formats (panel); if (err != 0) - set_panel_formats (panel); + set_panel_formats (panel); /* Because do_load_dir lists files in current directory */ if (wpath) - mc_chdir(wpath); + mc_chdir (wpath); /* Load the default format */ panel->count = - do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine, - panel->reverse, panel->case_sensitive, - panel->exec_first, panel->filter); + do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine, + panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter); /* Restore old right path */ if (wpath) - mc_chdir(curdir); + mc_chdir (curdir); return panel; } void -panel_reload (WPanel *panel) +panel_reload (WPanel * panel) { struct stat current_stat; if (fast_reload && !stat (panel->cwd, ¤t_stat) - && current_stat.st_ctime == panel->dir_stat.st_ctime - && current_stat.st_mtime == panel->dir_stat.st_mtime) - return; + && current_stat.st_ctime == panel->dir_stat.st_ctime + && current_stat.st_mtime == panel->dir_stat.st_mtime) + return; - while (mc_chdir (panel->cwd) == -1) { - char *last_slash; + while (mc_chdir (panel->cwd) == -1) + { + char *last_slash; - if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0) { - panel_clean_dir (panel); - panel->count = set_zero_dir (&panel->dir) ? 1 : 0; - return; - } - last_slash = strrchr (panel->cwd, PATH_SEP); - if (!last_slash || last_slash == panel->cwd) - strcpy (panel->cwd, PATH_SEP_STR); - else - *last_slash = 0; - memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); - show_dir (panel); + if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0) + { + panel_clean_dir (panel); + panel->count = set_zero_dir (&panel->dir) ? 1 : 0; + return; + } + last_slash = strrchr (panel->cwd, PATH_SEP); + if (!last_slash || last_slash == panel->cwd) + strcpy (panel->cwd, PATH_SEP_STR); + else + *last_slash = 0; + memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); + show_dir (panel); } panel->count = - do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine, - panel->count, panel->reverse, panel->case_sensitive, - panel->exec_first, panel->filter); + do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine, + panel->count, panel->reverse, panel->case_sensitive, + panel->exec_first, panel->filter); panel->dirty = 1; if (panel->selected >= panel->count) - do_select (panel, panel->count - 1); + do_select (panel, panel->count - 1); recalculate_panel_summary (panel); } static void -panel_paint_sort_info(WPanel *panel) +panel_paint_sort_info (WPanel * panel) { const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign; char *str; if (*panel->current_sort_field->hotkey == '\0') - return; + return; - str = g_strdup_printf("%s%s",sort_sign, Q_(panel->current_sort_field->hotkey)); + str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->current_sort_field->hotkey)); widget_move (&panel->widget, 1, 1); tty_print_string (str); - g_free(str); + g_free (str); } -static gchar* -panel_get_title_without_hotkey(const char *title) +static gchar * +panel_get_title_without_hotkey (const char *title) { char *translated_title; char *hkey; if (title == NULL) - return NULL; + return NULL; if (title[0] == '\0') - return g_strdup(""); + return g_strdup (""); - translated_title = g_strdup(_(title)); + translated_title = g_strdup (_(title)); - hkey = strchr(translated_title, '&'); + hkey = strchr (translated_title, '&'); if ((hkey != NULL) && (hkey[1] != '\0')) - memmove((void *) hkey, (void *) hkey+1,strlen(hkey)); + memmove ((void *) hkey, (void *) hkey + 1, strlen (hkey)); return translated_title; } static void -paint_frame (WPanel *panel) +paint_frame (WPanel * panel) { int side, width; GString *format_txt; if (!panel->split) - adjust_top_file (panel); + adjust_top_file (panel); widget_erase (&panel->widget); show_dir (panel); widget_move (&panel->widget, 1, 1); - for (side = 0; side <= panel->split; side++){ - format_e *format; + for (side = 0; side <= panel->split; side++) + { + format_e *format; - if (side){ - tty_setcolor (NORMAL_COLOR); - tty_print_one_vline (); - width = panel->widget.cols - panel->widget.cols/2 - 1; - } else if (panel->split) - width = panel->widget.cols/2 - 3; - else - width = panel->widget.cols - 2; + if (side) + { + tty_setcolor (NORMAL_COLOR); + tty_print_one_vline (); + width = panel->widget.cols - panel->widget.cols / 2 - 1; + } + else if (panel->split) + width = panel->widget.cols / 2 - 3; + else + width = panel->widget.cols - 2; - format_txt = g_string_new(""); - for (format = panel->format; format; format = format->next){ - if (format->string_fn){ - g_string_set_size(format_txt, 0); + format_txt = g_string_new (""); + for (format = panel->format; format; format = format->next) + { + if (format->string_fn) + { + g_string_set_size (format_txt, 0); - if (panel->list_type == list_long && strcmp (format->id, panel->current_sort_field->id) == 0) - g_string_append (format_txt, (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign); + if (panel->list_type == list_long + && strcmp (format->id, panel->current_sort_field->id) == 0) + g_string_append (format_txt, + (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign); g_string_append (format_txt, format->title); - if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter) { - g_string_append (format_txt, " ["); - g_string_append (format_txt, panel->filter); - g_string_append (format_txt, "]"); + if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter) + { + g_string_append (format_txt, " ["); + g_string_append (format_txt, panel->filter); + g_string_append (format_txt, "]"); } tty_setcolor (MARKED_COLOR); tty_print_string (str_fit_to_term (format_txt->str, format->field_len, - J_CENTER_LEFT)); + J_CENTER_LEFT)); width -= format->field_len; - } else { - tty_setcolor (NORMAL_COLOR); - tty_print_one_vline (); - width--; - } - } - g_string_free(format_txt, TRUE); + } + else + { + tty_setcolor (NORMAL_COLOR); + tty_print_one_vline (); + width--; + } + } + g_string_free (format_txt, TRUE); - if (width > 0) - tty_draw_hline (-1, -1, ' ', width); + if (width > 0) + tty_draw_hline (-1, -1, ' ', width); } if (panel->list_type != list_long) - panel_paint_sort_info(panel); + panel_paint_sort_info (panel); } static const char * -parse_panel_size (WPanel *panel, const char *format, int isstatus) +parse_panel_size (WPanel * panel, const char *format, int isstatus) { int frame = frame_half; format = skip_separators (format); - if (!strncmp (format, "full", 4)){ - frame = frame_full; - format += 4; - } else if (!strncmp (format, "half", 4)){ - frame = frame_half; - format += 4; + if (!strncmp (format, "full", 4)) + { + frame = frame_full; + format += 4; + } + else if (!strncmp (format, "half", 4)) + { + frame = frame_half; + format += 4; } - if (!isstatus){ + if (!isstatus) + { panel->frame_size = frame; panel->split = 0; } @@ -1479,10 +1583,11 @@ parse_panel_size (WPanel *panel, const char *format, int isstatus) /* Now, the optional column specifier */ format = skip_separators (format); - if (*format == '1' || *format == '2'){ - if (!isstatus) - panel->split = *format == '2'; - format++; + if (*format == '1' || *format == '2') + { + if (!isstatus) + panel->split = *format == '2'; + format++; } if (!isstatus) @@ -1496,7 +1601,7 @@ parse_panel_size (WPanel *panel, const char *format, int isstatus) all := panel_format? format panel_format := [full|half] [1|2] format := one_format_e - | format , one_format_e + | format , one_format_e one_format_e := just format.id [opt_size] just := [<=>] @@ -1504,27 +1609,29 @@ parse_panel_size (WPanel *panel, const char *format, int isstatus) size := [0-9]+ opt_expand := + -*/ + */ static format_e * -parse_display_format (WPanel *panel, const char *format, char **error, int isstatus, int *res_total_cols) +parse_display_format (WPanel * panel, const char *format, char **error, int isstatus, + int *res_total_cols) { - format_e *darr, *old = 0, *home = 0; /* The formats we return */ - int total_cols = 0; /* Used columns by the format */ - int set_justify; /* flag: set justification mode? */ - align_crt_t justify = J_LEFT; /* Which mode. */ - size_t i; + format_e *darr, *old = 0, *home = 0; /* The formats we return */ + int total_cols = 0; /* Used columns by the format */ + int set_justify; /* flag: set justification mode? */ + align_crt_t justify = J_LEFT; /* Which mode. */ + size_t i; - static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */ + static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */ *error = 0; - if (i18n_timelength == 0) { - i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */ + if (i18n_timelength == 0) + { + i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */ - for (i = 0; panel_fields[i].id != NULL; i++) - if (strcmp ("time", panel_fields[i].id + 1) == 0) - panel_fields [i].min_size = i18n_timelength; + for (i = 0; panel_fields[i].id != NULL; i++) + if (strcmp ("time", panel_fields[i].id + 1) == 0) + panel_fields[i].min_size = i18n_timelength; } /* @@ -1533,8 +1640,9 @@ parse_display_format (WPanel *panel, const char *format, char **error, int issta */ format = parse_panel_size (panel, format, isstatus); - while (*format){ /* format can be an empty string */ - int found = 0; + while (*format) + { /* format can be an empty string */ + int found = 0; darr = g_new0 (format_e, 1); @@ -1546,88 +1654,95 @@ parse_display_format (WPanel *panel, const char *format, char **error, int issta darr->next = 0; old = darr; - format = skip_separators (format); + format = skip_separators (format); - if (strchr ("<=>", *format)){ - set_justify = 1; - switch (*format) - { - case '<': - justify = J_LEFT; - break; - case '=': - justify = J_CENTER; - break; - case '>': - default: - justify = J_RIGHT; - break; - } - format = skip_separators (format+1); - } else - set_justify = 0; + if (strchr ("<=>", *format)) + { + set_justify = 1; + switch (*format) + { + case '<': + justify = J_LEFT; + break; + case '=': + justify = J_CENTER; + break; + case '>': + default: + justify = J_RIGHT; + break; + } + format = skip_separators (format + 1); + } + else + set_justify = 0; - for (i = 0; panel_fields[i].id != NULL; i++) { - size_t klen = strlen (panel_fields [i].id); + for (i = 0; panel_fields[i].id != NULL; i++) + { + size_t klen = strlen (panel_fields[i].id); - if (strncmp (format, panel_fields [i].id, klen) != 0) - continue; + if (strncmp (format, panel_fields[i].id, klen) != 0) + continue; - format += klen; + format += klen; - darr->requested_field_len = panel_fields [i].min_size; - darr->string_fn = panel_fields [i].string_fn; - darr->title = panel_get_title_without_hotkey(panel_fields [i].title_hotkey); + darr->requested_field_len = panel_fields[i].min_size; + darr->string_fn = panel_fields[i].string_fn; + darr->title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey); - darr->id = panel_fields [i].id; - darr->expand = panel_fields [i].expands; - darr->just_mode = panel_fields [i].default_just; + darr->id = panel_fields[i].id; + darr->expand = panel_fields[i].expands; + darr->just_mode = panel_fields[i].default_just; - if (set_justify) { - if (IS_FIT(darr->just_mode)) - darr->just_mode = MAKE_FIT(justify); - else - darr->just_mode = justify; - } - found = 1; + if (set_justify) + { + if (IS_FIT (darr->just_mode)) + darr->just_mode = MAKE_FIT (justify); + else + darr->just_mode = justify; + } + found = 1; - format = skip_separators (format); + format = skip_separators (format); - /* If we have a size specifier */ - if (*format == ':'){ - int req_length; + /* If we have a size specifier */ + if (*format == ':') + { + int req_length; - /* If the size was specified, we don't want - * auto-expansion by default - */ - darr->expand = 0; - format++; - req_length = atoi (format); - darr->requested_field_len = req_length; + /* If the size was specified, we don't want + * auto-expansion by default + */ + darr->expand = 0; + format++; + req_length = atoi (format); + darr->requested_field_len = req_length; - format = skip_numbers (format); + format = skip_numbers (format); - /* Now, if they insist on expansion */ - if (*format == '+'){ - darr->expand = 1; - format++; - } + /* Now, if they insist on expansion */ + if (*format == '+') + { + darr->expand = 1; + format++; + } - } + } - break; - } - if (!found){ - char *tmp_format = g_strdup (format); + break; + } + if (!found) + { + char *tmp_format = g_strdup (format); - int pos = min (8, strlen (format)); - delete_format (home); - tmp_format [pos] = 0; - *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL); - g_free (tmp_format); - return 0; - } - total_cols += darr->requested_field_len; + int pos = min (8, strlen (format)); + delete_format (home); + tmp_format[pos] = 0; + *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL); + g_free (tmp_format); + return 0; + } + total_cols += darr->requested_field_len; } *res_total_cols = total_cols; @@ -1635,76 +1750,84 @@ parse_display_format (WPanel *panel, const char *format, char **error, int issta } static format_e * -use_display_format (WPanel *panel, const char *format, char **error, int isstatus) +use_display_format (WPanel * panel, const char *format, char **error, int isstatus) { #define MAX_EXPAND 4 - int expand_top = 0; /* Max used element in expand */ - int usable_columns; /* Usable columns in the panel */ - int total_cols = 0; - int i; + int expand_top = 0; /* Max used element in expand */ + int usable_columns; /* Usable columns in the panel */ + int total_cols = 0; + int i; format_e *darr, *home; if (!format) - format = DEFAULT_USER_FORMAT; + format = DEFAULT_USER_FORMAT; home = parse_display_format (panel, format, error, isstatus, &total_cols); if (*error) - return 0; + return 0; panel->dirty = 1; /* Status needn't to be split */ - usable_columns = ((panel->widget.cols-2)/((isstatus) - ? 1 - : (panel->split+1))) - (!isstatus && panel->split); + usable_columns = ((panel->widget.cols - 2) / ((isstatus) + ? 1 + : (panel->split + 1))) - (!isstatus + && panel->split); /* Look for the expandable fields and set field_len based on the requested field len */ - for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next){ - darr->field_len = darr->requested_field_len; - if (darr->expand) - expand_top++; + for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next) + { + darr->field_len = darr->requested_field_len; + if (darr->expand) + expand_top++; } /* If we used more columns than the available columns, adjust that */ - if (total_cols > usable_columns){ - int pdif, dif = total_cols - usable_columns; + if (total_cols > usable_columns) + { + int pdif, dif = total_cols - usable_columns; - while (dif){ - pdif = dif; - for (darr = home; darr; darr = darr->next){ - if (dif && darr->field_len - 1){ - darr->field_len--; - dif--; - } - } + while (dif) + { + pdif = dif; + for (darr = home; darr; darr = darr->next) + { + if (dif && darr->field_len - 1) + { + darr->field_len--; + dif--; + } + } - /* avoid endless loop if num fields > 40 */ - if (pdif == dif) - break; - } - total_cols = usable_columns; /* give up, the rest should be truncated */ + /* avoid endless loop if num fields > 40 */ + if (pdif == dif) + break; + } + total_cols = usable_columns; /* give up, the rest should be truncated */ } /* Expand the available space */ - if ((usable_columns > total_cols) && expand_top){ - int spaces = (usable_columns - total_cols) / expand_top; - int extra = (usable_columns - total_cols) % expand_top; + if ((usable_columns > total_cols) && expand_top) + { + int spaces = (usable_columns - total_cols) / expand_top; + int extra = (usable_columns - total_cols) % expand_top; - for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next) - if (darr->expand){ - darr->field_len += (spaces + ((i == 0) ? extra : 0)); - i++; - } + for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next) + if (darr->expand) + { + darr->field_len += (spaces + ((i == 0) ? extra : 0)); + i++; + } } return home; } -/* Switches the panel to the mode specified in the format */ +/* Switches the panel to the mode specified in the format */ /* Seting up both format and status string. Return: 0 - on success; */ /* 1 - format error; 2 - status error; 3 - errors in both formats. */ int -set_panel_formats (WPanel *p) +set_panel_formats (WPanel * p) { format_e *form; char *err = NULL; @@ -1712,38 +1835,48 @@ set_panel_formats (WPanel *p) form = use_display_format (p, panel_format (p), &err, 0); - if (err != NULL) { + if (err != NULL) + { g_free (err); retcode = 1; - } else { + } + else + { delete_format (p->format); p->format = form; } - if (show_mini_info) { - form = use_display_format (p, mini_status_format (p), &err, 1); + if (show_mini_info) + { + form = use_display_format (p, mini_status_format (p), &err, 1); - if (err != NULL) { - g_free (err); - retcode += 2; - } else { - delete_format (p->status_format); - p->status_format = form; - } + if (err != NULL) + { + g_free (err); + retcode += 2; + } + else + { + delete_format (p->status_format); + p->status_format = form; + } } panel_format_modified (p); panel_update_cols (&(p->widget), p->frame_size); if (retcode) - message (D_ERROR, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) ); - if (retcode & 0x01){ + message (D_ERROR, _("Warning"), + _("User supplied format looks invalid, reverting to default.")); + if (retcode & 0x01) + { g_free (p->user_format); p->user_format = g_strdup (DEFAULT_USER_FORMAT); } - if (retcode & 0x02){ - g_free (p->user_status_format [p->list_type]); - p->user_status_format [p->list_type] = g_strdup (DEFAULT_USER_FORMAT); + if (retcode & 0x02) + { + g_free (p->user_status_format[p->list_type]); + p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT); } return retcode; @@ -1751,45 +1884,47 @@ set_panel_formats (WPanel *p) /* Given the panel->view_type returns the format string to be parsed */ static const char * -panel_format (WPanel *panel) +panel_format (WPanel * panel) { - switch (panel->list_type){ + switch (panel->list_type) + { case list_long: - return "full perm space nlink space owner space group space size space mtime space name"; + return "full perm space nlink space owner space group space size space mtime space name"; case list_brief: - return "half 2 type name"; + return "half 2 type name"; case list_user: - return panel->user_format; + return panel->user_format; default: case list_full: - return "half type name | size | mtime"; + return "half type name | size | mtime"; } } static const char * -mini_status_format (WPanel *panel) +mini_status_format (WPanel * panel) { if (panel->user_mini_status) - return panel->user_status_format [panel->list_type]; + return panel->user_status_format[panel->list_type]; - switch (panel->list_type){ + switch (panel->list_type) + { case list_long: - return "full perm space nlink space owner space group space size space mtime space name"; + return "full perm space nlink space owner space group space size space mtime space name"; case list_brief: - return "half type name space bsize space perm space"; + return "half type name space bsize space perm space"; case list_full: - return "half type name"; + return "half type name"; default: case list_user: - return panel->user_format; + return panel->user_format; } } @@ -1801,35 +1936,39 @@ mini_status_format (WPanel *panel) static cb_ret_t maybe_cd (int move_up_dir) { - if (navigate_with_arrows) { - if (!cmdline->buffer[0]) { - if (move_up_dir) { - do_cd ("..", cd_exact); - return MSG_HANDLED; - } - if (S_ISDIR (selection (current_panel)->st.st_mode) - || link_isdir (selection (current_panel))) { - do_cd (selection (current_panel)->fname, cd_exact); - return MSG_HANDLED; - } - } + if (navigate_with_arrows) + { + if (!cmdline->buffer[0]) + { + if (move_up_dir) + { + do_cd ("..", cd_exact); + return MSG_HANDLED; + } + if (S_ISDIR (selection (current_panel)->st.st_mode) + || link_isdir (selection (current_panel))) + { + do_cd (selection (current_panel)->fname, cd_exact); + return MSG_HANDLED; + } + } } return MSG_NOT_HANDLED; } /* Returns the number of items in the given panel */ static int -ITEMS (WPanel *p) +ITEMS (WPanel * p) { if (p->split) - return llines (p) * 2; + return llines (p) * 2; else - return llines (p); + return llines (p); } /* Select current item and readjust the panel */ void -select_item (WPanel *panel) +select_item (WPanel * panel) { int items = ITEMS (panel); @@ -1838,28 +1977,29 @@ select_item (WPanel *panel) forget it someday, so it's better to do the actual fitting here */ if (panel->top_file < 0) - panel->top_file = 0; + panel->top_file = 0; if (panel->selected < 0) - panel->selected = 0; + panel->selected = 0; if (panel->selected > panel->count - 1) - panel->selected = panel->count - 1; + panel->selected = panel->count - 1; if (panel->top_file > panel->count - 1) - panel->top_file = panel->count - 1; + panel->top_file = panel->count - 1; - if ((panel->count - panel->top_file) < items) { - panel->top_file = panel->count - items; - if (panel->top_file < 0) - panel->top_file = 0; + if ((panel->count - panel->top_file) < items) + { + panel->top_file = panel->count - items; + if (panel->top_file < 0) + panel->top_file = 0; } if (panel->selected < panel->top_file) - panel->top_file = panel->selected; + panel->top_file = panel->selected; if ((panel->selected - panel->top_file) >= items) - panel->top_file = panel->selected - items + 1; + panel->top_file = panel->selected - items + 1; panel->dirty = 1; @@ -1868,14 +2008,14 @@ select_item (WPanel *panel) /* Clears all files in the panel, used only when one file was marked */ void -unmark_files (WPanel *panel) +unmark_files (WPanel * panel) { int i; if (!panel->marked) - return; + return; for (i = 0; i < panel->count; i++) - file_mark (panel, i, 0); + file_mark (panel, i, 0); panel->dirs_marked = 0; panel->marked = 0; @@ -1883,120 +2023,128 @@ unmark_files (WPanel *panel) } static void -unselect_item (WPanel *panel) +unselect_item (WPanel * panel) { - repaint_file (panel, panel->selected, 1, 2*selection (panel)->f.marked, 0); + repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0); } static void -move_down (WPanel *panel) +move_down (WPanel * panel) { - if (panel->selected+1 == panel->count) - return; + if (panel->selected + 1 == panel->count) + return; unselect_item (panel); panel->selected++; - if (panel->selected - panel->top_file == ITEMS (panel) && - panel_scroll_pages) { - /* Scroll window half screen */ - panel->top_file += ITEMS (panel)/2; - if (panel->top_file > panel->count - ITEMS (panel)) - panel->top_file = panel->count - ITEMS (panel); - paint_dir (panel); + if (panel->selected - panel->top_file == ITEMS (panel) && panel_scroll_pages) + { + /* Scroll window half screen */ + panel->top_file += ITEMS (panel) / 2; + if (panel->top_file > panel->count - ITEMS (panel)) + panel->top_file = panel->count - ITEMS (panel); + paint_dir (panel); } select_item (panel); } static void -move_up (WPanel *panel) +move_up (WPanel * panel) { if (panel->selected == 0) - return; + return; unselect_item (panel); panel->selected--; - if (panel->selected < panel->top_file && panel_scroll_pages) { - /* Scroll window half screen */ - panel->top_file -= ITEMS (panel)/2; - if (panel->top_file < 0) - panel->top_file = 0; - paint_dir (panel); + if (panel->selected < panel->top_file && panel_scroll_pages) + { + /* Scroll window half screen */ + panel->top_file -= ITEMS (panel) / 2; + if (panel->top_file < 0) + panel->top_file = 0; + paint_dir (panel); } select_item (panel); } /* Changes the selection by lines (may be negative) */ static void -move_selection (WPanel *panel, int lines) +move_selection (WPanel * panel, int lines) { int new_pos; int adjust = 0; new_pos = panel->selected + lines; if (new_pos >= panel->count) - new_pos = panel->count-1; + new_pos = panel->count - 1; if (new_pos < 0) - new_pos = 0; + new_pos = 0; unselect_item (panel); panel->selected = new_pos; - if (panel->selected - panel->top_file >= ITEMS (panel)){ - panel->top_file += lines; - adjust = 1; + if (panel->selected - panel->top_file >= ITEMS (panel)) + { + panel->top_file += lines; + adjust = 1; } - if (panel->selected - panel->top_file < 0){ - panel->top_file += lines; - adjust = 1; + if (panel->selected - panel->top_file < 0) + { + panel->top_file += lines; + adjust = 1; } - if (adjust){ - if (panel->top_file > panel->selected) - panel->top_file = panel->selected; - if (panel->top_file < 0) - panel->top_file = 0; - paint_dir (panel); + if (adjust) + { + if (panel->top_file > panel->selected) + panel->top_file = panel->selected; + if (panel->top_file < 0) + panel->top_file = 0; + paint_dir (panel); } select_item (panel); } static cb_ret_t -move_left (WPanel *panel) +move_left (WPanel * panel) { - if (panel->split) { - move_selection (panel, -llines (panel)); - return MSG_HANDLED; - } else - return maybe_cd (1); /* cd .. */ + if (panel->split) + { + move_selection (panel, -llines (panel)); + return MSG_HANDLED; + } + else + return maybe_cd (1); /* cd .. */ } static int -move_right (WPanel *panel) +move_right (WPanel * panel) { - if (panel->split) { - move_selection (panel, llines (panel)); - return MSG_HANDLED; - } else - return maybe_cd (0); /* cd (selection) */ + if (panel->split) + { + move_selection (panel, llines (panel)); + return MSG_HANDLED; + } + else + return maybe_cd (0); /* cd (selection) */ } static void -prev_page (WPanel *panel) +prev_page (WPanel * panel) { int items; if (!panel->selected && !panel->top_file) - return; + return; unselect_item (panel); items = ITEMS (panel); if (panel->top_file < items) - items = panel->top_file; + items = panel->top_file; if (!items) - panel->selected = 0; + panel->selected = 0; else - panel->selected -= items; + panel->selected -= items; panel->top_file -= items; select_item (panel); @@ -2004,29 +2152,29 @@ prev_page (WPanel *panel) } static void -ctrl_prev_page (WPanel *panel) +ctrl_prev_page (WPanel * panel) { (void) panel; do_cd ("..", cd_exact); } static void -next_page (WPanel *panel) +next_page (WPanel * panel) { int items; if (panel->selected == panel->count - 1) - return; + return; unselect_item (panel); items = ITEMS (panel); if (panel->top_file > panel->count - 2 * items) - items = panel->count - items - panel->top_file; + items = panel->count - items - panel->top_file; if (panel->top_file + items < 0) - items = -panel->top_file; + items = -panel->top_file; if (!items) - panel->selected = panel->count - 1; + panel->selected = panel->count - 1; else - panel->selected += items; + panel->selected += items; panel->top_file += items; select_item (panel); @@ -2034,16 +2182,16 @@ next_page (WPanel *panel) } static void -ctrl_next_page (WPanel *panel) +ctrl_next_page (WPanel * panel) { - if ((S_ISDIR (selection (panel)->st.st_mode) - || link_isdir (selection (panel)))) { - do_cd (selection (panel)->fname, cd_exact); + if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel)))) + { + do_cd (selection (panel)->fname, cd_exact); } } static void -goto_top_file (WPanel *panel) +goto_top_file (WPanel * panel) { unselect_item (panel); panel->selected = panel->top_file; @@ -2051,15 +2199,15 @@ goto_top_file (WPanel *panel) } static void -goto_middle_file (WPanel *panel) +goto_middle_file (WPanel * panel) { unselect_item (panel); - panel->selected = panel->top_file + (ITEMS (panel)/2); + panel->selected = panel->top_file + (ITEMS (panel) / 2); select_item (panel); } static void -goto_bottom_file (WPanel *panel) +goto_bottom_file (WPanel * panel) { unselect_item (panel); panel->selected = panel->top_file + ITEMS (panel) - 1; @@ -2067,23 +2215,26 @@ goto_bottom_file (WPanel *panel) } static void -move_home (WPanel *panel) +move_home (WPanel * panel) { if (panel->selected == 0) - return; + return; unselect_item (panel); - if (torben_fj_mode){ - int middle_pos = panel->top_file + (ITEMS (panel)/2); + if (torben_fj_mode) + { + int middle_pos = panel->top_file + (ITEMS (panel) / 2); - if (panel->selected > middle_pos){ - goto_middle_file (panel); - return; - } - if (panel->selected != panel->top_file){ - goto_top_file (panel); - return; - } + if (panel->selected > middle_pos) + { + goto_middle_file (panel); + return; + } + if (panel->selected != panel->top_file) + { + goto_top_file (panel); + return; + } } panel->top_file = 0; @@ -2094,25 +2245,28 @@ move_home (WPanel *panel) } static void -move_end (WPanel *panel) +move_end (WPanel * panel) { - if (panel->selected == panel->count-1) - return; + if (panel->selected == panel->count - 1) + return; unselect_item (panel); - if (torben_fj_mode){ - int middle_pos = panel->top_file + (ITEMS (panel)/2); + if (torben_fj_mode) + { + int middle_pos = panel->top_file + (ITEMS (panel) / 2); - if (panel->selected < middle_pos){ - goto_middle_file (panel); - return; - } - if (panel->selected != (panel->top_file + ITEMS(panel)-1)){ - goto_bottom_file (panel); - return; - } + if (panel->selected < middle_pos) + { + goto_middle_file (panel); + return; + } + if (panel->selected != (panel->top_file + ITEMS (panel) - 1)) + { + goto_bottom_file (panel); + return; + } } - panel->selected = panel->count-1; + panel->selected = panel->count - 1; paint_dir (panel); select_item (panel); } @@ -2120,74 +2274,81 @@ move_end (WPanel *panel) /* Recalculate the panels summary information, used e.g. when marked files might have been removed by an external command */ void -recalculate_panel_summary (WPanel *panel) +recalculate_panel_summary (WPanel * panel) { int i; panel->marked = 0; panel->dirs_marked = 0; - panel->total = 0; + panel->total = 0; for (i = 0; i < panel->count; i++) - if (panel->dir.list [i].f.marked){ - /* do_file_mark will return immediately if newmark == oldmark. - So we have to first unmark it to get panel's summary information - updated. (Norbert) */ - panel->dir.list [i].f.marked = 0; - do_file_mark (panel, i, 1); - } + if (panel->dir.list[i].f.marked) + { + /* do_file_mark will return immediately if newmark == oldmark. + So we have to first unmark it to get panel's summary information + updated. (Norbert) */ + panel->dir.list[i].f.marked = 0; + do_file_mark (panel, i, 1); + } } /* This routine marks a file or a directory */ void -do_file_mark (WPanel *panel, int idx, int mark) +do_file_mark (WPanel * panel, int idx, int mark) { if (panel->dir.list[idx].f.marked == mark) - return; + return; /* Only '..' can't be marked, '.' isn't visible */ if (!strcmp (panel->dir.list[idx].fname, "..")) - return; + return; file_mark (panel, idx, mark); - if (panel->dir.list[idx].f.marked) { - panel->marked++; - if (S_ISDIR (panel->dir.list[idx].st.st_mode)) { - if (panel->dir.list[idx].f.dir_size_computed) - panel->total += panel->dir.list[idx].st.st_size; - panel->dirs_marked++; - } else - panel->total += panel->dir.list[idx].st.st_size; - set_colors (panel); - } else { - if (S_ISDIR (panel->dir.list[idx].st.st_mode)) { - if (panel->dir.list[idx].f.dir_size_computed) - panel->total -= panel->dir.list[idx].st.st_size; - panel->dirs_marked--; - } else - panel->total -= panel->dir.list[idx].st.st_size; - panel->marked--; + if (panel->dir.list[idx].f.marked) + { + panel->marked++; + if (S_ISDIR (panel->dir.list[idx].st.st_mode)) + { + if (panel->dir.list[idx].f.dir_size_computed) + panel->total += panel->dir.list[idx].st.st_size; + panel->dirs_marked++; + } + else + panel->total += panel->dir.list[idx].st.st_size; + set_colors (panel); + } + else + { + if (S_ISDIR (panel->dir.list[idx].st.st_mode)) + { + if (panel->dir.list[idx].f.dir_size_computed) + panel->total -= panel->dir.list[idx].st.st_size; + panel->dirs_marked--; + } + else + panel->total -= panel->dir.list[idx].st.st_size; + panel->marked--; } } static void -do_mark_file (WPanel *panel, int do_move) +do_mark_file (WPanel * panel, int do_move) { - do_file_mark (panel, panel->selected, - selection (panel)->f.marked ? 0 : 1); + do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1); if (mark_moves_down && do_move) - move_down (panel); + move_down (panel); } static void -mark_file (WPanel *panel) +mark_file (WPanel * panel) { do_mark_file (panel, 1); } /* Incremental search of a file name in the panel */ static void -do_search (WPanel *panel, int c_code) +do_search (WPanel * panel, int c_code) { size_t l; int i, sel; @@ -2198,31 +2359,38 @@ do_search (WPanel *panel, int c_code) gboolean is_found = FALSE; l = strlen (panel->search_buffer); - if (c_code == KEY_BACKSPACE) { - if (l != 0) { + if (c_code == KEY_BACKSPACE) + { + if (l != 0) + { act = panel->search_buffer + l; str_prev_noncomb_char (&act, panel->search_buffer); act[0] = '\0'; } panel->search_chpoint = 0; - } else { - if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char)) { + } + else + { + if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char)) + { panel->search_char[panel->search_chpoint] = c_code; panel->search_chpoint++; } - if (panel->search_chpoint > 0) { - switch (str_is_valid_char (panel->search_char, panel->search_chpoint)) { + if (panel->search_chpoint > 0) + { + switch (str_is_valid_char (panel->search_char, panel->search_chpoint)) + { case -2: return; case -1: panel->search_chpoint = 0; return; default: - if (l + panel->search_chpoint < sizeof (panel->search_buffer)) { - memcpy (panel->search_buffer + l, panel->search_char, - panel->search_chpoint); - l+= panel->search_chpoint; + if (l + panel->search_chpoint < sizeof (panel->search_buffer)) + { + memcpy (panel->search_buffer + l, panel->search_char, panel->search_chpoint); + l += panel->search_chpoint; (panel->search_buffer + l)[0] = '\0'; panel->search_chpoint = 0; } @@ -2238,26 +2406,31 @@ do_search (WPanel *panel, int c_code) search->is_case_sentitive = 0; sel = panel->selected; - for (i = panel->selected; !wrapped || i != panel->selected; i++) { - if (i >= panel->count) { + for (i = panel->selected; !wrapped || i != panel->selected; i++) + { + if (i >= panel->count) + { i = 0; if (wrapped) break; wrapped = TRUE; } - if (mc_search_run (search, panel->dir.list[i].fname, - 0, panel->dir.list[i].fnamelen, NULL)) { + if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL)) + { sel = i; is_found = TRUE; break; } } - if (is_found) { + if (is_found) + { unselect_item (panel); panel->selected = sel; select_item (panel); paint_panel (panel); - } else if (c_code != KEY_BACKSPACE) { + } + else if (c_code != KEY_BACKSPACE) + { act = panel->search_buffer + l; str_prev_noncomb_char (&act, panel->search_buffer); act[0] = '\0'; @@ -2268,27 +2441,30 @@ do_search (WPanel *panel, int c_code) } static void -start_search (WPanel *panel) +start_search (WPanel * panel) { - if (panel->searching){ - if (panel->selected+1 == panel->count) - panel->selected = 0; - else - move_down (panel); - do_search (panel, 0); - } else { - panel->searching = 1; - panel->search_buffer[0] = '\0'; + if (panel->searching) + { + if (panel->selected + 1 == panel->count) + panel->selected = 0; + else + move_down (panel); + do_search (panel, 0); + } + else + { + panel->searching = 1; + panel->search_buffer[0] = '\0'; panel->search_char[0] = '\0'; panel->search_chpoint = 0; - display_mini_info (panel); - mc_refresh (); + display_mini_info (panel); + mc_refresh (); } } /* Return 1 if the Enter key has been processed, 0 otherwise */ static int -do_enter_on_file_entry (file_entry *fe) +do_enter_on_file_entry (file_entry * fe) { char *full_name; @@ -2296,52 +2472,54 @@ do_enter_on_file_entry (file_entry *fe) * Directory or link to directory - change directory. * Try the same for the entries on which mc_lstat() has failed. */ - if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) - || (fe->st.st_mode == 0)) { - if (!do_cd (fe->fname, cd_exact)) - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); - return 1; + if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0)) + { + if (!do_cd (fe->fname, cd_exact)) + message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + return 1; } /* Try associated command */ if (regex_command (fe->fname, "Open", 0) != 0) - return 1; + return 1; /* Check if the file is executable */ full_name = concat_dir_and_file (current_panel->cwd, fe->fname); - if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) { - g_free (full_name); - return 0; + if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) + { + g_free (full_name); + return 0; } g_free (full_name); - if (confirm_execute) { - if (query_dialog - (_(" The Midnight Commander "), - _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), - _("&No")) != 0) - return 1; + if (confirm_execute) + { + if (query_dialog + (_(" The Midnight Commander "), + _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), _("&No")) != 0) + return 1; } #ifdef ENABLE_VFS - if (!vfs_current_is_local ()) { - char *tmp; - int ret; + if (!vfs_current_is_local ()) + { + char *tmp; + int ret; - tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname); - ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL); - g_free (tmp); - /* We took action only if the dialog was shown or the execution - * was successful */ - return confirm_execute || (ret == 0); + tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname); + ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL); + g_free (tmp); + /* We took action only if the dialog was shown or the execution + * was successful */ + return confirm_execute || (ret == 0); } #endif { - char *tmp = name_quote (fe->fname, 0); - char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL); - g_free (tmp); - shell_execute (cmd, 0); - g_free (cmd); + char *tmp = name_quote (fe->fname, 0); + char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL); + g_free (tmp); + shell_execute (cmd, 0); + g_free (cmd); } #if HAVE_CHARSET @@ -2352,33 +2530,36 @@ do_enter_on_file_entry (file_entry *fe) } static int -do_enter (WPanel *panel) +do_enter (WPanel * panel) { return do_enter_on_file_entry (selection (panel)); } static void -chdir_other_panel (WPanel *panel) +chdir_other_panel (WPanel * panel) { char *new_dir; char *sel_entry = NULL; - - if (get_other_type () != view_listing) { - set_display_type (get_other_index (), view_listing); + + if (get_other_type () != view_listing) + { + set_display_type (get_other_index (), view_listing); } - if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) { + if (!S_ISDIR (panel->dir.list[panel->selected].st.st_mode)) + { new_dir = concat_dir_and_file (panel->cwd, ".."); - sel_entry = strrchr(panel->cwd, PATH_SEP); - } else - new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname); + sel_entry = strrchr (panel->cwd, PATH_SEP); + } + else + new_dir = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname); change_panel (); do_cd (new_dir, cd_exact); if (sel_entry) - try_to_select (current_panel, sel_entry); + try_to_select (current_panel, sel_entry); change_panel (); - + move_down (panel); g_free (new_dir); @@ -2391,245 +2572,281 @@ chdir_other_panel (WPanel *panel) * doesn't become panelized. */ static void -sync_other_panel (WPanel *panel) +sync_other_panel (WPanel * panel) { - if (get_other_type () != view_listing) { - set_display_type (get_other_index (), view_listing); + if (get_other_type () != view_listing) + { + set_display_type (get_other_index (), view_listing); } do_panel_cd (other_panel, current_panel->cwd, cd_exact); /* try to select current filename on the other panel */ - if (!panel->is_panelized) { - try_to_select (other_panel, selection (panel)->fname); + if (!panel->is_panelized) + { + try_to_select (other_panel, selection (panel)->fname); } } static void -chdir_to_readlink (WPanel *panel) +chdir_to_readlink (WPanel * panel) { char *new_dir; if (get_other_type () != view_listing) - return; + return; - if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)) { - char buffer [MC_MAXPATHLEN], *p; - int i; - struct stat st; + if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode)) + { + char buffer[MC_MAXPATHLEN], *p; + int i; + struct stat st; - i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1); - if (i < 0) - return; - if (mc_stat (selection (panel)->fname, &st) < 0) - return; - buffer [i] = 0; - if (!S_ISDIR (st.st_mode)) { - p = strrchr (buffer, PATH_SEP); - if (p && !p[1]) { - *p = 0; - p = strrchr (buffer, PATH_SEP); - } - if (!p) - return; - p[1] = 0; - } - if (*buffer == PATH_SEP) - new_dir = g_strdup (buffer); - else - new_dir = concat_dir_and_file (panel->cwd, buffer); + i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1); + if (i < 0) + return; + if (mc_stat (selection (panel)->fname, &st) < 0) + return; + buffer[i] = 0; + if (!S_ISDIR (st.st_mode)) + { + p = strrchr (buffer, PATH_SEP); + if (p && !p[1]) + { + *p = 0; + p = strrchr (buffer, PATH_SEP); + } + if (!p) + return; + p[1] = 0; + } + if (*buffer == PATH_SEP) + new_dir = g_strdup (buffer); + else + new_dir = concat_dir_and_file (panel->cwd, buffer); - change_panel (); - do_cd (new_dir, cd_exact); - change_panel (); + change_panel (); + do_cd (new_dir, cd_exact); + change_panel (); - move_down (panel); + move_down (panel); - g_free (new_dir); + g_free (new_dir); } } static gsize -panel_get_format_field_count(WPanel *panel) +panel_get_format_field_count (WPanel * panel) { format_e *format; gsize lc_index; - for ( - lc_index=0, format = panel->format; - format != NULL; - format = format->next, lc_index++ - ); + for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++); return lc_index; } /* -function return 0 if not found and REAL_INDEX+1 if found -*/ + function return 0 if not found and REAL_INDEX+1 if found + */ static gsize -panel_get_format_field_index_by_name(WPanel *panel, const char *name) +panel_get_format_field_index_by_name (WPanel * panel, const char *name) { format_e *format; gsize lc_index; - for ( - lc_index=1, format = panel->format; - ! ( format == NULL || strcmp(format->title, name) == 0 ); - format = format->next, lc_index++ - ); + for (lc_index = 1, format = panel->format; + !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++); if (format == NULL) - lc_index = 0; + lc_index = 0; return lc_index; } static format_e * -panel_get_format_field_by_index(WPanel *panel, gsize lc_index) +panel_get_format_field_by_index (WPanel * panel, gsize lc_index) { format_e *format; - for ( - format = panel->format; - ! ( format == NULL || lc_index == 0 ); - format = format->next, lc_index-- - ); + for (format = panel->format; + !(format == NULL || lc_index == 0); format = format->next, lc_index--); return format; } static const panel_field_t * -panel_get_sortable_field_by_format(WPanel *panel, gsize lc_index) +panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index) { const panel_field_t *pfield; format_e *format; - format = panel_get_format_field_by_index(panel, lc_index); + format = panel_get_format_field_by_index (panel, lc_index); if (format == NULL) - return NULL; - pfield = panel_get_field_by_title(format->title); + return NULL; + pfield = panel_get_field_by_title (format->title); if (pfield == NULL) - return NULL; + return NULL; if (pfield->sort_routine == NULL) - return NULL; + return NULL; return pfield; } static void -panel_toggle_sort_order_prev(WPanel *panel) +panel_toggle_sort_order_prev (WPanel * panel) { gsize lc_index, i; gchar *title; const panel_field_t *pfield = NULL; - title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey); - lc_index = panel_get_format_field_index_by_name(panel, title); - g_free(title); + title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey); + lc_index = panel_get_format_field_index_by_name (panel, title); + g_free (title); - if (lc_index > 1){ - /* search for prev sortable column in panel format */ - for ( - i = lc_index-1 ; - i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ; - i-- - ); + if (lc_index > 1) + { + /* search for prev sortable column in panel format */ + for (i = lc_index - 1; + i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--); } - if ( pfield == NULL) { - /* Sortable field not found. Try to search in each array */ - for ( - i = panel_get_format_field_count(panel) ; - i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ; - i-- - ); + if (pfield == NULL) + { + /* Sortable field not found. Try to search in each array */ + for (i = panel_get_format_field_count (panel); + i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--); } - if ( pfield == NULL) - return; + if (pfield == NULL) + return; panel->current_sort_field = pfield; - panel_set_sort_order(panel, panel->current_sort_field); + panel_set_sort_order (panel, panel->current_sort_field); } static void -panel_toggle_sort_order_next(WPanel *panel) +panel_toggle_sort_order_next (WPanel * panel) { gsize lc_index, i; const panel_field_t *pfield = NULL; - gsize format_field_count = panel_get_format_field_count(panel); + gsize format_field_count = panel_get_format_field_count (panel); gchar *title; - title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey); - lc_index = panel_get_format_field_index_by_name(panel, title); - g_free(title); + title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey); + lc_index = panel_get_format_field_index_by_name (panel, title); + g_free (title); - if (lc_index != 0 && lc_index != format_field_count){ - /* search for prev sortable column in panel format */ - for ( - i = lc_index; - i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ; - i++ - ); + if (lc_index != 0 && lc_index != format_field_count) + { + /* search for prev sortable column in panel format */ + for (i = lc_index; + i != format_field_count + && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++); } - if ( pfield == NULL) { - /* Sortable field not found. Try to search in each array */ - for ( - i = 0 ; - i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ; - i++ - ); + if (pfield == NULL) + { + /* Sortable field not found. Try to search in each array */ + for (i = 0; + i != format_field_count + && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++); } - if ( pfield == NULL) - return; + if (pfield == NULL) + return; panel->current_sort_field = pfield; - panel_set_sort_order(panel, panel->current_sort_field); + panel_set_sort_order (panel, panel->current_sort_field); } static void -panel_select_sort_order(WPanel *panel) +panel_select_sort_order (WPanel * panel) { const panel_field_t *sort_order; sort_order = sort_box (panel->current_sort_field, &panel->reverse, - &panel->case_sensitive, - &panel->exec_first); + &panel->case_sensitive, &panel->exec_first); if (sort_order == NULL) - return; + return; panel->current_sort_field = sort_order; panel_set_sort_order (panel, panel->current_sort_field); } static void -panel_set_sort_type_by_id(WPanel *panel, const char *name) +panel_set_sort_type_by_id (WPanel * panel, const char *name) { const panel_field_t *sort_order; - if (strcmp(panel->current_sort_field->id, name) != 0) { + if (strcmp (panel->current_sort_field->id, name) != 0) + { sort_order = panel_get_field_by_id (name); if (sort_order == NULL) - return; - panel->current_sort_field = sort_order; - } else { - panel->reverse = ! panel->reverse; + return; + panel->current_sort_field = sort_order; + } + else + { + panel->reverse = !panel->reverse; } panel_set_sort_order (panel, panel->current_sort_field); } typedef void (*panel_key_callback) (WPanel *); -static void cmd_do_enter(WPanel *wp) { (void) do_enter(wp); } -static void cmd_view_simple(WPanel *wp) { (void) wp; view_simple_cmd(); } -static void cmd_edit_new(WPanel *wp) { (void) wp; edit_cmd_new(); } -static void cmd_copy_local(WPanel *wp) { (void) wp; copy_cmd_local(); } -static void cmd_rename_local(WPanel *wp) { (void) wp; rename_cmd_local(); } -static void cmd_delete_local(WPanel *wp) { (void) wp; delete_cmd_local(); } -static void cmd_select(WPanel *wp) { (void) wp; select_cmd(); } -static void cmd_unselect(WPanel *wp) { (void) wp; unselect_cmd(); } -static void cmd_reverse_selection(WPanel *wp) { (void) wp; reverse_selection_cmd(); } +static void +cmd_do_enter (WPanel * wp) +{ + (void) do_enter (wp); +} +static void +cmd_view_simple (WPanel * wp) +{ + (void) wp; + view_simple_cmd (); +} +static void +cmd_edit_new (WPanel * wp) +{ + (void) wp; + edit_cmd_new (); +} +static void +cmd_copy_local (WPanel * wp) +{ + (void) wp; + copy_cmd_local (); +} +static void +cmd_rename_local (WPanel * wp) +{ + (void) wp; + rename_cmd_local (); +} +static void +cmd_delete_local (WPanel * wp) +{ + (void) wp; + delete_cmd_local (); +} +static void +cmd_select (WPanel * wp) +{ + (void) wp; + select_cmd (); +} +static void +cmd_unselect (WPanel * wp) +{ + (void) wp; + unselect_cmd (); +} +static void +cmd_reverse_selection (WPanel * wp) +{ + (void) wp; + reverse_selection_cmd (); +} static cb_ret_t -panel_execute_cmd (WPanel *panel, unsigned long command) +panel_execute_cmd (WPanel * panel, unsigned long command) { int res = MSG_HANDLED; - switch (command) { + switch (command) + { case CK_PanelChdirOtherPanel: chdir_other_panel (panel); break; @@ -2724,149 +2941,161 @@ panel_execute_cmd (WPanel *panel, unsigned long command) sync_other_panel (panel); break; case CK_PanelSelectSortOrder: - panel_select_sort_order(panel); + panel_select_sort_order (panel); break; case CK_PanelToggleSortOrderPrev: - panel_toggle_sort_order_prev(panel); + panel_toggle_sort_order_prev (panel); break; case CK_PanelToggleSortOrderNext: - panel_toggle_sort_order_next(panel); + panel_toggle_sort_order_next (panel); break; case CK_PanelReverseSort: - panel->reverse = ! panel->reverse; + panel->reverse = !panel->reverse; panel_set_sort_order (panel, panel->current_sort_field); break; case CK_PanelSortOrderByName: - panel_set_sort_type_by_id(panel, "name"); + panel_set_sort_type_by_id (panel, "name"); break; case CK_PanelSortOrderByExt: - panel_set_sort_type_by_id(panel, "extension"); + panel_set_sort_type_by_id (panel, "extension"); break; case CK_PanelSortOrderBySize: - panel_set_sort_type_by_id(panel, "size"); + panel_set_sort_type_by_id (panel, "size"); break; case CK_PanelSortOrderByMTime: - panel_set_sort_type_by_id(panel, "mtime"); + panel_set_sort_type_by_id (panel, "mtime"); break; } - return res; + return res; } static cb_ret_t -panel_key (WPanel *panel, int key) +panel_key (WPanel * panel, int key) { size_t i; unsigned long res, command; - for (i = 0; panel_map[i].key != 0; i++) { - if (key == panel_map[i].key) { - int old_searching = panel->searching; + for (i = 0; panel_map[i].key != 0; i++) + { + if (key == panel_map[i].key) + { + int old_searching = panel->searching; - if (panel_map[i].command != CK_PanelStartSearch) - panel->searching = 0; + if (panel_map[i].command != CK_PanelStartSearch) + panel->searching = 0; - command = panel_map[i].command; - res = panel_execute_cmd (panel, command); + command = panel_map[i].command; + res = panel_execute_cmd (panel, command); - if (res == MSG_NOT_HANDLED) - return res; + if (res == MSG_NOT_HANDLED) + return res; - if (panel->searching != old_searching) - display_mini_info (panel); - return MSG_HANDLED; - } + if (panel->searching != old_searching) + display_mini_info (panel); + return MSG_HANDLED; + } } - if (torben_fj_mode && key == ALT ('h')) { - goto_middle_file (panel); - return MSG_HANDLED; + if (torben_fj_mode && key == ALT ('h')) + { + goto_middle_file (panel); + return MSG_HANDLED; } - if (is_abort_char (key)) { - panel->searching = 0; - display_mini_info (panel); - return MSG_HANDLED; + if (is_abort_char (key)) + { + panel->searching = 0; + display_mini_info (panel); + return MSG_HANDLED; } /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */ - if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) { - if (panel->searching) { - do_search (panel, key); - return MSG_HANDLED; - } + if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) + { + if (panel->searching) + { + do_search (panel, key); + return MSG_HANDLED; + } - if (!command_prompt) { - start_search (panel); - do_search (panel, key); - return MSG_HANDLED; - } + if (!command_prompt) + { + start_search (panel); + do_search (panel, key); + return MSG_HANDLED; + } } return MSG_NOT_HANDLED; } static cb_ret_t -panel_callback (Widget *w, widget_msg_t msg, int parm) +panel_callback (Widget * w, widget_msg_t msg, int parm) { WPanel *panel = (WPanel *) w; WButtonBar *bb; - switch (msg) { + switch (msg) + { case WIDGET_DRAW: - paint_panel (panel); - return MSG_HANDLED; + paint_panel (panel); + return MSG_HANDLED; case WIDGET_FOCUS: - current_panel = panel; - panel->active = 1; - if (mc_chdir (panel->cwd) != 0) { - char *cwd = strip_password (g_strdup (panel->cwd), 1); - message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), - cwd, unix_error_string (errno)); - g_free(cwd); - } else - subshell_chdir (panel->cwd); + current_panel = panel; + panel->active = 1; + if (mc_chdir (panel->cwd) != 0) + { + char *cwd = strip_password (g_strdup (panel->cwd), 1); + message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), + cwd, unix_error_string (errno)); + g_free (cwd); + } + else + subshell_chdir (panel->cwd); - update_xterm_title_path (); - select_item (panel); - show_dir (panel); - paint_dir (panel); - panel->dirty = 0; + update_xterm_title_path (); + select_item (panel); + show_dir (panel); + paint_dir (panel); + panel->dirty = 0; - bb = find_buttonbar (panel->widget.parent); - midnight_set_buttonbar (bb); - buttonbar_redraw (bb); - return MSG_HANDLED; + bb = find_buttonbar (panel->widget.parent); + midnight_set_buttonbar (bb); + buttonbar_redraw (bb); + return MSG_HANDLED; case WIDGET_UNFOCUS: - /* Janne: look at this for the multiple panel options */ - if (panel->searching){ - panel->searching = 0; - display_mini_info (panel); - } - panel->active = 0; - show_dir (panel); - unselect_item (panel); - return MSG_HANDLED; + /* Janne: look at this for the multiple panel options */ + if (panel->searching) + { + panel->searching = 0; + display_mini_info (panel); + } + panel->active = 0; + show_dir (panel); + unselect_item (panel); + return MSG_HANDLED; case WIDGET_KEY: - return panel_key (panel, parm); + return panel_key (panel, parm); case WIDGET_DESTROY: - panel_destroy (panel); - return MSG_HANDLED; + panel_destroy (panel); + return MSG_HANDLED; default: - return default_proc (msg, parm); + return default_proc (msg, parm); } } void -file_mark (WPanel *panel, int lc_index, int val) +file_mark (WPanel * panel, int lc_index, int val) { - if (panel->dir.list[lc_index].f.marked != val) { - panel->dir.list[lc_index].f.marked = val; - panel->dirty = 1; + if (panel->dir.list[lc_index].f.marked != val) + { + panel->dir.list[lc_index].f.marked = val; + panel->dirty = 1; } } @@ -2876,30 +3105,31 @@ file_mark (WPanel *panel, int lc_index, int val) static int mouse_marking = 0; static void -mouse_toggle_mark (WPanel *panel) +mouse_toggle_mark (WPanel * panel) { do_mark_file (panel, 0); mouse_marking = selection (panel)->f.marked; } static void -mouse_set_mark (WPanel *panel) +mouse_set_mark (WPanel * panel) { if (mouse_marking && !(selection (panel)->f.marked)) - do_mark_file (panel, 0); + do_mark_file (panel, 0); else if (!mouse_marking && (selection (panel)->f.marked)) - do_mark_file (panel, 0); + do_mark_file (panel, 0); } static int -mark_if_marking (WPanel *panel, Gpm_Event *event) +mark_if_marking (WPanel * panel, Gpm_Event * event) { - if (event->buttons & GPM_B_RIGHT){ - if (event->type & GPM_DOWN) - mouse_toggle_mark (panel); - else - mouse_set_mark (panel); - return 1; + if (event->buttons & GPM_B_RIGHT) + { + if (event->type & GPM_DOWN) + mouse_toggle_mark (panel); + else + mouse_set_mark (panel); + return 1; } return 0; } @@ -2909,7 +3139,7 @@ mark_if_marking (WPanel *panel, Gpm_Event *event) * sorted on that column. */ static void -mouse_sort_col(Gpm_Event *event, WPanel *panel) +mouse_sort_col (Gpm_Event * event, WPanel * panel) { int i; const char *lc_sort_name = NULL; @@ -2917,37 +3147,44 @@ mouse_sort_col(Gpm_Event *event, WPanel *panel) format_e *format; gchar *title; - for (i = 0, format = panel->format; format != NULL; format = format->next) { - i += format->field_len; - if (event->x < i + 1) { - /* found column */ - lc_sort_name = format->title; - break; - } + for (i = 0, format = panel->format; format != NULL; format = format->next) + { + i += format->field_len; + if (event->x < i + 1) + { + /* found column */ + lc_sort_name = format->title; + break; + } } if (lc_sort_name == NULL) - return; + return; - for(i = 0; panel_fields[i].id != NULL; i++) { - title = panel_get_title_without_hotkey(panel_fields[i].title_hotkey); - if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine) { - col_sort_format = &panel_fields[i]; - g_free(title); - break; - } - g_free(title); + for (i = 0; panel_fields[i].id != NULL; i++) + { + title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey); + if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine) + { + col_sort_format = &panel_fields[i]; + g_free (title); + break; + } + g_free (title); } if (!col_sort_format) - return; + return; - if (panel->current_sort_field == col_sort_format) { - /* reverse the sort if clicked column is already the sorted column */ - panel->reverse = !panel->reverse; - } else { + if (panel->current_sort_field == col_sort_format) + { + /* reverse the sort if clicked column is already the sorted column */ + panel->reverse = !panel->reverse; + } + else + { /* new sort is forced to be ascending */ - panel->reverse = 0; + panel->reverse = 0; } panel_set_sort_order (panel, col_sort_format); } @@ -2958,121 +3195,138 @@ mouse_sort_col(Gpm_Event *event, WPanel *panel) * If the event is redirected to the menu, *redir is set to 1. */ static int -do_panel_event (Gpm_Event *event, WPanel *panel, int *redir) +do_panel_event (Gpm_Event * event, WPanel * panel, int *redir) { const int lines = llines (panel); const gboolean is_active = dlg_widget_active (panel); const gboolean mouse_down = (event->type & GPM_DOWN) != 0; /* "." button show/hide hidden files */ - if (event->type & GPM_DOWN && event->x == panel->widget.cols - 5 && event->y == 1) { - toggle_show_hidden(); - repaint_screen (); - return MOU_NORMAL; + if (event->type & GPM_DOWN && event->x == panel->widget.cols - 5 && event->y == 1) + { + toggle_show_hidden (); + repaint_screen (); + return MOU_NORMAL; } /* "<" button */ - if (mouse_down && event->y == 1 && event->x == 2) { - directory_history_prev (panel); - return MOU_NORMAL; + if (mouse_down && event->y == 1 && event->x == 2) + { + directory_history_prev (panel); + return MOU_NORMAL; } /* ">" button */ - if (mouse_down && event->y == 1 && event->x == panel->widget.cols - 1) { - directory_history_next (panel); - return MOU_NORMAL; + if (mouse_down && event->y == 1 && event->x == panel->widget.cols - 1) + { + directory_history_next (panel); + return MOU_NORMAL; } /* "^" button */ - if (mouse_down && event->y == 1 && event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2) { - directory_history_list (panel); - return MOU_NORMAL; + if (mouse_down && event->y == 1 && event->x >= panel->widget.cols - 4 + && event->x <= panel->widget.cols - 2) + { + directory_history_list (panel); + return MOU_NORMAL; } /* sort on clicked column */ - if (event->type & GPM_DOWN && event->y == 2) { - mouse_sort_col(event,panel); - return MOU_NORMAL; + if (event->type & GPM_DOWN && event->y == 2) + { + mouse_sort_col (event, panel); + return MOU_NORMAL; } /* rest of the upper frame, the menu is invisible - call menu */ - if (mouse_down && event->y == 1 && !menubar_visible) { - *redir = 1; - event->x += panel->widget.x; - return the_menubar->widget.mouse (event, the_menubar); + if (mouse_down && event->y == 1 && !menubar_visible) + { + *redir = 1; + event->x += panel->widget.x; + return the_menubar->widget.mouse (event, the_menubar); } /* Mouse wheel events */ - if (mouse_down && (event->buttons & GPM_B_UP)) { - if (is_active) { - if (panel->top_file > 0) - prev_page (panel); - else /* We are in first page */ - move_up (panel); - } - return MOU_NORMAL; + if (mouse_down && (event->buttons & GPM_B_UP)) + { + if (is_active) + { + if (panel->top_file > 0) + prev_page (panel); + else /* We are in first page */ + move_up (panel); + } + return MOU_NORMAL; } - if (mouse_down && (event->buttons & GPM_B_DOWN)) { - if (is_active) { - if (panel->top_file + ITEMS (panel) < panel->count) - next_page (panel); - else /* We are in last page */ - move_down (panel); - } - return MOU_NORMAL; + if (mouse_down && (event->buttons & GPM_B_DOWN)) + { + if (is_active) + { + if (panel->top_file + ITEMS (panel) < panel->count) + next_page (panel); + else /* We are in last page */ + move_down (panel); + } + return MOU_NORMAL; } event->y -= 2; - if ((event->type & (GPM_DOWN | GPM_DRAG))) { - int my_index; + if ((event->type & (GPM_DOWN | GPM_DRAG))) + { + int my_index; - if (!is_active) - change_panel (); + if (!is_active) + change_panel (); - if (event->y <= 0) { - mark_if_marking (panel, event); - if (mouse_move_pages) - prev_page (panel); - else - move_up (panel); - return MOU_REPEAT; - } + if (event->y <= 0) + { + mark_if_marking (panel, event); + if (mouse_move_pages) + prev_page (panel); + else + move_up (panel); + return MOU_REPEAT; + } - if (!((panel->top_file + event->y <= panel->count) && event->y <= lines)) { - mark_if_marking (panel, event); - if (mouse_move_pages) - next_page (panel); - else - move_down (panel); - return MOU_REPEAT; - } + if (!((panel->top_file + event->y <= panel->count) && event->y <= lines)) + { + mark_if_marking (panel, event); + if (mouse_move_pages) + next_page (panel); + else + move_down (panel); + return MOU_REPEAT; + } - my_index = panel->top_file + event->y - 1; - if (panel->split && (event->x > ((panel->widget.cols - 2) / 2))) - my_index += llines (panel); + my_index = panel->top_file + event->y - 1; + if (panel->split && (event->x > ((panel->widget.cols - 2) / 2))) + my_index += llines (panel); - if (my_index >= panel->count) - my_index = panel->count - 1; + if (my_index >= panel->count) + my_index = panel->count - 1; - if (my_index != panel->selected) { - unselect_item (panel); - panel->selected = my_index; - select_item (panel); - } + if (my_index != panel->selected) + { + unselect_item (panel); + panel->selected = my_index; + select_item (panel); + } - /* This one is new */ - mark_if_marking (panel, event); - } else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) { - if (event->y > 0 && event->y <= lines) - do_enter (panel); + /* This one is new */ + mark_if_marking (panel, event); + } + else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) + { + if (event->y > 0 && event->y <= lines) + do_enter (panel); } return MOU_NORMAL; } /* Mouse callback of the panel */ static int -panel_event (Gpm_Event *event, void *data) +panel_event (Gpm_Event * event, void *data) { WPanel *panel = data; int ret; @@ -3080,59 +3334,62 @@ panel_event (Gpm_Event *event, void *data) ret = do_panel_event (event, panel, &redir); if (!redir) - paint_panel (panel); + paint_panel (panel); return ret; } void -panel_re_sort (WPanel *panel) +panel_re_sort (WPanel * panel) { char *filename; - int i; + int i; if (panel == NULL) - return; + return; filename = g_strdup (selection (panel)->fname); unselect_item (panel); - do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count-1, panel->reverse, + do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count - 1, panel->reverse, panel->case_sensitive, panel->exec_first); panel->selected = -1; - for (i = panel->count; i; i--){ - if (!strcmp (panel->dir.list [i-1].fname, filename)){ - panel->selected = i-1; - break; - } + for (i = panel->count; i; i--) + { + if (!strcmp (panel->dir.list[i - 1].fname, filename)) + { + panel->selected = i - 1; + break; + } } g_free (filename); - panel->top_file = panel->selected - ITEMS (panel)/2; + panel->top_file = panel->selected - ITEMS (panel) / 2; select_item (panel); panel->dirty = 1; } void -panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order) +panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order) { if (sort_order == 0) - return; + return; panel->current_sort_field = sort_order; /* The directory is already sorted, we have to load the unsorted stuff */ - if (sort_order->sort_routine == (sortfn *) unsorted){ - char *current_file; + if (sort_order->sort_routine == (sortfn *) unsorted) + { + char *current_file; - current_file = g_strdup (panel->dir.list [panel->selected].fname); - panel_reload (panel); - try_to_select (panel, current_file); - g_free (current_file); + current_file = g_strdup (panel->dir.list[panel->selected].fname); + panel_reload (panel); + try_to_select (panel, current_file); + g_free (current_file); } panel_re_sort (panel); } void -set_panel_encoding (WPanel *panel) +set_panel_encoding (WPanel * panel) { const char *encoding = NULL; char *cd_path; @@ -3143,28 +3400,31 @@ set_panel_encoding (WPanel *panel) r = select_charset (-1, -1, default_source_codepage, FALSE); if (r == SELECT_CHARSET_CANCEL) - return; /* Cancel */ + return; /* Cancel */ - if (r == SELECT_CHARSET_NO_TRANSLATE) { - /* No translation */ - errmsg = init_translation_table (display_codepage, display_codepage); - cd_path = remove_encoding_from_path (panel->cwd); - do_panel_cd (panel, cd_path, 0); - g_free (cd_path); - return; + if (r == SELECT_CHARSET_NO_TRANSLATE) + { + /* No translation */ + errmsg = init_translation_table (display_codepage, display_codepage); + cd_path = remove_encoding_from_path (panel->cwd); + do_panel_cd (panel, cd_path, 0); + g_free (cd_path); + return; } source_codepage = r; errmsg = init_translation_table (source_codepage, display_codepage); - if (errmsg) { + if (errmsg) + { message (D_ERROR, MSG_ERROR, "%s", errmsg); return; } encoding = get_codepage_id (source_codepage); #endif - if (encoding != NULL) { + if (encoding != NULL) + { cd_path = add_encoding_to_path (panel->cwd, encoding); if (!do_panel_cd (panel, cd_path, 0)) message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path); @@ -3173,83 +3433,89 @@ set_panel_encoding (WPanel *panel) } static void -reload_panelized (WPanel *panel) +reload_panelized (WPanel * panel) { int i, j; dir_list *list = &panel->dir; if (panel != current_panel) - mc_chdir (panel->cwd); + mc_chdir (panel->cwd); - for (i = 0, j = 0; i < panel->count; i++) { - if (list->list[i].f.marked) { - /* Unmark the file in advance. In case the following mc_lstat - * fails we are done, else we have to mark the file again - * (Note: do_file_mark depends on a valid "list->list [i].buf"). - * IMO that's the best way to update the panel's summary status - * -- Norbert - */ - do_file_mark (panel, i, 0); - } - if (mc_lstat (list->list[i].fname, &list->list[i].st)) { - g_free (list->list[i].fname); - continue; - } - if (list->list[i].f.marked) - do_file_mark (panel, i, 1); - if (j != i) - list->list[j] = list->list[i]; - j++; + for (i = 0, j = 0; i < panel->count; i++) + { + if (list->list[i].f.marked) + { + /* Unmark the file in advance. In case the following mc_lstat + * fails we are done, else we have to mark the file again + * (Note: do_file_mark depends on a valid "list->list [i].buf"). + * IMO that's the best way to update the panel's summary status + * -- Norbert + */ + do_file_mark (panel, i, 0); + } + if (mc_lstat (list->list[i].fname, &list->list[i].st)) + { + g_free (list->list[i].fname); + continue; + } + if (list->list[i].f.marked) + do_file_mark (panel, i, 1); + if (j != i) + list->list[j] = list->list[i]; + j++; } if (j == 0) - panel->count = set_zero_dir (list) ? 1 : 0; + panel->count = set_zero_dir (list) ? 1 : 0; else - panel->count = j; + panel->count = j; if (panel != current_panel) - mc_chdir (current_panel->cwd); + mc_chdir (current_panel->cwd); } static void -update_one_panel_widget (WPanel *panel, int force_update, - const char *current_file) +update_one_panel_widget (WPanel * panel, int force_update, const char *current_file) { int free_pointer; char *my_current_file = NULL; - if (force_update & UP_RELOAD) { - panel->is_panelized = 0; - mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0); - memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); + if (force_update & UP_RELOAD) + { + panel->is_panelized = 0; + mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0); + memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); } /* If current_file == -1 (an invalid pointer) then preserve selection */ - if (current_file == UP_KEEPSEL) { - free_pointer = 1; - my_current_file = g_strdup (panel->dir.list[panel->selected].fname); - current_file = my_current_file; - } else - free_pointer = 0; + if (current_file == UP_KEEPSEL) + { + free_pointer = 1; + my_current_file = g_strdup (panel->dir.list[panel->selected].fname); + current_file = my_current_file; + } + else + free_pointer = 0; if (panel->is_panelized) - reload_panelized (panel); + reload_panelized (panel); else - panel_reload (panel); + panel_reload (panel); try_to_select (panel, current_file); panel->dirty = 1; if (free_pointer) - g_free (my_current_file); + g_free (my_current_file); } static void update_one_panel (int which, int force_update, const char *current_file) { - if (get_display_type (which) == view_listing) { - WPanel *panel; - panel = (WPanel *) get_panel_widget (which); - update_one_panel_widget (panel, force_update, current_file); + if (get_display_type (which) == view_listing) + { + WPanel *panel; + panel = (WPanel *) get_panel_widget (which); + update_one_panel_widget (panel, force_update, current_file); } } @@ -3260,7 +3526,7 @@ update_one_panel (int which, int force_update, const char *current_file) * * if force_update has the UP_ONLY_CURRENT bit toggled on, then it * will not reload the other panel. -*/ + */ void update_panels (int force_update, const char *current_file) { @@ -3269,155 +3535,149 @@ update_panels (int force_update, const char *current_file) update_one_panel (get_current_index (), force_update, current_file); if (reload_other) - update_one_panel (get_other_index (), force_update, UP_KEEPSEL); + update_one_panel (get_other_index (), force_update, UP_KEEPSEL); if (get_current_type () == view_listing) - panel = (WPanel *) get_panel_widget (get_current_index ()); + panel = (WPanel *) get_panel_widget (get_current_index ()); else - panel = (WPanel *) get_panel_widget (get_other_index ()); + panel = (WPanel *) get_panel_widget (get_other_index ()); mc_chdir (panel->cwd); } gsize -panel_get_num_of_sortable_fields(void) +panel_get_num_of_sortable_fields (void) { gsize ret = 0, lc_index; - for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) - if (panel_fields[lc_index].is_user_choice) - ret++; + for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++) + if (panel_fields[lc_index].is_user_choice) + ret++; return ret; } const char ** -panel_get_sortable_fields(gsize *array_size) +panel_get_sortable_fields (gsize * array_size) { char **ret; gsize lc_index, i; - lc_index = panel_get_num_of_sortable_fields(); + lc_index = panel_get_num_of_sortable_fields (); ret = g_try_new0 (char *, lc_index + 1); if (ret == NULL) return NULL; if (array_size != NULL) - *array_size = lc_index; + *array_size = lc_index; - lc_index=0; + lc_index = 0; - for(i=0; panel_fields[i].id != NULL; i ++) - if (panel_fields[i].is_user_choice) - ret[lc_index++] = g_strdup(_(panel_fields[i].title_hotkey)); - return (const char**) ret; + for (i = 0; panel_fields[i].id != NULL; i++) + if (panel_fields[i].is_user_choice) + ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey)); + return (const char **) ret; } const panel_field_t * -panel_get_field_by_id(const char *name) +panel_get_field_by_id (const char *name) { gsize lc_index; - for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) - if ( - panel_fields[lc_index].id != NULL && - strcmp(name, panel_fields[lc_index].id) == 0 - ) - return &panel_fields[lc_index]; + for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++) + if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0) + return &panel_fields[lc_index]; return NULL; } const panel_field_t * -panel_get_field_by_title_hotkey(const char *name) +panel_get_field_by_title_hotkey (const char *name) { gsize lc_index; - for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) - if ( - panel_fields[lc_index].title_hotkey != NULL && - strcmp(name, _(panel_fields[lc_index].title_hotkey)) == 0 - ) - return &panel_fields[lc_index]; + for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++) + if (panel_fields[lc_index].title_hotkey != NULL && + strcmp (name, _(panel_fields[lc_index].title_hotkey)) == 0) + return &panel_fields[lc_index]; return NULL; } const panel_field_t * -panel_get_field_by_title(const char *name) +panel_get_field_by_title (const char *name) { gsize lc_index; gchar *title = NULL; - for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) { - title = panel_get_title_without_hotkey(panel_fields[lc_index].title_hotkey); - if ( - panel_fields[lc_index].title_hotkey != NULL && - strcmp(name, title) == 0 - ) { - g_free(title); - return &panel_fields[lc_index]; - } + for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++) + { + title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey); + if (panel_fields[lc_index].title_hotkey != NULL && strcmp (name, title) == 0) + { + g_free (title); + return &panel_fields[lc_index]; + } } - g_free(title); + g_free (title); return NULL; } gsize -panel_get_num_of_user_possible_fields(void) +panel_get_num_of_user_possible_fields (void) { gsize ret = 0, lc_index; - for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) - if (panel_fields[lc_index].use_in_user_format) - ret++; + for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++) + if (panel_fields[lc_index].use_in_user_format) + ret++; return ret; } const char ** -panel_get_user_possible_fields(gsize *array_size) +panel_get_user_possible_fields (gsize * array_size) { char **ret; gsize lc_index, i; - lc_index = panel_get_num_of_user_possible_fields(); + lc_index = panel_get_num_of_user_possible_fields (); ret = g_try_new0 (char *, lc_index + 1); if (ret == NULL) return NULL; if (array_size != NULL) - *array_size = lc_index; + *array_size = lc_index; - lc_index=0; + lc_index = 0; - for(i=0; panel_fields[i].id != NULL; i ++) - if (panel_fields[i].use_in_user_format) - ret[lc_index++] = g_strdup(_(panel_fields[i].title_hotkey)); - return (const char**) ret; + for (i = 0; panel_fields[i].id != NULL; i++) + if (panel_fields[i].use_in_user_format) + ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey)); + return (const char **) ret; } void -panel_init(void) +panel_init (void) { - panel_sort_up_sign = mc_skin_get("widget-common","sort-sign-up","'"); - panel_sort_down_sign = mc_skin_get("widget-common","sort-sign-down",","); + panel_sort_up_sign = mc_skin_get ("widget-common", "sort-sign-up", "'"); + panel_sort_down_sign = mc_skin_get ("widget-common", "sort-sign-down", ","); - panel_hiddenfiles_sign_show = mc_skin_get("widget-panel", "hiddenfiles-sign-show", "."); - panel_hiddenfiles_sign_hide = mc_skin_get("widget-panel", "hiddenfiles-sign-hide", "."); - panel_history_prev_item_sign = mc_skin_get("widget-panel", "history-prev-item-sign", "<"); - panel_history_next_item_sign = mc_skin_get("widget-panel", "history-next-item-sign", ">"); - panel_history_show_list_sign = mc_skin_get("widget-panel", "history-show-list-sign", "^"); + panel_hiddenfiles_sign_show = mc_skin_get ("widget-panel", "hiddenfiles-sign-show", "."); + panel_hiddenfiles_sign_hide = mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", "."); + panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<"); + panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">"); + panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^"); } void -panel_deinit(void) +panel_deinit (void) { - g_free(panel_sort_up_sign); - g_free(panel_sort_down_sign); + g_free (panel_sort_up_sign); + g_free (panel_sort_down_sign); - g_free(panel_hiddenfiles_sign_show); - g_free(panel_hiddenfiles_sign_hide); - g_free(panel_history_prev_item_sign); - g_free(panel_history_next_item_sign); - g_free(panel_history_show_list_sign); + g_free (panel_hiddenfiles_sign_show); + g_free (panel_hiddenfiles_sign_hide); + g_free (panel_history_prev_item_sign); + g_free (panel_history_next_item_sign); + g_free (panel_history_show_list_sign); } diff --git a/src/setup.c b/src/setup.c index ad9eba557..78dfb1b65 100644 --- a/src/setup.c +++ b/src/setup.c @@ -32,7 +32,7 @@ #include "lib/tty/tty.h" #include "lib/tty/key.h" -#include "lib/tty/mouse.h" /* To make view.h happy */ +#include "lib/tty/mouse.h" /* To make view.h happy */ #include "lib/vfs/mc-vfs/vfs.h" #include "lib/mcconfig.h" #include "lib/fileloc.h" @@ -45,22 +45,22 @@ # include "lib/vfs/mc-vfs/ftpfs.h" # include "lib/vfs/mc-vfs/fish.h" #endif -#include "lib/strutil.h" /* str_isutf8 () */ +#include "lib/strutil.h" /* str_isutf8 () */ #include "args.h" #include "dir.h" #include "panel.h" #include "main.h" -#include "tree.h" /* xtree_mode */ +#include "tree.h" /* xtree_mode */ #include "setup.h" -#include "src/viewer/mcviewer.h" /* For the externs */ -#include "hotlist.h" /* load/save/done hotlist */ -#include "panelize.h" /* load/save/done panelize */ +#include "src/viewer/mcviewer.h" /* For the externs */ +#include "hotlist.h" /* load/save/done hotlist */ +#include "panelize.h" /* load/save/done panelize */ #include "layout.h" -#include "menu.h" /* menubar_visible declaration */ +#include "menu.h" /* menubar_visible declaration */ #include "cmd.h" -#include "file.h" /* safe_delete */ -#include "keybind.h" /* lookup_action */ +#include "file.h" /* safe_delete */ +#include "keybind.h" /* lookup_action */ #include "wtools.h" #ifdef HAVE_CHARSET @@ -75,8 +75,8 @@ extern int num_history_items_recorded; -char *profile_name; /* .mc/ini */ -char *global_profile_name; /* mc.lib */ +char *profile_name; /* .mc/ini */ +char *global_profile_name; /* mc.lib */ char *setup_color_string; char *term_color_string; @@ -90,8 +90,9 @@ panel_view_mode_t startup_right_mode; int saving_setup; int setup_copymove_persistent_attr = 1; -static char *panels_profile_name = NULL; /* .mc/panels.ini */ +static char *panels_profile_name = NULL; /* .mc/panels.ini */ +/* *INDENT-OFF* */ static const struct { const char *key; int list_type; @@ -233,27 +234,33 @@ static const struct { { "select_flags", &select_flags }, { 0, 0 } }; +/* *INDENT-ON* */ extern char *user_recent_timeformat; extern char *user_old_timeformat; /* - In order to use everywhere the same setup - for the locale we use defines -*/ + In order to use everywhere the same setup + for the locale we use defines + */ #define FMTYEAR _("%b %e %Y") #define FMTTIME _("%b %e %H:%M") -static const struct { +static const struct +{ const char *opt_name; char **opt_addr; const char *opt_defval; -} str_options [] = { +} str_options[] = +{ #ifdef USE_INTERNAL_EDIT - { "editor_backup_extension", &option_backup_ext, "~" }, + { + "editor_backup_extension", &option_backup_ext, "~"}, #endif - { "mcview_eof", &mcview_show_eof, "" }, - { NULL, NULL, NULL } + { + "mcview_eof", &mcview_show_eof, ""}, + { + NULL, NULL, NULL} }; void @@ -262,40 +269,43 @@ panel_save_setup (struct WPanel *panel, const char *section) char buffer[BUF_TINY]; size_t i; - mc_config_set_int(mc_panels_config, section, "reverse", panel->reverse); - mc_config_set_int(mc_panels_config, section, "case_sensitive", panel->case_sensitive); - mc_config_set_int(mc_panels_config, section, "exec_first", panel->exec_first); + mc_config_set_int (mc_panels_config, section, "reverse", panel->reverse); + mc_config_set_int (mc_panels_config, section, "case_sensitive", panel->case_sensitive); + mc_config_set_int (mc_panels_config, section, "exec_first", panel->exec_first); - mc_config_set_string(mc_panels_config, section, "sort_order", panel->current_sort_field->id); + mc_config_set_string (mc_panels_config, section, "sort_order", panel->current_sort_field->id); - for (i = 0; list_types [i].key; i++) - if (list_types [i].list_type == panel->list_type){ - mc_config_set_string(mc_panels_config, section, "list_mode", list_types [i].key); - break; - } + for (i = 0; list_types[i].key; i++) + if (list_types[i].list_type == panel->list_type) + { + mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key); + break; + } - mc_config_set_string(mc_panels_config, section, "user_format", panel->user_format); + mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format); - for (i = 0; i < LIST_TYPES; i++){ - g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i); - mc_config_set_string(mc_panels_config, section, buffer, panel->user_status_format [i]); + for (i = 0; i < LIST_TYPES; i++) + { + g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i); + mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]); } - mc_config_set_int(mc_panels_config, section, "user_mini_status", panel->user_mini_status); + mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status); } void save_layout (void) { char *profile; - int i; + int i; profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL); /* Save integer options */ - for (i = 0; layout [i].opt_name; i++){ - mc_config_set_int(mc_main_config, "Layout", layout [i].opt_name, *layout [i].opt_addr); + for (i = 0; layout[i].opt_name; i++) + { + mc_config_set_int (mc_main_config, "Layout", layout[i].opt_name, *layout[i].opt_addr); } mc_config_save_to_file (mc_main_config, profile, NULL); @@ -307,20 +317,22 @@ save_configure (void) { char *profile; GError *error = NULL; - int i; + int i; profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL); /* Save integer options */ for (i = 0; int_options[i].opt_name; i++) - mc_config_set_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr); + mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, + *int_options[i].opt_addr); /* Save string options */ for (i = 0; str_options[i].opt_name != NULL; i++) - mc_config_set_string(mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, *str_options[i].opt_addr); + mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, + *str_options[i].opt_addr); - if (! mc_config_save_to_file (mc_main_config, profile, &error)) - setup_save_config_show_error(profile, &error); + if (!mc_config_save_to_file (mc_main_config, profile, &error)) + setup_save_config_show_error (profile, &error); g_free (profile); } @@ -330,12 +342,12 @@ panel_save_type (const char *section, panel_view_mode_t type) { int i; - for (i = 0; panel_types [i].opt_name != NULL; i++) - if (panel_types [i].opt_type == type) { - mc_config_set_string (mc_panels_config, section, - "display", panel_types [i].opt_name); - break; - } + for (i = 0; panel_types[i].opt_name != NULL; i++) + if (panel_types[i].opt_type == type) + { + mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name); + break; + } } void @@ -344,27 +356,26 @@ save_panel_types (void) panel_view_mode_t type; if ((view_one_file != NULL) || (edit_one_file != NULL)) - return; + return; if (!mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, - "auto_save_setup_panels", auto_save_setup)) - return; + "auto_save_setup_panels", auto_save_setup)) + return; type = get_display_type (0); panel_save_type ("New Left Panel", type); if (type == view_listing) - panel_save_setup (left_panel, left_panel->panel_name); + panel_save_setup (left_panel, left_panel->panel_name); type = get_display_type (1); panel_save_type ("New Right Panel", type); if (type == view_listing) - panel_save_setup (right_panel, right_panel->panel_name); + panel_save_setup (right_panel, right_panel->panel_name); - mc_config_set_string (mc_panels_config, "Dirs" , "other_dir", - get_panel_dir_for (other_panel)); + mc_config_set_string (mc_panels_config, "Dirs", "other_dir", get_panel_dir_for (other_panel)); if (current_panel != NULL) - mc_config_set_string (mc_panels_config, "Dirs" , "current_is_left", - get_current_index () == 0 ? "1" : "0"); + mc_config_set_string (mc_panels_config, "Dirs", "current_is_left", + get_current_index () == 0 ? "1" : "0"); if (mc_panels_config->ini_path == NULL) mc_panels_config->ini_path = g_strdup (panels_profile_name); @@ -391,23 +402,20 @@ save_setup (void) save_panelize (); save_panel_types (); -/* directory_history_save (); */ + /* directory_history_save (); */ #if defined(ENABLE_VFS) && defined (USE_NETCODE) - mc_config_set_string(mc_main_config, "Misc" , "ftpfs_password", - ftpfs_anonymous_passwd); + mc_config_set_string (mc_main_config, "Misc", "ftpfs_password", ftpfs_anonymous_passwd); if (ftpfs_proxy_host) - mc_config_set_string(mc_main_config, "Misc" , "ftp_proxy_host", - ftpfs_proxy_host); + mc_config_set_string (mc_main_config, "Misc", "ftp_proxy_host", ftpfs_proxy_host); #endif /* ENABLE_VFS && USE_NETCODE */ #ifdef HAVE_CHARSET - mc_config_set_string (mc_main_config, "Misc" , "display_codepage", - get_codepage_id( display_codepage )); - mc_config_set_string (mc_main_config, "Misc" , "source_codepage", - get_codepage_id( default_source_codepage )); - mc_config_set_string (mc_main_config, "Misc" , "autodetect_codeset", - autodetect_codeset ); + mc_config_set_string (mc_main_config, "Misc", "display_codepage", + get_codepage_id (display_codepage)); + mc_config_set_string (mc_main_config, "Misc", "source_codepage", + get_codepage_id (default_source_codepage)); + mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset); #endif /* HAVE_CHARSET */ tmp_profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL); ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL); @@ -418,46 +426,50 @@ save_setup (void) } void -panel_load_setup (WPanel *panel, const char *section) +panel_load_setup (WPanel * panel, const char *section) { size_t i; char *buffer, buffer2[BUF_TINY]; - panel->reverse = mc_config_get_int(mc_panels_config, section, "reverse", 0); - panel->case_sensitive = mc_config_get_int(mc_panels_config, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT); - panel->exec_first = mc_config_get_int(mc_panels_config, section, "exec_first", 0); + panel->reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0); + panel->case_sensitive = + mc_config_get_int (mc_panels_config, section, "case_sensitive", + OS_SORT_CASE_SENSITIVE_DEFAULT); + panel->exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0); /* Load sort order */ - buffer = mc_config_get_string(mc_panels_config, section, "sort_order", "name"); - panel->current_sort_field = panel_get_field_by_id(buffer); - if (panel->current_sort_field == NULL ) - panel->current_sort_field = panel_get_field_by_id("name"); + buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name"); + panel->current_sort_field = panel_get_field_by_id (buffer); + if (panel->current_sort_field == NULL) + panel->current_sort_field = panel_get_field_by_id ("name"); - g_free(buffer); + g_free (buffer); /* Load the listing mode */ - buffer = mc_config_get_string(mc_panels_config, section, "list_mode", "full"); + buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full"); panel->list_type = list_full; - for (i = 0; list_types [i].key; i++) - if ( g_strcasecmp (list_types [i].key, buffer) == 0){ - panel->list_type = list_types [i].list_type; - break; - } - g_free(buffer); + for (i = 0; list_types[i].key; i++) + if (g_strcasecmp (list_types[i].key, buffer) == 0) + { + panel->list_type = list_types[i].list_type; + break; + } + g_free (buffer); /* User formats */ g_free (panel->user_format); - panel->user_format = mc_config_get_string(mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT); + panel->user_format = + mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT); - for (i = 0; i < LIST_TYPES; i++){ - g_free (panel->user_status_format [i]); - g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i); - panel->user_status_format [i] = - mc_config_get_string(mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT); + for (i = 0; i < LIST_TYPES; i++) + { + g_free (panel->user_status_format[i]); + g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i); + panel->user_status_format[i] = + mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT); } - panel->user_mini_status = - mc_config_get_int(mc_panels_config, section, "user_mini_status", 0); + panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0); } @@ -466,9 +478,9 @@ load_layout () { int i; - for (i = 0; layout [i].opt_name; i++) - *layout [i].opt_addr = - mc_config_get_int(mc_main_config,"Layout", layout [i].opt_name, *layout [i].opt_addr); + for (i = 0; layout[i].opt_name; i++) + *layout[i].opt_addr = + mc_config_get_int (mc_main_config, "Layout", layout[i].opt_name, *layout[i].opt_addr); } static panel_view_mode_t @@ -481,52 +493,50 @@ setup__load_panel_state (const char *section) /* Load the display mode */ buffer = mc_config_get_string (mc_panels_config, section, "display", "listing"); - for (i = 0; panel_types [i].opt_name != NULL; i++) - if (g_strcasecmp (panel_types [i].opt_name, buffer) == 0) { - mode = panel_types [i].opt_type; - break; - } + for (i = 0; panel_types[i].opt_name != NULL; i++) + if (g_strcasecmp (panel_types[i].opt_name, buffer) == 0) + { + mode = panel_types[i].opt_type; + break; + } g_free (buffer); return mode; } static const char * -setup__is_cfg_group_must_panel_config(const char *grp) +setup__is_cfg_group_must_panel_config (const char *grp) { - if ( - ! strcasecmp("Dirs",grp) || - ! strcasecmp("Temporal:New Right Panel",grp) || - ! strcasecmp("Temporal:New Left Panel",grp) || - ! strcasecmp("New Left Panel",grp) || - ! strcasecmp("New Right Panel",grp) - ) + if (!strcasecmp ("Dirs", grp) || + !strcasecmp ("Temporal:New Right Panel", grp) || + !strcasecmp ("Temporal:New Left Panel", grp) || + !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp)) return grp; return NULL; } static void -setup__move_panels_config_into_separate_file(const char*profile) +setup__move_panels_config_into_separate_file (const char *profile) { mc_config_t *tmp_cfg; char **groups, **curr_grp; const char *need_grp; - if (!exist_file(profile)) + if (!exist_file (profile)) return; - tmp_cfg = mc_config_init(profile); + tmp_cfg = mc_config_init (profile); if (!tmp_cfg) return; curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL); if (!groups) { - mc_config_deinit(tmp_cfg); + mc_config_deinit (tmp_cfg); return; } while (*curr_grp) { - if ( setup__is_cfg_group_must_panel_config(*curr_grp) == NULL) + if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL) { mc_config_del_group (tmp_cfg, *curr_grp); } @@ -534,12 +544,12 @@ setup__move_panels_config_into_separate_file(const char*profile) } mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL); - mc_config_deinit(tmp_cfg); + mc_config_deinit (tmp_cfg); - tmp_cfg = mc_config_init(profile); + tmp_cfg = mc_config_init (profile); if (!tmp_cfg) { - g_strfreev(groups); + g_strfreev (groups); return; } @@ -547,16 +557,16 @@ setup__move_panels_config_into_separate_file(const char*profile) while (*curr_grp) { - need_grp = setup__is_cfg_group_must_panel_config(*curr_grp); - if ( need_grp != NULL) + need_grp = setup__is_cfg_group_must_panel_config (*curr_grp); + if (need_grp != NULL) { mc_config_del_group (tmp_cfg, need_grp); } curr_grp++; } - g_strfreev(groups); + g_strfreev (groups); mc_config_save_file (tmp_cfg, NULL); - mc_config_deinit(tmp_cfg); + mc_config_deinit (tmp_cfg); } @@ -573,62 +583,65 @@ setup__move_panels_config_into_separate_file(const char*profile) Newly allocated path to config name or NULL if file not found If config_file_name is a relative path, then search config in stantart pathes */ -static char* -load_setup_get_full_config_name(const char *subdir, const char *config_file_name) +static char * +load_setup_get_full_config_name (const char *subdir, const char *config_file_name) { /* - TODO: IMHO, in future this function must be placed into mc_config module. - Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir; - home_mc => mc_user_homedir - */ + TODO: IMHO, in future this function must be placed into mc_config module. + Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir; + home_mc => mc_user_homedir + */ char *lc_basename, *ret; if (config_file_name == NULL) - return NULL; + return NULL; if (g_path_is_absolute (config_file_name)) - return g_strdup(config_file_name); + return g_strdup (config_file_name); - lc_basename = g_path_get_basename(config_file_name); + lc_basename = g_path_get_basename (config_file_name); if (lc_basename == NULL) - return NULL; + return NULL; if (subdir) - ret = g_build_filename (home_dir, MC_USERCONF_DIR, subdir, lc_basename, NULL); + ret = g_build_filename (home_dir, MC_USERCONF_DIR, subdir, lc_basename, NULL); else - ret = g_build_filename (home_dir, MC_USERCONF_DIR, lc_basename, NULL); + ret = g_build_filename (home_dir, MC_USERCONF_DIR, lc_basename, NULL); - if (exist_file(ret)) { - g_free(lc_basename); - return ret; + if (exist_file (ret)) + { + g_free (lc_basename); + return ret; } - g_free(ret); + g_free (ret); if (subdir) - ret = g_build_filename (mc_home, subdir, lc_basename, NULL); + ret = g_build_filename (mc_home, subdir, lc_basename, NULL); else - ret = g_build_filename (mc_home, lc_basename, NULL); + ret = g_build_filename (mc_home, lc_basename, NULL); - if (exist_file(ret)) { - g_free(lc_basename); - return ret; + if (exist_file (ret)) + { + g_free (lc_basename); + return ret; } - g_free(ret); + g_free (ret); if (subdir) - ret = g_build_filename (mc_home_alt, subdir, lc_basename, NULL); + ret = g_build_filename (mc_home_alt, subdir, lc_basename, NULL); else - ret = g_build_filename (mc_home_alt, lc_basename, NULL); + ret = g_build_filename (mc_home_alt, lc_basename, NULL); - if (exist_file(ret)) { - g_free(lc_basename); - return ret; + if (exist_file (ret)) + { + g_free (lc_basename); + return ret; } - g_free(ret); - g_free(lc_basename); + g_free (ret); + g_free (lc_basename); return NULL; } @@ -639,71 +652,73 @@ load_setup_get_full_config_name(const char *subdir, const char *config_file_name */ static void -load_setup_init_config_from_file(mc_config_t **config, const char *fname) +load_setup_init_config_from_file (mc_config_t ** config, const char *fname) { /* - TODO: IMHO, in future this function must be placed into mc_config module. - */ - if (exist_file(fname)) { - if (*config) - mc_config_read_file( *config, fname); - else - *config = mc_config_init(fname); + TODO: IMHO, in future this function must be placed into mc_config module. + */ + if (exist_file (fname)) + { + if (*config) + mc_config_read_file (*config, fname); + else + *config = mc_config_init (fname); } } static mc_config_t * -load_setup_get_keymap_profile_config(void) +load_setup_get_keymap_profile_config (void) { /* - TODO: IMHO, in future this function must be placed into mc_config module. - */ - mc_config_t *keymap_config = NULL ; + TODO: IMHO, in future this function must be placed into mc_config module. + */ + mc_config_t *keymap_config = NULL; char *fname, *fname2; /* 1) /usr/share/mc (mc_home_alt) */ fname = g_build_filename (mc_home_alt, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file( &keymap_config, fname); - g_free(fname); + load_setup_init_config_from_file (&keymap_config, fname); + g_free (fname); /* 2) /etc/mc (mc_home) */ fname = g_build_filename (mc_home, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file( &keymap_config, fname); - g_free(fname); + load_setup_init_config_from_file (&keymap_config, fname); + g_free (fname); /* 3) ~/.mc (home_dir?) */ fname = g_build_filename (home_dir, MC_USERCONF_DIR, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file( &keymap_config, fname); - g_free(fname); + load_setup_init_config_from_file (&keymap_config, fname); + g_free (fname); - /* 4) main config; [Midnight Commander] -> keymap*/ + /* 4) main config; [Midnight Commander] -> keymap */ - fname2 = mc_config_get_string(mc_main_config, CONFIG_APP_SECTION, "keymap" , GLOBAL_KEYMAP_FILE); - fname = load_setup_get_full_config_name(NULL, fname2); + fname2 = + mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", GLOBAL_KEYMAP_FILE); + fname = load_setup_get_full_config_name (NULL, fname2); if (fname) { - load_setup_init_config_from_file( &keymap_config, fname); - g_free(fname); + load_setup_init_config_from_file (&keymap_config, fname); + g_free (fname); } - g_free(fname2); + g_free (fname2); /* 5) getenv("MC_KEYMAP") */ - fname = load_setup_get_full_config_name(NULL, g_getenv ("MC_KEYMAP")); + fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP")); if (fname) { - load_setup_init_config_from_file( &keymap_config, fname); - g_free(fname); + load_setup_init_config_from_file (&keymap_config, fname); + g_free (fname); } /* 6) --keymap= */ - fname = load_setup_get_full_config_name(NULL, mc_args__keymap_file); + fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file); if (fname) { - load_setup_init_config_from_file( &keymap_config, fname); - g_free(fname); + load_setup_init_config_from_file (&keymap_config, fname); + g_free (fname); } return keymap_config; @@ -712,27 +727,33 @@ load_setup_get_keymap_profile_config(void) char * setup_init (void) { - char *profile; - char *inifile; + char *profile; + char *inifile; if (profile_name) - return profile_name; + return profile_name; profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL); - if (!exist_file (profile)){ - inifile = concat_dir_and_file (mc_home, "mc.ini"); - if (exist_file (inifile)){ - g_free (profile); - profile = inifile; - } else { - g_free (inifile); - inifile = concat_dir_and_file (mc_home_alt, "mc.ini"); - if (exist_file (inifile)) { - g_free (profile); - profile = inifile; - } else - g_free (inifile); - } + if (!exist_file (profile)) + { + inifile = concat_dir_and_file (mc_home, "mc.ini"); + if (exist_file (inifile)) + { + g_free (profile); + profile = inifile; + } + else + { + g_free (inifile); + inifile = concat_dir_and_file (mc_home_alt, "mc.ini"); + if (exist_file (inifile)) + { + g_free (profile); + profile = inifile; + } + else + g_free (inifile); + } } profile_name = profile; @@ -744,7 +765,7 @@ void load_setup (void) { char *profile; - int i; + int i; char *buffer; profile = setup_init (); @@ -752,29 +773,32 @@ load_setup (void) /* mc.lib is common for all users, but has priority lower than ~/.mc/ini. FIXME: it's only used for keys and treestore now */ global_profile_name = concat_dir_and_file (mc_home, MC_GLOBAL_CONFIG_FILE); - if (!exist_file (global_profile_name)) { - g_free (global_profile_name); - global_profile_name = concat_dir_and_file (mc_home_alt, MC_GLOBAL_CONFIG_FILE); + if (!exist_file (global_profile_name)) + { + g_free (global_profile_name); + global_profile_name = concat_dir_and_file (mc_home_alt, MC_GLOBAL_CONFIG_FILE); } panels_profile_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_PANELS_FILE, NULL); mc_main_config = mc_config_init (profile); - if (!exist_file(panels_profile_name)) + if (!exist_file (panels_profile_name)) setup__move_panels_config_into_separate_file (profile); mc_panels_config = mc_config_init (panels_profile_name); /* Load integer boolean options */ for (i = 0; int_options[i].opt_name; i++) - *int_options[i].opt_addr = - mc_config_get_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr); + *int_options[i].opt_addr = + mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, + *int_options[i].opt_addr); /* Load string options */ for (i = 0; str_options[i].opt_name != NULL; i++) - *str_options[i].opt_addr = - mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval); + *str_options[i].opt_addr = + mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, + str_options[i].opt_defval); load_layout (); @@ -785,21 +809,22 @@ load_setup (void) /* At least one of the panels is a listing panel */ if (startup_left_mode != view_listing && startup_right_mode != view_listing) - startup_left_mode = view_listing; + startup_left_mode = view_listing; - if (!other_dir){ - buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", "."); - if (vfs_file_is_local (buffer)) - other_dir = buffer; - else - g_free (buffer); + if (!other_dir) + { + buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", "."); + if (vfs_file_is_local (buffer)) + other_dir = buffer; + else + g_free (buffer); } - boot_current_is_left = - mc_config_get_int (mc_panels_config, "Dirs", "current_is_left", 1); + boot_current_is_left = mc_config_get_int (mc_panels_config, "Dirs", "current_is_left", 1); /* Load time formats */ - user_recent_timeformat = mc_config_get_string (mc_main_config, "Misc", "timeformat_recent", FMTTIME); + user_recent_timeformat = + mc_config_get_string (mc_main_config, "Misc", "timeformat_recent", FMTTIME); user_old_timeformat = mc_config_get_string (mc_main_config, "Misc", "timeformat_old", FMTYEAR); #ifdef USE_NETCODE @@ -812,32 +837,35 @@ load_setup (void) color_terminal_string = mc_config_get_string (mc_main_config, "Colors", "color_terminals", ""); /* Load the directory history */ -/* directory_history_load (); */ + /* directory_history_load (); */ /* Remove the temporal entries */ #if defined(ENABLE_VFS) && defined (USE_NETCODE) ftpfs_init_passwd (); #endif /* ENABLE_VFS && USE_NETCODE */ #ifdef HAVE_CHARSET - if (load_codepages_list () > 0) { - buffer = mc_config_get_string (mc_main_config, "Misc", "display_codepage", ""); - if (buffer[0] != '\0') { - display_codepage = get_codepage_index (buffer); - cp_display = get_codepage_id (display_codepage); - } - g_free(buffer); - buffer = mc_config_get_string(mc_main_config, "Misc", "source_codepage", ""); - if (buffer[0] != '\0') { - default_source_codepage = get_codepage_index (buffer); - source_codepage = default_source_codepage; /* May be source_codepage don't needed this */ - cp_source = get_codepage_id (source_codepage); - } - g_free(buffer); + if (load_codepages_list () > 0) + { + buffer = mc_config_get_string (mc_main_config, "Misc", "display_codepage", ""); + if (buffer[0] != '\0') + { + display_codepage = get_codepage_index (buffer); + cp_display = get_codepage_id (display_codepage); + } + g_free (buffer); + buffer = mc_config_get_string (mc_main_config, "Misc", "source_codepage", ""); + if (buffer[0] != '\0') + { + default_source_codepage = get_codepage_index (buffer); + source_codepage = default_source_codepage; /* May be source_codepage don't needed this */ + cp_source = get_codepage_id (source_codepage); + } + g_free (buffer); } autodetect_codeset = mc_config_get_string (mc_main_config, "Misc", "autodetect_codeset", ""); - if ((autodetect_codeset[0] != '\0') && (strcmp(autodetect_codeset, "off"))) - is_autodetect_codeset_enabled=TRUE; + if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off"))) + is_autodetect_codeset_enabled = TRUE; init_translation_table (source_codepage, display_codepage); if (get_codepage_id (display_codepage)) @@ -851,11 +879,11 @@ load_anon_passwd () { char *buffer; - buffer = mc_config_get_string(mc_main_config, "Misc", "ftpfs_password", ""); - if (buffer [0]) - return buffer; + buffer = mc_config_get_string (mc_main_config, "Misc", "ftpfs_password", ""); + if (buffer[0]) + return buffer; - g_free(buffer); + g_free (buffer); return NULL; } #endif /* ENABLE_VFS && USE_NETCODE */ @@ -874,19 +902,19 @@ done_setup (void) mc_config_deinit (mc_main_config); mc_config_deinit (mc_panels_config); - g_free(user_recent_timeformat); - g_free(user_old_timeformat); + g_free (user_recent_timeformat); + g_free (user_old_timeformat); for (i = 0; str_options[i].opt_name != NULL; i++) - g_free (*str_options[i].opt_addr); + g_free (*str_options[i].opt_addr); done_hotlist (); done_panelize (); -/* directory_history_free (); */ + /* directory_history_free (); */ } static void -load_keys_from_section (const char *terminal, mc_config_t *cfg) +load_keys_from_section (const char *terminal, mc_config_t * cfg) { char *section_name; gchar **profile_keys, **keys; @@ -896,49 +924,58 @@ load_keys_from_section (const char *terminal, mc_config_t *cfg) gsize len, values_len; if (!terminal) - return; + return; section_name = g_strconcat ("terminal:", terminal, (char *) NULL); profile_keys = keys = mc_config_get_keys (cfg, section_name, &len); - while (*profile_keys){ + while (*profile_keys) + { - /* copy=other causes all keys from [terminal:other] to be loaded. */ - if (g_strcasecmp (*profile_keys, "copy") == 0) { - valcopy = mc_config_get_string (cfg, section_name, *profile_keys, ""); - load_keys_from_section (valcopy, cfg); - g_free(valcopy); - profile_keys++; - continue; - } - curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len); + /* copy=other causes all keys from [terminal:other] to be loaded. */ + if (g_strcasecmp (*profile_keys, "copy") == 0) + { + valcopy = mc_config_get_string (cfg, section_name, *profile_keys, ""); + load_keys_from_section (valcopy, cfg); + g_free (valcopy); + profile_keys++; + continue; + } + curr_values = values = + mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len); - key_code = lookup_key (*profile_keys, NULL); - if (key_code != 0) { - if (curr_values){ - while (*curr_values){ - valcopy = convert_controls (*curr_values); - define_sequence (key_code, valcopy, MCKEY_NOACTION); - g_free (valcopy); - curr_values++; - } - } else { - value = mc_config_get_string (cfg, section_name, *profile_keys, ""); - valcopy = convert_controls (value); - define_sequence (key_code, valcopy, MCKEY_NOACTION); - g_free (valcopy); - g_free (value); - } - } - profile_keys++; - if (values) - g_strfreev (values); + key_code = lookup_key (*profile_keys, NULL); + if (key_code != 0) + { + if (curr_values) + { + while (*curr_values) + { + valcopy = convert_controls (*curr_values); + define_sequence (key_code, valcopy, MCKEY_NOACTION); + g_free (valcopy); + curr_values++; + } + } + else + { + value = mc_config_get_string (cfg, section_name, *profile_keys, ""); + valcopy = convert_controls (value); + define_sequence (key_code, valcopy, MCKEY_NOACTION); + g_free (valcopy); + g_free (value); + } + } + profile_keys++; + if (values) + g_strfreev (values); } g_strfreev (keys); g_free (section_name); } -void load_key_defs (void) +void +load_key_defs (void) { /* * Load keys from mc.lib before ~/.mc/ini, so that the user @@ -946,12 +983,12 @@ void load_key_defs (void) */ mc_config_t *mc_global_config; - mc_global_config = mc_config_init(global_profile_name); + mc_global_config = mc_config_init (global_profile_name); if (mc_global_config != NULL) { load_keys_from_section ("general", mc_global_config); load_keys_from_section (getenv ("TERM"), mc_global_config); - mc_config_deinit(mc_global_config); + mc_config_deinit (mc_global_config); } load_keys_from_section ("general", mc_main_config); load_keys_from_section (getenv ("TERM"), mc_main_config); @@ -959,43 +996,50 @@ void load_key_defs (void) } static void -load_keymap_from_section (const char *section_name, GArray *keymap, mc_config_t *cfg) +load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg) { gchar **profile_keys, **keys; gchar **values, **curr_values; char *valcopy, *value; - int action; + int action; gsize len, values_len; if (!section_name) - return; + return; profile_keys = keys = mc_config_get_keys (cfg, section_name, &len); - while (*profile_keys) { - curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len); - action = lookup_action (*profile_keys); - if (action>0) { - if (curr_values) { - while (*curr_values) { - valcopy = convert_controls (*curr_values); - keybind_cmd_bind (keymap, valcopy, action); - g_free (valcopy); - curr_values++; - } - } else { - value = mc_config_get_string (cfg, section_name, *profile_keys, ""); - valcopy = convert_controls (value); - /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */ - g_free (valcopy); - g_free (value); - } - } - profile_keys++; - if (values) - g_strfreev(values); + while (*profile_keys) + { + curr_values = values = + mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len); + action = lookup_action (*profile_keys); + if (action > 0) + { + if (curr_values) + { + while (*curr_values) + { + valcopy = convert_controls (*curr_values); + keybind_cmd_bind (keymap, valcopy, action); + g_free (valcopy); + curr_values++; + } + } + else + { + value = mc_config_get_string (cfg, section_name, *profile_keys, ""); + valcopy = convert_controls (value); + /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */ + g_free (valcopy); + g_free (value); + } + } + profile_keys++; + if (values) + g_strfreev (values); } - g_strfreev(keys); + g_strfreev (keys); } void @@ -1007,7 +1051,7 @@ load_keymap_defs (void) */ mc_config_t *mc_global_keymap; - mc_global_keymap = load_setup_get_keymap_profile_config(); + mc_global_keymap = load_setup_get_keymap_profile_config (); if (mc_global_keymap != NULL) { @@ -1049,37 +1093,36 @@ free_keymap_defs (void) { #ifdef USE_INTERNAL_EDIT if (editor_keymap != NULL) - g_array_free (editor_keymap, TRUE); + g_array_free (editor_keymap, TRUE); if (editor_x_keymap != NULL) - g_array_free (editor_x_keymap, TRUE); + g_array_free (editor_x_keymap, TRUE); #endif if (viewer_keymap != NULL) - g_array_free (viewer_keymap, TRUE); + g_array_free (viewer_keymap, TRUE); if (viewer_hex_keymap != NULL) - g_array_free (viewer_hex_keymap, TRUE); + g_array_free (viewer_hex_keymap, TRUE); if (main_keymap != NULL) - g_array_free (main_keymap, TRUE); + g_array_free (main_keymap, TRUE); if (main_x_keymap != NULL) - g_array_free (main_x_keymap, TRUE); + g_array_free (main_x_keymap, TRUE); if (panel_keymap != NULL) - g_array_free (panel_keymap, TRUE); + g_array_free (panel_keymap, TRUE); if (input_keymap != NULL) - g_array_free (input_keymap, TRUE); + g_array_free (input_keymap, TRUE); if (tree_keymap != NULL) - g_array_free (tree_keymap, TRUE); + g_array_free (tree_keymap, TRUE); if (help_keymap != NULL) - g_array_free (help_keymap, TRUE); + g_array_free (help_keymap, TRUE); } void -setup_save_config_show_error(const char *filename, GError **error) +setup_save_config_show_error (const char *filename, GError ** error) { if (error == NULL || *error == NULL) return; - message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), - filename, (*error)->message); + message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message); - g_error_free(*error); + g_error_free (*error); *error = NULL; } diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 52e8ca8be..016c0ef4b 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -36,12 +36,12 @@ */ /* - The functions in this section can be bound to hotkeys. They are all - of the same type (taking a pointer to mcview_t as parameter and - returning void). TODO: In the not-too-distant future, these commands - will become fully configurable, like they already are in the - internal editor. By convention, all the function names end in - "_cmd". + The functions in this section can be bound to hotkeys. They are all + of the same type (taking a pointer to mcview_t as parameter and + returning void). TODO: In the not-too-distant future, these commands + will become fully configurable, like they already are in the + internal editor. By convention, all the function names end in + "_cmd". */ #include @@ -54,7 +54,7 @@ #include "lib/tty/tty.h" #include "lib/tty/key.h" -#include "src/dialog.h" /* cb_ret_t */ +#include "src/dialog.h" /* cb_ret_t */ #include "src/panel.h" #include "src/layout.h" #include "src/wtools.h" @@ -64,7 +64,7 @@ #include "src/execute.h" #include "src/help.h" #include "src/keybind.h" -#include "src/cmddef.h" /* CK_ cmd name const */ +#include "src/cmddef.h" /* CK_ cmd name const */ #include "internal.h" #include "mcviewer.h" @@ -81,7 +81,7 @@ /* Both views */ static void -mcview_search (mcview_t *view) +mcview_search (mcview_t * view) { if (mcview_dialog_search (view)) mcview_do_search (view); @@ -92,14 +92,18 @@ mcview_search (mcview_t *view) static void mcview_continue_search_cmd (mcview_t * view) { - if (view->last_search_string != NULL) { + if (view->last_search_string != NULL) + { mcview_do_search (view); - } else { + } + else + { /* find last search string in history */ GList *history; history = history_get (MC_HISTORY_SHARED_SEARCH); - if (history != NULL && history->data != NULL) { - view->last_search_string = (gchar *) g_strdup(history->data); + if (history != NULL && history->data != NULL) + { + view->last_search_string = (gchar *) g_strdup (history->data); history = g_list_first (history); g_list_foreach (history, (GFunc) g_free, NULL); g_list_free (history); @@ -107,12 +111,15 @@ mcview_continue_search_cmd (mcview_t * view) view->search = mc_search_new (view->last_search_string, -1); view->search_nroff_seq = mcview_nroff_seq_new (view); - if (!view->search) { + if (!view->search) + { /* if not... then ask for an expression */ - g_free(view->last_search_string); + g_free (view->last_search_string); view->last_search_string = NULL; mcview_search (view); - } else { + } + else + { view->search->search_type = mcview_search_options.type; view->search->is_all_charsets = mcview_search_options.all_codepages; view->search->is_case_sentitive = mcview_search_options.case_sens; @@ -122,9 +129,11 @@ mcview_continue_search_cmd (mcview_t * view) mcview_do_search (view); } - } else { + } + else + { /* if not... then ask for an expression */ - g_free(view->last_search_string); + g_free (view->last_search_string); view->last_search_string = NULL; mcview_search (view); } @@ -137,12 +146,14 @@ mcview_continue_search_cmd (mcview_t * view) static cb_ret_t mcview_check_left_right_keys (mcview_t * view, int c) { - if (c == KEY_LEFT) { + if (c == KEY_LEFT) + { mcview_move_left (view, 1); return MSG_HANDLED; } - if (c == KEY_RIGHT) { + if (c == KEY_RIGHT) + { mcview_move_right (view, 1); return MSG_HANDLED; } @@ -151,7 +162,8 @@ mcview_check_left_right_keys (mcview_t * view, int c) if (view->hex_mode || view->text_wrap_mode) return MSG_NOT_HANDLED; - if (c == (KEY_M_CTRL | KEY_LEFT)) { + if (c == (KEY_M_CTRL | KEY_LEFT)) + { if (view->dpy_text_column >= 10) view->dpy_text_column -= 10; else @@ -160,7 +172,8 @@ mcview_check_left_right_keys (mcview_t * view, int c) return MSG_HANDLED; } - if (c == (KEY_M_CTRL | KEY_RIGHT)) { + if (c == (KEY_M_CTRL | KEY_RIGHT)) + { if (view->dpy_text_column <= OFFSETTYPE_MAX - 10) view->dpy_text_column += 10; else @@ -216,7 +229,8 @@ mcview_hook (void *v) /* If the user is busy typing, wait until he finishes to update the screen */ - if (!is_idle ()) { + if (!is_idle ()) + { if (!hook_present (idle_hook, mcview_hook)) add_hook (&idle_hook, mcview_hook, v); return; @@ -247,12 +261,15 @@ mcview_handle_editkey (mcview_t * view, int key) while (node && (node->offset != view->hex_cursor)) node = node->next; - if (!view->hexview_in_text) { + if (!view->hexview_in_text) + { /* Hex editing */ unsigned int hexvalue = 0; - if (key >= '0' && key <= '9') { + if (key >= '0' && key <= '9') + { hexvalue = 0 + (key - '0'); - } else if (key >= 'A' && key <= 'F') + } + else if (key >= 'A' && key <= 'F') hexvalue = 10 + (key - 'A'); else if (key >= 'a' && key <= 'f') hexvalue = 10 + (key - 'a'); @@ -264,24 +281,32 @@ mcview_handle_editkey (mcview_t * view, int key) else mcview_get_byte (view, view->hex_cursor, &byte_val); - if (view->hexedit_lownibble) { + if (view->hexedit_lownibble) + { byte_val = (byte_val & 0xf0) | (hexvalue); - } else { + } + else + { byte_val = (byte_val & 0x0f) | (hexvalue << 4); } - } else { + } + else + { /* Text editing */ if (key < 256 && ((key == '\n') || is_printable (key))) byte_val = key; else return MSG_NOT_HANDLED; } - if (!node) { + if (!node) + { node = g_new (struct hexedit_change_node, 1); node->offset = view->hex_cursor; node->value = byte_val; mcview_enqueue_change (&view->change_list, node); - } else { + } + else + { node->value = byte_val; } view->dirty++; @@ -292,11 +317,12 @@ mcview_handle_editkey (mcview_t * view, int key) /* --------------------------------------------------------------------------------------------- */ static cb_ret_t -mcview_execute_cmd (mcview_t *view, unsigned long command) +mcview_execute_cmd (mcview_t * view, unsigned long command) { int res = MSG_HANDLED; - switch (command) { + switch (command) + { case CK_ViewHelp: interactive_display (NULL, "[Internal File Viewer]"); break; @@ -316,19 +342,21 @@ mcview_execute_cmd (mcview_t *view, unsigned long command) view->dirty++; break; case CK_ViewGoto: - { - off_t addr; + { + off_t addr; - if (mcview_dialog_goto (view, &addr)) { - if (addr >= 0) - mcview_moveto_offset (view, addr); - else { - message (D_ERROR, _("Warning"), _("Invalid value")); - view->dirty++; + if (mcview_dialog_goto (view, &addr)) + { + if (addr >= 0) + mcview_moveto_offset (view, addr); + else + { + message (D_ERROR, _("Warning"), _("Invalid value")); + view->dirty++; + } } + break; } - break; - } case CK_ViewHexEditSave: mcview_hexedit_save_changes (view); break; @@ -387,12 +415,12 @@ mcview_execute_cmd (mcview_t *view, unsigned long command) case CK_ShowCommandLine: view_other_cmd (); break; - /* - // Unlike Ctrl-O, run a new shell if the subshell is not running - case '!': - exec_shell (); - return MSG_HANDLED; - */ + /* + // Unlike Ctrl-O, run a new shell if the subshell is not running + case '!': + exec_shell (); + return MSG_HANDLED; + */ case CK_ViewGotoBookmark: view->marks[view->marker] = view->dpy_start; break; @@ -415,7 +443,7 @@ mcview_execute_cmd (mcview_t *view, unsigned long command) if (mcview_ok_to_quit (view)) view->want_to_quit = TRUE; break; - default : + default: res = MSG_NOT_HANDLED; } return res; @@ -429,21 +457,19 @@ mcview_handle_key (mcview_t * view, int key) key = convert_from_input_c (key); - if (view->hex_mode) { - if (view->hexedit_mode - && (mcview_handle_editkey (view, key) == MSG_HANDLED)) - return MSG_HANDLED; + if (view->hex_mode) + { + if (view->hexedit_mode && (mcview_handle_editkey (view, key) == MSG_HANDLED)) + return MSG_HANDLED; command = lookup_keymap_command (view->hex_map, key); - if ((command != CK_Ignore_Key) - && (mcview_execute_cmd (view, command) == MSG_HANDLED)) - return MSG_HANDLED; + if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED)) + return MSG_HANDLED; } command = lookup_keymap_command (view->plain_map, key); - if ((command != CK_Ignore_Key) - && (mcview_execute_cmd (view, command) == MSG_HANDLED)) - return MSG_HANDLED; + if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED)) + return MSG_HANDLED; if (mcview_check_left_right_keys (view, key)) return MSG_HANDLED; @@ -454,7 +480,8 @@ mcview_handle_key (mcview_t * view, int key) return MSG_HANDLED; #ifdef MC_ENABLE_DEBUGGING_CODE - if (c == 't') { /* mnemonic: "test" */ + if (c == 't') + { /* mnemonic: "test" */ mcview_ccache_dump (view); return MSG_HANDLED; } @@ -470,7 +497,7 @@ mcview_handle_key (mcview_t * view, int key) /* --------------------------------------------------------------------------------------------- */ static inline void -mcview_adjust_size (Dlg_head *h) +mcview_adjust_size (Dlg_head * h) { mcview_t *view; WButtonBar *b; @@ -480,7 +507,7 @@ mcview_adjust_size (Dlg_head *h) b = find_buttonbar (h); widget_set_size (&view->widget, 0, 0, LINES - 1, COLS); - widget_set_size (&b->widget , LINES - 1, 0, 1, COLS); + widget_set_size (&b->widget, LINES - 1, 0, 1, COLS); mcview_compute_areas (view); mcview_update_bytes_per_line (view); @@ -503,7 +530,8 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) mcview_compute_areas (view); mcview_update_bytes_per_line (view); - switch (msg) { + switch (msg) + { case WIDGET_INIT: if (mcview_is_in_panel (view)) add_hook (&select_file_hook, mcview_hook, view); @@ -555,12 +583,12 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) /* --------------------------------------------------------------------------------------------- */ cb_ret_t -mcview_dialog_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +mcview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { mcview_t *view = data; - switch (msg) { + switch (msg) + { case DLG_RESIZE: mcview_adjust_size (h); return MSG_HANDLED; diff --git a/src/viewer/coord_cache.c b/src/viewer/coord_cache.c index 479b32092..211f0bd2e 100644 --- a/src/viewer/coord_cache.c +++ b/src/viewer/coord_cache.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -47,11 +47,11 @@ neighbor entries. The algorithm used for determining the line/column for a specific offset needs to be kept synchronized with the one used in display(). -*/ + */ #include -#include /* for g_memmove() */ +#include /* for g_memmove() */ #include "lib/global.h" #include "lib/tty/tty.h" @@ -66,8 +66,7 @@ /*** file scope type declarations ****************************************************************/ -typedef gboolean (*cmp_func_t) (const coord_cache_entry_t *a, - const coord_cache_entry_t *b); +typedef gboolean (*cmp_func_t) (const coord_cache_entry_t * a, const coord_cache_entry_t * b); /*** file scope variables ************************************************************************/ @@ -77,39 +76,36 @@ typedef gboolean (*cmp_func_t) (const coord_cache_entry_t *a, /* insert new cache entry into the cache */ static void -mcview_ccache_add_entry (coord_cache_t *cache, - size_t pos, const coord_cache_entry_t *entry) +mcview_ccache_add_entry (coord_cache_t * cache, size_t pos, const coord_cache_entry_t * entry) { if ((cache == NULL) || (entry == NULL)) - return; + return; pos = min (pos, cache->size); /* increase cache capacity if needed */ - if (cache->size == cache->capacity) { - cache->capacity += CACHE_CAPACITY_DELTA; - cache->cache = g_realloc (cache->cache, - cache->capacity * sizeof (coord_cache_entry_t *)); + if (cache->size == cache->capacity) + { + cache->capacity += CACHE_CAPACITY_DELTA; + cache->cache = g_realloc (cache->cache, cache->capacity * sizeof (coord_cache_entry_t *)); } /* insert new entry */ if (pos != cache->size) - g_memmove (cache->cache[pos + 1], cache->cache[pos], - (cache->size - pos) * sizeof (coord_cache_entry_t *)); + g_memmove (cache->cache[pos + 1], cache->cache[pos], + (cache->size - pos) * sizeof (coord_cache_entry_t *)); cache->cache[pos] = g_memdup (entry, sizeof (coord_cache_entry_t)); cache->size++; } static gboolean -mcview_coord_cache_entry_less_offset (const coord_cache_entry_t *a, - const coord_cache_entry_t *b) +mcview_coord_cache_entry_less_offset (const coord_cache_entry_t * a, const coord_cache_entry_t * b) { return (a->cc_offset < b->cc_offset); } static gboolean -mcview_coord_cache_entry_less_plain (const coord_cache_entry_t *a, - const coord_cache_entry_t *b) +mcview_coord_cache_entry_less_plain (const coord_cache_entry_t * a, const coord_cache_entry_t * b) { if (a->cc_line < b->cc_line) return TRUE; @@ -122,8 +118,7 @@ mcview_coord_cache_entry_less_plain (const coord_cache_entry_t *a, static gboolean -mcview_coord_cache_entry_less_nroff (const coord_cache_entry_t *a, - const coord_cache_entry_t *b) +mcview_coord_cache_entry_less_nroff (const coord_cache_entry_t * a, const coord_cache_entry_t * b) { if (a->cc_line < b->cc_line) return TRUE; @@ -138,21 +133,24 @@ mcview_coord_cache_entry_less_nroff (const coord_cache_entry_t *a, /* Find and return the index of the last cache entry that is * smaller than ''coord'', according to the criterion ''sort_by''. */ static inline size_t -mcview_ccache_find (mcview_t *view, const coord_cache_entry_t *coord, - cmp_func_t cmp_func) +mcview_ccache_find (mcview_t * view, const coord_cache_entry_t * coord, cmp_func_t cmp_func) { size_t base = 0; size_t limit = view->coord_cache->size; assert (limit != 0); - while (limit > 1) { + while (limit > 1) + { size_t i; i = base + limit / 2; - if (cmp_func (coord, view->coord_cache->cache[i])) { + if (cmp_func (coord, view->coord_cache->cache[i])) + { /* continue the search in the lower half of the cache */ - } else { + } + else + { /* continue the search in the upper half of the cache */ base = i; } @@ -183,16 +181,17 @@ coord_cache_new (void) /* --------------------------------------------------------------------------------------------- */ void -coord_cache_free (coord_cache_t *cache) +coord_cache_free (coord_cache_t * cache) { - if (cache != NULL) { - size_t i; + if (cache != NULL) + { + size_t i; - for (i = 0; i < cache->size; i++) - g_free (cache->cache[i]); + for (i = 0; i < cache->size; i++) + g_free (cache->cache[i]); - g_free (cache->cache); - g_free (cache); + g_free (cache->cache); + g_free (cache); } } @@ -218,7 +217,8 @@ mcview_ccache_dump (mcview_t * view) (void) setvbuf (f, NULL, _IONBF, 0); /* cache entries */ - for (i = 0; i < view->coord_cache->size; i++) { + for (i = 0; i < view->coord_cache->size; i++) + { (void) fprintf (f, "entry %8u " "offset %8" OFFSETTYPE_PRId " " @@ -231,7 +231,8 @@ mcview_ccache_dump (mcview_t * view) (void) fprintf (f, "\n"); /* offset -> line/column translation */ - for (offset = 0; offset < filesize; offset++) { + for (offset = 0; offset < filesize; offset++) + { mcview_offset_to_coord (view, &line, &column, offset); (void) fprintf (f, "offset %8" OFFSETTYPE_PRId " " @@ -240,11 +241,13 @@ mcview_ccache_dump (mcview_t * view) } /* line/column -> offset translation */ - for (line = 0; TRUE; line++) { + for (line = 0; TRUE; line++) + { mcview_coord_to_offset (view, &nextline_offset, line + 1, 0); (void) fprintf (f, "nextline_offset %8" OFFSETTYPE_PRId "\n", nextline_offset); - for (column = 0; TRUE; column++) { + for (column = 0; TRUE; column++) + { mcview_coord_to_offset (view, &offset, line, column); if (offset >= nextline_offset) break; @@ -270,8 +273,7 @@ mcview_ccache_dump (mcview_t * view) * matches the existing components of ''coord''. */ void -mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, - enum ccache_type lookup_what) +mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord, enum ccache_type lookup_what) { size_t i; coord_cache_t *cache; @@ -280,7 +282,8 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, off_t limit; cmp_func_t cmp_func; - enum { + enum + { NROFF_START, NROFF_BACKSPACE, NROFF_CONTINUATION @@ -291,7 +294,8 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, cache = view->coord_cache; - if (cache->size == 0) { + if (cache->size == 0) + { current.cc_offset = 0; current.cc_line = 0; current.cc_column = 0; @@ -324,17 +328,21 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, entry = current; nroff_state = NROFF_START; - for (; current.cc_offset < limit; current = next) { + for (; current.cc_offset < limit; current = next) + { int c, nextc; - if (! mcview_get_byte (view, current.cc_offset, &c)) + if (!mcview_get_byte (view, current.cc_offset, &c)) break; - if (!cmp_func (¤t, coord)) { - if (lookup_what == CCACHE_OFFSET - && view->text_nroff_mode && nroff_state != NROFF_START) { + if (!cmp_func (¤t, coord)) + { + if (lookup_what == CCACHE_OFFSET && view->text_nroff_mode && nroff_state != NROFF_START) + { /* don't break here */ - } else { + } + else + { break; } } @@ -346,43 +354,56 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, next.cc_nroff_column = current.cc_nroff_column + 1; /* and override some of them as necessary. */ - if (c == '\r') { + if (c == '\r') + { mcview_get_byte_indexed (view, current.cc_offset, 1, &nextc); /* Ignore '\r' if it is followed by '\r' or '\n'. If it is * followed by anything else, it is a Mac line ending and * produces a line break. */ - if (nextc == '\r' || nextc == '\n') { + if (nextc == '\r' || nextc == '\n') + { next.cc_column = current.cc_column; next.cc_nroff_column = current.cc_nroff_column; - } else { + } + else + { next.cc_line = current.cc_line + 1; next.cc_column = 0; next.cc_nroff_column = 0; } - } else if (nroff_state == NROFF_BACKSPACE) { + } + else if (nroff_state == NROFF_BACKSPACE) + { next.cc_nroff_column = current.cc_nroff_column - 1; - } else if (c == '\t') { + } + else if (c == '\t') + { next.cc_column = mcview_offset_rounddown (current.cc_column, 8) + 8; next.cc_nroff_column = mcview_offset_rounddown (current.cc_nroff_column, 8) + 8; - } else if (c == '\n') { + } + else if (c == '\n') + { next.cc_line = current.cc_line + 1; next.cc_column = 0; next.cc_nroff_column = 0; - } else { + } + else + { /* Use all default values from above */ } - switch (nroff_state) { + switch (nroff_state) + { case NROFF_START: case NROFF_CONTINUATION: nroff_state = mcview_is_nroff_sequence (view, current.cc_offset) - ? NROFF_BACKSPACE : NROFF_START; + ? NROFF_BACKSPACE : NROFF_START; break; case NROFF_BACKSPACE: nroff_state = NROFF_CONTINUATION; @@ -397,7 +418,8 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, entry = next; } - if (i + 1 == cache->size && entry.cc_offset != cache->cache[i]->cc_offset) { + if (i + 1 == cache->size && entry.cc_offset != cache->cache[i]->cc_offset) + { mcview_ccache_add_entry (cache, cache->size, &entry); if (!tty_got_interrupt ()) @@ -406,9 +428,12 @@ mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t *coord, tty_disable_interrupt_key (); - if (lookup_what == CCACHE_OFFSET) { + if (lookup_what == CCACHE_OFFSET) + { coord->cc_offset = current.cc_offset; - } else { + } + else + { coord->cc_line = current.cc_line; coord->cc_column = current.cc_column; coord->cc_nroff_column = current.cc_nroff_column; diff --git a/src/viewer/datasource.c b/src/viewer/datasource.c index c23491323..cbee2223c 100644 --- a/src/viewer/datasource.c +++ b/src/viewer/datasource.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -36,22 +36,22 @@ */ /* - The data source provides the viewer with data from either a file, a - string or the output of a command. The mcview_get_byte() function can be - used to get the value of a byte at a specific offset. If the offset - is out of range, -1 is returned. The function mcview_get_byte_indexed(a,b) - returns the byte at the offset a+b, or -1 if a+b is out of range. + The data source provides the viewer with data from either a file, a + string or the output of a command. The mcview_get_byte() function can be + used to get the value of a byte at a specific offset. If the offset + is out of range, -1 is returned. The function mcview_get_byte_indexed(a,b) + returns the byte at the offset a+b, or -1 if a+b is out of range. - The mcview_set_byte() function has the effect that later calls to - mcview_get_byte() will return the specified byte for this offset. This - function is designed only for use by the hexedit component after - saving its changes. Inspect the source before you want to use it for - other purposes. + The mcview_set_byte() function has the effect that later calls to + mcview_get_byte() will return the specified byte for this offset. This + function is designed only for use by the hexedit component after + saving its changes. Inspect the source before you want to use it for + other purposes. - The mcview_get_filesize() function returns the current size of the - data source. If the growing buffer is used, this size may increase - later on. Use the mcview_may_still_grow() function when you want to - know if the size can change later. + The mcview_get_filesize() function returns the current size of the + data source. If the growing buffer is used, this size may increase + later on. Use the mcview_may_still_grow() function when you want to + know if the size can change later. */ #include @@ -99,7 +99,8 @@ mcview_set_datasource_none (mcview_t * view) off_t mcview_get_filesize (mcview_t * view) { - switch (view->datasource) { + switch (view->datasource) + { case DS_NONE: return 0; case DS_STDIO_PIPE: @@ -120,7 +121,8 @@ mcview_get_filesize (mcview_t * view) void mcview_update_filesize (mcview_t * view) { - if (view->datasource == DS_FILE) { + if (view->datasource == DS_FILE) + { struct stat st; if (mc_fstat (view->ds_file_fd, &st) != -1) view->ds_file_filesize = st.st_size; @@ -164,7 +166,8 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r *result = TRUE; - switch (view->datasource) { + switch (view->datasource) + { case DS_STDIO_PIPE: case DS_VFS_PIPE: str = mcview_get_ptr_growing_buffer (view, byte_index); @@ -179,7 +182,8 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r break; } - if (str == NULL) { + if (str == NULL) + { *result = FALSE; width = 0; return 0; @@ -187,16 +191,22 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r res = g_utf8_get_char_validated (str, -1); - if (res < 0) { + if (res < 0) + { ch = *str; width = 0; - } else { + } + else + { ch = res; /* Calculate UTF-8 char width */ next_ch = g_utf8_next_char (str); - if (next_ch) { + if (next_ch) + { width = next_ch - str; - } else { + } + else + { ch = 0; width = 0; } @@ -211,7 +221,8 @@ gboolean mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval) { assert (view->datasource == DS_STRING); - if (byte_index < (off_t) view->ds_string_len) { + if (byte_index < (off_t) view->ds_string_len) + { if (retval) *retval = view->ds_string_data[byte_index]; return TRUE; @@ -247,7 +258,7 @@ mcview_set_byte (mcview_t * view, off_t offset, byte b) /* --------------------------------------------------------------------------------------------- */ -/*static*/ +/*static */ void mcview_file_load_data (mcview_t * view, off_t byte_index) { @@ -268,7 +279,8 @@ mcview_file_load_data (mcview_t * view, off_t byte_index) goto error; bytes_read = 0; - while (bytes_read < view->ds_file_datasize) { + while (bytes_read < view->ds_file_datasize) + { res = mc_read (view->ds_file_fd, view->ds_file_data + bytes_read, view->ds_file_datasize - bytes_read); @@ -279,10 +291,13 @@ mcview_file_load_data (mcview_t * view, off_t byte_index) bytes_read += (size_t) res; } view->ds_file_offset = blockoffset; - if ((off_t) bytes_read > view->ds_file_filesize - view->ds_file_offset) { + if ((off_t) bytes_read > view->ds_file_filesize - view->ds_file_offset) + { /* the file has grown in the meantime -- stick to the old size */ view->ds_file_datalen = view->ds_file_filesize - view->ds_file_offset; - } else { + } + else + { view->ds_file_datalen = bytes_read; } return; @@ -296,11 +311,13 @@ mcview_file_load_data (mcview_t * view, off_t byte_index) void mcview_close_datasource (mcview_t * view) { - switch (view->datasource) { + switch (view->datasource) + { case DS_NONE: break; case DS_STDIO_PIPE: - if (view->ds_stdio_pipe != NULL) { + if (view->ds_stdio_pipe != NULL) + { (void) pclose (view->ds_stdio_pipe); mcview_display (view); close_error_pipe (D_NORMAL, NULL); @@ -309,7 +326,8 @@ mcview_close_datasource (mcview_t * view) mcview_growbuf_free (view); break; case DS_VFS_PIPE: - if (view->ds_vfs_pipe != -1) { + if (view->ds_vfs_pipe != -1) + { (void) mc_close (view->ds_vfs_pipe); view->ds_vfs_pipe = -1; } @@ -355,7 +373,8 @@ mcview_load_command_output (mcview_t * view, const char *command) mcview_close_datasource (view); open_error_pipe (); - if ((fp = popen (command, "r")) == NULL) { + if ((fp = popen (command, "r")) == NULL) + { /* Avoid two messages. Message from stderr has priority. */ mcview_display (view); if (!close_error_pipe (mcview_is_in_panel (view) ? -1 : D_ERROR, NULL)) @@ -365,7 +384,8 @@ mcview_load_command_output (mcview_t * view, const char *command) /* First, check if filter produced any output */ mcview_set_datasource_stdio_pipe (view, fp); - if (! mcview_get_byte (view, 0, NULL)) { + if (!mcview_get_byte (view, 0, NULL)) + { mcview_close_datasource (view); /* Avoid two messages. Message from stderr has priority. */ @@ -373,7 +393,9 @@ mcview_load_command_output (mcview_t * view, const char *command) if (!close_error_pipe (mcview_is_in_panel (view) ? -1 : D_ERROR, NULL)) mcview_show_error (view, _("Empty output from child filter")); return FALSE; - } else { + } + else + { /* * At least something was read correctly. Close stderr and let * program die if it will try to write something there. diff --git a/src/viewer/dialogs.c b/src/viewer/dialogs.c index 18d6765ed..edc178a8d 100644 --- a/src/viewer/dialogs.c +++ b/src/viewer/dialogs.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -52,8 +52,7 @@ /*** global variables ****************************************************************************/ -mcview_search_options_t mcview_search_options = -{ +mcview_search_options_t mcview_search_options = { .type = MC_SEARCH_T_NORMAL, .case_sens = FALSE, .backwards = FALSE, @@ -87,52 +86,53 @@ mcview_dialog_search (mcview_t * view) gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY; - QuickWidget quick_widgets[] = - { - QUICK_BUTTON (6, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), - QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), + QuickWidget quick_widgets[] = { + QUICK_BUTTON (6, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, + NULL), + QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), #ifdef HAVE_CHARSET - QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, - N_("All charsets"), &mcview_search_options.all_codepages), + QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, + N_("All charsets"), &mcview_search_options.all_codepages), #endif - QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, - N_("&Whole words"), &mcview_search_options.whole_words), - QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, - N_("&Backwards"), &mcview_search_options.backwards), - QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, - N_("case &Sensitive"), &mcview_search_options.case_sens), - QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, - num_of_types, (const char **) list_of_types, - (int *) &mcview_search_options.type), - QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, - INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp), - QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")), - QUICK_END + QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, + N_("&Whole words"), &mcview_search_options.whole_words), + QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, + N_("&Backwards"), &mcview_search_options.backwards), + QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, + N_("case &Sensitive"), &mcview_search_options.case_sens), + QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, + num_of_types, (const char **) list_of_types, + (int *) &mcview_search_options.type), + QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, + INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp), + QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")), + QUICK_END }; - QuickDialog Quick_input = - { - SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, - N_("Search"), "[Input Line Keys]", - quick_widgets, FALSE + QuickDialog Quick_input = { + SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, + N_("Search"), "[Input Line Keys]", + quick_widgets, FALSE }; qd_result = quick_dialog (&Quick_input); g_strfreev (list_of_types); - if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0')) { + if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0')) + { g_free (exp); return FALSE; } #ifdef HAVE_CHARSET { - GString *tmp = str_convert_to_input (exp); + GString *tmp = str_convert_to_input (exp); - if (tmp) { - g_free (exp); - exp = g_string_free (tmp, FALSE); - } + if (tmp) + { + g_free (exp); + exp = g_string_free (tmp, FALSE); + } } #endif @@ -147,13 +147,14 @@ mcview_dialog_search (mcview_t * view) view->search = mc_search_new (view->last_search_string, -1); view->search_nroff_seq = mcview_nroff_seq_new (view); - if (view->search != NULL) { - view->search->search_type = mcview_search_options.type; - view->search->is_all_charsets = mcview_search_options.all_codepages; - view->search->is_case_sentitive = mcview_search_options.case_sens; - view->search->whole_words = mcview_search_options.whole_words; - view->search->search_fn = mcview_search_cmd_callback; - view->search->update_fn = mcview_search_update_cmd_callback; + if (view->search != NULL) + { + view->search->search_type = mcview_search_options.type; + view->search->is_all_charsets = mcview_search_options.all_codepages; + view->search->is_case_sentitive = mcview_search_options.case_sens; + view->search->whole_words = mcview_search_options.whole_words; + view->search->search_fn = mcview_search_cmd_callback; + view->search->update_fn = mcview_search_update_cmd_callback; } return (view->search != NULL); @@ -162,21 +163,21 @@ mcview_dialog_search (mcview_t * view) /* --------------------------------------------------------------------------------------------- */ gboolean -mcview_dialog_goto (mcview_t *view, off_t *offset) +mcview_dialog_goto (mcview_t * view, off_t * offset) { - typedef enum { + typedef enum + { MC_VIEW_GOTO_LINENUM = 0, MC_VIEW_GOTO_PERCENT = 1, MC_VIEW_GOTO_OFFSET_DEC = 2, MC_VIEW_GOTO_OFFSET_HEX = 3 } mcview_goto_type_t; - const char *mc_view_goto_str[] = - { - N_("&Line number (decimal)"), - N_("Pe&rcents"), - N_("&Decimal offset"), - N_("He&xadecimal offset") + const char *mc_view_goto_str[] = { + N_("&Line number (decimal)"), + N_("Pe&rcents"), + N_("&Decimal offset"), + N_("He&xadecimal offset") }; const int goto_dlg_height = 12; @@ -186,32 +187,30 @@ mcview_dialog_goto (mcview_t *view, off_t *offset) size_t i; - size_t num_of_types = sizeof (mc_view_goto_str) /sizeof (mc_view_goto_str[0]); + size_t num_of_types = sizeof (mc_view_goto_str) / sizeof (mc_view_goto_str[0]); char *exp = NULL; int qd_result; gboolean res = FALSE; - QuickWidget quick_widgets[] = - { - QUICK_BUTTON (6, 10, goto_dlg_height - 3, goto_dlg_height, N_("&Cancel"), B_CANCEL, NULL), - QUICK_BUTTON (2, 10, goto_dlg_height - 3, goto_dlg_height, N_("&OK"), B_ENTER, NULL), - QUICK_RADIO (3, goto_dlg_width, 4, goto_dlg_height, - num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type), - QUICK_INPUT (3, goto_dlg_width, 2, goto_dlg_height, - INPUT_LAST_TEXT, goto_dlg_width - 6, 0, MC_HISTORY_VIEW_GOTO, &exp), - QUICK_END + QuickWidget quick_widgets[] = { + QUICK_BUTTON (6, 10, goto_dlg_height - 3, goto_dlg_height, N_("&Cancel"), B_CANCEL, NULL), + QUICK_BUTTON (2, 10, goto_dlg_height - 3, goto_dlg_height, N_("&OK"), B_ENTER, NULL), + QUICK_RADIO (3, goto_dlg_width, 4, goto_dlg_height, + num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type), + QUICK_INPUT (3, goto_dlg_width, 2, goto_dlg_height, + INPUT_LAST_TEXT, goto_dlg_width - 6, 0, MC_HISTORY_VIEW_GOTO, &exp), + QUICK_END }; - QuickDialog Quick_input = - { - goto_dlg_width, goto_dlg_height, -1, -1, - N_("Goto"), "[Input Line Keys]", - quick_widgets, FALSE + QuickDialog Quick_input = { + goto_dlg_width, goto_dlg_height, -1, -1, + N_("Goto"), "[Input Line Keys]", + quick_widgets, FALSE }; #ifdef ENABLE_NLS for (i = 0; i < num_of_types; i++) - mc_view_goto_str [i] = _(mc_view_goto_str [i]); + mc_view_goto_str[i] = _(mc_view_goto_str[i]); quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text); quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text); @@ -219,71 +218,74 @@ mcview_dialog_goto (mcview_t *view, off_t *offset) /* calculate widget coordinates */ { - int b0_len, b1_len, len; - const int button_gap = 2; + int b0_len, b1_len, len; + const int button_gap = 2; - /* preliminary dialog width */ - goto_dlg_width = max (goto_dlg_width, str_term_width1 (Quick_input.title) + 4); + /* preliminary dialog width */ + goto_dlg_width = max (goto_dlg_width, str_term_width1 (Quick_input.title) + 4); - /* length of radiobuttons */ - for (i = 0; i < num_of_types; i++) - goto_dlg_width = max (goto_dlg_width, str_term_width1 (mc_view_goto_str [i]) + 10); + /* length of radiobuttons */ + for (i = 0; i < num_of_types; i++) + goto_dlg_width = max (goto_dlg_width, str_term_width1 (mc_view_goto_str[i]) + 10); - /* length of buttons */ - b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; - b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */ - len = b0_len + b1_len + button_gap * 2; + /* length of buttons */ + b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; + b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */ + len = b0_len + b1_len + button_gap * 2; - /* dialog width */ - Quick_input.xlen = max (goto_dlg_width, len + 6); + /* dialog width */ + Quick_input.xlen = max (goto_dlg_width, len + 6); - /* correct widget coordinates */ - for (i = sizeof (quick_widgets)/sizeof (quick_widgets[0]); i > 0; i--) - quick_widgets[i - 1].x_divisions = Quick_input.xlen; + /* correct widget coordinates */ + for (i = sizeof (quick_widgets) / sizeof (quick_widgets[0]); i > 0; i--) + quick_widgets[i - 1].x_divisions = Quick_input.xlen; - /* input length */ - quick_widgets[3].u.input.len = Quick_input.xlen - 6; + /* input length */ + quick_widgets[3].u.input.len = Quick_input.xlen - 6; - /* button positions */ - quick_widgets[1].relative_x = Quick_input.xlen/2 - len/2; + /* button positions */ + quick_widgets[1].relative_x = Quick_input.xlen / 2 - len / 2; quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap; } - /* run dialog*/ + /* run dialog */ qd_result = quick_dialog (&Quick_input); *offset = -1; /* check input line value */ - if ((qd_result != B_CANCEL) && (exp != NULL) && (exp[0] != '\0')) { - int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10; - off_t addr; - char *error; + if ((qd_result != B_CANCEL) && (exp != NULL) && (exp[0] != '\0')) + { + int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10; + off_t addr; + char *error; - res = TRUE; + res = TRUE; - addr = strtoll (exp, &error, base); - if ((*error == '\0') && (addr >= 0)) { - switch (current_goto_type) { - case MC_VIEW_GOTO_LINENUM: - mcview_coord_to_offset (view, offset, addr, 0); - break; - case MC_VIEW_GOTO_PERCENT: - if (addr > 100) - addr = 100; - *offset = addr * mcview_get_filesize (view) / 100; - break; - case MC_VIEW_GOTO_OFFSET_DEC: - *offset = addr; - break; - case MC_VIEW_GOTO_OFFSET_HEX: - *offset = addr; - break; - default: - break; - } - *offset = mcview_bol (view, *offset); - } + addr = strtoll (exp, &error, base); + if ((*error == '\0') && (addr >= 0)) + { + switch (current_goto_type) + { + case MC_VIEW_GOTO_LINENUM: + mcview_coord_to_offset (view, offset, addr, 0); + break; + case MC_VIEW_GOTO_PERCENT: + if (addr > 100) + addr = 100; + *offset = addr * mcview_get_filesize (view) / 100; + break; + case MC_VIEW_GOTO_OFFSET_DEC: + *offset = addr; + break; + case MC_VIEW_GOTO_OFFSET_HEX: + *offset = addr; + break; + default: + break; + } + *offset = mcview_bol (view, *offset); + } } g_free (exp); diff --git a/src/viewer/display.c b/src/viewer/display.c index b6e06dda0..9b19a498c 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009, 2010 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009, 2010 Ilia Maslakov This file is part of the Midnight Commander. @@ -44,9 +44,9 @@ #include "lib/strutil.h" #include "src/main.h" -#include "src/dialog.h" /* Dlg_head */ +#include "src/dialog.h" /* Dlg_head */ #include "src/charsets.h" -#include "src/widget.h" /* WButtonBar */ +#include "src/widget.h" /* WButtonBar */ #include "internal.h" #include "mcviewer.h" @@ -60,7 +60,8 @@ /*** file scope variables ************************************************************************/ /* If set, show a ruler */ -static enum ruler_type { +static enum ruler_type +{ RULER_NONE, RULER_TOP, RULER_BOTTOM @@ -72,7 +73,7 @@ static enum ruler_type { /* Define labels and handlers for functional keys */ static void -mcview_set_buttonbar (mcview_t *view) +mcview_set_buttonbar (mcview_t * view) { Dlg_head *h = view->widget.parent; WButtonBar *b = find_buttonbar (h); @@ -80,22 +81,24 @@ mcview_set_buttonbar (mcview_t *view) buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, (Widget *) view); - if (view->hex_mode) { - if (view->hexedit_mode) + if (view->hex_mode) + { + if (view->hexedit_mode) buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, (Widget *) view); - else if (view->datasource == DS_FILE) + else if (view->datasource == DS_FILE) buttonbar_set_label (b, 2, Q_ ("ButtonBar|Edit"), keymap, (Widget *) view); - else + else buttonbar_set_label (b, 2, "", keymap, (Widget *) view); buttonbar_set_label (b, 4, Q_ ("ButtonBar|Ascii"), keymap, (Widget *) view); buttonbar_set_label (b, 6, Q_ ("ButtonBar|Save"), keymap, (Widget *) view); buttonbar_set_label (b, 7, Q_ ("ButtonBar|HxSrch"), keymap, (Widget *) view); - } else { + } + else + { buttonbar_set_label (b, 2, view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap") - : Q_ ("ButtonBar|Wrap"), - keymap, (Widget *) view); + : Q_ ("ButtonBar|Wrap"), keymap, (Widget *) view); buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, (Widget *) view); buttonbar_set_label (b, 6, "", keymap, (Widget *) view); buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), keymap, (Widget *) view); @@ -103,17 +106,16 @@ mcview_set_buttonbar (mcview_t *view) buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, (Widget *) view); buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw") - : Q_ ("ButtonBar|Parse"), - keymap, (Widget *) view); + : Q_ ("ButtonBar|Parse"), keymap, (Widget *) view); if (mcview_is_in_panel (view)) buttonbar_set_label (b, 10, "", keymap, (Widget *) view); - else { + else + { /* don't override some panel buttonbar keys */ buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, (Widget *) view); buttonbar_set_label (b, 9, view->text_nroff_mode ? Q_ ("ButtonBar|Unform") - : Q_ ("ButtonBar|Format"), - keymap, (Widget *) view); + : Q_ ("ButtonBar|Format"), keymap, (Widget *) view); buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, (Widget *) view); } } @@ -140,22 +142,25 @@ mcview_display_status (mcview_t * view) file_label = view->filename ? view->filename : view->command ? view->command : ""; file_label_width = str_term_width1 (file_label) - 2; - if (width > 40) { - char buffer [BUF_TINY]; + if (width > 40) + { + char buffer[BUF_TINY]; widget_move (view, top, width - 32); - if (view->hex_mode) { + if (view->hex_mode) + { tty_printf ("0x%08lx", (unsigned long) view->hex_cursor); - } else { + } + else + { size_trunc_len (buffer, 5, mcview_get_filesize (view), 0); tty_printf ("%9lli/%s%s %s", view->dpy_end, - buffer, - mcview_may_still_grow (view) ? "+" : " ", + buffer, mcview_may_still_grow (view) ? "+" : " ", #ifdef HAVE_CHARSET source_codepage >= 0 ? get_codepage_id (source_codepage) : "" #else "" #endif - ); + ); } } widget_move (view, top, left); @@ -178,13 +183,15 @@ mcview_update (mcview_t * view) { static int dirt_limit = 1; - if (view->dpy_bbar_dirty) { + if (view->dpy_bbar_dirty) + { view->dpy_bbar_dirty = FALSE; mcview_set_buttonbar (view); buttonbar_redraw (find_buttonbar (view->widget.parent)); } - if (view->dirty > dirt_limit) { + if (view->dirty > dirt_limit) + { /* Too many updates skipped -> force a update */ mcview_display (view); view->dirty = 0; @@ -192,14 +199,19 @@ mcview_update (mcview_t * view) dirt_limit++; if (dirt_limit > mcview_max_dirt_limit) dirt_limit = mcview_max_dirt_limit; - } else if (view->dirty > 0) { - if (is_idle ()) { + } + else if (view->dirty > 0) + { + if (is_idle ()) + { /* We have time to update the screen properly */ mcview_display (view); view->dirty = 0; if (dirt_limit > 1) dirt_limit--; - } else { + } + else + { /* We are busy -> skipping full update, only the status line is updated */ mcview_display_status (view); @@ -215,11 +227,16 @@ mcview_update (mcview_t * view) void mcview_display (mcview_t * view) { - if (view->hex_mode) { + if (view->hex_mode) + { mcview_display_hex (view); - } else if (view->text_nroff_mode) { + } + else if (view->text_nroff_mode) + { mcview_display_nroff (view); - } else { + } + else + { mcview_display_text (view); } mcview_display_status (view); @@ -267,7 +284,8 @@ mcview_compute_areas (mcview_t * view) view->status_area.top = y; y += view->status_area.height; - if (ruler == RULER_TOP) { + if (ruler == RULER_TOP) + { view->ruler_area.top = y; y += view->ruler_area.height; } @@ -302,7 +320,8 @@ mcview_update_bytes_per_line (mcview_t * view) void mcview_display_toggle_ruler (mcview_t * view) { - static const enum ruler_type next[3] = { + static const enum ruler_type next[3] = + { RULER_TOP, RULER_BOTTOM, RULER_NONE @@ -320,10 +339,11 @@ mcview_display_clean (mcview_t * view) { tty_setcolor (NORMAL_COLOR); widget_erase ((Widget *) view); - if (view->dpy_frame_size != 0) { + if (view->dpy_frame_size != 0) + { tty_draw_box (view->widget.y, view->widget.x, view->widget.lines, view->widget.cols); -/* draw_double_box (view->widget.parent, view->widget.y, - view->widget.x, view->widget.lines, view->widget.cols);*/ + /* draw_double_box (view->widget.parent, view->widget.y, + view->widget.x, view->widget.lines, view->widget.cols); */ } } @@ -348,16 +368,20 @@ mcview_display_ruler (mcview_t * view) return; tty_setcolor (MARKED_COLOR); - for (c = 0; c < width; c++) { + for (c = 0; c < width; c++) + { cl = view->dpy_text_column + c; - if (line_row < height) { + if (line_row < height) + { widget_move (view, top + line_row, left + c); tty_print_char (ruler_chars[cl % 10]); } - if ((cl != 0) && (cl % 10) == 0) { + if ((cl != 0) && (cl % 10) == 0) + { g_snprintf (r_buff, sizeof (r_buff), "%" OFFSETTYPE_PRId, (long unsigned int) cl); - if (nums_row < height) { + if (nums_row < height) + { widget_move (view, top + nums_row, left + c - 1); tty_print_string (r_buff); } diff --git a/src/viewer/growbuf.c b/src/viewer/growbuf.c index 8709594dd..953df8210 100644 --- a/src/viewer/growbuf.c +++ b/src/viewer/growbuf.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -118,8 +118,10 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs) return; short_read = FALSE; - while (mcview_growbuf_filesize (view) < ofs || short_read) { - if (view->growbuf_lastindex == VIEW_PAGE_SIZE) { + while (mcview_growbuf_filesize (view) < ofs || short_read) + { + if (view->growbuf_lastindex == VIEW_PAGE_SIZE) + { /* Append a new block to the growing buffer */ byte *newblock = g_try_malloc (VIEW_PAGE_SIZE); if (newblock == NULL) @@ -128,16 +130,16 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs) g_ptr_array_add (view->growbuf_blockptr, newblock); view->growbuf_lastindex = 0; } - p = g_ptr_array_index( - view->growbuf_blockptr, - view->growbuf_blockptr->len - 1) - + view->growbuf_lastindex; + p = g_ptr_array_index (view->growbuf_blockptr, + view->growbuf_blockptr->len - 1) + view->growbuf_lastindex; bytesfree = VIEW_PAGE_SIZE - view->growbuf_lastindex; - if (view->datasource == DS_STDIO_PIPE) { + if (view->datasource == DS_STDIO_PIPE) + { nread = fread (p, 1, bytesfree, view->ds_stdio_pipe); - if (nread == 0) { + if (nread == 0) + { view->growbuf_finished = TRUE; (void) pclose (view->ds_stdio_pipe); mcview_display (view); @@ -145,12 +147,17 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs) view->ds_stdio_pipe = NULL; return; } - } else { - assert (view->datasource == DS_VFS_PIPE); - do { + } + else + { + assert (view->datasource == DS_VFS_PIPE); + do + { nread = mc_read (view->ds_vfs_pipe, p, bytesfree); - } while (nread == -1 && errno == EINTR); - if (nread == -1 || nread == 0) { + } + while (nread == -1 && errno == EINTR); + if (nread == -1 || nread == 0) + { view->growbuf_finished = TRUE; (void) mc_close (view->ds_vfs_pipe); view->ds_vfs_pipe = -1; @@ -184,14 +191,16 @@ mcview_get_byte_growing_buffer (mcview_t * view, off_t byte_index, int *retval) mcview_growbuf_read_until (view, byte_index + 1); if (view->growbuf_blockptr->len == 0) return FALSE; - if (pageno < view->growbuf_blockptr->len - 1) { + if (pageno < view->growbuf_blockptr->len - 1) + { if (retval) - *retval = *((byte *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex)); + *retval = *((byte *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex)); return TRUE; } - if (pageno == view->growbuf_blockptr->len - 1 && pageindex < (off_t) view->growbuf_lastindex) { + if (pageno == view->growbuf_blockptr->len - 1 && pageindex < (off_t) view->growbuf_lastindex) + { if (retval) - *retval = *((byte *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex)); + *retval = *((byte *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex)); return TRUE; } return FALSE; @@ -214,9 +223,9 @@ mcview_get_ptr_growing_buffer (mcview_t * view, off_t byte_index) if (view->growbuf_blockptr->len == 0) return NULL; if (pageno < view->growbuf_blockptr->len - 1) - return (char *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex); + return (char *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex); if (pageno == view->growbuf_blockptr->len - 1 && pageindex < (off_t) view->growbuf_lastindex) - return (char *) (g_ptr_array_index(view->growbuf_blockptr, pageno) + pageindex); + return (char *) (g_ptr_array_index (view->growbuf_blockptr, pageno) + pageindex); return NULL; } diff --git a/src/viewer/hex.c b/src/viewer/hex.c index 73202f60b..2af5da2f8 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -57,7 +57,8 @@ /*** file scope type declarations ****************************************************************/ -typedef enum { +typedef enum +{ MARK_NORMAL, MARK_SELECTED, MARK_CURSOR, @@ -104,11 +105,13 @@ mcview_display_hex (mcview_t * view) /* Find the first displayable changed byte */ from = view->dpy_start; - while (curr && (curr->offset < from)) { + while (curr && (curr->offset < from)) + { curr = curr->next; } - for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++) { + for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++) + { col = 0; /* Print the hex offset */ @@ -116,17 +119,20 @@ mcview_display_hex (mcview_t * view) (long unsigned int) from); widget_move (view, top + row, left); tty_setcolor (MARKED_COLOR); - for (i = 0; col < width && hex_buff[i] != '\0'; i++) { + for (i = 0; col < width && hex_buff[i] != '\0'; i++) + { tty_print_char (hex_buff[i]); -/* tty_print_char(hex_buff[i]);*/ + /* tty_print_char(hex_buff[i]); */ col += 1; } tty_setcolor (NORMAL_COLOR); - for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) { + for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) + { #ifdef HAVE_CHARSET - if (view->utf8) { + if (view->utf8) + { int cw = 1; gboolean read_res = TRUE; ch = mcview_get_utf (view, from, &cw, &read_res); @@ -134,11 +140,12 @@ mcview_display_hex (mcview_t * view) break; } #endif - if (! mcview_get_byte (view, from, &c)) + if (!mcview_get_byte (view, from, &c)) break; /* Save the cursor position for mcview_place_cursor() */ - if (from == view->hex_cursor && !view->hexview_in_text) { + if (from == view->hex_cursor && !view->hexview_in_text) + { view->cursor_row = row; view->cursor_col = col; } @@ -151,7 +158,8 @@ mcview_display_hex (mcview_t * view) from < view->search_end) ? MARK_SELECTED : MARK_NORMAL; /* Determine the value of the current byte */ - if (curr != NULL && from == curr->offset) { + if (curr != NULL && from == curr->offset) + { c = curr->value; curr = curr->next; } @@ -165,30 +173,37 @@ mcview_display_hex (mcview_t * view) /* Print the hex number */ widget_move (view, top + row, left + col); - if (col < width) { + if (col < width) + { tty_print_char (hex_char[c / 16]); col += 1; } - if (col < width) { + if (col < width) + { tty_print_char (hex_char[c % 16]); col += 1; } /* Print the separator */ tty_setcolor (NORMAL_COLOR); - if (bytes != view->bytes_per_line - 1) { - if (col < width) { + if (bytes != view->bytes_per_line - 1) + { + if (col < width) + { tty_print_char (' '); col += 1; } /* After every four bytes, print a group separator */ - if (bytes % 4 == 3) { - if (view->data_area.width >= 80 && col < width) { + if (bytes % 4 == 3) + { + if (view->data_area.width >= 80 && col < width) + { tty_print_one_vline (); col += 1; } - if (col < width) { + if (col < width) + { tty_print_char (' '); col += 1; } @@ -204,16 +219,23 @@ mcview_display_hex (mcview_t * view) view->hexview_in_text ? VIEW_UNDERLINED_COLOR : MARKED_SELECTED_COLOR); #ifdef HAVE_CHARSET - if (utf8_display) { - if (!view->utf8) { + if (utf8_display) + { + if (!view->utf8) + { ch = convert_from_8bit_to_utf_c ((unsigned char) ch, view->converter); } if (!g_unichar_isprint (ch)) ch = '.'; - } else { - if (view->utf8) { + } + else + { + if (view->utf8) + { ch = convert_from_utf_to_current_c (ch, view->converter); - } else { + } + else + { #endif ch = convert_to_display_c (ch); #ifdef HAVE_CHARSET @@ -225,17 +247,22 @@ mcview_display_hex (mcview_t * view) c = '.'; /* Print corresponding character on the text side */ - if (text_start + bytes < width) { + if (text_start + bytes < width) + { widget_move (view, top + row, left + text_start + bytes); - if (!view->utf8) { + if (!view->utf8) + { tty_print_char (c); - } else { + } + else + { tty_print_anychar (ch); } } /* Save the cursor position for mcview_place_cursor() */ - if (from == view->hex_cursor && view->hexview_in_text) { + if (from == view->hex_cursor && view->hexview_in_text) + { view->cursor_row = row; view->cursor_col = text_start + bytes; } @@ -267,7 +294,8 @@ mcview_hexedit_save_changes (mcview_t * view) if (fp == -1) goto save_error; - for (curr = view->change_list; curr != NULL; curr = next) { + for (curr = view->change_list; curr != NULL; curr = next) + { next = curr->next; if (mc_lseek (fp, curr->offset, SEEK_SET) == -1 || mc_write (fp, &(curr->value), 1) != 1) @@ -280,7 +308,8 @@ mcview_hexedit_save_changes (mcview_t * view) g_free (curr); } - if (mc_close (fp) == -1) { + if (mc_close (fp) == -1) + { error = g_strdup (unix_error_string (errno)); message (D_ERROR, _(" Save file "), _(" Error while closing the file: \n %s \n" @@ -321,7 +350,8 @@ mcview_hexedit_free_change_list (mcview_t * view) { struct hexedit_change_node *curr, *next; - for (curr = view->change_list; curr != NULL; curr = next) { + for (curr = view->change_list; curr != NULL; curr = next) + { next = curr->next; g_free (curr); } diff --git a/src/viewer/inlines.h b/src/viewer/inlines.h index 88708dac9..6edbb015d 100644 --- a/src/viewer/inlines.h +++ b/src/viewer/inlines.h @@ -81,7 +81,8 @@ mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval) assert (view->datasource == DS_FILE); mcview_file_load_data (view, byte_index); - if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen)) { + if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen)) + { if (retval) *retval = view->ds_file_data[byte_index - view->ds_file_offset]; return TRUE; @@ -96,7 +97,8 @@ mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval) static inline gboolean mcview_get_byte (mcview_t * view, off_t offset, int *retval) { - switch (view->datasource) { + switch (view->datasource) + { case DS_STDIO_PIPE: case DS_VFS_PIPE: return mcview_get_byte_growing_buffer (view, offset, retval); @@ -116,7 +118,8 @@ mcview_get_byte (mcview_t * view, off_t offset, int *retval) static inline gboolean mcview_get_byte_indexed (mcview_t * view, off_t base, off_t ofs, int *retval) { - if (base <= OFFSETTYPE_MAX - ofs) { + if (base <= OFFSETTYPE_MAX - ofs) + { return mcview_get_byte (view, base + ofs, retval); } if (retval) @@ -146,13 +149,13 @@ mcview_is_nroff_sequence (mcview_t * view, off_t offset) /* The following commands are ordered to speed up the calculation. */ - if (! mcview_get_byte_indexed (view, offset, 1, &c1) || c1 != '\b') + if (!mcview_get_byte_indexed (view, offset, 1, &c1) || c1 != '\b') return FALSE; - if (! mcview_get_byte_indexed (view, offset, 0, &c0) || !g_ascii_isprint (c0)) + if (!mcview_get_byte_indexed (view, offset, 0, &c0) || !g_ascii_isprint (c0)) return FALSE; - if (! mcview_get_byte_indexed (view, offset, 2, &c2) || !g_ascii_isprint (c2)) + if (!mcview_get_byte_indexed (view, offset, 2, &c2) || !g_ascii_isprint (c2)) return FALSE; return (c0 == c2 || c0 == '_' || (c0 == '+' && c2 == 'o')); diff --git a/src/viewer/internal.h b/src/viewer/internal.h index 4d7536651..fcf0b8de9 100644 --- a/src/viewer/internal.h +++ b/src/viewer/internal.h @@ -12,7 +12,7 @@ #include "src/dialog.h" #include "src/widget.h" -#include "src/keybind.h" /* global_keymap_t */ +#include "src/keybind.h" /* global_keymap_t */ /*** typedefs(not structures) and defined constants ********************/ @@ -30,7 +30,8 @@ extern const off_t OFFSETTYPE_MAX; /*** enums *************************************************************/ /* data sources of the view */ -enum view_ds { +enum view_ds +{ DS_NONE, /* No data available */ DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */ DS_VFS_PIPE, /* Data comes from a piped-in VFS file */ @@ -38,12 +39,14 @@ enum view_ds { DS_STRING /* Data comes from a string in memory */ }; -enum ccache_type { +enum ccache_type +{ CCACHE_OFFSET, CCACHE_LINECOL }; -typedef enum { +typedef enum +{ NROFF_TYPE_NONE = 0, NROFF_TYPE_BOLD = 1, NROFF_TYPE_UNDERLINE = 2 @@ -52,13 +55,15 @@ typedef enum { /*** structures declarations (and typedefs of structures)***************/ /* A node for building a change list on change_list */ -struct hexedit_change_node { +struct hexedit_change_node +{ struct hexedit_change_node *next; off_t offset; byte value; }; -struct area { +struct area +{ screen_dimen top, left; screen_dimen height, width; }; @@ -68,14 +73,16 @@ struct area { * line and column of that cache entry. cc_nroff_column is the column * corresponding to cc_offset in nroff mode. */ -typedef struct { +typedef struct +{ off_t cc_offset; off_t cc_line; off_t cc_column; off_t cc_nroff_column; } coord_cache_entry_t; -typedef struct { +typedef struct +{ size_t size; size_t capacity; coord_cache_entry_t **cache; @@ -83,7 +90,8 @@ typedef struct { struct mcview_nroff_struct; -typedef struct mcview_struct { +typedef struct mcview_struct +{ Widget widget; char *filename; /* Name of the file */ @@ -111,7 +119,7 @@ typedef struct mcview_struct { /* Growing buffers information */ gboolean growbuf_in_use; /* Use the growing buffers? */ - GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */ + GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */ size_t growbuf_lastindex; /* Number of bytes in the last page of the growing buffer */ gboolean growbuf_finished; /* TRUE when all data has been read. */ @@ -185,7 +193,8 @@ typedef struct mcview_struct { int search_numNeedSkipChar; } mcview_t; -typedef struct mcview_nroff_struct { +typedef struct mcview_nroff_struct +{ mcview_t *view; off_t index; int char_width; @@ -194,7 +203,8 @@ typedef struct mcview_nroff_struct { nroff_type_t prev_type; } mcview_nroff_t; -typedef struct mcview_search_options_t { +typedef struct mcview_search_options_t +{ mc_search_type_t type; gboolean case_sens; gboolean backwards; @@ -209,20 +219,20 @@ extern mcview_search_options_t mcview_search_options; /*** declarations of public functions **********************************/ /* actions_cmd.c: */ -cb_ret_t mcview_callback (Widget *w, widget_msg_t msg, int parm); -cb_ret_t mcview_dialog_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data); +cb_ret_t mcview_callback (Widget * w, widget_msg_t msg, int parm); +cb_ret_t mcview_dialog_callback (Dlg_head * h, Widget * sender, + dlg_msg_t msg, int parm, void *data); /* coord_cache.c: */ coord_cache_t *coord_cache_new (void); -void coord_cache_free (coord_cache_t *cache); +void coord_cache_free (coord_cache_t * cache); #ifdef MC_ENABLE_DEBUGGING_CODE -void mcview_ccache_dump (mcview_t *view); +void mcview_ccache_dump (mcview_t * view); #endif -void mcview_ccache_lookup (mcview_t *view, coord_cache_entry_t *coord, - enum ccache_type lookup_what); +void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord, + enum ccache_type lookup_what); /* datasource.c: */ void mcview_set_datasource_none (mcview_t *); @@ -242,46 +252,46 @@ void mcview_set_datasource_vfs_pipe (mcview_t *, int); void mcview_set_datasource_string (mcview_t *, const char *); /* dialog.c: */ -gboolean mcview_dialog_search (mcview_t *view); -gboolean mcview_dialog_goto (mcview_t *view, off_t *offset); +gboolean mcview_dialog_search (mcview_t * view); +gboolean mcview_dialog_goto (mcview_t * view, off_t * offset); /* display.c: */ -void mcview_update (mcview_t *view); -void mcview_display (mcview_t *view); -void mcview_compute_areas (mcview_t *view); -void mcview_update_bytes_per_line (mcview_t *view); -void mcview_display_toggle_ruler (mcview_t *view); -void mcview_display_clean (mcview_t *view); -void mcview_display_ruler (mcview_t *view); -void mcview_percent (mcview_t *view, off_t p); +void mcview_update (mcview_t * view); +void mcview_display (mcview_t * view); +void mcview_compute_areas (mcview_t * view); +void mcview_update_bytes_per_line (mcview_t * view); +void mcview_display_toggle_ruler (mcview_t * view); +void mcview_display_clean (mcview_t * view); +void mcview_display_ruler (mcview_t * view); +void mcview_percent (mcview_t * view, off_t p); /* growbuf.c: */ -void mcview_growbuf_init (mcview_t *view); -void mcview_growbuf_free (mcview_t *view); -off_t mcview_growbuf_filesize (mcview_t *view); -void mcview_growbuf_read_until (mcview_t *view, off_t p); -gboolean mcview_get_byte_growing_buffer (mcview_t *view, off_t p, int *); -char *mcview_get_ptr_growing_buffer (mcview_t *view, off_t p); +void mcview_growbuf_init (mcview_t * view); +void mcview_growbuf_free (mcview_t * view); +off_t mcview_growbuf_filesize (mcview_t * view); +void mcview_growbuf_read_until (mcview_t * view, off_t p); +gboolean mcview_get_byte_growing_buffer (mcview_t * view, off_t p, int *); +char *mcview_get_ptr_growing_buffer (mcview_t * view, off_t p); /* hex.c: */ -void mcview_display_hex (mcview_t *view); -gboolean mcview_hexedit_save_changes (mcview_t *view); -void mcview_toggle_hexedit_mode (mcview_t *view); -void mcview_hexedit_free_change_list (mcview_t *view); +void mcview_display_hex (mcview_t * view); +gboolean mcview_hexedit_save_changes (mcview_t * view); +void mcview_toggle_hexedit_mode (mcview_t * view); +void mcview_hexedit_free_change_list (mcview_t * view); void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *); /* lib.c: */ -void mcview_toggle_magic_mode (mcview_t *view); -void mcview_toggle_wrap_mode (mcview_t *view); -void mcview_toggle_nroff_mode (mcview_t *view); -void mcview_toggle_hex_mode (mcview_t *view); -gboolean mcview_ok_to_quit (mcview_t *view); -void mcview_done (mcview_t *view); -void mcview_select_encoding (mcview_t *view); -void mcview_set_codeset (mcview_t *view); -void mcview_show_error (mcview_t *view, const char *error); -off_t mcview_bol (mcview_t *view, off_t current); -off_t mcview_eol (mcview_t *view, off_t current); +void mcview_toggle_magic_mode (mcview_t * view); +void mcview_toggle_wrap_mode (mcview_t * view); +void mcview_toggle_nroff_mode (mcview_t * view); +void mcview_toggle_hex_mode (mcview_t * view); +gboolean mcview_ok_to_quit (mcview_t * view); +void mcview_done (mcview_t * view); +void mcview_select_encoding (mcview_t * view); +void mcview_set_codeset (mcview_t * view); +void mcview_show_error (mcview_t * view, const char *error); +off_t mcview_bol (mcview_t * view, off_t current); +off_t mcview_eol (mcview_t * view, off_t current); /* move.c */ void mcview_move_up (mcview_t *, off_t); @@ -301,10 +311,10 @@ void mcview_place_cursor (mcview_t *); void mcview_moveto_match (mcview_t *); /* nroff.c: */ -void mcview_display_nroff (mcview_t *view); -int mcview__get_nroff_real_len (mcview_t *view, off_t, off_t p); +void mcview_display_nroff (mcview_t * view); +int mcview__get_nroff_real_len (mcview_t * view, off_t, off_t p); -mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t *view, off_t p); +mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t * view, off_t p); mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view); void mcview_nroff_seq_free (mcview_nroff_t **); nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *); @@ -316,11 +326,11 @@ void mcview_display_text (mcview_t *); /* search.c: */ int mcview_search_cmd_callback (const void *user_data, gsize char_offset); int mcview_search_update_cmd_callback (const void *, gsize); -void mcview_do_search (mcview_t *view); +void mcview_do_search (mcview_t * view); /*** inline functions ****************************************************************************/ #include "inlines.h" -#endif /* MC_VIEWER_INTERNAL_H */ +#endif /* MC_VIEWER_INTERNAL_H */ diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 0e7b88636..947e2ace5 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -115,11 +115,14 @@ mcview_toggle_hex_mode (mcview_t * view) { view->hex_mode = !view->hex_mode; - if (view->hex_mode) { + if (view->hex_mode) + { view->hex_cursor = view->dpy_start; view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line); view->widget.options |= W_WANT_CURSOR; - } else { + } + else + { view->dpy_start = view->hex_cursor; mcview_moveto_bol (view); view->widget.options &= ~W_WANT_CURSOR; @@ -143,7 +146,8 @@ mcview_ok_to_quit (mcview_t * view) _(" File was modified, Save with exit? "), D_NORMAL, 3, _("&Cancel quit"), _("&Yes"), _("&No")); - switch (r) { + switch (r) + { case 1: return mcview_hexedit_save_changes (view); case 2: @@ -160,7 +164,8 @@ void mcview_done (mcview_t * view) { /* Save current file position */ - if (mcview_remember_file_position && view->filename != NULL) { + if (mcview_remember_file_position && view->filename != NULL) + { char *canon_fname; canon_fname = vfs_canon (view->filename); save_file_position (canon_fname, -1, 0, view->dpy_start); @@ -185,7 +190,8 @@ mcview_done (mcview_t * view) coord_cache_free (view->coord_cache), view->coord_cache = NULL; - if (!(view->converter == INVALID_CONV || view->converter != str_cnv_from_term)) { + if (!(view->converter == INVALID_CONV || view->converter != str_cnv_from_term)) + { str_close_conv (view->converter); view->converter = str_cnv_from_term; } @@ -203,10 +209,12 @@ mcview_set_codeset (mcview_t * view) view->utf8 = TRUE; cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage); - if (cp_id != NULL) { + if (cp_id != NULL) + { GIConv conv; conv = str_crt_conv_from (cp_id); - if (conv != INVALID_CONV) { + if (conv != INVALID_CONV) + { if (view->converter != str_cnv_from_term) str_close_conv (view->converter); view->converter = conv; @@ -224,7 +232,8 @@ void mcview_select_encoding (mcview_t * view) { #ifdef HAVE_CHARSET - if (do_select_codepage ()) { + if (do_select_codepage ()) + { mcview_set_codeset (view); } #else @@ -238,9 +247,12 @@ void mcview_show_error (mcview_t * view, const char *msg) { mcview_close_datasource (view); - if (mcview_is_in_panel (view)) { + if (mcview_is_in_panel (view)) + { mcview_set_datasource_string (view, msg); - } else { + } + else + { message (D_ERROR, MSG_ERROR, "%s", msg); } } @@ -261,13 +273,15 @@ mcview_bol (mcview_t * view, off_t current) return filesize; if (!mcview_get_byte (view, current, &c)) return current; - if (c == '\n') { + if (c == '\n') + { if (!mcview_get_byte (view, current - 1, &c)) return current; if (c == '\r') current--; } - while (current > 0) { + while (current > 0) + { if (!mcview_get_byte (view, current - 1, &c)) break; if (c == '\r' || c == '\n') @@ -289,13 +303,17 @@ mcview_eol (mcview_t * view, off_t current) return 0; if (current >= filesize) return filesize; - while (current < filesize) { + while (current < filesize) + { if (!mcview_get_byte (view, current, &c)) break; - if (c == '\n') { + if (c == '\n') + { current++; break; - } else if (prev_ch == '\r') { + } + else if (prev_ch == '\r') + { break; } current++; diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 07d91e504..6e5e259b1 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -46,8 +46,8 @@ #include "src/main.h" #include "src/charsets.h" -#include "src/main-widgets.h" /* the_menubar */ -#include "src/menu.h" /* menubar_visible */ +#include "src/main-widgets.h" /* the_menubar */ +#include "src/menu.h" /* menubar_visible */ #include "src/widget.h" #include "internal.h" @@ -88,18 +88,18 @@ char *mcview_show_eof = NULL; /* Both views */ static int -mcview_event (mcview_t *view, Gpm_Event *event, int *result) +mcview_event (mcview_t * view, Gpm_Event * event, int *result) { screen_dimen y, x; *result = MOU_NORMAL; /* rest of the upper frame, the menu is invisible - call menu */ - if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) - && event->y == 1 && !menubar_visible) { - event->x += view->widget.x; - *result = the_menubar->widget.mouse (event, the_menubar); - return 0; /* don't draw viewer over menu */ + if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) && event->y == 1 && !menubar_visible) + { + event->x += view->widget.x; + *result = the_menubar->widget.mouse (event, the_menubar); + return 0; /* don't draw viewer over menu */ } /* We are not interested in the release events */ @@ -107,11 +107,13 @@ mcview_event (mcview_t *view, Gpm_Event *event, int *result) return 0; /* Wheel events */ - if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) { + if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) + { mcview_move_up (view, 2); return 1; } - if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) { + if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) + { mcview_move_down (view, 2); return 1; } @@ -120,28 +122,39 @@ mcview_event (mcview_t *view, Gpm_Event *event, int *result) y = event->y; /* Scrolling left and right */ - if (!view->text_wrap_mode) { - if (x < view->data_area.width * 1 / 4) { + if (!view->text_wrap_mode) + { + if (x < view->data_area.width * 1 / 4) + { mcview_move_left (view, 1); goto processed; - } else if (x < view->data_area.width * 3 / 4) { + } + else if (x < view->data_area.width * 3 / 4) + { /* ignore the click */ - } else { + } + else + { mcview_move_right (view, 1); goto processed; } } /* Scrolling up and down */ - if (y < view->data_area.top + view->data_area.height * 1 / 3) { + if (y < view->data_area.top + view->data_area.height * 1 / 3) + { if (mcview_mouse_move_pages) mcview_move_up (view, view->data_area.height / 2); else mcview_move_up (view, 1); goto processed; - } else if (y < view->data_area.top + view->data_area.height * 2 / 3) { + } + else if (y < view->data_area.top + view->data_area.height * 2 / 3) + { /* ignore the click */ - } else { + } + else + { if (mcview_mouse_move_pages) mcview_move_down (view, view->data_area.height / 2); else @@ -270,7 +283,7 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start /* Create dialog and widgets, put them on the dialog */ view_dlg = create_dlg (0, 0, LINES, COLS, NULL, mcview_dialog_callback, - "[Internal File Viewer]", NULL, DLG_WANT_TAB); + "[Internal File Viewer]", NULL, DLG_WANT_TAB); lc_mcview = mcview_new (0, 0, LINES - 1, COLS, 0); add_widget (view_dlg, lc_mcview); @@ -278,11 +291,14 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start add_widget (view_dlg, buttonbar_new (TRUE)); succeeded = mcview_load (lc_mcview, command, file, start_line); - if (succeeded) { + if (succeeded) + { run_dlg (view_dlg); if (move_dir_p) *move_dir_p = lc_mcview->move_dir; - } else { + } + else + { if (move_dir_p) *move_dir_p = 0; } @@ -319,15 +335,20 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l for (i = 0; i < 10; i++) view->marks[i] = 0; - if (!mcview_is_in_panel (view)) { + if (!mcview_is_in_panel (view)) + { view->dpy_text_column = 0; } - if (command && (view->magic_mode || file == NULL || file[0] == '\0')) { + if (command && (view->magic_mode || file == NULL || file[0] == '\0')) + { retval = mcview_load_command_output (view, command); - } else if (file != NULL && file[0] != '\0') { + } + else if (file != NULL && file[0] != '\0') + { /* Open the file */ - if ((fd = mc_open (file, O_RDONLY | O_NONBLOCK)) == -1) { + if ((fd = mc_open (file, O_RDONLY | O_NONBLOCK)) == -1) + { g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "), file, unix_error_string (errno)); mcview_show_error (view, tmp); @@ -337,7 +358,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l } /* Make sure we are working with a regular file */ - if (mc_fstat (fd, &st) == -1) { + if (mc_fstat (fd, &st) == -1) + { mc_close (fd); g_snprintf (tmp, sizeof (tmp), _(" Cannot stat \"%s\"\n %s "), file, unix_error_string (errno)); @@ -347,7 +369,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l goto finish; } - if (!S_ISREG (st.st_mode)) { + if (!S_ISREG (st.st_mode)) + { mc_close (fd); mcview_show_error (view, _(" Cannot view: not a regular file ")); g_free (view->filename); @@ -355,13 +378,17 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l goto finish; } - if (st.st_size == 0 || mc_lseek (fd, 0, SEEK_SET) == -1) { + if (st.st_size == 0 || mc_lseek (fd, 0, SEEK_SET) == -1) + { /* Must be one of those nice files that grow (/proc) */ mcview_set_datasource_vfs_pipe (view, fd); - } else { + } + else + { type = get_compression_type (fd, file); - if (view->magic_mode && (type != COMPRESSION_NONE)) { + if (view->magic_mode && (type != COMPRESSION_NONE)) + { g_free (view->filename); view->filename = g_strconcat (file, decompress_extension (type), (char *) NULL); } @@ -380,7 +407,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l mcview_compute_areas (view); mcview_update_bytes_per_line (view); - if (mcview_remember_file_position && view->filename != NULL && start_line == 0) { + if (mcview_remember_file_position && view->filename != NULL && start_line == 0) + { long line, col; off_t new_offset; canon_fname = vfs_canon (view->filename); @@ -388,7 +416,9 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l new_offset = min (new_offset, mcview_get_filesize (view)); view->dpy_start = mcview_bol (view, new_offset); g_free (canon_fname); - } else if (start_line > 0) { + } + else if (start_line > 0) + { mcview_moveto (view, start_line - 1, 0); } diff --git a/src/viewer/mcviewer.h b/src/viewer/mcviewer.h index 89ba27727..ce40532cb 100644 --- a/src/viewer/mcviewer.h +++ b/src/viewer/mcviewer.h @@ -43,8 +43,7 @@ extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, int * point to a variable that will receive the direction in which the user * wants to move (-1 = previous file, 1 = next file, 0 = do nothing). */ -extern int mcview_viewer (const char *command, const char *file, - int *move_dir_p, int start_line); +extern int mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line); extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int); diff --git a/src/viewer/move.c b/src/viewer/move.c index 2951d1337..dcf789b8d 100644 --- a/src/viewer/move.c +++ b/src/viewer/move.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009, 2010 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009, 2010 Ilia Maslakov This file is part of the Midnight Commander. @@ -71,7 +71,8 @@ static void mcview_movement_fixups (mcview_t * view, gboolean reset_search) { mcview_scroll_to_cursor (view); - if (reset_search) { + if (reset_search) + { view->search_start = view->dpy_start; view->search_end = view->dpy_start; } @@ -88,18 +89,25 @@ void mcview_move_up (mcview_t * view, off_t lines) { off_t new_offset; - if (view->hex_mode) { + if (view->hex_mode) + { off_t bytes = lines * view->bytes_per_line; - if (view->hex_cursor >= bytes) { + if (view->hex_cursor >= bytes) + { view->hex_cursor -= bytes; if (view->hex_cursor < view->dpy_start) view->dpy_start = mcview_offset_doz (view->dpy_start, bytes); - } else { + } + else + { view->hex_cursor %= view->bytes_per_line; } - } else { + } + else + { off_t i; - for (i = 0; i < lines; i++) { + for (i = 0; i < lines; i++) + { new_offset = mcview_bol (view, view->dpy_start); if (new_offset > 0) new_offset--; @@ -119,21 +127,26 @@ mcview_move_down (mcview_t * view, off_t lines) { off_t last_byte; last_byte = mcview_get_filesize (view); - if (view->hex_mode) { + if (view->hex_mode) + { off_t i, limit; if (last_byte >= (off_t) view->bytes_per_line) limit = last_byte - view->bytes_per_line; else limit = 0; - for (i = 0; i < lines && view->hex_cursor < limit; i++) { + for (i = 0; i < lines && view->hex_cursor < limit; i++) + { view->hex_cursor += view->bytes_per_line; if (lines != 1) view->dpy_start += view->bytes_per_line; } - } else { + } + else + { off_t i; - for (i = 0; i < lines; i++) { + for (i = 0; i < lines; i++) + { off_t new_offset; new_offset = mcview_eol (view, view->dpy_start); view->dpy_start = new_offset; @@ -147,19 +160,25 @@ mcview_move_down (mcview_t * view, off_t lines) void mcview_move_left (mcview_t * view, off_t columns) { - if (view->hex_mode) { + if (view->hex_mode) + { off_t old_cursor = view->hex_cursor; assert (columns == 1); - if (view->hexview_in_text || !view->hexedit_lownibble) { + if (view->hexview_in_text || !view->hexedit_lownibble) + { if (view->hex_cursor > 0) view->hex_cursor--; } if (!view->hexview_in_text) if (old_cursor > 0 || view->hexedit_lownibble) view->hexedit_lownibble = !view->hexedit_lownibble; - } else if (view->text_wrap_mode) { + } + else if (view->text_wrap_mode) + { /* nothing to do */ - } else { + } + else + { if (view->dpy_text_column >= columns) view->dpy_text_column -= columns; else @@ -173,21 +192,27 @@ mcview_move_left (mcview_t * view, off_t columns) void mcview_move_right (mcview_t * view, off_t columns) { - if (view->hex_mode) { + if (view->hex_mode) + { off_t last_byte; off_t old_cursor = view->hex_cursor; - last_byte = mcview_offset_doz(mcview_get_filesize (view), 1); + last_byte = mcview_offset_doz (mcview_get_filesize (view), 1); assert (columns == 1); - if (view->hexview_in_text || view->hexedit_lownibble) { + if (view->hexview_in_text || view->hexedit_lownibble) + { if (view->hex_cursor < last_byte) view->hex_cursor++; } if (!view->hexview_in_text) if (old_cursor < last_byte || !view->hexedit_lownibble) view->hexedit_lownibble = !view->hexedit_lownibble; - } else if (view->text_wrap_mode) { + } + else if (view->text_wrap_mode) + { /* nothing to do */ - } else { + } + else + { view->dpy_text_column += columns; } mcview_movement_fixups (view, FALSE); @@ -198,15 +223,15 @@ mcview_move_right (mcview_t * view, off_t columns) void mcview_scroll_to_cursor (mcview_t * view) { - if (view->hex_mode) { + if (view->hex_mode) + { const off_t bytes = view->bytes_per_line; const off_t displaysize = view->data_area.height * bytes; const off_t cursor = view->hex_cursor; off_t topleft = view->dpy_start; if (topleft + displaysize <= cursor) - topleft = mcview_offset_rounddown (cursor, bytes) - - (displaysize - bytes); + topleft = mcview_offset_rounddown (cursor, bytes) - (displaysize - bytes); if (cursor < topleft) topleft = mcview_offset_rounddown (cursor, bytes); view->dpy_start = topleft; @@ -240,12 +265,15 @@ mcview_moveto_bottom (mcview_t * view) datalines = view->data_area.height; lines_up = mcview_offset_doz (datalines, 1); - if (view->hex_mode) { + if (view->hex_mode) + { last_offset = mcview_offset_doz (filesize, 1); view->hex_cursor = filesize; mcview_move_up (view, lines_up); view->hex_cursor = last_offset; - } else { + } + else + { view->dpy_start = filesize; mcview_move_up (view, 1); } @@ -256,9 +284,12 @@ mcview_moveto_bottom (mcview_t * view) void mcview_moveto_bol (mcview_t * view) { - if (view->hex_mode) { + if (view->hex_mode) + { view->hex_cursor -= view->hex_cursor % view->bytes_per_line; - } else if (!view->text_wrap_mode) { + } + else if (!view->text_wrap_mode) + { view->dpy_start = mcview_bol (view, view->dpy_start); } mcview_movement_fixups (view, TRUE); @@ -269,13 +300,17 @@ mcview_moveto_bol (mcview_t * view) void mcview_moveto_eol (mcview_t * view) { - if (view->hex_mode) { + if (view->hex_mode) + { off_t filesize, bol; bol = mcview_offset_rounddown (view->hex_cursor, view->bytes_per_line); - if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE) { + if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE) + { view->hex_cursor = bol + view->bytes_per_line - 1; - } else { + } + else + { filesize = mcview_get_filesize (view); view->hex_cursor = mcview_offset_doz (filesize, 1); } @@ -288,10 +323,13 @@ mcview_moveto_eol (mcview_t * view) void mcview_moveto_offset (mcview_t * view, off_t offset) { - if (view->hex_mode) { + if (view->hex_mode) + { view->hex_cursor = offset; view->dpy_start = offset - offset % view->bytes_per_line; - } else { + } + else + { view->dpy_start = offset; } mcview_movement_fixups (view, TRUE); @@ -333,8 +371,7 @@ mcview_offset_to_coord (mcview_t * view, off_t * ret_line, off_t * ret_column, o mcview_ccache_lookup (view, &coord, CCACHE_LINECOL); *ret_line = coord.cc_line; - *ret_column = (view->text_nroff_mode) - ? coord.cc_nroff_column : coord.cc_column; + *ret_column = (view->text_nroff_mode) ? coord.cc_nroff_column : coord.cc_column; } /* --------------------------------------------------------------------------------------------- */ @@ -362,10 +399,13 @@ mcview_moveto_match (mcview_t * view) offset = view->search_start; - if (view->hex_mode) { + if (view->hex_mode) + { view->hex_cursor = offset; view->dpy_start = offset - offset % view->bytes_per_line; - } else { + } + else + { view->dpy_start = mcview_bol (view, offset); } diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index 088ff6e4e..95d743fb4 100644 --- a/src/viewer/nroff.c +++ b/src/viewer/nroff.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -79,37 +79,46 @@ mcview_display_nroff (mcview_t * view) /* Find the first displayable changed byte */ from = view->dpy_start; - while (curr && (curr->offset < from)) { + while (curr && (curr->offset < from)) + { curr = curr->next; } tty_setcolor (NORMAL_COLOR); - for (row = 0, col = 0; row < height;) { + for (row = 0, col = 0; row < height;) + { #ifdef HAVE_CHARSET - if (view->utf8) { + if (view->utf8) + { gboolean read_res = TRUE; c = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; - } else + } + else #endif { - if (! mcview_get_byte (view, from, &c)) + if (!mcview_get_byte (view, from, &c)) break; } from++; if (cw > 1) from += cw - 1; - if (c == '\b') { - if (from > 1) { + if (c == '\b') + { + if (from > 1) + { mcview_get_byte (view, from - 2, &c_prev); mcview_get_byte (view, from, &c_next); } if (g_ascii_isprint (c_prev) && g_ascii_isprint (c_prev) - && (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o'))) { - if (col == 0) { - if (row == 0) { + && (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o'))) + { + if (col == 0) + { + if (row == 0) + { /* We're inside an nroff character sequence at the * beginning of the screen -- just skip the * backspace and continue with the next character. */ @@ -128,14 +137,16 @@ mcview_display_nroff (mcview_t * view) } } - if ((c == '\n') || (col >= width && view->text_wrap_mode)) { + if ((c == '\n') || (col >= width && view->text_wrap_mode)) + { col = 0; row++; if (c == '\n' || row >= height) continue; } - if (c == '\r') { + if (c == '\r') + { mcview_get_byte_indexed (view, from, 1, &c); if (c == '\r' || c == '\n') continue; @@ -144,34 +155,45 @@ mcview_display_nroff (mcview_t * view) continue; } - if (c == '\t') { + if (c == '\t') + { off_t line, column; mcview_offset_to_coord (view, &line, &column, from); col += (option_tab_spacing - col % option_tab_spacing); - if (view->text_wrap_mode && col >= width && width != 0) { + if (view->text_wrap_mode && col >= width && width != 0) + { row += col / width; col %= width; } continue; } - if (view->search_start <= from && from < view->search_end) { + if (view->search_start <= from && from < view->search_end) + { tty_setcolor (SELECTED_COLOR); } - if (col >= view->dpy_text_column && col - view->dpy_text_column < width) { + if (col >= view->dpy_text_column && col - view->dpy_text_column < width) + { widget_move (view, top + row, left + (col - view->dpy_text_column)); #ifdef HAVE_CHARSET - if (utf8_display) { - if (!view->utf8) { + if (utf8_display) + { + if (!view->utf8) + { c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); } if (!g_unichar_isprint (c)) c = '.'; - } else { - if (view->utf8) { + } + else + { + if (view->utf8) + { c = convert_from_utf_to_current_c (c, view->converter); - } else { + } + else + { #endif c = convert_to_display_c (c); #ifdef HAVE_CHARSET @@ -182,10 +204,11 @@ mcview_display_nroff (mcview_t * view) } col++; #ifdef HAVE_CHARSET - if (view->utf8) { - if (g_unichar_iswide(c)) + if (view->utf8) + { + if (g_unichar_iswide (c)) col++; - else if (g_unichar_iszerowidth(c)) + else if (g_unichar_iszerowidth (c)) col--; } #endif @@ -207,8 +230,10 @@ mcview__get_nroff_real_len (mcview_t * view, off_t start, off_t length) if (nroff == NULL) return 0; - while (i < length) { - if (nroff->type != NROFF_TYPE_NONE) { + while (i < length) + { + if (nroff->type != NROFF_TYPE_NONE) + { ret += 2; } i++; @@ -227,10 +252,11 @@ mcview_nroff_seq_new_num (mcview_t * view, off_t lc_index) mcview_nroff_t *nroff; nroff = g_try_malloc0 (sizeof (mcview_nroff_t)); - if (nroff != NULL) { - nroff->index = lc_index; - nroff->view = view; - mcview_nroff_seq_info (nroff); + if (nroff != NULL) + { + nroff->index = lc_index; + nroff->view = view; + mcview_nroff_seq_info (nroff); } return nroff; } @@ -266,29 +292,34 @@ mcview_nroff_seq_info (mcview_nroff_t * nroff) return NROFF_TYPE_NONE; nroff->type = NROFF_TYPE_NONE; - if (! mcview_get_byte (nroff->view, nroff->index, &nroff->current_char) - || !g_ascii_isprint (nroff->current_char)) /* FIXME: utf-8 and g_ascii_isprint */ + if (!mcview_get_byte (nroff->view, nroff->index, &nroff->current_char) || !g_ascii_isprint (nroff->current_char)) /* FIXME: utf-8 and g_ascii_isprint */ return nroff->type; nroff->char_width = 1; - if (! mcview_get_byte (nroff->view, nroff->index + 1, &next) || next != '\b') + if (!mcview_get_byte (nroff->view, nroff->index + 1, &next) || next != '\b') return nroff->type; - if (! mcview_get_byte (nroff->view, nroff->index + 2, &next2) - || !g_ascii_isprint (next2)) /* FIXME: utf-8 and g_ascii_isprint */ + if (!mcview_get_byte (nroff->view, nroff->index + 2, &next2) || !g_ascii_isprint (next2)) /* FIXME: utf-8 and g_ascii_isprint */ return nroff->type; - if (nroff->current_char == '_' && next2 == '_') { + if (nroff->current_char == '_' && next2 == '_') + { nroff->type = (nroff->prev_type == NROFF_TYPE_BOLD) ? NROFF_TYPE_BOLD : NROFF_TYPE_UNDERLINE; - } else if (nroff->current_char == next2) { + } + else if (nroff->current_char == next2) + { nroff->type = NROFF_TYPE_BOLD; - } else if (nroff->current_char == '_') { + } + else if (nroff->current_char == '_') + { nroff->current_char = next2; nroff->type = NROFF_TYPE_UNDERLINE; - } else if (nroff->current_char == '+' && next2 == 'o') { + } + else if (nroff->current_char == '+' && next2 == 'o') + { /* ??? */ } diff --git a/src/viewer/plain.c b/src/viewer/plain.c index 7a56576a6..bd0051659 100644 --- a/src/viewer/plain.c +++ b/src/viewer/plain.c @@ -6,17 +6,17 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov - 2010 Andrew Borodin + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + 2010 Andrew Borodin This file is part of the Midnight Commander. @@ -45,7 +45,7 @@ #include "lib/global.h" #include "src/main.h" #include "src/charsets.h" -#include "mcviewer.h" /* mcview_show_eof */ +#include "mcviewer.h" /* mcview_show_eof */ #include "internal.h" @@ -85,30 +85,34 @@ mcview_display_text (mcview_t * view) while ((curr != NULL) && (curr->offset < from)) curr = curr->next; - while (TRUE) { + while (TRUE) + { tty_setcolor (NORMAL_COLOR); if (row >= height) break; #ifdef HAVE_CHARSET - if (view->utf8) { + if (view->utf8) + { gboolean read_res = TRUE; c = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; - } else + } + else #endif - if (!mcview_get_byte (view, from, &c)) - break; + if (!mcview_get_byte (view, from, &c)) + break; last_row = FALSE; from++; if (cw > 1) from += cw - 1; - if (c != '\n' && prev_ch == '\r') { + if (c != '\n' && prev_ch == '\r') + { if (++row >= height) break; @@ -120,21 +124,25 @@ mcview_display_text (mcview_t * view) if (c == '\r') continue; - if (c == '\n') { + if (c == '\n') + { col = 0; row++; continue; } - if (col >= width && view->text_wrap_mode) { + if (col >= width && view->text_wrap_mode) + { col = 0; if (++row >= height) break; } - if (c == '\t') { + if (c == '\t') + { col += (option_tab_spacing - col % option_tab_spacing); - if (view->text_wrap_mode && col >= width && width != 0) { + if (view->text_wrap_mode && col >= width && width != 0) + { row += col / width; col %= width; } @@ -144,15 +152,18 @@ mcview_display_text (mcview_t * view) if (view->search_start <= from && from < view->search_end) tty_setcolor (SELECTED_COLOR); - if ((col >= view->dpy_text_column) && (col - view->dpy_text_column < width)) { + if ((col >= view->dpy_text_column) && (col - view->dpy_text_column < width)) + { widget_move (view, top + row, left + (col - view->dpy_text_column)); #ifdef HAVE_CHARSET - if (utf8_display) { + if (utf8_display) + { if (!view->utf8) c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); if (!g_unichar_isprint (c)) c = '.'; - } else if (view->utf8) + } + else if (view->utf8) c = convert_from_utf_to_current_c (c, view->converter); else #endif @@ -169,7 +180,8 @@ mcview_display_text (mcview_t * view) col++; #ifdef HAVE_CHARSET - if (view->utf8) { + if (view->utf8) + { if (g_unichar_iswide (c)) col++; else if (g_unichar_iszerowidth (c)) @@ -179,11 +191,13 @@ mcview_display_text (mcview_t * view) } view->dpy_end = from; - if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0') { + if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0') + { if (last_row && mcview_get_byte (view, from - 1, &c)) if (c != '\n') row--; - while (++row < height) { + while (++row < height) + { widget_move (view, top + row, left); tty_print_string (mcview_show_eof); } diff --git a/src/viewer/search.c b/src/viewer/search.c index 50faf9abc..8773fc01a 100644 --- a/src/viewer/search.c +++ b/src/viewer/search.c @@ -6,16 +6,16 @@ 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by: 1994, 1995, 1998 Miguel de Icaza - 1994, 1995 Janne Kukonlehto - 1995 Jakub Jelinek - 1996 Joseph M. Hinkle - 1997 Norbert Warmuth - 1998 Pavel Machek - 2004 Roland Illig - 2005 Roland Illig - 2009 Slava Zanko - 2009 Andrew Borodin - 2009 Ilia Maslakov + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov This file is part of the Midnight Commander. @@ -78,9 +78,11 @@ mcview_find (mcview_t * view, gsize search_start, gsize * len) view->search_numNeedSkipChar = 0; - if (mcview_search_options.backwards) { + if (mcview_search_options.backwards) + { search_end = mcview_get_filesize (view); - while ((int) search_start >= 0) { + while ((int) search_start >= 0) + { view->search_nroff_seq->index = search_start; mcview_nroff_seq_info (view->search_nroff_seq); @@ -107,35 +109,36 @@ mcview_find (mcview_t * view, gsize search_start, gsize * len) /* --------------------------------------------------------------------------------------------- */ static void -mcview_search_show_result(mcview_t * view, Dlg_head **d, size_t match_len) +mcview_search_show_result (mcview_t * view, Dlg_head ** d, size_t match_len) { - view->search_start = view->search->normal_offset + - mcview__get_nroff_real_len (view, - view->search->start_buffer, - view->search->normal_offset - - view->search->start_buffer); + view->search_start = view->search->normal_offset + + mcview__get_nroff_real_len (view, + view->search->start_buffer, + view->search->normal_offset - view->search->start_buffer); - if (!view->hex_mode) - view->search_start++; + if (!view->hex_mode) + view->search_start++; - view->search_end = view->search_start + match_len + - mcview__get_nroff_real_len (view, view->search_start - 1, match_len); + view->search_end = view->search_start + match_len + + mcview__get_nroff_real_len (view, view->search_start - 1, match_len); - if (view->hex_mode) { - view->hex_cursor = view->search_start; - view->hexedit_lownibble = FALSE; - view->dpy_start = view->search_start - view->search_start % view->bytes_per_line; - view->dpy_end = view->search_end - view->search_end % view->bytes_per_line; - } + if (view->hex_mode) + { + view->hex_cursor = view->search_start; + view->hexedit_lownibble = FALSE; + view->dpy_start = view->search_start - view->search_start % view->bytes_per_line; + view->dpy_end = view->search_end - view->search_end % view->bytes_per_line; + } - if (verbose) { - dlg_run_done (*d); - destroy_dlg (*d); - *d = create_message (D_NORMAL, _("Search"), _("Seeking to search result")); - tty_refresh (); - } - mcview_moveto_match (view); + if (verbose) + { + dlg_run_done (*d); + destroy_dlg (*d); + *d = create_message (D_NORMAL, _("Search"), _("Seeking to search result")); + tty_refresh (); + } + mcview_moveto_match (view); } @@ -152,14 +155,16 @@ mcview_search_cmd_callback (const void *user_data, gsize char_offset) mcview_t *view = (mcview_t *) user_data; /* view_read_continue (view, &view->search_onechar_info); *//* AB:FIXME */ - if (!view->text_nroff_mode) { - if (! mcview_get_byte (view, char_offset, &lc_byte)) + if (!view->text_nroff_mode) + { + if (!mcview_get_byte (view, char_offset, &lc_byte)) return MC_SEARCH_CB_INVALID; return lc_byte; } - if (view->search_numNeedSkipChar) { + if (view->search_numNeedSkipChar) + { view->search_numNeedSkipChar--; return MC_SEARCH_CB_SKIP; } @@ -184,9 +189,11 @@ mcview_search_update_cmd_callback (const void *user_data, gsize char_offset) { mcview_t *view = (mcview_t *) user_data; - if (char_offset >= (gsize) view->update_activate) { + if (char_offset >= (gsize) view->update_activate) + { view->update_activate += view->update_steps; - if (verbose) { + if (verbose) + { mcview_percent (view, char_offset); tty_refresh (); } @@ -212,18 +219,22 @@ mcview_do_search (mcview_t * view) size_t match_len; - if (verbose) { + if (verbose) + { d = create_message (D_NORMAL, _("Search"), _("Searching %s"), view->last_search_string); tty_refresh (); } /*for avoid infinite search loop we need to increase or decrease start offset of search */ - if (view->search_start) { + if (view->search_start) + { search_start = (mcview_search_options.backwards) ? -2 : 2; search_start = view->search_start + search_start + mcview__get_nroff_real_len (view, view->search_start, 2) * search_start; - } else { + } + else + { search_start = view->search_start; } @@ -236,19 +247,22 @@ mcview_do_search (mcview_t * view) tty_enable_interrupt_key (); - do { + do + { if (view->growbuf_in_use) growbufsize = mcview_growbuf_filesize (view); else growbufsize = view->search->original_len; - if (! mcview_find (view, search_start, &match_len)) { + if (!mcview_find (view, search_start, &match_len)) + { if (view->search->error_str == NULL) break; search_start = growbufsize - view->search->original_len; - if ( search_start <= 0 ) { + if (search_start <= 0) + { search_start = 0; break; } @@ -256,32 +270,40 @@ mcview_do_search (mcview_t * view) continue; } - mcview_search_show_result(view, &d, match_len); + mcview_search_show_result (view, &d, match_len); need_search_again = FALSE; isFound = TRUE; break; - } while (mcview_may_still_grow (view)); + } + while (mcview_may_still_grow (view)); - if (!isFound && need_search_again && !mcview_search_options.backwards) { + if (!isFound && need_search_again && !mcview_search_options.backwards) + { int result; mcview_update (view); result = - query_dialog (_("Search done"), _("Continue from begining?"), D_NORMAL, 2, _("&Yes"), _("&No")); + query_dialog (_("Search done"), _("Continue from begining?"), D_NORMAL, 2, _("&Yes"), + _("&No")); - if (result != 0) { - isFound=TRUE; - } else { + if (result != 0) + { + isFound = TRUE; + } + else + { search_start = 0; } } - if (!isFound && view->search->error_str != NULL && mcview_find (view, search_start, &match_len)) { - mcview_search_show_result(view, &d, match_len); + if (!isFound && view->search->error_str != NULL && mcview_find (view, search_start, &match_len)) + { + mcview_search_show_result (view, &d, match_len); isFound = TRUE; } - if (!isFound) { + if (!isFound) + { if (view->search->error_str) message (D_NORMAL, _("Search"), "%s", view->search->error_str); } @@ -290,7 +312,8 @@ mcview_do_search (mcview_t * view) mcview_update (view); tty_disable_interrupt_key (); - if (verbose) { + if (verbose) + { dlg_run_done (d); destroy_dlg (d); }