home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / CLPPASTE.ZIP / CLP2FILE.C < prev    next >
Text File  |  1991-02-06  |  2KB  |  66 lines

  1. /*
  2.  *   CLP2FILE  take text from clipboard and put into a file
  3.  */
  4. #define INCL_WIN
  5. #define INCL_GPI
  6. #define INCL_DOS
  7. #define INCL_DOSSESMGR
  8. #define NUL '\0'
  9.  
  10. #include <os2.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15.  
  16.  
  17. cdecl main( VOID )
  18. {
  19.   HAB         hab;                        /* handle to anchor block   */
  20.   HMQ         hmq;                        /* handle to message queue  */
  21.   SEL         selClipText;
  22.   CHAR        *pchText;
  23.   PCHAR       pchClipText=NULL;
  24.   USHORT      usLen,usIndex,usfmtInfo;
  25.   SHORT       exitcode;
  26.   FILE        *fp;
  27.  
  28.   /* initialize thread & create message queue */
  29.   hab = WinInitialize( 0 );
  30.   hmq = WinCreateMsgQueue( hab, 0 );
  31.   if (WinOpenClipbrd(hab))
  32.  
  33.      {
  34.          WinQueryClipbrdFmtInfo(hab,CF_TEXT,(PUSHORT)&usfmtInfo);
  35.          selClipText = (SEL)WinQueryClipbrdData(hab,CF_TEXT);
  36.          if (selClipText)
  37.           {
  38.            pchClipText = MAKEP(selClipText,0);
  39. //         usLen = strlen(pchClipText);
  40.            for(usLen = 0;pchClipText[usLen];usLen++);
  41.            pchText = malloc (usLen +1);
  42.            for(usIndex = 0;usIndex < usLen +1;usIndex++)
  43.              {
  44.               pchText[usIndex] = pchClipText[usIndex];
  45.              }
  46.            fp=fopen("clip.out","w+");
  47.            fputs(pchText,fp);
  48.            fclose(fp);
  49.            free(pchText);
  50.            exitcode=0;
  51.           // exit with a 0 if all ok
  52.           }
  53.          else
  54.           // exit with a 2 if clipboard  contains other than text data
  55.           exitcode=2;
  56.      }
  57.      else
  58.          // exit with a 3 if cannot open clipboard
  59.          exitcode=3;
  60.  
  61.     WinCloseClipbrd(hab);
  62.     WinDestroyMsgQueue(hmq);
  63.  
  64.  return(exitcode);
  65. }
  66.