home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / APPS / BUSINESS / TTYPRT36.ZIP / ED_FILE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-01-11  |  7.4 KB  |  189 lines

  1. {These are support routines to the mini-editor (file actions)}
  2.  
  3. PROCEDURE savefile;
  4. (*****************************************************************************
  5. saves the current mini editor text to a file
  6. ******************************************************************************)
  7. VAR i:INTEGER;
  8. LABEL loop;
  9. BEGIN
  10.     TextColor(LightGreen); TextBackGround(Black); clrscr;
  11.     WRITELN('Save message text into a disk file');
  12.     WRITELN;
  13.     TextColor(LightCyan); WRITE('     Options:  ');
  14.     TextColor(LightRed); WRITE('*    ');
  15.     TextColor(Cyan); WRITELN(#26,' For directory of files');
  16.     TextColor(LightRed); WRITE('               .    ');
  17.     TextColor(Cyan); WRITELN(#26,' To change current directory');
  18.     TextColor(LightRed); WRITE('             <esc>  ');
  19.     TextColor(Cyan); WRITELN(#26,' To abort saving file and continue');
  20.     TextColor(LightRed); WRITE('            <enter> ');
  21.     TextColor(Cyan); WRITELN(#26,' To save message into "',sfn,'"');
  22.     TextColor(LightRed); WRITE('               ?    ');
  23.     TextColor(Cyan); WRITELN(#26,' Help!  Explain this to me');
  24.     TextColor(LightRed); WRITE('            _______ ');
  25.     TextColor(Cyan); WRITELN(#26,' Or enter a different filename for message text');
  26. loop:
  27.     TextBackGround(Black);  WRITELN;
  28.     TextColor(Yellow); WRITE('Enter filename to save message text (or other option) ',#26,' ');
  29.     TextBackGround(Blue); TextColor(LightGray);
  30.     c:=READKEY;
  31.     WRITE(c);
  32.     CASE c OF
  33.     '?' : BEGIN                         {help}
  34.               help_msg('edsave');
  35.               clrscr;
  36.               GOTO loop;
  37.           END;
  38.     '*' : BEGIN                         {file directory}
  39.               disp_dir;
  40.               GOTO loop
  41.           END;
  42.     '.' : BEGIN                         {change directory}
  43.               chg_dir;
  44.               GOTO loop
  45.           END;
  46.     #27 : BEGIN                         {abort - no action}
  47.               dr_frame;
  48.               dr_page;                  {redraw screen}
  49.               exit
  50.           END;
  51.     ^M  : ;                             {no action}
  52.     ELSE  BEGIN
  53.               sfn:=get_fn(c);           {filename entered, so use it}
  54.               WRITELN
  55.           END;
  56.     END; {case}
  57.  
  58.     ASSIGN(io_file,sfn);                {existing file check ...}
  59.     {$I-} RESET(io_file); {$I+}         {open file for reading}
  60.     err:=IORESULT;
  61.     IF err=0 THEN BEGIN
  62.         WRITELN; TextColor(lightMagenta);
  63.         WRITELN('File already exists.');  TextColor(Yellow);
  64.         WRITE('  Do you want to overwrite current file, ',sfn,'?');
  65.         c:=READKEY; WRITELN;
  66.         IF NOT (c IN ['y','Y']) THEN GOTO loop;
  67.         CLOSE(io_file)
  68.     END;
  69.  
  70.     {$I-} REWRITE(io_file); {$I+}       {open file for writing}
  71.     err:=IORESULT;
  72.     IF err <> 0 THEN BEGIN
  73.         WRITELN; TextColor(LightMagenta+Blink);
  74.         WRITELN('ERR #',err,':  Problem opening output file!');
  75.         beep; TextColor(Cyan);
  76.         WRITE('Strike any key to continue ...');
  77.         c:=READKEY
  78.     END ELSE BEGIN
  79.         WRITE('Saving message to file ',sfn,' ... ');
  80.         FOR i:=1 TO last_ln+1 DO          {write ed_text to file}
  81.             WRITELN(io_file,ed_text[i]);
  82.         WRITELN('done!');
  83.         CLOSE(io_file)
  84.     END;
  85.     dr_frame; dr_page                   {redraw screen}
  86. END; {PROCEDURE savefile}
  87.  
  88. PROCEDURE readfile(dsp_menu:BOOLEAN);
  89. (*****************************************************************************
  90. reads an file into the mini editor - searches for file along path!
  91. ******************************************************************************)
  92. VAR org_ln:INTEGER;
  93.     found,stop_msg:BOOLEAN;
  94. LABEL loop;
  95. BEGIN
  96.     IF dsp_menu THEN BEGIN
  97.         TextColor(LightGreen); TextBackGround(Black); clrscr;
  98.         WRITELN('Read (insert) disk file into message');
  99.         WRITELN; TextColor(LightCyan);
  100.         WRITE('     Options:  ');
  101.         TextColor(LightRed); WRITE('*    ');
  102.         TextColor(Cyan); WRITELN(#26,' For directory of files');
  103.         TextColor(LightRed); WRITE('               .    ');
  104.         TextColor(Cyan); WRITELN(#26,' To change to different directory');
  105.         TextColor(LightRed); WRITE('             <esc>  ');
  106.         TextColor(Cyan); WRITELN(#26,' To abort reading file and return to editor');
  107.         TextColor(LightRed); WRITE('            <enter> ');
  108.         TextColor(Cyan); WRITELN(#26,' To read message from "',rfn,'"');
  109.         TextColor(LightRed); WRITE('               ?   ');
  110.         TextColor(Cyan); WRITELN(#26,' Help!  Explain this to me');
  111.         TextColor(LightRed); WRITE('            _______ ');
  112.         TextColor(Cyan); WRITELN(#26,' Or enter a different filename to read text from');
  113.         WRITELN;
  114.         WRITELN('Note:  file will be inserted starting at current line of the message;');
  115.         WRITELN('       any subsequent text will be overwritten by the inserted file.');
  116. loop:
  117.         WRITELN;
  118.         TextColor(Yellow); WRITE('Enter filename to insert into message (or other option) ',#26,' ');
  119.         TextBackGround(Blue); TextColor(LightGray);
  120.         c:=READKEY;
  121.         WRITE(c);
  122.         CASE c OF
  123.         '?' : BEGIN                         {help}
  124.                   help_msg('edread');
  125.                   clrscr;
  126.                   GOTO loop;
  127.               END;
  128.         '*' : BEGIN                         {file directory}
  129.                   disp_dir;
  130.                   GOTO loop
  131.               END;
  132.         '.' : BEGIN                         {change directory}
  133.                   chg_dir;
  134.                   GOTO loop
  135.               END;
  136.         #27 : BEGIN                         {abort - no action}
  137.                   dr_frame;
  138.                   dr_page;                  {redraw screen}
  139.                   exit
  140.               END;
  141.         ^M  : ;                             {no action}
  142.         ELSE  BEGIN
  143.                   rfn:=get_fn(c);           {filename entered, so use it}
  144.                   WRITELN;
  145.               END;
  146.         END; {case}
  147.     END; {if skip_menu}
  148.  
  149.     org_ln:=ln;
  150.     WRITELN; TextColor(Cyan);
  151.     stop_msg:=FALSE;
  152.     IF not open_fn(rfn) THEN BEGIN         {open given file}
  153.         beep; TextColor(LightMagenta+Blink);
  154.         WRITELN('File: ',rfn,' not found!  ');
  155.         stop_msg:=TRUE
  156.     END ELSE BEGIN
  157.         WRITELN('Reading input file ... ');
  158.         cc:=1; tmpstr:='';
  159.         WHILE (NOT EOF(io_file)) AND (ln<=Max_Ed_Lines) DO BEGIN
  160.             TextColor(Cyan); WRITE(^M'reading line ',ln);
  161.             tmpstr:=get_line;
  162.             IF tmpstr[1]<>'.' THEN BEGIN     {don't save dot commands}
  163.                 IF wrapper>0 THEN BEGIN
  164.                     WRITELN(^M^J'Splitting Line ',ln:2,' into two lines:');
  165.                     WRITELN(' -> ',ed_text[ln],^M^J);
  166.                     ln:=ln+1;
  167.                     stop_msg:=TRUE
  168.                 END;
  169.                 ln:=ln+1
  170.             END
  171.         END; {while}
  172.         IF last_ln<ln-1 THEN last_ln:=ln-1;
  173.         CLOSE(io_file)
  174.     END;
  175.     IF ln>Max_Ed_Lines THEN BEGIN
  176.         beep;
  177.         WRITELN; TextColor(LightMagenta+blink);
  178.         WRITELN('Note, input file had more lines than editor had available.');
  179.         WRITELN('Input file was truncated!');
  180.         stop_msg:=TRUE
  181.     END;
  182.     IF stop_msg THEN BEGIN
  183.         WRITELN; TextColor(Yellow);
  184.         WRITE('Strike any key to continue ... ');
  185.         c:=READKEY
  186.     END;
  187.     ln:=org_ln; cc:=1;
  188. END; {PROCEDURE readfile(dsp_menu:BOOLEAN)}
  189.