edit.c (6f26c71d76bb795b30684affb3b57870a7926b26) edit.c (2235c7feac959bcc9ddfd6a2bc6be32102b1f84c)
1/*
1/*
2 * Copyright (C) 1984-2020 Mark Nudelman
2 * Copyright (C) 1984-2021 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information, see the README file.
8 */
9
10

--- 4 unchanged lines hidden (view full) ---

15#endif
16#if OS2
17#include <signal.h>
18#endif
19
20public int fd0 = 0;
21
22extern int new_file;
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information, see the README file.
8 */
9
10

--- 4 unchanged lines hidden (view full) ---

15#endif
16#if OS2
17#include <signal.h>
18#endif
19
20public int fd0 = 0;
21
22extern int new_file;
23extern int errmsgs;
24extern int cbufs;
25extern char *every_first_cmd;
23extern int cbufs;
24extern char *every_first_cmd;
26extern int any_display;
27extern int force_open;
28extern int is_tty;
29extern int sigs;
25extern int force_open;
26extern int is_tty;
27extern int sigs;
28extern int hshift;
30extern IFILE curr_ifile;
31extern IFILE old_ifile;
32extern struct scrpos initial_scrpos;
33extern void *ml_examine;
34#if SPACES_IN_FILENAMES
35extern char openquote;
36extern char closequote;
37#endif

--- 4 unchanged lines hidden (view full) ---

42extern char *namelogfile;
43#endif
44
45#if HAVE_STAT_INO
46public dev_t curr_dev;
47public ino_t curr_ino;
48#endif
49
29extern IFILE curr_ifile;
30extern IFILE old_ifile;
31extern struct scrpos initial_scrpos;
32extern void *ml_examine;
33#if SPACES_IN_FILENAMES
34extern char openquote;
35extern char closequote;
36#endif

--- 4 unchanged lines hidden (view full) ---

41extern char *namelogfile;
42#endif
43
44#if HAVE_STAT_INO
45public dev_t curr_dev;
46public ino_t curr_ino;
47#endif
48
50
51/*
52 * Textlist functions deal with a list of words separated by spaces.
53 * init_textlist sets up a textlist structure.
54 * forw_textlist uses that structure to iterate thru the list of
55 * words, returning each one as a standard null-terminated string.
56 * back_textlist does the same, but runs thru the list backwards.
57 */
58 public void

--- 178 unchanged lines hidden (view full) ---

237 * ifile == NULL means just close the current file.
238 */
239 public int
240edit_ifile(ifile)
241 IFILE ifile;
242{
243 int f;
244 int answer;
49/*
50 * Textlist functions deal with a list of words separated by spaces.
51 * init_textlist sets up a textlist structure.
52 * forw_textlist uses that structure to iterate thru the list of
53 * words, returning each one as a standard null-terminated string.
54 * back_textlist does the same, but runs thru the list backwards.
55 */
56 public void

--- 178 unchanged lines hidden (view full) ---

235 * ifile == NULL means just close the current file.
236 */
237 public int
238edit_ifile(ifile)
239 IFILE ifile;
240{
241 int f;
242 int answer;
245 int no_display;
246 int chflags;
247 char *filename;
248 char *open_filename;
249 char *alt_filename;
250 void *altpipe;
251 IFILE was_curr_ifile;
252 PARG parg;
253

--- 203 unchanged lines hidden (view full) ---

457 {
458 curr_ino = statbuf.st_ino;
459 curr_dev = statbuf.st_dev;
460 }
461 }
462#endif
463 if (every_first_cmd != NULL)
464 {
243 int chflags;
244 char *filename;
245 char *open_filename;
246 char *alt_filename;
247 void *altpipe;
248 IFILE was_curr_ifile;
249 PARG parg;
250

--- 203 unchanged lines hidden (view full) ---

454 {
455 curr_ino = statbuf.st_ino;
456 curr_dev = statbuf.st_dev;
457 }
458 }
459#endif
460 if (every_first_cmd != NULL)
461 {
465 ungetcc(CHAR_END_COMMAND);
466 ungetsc(every_first_cmd);
462 ungetsc(every_first_cmd);
463 ungetcc_back(CHAR_END_COMMAND);
467 }
468 }
469
464 }
465 }
466
470 no_display = !any_display;
471 flush();
467 flush();
472 any_display = TRUE;
473
474 if (is_tty)
475 {
476 /*
477 * Output is to a real tty.
478 */
479
480 /*
481 * Indicate there is nothing displayed yet.
482 */
483 pos_clear();
484 clr_linenum();
485#if HILITE_SEARCH
486 clr_hilite();
487#endif
468
469 if (is_tty)
470 {
471 /*
472 * Output is to a real tty.
473 */
474
475 /*
476 * Indicate there is nothing displayed yet.
477 */
478 pos_clear();
479 clr_linenum();
480#if HILITE_SEARCH
481 clr_hilite();
482#endif
483 hshift = 0;
488 if (strcmp(filename, FAKE_HELPFILE) && strcmp(filename, FAKE_EMPTYFILE))
489 {
490 char *qfilename = shell_quote(filename);
491 cmd_addhist(ml_examine, qfilename, 1);
492 free(qfilename);
493 }
494
484 if (strcmp(filename, FAKE_HELPFILE) && strcmp(filename, FAKE_EMPTYFILE))
485 {
486 char *qfilename = shell_quote(filename);
487 cmd_addhist(ml_examine, qfilename, 1);
488 free(qfilename);
489 }
490
495 if (no_display && errmsgs > 0)
496 {
497 /*
498 * We displayed some messages on error output
499 * (file descriptor 2; see error() function).
500 * Before erasing the screen contents,
501 * display the file name and wait for a keystroke.
502 */
503 parg.p_string = filename;
504 error("%s", &parg);
505 }
506 }
507 free(filename);
508 return (0);
509}
510
511/*
512 * Edit a space-separated list of files.
513 * For each filename in the list, enter it into the ifile list.

--- 265 unchanged lines hidden (view full) ---

779
780 while ((c = ch_forw_get()) != EOI)
781 putchr(c);
782 flush();
783}
784
785#if LOGFILE
786
491 }
492 free(filename);
493 return (0);
494}
495
496/*
497 * Edit a space-separated list of files.
498 * For each filename in the list, enter it into the ifile list.

--- 265 unchanged lines hidden (view full) ---

764
765 while ((c = ch_forw_get()) != EOI)
766 putchr(c);
767 flush();
768}
769
770#if LOGFILE
771
772#define OVERWRITE_OPTIONS "Overwrite, Append, Don't log, or Quit?"
773
787/*
788 * If the user asked for a log file and our input file
789 * is standard input, create the log file.
790 * We take care not to blindly overwrite an existing file.
791 */
792 public void
793use_logfile(filename)
794 char *filename;

--- 27 unchanged lines hidden (view full) ---

822 */
823 answer = 'O';
824 } else
825 {
826 /*
827 * Ask user what to do.
828 */
829 parg.p_string = filename;
774/*
775 * If the user asked for a log file and our input file
776 * is standard input, create the log file.
777 * We take care not to blindly overwrite an existing file.
778 */
779 public void
780use_logfile(filename)
781 char *filename;

--- 27 unchanged lines hidden (view full) ---

809 */
810 answer = 'O';
811 } else
812 {
813 /*
814 * Ask user what to do.
815 */
816 parg.p_string = filename;
830 answer = query("Warning: \"%s\" exists; Overwrite, Append or Don't log? ", &parg);
817 answer = query("Warning: \"%s\" exists; "OVERWRITE_OPTIONS" ", &parg);
831 }
832
833loop:
834 switch (answer)
835 {
836 case 'O': case 'o':
837 /*
838 * Overwrite: create the file.

--- 11 unchanged lines hidden (view full) ---

850 logfile = -1;
851 }
852 break;
853 case 'D': case 'd':
854 /*
855 * Don't do anything.
856 */
857 return;
818 }
819
820loop:
821 switch (answer)
822 {
823 case 'O': case 'o':
824 /*
825 * Overwrite: create the file.

--- 11 unchanged lines hidden (view full) ---

837 logfile = -1;
838 }
839 break;
840 case 'D': case 'd':
841 /*
842 * Don't do anything.
843 */
844 return;
858 case 'q':
859 quit(QUIT_OK);
860 /*NOTREACHED*/
861 default:
862 /*
863 * Eh?
864 */
845 default:
846 /*
847 * Eh?
848 */
865 answer = query("Overwrite, Append, or Don't log? (Type \"O\", \"A\", \"D\" or \"q\") ", NULL_PARG);
849
850 answer = query(OVERWRITE_OPTIONS" (Type \"O\", \"A\", \"D\" or \"Q\") ", NULL_PARG);
866 goto loop;
867 }
868
869 if (logfile < 0)
870 {
871 /*
872 * Error in opening logfile.
873 */
874 parg.p_string = filename;
875 error("Cannot write to \"%s\"", &parg);
876 return;
877 }
878 SET_BINARY(logfile);
879}
880
881#endif
851 goto loop;
852 }
853
854 if (logfile < 0)
855 {
856 /*
857 * Error in opening logfile.
858 */
859 parg.p_string = filename;
860 error("Cannot write to \"%s\"", &parg);
861 return;
862 }
863 SET_BINARY(logfile);
864}
865
866#endif