zsh-workers
 help / color / mirror / code / Atom feed
* _man - fast searching for glob patterns
@ 1999-09-27 17:08 Andrej Borsenkow
  1999-09-27 17:17 ` Zefram
  0 siblings, 1 reply; 4+ messages in thread
From: Andrej Borsenkow @ 1999-09-27 17:08 UTC (permalink / raw)
  To: ZSH workers mailing list

Our system (descendant of Pyramid DC/OSx) has an unusual man system. The man
directory is assumed to have mandb file with format

man_page section path_to_file ...

("normal" man pages are supported as well - with caveat, that if the system
finds mandb man page it never searches for normal one).

Well, it is trivial to look for mandb file ... unfortunately, the number of
manual pages is about 4000 - so, the simple

while read manpage dummy
  if [[ $manpage == $our-search-pattern ]]
   ...
done < $mandb-file

needs a considerable amount of time (10-15 seconds here). Globbing is hard to
use, because path_to_file may be *anything* - so, file names are not always
valid manpage names. And directory structure under man dir may be of any depth
as well - so, recursive globbing is needed and it takes some time as well.

Any idea?

TIA

/andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: _man - fast searching for glob patterns
  1999-09-27 17:08 _man - fast searching for glob patterns Andrej Borsenkow
@ 1999-09-27 17:17 ` Zefram
  1999-09-27 17:33   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Zefram @ 1999-09-27 17:17 UTC (permalink / raw)
  To: Andrej Borsenkow; +Cc: zsh-workers

Andrej Borsenkow wrote:
>Well, it is trivial to look for mandb file ... unfortunately, the number of
>manual pages is about 4000

Better read the index file once, and cache it in an associative array.

-zefram


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: _man - fast searching for glob patterns
  1999-09-27 17:17 ` Zefram
@ 1999-09-27 17:33   ` Bart Schaefer
  1999-09-28  8:34     ` Andrej Borsenkow
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1999-09-27 17:33 UTC (permalink / raw)
  To: Andrej Borsenkow, ZSH workers mailing list, Zefram

On Sep 27,  9:08pm, Andrej Borsenkow wrote:
} Subject: _man - fast searching for glob patterns
}
} while read manpage dummy
}   if [[ $manpage == $our-search-pattern ]]
}    ...
} done < $mandb-file
} 
} needs a considerable amount of time (10-15 seconds here).

On Sep 27,  6:17pm, Zefram wrote:
} Subject: Re: _man - fast searching for glob patterns
}
} Better read the index file once, and cache it in an associative array.

Check out the "mapfile" module.

zmodload mapfile
if [[ -f /usr/man/mandb ]]
then
  allpages=(${"${(f)mapfile[/usr/man/mandb]}"%% *})
  firstmatchingpage=$allpages[(r)$our-search-pattern]
  # ... etc. ...
fi

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: _man - fast searching for glob patterns
  1999-09-27 17:33   ` Bart Schaefer
@ 1999-09-28  8:34     ` Andrej Borsenkow
  0 siblings, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 1999-09-28  8:34 UTC (permalink / raw)
  To: Bart Schaefer, ZSH workers mailing list, Zefram


>   firstmatchingpage=$allpages[(r)$our-search-pattern]

Thank you. This is a bit faster

rep[$#rep+1]=(${(M)allpages:#${~approx}$PREFIX${~star}$SUFFIX})

it gets all matching elements and assigns them to result. The speed is
acceptable (I suppose, globbing would take the same time).

BTW I wonder, if

array[$#array+1]=(...)

is much better than

array=($array ...)

??

cheers

/andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-09-28  9:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-27 17:08 _man - fast searching for glob patterns Andrej Borsenkow
1999-09-27 17:17 ` Zefram
1999-09-27 17:33   ` Bart Schaefer
1999-09-28  8:34     ` Andrej Borsenkow

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).