home *** CD-ROM | disk | FTP | other *** search
-
- #include "cp.h"
-
-
- BOOL AddSet( UBYTE *fName )
- {
- struct Set *NewSet;
- BPTR f;
- struct EasyStruct ES =
- {
- sizeof(struct EasyStruct),
- 0,
- "AddSet()",
- "%s",
- "Exit"
- };
-
-
- f = OpenFile( fName );
-
- if ( f && f != 1 )
- {
- NewSet = (struct Set *)AllocVec( sizeof( struct Set ), MEMF_CLEAR );
-
- if ( NewSet == NULL )
- {
- EasyRequest (NULL,&ES,NULL,"No More RAM");
- Close( f );
- return ( FALSE );
- }
-
- NewSet-> snode.ln_Name = NewSet-> fn;
- NewSet-> snode.ln_Type = NT_DATA;
- NewSet-> snode.ln_Pri = 0;
-
- NewSet-> FirstPoint = File2Set( f , NewSet);
-
- if ( NewSet-> FirstPoint )
- {
- strcpy( NewSet-> fn, FilePart( fName ));
- AddTail( SetList, &NewSet-> snode);
- return ( TRUE );
- }
- else
- {
- FreeVec( NewSet );
- return ( FALSE );
- }
- }
- return ( ( BOOL ) f );
- }
-
- BPTR OpenFile( UBYTE *fName)
- {
- BPTR fi;
- UBYTE str[128];
- WORD res;
-
- struct EasyStruct ES =
- {
- sizeof(struct EasyStruct),
- 0,
- "OpenFile()",
- "%s",
- "Continue | Bail"
- };
-
- fi = Open( fName, MODE_OLDFILE );
- if ( fi == NULL)
- {
- strcpy (str,"Can't Open file\n");
- strcat (str,fName);
- res = EasyRequest (NULL,&ES,NULL,str);
- return( res );
- }
-
- NameFromFH(fi, path, 255);
- return( fi );
- }
-
- struct Point *File2Set( BPTR fi , struct Set *ThisSet)
- {
-
- struct EasyStruct ES =
- {
- sizeof(struct EasyStruct),
- 0,
- "File2Set()",
- "%s",
- "Bye Bye"
- };
-
- char ch;
- char in[256];
- int c = 0;
- int k = 0;
- int n;
- double x, y;
-
- struct Point *ThisPoint;
- struct Point *LastPoint = NULL;
- struct Point *FirstPoint = NULL;
-
-
- while ( FGets( fi, in, 255 ))
- {
- n = sscanf( in, "%lf%c%lf", &x, &ch, &y ); /* ch to swallow csv */
- if ( n == 3 ) k++;
- if ( k >= points ) break;
-
- if ( n == 3 && k % thin == 0 )
- {
-
- ThisPoint = AllocVec( sizeof( struct Point ), NULL );
-
- if( ThisPoint == NULL )
- {
- EasyRequest (NULL,&ES,NULL,"Out of Memory");
- FreePoints( FirstPoint );
- Close ( fi );
- return ( NULL );
- }
-
- if ( c )
- {
- LastPoint-> NextPoint = ThisPoint;
- }
- else
- {
- FirstPoint = ThisPoint;
- }
-
- ThisPoint-> xval = x;
- ThisPoint-> yval = y;
-
- LastPoint = ThisPoint;
-
- if ( c )
- {
- ThisSet-> xmax = max( ThisSet-> xmax, x);
- ThisSet-> xmin = min( ThisSet-> xmin, x);
- ThisSet-> ymax = max( ThisSet-> ymax, y);
- ThisSet-> ymin = min( ThisSet-> ymin, y);
- }
- else
- {
- ThisSet-> xmax = x;
- ThisSet-> xmin = x;
- ThisSet-> ymax = y;
- ThisSet-> ymin = y;
- }
-
- c++;
- ThisPoint-> NextPoint = NULL;
- }
- }
- ThisSet-> npt = c;
- Close ( fi );
- return ( FirstPoint );
- }
-
- void FreePoints( struct Point *First )
- {
- struct Point *Next;
-
- while ( First )
- {
-
- Next = First -> NextPoint;
- FreeVec( First);
- First = Next;
-
- }
-
- }
-
- void FreeAllSets()
- {
- struct Set *node;
- struct Set *Next;
-
- node = (struct Set *)SetList-> lh_Head;
-
- while ( Next = (struct Set *)node-> snode.ln_Succ )
- {
- FreePoints( node -> FirstPoint);
- Remove( (struct Node *)node );
- FreeVec( node );
- node = Next;
- }
- }
-
- BOOL AddNewSet()
- {
- struct FileRequester *fr;
- UBYTE *fpp;
- struct WBArg *frargs;
- BOOL res;
- LONG x;
-
- if ((fr = AllocAslRequest( ASL_FileRequest, TAG_DONE )))
- {
-
- fpp = FilePart( path );
-
- *fpp = '\0';
-
- res = AslRequestTags( fr,
- ASL_Window, PlotWindowWnd,
- ASL_Hail, (ULONG)"Select Multiple Files",
- ASL_Dir, path,
- ASL_FuncFlags, FILF_MULTISELECT,
- TAG_DONE );
-
- if ( res )
- {
- if ( fr-> rf_NumArgs )
- {
- frargs = fr-> rf_ArgList;
-
- for( x = 0; x < fr-> rf_NumArgs; x++)
- {
- strcpy( path, fr-> rf_Dir);
- AddPart( path, frargs[x].wa_Name, 128);
-
- res = AddSet( path );
-
- }
- }
- else if( strlen(fr-> rf_File))
- {
- strcpy( path, fr-> rf_Dir);
- AddPart( path, fr-> rf_File, 128);
-
- res = AddSet( path );
- }
- }
- FreeAslRequest( fr );
- }
- return ( res );
- }
-