Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-04 - decus/20-0135/vided2.sim
There is 1 other file named vided2.sim in the archive. Click here to see a list.
00010	OPTIONS(/l/e); COMMENT DISPLAY EDITOR. SEE
00020	VISTA.MAN for explanations on the routines used in this program;
00030	EXTERNAL TEXT PROCEDURE conc, front, storbokstav, upcase, compress,
00040	rest, inline, frontstrip, scanto, from, upto, today;
00050	EXTERNAL CHARACTER PROCEDURE findtrigger, fetchar;
00060	EXTERNAL INTEGER PROCEDURE search, scanint;
00070	EXTERNAL INTEGER PROCEDURE scan;
00080	EXTERNAL REF (infile) PROCEDURE findinfile;
00090	EXTERNAL REF (outfile) PROCEDURE findoutfile;
00100	EXTERNAL CHARACTER PROCEDURE getch;
00110	EXTERNAL INTEGER PROCEDURE trmop, gettab, checkint;
00120	EXTERNAL BOOLEAN PROCEDURE puttext, numbered, dotypeout;
00130	EXTERNAL PROCEDURE depchar, outstring, forceout, echo, abort, exit;
00140	EXTERNAL PROCEDURE outchr;
00150	EXTERNAL CLASS mvista, qregister=vided0;
00160	EXTERNAL CLASS vided1;
00170	
00180	vided1 CLASS vided2(tmpoutfile,dot);
00190	BOOLEAN tmpoutfile; CHARACTER dot;
00200	VIRTUAL: PROCEDURE startmic, ! COMMENT closes files and exits;
00210	stop_editing;
00220	BEGIN
     
00230	PROCEDURE adjust_date(line); TEXT line;
00240	COMMENT The first line of the first page of a text file contains a
00250	date of last revision, which is updated with each edit on the file;
00260	BEGIN
00270	  INTEGER datepos;
00280	  INTEGER pos;
00290	  INTEGER after_first_date;
00300	  TEXT todaytext;
00310	  datepos:= right_margin-33;
00320	  IF arg[3] = "NUL:NUL" THEN ! No input file, wholly new file;
00330	  BEGIN line.setpos(datepos); puttext(line,today);
00340	  END ELSE
00350	  BEGIN ! Find existing creation and revision dates on top line;
00360	    pos:= 5;
00370	    loop: line.setpos(pos); scanto(line,'-'); pos:= line.pos;
00380	    IF pos + 7 > line.length THEN
00390	    BEGIN IF after_first_date = 0 THEN GOTO out;
00400	      datepos:= line.strip.length;
00410	      IF datepos + 23 > line.length THEN GOTO out;
00420	      line.setpos(datepos+3); puttext(line,"Revised: ");
00430	      puttext(line,todaytext);
00440	      GOTO out;
00450	    END;
00460	    line.setpos(pos-5);
00470	    IF NOT digit(line.getchar) THEN GOTO loop;
00480	    IF NOT digit(line.getchar) THEN GOTO loop;
00490	    IF NOT digit(line.getchar) THEN GOTO loop;
00500	    IF NOT digit(line.getchar) THEN GOTO loop;
00510	    line.getchar;
00520	    IF NOT digit(line.getchar) THEN GOTO loop;
00530	    IF NOT digit(line.getchar) THEN GOTO loop;
00540	    IF line.getchar NE '-' THEN GOTO loop;
00550	    IF NOT digit(line.getchar) THEN GOTO loop;
00560	    IF NOT digit(line.getchar) THEN GOTO loop;
00570	    IF after_first_date = 0 THEN
00580	    BEGIN
00590	      todaytext:- today;
00600	      IF(line.sub(line.pos-10,10) = todaytext) THEN GOTO out;
00610	      after_first_date:= pos:= line.pos;
00620	      GOTO loop;
00630	    END;
00640	    line.setpos(line.pos-10); puttext(line,todaytext);
00650	  END;
00660	  out:
00670	END;
     
00680	PROCEDURE initialload;
00690	BEGIN COMMENT input the first lines of a new page from the text file
00700	  being edited;
00710	  INTEGER i;
00720	  !z_t(11); IF endpage THEN addff:=TRUE;
00730	  IF addff AND out_pagenumber = 1 THEN out_pagenumber:= 2;
00740	  endpage:= FALSE;
00750	  FOR i:= 0 STEP 1 UNTIL heightm1 DO
00760	  BEGIN
00770	    call(p_editin_inimage);
00780	    screen(i):= editin_image_strip;
00790	  END;
00800	  IF pageheader THEN check_page_number;
00810	  home_the_cursor; !z_t(-11);
00820	END;
     
00830	PROCEDURE check_page_number;
00840	BEGIN COMMENT When editing a text file (with /p setting), each new
00850	  page is given a header with a page number. If a header with a page
00860	  number exists, no new header is created;
00870	  TEXT top_line, newnum; BOOLEAN bad_header;
00880	  INTEGER numstart, found_number;
00890	  IF upto(screen[0],24) =
00900	  "REPLACE WITH HEADER AND NUMBER OF PAGE"
00910	  THEN GOTO addheader;
00920	  IF upto(screen[0],46) =
00930	  page_end_marker
00940	  THEN GOTO addheader;
00950	  find_page: ! Find digits preceded by "PAGE" or "SID" ("SID" =
00960	  "PAGE" in Swedish);
00970	  line_model:= screen(0);
00980	  top_line:- storbokstav(line_model); top_line.setpos(1);
00990	  numstart:= search(top_line,page_word)+1;
01000	  IF numstart > top_line.length THEN
01010	  BEGIN ! "PAGE" not found, look for "SID";
01020	    top_line.setpos(1);
01030	    numstart:= search(top_line,sid_word);
01040	  END;
01050	  IF numstart > top_line.length THEN GOTO addheader;
01060	  COMMENT "PAGE" or "SID" has been found;
01070	  numstart:= numstart+4;
01080	  top_line:- screen[0]; top_line.setpos(numstart);
01090	  WHILE top_line.more DO
01100	  BEGIN IF NOT digit(top_line.getchar) THEN GOTO out;
01110	  END;
01120	  out:
01130	  found_number:= scanint(
01140	  top_line.sub(numstart,top_line.pos-numstart));
01150	  IF found_number NE out_pagenumber THEN
01160	  BEGIN COMMENT change the page number on the top line;
01170	    newnum:- blanks(9); newnum.putint(out_pagenumber);
01180	    newnum:- frontstrip(newnum);
01190	    COMMENT very clumsy code in the next statement. Can be done in a
01200	    more efficient manner;
01210	    screen[0]:= conc(top_line.sub(1,numstart-1),
01220	    newnum,from(top_line,top_line.pos-1),"         ").sub(1,width);
01230	  END;
01240	  IF FALSE THEN addheader:
01250	  BEGIN COMMENT No header with page number found;
01260	    IF out_pagenumber = 1 THEN GOTO exit;
01270	    IF bad_header THEN
01280	    BEGIN
01290	      top_line:- screen[0];
01300	      IF increment > 0 THEN top_line:- from(top_line,6);
01310	      top_line:=
01320	      "REPLACE WITH HEADER AND NUMBER OF PAGE";
01330	    END ELSE
01340	    BEGIN COMMENT add lines for header;
01350	      home_the_cursor; addlines(
01360	      IF sub_header == NOTEXT THEN 2 ELSE 3,FALSE,FALSE);
01370	      top_line:- screen[0];
01380	      IF increment > 0 THEN top_line:- from(top_line,6);
01390	      top_line:= header;
01400	      IF sub_header =/= NOTEXT THEN
01410	      BEGIN COMMENT Add subheader;
01420	        top_line:- screen[1];
01430	        IF increment > 0 THEN top_line:- from(top_line,6);
01440	        top_line:= sub_header;
01450	      END;
01460	      bad_header:= TRUE;
01470	    END;
01480	    GOTO find_page;
01490	  END;
01500	  exit: line_model:= NOTEXT;
01510	END;
     
01520	PROCEDURE append_page;
01530	COMMENT Convert two pages into one page by appending the next page
01540	at the end of the current page, &A VIDED command;
01550	BEGIN INTEGER i, startfill;
01560	  startfill:= written_lines+1;
01570	  move_the_cursor_to(0,heightm1); OPTIONS(/-W);
01580	  FOR startfill:= startfill STEP -1 UNTIL height-4 DO
01590	  BEGIN IF addaltmode THEN outchr(terminalout,altmode,1);
01600	    outchr(terminalout,linefeed,1);
01610	    call(p_scroll);
01620	  END;
01630	  endpage:= FALSE;
01640	  FOR i:= startfill STEP 1 UNTIL startfill+2 DO
01650	  BEGIN move_the_cursor_to(0,i);
01660	    call(p_editin_inimage); outtext(editin_image_strip);
01670	  END; OPTIONS(/W);
01680	  IF pageheader AND NOT endpage THEN
01690	  BEGIN COMMENT Check if this page has a proper header;
01700	    line_model:= screen(startfill); upcase(line_model);
01710	    line_model.setpos(1);
01720	    IF search(line_model,page_word) <
01730	    line_model.length THEN GOTO hasheader;
01740	    line_model.setpos(1);
01750	    IF search(line_model,sid_word) >=
01760	    line_model.length THEN GOTO afterheader;
01770	    hasheader:
01780	    i:= IF screen(startfill+1).strip.length <= first_text_pos
01790	    THEN 1 ELSE
01800	    IF screen(startfill+2).strip.length <= first_text_pos
01810	    THEN 2 ELSE 0;
01820	    IF i > 0 THEN
01830	    BEGIN move_the_cursor_to(0,startfill);
01840	      endpage:= TRUE;
01850	      removelines(i); startfill:= startfill-i;
01860	      endpage:= FALSE;
01870	      afterheader: line_model:= NOTEXT;
01880	    END;
01890	  END;
01900	  startfill:= startfill+3;
01910	  FOR i:= startfill STEP 1 UNTIL heightm1 DO
01920	  BEGIN move_the_cursor_to(0,i);
01930	    call(p_editin_inimage);
01940	    outtext(editin_image_strip);
01950	  END;
01960	  pagenumber:= pagenumber+1;
01970	END;
     
01980	PROCEDURE removelines(number); INTEGER number;
01990	COMMENT &K VIDED command removes lines from the screen;
02000	BEGIN
02010	  INTEGER i, vpos, hpos, startline;
02020	  !z_t(12); startline:= vpos:= q_verticalpos;
02030	  hpos:= q_horizontalpos;
02040	  save_lengthes;
02050	  IF hpos > 0 THEN
02060	  BEGIN COMMENT Blank the rest of the line at which the &K command
02070	    was given;
02080	    make_blank(width-hpos);
02090	    COMMENT One (partial) line has been removed (blanked);
02100	    number:= number-1; startline:= startline+1;
02110	    IF number > 0 AND startline > heightm1 THEN
02120	    BEGIN call(p_scroll);
02130	      startline:= startline-1;
02140	      vpos:= vpos-1;
02150	    END;
02160	  END;
02170	  IF number > 0 THEN
02180	  BEGIN
02190	    IF number <= heightm1 - startline THEN
02200	    BEGIN COMMENT All lines to be removed are inside the screen;
02210	      shift(startline+number,startline,height-startline-number);
02220	      restore_lines(startline,heightm1-number);
02230	      startline:= height-number;
02240	    END ELSE
02250	    BEGIN COMMENT Some lines below the screen are to be removed;
02260	      move_the_cursor_to(0,startline);
02270	      FOR i:= number - height + startline
02280	      STEP -1 UNTIL 1 DO
02290	      BEGIN move_the_cursor_to(0,startline);
02300	        cover_length:= 0;
02310	        call(p_one_more_line_please);
02320	      END;
02330	      screen_length(startline):=
02340	      screen(startline).strip.length;
02350	    END;
02360	    FOR i:= startline STEP 1 UNTIL heightm1 DO
02370	    BEGIN COMMENT Input lines to fill empty space;
02380	      move_the_cursor_to(0,i);
02390	      screen(i):= NOTEXT;
02400	      cover_length:= screen_length(i);
02410	      call(p_one_more_line_please);
02420	    END;
02430	  END;
02440	  synchronize(hpos,vpos); !z_t(-12);
02450	END;
     
02460	PROCEDURE z_scroll(steps); INTEGER steps;
02470	COMMENT &Z VIDED command, scrolls screen and inputs lines;
02480	BEGIN INTEGER i, hpos, vpos;
02490	  hpos:= q_horizontalpos; vpos:= q_verticalpos-steps;
02500	  IF vpos < 0 THEN
02510	  BEGIN hpos:= vpos:= 0;
02520	  END;
02530	  move_the_cursor_to(0,heightm1);
02540	  FOR i:= 1 STEP 1 UNTIL steps DO
02550	  BEGIN outchr(terminalout,linefeed,1);
02560	    call(p_scroll);
02570	  END;
02580	  move_the_cursor_to(hpos,vpos);
02590	END;
     
02600	PROCEDURE removechars(number); INTEGER number;
02610	BEGIN COMMENT &D VIDED command, removes chars from line;
02620	  INTEGER hpos, vpos, coverlength, i;
02630	  TEXT thisline, thisstripped;
02640	  IF number = 0 THEN number:= 1;
02650	  hpos:= q_horizontalpos; vpos:= q_verticalpos;
02660	  IF number > width-hpos THEN number:= width-hpos;
02670	  thisline:- screen(q_verticalpos);
02680	  thisstripped:- thisline.strip;
02690	  coverlength:= thisstripped.length-hpos-number;
02700	  IF coverlength > 0 THEN
02710	  outtext(thisline.sub(hpos+1+number,coverlength));
02720	  FOR i:= 1 STEP 1 UNTIL number DO
02730	  outchar(' ');
02740	  move_the_cursor_to(hpos,vpos);
02750	END;
     
02760	PROCEDURE removeword;
02770	BEGIN COMMENT &W VIDED command removes last written word;
02780	  INTEGER vertpos, horpos, coverlength, wordpos, wordlength;
02790	  TEXT thisline, thisstripped;
02800	  vertpos:= q_verticalpos; horpos:= q_horizontalpos;
02810	  loop:
02820	  thisline:- screen(vertpos);
02830	  thisstripped:- thisline.sub(1,horpos).strip;
02840	  IF thisstripped.length = 0 AND vertpos > 0 THEN
02850	  BEGIN vertpos:= vertpos-1; horpos:= width;
02860	    GOTO loop;
02870	  END;
02880	  FOR wordpos:= thisstripped.length STEP -1 UNTIL 1 DO
02890	  IF thisstripped.sub(wordpos,1) = " " THEN GOTO out;
02900	  out: wordlength:= thisstripped.length-wordpos;
02910	  move_the_cursor_to(wordpos,vertpos);
02920	  make_blank(wordlength);
02930	  move_the_cursor_to(wordpos,vertpos);
02940	END;
     
02950	PROCEDURE search_for(qname,commandchar);
02960	COMMENT &S and &N VIDED commands, searches for key in text file;
02970	TEXT qname; CHARACTER commandchar;
02980	BEGIN INTEGER hpos, vpos;
02990	  !z_t(13); hpos:= q_horizontalpos; vpos:= q_verticalpos;
03000	  storbokstav(qname); ! Upcase key to find up-low-case equivalents;
03010	  scan_screen:
03020	  line_model:= screen(vpos); storbokstav(line_model);
03030	  line_model.setpos(hpos+1);
03040	  hpos:= search(line_model,qname); ! Search first line;
03050	  IF hpos <= width THEN GOTO found;
03060	  FOR vpos:= vpos+1 STEP 1 UNTIL heightm1 DO
03070	  BEGIN ! Search lines on the screen;
03080	    line_model:= screen(vpos);
03090	    storbokstav(line_model);
03100	    line_model.setpos(1);
03110	    hpos:= search(line_model,qname);
03120	    IF hpos <= width THEN GOTO found;
03130	  END;
03140	  IF commandchar = 'S' THEN GOTO out;
03150	  COMMENT &S command stops, &N command searches after end of screen;
03160	  IF q_display_output THEN
03170	  BEGIN COMMENT Silent search;
03180	    cancel_display;
03190	    terminalout.outtext("Searching for """);
03200	    terminalout.outtext(qname); terminalout.outtext(""".");
03210	    terminalout.outimage;
03220	  END;
03230	  vpos:= heightm1; move_the_cursor_to(0,vpos);
03240	  printing:= FALSE;
03250	  WHILE NOT editin.endfile OR lower_lines =/= NONE DO
03260	  BEGIN
03270	    IF endpage THEN
03280	    BEGIN printpage; initialload; vpos:= 0; hpos:= 0;
03290	      GOTO scan_screen;
03300	    END;
03310	    call(p_scroll); ! very inefficient, can be optimized;
03320	    line_model:= screen(vpos); storbokstav(line_model);
03330	    line_model.setpos(1);
03340	    hpos:= search(line_model,qname); ! Search again;
03350	    IF hpos <= width THEN GOTO found;
03360	  END;
03370	  warning("Cannot find SEARCH text.");
03380	  IF NOT q_display_output THEN resume_display; home_the_cursor;
03390	  IF FALSE THEN found:
03400	  BEGIN
03410	    IF NOT q_display_output THEN resume_display;
03420	    move_the_cursor_to(hpos-1+qname.length,vpos);
03430	  END;
03440	  out: printing:= TRUE; line_model:= NOTEXT; !z_t(-13);
03450	END;
     
03460	PROCEDURE blank_front;
03470	COMMENT &U VIDED command blanks initial part of line;
03480	BEGIN INTEGER hpos, vpos;
03490	  hpos:= q_horizontalpos; vpos:= q_verticalpos;
03500	  move_the_cursor_to(0,vpos);
03510	  make_blank(hpos);
03520	  move_the_cursor_to(0,vpos);
03530	END;
     
03540	PROCEDURE settab(position,modechar);
03550	CHARACTER modechar; INTEGER position;
03560	COMMENT &T VIDED commands;
03570	BEGIN INTEGER i;
03580	  IF modechar = 'S' OR modechar = 's' THEN ! &TS command;
03590	  tab_position(position):= TRUE ELSE
03600	  BEGIN COMMENT &TZ or &TR VIDED commands;
03610	    FOR i:= 1 STEP 1 UNTIL width DO tab_position(i):= FALSE;
03620	    IF modechar = 'R' OR modechar = 'r' THEN
03630	    BEGIN
03640	      tab_position(left_margin):= TRUE;
03650	      FOR i:= 8 STEP 8 UNTIL width DO tab_position(i):= TRUE;
03660	    END;
03670	  END;
03680	END;
     
03690	PROCEDURE margset(secondchar,margpos);
03700	COMMENT &M VIDED commands, setting margins;
03710	CHARACTER secondchar; INTEGER margpos;
03720	BEGIN
03730	  IF margpos > widthm1 THEN margpos:= widthm1 ELSE
03740	  IF margpos < 0 THEN margpos:= 0;
03750	  IF secondchar = 'R' OR secondchar = 'r' THEN
03760	  right_margin:= margpos ELSE
03770	  IF secondchar = 'L' OR secondchar = 'l' THEN
03780	  BEGIN
03790	    IF margpos < first_text_pos THEN
03800	    BEGIN warning(
03810	      "Left margin must be >= 8 for line numbered file.");
03820	      margpos:= 8;
03830	    END;
03840	    left_margin:= margpos;
03850	  END;
03860	  margin_width:= right_margin-left_margin;
03870	  IF margin_width <= 0 THEN
03880	  BEGIN warning("Illegal margin values.");
03890	    left_margin:= 8; right_margin:= 68;
03900	  END;
03910	END;
     
03920	TEXT PROCEDURE warning(message); NAME message; TEXT message;
03930	BEGIN INTEGER hpos, vpos, sl0;
03940	  hpos:= q_horizontalpos; vpos:= q_verticalpos;
03950	  home_the_cursor;
03960	  INSPECT terminalin DO INSPECT terminalout DO
03970	  BEGIN
03980	    outtext("?VIDED - ");
03990	    outtext(message); outtext("   ");
04000	    sl0:= image.pos-1;  breakoutimage; outimage;
04010	    outtext("To continue type RETURN. "); breakoutimage;
04020	    inimage; warning:- image.strip;
04030	  END;
04040	  IF q_display_output THEN
04050	  BEGIN
04060	    home_the_cursor; outtext(screen[0].sub(1,sl0));
04070	    move_the_cursor_to(0,1); outtext(screen[1].sub(1,39));
04080	  END;
04090	  move_the_cursor_to(hpos,vpos);
04100	END;
     
04110	PROCEDURE justify(lines,evenmargin);
04120	INTEGER lines; BOOLEAN evenmargin;
04130	BEGIN COMMENT &J VIDED command;
04140	  TEXT longline, printline;
04150	  INTEGER last_line_in, printcount, vpos, divpos, line_number;
04160	  INTEGER hpos, part_length, leftmark;
     
04170	  PROCEDURE putline;
04180	  BEGIN COMMENT output one line of &J-justified text;
04190	    !z_t(14); printcount:= printcount+1;
04200	    IF printcount <= lines THEN
04210	    BEGIN
04220	      IF printcount = 1 THEN
04230	      BEGIN IF hpos < left_margin THEN
04240	        outtext(line_model.sub(1,left_margin-hpos));
04250	      END ELSE
04260	      outtext(line_model.sub(1,left_margin-leftmark+1));
04270	      outtext(printline);
04280	      make_blank(width-q_horizontalpos);
04290	    END ELSE
04300	    BEGIN
04310	      addlines(1,TRUE,FALSE);
04320	      move_the_cursor_to(left_margin,vpos);
04330	      outtext(printline);
04340	    END;
04350	    IF vpos = heightm1 THEN
04360	    BEGIN move_the_cursor_to(leftmark-1,heightm1);
04370	      outchr(terminalout,linefeed,1);
04380	      call(p_scroll);
04390	      move_the_cursor_to(leftmark-1,heightm1);
04400	    END ELSE
04410	    BEGIN vpos:= vpos+1;
04420	      move_the_cursor_to(first_text_pos,vpos);
04430	    END;
04440	    part_length:= margin_width; !z_t(-14);
04450	  END of putline;
     
04460	  COMMENT Main part of the justify procedure (&J VIDED command);
04470	  !z_t(15); vpos:= q_verticalpos; save_lengthes;
04480	  leftmark:= first_text_pos+1;
04490	  IF q_horizontalpos >= right_margin OR q_horizontalpos < leftmark-1
04500	  THEN move_the_cursor_to(leftmark-1,vpos);
04510	  hpos:= q_horizontalpos;
04520	  IF lines = 0 THEN
04530	  BEGIN COMMENT user did not give any size of area to be justify,
04540	    justify to next blank line or line beginning with a dot;
04550	    IF vpos < heightm1 THEN
04560	    BEGIN IF screen_length[vpos] = 0 THEN
04570	      BEGIN
04580	        vpos:= vpos+1; hpos:= 0;
04590	        move_the_cursor_to(0,vpos);
04600	      END;
04610	    END;
04620	    FOR last_line_in:= vpos STEP 1 UNTIL heightm1 DO
04630	    BEGIN
04640	      IF fetchar(screen[last_line_in],leftmark) = dot THEN
04650	      GOTO last_found;
04660	      IF screen_length[last_line_in] <= leftmark-1 THEN GOTO
04670	      last_found;
04680	    END;
04690	    last_line_in:= height;
04700	    last_found: last_line_in:= last_line_in-1;
04710	  END ELSE
04720	  BEGIN last_line_in:= vpos+lines-1;
04730	    IF last_line_in > heightm1 THEN last_line_in:= heightm1;
04740	  END;
04750	  lines:= last_line_in-vpos+1;
04760	
04770	  COMMENT We now know how many lines to justify, create a long
04780	  text in which to store the entire text to be justified;
04790	  longline:- blanks(width*(lines)+1);
04800	  COMMENT Put first line into this long buffer;
04810	  IF screen_length(vpos) > hpos THEN
04820	  puttext(longline,frontstrip(screen(vpos)
04830	  .sub(hpos+1,screen_length(vpos)-hpos)));
04840	  COMMENT scan through lines to be included in paragraph;
04850	  FOR line_number:= vpos+1 STEP 1 UNTIL last_line_in DO
04860	  BEGIN
04870	    IF fetchar(screen[line_number-1],
04880	    screen_length[line_number-1]) = '-' THEN
04890	    warning("There is a line ending with a dash (-).");
04900	    IF fetchar(screen[line_number],1) = '*' THEN
04910	    BEGIN COMMENT do not include page_end_marker in text;
04920	      IF screen[line_number].strip = page_end_marker THEN
04930	      GOTO loop;
04940	    END;
04950	    COMMENT space between words on successive lines;
04960	    IF screen_length(line_number-1) < width OR
04970	    fetchar(screen[line_number],1) = ' ' THEN
04980	    longline.setpos(longline.pos+1);
04990	    puttext(longline,frontstrip(screen[line_number].
05000	    sub(leftmark,screen_length[line_number]-leftmark+1)));
05010	    loop:
05020	  END;
05030	  part_length:= right_margin-hpos;
05040	  IF part_length > margin_width THEN
05050	  part_length:= margin_width;
05060	  longline:- longline.sub(1,longline.pos);
05070	  COMMENT split the combined text into suitable line segments
05080	  to output on succesive lines;
05090	  WHILE longline.length > part_length DO
05100	  BEGIN COMMENT find space do divide line at;
05110	    FOR divpos:= part_length+1 STEP -1 UNTIL 1 DO
05120	    BEGIN
05130	      IF fetchar(longline,divpos) = ' ' THEN
05140	      BEGIN
05150	        IF NOT digit(fetchar(longline,divpos-1)) THEN GOTO
05160	        divide;
05170	        IF NOT digit(fetchar(longline,divpos+1)) THEN GOTO
05180	        divide;
05190	      END;
05200	    END;
05210	    printline:- longline.sub(1,part_length);
05220	    longline:- longline.sub(part_length+1,
05230	    longline.length-part_length);
05240	    IF FALSE THEN
05250	    divide:
05260	    BEGIN
05270	      printline:- longline.sub(1,divpos-1);
05280	      longline:-
05290	      longline.sub(divpos+1,longline.length-divpos);
05300	    END;
05310	    putline;
05320	  END;
05330	  COMMENT output last line of paragraph;
05340	  IF longline =/= NOTEXT THEN
05350	  BEGIN printline:- longline; putline;
05360	  END;
05370	  COMMENT IF paragraph became shorter, remove the extra lines;
05380	  IF printcount < lines THEN
05390	  removelines(lines-printcount); !z_t(-15);
05400	END;
     
05410	PROCEDURE control_c;
05420	BEGIN COMMENT action of &c vided command;
05430	  INTEGER hor, vert;
05440	  hor:= q_horizontalpos; vert:= q_verticalpos;
05450	  synchronize(0,heightm1); ! Cursor down to bottom of screen;
05460	  terminalout.outimage; terminalout.outimage;
05470	  COMMENT restore switch settings;
05480	  trmop(8r2005,terminalout,ttytab); echon;
05490	  exit(0);
05500	  COMMENT user has typed continue or reenter-proceed. Set switches
05510	  and restore screen;
05520	  set_tty_tab;
05530	  q_horizontalpos:= hor; q_verticalpos:= vert;
05540	  restore_screen(q_verticalpos);
05550	END;
     
05560	PROCEDURE position_tab(tabcharhandling); BOOLEAN tabcharhandling;
05570	COMMENT User has input a horizontal tab <HT> character. Move to the
05580	next tabulator point;
05590	BEGIN
05600	  INTEGER i;
05610	  INTEGER hpos, vpos;
05620	  hpos:= q_horizontalpos; vpos:= q_verticalpos;
05630	  IF terminaltype = newelite OR terminaltype = newkthelite THEN
05640	  q_horizontalpos:= (q_horizontalpos+8)//8*8;
05650	  IF tabcharhandling AND
05660	  (terminaltype = minitec OR terminaltype = 0) THEN
05670	  BEGIN
05680	    synchronize(0,vpos);
05690	    hpos:= hpos+8; IF hpos > width THEN
05700	    restore_screen(q_verticalpos) ELSE
05710	    outtext(screen(vpos).sub(1,hpos));
05720	    hpos:= hpos-8;
05730	  END;
05740	  FOR i:= hpos+1 STEP 1 UNTIL widthm1 DO
05750	  IF tab_position(i) THEN GOTO out;
05760	  i:= widthm1; IF terminaltype >= elite AND
05770	  terminaltype <= newkthelite THEN synchronize(i,vpos);
05780	
05790	  out: move_the_cursor_to(i,vpos);
05800	END;
     
05810	PROCEDURE pagedivide;
05820	BEGIN COMMENT &PI VIDED command to split pages;
05830	  INTEGER vpos, i;
05840	  !z_t(16); vpos:= q_verticalpos;
05850	  cancel_display;
05860	  COMMENT split in the middle of a line;
05870	  IF q_horizontalpos > 0 THEN
05880	  BEGIN addlines(1,TRUE,FALSE); vpos:= vpos+1;
05890	  END;
05900	  COMMENT remove page_end_marker before splitting;
05910	  FOR i:= vpos STEP 1 UNTIL heightm1 DO
05920	  BEGIN
05930	    IF screen[i].strip = page_end_marker THEN
05940	    BEGIN
05950	      move_the_cursor_to(0,i); removelines(1);
05960	      move_the_cursor_to(0,vpos);
05970	    END;
05980	  END;
05990	  COMMENT Scroll out lines to previous page;
06000	  move_the_cursor_to(0,heightm1);
06010	  printing:= FALSE;
06020	  FOR i:= 1 STEP 1 UNTIL vpos DO
06030	  BEGIN call(p_scroll);
06040	    move_the_cursor_to(0,heightm1);
06050	  END;
06060	  printing:= TRUE;
06070	  COMMENT Output previous page to the output text file;
06080	  empty_top_of_page; addff:= TRUE;
06090	  IF out_pagenumber = 1 THEN out_pagenumber:= 2;
06100	  IF pageheader THEN check_page_number;
06110	  home_the_cursor; resume_display; !z_t(-16);
06120	END;
     
06130	PROCEDURE newpages(number, findend);
06140	INTEGER number; BOOLEAN findend; ! findend = &PnE command;
06150	COMMENT &P, &PnE and &PnN VIDED commands, move to given page;
06160	BEGIN INTEGER i; BOOLEAN addpage; CHARACTER c;
06170	  !z_t(17); IF addaltmode THEN outchr(terminalout,altmode,1);
06180	  outchr(terminalout,erasescreen,1);
06190	  COMMENT notify user before time consuming action;
06200	  IF number > 1 THEN forceout(terminalout);
06210	  pagenumber:= pagenumber+number;
06220	  COMMENT output and input "number" pages;
06230	  FOR i:= 1 STEP 1 UNTIL number DO
06240	  BEGIN
06250	    printpage;
06260	    IF NOT addpage AND editin.endfile THEN
06270	    BEGIN
06280	      INSPECT terminalout DO INSPECT terminalin DO
06290	      BEGIN
06300	        IF NOT q_echoenabled THEN echon;
06310	        outtext("No such page? Shall we?"); outimage;
06320	        loop: outtext("1 Add a new page"); outimage;
06330	        outtext("2 Finish the editing"); outimage;
06340	        inimage; c:= inchar;
06350	        IF c = '1' THEN addpage:= TRUE ELSE
06360	        IF c = '2' THEN stop_editing ELSE
06370	        BEGIN outtext("Answer 1 or 2"); outimage;
06380	          GOTO loop;
06390	        END;
06400	      END;
06410	    END;
06420	    initialload; addff:= TRUE;
06430	  END;
06440	  out:
06450	  home_the_cursor;
06460	  IF number = 0 THEN findtop; ! &P0 or &P0E command;
06470	  IF findend THEN ! &PnE command;
06480	  BEGIN
06490	    move_the_cursor_to(0,heightm1);
06500	    printing:= FALSE;
06510	    WHILE (NOT endpage AND NOT editin.endfile)
06520	    OR lower_lines =/= NONE DO call(p_scroll);
06530	    printing:= TRUE;
06540	  END;
06550	  restore_screen(q_verticalpos); !z_t(-17);
06560	END;
     
06570	PROCEDURE findtop;
06580	COMMENT move screen to the top of the current page;
06590	BEGIN INTEGER i, start, stop;
06600	  TEXT exchanger;
06610	  start:= heightm1; stop:= heightm1-top_fill;
06620	  IF stop < 0 THEN stop:= 0;
06630	  FOR i:= start STEP -1 UNTIL stop DO
06640	  push_line(screen[i]);
06650	  FOR top_fill:= top_fill STEP -1 UNTIL height DO
06660	  push_line(top_of_page[top_fill]);
06670	  IF top_fill > heightm1 THEN top_fill:= heightm1;
06680	  stop:= heightm1-top_fill-1;
06690	  FOR i:= 0 STEP 1 UNTIL stop DO
06700	  exchange_lines(heightm1-i,heightm1-i-top_fill-1);
06710	  FOR i:= 0 STEP 1 UNTIL top_fill DO
06720	  BEGIN exchanger:- screen(i);
06730	    screen[i]:- top_of_page[i];
06740	    top_of_page[i]:- exchanger;
06750	  END;
06760	  top_fill:= -1;
06770	END;
     
06780	PROCEDURE finalwrite;
06790	COMMENT &E VIDED command, input and output the rest of
06800	the pages and print final message;
06810	BEGIN
06820	  INTEGER i;
06830	  IF addaltmode THEN outchr(terminalout,altmode,1);
06840	  outchr(terminalout,erasescreen,1);
06850	  printpage;
06860	  WHILE NOT editin.endfile DO
06870	  BEGIN
06880	    initialload; addff:= TRUE;
06890	    printpage;
06900	  END;
06910	  blank_the_screen;
06920	  outtext("VIDED IS FINISHING.");
06930	  outimage;
06940	  outtext(" INPUT FILE """);
06950	  outtext(arg[3]); outchar('"'); outimage;
06960	  outtext(" OUTPUT FILE """);
06970	  outtext(arg[(IF tmpoutfile THEN 3 ELSE 1)]); outchar('"');
06980	  forceout(terminalout);
06990	
07000	END;
     
07010	PROCEDURE set_tty_tab;
07020	BEGIN COMMENT set TRMOP .TTY TAB setting to govern monitor handling
07030	of <HT> characters;
07040	  ttytab:= IF terminaltype = minitec
07050	  THEN 8r1005 ELSE 8r2005;
07060	  ttytab:= trmop(ttytab,terminalout,1);
07070	  IF terminaltype = infoton OR terminaltype = teletec THEN
07080	  ttytab:= 0;
07090	END;
     
07100	COMMENT Main part of the class VIDED2, initialize variables;
07110	scrollallow:= TRUE; first_input_line:= TRUE;
07120	out_pagenumber:= 1;
07130	page_word:- copy("PAGE "); sid_word:- copy("SID ");
07140	header:- blanks(IF increment > 0 THEN width-5 ELSE width);
07150	header:= "REPLACE WITH HEADER AND NUMBER OF PAGE 00";
07160	command:- blanks(width);
07170	restorechar:= erasescreen;
07180	line_model:- blanks(width);
07190	control_d:= char(4); control_f:= char(6);
07200	control_v:= char(22);
07210	control_u:=IF terminaltype = cdc71310s THEN char(1) ELSE  char(21);
07220	control_w:= char(23);
07230	margin_width:= right_margin-left_margin;
07240	set_tty_tab;
07250	settab(0,'R'); ! Initial default tab settings;
07260	initialload; pagenumber:= 1; ! Load first page;
07270	IF pageheader THEN adjust_date(screen[0]);
07280	restore_screen(0); ! Display first page;
07290	top_size:= pageheight;
07300	FOR top_fill:= top_size STEP -1 UNTIL 0 DO
07310	top_of_page[top_fill]:- blanks(width);
07320	INNER;
07330	COMMENT here we come when user has made the &E VIDED command;
07340	finalwrite;
07350	trmop(8r2005,terminalout,ttytab);
07360	startmic;
07370	END;