MCPcopy Create free account
hub / github.com/coreutils/coreutils / expand

Function expand

src/expand.c:101–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99 Read each file in 'file_list', in order. */
100
101static void
102expand (void)
103{
104 /* Input stream. */
105 FILE *fp = next_file (NULL);
106
107 if (!fp)
108 return;
109
110 static char line_in[IO_BUFSIZE];
111 mbbuf_t mbbuf;
112 mbbuf_init (&mbbuf, line_in, sizeof line_in, fp);
113
114 while (true)
115 {
116 /* Input character, or EOF. */
117 mcel_t g;
118
119 /* If true, perform translations. */
120 bool convert = true;
121
122
123 /* The following variables have valid values only when CONVERT
124 is true: */
125
126 /* Column of next input character. */
127 colno column = 0;
128
129 /* Index in TAB_LIST of next tab stop to examine. */
130 idx_t tab_index = 0;
131
132
133 /* Convert a line of text. */
134
135 do
136 {
137 while ((g = mbbuf_get_char (&mbbuf)).ch == MBBUF_EOF
138 && (fp = next_file (fp)))
139 mbbuf_init (&mbbuf, line_in, sizeof line_in, fp);
140
141 if (convert)
142 {
143 convert &= convert_entire_line || c32issep (g.ch);
144
145 if (g.ch == '\t')
146 {
147 /* Column the next input tab stop is on. */
148 bool last_tab;
149 colno next_tab_column
150 = get_next_tab_column (column, &tab_index, &last_tab);
151
152 while (++column < next_tab_column)
153 if (putchar (' ') < 0)
154 write_error ();
155
156 if (putchar (' ') < 0)
157 write_error ();
158

Callers 1

mainFunction · 0.85

Calls 7

next_fileFunction · 0.85
mbbuf_initFunction · 0.85
mbbuf_get_charFunction · 0.85
c32issepFunction · 0.85
get_next_tab_columnFunction · 0.85
write_errorFunction · 0.85
mbbuf_char_offsetFunction · 0.85

Tested by

no test coverage detected