Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #29550 > unrolled thread

glob-like word needed (Gforth under Linux)

Started byZbigniew <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com>
First post2014-04-12 00:02 +0000
Last post2014-04-12 15:15 +0200
Articles 4 — 4 participants

Back to article view | Back to comp.lang.forth


Contents

  glob-like word needed (Gforth under Linux) Zbigniew <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com> - 2014-04-12 00:02 +0000
    glob-like word needed (Gforth under Linux) humptydumpty <ouatubi@gmail.com> - 2014-04-11 23:44 -0700
    Re: glob-like word needed (Gforth under Linux) Julian Fondren <julian.fondren@gmail.com> - 2014-04-12 03:16 -0700
      Re: glob-like word needed (Gforth under Linux) Bernd Paysan <bernd.paysan@gmx.de> - 2014-04-12 15:15 +0200

#29550 — glob-like word needed (Gforth under Linux)

FromZbigniew <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com>
Date2014-04-12 00:02 +0000
Subjectglob-like word needed (Gforth under Linux)
Message-ID<slrnlkgvhd.6c4.empty.buffersYOU-DONT-WANT-THIS@Tichy.localnet>
Hi!

I need to create the word, which could return the filenames of the files in
current directory, or - even better - which works similarly to "glob {pattern}"
function (like e.g. in TCL).

The problem is, actually no idea, how to even start... O_O  there are several
words for file handling in existence, but - surprisingly - no equivalent of
simple "ls". Or maybe indeed I missed something?

Thanks in advance for suggestions (Gforth and Linux).
-- 
May the Forth be with you!

[toc] | [next] | [standalone]


#29555

Fromhumptydumpty <ouatubi@gmail.com>
Date2014-04-11 23:44 -0700
Message-ID<e2004d73-e63e-46e8-b2e3-ae4957b008bb@googlegroups.com>
In reply to#29550
Hi!

You could use open-pipe and friends to interact with Linux commands.

Have a nice day,
Humptydumpty.

[toc] | [prev] | [next] | [standalone]


#29559

FromJulian Fondren <julian.fondren@gmail.com>
Date2014-04-12 03:16 -0700
Message-ID<2cb56dd7-4e61-49e4-828d-1f1f69bd07ac@googlegroups.com>
In reply to#29550
On Friday, April 11, 2014 7:02:10 PM UTC-5, Zbigniew wrote:
> I need to create the word, which could return the filenames of the files in
> 
> current directory, or - even better - which works similarly to "glob {pattern}"
> 
> function (like e.g. in TCL).
> 
> 
> 
> The problem is, actually no idea, how to even start... O_O  there are several
> 
> words for file handling in existence, but - surprisingly - no equivalent of
> 
> simple "ls". Or maybe indeed I missed something?

Howdy,

OPEN-DIR and READ-DIR and CLOSE-DIR are the basic words necessary.  Gforth has
a FILENAME-MATCH that's also handy.

: each-file ( c-addr u xt -- )
  >r OPEN-DIR throw { d }
  begin pad 80 d READ-DIR throw while
    pad swap r@ execute
  repeat drop rdrop  d CLOSE-DIR throw ;

: ls ( "path" -- )
  0 parse [: cr type ;] each-file ;

: forth-files ( c-addr u -- )
  [: 2dup s" *.fs" filename-match if cr type else 2drop then ;] each-file ;

\ usage:
ls /sdcard/
ls .
s" /sdcard/gforth/home" forth-files

FILE-STATUS *should* be useful -- the standard allows it to be useful, without
specifying any actual utility  -- but it isn't.  It looks like you'll need to
use gforth's C interface to work with stat() , to get more information about
files than their name and size.


-- Julian

[toc] | [prev] | [next] | [standalone]


#29567

FromBernd Paysan <bernd.paysan@gmx.de>
Date2014-04-12 15:15 +0200
Message-ID<libe97$5u6$1@online.de>
In reply to#29559
Julian Fondren wrote:
> FILE-STATUS *should* be useful -- the standard allows it to be useful,
> without
> specifying any actual utility  -- but it isn't.  It looks like you'll need
> to use gforth's C interface to work with stat() , to get more information
> about files than their name and size.

In the current snapshot, there's unix/filestat.fs, which provides that 
interface.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web