home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / cca_110.zip / PMCLIP.CB < prev    next >
Text File  |  1997-09-20  |  6KB  |  171 lines

  1. /*
  2. **    BRIEF version 3.x -- Basic Reconfigurable Interactive Editing Facility
  3. **
  4. **    PmClip.cb             1.24   97/09/14
  5. **      modified by Don Hawkinson
  6. **      for use with my command line clipboard access programs
  7. **      my programs return 0 for success 1 for failure
  8. **      
  9. **      My keyboard is not a 101 key keyboard, so the
  10. **      original key assignments did not work.  I changed
  11. **      the key assignments to alt+> for paste from clipboard
  12. **      and alt+< to copy to clipboard.  I did not make an assignment
  13. **      for cut to clipboard.  
  14. **
  15. **
  16. **    PmClip.cb             1.22        94/08/23
  17. **
  18. **    By Rafal Kopicki, August 23, 1993.
  19. **    Owned by John N. Currier.
  20. **
  21. **    ===  A BRIEF Users Underground project  ===
  22. **
  23. **    pmclip.cb : The macro package enables you to copy/cut to
  24. **                and paste from the OS/2 PM Clipboard.
  25. **
  26. **    Use       : load_macro( "pmclip" );
  27. **
  28. **    Keys      : set #1 - if the ALT compiler directive disabled
  29. **                   <Ctrl-Keypad-Plus>   - copy to the OS/2 PM Clipboard
  30. **                   <Ctrl-Keypad-Minus>  - cut to the OS/2 PM Clipboard
  31. **                   <Ctrl-Ins>           - paste from the OS/2 PM Clipboard
  32. **                set #2 - if the ALT compiler directive enabled
  33. **                   <Alt-Keypad-Plus>    - copy to the OS/2 PM Clipboard
  34. **                   <Alt-Keypad-Minus>   - cut to the OS/2 PM Clipboard
  35. **                   <Alt-Ins>            - paste from the OS/2 PM Clipboard
  36. **
  37. **    Notice    : Based on Jim Fowler's CLIPAPI PACKAGE Version 1.1 (IBM IUO)
  38. **                (available on OS2TOOLS).
  39. **                Requires CLIPAPI.DLL and CLIPAPI.EXE.
  40. **
  41. **                * * *   IBM Internal Use Only   * * *
  42. */
  43.  
  44. #define  BRIEF2PM_CMD   "toclip"
  45. #define  PM2BRIEF_CMD   "fclip2"
  46.  
  47. #define  NULL_STRING    ""
  48.  
  49. #define  SYSTEM         1
  50.  
  51.  
  52. void  Brief2Pm(int);
  53. void  Pm2Brief(void);
  54. int   DosRc(int);
  55.  
  56.  
  57. global   string   pmclip_file;
  58.  
  59.  
  60. void _init(void)
  61. {
  62. /*
  63. #ifdef   ALT
  64.    assign_to_key( "<Alt-Keypad-Plus>",    "Brief2Pm 0" );   // Copy
  65.    assign_to_key( "<Alt-Keypad-Minus>",   "Brief2Pm 1" );   // Cut
  66.    assign_to_key( "<Alt-Ins>",            "Pm2Brief"   );   // Paste
  67. #else
  68.    assign_to_key( "<Ctrl-Keypad-Plus>",   "Brief2Pm 0" );   // Copy
  69.    assign_to_key( "<Ctrl-Keypad-Minus>",  "Brief2Pm 1" );   // Cut
  70.    assign_to_key( "<Ctrl-Ins>",           "Pm2Brief"   );   // Paste
  71. #endif
  72. */
  73.    assign_to_key( "#13056",    "Brief2Pm 0" );   // Copy
  74.    assign_to_key( "#13312",    "Pm2Brief"   );   // Paste
  75.  
  76.    // Search env vars for the temp directory : BTMP, TEMP, TMP.
  77.    if ((pmclip_file = inq_environment("BTMP")) == NULL_STRING)
  78.       if ((pmclip_file = inq_environment("TMP")) == NULL_STRING)
  79.          pmclip_file = inq_environment("TEMP");
  80.  
  81.    pmclip_file += "\\PMCLIP.TMP";
  82. }
  83.  
  84.  
  85. // *------------------------------  Brief2Pm  -------------------------------*
  86. void Brief2Pm(int Cut)
  87. {
  88.    int      BufferId, MsgLevel, PmClipId, NewLine;
  89.    string   DosCmdString;
  90.  
  91.    set_calling_name(NULL_STRING);      // Fix the copy/cut column bug
  92.  
  93.    if ((Cut ? cut() : copy()))         // Do the copy/cut
  94.    {
  95.       message((Cut ? "Cutting" : "Copying") + " to PM Clipboard ...");
  96.  
  97.       MsgLevel = set_msg_level(3);     // Suppress messages
  98.       set_calling_name("_");           //  ... required !!!
  99.       set_scrap_info(1);
  100.       inq_scrap(NewLine);              // NewLine is !0 if last \n is
  101.                                        // considered part of the scrap
  102.  
  103.       PmClipId = create_buffer("PMClip", pmclip_file, SYSTEM);
  104.       BufferId = set_buffer(PmClipId);
  105.  
  106.       paste();                         // Paste the Scrap contents
  107.  
  108.       write_buffer();                  // Put the Scrap into a temp file
  109.  
  110.       sprintf(DosCmdString, "%s <%s >&nul",
  111.                BRIEF2PM_CMD,  pmclip_file);
  112.  
  113.       set_msg_level(MsgLevel);
  114.  
  115.       if (DosRc(dos(DosCmdString, 0)) == 0)
  116.          message("Block " + (Cut ? "cut" : "copied") + " to Clipboard.");
  117.       else
  118.          error((Cut ? "Cut" : "Copy") + " to Clipboard failed.");
  119.  
  120.       set_buffer(BufferId);            // Switch back to the initial buffer
  121.  
  122.       delete_buffer(PmClipId);         // Get rid of the temp buffer & file
  123.       del(pmclip_file);                // The buffer then the file !!!
  124.    }
  125. }
  126.  
  127. // *------------------------------  Pm2Brief  -------------------------------*
  128. void Pm2Brief(void)
  129. {
  130.    int      MarkType, BufferId, PmClipId;
  131.    string   DosCmdString;
  132.  
  133.    message("Pasting from PM Clipboard ...");
  134.  
  135.    // Dump the PM Clipboard to a temp file
  136.    sprintf(DosCmdString, "%s >&%s", PM2BRIEF_CMD, pmclip_file);
  137.  
  138.    if ((DosRc(MarkType = dos(DosCmdString, 0)) == 0)
  139.        && (PmClipId = create_buffer("PMClip", pmclip_file, SYSTEM)))
  140.  
  141.    {
  142.       BufferId = set_buffer(PmClipId);
  143.  
  144.       drop_anchor(1);
  145.       end_of_buffer();
  146.       prev_char();
  147.  
  148.       copy();                          // Fill in the Scrap
  149.  
  150.       set_buffer(BufferId);            // Switch back to the initial buffer
  151.  
  152.       delete_buffer(PmClipId);         // Get rid of the temp buffer & file
  153.       del(pmclip_file);                // The buffer then the file !!!
  154.  
  155.       set_calling_name(NULL_STRING);
  156.  
  157.       paste();                         // Paste the contents into the buffer
  158.  
  159.       message("Clipboard copied to Scrap.");
  160.    }
  161.    else
  162.       error("Paste from Clipboard failed.");
  163. }
  164.  
  165. // *-------------------------------  DosRc  --------------------------------*
  166. int DosRc(int rc)    // Convert DOS return code (byte) to int
  167. {               
  168.    return((rc & 128) ? (rc | (-128)) : rc);
  169. }
  170.  
  171.