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

  1.  
  2. #include <clib/intuition_protos.h>
  3. #include <clib/gadtools_protos.h>
  4. #include <clib/exec_protos.h>
  5.  
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #include "project.h"
  10.  
  11. extern char PubName[];
  12.  
  13. char *ProgramName;
  14.  
  15. char *ProjectPathName;
  16. char *ProjectName;
  17. char *WindowTitle;
  18.  
  19. char *StartDir;
  20. char *PrgDir;
  21.  
  22. /****************************************************************************
  23. ***                                      ***
  24. ***    Fonctions divers                          ***
  25. ***                                      ***
  26. ****************************************************************************/
  27.  
  28. void ReplaceChar( char **dest , char *source )
  29. {
  30.     free( *dest );
  31.     *dest = strdup( source );
  32. }
  33.  
  34. /****************************************************************
  35. ***    Change le nom du projet en cours              ***
  36. ****************************************************************/
  37.  
  38. void ChangeProjectName( char *pathname ) {
  39.   char temp[200];
  40.  
  41.     ReplaceChar( &ProjectPathName , pathname );
  42.     ReplaceChar( &ProjectName , BaseName( pathname ) );
  43.     ProjectName[ strlen(ProjectName) - 4 ] = 0;
  44.     strcpy( temp , "DICE Project Handler : " );
  45.     strcat( temp , BaseName( pathname ) );
  46.     ReplaceChar( &WindowTitle , temp );
  47.     SetWindowTitles( ProjectWnd , WindowTitle , (UBYTE *)-1 );
  48. }
  49.  
  50. /****************************************************************
  51. ***    Change le nom du repertoire de DICE              ***
  52. ****************************************************************/
  53.  
  54. void ChangeDICEDir( char *dir ) {
  55.   char *prgt;
  56.  
  57.     ReplaceChar( &DICEDir , dir );
  58.     prgt = malloc( strlen( DICEDir ) + 10 );
  59.     strcpy( prgt , DICEDir );
  60.     strcat( prgt , "/bin/" );
  61.     ReplaceChar( &PrgDir , prgt );
  62.     free( prgt );
  63. }
  64.  
  65. /****************************************************************
  66. ***  Affiche une requete si un projet existe déjà ( Save as ) ***
  67. ****************************************************************/
  68.  
  69. LONG Overwrite( char *name ) {
  70.   FILE *test;
  71.   char message[200];
  72.  
  73.     if ( test = fopen( name , "r" ) ) {
  74.     fclose( test );
  75.     strcpy( message , "A project named " );
  76.     strcat( message , BaseName( name ) );
  77.     strcat( message , " already exists\nDo you want to overwrite it ?" );
  78.     return( Message( ProjectWnd , message , "Overwrite|Forget" ) );
  79.     }
  80.     return( TRUE );
  81. }
  82.  
  83. /****************************************************************
  84. ***    Lance l'edition d'un module spécifié par son nom      ***
  85. ****************************************************************/
  86.  
  87. void EditModule( char *name ) {
  88.   char *buf;
  89.  
  90.     SetDefaultPubScreen( PubName );
  91.     buf = malloc( strlen( PrgDir ) + strlen( name ) + 20 );
  92.     strcpy( buf , PrgDir );
  93.     strcat( buf , "DME \"" );
  94.     strcat( buf , name );
  95.     strcat( buf , "\"" );
  96.     Launch( buf , TRUE );
  97.     free( buf );
  98. }
  99.  
  100. /****************************************************************
  101. ***    Gestion des fichiers de commentaires              ***
  102. ****************************************************************/
  103.  
  104. char *CommentName( char *module ) {
  105.   char *result;
  106.  
  107.     result = malloc( strlen( module ) + 10 );
  108.     strcpy( result , module );
  109.     strcat( result , ".comment" );
  110.     return( result );
  111. }
  112.  
  113. BOOL IsCommented( char *module ) {
  114.   char *modulec;
  115.   struct FileInfoBlock fib;
  116.   BOOL r=FALSE;
  117.  
  118.     modulec = CommentName( module );
  119.     if ( GetInfo( &fib , modulec ) ) {
  120.     r = TRUE;
  121.     }
  122.     free( modulec );
  123.     return( r );
  124. }
  125.  
  126. /****************************************************************
  127. ***    Affiche une liste ou choisir un élément           ***
  128. ****************************************************************/
  129.  
  130. struct ModuleNode *ChooseInList( char *title , struct List *liste ) {
  131.   BOOL            done=FALSE;
  132.   struct IntuiMessage    *m;
  133.   ULONG         sec=-1,mic;
  134.   int            n;
  135.   struct ModuleNode    *wn=NULL;
  136.  
  137.     if ( !OpenCListeWindow( title ) ) {
  138.     gtag[0].ti_Data = (long)liste;
  139.     GT_SetGadgetAttrsA( CListeGadgets[0] , CListeWnd , NULL , gtag );
  140.     while ( !done ) {
  141.         Wait( 1 << CListeWnd->UserPort->mp_SigBit );
  142.         while( m = GT_GetIMsg( CListeWnd->UserPort )) {
  143.         GT_ReplyIMsg( m );
  144.         switch ( m->Class ) {
  145.           case IDCMP_CLOSEWINDOW:
  146.             done = TRUE;
  147.             break;
  148.           case      IDCMP_GADGETUP:
  149.             n = m->Code;
  150.             wn = liste->lh_Head;
  151.             while( wn->node.ln_Succ && n-- ) {
  152.             wn = wn->node.ln_Succ;
  153.             }
  154.             if ( sec != -1 && DoubleClick( sec , mic , m->Seconds , m->Micros ) )
  155.             done = TRUE;
  156.             else
  157.             wn = NULL;
  158.             sec = m->Seconds;
  159.             mic = m->Micros;
  160.             break;
  161.         }
  162.         }
  163.     }
  164.     CloseCListeWindow( );
  165.     }
  166.     return( wn );
  167. }
  168.  
  169.  
  170.