#include "ded.h" #include "iofile.h" /* for closeinput() */ /************************************************************************ * * * copyright Richard Bornat 1981 * * * ************************************************************************/ /* procedures to handle the commands which allow input/output * of files to ded */ extern char *get_range(); /* declaration to quieten lint */ /* process range and file arguments */ char *io_range(str, a_begin, a_end) char *str; int *a_begin, *a_end; { char crange; str = get_range(str, &crange, a_begin, a_end); if (*str==0) fdiag("!! file argument missing !!"); return(str); } extern char *get_pos(); /* declaration to quieten lint */ char *io_pos(str, a_line, a_after) char *str; int *a_line; char *a_after; { char crange; str = get_pos(str, &crange, a_line, a_after); if (*str==0) fdiag("!! file argument missing !!"); return(str); } extern fdiag(); /* read in a file */ do_read(str) char *str; { int line, fline; char after; char linebuf[ENOUGH]; savescreen(); str = io_pos(str, &line, &after); fline = line; /* line is the line BEFORE which text must appear */ if (after!='-') line++; openinput(str, fdiag); while(ded_inline(linebuf, fdiag)) { xshuffile(line, 1, 0); /* don't extend range */ saveline(line, linebuf); line++; } closeinput(); disp_range(fline, line, (after!='-'), false); /* finish up before file read in * - don't save screen */ } /* write out a line */ do_write(str) char *str; { if (*str==0) { savescreen(); if (!tmp_changed) tdiag("!! file hasn't changed - use reallywrite to force output"); else do_rwrite(); } else { int bra, era; str = io_range(str, &bra, &era); if (check_replay("do you want to write this file?")) { if (!createoutput(str, -1)) fdiag("!! cannot create file %s !!", str); while (bra <= era) { outline(bra, str, fdiag); bra++; } closeoutput(str, fdiag); } } } /* write out the contents of the file */ do_rwrite() { extern tdiag(); savefile(tdiag, true); complain(); i_mode(in_c.row, in_c.col); } /* write out a range, then delete it */ do_wrdel(str) char *str; { do_write(str); io_delete(str); } /* append to the end of a file */ do_append(str) char *str; { int bra, era; str = io_range(str, &bra, &era); if (check_replay("do you want to append to this file?")) { if (!openapp(str)) fdiag("!! cannot append or create file %s !!", str); while (bra<=era) { outline(bra, str, fdiag); bra++; } closeapp(str, fdiag); /* actually just closeoutput, I think */ } } /* append then delete */ do_appdel(str) char *str; { do_append(str); io_delete(str); } /* convert into a deletion command */ io_delete(str) char *str; { str[1] = '\0'; do_delete(str); }