1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
|
/* File: helpsubs.c
* Author: Fred Wobus (fw@sanger.ac.uk)
* Copyright (C) J Thierry-Mieg and R Durbin, 1998
*-------------------------------------------------------------------
* This file is part of the ACEDB genome database package, written by
* Richard Durbin (MRC LMB, UK) rd@sanger.ac.uk, and
* Jean Thierry-Mieg (CRBM du CNRS, France) mieg@kaa.cnrs-mop.fr
*
* SCCS: %W% %G%
* Description: controls the help system, provides HTML parsing
* Exported functions:
* HISTORY:
* Last edited: Dec 4 14:30 1998 (fw)
* * Oct 12 12:27 1998 (fw): checkSubject now case-insensitive
* * Oct 8 17:23 1998 (fw): removed warning, in case that
an open-list tag (e.g. <UL> was directly followed by a close-list
tag (e.g. </UL>). The warning tried to enforce that
every type of list only has a certain type of items.
* * Oct 8 11:36 1998 (fw): helpSubjectGetFilename takes over logic
from readHelpfile to locate the file containing the
help for a particular subject
* Created: Tue Aug 18 16:11:07 1998 (fw)
*-------------------------------------------------------------------
*/
#include "help_.h"
/************************************************************/
static char *makeHtmlIndex (STORE_HANDLE handle);
static char *makeHtmlImagePage (char *link, STORE_HANDLE handle);
static HtmlNode *parseHtmlText (char *text, STORE_HANDLE handle);
static BOOL parseSection (char **cp, HtmlNode **resultnode,
STORE_HANDLE handle);
/************************************************************/
/************ directory where help files are stored *********/
static char helpDir[MAXPATHLEN] = "" ;
/************************************************************/
/* function to register the helpOnRoutine
This can be called at any stage (before the first helpOn,
or later on, it will affect the system next time helpOn
is called. */
/************************************************************/
static QueryRoutine helpOnRoutine = 0;
UTIL_FUNC_DEF QueryRoutine helpOnRegister (QueryRoutine func)
/* call with func = 0x0 just to check whether
anything has been registered yet */
{
QueryRoutine old = helpOnRoutine ;
if (func)
helpOnRoutine = func ;
return old ;
}
/************************************************************/
/* Sets the helpDir; */
/************************************************************/
UTIL_FUNC_DEF char *helpSetDir (char *dirname)
{
if (dirname)
{
strcpy (helpDir, dirname);
if (filName (dirname,0,"rd"))
return (char*)&helpDir[0];
else
return (char*)0;
}
else
{
strcpy (helpDir, filGetFullPath ("whelp"));
if (filName (helpDir, 0, "rd"))
return (char*)&helpDir[0];
}
return (char*)0;
} /* helpGetDir */
/************************************************************/
/* return the current helpDirectory or
initialise if not previously set */
UTIL_FUNC_DEF char *helpGetDir (void)
{
if (!*helpDir)
return (helpSetDir(0)) ;
return (char*)&helpDir[0];
} /* helpGetDir */
/************************************************************/
/* pop up help on the given subject, depending on the registered
display function, that will be textual, in the built-in
simple HTML browser or even launch an external browser
to display the help document */
/************************************************************/
UTIL_FUNC_DEF BOOL helpOn (char *subject)
{
char *helpFilename;
if (!helpGetDir() || !filName(helpGetDir(), "", "rd"))
{
messout ("Sorry, No help available ! "
"Could not open the HTML help directory "
"%s\n"
"(%s)",
helpGetDir(),
messSysErrorText());
return FALSE;
}
helpFilename = helpSubjectGetFilename(subject);
/* may be NULL if file could not be found,
the registered helpOnRoutine has to cope
with this case and may decide to display an
index instead */
if (helpOnRoutine)
return ((*helpOnRoutine)(helpFilename));
return (helpPrint (helpFilename)); /* textual help as default */
} /* helpOn */
/************************************************************/
UTIL_FUNC_DEF char *helpSubjectGetFilename (char *subject)
/* this function attempts to find the file name corresponding
to a particular help-subject.
It will attempt to find a matching file according to
the current settings of helpDir and HELP_FILE_EXTENSION.
the subject '?' will just return ? again. This is a special
code within the help system to tell the help display
function that the user required some kind of help.
Usually the helpOnRegister'd function would display a
dynamically created index of the help-directory.
this function can be even cleverer by doing keyword searches
on <TITLE> and <H1> strings in files that might be relevant
of no obvious match is found.
*/
{
static char filename_array[MAXPATHLEN] = "";
char *filename = &filename_array[0];
char *subject_copy;
Array dirList;
if (subject == NULL)
return NULL;
if (strlen(subject) == 0)
return NULL;
if (strcmp(subject, "?") == 0)
{
/* return ? to signal that the calling
function needs to display a dynamically
created index or show some kind of help.
*/
/* if the construct
page = htmlPageCreate(helpGetFilename(subject_requested));
is used, the resulting page will therefor be a marked up
directory listing of helpsubjects
*/
strcpy (filename, "?");
return filename;
}
subject_copy = strnew (subject, 0);
strcpy (filename, ""); /* intialise, if this is
non-empty at the end of the loop,
we found a matching helpfile */
while (TRUE)
{
/* simple attempt to locate file - path/helpDir/subject.html */
sprintf(filename, "%s%s%s.%s",
filGetFullPath(helpGetDir()),
SUBDIR_DELIMITER_STR,
subject_copy, HELP_FILE_EXTENSION);
if (filName(filename, 0, "r"))
break;
/* advanced attempt, try to find a matching file from
the list of available ones by scanning the directory
contents of the helpdirectory */
if ((dirList = filDirectoryCreate
(helpGetDir(), HELP_FILE_EXTENSION, "r")) )
{
int i;
int matches;
char *s;
/* first look for an exact case-insensitive match */
strcpy (filename, "");
for (i = 0 ; i < arrayMax(dirList) ; i++)
{
s = arr(dirList,i,char*);
if (strcasecmp (s, subject_copy) == 0)
{
sprintf(filename, "%s%s%s.%s",
filGetFullPath(helpGetDir()),
SUBDIR_DELIMITER_STR,
s, HELP_FILE_EXTENSION);
if (filName(filename, 0, "r"))
break; /* exit for-loop */
strcpy (filename, "");
}
}
if (strlen(filename) > 0)
break; /* exit while(true) loop */
/* count the number of filenames starting with the
given subject string */
matches = 0;
for (i = 0 ; i < arrayMax(dirList) ; i++)
{
s = arr(dirList,i,char*);
if (strncasecmp (s, subject_copy,
strlen(subject_copy)) == 0)
{
sprintf(filename, "%s%s%s.%s",
filGetFullPath(helpGetDir()),
SUBDIR_DELIMITER_STR,
s, HELP_FILE_EXTENSION);
++matches;
}
}
if (matches == 0)
{
strcpy (filename, ""); /* not found */
}
else if (matches == 1)
{
/* the one exact match (already in filename string)
is the complete filename */
if (filName(filename, 0, "r"))
break; /* exit while(true) loop */
}
else if (matches > 1)
{
/* construct a filename that we know won't work.
But it may be used by the help display
function to give a meaningful message
to say that this subject is ambiguos.
The returned filename is then considered
a template, similar to 'ls subject*'
so the help-display function may give a list
of possible matching subjects. */
sprintf(filename, "%s%s%s",
filGetFullPath(helpGetDir()),
SUBDIR_DELIMITER_STR, subject_copy);
break;
}
filDirectoryDestroy (dirList);
} /* endif dirList */
/* file didn't exist, whichever way we tried so far,
so we try to chop off the last bit of the subject name.
In case trySubject was "Tree_Clone_Inside", we now
go through the look again with "Tree_Clone" and re-try. */
if (strchr (subject_copy, '_'))
{
int j;
j = strlen (subject_copy);
while (subject_copy[j--] != '_') ; /* find the last _ char */
subject_copy[j + 1] = '\0';
}
else
{
/* If we run out of trailing components, then we exit
* anyway.
*/
strcpy (filename, "");
break; /* exit while(true)loop */
}
} /* end-while(true) */
messfree (subject_copy);
if (strcmp(filename, "") != 0)
return filename; /* success */
if ((strcasecmp(subject, "index") == 0) ||
(strcasecmp(subject, "home") == 0) ||
(strcasecmp(subject, "toc") == 0))
{
/* we asked for some kind of index-page but couldn't find it,
so we can always try to return the question mark '?'
which will ask the calling function to display a
dynamically created index of help-subjects. */
strcpy (filename, "?");
return filename;
}
return NULL; /* failure - no file found */
} /* helpSubjectGetFilename */
/************************************************************/
/* helpPackage utility to find out the filename of a given
link reference. Absolute filenames are returned unchanged,
but relative filenames are expanded to be the full path
of the helpfile. Can be used for html/gif files referred to
by the HREF of anchor tags or the SRC or IMG tags */
/* NOTE: the pointer returned is a static copy, which is
re-used everytime it is called. If the calling function
wants to mess about with the returned string, a copy
has to be made.
NULL is returned if the resulting file can't be opened.
the calling function can inspect the result of
messSysErrorText(), the report the resaon for failure */
/************************************************************/
UTIL_FUNC_DEF char *helpLinkGetFilename (char *link)
{
static char link_path_array[MAXPATHLEN] = "";
char *link_path = &link_path_array[0];
if (link[0] == SUBDIR_DELIMITER) /* absolute path (UNIX) */
{
strcpy (link_path, link);
}
else /* relative path */
{
strcpy (link_path, helpGetDir());
strcat (link_path, SUBDIR_DELIMITER_STR);
strcat (link_path, link);
}
if (filName(link_path, "", "r"))
return link_path;
return NULL;
} /* helpLinkGetFilename */
/************************************************************/
/****************** ***********************/
/************** private helpPackage functions ***************/
/****************** ***********************/
/************************************************************/
HtmlPage *htmlPageCreate (char *helpFilename)
/* complemeted by htmlPageDestroy */
{
FILE *fil;
HtmlPage *page = 0;
if (!helpFilename) /* we could get a NULL filename */
return 0; /* here, which might come from
helpSubjectGetFilename() that couldn't
find a file matching the subject */
/* create a page with a marked up directory listing */
if (strcmp(helpFilename, "?") == 0)
{
page = messalloc (sizeof(HtmlPage));
page->handle = handleCreate();
page->htmlText = makeHtmlIndex(page->handle);
if (!(page->root = parseHtmlText(page->htmlText, page->handle)))
htmlPageDestroy(page);
return page;
}
if (!(filName(helpFilename, "", "r")))
return 0; /* prevent error caused
by unsucsessful filopen */
/* create a page inlining the image */
if (strcasecmp (helpFilename + (strlen(helpFilename)-4), ".gif") == 0)
{
page = messalloc (sizeof(HtmlPage));
page->handle = handleCreate();
page->htmlText = makeHtmlImagePage(helpFilename, page->handle);
if (!(page->root = parseHtmlText(page->htmlText, page->handle)))
htmlPageDestroy(page);
return page;
}
/* assume HTML page */
if ((fil = filopen(helpFilename, "", "r")))
{
page = htmlPageCreateFromFile (fil);
filclose (fil);
}
return page;
} /* htmlPageCreate */
/************************************************************/
HtmlPage *htmlPageCreateFromFile (FILE *fil)
{
HtmlPage *page;
int fileSize;
if (!fil)
return (HtmlPage*)0;
/* determine filesize */
rewind (fil);
fseek (fil, 0, SEEK_END);
fileSize = ftell (fil);
rewind (fil);
if (fileSize == 0)
return (HtmlPage*)0;
/* if we have a positive fileSize, we are pretty much
guaranteed, that we'll get some HTML text and a parsetree */
page = messalloc (sizeof(HtmlPage));
page->handle = handleCreate();
/* grab the contents of the file */
page->htmlText = halloc ((fileSize + 1) * sizeof(char), page->handle);
fread (page->htmlText, sizeof (char), fileSize, fil);
page->htmlText[fileSize] = '\0'; /* add string terminator */
/* get parsetree */
page->root = parseHtmlText(page->htmlText, page->handle);
return page;
} /* htmlPageCreateFromFile */
/************************************************************/
void htmlPageDestroy (HtmlPage *page)
{
if (!page) return;
/* clear all memory used during parsing of the page */
handleDestroy (page->handle);
/* clear the memory taken up by the structure itself */
messfree (page);
return;
} /* htmlPageDestroy */
/************************************************************/
void stripSpaces (char *cp)
/* utility to get rid of multiple spaces from a string */
/* we use it on node->text, where the text isn't within <PRE> tags */
{
char *s ;
int i ;
/* strip unwanted white spaces from the text */
for (i = 0; i < strlen(cp); ++i)
if (isspace ((int)cp[i])) cp[i] = ' ' ;
while ((s = strstr (cp, " ")))
{
s[1] = 0 ;
strcat (cp, s+2) ;
}
if (cp[strlen(cp)-1] == ' ')
cp[strlen(cp)-1] = '\0' ;
return ;
} /* stripSpaces */
/************************************************************/
/****************** ***********************/
/****************** static functions ***********************/
/****************** ***********************/
/************************************************************/
/************************************************************/
/* as the helpviewer supports inlined images, it is easy
to display image, even when they're not inlined as in
<A HREF=image.gif>click here for image</A>.
We just return a container page, that inlines the image */
/************************************************************/
static char *makeHtmlImagePage (char *link, STORE_HANDLE handle)
{
char *text;
int len;
len = 0;
len = 7+6+strlen(filGetFilename(link))+8+10+strlen(link)+2;
text = halloc((len+1)*sizeof(char), handle);
sprintf (text,
"<TITLE>Image %s</TITLE>"
"<IMG SRC=\"%s\">", filGetFilename(link), link);
text[len] = 0;
return text;
} /* makeHtmlImagePage */
/************************************************************/
/* reads the directory of helpDir and constructs an HTML-page
containing a <UL>-list of all HTML-files in helpDir */
/************************************************************/
static char *makeHtmlIndex (STORE_HANDLE handle)
{
char *cp, *text, *s ;
int i, len ;
Array dirList;
if(!(dirList = filDirectoryCreate
(helpGetDir(), HELP_FILE_EXTENSION, "r")) )
{
messout ("Can't open help directory %s\n"
"(%s)",
helpDir, messSysErrorText()) ;
return 0 ;
}
len = 0 ;
/* determine the length of the text to be returned */
len += 39+15+5+6 ; /* for header */
for (i = 0 ; i < arrayMax(dirList) ; i++)
{
s = arr(dirList,i,char*) ;
len += strlen(s)*2 + strlen(HELP_FILE_EXTENSION) + 19;
/* this is the length of each line as written
to the string by sprintf(cp,"<LI>...") below */
}
text = (char*)halloc ((len+1) * sizeof(char), handle) ;
cp = text ;
sprintf (cp,
"<TITLE>Index of Help Directory</TITLE>\n"
"<H1>Index</H1>\n"
"<UL>\n") ;
cp += 39+15+5 ;
for (i = 0 ; i < arrayMax(dirList) ; i++)
{
s = arr(dirList, i, char*) ;
sprintf (cp, "<LI><A HREF=%s.%s>%s</A>\n",
s, HELP_FILE_EXTENSION, s) ;
cp += strlen(s)*2 + strlen(HELP_FILE_EXTENSION) + 19;
}
sprintf (cp, "</UL>\n") ;
text[len] = 0 ;
filDirectoryDestroy (dirList) ;
return text ;
} /* makeHtmlIndex */
/************************************************************/
/*************************************************************
***************** HTML Parsing package *********************
*** currently very crude parser, will fall over any bad ****
*** whether Mosaic, Netscape or MSIE can deal with or not. **
************************************************************/
static HtmlNode *parseHtmlText(char *text, STORE_HANDLE handle)
/* return root node of html parse-tree,
generated from the HTML source text */
{
char *cp = text;
HtmlNode *node;
if (!text) return 0;
/* start recursion */
parseSection (&cp, &node, handle) ;
return node; /* return root-node */
} /* parseHtmlText */
/************************************************************/
static void skipSpaces (char **cp)
{
while (**cp && isspace((int)**cp)) { ++(*cp) ; }
} /* skipSpaces */
/************************************************************/
static void replaceEscapeCodes (char *cp)
{
char *s ;
/*
quotation mark " --> " " --> "
ampersand & --> & & --> &
less-than sign < --> < < --> <
greater-than sign > --> > > --> >
*/
s = cp ;
while (*s)
{
if (strncasecmp (s, """, 5) == 0)
{
s[0] = '"' ; s[1] = 0 ;
strcat (s+1, s+5) ;
}
else if (strncasecmp (s, "&", 5) == 0)
{
s[0] = '&' ; s[1] = 0 ;
strcat (s+1, s+5) ;
}
else if (strncasecmp (s, "<", 5) == 0)
{
s[0] = '<' ; s[1] = 0 ;
strcat (s+1, s+5) ;
}
else if (strncasecmp (s, ">", 5) == 0)
{
s[0] = '>' ; s[1] = 0 ;
strcat (s+1, s+5) ;
}
else if (strncasecmp (s, """, 6) == 0)
{
s[0] = '"' ; s[1] = 0 ;
strcat (s+1, s+6) ;
}
else if (strncasecmp (s, "&", 5) == 0)
{
s[0] = '&' ; s[1] = 0 ;
strcat (s+1, s+5) ;
}
else if (strncasecmp (s, "<", 4) == 0)
{
s[0] = '<' ; s[1] = 0 ;
strcat (s+1, s+4) ;
}
else if (strncasecmp (s, ">", 4) == 0)
{
s[0] = '>' ; s[1] = 0 ;
strcat (s+1, s+4) ;
}
else if (strncasecmp (s, " ", 4) == 0)
{
s[0] = ' ' ; s[1] = 0 ;
strcat (s+1, s+6) ;
}
++s ;
}
return ;
} /* replaceEscapeCodes */
/************************************************************/
static HtmlNode *makeNode (HtmlNodeType type, STORE_HANDLE handle)
/* allocate a node and initialise the type */
{
HtmlNode *newnode ;
newnode = (HtmlNode*)halloc (sizeof(HtmlNode), handle) ;
newnode->type = type ;
return (newnode) ;
} /* makeNode */
/************************************************************/
static BOOL parseHtml (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 6 ; /* skip <HTML> */
skipSpaces (cp) ;
node = makeNode (HTML_DOC, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : text inside <HTML> not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</HTML>", 7) == 0)
{
*cp += 7 ;
}
else
{
printf ("Warning : <HTML> tag not closed by </HTML> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseHtml */
/************************************************************/
static BOOL parseHead (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 6 ; /* skip <HEAD> */
skipSpaces (cp) ;
node = makeNode (HTML_HEAD, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : HTML inside <head> not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</HEAD>", 7) == 0)
{
*cp += 7 ;
}
else
{
printf ("Warning : <HEAD> tag not closed by </HEAD> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseHead */
/************************************************************/
static BOOL parseBody (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 6 ; /* skip <BODY> */
skipSpaces (cp) ;
node = makeNode (HTML_BODY, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : HTML inside <BODY> not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</BODY>", 7) == 0)
{
*cp += 7 ;
}
else
{
printf ("Warning : <BODY> tag not closed by </BODY> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseBody */
/************************************************************/
static BOOL parseComment (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node ;
int len ;
char *start ;
*cp += 4 ; /* skip <!-- */
start = *cp ;
while (**cp && **cp != '>') { ++(*cp) ; }
if (!**cp)
{
*resultnode = 0 ;
return FALSE ;
}
node = makeNode (HTML_COMMENT, handle) ;
len = *cp-start ;
++(*cp) ; /* skip '>' */
node->text = (char*)halloc ((len+1) * sizeof(char), handle) ;
strncpy (node->text, start, len) ;
node->text[len] = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseComment */
/************************************************************/
static BOOL parseTitle (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node ;
int len, numspaces=0 ;
char *start ;
*cp += 7 ; /* skip <TITLE> */
skipSpaces (cp) ;
start = *cp ;
while (**cp)
{
if (strncasecmp (*cp, "</title>", 8) == 0)
break ;
if (isspace((int)**cp))
++numspaces ;
else
numspaces = 0 ;
++(*cp) ;
}
node = makeNode (HTML_TITLE, handle) ;
len = (*cp-start) - numspaces ;
if (**cp)
*cp += 8 ;
node->text = (char*)halloc ((len+1) * sizeof(char), handle);
strncpy (node->text, start, len) ;
node->text[len] = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseTitle */
/************************************************************/
static BOOL parseHeader (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
int level ;
level = (*cp)[2]-'0' ;
*cp += 4 ; /* skip <H?> */
skipSpaces (cp) ;
node = makeNode (HTML_HEADER, handle) ;
node->hlevel = level ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : heading%d text not valid !!\n", level) ;
}
skipSpaces (cp) ;
if ((strncasecmp (*cp, "</H", 3) == 0) &&
(*cp)[3]-'0' == level && (*cp)[4] == '>')
{
*cp += 5 ;
}
else
{
printf ("Warning : <H%d> tag not closed by </H%d> !!\n", level, level) ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseHeader */
/************************************************************/
static BOOL parseCode (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 6 ; /* skip <CODE> */
skipSpaces (cp) ;
node = makeNode (HTML_CODE_STYLE, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : <code> text not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</CODE>", 7) == 0)
{
*cp += 7 ;
}
else
{
printf ("Warning : <CODE> tag not closed by </CODE> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseCode */
/************************************************************/
static BOOL parseBold (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 3 ; /* skip <B> */
skipSpaces (cp) ;
node = makeNode (HTML_BOLD_STYLE, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : HTML inside <B> not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</B>", 3) == 0)
{
*cp += 4 ;
}
else
{
printf ("Warning : <B> tag not closed by </B> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseBold */
/************************************************************/
static BOOL parseStrong (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 8 ; /* skip <STRONG> */
skipSpaces (cp) ;
node = makeNode (HTML_STRONG_STYLE, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : strong text not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</STRONG>", 9) == 0)
{
*cp += 9 ;
}
else
{
printf ("Warning : <STRONG> tag not closed by </STRONG> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseStrong */
/************************************************************/
static BOOL parseItalic (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 3 ; /* skip <I> */
skipSpaces (cp) ;
node = makeNode (HTML_ITALIC_STYLE, handle) ;
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : bold text not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</I>", 3) == 0)
{
*cp += 4 ;
}
else
{
printf ("Warning : <I> tag not closed by </I> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseItalic */
/************************************************************/
static BOOL parseText (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node ;
int len ;
char *start ;
start = *cp ;
while (**cp)
{
/* read until beginning of new TAG */
if (strncasecmp (*cp, "<", 1) == 0)
break ;
++(*cp) ;
}
if (*cp == start)
{
/* an unknown tag had been reached, the text read until that
will be of length zero, because parseSection() couldn't
recognise it, and passed the text here, where it reads
until it finds a '<', which it'll find imediately,
so the length will be zero */
while (**cp)
{
/* read until beginning of new TAG */
if (strncasecmp (*cp, ">", 1) == 0)
break ;
++(*cp) ;
}
++(*cp) ;
node = makeNode (HTML_UNKNOWN, handle) ;
/* copy unknown tag into node->text */
len = (*cp-start) ;
node->text = (char*)halloc ((len+1) * sizeof(char), handle);
strncpy (node->text, start, len);
node->text[len] = 0 ;
*resultnode = node ;
return TRUE ;
}
node = makeNode (HTML_TEXT, handle) ;
len = (*cp-start) ;
node->text = (char*)halloc ((len+1) * sizeof(char), handle);
strncpy (node->text, start, len) ;
node->text[len] = 0 ;
replaceEscapeCodes (node->text) ;
*resultnode = node ;
return TRUE ;
} /* parseText */
/************************************************************/
static BOOL parseHref (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
int hlen = -1; /* init for compiler happiness */
int numspaces ;
char *hstart = NULL; /* init for compiler happiness */
BOOL HAVE_HREF, IS_NAME_REF ;
*cp += 2 ; /* skip '<A' */
skipSpaces (cp) ;
IS_NAME_REF = FALSE ;
if (strncasecmp (*cp, "HREF=", 5) == 0)
{
HAVE_HREF = TRUE ;
*cp += 5 ; /* skip 'HREF=' */
}
else if (strncasecmp (*cp, "NAME=", 5) == 0)
{
HAVE_HREF = TRUE ;
IS_NAME_REF = TRUE ;
*cp += 5 ; /* skip 'NAME=' */
}
else
{
printf ("Warning : anchor tag <A without argument !!\n");
HAVE_HREF = FALSE ;
}
if (HAVE_HREF)
hstart = *cp ;
/* parse the href destination or if no arg given
just forward to next '>'*/
numspaces = 0 ;
while (**cp)
{
if (strncasecmp (*cp, ">", 1) == 0)
break ;
if (isspace((int)**cp))
++numspaces ;
else
numspaces = 0 ;
++(*cp) ;
}
if (HAVE_HREF)
hlen = (*cp-hstart) - numspaces ;
if (**cp)
*cp += 1 ; /* skip '>' */
node = makeNode (HTML_HREF, handle) ;
if (HAVE_HREF)
{
if ((hstart[0] == '"') && (hstart[hlen-1] == '"'))
{
++hstart ;
hlen -= 2 ;
}
node->isNameRef = IS_NAME_REF ;
node->link = (char*)halloc ((hlen+1) * sizeof(char), handle);
strncpy (node->link, hstart, hlen) ;
node->link[hlen] = 0 ;
}
else
node->link = 0 ; /* no link then */
if (!(parseSection (cp, &leftnode, handle)))
{
printf ("Warning : referenced text not valid !!\n") ;
}
skipSpaces (cp) ;
if (strncasecmp (*cp, "</a>", 4) == 0)
{
*cp += 4 ;
}
else
{
printf ("Warning : anchor tag not closed by </A> !!\n") ;
}
node->left = leftnode ;
node->right = 0 ;
*resultnode = node ;
return TRUE ;
} /* parseHref */
/************************************************************/
static BOOL parseImage (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node ;
int len, srclen, numspaces ;
char *start, *s ;
BOOL HAVE_SRC=FALSE ;
*cp += 4 ; /* skip '<IMG' */
skipSpaces (cp) ;
start = *cp ;
/* read in the arguments list until next '>'*/
numspaces = 0 ;
while (**cp)
{
if (strncasecmp (*cp, ">", 1) == 0)
break ;
if (isspace((int)**cp))
++numspaces ;
else
numspaces = 0 ;
++(*cp) ;
}
/* the length of everything between the
end of <IMG and the end of the args or the next > */
len = (*cp-start) - numspaces ;
if (**cp)
*cp += 1 ; /* skip '>' */
/* now find the SRC= argument */
s = start ;
while (*s)
{
if (strncasecmp (s, "src=", 4) == 0)
{
HAVE_SRC = TRUE ;
break ;
}
++s ;
}
if (HAVE_SRC)
{
s += 4 ; /* skip 'src=' */
len -= 4;
start = s ;
srclen = 0 ;
if (s[0] == '"') /* if src in quotes then link ends with quote */
{
s++ ; start++ ;
while (*s && ++srclen < len && *s != '"')
{ ++(s) ; }
--srclen; /* discard the quote */
}
else
{
while (*s && ++srclen < len && !isspace((int)*s))
{ ++(s) ; }
}
node = makeNode (HTML_GIFIMAGE, handle) ;
/* save the file name of the image */
node->link = (char*)halloc((srclen+1) * sizeof(char), handle);
strncpy (node->link, start, srclen) ;
node->link[srclen] = 0 ;
}
else
{
node = makeNode (HTML_UNKNOWN, handle) ;
}
*resultnode = node ;
return TRUE ;
} /* parseImage */
/************************************************************/
static BOOL parseListItem (HtmlListType style,
char **cp,
HtmlNode **resultnode,
STORE_HANDLE handle)
{
HtmlNode *node, *leftnode, *rightnode ;
int lstyle = style ;
skipSpaces (cp) ;
/* check, whether the next tag is a valid listitem tag */
/* with <DL> list <LI> and <DD> items are allowed */
if (lstyle == HTML_LIST_NOINDENT &&
!(strncasecmp (*cp, "<dd>", 4) == 0 ||
strncasecmp (*cp, "<li>", 4) == 0 ||
strncasecmp (*cp, "<dt>", 4) == 0))
{
*resultnode = 0 ;
return FALSE ;
}
/* only <LI> items in <UL> or <OL> lists */
else if ((lstyle == HTML_LIST_BULLET || lstyle == HTML_LIST_NUMBER) &&
!(strncasecmp (*cp, "<li>", 4) == 0))
{
*resultnode = 0 ;
return FALSE ;
}
if (lstyle == HTML_LIST_NOINDENT)
{
/* in <DL> list a <DD> item becomes indented but no bullet */
if (strncasecmp (*cp, "<dd>", 4) == 0)
lstyle = HTML_LIST_NOBULLET ;
else if (strncasecmp (*cp, "<dt>", 4) == 0)
lstyle = HTML_LIST_NOINDENT_NOBULLET ;
}
*cp += 4 ;
/* now cp stands right after an <LI> and parses the following
as a normal section */
parseSection (cp, &leftnode, handle) ;
node = makeNode (HTML_LISTITEM, handle) ;
node->left = leftnode ;
node->lstyle = lstyle ;
if (parseListItem (style, cp, &rightnode, handle))
{
node->right = rightnode ;
}
else
{
node->right = 0 ; /* no further list items */
}
*resultnode = node ;
return TRUE ;
} /* parseListItem */
/************************************************************/
static BOOL parseList (int style, char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode ;
*cp += 4 ; /* skip <UL> */
#ifdef ALLOW_SECONDLEVEL_LIST_LIST_DOESN_T_YET_WORK
if (strncasecmp (*cp, "<ul>", 4) == 0 ||
strncasecmp (*cp, "<ol>", 4) == 0 ||
strncasecmp (*cp, "<dl>", 4) == 0)
{
/* create list item for this list-in-list */
node = makeNode (HTML_LISTITEM, handle) ;
node->left = leftnode ;
node->lstyle = lstyle ;
}
#endif
parseListItem (style, cp, &leftnode, handle);
skipSpaces (cp) ;
if ((style == HTML_LIST_BULLET && strncasecmp (*cp, "</ul>", 5) == 0) ||
(style == HTML_LIST_NOINDENT && strncasecmp (*cp, "</dl>", 5) == 0) ||
(style == HTML_LIST_NUMBER && strncasecmp (*cp, "</ol>", 5) == 0))
{
*cp += 5 ; /* skip </ul> */
}
else
{
if (style == HTML_LIST_BULLET)
printf ("Warning : found <UL> without closing </UL> tag !!\n") ;
else if (style == HTML_LIST_NOINDENT)
printf ("Warning : found <DL> without closing </DL> tag !!\n") ;
else if (style == HTML_LIST_NUMBER)
printf ("Warning : found <OL> without closing </OL> tag !!\n") ;
}
node = makeNode (HTML_LIST, handle) ;
node->left = leftnode ;
node->lstyle = style ;
*resultnode = node ;
return TRUE ;
} /* parseList */
/************************************************************/
static BOOL parseSection (char **cp, HtmlNode **resultnode, STORE_HANDLE handle)
{
HtmlNode *node, *leftnode, *rightnode ;
static BOOL MODE_PREFORMAT=FALSE, MODE_BLOCKQUOTE=FALSE ;
if (!MODE_PREFORMAT)
skipSpaces (cp) ;
if (!**cp) /* EOF */
{
if (MODE_PREFORMAT)
printf ("Warning : found <PRE> tag "
"without closing </PRE> tag !!\n") ;
if (MODE_BLOCKQUOTE)
printf ("Warning : found <BLOCKQUOTE> tag "
"without closing </BLOCKQUOTE> tag !!\n") ;
*resultnode = 0 ;
return TRUE ;
}
if (strncasecmp (*cp, "<!--", 4) == 0)
{
if (!parseComment (cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "<html>", 6) == 0)
{
if (!(parseHtml (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</html>", 7) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<head>", 6) == 0)
{
if (!(parseHead (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</head>", 7) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<body>", 6) == 0)
{
if (!(parseBody (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</body>", 7) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<title>", 7) == 0)
{
if (!parseTitle (cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if ((strncasecmp (*cp, "<H", 2) == 0) &&
(*cp)[2]-'0' >= 1 && (*cp)[2]-'0' <= 7 && (*cp)[3] == '>')
{
if (!parseHeader (cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if ((strncasecmp (*cp, "</H", 3) == 0) &&
(*cp)[3]-'0' >= 1 && (*cp)[3]-'0' <= 7 && (*cp)[4] == '>')
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<a", 2) == 0 &&
(isspace((int)(*cp)[2]) || (*cp)[2] == '\n'))
{
if (!parseHref (cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</a>", 4) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<img", 4) == 0)
{
if (!parseImage (cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "<ul>", 4) == 0)
{
if (!parseList (HTML_LIST_BULLET, cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "<ol>", 4) == 0)
{
if (!parseList (HTML_LIST_NUMBER, cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "<dl>", 4) == 0)
{
if (!parseList (HTML_LIST_NOINDENT, cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "<li>", 4) == 0)
{
/* LI isn't a section, so we've hit the end of a section */
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<dd>", 4) == 0)
{
/* DD isn't a section, so we've hit the end of a section */
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<dt>", 4) == 0)
{
/* DT isn't a section, so we've hit the end of a section */
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "</ul>", 5) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "</ol>", 5) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "</dl>", 5) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<hr>", 4) == 0)
{
leftnode = makeNode (HTML_RULER, handle) ;
*cp += 4 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "<p>", 3) == 0)
{
leftnode = makeNode (HTML_PARAGRAPH, handle) ;
*cp += 3 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "</p>", 4) == 0)
{
leftnode = makeNode (HTML_PARAGRAPH, handle) ;
*cp += 4 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "<br>", 4) == 0)
{
leftnode = makeNode (HTML_LINEBREAK, handle) ;
*cp += 4 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "<pre>", 5) == 0)
{
if (MODE_PREFORMAT)
printf ("Warning : nesting of <PRE> tags without effect !!\n") ;
MODE_PREFORMAT = TRUE ;
leftnode = makeNode (HTML_STARTPREFORMAT, handle) ;
*cp += 5 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "</pre>", 6) == 0)
{
if (!MODE_PREFORMAT)
printf ("Warning : found </PRE> without preceeding <PRE>\n") ;
MODE_PREFORMAT = FALSE ;
leftnode = makeNode (HTML_ENDPREFORMAT, handle) ;
*cp += 6 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "<blockquote>", 12) == 0)
{
if (!MODE_BLOCKQUOTE)
{
leftnode = makeNode (HTML_STARTBLOCKQUOTE, handle) ;
MODE_BLOCKQUOTE = TRUE ;
}
else
printf ("Warning : nesting of <BLOCKQUOTE> tags "
"without effect !!\n") ;
*cp += 12 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "</blockquote>", 13) == 0)
{
if (MODE_BLOCKQUOTE)
{
leftnode = makeNode (HTML_ENDBLOCKQUOTE, handle) ;
MODE_BLOCKQUOTE = FALSE ;
}
else
printf ("Warning : found </BLOCKQUOTE> "
"without preceeding <BLOCKQUOTE>\n") ;
*cp += 13 ;
skipSpaces (cp) ;
}
else if (strncasecmp (*cp, "<code>", 6) == 0)
{
if (!(parseCode (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</code>", 7) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<b>", 3) == 0)
{
if (!(parseBold (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</b>", 4) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<strong>", 8) == 0)
{
if (!(parseStrong (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</strong>", 9) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else if (strncasecmp (*cp, "<i>", 3) == 0)
{
if (!(parseItalic (cp, &leftnode, handle)))
{
*resultnode = 0 ;
return FALSE ;
}
}
else if (strncasecmp (*cp, "</i>", 4) == 0)
{
*resultnode = 0 ;
return TRUE ;
}
else
{
if (!parseText (cp, &leftnode, handle))
{
*resultnode = 0 ;
return FALSE ;
}
}
node = makeNode (HTML_SECTION, handle) ;
node->left = leftnode ;
if (leftnode->type == 0)
{
printf ("section on section \n") ;
}
if (parseSection (cp, &rightnode, handle))
{
node->right = rightnode ;
*resultnode = node ;
return TRUE ;
}
else
{
node->right = 0 ;
*resultnode = node ;
return FALSE ;
}
} /* parseSection */
/************************************************************/
|