home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / text / tex / 14093 < prev    next >
Encoding:
Text File  |  1992-12-11  |  4.3 KB  |  157 lines

  1. Newsgroups: comp.text.tex
  2. Path: sparky!uunet!mcsun!ieunet!tcdcs!maths.tcd.ie!tim
  3. From: tim@maths.tcd.ie (Timothy Murphy)
  4. Subject: Subdirectory searching
  5. Message-ID: <1992Dec11.210037.17786@maths.tcd.ie>
  6. Summary: Karl you should have told us ...
  7. Keywords: Unix TeX directory searching
  8. Organization: Dept. of Maths, Trinity College, Dublin, Ireland.
  9. Date: Fri, 11 Dec 1992 21:00:37 GMT
  10. Lines: 145
  11.  
  12. Karl Berry <karl@cs.umb.edu> writes:
  13.  
  14. > Also, TeX only stats those files which are in directories which *have*
  15. > subdirectories.  This means that if all your zillions of font files are
  16. > in leaf directories, they don't have to be stat-ed.
  17.  
  18. Karl told me this a long time ago 
  19. {\em but I didn't understand him}.
  20. For one thing the term "leaf directory" 
  21. conveyed nothing to me
  22. beyond a vague picture of autumnal hues.
  23. Karl suffers from an over-optimistic view
  24. of the intelligence of the human race, 
  25. or at any rate the TeX race.
  26.  
  27. I believe this holds the solution to the tired TeX syndrome.
  28. if you are running TeX over NFS on another machine.
  29.  
  30. If you are using KB's directory searching facility 
  31. (by ending directories in your directory list with //)
  32. in his recent versions of Unix TeX,
  33. then you ought to try to make a "pure" directory.
  34.  
  35. I define a directory to be pure if it either consists entirely of files,
  36. or else consists entirely of subdirectories, each of which is pure.
  37.  
  38. In any case, {\em don't} have directories containing subdirectories
  39. and also a large number of files.
  40. (Eg don't copy the directory "latex-style-supported"
  41. from ftp.uni-stuttgart.de with all its subdirectories intact.)
  42.  
  43. Karl's algorithm makes a list of subdirectories to search
  44. by looking at each subdirectory
  45. to determine if it just contains files
  46. (by seeing if the number of links is <= 2).
  47. If it does contain only files
  48. then it passes by on the other side;
  49. otherwise it "stat"s every entry in the directory
  50. to see if it is a subdirectory.
  51.  
  52. Herewith a program to measure the impurity of your file system.
  53.  
  54. ============================= HowPure.c ======================
  55.  
  56. /* Timothy Murphy 5 Dec 1992 */
  57. /* This program may be used or misused in any way you like! */
  58.  
  59. /*
  60.  * I call the file system under a given directory
  61.  * "pure" if the directory either contains only files
  62.  * or else contains only subdirectories,
  63.  * all of which in turn are pure.
  64.  *
  65.  * Karl Berry's directory-searching technique in UnixTeX
  66.  * works best if any of the directories in TEXFONTS, TEXINPUTS, etc
  67.  * with subdirectory searching (as ordained by "//" at the end of the name)
  68.  * is pure.
  69.  *
  70.  * Usage: HowPure <dirname>
  71.  *
  72.  * The program returns the "impurity" of <dirname>
  73.  * defined as 0 if it contains only files,
  74.  * or else the number of files it contains
  75.  * plus the sum of the impurities of its subdirectories.
  76.  *
  77.  * Thus impurity = 0 if and only if <dirname> is pure.
  78.  */
  79.  
  80. #include <stdio.h>
  81. #include <string.h>
  82. #include <sys/types.h>
  83. #include <sys/dir.h>
  84. #include <sys/stat.h>
  85.  
  86. int dodir( char* );
  87.  
  88. int main( int argc, char **argv )
  89. {
  90.   struct stat statbuf;
  91.   DIR *dirp;
  92.   struct direct *dp;
  93.  
  94.   if ( argc != 2 ) {
  95.     fprintf( stderr, "Usage: HowPure <dirname>\n");
  96.     exit(1);
  97.   }
  98.  
  99.   printf( "impurity: %d\n", dodir( argv[1] ) );
  100.  
  101. }
  102.  
  103. int dodir( char *dirname )
  104. {
  105.   struct stat statbuf;
  106.   DIR *dirp;
  107.   struct direct *dp;
  108.   char *subdirname;
  109.   int len = strlen( dirname );
  110.   int impurity = 0;
  111.  
  112.   if ( stat( dirname, &statbuf ) < 0 )
  113.     perror( dirname ), exit( 2 );
  114.  
  115.   if ( statbuf.st_nlink <= 2 ) /* only files in directory */
  116.     return 0;
  117.  
  118.   dirp = opendir( dirname );
  119.   for ( dp = readdir( dirp ); dp; dp = readdir( dirp ) ) {
  120.  
  121.     if ( strcmp( dp->d_name, "." ) == NULL
  122.       || strcmp( dp->d_name, ".." ) == NULL )
  123.       continue;
  124.  
  125.     subdirname = (char*)malloc( len + dp->d_namlen + 2 );
  126.     if ( subdirname == NULL )
  127.       perror( "malloc" ), exit( 2 );
  128.     /* sprintf( subdirname, "%s/%s", dirname, dp->d_name ); */
  129.  
  130.     if ( stat( subdirname, &statbuf ) < 0 )
  131.       perror( subdirname ), exit( 2 );
  132.  
  133.     if ( statbuf.st_mode & S_IFDIR )
  134.       impurity += dodir( subdirname );
  135.     else 
  136.       impurity++;
  137.  
  138.     free( subdirname );
  139.  
  140.   }
  141.   closedir(dirp);
  142.  
  143. if ( impurity ) printf( "%s -> %d\n", dirname, impurity );
  144.  
  145.   return impurity;
  146.  
  147. }
  148.  
  149. ==============================================================
  150.  
  151.  
  152. -- 
  153. Timothy Murphy  
  154. e-mail: tim@maths.tcd.ie
  155. tel: +353-1-2842366
  156. s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland
  157.