home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / rot13.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  1.0 KB  |  67 lines

  1. %%
  2. %%  rot13.sl---- rotates text by 13 characters
  3. %%
  4. define do_rot13 (ch)
  5. {
  6.    variable delta = 0;
  7.    if (ch > 'Z') 
  8.      {
  9.     delta = 32;
  10.     ch -= 32;
  11.      }
  12.    
  13.    if ((ch < 'A') or (ch > 'Z'))
  14.      {
  15.     go_right(1);
  16.     return;
  17.      }
  18.    
  19.    if (ch > 'M') ch -= 13;
  20.    else ch += 13;
  21.    del ();
  22.    insert_char (ch + delta);
  23. }
  24.  
  25. . ( 
  26. .   [n r1 c1 c2]
  27. .   markp { "Set mark!" error } !if
  28.   
  29. .   push_spot
  30.   
  31. .   what_column =c2
  32. .   whatline "exchange" call whatline =r1
  33. .   r1 - =n  %number of lines - 1
  34. .   what_column =c1
  35.   
  36. .   {n 0 ==} {c1 c2 ==} andelse {"bad region!" error} if
  37.   
  38. .   n 0 < { n chs =n 
  39. .           r1 n - =r1
  40. .       c1 c2 =c1 =c2
  41. .     } if
  42.  
  43. .   n 0 == { c1 c2 > { c1 c2 =c1 =c2  "hmm" message } if } if
  44.   
  45. .   r1 goto_line c1 goto_column
  46.  
  47. .   n { 
  48. .        {eolp 0 ==}
  49. .          {
  50. .         what_char do_rot13
  51. .      } while
  52. .        1 down pop bol
  53. .     } loop
  54.     
  55.   %% take care of final line
  56.     
  57. .     {what_column c2 <}
  58. .      {
  59. .        what_char do_rot13
  60. .      } while
  61. .   0 pop_mark   
  62. .   pop_spot
  63. . ) rot13
  64.  
  65.  
  66.   
  67.