Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-06 - 43,50415/sqhelp.sim
There are 4 other files named sqhelp.sim in the archive. Click here to see a list.
COMMENT OPTIONS(/C/-Q/-A/-I/-D); OPTIONS(/L/E);
COMMENT sqhelp will list on SYSOUT the file given in helpfile.
If no dot ('.') in the string - ".HLP" will be assumed.
First sqhelp will try to find the file in the user's area.
If failed then in order at - HLP:  DOC:  and finally the SYS: areas.
sqhelp will return FALSE if all attempts failed.
;
EXTERNAL TEXT PROCEDURE conc,rest,scanto,from,upcase;
EXTERNAL REF (infile) PROCEDURE findinfile;
EXTERNAL BOOLEAN PROCEDURE dotypeout;
EXTERNAL INTEGER PROCEDURE search;
BOOLEAN PROCEDURE sqhelp(helpfile,selector,height,width);
VALUE helpfile, selector; TEXT helpfile, selector;
INTEGER height, width;
BEGIN
  REF (infile) inf;
  TEXT ARRAY line[1:height+1], strip_line[1:height+1];
  INTEGER current_line, max_line, match_line, heightp1, first_line;
  TEXT sysoutimage, lastline, upcased_line, stripinimage;
  BOOLEAN matching, some_match, first, full;
  CHARACTER lastchar, formfeed;
  PROCEDURE create_file;
  BEGIN
    formfeed:= char(12);
    helpfile:- helpfile.strip;
    IF scanto(helpfile,'.') == helpfile THEN
    helpfile:- conc(helpfile,".HLP");
    inf:- findinfile(helpfile);
    IF inf =/= NONE THEN GO TO list;
    scanto(helpfile,':');
    IF helpfile.more THEN helpfile:- rest(helpfile);
    helpfile:- conc("HLP:",helpfile);
    inf:- findinfile(helpfile);
    IF inf =/= NONE THEN GO TO list;
    helpfile.sub(1,3):= "DOC";
    inf:- findinfile(helpfile);
    IF inf =/= NONE THEN GO TO list;
    helpfile.sub(1,3):= "SYS";
    inf:- findinfile(helpfile);
    IF inf =/= NONE THEN GO TO list;
    outtext("?HLPCFF Cannot find file:");   helpfile.setpos(5);
    outtext(rest(helpfile));   outimage;
    list:
  END of procedure create_file;
  BOOLEAN PROCEDURE user_wants_more;
  BEGIN
    IF first THEN
    BEGIN first:= FALSE;
      GOTO out;
    END;
    dotypeout(sysout); sysout.image:- sysoutimage;
    outtext("    >>>>>>> Do you want more info");
    IF selector =/= NOTEXT THEN
    BEGIN
      outtext(" on """); outtext(selector); outchar('"');
    END;
    outtext("?/yes/:"); breakoutimage;
    inimage; lastchar:= ' ';
    stripinimage:- sysin.image.strip;
    IF stripinimage =/= NOTEXT THEN
    BEGIN
      WHILE lastchar EQ ' ' DO lastchar:= inchar;
      IF lastchar = 'n' THEN lastchar:= 'N'
      ELSE IF lastchar = '?' THEN
      BEGIN
        selector:- copy(sysin.image.sub(sysin.pos,
        stripinimage.length-sysin.pos+1));
        upcase(selector);
      END;
      sysin.setpos(-1);
    END;
    out: user_wants_more:= NOT lastchar = 'N';
  END of user_wants_more;
  PROCEDURE end_message;
  BEGIN
    dotypeout(sysout); sysout.image:- sysoutimage;
    IF lastchar = 'N' THEN outtext("[End of help") ELSE
    BEGIN
      outtext("[No "); IF some_match OR matching THEN outtext("more ");
      outtext("help");
    END;
    IF selector =/= NOTEXT THEN
    BEGIN
      outtext(" on """); outtext(selector); outchar('"');
    END;
    outtext(".] "); breakoutimage;
  END of procedure end_message;
  outimage;
  sysoutimage:- image;
  sysoutimage:= NOTEXT;
  IF selector == NOTEXT THEN
  BEGIN
    outtext("If you want help on a specific subject,");
    outimage;
    outtext("then type ? followed by a word");
    outimage;
    outtext("characterizing that subject,"); outimage;
    outtext("e.g. ?OUTPUT or ?");
    outtext(helpfile); outchar('.');
    outimage; outimage;
    outtext("If you do not do this, you will get complete help");
    outimage;
    outtext("on everything available about """);
  END ELSE
  BEGIN
    outtext("Searching for HELP on """);
    outtext(selector); outtext(""" in """);
  END;
  outtext(helpfile); outtext("""."); outimage; outimage;
  IF selector == NOTEXT THEN
  BEGIN
    IF NOT user_wants_more THEN GOTO quit;
  END;
  first:= TRUE;
  heightp1:= height+1;
  create_file;
  upcase(selector);
  INSPECT inf DO
  BEGIN
    PROCEDURE open_file;
    BEGIN
      sqhelp:= TRUE;
      open(sysout.image);
      FOR current_line:= 1 STEP 1 UNTIL heightp1 DO
      line[current_line]:- blanks(width);
      lastline:- line[heightp1];
    END;
    PROCEDURE read_page;
    BEGIN
      again:
      matching:= selector == NOTEXT; max_line:= 0; match_line:= 1;
      full:= FALSE;
      IF endfile THEN GOTO out;
      inline: max_line:= max_line+1; image:- line[max_line];
      inimage;
      image:- image.strip;
      IF image = NOTEXT THEN lastchar:= ' ' ELSE
      BEGIN image.setpos(image.length); lastchar:= image.getchar;
      END;
      IF lastchar = formfeed THEN
      BEGIN
        image:- image.sub(1,image.length-1);
      END;
      strip_line[max_line]:- image;
      IF NOT matching THEN
      BEGIN
        upcased_line:- lastline.sub(1,image.length);
        upcased_line:=image; upcase(upcased_line);
        upcased_line.setpos(1);
        IF search(upcased_line,selector) < upcased_line.length THEN
        BEGIN
          some_match:= matching:= TRUE;
          match_line:= max_line;
        END;
      END;
      IF max_line > height THEN max_line:= 0;
      IF max_line >= height THEN full:= TRUE;
      IF full AND matching THEN
      BEGIN IF mod(max_line-match_line+heightp1,
      heightp1)*2 > height THEN GOTO found;
      END;
      IF lastchar NE formfeed AND NOT endfile
      THEN GOTO inline;
      found:
      IF endfile OR image = NOTEXT THEN max_line:= max_line-1;
      if max_line < 0 then
      max_line:= max_line+heightp1;
      first_line:= max_line+2;
      IF NOT matching THEN GOTO again;
      IF NOT full AND max_line = 0 THEN GOTO again;
      out:
    END of read_page;
    PROCEDURE print_page;
    BEGIN
      IF full THEN
      FOR current_line:= first_line STEP 1 UNTIL heightp1 DO
      BEGIN
        sysout.image:- strip_line[current_line]; outimage;
      END;
      FOR current_line:= 1 STEP 1 UNTIL max_line DO
      BEGIN
        sysout.image:- strip_line[current_line]; outimage;
      END;
    END of print_page;
    open_file;
    next_page: read_page;
    IF max_line NE 0 OR full THEN
    BEGIN
      IF user_wants_more THEN
      BEGIN print_page; GOTO next_page;
      END;
    END;
    close; sysout.image:- sysoutimage;
  END inf;
  quit: end_message;
END of sqhelp;