home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / UNIXEDIT.PEL < prev    next >
Text File  |  1995-03-27  |  5KB  |  132 lines

  1. # $Header:   P:\source\wmacros\unixedit.pev   1.1   27 Mar 1995 09:41:38   NOBLE  $
  2. ## $Tabs:4 7$
  3.  
  4. ##############################################################################
  5. #
  6. #                 Compuware Corporation
  7. #              31440 Northwestern Highway
  8. #           Farmington Hills, Michigan 48334-2564
  9. #
  10. #   This source code listing contains information that is
  11. #   proprietary to Compuware Corporation and may not be copied
  12. #   duplicated, translated, transmitted, stored, retrieved
  13. #   or in any manner or by any method conveyed or disclosed
  14. #   to a third party or parties without express written
  15. #   permission from Compuware Corporation.
  16. #
  17. #  
  18. ##############################################################################
  19.  
  20.  
  21. #### $Workfile:   unixedit.pel  $: Support for UNIX newline files
  22.  
  23. #############
  24. #
  25. #  This file contains functions to allow the editing of files with Unix style
  26. #  end of line (EOL) characters, and the conversion of buffers between DOS and
  27. #  Unix EOL strings.
  28. #
  29. #  The function 'edit_unix_file_key()' can be assigned to a key and is used to
  30. #  edit a single Unix file when the editor is in the default DOS mode.
  31. #  If you have many Unix files to edit, you can change the default mode to Unix
  32. #  with the 'toggle_unix()' function.  This will switch the editor between DOS
  33. #  and Unix modes so that all subsequent file opens will use the proper EOL string.
  34. #
  35. #  The function 'toggle_buffer_eol()' will convert the current buffer from DOS to
  36. #  Unix, or vice versa.  An optional parameter of TRUE will always convert to Unix,
  37. #  and FALSE will always convert to DOS.  The default editor mode is unchanged.
  38. #
  39. #  Finally, the functions 'unix_edit()' and 'dos_edit()' switch the editor to
  40. #  Unix or DOS mode and convert the current buffer if the optional parameter is TRUE.
  41. #
  42. #############
  43.  
  44. # edits a single file with UNIX style end of line characters
  45. global function edit_unix_file_key(name)
  46. {
  47.    default_buffer_eol_string="\n"
  48.  
  49.    # and then reopen it to see the change.
  50.    create_buf_and_win_key(name)
  51.  
  52.    default_buffer_eol_string="\r\n"
  53. }
  54.  
  55. # Toggles between unix and dos newline modes.  All new files are
  56. # loaded with the new mode.
  57. global function toggle_unix(on) 
  58. {
  59.    local current_mode = (default_buffer_eol_string == "\n")
  60.    
  61.    if( argcount() < 1 )
  62.       on = !current_mode
  63.    else
  64.       on = on+0   # make sure that 'on' is an integer
  65.  
  66.    if ( on && !current_mode)
  67.       unix_edit(FALSE)    # switch to unix mode w/o changing current buffer
  68.    else if (!on  && current_mode)
  69.       dos_edit(FALSE)     # switch to dos mode w/o changing current buffer
  70.    else
  71.       message("File mode unchanged at %s", current_mode ? "Unix" : "DOS")
  72. }
  73.  
  74. # Change the editor to Unix file mode and optionally convert the current
  75. # buffer to Unix style EOL character.
  76. global function unix_edit(convertCurrent) 
  77. {
  78.    default_buffer_eol_string="\n"
  79.  
  80.    if (convertCurrent)
  81.       toggle_buffer_eol(TRUE)
  82.       
  83.    message("Edit Mode = Unix");
  84.  
  85.  
  86. # Change the editor to DOS file mode and optionally convert the current
  87. # buffer to DOS style EOL character.
  88. global function dos_edit(convertCurrent) 
  89. {
  90.    default_buffer_eol_string="\r\n"
  91.  
  92.    if (convertCurrent)
  93.       toggle_buffer_eol(FALSE)
  94.    
  95.    message("Edit Mode = DOS");
  96.  
  97.  
  98. # convert the current buffer from DOS to Unix, or Unix to DOS style EOL character.
  99. global function toggle_buffer_eol(unix) 
  100. {
  101.    local name     # filename of current buffer
  102.    local old_create_buf = create_new_bufwin
  103.    local old_default_eol_str = default_buffer_eol_string
  104.    
  105.    if (!and(buffer_flags, BUFFER_SYSTEM) &&
  106.        !and(buffer_flags, BUFFER_SCRATCH))
  107.    {
  108.       if( argcount() < 1 )
  109.          unix = (buffer_eol_string != "\n")
  110.       else
  111.          unix = unix+0  # make sure that 'on' is an integer
  112.    
  113.       if (unix)
  114.          default_buffer_eol_string = "\n"
  115.       else
  116.          default_buffer_eol_string = "\r\n"
  117.       
  118.       name = buffer_filename
  119.       create_new_bufwin = 0               # disable 'one buffer per window'
  120.       delete_buffer()                     # Close the buffer...
  121.       create_buf_and_win(name)            # and then reopen it to see the change
  122.    
  123.       message("Current buffer converted to %s EOL string",
  124.                 buffer_eol_string == "\n" ? "Unix" : "DOS")
  125.                 
  126.       create_new_bufwin = old_create_buf  # reset 'one buffer per window'
  127.       default_buffer_eol_string = old_default_eol_str # reset eol_string
  128.    }
  129.