Re: permisiions string

  • From: David Jensen <david567@xxxxxxxxxxxxxx>
  • To: emelfm2@xxxxxxxxxxxxx
  • Date: Fri, 2 May 2008 15:28:45 -0500

On Fri, 2 May 2008 13:15:40 -0500
David Jensen <david567@xxxxxxxxxxxxxx> wrote:

> 
> Attached a new patch, maybe it makes it all translatable.

attached 'Take 3': bit more robust. Translation is complete although it
will not handle UTF8.  I see no-one is translating these strings,
perhaps for that reason.

It compiles to 383 bytes (-O2 on x86-32), original was 515 bytes.

David Jensen
--- emelfm2-0.4/src/filesystem/e2_fs.c  2008-02-18 18:22:09.000000000 -0600
+++ emelfm2-0.4.new/src/filesystem/e2_fs.c      2008-05-02 14:36:03.000000000 
-0500
@@ -2792,43 +2792,42 @@
 */
 void e2_fs_get_perm_string (gchar *buf, gint len, mode_t mode)
 {
-       gchar *perm_sets[8];
-       perm_sets[0] = _("---");
-       perm_sets[1] = _("--x");
-       perm_sets[2] = _("-w-");
-       perm_sets[3] = _("-wx");
-       perm_sets[4] = _("r--");
-       perm_sets[5] = _("r-x");
-       perm_sets[6] = _("rw-");
-       perm_sets[7] = _("rwx");
-
-       gint u, g, o;
-       u = (mode & S_IRWXU) >> 6;
-       g = (mode & S_IRWXG) >> 3;
-       o = (mode & S_IRWXO);
-
-       g_snprintf (buf, len, "-%s%s%s", perm_sets[u], perm_sets[g], 
perm_sets[o]);
+       gchar *perms  = _("-rwxrwxrwx");
+       gchar *ftypes = _("ldbcfs");
+       gchar *fbits  = _("TtSs");
+
+       g_snprintf (buf, len, perms);
+
+       gint mask = 1;
+       gint i;
+       for (i = 9; i > 1; --i) {
+               if (!(mode & mask))
+                       buf[i] = perms[0];
+               mask = mask << 1;
+       }
 
-       //_I( FIXME the things below do not suppport translation !!
+       i = -1;
        if (S_ISLNK(mode))
-               buf[0] = 'l';
+               i = 0;
        else if (S_ISDIR(mode))
-               buf[0] = 'd';
+               i = 1;
        else if (S_ISBLK(mode))
-               buf[0] = 'b';
+               i = 2;
        else if (S_ISCHR(mode))
-               buf[0] = 'c';
+               i = 3;
        else if (S_ISFIFO(mode))
-               buf[0] = 'f';
+               i = 4;
        else if (S_ISSOCK(mode))
-               buf[0] = 's';
+               i = 5;
+       if (i >= 0)
+               buf[0] = ftypes[i];
 
        if (mode & S_ISVTX)
-               buf[9] = (buf[9] == '-') ? 'T' : 't';
+               buf[9] = (buf[9] == perms[0]) ? fbits[0] : fbits[1];
        if (mode & S_ISGID)
-               buf[6] = (buf[6] == '-') ? 'S' : 's';
+               buf[6] = (buf[6] == perms[0]) ? fbits[2] : fbits[3];
        if (mode & S_ISUID)
-               buf[3] = (buf[3] == '-') ? 'S' : 's';
+               buf[3] = (buf[3] == perms[0]) ? fbits[2] : fbits[3];
 }
 /**
 @brief display error message @a msg, with current system error description

Other related posts: