home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/system.pev 1.34 24 Sep 1990 11:58:48 ericj $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: system.pel $: support for dos_buffer, etc.
-
-
- local DOS_BUFFER_NAME = "DOS WINDOW" # dos buffer buffer_name
- local DOS_FILE_NAME = "_doswin.$$$"; # temporary dos buffer filename
- global dosScreenInitialized = 0; # signifies presence of dos screen
-
- ## create a buffer and capture interactive output from dos_window
- # No buffer created if running under OS/2
- #
- global function dos_buffer( command ) {
- local width = display_width - 8;
- local height = display_height - 8;
- local dosBuffer;
- local saveBuffer = current_buffer;
- local saveWindow = current_window;
- local dosFileName;
- local iconified = 0;
- local one_window;
- local isdiag = 0+dialog_window;
-
- # regular dos_window if OS/2
- if (os_name == "OS/2")
- return system( command );
-
- # make dialog window visible
- toggle_dialog( 1 );
-
- if (dosScreenInitialized) {
- # already initialized?
- if (!find_dos_window()) {
- # no, create the new window.
- current_window = create_window( 0, 0, \
- display_width, \
- display_height - 1, \
- WINDOW_SYSTEM + WINDOW_NOBORDER + DOS_WINDOW_FLAG );
- color_text = 14;
- }
- } else {
- # is there only one window on the screen?
- # if yes, split it, otherwise, use next_window
- #
- one_window = (next_window() == saveWindow);
- assign_current_window( saveWindow );
-
- if (one_window) {
- create_tiled_window(45,1);
- }
- }
-
- # search through the buffer list for the temporary dos_window buffer
- if (find_dos_buffer()) {
- # found it, make it current
- dosBuffer = current_buffer;
- current_buffer = saveBuffer;
- } else {
- #
- # create the dos window buffer with
- # NO_UNDO_HISTORY | SYSTEM_BUFFER
- dosBuffer = create_buffer( DOS_BUFFER_NAME, "", 9 + DOS_BUFFER_FLAG );
- }
-
- # try to find the temporary dos_window window.
- if (!find_dos_window()) {
- window_flags = or(window_flags, DOS_WINDOW_FLAG);
- }
-
- current_buffer = dosBuffer;
-
- attach_window_buffer( current_window, current_buffer );
-
- # if the window was iconified, remember this and restore later.
- if ( !and( window_flags, WINDOW_ZOOM )){
- iconified = 1;
- restore_window();
- }
-
- goto_buffer_bottom(); # reposition cursor at end of buffer
- goto_eol();
- saveVisibles( 1 )
-
- display_update()
-
- if ((dosFileName = buildpath( DOS_FILE_NAME ))) {
- write_buffer( dosFileName );
- if (!command)
- message( "To return to Sage Professional Editor, type \"EXIT\"." )
- dos_window( command ">>& " dosFileName );
-
- delete_buffer();
-
- #
- # create the dos window buffer with
- # NO_UNDO_HISTORY | SYSTEM_BUFFER
- #
- current_buffer = create_buffer( DOS_BUFFER_NAME, dosFileName, 9 + DOS_BUFFER_FLAG );
- goto_buffer_bottom();
- goto_eol();
- saveVisibles( 0 )
- display_update();
- unlink( dosFileName );
- #
- # restore previous window setting and buffer
- if (iconified || command) {
- if (iconified)
- collapse_window();
- assign_current_window( saveWindow );
- current_buffer = saveBuffer;
- }
- display_redraw();
- message( "" );
- } else {
- saveVisibles( 0 ) # restore visible attributes.
- message( "Illegal output filename." );
- }
-
- if (dosScreenInitialized) {
- # bury window if it's the background window
- bury_window( );
- }
- toggle_dialog( isdiag );
- }
-
- ## Set a flag to create a background window which is the entire
- # screen to hold any dos output.
- #
- global function init_dos_screen() {
- dosScreenInitialized = 1
- }
-
-
- local old_visible_end_buffer;
- local old_visible_newlines;
- local old_visible_spaces;
- local old_visible_tabs;
- local old_window_flags;
-
- ## save/restore current visible settings and reset to blanks
- #
- local function saveVisibles( saving ) {
- if (saving) {
- old_visible_end_buffer = visible_end_buffer;
- old_visible_newlines = visible_newlines;
- old_visible_spaces = visible_spaces;
- old_visible_tabs = visible_tabs;
- old_window_flags = window_flags;
- visible_end_buffer = "";
- visible_newlines = " ";
- visible_spaces = " ";
- visible_tabs = " ";
- } else {
- visible_end_buffer = old_visible_end_buffer;
- visible_newlines = old_visible_newlines;
- visible_spaces = old_visible_spaces;
- visible_tabs = old_visible_tabs;
- window_flags = old_window_flags;
- }
- }
-
- ## search through the list of windows until one is found with the
- # DOS_WINDOW_FLAG bit set in window_flags
- #
- # Returns: TRUE if found
- # FALSE if not found
- global function find_dos_window() {
- local saveWindow = current_window
-
- do {
- if( and( window_flags, DOS_WINDOW_FLAG ))
- return TRUE;
- } while (next_window("",1) != saveWindow);
- return FALSE;
- }
-
- ## search through the list of buffer until one is found with the
- # DOS_BUFFER_FLAG bit set in buffer_flags
- #
- # Returns: TRUE if found
- # FALSE if not found
- global function find_dos_buffer()
- {
- local saveBuffer = current_buffer
-
- do {
- if (and(buffer_flags, DOS_BUFFER_FLAG))
- return TRUE;
- } while (next_buffer( "", 1 ) != saveBuffer);
- return FALSE;
- }
-
-
- ## system_window_command
- #
- # Invoke a DOS command and display the output in a window centered
- # on the screen.
- #
- # Direct the output to the filename specified in dosFileName.
- # If dosFileName is not given, create a temp name and use that.
- #
- local arg_array
-
- global function system_window_command( command, dosFileName ) {
- local prevWindow = current_window
- local removeTempFile
- local status
-
- if ( !command ) {
- return -1
- }
-
- dosFileName = buildpath( dosFileName )
-
- # under OS/2, just run the command
- if ( os_name == "OS/2" ) {
- if ( dosFileName ){
- command = command " >>&" dosFileName
- }
- return system( command )
- }
-
- # get file name to use for DOS buffer
- if ( !dosFileName ) {
- if ( !(dosFileName = create_temp_name()) ) {
- return -1
- }
- removeTempFile = TRUE
- }
-
- # if not enough memory for even a reduced window, quit now
- if ( !init_system_factory_window()) {
- if ( removeTempFile ) {
- unlink( dosFileName )
- }
- return -1
- }
- display_update()
-
- # It is possible for the following invocation of dos_window()
- # not to return. This happens whenever the current
- # sageedit.ae file is removed or changed by the system
- # command. To avoid leaving the "factory window" on the
- # screen, we attach an event handler to remove it for us.
- #
- # It is still conceivable that the clean-up would not occur,
- # i.e. if both this function and the event handler function
- # are changed by the system command. To reduce the
- # likelihood of that occurence, we keep the two functions in
- # different files.
-
- arg_array[ 1 ] = current_window
- arg_array[ 2 ] = prevWindow
- arg_array[ 3 ] = dosFileName
- arg_array[ 4 ] = removeTempFile
- attach_cleanup_handler( "display_dos_buffer" )
-
- # do the system command in a window
- status = dos_window( command " >& " dosFileName )
-
- # If the event handler installed above did not get invoked, it
- # must have been changed by the system command. Do here what
- # the event handler would have done had it been invoked.
-
- if ( arg_array ) {
- display_dos_buffer()
- }
-
- return status
- }
-
- ## display dos_buffer output - second half of system_window_command()
- #
- global function display_dos_buffer() {
-
- local isdiag = 0+dialog_window
- local current_window = arg_array[ 1 ]
- local prevWindow = arg_array[ 2 ]
- local dosFileName = arg_array[ 3 ]
- local removeTempFile = arg_array[ 4 ]
-
- delete arg_array
-
- # create the dos window buffer
- current_buffer = \
- create_buffer( "", dosFileName, \
- BUFFER_SYSTEM + BUFFER_NO_UNDO )
-
- attach_window_buffer( current_window, current_buffer )
-
- goto_buffer_bottom()
-
- toggle_dialog( 1 )
- confirm( "Press <Enter> to continue.", "" )
- toggle_dialog( isdiag )
- message( "" )
-
- delete_buffer()
- delete_window()
- if ( prevWindow ) {
- current_window = prevWindow
- }
-
- if ( removeTempFile ) {
- unlink( dosFileName )
- }
- }
-
- # build the window used by system_window_command()
- local function init_system_factory_window() {
- local prevWindow = current_window
- local x,y, x1,y1
-
- x = 3
- y = 8
- x1 = display_width - (x*2)
- y1 = display_height - (y*2)
-
- current_window = create_factory_window( x, y, x1, y1, WINDOW_MENU0 )
-
- # if not enough memory - try once more with a smaller window
- if ( current_window == prevWindow ) {
- y1 = 6
- current_window = create_factory_window( x, y, x1, y1, WINDOW_MENU0 )
- if ( current_window == prevWindow ) {
- warning( "unable to create window" )
- return 0
- }
- }
-
- window_cursor_x = 0
- window_cursor_y = 0
-
- return TRUE
- }
-