[comp.sys.apollo] cut/paste tools for DM and X

valante_g@apollo.HP.COM (Glen E Valante) (08/16/90)

 
Hello,
  
 After a lot of requests for this, here it is.......

--glen

  

How to use dm2x and x2dm cut/paste tools.

Since the dm and X do not share the same cut/paste buffers there has to 
be a mechanism to transfer the needed data between them.  The tools dm2x
and x2dm will transfer the data between the dm pastebuffer in `node_data/
paste_buffers/default.txt to the X buffer 0.

Place x2dm and dm2x in your ~/com, ~/bin or some place where search rules 
apply.

I will use Xterm as an example of an X window.  Note that all X clients do not
perform a cut/paste with the same keys but hopefully they will use the
same cutbuffer.

To cut text in Xterm, press mouse 1 button where you want to start highlighting
text.  Holding the button down, drag the mouse over the area and release
when you have what you want.  The area that will be cut will be highlighted.  

Execute the x2dm utility.

You will then be able to paste the text with the <paste> key into any Dm edit
window.

To cut text from a Dm window, Mark the text you want to transfer, then
press the 
<copy> key.

Execute the dm2x utility.

You will then be able to paste into the Xterm window with just positioning the
Xterm text cursor and pressing the mouse 2 button.
                                                                           
  If you run motif or uwm, you can customize your rc file to exicute
them from a 
roll down menu.

  If you use the Dm as your window manager, you can exicute them with a
dm keydeff.  
The keydeff will look something like this:

             kd f1 cps /com/sh -c '~/com/x2dm' -cps; msg 'x2dm' ke
             kd f2 cps /com/sh -c '~/com/dm2x' -cps; msg 'dm2x' ke


Limitations:   

/sys/node_data/paste_buffers/default.txt has to exist before running for
example x2dm
This can be created by a simple dm cut opperation.

Disclaimer:

Apollo/HP does not know this exists, and they don't want to know. Excuse
any typo's.

Any comments or suggestions or praise should be sent to
valante_g@APOLLO.HP.COM.

ABOUT THE AUTHORS:

This meager tool came about because of the needs of many dm users that
were thrust into the X world.  The thought and technical abilities 
applied to this code are that of Peter Craine and Glen Valante.

ENJOY.........



**************cut here  cut here**************
/*    

dm2x.c

   Copies data from the DM paste buffer to the X-windows
paste buffer # 0
  
*/         

#include <X11/Xlib.h>
#include <strings.h>
#include <stdio.h>                       
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>

#define MAX_BUFFER_SIZE 4096

Display *display;
char * p;  
int i;
char *path = "`node_data/paste_buffers/default.txt";

main()
{
  int fd;
  struct stat Stat_Buf;
  char Buff[MAX_BUFFER_SIZE];
  int Size;

  if ( (display=XOpenDisplay(NULL)) == NULL )
     {
     fprintf(stderr, "basic: can't connect to x server
%s\n",XDisplayName(NULL));
     exit(-1);
     };

  fd = open( path, O_RDONLY );
  if ( fd < 0 )
     {
     perror( "ERROR: problem opening file" );
     exit( 1 );
     };

  i = fstat( fd, &Stat_Buf );
  if ( i < 0 )
     {
     perror( "ERROR: problem reading file" );
     exit( 1 );
     };

  Size = Stat_Buf.st_size;

  if ( Size > MAX_BUFFER_SIZE )
     {
     printf( "DM Paste buffer too large (%d chars).  Only moving %d chars.\n",
                       Stat_Buf.st_size, MAX_BUFFER_SIZE );
     Size = MAX_BUFFER_SIZE;
     };

  i = read( fd, Buff, Size );
  if ( i < Size )
     {
     printf( "OOPS:  Only got %d characters from DM paste buffer\n",i );
     Size = i;
     };

  close( fd );

  XStoreBuffer( display, Buff, Size, 0 );

  p = XFetchBuffer( display, &i, 0 );
    
  XCloseDisplay(display);

}; 

**************cut here  cut here**************
/*    

x2dm.c

   Copies data from X-windows paste buffer # 0 to the DM
paste buffer.
  
*/         


#include <X11/Xlib.h>
#include <strings.h>
#include <stdio.h>                       
#include <sys/file.h>

Display *display;
char * p;  
int i;
char *path = "`node_data/paste_buffers/default.txt";

main()
{
   int fd;
   int l;

   if ( (display=XOpenDisplay(NULL)) == NULL )
     {
     fprintf(stderr, "basic: can't connect to x server
%s\n",XDisplayName(NULL));
     exit(-1);
     };

   p = XFetchBuffer( display, &l, 0 );

   fd = open( path, O_WRONLY|O_TRUNC );
   if ( fd < 0 )
      {
      perror( "ERROR: problem opening file" );
      exit( 1 );
      };
    i = lseek( fd, 0, L_SET );
    if ( i < 0 )
      {
      perror( "ERROR: problem in lseek" );
      exit( 1 );
      };
    i = write( fd, p, l );
    if ( i < 0 )
      {
      perror( "ERROR: problem writing to file" );
      exit( 1 );
      };
    if ( i < l )
      {
      printf( "OOPS:  Only put %d chars in DM buffer\n",i );
      };
    close( fd );

    XCloseDisplay (display);

};
-------------------------------------------------------------------------------
  Glen Valante                     | These are my opinions...
  Apollo / Hewlett-Packard         |    
  North American Customer Support  |
________________________________________________________________________
________