commit 88b4716fa34e80a4781b8b42ad52b72cb40348bf
parent 186d822c020fa5ac518de41eedb7d82341a09ed9
Author: ukai <ukai>
Date: Wed, 17 Apr 2002 02:44:22 +0000
[w3m-dev 03178] Parser of ``cols'' and ``rows''
* frame.c (parseFrameSetLength): added
(newFrameSet): use parseFrameSetLength()
From: Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
Diffstat:
M | ChangeLog | | | 6 | ++++++ |
M | frame.c | | | 116 | +++++++++++++++++++++++++++++++------------------------------------------------ |
2 files changed, 51 insertions(+), 71 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,5 +1,11 @@
2002-04-17 Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
+ * [w3m-dev 03178] Parser of ``cols'' and ``rows''
+ * frame.c (parseFrameSetLength): added
+ (newFrameSet): use parseFrameSetLength()
+
+2002-04-17 Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
+
* [w3m-dev 03177] SIGUSR1 --> W3M_SIGIMG in image.c
* image.c (W3M_SIGIMG): added
(load_image_handler): s/SIGUSR1/W3M_SIGIMG/
diff --git a/frame.c b/frame.c
@@ -20,13 +20,52 @@ KeyAbort(SIGNAL_ARG)
LONGJMP(AbortLoading, 1);
}
+static int
+parseFrameSetLength(char *s, char ***ret)
+{
+ int i, len;
+ char *p, *q, **lv;
+
+ i = 1;
+
+ if (s)
+ for (p = s; (p = strchr(p, ',')); ++p)
+ ++i;
+ else
+ s = "*";
+
+ lv = New_N(char *, i);
+
+ for (i = 0, p = s;; ++p) {
+ SKIP_BLANKS(p);
+ len = strtoul(p, &q, 10);
+
+ switch (*q) {
+ case '%':
+ lv[i++] = Sprintf("%d%%", len)->ptr;
+ break;
+ case '*':
+ lv[i++] = "*";
+ break;
+ default:
+ lv[i++] = Sprintf("%d", len)->ptr;
+ break;
+ }
+
+ if (!(p = strchr(q, ',')))
+ break;
+ }
+
+ *ret = lv;
+ return i;
+}
+
struct frameset *
newFrameSet(struct parsed_tag *tag)
{
struct frameset *f;
int i;
- char *cols = NULL, *rows = NULL, *p, *q;
- char *length[100];
+ char *cols = NULL, *rows = NULL;
f = New(struct frameset);
f->attr = F_FRAMESET;
@@ -34,78 +73,13 @@ newFrameSet(struct parsed_tag *tag)
f->currentURL = NULL;
parsedtag_get_value(tag, ATTR_COLS, &cols);
parsedtag_get_value(tag, ATTR_ROWS, &rows);
- i = 0;
- if (cols) {
- length[i] = p = cols;
- while (*p != '\0')
- if (*p++ == ',') {
- length[++i] = p;
- if (i >= sizeof(length) / sizeof(length[0]) - 2)
- break;
- }
- length[++i] = p + 1;
- }
- if (i > 1) {
- f->col = i;
- f->width = New_N(char *, i);
- p = length[i];
- do {
- i--;
- q = p - 2;
- p = length[i];
- switch (*q) {
- Str tmp;
- case '%':
- f->width[i] = allocStr(p, q - p + 1);
- break;
- case '*':
- f->width[i] = "*";
- break;
- default:
- tmp = Sprintf("%d", atoi(p));
- f->width[i] = tmp->ptr;
- break;
- }
- } while (i);
- }
- else {
- f->col = 1;
- f->width = New_N(char *, 1);
- f->width[0] = "*";
- }
- i = 0;
- if (rows) {
- length[i] = p = rows;
- while (*p != '\0')
- if (*p++ == ',') {
- length[++i] = p;
- if (i >= sizeof(length) / sizeof(length[0]) - 2)
- break;
- }
- length[++i] = p + 1;
- }
- if (i > 1) {
- f->row = i;
- f->height = New_N(char *, i);
- p = length[i];
- do {
- i--;
- q = p - 2;
- p = length[i];
- f->height[i] = allocStr(p, q - p + 1);
- } while (i);
- }
- else {
- f->row = 1;
- f->height = New_N(char *, 1);
- f->height[0] = "*";
- }
- i = f->row * f->col;
+ f->col = parseFrameSetLength(cols, &f->width);
+ f->row = parseFrameSetLength(rows, &f->height);
f->i = 0;
+ i = f->row * f->col;
f->frame = New_N(union frameset_element, i);
do {
- i--;
- f->frame[i].element = NULL;
+ f->frame[--i].element = NULL;
} while (i);
return f;
}