{ 
* 
*     NAME:   PFGBL 
*     SOURCE: 92070-18297 
*     RELOC:  NONE (PART NUMBER IS RESERVED)
*     PGMR:   DAVE NEFF 
****************************************************************
* (C) COPYRIGHT HEWLETT-PACKARD COMPANY, 1979. ALL RIGHTS      *
* RESERVED. NO PART OF THIS PROGRAM MAY BE PHOTOCOPIED,        *
* REPRODUCED OR TRANSLATED TO ANOTHER PROGRAM LANGUAGE WITHOUT *
* THE PRIOR WRITTEN CONSENT OF HEWLETT-PACKARD COMPANY.        *
****************************************************************
* 
{This file contains the declaration of all global variables, types
 and constants which are used by PFORM and its
segments.  This file is merged into PFORM and its segments
 at compilation time by the $include directive.  There is obviously 
 no relocatable file corresponding to PFGBL, but the part number
 for the relocatable is reserved to maintain consistancy in 
 numbering.}
{No routines are recursive, so turn off the recursive option to 
 save code and execution time.} 
$recursive off$ 
{No range checking is necessary due to careful coding through the use 
 of constants. Turning the range checking off saves a good deal 
 of code and execution time. If substantial modifications are made
 to PFORM or any of its segments, it would be wise to turn this 
 option back on for debugging purposes.}
$range off$ 
  CONST 
  
   {These error messages are used by the main program.} 
  
   error3='*ERROR - UNRECOGNIZED COMMAND';
   error4='*ERROR - OVERFLOW OF MEMORY';
  
   {These errors are used by more than one procedure.}
   error5='*ERROR - DUPLICATE FILE NAME'; 
   error18='*ERROR - ID SEGMENT TRACK OFFSET OVERFLOW'; 
  
   fdir_length=16;             {Length in words of an RTE-L file
  
                                directory entry.} 
    idseg_length=30;           {Length in words of an id segment.}
    if_type=30;                {The interface type in the IFT must be 
                                36(8) for the all PROM cards. This is 
                                to be specified at generation time.}
    line_length=72;            {Length of an input line (max).} 
    long_idseg_length=34;      {Length of a 'skeleton' long id segment
                                obtained from the header of a program 
                                file.}
    max_io_cards=14;           {An L system backplane has at most 14
                                slots for IO (or PROM) cards.}
    max_num_labls=5;           {The maximum number of labls to be 
                                retrieved from the snapshot file.}
    max_words=3;               {The maximum number of words denoting
                                a label in the shapshot file.}
    max_char=max_words*2;      {The maximum number of characters denoting 
                                a label in the shapshot file.}
  
    maxint=32767;              {Maximum single word integer range.} 
    minint=-32768;             {Minumum single word integer range.} 
  
    null=0;                    {ASCII null character ordinal number.} 
    recd_len=128;              {The number of words in one record.} 
    recds_per_2k=2048 DIV 
                   recd_len;   {The number of records in 2k. Used 
                                for bumping to a 2k boundary.}
    short_idseg_length=8;      {Eight words per short id segment.}
  
  TYPE
    doubint=-214748647..214748647;
  
    {Declare the integer TYPE to be single word.} 
    integer=minint..maxint; 
  
    {The TYPE address_array is used to pass and return the addresses
     of the labels found in the snapshot file.} 
    address_array=ARRAY [1..max_num_labls] OF integer;
  
    {The TYPE buffer is used for readf and writf calls. Type 1 access 
     makes the readf and writf calls fill or use the buffer immediately,
     without buffering through the dcb first.}
    buffer=ARRAY [1..recd_len] OF integer;
  
    {The TYPE dcb is used to make data control blocks for FMP calls.} 
    {The RECORD structure allows calls to readf and writf routines
     with type 1 access, but without having a seperate dcb and buffer.} 
    dcb=
      RECORD
        header:ARRAY [1..16] OF integer;
        buff:buffer;
      END;
  
    {error_type handles certain compiler errors.} 
    error_type = (run,ema,io,fmp,seg);
  
    {The TYPE file_directory is used to make file directory entries.} 
    file_directory=ARRAY [1..fdir_length] OF integer; 
  
    {The TYPE fname represents a file name identifier.} 
    fname=PACKED ARRAY [1..6] OF char;
  
    {The TYPE input_line represents a line of terminal text.} 
    input_line=PACKED ARRAY [1..LINE_LENGTH] OF char; 
  
    {The TYPE idseg represents the structure of a 30 word id segment.}
    idseg=ARRAY [1..idseg_length] of integer; 
  
    {The TYPE isize_type is a two word array used by FMP to 
     denote length of files created.} 
    isize_type=ARRAY [1..2] OF doubint; 
  
    {The TYPE varl_labl represents the structure of the label 
     identifiers in the snapshot file. varl_labl stands for 
     variable length label, since the identifier length is
     subject to future change.} 
    varl_labl=PACKED ARRAY[1..max_char] OF char;
  
    {The TYPE labl_array is an array of variable length labels.}
    labl_array=ARRAY [1..max_num_labls] OF varl_labl; 
  
  
   {The TYPE lo_idseg represents the structure of a long id segment.} 
    lo_idseg=ARRAY [1..long_idseg_length] OF integer; 
   {The TYPE lu_array is for storing the specified PROM lu numbers to 
    prevent duplicate lus for seperate PROM images.}
    lu_array=ARRAY [1..max_io_cards] OF integer;
  
    {The TYPE sh_idseg represents the structure of a short id segment.} 
    sh_idseg=ARRAY [1..short_idseg_length] of integer;
  
  VAR 
    {All global variables are declared here.} 
  
    {Two character packed type for abreviated commands.}
    abrv_cmmd: PACKED ARRAY [1..2] OF char; 
    {address_array TYPE declaration}
    address:address_array;       {Addresses of labels found in the
                                  snapshot file.} 
  
    {boolean TYPE declarations.}
    abort,                       {True when user wishes to abort, 
                                  false otherwise.} 
    abort_or_pform_ended,        {Logical or of two frequently
                                  used booleans.} 
    boot,                        {True when the user wished to boot the 
                                  system from some outfile, false if the
                                  user never said YES to the boot from
                                  outfile prompt.}
    bootable_outfile,            {True when an output file actually has 
                                  a bootable image (after the system
                                  has been transfered).}
    bump,                        {True when the command was 'BUMP  ', 
                                  false for all other commands.}
    com_error,                   {True when the command was unrecognized, 
                                  false if the command was recognized.} 
    created,                     {True when an output file was created, 
                                  false if not created.}
    csw_error,                   {True when a PROGRAM or RP command was 
                                  given, but the file was not for the 
                                  system specified, otherwise, false.}
    dupl_fname,                  {True when the current FILE,RP, or PROGRAM 
                                  command specifies a file name which is
                                  the same as some file name already entered
                                  into the directory, false otherwise.} 
    echo_read,                   {True when all readlines must be echoed
                                  to the output file, false otherwise.} 
    echo_write,                  {True when all writes must be echoed to
                                  the input file, false otherwise.} 
    first_boot,                  {True when the user wishes to boot the 
                                  system from the current outfile, false
                                  otherwise.} 
    first_pform,                 {True on the first pass at formatting
                                  the PROM, false on subsequent passes. 
                                  Used to indicate if instructional 
                                  messages should be output.} 
    full_directory,              {True when the directory track is full,
                                  but no new directory track can be 
                                  allocated.} 
    init_complete,               {True when the cartridge initialization
                                  is complete, false otherwise.}
    interactive,                 {True when the PFORM program is being run
                                  from an interactive device, false if not.}
    io_error,                    {True when an FMP error has occurred, false
                                  in all other cases.}
    made_scratch,                {True if a scratch system file was success-
                                  fully made, false otherwise.} 
    make_fill_file,              {True when a file entry must be made 
                                  to indicate a full PROM, false otherwise.}
    next,                        {True if the command was NEXT, false if not.}
    no_directory,                {True if the current PROM image file has no
                                  directory track (due to large system image),
                                  false otherwise.} 
    overflow,                    {True if copying the specified file to 
                                  the PROM image would overflow the memory, 
                                  or if the user specifies to boot from 
                                  the PROM where the system image overlays
                                  with the last (file directory) track, 
                                  false if there is room for the file and 
                                  its directory entry.} 
    pform_ended,                 {True when the user wishes to stop formatting
                                  PROM image files, false  otherwise.}
    repeat_prompt,               {True whenever a prompt must be repeated.} 
    rp_error,                    {True if an RP command cannot occur due
                                  to no free id segments, or a real time
                                  program conflicts with currently rp'd 
                                  real time programs, false otherwise.} 
    terminal_outfile,            {True when the list, or output, namr 
                                  is a terminal lu, false otherwise.} 
    tr_off_err:boolean;          {True if an overflow of a track offset 
                                  field occurs while fixing a short id
                                  segment.  Due to limits in the fields 
                                  of a short id segment, a base page for
                                  a segment must be within 63 tracks of 
                                  the main track, and the segments main 
                                  must be within 255 tracks of the main.} 
  
    {dcb TYPE declarations.}
    prog_dcb,                    {dcb used for duplicate system file, snapshot, 
                                  and programs to be moved to the outfile.} 
    out_dcb,                     {dcb for the current outfile.} 
    sys_dcb:dcb;                 {dcb of the system image.} 
  
    {file_directory TYPE declarations.} 
    cart_dir,                   {File directory entry for the 
                                 cartridge itself.} 
    directory:file_directory;   {File directory entry for the 
                                 file moved to the PROM 'disk'.}
  
    {fname TYPE declarations.}
    command,                    {The command returned by parse_namr 
                                 of the second part of PFORM. It will 
                                 be 'PROGRA','RP    ','BUMP  ',etc.}
    crlab,                      {The cartridge label returned by the
                                 user after it is prompted for.}
    input_file,                 {The external name of ifile.} 
    name,                       {A fname TYPE used for several purposes-- 
                                 its a temporary fname.}
    newname,                    {The new name to put in the id segment
                                 of a program when RP'd.} 
    login_lu,                   {ASCII value of the scheduling terminal.} 
    orig_system,                {The origional name of the destination
                                 system.} 
    output_file,                {External representation of ofile.} 
    outfile,                    {The name of the PROM image file being made.} 
    scratch,                    {The name of the scratch file made of the 
                                 system image.} 
    snap,                       {The name of the snapshot file.}
    system:fname;               {The name of the file currently containing
                                 the system image being modified.}
  
    {input_line TYPE declarations.} 
    inline:input_line;          {The buffer used to read strings given
                                 by the user.}
  
    {integer TYPE declarations.}
    bgbp,                      {Starting address of the background
                                base page partition.} 
    bp_block,                  {Base page block, used to store the base 
                                page sector when fixing short and long
                                id segments.} 
    bp_tr_off,                  {Base page track offset, used to
                                 store the offset for fixing up short and 
                                 long id segments.} 
    crn,                        {User defines this cartridge reference
                                 number when it is prompted for.} 
    cur_fde,                    {Keeps track of the current file
                                 directory entry availiable.} 
    cur_ofile_rec,              {Keeps track of the current record
                                 availiable in the PROM image (outfile) 
                                 file.} 
    cur_prog_rec,               {Keeps track of the current record
                                 to write of the file to be transfered
                                 to the outfile.} 
    cur_sector,                 {The sector associated with the cur_
                                 ofile_rec.}
    cur_sys_rec,                {Keeps track of the current record
                                 of the system which is stored in 
                                 its buffer.} 
    cur_track,                  {The track associated with the cur_ 
                                 _ofile_rec.} 
    fde_recnum,                 {First directory entry record number for
                                 the current directory track.}
    fdir_entries_per_track,     {The number of file directory entries 
                                 in one track.} 
    first_dir_track,            {The first directory track number.} 
    first_fde_recnum,           {First directory entry record number for
                                 the first directory track (last disk 
                                 track.}
    first_ofile_rec,            {The starting record number in the
                                 PROM image file for the current
                                 file transfer. Used to recover 
                                 from possible FMP errors during
                                 the transfer of files to the PROM
                                 image file.} 
    free_addr,                  {The address of the first free id segment 
                                 in the system image.}
    ftype,                      {The origional type of the program being
                                 moved to the PROM image file.} 
    fwbg,                       {Address of the first word of back ground.} 
    hi_bpp1,                    {The high base page address plus one which
                                 a relocated program uses. Used for fixing
                                 id segments.}
    hi_mainp1,                  {The high address plus 1 which a main part
                                 of a relocated program uses. Used for
                                 fixing id segments.} 
    i,                          {A loop index which is frequently reused.}
    icrn,                       {The cartridge reference number returned
                                 by some parse_namr calls.} 
    id_addr,                    {Address of the first id segment in the 
                                 system image.} 
    id_num,                     {Maximum number of id segments allowed in 
                                 the system image.} 
    ierr,                       {The status returned from an FMP call.
                                 When an error occurs, ierr is the negative 
                                 FMP error code.} 
    ioff,irb,irec,              {Dummy parameters required by a call to locf
                                 but of no concern in the program since 
                                 type 1 access is forced.}
    isecu,                      {The security code returned by some parse_namr
                                 calls, and used to open the files.}
    istrc,                      {Starting character to tell namr where
                                 to begin its parse.} 
    jlu,                        {The lu returned by a call of locf, which 
                                 retrieves file information.} 
    jsec,                       {The sector returned by locf. Not used by 
                                 this program.} 
    jty,                        {The file type returned by locf.} 
    last_rec,                   {The last record number of the PROM image 
                                 file which the current program transfer
                                 will  use.}
    len,                        {Used to indicate the length of an input
                                 string read via readline.} 
    log_lu,                     {Integer value of the scheduling terminal.} 
    lo_bp,                      {The low base page address a program uses.} 
    lo_main,                    {The low main address a program uses.}
    lu_count,                   {The number of lu's specified so far in 
                                 the PFORM process.}
    lut_num,                    {The number of entries in the logical unit
                                 table.}
    lut_addr,                   {Starting address of the logical unit table.} 
    main_block,                 {The block  on the PROM image 'disk' where
                                 a main program begins (for fixing long 
                                 id segment).A block is a logical record.}
    main_track,                 {The track on the PROM image 'disk' where 
                                 a main program begins.}
    main_tr_off,                {The offset a segment is from the main track.}
    mem_size,                   {The memory size of the current PROM module 
                                 in K words (rounded up if not integral).}
    namr_type,                  {The TYPE of the namr string returned by the
                                 parse_namr routine.} 
    num_bp_recs,                {The number of records the base page takes
                                 up in disk storage.} 
    num_labls,                  {Number of labels to retrieve from the
                                 snapshot file.}
    num_main_recs,              {The number of records a main program or
                                 segment takes up in disk storage.} 
    num_tracks,                 {Stores number of tracks on 'disk'-PROM.
                                 This value is obtained from DVP6 of the
                                 DVT for the lu the user specified.}
    num_segs,                   {The number of segments in a program
                                 as specified in the header.} 
    num_sys_entries,            {The number of system entries (or labels) 
                                 actually contained in the snapshot file.}
    ofile_len,                  {Length of the outfile (PROM image), in 
                                 records.}
    out_crn,                    {The cartridge reference number of the
                                 output (PROM image) file.} 
    out_secu,                   {The security code for the output file.}
    prog_len,                   {The length in records of the file to be
                                 transferred to the PROM image file.} 
    promlu,                     {The lu of the prom card which is 
                                 being configured.} 
    prom_num,                   {The prom number that a file starts 
                                 at in the prom image (2K PROMS).}
    recs_per_track,             {The number of 128 word records on
                                 one PROM track.} 
    rem_blocks,                 {The remaining number of blocks on the
                                 PROM image file which can be used to 
                                 store programs or files.}
    temp,                       {Temporary integer storage.}
    track,                      {Temporary indicatory of a track on the 
                                 PROM 'disk', used for fixing id segments.} 
    sector,                     {Temporary indicator of a sector on the 
                                 PROM 'disk'.}
    sect_per_track,             {The number of sectors in one PROM
                                 track. Retrieved from DVT7 of the
                                 DVT pointed to by the specified lu.} 
    seg_num,                    {The number of the segment currently in 
                                 memory.} 
    sys_crn,                    {Cartridge reference number of the system 
                                 image, and its copy (from crets).} 
    sys_csw,                    {The system image checksum word.} 
    sys_len,                    {The length of the system image.} 
    sys_secu,                   {Security code for the system image 
                                 and its copy.} 
    words_per_track:integer;    {The number of words on one PROM track.}
  
    {labl_array declaration}
    labls:labl_array;           {Array of labels to retrieve from the 
                                 snapshot file.}
  
    {lo_idseg TYPE declaration.}
    skel_ids:lo_idseg;          {The first 34 words of a type 6 file.}
  
    {lu_array TYPE declaration.}
    lus:lu_array;               {Stores all the lu's specified so far.} 
  
    {text TYPE declarations.} 
    ifile,                        {The input file specified 
                                   by the runstring, defaults 
                                   to loglu.} 
    ofile:text;                   {The output file specified
                                   by the runstring, defaults 
                                   to loglu.} 
  
                                                                                                                