toolbox

Check-in [2ff913e864]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:retab: simplify max_widths()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2ff913e8641ebabe93e20f9ab77143b4a12817433281ea59098f537f8330a344
User & Date: jef 2020-05-02 08:48:35
Context
2020-05-02
09:16
lib: switch to TAILQ for jtlst implementation for openbsd compatibility check-in: f070c34d00 user: jef tags: trunk
08:48
retab: simplify max_widths() check-in: 2ff913e864 user: jef tags: trunk
2020-05-01
14:28
retab: remove unnecessary check check-in: ab0b7a818c user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/retab/retab.c.

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187


188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
		buf = jtbuf_append_str(buf, " |");
		puts(buf);
		jtbuf_free(buf);
	}
}

jtlst *
max_widths(jtlst *r1, jtlst *r2)
{
	jtlst *res;
	size_t *v1, *v2;

	if (jtlst_size(r1) != jtlst_size(r2))
		die("rows with different number of fields");

	res = jtlst_new();
	jtlstnode *iter1 = jtlst_iter(r1);
	jtlstnode *iter2 = jtlst_iter(r2);


	while (jtlst_next(&iter1, (void **) &v1) && jtlst_next(&iter2, (void **) &v2))
		jtlst_append(res, (size_t *) max((size_t) v1, (size_t) v2));


	return res;
}

jtlst *
table_widths(jtlst *rows)
{
	jtlst *tmp, *res = NULL;
	struct row *row;

	JTLST_FOREACH(row, rows) {
		if (row->is_line)
			continue;
		else if (res == NULL) {
			res = jtlst_clone(row->fields_widths);
			continue;
		}
		else {
			tmp = max_widths(res, row->fields_widths);
			jtlst_free(res);
			res = tmp;
		}
	}

	return res;
}

void
retab()







|

|
<

|


<
|
|
>
>
|
|
|
>
|





|









|
|
<
<
<







170
171
172
173
174
175
176
177
178
179

180
181
182
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209



210
211
212
213
214
215
216
		buf = jtbuf_append_str(buf, " |");
		puts(buf);
		jtbuf_free(buf);
	}
}

jtlst *
max_widths(jtlst *rows_maxs, jtlst *row)
{
	void *data;


	if (jtlst_size(rows_maxs) != jtlst_size(row))
		die("rows with different number of fields");


	jtlstnode *iter1 = jtlst_iter(rows_maxs);
	jtlstnode *iter2 = jtlst_iter(row);
	while (iter1 && iter2) {
		iter1->data = (size_t *) max((size_t) iter1->data, (size_t) iter2->data);
		jtlst_next(&iter1, &data);
		jtlst_next(&iter2, &data);
	}

	return rows_maxs;
}

jtlst *
table_widths(jtlst *rows)
{
	jtlst *res = NULL;
	struct row *row;

	JTLST_FOREACH(row, rows) {
		if (row->is_line)
			continue;
		else if (res == NULL) {
			res = jtlst_clone(row->fields_widths);
			continue;
		}
		else
			res = max_widths(res, row->fields_widths);



	}

	return res;
}

void
retab()