home *** CD-ROM | disk | FTP | other *** search
- Example code
- ------------
-
- Here is a little bit of code to show how gstream can be used. It should
- be regsistered with as a handler for win_ICONBARLOAD
-
- What it does is when a file is dragged to the app, the function will
- use gsopenxferrecv to open a read stream (thus responding to the
- dataload or datasave message), then open an internal write stream, and
- copy the incoming data into the internal stream.
-
- After closing the internal write stream and the xferrecv stream, it
- opens a xfersend stream (using savebox()) and opens the internal buffer,
- copying the data from the internal buffer to the write stream. I bet
- that's a *lot* simpler than it is using RISC_OSLib's xfersend, xferrecv
- and saveas modules. :-)
-
- static void icon_load_handler(wimp_eventstr *e, void *handle)
- {
- gstream stream,
- internal_buffer;
- int safe,
- type,
- load_succeded=TRUE;
- char name[256]="File";
-
- switch(e->data.msg.hdr.action)
- {
- case wimp_MDATALOAD:
- strcpy(name,e->data.msg.data.dataload.name);
- type=e->data.msg.data.dataload.type;
- break;
- case wimp_MDATASAVE:
- strcpy(name,e->data.msg.data.datasave.leaf);
- type=e->data.msg.data.datasave.type;
- break;
- }
-
- visdelay_begin();
- if (gsopenxferrecv(e,&stream))
- {
- if (gsopeninternalw(&internal_buffer))
- {
- char dummy[256];
- int c;
- while((c=gsread((void *) dummy, 1, 256, &stream))!=0)
- {
- gswrite(dummy,1,c,&internal_buffer);
- if (gserror(&stream) || gserror(&internal_buffer))
- {
- werr(FALSE,"Error in load");
- break;
- }
- }
- gsclose(&internal_buffer);
- if (gserror(&stream) || gserror(&internal_buffer))
- {
- load_succeded=FALSE;
- gsdiscardinternal(&internal_buffer);
- }
- }
- else
- load_succeded=FALSE;
- gsclose(&stream);
- }
- else
- load_succeded=FALSE;
- visdelay_end();
-
- if (load_succeded)
- {
- if (gsopeninternalr(&internal_buffer))
- {
- if (savebox(name,1024,type,&safe,&stream))
- {
- char dummy[256];
- int c;
- visdelay_begin();
- while((c=gsread((void *) dummy, 1, 256, &internal_buffer))!=0)
- {
- gswrite(dummy,1,c,&stream);
- if (gserror(&stream))
- break;
- }
- visdelay_end();
- gsclose(&stream);
- }
- gsclose(&internal_buffer);
- }
- gsdiscardinternal(&internal_buffer);
- }
- }
-