home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 458.lha / KCD / kcd.c < prev    next >
C/C++ Source or Header  |  1990-12-28  |  24KB  |  1,026 lines

  1. /* HeaderFiles */
  2.  
  3. #include <stdio.h>
  4. #include <exec/memory.h>
  5. #include <libraries/dosextens.h>
  6. #include <intuition/intuitionbase.h>
  7.  
  8. /*  Macros */
  9.  
  10. #define ACTIVE_SCREEN IntuitionBase->ActiveScreen
  11. #define ACTIVE_WINDOW IntuitionBase->ActiveWindow
  12. #define CLASS         ((Message)? Message->Class: 0 )
  13.  
  14. /* Declarations */
  15.  
  16. struct Library      * OpenLibrary() ;
  17. struct Window       * OpenWindow() ;
  18. struct IntuiMessage * GetMsg() ,
  19.                     * Message = NULL ;
  20.  
  21. VOID   CloseLibrary() ;
  22.  
  23. /* externe Strukturen */
  24.  
  25. struct IntuitionBase    * IntuitionBase ;
  26. struct GfxBase          * GfxBase ;
  27.  
  28. /* Funktionen */
  29.  
  30. SHORT OpenLib()
  31. {
  32.   if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  33.     { return (1) ; }
  34.  
  35.   if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
  36.     { return (2) ; }
  37.  
  38.   return(0) ;
  39. }
  40.  
  41. VOID CloseLib()
  42. {
  43.   if(IntuitionBase) CloseLibrary(IntuitionBase);
  44.   if(GfxBase)       CloseLibrary(GfxBase);
  45. }
  46.  
  47. struct Window   * win = NULL ;
  48. struct RastPort * RP  = NULL ;
  49.  
  50. struct Task *FindTask() ;
  51.  
  52. VOID Print() ;
  53. VOID Block() ;
  54. VOID Line() ;
  55. ULONG GetMessage() ;
  56. struct Window *GetWindow() ;
  57. void * calloc() ;
  58. extern long Lock(), Examine(), ExNext() ;
  59. char * strsave() ;
  60. struct Dir_Eintrag * sortiere_liste() ;
  61.  
  62. struct Dir_Eintrag {
  63.                      struct Dir_Eintrag * next  ;
  64.                      struct Dir_Eintrag * prev  ;
  65.                      int                  ebene ;
  66.                      char               * name  ;
  67.                    }  ;
  68.  
  69. struct anti_list   {
  70.                      struct anti_list * next  ;
  71.                      char             * name  ;
  72.                    }  ;
  73.  
  74. struct anti_list * anti_list_anf = NULL ;
  75.  
  76. struct Dir_Eintrag * Dir_Anfang = NULL ,
  77.                    * Dir_Ende   = NULL ,
  78.                    * window_anf = NULL ,
  79.                    * window_end = NULL ;
  80.  
  81. FILE  * datei_zeiger,
  82.       * datei_zeiger1;
  83.  
  84. int     i,
  85.         xpos = 0 ,
  86.         ypos = 0 ,
  87.         R_Rand = 8,
  88.         O_Rand = 11,
  89.         max_laenge = 0,
  90.         max_hoehe  = 0,
  91.         max_window_height = 0 ,
  92.         TEXTCOL = 1 ,
  93.         MARKCOL = 3 ,
  94.         LINECOL = 2 ,
  95.         delay   = 0 ,
  96.         scroll  = 8 ,
  97.         new     = 0 ,
  98.         list    = 0 ,
  99.         sort    = 0 ,
  100.         temp    = 0 ,
  101.         file    = 0 ;
  102.  
  103. char    *prog_name,
  104.         command_string[100] ,
  105.         newdir[200] ,
  106.         newdirBCPL[200] ,
  107.         rootdir[40] ,
  108.         text1[40] ,
  109.         text2[80] ,
  110.         dirlist[50] ,
  111.         antilist[50] ,
  112.         configfile[50] ,
  113.         rootdir_list[5][40] = {
  114.                                 "DH0:",
  115.                                 "\0",
  116.                                 "\0",
  117.                                 "\0",
  118.                                 "\0"
  119.                               } ;
  120.  
  121. /* ************************************************************************* */
  122.  
  123. main ( argc , argv )
  124.   int argc ;
  125.   char * argv[] ;
  126. {
  127.   int zaehler = 0 ;
  128.   prog_name = "KCD" ;
  129.  
  130.   sprintf( configfile, "s:%s.cfg"     , prog_name ) ;
  131.   sprintf( dirlist   , "s:%s.list"    , prog_name ) ;
  132.   sprintf( antilist  , "s:%s.antilist", prog_name ) ;
  133.   strcpy( command_string , "setenv NewPath %s" ) ;
  134.  
  135.   if( datei_zeiger = fopen( configfile , "r" ) )
  136.    {
  137.     while ( lese_config_file( datei_zeiger ) )
  138.     {
  139.      if( !stricmp( text1 , "TEXTCOLOR" ) )
  140.       { TEXTCOL = atoi(text2) ; continue ; }
  141.  
  142.      if( !stricmp( text1 , "MARKCOLOR" ) )
  143.       { MARKCOL = atoi(text2) ; continue ; }
  144.  
  145.      if( !stricmp( text1 , "LINECOLOR" ) )
  146.       { LINECOL = atoi(text2) ; continue ; }
  147.  
  148.      if( !stricmp( text1 , "WINDOWX" ) )
  149.       {
  150.        xpos    = atoi(text2) ;
  151.        if( xpos<0 )
  152.         xpos = 0 ;
  153.        continue ;
  154.       }
  155.  
  156.      if( !stricmp( text1 , "WINDOWY" ) )
  157.       {
  158.        ypos    = atoi(text2) ;
  159.        if( ypos<0 )
  160.         ypos = 0 ;
  161.        continue ;
  162.       }
  163.  
  164.      if( !stricmp( text1 , "ROOTDIR" ) )
  165.       { strcpy(rootdir_list[zaehler],text2) ; ++zaehler ; continue ; }
  166.  
  167.      if( !stricmp( text1 , "DELAY" ) )
  168.       { delay   = atoi(text2) ; continue ; }
  169.  
  170.      if( !stricmp( text1 , "SORT" ) )
  171.       { sort  = atoi(text2) ; continue ; }
  172.  
  173.      if( !stricmp( text1 , "SCROLL" ) )
  174.       {
  175.        scroll  = atoi(text2) ;
  176.        if( scroll<1 || scroll>4 )
  177.         scroll=8 ;
  178.        if( scroll == 3 )
  179.         scroll=4 ;
  180.        continue ;
  181.       }
  182.  
  183.      if( !stricmp( text1 , "NOT" ) )
  184.       { make_anti_list( text2 ) ; continue ; }
  185.  
  186.      if( !stricmp( text1 , "COMMAND" ) )
  187.       { strcpy( command_string , text2 ) ; continue ; }
  188.  
  189.      printf("\n%s nicht erlaubt in Konfigurations-Datei %s.\n\n" , text1 , configfile ) ;
  190.      End(0) ;
  191.     }
  192.    }
  193.   fclose( datei_zeiger ) ;
  194.  
  195.   if( argc>2 )
  196.       print_use() ;
  197.  
  198.   if( argc == 2 )
  199.    {
  200.     if( argv[1][0] == '-' )
  201.      switch( argv[1][1] )
  202.       {
  203.         case 'n' :
  204.         case 'N' :
  205.                       new = 1 ;
  206.                       break ;
  207.  
  208.         case 'l' :
  209.         case 'L' :
  210.                       list = 1 ;
  211.                       break ;
  212.  
  213.         case '?' :
  214.                       print_use() ;
  215.                       break ;
  216.  
  217.         case 'f' :
  218.         case 'F' :
  219.                       strcpy( dirlist, argv[1]+2 ) ;
  220.                       if( !fopen( dirlist ,"r") )
  221.                        {
  222.                         printf( "\nKann Datei `%s' nicht oeffnen !\n\n", dirlist ) ;
  223.                         End(0) ;
  224.                        }
  225.                       file = 1 ;
  226.                       break ;
  227.  
  228.         default :
  229.                       print_use() ;
  230.       }
  231.     else
  232.      {
  233.       int laenge ;
  234.  
  235.       laenge = strlen(argv[1]) ;
  236.       temp = 1 ;
  237.       if( laenge == 1 && argv[1][0] == '?' )
  238.         print_use() ;
  239.       sprintf( dirlist, "RAM:%s.list", prog_name) ;
  240.       strcpy(rootdir_list[0],argv[1]) ;
  241.       if( (argv[1][laenge-1] != '/') &&
  242.           (argv[1][laenge-1] != ':') )
  243.        {
  244.         rootdir_list[0][laenge]   = '/' ;
  245.         rootdir_list[0][laenge+1] = '\0' ;
  246.        }
  247.  
  248.       rootdir_list[1][0] = '\0' ;
  249.      }
  250.    }
  251.  
  252.   if(OpenLib())
  253.     printf("\nKann Library nicht oeffnen!\n\n"), exit(0) ;
  254.  
  255.   if( !(datei_zeiger = fopen( dirlist ,"r")) || new || list || temp )
  256.    {
  257.     fclose( datei_zeiger ) ;
  258.  
  259.     if( list )
  260.      {
  261.       if( datei_zeiger1 = fopen( antilist ,"r") )
  262.        {
  263.         printf( "\nDatei `%s' schon vorhanden.\n", antilist ) ;
  264.         printf( "-->Von Hand mit `delete %s' loeschen.\n\n", antilist ) ;
  265.         End(0) ;
  266.        }
  267.  
  268.       if( !(datei_zeiger1 = fopen( antilist ,"w")) )
  269.        {
  270.         printf( "\nKann Datei `%s' nicht zum schreiben oeffnen !!\n\n", antilist ) ;
  271.         End(0) ;
  272.        }
  273.      }
  274.      else
  275.       if( !temp)
  276.        lese_anti_list() ;
  277.  
  278.     if( datei_zeiger = fopen( dirlist ,"w"))
  279.      {
  280.       if( !temp )
  281.        printf("\nDirectory-Struktur wird ermittelt.\nBitte etwas Geduld.\n\n");
  282.       for( zaehler = 0 ; zaehler<6 && rootdir_list[zaehler][0]!='\0' ; ++zaehler )
  283.        {
  284.         strcpy( rootdir , rootdir_list[zaehler] ) ;
  285.         fprintf( datei_zeiger, " 0 %s\n", rootdir ) ;
  286.         if( !temp )
  287.          printf( "Untersuche %s\n", rootdir ) ;
  288.         search_dir( rootdir , 1 ) ;
  289.         if( sort )
  290.          Dir_Anfang = sortiere_liste( Dir_Anfang , 1 ) ;
  291.         for( window_anf = Dir_Anfang ; window_anf ; window_anf = window_anf->next )
  292.          fprintf( datei_zeiger , "%2d %s\n", window_anf->ebene , window_anf->name ) ;
  293.         Dir_Anfang = NULL ;
  294.         Dir_Ende   = NULL ;
  295.         window_anf = NULL ;
  296.         window_end = NULL ;
  297.        }
  298.       fclose( datei_zeiger ) ;
  299.       if( !temp )
  300.         End(0) ;
  301.        else
  302.         {
  303.          max_laenge = 0 ;
  304.          max_hoehe  = 0 ;
  305.         }
  306.      }
  307.      else
  308.      {
  309.       printf( "\nKann Datei `%s' nicht oeffnen !!\n\n", dirlist ) ;
  310.       End(0) ;
  311.      }
  312.    }
  313.  
  314.   lese_structur() ;
  315.  
  316.   if( max_hoehe == 1 )
  317.    {
  318.     printf( "Keine Unterverzeichnisse gefunden.\n") ;
  319.     End(0) ;
  320.    }
  321.  
  322.   max_hoehe = 8*max_hoehe + 18 ;
  323.  
  324.   if( max_hoehe > ACTIVE_SCREEN->Height )
  325.     max_hoehe = ACTIVE_SCREEN->Height ;
  326.  
  327.   max_window_height = max_hoehe ;
  328.  
  329.   if( max_hoehe+ypos > ACTIVE_SCREEN->Height )
  330.     max_hoehe = ACTIVE_SCREEN->Height - ypos ;
  331.  
  332.   max_laenge += 20 ;
  333.  
  334.   if( max_laenge < 110 )
  335.     max_laenge = 110 ;
  336.  
  337.   if( max_laenge > ACTIVE_SCREEN->Width )
  338.     max_laenge = ACTIVE_SCREEN->Width ;
  339.  
  340.   if( max_laenge+xpos > ACTIVE_SCREEN->Width )
  341.     xpos = ACTIVE_SCREEN->Width - max_laenge ;
  342.  
  343.   if(!( win = GetWindow(xpos , ypos , max_laenge , max_hoehe , 0 ,
  344.                         WINDOWCLOSE|ACTIVATE|WINDOWSIZING|WINDOWDRAG|REPORTMOUSE,
  345.                         prog_name,0)))
  346.     End(0) ;
  347.  
  348.   RP = win->RPort ;
  349.  
  350.   strcpy( newdir , "" ) ;
  351.  
  352.   zeige_structur() ;
  353.  
  354.   End(0) ;
  355. }
  356.  
  357. /* ************************************************************************* */
  358.  
  359. print_use()
  360. {
  361.   printf( " %s 1.0 by Karsten Krauskopf, Feb 1990\n", prog_name );
  362.   printf( "  USE: %s [ ? | -n | -l | -f<file> | <Directory> | <Device:> ]\n", prog_name );
  363.   printf( "    ? .. dieser Text\n" );
  364.   printf( "   -n .. Datei %s neu ermitteln\n", dirlist );
  365.   printf( "   -l .. Datei %s neu ermitteln\n", antilist );
  366.   printf( "   -f .. Struktur aus Datei <file>\n\n" );
  367.   End(0) ;
  368. }
  369.  
  370. /* ************************************************************************* */
  371.  
  372. End( error )
  373.   int error ;
  374. {
  375.   if ( win )
  376.    CloseWindow( win ) ;
  377.   CloseLib() ;
  378.   exit( error );
  379. }
  380.  
  381. /* ************************************************************************* */
  382.  
  383. lese_config_file( datei )
  384.   FILE *datei ;
  385. {
  386.   char zeile[120] ;
  387.   char *pointer, c ;
  388.   int  textnummer = 0 , i ;
  389.  
  390. next_zeile:
  391.   if( !fgets(zeile,120,datei) )
  392.    return 0 ;
  393.  
  394.   pointer = text1 ;
  395.  
  396.   for( i=0 ; i<120 ; ++i )
  397.   {
  398.    switch( zeile[i] )
  399.    {
  400.     case '\n' :
  401.     case ';'  :
  402.                  i = 120 ;
  403.                  break ;
  404.  
  405.     case '\''  :
  406.                  pointer = text2 ; ++i ;
  407.                  *pointer = '\0' ;
  408.                  while( zeile[i] < 120 )
  409.                   {
  410.                    if( zeile[i] == '\'' )
  411.                      { i = 120 ; textnummer = 4 ; break ; }
  412.                    *pointer = zeile[i] ; ++pointer ; ++i ; *pointer = '\0' ;
  413.                   }
  414.                  break ;
  415.  
  416.     case ' ' :
  417.                  if( textnummer == 1 || textnummer == 3 )
  418.                    {
  419.                      ++textnummer ;
  420.                      if( textnummer == 2 )
  421.                        pointer = text2 ;
  422.                    }
  423.                  break ;
  424.  
  425.     default  :
  426.                  if( textnummer == 0 || textnummer == 2 )
  427.                    ++textnummer ;
  428.                  *pointer = zeile[i] ;
  429.                  ++pointer ;
  430.                  *pointer = '\0' ;
  431.                  break ;
  432.  
  433.    }
  434.   }
  435.   if( textnummer >= 3 )
  436.     return 1 ;
  437.   textnummer=0 ;
  438.   pointer=text1 ;
  439.   goto next_zeile ;
  440. }
  441.  
  442. /* ************************************************************************* */
  443.  
  444. lese_anti_list()
  445. {
  446.   char Directory[200] ;
  447.   struct anti_list *ptr ;
  448.  
  449.   if( datei_zeiger1 = fopen( antilist ,"r") )
  450.    while ( fgets( &Directory , 200 , datei_zeiger1 ) )
  451.     if( Directory[0] == '-' )
  452.      {
  453.       Directory[strlen(Directory)-1] = '\0' ;
  454.       make_anti_list( &Directory[1] ) ;
  455.      }
  456.   fclose( datei_zeiger1 ) ;
  457. }
  458.  
  459. /* ************************************************************************* */
  460.  
  461. make_anti_list( Dir_Name )
  462.   char *Dir_Name ;
  463. {
  464.   static struct anti_list *new_entry = NULL ,
  465.                           *ptr                     ;
  466.   static int               new_entry_counter = 101 ;
  467.  
  468.   ++new_entry ;
  469.   if( (++new_entry_counter) > 100 )
  470.    {
  471.     new_entry_counter = 1 ;
  472.     if ( !(new_entry = (struct anti_list *) calloc(100,sizeof(struct anti_list))) )
  473.      platzprobleme() ;
  474.    }
  475.  
  476.   new_entry->next  = (struct anti_list *) NULL ;
  477.   new_entry->name  = strsave( Dir_Name ) ;
  478.  
  479.   if( !anti_list_anf )
  480.    {
  481.     anti_list_anf = new_entry ;
  482.     ptr = new_entry ;
  483.     return ;
  484.    }
  485.   ptr->next = new_entry ;
  486.   ptr = new_entry ;
  487. }
  488.  
  489. /* ************************************************************************* */
  490.  
  491. suche_anti_list( Dir_Name )
  492.   char *Dir_Name ;
  493. {
  494.   struct anti_list *ptr ;
  495.  
  496.   for( ptr = anti_list_anf ; ptr ; ptr = ptr->next )
  497.    if( !stricmp( Dir_Name , ptr->name ) )
  498.     return 1 ;
  499.   return 0 ;
  500. }
  501.  
  502. /* ************************************************************************* */
  503.  
  504. search_dir( name , ebene )
  505.   char *name  ;
  506.   int   ebene ;
  507. {
  508.   struct FileInfoBlock * fib ;
  509.   BPTR                   lok ;
  510.   char                   temp[200] ;
  511.   int                    i ;
  512.  
  513.   if(!(lok=Lock (name,ACCESS_READ)))
  514.    {
  515.     printf( "\nDirectory %s nicht gefunden.\n\n", name ) ;
  516.     End(0) ;
  517.    }
  518.  
  519.   if (!(fib = (struct FileInfoBlock *) calloc(1,sizeof(struct FileInfoBlock))))
  520.    {
  521.     printf ("\nCan't allocate FileInfoBlock.\n\n") ;
  522.     End(0) ;
  523.    }
  524.  
  525.   if(!Examine(lok,fib))
  526.    {
  527.     printf("\nExamine failed.\n\n") ;
  528.     End(0) ;
  529.    }
  530.  
  531.   while ( ExNext( lok , fib ) )
  532.    if( fib->fib_DirEntryType > 0 )
  533.     {
  534.      strcpy( temp , name );
  535.      if (ebene == 1)
  536.        strcat(temp,fib->fib_FileName);
  537.       else
  538.        strcat(temp,"/"),strcat(temp,fib->fib_FileName);
  539.  
  540.      if( list )
  541.       {
  542.        if( !suche_anti_list( temp ) )
  543.         {
  544.          fprintf( datei_zeiger1, "%s\n"  , temp ) ;
  545.          make_eintrag( ebene , fib->fib_FileName ) ;
  546.          search_dir( temp , ebene+1 ) ;
  547.         }
  548.       }
  549.       else
  550.        if( !suche_anti_list( temp ) )
  551.         {
  552.          make_eintrag( ebene , fib->fib_FileName ) ;
  553.          search_dir( temp , ebene+1 ) ;
  554.         }
  555.     }
  556.  
  557. ende:
  558.   if ( lok ) UnLock( lok ) ;
  559. }
  560.  
  561. /* ************************************************************************* */
  562.  
  563. lese_structur()
  564. {
  565.   char Directory[35] ;
  566.  
  567.   if( !( datei_zeiger = fopen( dirlist , "r" )))
  568.    {
  569.     printf("\nKann Datei `%s' nicht oeffnen !!!\n\n", dirlist ) ;
  570.     End(0) ;
  571.    }
  572.  
  573.   while ( fgets( &Directory , 35 , datei_zeiger ) )
  574.   {
  575.    Directory[strlen(Directory)-1] = '\0' ;
  576.    Directory[2] = '\0' ;
  577.    make_eintrag( atoi(Directory) , &Directory[3] ) ;
  578.   }
  579.  
  580.   if( max_hoehe < 1 )
  581.    {
  582.     printf("\nDatei `%s' hat keine Eintraege !!\n\n", dirlist ) ;
  583.     End(0) ;
  584.    }
  585. }
  586.  
  587. /* ************************************************************************* */
  588.  
  589. make_eintrag( Ebene , Dir_Name )
  590.   int    Ebene    ;
  591.   char  *Dir_Name ;
  592. {
  593.   static struct Dir_Eintrag *new_entry         = NULL ;
  594.   static int                 new_entry_counter = 101  ;
  595.  
  596.   ++max_hoehe ;
  597.   ++new_entry ;
  598.   if( (++new_entry_counter) > 100 )
  599.    {
  600.     new_entry_counter = 1 ;
  601.     if ( !(new_entry = (struct Dir_Eintrag *) calloc(100,sizeof(struct Dir_Eintrag))) )
  602.      platzprobleme() ;
  603.    }
  604.  
  605.   if( max_laenge < ( R_Rand + Ebene*32 + 8*strlen(Dir_Name) ) )
  606.    max_laenge = R_Rand + Ebene*32 + 8*strlen(Dir_Name) ;
  607.  
  608.   if( Dir_Anfang )
  609.    {
  610.     new_entry->next  = (struct Dir_Eintrag *) NULL ;
  611.     new_entry->prev  = Dir_Ende ;
  612.     new_entry->ebene = Ebene ;
  613.     new_entry->name  = strsave( Dir_Name ) ;
  614.  
  615.     Dir_Ende->next   = new_entry ;
  616.     Dir_Ende         = new_entry ;
  617.  
  618.     return ;
  619.    }
  620.  
  621.   new_entry->next     = (struct Dir_Eintrag *) NULL ;
  622.   new_entry->prev     = (struct Dir_Eintrag *) NULL ;
  623.   new_entry->ebene    = Ebene ;
  624.   new_entry->name     = strsave( Dir_Name ) ;
  625.  
  626.   Dir_Anfang = new_entry ;
  627.   Dir_Ende   = new_entry ;
  628. }
  629.  
  630. /* ************************************************************************* */
  631.  
  632. char *strsave(s)
  633.   register char *s ;
  634. {
  635.   register char * cp = calloc( strlen(s)+1, 1 ) ;
  636.  
  637.   if ( cp )
  638.    {
  639.     strcpy( cp , s ) ;
  640.     return cp ;
  641.    }
  642.   platzprobleme() ;
  643. }
  644.  
  645. /* ************************************************************************* */
  646.  
  647. struct Dir_Eintrag * hole_eintrag( position )
  648.         int     position ;
  649. {
  650.   struct Dir_Eintrag * ptr ;
  651.  
  652.   for( ptr = window_anf ; ptr ; ptr = ptr->next , --position )
  653.    if( !position ) return ptr ;
  654. }
  655.  
  656. /* ************************************************************************* */
  657.  
  658. ermittle_dir( pointer )
  659.         struct Dir_Eintrag * pointer ;
  660. {
  661.   struct Dir_Eintrag * ptr ;
  662.   int ebene ;
  663.   char temp[200] ;
  664.  
  665.   ebene = pointer->ebene ;
  666.   strcpy( newdir , pointer->name ) ;
  667.  
  668.   for( ptr = pointer ; ptr ; ptr = ptr->prev )
  669.    if( ptr->ebene < ebene )
  670.     {
  671.      ebene = ptr->ebene ;
  672.      strcpy( temp , ptr->name ) ;
  673.      if( ptr->ebene >0 )
  674.       strcat( temp , "/" ) ;
  675.      strcat( temp , newdir ) ;
  676.      strcpy( newdir , temp ) ;
  677.     }
  678.   newdirBCPL[0] = (char)strlen(newdir) ;
  679.   newdirBCPL[1] = '\0' ;
  680.   strcat( newdirBCPL , newdir ) ;
  681. }
  682.  
  683. /* ************************************************************************* */
  684.  
  685. zeige_structur()
  686.  
  687. {
  688.   int   i,
  689.         pos,
  690.         pos_alt,
  691.         x,
  692.         y,
  693.         anzahl_zeilen,
  694.         anzahl_spalten,
  695.         hoehe,
  696.         breite ,
  697.         activ = 1 ;
  698.  
  699.   struct Dir_Eintrag * ptr = NULL ;
  700.  
  701.   ModifyIDCMP( win , MOUSEBUTTONS|CLOSEWINDOW|REFRESHWINDOW ) ;
  702.  
  703. anfang:
  704.   anzahl_zeilen  = (win->Height-13)/8 ;
  705.   anzahl_spalten = (win->Width-25)/8 ;
  706.   hoehe  = win->Height ;
  707.   breite = win->Width ;
  708.  
  709.   i = 0 ;
  710.   for ( ptr = Dir_Anfang ; ptr ; ptr = ptr->next )
  711.    {
  712.     if ( i == anzahl_zeilen )
  713.      break ;
  714.     zeige_eintrag( ptr , i ) ;
  715.     ++i ;
  716.    }
  717.  
  718.   window_anf = Dir_Anfang ;
  719.   if( ptr )
  720.     window_end = ptr->prev ;
  721.    else
  722.     window_end = Dir_Ende ;
  723.  
  724.   pos_alt = -1 ;
  725.  
  726.   while( 1 )
  727.   {
  728.    while(ACTIVE_WINDOW != win)
  729.     { Delay(10) ; activ = 0 ; }
  730.  
  731.    if( delay )
  732.     Delay(delay) ;
  733.  
  734.    if ( win->Height != hoehe || win->Width != breite )
  735.     {
  736.      Block(RP,0,2,11,win->Width-17,win->Height-2);
  737.      goto anfang;
  738.     }
  739.    pos = ((win->MouseY)-12)/8 ;
  740.  
  741.    if ( pos != pos_alt && pos>=0 && pos<anzahl_zeilen )
  742.     {
  743.      if( pos_alt >= 0 )
  744.       {
  745.        ptr = hole_eintrag( pos_alt ) ;
  746.        x = R_Rand + ptr->ebene*32 ; y = 18+pos_alt*8 ;
  747.        Print(RP, ptr->name, TEXTCOL, x, y) ;
  748.       }
  749.  
  750.      ptr = hole_eintrag( pos ) ;
  751.      x = R_Rand + ptr->ebene*32 ; y = 18+pos*8 ;
  752.      Print(RP, ptr->name, MARKCOL , x, y) ;
  753.      pos_alt = pos ;
  754.     }
  755.  
  756.    if ( pos <= 0 && window_anf != Dir_Anfang )
  757.     {
  758.      int z ;
  759.  
  760.      window_anf = window_anf->prev ;
  761.      window_end = window_end->prev ;
  762.      ++pos_alt ;
  763.      for( z=0 ; z<8 ; z+=scroll )
  764.       ScrollRaster(RP,0,-scroll,2,11,win->Width-17,O_Rand+anzahl_zeilen*8) ;
  765.      zeige_eintrag( window_anf , 0 ) ;
  766.     }
  767.  
  768.    if (pos >= anzahl_zeilen-1 && window_end != Dir_Ende )
  769.     {
  770.      int z ;
  771.  
  772.      window_anf = window_anf->next ;
  773.      window_end = window_end->next ;
  774.      --pos_alt ;
  775.      for( z=0 ; z<8 ; z+=scroll )
  776.       ScrollRaster(RP,0,scroll,2,11,win->Width-17,O_Rand+anzahl_zeilen*8) ;
  777.      zeige_eintrag( window_end , anzahl_zeilen-1 ) ;
  778.     }
  779.  
  780.    if( GetMessage( win ) )
  781.     {
  782.      if ( (CLASS == MOUSEBUTTONS) && ptr )
  783.       {
  784.        if( activ )
  785.         {
  786.          char temp[200] ;
  787.  
  788.          ermittle_dir( ptr ) ;
  789.          sprintf( temp , command_string , newdir ) ;
  790.          Execute( temp , 0 , 0 ) ;
  791.          End(0) ;
  792.         }
  793.         else
  794.          if ( Message->Code == SELECTUP )
  795.           activ = 1 ;
  796.       }
  797.  
  798.      if ( CLASS == CLOSEWINDOW )
  799.       {
  800.        Execute( "setenv newpath" , 0 , 0 ) ;
  801.        break ;
  802.       }
  803.  
  804.     }
  805.   }
  806. }
  807.  
  808. /* ************************************************************************* */
  809.  
  810. zeige_eintrag( eintrag , zeile )
  811.    struct Dir_Eintrag * eintrag ;
  812.    int                  zeile ;
  813.  
  814. {
  815.   int    x, y, j, ebene ;
  816.   struct Dir_Eintrag * ptr ;
  817.  
  818.   x = R_Rand +(eintrag->ebene)*32 ; y = O_Rand+7+zeile*8 ;
  819.   Print( RP , eintrag->name , TEXTCOL , x , y ) ;
  820.   if( eintrag->ebene )
  821.     {
  822.       if( eintrag->next && ( eintrag->ebene == eintrag->next->ebene ) )
  823.           Line( RP,LINECOL,x-18,y-7,x-18,y );
  824.         else
  825.           Line( RP,LINECOL,x-18,y-7,x-18,y-3 ) ;
  826.       Line(RP,LINECOL,x-18,y-3,x-2,y-3) ;
  827.       ebene = eintrag->ebene ;
  828.       ptr = eintrag ;
  829.       while ( ptr )
  830.         {
  831.           ptr = ptr->next ;
  832.           if( ptr->ebene < ebene )
  833.             {
  834.               ebene = ptr->ebene ;
  835.               x = R_Rand+ebene*32 ; y = 18+zeile*8 ;
  836.               Line(RP,LINECOL,x-18,y-7,x-18,y);
  837.             }
  838.         }
  839.     }
  840. }
  841.  
  842. /* ************************************************************************* */
  843.  
  844. struct Window *GetWindow(left,top,width,height,idcmp,flags,title,gad)
  845.   SHORT  left,top,width,height ;
  846.   ULONG  idcmp,flags ;
  847.   STRPTR title ;
  848.   struct Gadget *gad ;
  849.  
  850. {
  851.   struct NewWindow NW ;
  852.  
  853.   NW.LeftEdge    = left ;
  854.   NW.TopEdge     = top ;
  855.   NW.Width       = width ;
  856.   NW.Height      = height ;
  857.   NW.DetailPen   = -1 ;
  858.   NW.BlockPen    = -1 ;
  859.   NW.IDCMPFlags  = idcmp ;
  860.   NW.Flags       = flags ;
  861.   NW.FirstGadget = gad ;
  862.   NW.CheckMark   = NULL ;
  863.   NW.Title       = title ;
  864.   NW.Screen      = ACTIVE_SCREEN ;
  865.   NW.BitMap      = NULL ;
  866.   NW.MinWidth    = width ;
  867.   NW.MinHeight   = 34 ;
  868.   NW.MaxWidth    = width  ;
  869.   NW.MaxHeight   = max_window_height ;
  870.   NW.Type        = WBENCHSCREEN ;
  871.  
  872.   return(OpenWindow(&NW)) ;
  873. }
  874.  
  875. /* ************************************************************************* */
  876.  
  877. ULONG GetMessage(MW)  /* Intuition-Message lesen */
  878.   struct Window *MW ;
  879. {
  880.   ULONG class = 0 ;
  881.  
  882.   if ( Message = GetMsg(MW->UserPort))
  883.     {
  884.       class = Message->Class ;
  885.       ReplyMsg(Message) ;
  886.     }
  887.   return class ;
  888. }
  889.  
  890. /* ************************************************************************* */
  891.  
  892. VOID Line(RP, col, x1, y1, x2, y2)
  893.   struct RastPort *RP ;
  894.   SHORT  col, x1, y1, x2, y2 ;
  895. {
  896.   SetDrMd(RP, JAM1) ;
  897.   SetAPen(RP, col) ;
  898.   Move(RP, x1, y1) ;
  899.   Draw(RP, x2, y2) ;
  900. }
  901.  
  902. /* ************************************************************************* */
  903.  
  904. VOID Block(RP, col, x1, y1, x2, y2)
  905.   struct RastPort *RP ;
  906.   SHORT  col, x1, y1, x2, y2 ;
  907. {
  908.   if ( (x1>x2)||(y1>y2)) return ;
  909.   SetDrMd(RP, JAM1) ;
  910.   SetAPen(RP, col) ;
  911.   RectFill(RP, x1, y1, x2, y2) ;
  912. }
  913.  
  914. /* ************************************************************************* */
  915.  
  916. VOID Print(RP, text, col, xpos, ypos)
  917.   struct RastPort *RP ;
  918.   STRPTR text ;
  919.   SHORT  col, xpos, ypos ;
  920. {
  921.   SetDrMd(RP, JAM1) ;
  922.   SetAPen(RP, col) ;
  923.   Move(RP, xpos, ypos);
  924.   Text(RP, text, strlen(text));
  925. }
  926.  
  927. /* ************************************************************************* */
  928.  
  929. platzprobleme()
  930. {
  931.   printf( "\nKein Platz mehr fuer weiter Eintraege.\n\n") ;
  932.   End(0) ;
  933. }
  934.  
  935. /* ************************************************************************* */
  936.  
  937. int stricmp(str1,str2)
  938. register char *str1,*str2;
  939. {
  940.   register int index = 0;
  941.  
  942.   while ( str1[index] && str2[index] && tolower(str1[index]) == tolower(str2[index]) )
  943.     ++index;
  944.  
  945.   return( (tolower(str1[index]) < tolower(str2[index])) ? -1 :
  946.         ( (tolower(str1[index]) > tolower(str2[index])) ?  1 : 0) );
  947. }
  948.  
  949. /* ************************************************************************* */
  950.  
  951. struct Dir_Eintrag * sortiere_liste( anfang , ebene )
  952.   struct Dir_Eintrag * anfang ;
  953.   int                  ebene ;
  954. {
  955.   struct Dir_Eintrag * ptr1 , * ptr2 ;
  956.  
  957.   ptr1 = anfang ;
  958.   ptr2 = ptr1   ;
  959.  
  960.   while( ptr2 && (ptr2->ebene >= ebene) )
  961.    {
  962.     if( ptr2->ebene > ebene )
  963.       {
  964.         ptr2 = sortiere_liste( ptr2 , ebene+1 ) ;
  965.         while( ptr2 && (ptr2->ebene > ebene) )
  966.           ptr2 = ptr2->next ;
  967.         continue ;
  968.       }
  969.     ptr2 = ptr2->next ;
  970.    }
  971.  
  972.   while( 1 )
  973.    {
  974.     while( ptr1 && (ptr1->ebene != ebene) )
  975.       ptr1 = ptr1->next ;
  976.     if( !ptr1 || (ptr1->ebene < ebene ) )
  977.       break ;
  978.     ptr2 = ptr1->next ;
  979.     while(1)
  980.      {
  981.       while( ptr2 && (ptr2->ebene > ebene) )
  982.         ptr2 = ptr2->next ;
  983.       if( !ptr2 || (ptr2->ebene < ebene ) )
  984.         break ;
  985.       if( ( sort > 0 && stricmp( ptr1->name , ptr2->name ) > 0 ) ||
  986.           ( sort < 0 && stricmp( ptr1->name , ptr2->name ) < 0 )   )
  987.         {
  988.           struct Dir_Eintrag * hilf1 , *hilf2 , *hilf3 ;
  989.  
  990.           hilf1 = ptr1 ;
  991.           while( hilf1->next && (hilf1->next->ebene > ebene ))
  992.             hilf1 = hilf1->next ;
  993.  
  994.           hilf2 = ptr2 ;
  995.           while( hilf2->next && (hilf2->next->ebene > ebene ))
  996.             hilf2 = hilf2->next ;
  997.  
  998.           if( ptr1 == anfang )
  999.             anfang = ptr2 ;
  1000.  
  1001.           ptr1->prev->next = ptr2 ;
  1002.           ptr2->prev->next = ptr1 ;
  1003.           hilf3 = hilf1->next ;
  1004.           hilf1->next = hilf2->next ;
  1005.           hilf2->next = hilf3 ;
  1006.  
  1007.           hilf3 = ptr1->prev ;
  1008.           ptr1->prev = ptr2->prev ;
  1009.           ptr2->prev = hilf3 ;
  1010.           if( hilf2->next )
  1011.             hilf2->next->prev = hilf2 ;
  1012.           if( hilf1->next )
  1013.             hilf1->next->prev = hilf1 ;
  1014.  
  1015.           hilf3 = ptr1 ;
  1016.           ptr1 = ptr2 ;
  1017.           ptr2 = hilf3 ;
  1018.         }
  1019.       ptr2 = ptr2->next ;
  1020.      }
  1021.     ptr1 = ptr1->next ;
  1022.    }
  1023.   return anfang ;
  1024. }
  1025.  
  1026.