}
free (src);
free (dest);
+ freelist (list[panel]);
+ list[panel] = NULL;
}
- freelist (list[panel]);
- list[panel] = NULL;
free (string);
}
break;
break;
case ALT_V: /* view */
break;
+ case ALT_X: /* chmod */
+ string = getwindow ("Change to mode", winscreen, 4, 4, "0644");
+ if (string) {
+ int mode = strtol (string, NULL, 8);
+ if ((mode <= 0) || (mode > 0777)) {
+ char *octal = itoo (mode);
+ char *buf = strdupcat ("Can't change file(s) to mode 0", (octal && *octal) ? octal : "000" , NULL);
+ msgwindow (buf, winscreen, 0);
+ getch ();
+ free (octal);
+ free (buf);
+ } else {
+ for (i = 0; i < list[panel]->nb; i++) {
+ current = list[panel]->tab + i;
+ if (current->selected) {
+ char *src = strdupcat (dirname[panel], SEPARATOR, current->name, NULL);
+ char *msg = processchmod (src, mode);
+ if (msg) {
+ msgwindow (msg, winscreen, 0);
+ getch ();
+ free (msg);
+ }
+ free (src);
+ }
+ }
+ freelist (list[panel]);
+ list[panel] = NULL;
+ }
+ free (string);
+ }
#ifndef PDCURSES
}
break;
return string;
}
+int _log8 (int x)
+{
+ int l = 0;
+ while (x > 0) {
+ x /= 8;
+ l++;
+ }
+ return l;
+}
+
+char *itoo (int x)
+{
+ int n = _log8 (x);
+ char *octal = (char *) calloc (n, 1);
+ CHECKALLOC (octal);
+
+ int l = 0;
+ while (x > 0) {
+ octal[n - 1 - (l++)] = '0' + (x % 8);
+ x /= 8;
+ }
+
+ return octal;
+}
+
char *newfilename (char *dirname, char *filename)
{
char *name = (char *) calloc (strlen (dirname) + strlen (SEPARATOR) + strlen (filename) + 1, 1);
return msg;
}
+char *processchmod (char *name, int mode)
+{
+ char *msg = NULL;
+
+ struct stat sb;
+ if (STAT (name, &sb) == 0) {
+ char *octal = itoo (mode);
+ if ((sb.st_mode & S_IFMT) == S_IFDIR) {
+ DIR *dir = opendir (name);
+
+ if (dir != NULL) {
+ struct dirent *dp = NULL;
+ while (((dp = readdir (dir)) != NULL) && (msg == NULL)) {
+ if ((strcmp (dp->d_name, ".") == 0) || (strcmp (dp->d_name, "..") == 0)) {
+ continue;
+ }
+ char *next = strdupcat (name, SEPARATOR, dp->d_name, NULL);
+ msg = processchmod (next, mode);
+ free (next);
+ }
+ closedir (dir);
+ if (msg == NULL) {
+ VERBOSE (DEBUG, fprintf (stderr, "chmod '%s' to 0%o\n", name, mode));
+ if (chmod (name, mode) != 0) {
+ msg = strdupcat ("Can't change mode ", octal, " for directory '", name, "'");
+ }
+ }
+ } else {
+ msg = strdupcat ("Can't open directory '", name, "'");
+ }
+ } else {
+ VERBOSE (DEBUG, fprintf (stderr, "chmod '%s' to 0%o\n", name, mode));
+ if (chmod (name, mode) != 0) {
+ msg = strdupcat ("Can't change mode ", octal, " for file '", name, "'");
+ }
+ }
+ free (octal);
+ } else {
+ VERBOSE (ERROR, fprintf (stderr, "can't stat on file '%s'\n", name));
+ exit (1);
+ }
+
+ return msg;
+}
+
/* vim: set ts=4 sw=4 et: */
char *strdupcat (char *init, ...);
+char *itoo (int x);
+
char *newfilename (char *dirname, char *filename);
list_t *alloclist (void);
char *processmove (char *dest, char *src);
+char *processchmod (char *name, int mode);
+
#endif /* __FUNCTION_H__ */
/* vim: set ts=4 sw=4 et: */