home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
DOSBOX.PEL
< prev
next >
Wrap
Text File
|
1995-04-04
|
10KB
|
319 lines
# $Header: P:\source\wmacros\dosbox.pev 1.16 04 Apr 1995 09:27:50 WALKER $
## $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: dosbox.pel $: dos_box (DOS in a dialog).
## System flags (for the dos_box() function)
global SYS_MASK = 0x007F
global SYS_CLOSE = 0x0080
global SYS_PROMPT = 0x0100
#
# Resource ID's used by the DOS BOX.
#
local IDD_DOSBOX = 253
local IDE_STDOUT = 51
local IDE_STDIN = 52
#
# Values used to calculate the size of the STDOUT box when re-sizing.
#
local DOS_WIDTH_DIFF = 50
local DOS_HEIGHT_DIFF = 70
local dos_boxes
local dos_pipes
global function dos_box(cmd, flags, title)
{
local dh_dos_box
local status = 0
local pipeid = create_pipes()
if (pipeid)
{
dh_dos_box = create_mdialog(function_id( "dos_callback" ), mdi_mode == 2 ? -1 : 0,
IDD_DOSBOX, resource_dll )
if (dh_dos_box)
{
dos_boxes[pipeid] = dh_dos_box
dos_pipes[dh_dos_box] = pipeid
attach_event_handler(EVENT.PIPE_DATA, function_id("dos_data"))
if (and(flags, SYS_PROMPT))
attach_event_handler(EVENT.PROCESS_COMPLETE, function_id("dos_done 2"))
else if (and(flags, SYS_CLOSE))
attach_event_handler(EVENT.PROCESS_COMPLETE, function_id("dos_done 1"))
else
attach_event_handler(EVENT.PROCESS_COMPLETE, function_id("dos_done 0"))
if (title)
set_dialog_window( dh_dos_box, DWC_TITLE, title )
else if (cmd)
set_dialog_window( dh_dos_box, DWC_TITLE, cmd )
begin_dialog(dh_dos_box, TRUE)
status = system(cmd, pipeid, pipeid, pipeid, \
and(or(flags, SYS_NOSESSION + SYS_ASYNC), SYS_MASK))
if ( status > 0 )
{
if ( !and(flags, SYS_NOEXPOSE) )
process_pipes(pipeid, FALSE, FALSE)
}
else
{
cleanup_dos_box(dh_dos_box)
delete_dialog(dh_dos_box)
close_pipes(pipeid)
}
}
}
else
status = system(cmd, 0, 0, 0, \
and(or(flags, SYS_SESSION + SYS_ASYNC), SYS_MASK))
return status
}
local IDM_DOS_COPY = 2001
local IDM_DOS_PASTE = 2002
local IDM_DOS_EDIT = 2003
local dos_menu
local dos_edit_menu
local function create_dos_menu(dlgid)
{
dos_menu[dlgid] = create_menu()
dos_edit_menu[dlgid] = create_menu()
# Make append_menuitem work for duplicate menus, since we don't use
# menu functions.
menu_functions[IDM_DOS_COPY] = ""; delete menu_functions[IDM_DOS_COPY]
menu_functions[IDM_DOS_PASTE] = ""; delete menu_functions[IDM_DOS_PASTE]
menu_functions[IDM_DOS_EDIT] = ""; delete menu_functions[IDM_DOS_EDIT]
append_menuitem(dos_edit_menu[dlgid], IDM_DOS_COPY, 0x0408,
"~Copy\tCtrl-Ins")
append_menuitem(dos_edit_menu[dlgid], IDM_DOS_PASTE, 0x0408,
"~Paste\tShift-Ins")
append_menuitem(dos_menu[dlgid], IDM_DOS_EDIT, 0x0208,
"~Edit", dos_edit_menu[dlgid])
change_menu(dos_menu[dlgid], dlgid)
}
local function cleanup_dos_menu(dlgid)
{
# delete_menu(dos_edit_menu[dlgid], dlgid)
# delete_menu(dos_menu[dlgid], dlgid)
delete dos_edit_menu[dlgid]
delete dos_menu[dlgid]
menu_functions[IDM_DOS_COPY] = ""; delete menu_functions[IDM_DOS_COPY]
menu_functions[IDM_DOS_PASTE] = ""; delete menu_functions[IDM_DOS_PASTE]
menu_functions[IDM_DOS_EDIT] = ""; delete menu_functions[IDM_DOS_EDIT]
}
global function cleanup_dos_box(dlgid)
{
cleanup_prompt_history()
cleanup_dos_menu(dlgid)
}
global function dos_callback()
{
local data
local dlgid
local buffer
local pipeid
if ( callback_msg == DM_INIT )
{
create_dos_menu(callback_dialog_handle)
add_dialog_item(callback_dialog_handle, IDE_STDOUT, DCTRL_MLE)
add_dialog_item(callback_dialog_handle, IDE_STDIN, DCTRL_EDIT_KEY)
set_dialog_item(callback_dialog_handle, IDE_STDIN, DAC_SETFOCUS)
setup_prompt_history( "DOSBOX" )
}
else if ( callback_msg == DM_CLOSE || callback_msg == DM_CANCEL )
{
if (callback_dialog_handle in dos_pipes)
close_pipes(dos_pipes[callback_dialog_handle])
cleanup_dos_box(callback_dialog_handle)
delete dos_pipes[callback_dialog_handle]
return DRC_EXIT
}
else if ( callback_msg == DM_OK )
{
if (callback_dialog_handle in dos_pipes)
{
dlgid = callback_dialog_handle
pipeid = dos_pipes[dlgid]
data = query_dialog_item(dlgid, IDE_STDIN, DAC_EDIT_TEXT) "\n"
buffer = dos_buffer(dlgid, length(data)) data
set_dialog_item(dlgid, IDE_STDOUT, DAC_EDIT_TEXT, buffer)
set_dialog_item(dlgid, IDE_STDIN, DAC_EDIT_TEXT, "")
set_dialog_item(dlgid, IDE_STDIN, DAC_SETFOCUS)
pputs(data, pipeid)
}
return DRC_MSG_PROCESSED
}
else if ( callback_msg == DM_MENUCOMMAND )
{
if (callback_index == IDM_DOS_COPY)
set_dialog_item(callback_dialog_handle, IDE_STDOUT, DAC_COPY)
else if (callback_index == IDM_DOS_PASTE)
set_dialog_item(callback_dialog_handle, IDE_STDIN, DAC_PASTE)
}
else if ( ( callback_msg == DM_CLICK && callback_index == DI_HELP ) ||
( callback_msg == DM_HELPREQUESTED ) )
{
display_help("dosbox", 0 )
return DRC_MSG_PROCESSED
}
else if ( callback_msg == DM_INVALID_PCHAR &&
callback_index == IDE_STDIN )
{
dlgid = callback_dialog_handle
prompt_response = query_dialog_item(dlgid, IDE_STDIN, DAC_EDIT_TEXT)
execute_event_handler(EVENT.INVALID_PCHAR)
set_dialog_item(dlgid, IDE_STDIN, DAC_EDIT_TEXT, prompt_response)
}
else if ( callback_msg == DM_RESIZE )
resize_dos_dialog( callback_dialog_handle )
return DRC_CONTINUE
}
global function dos_data()
{
local len
local data
local dlgid
local buffer
if ( process_pipe in dos_boxes )
{
data = pipe_data
dlgid = dos_boxes[process_pipe]
if (dlgid in dos_pipes)
{
buffer = dos_buffer(dlgid, length(data)) data
set_dialog_item(dlgid, IDE_STDOUT, DAC_EDIT_TEXT, buffer)
len = length(buffer)
set_dialog_item(dlgid, IDE_STDOUT, DAC_SELECTION, len, len)
}
}
}
global function dos_done(close)
{
local save
local level
local title
local dlgid
if ( process_pipe in dos_boxes )
{
dlgid = dos_boxes[process_pipe]
if (dlgid in dos_pipes)
{
title = query_dialog_window( dlgid, DWC_TITLE )
set_dialog_item(dlgid, DI_OK, DAC_DISABLE)
set_dialog_item(dlgid, IDE_STDIN, DAC_DISABLE)
set_dialog_window(dlgid, DWC_TITLE, "Completed: " title)
if (close)
{
if (close > 1)
{
level = message_level
message_level = 0
save = status_bar_flags
status_bar_flags = and( status_bar_flags, not( STB_MESSAGES ))
notify((length(title) ? title : "Command ") " Complete")
status_bar_flags = save
message_level = level
}
if (dlgid in dos_pipes)
{
cleanup_dos_box(dlgid)
delete_dialog(dlgid)
}
}
}
delete dos_boxes[process_pipe]
delete dos_pipes[dlgid]
delete_event(EVENT.PIPE_DATA, function_id("dos_data"))
if (close)
delete_event(EVENT.PROCESS_COMPLETE, function_id("dos_done " close))
else
delete_event(EVENT.PROCESS_COMPLETE, function_id("dos_done 0"))
}
}
local function dos_buffer(dlgid, len)
{
local buffer = query_dialog_item(dlgid, IDE_STDOUT, DAC_EDIT_TEXT)
if (length(buffer) + len > 7800)
return suffix(buffer, 6000 - len)
else
return buffer
}
local function resize_dos_dialog( dlgid )
{
local new, pos, delta
# new size is stored in a long as (short width)(short height)
new.width = callback_data / 65536
new.height = callback_data % 65536
# resize stdin & stdout boxes to match new dialog size
if ( new.width && new.height )
{
pos = query_dialog_item( dlgid, IDE_STDOUT, DAC_POSITION)
delta = pos % 65536 + DOS_HEIGHT_DIFF
set_dialog_item(dlgid, IDE_STDOUT, DAC_SIZE,
new.width - DOS_WIDTH_DIFF, new.height - delta )
set_dialog_item(dlgid, IDE_STDIN, DAC_SIZE, new.width - DOS_WIDTH_DIFF,
query_dialog_item( dlgid, IDE_STDIN, DAC_SIZE) % 65536 )
# show/hide the group of buttons if new dimensions are smaller
# than the group of buttons
#
show_button( dlgid, DI_OK, new )
show_button( dlgid, DI_CANCEL, new )
show_button( dlgid, DI_HELP, new )
}
}