home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / dicepj11.lha / diceproject / main.c < prev    next >
C/C++ Source or Header  |  1993-03-12  |  24KB  |  929 lines

  1. /* This file contains empty template routines that
  2.  * the IDCMP handler will call uppon. Fill out these
  3.  * routines with your code or use them as a reference
  4.  * to create your program.
  5.  */
  6.  
  7. #include <exec/types.h>
  8. #include <exec/lists.h>
  9. #include <exec/memory.h>
  10. #include <exec/nodes.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/classusr.h>
  14. #include <intuition/imageclass.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <libraries/gadtools.h>
  17. #include <libraries/asl.h>
  18. #include <graphics/displayinfo.h>
  19. #include <graphics/gfxbase.h>
  20. #include <dos/datetime.h>
  21. #include <dos/dostags.h>
  22. #include <dos/dos.h>
  23.  
  24. #include <clib/alib_protos.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/asl_protos.h>
  28. #include <clib/intuition_protos.h>
  29. #include <clib/icon_protos.h>
  30. #include <clib/wb_protos.h>
  31. #include <clib/gadtools_protos.h>
  32. #include <clib/graphics_protos.h>
  33. #include <clib/utility_protos.h>
  34.  
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <ctype.h>
  39.  
  40. #include "project.h"
  41.  
  42. /*  Variables global de status    */
  43.  
  44. BOOL done=FALSE;
  45. BOOL named = FALSE;
  46. BOOL saved = TRUE;
  47.  
  48. struct List *ModuleList;
  49.  
  50. struct ModuleNode *CurrentModule;
  51.  
  52. /*  Variables du menu options    */
  53.  
  54. struct TagItem gtag[] = { GTLV_Labels , 0 , 0 };
  55.  
  56. struct TagItem ttag[] = { GTTX_Text , 0 , 0 };
  57.  
  58. /****************************************************************************
  59. ***                                      ***
  60. ***    Gestion de la liste des modules                   ***
  61. ***                                      ***
  62. ****************************************************************************/
  63.  
  64. /****************************************************************
  65. ***    Liste des modules au niveau de GadTools           ***
  66. ****************************************************************/
  67.  
  68. void DettachList( void ) {
  69.     gtag[0].ti_Data = 0;
  70.     GT_SetGadgetAttrsA( ProjectGadgets[0] , ProjectWnd , NULL , gtag );
  71. }
  72.  
  73. void AttachList( void ) {
  74.     gtag[0].ti_Data = (long)ModuleList;
  75.     GT_SetGadgetAttrsA( ProjectGadgets[0] , ProjectWnd , NULL , gtag );
  76. }
  77.  
  78. /****************************************************************
  79. ***    Creation du nom devant être affiché dans la liste     ***
  80. ****************************************************************/
  81.  
  82. void MakeRealNameList( struct ModuleNode *mn ) {
  83.   char *name,*objfile;
  84.   struct FileInfoBlock fib;
  85.   char size[10];
  86.  
  87.     if ( stricmp( mn->directory , SourceDir ) )
  88.     name = mn->pathfile;
  89.     else
  90.     name = mn->filename;
  91.     mn->namelist = malloc( strlen(name) + 20 );
  92.     *mn->namelist = 0;
  93.     if ( mn->type=='c' && GetInfo( &fib , mn->pathfile ) ) {
  94.     ltoa( size , fib.fib_Size );
  95.     while( strlen( mn->namelist ) + strlen( size ) < 6 )
  96.         strcat( mn->namelist , " " );
  97.     strcat( mn->namelist , size );
  98.     } else
  99.     strcat( mn->namelist , "  --  " );
  100.     if ( mn->type == 'c' ) {
  101.     objfile = PathName( ObjDir , mn->filename );
  102.     MakeObject( objfile );
  103.     } else
  104.     objfile = strdup( mn->pathfile );
  105.     if ( GetInfo( &fib , objfile ) ) {
  106.     ltoa( size , fib.fib_Size );
  107.     while( strlen( mn->namelist ) + strlen( size ) < 13 )
  108.         strcat( mn->namelist , " " );
  109.     strcat( mn->namelist , size );
  110.     } else
  111.     strcat( mn->namelist , "   --  " );
  112.     free( objfile );
  113.     if ( IsCommented( mn->pathfile ) )
  114.     strcat( mn->namelist , "  * " );
  115.     else
  116.     strcat( mn->namelist , "    " );
  117.     strcat( mn->namelist , name );
  118.     mn->node.ln_Name = mn->namelist;
  119.     mn->name = &mn->namelist[17];
  120. }
  121.  
  122. /****************************************************************
  123. ***    Mise à jour des noms apparaissant dans la liste       ***
  124. ****************************************************************/
  125.  
  126. void UpdateNameList( void ) {
  127.   struct ModuleNode *mn=ModuleList->lh_Head;
  128.  
  129.     DettachList( );
  130.     while( mn->node.ln_Succ ) {
  131.     MakeRealNameList( mn );
  132.     mn = mn->node.ln_Succ;
  133.     }
  134.     AttachList( );
  135. }
  136.  
  137. /****************************************************************
  138. ***    Liste des modules dans le chainage d'Exec             ***
  139. ****************************************************************/
  140.  
  141. BOOL FindName2( char *search ) {
  142.   struct ModuleNode *wn=ModuleList->lh_Head;
  143.  
  144.     while( wn->node.ln_Succ ) {
  145.     if ( !stricmp( wn->name , search ) )
  146.         return( TRUE );
  147.     wn = wn->node.ln_Succ;
  148.     }
  149.     return( FALSE );
  150. }
  151.  
  152. struct ModuleNode *AddModuleNode( struct List *list , char *name , char *directory ) {
  153.   struct ModuleNode *wn;
  154.   struct ModuleNode *bn = list->lh_TailPred;
  155.   int r;
  156.   char *t;
  157.  
  158.     if ( (wn = malloc( sizeof(struct ModuleNode) )) ) {
  159.     if ( !strchr( directory , ':' ) )
  160.         wn->directory = PathName( SourceDir , directory );
  161.     else
  162.         wn->directory = strdup( directory );
  163.     wn->pathfile = PathName( wn->directory , name );
  164.     wn->filename = BaseName( wn->pathfile );
  165.     r = stricmp( wn->directory , SourceDir );
  166.     if ( (r && FindName2( wn->pathfile )) ||
  167.                 (!r && FindName2( wn->filename )) ) {
  168.         free( wn->directory );
  169.         free( wn->pathfile );
  170.         free( wn );
  171.         return;
  172.     }
  173.     wn->node.ln_Type = MODULE_NODE;
  174.     if ( t = strchr( wn->filename , '.' ) )
  175.         wn->type = tolower( t[1] );
  176.     else
  177.         wn->type = 0;
  178.     if ( list == ModuleList ) {
  179.         saved = FALSE;
  180.         MakeRealNameList( wn );
  181.     } else
  182.         wn->node.ln_Name = wn->namelist = wn->name = strdup( wn->filename );
  183.  
  184.     while( (struct List *)bn!=list && stricmp( wn->name , bn->name ) < 0 )
  185.         bn = bn->node.ln_Pred;
  186.     if ( (struct List *)bn!=list )
  187.         Insert( list , (struct Node *)wn , (struct Node *)bn );
  188.     else
  189.         AddHead( list , (struct Node *)wn );
  190.     return( wn );
  191.     }
  192.     return( NULL );
  193. }
  194.  
  195. /****************************************************************
  196. ***    Detruit un module dans une liste              ***
  197. ****************************************************************/
  198.  
  199. void RemModuleNode( struct ModuleNode *wn ) {
  200.  
  201.     free( wn->directory );
  202.     free( wn->pathfile );
  203.     free( wn->namelist );
  204.     Remove( (struct Node *)wn );
  205.     free( wn );
  206. }
  207.  
  208. /****************************************************************
  209. ***    Detruit tous les modules d'une list                   ***
  210. ****************************************************************/
  211.  
  212. void FreeModuleNodes( struct List *list ) {
  213.   struct ModuleNode *wn,*nn;
  214.  
  215.     wn = list->lh_Head;
  216.     while( wn->node.ln_Succ ) {
  217.     nn = wn->node.ln_Succ;
  218.     RemModuleNode( wn );
  219.     wn = nn;
  220.     }
  221. }
  222.  
  223. /****************************************************************
  224. ***    Detruit une liste ainsi que ses modules           ***
  225. ****************************************************************/
  226.  
  227. void FreeList( struct List *list ) {
  228.     FreeModuleNodes( list );
  229.     free( list );
  230. }
  231.  
  232. /****************************************************************
  233. ***    Genere une liste des fichiers include              ***
  234. ****************************************************************/
  235.  
  236. void AddIncludeList( struct List *list , struct ModuleNode *wn ) {
  237.   FILE *in;
  238.   char temp[500];
  239.  
  240.     if ( wn ) {
  241.     if ( in = fopen( wn->pathfile , "r" ) ) {
  242.         while( !feof( in ) ) {
  243.         fgets( temp , 500 , in );
  244.         if ( !strnicmp( temp , "#include \"" , 10 ) ) {
  245.             temp[ strlen(temp) - 2 ] = 0;
  246.             AddIncludeList( list , AddModuleNode( list , &temp[10] , wn->directory ) );
  247.         }
  248.         }
  249.         fclose( in );
  250.     }
  251.     }
  252. }
  253.  
  254. struct List *BuildIncludeList( struct ModuleNode *wn ) {
  255.   struct List *build;
  256.  
  257.     if ( build = malloc( sizeof( struct List ) ) ) {
  258.     NewList( build );
  259.     AddIncludeList( build , wn );
  260.     return( build );
  261.     }
  262.     return( NULL );
  263. }
  264.  
  265. /****************************************************************************
  266. ***                                      ***
  267. ***    Initialisation / Liberation des variables globales          ***
  268. ***                                      ***
  269. ****************************************************************************/
  270.  
  271. int InitVar( void ) {
  272.     ModuleList = malloc( sizeof( struct List ) );
  273.     if ( !ModuleList )
  274.     return( FALSE );
  275.     NewList( ModuleList );
  276.  
  277.     SourceDir = getcwd( NULL , 500 );
  278.     DestDir = strdup( SourceDir );
  279.     IncludeDir = strdup( "Work:DICE/include" );
  280.     LibDir = strdup( "Work:DICE/dlib" );
  281.     ObjDir = strdup( SourceDir );
  282.     PrgDir = strdup( "Work:DICE/bin/" );
  283.     DICEDir = strdup( "Work:DICE" );
  284.     MakeAssign( );
  285.     ProjectPathName = strdup( "No Name" );
  286.     ProjectName = strdup( "No Name" );
  287.     WindowTitle = strdup( "Project Handler : No Name" );
  288.     StartDir = getcwd( NULL , 500 );
  289.     OptFile = strdup( "Env:project.prefs" );
  290.     OptLine = strdup( "" );
  291.     MakeOptions( );
  292.     CurrentModule = NULL;
  293.     return( TRUE );
  294. }
  295.  
  296. void FreeVar( void ) {
  297.     FreeList( ModuleList );
  298.     RemoveAssign( );
  299.     free( DICEDir );
  300.     free( SourceDir );
  301.     free( DestDir );
  302.     free( IncludeDir );
  303.     free( LibDir );
  304.     free( ObjDir );
  305.     free( PrgDir );
  306.     free( ProjectPathName );
  307.     free( ProjectName );
  308.     free( WindowTitle );
  309.     free( StartDir );
  310.     free( OptFile );
  311.     free( OptLine );
  312. }
  313.  
  314.  
  315. /****************************************************************************
  316. ***                                      ***
  317. ***    Lecture des tooltypes de l'icone du programme                     ***
  318. ***                                      ***
  319. ****************************************************************************/
  320.  
  321. void GetToolTypes( struct WBStartup *WBStart ) {
  322.   struct WBArg *WBArg = WBStart->sm_ArgList;
  323.   struct DiskObject *dobj;
  324.   char **tt,*s;
  325.  
  326.     ProgramName = WBArg->wa_Name;
  327.     if ( dobj = GetDiskObject( WBArg->wa_Name ) ) {
  328.     tt = (char **)dobj->do_ToolTypes;
  329.     if( s=(char *)FindToolType(tt,"TOPEDGE" ) )
  330.         ProjectTop = (UWORD)atol(s);
  331.     if( s=(char *)FindToolType(tt,"LEFTEDGE" ) )
  332.         ProjectLeft = (UWORD)atol(s);
  333.     if( s=(char *)FindToolType(tt,"WIDTH" ) ) {
  334.         ProjectWidth = (UWORD)atol(s);
  335.         ProjectWidth -= OffX + Scr->WBorRight;
  336.     }
  337.     if( s=(char *)FindToolType(tt,"HEIGHT" ) ) {
  338.         ProjectHeight = (UWORD)atol(s);
  339.         ProjectHeight -= OffY + Scr->WBorBottom;
  340.     }
  341.     if( s=(char *)FindToolType(tt,"MTOPEDGE" ) )
  342.         MessTop = (UWORD)atol(s);
  343.     if( s=(char *)FindToolType(tt,"MLEFTEDGE" ) )
  344.         MessLeft = (UWORD)atol(s);
  345.     if( s=(char *)FindToolType(tt,"MWIDTH" ) ) {
  346.         MessWidth = (UWORD)atol(s);
  347.         MessWidth -= OffX + Scr->WBorRight;
  348.     }
  349.     if( s=(char *)FindToolType(tt,"MHEIGHT" ) ) {
  350.         MessHeight = (UWORD)atol(s);
  351.         MessHeight -= OffY + Scr->WBorBottom;
  352.     }
  353.     RemoveAssign( );
  354.     MakeAssign( );
  355.     FreeDiskObject( dobj );
  356.     }
  357. }
  358.  
  359.  
  360. /****************************************************************************
  361. ***                                      ***
  362. ***    Action des boutons ( liste ) de la fenêtre principale          ***
  363. ***                                      ***
  364. ****************************************************************************/
  365.  
  366. int ModuleListClicked( void )
  367. {
  368.   int n = ProjectMsg.Code;
  369.   struct ModuleNode *wn = ModuleList->lh_Head;
  370.   static ULONG sec=-1,mic;
  371.  
  372.     while( wn->node.ln_Succ && n-- ) {
  373.     wn = wn->node.ln_Succ;
  374.     }
  375.     if ( wn->node.ln_Succ )
  376.     CurrentModule = wn;
  377.     if ( sec != -1 && DoubleClick( sec , mic , ProjectMsg.Seconds , ProjectMsg.Micros ) )
  378.     ProjectEdit( );
  379.     sec = ProjectMsg.Seconds;
  380.     mic = ProjectMsg.Micros;
  381. }
  382.  
  383.  
  384. /****************************************************************************
  385. ***                                      ***
  386. ***    Actions des menus de la fenêtre principale              ***
  387. ***                                      ***
  388. ****************************************************************************/
  389.  
  390. int CancelForSave( void ) {
  391.   int r=1;
  392.  
  393.     if ( !strcmp( ProjectName , "No Name" ) )
  394.     return( 0 );
  395.     while ( !saved && r==1 ) {
  396.     r = 2-Message( ProjectWnd , "Current project is not saved !\nDo you want to save it before ?" , "Save|Don't|Cancel" );
  397.     if ( r==2 )
  398.         return( 1 );
  399.     if ( r==1 )
  400.         ProjectSave();
  401.     }
  402.     return( 0 );
  403. }
  404.  
  405. int ProjectNew( void )
  406. {
  407.     if ( !CancelForSave() ) {
  408.     DettachList( );
  409.     FreeModuleNodes( ModuleList );
  410.     ChangeProjectName( "No Name" );
  411.     saved = TRUE;
  412.     }
  413. }
  414.  
  415. int ProjectOpen( void )
  416. {
  417.   struct FileRequester *fr;
  418.   char *pf,name[200],name2[200];
  419.   FILE *fin;
  420.   ULONG OldDispID = DisplayScreen;
  421.  
  422.     if ( !CancelForSave() )
  423.     if ( fr = AskFile( "Select project to open" , "*.prj" ) ) {
  424.         pf = PathName( fr->rf_Dir , fr->rf_File );
  425.         if ( fin = fopen( pf , "r" ) ) {
  426.         if ( LoadOptions( pf , fin ) && VerifPrj( pf , "%MODULES%" , fin ) ) {
  427.             DettachList( );
  428.             RemoveAssign( );
  429.             MakeAssign( );
  430.             FreeModuleNodes( ModuleList );
  431.             while ( !feof( fin ) ) {
  432.             InputString( name , 200 , fin );
  433.             InputString( name2 , 200 , fin );
  434.             if ( feof( fin ) )
  435.                 break;
  436.             AddModuleNode( ModuleList , name , name2 );
  437.             }
  438.             AttachList( );
  439.             named = TRUE;
  440.             saved = TRUE;
  441.             ChangeProjectName( pf );
  442.         }
  443.         fclose( fin );
  444.         } else {
  445.         strcpy( name , "Can't open project \n" );
  446.         strcat( name , BaseName( pf ) );
  447.         Message( ProjectWnd , name , "OK" );
  448.         }
  449.         free( pf );
  450.         FreeAslRequest( fr );
  451.         if ( OldDispID != DisplayScreen )
  452.         UpdateScreen( );
  453.     }
  454. }
  455.  
  456. void SaveProject( void ) {
  457.   FILE *fout;
  458.   struct ModuleNode *wn = (struct Node *)ModuleList->lh_Head;
  459.  
  460.     if ( fout=fopen( ProjectPathName , "w" ) ) {
  461.     SaveOptions( fout );
  462.     fputs( "%MODULES%\n" , fout );
  463.     while( wn->node.ln_Succ ) {
  464.         OutputString( wn->filename , fout );
  465.         OutputString( wn->directory , fout );
  466.         wn = wn->node.ln_Succ;
  467.     }
  468.     fclose( fout );
  469.     saved = TRUE;
  470.     }
  471. }
  472.  
  473. int ProjectSaveas( void )
  474. {
  475.   struct FileRequester *fr;
  476.   char *pf;
  477.  
  478.     if ( fr = AskFile( "Enter project name" , "*.prj" ) ) {
  479.     pf = PathName( fr->rf_Dir , fr->rf_File );
  480.     if ( Overwrite( pf ) ) {
  481.         ChangeProjectName( pf );
  482.         SaveProject( );
  483.         named = TRUE;
  484.     } else
  485.         free( pf );
  486.     FreeAslRequest( fr );
  487.     }
  488. }
  489.  
  490. int ProjectSave( void )
  491. {
  492.     if ( !named ) {
  493.     ProjectSaveas( );
  494.     }
  495.     SaveProject( );
  496. }
  497.  
  498. /* Iconification : Ne marche pas pour l'instant ????? */
  499.  
  500. int ProjectIcon( void )
  501. {
  502. /*  struct DiskObject *dobj;
  503.   struct MsgPort    *iconport;
  504.   struct AppIcon    *appicon;
  505.   struct AppMessage *appmsg;
  506.  
  507.     if ( dobj = GetDiskObject( ProgramName ) ) {
  508.     dobj->do_Type = NULL;
  509.     if ( iconport = CreateMsgPort( ) ) {
  510.         MessCloseWindow( );
  511.         CloseProjectWindow( );
  512.         CloseDownScreen( );
  513.         if ( appicon = AddAppIconA( 0L , 0L , "DICE Project" , iconport , NULL , dobj , NULL ) ) {
  514.         WaitPort( iconport );
  515.         RemoveAppIcon( appicon );
  516.         }
  517.         while( appmsg=(struct AppMessage *)GetMsg( iconport ) )
  518.         ReplyMsg( (struct Message *)appmsg );
  519.         DeleteMsgPort( iconport );
  520.         SetupScreen( );
  521.         OpenProjectWindow( );
  522.         ChangeProjectName( ProjectPathName );
  523.         AttachList( );
  524.     }
  525.     FreeDiskObject( dobj );
  526.     }*/
  527. }
  528.  
  529. int ProjectAbout( void )
  530. {
  531.     Message( ProjectWnd ,
  532.          "Project Handler 1.1 ( 12 mars 1993 )\n\n"
  533.          "© Copyright 1993 Arcad Development\n"
  534.          " Written using DICE C v2.06.40 by\n"
  535.          "         Cedric Counotte\n\n"
  536.          " Thanks to Jan van den Baard\n"
  537.          "     for GadToolsBox 37.176\n"
  538.         , "Continue" );
  539. }
  540.  
  541. int ProjectQuit( void )
  542. {
  543.     if ( !CancelForSave() )
  544.     done = 1;
  545. }
  546.  
  547. int ProjectEdit( void )
  548. {
  549.     if ( CurrentModule ) {
  550.     EditModule( CurrentModule->pathfile );
  551.     }
  552. }
  553.  
  554. int ProjectInclude( void )
  555. {
  556.   struct List *IncludeList;
  557.   struct ModuleNode *include;
  558.  
  559.     if ( CurrentModule ) {
  560.     if ( IncludeList = BuildIncludeList( CurrentModule ) ) {
  561.         if ( IncludeList->lh_Head->ln_Succ ) {
  562.         include = ChooseInList( "Select module to edit :" , IncludeList );
  563.         if ( include )
  564.             EditModule( include->pathfile );
  565.         }
  566.         FreeList( IncludeList );
  567.     }
  568.     }
  569. }
  570.  
  571. int ProjectComment( void )
  572. {
  573.   struct FileInfoBlock fib;
  574.   char *commentfile;
  575.  
  576.     if ( CurrentModule ) {
  577.     if ( CurrentModule->filename[ strlen(CurrentModule->filename)-1 ] == 'c' ) {
  578.         commentfile = CommentName( CurrentModule->pathfile );
  579.         if ( !GetInfo( &fib , commentfile ) )
  580.         if ( !Message( ProjectWnd , "No comments currently binded to this module !\nDo you want to create one ?" , "Create|Forget" ) ) {
  581.             free( commentfile );
  582.             return( 0 );
  583.         }
  584.         EditModule( commentfile );
  585.         DettachList( );
  586.         MakeRealNameList( CurrentModule );
  587.         AttachList( );
  588.         free( commentfile );
  589.     } else
  590.         Message( ProjectWnd , "Sorry, you can't bind comments on this module !" , "Continue" );
  591.     }
  592. }
  593.  
  594. int ProjectCommentKill( void )
  595. {
  596.   char *commentfile,mess[200];
  597.  
  598.     if ( CurrentModule ) {
  599.     if ( CurrentModule->filename[ strlen(CurrentModule->filename)-1 ] == 'c' ) {
  600.         commentfile = CommentName( CurrentModule->pathfile );
  601.         if ( IsCommented( CurrentModule->pathfile ) ) {
  602.         strcpy( mess , "Comments binded to module " );
  603.         strcat( mess , CurrentModule->filename );
  604.         strcat( mess , " will be erased !\nAre you sure ?" );
  605.         if ( Message( ProjectWnd , mess , "Erase|Forget" ) ) {
  606.             DeleteFile( commentfile );
  607.             DettachList( );
  608.             MakeRealNameList( CurrentModule );
  609.             AttachList( );
  610.         }
  611.         } else
  612.         Message( ProjectWnd , "Sorry, this module don't owned any comments !" , "Continue" );
  613.         free( commentfile );
  614.     } else
  615.         Message( ProjectWnd , "Sorry, this module can't owned any comments !" , "Continue" );
  616.     }
  617. }
  618.  
  619. int ProjectAdd( void )
  620. {
  621.   struct FileRequester *fr;
  622.  
  623.     if (fr = AskFile( "Select module to add" , "(*.c|*.o|*.lib)" )) {
  624.     DettachList( );
  625.     AddModuleNode( ModuleList , fr->rf_File , fr->rf_Dir );
  626.     AttachList( );
  627.     FreeAslRequest(fr);
  628.     }
  629. }
  630.  
  631. int ProjectRem( void )
  632. {
  633.     if ( CurrentModule ) {
  634.     DettachList( );
  635.     RemModuleNode( CurrentModule );
  636.     saved = FALSE;
  637.     AttachList( );
  638.     CurrentModule = NULL;
  639.     }
  640. }
  641.  
  642. int ProjectOther( void )
  643. {
  644.   struct FileRequester *fr;
  645.   char *buf;
  646.  
  647.     if ( fr = AskFile( "Select module to edit" , "(*.c|*.h)" ) ) {
  648.     buf = PathName( fr->rf_Dir , fr->rf_File );
  649.     EditModule( buf );
  650.     free( buf );
  651.     FreeAslRequest( fr );
  652.     }
  653. }
  654.  
  655. int CheckDependencies( struct ModuleNode *wn ) {
  656.   char *obj;
  657.   struct FileInfoBlock fib1,fib2;
  658.   struct List *includes;
  659.   BOOL ret;
  660.  
  661.     CompileRender( TXT_CHECKING );
  662.     obj = PathName( ObjDir , wn->filename );
  663.     MakeObject( obj );
  664.     ret = !GetInfo( &fib1 , obj );
  665.     free( obj );
  666.  
  667.     if ( !ret && GetInfo( &fib2 , wn->pathfile ) )
  668.     if ( CompareDates( &fib1.fib_Date , &fib2.fib_Date ) > 0 )
  669.         ret = TRUE;
  670.     if ( !ret ) {
  671.     includes = BuildIncludeList( wn );
  672.     wn = includes->lh_Head;
  673.     while( wn->node.ln_Succ ) {
  674.         if ( GetInfo( &fib2 , wn->pathfile ) )
  675.         if ( CompareDates( &fib1.fib_Date , &fib2.fib_Date ) > 0 )
  676.             ret = TRUE;
  677.         wn = wn->node.ln_Succ;
  678.     }
  679.     FreeList( includes );
  680.     }
  681.     CompileRender( TXT_COMPILING );
  682.     return( ret );
  683. }
  684.  
  685. int ProjectCompile( void )
  686. {
  687.   char command[500];
  688.   struct ModuleNode *wn = ModuleList->lh_Head;
  689.   struct IntuiMessage *m=NULL;
  690.  
  691.     KeepMessages = FALSE;
  692.     OpenCompileWindow( TXT_COMPILING );
  693.     while( wn->node.ln_Succ ) {
  694.     if ( wn->type == 'c' ) {
  695.         ttag[0].ti_Data = wn->name;
  696.         GT_SetGadgetAttrsA( CompileGadgets[0] , CompileWnd , NULL , ttag );
  697.         if ( CheckDependencies( wn ) ) {
  698.         strcpy( command , PrgDir );
  699.         strcat( command , "dcc >RAM:Compiler_Error -c " );
  700.         strcat( command , wn->pathfile );
  701.         strcat( command , " -o " );
  702.         strcat( command , ObjDir );
  703.         MakePath( command );
  704.         strcat( command , wn->filename );
  705.         MakeObject( command );
  706.         strcat( command , OptLine );
  707.         strcat( command , " -E \"ram:Compiler_Errors\"" );
  708.         if ( strlen( command )>499 )
  709.             Message( ProjectWnd , "Warning : Command length greater than 500 !" , "Continue" );
  710.         DeleteFile( "RAM:Compiler_Errors" );
  711.         DeleteFile( "RAM:Compiler_Error" );
  712.         Launch( command , FALSE );
  713.         if ( (m = GT_GetIMsg( CompileWnd->UserPort )) || ViewErrors( "RAM:Compiler_Errors" ) ) {
  714.             if ( m )
  715.             GT_ReplyIMsg( m );
  716.             CloseCompileWindow( );
  717.             UpdateNameList( );
  718.             return( FALSE );
  719.         }
  720.         }
  721.     }
  722.     wn = wn->node.ln_Succ;
  723.     }
  724.     CloseCompileWindow( );
  725.     UpdateNameList( );
  726.     return( TRUE );
  727. }
  728.  
  729. void CreateObjList( void ) {
  730.   struct ModuleNode *wn = ModuleList->lh_Head;
  731.   FILE *out;
  732.   char *buf;
  733.  
  734.     if ( out = fopen( "ram:objlist" , "w" ) ) {
  735.     while( wn->node.ln_Succ ) {
  736.         buf = strdup( wn->filename );
  737.         if ( wn->type == 'c' )
  738.         MakeObject( buf );
  739.         OutputString( buf , out );
  740.         free( buf );
  741.         wn = wn->node.ln_Succ;
  742.     }
  743.     fclose( out );
  744.     }
  745. }
  746.  
  747. int ProjectLink( void )
  748. {
  749.   char command[500];
  750.  
  751.     OpenCompileWindow( TXT_LINKING );
  752.     CreateObjList( );
  753.     chdir( ObjDir );
  754.     strcpy( command , PrgDir );
  755.     strcat( command , "dcc >\"RAM:Linker_Error\" @RAM:objlist -E \"RAM:Linker_Errors\" -o " );
  756.     strcat( command , DestDir );
  757.     MakePath( command );
  758.     strcat( command , ProjectName );
  759.     strcat( command , OptLine );
  760.     if ( strlen( command )>499 )
  761.     Message( ProjectWnd , "Warning : Command length greater than 500 !" , "Continue" );
  762.     DeleteFile( "RAM:Linker_Errors" );
  763.     DeleteFile( "RAM:Linker_Error" );
  764.     Launch( command , FALSE );
  765.     chdir( StartDir );
  766.     ViewErrors( "RAM:Linker_Errors" );
  767.     CloseCompileWindow( );
  768. }
  769.  
  770. int ProjectGenerate( void )
  771. {
  772.   char *temp;
  773.   struct ModuleNode *wn = ModuleList->lh_Head;
  774.  
  775.     while( wn->node.ln_Succ ) {
  776.     temp = PathName( ObjDir , wn->filename );
  777.     MakeObject( temp );
  778.     DeleteFile( temp );
  779.     free( temp );
  780.     wn = wn->node.ln_Succ;
  781.     }
  782.     if ( ProjectCompile( ) )
  783.     ProjectLink( );
  784. }
  785.  
  786. int ProjectLibrary( void )
  787. {
  788.   char command[500];
  789.  
  790.     ProjectCompile( );
  791.     OpenCompileWindow( TXT_LIBMAKING );
  792.     CreateObjList( );
  793.     chdir( ObjDir );
  794.     strcpy( command , PrgDir );
  795.     strcat( command , "libmake RAM:objlist -mRR -proto -o ram: -l " );
  796.     strcat( command , LibDir );
  797.     MakePath( command );
  798.     strcat( command , ProjectName );
  799.     strcat( command , ".lib" );
  800.     Launch( command , FALSE );
  801.     chdir( StartDir );
  802.     CloseCompileWindow( );
  803. }
  804.  
  805. int ProjectMake( void )
  806. {
  807.     if ( ProjectCompile( ) )
  808.     ProjectLink( );
  809. }
  810.  
  811. int ProjectCodeInfo( void )
  812. {
  813.   struct FileInfoBlock fib;
  814.   char mess[500];
  815.   struct DateTime *dt;
  816.  
  817.     chdir( DestDir );
  818.     if ( GetInfo( &fib , ProjectName ) ) {
  819.     strcpy( mess , "Project Name : " );
  820.     strcat( mess , ProjectName );
  821.     strcat( mess , "\n\nExecutable : " );
  822.     ltoa( &mess[ strlen(mess) ] , fib.fib_Size );
  823.     strcat( mess , "\n\nDate : " );
  824.     if ( dt = GetDate( &fib ) ) {
  825.         strcat( mess , dt->dat_StrDay );
  826.         strcat( mess , " " );
  827.         strcat( mess , dt->dat_StrDate );
  828.         strcat( mess , "\nTime : " );
  829.         strcat( mess , dt->dat_StrTime );
  830.     }
  831.     strcat( mess , "\n\n" );
  832.     Message( ProjectWnd , mess , "Continue" );
  833.     } else
  834.     Message( ProjectWnd , "You must generate it before !" , "Continue" );
  835.     chdir( StartDir );
  836. }
  837.  
  838. int ProjectLaunch( void )
  839. {
  840.   char *command = PathName( DestDir , ProjectName );
  841.  
  842.     Launch( command , TRUE );
  843.     free( command );
  844. }
  845.  
  846. int ProjectLaunchWB( void )
  847. {
  848.  
  849. }
  850.  
  851. /****************************************************************************
  852. ***                                      ***
  853. ***    Actions des messages IDCMP                      ***
  854. ***                                      ***
  855. ****************************************************************************/
  856.  
  857. int ProjectCloseWindow( void )
  858. {
  859.     ProjectQuit( );
  860. }
  861.  
  862. int ProjectNewSize( void )
  863. {
  864.     DettachList( );
  865.  
  866.     CloseProjectWindow( );
  867.     OpenProjectWindow( );
  868.     ChangeProjectName( ProjectPathName );
  869.  
  870.     AttachList( );
  871. }
  872.  
  873. int DirSetCloseWindow( void )
  874. {
  875.     RemoveAssign( );
  876.     MakeAssign( );
  877.     done = TRUE;
  878. }
  879.  
  880. int CompilerOptCloseWindow( void )
  881. {
  882.     done = TRUE;
  883. }
  884.  
  885.  
  886. /****************************************************************************
  887. ***                                      ***
  888. ***    Programme principale comme l'on peut le constater                 ***
  889. ***                                      ***
  890. ****************************************************************************/
  891.  
  892. #define winsignal(win) (1 << win->UserPort->mp_SigBit)
  893.  
  894. int main( int argc , char **argv ) {
  895.   LONG signal;
  896.  
  897.     if ( InitVar( ) ) {
  898.     if ( !argc )
  899.         GetToolTypes( (struct WBStartup *)argv );
  900.     else
  901.         ProgramName = argv[0];
  902.     LoadPrefs( );
  903.     if ( !SetupScreen( ) ) {
  904.         if ( !OpenProjectWindow( ) ) {
  905.         while ( !done ) {
  906.             signal = winsignal(ProjectWnd);
  907.             if ( MessWnd )
  908.             signal |= winsignal(MessWnd);
  909.             signal = Wait( signal );
  910.             if ( signal==winsignal(ProjectWnd) )
  911.             HandleProjectIDCMP( );
  912.             else
  913.             HandleMessIDCMP( );
  914.         }
  915.         MessCloseWindow( );
  916.         CloseProjectWindow( );
  917.         }
  918.         CloseDownScreen( );
  919.     }
  920.     FreeVar( );
  921.     }
  922.     return( 0 );
  923. }
  924.  
  925. int wbmain( struct WBStartup *WB ) {
  926.     main( 0 , (char **)WB );
  927. }
  928.  
  929.