home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / utility / misc / guideutl / 2ndindex / 2ndindex.c next >
C/C++ Source or Header  |  1993-09-28  |  3KB  |  139 lines

  1. /* 2ndIndex zu 1stGuide, dem Hypertextsystem von Guido Vollbeding
  2.  * 2ndIndex von Dirk Haun, 30.04./01.05.1993 (Pure C 1.1)
  3.  *            & Guido Vollbeding, 28.09.1993 (Pure C 1.1 vom Mar 20 1993)
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. #define TRUE    1
  11. #define FALSE   0
  12. #define forever for (;;)
  13.  
  14. typedef struct node
  15. {
  16.   struct node *next;
  17.   char s[];
  18. }
  19. NODE;
  20.  
  21. /* Prototypes */
  22. int make_index( void );
  23. int insert_node( NODE *base, char *entry );
  24.  
  25. /* globale Variablen */
  26. NODE stwbase = { 0 }, datbase = { 0 };
  27. char refpath[256];
  28. long refpos;
  29. FILE *fp;
  30.  
  31. int main( int argc, char *argv[] )
  32. {
  33.   char *xp;
  34.   NODE *actfile;
  35.  
  36.   if (--argc <= 0)
  37.   {
  38.     fprintf( stderr, "\n Aufruf: 2ndindex [pfadname] [>output]\n\n" );
  39.     return 0;
  40.   }
  41.   strcpy( refpath, argv[1] );
  42.   if ((xp = strrchr( refpath, '\\' )) == 0)
  43.   {
  44.     fprintf( stderr, "\n 2ndindex: Bitte kompletten Pfadnamen angeben.\n\n" );
  45.     return 1;
  46.   }
  47.   refpos = xp + 1 - refpath;
  48.   if ((fp = fopen( refpath, "rb" )) == 0)
  49.   {
  50.     fprintf( stderr, "\n 2ndindex: Fehler beim Öffnen!\n\n" );
  51.     return 1;
  52.   }
  53.   fprintf( stderr, "\n Erstelle Index von %s ...\n", refpath );
  54.   actfile = &datbase;
  55.   forever
  56.   {
  57.     make_index();
  58.     forever
  59.     {
  60.       if ((actfile = actfile->next) == 0) /* fertig! */
  61.       { 
  62.         fprintf( stderr, "\n 2ndindex: Operation erfolgreich abgeschlossen.\n\n" );
  63.         fclose( fp ); return 0;
  64.       }
  65.       if ((xp = strrchr( actfile->s, '.' )) != 0)
  66.       {
  67.         if (stricmp( xp, ".IMG" ) == 0) continue;
  68.         if (stricmp( xp, ".IFF" ) == 0) continue;
  69.         if (stricmp( xp, ".JPG" ) == 0) continue;
  70.         if (stricmp( xp, ".GEM" ) == 0) continue;
  71.         if (stricmp( xp, ".RSC" ) == 0) continue;
  72.         if (stricmp( xp, ".SAM" ) == 0) continue;
  73.         if (stricmp( xp, ".SND" ) == 0) continue;
  74.         if (stricmp( xp, ".AVR" ) == 0) continue;
  75.       }
  76.       if (freopen( actfile->s, "rb", fp ) == 0) continue;
  77.       break;
  78.     }
  79.     strcpy( refpath, actfile->s );
  80. } }
  81.  
  82. int make_index( void )
  83. {
  84.   int c;
  85.   char *cp, *dp, wort[256], datei[256], pfad[256];
  86.  
  87.   forever
  88.   {
  89.     c = fgetc( fp );
  90.     if (c == EOF) return TRUE;
  91.     if (c == (unsigned char)'§')
  92.     {
  93.       cp = wort;
  94.       forever
  95.       {
  96.         c = fgetc( fp );
  97.         if (c == EOF) return FALSE;
  98.         if (c == (unsigned char)'§') break;
  99.         *cp++ = c;
  100.       }
  101.       *cp = 0;
  102.       cp = datei;
  103.       forever
  104.       {
  105.         c = fgetc( fp );
  106.         if (c == EOF) return FALSE;
  107.         if (c == (unsigned char)'§') break;
  108.         *cp++ = c;
  109.       }
  110.       *cp = 0;
  111.       if (insert_node( &stwbase, wort ))
  112.       {
  113.         strcpy( pfad, refpath ); dp = datei;
  114.         forever
  115.         {
  116.           cp = strrchr( pfad, '\\' );
  117.           if (strncmp( dp, "..\\", 3 )) break;
  118.           *cp = 0; dp += 3;
  119.         }
  120.         strcpy( cp + 1, dp );
  121.         printf( "\t§%s§%s§\n", wort, pfad + refpos );
  122.         insert_node( &datbase, pfad );
  123. } } } }
  124.  
  125. int insert_node( NODE *np, char *entry )
  126. {
  127.   while (np->next)
  128.   {
  129.     np = np->next;
  130.     if (stricmp( np->s, entry ) == 0) return FALSE;
  131.   }                       /* Länge des Strings + Nullbyte + Zeiger */
  132.   if ((np->next = malloc( strlen( entry ) + (1 + sizeof(NODE)) )) == 0)
  133.     return FALSE;
  134.   np = np->next;
  135.   np->next = 0;
  136.   strcpy( np->s, entry );
  137.   return TRUE;
  138. }
  139.