home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / PCGDOOR.ZIP / READ41B.PAS
Encoding:
Pascal/Delphi Source File  |  1987-04-21  |  13.7 KB  |  396 lines

  1. program reader_41b;
  2. {for pcg201 and above
  3. Herein resides the source code and various comments for READER.COM.
  4.  READER 4.1 is used to view PC Gazette issue 2.01 and later online on BBS's.
  5.  Code written by Robert Flores...PC Gazette, 155 East C St. Suite D,
  6.                                     Upland, CA 91786}
  7.  
  8.  
  9. type
  10.     strtype    = string[15];
  11.     filelabel  = string[12];
  12.     str80      = string[80];
  13.     yesansi    = boolean;
  14.  
  15. var
  16.    i,j,x,y,px,px1,m1,
  17.    max,lftside,
  18.    rtside,p,
  19.    plx,prx,
  20.    curpage,
  21.    lastpage,
  22.    curpart,
  23.    lastpart,
  24.    maxparts,
  25.    code,m2,
  26.    i1,j1,i2,j2   : integer;
  27.    t1            : array[1..500] of str80;
  28.    Strng         : string[90];
  29.    blank,
  30.    dosline       : str80;
  31.    file0,
  32.    file3,
  33.    file2         : text;
  34.    pagetop,
  35.    filename2     : strtype;
  36.    filestrng,
  37.    filename3     : str80;
  38.    filename,
  39.    pagefile      : array[1..6] of filelabel;
  40.    scrollfile    : array[1..6,0..9] of filelabel;
  41.    t2            : array[0..9,1..25] of string[80];
  42.    hlp           : str80;
  43.    numpage,
  44.    maxpages      : array[1..6] of integer;
  45.    secondpage,
  46.    scrollpage    : array[1..6,0..9] of integer;
  47.    scrolling,
  48.    bothsides,
  49.    ok            : boolean;
  50.    fileline      : strtype;
  51.    file1         : file;
  52.    getchar       : char;
  53.  
  54.  
  55.  
  56.  
  57. procedure loadfile(filevar:filelabel); {load scroll file for scrolling long articles}
  58.   begin
  59.      assign(file2,filevar);
  60.      {$i-} reset(file2) {$I+};
  61.      ok:=(ioresult=0);
  62.      if ok then begin
  63.      max:=1;
  64.      if scrollpage[curpart,curpage]=1 then begin m2:=79;m1:=21 end
  65.       else begin m2:=40;m1:=42 end;
  66.      while not eof(file2) do begin
  67.            readln(file2,strng);
  68.            if length(strng)<m2 then strng:=strng+copy(blank,1,m2-length(strng));
  69.            t1[max]:=strng;
  70.            max:=max+1;
  71.      end;
  72.      end;
  73.      close(file2);
  74.      lftside:=1;rtside:=80;bothsides:=true;
  75.      px:=secondpage[curpart,curpage];j:=0;plx:=1;prx:=1;
  76.   end;
  77.  
  78. procedure getparm;        {get parameter for command line}
  79.     var parms: str80 absolute cseg:$80;
  80.         s:str80;
  81.     begin
  82.       s:='';
  83.       while (length(parms)>0) and (parms[1]=' ') do delete(parms,1,1);
  84.       while (length(parms)>0) and (parms[1]<>' ') do begin
  85.             s:=s+parms[1];delete(parms,1,1);
  86.       end;
  87.       if length(s)>0 then filename3:=s else filename3:='COM1';
  88.     end;
  89.  
  90. procedure writefile(var fileline:str80);
  91.     var ry : integer;
  92.     begin
  93.          for ry:=1 to length(fileline) do write(file0,copy(fileline,ry,1));
  94.          write(file0,#13#10);
  95.     end;
  96. procedure writefile1(var fileline:str80);
  97.     var ry : integer;
  98.     begin
  99.          for ry:=1 to length(fileline) do write(file0,copy(fileline,ry,1));
  100.     end;
  101.  
  102.  
  103. procedure Fwrite(col,row : integer ;scrnline : str80);
  104.   begin
  105.        gotoxy(col,row);                    {left over from original program}
  106.        write(scrnline);
  107.   end;
  108.  
  109. procedure writepage;
  110.   begin
  111.        filestrng:=pagetop;
  112.        writefile(filestrng);
  113.  
  114.        for i:=1 to 23 do begin
  115.            writefile(t2[curpage,i]);
  116.  
  117.        end;
  118.   end;
  119.  
  120.  
  121.  
  122. procedure scroller;       {scrolling routine}
  123.   begin
  124.    if bothsides=true then begin plx:=px;prx:=px end;
  125.    filestrng:=pagetop;
  126.    writefile(filestrng);
  127.    filestrng:=t2[curpage,1];
  128.    writefile(filestrng);
  129.    writefile(t2[curpage,2]);
  130.     for j:=px to px+20 do begin
  131.         writefile1(t1[j]);
  132.         if scrollpage[curpart,curpage]=2 then begin
  133.              filestrng:=copy(t1[j+21],1,39);
  134.              writefile1(filestrng);
  135.         end;
  136.         filestrng:=#13+#10;
  137.         if j<px+20 then writefile1(filestrng);
  138.     end;
  139.   end;
  140.  
  141. procedure scrollup;
  142.  
  143.     begin
  144.     if px<1 then px:=1;
  145.     scroller;
  146.     end;
  147.  
  148. procedure scrolldown;
  149.  
  150.     begin
  151.     if px>max-m1 then px:=max-m1;
  152.     if px<1 then px:=1;
  153.     scroller;
  154.     end;
  155.  
  156.  
  157. procedure getpart;         {load a section of pagetops into memory}
  158.    begin
  159.  
  160.         filestrng:='      Loading Section into memory. . . .     ';
  161.         if lastpage<>-1 then filestrng:=pagetop+filestrng;
  162.         writefile(filestrng);
  163.         assign(file2,pagefile[curpart]);
  164.         reset(file2);
  165.         for i:=0 to maxpages[curpart] do begin
  166.             for j:=1 to 25 do readln(file2,t2[i,j]);
  167.         end;
  168.         close(file2);
  169.         curpage:=0;
  170.         if lastpage<>-1 then lastpage:=0;
  171.         if lastpage<>-1 then writepage;
  172.    end;
  173.  
  174.  
  175. procedure startoff;              {Find out what files will be used}
  176.    var ifile : filelabel;
  177.    begin
  178.  
  179.         curpage:=0;lastpage:=-1;curpart:=1;lastpart:=1;scrolling:=false;
  180.         pagetop:=#27+'[2J'+#8+#8+#8+#8;
  181.         assign(file2,'reader.opt');
  182.         reset(file2);
  183.         readln(file2,maxparts);                  {read number of sections}
  184.         for i:=1 to maxparts do begin
  185.             readln(file2,pagefile[i]);           {read name of section file}
  186.             readln(file2,maxpages[i]);           {number of pages in section}
  187.             for j:=0 to maxpages[i] do begin
  188.                readln(file2,scrollpage[i,j]); {check to see if page can scroll}
  189.                if scrollpage[i,j]>0 then begin    {0=no;1=full pg;2=dbl.column}
  190.                    readln(file2,scrollfile[i,j]); {name of scroll file}
  191.                    readln(file2,secondpage[i,j]); {line number for 1st scroll}
  192.                 end;
  193.             end;
  194.         end;
  195.         close(file2);
  196.  
  197.    end;
  198.  
  199. Function getkey(var functionkey : boolean):char;     {check keypress & see if it is a function key}
  200.    var ch : char;
  201.    begin
  202.      repeat
  203.         read(FILE3,ch);
  204.         ch:=upcase(ch);
  205.      until ch in [#9,#10,#13,#32,'0'..'9','?','A'..'F','L','N','P','Q','S','T'];
  206.      getkey:=ch;
  207.    end;
  208.  
  209. procedure movepage;  {Determine what do do with keypress and execute}
  210.    var
  211.       inkey:char;
  212.       functionkey:boolean;
  213.    procedure pagemove(inkey:char; functionkey:boolean);
  214.  
  215.       begin
  216.            case upcase(inkey) of
  217.            '0'..'9': val(inkey,curpage,code);    {change page}
  218.            'A'..'F': begin                       {change section}
  219.                        case upcase(inkey) of
  220.                        'A' : if curpart<>1 then curpart:=1;
  221.                        'B' : if (maxparts>1) and (curpart<>2) then curpart:=2;
  222.                        'C' : if (maxparts>2) and (curpart<>3) then curpart:=3;
  223.                        'D' : if (maxparts>3) and (curpart<>4) then curpart:=4;
  224.                        'E' : if (maxparts>4) and (curpart<>5) then curpart:=5;
  225.                        'F' : if (maxparts>5) and (curpart<>6) then curpart:=6;
  226.                        end;
  227.                        if lastpart<>curpart then getpart;
  228.                        lastpart:=curpart;
  229.                      end;
  230.            'P'     :begin                              {to previous scroll}
  231.                          if scrolling then begin
  232.                           if px>1 then begin
  233.                             px:=px-m1;
  234.                             scrollup;
  235.                           end;
  236.                          end
  237.                          else curpage:=curpage-1;      {or previous page}
  238.                     end;
  239.    #32,#13,'N'     :begin                              {to next scroll}
  240.                          if scrolling then begin
  241.  
  242.                           if px<max-m1 then begin
  243.                             px:=px+m1;
  244.                             scrolldown;
  245.                           end;
  246.                          end
  247.                          else curpage:=curpage+1;      {or next page}
  248.                          if lastpage=-1 then curpage:=0;
  249.                     end;
  250.            #9,'S'  :begin                              {start/end scroll}
  251.                          if scrolling then begin
  252.                             inkey:=#255;
  253.                             scrolling :=false;
  254.                             writepage;
  255.                          end
  256.                          else begin
  257.                           if scrollpage[curpart,curpage]>0 then begin
  258.                             scrolling:=true;
  259.                             filestrng:=pagetop+'                                                            ';
  260.                             writefile(filestrng);
  261.                             filestrng:='   One moment while rest of page is loaded into memory...   ';
  262.                             writefile(filestrng);
  263.                             filestrng:='                                                            ';
  264.                             loadfile(scrollfile[curpart,curpage]);
  265.                             scroller;
  266.                            end
  267.                            else begin
  268.                              filestrng:=#7;
  269.                              writefile1(filestrng);
  270.                            end;
  271.                           end;
  272.                     end;
  273.            #10,'Q'  :begin                       {stop scroll/program}
  274.                        if scrolling then begin
  275.                           inkey:=#255;
  276.                           scrolling:=false;
  277.                           curpage:=curpage+1;
  278.                           if curpage>maxpages[curpart] then curpage:=0;
  279.                           lastpage:=curpage;
  280.                           writepage;
  281.                        end
  282.                        else begin
  283.                          clrscr;
  284.                          filestrng:='Exiting PC Gazette door....';
  285.                          writefile(filestrng);
  286.                          close(file0);
  287.                          close(file3);
  288.                          halt;
  289.                        end;
  290.                     end;
  291.            'T'    : begin                      {to 1st page or top of scroll}
  292.                        if scrolling then begin
  293.                         if px>1 then begin
  294.                           px:=1;
  295.                           scroller;
  296.                         end;
  297.                        end
  298.                        else curpage:=0;
  299.                     end;
  300.            'L'    : begin           {to last page or last of scroll}
  301.                        if scrolling then begin
  302.                         if px<max-m1 then begin
  303.                           px:=max-m1;
  304.                           if px<1 then px:=1;
  305.                           scroller;
  306.                         end;
  307.                        end
  308.                        else curpage:=maxpages[curpart];
  309.                      end;
  310.            '?'    : begin                     {request help}
  311.                          assign(file2,'reader.hlp');
  312.                          reset(file2);
  313.                          for i:=1 to 15 do begin
  314.                              readln(file2,hlp);
  315.                              if i=1 then hlp:=pagetop+hlp;
  316.                              writefile(hlp);
  317.                          end;
  318.                          close(file2);
  319.                     end;
  320.            end;
  321.       end;
  322.       procedure increment;                  {change page}
  323.          begin
  324.               if curpage>maxpages[curpart] then curpage:=maxpages[curpart];
  325.               if curpage<0 then curpage:=0;
  326.               if curpage<>lastpage then begin
  327.                   writepage;
  328.                end;
  329.               lastpage:=curpage;
  330.          end;
  331.    begin
  332.         repeat
  333.               inkey:=#255;
  334.               read(file3,inkey);
  335.               inkey:=upcase(inkey);
  336.               if inkey in [#9,#10,#13,#32,'0'..'9','?','A'..'F','L','N','P','Q','S','T'] then begin
  337.                  pagemove(inkey,functionkey);
  338.                  increment;
  339.               end;
  340.         until upcase(inkey) in [#10,^C];
  341.    end;
  342.  
  343. begin
  344.      blank:='                                                                                ';
  345.      clrscr;
  346.      getparm;          {find out if COM1: or COM2: or CON: will be used}
  347.      assign(file0,filename3);
  348.      rewrite(file0);
  349.      if (filename3='con') or (filename3='CON') then filename3:='kbd:';
  350.      assign(file3,filename3);
  351.      reset(file3);
  352. filestrng:=' ';          {let everyone know what this is and who made it}
  353. writefile(filestrng);
  354. filestrng:='                Aaron A. Aardvark and the Platypus Patrol present';
  355. writefile(filestrng);
  356. filestrng:='═══════════════════════════════════════════════════════════════════════════════';
  357. writefile(filestrng);
  358. filestrng:='   ░░░░░▄░░░░░▄    ░░░░░▄░░░░░▄░░░░░▄░░░░░▄░░░░░▄░░░░░▄░░░░░▄';
  359. writefile(filestrng);
  360. filestrng:='   ░░░█░█░░░█▀▀    ░░░█▀▀░░░█░█ ▀░░░█░░░█▀▀ ░░░█▀ ░░░█▀░░░█▀▀        The';
  361. writefile(filestrng);
  362. filestrng:='   ░░░█░█░░░█      ░░░█░▄░░░█░█ ░░░█▀░░░░░▄ ░░░█  ░░░█ ░░░░░▄     Electronic';
  363. writefile(filestrng);
  364. filestrng:='   ░░░░░█░░░█      ░░░█░█░░░░░█░░░█▀ ░░░█▀▀ ░░░█  ░░░█ ░░░█▀▀      Journal';
  365. writefile(filestrng);
  366. filestrng:='   ░░░█▀▀░░░░░▄    ░░░░░█░░░█░█░░░░░▄░░░░░▄ ░░░█  ░░░█ ░░░░░▄';
  367. writefile(filestrng);
  368. filestrng:='    ▀▀▀   ▀▀▀▀▀     ▀▀▀▀▀ ▀▀▀ ▀ ▀▀▀▀▀ ▀▀▀▀▀  ▀▀▀   ▀▀▀  ▀▀▀▀▀';
  369. writefile(filestrng);
  370. filestrng:='═══════════════════════════════════════════════════════════════════════════════';
  371. writefile(filestrng);
  372. filestrng:=' ';
  373. writefile(filestrng);
  374. filestrng:='                            created by Robert Flores';
  375. writefile(filestrng);
  376. filestrng:=' ';    {modification credit could go here...but let me know first}
  377. writefile(filestrng);
  378. filestrng:='                         Copyright 1987  Robert Flores';
  379. writefile(filestrng);
  380. filestrng:='                          A User-supported Newsletter';
  381. writefile(filestrng);
  382. filestrng:=' ';
  383. writefile(filestrng);
  384. filestrng:='                              Reader version 4.1b';
  385. writefile(filestrng);
  386. startoff;
  387. filestrng:=' ';
  388. writefile(filestrng);
  389. writefile(filestrng);
  390. getpart;
  391. filestrng:='                             Press Enter to begin.';
  392. writefile(filestrng);
  393.         getchar:=#255;
  394.      movepage;
  395. end.               {That's all, folks!! R.F}
  396.