home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / clipboard / clip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  4.3 KB  |  161 lines

  1. ;/* clip.c - Execute me to compile me with Lattice 5.04
  2. LC -b1 -cfistq -v -y -j73 clip.c
  3. LC -b1 -cfistq -v -y -j73 cbio.c
  4. Blink FROM LIB:c.o,clip.o,cbio.o TO clip LIBRARY LIB:LC.lib,LIB:Amiga.lib
  5. quit
  6. */
  7.  
  8. /*
  9.  *  Program name:  clip
  10.  *  Purpose:  Demonstrate the use of the clipboard
  11.  *      This program can be run by itself, or two or more
  12.  *      copies can be run, demonstrating how one program
  13.  *      can send data to another.  If the POST option is used,
  14.  *      two programs must be used together. 
  15.  *
  16.  * Copyright (c) 1990 Commodore-Amiga, Inc.
  17.  *
  18.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  19.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  20.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  21.  * information on the correct usage of the techniques and operating system
  22.  * functions presented in this example.  The source and executable code of
  23.  * this example may only be distributed in free electronic form, via bulletin
  24.  * board or as part of a fully non-commercial and freely redistributable
  25.  * diskette.  Both the source and executable code (including comments) must
  26.  * be included, without modification, in any copy.  This example may not be
  27.  * published in printed form or distributed with any commercial product.
  28.  * However, the programming techniques and support routines set forth in
  29.  * this example may be used in the development of original executable
  30.  * software products for Commodore Amiga computers.
  31.  * All other rights reserved.
  32.  * This example is provided "as-is" and is subject to change; no warranties
  33.  * are made.  All use is at your own risk.  No liability or responsibility
  34.  * is assumed.
  35.  *
  36.  */
  37.  
  38. #include <exec/types.h>
  39. #include <libraries/dos.h>
  40. #include <devices/clipboard.h>
  41.  
  42. #ifdef LATTICE
  43. #include <proto/all.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47. int  CXBRK(void) { return(0); }        /* Disable Lattice CTRL-C handling */
  48. int chkabort(void) { return(0); }    /* really */
  49. #endif
  50.  
  51. extern long CBOpen(long);
  52. extern void CBClose(void);
  53. extern void writeLong(long *);
  54. extern void CBCutS(UBYTE *);
  55. extern long CBPasteS(UBYTE *);
  56. extern long CBPost(void);
  57. extern long CBCurrentReadID(void);
  58. extern long CBCurrentWriteID(void);
  59. extern BOOL CBCheckSatisfy(long *);
  60. extern void CBSatisfyPost(UBYTE *);
  61. extern void CBCut(UBYTE *,long);
  62.  
  63.  
  64. void cleanExit(long);
  65. void readS(UBYTE *);
  66. void print(UBYTE *,long);
  67.  
  68. LONG con;
  69.  
  70. void main(int argc,char **argv)
  71. {
  72.     UBYTE c;
  73.     ULONG postID;
  74.     UBYTE cbuf[80];
  75.     UBYTE buffer[80];
  76.  
  77.     con = Open("RAW:0/25/400/80/CLIP  w=write r=read p=post CTRL-\\=quit",MODE_OLDFILE);
  78.     if( !con || CBOpen(PRIMARY_CLIP))cleanExit(10);
  79.  
  80.     print(cbuf,sprintf(cbuf,"\033[20hclipboard.device is open.\n"));
  81.  
  82.     c = 0;
  83.     postID = 0;
  84.     while (c != '\34')
  85.     {   /* while not EOF */
  86.  
  87.     while((postID) && (!WaitForChar(con, 1000000)))
  88.  
  89.         if (CBCheckSatisfy(&postID))
  90.         {
  91.         if (postID)
  92.         {
  93.             print("Please satisfy request for post:\n",0);
  94.             readS(buffer);
  95.             print(cbuf,
  96.             (sprintf(cbuf,"\nsatisfying with \"%s\"\n", buffer)));
  97.             CBSatisfyPost(buffer);
  98.             postID = 0;
  99.         }
  100.         }
  101.     Read(con, &c, 1);
  102.     switch ((int)c)
  103.     {
  104.         case 'w':
  105.         print("Enter cut data\n",0);
  106.         readS(buffer);
  107.         CBCutS(buffer);
  108.         print(cbuf,
  109.             (sprintf(cbuf,"\n\"%s\" sent to clipboard\n",buffer)));
  110.         break;
  111.         case 'r':
  112.         CBPasteS(buffer);
  113.         print(cbuf,(sprintf(cbuf,"paste is \"%s\"\n",buffer)));
  114.  
  115.         break;
  116.         case 'p':   /* This function will wait for another program */
  117.             /* to request data from the clipboard. */
  118.             /* Running two copies of this program is the */
  119.             /* easiest way to do this. */
  120.             print("Posting, waiting for data request\n",0);
  121.         postID = CBPost();
  122.         break;
  123.         default:;
  124.     }
  125.     }
  126.     print("Exiting...\n",0);
  127.     cleanExit(0);
  128. }
  129.  
  130. void cleanExit(error)
  131. long error;
  132. {
  133.     CBClose();
  134.     Close(con);
  135.     exit(error);    
  136. }
  137.  
  138. void readS(buf)
  139. UBYTE *buf;
  140. {
  141. UBYTE c;
  142. long count=0;
  143.  
  144.     while (Read(con, &c, 1), ((c != '\34') && (c != '\r')))
  145.     {
  146.     *buf++ = c;
  147.     Write(con,&c,1);
  148.     if(++count > 79)return;
  149.     }
  150.     *buf = '\0';
  151. }
  152.  
  153. void print(string,length)
  154. UBYTE *string;
  155. long length;
  156. {
  157. if(!length) length=strlen(string);
  158. Write(con,string,length);
  159. }
  160.  
  161.