[net.unix-wizards] help with dir. structure sysV vs. 4.2BSD

simpsong@cwruecmp.UUCP (Greg) (08/16/85)

*** Is there a line eater out there.. ***

In K&P's book "The Unix Programming Enviroment"
a spelling correction algorithym is presented to
use with such things as paginators. (see spname 
in the index.) It is written for sysV/4.1 directory
structures. I am having trouble converting it to 4.2

It uses a low level read (shown below; it is in
mindist() ) to look at the directory. I believe this 
is the line which gives me trouble.

       while (read(fd,(char *) &nbuf, sizeof(struct direct)) > 0)

I think I should be using DIRSIZ(dp), instead of sizeof... but
this is where I get in over my head. Has anyone out there 
ported this to 4.2? I have the rest of the sources, but I
didn't want to post K&P's program without their permission.

Thanks in advance... p.s. If you don't have the book, buy it
it is worth the money...

If I get it working on 4.2 and sysV, and get permission to
post it... I will

Please send answers by mail. I will post a summary.

Gregory R. Simpson  ---  decvax!cwruecmp!simpsong

       or CSNET:  simpsong%case.csnet@CSNET-RELAY.CSNET

guy@sun.uucp (Guy Harris) (08/17/85)

> In K&P's book "The Unix Programming Enviroment"
> a spelling correction algorithym is presented to
> use with such things as paginators. (see spname 
> in the index.) It is written for sysV/4.1 directory
> structures. I am having trouble converting it to 4.2
> 
> It uses a low level read (shown below; it is in
> mindist() ) to look at the directory. I believe this 
> is the line which gives me trouble.

Using low level reads to look at the directory is the wrong thing to do on
any 4.2BSD system; it's also not the best thing to do on the V7 file system,
either.  If you use the "directory library", either in its V7 file system
form or its 4.2 file system form, you can move your code between systems
using the two different file systems without change.

See DIRECTORY(3) for a writeup on this library.  The library was originally
written for 4.1aBSD, which used the V7 file system, and programs were
converted to use it; later, a 4.2BSD version was written.  The V7 file
system version was posted to net.sources by Kirk McKusick a long time ago,
and is available in the distributions of several bits of software like
"sendmail" and the RTI/4.2BSD UUCP.  Another V7 file system version was
posted by Doug Gwyn more recently.

Everybody out there offering a UNIX with a V7 file system (this means you,
AT&T) should provide the directory library with their system, and rewrite
their programs to use it.  It's easy, it's fun, and it fixes at least two
known bugs in S5 utilities, since "readdir" always null-terminates the file
name, while the filename isn't necessarily terminated in the raw directory
structure (this causes "ls -C" to screw up its pagination if it encounters a
14-character file name, and I believe it also screwed up "make" or the
shell).

	Guy Harris

peter@baylor.UUCP (Peter da Silva) (08/19/85)

> It uses a low level read (shown below; it is in
> mindist() ) to look at the directory. I believe this 
> is the line which gives me trouble.
> 
>        while (read(fd,(char *) &nbuf, sizeof(struct direct)) > 0)
> 
> I think I should be using DIRSIZ(dp), instead of sizeof... but
> this is where I get in over my head. Has anyone out there 
> ported this to 4.2? I have the rest of the sources, but I
> didn't want to post K&P's program without their permission.

You want to replace the code with the library routines to read
directories. Look it up in section 3 of the manual.
-- 
	Peter (Made in Australia) da Silva
		UUCP: ...!shell!neuro1!{hyd-ptd,baylor,datafac}!peter
		MCI: PDASILVA; CIS: 70216,1076

tim@cithep.UucP (Tim Smith ) (08/31/85)

Another nice place for the spelling corrector is the shell.  Someone ( I
think it was Rob himself ) has placed it in the shell at cithep.  It is
used on the pathname when a cd fails.
-- 
unlk	a6
rts
					Tim Smith
				ihnp4!{wlbr!callan,cithep}!tim