Lines Matching refs:input
115 struct input { struct
135 bool (*read_fn) P_((struct input *)); /* read one line */ argument
512 static bool read_always_fail P_((struct input *));
514 read_always_fail(input) in read_always_fail() argument
515 struct input *input UNUSED; in read_always_fail()
520 static bool read_file_line P_((struct input *));
522 read_file_line(input) in read_file_line() argument
523 struct input *input; in read_file_line()
528 long result = ck_getline (&b, &blen, input->fp);
693 static void open_next_file P_((const char *name, struct input *));
695 open_next_file(name, input) in open_next_file() argument
697 struct input *input;
704 input->fp = ck_fdopen (fileno (stdin), "stdin", read_mode, false);
706 else if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
710 input->read_fn = read_always_fail; /* a redundancy */
711 ++input->bad_count;
715 input->read_fn = read_file_line;
728 input->in_file_name = follow_symlink (name);
730 input->in_file_name = name;
733 tmpdir = ck_strdup(input->in_file_name);
739 if (isatty (fileno (input->fp)))
740 panic(_("couldn't edit %s: is a terminal"), input->in_file_name);
742 input_fd = fileno (input->fp);
743 fstat (input_fd, &input->st);
744 if (!S_ISREG (input->st.st_mode))
745 panic(_("couldn't edit %s: not a regular file"), input->in_file_name);
751 if (getfilecon (input->in_file_name, &con) != -1)
765 myname, input->in_file_name, strerror (errno));
770 output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed");
783 panic(_("couldn't open temporary file %s: %s"), input->out_file_name, strerror(errno));
791 static void closedown P_((struct input *));
793 closedown(input) in closedown() argument
794 struct input *input; in closedown()
796 input->read_fn = read_always_fail;
797 if (!input->fp)
805 target_name = input->in_file_name;
806 input_fd = fileno (input->fp);
808 copy_acl (input->in_file_name, input_fd,
809 input->out_file_name, output_fd,
810 input->st.st_mode);
812 if (fchown (output_fd, input->st.st_uid, input->st.st_gid) == -1)
813 fchown (output_fd, -1, input->st.st_gid);
816 ck_fclose (input->fp);
821 ck_rename (target_name, backup_file_name, input->out_file_name);
825 ck_rename (input->out_file_name, target_name, input->out_file_name);
826 free (input->out_file_name);
829 ck_fclose (input->fp);
831 input->fp = NULL;
854 static bool read_pattern_space P_((struct input *, struct vector *, int));
856 read_pattern_space(input, the_program, append) in read_pattern_space() argument
857 struct input *input; in read_pattern_space()
868 while ( ! (*input->read_fn)(input) )
870 closedown(input);
872 if (!*input->file_list)
875 if (input->reset_at_next_file)
877 input->line_number = 0;
888 input->reset_at_next_file = separate_files;
891 open_next_file (*input->file_list++, input);
894 ++input->line_number;
899 static bool last_file_with_data_p P_((struct input *));
901 last_file_with_data_p(input) in last_file_with_data_p() argument
902 struct input *input; in last_file_with_data_p()
908 closedown(input);
909 if (!*input->file_list)
911 open_next_file(*input->file_list++, input);
912 if (input->fp)
914 if ((ch = getc(input->fp)) != EOF)
916 ungetc(ch, input->fp);
924 static bool test_eof P_((struct input *));
926 test_eof(input) in test_eof() argument
927 struct input *input; in test_eof()
933 if (!input->fp)
934 return separate_files || last_file_with_data_p(input);
935 if (feof(input->fp))
936 return separate_files || last_file_with_data_p(input);
937 if ((ch = getc(input->fp)) == EOF)
938 return separate_files || last_file_with_data_p(input);
939 ungetc(ch, input->fp);
945 static bool match_an_address_p P_((struct addr *, struct input *));
947 match_an_address_p(addr, input) in match_an_address_p() argument
949 struct input *input;
960 return (input->line_number >= addr->addr_number
961 && ((input->line_number - addr->addr_number) % addr->addr_step) == 0);
968 return (addr->addr_number <= input->line_number);
971 return test_eof(input);
983 static bool match_address_p P_((struct sed_cmd *, struct input *));
985 match_address_p(cmd, input) in match_address_p() argument
987 struct input *input;
1000 return (input->line_number == cmd->a1->addr_number);
1003 || input->line_number < cmd->a1->addr_number)
1009 return match_an_address_p(cmd->a1, input);
1011 if (!match_an_address_p(cmd->a1, input))
1024 if (input->line_number >= cmd->a2->addr_number)
1028 cmd->a2->addr_number = input->line_number + cmd->a2->addr_step;
1031 cmd->a2->addr_number = input->line_number + cmd->a2->addr_step
1032 - (input->line_number%cmd->a2->addr_step);
1048 if (input->line_number >= cmd->a2->addr_number)
1051 return (input->line_number <= cmd->a2->addr_number);
1055 if (match_an_address_p(cmd->a2, input))
1384 static int execute_program P_((struct vector *, struct input *));
1386 execute_program(vec, input) in execute_program() argument
1388 struct input *input;
1397 if (match_address_p(cur_cmd, input) != cur_cmd->addr_bang)
1559 if (test_eof(input) || !read_pattern_space(input, vec, false))
1566 if (test_eof(input) || !read_pattern_space(input, vec, true))
1753 CAST(unsigned long)input->line_number);
1781 : cur_cmd->a1->addr_number < input->line_number))
1829 struct input input; local
1839 input.reset_at_next_file = true;
1841 input.file_list = argv;
1845 input.file_list = stdin_argv;
1847 input.bad_count = 0;
1848 input.line_number = 0;
1849 input.read_fn = read_always_fail;
1850 input.fp = NULL;
1853 while (read_pattern_space(&input, the_program, false))
1855 status = execute_program(the_program, &input);
1861 closedown(&input);
1876 if (input.bad_count)