Article View: comp.text.tex
Article #9657Subdirectory searching
From: Timothy Murphy
Date: Fri, 11 Dec 1992 21:00
Date: Fri, 11 Dec 1992 21:00
145 lines
4558 bytes
4558 bytes
Karl Berry <karl@cs.umb.edu> writes:
> Also, TeX only stats those files which are in directories which *have*
> subdirectories. This means that if all your zillions of font files are
> in leaf directories, they don't have to be stat-ed.
Karl told me this a long time ago
{\em but I didn't understand him}.
For one thing the term "leaf directory"
conveyed nothing to me
beyond a vague picture of autumnal hues.
Karl suffers from an over-optimistic view
of the intelligence of the human race,
or at any rate the TeX race.
I believe this holds the solution to the tired TeX syndrome.
if you are running TeX over NFS on another machine.
If you are using KB's directory searching facility
(by ending directories in your directory list with //)
in his recent versions of Unix TeX,
then you ought to try to make a "pure" directory.
I define a directory to be pure if it either consists entirely of files,
or else consists entirely of subdirectories, each of which is pure.
In any case, {\em don't} have directories containing subdirectories
and also a large number of files.
(Eg don't copy the directory "latex-style-supported"
from ftp.uni-stuttgart.de with all its subdirectories intact.)
Karl's algorithm makes a list of subdirectories to search
by looking at each subdirectory
to determine if it just contains files
(by seeing if the number of links is <= 2).
If it does contain only files
then it passes by on the other side;
otherwise it "stat"s every entry in the directory
to see if it is a subdirectory.
Herewith a program to measure the impurity of your file system.
============================= HowPure.c ======================
/* Timothy Murphy 5 Dec 1992 */
/* This program may be used or misused in any way you like! */
/*
* I call the file system under a given directory
* "pure" if the directory either contains only files
* or else contains only subdirectories,
* all of which in turn are pure.
*
* Karl Berry's directory-searching technique in UnixTeX
* works best if any of the directories in TEXFONTS, TEXINPUTS, etc
* with subdirectory searching (as ordained by "//" at the end of the name)
* is pure.
*
* Usage: HowPure <dirname>
*
* The program returns the "impurity" of <dirname>
* defined as 0 if it contains only files,
* or else the number of files it contains
* plus the sum of the impurities of its subdirectories.
*
* Thus impurity = 0 if and only if <dirname> is pure.
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/stat.h>
int dodir( char* );
int main( int argc, char **argv )
{
struct stat statbuf;
DIR *dirp;
struct direct *dp;
if ( argc != 2 ) {
fprintf( stderr, "Usage: HowPure <dirname>\n");
exit(1);
}
printf( "impurity: %d\n", dodir( argv[1] ) );
}
int dodir( char *dirname )
{
struct stat statbuf;
DIR *dirp;
struct direct *dp;
char *subdirname;
int len = strlen( dirname );
int impurity = 0;
if ( stat( dirname, &statbuf ) < 0 )
perror( dirname ), exit( 2 );
if ( statbuf.st_nlink <= 2 ) /* only files in directory */
return 0;
dirp = opendir( dirname );
for ( dp = readdir( dirp ); dp; dp = readdir( dirp ) ) {
if ( strcmp( dp->d_name, "." ) == NULL
|| strcmp( dp->d_name, ".." ) == NULL )
continue;
subdirname = (char*)malloc( len + dp->d_namlen + 2 );
if ( subdirname == NULL )
perror( "malloc" ), exit( 2 );
/* sprintf( subdirname, "%s/%s", dirname, dp->d_name ); */
if ( stat( subdirname, &statbuf ) < 0 )
perror( subdirname ), exit( 2 );
if ( statbuf.st_mode & S_IFDIR )
impurity += dodir( subdirname );
else
impurity++;
free( subdirname );
}
closedir(dirp);
if ( impurity ) printf( "%s -> %d\n", dirname, impurity );
return impurity;
}
==============================================================
--
Timothy Murphy
e-mail: tim@maths.tcd.ie
tel: +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland
Technical Details
Message-ID:
<1992Dec11.210037.17786@maths.tcd.ie>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!ieunet!tcdcs!maths.tcd.ie!timShow Full Headers
Complete Article Headers
Newsgroups: comp.text.tex Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!ieunet!tcdcs!maths.tcd.ie!tim From: tim@maths.tcd.ie (Timothy Murphy) Subject: Subdirectory searching Message-ID: <1992Dec11.210037.17786@maths.tcd.ie> Summary: Karl you should have told us ... Keywords: Unix TeX directory searching Organization: Dept. of Maths, Trinity College, Dublin, Ireland. Date: Fri, 11 Dec 1992 21:00:37 GMT Lines: 145