home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
UNIXEDIT.PEL
< prev
next >
Wrap
Text File
|
1995-03-27
|
5KB
|
132 lines
# $Header: P:\source\wmacros\unixedit.pev 1.1 27 Mar 1995 09:41:38 NOBLE $
## $Tabs:4 7$
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: unixedit.pel $: Support for UNIX newline files
#############
#
# This file contains functions to allow the editing of files with Unix style
# end of line (EOL) characters, and the conversion of buffers between DOS and
# Unix EOL strings.
#
# The function 'edit_unix_file_key()' can be assigned to a key and is used to
# edit a single Unix file when the editor is in the default DOS mode.
# If you have many Unix files to edit, you can change the default mode to Unix
# with the 'toggle_unix()' function. This will switch the editor between DOS
# and Unix modes so that all subsequent file opens will use the proper EOL string.
#
# The function 'toggle_buffer_eol()' will convert the current buffer from DOS to
# Unix, or vice versa. An optional parameter of TRUE will always convert to Unix,
# and FALSE will always convert to DOS. The default editor mode is unchanged.
#
# Finally, the functions 'unix_edit()' and 'dos_edit()' switch the editor to
# Unix or DOS mode and convert the current buffer if the optional parameter is TRUE.
#
#############
# edits a single file with UNIX style end of line characters
global function edit_unix_file_key(name)
{
default_buffer_eol_string="\n"
# and then reopen it to see the change.
create_buf_and_win_key(name)
default_buffer_eol_string="\r\n"
}
# Toggles between unix and dos newline modes. All new files are
# loaded with the new mode.
global function toggle_unix(on)
{
local current_mode = (default_buffer_eol_string == "\n")
if( argcount() < 1 )
on = !current_mode
else
on = on+0 # make sure that 'on' is an integer
if ( on && !current_mode)
unix_edit(FALSE) # switch to unix mode w/o changing current buffer
else if (!on && current_mode)
dos_edit(FALSE) # switch to dos mode w/o changing current buffer
else
message("File mode unchanged at %s", current_mode ? "Unix" : "DOS")
}
# Change the editor to Unix file mode and optionally convert the current
# buffer to Unix style EOL character.
global function unix_edit(convertCurrent)
{
default_buffer_eol_string="\n"
if (convertCurrent)
toggle_buffer_eol(TRUE)
message("Edit Mode = Unix");
}
# Change the editor to DOS file mode and optionally convert the current
# buffer to DOS style EOL character.
global function dos_edit(convertCurrent)
{
default_buffer_eol_string="\r\n"
if (convertCurrent)
toggle_buffer_eol(FALSE)
message("Edit Mode = DOS");
}
# convert the current buffer from DOS to Unix, or Unix to DOS style EOL character.
global function toggle_buffer_eol(unix)
{
local name # filename of current buffer
local old_create_buf = create_new_bufwin
local old_default_eol_str = default_buffer_eol_string
if (!and(buffer_flags, BUFFER_SYSTEM) &&
!and(buffer_flags, BUFFER_SCRATCH))
{
if( argcount() < 1 )
unix = (buffer_eol_string != "\n")
else
unix = unix+0 # make sure that 'on' is an integer
if (unix)
default_buffer_eol_string = "\n"
else
default_buffer_eol_string = "\r\n"
name = buffer_filename
create_new_bufwin = 0 # disable 'one buffer per window'
delete_buffer() # Close the buffer...
create_buf_and_win(name) # and then reopen it to see the change
message("Current buffer converted to %s EOL string",
buffer_eol_string == "\n" ? "Unix" : "DOS")
create_new_bufwin = old_create_buf # reset 'one buffer per window'
default_buffer_eol_string = old_default_eol_str # reset eol_string
}
}