[CentOS] OT? File order on CentOS/Samba server -- SOLVED (kind of...)

Filipe Brandenburger filbranden at gmail.com
Sat Jan 24 02:55:31 UTC 2009


Hi,

On Fri, Jan 23, 2009 at 20:45, Filipe Brandenburger
<filbranden at gmail.com> wrote:
> 3) Rundirex.txt (even with a .txt extension) is a Postscript file. [...]
> [...] way to sort the list of files from inside Postscript.

I think I did it.

Inside your Rundirex.txt, you should have this snippet:


/RunDir {                       % Uses PathName variable on the operand stack
        { /mysave save def      % Performs a save before running the PS file
          dup = flush           % Shows name of PS file being run
          RunFile               % Calls built in Distiller procedure
          clear cleardictstack  % Cleans up after PS file
          mysave restore        % Restores save level
        }
        255 string
        filenameforall
} def


Right?  If so, then add the definition of a bubble sort routine before
that (which I got from Wikipedia), and then modify /RunDir into the
snippet below. Ghostscript has a .sort built-in that does exaclty
that, but I'm including it here as I don't know if Distiller will too.


% Bubble sort from Wikibooks page on PostScript
/mybubblesort
  { 1 index length 1 sub -1 1
      { 2 index exch 2 copy get 3 copy  % arr proc arr i arr[i] arr i arr[i]
        0 1 3 index 1 sub
          { 3 index 1 index get         % arr proc arr i arr[i] arr
imax amax j arr[j]
            2 index 1 index 10 index exec
              {                               % ... amax < arr[j]
                4 2 roll
              }
            if pop pop
          }
        for                                     % arr proc arr i
arr[i] arr imax amax
        4 -1 roll exch 4 1 roll put put
      }
    for
    pop
  } bind def

/RunDir {                       % Uses PathName variable on the operand stack
        /nf 0 def               % Reset counter for number of files
        { 255 string copy       % Copy to a separate string (otherwise
would be overwritten)
          /nf nf 1 add def      % Increment counter of number of files
        }
        255 string
        filenameforall

        nf array astore         % Put all filenames in an array
        { lt } mybubblesort     % And sort it

        { /mysave save def      % Performs a save before running the PS file
          dup = flush           % Shows name of PS file being run
          RunFile               % Calls built in Distiller procedure
          clear cleardictstack  % Cleans up after PS file
          mysave restore        % Restores save level
        }
        forall                  % Execute original procedure, but
using sorted array
} def


Of course I did not test it with Distiller which I don't have... I did
test the part of sorting the list of files with Ghostscript and it
works.

Maybe word wrapping in the e-mail will ruin the snippet, if that's the
case please let me know and I'll send it attached to you.

Let us know if that works!

Filipe


More information about the CentOS mailing list