root/src/filemanager/chattr.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. chattr_is_modifiable
  2. chattr_fill_str
  3. fileattrtext_fill
  4. fileattrtext_callback
  5. fileattrtext_new
  6. chattr_draw_select
  7. chattr_toggle_select
  8. chattrboxes_draw_scrollbar
  9. chattrboxes_draw
  10. chattrboxes_rename
  11. checkboxes_save_state
  12. chattrboxes_down
  13. chattrboxes_page_down
  14. chattrboxes_end
  15. chattrboxes_up
  16. chattrboxes_page_up
  17. chattrboxes_home
  18. chattrboxes_execute_cmd
  19. chattrboxes_key
  20. chattrboxes_callback
  21. chattrboxes_handle_mouse_event
  22. chattrboxes_mouse_callback
  23. chattrboxes_new
  24. chattr_init
  25. chattr_dlg_create
  26. chattr_done
  27. next_file
  28. try_chattr
  29. do_chattr
  30. chattr_apply_mask
  31. chattr_cmd
  32. chattr_get_as_str

   1 /*
   2    Chattr command -- for the Midnight Commander
   3 
   4    Copyright (C) 2020
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2020
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 /** \file chattr.c
  27  *  \brief Source: chattr command
  28  */
  29 
  30 /* TODO: change attributes recursively (ticket #3109) */
  31 
  32 #include <config.h>
  33 
  34 #include <errno.h>
  35 #include <sys/types.h>
  36 #include <sys/stat.h>
  37 
  38 #include <e2p/e2p.h>
  39 #include <ext2fs/ext2_fs.h>
  40 
  41 #include "lib/global.h"
  42 
  43 #include "lib/tty/tty.h"        /* tty_print*() */
  44 #include "lib/tty/color.h"      /* tty_setcolor() */
  45 #include "lib/skin.h"           /* COLOR_NORMAL, DISABLED_COLOR */
  46 #include "lib/vfs/vfs.h"
  47 #include "lib/widget.h"
  48 
  49 #include "src/keybind-defaults.h"       /* chattr_map */
  50 
  51 #include "midnight.h"           /* current_panel */
  52 #include "panel.h"              /* do_file_mark() */
  53 
  54 #include "chattr.h"
  55 
  56 /*** global variables ****************************************************************************/
  57 
  58 /*** file scope macro definitions ****************************************************************/
  59 
  60 #define B_MARKED B_USER
  61 #define B_SETALL (B_USER + 1)
  62 #define B_SETMRK (B_USER + 2)
  63 #define B_CLRMRK (B_USER + 3)
  64 
  65 #define BUTTONS  6
  66 
  67 #define CHATTRBOXES(x) ((WChattrBoxes *)(x))
  68 
  69 /*** file scope type declarations ****************************************************************/
  70 
  71 typedef struct WFileAttrText WFileAttrText;
  72 
  73 struct WFileAttrText
  74 {
  75     Widget widget;              /* base class */
  76 
  77     char *filename;
  78     int filename_width;         /* cached width of file name */
  79     char attrs[32 + 1];         /* 32 bits in attributes (unsigned long) */
  80 };
  81 
  82 typedef struct WChattrBoxes WChattrBoxes;
  83 
  84 struct WChattrBoxes
  85 {
  86     WGroup base;                /* base class */
  87 
  88     int pos;                    /* The current checkbox selected */
  89     int top;                    /* The first flag displayed */
  90 };
  91 
  92 /*** file scope variables ************************************************************************/
  93 
  94 /* see /usr/include/ext2fs/ext2_fs.h
  95  *
  96  * EXT2_SECRM_FL            0x00000001 -- Secure deletion
  97  * EXT2_UNRM_FL             0x00000002 -- Undelete
  98  * EXT2_COMPR_FL            0x00000004 -- Compress file
  99  * EXT2_SYNC_FL             0x00000008 -- Synchronous updates
 100  * EXT2_IMMUTABLE_FL        0x00000010 -- Immutable file
 101  * EXT2_APPEND_FL           0x00000020 -- writes to file may only append
 102  * EXT2_NODUMP_FL           0x00000040 -- do not dump file
 103  * EXT2_NOATIME_FL          0x00000080 -- do not update atime
 104  * * Reserved for compression usage...
 105  * EXT2_DIRTY_FL            0x00000100
 106  * EXT2_COMPRBLK_FL         0x00000200 -- One or more compressed clusters
 107  * EXT2_NOCOMPR_FL          0x00000400 -- Access raw compressed data
 108  * * nb: was previously EXT2_ECOMPR_FL
 109  * EXT4_ENCRYPT_FL          0x00000800 -- encrypted inode
 110  * * End compression flags --- maybe not all used
 111  * EXT2_BTREE_FL            0x00001000 -- btree format dir
 112  * EXT2_INDEX_FL            0x00001000 -- hash-indexed directory
 113  * EXT2_IMAGIC_FL           0x00002000
 114  * EXT3_JOURNAL_DATA_FL     0x00004000 -- file data should be journaled
 115  * EXT2_NOTAIL_FL           0x00008000 -- file tail should not be merged
 116  * EXT2_DIRSYNC_FL          0x00010000 -- Synchronous directory modifications
 117  * EXT2_TOPDIR_FL           0x00020000 -- Top of directory hierarchies
 118  * EXT4_HUGE_FILE_FL        0x00040000 -- Set to each huge file
 119  * EXT4_EXTENTS_FL          0x00080000 -- Inode uses extents
 120  * EXT4_VERITY_FL           0x00100000 -- Verity protected inode
 121  * EXT4_EA_INODE_FL         0x00200000 -- Inode used for large EA
 122  * EXT4_EOFBLOCKS_FL        0x00400000 was here, unused
 123  * FS_NOCOW_FL              0x00800000 -- Do not cow file
 124  * EXT4_SNAPFILE_FL         0x01000000 -- Inode is a snapshot
 125  *                          0x02000000 -- unused yet
 126  * EXT4_SNAPFILE_DELETED_FL 0x04000000 -- Snapshot is being deleted
 127  * EXT4_SNAPFILE_SHRUNK_FL  0x08000000 -- Snapshot shrink has completed
 128  * EXT4_INLINE_DATA_FL      0x10000000 -- Inode has inline data
 129  * EXT4_PROJINHERIT_FL      0x20000000 -- Create with parents projid
 130  * EXT4_CASEFOLD_FL         0x40000000 -- Casefolded file
 131  *                          0x80000000 -- unused yet
 132  */
 133 
 134 static struct
 135 {
 136     unsigned long flags;
 137     char attr;
 138     const char *text;
 139     gboolean selected;
 140     gboolean state;             /* state of checkboxes */
 141 } check_attr[] =
 142 {
 143     /* *INDENT-OFF* */
 144     { EXT2_SECRM_FL,        's', N_("Secure deletion"),               FALSE, FALSE },
 145     { EXT2_UNRM_FL,         'u', N_("Undelete"),                      FALSE, FALSE },
 146     { EXT2_SYNC_FL,         'S', N_("Synchronous updates"),           FALSE, FALSE },
 147     { EXT2_DIRSYNC_FL,      'D', N_("Synchronous directory updates"), FALSE, FALSE },
 148     { EXT2_IMMUTABLE_FL,    'i', N_("Immutable"),                     FALSE, FALSE },
 149     { EXT2_APPEND_FL,       'a', N_("Append only"),                   FALSE, FALSE },
 150     { EXT2_NODUMP_FL,       'd', N_("No dump"),                       FALSE, FALSE },
 151     { EXT2_NOATIME_FL,      'A', N_("No update atime"),               FALSE, FALSE },
 152     { EXT2_COMPR_FL,        'c', N_("Compress"),                      FALSE, FALSE },
 153 #ifdef EXT2_COMPRBLK_FL
 154     /* removed in v1.43-WIP-2015-05-18
 155        ext2fsprogs 4a05268cf86f7138c78d80a53f7e162f32128a3d 2015-04-12 */
 156     { EXT2_COMPRBLK_FL,     'B', N_("Compressed clusters"),           FALSE, FALSE },
 157 #endif
 158 #ifdef EXT2_DIRTY_FL
 159     /* removed in v1.43-WIP-2015-05-18
 160        ext2fsprogs 4a05268cf86f7138c78d80a53f7e162f32128a3d 2015-04-12 */
 161     { EXT2_DIRTY_FL,        'Z', N_("Compressed dirty file"),         FALSE, FALSE },
 162 #endif
 163 #ifdef EXT2_NOCOMPR_FL
 164     /* removed in v1.43-WIP-2015-05-18
 165        ext2fsprogs 4a05268cf86f7138c78d80a53f7e162f32128a3d 2015-04-12 */
 166     { EXT2_NOCOMPR_FL,      'X', N_("Compression raw access"),        FALSE, FALSE },
 167 #endif
 168 #ifdef EXT4_ENCRYPT_FL
 169     { EXT4_ENCRYPT_FL,      'E', N_("Encrypted inode"),               FALSE, FALSE },
 170 #endif
 171     { EXT3_JOURNAL_DATA_FL, 'j', N_("Journaled data"),                FALSE, FALSE },
 172     { EXT2_INDEX_FL,        'I', N_("Indexed directory"),             FALSE, FALSE },
 173     { EXT2_NOTAIL_FL,       't', N_("No tail merging"),               FALSE, FALSE },
 174     { EXT2_TOPDIR_FL,       'T', N_("Top of directory hierarchies"),  FALSE, FALSE },
 175     { EXT4_EXTENTS_FL,      'e', N_("Inode uses extents"),            FALSE, FALSE },
 176 #ifdef EXT4_HUGE_FILE_FL
 177     /* removed in v1.43.9
 178        ext2fsprogs 4825daeb0228e556444d199274b08c499ac3706c 2018-02-06 */
 179     { EXT4_HUGE_FILE_FL,    'h', N_("Huge_file"),                     FALSE, FALSE },
 180 #endif
 181     { FS_NOCOW_FL,          'C', N_("No COW"),                        FALSE, FALSE },
 182 #ifdef EXT4_CASEFOLD_FL
 183     /* added in v1.45.0
 184        ext2fsprogs 1378bb6515e98a27f0f5c220381d49d20544204e 2018-12-01 */
 185     { EXT4_CASEFOLD_FL,     'F', N_("Casefolded file"),               FALSE, FALSE },
 186 #endif
 187 #ifdef EXT4_INLINE_DATA_FL
 188     { EXT4_INLINE_DATA_FL,  'N', N_("Inode has inline data"),         FALSE, FALSE },
 189 #endif
 190 #ifdef EXT4_PROJINHERIT_FL
 191     /* added in v1.43-WIP-2016-05-12
 192        ext2fsprogs e1cec4464bdaf93ea609de43c5cdeb6a1f553483 2016-03-07
 193                    97d7e2fdb2ebec70c3124c1a6370d28ec02efad0 2016-05-09 */
 194     { EXT4_PROJINHERIT_FL,  'P', N_("Project hierarchy"),             FALSE, FALSE },
 195 #endif
 196 #ifdef EXT4_VERITY_FL
 197     /* added in v1.44.4
 198        ext2fsprogs faae7aa00df0abe7c6151fc4947aa6501b981ee1 2018-08-14
 199        v1.44.5
 200        ext2fsprogs 7e5a95e3d59719361661086ec7188ca6e674f139 2018-08-21 */
 201     { EXT4_VERITY_FL,       'V', N_("Verity protected inode"),        FALSE, FALSE }
 202 #endif
 203     /* *INDENT-ON* */
 204 };
 205 
 206 /* number of attributes */
 207 static const size_t check_attr_num = G_N_ELEMENTS (check_attr);
 208 
 209 /* modifable attribute numbers */
 210 static int check_attr_mod[32];
 211 static int check_attr_mod_num = 0;      /* 0..31 */
 212 
 213 /* maximum width of attribute text */
 214 static int check_attr_width = 0;
 215 
 216 static struct
 217 {
 218     int ret_cmd;
 219     button_flags_t flags;
 220     int width;
 221     const char *text;
 222     Widget *button;
 223 } chattr_but[BUTTONS] =
 224 {
 225     /* *INDENT-OFF* */
 226     /* 0 */ { B_SETALL, NORMAL_BUTTON, 0, N_("Set &all"),      NULL },
 227     /* 1 */ { B_MARKED, NORMAL_BUTTON, 0, N_("&Marked all"),   NULL },
 228     /* 2 */ { B_SETMRK, NORMAL_BUTTON, 0, N_("S&et marked"),   NULL },
 229     /* 3 */ { B_CLRMRK, NORMAL_BUTTON, 0, N_("C&lear marked"), NULL },
 230     /* 4 */ { B_ENTER, DEFPUSH_BUTTON, 0, N_("&Set"),          NULL },
 231     /* 5 */ { B_CANCEL, NORMAL_BUTTON, 0, N_("&Cancel"),       NULL }
 232     /* *INDENT-ON* */
 233 };
 234 
 235 static gboolean flags_changed;
 236 static int current_file;
 237 static gboolean ignore_all;
 238 
 239 static unsigned long and_mask, or_mask, flags;
 240 
 241 static WFileAttrText *file_attr;
 242 
 243 /* x-coord of widget in the dialog */
 244 static const int wx = 3;
 245 
 246 /* --------------------------------------------------------------------------------------------- */
 247 /*** file scope functions ************************************************************************/
 248 /* --------------------------------------------------------------------------------------------- */
 249 
 250 static inline gboolean
 251 chattr_is_modifiable (size_t i)
     /* [previous][next][first][last][top][bottom][index][help]  */
 252 {
 253     return ((check_attr[i].flags & EXT2_FL_USER_MODIFIABLE) != 0);
 254 }
 255 
 256 /* --------------------------------------------------------------------------------------------- */
 257 
 258 static void
 259 chattr_fill_str (unsigned long attr, char *str)
     /* [previous][next][first][last][top][bottom][index][help]  */
 260 {
 261     size_t i;
 262 
 263     for (i = 0; i < check_attr_num; i++)
 264         str[i] = (attr & check_attr[i].flags) != 0 ? check_attr[i].attr : '-';
 265 
 266     str[check_attr_num] = '\0';
 267 }
 268 
 269 /* --------------------------------------------------------------------------------------------- */
 270 
 271 static void
 272 fileattrtext_fill (WFileAttrText * fat, unsigned long attr)
     /* [previous][next][first][last][top][bottom][index][help]  */
 273 {
 274     chattr_fill_str (attr, fat->attrs);
 275     widget_draw (WIDGET (fat));
 276 }
 277 
 278 /* --------------------------------------------------------------------------------------------- */
 279 
 280 static cb_ret_t
 281 fileattrtext_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
 282 {
 283     WFileAttrText *fat = (WFileAttrText *) w;
 284 
 285     switch (msg)
 286     {
 287     case MSG_DRAW:
 288         {
 289             int color;
 290             size_t i;
 291 
 292             color = COLOR_NORMAL;
 293             tty_setcolor (color);
 294 
 295             if (w->cols > fat->filename_width)
 296             {
 297                 widget_gotoyx (w, 0, (w->cols - fat->filename_width) / 2);
 298                 tty_print_string (fat->filename);
 299             }
 300             else
 301             {
 302                 widget_gotoyx (w, 0, 0);
 303                 tty_print_string (str_trunc (fat->filename, w->cols));
 304             }
 305 
 306             /* hope that w->cols is greater than check_attr_num */
 307             widget_gotoyx (w, 1, (w->cols - check_attr_num) / 2);
 308             for (i = 0; i < check_attr_num; i++)
 309             {
 310                 /* Do not set new color for each symbol. Try to use previous color. */
 311                 if (chattr_is_modifiable (i))
 312                 {
 313                     if (color == DISABLED_COLOR)
 314                     {
 315                         color = COLOR_NORMAL;
 316                         tty_setcolor (color);
 317                     }
 318                 }
 319                 else
 320                 {
 321                     if (color != DISABLED_COLOR)
 322                     {
 323                         color = DISABLED_COLOR;
 324                         tty_setcolor (color);
 325                     }
 326                 }
 327 
 328                 tty_print_char (fat->attrs[i]);
 329             }
 330             return MSG_HANDLED;
 331         }
 332 
 333     case MSG_RESIZE:
 334         {
 335             Widget *wo = WIDGET (w->owner);
 336 
 337             widget_default_callback (w, sender, msg, parm, data);
 338             /* intially file name may be wider than screen */
 339             if (fat->filename_width > wo->cols - wx * 2)
 340             {
 341                 w->x = wo->x + wx;
 342                 w->cols = wo->cols - wx * 2;
 343             }
 344             return MSG_HANDLED;
 345         }
 346 
 347     case MSG_DESTROY:
 348         g_free (fat->filename);
 349         return MSG_HANDLED;
 350 
 351     default:
 352         return widget_default_callback (w, sender, msg, parm, data);
 353     }
 354 }
 355 
 356 /* --------------------------------------------------------------------------------------------- */
 357 
 358 static WFileAttrText *
 359 fileattrtext_new (int y, int x, const char *filename, unsigned long attr)
     /* [previous][next][first][last][top][bottom][index][help]  */
 360 {
 361     WFileAttrText *fat;
 362     int width, cols;
 363 
 364     width = str_term_width1 (filename);
 365     cols = MAX (width, (int) check_attr_num);
 366 
 367     fat = g_new (WFileAttrText, 1);
 368     widget_init (WIDGET (fat), y, x, 2, cols, fileattrtext_callback, NULL);
 369 
 370     fat->filename = g_strdup (filename);
 371     fat->filename_width = width;
 372     fileattrtext_fill (fat, attr);
 373 
 374     return fat;
 375 }
 376 
 377 /* --------------------------------------------------------------------------------------------- */
 378 
 379 static void
 380 chattr_draw_select (const Widget * w, gboolean selected)
     /* [previous][next][first][last][top][bottom][index][help]  */
 381 {
 382     widget_gotoyx (w, 0, -1);
 383     tty_print_char (selected ? '*' : ' ');
 384     widget_gotoyx (w, 0, 1);
 385 }
 386 
 387 /* --------------------------------------------------------------------------------------------- */
 388 
 389 static void
 390 chattr_toggle_select (const WChattrBoxes * cb, int Id)
     /* [previous][next][first][last][top][bottom][index][help]  */
 391 {
 392     Widget *w;
 393 
 394     /* find checkbox */
 395     w = WIDGET (g_list_nth_data (GROUP (cb)->widgets, Id - cb->top));
 396 
 397     check_attr[Id].selected = !check_attr[Id].selected;
 398 
 399     tty_setcolor (COLOR_NORMAL);
 400     chattr_draw_select (w, check_attr[Id].selected);
 401 }
 402 
 403 /* --------------------------------------------------------------------------------------------- */
 404 
 405 static inline void
 406 chattrboxes_draw_scrollbar (const WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 407 {
 408     const Widget *w = CONST_WIDGET (cb);
 409     int max_line;
 410     int line;
 411     int i;
 412 
 413     /* Are we at the top? */
 414     widget_gotoyx (w, 0, w->cols);
 415     if (cb->top == 0)
 416         tty_print_one_vline (TRUE);
 417     else
 418         tty_print_char ('^');
 419 
 420     max_line = w->lines - 1;
 421 
 422     /* Are we at the bottom? */
 423     widget_gotoyx (w, max_line, w->cols);
 424     if (cb->top + w->lines == check_attr_mod_num || w->lines >= check_attr_mod_num)
 425         tty_print_one_vline (TRUE);
 426     else
 427         tty_print_char ('v');
 428 
 429     /* Now draw the nice relative pointer */
 430     line = 1 + (cb->pos * (w->lines - 2)) / check_attr_mod_num;
 431 
 432     for (i = 1; i < max_line; i++)
 433     {
 434         widget_gotoyx (w, i, w->cols);
 435         if (i != line)
 436             tty_print_one_vline (TRUE);
 437         else
 438             tty_print_char ('*');
 439     }
 440 }
 441 
 442 /* --------------------------------------------------------------------------------------------- */
 443 
 444 static void
 445 chattrboxes_draw (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 446 {
 447     Widget *w = WIDGET (cb);
 448     int i;
 449     GList *l;
 450     const int *colors;
 451 
 452     colors = widget_get_colors (w);
 453     tty_setcolor (colors[DLG_COLOR_NORMAL]);
 454     tty_fill_region (w->y, w->x - 1, w->lines, w->cols + 1, ' ');
 455 
 456     /* redraw checkboxes */
 457     group_default_callback (w, NULL, MSG_DRAW, 0, NULL);
 458 
 459     /* draw scrollbar */
 460     tty_setcolor (colors[DLG_COLOR_NORMAL]);
 461     if (!mc_global.tty.slow_terminal && check_attr_mod_num > w->lines)
 462         chattrboxes_draw_scrollbar (cb);
 463 
 464     /* mark selected checkboxes */
 465     for (i = cb->top, l = GROUP (cb)->widgets; l != NULL; i++, l = g_list_next (l))
 466         chattr_draw_select (WIDGET (l->data), check_attr[i].selected);
 467 }
 468 
 469 /* --------------------------------------------------------------------------------------------- */
 470 
 471 static void
 472 chattrboxes_rename (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 473 {
 474     Widget *w = WIDGET (cb);
 475     gboolean active;
 476     int i;
 477     GList *l;
 478     char btext[BUF_SMALL];      /* FIXME: is 128 bytes enough? */
 479 
 480     active = widget_get_state (w, WST_ACTIVE);
 481 
 482     /* lock the group to avoid redraw of checkboxes individually */
 483     if (active)
 484         widget_set_state (w, WST_SUSPENDED, TRUE);
 485 
 486     for (i = cb->top, l = GROUP (cb)->widgets; l != NULL; i++, l = g_list_next (l))
 487     {
 488         WCheck *c = CHECK (l->data);
 489         int m;
 490 
 491         m = check_attr_mod[i];
 492         g_snprintf (btext, sizeof (btext), "(%c) %s", check_attr[m].attr, check_attr[m].text);
 493         check_set_text (c, btext);
 494         c->state = check_attr[m].state;
 495     }
 496 
 497     /* unlock */
 498     if (active)
 499         widget_set_state (w, WST_ACTIVE, TRUE);
 500 
 501     widget_draw (w);
 502 }
 503 
 504 /* --------------------------------------------------------------------------------------------- */
 505 
 506 static void
 507 checkboxes_save_state (const WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 508 {
 509     int i;
 510     GList *l;
 511 
 512     for (i = cb->top, l = GROUP (cb)->widgets; l != NULL; i++, l = g_list_next (l))
 513     {
 514         int m;
 515 
 516         m = check_attr_mod[i];
 517         check_attr[m].state = CHECK (l->data)->state;
 518     }
 519 }
 520 
 521 /* --------------------------------------------------------------------------------------------- */
 522 
 523 static cb_ret_t
 524 chattrboxes_down (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 525 {
 526     if (cb->pos == cb->top + WIDGET (cb)->lines - 1)
 527     {
 528         /* We are on the last checkbox.
 529            Keep this position. */
 530 
 531         if (cb->pos == check_attr_mod_num - 1)
 532             /* get out of widget */
 533             return MSG_NOT_HANDLED;
 534 
 535         /* emulate scroll of checkboxes */
 536         checkboxes_save_state (cb);
 537         cb->pos++;
 538         cb->top++;
 539         chattrboxes_rename (cb);
 540     }
 541     else                        /* cb->pos > cb-top */
 542     {
 543         GList *l;
 544 
 545         /* select next checkbox */
 546         cb->pos++;
 547         l = g_list_next (GROUP (cb)->current);
 548         widget_select (WIDGET (l->data));
 549     }
 550 
 551     return MSG_HANDLED;
 552 }
 553 
 554 /* --------------------------------------------------------------------------------------------- */
 555 
 556 static cb_ret_t
 557 chattrboxes_page_down (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 558 {
 559     WGroup *g = GROUP (cb);
 560     GList *l;
 561 
 562     if (cb->pos == check_attr_mod_num - 1)
 563     {
 564         /* We are on the last checkbox.
 565            Keep this position.
 566            Do nothing. */
 567         l = g_list_last (g->widgets);
 568     }
 569     else
 570     {
 571         int i = WIDGET (cb)->lines;
 572 
 573         checkboxes_save_state (cb);
 574 
 575         if (cb->top > check_attr_mod_num - 2 * i)
 576             i = check_attr_mod_num - i - cb->top;
 577         if (cb->top + i < 0)
 578             i = -cb->top;
 579         if (i == 0)
 580         {
 581             cb->pos = check_attr_mod_num - 1;
 582             cb->top += i;
 583             l = g_list_last (g->widgets);
 584         }
 585         else
 586         {
 587             cb->pos += i;
 588             cb->top += i;
 589             l = g_list_nth (g->widgets, cb->pos - cb->top);
 590         }
 591 
 592         chattrboxes_rename (cb);
 593     }
 594 
 595     widget_select (WIDGET (l->data));
 596 
 597     return MSG_HANDLED;
 598 }
 599 
 600 /* --------------------------------------------------------------------------------------------- */
 601 
 602 static cb_ret_t
 603 chattrboxes_end (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 604 {
 605     GList *l;
 606 
 607     checkboxes_save_state (cb);
 608     cb->pos = check_attr_mod_num - 1;
 609     cb->top = cb->pos - WIDGET (cb)->lines + 1;
 610     l = g_list_last (GROUP (cb)->widgets);
 611     chattrboxes_rename (cb);
 612     widget_select (WIDGET (l->data));
 613 
 614     return MSG_HANDLED;
 615 }
 616 
 617 /* --------------------------------------------------------------------------------------------- */
 618 
 619 static cb_ret_t
 620 chattrboxes_up (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 621 {
 622     if (cb->pos == cb->top)
 623     {
 624         /* We are on the first checkbox.
 625            Keep this position. */
 626 
 627         if (cb->top == 0)
 628             /* get out of widget */
 629             return MSG_NOT_HANDLED;
 630 
 631         /* emulate scroll of checkboxes */
 632         checkboxes_save_state (cb);
 633         cb->pos--;
 634         cb->top--;
 635         chattrboxes_rename (cb);
 636     }
 637     else                        /* cb->pos > cb-top */
 638     {
 639         GList *l;
 640 
 641         /* select previous checkbox */
 642         cb->pos--;
 643         l = g_list_previous (GROUP (cb)->current);
 644         widget_select (WIDGET (l->data));
 645     }
 646 
 647     return MSG_HANDLED;
 648 }
 649 
 650 /* --------------------------------------------------------------------------------------------- */
 651 
 652 static cb_ret_t
 653 chattrboxes_page_up (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 654 {
 655     WGroup *g = GROUP (cb);
 656     GList *l;
 657 
 658     if (cb->pos == 0 && cb->top == 0)
 659     {
 660         /* We are on the first checkbox.
 661            Keep this position.
 662            Do nothing. */
 663         l = g_list_first (g->widgets);
 664     }
 665     else
 666     {
 667         int i = WIDGET (cb)->lines;
 668 
 669         checkboxes_save_state (cb);
 670 
 671         if (cb->top < i)
 672             i = cb->top;
 673         if (i == 0)
 674         {
 675             cb->pos = 0;
 676             cb->top -= i;
 677             l = g_list_first (g->widgets);
 678         }
 679         else
 680         {
 681             cb->pos -= i;
 682             cb->top -= i;
 683             l = g_list_nth (g->widgets, cb->pos - cb->top);
 684         }
 685 
 686         chattrboxes_rename (cb);
 687     }
 688 
 689     widget_select (WIDGET (l->data));
 690 
 691     return MSG_HANDLED;
 692 }
 693 
 694 /* --------------------------------------------------------------------------------------------- */
 695 
 696 static cb_ret_t
 697 chattrboxes_home (WChattrBoxes * cb)
     /* [previous][next][first][last][top][bottom][index][help]  */
 698 {
 699     GList *l;
 700 
 701     checkboxes_save_state (cb);
 702     cb->pos = 0;
 703     cb->top = 0;
 704     l = g_list_first (GROUP (cb)->widgets);
 705     chattrboxes_rename (cb);
 706     widget_select (WIDGET (l->data));
 707 
 708     return MSG_HANDLED;
 709 }
 710 
 711 /* --------------------------------------------------------------------------------------------- */
 712 
 713 static cb_ret_t
 714 chattrboxes_execute_cmd (WChattrBoxes * cb, long command)
     /* [previous][next][first][last][top][bottom][index][help]  */
 715 {
 716     switch (command)
 717     {
 718     case CK_Down:
 719         return chattrboxes_down (cb);
 720 
 721     case CK_PageDown:
 722         return chattrboxes_page_down (cb);
 723 
 724     case CK_Bottom:
 725         return chattrboxes_end (cb);
 726 
 727     case CK_Up:
 728         return chattrboxes_up (cb);
 729 
 730     case CK_PageUp:
 731         return chattrboxes_page_up (cb);
 732 
 733     case CK_Top:
 734         return chattrboxes_home (cb);
 735 
 736     case CK_Mark:
 737     case CK_MarkAndDown:
 738         {
 739             chattr_toggle_select (cb, cb->pos); /* FIXME */
 740             if (command == CK_MarkAndDown)
 741                 chattrboxes_down (cb);
 742 
 743             return MSG_HANDLED;
 744         }
 745 
 746     default:
 747         return MSG_NOT_HANDLED;
 748     }
 749 }
 750 
 751 /* --------------------------------------------------------------------------------------------- */
 752 
 753 static cb_ret_t
 754 chattrboxes_key (WChattrBoxes * cb, int key)
     /* [previous][next][first][last][top][bottom][index][help]  */
 755 {
 756     long command;
 757 
 758     command = widget_lookup_key (WIDGET (cb), key);
 759     if (command == CK_IgnoreKey)
 760         return MSG_NOT_HANDLED;
 761     return chattrboxes_execute_cmd (cb, command);
 762 }
 763 
 764 /* --------------------------------------------------------------------------------------------- */
 765 
 766 static cb_ret_t
 767 chattrboxes_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
 768 {
 769     WChattrBoxes *cb = CHATTRBOXES (w);
 770     WGroup *g = GROUP (w);
 771 
 772     switch (msg)
 773     {
 774     case MSG_DRAW:
 775         chattrboxes_draw (cb);
 776         return MSG_HANDLED;
 777 
 778     case MSG_NOTIFY:
 779         {
 780             /* handle checkboxes */
 781             int i;
 782 
 783             i = g_list_index (g->widgets, sender);
 784             if (i >= 0)
 785             {
 786                 int m;
 787 
 788                 i += cb->top;
 789                 m = check_attr_mod[i];
 790                 flags ^= check_attr[m].flags;
 791                 fileattrtext_fill (file_attr, flags);
 792                 chattr_toggle_select (cb, i);
 793                 flags_changed = TRUE;
 794                 return MSG_HANDLED;
 795             }
 796         }
 797         return MSG_NOT_HANDLED;
 798 
 799     case MSG_CHANGED_FOCUS:
 800         /* sender is one of chattr checkboxes */
 801         if (widget_get_state (sender, WST_FOCUSED))
 802         {
 803             int i;
 804 
 805             i = g_list_index (g->widgets, sender);
 806             cb->pos = cb->top + i;
 807         }
 808         return MSG_HANDLED;
 809 
 810     case MSG_KEY:
 811         {
 812             cb_ret_t ret;
 813 
 814             ret = chattrboxes_key (cb, parm);
 815             if (ret != MSG_HANDLED)
 816                 ret = group_default_callback (w, NULL, MSG_KEY, parm, NULL);
 817 
 818             return ret;
 819         }
 820 
 821     case MSG_ACTION:
 822         return chattrboxes_execute_cmd (cb, parm);
 823 
 824     case MSG_DESTROY:
 825         /* save all states */
 826         checkboxes_save_state (cb);
 827         MC_FALLTHROUGH;
 828 
 829     default:
 830         return group_default_callback (w, sender, msg, parm, data);
 831     }
 832 }
 833 
 834 /* --------------------------------------------------------------------------------------------- */
 835 
 836 static int
 837 chattrboxes_handle_mouse_event (Widget * w, Gpm_Event * event)
     /* [previous][next][first][last][top][bottom][index][help]  */
 838 {
 839     int mou;
 840 
 841     mou = mouse_handle_event (w, event);
 842     if (mou == MOU_UNHANDLED)
 843         mou = group_handle_mouse_event (w, event);
 844 
 845     return mou;
 846 }
 847 
 848 /* --------------------------------------------------------------------------------------------- */
 849 
 850 static void
 851 chattrboxes_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
     /* [previous][next][first][last][top][bottom][index][help]  */
 852 {
 853     WChattrBoxes *cb = CHATTRBOXES (w);
 854 
 855     (void) event;
 856 
 857     switch (msg)
 858     {
 859     case MSG_MOUSE_SCROLL_UP:
 860         chattrboxes_up (cb);
 861         break;
 862 
 863     case MSG_MOUSE_SCROLL_DOWN:
 864         chattrboxes_down (cb);
 865         break;
 866 
 867     default:
 868         /* return MOU_UNHANDLED */
 869         event->result.abort = TRUE;
 870         break;
 871     }
 872 }
 873 
 874 /* --------------------------------------------------------------------------------------------- */
 875 
 876 static WChattrBoxes *
 877 chattrboxes_new (int y, int x, int height, int width)
     /* [previous][next][first][last][top][bottom][index][help]  */
 878 {
 879     WChattrBoxes *cb;
 880     Widget *w;
 881 
 882     if (height <= 0)
 883         height = 1;
 884 
 885     cb = g_new0 (WChattrBoxes, 1);
 886     w = WIDGET (cb);
 887     group_init (GROUP (cb), y, x, height, width, chattrboxes_callback, chattrboxes_mouse_callback);
 888     w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR;
 889     w->mouse_handler = chattrboxes_handle_mouse_event;
 890     w->keymap = chattr_map;
 891 
 892     return cb;
 893 }
 894 
 895 /* --------------------------------------------------------------------------------------------- */
 896 
 897 static void
 898 chattr_init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 899 {
 900     static gboolean i18n = FALSE;
 901     size_t i;
 902 
 903     for (i = 0; i < check_attr_num; i++)
 904         check_attr[i].selected = FALSE;
 905 
 906     if (i18n)
 907         return;
 908 
 909     i18n = TRUE;
 910 
 911     for (i = 0; i < check_attr_num; i++)
 912         if (chattr_is_modifiable (i))
 913         {
 914             int width;
 915 
 916 #ifdef ENABLE_NLS
 917             check_attr[i].text = _(check_attr[i].text);
 918 #endif
 919 
 920             check_attr_mod[check_attr_mod_num++] = i;
 921 
 922             width = 4 + str_term_width1 (check_attr[i].text);   /* "(Q) text " */
 923             check_attr_width = MAX (check_attr_width, width);
 924         }
 925 
 926     check_attr_width += 1 + 3 + 1;      /* mark, [x] and space */
 927 
 928     for (i = 0; i < BUTTONS; i++)
 929     {
 930 #ifdef ENABLE_NLS
 931         chattr_but[i].text = _(chattr_but[i].text);
 932 #endif
 933 
 934         chattr_but[i].width = str_term_width1 (chattr_but[i].text) + 3; /* [], spaces and w/o & */
 935         if (chattr_but[i].flags == DEFPUSH_BUTTON)
 936             chattr_but[i].width += 2;   /* <> */
 937     }
 938 }
 939 
 940 /* --------------------------------------------------------------------------------------------- */
 941 
 942 static WDialog *
 943 chattr_dlg_create (const char *fname, unsigned long attr)
     /* [previous][next][first][last][top][bottom][index][help]  */
 944 {
 945     const Widget *mw = CONST_WIDGET (midnight_dlg);
 946     gboolean single_set;
 947     WDialog *ch_dlg;
 948     int lines, cols;
 949     int checkboxes_lines = check_attr_mod_num;
 950     size_t i;
 951     int y;
 952     Widget *dw;
 953     WGroup *dg, *cbg;
 954     WChattrBoxes *cb;
 955     const int cb_scrollbar_width = 1;
 956 
 957     /* prepate to set up checkbox states */
 958     for (i = 0; i < check_attr_num; i++)
 959         check_attr[i].state = chattr_is_modifiable (i) && (attr & check_attr[i].flags) != 0;
 960 
 961     cols = check_attr_width + cb_scrollbar_width;
 962 
 963     single_set = (current_panel->marked < 2);
 964 
 965     lines = 5 + checkboxes_lines + 4;
 966     if (!single_set)
 967         lines += 3;
 968 
 969     if (lines >= mw->lines - 2)
 970     {
 971         int dl;
 972 
 973         dl = lines - (mw->lines - 2);
 974         lines -= dl;
 975         checkboxes_lines -= dl;
 976     }
 977 
 978     ch_dlg =
 979         dlg_create (TRUE, 0, 0, lines, cols + wx * 2, WPOS_CENTER, FALSE, dialog_colors,
 980                     dlg_default_callback, NULL, "[Chattr]", _("Chattr command"));
 981     dg = GROUP (ch_dlg);
 982     dw = WIDGET (ch_dlg);
 983 
 984     y = 2;
 985     file_attr = fileattrtext_new (y, wx, fname, attr);
 986     group_add_widget_autopos (dg, file_attr, WPOS_KEEP_TOP | WPOS_CENTER_HORZ, NULL);
 987     y += WIDGET (file_attr)->lines;
 988     group_add_widget (dg, hline_new (y++, -1, -1));
 989 
 990     if (cols < WIDGET (file_attr)->cols)
 991     {
 992         cols = WIDGET (file_attr)->cols;
 993         cols = MIN (cols, mw->cols - wx * 2);
 994         widget_set_size (dw, dw->y, dw->x, lines, cols + wx * 2);
 995     }
 996 
 997     cb = chattrboxes_new (y++, wx, checkboxes_lines, cols);
 998     cbg = GROUP (cb);
 999     group_add_widget_autopos (dg, cb, WPOS_KEEP_TOP | WPOS_KEEP_HORZ, NULL);
1000 
1001     /* create checkboxes */
1002     for (i = 0; i < (size_t) check_attr_mod_num && i < (size_t) checkboxes_lines; i++)
1003     {
1004         int m;
1005         WCheck *check;
1006 
1007         m = check_attr_mod[i];
1008 
1009         check = check_new (i, 0, check_attr[m].state, NULL);
1010         group_add_widget (cbg, check);
1011     }
1012 
1013     chattrboxes_rename (cb);
1014 
1015     y += i - 1;
1016     cols = 0;
1017 
1018     for (i = single_set ? (BUTTONS - 2) : 0; i < BUTTONS; i++)
1019     {
1020         if (i == 0 || i == BUTTONS - 2)
1021             group_add_widget (dg, hline_new (y++, -1, -1));
1022 
1023         chattr_but[i].button = WIDGET (button_new (y, dw->cols / 2 + 1 - chattr_but[i].width,
1024                                                    chattr_but[i].ret_cmd, chattr_but[i].flags,
1025                                                    chattr_but[i].text, NULL));
1026         group_add_widget (dg, chattr_but[i].button);
1027 
1028         i++;
1029         chattr_but[i].button = WIDGET (button_new (y++, dw->cols / 2 + 2, chattr_but[i].ret_cmd,
1030                                                    chattr_but[i].flags, chattr_but[i].text, NULL));
1031         group_add_widget (dg, chattr_but[i].button);
1032 
1033         /* two buttons in a row */
1034         cols = MAX (cols, chattr_but[i - 1].button->cols + 1 + chattr_but[i].button->cols);
1035     }
1036 
1037     /* adjust dialog size and button positions */
1038     cols += 6;
1039     if (cols > dw->cols)
1040     {
1041         widget_set_size (dw, dw->y, dw->x, lines, cols);
1042 
1043         /* dialog center */
1044         cols = dw->x + dw->cols / 2 + 1;
1045 
1046         for (i = single_set ? (BUTTONS - 2) : 0; i < BUTTONS; i++)
1047         {
1048             Widget *b;
1049 
1050             b = chattr_but[i++].button;
1051             widget_set_size (b, b->y, cols - b->cols, b->lines, b->cols);
1052 
1053             b = chattr_but[i].button;
1054             widget_set_size (b, b->y, cols + 1, b->lines, b->cols);
1055         }
1056     }
1057 
1058     /* select first checkbox */
1059     cbg->current = cbg->widgets;
1060     widget_select (WIDGET (cb));
1061 
1062     return ch_dlg;
1063 }
1064 
1065 /* --------------------------------------------------------------------------------------------- */
1066 
1067 static void
1068 chattr_done (gboolean need_update)
     /* [previous][next][first][last][top][bottom][index][help]  */
1069 {
1070     if (need_update)
1071         update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1072     repaint_screen ();
1073 }
1074 
1075 /* --------------------------------------------------------------------------------------------- */
1076 
1077 static const char *
1078 next_file (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1079 {
1080     while (!current_panel->dir.list[current_file].f.marked)
1081         current_file++;
1082 
1083     return current_panel->dir.list[current_file].fname;
1084 }
1085 
1086 /* --------------------------------------------------------------------------------------------- */
1087 
1088 static gboolean
1089 try_chattr (const char *p, unsigned long m)
     /* [previous][next][first][last][top][bottom][index][help]  */
1090 {
1091     while (fsetflags (p, m) == -1 && !ignore_all)
1092     {
1093         int my_errno = errno;
1094         int result;
1095         char *msg;
1096 
1097         msg =
1098             g_strdup_printf (_("Cannot chattr \"%s\"\n%s"), x_basename (p),
1099                              unix_error_string (my_errno));
1100         result =
1101             query_dialog (MSG_ERROR, msg, D_ERROR, 4, _("&Ignore"), _("Ignore &all"), _("&Retry"),
1102                           _("&Cancel"));
1103         g_free (msg);
1104 
1105         switch (result)
1106         {
1107         case 0:
1108             /* try next file */
1109             return TRUE;
1110 
1111         case 1:
1112             ignore_all = TRUE;
1113             /* try next file */
1114             return TRUE;
1115 
1116         case 2:
1117             /* retry this file */
1118             break;
1119 
1120         case 3:
1121         default:
1122             /* stop remain files processing */
1123             return FALSE;
1124         }
1125     }
1126 
1127     return TRUE;
1128 }
1129 
1130 /* --------------------------------------------------------------------------------------------- */
1131 
1132 static gboolean
1133 do_chattr (const vfs_path_t * p, unsigned long m)
     /* [previous][next][first][last][top][bottom][index][help]  */
1134 {
1135     gboolean ret;
1136 
1137     m &= and_mask;
1138     m |= or_mask;
1139 
1140     ret = try_chattr (vfs_path_as_str (p), m);
1141 
1142     do_file_mark (current_panel, current_file, 0);
1143 
1144     return ret;
1145 }
1146 
1147 /* --------------------------------------------------------------------------------------------- */
1148 
1149 static void
1150 chattr_apply_mask (vfs_path_t * vpath, unsigned long m)
     /* [previous][next][first][last][top][bottom][index][help]  */
1151 {
1152     gboolean ok;
1153 
1154     if (!do_chattr (vpath, m))
1155         return;
1156 
1157     do
1158     {
1159         const char *fname;
1160 
1161         fname = next_file ();
1162         ok = (fgetflags (fname, &m) == 0);
1163 
1164         if (!ok)
1165         {
1166             /* if current file was deleted outside mc -- try next file */
1167             /* decrease current_panel->marked */
1168             do_file_mark (current_panel, current_file, 0);
1169 
1170             /* try next file */
1171             ok = TRUE;
1172         }
1173         else
1174         {
1175             vpath = vfs_path_from_str (fname);
1176             flags = m;
1177             ok = do_chattr (vpath, m);
1178             vfs_path_free (vpath);
1179         }
1180     }
1181     while (ok && current_panel->marked != 0);
1182 }
1183 
1184 /* --------------------------------------------------------------------------------------------- */
1185 /*** public functions ****************************************************************************/
1186 /* --------------------------------------------------------------------------------------------- */
1187 
1188 void
1189 chattr_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1190 {
1191     gboolean need_update = FALSE;
1192     gboolean end_chattr = FALSE;
1193 
1194     chattr_init ();
1195 
1196     current_file = 0;
1197     ignore_all = FALSE;
1198 
1199     do
1200     {                           /* do while any files remaining */
1201         vfs_path_t *vpath;
1202         WDialog *ch_dlg;
1203         const char *fname, *fname2;
1204         size_t i;
1205         int result;
1206 
1207         if (!vfs_current_is_local ())
1208         {
1209             message (D_ERROR, MSG_ERROR, "%s",
1210                      _("Cannot change attributes on non-local filesystems"));
1211             break;
1212         }
1213 
1214         do_refresh ();
1215 
1216         need_update = FALSE;
1217         end_chattr = FALSE;
1218 
1219         if (current_panel->marked != 0)
1220             fname = next_file ();       /* next marked file */
1221         else
1222             fname = selection (current_panel)->fname;   /* single file */
1223 
1224         vpath = vfs_path_from_str (fname);
1225         fname2 = vfs_path_as_str (vpath);
1226 
1227         if (fgetflags (fname2, &flags) != 0)
1228         {
1229             message (D_ERROR, MSG_ERROR, _("Cannot get flags of \"%s\"\n%s"), fname,
1230                      unix_error_string (errno));
1231             vfs_path_free (vpath);
1232             break;
1233         }
1234 
1235         flags_changed = FALSE;
1236 
1237         ch_dlg = chattr_dlg_create (fname, flags);
1238         result = dlg_run (ch_dlg);
1239         dlg_destroy (ch_dlg);
1240 
1241         switch (result)
1242         {
1243         case B_CANCEL:
1244             end_chattr = TRUE;
1245             break;
1246 
1247         case B_ENTER:
1248             if (flags_changed)
1249             {
1250                 if (current_panel->marked <= 1)
1251                 {
1252                     /* single or last file */
1253                     if (fsetflags (fname2, flags) == -1 && !ignore_all)
1254                         message (D_ERROR, MSG_ERROR, _("Cannot chattr \"%s\"\n%s"), fname,
1255                                  unix_error_string (errno));
1256                     end_chattr = TRUE;
1257                 }
1258                 else if (!try_chattr (fname2, flags))
1259                 {
1260                     /* stop multiple files processing */
1261                     result = B_CANCEL;
1262                     end_chattr = TRUE;
1263                 }
1264             }
1265 
1266             need_update = TRUE;
1267             break;
1268 
1269         case B_SETALL:
1270         case B_MARKED:
1271             or_mask = 0;
1272             and_mask = ~0;
1273 
1274             for (i = 0; i < check_attr_num; i++)
1275                 if (chattr_is_modifiable (i) && (check_attr[i].selected || result == B_SETALL))
1276                 {
1277                     if (check_attr[i].state)
1278                         or_mask |= check_attr[i].flags;
1279                     else
1280                         and_mask &= ~check_attr[i].flags;
1281                 }
1282 
1283             chattr_apply_mask (vpath, flags);
1284             need_update = TRUE;
1285             end_chattr = TRUE;
1286             break;
1287 
1288         case B_SETMRK:
1289             or_mask = 0;
1290             and_mask = ~0;
1291 
1292             for (i = 0; i < check_attr_num; i++)
1293                 if (chattr_is_modifiable (i) && check_attr[i].selected)
1294                     or_mask |= check_attr[i].flags;
1295 
1296             chattr_apply_mask (vpath, flags);
1297             need_update = TRUE;
1298             end_chattr = TRUE;
1299             break;
1300 
1301         case B_CLRMRK:
1302             or_mask = 0;
1303             and_mask = ~0;
1304 
1305             for (i = 0; i < check_attr_num; i++)
1306                 if (chattr_is_modifiable (i) && check_attr[i].selected)
1307                     and_mask &= ~check_attr[i].flags;
1308 
1309             chattr_apply_mask (vpath, flags);
1310             need_update = TRUE;
1311             end_chattr = TRUE;
1312             break;
1313 
1314         default:
1315             break;
1316         }
1317 
1318         if (current_panel->marked != 0 && result != B_CANCEL)
1319         {
1320             do_file_mark (current_panel, current_file, 0);
1321             need_update = TRUE;
1322         }
1323 
1324         vfs_path_free (vpath);
1325 
1326     }
1327     while (current_panel->marked != 0 && !end_chattr);
1328 
1329     chattr_done (need_update);
1330 }
1331 
1332 /* --------------------------------------------------------------------------------------------- */
1333 
1334 const char *
1335 chattr_get_as_str (unsigned long attr)
     /* [previous][next][first][last][top][bottom][index][help]  */
1336 {
1337     static char str[32 + 1];    /* 32 bits in attributes (unsigned long) */
1338 
1339     chattr_fill_str (attr, str);
1340 
1341     return str;
1342 }
1343 
1344 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */