home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / word / text / 019 / util.sl < prev    next >
Text File  |  1993-01-19  |  1KB  |  67 lines

  1. ;;
  2. ;;  utility functions which Must be available (e.g., autoload)
  3. ;;
  4.  
  5. ;;
  6. ;; A function to contat a directory with a filename.  Basically checks
  7. ;;  for the final slash on the dir and adds on if necessary
  8. ;;   
  9.  
  10. (
  11.    [dir file] =file =dir
  12.    [n] dir strlen =n 
  13.    [slash] "_IBMPC"  defined? {"\\"}{"/"} else =slash
  14.    
  15.    {"_VMS" defined? 0 ==}{n} andelse {
  16.        dir n 1 substr slash strcmp {dir slash strcat =dir} if
  17.    } if
  18.    dir file strcat
  19. ) dircat
  20.  
  21.  
  22. ;; Since this version of JED uses Linked-List approach and does not
  23. ;; support regular expressions, it is hard to search for strings at the 
  24. ;; beginning or end of a line.  Here are some functions which do this:
  25.  
  26. (           ;; bol_fsearch  returns 0 if not found
  27.   [s] =s    ;; sample usage:  push_spot "string" bol_fsearch
  28.             ;;                {pop_spot} !if
  29.   {1 down}
  30.   { bol s looking_at {1 return} if }
  31.   while
  32.   0
  33. ) bol_fsearch
  34.  
  35.  
  36. (  [str] =str
  37.    
  38.    {str bsearch}{bolp { 1 return } if } while
  39.    0
  40. ) bol_bsearch
  41.  
  42.  
  43. ;;
  44. ;;  A routine that trims the buffer by:  removing excess whitespace at the
  45. ;;  end of lines and removing excess newlines
  46. ;;
  47.  
  48. (
  49.   push_spot
  50.   bob
  51.   {1} {
  52.     eol trim bol 
  53.     eolp {
  54.       1 down pop
  55.       { {eol trim bol eolp } {eobp 0 ==} andelse } { del } while
  56.     } if
  57.     1 down {break} !if
  58.       } while
  59.   bob eol trim bol eolp {del} if
  60.   pop_spot
  61. ) trim_buffer
  62.       
  63. (
  64.    getbuf_info
  65.    1 xor setbuf_info
  66. ) tog_bufmod
  67.