| | @@ -1336,5 +1336,31 @@ |
| 1336 | 1336 | blob_zero(&out); |
| 1337 | 1337 | blob_read_from_file(&in, g.argv[2]); |
| 1338 | 1338 | wiki_convert(&in, &out, 0); |
| 1339 | 1339 | blob_write_to_file(&out, "-"); |
| 1340 | 1340 | } |
| 1341 | + |
| 1342 | +/* |
| 1343 | +** Search for a <title>...</title> at the beginning of a wiki page. |
| 1344 | +** Return true (nonzero) if a title is found. Return zero if there is |
| 1345 | +** not title. |
| 1346 | +** |
| 1347 | +** If a title is found, initialize the pTitle blob to be the content |
| 1348 | +** of the title and initialize pTail to be the text that follows the |
| 1349 | +** title. |
| 1350 | +*/ |
| 1351 | +int wiki_find_title(Blob *pIn, Blob *pTitle, Blob *pTail){ |
| 1352 | + char *z; |
| 1353 | + int i; |
| 1354 | + int iStart; |
| 1355 | + z = blob_str(pIn); |
| 1356 | + for(i=0; isspace(z[i]); i++){} |
| 1357 | + if( z[i]!='<' ) return 0; |
| 1358 | + i++; |
| 1359 | + if( strncmp(&z[i],"title>", 6)!=0 ) return 0; |
| 1360 | + iStart = i+6; |
| 1361 | + for(i=iStart; z[i] && (z[i]!='<' || strncmp(&z[i],"</title>",8)!=0); i++){} |
| 1362 | + if( z[i]!='<' ) return 0; |
| 1363 | + blob_init(pTitle, &z[iStart], i-iStart); |
| 1364 | + blob_init(pTail, &z[i+8], -1); |
| 1365 | + return 1; |
| 1366 | +} |
| 1341 | 1367 | |