home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / wp / casechng.zip / CASECHNG.PF2
Text File  |  1990-01-31  |  5KB  |  175 lines

  1. '    CASECHNG.PF2 :  Change Case For Block Of Text
  2. '
  3. '    Currently processes one character at a time using WPGET to get
  4. '    character and KEYS LOOK to put case-changed character.  WPGET always
  5. '    returns special characters currently (an error reported to Informix)
  6. '    and WPPUT always inserts text - can't currently overwrite existing
  7. '    text (this shortcoming has also been reported to Informix).  I'm
  8. '    sure the process can be improved once the two problems are corrected.
  9. '
  10. '    Jon Haney 12/21/89
  11.  
  12.  
  13. global move_cursor(),change_case()
  14. public sec_1,pag_1,lin_1,col_1 'Starting section, page, line, column
  15. public sec_2,pag_2,lin_2,col_2 'Ending section, page, line, column
  16. public cur_1,cur1_lin,cur1_col 'Starting cursor position for current screen
  17. public cur_2,cur2_lin,cur2_col 'Ending   cursor position for current screen
  18. public tx                      'Current text char
  19. public in_char                 'Input character from user
  20. public ins_mode                'Insert mode (0=off,1=on)
  21. public change_up               '<U> = change to upper case, <L> = lower
  22.  
  23. smartpeek $_cpos cur_1
  24. cur1_lin = int(cur_1/256)
  25. cur1_col = mod(cur_1,256)
  26. locate cur1_lin cur1_col 2
  27. in_char = 0
  28. while in_char <> "Enter"
  29.   screen clear box 22 1 23 80 15 0 no-border
  30.   screen print 22 1 15 0 "Position cursor on FIRST character of block and press Enter"
  31.   key name inchar in_char
  32.   if in_char <> "Enter"
  33.     move_cursor()             'Move cursor if necessary
  34.   end if
  35. end while
  36. sec_1 = wpinfo(1)
  37. pag_1 = wpinfo(2)
  38. lin_1 = wpinfo(3)
  39. col_1 = wpinfo(4)
  40.  
  41. smartpeek $_cpos cur_2
  42. cur2_lin = int(cur_2/256)
  43. cur2_col = mod(cur_2,256)
  44. locate cur2_lin cur2_col 2
  45. in_char = 0
  46. while in_char <> "Enter"
  47.   screen clear box 22 1 23 80 15 0 no-border
  48.   screen print 22 1 15 0 "Position cursor on LAST character of block and press Enter"
  49.   key name inchar in_char
  50.   if in_char <> "Enter"
  51.     move_cursor()
  52.   end if
  53. end while
  54.  
  55. change_up = 0
  56. while NOT(change_up=="U" or change_up=="L")
  57.   screen clear box 22 1 23 80 15 0 no-border
  58.   screen print 22 1 15 0 "All <U>pper case or all <L>ower case ?"
  59.   key name inchar change_up
  60. end while
  61.  
  62. repaint off
  63.  
  64. sec_2 = wpinfo(1)
  65. pag_2 = wpinfo(2)
  66. lin_2 = wpinfo(3)
  67. col_2 = wpinfo(4)
  68.  
  69. evaluate("document goto location \
  70.           s"|str(sec_1)|"p"|str(pag_1)|"l"|str(lin_1)|"c"|str(col_1))
  71.  
  72. smartpeek $_ins ins_mode     'save current insert_mode status
  73. smartpoke $_ins false        'set insert_mode off
  74.  
  75. while ins_mode <> 2          'ins_mode will always not equal 2
  76.   if (sec_1=sec_2 and pag_1=pag_2 and lin_1=lin_2 and col_1=col_2)
  77.     change_case()
  78.     exit while               'exit while loop
  79.   end if
  80.   change_case()
  81.   sec_1 = wpinfo(1)
  82.   pag_1 = wpinfo(2)
  83.   lin_1 = wpinfo(3)
  84.   col_1 = wpinfo(4)
  85. end while
  86.  
  87. smartpoke $_ins ins_mode     'restore initial insert_mode
  88. repaint
  89.  
  90. end
  91.  
  92. function move_cursor()       'allows you to move cursor to mark block
  93. case                         '   (NOTE: I don't highlight the block
  94.   when (in_char = "Right")   '          with current implementation)
  95.     suspend
  96.     keys Right,F8
  97.   when (in_char = "Left")
  98.     suspend
  99.     keys Left,F8
  100.   when (in_char = "Up")
  101.     suspend
  102.     keys Up,F8
  103.   when (in_char = "Down")
  104.     suspend
  105.     keys Down,F8
  106.   when (in_char = "PgUp")
  107.     suspend
  108.     keys PgUp,F8
  109.   when (in_char = "PgDn")
  110.     suspend
  111.     keys PgDn,F8
  112.   when (in_char = "^Right")
  113.     suspend
  114.     keys ^Right,F8
  115.   when (in_char = "^Left")
  116.     suspend
  117.     keys ^Left,F8
  118.   when (in_char = "Home")
  119.     suspend
  120.     keys Home,F8
  121.   when (in_char = "End")
  122.     suspend
  123.     keys End,F8
  124.   when (in_char = "^Home")
  125.     suspend
  126.     keys ^Home,F8
  127.   when (in_char = "^End")
  128.     suspend
  129.     keys ^End,F8
  130. end case
  131. return
  132. end function
  133.  
  134. function change_case()
  135. tx = left(wpget(1,0),2)    'get character of text, or special char(s)
  136.                            '"%" returns more than "%%" so limit to 2
  137. case
  138.   when (tx=" ")            'skip over special characters
  139.     suspend                '  (AND UNDOCUMENTED characters that
  140.     keys Right,F8          '   cause the KEYS LOOK command to error)
  141.   when (tx="""")
  142.     suspend
  143.     keys Right,F8
  144.   when (tx="%t")
  145.     suspend
  146.     keys Tab,F8
  147.   when (tx="%p")
  148.     suspend
  149.     keys Right,F8
  150.   when (tx="%-")
  151.     suspend
  152.     keys Right,F8
  153.   when (tx="%%")
  154.     suspend
  155.     keys "%",F8
  156.   when (tx=",")
  157.     suspend
  158.     keys Right,F8
  159.   when (tx="'")
  160.     suspend
  161.     keys Right,F8
  162.   otherwise                'change case of text characters
  163.     if change_up=="U"
  164.       tx = upper(tx)
  165.     else
  166.       tx = lower(tx)
  167.     end if
  168.     key define "#1000" tx
  169.     suspend
  170.     keys look,#1000,F8     'overwrite existing text character
  171.     key remove "#1000"     '  with case-changed text character
  172. end case
  173. return
  174. end
  175.