home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / spike.zip / SPIKE.C < prev    next >
C/C++ Source or Header  |  1996-01-07  |  2KB  |  73 lines

  1. /*  Spike.c  */
  2.  
  3. /*  We need to include the presentation manager prototypes  */
  4. #define INCL_PM
  5.  
  6. /*  Include os2 prototypes  */
  7. #include <os2.h>
  8.  
  9. /*  Everything includes standard stuff  */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12.  
  13. /*  We need memory allocation and stirng prototypes  */
  14. #include <malloc.h>
  15. #include <string.h>
  16.  
  17. int main(int argc, char **argv)
  18. {
  19.     HAB hab;
  20.     HMQ hmq;
  21.     char SpikeFile[CCHMAXPATH];
  22.  
  23.     /*  Set up a default filename in case none was passed  */
  24.     strcpy(SpikeFile,"SpikeFile");
  25.     if(argc > 1) {
  26.         /*  if we got a filename as a command parameter, use it instead  */
  27.         strcpy(SpikeFile,argv[1]);
  28.     }
  29.     /*  All pm programs need an anchor block  */
  30.     hab=WinInitialize(0);
  31.     if(hab != 0) {
  32.         /*  A pm program needs a message que, even if it's not gonna be used */
  33.         hmq=WinCreateMsgQueue(hab,0);
  34.         if(hmq != 0) {
  35.             /*  Open the clipboard  */
  36.             if(WinOpenClipbrd(hab)) {
  37.                 PSZ Handle;
  38.                 /*  Get a pointer to the plain text in the clipboard  */
  39.                 Handle=(PSZ)WinQueryClipbrdData(hab,CF_TEXT);
  40.                 if(Handle != NULL) {
  41.                     PSZ ThisText;
  42.                     FILE *f;
  43.                     /*  We got some text ok, so copy it into local storage  */
  44.                     ThisText=malloc(strlen(Handle)+2);
  45.                     strcpy(ThisText,Handle);
  46.                     /*  Open the file in append mode */
  47.                     f=fopen(SpikeFile,"ab");
  48.                     if(f != NULL) {
  49.                         /*  Write out a separator  */
  50.                         fprintf(f,"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n");
  51.                         /*  Now write out the stuff that came from the clipboard  */
  52.                         fwrite(ThisText,1,strlen(ThisText),f);
  53.                         /*  and finally we close the file  */
  54.                         fclose(f);
  55.                     }
  56.                     /*  free the memory we allocated  */
  57.                     free(ThisText);
  58.                 }
  59.                 /*  Close the clipboard  */
  60.                 WinCloseClipbrd(hab);
  61.             }
  62.             /*  Destroy the message que we never used  */
  63.             WinDestroyMsgQueue(hmq);
  64.         }
  65.         /*  Clean up the pm instance  */
  66.         WinTerminate(hab);
  67.         /*  Return success  */
  68.         return 0;
  69.     }
  70.     /*  Return failure  */
  71.     return 1;
  72. }
  73.