home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / dicepj11.lha / diceproject / winmess.c < prev   
C/C++ Source or Header  |  1993-03-10  |  2KB  |  138 lines

  1.  
  2. #include <intuition/gadgetclass.h>
  3. #include <libraries/gadtools.h>
  4. #include <dos/dos.h>
  5.  
  6. #include <clib/gadtools_protos.h>
  7. #include <clib/exec_protos.h>
  8. #include <clib/alib_protos.h>
  9. #include <clib/dos_protos.h>
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "project.h"
  16.  
  17. extern struct TagItem gtag[];
  18.  
  19. BOOL KeepMessages;
  20.  
  21. struct List *MessList=NULL;
  22.  
  23. struct MessNode {
  24.     struct Node node;
  25.     char *mess;
  26. };
  27.  
  28. void FreeMess( void ) {
  29.   struct MessNode *mn,*on;
  30.  
  31.     if ( MessList ) {
  32.     mn = MessList->lh_Head;
  33.     while( on = mn->node.ln_Succ ) {
  34.         free( mn->mess );
  35.         Remove( (struct Node *)mn );
  36.         free( mn );
  37.         mn = on;
  38.     }
  39.     free( MessList );
  40.     MessList = NULL;
  41.     }
  42. }
  43.  
  44. void NewMess( void ) {
  45.     MessList = malloc( sizeof(struct List) );
  46.     NewList( MessList );
  47. }
  48.  
  49. void AddMess( char *mess ) {
  50.   struct MessNode *mn = malloc( sizeof(struct MessNode) );
  51.  
  52.     mn->mess = strdup( mess );
  53.     mn->node.ln_Name = mn->mess;
  54.     AddTail( MessList , (struct Node *)mn );
  55. }
  56.  
  57. void DettachMess( void ) {
  58.     gtag[0].ti_Data = 0;
  59.     GT_SetGadgetAttrsA( MessGadgets[0] , MessWnd , NULL , gtag );
  60. }
  61.  
  62. void AttachMess( void ) {
  63.     gtag[0].ti_Data = (long)MessList;
  64.     GT_SetGadgetAttrsA( MessGadgets[0] , MessWnd , NULL , gtag );
  65. }
  66.  
  67. BOOL CheckError( char *file ) {
  68.   struct FileInfoBlock fib;
  69.   char temp[200];
  70.   FILE *in;
  71.  
  72.     KeepMessages = TRUE;
  73.     if ( ( GetInfo( &fib , file )) && fib.fib_Size ) {
  74.     if ( !MessWnd )
  75.         OpenMessWindow( );
  76.     DettachMess( );
  77.     if ( !MessList )
  78.         NewMess( );
  79.     in = fopen( file , "r" );
  80.     InputString( temp , 200 , in );
  81.     while( !feof( in ) ) {
  82.         if ( strstr( temp , "Error" ) || strstr( temp , "Fatal" ) )
  83.         KeepMessages = FALSE;
  84.         AddMess( temp );
  85.         InputString( temp , 200 , in );
  86.     }
  87.     fclose( in );
  88.     AttachMess( );
  89.     return( TRUE );
  90.     }
  91.     return( FALSE );
  92. }
  93.  
  94. BOOL ViewErrors( char *file ) {
  95.   char *file2;
  96.  
  97.     if ( !KeepMessages ) {
  98.     if ( MessWnd )
  99.         DettachMess( );
  100.     FreeMess( );
  101.     NewMess( );
  102.     if ( MessWnd )
  103.         AttachMess( );
  104.     KeepMessages = TRUE;
  105.     }
  106.     if ( !CheckError( file ) ) {
  107.     file2 = strdup( file );
  108.     file2[ strlen(file2)-1 ] = 0;
  109.     CheckError( file2 );
  110.     free( file2 );
  111.     }
  112.     if ( KeepMessages )
  113.     return( FALSE );
  114.     return( TRUE );
  115. }
  116.  
  117. int MessListClicked( void )
  118. {
  119. }
  120.  
  121. int MessCloseWindow( void )
  122. {
  123.     if ( MessWnd ) {
  124.     DettachMess( );
  125.     FreeMess( );
  126.     CloseMessWindow( );
  127.     }
  128. }
  129.  
  130. int MessNewSize( void )
  131. {
  132.     DettachMess( );
  133.     CloseMessWindow( );
  134.     OpenMessWindow( );
  135.     AttachMess( );
  136. }
  137.  
  138.