home *** CD-ROM | disk | FTP | other *** search
- {$S40,P+,T+}
- PROGRAM Pas_Main ;
-
- (* Program: PASCALM.PAS
- By: Jinfu Chen, based on OSS' PASCAL 1.x source code
- Rev: 0.80, 1/1/87
- A beta version. Most of the functions work. Info_Window
- is taken out because of reentrant problem. Replaced by
- dialog box, Info_Msg, for temporary fix.
- *)
-
- (*$I auxsubs.pas*)
-
- CONST
- {$I gemconst.pas}
- {$I pascalm.i} (* resource file definition *)
- max_option = 30 ; { Maximum number of options in one dialog }
- chunk = 1024 ; (* size to be copy at one time *)
- HIDE = TRUE; (* just name them for the ease of reading *)
- NOHIDE = FALSE;
- GEM_O = 1 ;
- TOS_O = 2 ;
- TTP_O = 3 ;
- ACC_O = 4 ;
-
- TYPE
- {$I gemtype.pas}
- opt_range = 1..max_option ;
- opt_array = PACKED ARRAY [ opt_range ] OF boolean ;
- (* opt_set = SET OF opt_range ; *)
- environment = C_String ;
- env_ptr = ^environment ;
- buf_type = Packed Array [1..chunk] OF BYTE ;
- drive_array = PACKED ARRAY[1..4] OF Long_INTEGER ;
- C_Path_Type = Packed Array [1..80] OF CHAR ;
-
- VAR
- envp : env_ptr ;
- rez : integer ; (* screen resolution *)
- (* never used
- zero_word : integer ;
- *)
- menu : Menu_Ptr ;
- info_dial : Dialog_Ptr ;
- dummy : integer ;
- for_gem : Integer ; (* 1 for gem, 2 for tos, 3 for acc *)
- cmp_opts : opt_array ;
- bad_res,
- temp_path,
- backup_path,
- addl_files,
- addl_libs : Str255 ;
- work_path, (* path for FILE menu *)
- file_path, (* path for SPECIALS menu *)
- compiler_name,
- linker_name,
- editor_name,
- paslib_name,
- pasgem_name,
- printer_name,
- src_name, (* source filename for COPY *)
- des_name, (* destination filename for COPY *)
- cmp_name,
- link_name,
- edit_name,
- run_name : Path_Name ;
- { wind_title : Window_Title ; } { window title, not used }
- { window_id : INTEGER ; } { window id }
- (* fullx, fully, fullw, fullh : integer ; *)
-
- {$I gemsubs.pas}
-
- FUNCTION Dsetdrv( drive : INTEGER ) : Long_INTEGER ;
- GEMDOS($0E) ;
- (* Set Default Drive *)
-
- FUNCTION Dgetdrv : integer ;
- GEMDOS( $19 ) ;
-
- FUNCTION FCreate( VAR fname : C_Path_Type ; mode : INTEGER ) : INTEGER ;
- GEMDOS( $3C ) ;
-
- PROCEDURE Dfree( VAR buf : DRIVE_ARRAY ; driveno : INTEGER ) ;
- GEMDOS($36) ;
- (* Get Drive Free Space *)
- (* Some Information :
- buf[1] : number of free clusters ;
- buf[2] : total number of clusters ;
- buf[3] : sector size in bytes ;
- buf[4] : cluster size in bytes.
- *)
-
- FUNCTION Ddelete( VAR pathname : C_Path_Type ) : INTEGER ;
- GEMDOS($3A) ;
- (* Delete Directory *)
-
- FUNCTION FOpen( VAR fname : C_Path_Type ; mode : INTEGER ) : INTEGER ;
- GEMDOS( $3D ) ;
-
- PROCEDURE FClose( fhandle : INTEGER ) ;
- GEMDOS( $3E ) ;
-
- FUNCTION FRead( fhandle : INTEGER ; n_bytes : Long_INTEGER ;
- VAR buf : buf_type ) : Long_Integer ;
- GEMDOS( $3F ) ;
-
- FUNCTION FWrite( fhandle : INTEGER ; n_bytes : Long_INTEGER ;
- VAR buf : buf_type ) : Long_Integer ;
- GEMDOS( $40 ) ;
-
- FUNCTION FDelete( VAR fname : C_Path_Type ) : INTEGER ;
- GEMDOS($41) ;
- (* Delete File *)
-
- PROCEDURE Dgetpath( VAR path_buf : C_Path_Type ; drive : integer ) ;
- GEMDOS( $47 ) ;
-
- FUNCTION Frename( zero : INTEGER; VAR oldname,
- newname : C_Path_TYPE ) : INTEGER ;
- GEMDOS($56) ;
- (* Rename File *)
-
- FUNCTION get_rez : integer ;
- XBIOS( 4 ) ;
-
- PROCEDURE bconin( dev : integer ) ; { Really a function! }
- BIOS( 2 ) ;
-
- PROCEDURE bconout( dev, c : integer ) ;
- BIOS( 3 ) ;
-
-
- PROCEDURE P_To_CPath( P_Path : Path_Name ; VAR C_Path : C_Path_Type ) ;
- (* convert Pascal string to C string, the built-in routines only work for
- long string *)
- VAR
- i : INTEGER;
-
- BEGIN
- FOR i := 1 TO Length( p_path ) DO
- c_path[i] := p_path[i] ;
- c_path[ i + 1 ] := chr(0) ;
- END ;
-
- PROCEDURE C_To_PPath( C_Path : C_Path_Type ; VAR P_Path : Path_Name ) ;
- (* convert C string to Pascal string *)
- VAR
- i : INTEGER;
-
- BEGIN
- i := 1 ;
- While (C_Path[i] <> CHR(0)) AND (C_Path[i] <> ' ') AND ( i <= 80 ) DO BEGIN
- P_Path[i] := C_Path[i] ;
- i := i + 1 ;
- END ;
- P_Path[0] := Chr( i - 1 ) ;
- END ;
-
-
- FUNCTION Is_Gem_Name( fname : Path_Name ) : boolean ;
- (* check if the program is a GEM program *)
- VAR
- i : integer ;
-
- BEGIN
- Is_Gem_Name := false ;
- IF length( fname ) > 3 THEN BEGIN
- i := length( fname ) - 3 ;
- IF ( fname[i]='.') AND (fname[i+1]='P') AND (fname[i+2]='R')
- AND (fname[i+3]='G') THEN
- Is_Gem_name := true ;
- END
- END ;
-
- FUNCTION Is_TTP_Name( fname : Path_Name ) : boolean ;
- (* check if the program is a TTP program *)
- VAR
- i : integer ;
-
- BEGIN
- Is_TTP_Name := false ;
- IF length( fname ) > 3 THEN BEGIN
- i := length( fname ) - 3 ;
- IF ( fname[i]='.') AND (fname[i+1]='T') AND (fname[i+2]='T')
- AND (fname[i+3]='P') THEN
- Is_TTP_name := true ;
- END
- END ;
-
-
- FUNCTION Get_CMD( fname : Path_Name; VAR cmd_line : Str255 ) : BOOLEAN ;
- (* get the command line for TTP program, the box looks exactly the same as
- the one in DESKTOP *)
- VAR
- i : integer ;
- btn : Integer ;
- t_box : Dialog_Ptr ;
- name : Str255 ;
-
- BEGIN
- cmd_line[0] := chr(0) ; (* zero length the cmd_line *)
- Get_CMD := TRUE ;
- Find_Dialog( TTPBOX, t_box ) ;
- Center_Dialog( t_box ) ;
- i := length( fname ) ;
- WHILE (fname[i] <> '\') DO
- i := i - 1 ; (* backwardly hunt the backslash *)
- name := Copy( fname, i + 1, length( fname ) - i - 4 ) ;
- Set_DText( t_box, TTPNAME, name, System_Font, TE_LEFT ) ;
- Set_DText( t_box, CMDLINE, cmd_line, System_Font, TE_LEFT ) ;
- btn := Do_Dialog( t_box, CMDLINE ) ;
- Obj_SetState( t_box, btn, NORMAL, TRUE ) ;
- IF btn = TTPCAN THEN
- Get_CMD := FALSE ;
- Get_DEdit( t_box, CMDLINE, cmd_line ) ;
- End_Dialog( t_box ) ;
- Delete_Dialog( t_box ) ;
- END ;
-
- PROCEDURE Wait(waittime : Long_Integer);
- (* just wait for n seconds. Note that TOS clock is in 2 second interval *)
- VAR
- starttime : Long_Integer;
- BEGIN
- starttime := Clock;
- WHILE ((Clock - starttime) < waittime ) DO
- ;
- END;
-
-
- PROCEDURE info_msg( msg : Str255) ;
- (* put up a message box on top of the Item Selector. Using window is better
- but for some reason text does not show up after p_exec a program. *)
- VAR
- x, y, w, h : integer ;
- item,
- dial_ind : Tree_Index ;
-
- BEGIN
- info_dial := New_Dialog( 2, 20, 1, 40, 3 ) ;
- item := Add_Ditem( info_dial, G_String, None, 1, 1, 38, 1,
- 0, D_Color( Black, Black, True, 0, 0 ) ) ;
- Obj_Size( info_dial, Root, x, y, w, h ) ;
- Set_Dtext( info_dial, item, msg, System_Font, TE_Left ) ;
- (* x := 155; y := 12*rez ; *)
- Obj_Draw( info_dial, Root, max_depth, x, y, w, h ) ;
- (*
- Show_Dialog( info_dial, 0 ) ;
- *)
- END ;
-
- PROCEDURE formdo(index : INTEGER; hide_item : INTEGER; hide : BOOLEAN) ;
- (* put a zoom box to screen, button can be hiden *)
- VAR
- x, y, w, h : Short_Integer;
- dia_obj : Dialog_Ptr;
-
- BEGIN (* formdo *)
- Find_Dialog(index, dia_obj);
- Center_Dialog(dia_obj);
- Obj_Size(dia_obj, Root, x, y, w, h); (* get some size info about the obj*)
- Form_Dial(0, 0, 0, 0, 0, x, y, w, h); (* reserve space for the box *)
- Form_Dial(1, 0, 0, 0, 0, x, y, w, h); (* expanding box -- zoom out *)
- IF hide THEN BEGIN
- Obj_Setflags(dia_obj, hide_item, HIDE_TREE); (* hide the button *)
- Show_Dialog(dia_obj, Root); (* no interaction *)
- Wait(2); (* 2 seconds later close down *)
- Obj_Setflags(dia_obj, hide_item, EXIT_BTN|DEFAULT|SELECTABLE);
- (* put the button back *)
- END
- ELSE
- dummy := Do_Dialog(dia_obj, 0); (* no need to hide the buttom *)
- Form_Dial(2, 0, 0, 0, 0, x, y, w, h); (* shrinking box -- zoom in *)
- Form_Dial(3, 0, 0, 0, 0, x, y, w, h); (* close the box *)
- Obj_Setstate(dia_obj, dummy, NORMAL, FALSE);
- End_Dialog(dia_obj);
- Delete_Dialog(dia_obj);
- END; (* formdo *)
-
-
- PROCEDURE Set_Defaults ;
- (* initialize some variables *)
- VAR
- opt : opt_range ;
- path : c_path_type ;
- p_path : Path_Name ;
-
- BEGIN
- FOR opt := 1 TO max_option DO
- IF opt IN [ ERRPAUSE,CHNLINK,DBGOPT,STKOPT,RNGOPT ]
- THEN cmp_opts[ opt ] := true ;
- work_path[1] := chr( ord('A') + Dgetdrv ) ;
- work_path[2] := ':' ;
- work_path[0] := chr(2) ;
-
- Dgetpath( path, 0 ) ; { Get default path } ;
- (* original OSS code:
- i := 1 ;
- WHILE (path[i] <> chr(0)) AND (path[i] <> ' ') AND (i <= 64 ) DO
- BEGIN
- work_path[i+2] := path[i] ;
- i := i + 1 ;
- END ;
- i := i + 1 ;
- work_path[0] := chr(i) ;
- *)
- C_To_PPath(path, p_path); (* convert C string to Pas string *)
-
- work_path := concat( work_path, p_path, '\' ) ; (* used by FILE *)
- file_path := concat( work_path, '*.*' ) ; (* used by SPECIALS *)
- editor_name := concat( work_path, 'EDITOR.PRG ') ;
- compiler_name := concat( work_path, 'COMPILER.PRG ' ) ;
- linker_name := concat( work_path, 'LINKER.PRG ' ) ;
- paslib_name := concat ( work_path, 'PASLIB' ) ;
- pasgem_name := concat ( work_path, 'GEMLIB' ) ;
- printer_name := concat( work_path, 'PRINTER.PRG ' ) ;
- backup_path := work_path ;
- work_path := concat( work_path, '*.PAS' ) ;
- for_gem := GEM_O ;
-
- (* uncomment following if trying to do window
- wind_title := ' ';
- window_id := New_Window(None, wind_title,0 ,0, 0, 0);
- *)
-
- END ;
-
- PROCEDURE Copy_Files( src_file, des_file : Path_Name ) ;
- (* a generic routine to copy file *)
- VAR
- i,
- infile, (* file handle for input file *)
- outfile : INTEGER ; (* file handle for output file *)
- n_bytes : Long_INTEGER ; (* number of bytes for read/wirte *)
- write_error : BOOLEAN ;
- cnvrt_str : C_Path_Type ;
- buf : buf_type ;
-
- BEGIN
- write_error := FALSE ;
- P_To_CPath(src_file, cnvrt_str) ; (* convert to C string *)
- infile := FOpen( cnvrt_str, 0 ) ; (* open file to read *)
- IF infile >= 0 THEN BEGIN (* open success *)
- P_To_CPath(des_file, cnvrt_str) ;
- outfile := FCreate( cnvrt_str, 0 ) ; (* open a file regardless existence *)
- IF outfile >= 0 THEN BEGIN (* open success *)
- Set_Mouse( M_BEE ) ; (* busy copying file *)
- REPEAT
- n_bytes := FRead( infile, chunk, buf ) ;
- IF n_bytes > 0 THEN BEGIN (* we read something *)
- IF FWrite( outfile, n_bytes, buf ) <> n_bytes THEN BEGIN
- write_error := TRUE ; (* write error *)
- i := Do_Alert('[3][Error in writing|Disk is full?][ Abort ]',1) ;
- END ; (* write *)
- END ; (* read *)
- UNTIL ((n_bytes = 0) OR write_error ) ;
- FClose( outfile ) ;
- Set_Mouse( M_ARROW ) ; (* copy is done *)
- END (* outfile *)
- ELSE
- i := Do_Alert('[3][Error to open file|Too many file opened?][ Abort ]',1) ;
- FClose( infile ) ;
- END (* infile *)
- ELSE
- i := Do_Alert('[3][Error to open file|File not existed?][ Abort ]',1) ;
- END ;
-
-
- PROCEDURE Do_Copy;
- (* get source and destination names and call copy_file routine *)
-
- BEGIN
- (* uncomment all the routines relate to window if want to try window
- Info_Window('Select File To Be Copied From...') ;
- *)
- Info_Msg('Select File To Be Copied FROM...') ;
- IF Get_In_File( file_path, src_name ) AND (length(src_name) <> 0)
- THEN BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- (*
- Info_Window('Select File To Be Copied To...') ;
- *)
- Info_Msg('Select File To Be Copied TO...') ;
- IF ( Get_In_File( file_path, des_name ) AND (length(des_name) <> 0)
- AND (src_name <> des_name) ) THEN BEGIN (* don't copy to itself! *)
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- Copy_Files( src_name, des_name ) ;
- END
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
-
- END
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- Draw_Menu( menu ) ;
- END;
-
-
- PROCEDURE Disk_Space ;
- (* check free space of a drive *)
- VAR
- space_box : Dialog_Ptr ;
- btn : INTEGER ;
- drive_char,
- byte_used,
- byte_available : Str255 ;
- temp,
- drive_map : Long_INTEGER ; (* an array with all available drives *)
- drive_id : INTEGER ;
- drive_buf : DRIVE_ARRAY ;
-
- BEGIN
- byte_used := '';
- byte_available := '' ;
- drive_id := Dgetdrv ; (* used current drv first *)
- drive_char[1] := CHR(ORD('A') + drive_id) ; (* convert to char *)
- drive_char[0] := CHR(1) ; (* force string length to 1 *)
-
- Find_Dialog( DISKSP, space_box ) ;
- Center_Dialog( space_box ) ;
- Set_DText( space_box, DISKID, drive_char, System_Font, TE_LEFT ) ;
- btn := Do_Dialog( space_box, DISKID ) ;
-
- Set_Mouse(M_BEE) ; (* it takes a while for disk-free routine *)
- Get_DEdit( space_box, DISKID, drive_char ) ;
-
- drive_id := ORD(drive_char[1]) - ORD('A') ; (* get the drive user wants *)
-
- (* check if the requested drive in system *)
- drive_map := ShR( Dsetdrv(drive_id), drive_id ) & $0001; (* check the bit *)
-
- Obj_SetState( space_box, btn, Normal, true ) ;
- IF ( (drive_map * drive_id) = drive_id) THEN BEGIN
- Dfree(drive_buf, drive_id + 1 ) ; (* it's a valid drive *)
- temp := drive_buf[3] * drive_buf[4]; (* bytes per cluster *)
- WriteV( byte_available, (drive_buf[1] * temp) : 8 ) ;
- WriteV( byte_used, ((drive_buf[2] - drive_buf[1])* temp) : 8 ) ;
- Set_DText( space_box, BYTEAVL, byte_available, System_Font, TE_RIGHT ) ;
- Set_DText( space_box, BYTEUSED, byte_used, System_Font, TE_RIGHT ) ;
- Obj_SetFlags( space_box, DISKID, NONE) ; (* don't edit the id now *)
- Set_Mouse(M_Arrow) ;
- btn := Do_Dialog( space_box, 0 ) ;
- Obj_SetFlags( space_box, DISKID, EDITABLE) ; (* resume the editable *)
- Obj_SetState( space_box, btn, Normal, true ) ;
- Set_Mouse(M_ARROW) ;
- END
- ELSE BEGIN
- Set_Mouse(M_ARROW) ;
- End_Dialog( space_box ) ;
- byte_used:=Concat('[2][ |Drive ',drive_char,'|does not existed][ Abort ]');
- btn := Do_Alert(byte_used, 1 ) ;
- END ;
- End_Dialog( space_box ) ;
- Delete_Dialog( space_box ) ;
- END ;
-
-
- PROCEDURE Rename_File ;
- (* renaming file *)
- VAR
- old, new : C_Path_Type ;
- i : INTEGER ;
-
- BEGIN
- (*
- Info_Window('Select File To Be Renamed From...') ;
- *)
- info_msg( 'Select file to be renamed FROM...') ;
- IF Get_In_File( file_path, src_name ) AND (length(src_name) <> 0)
- THEN BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- (*
- Info_Window('Select File To Be Renamed To...') ;
- *)
- info_msg( 'Select file to be rename TO...' ) ;
- IF ( Get_In_File( file_path, des_name ) AND (length(des_name) <> 0)
- AND (src_name <> des_name) ) THEN BEGIN (* don't rename to itself! *)
- (* Close_Window( window_id ) ; *)
- End_Dialog( info_dial ) ;
- P_To_CPath( src_name, old ) ;
- P_To_CPath( des_name, new ) ;
- IF src_name[1] <> des_name[1] THEN
- i := Do_Alert('[3][Cannot rename to|a different drive][ Abort ]',
- 1 )
- ELSE
- CASE FRename( 0, old, new ) OF
- -34 :
- i := Do_Alert('[3][Cannot rename to an|existent file][ Abort ]',
- 1 ) ;
- -36 :
- i := Do_Alert('[3][Error in renaming file|File not found][ Abort ]',
- 1 ) ;
- END ; (* case *)
- END (* outfile *)
- ELSE
- (* Close_Window( window_id ) ; *)
- End_Dialog( info_dial ) ;
- END (* infile *)
- ELSE
- (* Close_Window( window_id ) ; *)
- End_Dialog( info_dial ) ;
- Draw_Menu( menu ) ; (* kludgy way to repain the menu bar *)
- END ;
-
- PROCEDURE Delete_File ;
- VAR
- c_str : C_Path_Type ;
- i : INTEGER ;
-
- BEGIN
- (*
- Info_Window('Select File To Be Deleted...') ;
- *)
- Info_Msg('Select File To Be Deleted...') ;
- IF Get_In_File( file_path, src_name ) AND (length(src_name) <> 0)
- THEN BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- P_To_CPath(src_name, c_str) ;
- IF FDelete(c_str) < 0 THEN
- i := Do_Alert('[2][Error in deleting file|Non-existent file?][ Abort ]',
- 1 ) ;
- END
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- Draw_Menu( menu ) ;
- END ;
-
- PROCEDURE Print_File ;
- (* to be completed. Will have some codes to check printer status and call up
- the printer.prg program *)
- BEGIN
- ;
- END ;
-
-
- PROCEDURE Locate_Programs ;
- (* local filenames, similar to Pascal version 2. *)
- VAR
- fpath,
- fname : Path_Name ;
- msg : Str255 ;
- l_box : Dialog_Ptr ;
- btn : Integer ;
-
- BEGIN
- Find_Dialog( LOCATE, l_box ) ;
- Center_Dialog( l_box ) ;
- REPEAT
- btn := Do_Dialog( l_box, 0 ) ;
- CASE btn OF
- LEDIT : BEGIN
- msg := 'Select the EDITOR filename...' ;
- fname := 'EDITOR.' ;
- END ;
- LCMP : BEGIN
- msg := 'Select the COMPILER filename...' ;
- fname := 'COMPILER.PRG' ;
- END ;
- LLINK : BEGIN
- msg := 'Select the LINKER filename...' ;
- fname := 'LINKER.PRG' ;
- END ;
- LPASGEM : BEGIN
- msg := 'Select the PASGEM filename...' ;
- fname := 'PASGEM' ;
- END ;
- LPASLIB : BEGIN
- msg := 'Select the PASLIB filename...' ;
- fname := 'PASLIB' ;
- END ;
- LPRT : BEGIN
- msg := 'Select the PRINTER filename...' ;
- fname := 'PRINTER.PRG' ;
- END ;
- END ;
- IF btn <> LOKBTN THEN BEGIN
- (*
- info_window( msg ) ;
- *)
- Info_Msg( msg ) ;
- IF Get_In_File( file_path, fname ) AND (length(fname) <> 0) THEN BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- Draw_Menu( menu ) ;
- CASE btn OF
- LEDIT : editor_name := fname ;
- LCMP : compiler_name := fname ;
- LLINK : linker_name := fname ;
- LPASGEM : pasgem_name := fname ;
- LPASLIB : paslib_name := fname ;
- LPRT : printer_name := fname ;
- END ;
- END
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- End_Dialog( info_dial ) ;
- Draw_Menu( menu ) ;
- END ;
- Obj_SetState( l_box, btn, Normal, TRUE ) ;
- UNTIL btn = LOKBTN ;
- End_Dialog( l_box ) ;
- Delete_Dialog( l_box ) ;
- END ;
-
-
- PROCEDURE Read_Options ;
- (* read options from the .INF file *)
- VAR
- f : text ;
- version : integer ;
- temp : integer ;
- opt : opt_range ;
-
- BEGIN
- IO_Check( false ) ;
- reset( f, 'PASCALM.INF' ) ;
- IO_Check( true ) ;
- IF IO_Result = 0 THEN
- BEGIN
- readln( f, version ) ;
- FOR opt := 1 TO max_option DO
- IF opt IN [ ERRPAUSE,CHNLINK,DBGOPT,
- STKOPT,RNGOPT,CLROPT,BAKOPT,NOCODE ]
- THEN
- BEGIN
- readln( f, temp ) ;
- cmp_opts[ opt ] := temp <> 0 ;
- END ;
- readln( f, for_gem ) ; (* 1 for GEM, 2 for TOS, 3 for TTP, 4 for ACC *)
- readln( f, addl_files ) ;
- readln( f, addl_libs ) ;
- readln( f, backup_path ) ;
- readln( f, editor_name ) ;
- readln( f, compiler_name ) ;
- readln( f, linker_name ) ;
- readln( f, pasgem_name ) ;
- readln( f, paslib_name ) ;
- readln( f, printer_name ) ;
- close( f ) ;
- END
- END ;
-
- PROCEDURE Save_Options ;
- (* sace options to the .INF file *)
- VAR
- f : text ;
- junk : integer ;
- alert : Str255 ;
- opt : opt_range ;
-
- BEGIN
- IO_Check( false ) ;
- rewrite( f, 'PASCALM.INF' ) ;
- IO_Check( true ) ;
- IF IO_Result <> 0 THEN
- BEGIN
- alert := '[2][Error occurred while trying|to write the options';
- alert := ConCat(alert, 'file.][ OK ]');
- junk:=Do_Alert(alert, 1 ) ;
- END
- ELSE
- BEGIN
- Set_Mouse( M_BEE ) ; (* busy saving file *)
- writeln( f, $100:1 ) ; { Version 1.00 }
- FOR opt := 1 TO max_option DO
- IF opt IN [ ERRPAUSE,CHNLINK,DBGOPT,STKOPT,RNGOPT,CLROPT,
- BAKOPT,NOCODE ]
- THEN
- writeln( f, ord( cmp_opts[opt] ):1 ) ;
- writeln( f, for_gem ) ;
- writeln( f, addl_files ) ;
- writeln( f, addl_libs ) ;
- writeln( f, backup_path ) ;
- writeln( f, editor_name ) ;
- writeln( f, compiler_name ) ;
- writeln( f, linker_name ) ;
- writeln( f, pasgem_name ) ;
- writeln( f, paslib_name ) ;
- writeln( f, printer_name ) ;
- close( f ) ;
- Set_Mouse( M_ARROW ) ;
- END
- END ;
-
-
- PROCEDURE out_esc( c : char ) ;
-
- BEGIN
- bconout( 2, 27 ) ;
- bconout( 2, ord(c) ) ;
- END ;
-
- PROCEDURE Tos_Screen ;
-
- BEGIN
- Hide_Mouse ;
- out_esc( 'E' ) ; { Clear screen }
- out_esc( 'e' ) ; { and cursor on }
- END ;
-
- PROCEDURE Redraw_Screen ;
- VAR
- x, y, w, h : integer;
-
- BEGIN
- Work_Rect( 0, x, y, w, h ) ;
- Form_Dial( 3, 0, 0, 0, 0, x, y, w, h ) ; (* a dirty and quick way *)
- END ;
-
-
-
- PROCEDURE Gem_Screen ;
-
- BEGIN
- out_esc( 'f' ) ; { Cursor off }
- Show_Mouse ;
- END ;
-
- FUNCTION Call_Overlay( prog : Path_Name ; VAR cmd_line : Str255 ;
- tos : boolean ) : integer ;
- (* call editor, compiler, linker *)
- VAR
- i : integer ;
- prog_name : C_Path_Type ;
- tail : C_String ;
-
- FUNCTION p_exec( load : integer ; VAR name : C_Path_Type;
- VAR tail : C_String ; VAR envp : env_ptr ) : integer ;
- GEMDOS( $4B ) ;
-
- BEGIN
- FOR i := 1 TO length( cmd_line ) DO
- tail[i] := cmd_line[i] ;
- tail[ length(cmd_line)+1 ] := chr(0) ;
- tail[0] := chr( length(cmd_line) ) ;
-
- P_To_CPath( prog, prog_name ) ;
- Erase_Menu( menu ) ;
- IF tos THEN
- Tos_Screen ;
- Call_Overlay := p_exec( 0, prog_name, tail, envp ) ;
- IF tos THEN
- Gem_Screen ;
- Redraw_Screen ;
- Draw_Menu( menu ) ;
- (*
- window_id := New_Window(None, wind_title, 0 ,0, 0, 0);
- *)
- END ;
-
-
- PROCEDURE Strip_Extension( VAR fn : Path_Name ) ;
- { Strip_Extension - Remove the extension from a Path_Name variable. }
-
- VAR
- i : integer ;
- done : boolean ;
-
- BEGIN
- i := length( fn ) ;
- done := false ;
- WHILE NOT done DO
- BEGIN
- IF i < 1 THEN
- done := true
- ELSE IF (fn[i] = ':') OR (fn[i] = '\') THEN
- done := true
- ELSE IF fn[i] = '.' THEN
- BEGIN
- fn[0] := chr(i-1) ;
- done := true ;
- END
- ELSE
- i := i - 1 ;
- END ;
- END ;
-
- PROCEDURE Do_Link( name : Path_Name ; for_gem : integer ) ;
- { Do_Link - Call the linker with a desired file as input. }
-
- VAR
- junk : integer ;
- extension : STRING [ 5 ] ;
- libs,
- cmd_line : Str255 ;
- x, y, w, h : integer ;
- dial : Dialog_Ptr ;
-
- BEGIN
- Strip_Extension( name ) ;
- cmd_line := name ;
- CASE for_gem OF
- GEM_O : extension := '.PRG=' ;
- ACC_O : extension := '.ACC=' ;
- TOS_O : extension := '.TOS=' ;
- TTP_O : extension := '.TTP=' ;
- END ;
- CASE for_gem OF
- GEM_O, ACC_O : libs := concat(',', pasgem_name, ',', paslib_name) ;
- TOS_O, TTP_O : libs := concat(',', paslib_name) ;
- END ;
- cmd_line := concat( '! ', name, extension, name ) ;
- IF length(addl_files) > 0 THEN
- cmd_line := concat( cmd_line, ',', addl_files ) ;
- IF length(addl_libs) > 0 THEN
- cmd_line := concat( cmd_line, ',', addl_libs ) ;
- cmd_line := concat( cmd_line, libs ) ;
- Find_Dialog( LOADING, dial ) ;
- Set_DText( dial, LOADNAME, 'LINKER.PRG', System_Font, TE_Left ) ;
- Center_Dialog( dial ) ;
- Obj_Size( dial, Root, x, y, w, h ) ;
- Obj_Draw( dial, Root, Max_Depth, x, y, w, h ) ;
- junk := Call_Overlay( linker_name, cmd_line, false ) ;
- END ;
-
- FUNCTION Do_Compile : integer ;
- { Do_Compile - Call the compiler with a desired file as input. }
-
- VAR
- cmp_code : integer ;
- cmd_line : Str255 ;
- src,
- des,
- name : Path_Name ;
- x, y, w, h,
- i : integer ;
- dial : Dialog_Ptr ;
-
- BEGIN
- name := edit_name ;
- Strip_Extension( name ) ;
- cmd_line := concat( name, ' ', temp_path, ' /UGEM' ) ;
- CASE for_gem OF
- GEM_O : cmd_line := concat( cmd_line, ' /GEM' ) ;
- ACC_O : cmd_line := concat( cmd_line, ' /ACC' ) ;
- END ;
- IF cmp_opts[ ERRPAUSE ] THEN
- cmd_line := concat( cmd_line, ' /PAUSE' ) ;
- IF cmp_opts[ DBGOPT ] THEN
- cmd_line := concat( cmd_line, ' /DEBUG' ) ;
- IF NOT cmp_opts[ STKOPT ] THEN
- cmd_line := concat( cmd_line, ' /NOCHECK' ) ;
- IF cmp_opts[ RNGOPT ] THEN
- cmd_line := concat( cmd_line, ' /CHECK' ) ;
- IF cmp_opts[ CLROPT ] THEN
- cmd_line := concat( cmd_line, ' /CLEAR' ) ;
- IF cmp_opts[ NOCODE ] THEN
- cmd_line := concat( cmd_line, ' /NOCODE' ) ;
- Find_Dialog( LOADING, dial ) ;
- Set_DText( dial, LOADNAME, 'COMPILER.PRG', System_Font, TE_Left ) ;
- Center_Dialog( dial ) ;
- Obj_Size( dial, Root, x, y, w, h ) ;
- Obj_Draw( dial, Root, Max_Depth, x, y, w, h ) ;
- cmp_code := Call_Overlay( compiler_name, cmd_line, false ) ;
- Do_Compile := 0 ;
- IF cmp_code = 2 THEN { User wants to edit! }
- BEGIN
- Do_Compile := 1 ;
- i := 0 ;
- WHILE envp^[i] <> chr(0) DO
- BEGIN
- edit_name[i+1] := envp^[i] ;
- i := i + 1 ;
- END ;
- edit_name[0] := chr(i) ;
- END
- ELSE BEGIN
- IF (cmp_code = 0) AND (cmp_opts[ BAKOPT ]) THEN BEGIN
- src := edit_name ;
- i := length(src) ;
- WHILE src[i] <> '\' DO (* backwardly hunt the backslash *)
- i := i - 1 ;
- des := COPY( src, i + 1, length(src) - i ) ;
- des := concat( backup_path, des ) ;
- Copy_Files( src, des ) ;
- END ;
- IF (cmp_code = 0) AND (cmp_opts[ CHNLINK ]) THEN
- Do_Link( name, for_gem ) ;
- END ;
- END ;
-
- FUNCTION Do_Edit : integer ;
- { Do_Edit - Pass control to the Lohse editor. }
-
- VAR
- cmd_line : Str255 ;
- i : integer ;
- is_tos : boolean ;
-
- BEGIN
- cmd_line := edit_name ;
- is_tos := Is_TTP_Name( editor_name ) ; (* allow using different type of
- editors *)
- IF Call_Overlay( editor_name, cmd_line, is_tos ) = 1 THEN
- Do_Edit := 2
- ELSE
- Do_Edit := 0
- END ;
-
- PROCEDURE Compile_Edit( which : integer ) ;
- { Compile_Edit - Loop for "compile-edit-link" process. }
- (* which : 1 Editor
- 2 Compiler
- *)
- VAR
- i : integer ;
-
- BEGIN
- Strip_Extension( work_path ) ;
- work_path := concat( work_path, '.PAS' ) ;
-
- (*
- IF which = 1 THEN
- Info_Window('Select File To Be Edit...') ;
- IF which = 2 THEN
- Info_Window('Select File To Be Compiled...') ;
- *)
-
- IF Get_In_File( work_path, edit_name ) AND (length(edit_name) <> 0)
- THEN BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- WHILE which <> 0 DO
- BEGIN
- IF which = 1 THEN { Editor phase! }
- BEGIN
- which := Do_Edit ;
- FOR i := length( edit_name ) DOWNTO 1 DO
- IF edit_name[i] = ' ' THEN
- edit_name[0] := chr( i-1 ) ;
- END (* IF *)
- ELSE
- which := Do_Compile ;
- END ; (* WHILE *)
- END (* IF *)
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- END ;
-
-
- PROCEDURE Call_Linker ;
-
- BEGIN
- Strip_Extension( work_path ) ;
- work_path := concat( work_path, '.O' ) ;
- (*
- Info_Window('Select File To Be Linked...') ;
- *)
- IF Get_In_File( work_path, link_name ) AND (length(link_name) <> 0)
- THEN BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- Do_Link( link_name, for_gem ) ;
- END (* IF *)
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- END ;
-
-
- PROCEDURE Call_Program ;
-
- TYPE
- environment = PACKED ARRAY [ 1..9 ] OF char ;
-
- VAR
- skip : boolean ;
- i : integer ;
- name : C_Path_Type ;
- tail : C_String ;
- cmd_line : Str255 ;
- env : environment ;
- run_gem : boolean ;
- ttp_box : Dialog_Ptr ;
-
- PROCEDURE p_exec( load : integer ; VAR name : C_Path_Type ;
- VAR tail : C_String ; VAR env : environment ) ;
- GEMDOS( $4B ) ;
-
-
- BEGIN
- skip := FALSE ;
- Strip_Extension( work_path ) ;
- CASE for_gem OF
- GEM_O : work_path := concat( work_path, '.PRG' ) ;
- TOS_O : work_path := concat( work_path, '.TOS' ) ;
- TTP_O : work_path := concat( work_path, '.TTP' ) ;
- END ;
- (*
- Info_Window('Select File To Be Run...') ;
- *)
- IF Get_In_File( work_path, run_name ) AND (length(run_name) <> 0) THEN
- BEGIN
- (*
- Close_Window( window_id ) ;
- *)
- P_To_CPath( run_name, name ) ;
- env := 'PATH=A:\ ' ;
- env[9] := chr(0) ;
- run_gem := Is_Gem_Name( run_name ) ;
- IF Is_TTP_Name( run_name ) THEN BEGIN
- IF Get_CMD( run_name, cmd_line ) THEN BEGIN ; (* get command line *)
- FOR i := 1 TO length( cmd_line ) DO
- tail[i] := cmd_line[i] ;
- tail[ length(cmd_line)+1 ] := chr(0) ;
- tail[0] := chr( length(cmd_line) ) ;
- END
- ELSE
- skip := TRUE ;
- (*
- P_To_Cstr( cmd_line, tail ) ;
- tail[0] := chr(length( cmd_line )) ;
- tail[ length( cmd_line ) + 1 ] := chr(0) ;
- *)
- END
- ELSE BEGIN
- tail[0] := chr(0) ;
- tail[1] := chr(0) ;
- END ;
- IF NOT skip THEN BEGIN
- Erase_Menu( menu ) ;
- (*
- Delete_Window( window_id ) ;
- *)
- IF NOT run_gem THEN
- Tos_Screen ;
- p_exec( 0, name, tail, env ) ;
- IF NOT run_gem THEN
- BEGIN
- writeln( 'Hit any key to continue...' ) ;
- bconin( 2 ) ; { Get a key from the BIOS! }
- Gem_Screen ;
- END ;
- Redraw_Screen ;
- Draw_Menu( menu ) ;
- END (* not skip *)
- END (* get filename *)
- ELSE
- (*
- Close_Window( window_id ) ;
- *)
- END ;
-
-
- PROCEDURE Link_Options ;
-
- VAR
- dial : Dialog_Ptr ;
- opt,
- button : integer ;
-
- BEGIN
- Find_Dialog( LNKOPTS, dial ) ;
- Center_Dialog( dial ) ;
- FOR opt := 1 TO max_option DO
- IF opt IN [ LFORGEM,LFORTOS,LFORTTP,LFORACC ] THEN
- Obj_SetState( dial, opt, Normal, false ) ; (* reset every buttons *)
- CASE for_gem OF
- GEM_O : Obj_SetState( dial, LFORGEM, Selected, false ) ;
- TOS_O : Obj_SetState( dial, LFORTOS, Selected, false ) ;
- TTP_O : Obj_SetState( dial, LFORTTP, Selected, false ) ;
- ACC_O : Obj_SetState( dial, LFORACC, Selected, false ) ;
- END ;
- Set_DText( dial, LNKADDL, addl_files, System_Font, TE_Left ) ;
- Set_DText( dial, LNKLIBS, addl_libs, System_Font, TE_Left ) ;
- button := Do_Dialog( dial, LNKADDL ) ;
- Obj_SetState( dial, button, Normal, true ) ;
- End_Dialog( dial ) ;
- IF button = LNKOK THEN
- BEGIN
- IF Obj_State( dial, LFORGEM ) = Selected THEN
- for_gem := GEM_O ;
- IF Obj_State( dial, LFORTOS ) = Selected THEN
- for_gem := TOS_O ;
- IF Obj_State( dial, LFORTTP ) = Selected THEN
- for_gem := TTP_O ;
- IF Obj_State( dial, LFORACC ) = Selected THEN
- for_gem := ACC_O ;
- Get_DEdit( dial, LNKADDL, addl_files ) ;
- Get_DEdit( dial, LNKLIBS, addl_libs ) ;
- END ;
- Delete_Dialog( dial ) ;
- END ;
-
-
- { Compiler_Options - Allow the user to change various options within the
- compiler by activating the "Personal Pascal Compiler Options" dialog. }
-
- PROCEDURE Compiler_Options ;
-
- VAR
- dial : Dialog_Ptr ;
- button : integer ;
- opt : opt_range ;
-
- BEGIN
- Find_Dialog( CMPOPTS, dial ) ;
- Center_Dialog( dial ) ;
- { First, we need to ensure that the state of various dialog objects
- matches the state of our internal variables! }
- FOR opt := 1 TO max_option DO
- IF opt IN [ FORGEM,FORTOS,FORACC,ERRPAUSE, DBGOPT,
- STKOPT,RNGOPT,CLROPT,BAKOPT,NOCODE ] THEN
- Obj_SetState( dial, opt, Normal, false ) ;
- CASE for_gem OF
- GEM_O : Obj_SetState( dial, FORGEM, Selected, false ) ;
- TOS_O, TTP_O : Obj_SetState( dial, FORTOS, Selected, false ) ;
- ACC_O : Obj_SetState( dial, FORACC, Selected, false ) ;
- END ;
- FOR opt := 1 TO max_option DO
- IF opt IN [ ERRPAUSE, DBGOPT,STKOPT,RNGOPT,CLROPT,BAKOPT, NOCODE ] THEN
- IF cmp_opts[ opt ] THEN
- Obj_SetState( dial, opt, Checked, false ) ;
- IF cmp_opts[ NOCODE ] THEN BEGIN (* no object code, so no link *)
- cmp_opts[ CHNLINK ] := FALSE ;
- Obj_SetState( dial, CHNLINK, Normal, false ) ;
- END
- ELSE
- Obj_SetState( dial, CHNLINK, Checked, false ) ;
- Set_DText( dial, BACKPATH, backup_path, System_Font, TE_Left ) ;
- button := Do_Dialog( dial, BACKPATH ) ;
- WHILE (button <> CMPOK) AND (button <> CMPCAN) DO
- BEGIN
- IF Obj_State(dial, button) = Normal THEN
- Obj_SetState( dial, button, Checked, true )
- ELSE
- Obj_SetState( dial, button, Normal, true ) ;
- IF Obj_State(dial, NOCODE) = Checked THEN
- Obj_SetState( dial, CHNLINK, Normal, true ) ;
- button := Redo_Dialog( dial, BACKPATH ) ;
- END ;
- Obj_SetState( dial, button, Normal, true ) ;
- End_Dialog( dial ) ;
- IF button = CMPOK THEN
- BEGIN
- FOR opt := 1 TO max_option DO
- IF opt IN [ ERRPAUSE,CHNLINK,DBGOPT,STKOPT,RNGOPT,CLROPT,
- BAKOPT,NOCODE ] THEN
- cmp_opts[ opt ] := Obj_State( dial, opt ) = Checked ;
- IF Obj_State( dial, FORGEM ) = Selected THEN
- for_gem := GEM_O ;
- IF Obj_State( dial, FORTOS ) = Selected THEN
- for_gem := TOS_O ;
- IF Obj_State( dial, FORACC ) = Selected THEN
- for_gem := ACC_O ;
- Get_DEdit( dial, BACKPATH, backup_path ) ;
- END ;
- Delete_Dialog( dial ) ;
- END ;
-
-
-
- { Do_Menu - Perform a menu operation which was selected by the user with the
- mouse. The chosen menu title and item are passed in the parameters
- 'title' and 'item', respectively. }
-
- FUNCTION Do_Menu( title, item : integer ) : boolean ;
-
- VAR
- done : boolean ;
-
- BEGIN
- done := false ;
- CASE item OF
- MIINFO : Formdo(PASINFO, INFOBTN, NOHIDE);
- MIEDIT : Compile_Edit( 1 ) ;
- MICOMPIL : Compile_Edit( 2 ) ;
- MILINK : Call_Linker ;
- MIRUN : Call_Program ;
- MICMPOPT : Compiler_Options ;
- MILNKOPT : Link_Options ;
- MISAVOPT : Save_Options ;
- MILOCATE : Locate_programs ;
- MICOPY : Do_Copy ;
- MIDLF : Delete_File ;
- MICHN : Rename_File ;
- MIPRF : Print_File ;
- MIDF : Disk_Space ;
- MIQUIT : done := true ;
- END ;
- Menu_Normal( menu, title ) ;
- Redraw_Screen ;
- Do_Menu := done ;
- END ;
-
- PROCEDURE Event_Loop ;
-
- VAR
- which : integer ;
- done : boolean ;
- msg : Message_Buffer ;
-
- BEGIN
- REPEAT
- which := Get_Event( E_Message, 0, 0, 0, 0,
- false, 0, 0, 0, 0, false, 0, 0, 0, 0,
- msg, dummy, dummy, dummy, dummy, dummy, dummy ) ;
- IF which & E_Message <> 0 THEN
- done := Do_Menu( msg[3], msg[4] ) ;
- UNTIL done ;
- END ;
-
-
- FUNCTION Low_Resolution : boolean ;
-
- BEGIN
- rez := get_rez ; (* need to remember screen resolution *)
- Low_Resolution := (rez = 0) ;
- END ;
-
- (* main *)
- BEGIN
- IF Init_Gem <> -1 THEN
- BEGIN
- IF NOT Load_Resource( 'pascalm.rsc' ) THEN
- dummy := Do_Alert( '[3][PASCALM.RSC not found!][ Cancel ]', 0 )
- ELSE IF Low_Resolution THEN
- BEGIN
- bad_res := '[3][You must use medium or|high resolution to use|';
- bad_res := ConCat(bad_res, 'Personal Pascal.][ Cancel ]');
- dummy := Do_Alert(bad_res, 0);
- END
- ELSE
- BEGIN
- Set_Defaults ;
- Read_Options ;
- new( envp ) ;
- envp^[0] := chr(0) ;
- (* zero_word := 0 ; *)
- Find_Menu( PASMENU, menu ) ;
- Draw_Menu( menu ) ;
- (* Border_Rect( 0, fullx, fully, fullw, fullh ) ; *)
- Init_Mouse;
- Set_Mouse( M_Arrow ) ;
- Formdo(PASINFO, INFOBTN, HIDE);
- Event_Loop ;
- Erase_Menu( menu ) ;
- (*
- Delete_Window( window_id );
- *)
- END ;
- Exit_Gem ;
- END ;
- END.
-
- { End of pascalm.pas }
-