home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP23.EXE / CHP2312.PRG < prev   
Encoding:
Text File  |  1991-04-30  |  4.7 KB  |  149 lines

  1. /*
  2.    Listing 23.12  CDG_EDIT()
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. memvar getlist
  14.  
  15.  
  16. // Pre-processor settings //
  17.  
  18. #define DEF_SIZE 2048
  19. #define LINE_LNG 255
  20. #include "MEMOEDIT.CH"
  21. #include "INKEY.CH"
  22. #include "BOX.CH"
  23. #include "SETCURS.CH"
  24.  
  25. function cdg_edit
  26. LOCAL mx:=Maxrow(),mc:=Maxcol()
  27. LOCAL backscr := savescreen(0,0,mx,mc)
  28. LOCAL msearch:=space(8),mreplace:=space(8)
  29. LOCAL mcount:=1,msave
  30.  
  31. PRIVATE keepgoing := .t.
  32. PRIVATE memo_buff:=space(DEF_SIZE)
  33. PRIVATE me_file := space(12),me_command :=0
  34. PRIVATE me_macros:={space(15),space(15),space(15),space(15)}
  35.  
  36. //  Set the colors and draw the screen  //
  37.  
  38. setcolor('W+/B')
  39. cls
  40. dispbox(01, 00, mx, mc, 2)
  41. @ 02,03 say "FILE:"
  42. @ 02,60 say "Row:      Col:"
  43. @ 03,01 say replicate( chr(196),mc-1)
  44. @ mx-2,01 say "─────────┬─────────┬────────────┬─────────┬──────────────────┬────────────────"
  45. @ mx-1,01 say "  F2-Get │ F3-Save │ F4-Replace │ F5-Date │ F6-Define Macros │ F7-F10 Macros  "
  46. @ mx,  01 say "═════════╧═════════╧════════════╧═════════╧══════════════════╧════════════════"
  47. set color to W/B
  48.  
  49. do while keepgoing
  50.    memo_buff :=memoedit(memo_buff,4,1,mx-3,mc-1,.T.,"ME_UDF",LINE_LNG)
  51.    if !empty(me_command)
  52.       do case
  53.       case me_command = 1
  54.          keepgoing := .F.
  55.          loop
  56.       case me_command = 2        // Get a new file
  57.          memo_buff := memoread(me_file)
  58.       case me_command = 3        // Save existing file
  59.          memowrit(me_file,memo_buff)
  60.       case me_command = 4        // Search/replace a string
  61.          msave := savescreen(2,24,2,79)
  62.          @ 2,60 say space(18)
  63.          @ 2,24 say "SEARCH:"  get msearch
  64.          @ 2,42 say "REPLACE:" get mreplace
  65.          @ 2,62 say "COUNT:"   get mcount   ;
  66.                 pict "99999" valid mcount>=0
  67.          read
  68.          if lastkey() <> K_ESC
  69.             mcount := if(mcount=0,99999,mcount)
  70.             memo_buff := strtran(memo_buff,trim(msearch),;
  71.                          trim(mreplace),1,mcount)
  72.          endif
  73.          restscreen(2,24,2,79,msave)
  74.       endcase
  75.       me_command = 0
  76.    endif
  77. enddo
  78. set key 28 to
  79. restscreen(0,0,mx,mc,backscr)
  80. return NIL
  81.  
  82.  
  83. /****************************************************/
  84. function me_udf(me_mode,me_row,me_col)
  85. LOCAL me_key := lastkey(),me_save
  86. MEMVAR me_macros,me_file,me_command
  87.  
  88. if me_mode = ME_INIT        // Initialization mode
  89.    return 0                 // Tell memoedit to start
  90. elseif me_mode = ME_IDLE    // Idle mode, update row/colum
  91.    @ 02,10 say me_file
  92.    @ 02,65 say me_row    pict "9999"
  93.    @ 02,74 say me_col+1  pict "9999"  // Starts at zero
  94. else
  95.    do case
  96.    case me_key = K_INS     // Insert key
  97.       if readinsert()      // Is insert on?
  98.          setcursor(SC_NORMAL)    // Underline cursor
  99.       else
  100.          setcursor(SC_SPECIAL1)  // Full block cursor
  101.       endif
  102.       return K_INS         // Toggle cursor ON/OFF
  103.    case me_key = K_ESC .or. me_key = K_CTRL_END
  104.       me_command := 1
  105.       return me_key
  106.    case me_key = K_F2
  107.       @ 2,10 get me_file pict "!!!!!!!!!!!!"  ;
  108.              valid file(me_file) .or. lastkey() = K_UP
  109.       read
  110.       if lastkey() <> K_ESC
  111.          me_command :=2
  112.          return 27
  113.       endif
  114.    case me_key = K_F3         // Get a file name to save
  115.       @ 2,10 get me_file pict "!!!!!!!!!!!!" ;
  116.              valid !empty(me_file)
  117.       read
  118.       if lastkey() <> K_ESC
  119.          me_command := 3    // Set command to save contents
  120.          return 23
  121.       endif
  122.    case me_key = K_F4
  123.       me_command :=4        // Set command to search/replace
  124.       return 23             // Save the memo's contents
  125.    case me_key = K_F5
  126.       keyboard dtoc(date()) // Insert a date into the memo
  127.    case me_key = K_F6
  128.       me_save := savescreen(9,29,14,53)
  129.       @ 9,29,14,52 box B_DOUBLE_SINGLE + " "
  130.       @ 10,30 say "F7  -" get me_macros[1]
  131.       @ 11,30 say "F8  -" get me_macros[2]
  132.       @ 12,30 say "F9  -" get me_macros[3]
  133.       @ 13,30 say "F10 -" get me_macros[4]
  134.       read
  135.       restscreen(9,29,14,53,me_save)
  136.    case me_key = K_F7
  137.       keyboard trim(me_macros[1])  // Insert first macro
  138.    case me_key = K_F8
  139.       keyboard trim(me_macros[2])  // Insert second macro
  140.    case me_key = K_F9
  141.       keyboard trim(me_macros[3])  // Insert third macro
  142.    case me_key = K_F10
  143.       keyboard trim(me_macros[4])  // Insert fourth macro
  144.    endcase
  145. endif
  146. return ME_DEFAULT          // Process key's default value
  147.  
  148. // end of file CHP2312.PRG
  149.