jed-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Dynamic string arrays in slang/jed?


Brian Blais <bblais@xxxxxxxxxx> wrote:
>My current solution is to use a jed buffer, copy the buffer, and then do a
>strtok() call looking for end-of-line characters:
>
>dirname="/home/blah/tmp";
>
>s=listdir(dirname);
>
>for (i=0; i<length(s); i++) {
>    if (isimage(s[i])) {
>       insert(dirname+"/"+s[i]+"\n");
>    }
>}

In addition to what has already been suggested, you can use an
associative array, e.g.,

  files = Assoc_Type[];
  s = listdir (dirname);
  s = s[where(array_map(Int_Type, &isimage, s))];
  
After the last step, s will contain only those filenames for which
isimage is non-zero.  You can add them to the associative array via
an explicit loop, e.g.,

   variable i;
   _for (0, length(s)-1, 1)
   {
      i = ();
      files[s[i]] = i;
   }

Then you can get them back out of the array using assoc_get_keys.

--John

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]