!FILE LAST CHANGED ON 20/01/83
!  *******************************************************************
!  *                                                                 *
!  *    THE JOURNAL SYSTEM:    PACKAGE E                             *
!  *    THIS PACKAGE IS THE HELP INFO SECTION OF THE EMAS 2900       *
!  *    JOURNAL SYSTEM.                                              *
!  *                                                                 *
!  *    IT ALSO CONTAINS SERVICE ROUTINES USED BY SOME OF THE        *
!  *    OTHER JOURNAL COMPONENTS (A, B, C, D).                       *
!  *                                                                 *
!  *    DESIGNED AND WRITTEN BY JOHN HENSHALL                        *
!  *                                                                 *
!  *    JOHN MURISON                       VERSION: 014              *
!  *                                                                 *
!  *                                                                 *
!  *******************************************************************
!
constinteger  kent = 0, ercc = 1
constinteger  journalsite = kent

systemroutinespec  outfile(string (31) s, integer  size, hole,
        protection, integername  conad, flag)
systemroutinespec  destroy(string (31) s, integername  flag)
externalroutinespec  cherish(string (31) s)
recordformat  rf(integer  conad, filetype, datastart, dataend)
systemroutinespec  connect(string (31) file, integer  mode, hole,
                    project, record (rf)name  r, integername  flag)
systemroutinespec  changefilesize(string (31) file, integer  newsize, integername  flag)
systemintegerfnspec  dtword(integer  old date)

externalintegerfn  cyclic(integer  from, direction)
  !This function will return a value one up or one down from the
  !given value 'from' in the cyclic order 0-index top.
  !Direction = -1 if down , 1 if up.
  constinteger  index top = 9999
  from=from+direction
  result  = from if  0<=from<=index top
  result  = from - direction*(index top+1)
end ;  !of cyclic

externalstringfn  intostr(integer  n)
  !  Turns an integer into a string.  Uses machine code.
  string  (16) s
  integer  d0, d1, d2, d3
  *lss_n;  *cdec_0
  *ld_s;  *inca_1;                     ! PAST LENGTH BYTE
  *cpb_b ;                             ! SET CC=0
  *supk_l =15, 0, 32;                  ! UNPACK 15 DIGITS SPACE FILL
  *std_d2;                             ! FINAL DR FOR LENGTH CALCS
  *jcc_8, <waszero>;                   ! N=0 CASE
  *lsd_tos ;  *st_d0;                  ! SIGN DESCRIPTOR STKED BY SUPK
  *ld_s;  *inca_1
  *mvl_l =15, 15, 48;                  ! FORCE IN ISO ZONE CODES
  if  n < 0 then  byteinteger(d1) = '-' and  d1 = d1-1
  byteinteger(d1) = d3-d1-1
  result  = string(d1)
waszero:
  result  = "0"
end ;  !OF INTOSTR

externalroutine  read description(stringname  reply)
  ! This routine reads the reply to an issued prompt.
  ! It does not change the case of the letters (cf. READ PROMPT REPLY, below).
  integer  i
  skipsymbol while  nextsymbol=nl
  reply="";  !CLEAR OUT THE REPLY AREA.
  while  nextsymbol#nl cycle 
    readsymbol(i)
    reply=reply.tostring(i)
  repeat 
end ;  !OF READ DESCRIPTION.

externalroutine  read prompt reply(stringname  reply)
  ! This routine reads the reply to an issued prompt.
  ! It converts all letters to upper case.
  integer  i
  skipsymbol while  nextsymbol=nl
  reply="";  !Clear out the reply area.
  while  nextsymbol#nl cycle 
    readsymbol(i)
    i=i&95 if  'a'<=i<='z'
    reply=reply.tostring(i)
  repeat 
end ;  !OF READ PROMPT REPLY.

externalintegerfn  s to i(string (255) s)
  integer  j, z, c
  z = 0
  for  j=1,1,length(s) cycle 
    c = charno(s,j)
    result =0 unless  '0'<=c<='9'
    z = 10*z+c-'0'
  repeat 
  result  = z
end 

externalintegerfn  minutes between(integer  from, to)
   !This routine calculates the minutes between two dates given in the
   !standard EMAS packed date format.
  result  = (dtword(to)&x'7fffffff' - dtword(from)&x'7fffffff')//60
end ;  !Of %integer %fn minutes between.

externalroutine  expand jfile(string (31) file, integer  newsize,
                              integername  conad, flag)
   ! We can use change filesize without disconnecting - possibly.
   record (rf) r
   conad = 0
   change filesize(file, newsize, flag)
   return  if  flag=0; ! OK
   connect(file, 3, newsize, 0, r, flag)
   change filesize(file, newsize, flag)
   conad = r_conad if  flag=0
   ! conad non-zero on return means file was reconnected.
   cherish(file) unless  substring(file,1,2)="T#"
end ; ! Of %externalroutine expand jfile.

externalroutine  create jfile(string (11) file, integer  cells, cellsize, header size,
                      integername  conad, flag)
   ! Creates a file of name "file" large enough to contain a header of size
   ! "header size" plus "cells" cells each of "cell size" bytes.
   recordformat  ss head f(integer  end, start, size, filetype,
                           checksum, date, format, s0)
   record (ss head f)name  ss head

   destroy(file, flag)
   outfile(file, header size+cells*cell size, 0, 0, conad, flag)
   monitor  and  return  if  flag#0
   ! Now set up some of the header.
   return  if  header size<32
   ss head == record(conad)
   sshead_start = header size
   sshead_size = header size+cells*cellsize
   sshead_end = sshead_size; ! Note this - set to be full.
   sshead_filetype = 4; ! Data file.
   sshead_format = 3; ! Unstructured.
   cherish(file) unless  substring(file,1,2) = "T#"
end ; ! Of %externalroutine create jfile.

externalroutine  print help(integer  link)
switch  help(1:9)
!
->help(link)
!
help(1):
printstring("Give the recognition keyword (up to twelve characters)
of the FILETYPE in question.
Examples:  MAINLOG   SPOOLR   VOLUMS  ACCOUNTS  BACK&ARCH  DIRECT
           UPDATES   MAILER

")
return 
!
help(2):
printstring("On replying FILES you will be expected to know the file
sequence numbers by which the stored files are identified.
(Command LIST JOURNAL INDEX  gives a list of an index)
")
printstring("On replying DATES you will be expected to define the time
period for which the files required were relevant.

")
return 
!
help(3):
printstring("Reply in the format   ddmmyy,hhmmss
Noting that  1)  yy is optional, omission assumes this year.
             2)  ss is optional, omission assumes 00.
ALWAYS include leading zeros.
Examples:  2404,105632    021178,1214   2110,1012

")
return 
!
help(4):
printstring("Reply with a retrieval function (COMPLETE  or   ON KEY).
")
printstring("A reply of END terminates the initialisation sequence and
retrieval commences.
A reply of STOP terminates the run immediately.
See Journal documentation, Chapter 5, for further details.

")
return 
!
help(5):
printstring("FIXED format enables you to search each line of the
file(s) for a match with a defined set of KEYWORDS that occur
in fixed positions in a line.  After every match, n (user defined)
lines from the file are printed.
")
printstring("FREE format enables you to search each line of the file(s)
for a match with a defined set of keywords (one or more) that 
occur consecutively but not at any particular starting point in 
a line.  After every match, n lines are printed.
")
printstring("Note 1) !END acts as a terminator to the KEYWORD definition
        sequence
     2) A maximum of 10 keywords for any one set.
     3) You may define as many sets of KEYWORDS to search on during 
        one run by multiple use of ON KEY calls.")
printstring("
     (The output from the result of all the defined searches will
     appear in the same file.)
     4) The output appears in the file JJANL. You will be asked to
        define how it is to be handled at the end of the run.

")
return 
!
help(6):
printstring("Reply with LIST   SEND  or  LIST+OFFER

")
return 
help(7):
printstring("There are three valid options, as follows:
      ALL    give a complete summary of device errors and controller
             errors for the period.
      DISC   give a summary of disc errors for the period.
")
printstring("      CONTROLLER  give all controller errors of the type 
             defined for the period in question.

")
return 
!
help(8):
printstring("Define the Line Printer that you require.
        Give LP for the local mainframe printer or give the recognised
        device name, e.g.  LP72     LP80   LPAH

")
return 
!
help(9):
printstring("Give TERMINAL or T if you require the output on your terminal
or else give the name of the LINE PRINTER to be used for the output.
(  LP   gives the local mainframe line printer)
Examples:   T    LP   LPAH   LP80    ....

")
return 
end ;  !OF PRINT HELP.
endoffile