List Info

Thread: "ocaml_beginners"::[] Unix "locate" database access ?




"ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
France
2007-03-10 04:41:40

Hi,

"updatedb" utility stores file names in /var/cache/locate/locatedb on my Debian Linux.

Please does any OCaml library provide easy access to these data ?

Thanks.

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
United Kingdom
2007-03-10 10:07:34

On Sat, Mar 10, 2007 at 11:41:40AM +0100, Fabrice Marchant wrote:
> "updatedb" utility stores file names in /var/cache/locate/locatedb on my Debian Linux.
>
> Please does any OCaml library provide easy access to these data ?

It's unlikely. The best bet is to download the source code (in
findutils) and try to reverse engineer the format from the source --
it uses a weird type of compression. From locate/code.c:

Compress a sorted list.
Works with `find' to encode a filename database to save space
and search time.

Usage:

bigram < file_list > bigrams
process-bigrams > most_common_bigrams
code most_common_bigrams < file_list > squeezed_list

Uses `front compression' (see ";login:", March 1983, p. 8).
The output begins with the 128 most common bigrams.
After that, the output format is, for each line,
an offset (from the previous line) differential count byte
followed by a (partially bigram-encoded) ASCII remainder.
The output lines have no terminating byte; the start of the next line
is indicated by its first byte having a value <= 30.

The encoding of the output bytes is:

0-28 likeliest differential counts + offset (14) to make nonnegative
30 escape code for out-of-range count to follow in next halfword
128-255 bigram codes (the 128 most common, as determined by `updatedb')
32-127 single character (printable) ASCII remainder

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
United Kingdom
2007-03-10 10:41:53


Actually a much better guide is to look at the locatedb(5) man page.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
RE: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
United States
2007-03-10 17:04:22

If you're trying to do something simple that you could do in a shell, you
can use one of the Unix process commands and "screen scrape&quot; the results.

-Grant

_____

From: ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com
[mailto: ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com] On Behalf Of Fabrice Marchant
Sent: Saturday, March 10, 2007 5:42 AM
To: ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com
Subject: "ocaml_beginners"::[] Unix "locate" database access ?

Hi,

";updatedb&quot; utility stores file names in /var/cache/locate/locatedb on my
Debian Linux.

Please does any OCaml library provide easy access to these data ?

Thanks.

Fabrice

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
France
2007-03-11 13:04:14

Thanks a lot Rich and Grant !

Rich wrote :
> ... The best bet is to download the source code (in
> findutils) and try to reverse engineer the format from the source --
> it uses a weird type of compression. From locate/code.c:
I've apt-got the source and look at this code. It is short.
locatedb man page explains how "front compression" of lists works.
However, I'll consider to work another way, maybe re-scanning the disks with the OCaml program.

Grant wrote :
> If you're trying to do something simple that you could do in a shell, you
> can use one of the Unix process commands and "screen scrape&quot; the results.
I've soon used Sys.command but I do not know how to crop the results back to my OCaml program :
have no idea about how to proceed to the "screen scrape&quot;...
If you had further explanations about this. Thanks.
I wonder if we can consider this as a good programming practice ?

Best regards

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
United States
2007-03-11 14:15:24

On Mar 11, 2007, at 12:04 PM, Fabrice Marchant wrote:

> I've soon used Sys.command but I do not know how to crop the
> results back to my OCaml program :
> have no idea about how to proceed to the "screen scrape&quot;...

Look at the Unix.open_process* functions <http://caml.inria.fr/pub/
docs/manual-ocaml/libref/
Unix.html#6_Highlevelprocessandredirectionmanagement>

William D. Neumann

"I eat T-bone steaks, I lift barbell plates, I'm sweeter than a
German chocolate cake. I'm the reflection of perfection, the number
one selection. I'm the man of the hour, the man with the power, too
sweet to be sour. The ladies' pet, the men's regret, where what you
see is what you get, and what you don't see, is better yet."

--Superstar Billy Graham

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
France
2007-03-12 17:35:16

Thanks a lot William !

>; Look at the Unix.open_process* functions <http://caml.inria.fr/pub/
> docs/manual-ocaml/libref/
> Unix.html#6_Highlevelprocessandredirectionmanagement>

I've seen the doc and can try these process functions now.
But that isn't obvious for me. If you know a "screen scrape&quot; example somewhere...

Regards

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
United States
2007-03-12 18:13:37

On Mon, 12 Mar 2007, Fabrice Marchant wrote:

> Thanks a lot William !
>
>> Look at the Unix.open_process* functions <http://caml.inria.fr/pub/
&gt;> docs/manual-ocaml/libref/
>;> Unix.html#6_Highlevelprocessandredirectionmanagement>
>;
> I've seen the doc and can try these process functions now.
>; But that isn't obvious for me. If you know a "screen scrape&quot; example
> somewhere...

See "slurp_command&quot; on that page:
http://martin.jambon.free.fr/toolbox.html#programs

Micmatch.Text.iter_lines_of_channel can also be useful when combined with
Unix.open_process_in.

Martin

--
Martin Jambon
http://martin.jambon.free.fr

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
France
2007-03-12 18:18:24

Thanks Robert for your abstract but useful explanations.

I discover this way of working. There is no reason though to be specific to OCaml.

Regards

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Unix "locate" database access ?
country flaguser name
Germany
2007-03-13 04:07:52

On Mon, Mar 12, 2007 at 11:35:16PM +0100, Fabrice Marchant wrote:
&gt; Thanks a lot William !
>
> > Look at the Unix.open_process* functions <http://caml.inria.fr/pub/
> > docs/manual-ocaml/libref/
> > Unix.html#6_Highlevelprocessandredirectionmanagement>
>;
> I've seen the doc and can try these process functions now.
>; But that isn't obvious for me. If you know a "screen scrape&quot; example somewhere...
>
[...]

Unix.open_process_in

is what you can use.

The term screen scrape, when used for the following,is a misnomer,
because you directly read from the process you inderectly invoked via
open_process_in:

===============================================================================
first:~/Desktop/OCAML-Programmierung-Dokus oliver$ ocaml unix.cma
Objective Caml version 3.09.3

# open Unix;;
# let channel = open_process_in "ls -lt";;
val channel : in_channel = <abstr&gt;
# while true do print_endline (input_line channel) done ;;
total 14216
drwxr-xr-x 59 oliver oliver 2006 28 Feb 11:45 OCAML-htmlman-Reference-Manual
-rw-r--r-- 1 oliver oliver 124188 21 Feb 19:32 ocamldoc-doku.pdf
drwxr-xr-x 4 oliver oliver 136 14 Feb 23:30 style Files
-rw-r--r-- 1 oliver oliver 28295 14 Feb 23:30 style.html
drwxr-xr-x 5 oliver oliver 170 12 Feb 10:45 Camlp4-Tutorial
drwxr-xr-x 8 oliver oliver 272 12 Feb 10:41 OCAMl-Infos-Web-OCamlP3l-und-anderes
-rw-r--r-- 1 oliver oliver 415384 4 Feb 07:11 javavsocaml.pdf
drwxr-xr-x 3 oliver oliver 102 24 Aug 2006 GoF-DesignPatterns
drwxr-xr-x 36 oliver oliver 1224 7 May 2006 OCAML-COCOA
drwxr-xr-x 27 oliver oliver 918 7 May 2006 Ocaml--Format-Module
drwxr-xr-x 3 oliver oliver 102 7 May 2006 diverses
-rw-r--r-- 1 oliver oliver 71171 7 Feb 2006 Ocaml-two-forms-of-LET.pdf
-rw-r--r-- 1 oliver oliver 1880564 19 Nov 2005 ocaml-3.09-refman.pdf
drwxr-xr-x 5 oliver oliver 170 25 Oct 2005 81bbc08defeb05351c2e0e3164dca32c.en Files
-rw-r--r-- 1 oliver oliver 10907 25 Oct 2005 81bbc08defeb05351c2e0e3164dca32c.en.html
drwxr-xr-x 5 oliver oliver 170 21 Oct 2005 OCaml-vs-other-Languages
drwxr-xr-x 22 oliver oliver 748 21 Oct 2005 OCAML-diverses
-rw-r--r-- 1 oliver oliver 21316 15 May 2005 not a bug.html
drwxr-xr-x 3 oliver oliver 102 15 May 2005 not a bug_files
-rw-r--r-- 1 oliver oliver 100525 15 May 2005 FAQ_EXPERT-eng.html
-rw-r--r-- 1 oliver oliver 17976 2 May 2005 Polymorphic-Variants.pdf
drwxr-xr-x 4 oliver oliver 136 29 Mar 2005 Ocaml-an-introduction
drwxr-xr-x 4 oliver oliver 136 29 Mar 2005 OCaml-concise-introduction
drwxr-xr-x 30 oliver oliver 1020 29 Mar 2005 OCAML-Tutorial
-rw-r--r-- 1 oliver oliver 360389 29 Mar 2005 book.pdf
-rw-r--r-- 1 oliver oliver 302580 27 Feb 2005 chapter1.pdf
-rw------- 1 oliver oliver 5096 10 Feb 2005 Ocaml-Extlib.url
-rw-r--r-- 1 oliver oliver 188570 22 Dec 2004 ocamllex-tutorial.pdf
-rw-r--r-- 1 oliver oliver 458918 22 Dec 2004 ocamlyacc-tutorial.pdf
-rw-r--r-- 1 oliver oliver 2875150 20 Dec 2004 ocaml-OReilly-Book.pdf
-rw-r--r-- 1 oliver oliver 129871 13 May 2003 recursive-modules-note.pdf
-rwxr-xr-x 1 oliver oliver 126386 11 Jan 2003 KOPIE-camlp4-3.06-tutorial.ps.gz
-rwxr-xr-x 1 oliver oliver 126386 20 Aug 2002 camlp4-3.06-tutorial.ps.gz
Exception: End_of_file.
#
===============================================================================

open_process_in is the aequivalent to a Unix popen(3) call
with a OCaml's channels on top of it.

You give that function the command you would type in a shell
and get back the stdout of the process - the stuff you
normally get to screen, when calling the command from
the shell.

BTW: after you finished, you have to call close_process_in; I didn't do thatin the
above example.

Best wishes,
Oliver Bandel

__._,_.___
.

__,_._,___
[1-10]

about | contact  Other archives ( Real Estate discussion Medical topics )