Lines Matching refs:input
115 /* State information for the input stream. */
116 struct input {
126 /* Current input line number (over all files). */
136 bool (*read_fn) P_((struct input *)); /* read one line */
158 /* The `current' input line. */
161 /* An input line used to accumulate the result of the s and e commands. */
164 /* An input line that's been stored by later use by the program */
167 /* The buffered input look-ahead. The only field that should be
515 static bool read_always_fail P_((struct input *));
517 read_always_fail(input)
518 struct input *input UNUSED;
523 static bool read_file_line P_((struct input *));
525 read_file_line(input)
526 struct input *input;
531 long result = ck_getline (&b, &blen, input->fp);
697 /* Initialize a struct input for the named file. */
698 static void open_next_file P_((const char *name, struct input *));
700 open_next_file(name, input)
702 struct input *input;
709 input->fp = ck_fdopen (fileno (stdin), "stdin", read_mode, false);
711 else if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
715 input->read_fn = read_always_fail; /* a redundancy */
716 ++input->bad_count;
720 input->read_fn = read_file_line;
733 input->in_file_name = follow_symlink (name);
735 input->in_file_name = name;
738 tmpdir = ck_strdup(input->in_file_name);
744 if (isatty (fileno (input->fp)))
745 panic(_("couldn't edit %s: is a terminal"), input->in_file_name);
747 input_fd = fileno (input->fp);
748 fstat (input_fd, &input->st);
749 if (!S_ISREG (input->st.st_mode))
750 panic(_("couldn't edit %s: not a regular file"), input->in_file_name);
756 if (getfilecon (input->in_file_name, &con) != -1)
770 myname, input->in_file_name, strerror (errno));
775 output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed");
788 panic(_("couldn't open temporary file %s: %s"), input->out_file_name, strerror(errno));
795 /* Clean up an input stream that we are done with. */
796 static void closedown P_((struct input *));
798 closedown(input)
799 struct input *input;
801 input->read_fn = read_always_fail;
802 if (!input->fp)
810 target_name = input->in_file_name;
811 input_fd = fileno (input->fp);
813 copy_acl (input->in_file_name, input_fd,
814 input->out_file_name, output_fd,
815 input->st.st_mode);
817 if (fchown (output_fd, input->st.st_uid, input->st.st_gid) == -1)
818 fchown (output_fd, -1, input->st.st_gid);
821 ck_fclose (input->fp);
826 ck_rename (target_name, backup_file_name, input->out_file_name);
830 ck_rename (input->out_file_name, target_name, input->out_file_name);
831 free (input->out_file_name);
834 ck_fclose (input->fp);
836 input->fp = NULL;
857 /* Read in the next line of input, and store it in the pattern space.
858 Return zero if there is nothing left to input. */
859 static bool read_pattern_space P_((struct input *, struct vector *, int));
861 read_pattern_space(input, the_program, append)
862 struct input *input;
873 while ( ! (*input->read_fn)(input) )
875 closedown(input);
877 if (!*input->file_list)
880 if (input->reset_at_next_file)
882 input->line_number = 0;
893 input->reset_at_next_file = separate_files;
896 open_next_file (*input->file_list++, input);
899 ++input->line_number;
905 static bool last_file_with_data_p P_((struct input *));
907 last_file_with_data_p(input)
908 struct input *input;
914 closedown(input);
915 if (!*input->file_list)
917 open_next_file(*input->file_list++, input);
918 if (input->fp)
920 if ((ch = getc(input->fp)) != EOF)
922 ungetc(ch, input->fp);
930 static bool test_eof P_((struct input *));
932 test_eof(input)
933 struct input *input;
939 if (!input->fp)
940 return separate_files || last_file_with_data_p(input);
941 if (feof(input->fp))
942 return separate_files || last_file_with_data_p(input);
943 if ((ch = getc(input->fp)) == EOF)
944 return separate_files || last_file_with_data_p(input);
945 ungetc(ch, input->fp);
951 static bool match_an_address_p P_((struct addr *, struct input *));
953 match_an_address_p(addr, input)
955 struct input *input;
966 return (input->line_number >= addr->addr_number
967 && ((input->line_number - addr->addr_number) % addr->addr_step) == 0);
974 return (addr->addr_number <= input->line_number);
977 return test_eof(input);
989 static bool match_address_p P_((struct sed_cmd *, struct input *));
991 match_address_p(cmd, input)
993 struct input *input;
1006 return (input->line_number == cmd->a1->addr_number);
1009 || input->line_number < cmd->a1->addr_number)
1015 return match_an_address_p(cmd->a1, input);
1017 if (!match_an_address_p(cmd->a1, input))
1030 if (input->line_number >= cmd->a2->addr_number)
1034 cmd->a2->addr_number = input->line_number + cmd->a2->addr_step;
1037 cmd->a2->addr_number = input->line_number + cmd->a2->addr_step
1038 - (input->line_number%cmd->a2->addr_step);
1054 if (input->line_number >= cmd->a2->addr_number)
1057 return (input->line_number <= cmd->a2->addr_number);
1061 if (match_an_address_p(cmd->a2, input))
1389 /* Execute the program `vec' on the current input line.
1391 static int execute_program P_((struct vector *, struct input *));
1393 execute_program(vec, input)
1395 struct input *input;
1404 if (match_address_p(cur_cmd, input) != cur_cmd->addr_bang)
1513 The problem is that hold space and the input file might as
1515 that subsequent input might be read incorrectly, while
1566 if (test_eof(input) || !read_pattern_space(input, vec, false))
1573 if (test_eof(input) || !read_pattern_space(input, vec, true))
1678 int idx, prev_idx; /* index in the input line. */
1760 CAST(unsigned long)input->line_number);
1773 or otherwise quickly copy input to output. Now whether this
1788 : cur_cmd->a1->addr_number < input->line_number))
1837 struct input input;
1847 input.reset_at_next_file = true;
1849 input.file_list = argv;
1851 panic(_("no input
1853 input.file_list = stdin_argv;
1855 input.bad_count = 0;
1856 input.line_number = 0;
1857 input.read_fn = read_always_fail;
1858 input.fp = NULL;
1861 while (read_pattern_space(&input, the_program, false))
1863 status = execute_program(the_program, &input);
1869 closedown(&input);
1884 if (input.bad_count)