version 1.27, 2011/12/08 02:24:31 |
version 1.28, 2011/12/08 09:19:13 |
Line 1288 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
Line 1288 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
buf_append(buf, of->title); |
buf_append(buf, of->title); |
hash_put(hash, buf, TYPE_Nm); |
hash_put(hash, buf, TYPE_Nm); |
|
|
while (NULL != (line = fgetln(stream, &len)) && '\n' != *line) |
/* Skip to first blank line. */ |
/* Skip to first blank line. */ ; |
|
|
|
while (NULL != (line = fgetln(stream, &len)) && |
while (NULL != (line = fgetln(stream, &len))) |
('\n' == *line || ' ' == *line)) |
if (len && '\n' == *line) |
/* Skip to first section header. */ ; |
break; |
|
|
|
/* |
|
* Skip to first section header. |
|
* This happens when text is flush-left. |
|
*/ |
|
|
|
while (NULL != (line = fgetln(stream, &len))) |
|
if (len && '\n' != *line && ' ' != *line) |
|
break; |
|
|
/* |
/* |
* If no page content can be found, |
* If no page content can be found or the input line is |
* reuse the page title as the page description. |
* malformed (zer-length or has no trailing newline), reuse the |
|
* page title as the page description. |
*/ |
*/ |
|
|
if (NULL == (line = fgetln(stream, &len))) { |
line = fgetln(stream, &len); |
|
if (NULL == line || len == 0 || '\n' != line[(int)len - 1]) { |
buf_appendb(dbuf, buf->cp, buf->size); |
buf_appendb(dbuf, buf->cp, buf->size); |
hash_put(hash, buf, TYPE_Nd); |
hash_put(hash, buf, TYPE_Nd); |
fclose(stream); |
fclose(stream); |
return; |
return; |
} |
} |
fclose(stream); |
|
|
|
/* |
line[(int)--len] = '\0'; |
* If there is a dash, skip to the text following it. |
|
|
/* |
|
* Skip to the last dash. |
|
* Use the remaining line as the description (no more than 70 |
|
* bytes). |
*/ |
*/ |
|
|
for (p = line, plen = len; plen; p++, plen--) |
if (NULL != (p = strrchr(line, '-'))) { |
if ('-' == *p) |
for (++p; ' ' == *p || '\b' == *p; p++) |
break; |
/* Skip to next word. */ ; |
for ( ; plen; p++, plen--) |
} else |
if ('-' != *p && ' ' != *p && 8 != *p) |
|
break; |
|
if (0 == plen) { |
|
p = line; |
p = line; |
plen = len; |
|
} |
|
|
|
/* |
if ((plen = strlen(p)) > 70) { |
* Copy the rest of the line, but no more than 70 bytes. |
|
*/ |
|
|
|
if (70 < plen) |
|
plen = 70; |
plen = 70; |
p[plen-1] = '\0'; |
p[plen] = '\0'; |
buf_appendb(dbuf, p, plen); |
} |
|
|
|
buf_appendb(dbuf, p, plen + 1); |
buf->len = 0; |
buf->len = 0; |
buf_appendb(buf, p, plen); |
buf_appendb(buf, p, plen + 1); |
hash_put(hash, buf, TYPE_Nd); |
hash_put(hash, buf, TYPE_Nd); |
|
fclose(stream); |
} |
} |
|
|
static void |
static void |