home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 23.12 CDG_EDIT()
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- memvar getlist
-
-
- // Pre-processor settings //
-
- #define DEF_SIZE 2048
- #define LINE_LNG 255
- #include "MEMOEDIT.CH"
- #include "INKEY.CH"
- #include "BOX.CH"
- #include "SETCURS.CH"
-
- function cdg_edit
- LOCAL mx:=Maxrow(),mc:=Maxcol()
- LOCAL backscr := savescreen(0,0,mx,mc)
- LOCAL msearch:=space(8),mreplace:=space(8)
- LOCAL mcount:=1,msave
-
- PRIVATE keepgoing := .t.
- PRIVATE memo_buff:=space(DEF_SIZE)
- PRIVATE me_file := space(12),me_command :=0
- PRIVATE me_macros:={space(15),space(15),space(15),space(15)}
-
- // Set the colors and draw the screen //
-
- setcolor('W+/B')
- cls
- dispbox(01, 00, mx, mc, 2)
- @ 02,03 say "FILE:"
- @ 02,60 say "Row: Col:"
- @ 03,01 say replicate( chr(196),mc-1)
- @ mx-2,01 say "─────────┬─────────┬────────────┬─────────┬──────────────────┬────────────────"
- @ mx-1,01 say " F2-Get │ F3-Save │ F4-Replace │ F5-Date │ F6-Define Macros │ F7-F10 Macros "
- @ mx, 01 say "═════════╧═════════╧════════════╧═════════╧══════════════════╧════════════════"
- set color to W/B
-
- do while keepgoing
- memo_buff :=memoedit(memo_buff,4,1,mx-3,mc-1,.T.,"ME_UDF",LINE_LNG)
- if !empty(me_command)
- do case
- case me_command = 1
- keepgoing := .F.
- loop
- case me_command = 2 // Get a new file
- memo_buff := memoread(me_file)
- case me_command = 3 // Save existing file
- memowrit(me_file,memo_buff)
- case me_command = 4 // Search/replace a string
- msave := savescreen(2,24,2,79)
- @ 2,60 say space(18)
- @ 2,24 say "SEARCH:" get msearch
- @ 2,42 say "REPLACE:" get mreplace
- @ 2,62 say "COUNT:" get mcount ;
- pict "99999" valid mcount>=0
- read
- if lastkey() <> K_ESC
- mcount := if(mcount=0,99999,mcount)
- memo_buff := strtran(memo_buff,trim(msearch),;
- trim(mreplace),1,mcount)
- endif
- restscreen(2,24,2,79,msave)
- endcase
- me_command = 0
- endif
- enddo
- set key 28 to
- restscreen(0,0,mx,mc,backscr)
- return NIL
-
-
- /****************************************************/
- function me_udf(me_mode,me_row,me_col)
- LOCAL me_key := lastkey(),me_save
- MEMVAR me_macros,me_file,me_command
-
- if me_mode = ME_INIT // Initialization mode
- return 0 // Tell memoedit to start
- elseif me_mode = ME_IDLE // Idle mode, update row/colum
- @ 02,10 say me_file
- @ 02,65 say me_row pict "9999"
- @ 02,74 say me_col+1 pict "9999" // Starts at zero
- else
- do case
- case me_key = K_INS // Insert key
- if readinsert() // Is insert on?
- setcursor(SC_NORMAL) // Underline cursor
- else
- setcursor(SC_SPECIAL1) // Full block cursor
- endif
- return K_INS // Toggle cursor ON/OFF
- case me_key = K_ESC .or. me_key = K_CTRL_END
- me_command := 1
- return me_key
- case me_key = K_F2
- @ 2,10 get me_file pict "!!!!!!!!!!!!" ;
- valid file(me_file) .or. lastkey() = K_UP
- read
- if lastkey() <> K_ESC
- me_command :=2
- return 27
- endif
- case me_key = K_F3 // Get a file name to save
- @ 2,10 get me_file pict "!!!!!!!!!!!!" ;
- valid !empty(me_file)
- read
- if lastkey() <> K_ESC
- me_command := 3 // Set command to save contents
- return 23
- endif
- case me_key = K_F4
- me_command :=4 // Set command to search/replace
- return 23 // Save the memo's contents
- case me_key = K_F5
- keyboard dtoc(date()) // Insert a date into the memo
- case me_key = K_F6
- me_save := savescreen(9,29,14,53)
- @ 9,29,14,52 box B_DOUBLE_SINGLE + " "
- @ 10,30 say "F7 -" get me_macros[1]
- @ 11,30 say "F8 -" get me_macros[2]
- @ 12,30 say "F9 -" get me_macros[3]
- @ 13,30 say "F10 -" get me_macros[4]
- read
- restscreen(9,29,14,53,me_save)
- case me_key = K_F7
- keyboard trim(me_macros[1]) // Insert first macro
- case me_key = K_F8
- keyboard trim(me_macros[2]) // Insert second macro
- case me_key = K_F9
- keyboard trim(me_macros[3]) // Insert third macro
- case me_key = K_F10
- keyboard trim(me_macros[4]) // Insert fourth macro
- endcase
- endif
- return ME_DEFAULT // Process key's default value
-
- // end of file CHP2312.PRG
-