home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Text / hyper / guideml.lha / GuideML3 / GuideML.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-03  |  108.1 KB  |  3,537 lines

  1. /***************************************************************
  2. **                                                            **
  3. **      GuideML -- Converts AmigaGuide into HTML              **
  4. **                                                            **
  5. ***************************************************************/
  6. /*
  7. **  Copyright (C) 1997-98 Richard Körber  --  All Rights Reserved
  8. **    E-Mail: shred@eratosthenes.starfleet.de
  9. **    URL:    http://shredzone.home.pages.de
  10. **
  11. ** Updated 2001-2004 by Chris Young
  12. ** chris@unsatisfactorysoftware.co.uk
  13. ** http://www.unsatisfactorysoftware.co.uk
  14. ***************************************************************/
  15. /*
  16. **  This program is free software; you can redistribute it and/or modify
  17. **  it under the terms of the GNU General Public License as published by
  18. **  the Free Software Foundation; either version 2 of the License, or
  19. **  any later version.
  20. **
  21. **  This program is distributed in the hope that it will be useful,
  22. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. **  GNU General Public License for more details.
  25. **
  26. **  You should have received a copy of the GNU General Public License
  27. **  along with this program; if not, write to the Free Software
  28. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. **
  30. **  The author (Richard Körber) reserves the right to revoke the
  31. **  GNU General Public License whenever he feels that it is necessary,
  32. **  especially when he found out that the licence has been abused,
  33. **  ignored or violated, and without prior notice.
  34. **
  35. **  You must not use this source code to gain profit of any kind!
  36. **
  37. ***************************************************************/
  38. /*
  39. ** If you use an editor that is capable of text folding, use
  40. ** "//>" and "//<" as begin and end fold markers, respectively.
  41. */
  42.  
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include <clib/alib_protos.h>
  46. #include <clib/exec_protos.h>
  47. #include <clib/dos_protos.h>
  48. #include <pragmas/exec_pragmas.h>
  49. #include <pragmas/dos_pragmas.h>
  50. #include <exec/lists.h>
  51. #include <exec/nodes.h>
  52. #include <exec/memory.h>
  53. #include <dos/dos.h>
  54. #include <libraries/dos.h>
  55.  
  56. #include <exec/types.h>
  57. #include <exec/io.h>
  58. #include <clib/asl_protos.h>
  59. #include <clib/intuition_protos.h>
  60. #include <clib/window_protos.h>
  61. #include <clib/layout_protos.h>
  62. #include <clib/checkbox_protos.h>
  63. #include <clib/button_protos.h>
  64. #include <clib/label_protos.h>
  65. #include <clib/chooser_protos.h>
  66. #include <clib/getfile_protos.h>
  67. #include <clib/clicktab_protos.h>
  68. #include <clib/string_protos.h>
  69. // #include <clib/integer_protos.h>
  70. // #include <clib/listbrowser_protos.h>
  71. #include <clib/gadtools_protos.h>
  72. #include <clib/icon_protos.h>
  73.  
  74. #include <intuition/intuition.h>
  75. #include <libraries/gadtools.h>
  76. #include <workbench/icon.h>
  77.  
  78. #include <stdlib.h>
  79.  
  80. #include <classes/window.h>
  81. #include <gadgets/layout.h>
  82. #include <gadgets/checkbox.h>
  83. #include <gadgets/button.h>
  84. #include <gadgets/chooser.h>
  85. #include <gadgets/clicktab.h>
  86. // #include <gadgets/integer.h>
  87. #include <gadgets/string.h>
  88. // #include <gadgets/listbrowser.h>
  89. #include <gadgets/getfile.h>
  90. #include <images/label.h>
  91.  
  92. #include <reaction/reaction.h>
  93. #include <reaction/reaction_macros.h>
  94.  
  95.  
  96.  
  97. #define VERSIONSTR "3.1"                 /* Version Nr */
  98. #define VERSIONDATE "03.01.2004"            /* Version Date */
  99. #define LINELEN (1024)                    /* Maximum length of a line */
  100.  
  101. extern struct Library *DOSBase;
  102. struct Library *aslbase;
  103. struct Library *intuitionbase;
  104. struct Library *WindowBase;
  105. struct Library *GadToolsBase;
  106. struct Library *LayoutBase;
  107. struct Library *ButtonBase;
  108. struct Library *CheckBoxBase;
  109. struct Library *LabelBase;
  110. struct Library *ChooserBase;
  111. struct Library *ClickTabBase;
  112. // struct Library *IntegerBase;
  113. struct Library *StringBase;
  114. // struct Library *ListBrowserBase;
  115. struct Library *GetFileBase;
  116. struct Library *IconBase;
  117.  
  118. int err(char *,char *,int);
  119. void ui();
  120. void free_list(struct List *);
  121. void freetablist(struct List *);
  122. BOOL make_list(struct List *, UBYTE **);
  123. BOOL maketablist(struct List *, UBYTE **);
  124. void gettooltypes(); // struct WBArg *);
  125. struct Menu *addmenu(struct Window *);
  126. void cleanup(int);
  127.  
  128. enum
  129. {
  130.     GID_MAIN=0,
  131.     GID_CONV,
  132.     GID_FILE,
  133.     GID_TO,
  134.     GID_HOMEURL,
  135.     GID_FINDURL,
  136.     GID_PREV,
  137.     GID_NEXT,
  138.     GID_INDEX,
  139.     GID_TOC,
  140.     GID_HELP,
  141.     GID_RETRACE,
  142.     GID_HOME,
  143.     GID_FIND,
  144.     GID_BAR,
  145.     GID_BODY,
  146.     GID_LINKS,
  147.     GID_MSDOS,
  148.     GID_CSS,
  149.     GID_HTMLHEADF,
  150.     GID_HTMLFOOTF,
  151.     GID_WRAP,
  152.     GID_VARWIDTH,
  153.     GID_NAVBAR,
  154.     GID_MOZNAV,
  155.     GID_IMAGES,
  156.     GID_SHOWALL,
  157.     GID_TABS,
  158.     GID_PAGE,
  159.     GID_LAST
  160. };
  161.  
  162. enum
  163. {
  164.     WID_MAIN=0,
  165.     WID_LAST
  166. };
  167.  
  168. enum
  169. {
  170.     OID_MAIN=0,
  171.     OID_LAST
  172. };
  173.  
  174. struct Gadget *gadgets[GID_LAST];
  175.  
  176. char VerStr[] = "\0$VER: GuideML "VERSIONSTR" ("VERSIONDATE")";
  177.   static unsigned char defbar[] = " | ";
  178. //    struct WBArg *wbarg;
  179.  
  180.  
  181. struct Parameter                          /* Structure of Shell parameters */
  182. {
  183.   STRPTR from;
  184.   STRPTR to;
  185.   STRPTR homeurl;
  186.   STRPTR findurl;
  187.   STRPTR prev;
  188.   STRPTR next;
  189.   STRPTR index;
  190.   STRPTR toc;
  191.   STRPTR help;
  192.   STRPTR retrace;
  193.   STRPTR home;
  194.   STRPTR find;
  195.   STRPTR bar;
  196.   STRPTR bodyext;
  197.   LONG   verbatim;
  198.   LONG   images;
  199.   LONG   footer;
  200.   LONG   nolink;
  201.   LONG   noemail;
  202.   LONG   nowarn;
  203.   LONG   msdos;
  204.   LONG   nonavbar;
  205.   LONG   nomoznav;
  206.   LONG   showall;
  207.   STRPTR htmltoptxt;
  208.   STRPTR htmlheadf;
  209.   STRPTR htmlbottxt;
  210.   STRPTR htmlfootf;
  211.   STRPTR cssurl;
  212.   LONG   wordwrap;
  213.   LONG    smartwrap;
  214.   LONG   varwidth;
  215.   LONG     noauto;
  216. }param = {NULL};
  217.  
  218.   long *htmltop;
  219.   long *htmlbot;
  220.  
  221. struct text
  222. {
  223.   STRPTR from;
  224.   STRPTR to;
  225.   STRPTR prev;
  226.   STRPTR next;
  227.   STRPTR index;
  228.   STRPTR toc;
  229.   STRPTR help;
  230.   STRPTR retrace;
  231.   STRPTR home;
  232.   STRPTR find;
  233.   STRPTR bar;
  234. };
  235.  
  236. struct text textlabs;
  237.  
  238. struct Entry                              /* List of all nodes and links */
  239. {
  240.   struct MinNode link;
  241.   ULONG Count;
  242.   char Node[100];
  243.   char Prev[100];
  244.   char Next[100];
  245.   char TOC[100];
  246.   char Help[100];
  247.   char Index[100];
  248.   char Titl[100];
  249. };
  250. struct MinList entries;
  251.  
  252. struct LinkStr                            /* Link bar alternative texts */
  253. {
  254.   char Prev[100];
  255.   char Next[100];
  256.   char Index[100];
  257.   char Toc[100];
  258.   char Home[100];
  259.   char Help[100];
  260.   char Find[100];
  261.   char Retrace[100];
  262. };
  263.  
  264. char Index[100];                          /* Index page name */
  265. char Help[100];
  266.  
  267. //Some dummy memory-allocating rodents for tooltype porpoises.
  268. char *ttfrom = 0;
  269. char *ttto = 0;
  270. char *tthomeurl = 0;
  271. char *ttfindurl = 0;
  272. char *ttprev = 0;
  273. char *ttnext = 0;
  274. char *ttindex = 0;
  275. char *tttoc = 0;
  276. char *tthelp = 0;
  277. char *ttretrace = 0;
  278. char *tthome = 0;
  279. char *ttfind = 0;
  280. char *ttbar = 0;
  281. char *ttbody = 0;
  282. char *tthtmlheadf = 0;
  283. char *tthtmlfootf = 0;
  284. char *ttcss = 0;
  285.  
  286. int wb=0;
  287. int ok=0;
  288.  
  289. char defname[100];
  290.  
  291. //> UBYTE Img#?[] = {...};
  292. /*
  293. **  These are the navigation bar images, in GIF format
  294. */
  295. UBYTE ImgHome[] =
  296. {
  297.   0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  298.   0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  299.   0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  300.   0x4A,0x08,0xBA,0x20,0xFC,0xB0,0x9D,0xD1,0x44,0x88,0x4B,0x9C,0x3D,0xF4,0xC5,0xDA,
  301.   0x26,0x1E,0x1F,0x14,0x8E,0x5B,0xC9,0x9C,0x28,0x69,0xB6,0x28,0x95,0x91,0x01,0x4B,
  302.   0x7B,0x73,0x70,0xD8,0x3A,0xAE,0x68,0x82,0x20,0x2A,0xE8,0x93,0xC0,0x50,0x25,0x4F,
  303.   0xED,0xC6,0x4C,0x92,0x76,0x4F,0x0F,0xD4,0x49,0x8C,0xEE,0x84,0xCE,0x51,0x0F,0x99,
  304.   0x09,0x78,0xBF,0xB4,0xAF,0x17,0x43,0x2E,0x9B,0x01,0x09,0x00,0x3B
  305.  
  306. };
  307. #define LEN_IMGHOME (0x7C)
  308.  
  309. UBYTE ImgIndex[] =
  310. {
  311.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  312.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  313.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  314.  0x41,0x28,0xBA,0xDC,0x12,0x40,0x9C,0x49,0xAB,0x85,0xD2,0x6A,0x8A,0x4F,0xF8,0x20,
  315.  0xE8,0x05,0x53,0xE7,0x2C,0x87,0x52,0x46,0x5B,0xDB,0x85,0xF0,0xB8,0x4A,0xA7,0xAA,
  316.  0x7A,0x6C,0xAB,0xBD,0xB0,0xF8,0xCD,0xA9,0x5A,0x10,0xA8,0xBB,0xB0,0x7A,0x3E,0x12,
  317.  0x8E,0x26,0xBC,0x75,0x8A,0x95,0x27,0x74,0x86,0xAC,0x42,0x00,0xD8,0xAC,0x76,0x9B,
  318.  0x4D,0x00,0x00,0x3B
  319.  
  320.  
  321. };
  322. #define LEN_IMGINDEX (0x73)
  323.  
  324. UBYTE ImgNext[] =
  325. {
  326.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  327.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  328.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  329.  0x33,0x08,0xBA,0x2A,0xFC,0xB0,0x8D,0x48,0x81,0x38,0xB3,0xBE,0x8B,0x35,0xE3,0xDD,
  330.  0x27,0x8C,0xE4,0x78,0x9C,0x61,0x83,0xAE,0x6C,0x0A,0xB6,0x6C,0xA0,0xC2,0xF1,0x22,
  331.  0x04,0x78,0x8E,0xAF,0xB2,0x07,0xF6,0xBE,0x13,0x30,0x38,0xF4,0x15,0x7D,0x9E,0xA4,
  332.  0x72,0xA9,0x4C,0x00,0x00,0x3B
  333.  
  334.  
  335. };
  336. #define LEN_IMGNEXT (0x65)
  337.  
  338. UBYTE ImgPrev[] =
  339. {
  340.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  341.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  342.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  343. 0x37,0x08,0xBA,0x10,0xFC,0x10,0x08,0x17,0xA3,0x38,0xB4,0xB2,0x8B,0xF5,0x3E,0x60,
  344. 0xA6,0x71,0xA0,0x60,0x9E,0xE7,0x42,0x82,0x6C,0xDB,0x01,0x83,0x2B,0xB3,0x59,0x3C,
  345. 0xBB,0xA2,0x1D,0x06,0x7C,0xCF,0x3F,0x3A,0x91,0xC7,0x26,0x1C,0xBE,0x3C,0x8C,0x41,
  346. 0x11,0xB9,0x44,0x3A,0x9F,0xD0,0x48,0x02,0x00,0x3B
  347.  
  348.  
  349. };
  350. #define LEN_IMGPREV (0x69)
  351.  
  352. UBYTE ImgTOC[] =
  353. {
  354.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  355.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  356.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  357. 0x34,0x08,0xBA,0x20,0xFC,0xB0,0x9D,0x11,0xA3,0x38,0x98,0xD6,0x75,0x71,0xDE,0x92,
  358. 0xE7,0x69,0x50,0x27,0x8E,0xE5,0xA9,0x92,0x4D,0xE0,0xBA,0xDE,0xFB,0x56,0x66,0x00,
  359. 0x72,0xF1,0xAD,0xD4,0x7A,0x78,0xD8,0x3A,0x5E,0x30,0x37,0xC4,0x00,0x6F,0x02,0x59,
  360. 0x6F,0xC9,0x54,0x24,0x00,0x00,0x3B
  361. };
  362. #define LEN_IMGTOC (0x66)
  363.  
  364. // below are temporary images
  365. UBYTE ImgHelp[] =
  366. {
  367.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  368.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  369.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  370. 0x36,0x08,0x2A,0xDC,0x32,0x2A,0x4A,0x71,0xAA,0xAD,0x50,0xAE,0xCB,0x4F,0xD0,0x00,
  371. 0x15,0x8C,0x24,0xE5,0x69,0xE6,0x37,0x55,0x6A,0x94,0xAE,0x27,0x28,0xB4,0x21,0x0B,
  372. 0xDE,0xEF,0x2D,0xC7,0x3A,0x4C,0xF7,0x0A,0x1E,0x70,0x08,0x64,0x10,0x5D,0xB6,0x63,
  373. 0xEE,0x38,0x3A,0x3A,0x9F,0x92,0x04,0x00,0x3B
  374.  
  375. };
  376. #define LEN_IMGHELP (0x68)
  377.  
  378. UBYTE ImgFind[] =
  379. {
  380.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  381.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  382.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  383. 0x42,0x08,0x0A,0xD2,0xBD,0x30,0x8A,0x43,0xE9,0x88,0x92,0x86,0x6D,0xB1,0x9A,0x47,
  384. 0xB0,0x0C,0x5D,0x16,0x46,0xE4,0x09,0x4D,0x22,0xC6,0x66,0x2D,0x2C,0xBB,0xEA,0x02,
  385. 0x5E,0xAB,0x86,0xA5,0x38,0xA3,0x7B,0x29,0x47,0xE5,0xD0,0x43,0x0D,0x43,0x95,0x22,
  386. 0x64,0xC3,0x04,0xA4,0x88,0x1E,0x60,0x32,0xBA,0xFB,0x51,0x21,0x83,0xCD,0x75,0xCB,
  387. 0x8D,0x24,0x00,0x00,0x3B
  388.  
  389. };
  390. #define LEN_IMGFIND (0x74)
  391.  
  392. UBYTE ImgRetrace[] =
  393. {
  394.  0x47,0x49,0x46,0x38,0x39,0x61,0x12,0x00,0x12,0x00,0xF2,0x00,0x00,0xCC,0xCC,0xCC,
  395.  0x00,0x00,0x00,0xFF,0xFF,0xFF,0x88,0x88,0x88,0xAA,0x22,0x00,0xDD,0x55,0x00,0xEE,
  396.  0xBB,0x00,0xAD,0xC1,0xD5,0x2C,0x00,0x00,0x00,0x00,0x12,0x00,0x12,0x00,0x02,0x03,
  397. 0x42,0x28,0x02,0xA0,0xCE,0x30,0x8A,0xA3,0x8E,0xB5,0x6A,0x44,0x36,0xAF,0xBF,0x9A,
  398. 0x74,0x05,0x24,0xE9,0x85,0xDC,0x18,0x0D,0xA0,0x54,0x92,0x6B,0xBB,0xCD,0xE9,0x11,
  399. 0xD0,0x74,0x77,0xE3,0x9B,0xCE,0xF7,0x96,0x5D,0x43,0x91,0x0B,0x8A,0x0E,0xA8,0x9A,
  400. 0xED,0x48,0x71,0x74,0x96,0x1B,0xD6,0x47,0x45,0x33,0x79,0x60,0xBF,0x97,0xF0,0xC7,
  401. 0xED,0xF2,0x12,0x00,0x3B
  402.  
  403. };
  404. #define LEN_IMGRETRACE (0x74)
  405.  
  406. //<
  407.  
  408. //> STRPTR entity[96] = {...};
  409. /*
  410. ** This are the full names of all HTML entities
  411. */
  412. STRPTR entity[96] =
  413. {
  414.   "nbsp","iexcl","cent","pound","curren","yen","brvbar","sect","uml",
  415.   "copy","ordf","laquo","not","shy","reg","macr","deg","plusmn","sup2",
  416.   "sup3","acute","micro","para","middot","cedil","sup1","ordm","raquo",
  417.   "frac14","frac12","frac34","iquest","Agrave","Aacute","Acirc","Atilde",
  418.   "Auml","Aring","AElig","Ccedil","Egrave","Eacute","Ecirc","Euml","Igrave",
  419.   "Iacute","Icirc","Iuml","ETH","Ntilde","Ograve","Oacute","Ocirc","Otilde",
  420.   "Ouml","times","Oslash","Ugrave","Uacute","Ucirc","Uuml","Yacute","THORN",
  421.   "szlig","agrave","aacute","acirc","atilde","auml","aring","aelig","ccedil",
  422.   "egrave","eacute","ecirc","euml","igrave","iacute","acirc","iuml","eth",
  423.   "ntilde","ograve","oacute","ocirc","otilde","ouml","divide","oslash",
  424.   "ugrave","uacute","ucirc","uuml","yacute","thorn","yuml"
  425. };
  426. //<
  427. //> STRPTR agpens[] , htmlpens[]
  428. /*
  429. ** This are the pen names in AmigaGuide documents
  430. */
  431. STRPTR agpens[] =
  432. {
  433.   "text}","shine}","shadow}","fill}","filltext}","background}","highlight}",
  434.   NULL
  435. };
  436.  
  437. /*
  438. ** And this are the appropriate HTML colors
  439. */
  440. STRPTR htmlpens[] =
  441. {
  442.   "#000000","#ffffff","#000000","#3864a0","#000000","#949494","#ffffff"
  443. };
  444.  
  445. STRPTR cssclass[] =
  446. {
  447.   "agtext","agshine","agshadow","agfill","agfilltext","agbackground","aghighlight"
  448. };
  449. //<
  450.  
  451. //> SaveImg()
  452. /*------------------------------------------------------------*
  453. *   SaveImg()        Saves one image                          *
  454. *     -> file File Name                                       *
  455. *     -> data Data buffer                                     *
  456. *     -> len  Length                                          *
  457. *     <-      Success                                         *
  458. */
  459. LONG SaveImg(STRPTR file, UBYTE *data, ULONG len)
  460. {
  461.   BPTR lock;
  462.  
  463.   if(lock = Lock(file,ACCESS_READ))       // Already existing?
  464.   {
  465.     UnLock(lock);
  466.     return(1);                            // then leave with success
  467.   }
  468.  
  469.   if(param.verbatim) Printf("Creating image '%s'\n",file);  // Report
  470.  
  471.   if(lock = Open(file,MODE_NEWFILE))      // Open the image file
  472.   {
  473.     if(-1 == Write(lock,data,len))        // Write the image
  474.     {
  475.       Close(lock);                        // Write failed, so
  476.       return(0);                          // return without success
  477.     }
  478.     Close(lock);                          // Write succeeded, so
  479.     return(1);                            // return with success
  480.   }
  481.   return(0);                              // No lock, no success
  482. }
  483. //<
  484. //> SaveImages()
  485. /*------------------------------------------------------------*
  486. *   SaveImages()     Saves all required images                *
  487. *     <-      Success                                         *
  488. */
  489. LONG SaveImages(void)
  490. {
  491.   for(;;)
  492.   {
  493.     if(param.homeurl)
  494.       if(!SaveImg("home.gif" ,ImgHome ,LEN_IMGHOME )) break;
  495.     if(param.retrace)
  496.       if(!SaveImg("retrace.gif" ,ImgRetrace ,LEN_IMGRETRACE )) break;
  497.     if(param.help)
  498.       if(!SaveImg("help.gif" ,ImgHelp ,LEN_IMGHELP )) break;
  499.     if(param.findurl)
  500.       if(!SaveImg("find.gif" ,ImgFind ,LEN_IMGFIND )) break;
  501.  
  502. //    if(*Index)
  503.       if(!SaveImg("index.gif",ImgIndex,LEN_IMGINDEX)) break;
  504.  
  505.     if(!SaveImg("next.gif" ,ImgNext ,LEN_IMGNEXT )) break;
  506.     if(!SaveImg("prev.gif" ,ImgPrev ,LEN_IMGPREV )) break;
  507.     if(!SaveImg("toc.gif"  ,ImgTOC  ,LEN_IMGTOC  )) break;
  508.     return(1);
  509.   }
  510.   return(0);
  511. }
  512. //<
  513.  
  514. //> CopyLink()
  515. /*------------------------------------------------------------*
  516. *   CopyLink()       Copies a link file name into a variable  *
  517. *     -> link Link                                            *
  518. *     -> var  String-Var                                      *
  519. */
  520. void CopyLink(STRPTR link, STRPTR var)
  521. {
  522.   char ch;
  523.  
  524.   var[0] = '\0';                          // Init
  525.  
  526.   while(*link && *link==' ') link++;      // Suppress spaces
  527.   if(!*link) return;                      //   there were only spaces!
  528.  
  529.   if(*link != '\"')
  530.   {                                       // Quick Mode
  531.     while((ch = *link++)!=' ' && ch!='\n')
  532.     {
  533.       if(ch==':') ch='/'; // colon to slash again
  534.       if(ch>='A' && ch<='Z') ch+=32; // upper to lower again
  535.       *var++ = ch;
  536.     }
  537.   }
  538.   else
  539.   {                                       // Quote Mode
  540.     link++;                               //   we had a leading quote
  541.     if(!*link) return;
  542.     while((ch = *link++)!='\"' && ch!='\n')
  543.     {
  544.       if(ch==' ') ch = '_'; // space converts to underscore
  545.       if(ch==':') ch = '/'; // colon converts to slash
  546.       if(ch>='A' && ch<='Z') ch+=32; // uppercase converts to lowercase
  547.       *var++ = ch;
  548.     }
  549.   }
  550.  
  551.   *var++ = '.';                           // Add html suffix
  552.   *var++ = 'h';
  553.   *var++ = 't';
  554.   *var++ = 'm';
  555.   if(!param.msdos) *var++ = 'l';
  556.   *var = '\0';
  557. }
  558. //<
  559. //> MyPutCh()
  560. /*------------------------------------------------------------*
  561. *   MyPutCh()       Writes single chars into HTML             *
  562. *     -> fh   output file handle                              *
  563. *     -> ch   Amiga char to be written                        *
  564. *     <-      -1 for failure                                  *
  565. */
  566. LONG MyPutCh(BPTR fh, unsigned char ch)
  567. {
  568.   if(ch<' ' && ch!='\n')                // Is it a control char?
  569.   {
  570.     return FPrintf(fh,"&#%03ld;",ch);   //   yes: return them as number
  571.   }
  572.   else if(ch < 128)                     // Is it an ASCII char?
  573.   {
  574.     if(ch=='\"') return FPuts(fh,""");     // Convert some exceptions
  575.     else if(ch=='&') return FPuts(fh,"&");
  576.     else if(ch=='<') return FPuts(fh,"<");   // #060
  577.     else if(ch=='>') return FPuts(fh,">"); // #062
  578.     else return FPutC(fh,ch);                   // else put char directly
  579.   }
  580.   else                                  // Chars >127 ?
  581.   {
  582.     if(ch>=160)                         // Do we have an entity name?
  583.       return FPrintf(fh,"&%s;",entity[ch-160]); // yes: use this one
  584.     else
  585.       return FPrintf(fh,"&#%03ld;",ch);         // no: use it's number
  586.   }
  587. }
  588. //<
  589. //> MyPuts()
  590. /*------------------------------------------------------------*
  591. *   MyPuts()        Writes a string into HTML                 *
  592. *     -> fh   Output file handle                              *
  593. *     -> str  String to be output                             *
  594. *     <-      -1 for failure                                  *
  595. */
  596. LONG MyPuts(BPTR fh, STRPTR str)
  597. {
  598.   unsigned char ch;
  599.  
  600.   while(ch = *str++)                        // go through the string
  601.   {
  602.     if(ch=='\"' || ch=='<' || ch=='>' || ch=='&')      // do NOT convert them
  603.     {                                       //  since they are also used
  604.       if(-1 == FPutC(fh,ch)) return(-1);    //  in HTML tags
  605.     }
  606.     else
  607.     {
  608.       if(-1 == MyPutCh(fh,ch)) return(-1);
  609.     }
  610.   }
  611.   return(0);
  612. }
  613. //<
  614. //> ConvLine()
  615. /*------------------------------------------------------------*
  616. *   ConvLine()      Converts an AmigaGuide line               *
  617. *     -> fh   output file handle                              *
  618. *     -> buf  Source buffer                                   *
  619. *     -> linenr line number                                   *
  620. *     <-      Success                                         *
  621. */
  622. LONG ConvLine(BPTR fh, STRPTR buf, ULONG linenr)
  623. {
  624.   unsigned char ch;
  625.   char linkstr[100];
  626.   register UWORD dolink  = !param.nolink;
  627.   register UWORD doemail = !param.noemail;
  628.  
  629. if((param.smartwrap) && (strlen(buf)<2))
  630.     {
  631.     if(-1 == FPuts(fh,"<br>")) return(0);
  632.     }
  633.  
  634.   while(ch = *buf++)                      // while chars available
  635.   {
  636.     if('\\'==ch)                          //   backslash escape character?
  637.     {
  638.       switch(*buf)
  639.       {
  640.         case '\\':                        // '\\' -> '\'
  641.         case '@':                         // '\@' -> '@'
  642.           if(-1 == MyPutCh(fh,*buf)) return(0);
  643.           buf++;
  644.           break;
  645.       }
  646.       continue;
  647.     }
  648.  
  649.     if(doemail)                           // email recognition activated?
  650.     {
  651.       if(  (ch>='a' && ch<='z')           // Could this be a valid email?
  652.          ||(ch>='A' && ch<='Z')
  653.          ||(ch>='0' && ch<='9'))
  654.       {
  655.         UWORD length   = 0;   // length of the email string
  656.         UWORD atfound  = 0;   // how many '@' were found?
  657.         UWORD charcnt  = 0;   // how many characters in total?
  658.         UWORD dotfound = 0;   // how many dots?
  659.         UWORD atdot    = 0;   // how many dots after the '@'?
  660.         UWORD chardot  = 0;   // how many chars after the last dot?
  661.         STRPTR index   = --buf;
  662.         UWORD i;
  663.         unsigned char ech;
  664.  
  665.         while(ech = *index++)
  666.         {
  667.           if(   !(ech>='a' && ech<='z')   // still a valid email char?
  668.              && !(ech>='A' && ech<='Z')
  669.              && !(ech>='0' && ech<='9')
  670.              && !(ech=='@' || ech=='.' || ech=='_' || ech=='-')) break;
  671.           length++;
  672.           if(ech=='@')                    // count '@'
  673.           {
  674.             if(*index=='{')               // is it an AmigaGuide attribute?
  675.             {
  676.               length--;                   //   exclude the '@'
  677.               break;                      //   the address is finished
  678.             }
  679.             atfound++;
  680.             atdot = 0;
  681.             continue;
  682.           }
  683.           if(ech=='.')                    // count '.'
  684.           {
  685.             dotfound++;
  686.             atdot++;
  687.             chardot = 0;
  688.             continue;
  689.           }
  690.           charcnt++;                      // one more char
  691.           chardot++;
  692.         }
  693.         if(   atfound==1                  // exactly one '@'
  694.            && dotfound>0                  // at least one '.' (domain.country)
  695.            && atdot>0                     //   this dot must be after the '@'
  696.            && chardot>=2 && chardot<=4    // domain must have two or three chars
  697.            && charcnt>6)                  // and we have also some chars
  698.         {
  699.           if(-1 == FPuts(fh,"<a href=\"mailto:")) return(0);  // Generate email link
  700.           for(i=0;i<length;i++)
  701.           {
  702.             if(-1 == FPutC(fh,buf[i])) return(0);
  703.           }
  704.           if(-1 == FPuts(fh,"\">")) return(0);
  705.           for(;length;length--)
  706.           {
  707.             if(-1 == FPutC(fh,*buf++)) return(0);
  708.           }
  709.           if(-1 == FPuts(fh,"</a>")) return(0);
  710.           continue;
  711.         }
  712.         buf++;
  713.       }
  714.     }
  715.  
  716.     if(dolink)                            // internet link recognition
  717.     {
  718.       if(  (!strnicmp(buf-1,"ftp://"  ,6))    // ftp://... - Link ?
  719.          ||(!strnicmp(buf-1,"gopher:" ,7))    // gopher:... - Link ?
  720.          ||(!strnicmp(buf-1,"http://" ,7))    // http://... - Link ?
  721.          ||(!strnicmp(buf-1,"https://",8))    // https://... - Link ?
  722.          ||(!strnicmp(buf-1,"mailto:" ,7))    // mailto:... - Link ?
  723.          ||(!strnicmp(buf-1,"news:"   ,5))    // news:... - Link ?
  724.          ||(!strnicmp(buf-1,"nntp:"   ,5))    // nntp:... - Link ?
  725.          ||(!strnicmp(buf-1,"telnet:" ,7))    // telnet:... - Link ?
  726.          ||(!strnicmp(buf-1,"www."    ,4)))   // www. - Link?
  727.       {
  728.         STRPTR bufstart;
  729.  
  730.         if(-1 == FPuts(fh,"<a href=\"")) return(0);
  731.  
  732.         if(!strnicmp(buf-1,"www.",4))
  733.           if(-1 == FPuts(fh,"http://")) return(0);
  734.  
  735.         bufstart = --buf;
  736.         while(ch = *buf++)
  737.         {
  738.           if(' '==ch || '\n'==ch || ')'==ch || ('@'==ch && '{'==*buf)) break;
  739.           if(-1 == FPutC(fh,ch)) return(0);
  740.         }
  741.         if(-1 == FPuts(fh,"\">")) return(0);
  742.         for(;bufstart<buf-1;bufstart++)     // followed by a verbatim copy
  743.         {
  744.           if(-1 == FPutC(fh,*bufstart)) return(0);
  745.         }
  746.         if(-1 == FPuts(fh,"</a>")) return(0);
  747.       }
  748.     }
  749.  
  750.     if('@'==ch && '{'==*buf)              // AmigaGuide command?
  751.     {
  752.       buf++;                              // read the command?
  753.       for(;;)
  754.       {
  755.         if('\"' == *buf)                  // is it a link?
  756.         {
  757.           STRPTR link;
  758.           UWORD  linkpos=0;
  759.           BOOL   linkquot=0;
  760.  
  761.           buf++;                          // skip the quotation marks
  762.           link = buf;
  763.           while(*link && *link!='\"') link++;
  764.           if(!*link) return(0);
  765.           link++;
  766.           while(*link && (*link==' ' || *link==',' || *link=='\t')) link++;
  767.           if(!*link) return(0);
  768.           if(strnicmp(link,"link",4))
  769.           {                               // this is NO link command!
  770.             if(-1 == FPuts(fh,"<u>")) return(0);
  771.             while((ch = *buf++) != '\"')
  772.               if(-1 == MyPutCh(fh,ch)) return(0);
  773.             if(-1 == FPuts(fh,"</u>")) return(0);
  774.             buf = link;
  775.             while(*buf && *buf!=' ') buf++;
  776.             *buf++ = '\0';
  777.             if(!param.nowarn) Printf("Line %ld: WARNING: '%s' command skipped!\n",linenr,link);
  778.             while(*buf && *buf!='}') buf++;
  779.             if(*buf =='}') buf++;
  780.             break;
  781.           }
  782.           link+=4;
  783.           while(*link && *link==' ') link++;
  784.           if(!*link) return(0);
  785.           if(*link == '\"')
  786.           {
  787.             link++;
  788.             linkquot=1;
  789.           }
  790.           while(*link && *link!='}')
  791.           {
  792.             ch = *link++;
  793.             if(ch=='\"' && linkquot) break;
  794.             if(ch>='A' && ch<='Z') ch+=32;
  795.             linkstr[linkpos++] = (ch==' ' || ch==':' ? '_' : ch);
  796.           }
  797.           while(*link && *link!='}') link++;
  798.           while(linkpos>0 && linkstr[linkpos-1] == '_') linkpos--;
  799.           if(linkstr[linkpos-1] == '\"') linkpos--;
  800.           linkstr[linkpos] = '\0';
  801.           if(!*link) return(0);
  802.           link++;
  803.           if(-1 == FPuts(fh,"<a href=\"")) return(0);
  804.           if(-1 == FPuts(fh,linkstr)) return(0);
  805.           if(param.msdos)
  806.           {
  807.             if(-1 == FPuts(fh,".htm\">")) return(0);
  808.           }
  809.           else
  810.           {
  811.             if(-1 == FPuts(fh,".html\">")) return(0);
  812.           }
  813.           while((ch = *buf++) != '\"')
  814.             if(-1 == MyPutCh(fh,ch)) return(0);
  815.           if(-1 == FPuts(fh,"</a>")) return(0);
  816.           buf = link;
  817.           break;
  818.         }
  819.  
  820.         if(!strnicmp(buf,"b}",2))         // @{B}
  821.         {
  822.           if(-1 == FPuts(fh,"<b>")) return(0);
  823.           buf += 2;
  824.           break;
  825.         }
  826.         if(!strnicmp(buf,"ub}",3))        // @{UB}
  827.         {
  828.           if(-1 == FPuts(fh,"</b>")) return(0);
  829.           buf += 3;
  830.           break;
  831.         }
  832.  
  833.         if(!strnicmp(buf,"i}",2))         // @{I}
  834.         {
  835.           if(-1 == FPuts(fh,"<i>")) return(0);
  836.           buf += 2;
  837.           break;
  838.         }
  839.         if(!strnicmp(buf,"ui}",3))        // @{UI}
  840.         {
  841.           if(-1 == FPuts(fh,"</i>")) return(0);
  842.           buf += 3;
  843.           break;
  844.         }
  845.  
  846.         if(!strnicmp(buf,"u}",2))         // @{U}
  847.         {
  848.           if(-1 == FPuts(fh,"<u>")) return(0);
  849.           buf += 2;
  850.           break;
  851.         }
  852.         if(!strnicmp(buf,"uu}",3))        // @{UU}
  853.         {
  854.           if(-1 == FPuts(fh,"</u>")) return(0);
  855.           buf += 3;
  856.           break;
  857.         }
  858.         if(!strnicmp(buf,"code}",3))        // @{CODE}
  859.         {
  860.           if(-1 == FPuts(fh,"<pre>")) return(0);
  861.           buf += 5;
  862.           break;
  863.         }
  864.         if(!strnicmp(buf,"body}",3))        // @{BODY}
  865.         {
  866.           if(-1 == FPuts(fh,"</pre>")) return(0);
  867.           buf += 5;
  868.           break;
  869.         }
  870.         if(!strnicmp(buf,"line}",3))        // @{LINE}
  871.         {
  872.           if(-1 == FPuts(fh,"<br>")) return(0);
  873.           buf += 5;
  874.           break;
  875.         }
  876.         if(!strnicmp(buf,"par}",3))        // @{PAR}
  877.         {
  878.           if(-1 == FPuts(fh,"<p>")) return(0);
  879.           buf += 4;
  880.           break;
  881.         }
  882.         if(!strnicmp(buf,"plain}",3))        // @{PLAIN}
  883.         {
  884.           if(-1 == FPuts(fh,"</b></i></u>")) return(0);
  885.           buf += 6;
  886.           break;
  887.         }
  888.  
  889.         if(!strnicmp(buf,"fg ",3))        // @{FG ...}
  890.         {
  891.           UWORD i=0;
  892.           buf += 3;
  893.  
  894.           while(*buf == ' ') buf++;
  895.  
  896.           while(agpens[i])
  897.           {
  898.             if(!strnicmp(buf,agpens[i],strlen(agpens[i])))
  899.             {
  900.               if(-1 == FPrintf(fh,"<font color=\"%s\" class=\"%s\">",htmlpens[i],cssclass[i])) return(0);
  901.               buf += strlen(agpens[i]);
  902.               break;
  903.             }
  904.             i++;
  905.           }
  906.           if(agpens[i]) break;
  907.         }
  908.  
  909.         while(*buf && *buf!='}') buf++;   // Skip an unknown command!
  910.         buf++;
  911.         break;
  912.       }
  913.  
  914.     }
  915.     else
  916.       if(-1 == MyPutCh(fh,ch)) return(0); // Error!
  917.   }
  918.   return(1);
  919. }
  920. //<
  921.  
  922. //> NavBar()
  923. /*------------------------------------------------------------*
  924. *   NavBar()        Produces the navigation bar               *
  925. *     -> tfh   output file handle                             *
  926. *     -> enode node with link data                            *
  927. *     <-      Success                                         *
  928. */
  929. LONG NavBar(BPTR tfh, struct Entry *enode)
  930. {
  931.   short before = 0;
  932.  
  933.   for(;;)
  934.   {
  935.  
  936.     if(param.homeurl)
  937.     {
  938.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  939.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",param.homeurl)) break;
  940.       if(-1 == MyPuts(tfh,param.home)) break;
  941.       if(-1 == FPuts(tfh,"</a>")) break;
  942.         before = 1;
  943.     }
  944.  
  945.  
  946.     if(enode->Count)            // main page does not have a TOC link
  947.     {
  948.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  949.  
  950.       if(param.msdos)
  951.       {
  952.         if(-1 == FPrintf(tfh,"<a href=\"%s\">",(*enode->TOC ? enode->TOC : "main.htm"))) break;
  953.       }
  954.       else
  955.       {
  956.         if(-1 == FPrintf(tfh,"<a href=\"%s\">",(*enode->TOC ? enode->TOC : "main.html"))) break;
  957.       }
  958.       if(-1 == MyPuts(tfh,param.toc)) break;
  959.       if(-1 == FPuts(tfh,"</a>")) break;
  960.       before = 1;
  961.     }
  962.     else if(param.showall)
  963.     {
  964.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  965.       if(-1 == MyPuts(tfh,param.toc)) break;
  966.       before = 1;
  967.     }
  968.  
  969.     if(*enode->Index)
  970.     {
  971.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  972.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",enode->Index)) break;
  973.       if(-1 == MyPuts(tfh,param.index)) break;
  974.       if(-1 == FPuts(tfh,"</a>")) break;
  975.       before = 1;
  976.     }
  977.     else if(*Index)
  978.     {
  979.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  980.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",Index)) break;
  981.       if(-1 == MyPuts(tfh,param.index)) break;
  982.       if(-1 == FPuts(tfh,"</a>")) break;
  983.       before = 1;
  984.     }
  985.     else if(param.showall)
  986.     {
  987.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  988.       if(-1 == MyPuts(tfh,param.index)) break;
  989.       before = 1;
  990.     }
  991.  
  992.     if(*enode->Help)
  993.     {
  994.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  995.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",enode->Help)) break;
  996.       if(-1 == MyPuts(tfh,param.help)) break;
  997.       if(-1 == FPuts(tfh,"</a>")) break;
  998.       before = 1;
  999.     }
  1000.     else if(*Help)
  1001.     {
  1002.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1003.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",Help)) break;
  1004.       if(-1 == MyPuts(tfh,param.help)) break;
  1005.       if(-1 == FPuts(tfh,"</a>")) break;
  1006.       before = 1;
  1007.     }
  1008.     else if(param.showall)
  1009.     {
  1010.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1011.       if(-1 == FPrintf(tfh,"<a href=\"http://www.unsatisfactorysoftware.co.uk/guideml/help.guide/main.html\">",Help)) break;
  1012.       if(-1 == MyPuts(tfh,param.help)) break;
  1013.       if(-1 == FPuts(tfh,"</a>")) break;
  1014.       before = 1;
  1015.     }
  1016.  
  1017.     if(param.retrace)
  1018.     {
  1019.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1020.       if(-1 == MyPuts(tfh,"<a href=\"javascript:window.history.go(-1)\">")) break;
  1021.       if(-1 == MyPuts(tfh,param.retrace)) break;
  1022.       if(-1 == FPuts(tfh,"</a>")) break;
  1023.       before = 1;
  1024.     }
  1025.  
  1026.     if(*enode->Prev)
  1027.     {
  1028.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1029.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",enode->Prev)) break;
  1030.       if(-1 == MyPuts(tfh,param.prev)) break;
  1031.       if(-1 == FPuts(tfh,"</a>")) break;
  1032.       before = 1;
  1033.     }
  1034.     else
  1035.     {
  1036.       struct Entry *pred = (struct Entry *)enode->link.mln_Pred;
  1037.       if(pred->link.mln_Pred)
  1038.       {
  1039.         if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1040.         if(-1 == FPrintf(tfh,"<a href=\"%s\">",pred->Node)) break;
  1041.         if(-1 == MyPuts(tfh,param.prev)) break;
  1042.         if(-1 == FPuts(tfh,"</a>")) break;
  1043.         before = 1;
  1044.       }
  1045.       else if(param.showall)
  1046.       {
  1047.         if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1048.         if(-1 == MyPuts(tfh,param.prev)) break;
  1049.         before = 1;
  1050.       }
  1051.  
  1052.     }
  1053.  
  1054.     if(*enode->Next)
  1055.     {
  1056.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1057.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",enode->Next)) break;
  1058.       if(-1 == MyPuts(tfh,param.next)) break;
  1059.       if(-1 == FPuts(tfh,"</a>")) break;
  1060.       before = 1;
  1061.     }
  1062.     else
  1063.     {
  1064.       struct Entry *next = (struct Entry *)enode->link.mln_Succ;
  1065.       if(next->link.mln_Succ)
  1066.       {
  1067.         if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1068.         if(-1 == FPrintf(tfh,"<a href=\"%s\">",next->Node)) break;
  1069.         if(-1 == MyPuts(tfh,param.next)) break;
  1070.         if(-1 == FPuts(tfh,"</a>")) break;
  1071.         before = 1;
  1072.       }
  1073.       else if(param.showall)
  1074.       {
  1075.         if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1076.         if(-1 == MyPuts(tfh,param.next)) break;
  1077.         before = 1;
  1078.       }
  1079.  
  1080.     }
  1081.     if(param.findurl)
  1082.     {
  1083.       if(before) if(-1 == MyPuts(tfh,param.bar)) break;
  1084.       if(-1 == FPrintf(tfh,"<a href=\"%s\">",param.findurl)) break;
  1085.       if(-1 == MyPuts(tfh,param.find)) break;
  1086.       if(-1 == FPuts(tfh,"</a>")) break;
  1087.       before = 1;
  1088.     }
  1089.  
  1090.  
  1091.     if(-1 == FPutC(tfh,'\n')) break;
  1092.     return(1);                            // ALL OK
  1093.   }
  1094.   return(0);                              // ERROR
  1095. }
  1096. //<
  1097.  
  1098. //> MozNavBar()
  1099. /*--------------------------------------------------------------------*
  1100. *   MozNavBar() Produces a Mozilla-compatible site navigation bar     *
  1101. *     -> tfh   output file handle                                     *
  1102. *     -> enode node with link data                                    *
  1103. *     <-      Success                                                 *
  1104. */
  1105. LONG MozNavBar(BPTR tfh, struct Entry *enode)
  1106. {
  1107.   short before = 0;
  1108.  
  1109.   for(;;)
  1110.   {
  1111.     if(enode->Count)            // main page does not have a TOC link
  1112.     {
  1113.       if(param.msdos)
  1114.       {
  1115.         if(-1 == FPrintf(tfh,"<link rel=\"up\" href=\"%s\" title=\"%s\" />\n",(*enode->TOC ? enode->TOC : "main.htm"),textlabs.toc)) break;
  1116.       }
  1117.       else
  1118.       {
  1119.         if(-1 == FPrintf(tfh,"<link rel=\"up\" href=\"%s\" title=\"%s\" />\n",(*enode->TOC ? enode->TOC : "main.html"),textlabs.toc)) break;
  1120.       }
  1121.     }
  1122.  
  1123.     if(*enode->Index)
  1124.     {
  1125.       if(-1 == FPrintf(tfh,"<link rel=\"index\" href=\"%s\" title=\"%s\" />\n",enode->Index,textlabs.index)) break;
  1126.     }
  1127.     else if(*Index)
  1128.     {
  1129.       if(-1 == FPrintf(tfh,"<link rel=\"index\" href=\"%s\" title=\"%s\" />\n",Index,param.index)) break;
  1130.     }
  1131.  
  1132.     if(*enode->Prev)
  1133.     {
  1134.       if(-1 == FPrintf(tfh,"<link rel=\"previous\" href=\"%s\" title=\"%s\" />\n",enode->Prev,textlabs.prev)) break;
  1135.     }
  1136.     else
  1137.     {
  1138.       struct Entry *pred = (struct Entry *)enode->link.mln_Pred;
  1139.       if(pred->link.mln_Pred)
  1140.       {
  1141.         if(-1 == FPrintf(tfh,"<link rel=\"previous\" href=\"%s\" title=\"%s\" />\n",pred->Node,textlabs.prev)) break;
  1142.       }
  1143.     }
  1144.  
  1145.     if(*enode->Next)
  1146.     {
  1147.       if(-1 == FPrintf(tfh,"<link rel=\"next\" href=\"%s\" title=\"%s\" />\n",enode->Next,textlabs.next)) break;
  1148.     }
  1149.     else
  1150.     {
  1151.       struct Entry *next = (struct Entry *)enode->link.mln_Succ;
  1152.       if(next->link.mln_Succ)
  1153.       {
  1154.         if(-1 == FPrintf(tfh,"<link rel=\"next\" href=\"%s\" title=\"%s\" />\n",next->Node,textlabs.next)) break;
  1155.       }
  1156.     }
  1157.  
  1158.     if(*enode->Help)
  1159.     {
  1160.       if(-1 == FPrintf(tfh,"<link rel=\"help\" href=\"%s\" title=\"%s\" />\n",enode->Help,textlabs.help)) break;
  1161.     }
  1162.     else if(*Help)
  1163.     {
  1164.       if(-1 == FPrintf(tfh,"<link rel=\"help\" href=\"%s\" title=\"%s\" />\n",Help,textlabs.help)) break;
  1165.     }
  1166.      else
  1167.      {
  1168.       if(-1 == FPuts(tfh,"<link rel=\"help\" href=\"http://www.unsatisfactorysoftware.co.uk/guideml/help.guide/main.html\" title=\"AmigaGuide Help\" />\n")) break;
  1169.      }
  1170.  
  1171.     if(param.homeurl)
  1172.     {
  1173.       if(-1 == FPrintf(tfh,"<link rel=\"top\" href=\"%s\" title=\"%s\" />\n",param.homeurl,textlabs.home)) break;
  1174.     }
  1175.  
  1176.     if(param.findurl)
  1177.     {
  1178.       if(-1 == FPrintf(tfh,"<link rel=\"search\" href=\"%s\" title=\"%s\" />\n",param.findurl,textlabs.find)) break;
  1179.     }
  1180.  
  1181.       if(-1 == FPuts(tfh,"<link rel=\"GuideML\" href=\"http://www.unsatisfactorysoftware.co.uk/\" title=\"Unsatisfactory Software\" />\n")) break;
  1182.  
  1183.  
  1184. //    if(-1 == FPutC(tfh,'\n')) break;
  1185.     return(1);                            // ALL OK
  1186.   }
  1187.   return(0);                              // ERROR
  1188. }
  1189. //<
  1190.  
  1191. //> Convert()
  1192. /*------------------------------------------------------------*
  1193. *   Convert()       Reads guide and creates HTML files        *
  1194. *     -> fh   input file handle                               *
  1195. *     <-      Success                                         *
  1196. */
  1197. LONG Convert(BPTR fh)
  1198. {
  1199.   STRPTR buffer = AllocVec(LINELEN,MEMF_ANY);     // allocate line buffer
  1200.   char copyright[100] = "\0";
  1201.   char author[100] = "\0";
  1202.   char version[100] = "\0";
  1203.   char master[100] = "\0";
  1204.   char database[100] = "\0";
  1205.   char keywords[100] = "\0";
  1206.   char description[200] = "\0";
  1207.   STRPTR node, title, line;
  1208.   char nodename[100];
  1209.   BPTR tfh = NULL;
  1210.   ULONG linenr = 0;
  1211.   short firstpage = 1;
  1212.   struct Entry *enode = (struct Entry *)entries.mlh_Head;
  1213.   register UWORD donavbar = !param.nonavbar;
  1214.   LONG wrap = 0;
  1215.  
  1216.   if(param.wordwrap || param.smartwrap) wrap = 1;
  1217.  
  1218.   if(!buffer) return(0);
  1219.  
  1220.   PutStr("Converting into HTML\n");
  1221.  
  1222.    /* search for @node */
  1223.   do
  1224.   {
  1225.     linenr++;
  1226.     if(FGets(fh,buffer,LINELEN) == NULL) goto Done;
  1227.  
  1228.    if(!param.noauto)
  1229.    {
  1230.     if(strnicmp(buffer,"@wordwrap",9)==0)
  1231.     {
  1232.     PutStr("@wordwrap detected!\n");
  1233.      param.wordwrap = 1;
  1234.      wrap = 1;
  1235.      }
  1236.     if(strnicmp(buffer,"@smartwrap",10)==0)
  1237.     {
  1238.     PutStr("@smartwrap detected!\n");
  1239.      param.smartwrap = 1;
  1240.      wrap = 1;
  1241.      }
  1242.    }
  1243.  
  1244.    // the below would be seriously better off as subroutines...
  1245.  
  1246.      if(strnicmp(buffer,"@(c) ",5)==0)
  1247.      {
  1248.        line = buffer+5;
  1249.       while(*line == ' ') line++;   // Skip spaces
  1250.       if(*line == '\"') line++;     // Skip quotation mark
  1251.       title = line;
  1252.       while(*line != '\n') line++;  // search EOL
  1253.       do line--; while(*line==' '); // skip trailing spaces
  1254.       if(*line == '\"') line--;     // skip trailing quotation mark
  1255.       *++line = '\0';               // terminate the line
  1256.       strcpy(copyright,title);
  1257.     }
  1258.  
  1259.      if(strnicmp(buffer,"@author ",8)==0)
  1260.      {
  1261.        line = buffer+8;
  1262.       while(*line == ' ') line++;   // Skip spaces
  1263.       if(*line == '\"') line++;     // Skip quotation mark
  1264.       title = line;
  1265.       while(*line != '\n') line++;  // search EOL
  1266.       do line--; while(*line==' '); // skip trailing spaces
  1267.       if(*line == '\"') line--;     // skip trailing quotation mark
  1268.       *++line = '\0';               // terminate the line
  1269.       strcpy(author,title);
  1270.      }
  1271.  
  1272.      if(strnicmp(buffer,"@$ver:",6)==0)
  1273.      {
  1274.             line = buffer+6;
  1275.       while(*line == ' ') line++;   // Skip spaces
  1276.       if(*line == '\"') line++;     // Skip quotation mark
  1277.       title = line;
  1278.       while(*line != '\n') line++;  // search EOL
  1279.       do line--; while(*line==' '); // skip trailing spaces
  1280.       if(*line == '\"') line--;     // skip trailing quotation mark
  1281.       *++line = '\0';               // terminate the line
  1282.       strcpy(version,title);
  1283.     }
  1284.  
  1285.      if(strnicmp(buffer,"@database ",10)==0)
  1286.      {
  1287.        line = buffer+10;
  1288.       while(*line == ' ') line++;   // Skip spaces
  1289.       if(*line == '\"') line++;     // Skip quotation mark
  1290.       title = line;
  1291.       while(*line != '\n') line++;  // search EOL
  1292.       do line--; while(*line==' '); // skip trailing spaces
  1293.       if(*line == '\"') line--;     // skip trailing quotation mark
  1294.       *++line = '\0';               // terminate the line
  1295.       strcpy(database,title);
  1296.     }
  1297.  
  1298.      if(strnicmp(buffer,"@master ",8)==0)
  1299.      {
  1300.             line = buffer+8;
  1301.       while(*line == ' ') line++;   // Skip spaces
  1302.       if(*line == '\"') line++;     // Skip quotation mark
  1303.       title = line;
  1304.       while(*line != '\n') line++;  // search EOL
  1305.       do line--; while(*line==' '); // skip trailing spaces
  1306.       if(*line == '\"') line--;     // skip trailing quotation mark
  1307.       *++line = '\0';               // terminate the line
  1308.       strcpy(master,title);
  1309.     }
  1310.  
  1311.      if(strnicmp(buffer,"@keywords ",10)==0)
  1312.      {
  1313.             line = buffer+10;
  1314.       while(*line == ' ') line++;   // Skip spaces
  1315.       if(*line == '\"') line++;     // Skip quotation mark
  1316.       title = line;
  1317.       while(*line != '\n') line++;  // search EOL
  1318.       do line--; while(*line==' '); // skip trailing spaces
  1319.       if(*line == '\"') line--;     // skip trailing quotation mark
  1320.       *++line = '\0';               // terminate the line
  1321.      strcpy(keywords,title);
  1322.     }
  1323.  
  1324.      if(strnicmp(buffer,"@description ",13)==0)
  1325.      {
  1326.             line = buffer+13;
  1327.       while(*line == ' ') line++;   // Skip spaces
  1328.       if(*line == '\"') line++;     // Skip quotation mark
  1329.       title = line;
  1330.       while(*line != '\n') line++;  // search EOL
  1331.       do line--; while(*line==' '); // skip trailing spaces
  1332.       if(*line == '\"') line--;     // skip trailing quotation mark
  1333.       *++line = '\0';               // terminate the line
  1334.      strcpy(description,title);
  1335.     }
  1336.  
  1337.   }
  1338.   while(strnicmp(buffer,"@node ",strlen("@node ")));
  1339.  
  1340.    /* and go... */
  1341.   for(;;)
  1342.   {
  1343.     if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) goto ErrorBrk;
  1344.  
  1345.      /* search the node name */
  1346.     node = buffer+strlen("@node ");
  1347.     while(*node == ' ') node++;     // skip leading spaces
  1348.     if(*node == '\"')
  1349.     {                               // Quote Mode
  1350.       node++;
  1351.       line = node;
  1352.       while(*line!='\"' && *line!='\n')
  1353.       {
  1354.         if(*line==' ' || *line==':') *line='_';  // space -> '_'
  1355.         line++;
  1356.       }
  1357.       *line++ = '\0';
  1358.     }
  1359.     else
  1360.     {
  1361.       line = node;
  1362.       while(*line!=' ' && *line!='\n')
  1363.       {
  1364.         if(*line==':') *line='/';               // ':' -> '_'
  1365.         line++;
  1366.       }
  1367.       *line++ = '\0';
  1368.     }
  1369.  
  1370.      /* search node title */
  1371.     if(*line == '\0')
  1372.         {
  1373.       title = line;                 // Node does not have a title
  1374.         if(*enode->Titl)
  1375.             {
  1376.                 title = enode->Titl;
  1377.             }
  1378.         }
  1379.     else
  1380.     {
  1381.       while(*line == ' ') line++;   // Skip spaces
  1382.       if(*line == '\"') line++;     // Skip quotation mark
  1383.       title = line;
  1384.       while(*line != '\n') line++;  // search EOL
  1385.       do line--; while(*line==' '); // skip trailing spaces
  1386.       if(*line == '\"') line--;     // skip trailing quotation mark
  1387.       *++line = '\0';               // terminate the line
  1388.     }
  1389.  
  1390.     strlwr(node);                   // node name to lowercase
  1391.     strcpy(nodename,node);
  1392.     if(param.msdos)
  1393.     {
  1394.       strcat(nodename,".htm");
  1395.     }
  1396.     else
  1397.     {
  1398.       strcat(nodename,".html");
  1399.     }
  1400.  
  1401.     if(tfh = Open(nodename,MODE_NEWFILE))
  1402.     {
  1403.       if(param.verbatim) Printf("Creating page '%s' (Title: '%s')\n",nodename,title);
  1404.       if(-1 == FPuts(tfh,"<html>\n<head>\n<title>")) goto ErrorFile;
  1405.       if(-1 == MyPuts(tfh,title)) goto ErrorFile;
  1406.       if(-1 == FPuts(tfh,"</title>\n"
  1407.                          "<meta name=\"Generator\" content=\"GuideML " VERSIONSTR " (http://www.unsatisfactorysoftware.co.uk/guideml/)\">\n"
  1408.                          "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n")) goto ErrorFile;
  1409.         // start custom meta
  1410.         if(strlen(copyright) > 2)
  1411.         {
  1412.         if(-1 == FPuts(tfh,"<meta name=\"Copyright\" content=\"")) goto ErrorFile;
  1413.         if(-1 == MyPuts(tfh,copyright)) goto ErrorFile;
  1414.         if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1415.         }
  1416.         // end custom meta
  1417.         // start custom meta
  1418.         if(strlen(author) > 2)
  1419.         {
  1420.         if(-1 == FPuts(tfh,"<meta name=\"Author\" content=\"")) goto ErrorFile;
  1421.         if(-1 == MyPuts(tfh,author)) goto ErrorFile;
  1422.         if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1423.         }
  1424.         // end custom meta
  1425.         // start custom meta
  1426.         if(strlen(version) > 2)
  1427.         {
  1428.         if(-1 == FPuts(tfh,"<meta name=\"Version\" content=\"")) goto ErrorFile;
  1429.         if(-1 == MyPuts(tfh,version)) goto ErrorFile;
  1430.         if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1431.         }
  1432.         // end custom meta
  1433.         // start custom meta
  1434.         if(strlen(database) > 2)
  1435.         {
  1436.         if(-1 == FPuts(tfh,"<meta name=\"Database\" content=\"")) goto ErrorFile;
  1437.         if(-1 == MyPuts(tfh,database)) goto ErrorFile;
  1438.         if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1439.         }
  1440.         // end custom meta
  1441.         // start custom meta
  1442.         if(strlen(master) > 2)
  1443.         {
  1444.         if(-1 == FPuts(tfh,"<meta name=\"Master\" content=\"")) goto ErrorFile;
  1445.         if(-1 == MyPuts(tfh,master)) goto ErrorFile;
  1446.         if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1447.         }
  1448.         // end custom meta
  1449.         // start custom meta
  1450.         if(strlen(keywords) > 2)
  1451.         {
  1452.             if(-1 == FPuts(tfh,"<meta name=\"Keywords\" content=\"")) goto ErrorFile;
  1453.             if(-1 == MyPuts(tfh,keywords)) goto ErrorFile;
  1454.             if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1455.         }
  1456.         // end custom meta
  1457.         // start custom meta
  1458.         if(strlen(description) > 2)
  1459.         {
  1460.             if(-1 == FPuts(tfh,"<meta name=\"Description\" content=\"")) goto ErrorFile;
  1461.             if(-1 == MyPuts(tfh,description)) goto ErrorFile;
  1462.             if(-1 == FPuts(tfh,"\">\n")) goto ErrorFile;
  1463.         }
  1464.         // end custom meta
  1465.  
  1466.         if(param.cssurl)
  1467.         {
  1468.             if(-1 == FPuts(tfh,"<link rel=\"stylesheet\" href=\"")) goto ErrorFile;
  1469.             if(-1 == MyPuts(tfh,param.cssurl)) goto ErrorFile;
  1470.             if(-1 == FPuts(tfh,"\" type=\"text/css\">")) goto ErrorFile;
  1471.         }
  1472.  
  1473.         if(!param.nomoznav)
  1474.         {
  1475.       if(!MozNavBar(tfh,enode)) goto ErrorFile;
  1476.       }
  1477.  
  1478.  
  1479.         if(-1 == FPuts(tfh,"</head>\n<body")) goto ErrorFile;
  1480.  
  1481.       if(param.bodyext)
  1482.       {
  1483.         if(-1 == FPutC(tfh,' ')) goto ErrorFile;
  1484.         if(-1 == MyPuts(tfh,param.bodyext)) goto ErrorFile;
  1485.       }
  1486.       if(-1 == FPuts(tfh,">\n")) goto ErrorFile;
  1487.  
  1488.       if(param.htmltoptxt)
  1489.       {
  1490.         if(-1 == FPutC(tfh,' ')) goto ErrorFile;
  1491.         if(-1 == MyPuts(tfh,param.htmltoptxt)) goto ErrorFile;
  1492.       }
  1493.       if(param.htmlheadf)
  1494.       {
  1495.         if(-1 == FPutC(tfh,' ')) goto ErrorFile;
  1496.         if(-1 == MyPuts(tfh,(STRPTR)htmltop)) goto ErrorFile;
  1497.       }
  1498.  
  1499.  
  1500.         if(donavbar)
  1501.         {
  1502.       if(!NavBar(tfh,enode)) goto ErrorFile;
  1503.       if(-1 == FPuts(tfh,"<hr>\n")) goto ErrorFile;
  1504.       }
  1505.  
  1506.         if(!wrap)
  1507.         {
  1508.           if(-1 == FPuts(tfh,"<pre>\n")) goto ErrorFile;
  1509.         }
  1510.         else
  1511.         {
  1512.             if(!param.varwidth)
  1513.           {
  1514.               if(-1 == FPuts(tfh,"<tt>\n")) goto ErrorFile;
  1515.           }
  1516.         }
  1517.  
  1518.       for(;;)
  1519.       {
  1520.         linenr++;
  1521.         if(FGets(fh,buffer,LINELEN) == NULL) goto ErrorEOF;
  1522.  
  1523. // TEMPORARY FOR TEST PORPOISES!
  1524. //Printf("%s\n",buffer);
  1525.  
  1526.         if(buffer[0]=='@' && buffer[1]!='{')    // is it an AmigaGuide command
  1527.         {
  1528.           if(!strnicmp(buffer,"@node ",strlen("@node "))) break;
  1529.           if(!strnicmp(buffer,"@endnode",strlen("@endnode"))) break;
  1530.           continue;                           // unknown command
  1531.         }
  1532.  
  1533.         if(!ConvLine(tfh,buffer,linenr))
  1534.         {
  1535.           Printf("Line %ld: Couldn't convert!\n",linenr);
  1536.           goto Error;
  1537.         }
  1538.                 if(param.wordwrap)
  1539.                 {
  1540.                       if(-1 == FPuts(tfh,"<br>")) return(0);
  1541.                 }
  1542.  
  1543.       }
  1544.  
  1545.         if(!wrap)
  1546.         {
  1547.           if(-1 == FPuts(tfh,"</pre>\n")) goto ErrorFile;
  1548.         }
  1549.         else
  1550.         {
  1551.             if(!param.varwidth)
  1552.           {
  1553.               if(-1 == FPuts(tfh,"</tt>\n")) goto ErrorFile;
  1554.             }
  1555.         }
  1556.  
  1557.       if(param.footer)
  1558.       {
  1559.         if(-1 == FPuts(tfh,"<hr>\n")) goto ErrorFile;
  1560.         if(donavbar)
  1561.             {
  1562.             if(!NavBar(tfh,enode)) goto ErrorFile;
  1563.             }
  1564.       }
  1565.  
  1566.       if(param.htmlbottxt)
  1567.       {
  1568.         if(-1 == FPutC(tfh,' ')) goto ErrorFile;
  1569.         if(-1 == MyPuts(tfh,param.htmlbottxt)) goto ErrorFile;
  1570.       }
  1571.       else if(param.htmlfootf)
  1572.       {
  1573.         if(-1 == FPutC(tfh,' ')) goto ErrorFile;
  1574.         if(-1 == MyPuts(tfh,(STRPTR)htmlbot)) goto ErrorFile;
  1575.       }
  1576.         else
  1577.         {
  1578.           if(firstpage)
  1579.           {
  1580.             firstpage = 0;
  1581.             if(-1 == FPuts(tfh,"<hr>\n<address>Converted using <a href=\"http://www.unsatisfactorysoftware.co.uk/guideml/\">GuideML "VERSIONSTR "</a></address>\n")) goto ErrorFile;
  1582.           }
  1583.       }
  1584.  
  1585.  
  1586.       if(-1 == FPuts(tfh,"</body>\n</html>\n")) goto ErrorFile;
  1587.       enode = (struct Entry *)enode->link.mln_Succ;
  1588.       Close(tfh);
  1589.       tfh = NULL;
  1590.     }
  1591.     else
  1592.     {
  1593.       Printf("Line %ld: Couldn't open %s for writing!\n",linenr,nodename);
  1594.       goto Error;
  1595.     }
  1596.  
  1597.     while(strnicmp(buffer,"@node ",strlen("@node ")))
  1598.     {
  1599.       linenr++;
  1600.       if(FGets(fh,buffer,LINELEN) == NULL) goto Done;
  1601.     }
  1602.   }
  1603.  
  1604. Done:
  1605.   FreeVec(buffer);
  1606.   return(1);
  1607.  
  1608. ErrorBrk:
  1609.   Printf("Line %ld: <CTRL-C> pressed!\n",linenr);
  1610.   goto Error;
  1611. ErrorFile:
  1612.   Printf("Line %ld: Error writing file!\n",linenr);
  1613.   goto Error;
  1614. ErrorEOF:
  1615.   Printf("Line %ld: Unexpected EOF!\n",linenr);
  1616. Error:
  1617.   if(tfh) Close(tfh);
  1618.   FreeVec(buffer);
  1619.   return(0);
  1620. }
  1621. //<
  1622. //> PreScan()
  1623. /*------------------------------------------------------------*
  1624. *   PreScan()       Scans the AmigaGuide file                 *
  1625. *     -> fh   input file handle                               *
  1626. *     <-      Success                                         *
  1627. */
  1628. LONG PreScan(BPTR fh)
  1629. {
  1630.   STRPTR buffer = AllocVec(LINELEN,MEMF_ANY);     // allocate line buffer
  1631.   STRPTR parse;
  1632.   ULONG linenr  = 0;
  1633.   ULONG nodectr = 0;
  1634.   struct Entry *currentry = NULL;
  1635.  
  1636.   if(!buffer) return(0);
  1637.  
  1638.   PutStr("Scanning AmigaGuide document\n");
  1639.    /* Is it an AmigaGuide document ? */
  1640.   linenr++;
  1641.   if(NULL == FGets(fh,buffer,LINELEN)) goto ErrorEOF;
  1642.   if(strnicmp(buffer,"@database",strlen("@database")))
  1643.   {
  1644.     PutStr("This is no valid AmigaGuide file!\n");
  1645.     goto Error;
  1646.   }
  1647.  
  1648.    /* Search for commands */
  1649.   for(;;)
  1650.   {
  1651.     if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) goto ErrorBrk;
  1652.     linenr++;
  1653.     if(!FGets(fh,buffer,LINELEN)) break;      // Scan all lines
  1654.     if(buffer[0]!='@') continue;              // no command line
  1655.     if(buffer[1]=='{') continue;              // a text command at first column?
  1656.  
  1657.     parse = buffer+1;
  1658.  
  1659.     if(!strnicmp(parse,"node ",strlen("node ")))      // @node <name>
  1660.     {
  1661.       if(currentry) AddTail((struct List *)&entries,(struct Node *)currentry);
  1662.       currentry = AllocVec(sizeof(struct Entry),MEMF_ANY|MEMF_CLEAR);
  1663.       if(!currentry) goto ErrorMem;
  1664.       currentry->Count = nodectr++;
  1665.       CopyLink(parse+strlen("node "), currentry->Node);
  1666.     }
  1667.  
  1668.     if(!strnicmp(parse,"index ",strlen("index ")))    // @index <index>
  1669.     {
  1670.       if(currentry)
  1671.       {
  1672.         CopyLink(parse+strlen("prev "), currentry->Index);
  1673.       }
  1674.       else
  1675.       {
  1676.           CopyLink(parse+strlen("index "), Index);
  1677.       }
  1678.     }
  1679.  
  1680.     if(!strnicmp(parse,"prev ",strlen("prev ")))      // @prev <name>
  1681.     {
  1682.       if(currentry)
  1683.       {
  1684.         CopyLink(parse+strlen("prev "), currentry->Prev);
  1685.       }
  1686.     }
  1687.  
  1688.     if(!strnicmp(parse,"next ",strlen("next ")))      // @next <name>
  1689.     {
  1690.       if(currentry)
  1691.       {
  1692.         CopyLink(parse+strlen("next "), currentry->Next);
  1693.       }
  1694.     }
  1695.  
  1696.     if(!strnicmp(parse,"toc ",strlen("toc ")))        // @toc <name>
  1697.     {
  1698.       if(currentry)
  1699.       {
  1700.         CopyLink(parse+strlen("toc "), currentry->TOC);
  1701.       }
  1702.     }
  1703.  
  1704.     if(!strnicmp(parse,"title ",strlen("title ")))        // @title <name>
  1705.     {
  1706.       if(currentry)
  1707.       {
  1708.         CopyLink(parse+strlen("title "), currentry->Titl);
  1709.         }
  1710.     }
  1711.  
  1712.     if(!strnicmp(parse,"help ",strlen("help ")))        // @help <name>
  1713.     {
  1714.       if(currentry)
  1715.       {
  1716.         CopyLink(parse+strlen("help "), currentry->Help);
  1717.       }
  1718.       else
  1719.       {
  1720.           CopyLink(parse+strlen("help "), Help);
  1721.       }
  1722.     }
  1723.  
  1724.     if(!strnicmp(parse,"endnode",strlen("endnode")))  // @endnode
  1725.     {
  1726.       if(currentry)
  1727.       {
  1728.         AddTail((struct List *)&entries,(struct Node *)currentry);
  1729.         currentry = NULL;
  1730.       }
  1731.     }
  1732.   }
  1733.   if(currentry)
  1734.   {
  1735.     AddTail((struct List *)&entries,(struct Node *)currentry);
  1736.     if(!param.nowarn) Printf("Line %ld: WARNING: No closing @endnode found!\n",linenr);
  1737. //*    currentry = NULL;
  1738.   }
  1739.  
  1740.   FreeVec(buffer);
  1741.   return(1);
  1742.  
  1743. ErrorMem:
  1744.   Printf("Line %ld: Not enough memory!\n",linenr);
  1745.   goto Error;
  1746. ErrorBrk:
  1747.   Printf("Line %ld: <CTRL-C> pressed!\n",linenr);
  1748.   goto Error;
  1749. ErrorEOF:
  1750.   Printf("Line %ld: Unexpected EOF!\n",linenr);
  1751. Error:
  1752.   FreeVec(buffer);
  1753.   return(0);
  1754. }
  1755. //<
  1756.  
  1757. //> main()
  1758. /*------------------------------------------------------------*
  1759. *   main()          M A I N   P R O G R A M                   *
  1760. */
  1761. int main(void)
  1762. {
  1763.   struct RDArgs *args;
  1764.   static char template[] = "FILE/A,TO/K,URL=HOMEURL/K,FINDURL=SEARCHURL/K,PREV/K,NEXT/K,INDEX/K,TOC/K,HELP/K,RETRACE/K,HOME/K,FIND=SEARCH/K,BAR/K,BODY/K,VER=VERBATIM/S,IMG=IMAGES/S,FTR=FOOTER/S,NL=NOLINKS/S,NE=NOEMAIL/S,NW=NOWARN/S,MSDOS/S,NONAVBAR/S,NOMOZNAV/S,SHOWALL/S,HTMLHEAD/K,HTMLHEADF/K,HTMLFOOT/K,HTMLFOOTF/K,CSS/K,WORDWRAP/S,SMARTWRAP/S,VARWIDTH/S,NOAUTO/S";
  1765.   BPTR fh;
  1766.   BPTR hhf;
  1767.   BPTR oldlock = NULL;
  1768.   struct Entry *node, *next;
  1769.   struct LinkStr *lstr = NULL;
  1770.   struct FileInfoBlock *fib = NULL;
  1771.   long hfs = 4096;
  1772.   long hhs = 4096;
  1773.  
  1774.   NewList((struct List *)&entries);
  1775.  
  1776.  
  1777. if(!wb)
  1778. {
  1779.   param.prev  = "< Browse";
  1780.   param.next  = "Browse >";
  1781.   param.index = "Index";
  1782.   param.toc   = "Contents";
  1783.   param.home  = "Home";
  1784.   param.help  = "Help";
  1785.   param.find  = "Search";
  1786.   param.bar   = defbar;
  1787.   param.retrace = NULL;
  1788.  
  1789.   if(args = (struct RDArgs *)ReadArgs(template,(LONG *)¶m,NULL))
  1790.     {
  1791.         ok=1;
  1792.     }
  1793. }
  1794.  
  1795. if(ok)
  1796.   {
  1797.     PutStr("GuideML "VERSIONSTR"\n");
  1798.  
  1799.   textlabs.prev = param.prev;
  1800.   textlabs.next = param.next;
  1801.   textlabs.index = param.index;
  1802.   textlabs.toc = param.toc;
  1803.   textlabs.home = param.home;
  1804.   textlabs.help = param.help;
  1805.   textlabs.find = param.find;
  1806.   textlabs.retrace = param.retrace;
  1807.   textlabs.bar = param.bar;
  1808.  
  1809.     if(param.images)
  1810.     {
  1811.       lstr = AllocVec(sizeof(struct LinkStr),MEMF_ANY);
  1812.       if(!lstr)
  1813.       {
  1814.         PutStr("**ERROR: Out of memory.\n");
  1815.         goto Flush;
  1816.       }
  1817.  
  1818.       sprintf(lstr->Prev ,"<img src=\"prev.gif\" alt=\"%s\" border=0>" ,param.prev );
  1819.       sprintf(lstr->Next ,"<img src=\"next.gif\" alt=\"%s\" border=0>" ,param.next );
  1820.       sprintf(lstr->Index,"<img src=\"index.gif\" alt=\"%s\" border=0>",param.index);
  1821.       sprintf(lstr->Retrace,"<img src=\"retrace.gif\" alt=\"%s\" border=0>",param.retrace);
  1822.       sprintf(lstr->Toc  ,"<img src=\"toc.gif\" alt=\"%s\" border=0>"  ,param.toc  );
  1823.       sprintf(lstr->Home ,"<img src=\"home.gif\" alt=\"%s\" border=0>" ,param.home );
  1824.       sprintf(lstr->Help ,"<img src=\"help.gif\" alt=\"%s\" border=0>" ,param.help );
  1825.       sprintf(lstr->Find ,"<img src=\"find.gif\" alt=\"%s\" border=0>" ,param.find );
  1826.       param.prev  = lstr->Prev;
  1827.       param.next  = lstr->Next;
  1828.       param.index = lstr->Index;
  1829.       param.toc   = lstr->Toc;
  1830.       param.home  = lstr->Home;
  1831.       param.help  = lstr->Help;
  1832.       param.find  = lstr->Find;
  1833.       if(param.retrace) param.retrace  = lstr->Retrace;
  1834.       if(param.bar == defbar) param.bar = "";
  1835.     }
  1836.  
  1837.  
  1838.     if(param.htmlheadf)
  1839.     {
  1840.         if(hhf=Open(param.htmlheadf,MODE_OLDFILE))
  1841.         {
  1842. //        if(ExamineFH(hhf,fib))
  1843. //            {
  1844. //                hhs=fib->fib_Size;
  1845.                 if(htmltop = AllocMem(hhs,MEMF_CLEAR))
  1846.                     {
  1847.                         Read(hhf,htmltop,hhs);
  1848.  
  1849.                         param.htmltoptxt=NULL;
  1850.                         printf("%s loaded ok\n",param.htmlheadf);
  1851.  
  1852.                     }
  1853.             Close(hhf);
  1854.         }
  1855.     }
  1856.  
  1857.     if(param.htmlfootf)
  1858.     {
  1859.         if(hhf=Open(param.htmlfootf,MODE_OLDFILE))
  1860.         {
  1861.                 if(htmlbot = AllocMem(hfs,MEMF_CLEAR))
  1862.                     {
  1863.                         Read(hhf,htmlbot,hfs);
  1864.                         param.htmlbottxt=NULL;
  1865.                         printf("%s loaded ok\n",param.htmlfootf);
  1866.                     }
  1867.             Close(hhf);
  1868.         }
  1869.     }
  1870.  
  1871.     if(fh = Open(param.from,MODE_OLDFILE))
  1872.     {
  1873.       if(param.to)
  1874.       {
  1875.         BPTR destlock;
  1876.         destlock = Lock(param.to,ACCESS_READ);
  1877.         if(!destlock)
  1878.         {
  1879.           PutStr("**ERROR: Couldn't lock destination drawer.\n");
  1880.           Close(fh);
  1881.           goto Flush;
  1882.         }
  1883.         oldlock = CurrentDir(destlock);
  1884.       }
  1885.  
  1886.       if(!PreScan(fh))
  1887.       {
  1888.         PutStr("**ERROR: Scanning failed.\n");
  1889.         Close(fh);
  1890.         goto Flush;
  1891.       }
  1892.       Seek(fh,0,OFFSET_BEGINNING);
  1893.       if(!Convert(fh))
  1894.       {
  1895.         PutStr("**ERROR: Conversion failed.\n");
  1896.         Close(fh);
  1897.         goto Flush;
  1898.       }
  1899.       Close(fh);
  1900.     }
  1901.     else
  1902.       Printf("**ERROR: couldn't open file %s!\n",param.from);
  1903.  
  1904.     if(param.images)
  1905.     {
  1906.       PutStr("Saving images\n");
  1907.       if(!SaveImages())
  1908.         PutStr("**ERROR: couldn't save image files\n");
  1909.     }
  1910.  
  1911.     Printf("All finished!\n");
  1912.  
  1913. Flush:
  1914.     for (node = (struct Entry *)entries.mlh_Head;
  1915.          next = (struct Entry *)node->link.mln_Succ;
  1916.          node = next)
  1917.     {
  1918.       Remove((struct Node *)node);
  1919.       FreeVec(node);
  1920.     }
  1921.  
  1922.     if(lstr) FreeVec(lstr);
  1923.     if(htmltop) FreeMem(htmltop,hhs);
  1924.     if(htmlbot) FreeMem(htmlbot,hfs);
  1925.  
  1926.  
  1927.     if(oldlock) UnLock(CurrentDir(oldlock));
  1928.  
  1929.     if(!wb) FreeArgs(args);
  1930.   }
  1931.   else
  1932.     PutStr("GuideML "VERSIONSTR"\n"
  1933.            "© 1997-98 by Richard Körber <shred@eratosthenes.starfleet.de>\n"
  1934.            "Updated in 2001-03 by Chris Young <chris@unsatisfactorysoftware.co.uk>\n"
  1935.            "Yet Another (tm) AmigaGuide to HTML Converter!\n\n"
  1936.            "USAGE:\tFILE/A\t\t\tAmigaGuide file to be converted\n"
  1937.            "\tTO/K\t\t\tDestination drawer for the html pages\n"
  1938.            "\tURL=HOMEURL/K\t\tURL accessed by the 'HOME' button\n"
  1939.            "\tFINDURL=SEARCHURL/K\tURL accessed by the 'SEARCH' button\n"
  1940.            "\tPREV/K\t\t\t'PREV' button text/image\n"
  1941.            "\tNEXT/K\t\t\t'NEXT' button text/image\n"
  1942.            "\tINDEX/K\t\t\t'INDEX' button text/image\n"
  1943.            "\tTOC/K\t\t\t'CONTENTS' button text/image\n"
  1944.            "\tHELP/K\t\t\t'HELP' button text/image\n"
  1945.            "\tRETRACE/K\t\t'RETRACE' button text/image (displays only if specified)\n"
  1946.            "\tHOME/K\t\t\t'HOME' button text/image\n"
  1947.            "\tFIND=SEARCH/K\t\t'SEARCH' button text/image\n"
  1948.            "\tBAR/K\t\t\tBar text between navigation buttons\n"
  1949.            "\tBODY/K\t\t\tAddition to the body tag of every page\n"
  1950.            "\tVER=VERBATIM/S\t\tList of created files\n"
  1951.            "\tIMG=IMAGES/S\t\tCreate image navigation bar\n"
  1952.            "\tFTR=FOOTER/S\t\tNavigation bar also at end of page\n"
  1953.            "\tNL=NOLINKS/S\t\tIgnore internet links\n"
  1954.            "\tNE=NOEMAIL/S\t\tIgnore e-mail addresses\n"
  1955.            "\tNW=NOWARN/S\t\tDon't show warnings\n"
  1956.            "\tMSDOS/S\t\t\tCreate MS-DOS filenames (*.htm)\n"
  1957.            "\tNONAVBAR/S\t\tDo not create the HTML navigation bar\n"
  1958.            "\tNOMOZNAV/S\t\tDo not create Mozilla-compatible Site Navigation Bar\n"
  1959.            "\tSHOWALL/S\t\tKeep navbar consistent between pages\n"
  1960.            "\tHTMLHEAD/K\t\tHTML to put in front of guide text\n"
  1961.            "\tHTMLHEADF/K\t\tFile containing HTMLHEAD (overrides HTMLHEAD)\n"
  1962.            "\tHTMLFOOT/K\t\tHTML to put underneath guide text\n"
  1963.            "\tHTMLFOOTF/K\t\tFile containing HTMLFOOT (overrides HTMLFOOT)\n"
  1964.            "\tCSS/K\t\t\tURL of Cascading Style Sheet to link to\n"
  1965.            "\tWORDWRAP/S\t\tWord-wraps text (converts @wordwrap)\n"
  1966.            "\tSMARTWRAP/S\t\tSmartwraps text (converts @smartwrap)\n"
  1967.            "\tVARWIDTH/S\t\tDo not use fixed width font (#?WRAP only)\n"
  1968.            "\tNOAUTO/S\t\tDo not auto-detect wrap mode\n"
  1969.  
  1970.            "\n");
  1971.   return(0);
  1972. }
  1973. //<
  1974.  
  1975. /**************************************************************/
  1976.  
  1977. /* New GuiML stuff starts here.. code might be a bit messy *
  1978.  * as it is largely cut'n'paste from a different project   *
  1979.  * --- Starts with GuideML 3.1 ---                         */
  1980.  
  1981. void wbmain(struct WBStartup *WBenchMsg)
  1982. {
  1983. struct WBArg *wbarg;
  1984.     char i;
  1985.     int olddir;
  1986. int name = 0;
  1987.  
  1988. wb=1;
  1989. ok=1;
  1990.  
  1991.   param.prev  = "< Browse";
  1992.   param.next  = "Browse >";
  1993.   param.index = "Index";
  1994.   param.toc   = "Contents";
  1995.   param.home  = "Home";
  1996.   param.help  = "Help";
  1997.   param.find  = "Search";
  1998.   param.bar   = defbar;
  1999.   param.retrace = NULL;
  2000.  
  2001.     if((intuitionbase = OpenLibrary("intuition.library",37))==0)
  2002.         {
  2003.          err("Unable to open intuition.library v37","OK",20);
  2004.         }
  2005.  
  2006.     if((DOSBase = OpenLibrary("dos.library",37))==0)
  2007.         {
  2008.           err("Unable to open dos.library v37","OK",20);
  2009.         }
  2010.  
  2011.     if((aslbase = OpenLibrary("asl.library",38))==0)
  2012.         {
  2013.           err("Unable to open asl.library v38","OK",20);
  2014.         }
  2015.     if((GadToolsBase = OpenLibrary("gadtools.library",37))==0)
  2016.         {
  2017.           err("Unable to open gadtools.library v37","OK",20);
  2018.         }
  2019.  
  2020.      if((WindowBase = OpenLibrary("window.class",44))==0) err("Unable to open window.class v44","OK",20);
  2021.      if((LayoutBase = OpenLibrary("gadgets/layout.gadget",44))==0) err("Unable to open layout.gadget v44","OK",20);
  2022.      if((ButtonBase = OpenLibrary("gadgets/button.gadget",44))==0) err("Unable to open button.gadget v44","OK",20);
  2023.      if((CheckBoxBase = OpenLibrary("gadgets/checkbox.gadget",44))==0) err("Unable to open checkbox.gadget v44","OK",20);
  2024.      if((LabelBase = OpenLibrary("images/label.image",44))==0) err("Unable to open label.image v44","OK",20);
  2025.      if((ChooserBase = OpenLibrary("gadgets/chooser.gadget",44))==0) err("Unable to open chooser.gadget v44","OK",20);
  2026.      if((ClickTabBase = OpenLibrary("gadgets/clicktab.gadget",44))==0) err("Unable to open clicktab.gadget v44","OK",20);
  2027. //     if((IntegerBase = OpenLibrary("gadgets/integer.gadget",44))==0) err("Unable to open integer.gadget v44","OK",20);
  2028. //     if((ListBrowserBase = OpenLibrary("gadgets/listbrowser.gadget",44))==0) err("Unable to open listbrowser.gadget v44","OK",20);
  2029.      if((GetFileBase = OpenLibrary("gadgets/getfile.gadget",44))==0) err("Unable to open getfile.gadget v44","OK",20);
  2030.      if((StringBase = OpenLibrary("gadgets/string.gadget",44))==0) err("Unable to open string.gadget v44","OK",20);
  2031.  
  2032.  
  2033.     IconBase = OpenLibrary("icon.library",44);
  2034.     if(!IconBase) err("Cannot open icon.library v44","OK",20);
  2035.  
  2036.     for(i=0,wbarg=WBenchMsg->sm_ArgList;i<WBenchMsg->sm_NumArgs;i++,wbarg++)
  2037.         {
  2038.         olddir =-1;
  2039.         if((wbarg->wa_Lock)&&(*wbarg->wa_Name))
  2040.             olddir = CurrentDir(wbarg->wa_Lock);
  2041. if(!name)
  2042. {
  2043. strcpy(defname,"PROGDIR:");
  2044.  AddPart(defname,wbarg->wa_Name,100);
  2045.  name=1;
  2046. }
  2047.  
  2048.         gettooltypes(wbarg);
  2049.  
  2050.         if(olddir !=-1) CurrentDir(olddir);
  2051.         }
  2052.  
  2053. ui();
  2054.  
  2055. }
  2056.  
  2057. void gettooltypes(struct WBArg *wbarg)
  2058. {
  2059.     struct DiskObject *dobj;
  2060.     CONST_STRPTR *toolarray;
  2061.     char *s;
  2062.  
  2063.  
  2064.     if((*wbarg->wa_Name) && (dobj=GetIconTags(wbarg->wa_Name,NULL)))
  2065.         {
  2066.         toolarray = (CONST_STRPTR *)dobj->do_ToolTypes;
  2067.         if(s = (char *)FindToolType(toolarray,"FILE"))
  2068.             {
  2069.                 ttfrom = AllocMem(strlen(s)+1,NULL);
  2070.                 if(ttfrom)
  2071.                     {
  2072.                          strcpy(ttfrom,s);
  2073.                          param.from = ttfrom;
  2074.                     }
  2075.             }
  2076.         if(s = (char *)FindToolType(toolarray,"TO"))
  2077.             {
  2078.                 ttto = AllocMem(strlen(s)+1,NULL);
  2079.                 if(ttto)
  2080.                     {
  2081.                          strcpy(ttto,s);
  2082.                          param.to = ttto;
  2083.                     }
  2084.             }
  2085.  
  2086.         if(s = (char *)FindToolType(toolarray,"HOMEURL"))
  2087.             {
  2088.                 tthomeurl = AllocMem(strlen(s)+1,NULL);
  2089.                 if(tthomeurl)
  2090.                     {
  2091.                          strcpy(tthomeurl,s);
  2092.                          param.homeurl = tthomeurl;
  2093.                     }
  2094.             }
  2095.  
  2096.         if(s = (char *)FindToolType(toolarray,"SEARCHURL"))
  2097.             {
  2098.                 ttfindurl = AllocMem(strlen(s)+1,NULL);
  2099.                 if(ttfindurl)
  2100.                     {
  2101.                          strcpy(ttfindurl,s);
  2102.                          param.findurl = ttfindurl;
  2103.                     }
  2104.             }
  2105.  
  2106.         if(s = (char *)FindToolType(toolarray,"PREV"))
  2107.             {
  2108.                 ttprev = AllocMem(strlen(s)+1,NULL);
  2109.                 if(ttprev)
  2110.                     {
  2111.                          strcpy(ttprev,s);
  2112.                          param.prev = ttprev;
  2113.                     }
  2114.             }
  2115.  
  2116.         if(s = (char *)FindToolType(toolarray,"NEXT"))
  2117.             {
  2118.                 ttnext = AllocMem(strlen(s)+1,NULL);
  2119.                 if(ttnext)
  2120.                     {
  2121.                          strcpy(ttnext,s);
  2122.                          param.next = ttnext;
  2123.                     }
  2124.             }
  2125.  
  2126.         if(s = (char *)FindToolType(toolarray,"INDEX"))
  2127.             {
  2128.                 ttindex = AllocMem(strlen(s)+1,NULL);
  2129.                 if(ttindex)
  2130.                     {
  2131.                          strcpy(ttindex,s);
  2132.                          param.index = ttindex;
  2133.                     }
  2134.             }
  2135.  
  2136.         if(s = (char *)FindToolType(toolarray,"TOC"))
  2137.             {
  2138.                 tttoc = AllocMem(strlen(s)+1,NULL);
  2139.                 if(tttoc)
  2140.                     {
  2141.                          strcpy(tttoc,s);
  2142.                          param.toc = tttoc;
  2143.                     }
  2144.             }
  2145.  
  2146.         if(s = (char *)FindToolType(toolarray,"HELP"))
  2147.             {
  2148.                 tthelp = AllocMem(strlen(s)+1,NULL);
  2149.                 if(tthelp)
  2150.                     {
  2151.                          strcpy(tthelp,s);
  2152.                          param.help = tthelp;
  2153.                     }
  2154.             }
  2155.  
  2156.         if(s = (char *)FindToolType(toolarray,"RETRACE"))
  2157.             {
  2158.                 ttretrace = AllocMem(strlen(s)+1,NULL);
  2159.                 if(ttretrace)
  2160.                     {
  2161.                          strcpy(ttretrace,s);
  2162.                          param.retrace = ttretrace;
  2163.                     }
  2164.             }
  2165.  
  2166.         if(s = (char *)FindToolType(toolarray,"HOME"))
  2167.             {
  2168.                 tthome = AllocMem(strlen(s)+1,NULL);
  2169.                 if(tthome)
  2170.                     {
  2171.                          strcpy(tthome,s);
  2172.                          param.home = tthome;
  2173.                     }
  2174.             }
  2175.  
  2176.         if(s = (char *)FindToolType(toolarray,"SEARCH"))
  2177.             {
  2178.                 ttfind = AllocMem(strlen(s)+1,NULL);
  2179.                 if(ttfind)
  2180.                     {
  2181.                          strcpy(ttfind,s);
  2182.                          param.find = ttfind;
  2183.                     }
  2184.             }
  2185.  
  2186.         if(s = (char *)FindToolType(toolarray,"BAR"))
  2187.             {
  2188.                 ttbar = AllocMem(strlen(s)+1,NULL);
  2189.                 if(ttbar)
  2190.                     {
  2191.                          strcpy(ttbar,s);
  2192.                          param.bar = ttbar;
  2193.                     }
  2194.             }
  2195.  
  2196.         if(s = (char *)FindToolType(toolarray,"BODY"))
  2197.             {
  2198.                 ttbody = AllocMem(strlen(s)+1,NULL);
  2199.                 if(ttbody)
  2200.                     {
  2201.                          strcpy(ttbody,s);
  2202.                          param.bodyext = ttbody;
  2203.                     }
  2204.             }
  2205.  
  2206.         if(s = (char *)FindToolType(toolarray,"HTMLHEADF"))
  2207.             {
  2208.                 tthtmlheadf = AllocMem(strlen(s)+1,NULL);
  2209.                 if(tthtmlheadf)
  2210.                     {
  2211.                          strcpy(tthtmlheadf,s);
  2212.                          param.htmlheadf = tthtmlheadf;
  2213.                     }
  2214.             }
  2215.  
  2216.         if(s = (char *)FindToolType(toolarray,"HTMLFOOTF"))
  2217.             {
  2218.                 tthtmlfootf = AllocMem(strlen(s)+1,NULL);
  2219.                 if(tthtmlfootf)
  2220.                     {
  2221.                          strcpy(tthtmlfootf,s);
  2222.                          param.htmlfootf = tthtmlfootf;
  2223.                     }
  2224.             }
  2225.  
  2226.         if(s = (char *)FindToolType(toolarray,"CSS"))
  2227.             {
  2228.                 ttcss = AllocMem(strlen(s)+1,NULL);
  2229.                 if(ttcss)
  2230.                     {
  2231.                          strcpy(ttcss,s);
  2232.                          param.cssurl = ttcss;
  2233.                     }
  2234.             }
  2235.  
  2236.         if(s = (char *)FindToolType(toolarray,"IMAGES")) param.images = TRUE;
  2237.         if(s = (char *)FindToolType(toolarray,"FOOTER")) param.footer = TRUE;
  2238.         if(s = (char *)FindToolType(toolarray,"NOLINKS")) param.nolink = TRUE;
  2239.         if(s = (char *)FindToolType(toolarray,"NOEMAIL")) param.noemail = TRUE;
  2240.         if(s = (char *)FindToolType(toolarray,"MSDOS")) param.msdos = TRUE;
  2241.         if(s = (char *)FindToolType(toolarray,"NONAVBAR")) param.nonavbar = TRUE;
  2242.         if(s = (char *)FindToolType(toolarray,"NOMOZNAV")) param.nomoznav = TRUE;
  2243.         if(s = (char *)FindToolType(toolarray,"SHOWALL")) param.showall = TRUE;
  2244.         if(s = (char *)FindToolType(toolarray,"VARWIDTH")) param.varwidth = TRUE;
  2245.         if(s = (char *)FindToolType(toolarray,"NOAUTO")) param.noauto = TRUE;
  2246.         if(s = (char *)FindToolType(toolarray,"WORDWRAP")) param.wordwrap = TRUE;
  2247.         if(s = (char *)FindToolType(toolarray,"SMARTWRAP")) param.smartwrap = TRUE;
  2248.         FreeDiskObject(dobj);
  2249.         }
  2250.  
  2251. }
  2252.  
  2253. void savetooltypes(char *fname,int def)
  2254. {
  2255.     struct DiskObject *dobj;
  2256.     UBYTE **oldtooltypes;
  2257.     UBYTE *olddefaulttool;
  2258.     UBYTE oldtype;
  2259.     long olddir=-1;
  2260.     UBYTE *newtooltypes[30];
  2261.     char tttmp1[100];
  2262.     char tttmp2[100];
  2263.     char tttmp3[100];
  2264.     char tttmp4[100];
  2265.     char tttmp5[100];
  2266.     char tttmp6[100];
  2267.     char tttmp7[100];
  2268.     char tttmp8[100];
  2269.     char tttmp9[100];
  2270.     char tttmp10[100];
  2271.     char tttmp11[100];
  2272.     char tttmp12[100];
  2273.     char tttmp13[100];
  2274.     char tttmp14[100];
  2275.     char tttmp15[100];
  2276.     char tttmp16[100];
  2277.     char tttmp17[100];
  2278.     char defaulttool[] = "guideml\0";
  2279.  
  2280. //char *fname="progdir:guideml\0";
  2281.  
  2282. // if((wbarg->wa_Lock) && (wbarg->wa_Name)) olddir=CurrentDir(wbarg->wa_Lock);
  2283.  
  2284. //    if((*wbarg->wa_Name) && (dobj=GetDiskObject(wbarg->wa_Name)))
  2285.     if(dobj=GetIconTags(fname,ICONGETA_FailIfUnavailable,FALSE,NULL))
  2286.         {
  2287.             oldtooltypes = dobj->do_ToolTypes;
  2288.             olddefaulttool = dobj->do_DefaultTool;
  2289.             oldtype = dobj->do_Type;
  2290.  
  2291.             if(param.smartwrap) newtooltypes[0] = "SMARTWRAP";
  2292.                                 else newtooltypes[0] = "(SMARTWRAP)";
  2293.             if(param.wordwrap) newtooltypes[1] = "WORDWRAP";
  2294.                                 else newtooltypes[1] = "(WORDWRAP)";
  2295.             if(param.noauto) newtooltypes[2] = "NOAUTO";
  2296.                                 else newtooltypes[2] = "(NOAUTO)";
  2297.             if(param.varwidth) newtooltypes[3] = "VARWIDTH";
  2298.                                 else newtooltypes[3] = "(VARWIDTH)";
  2299.             if(param.showall) newtooltypes[4] = "SHOWALL";
  2300.                                 else newtooltypes[4] = "(SHOWALL)";
  2301.             if(param.nomoznav) newtooltypes[5] = "NOMOZNAV";
  2302.                                 else newtooltypes[5] = "(NOMOZNAV)";
  2303.             if(param.nonavbar) newtooltypes[6] = "NONAVBAR";
  2304.                                 else newtooltypes[6] = "(NONAVBAR)";
  2305.             if(param.msdos) newtooltypes[7] = "MSDOS";
  2306.                                 else newtooltypes[7] = "(MSDOS)";
  2307.             if(param.noemail) newtooltypes[8] = "NOEMAIL";
  2308.                                 else newtooltypes[8] = "(NOEMAIL)";
  2309.             if(param.nolink) newtooltypes[9] = "NOLINKS";
  2310.                                 else newtooltypes[9] = "(NOLINKS)";
  2311.             if(param.footer) newtooltypes[10] = "FOOTER";
  2312.                                 else newtooltypes[10] = "(FOOTER)";
  2313.             if(param.images) newtooltypes[11] = "IMAGES";
  2314.                                 else newtooltypes[11] = "(IMAGES)";
  2315.             if(param.cssurl)
  2316.             {
  2317.                 strcpy(tttmp1,"CSS=");
  2318.                 newtooltypes[12] = strcat(tttmp1,param.cssurl);
  2319.             }
  2320.                 else
  2321.             {
  2322.                 newtooltypes[12]="(CSS=)";
  2323.             }
  2324.  
  2325.             if(param.htmlfootf)
  2326.             {
  2327.                 strcpy(tttmp2,"HTMLFOOTF=");
  2328.                 newtooltypes[13] = strcat(tttmp2,param.htmlfootf);
  2329.             }
  2330.                 else
  2331.             {
  2332.                 newtooltypes[13]="(HTMLFOOTF=)";
  2333.             }
  2334.  
  2335.             if(param.htmlheadf)
  2336.             {
  2337.                 strcpy(tttmp3,"HTMLHEADF=");
  2338.                 newtooltypes[14] = strcat(tttmp3,param.htmlheadf);
  2339.             }
  2340.                 else
  2341.             {
  2342.                 newtooltypes[14]="(HTMLHEADF=)";
  2343.             }
  2344.  
  2345.             if(param.bodyext)
  2346.             {
  2347.                 strcpy(tttmp4,"BODY=");
  2348.                 newtooltypes[15] = strcat(tttmp4,param.bodyext);
  2349.             }
  2350.                 else
  2351.             {
  2352.                 newtooltypes[15]="(BODY=)";
  2353.             }
  2354.  
  2355.             if(param.bar)
  2356.             {
  2357.                 strcpy(tttmp5,"BAR=");
  2358.                 newtooltypes[16] = strcat(tttmp5,param.bar);
  2359.             }
  2360.                 else
  2361.             {
  2362.                 newtooltypes[16]="(BAR=)";
  2363.             }
  2364.  
  2365.             if(param.find)
  2366.             {
  2367.                 strcpy(tttmp6,"SEARCH=");
  2368.                 newtooltypes[17] = strcat(tttmp6,param.find);
  2369.             }
  2370.                 else
  2371.             {
  2372.                 newtooltypes[17]="(SEARCH=)";
  2373.             }
  2374.  
  2375.             if(param.home)
  2376.             {
  2377.                 strcpy(tttmp7,"HOME=");
  2378.                 newtooltypes[18] = strcat(tttmp7,param.home);
  2379.             }
  2380.                 else
  2381.             {
  2382.                 newtooltypes[18]="(HOME=)";
  2383.             }
  2384.  
  2385.             if(param.retrace)
  2386.             {
  2387.                 strcpy(tttmp8,"RETRACE=");
  2388.                 newtooltypes[19] = strcat(tttmp8,param.retrace);
  2389.             }
  2390.                 else
  2391.             {
  2392.                 newtooltypes[19]="(RETRACE=)";
  2393.             }
  2394.  
  2395.             if(param.help)
  2396.             {
  2397.                 strcpy(tttmp9,"HELP=");
  2398.                 newtooltypes[20] = strcat(tttmp9,param.help);
  2399.             }
  2400.                 else
  2401.             {
  2402.                 newtooltypes[20]="(HELP=)";
  2403.             }
  2404.  
  2405.             if(param.toc)
  2406.             {
  2407.                 strcpy(tttmp10,"TOC=");
  2408.                 newtooltypes[21] = strcat(tttmp10,param.toc);
  2409.             }
  2410.                 else
  2411.             {
  2412.                 newtooltypes[21]="(TOC=)";
  2413.             }
  2414.  
  2415.             if(param.index)
  2416.             {
  2417.                 strcpy(tttmp11,"INDEX=");
  2418.                 newtooltypes[22] = strcat(tttmp11,param.index);
  2419.             }
  2420.                 else
  2421.             {
  2422.                 newtooltypes[22]="(INDEX=)";
  2423.             }
  2424.  
  2425.             if(param.next)
  2426.             {
  2427.                 strcpy(tttmp12,"NEXT=");
  2428.                 newtooltypes[23] = strcat(tttmp12,param.next);
  2429.             }
  2430.                 else
  2431.             {
  2432.                 newtooltypes[23]="(NEXT=)";
  2433.             }
  2434.  
  2435.             if(param.prev)
  2436.             {
  2437.                 strcpy(tttmp13,"PREV=");
  2438.                 newtooltypes[24] = strcat(tttmp13,param.prev);
  2439.             }
  2440.                 else
  2441.             {
  2442.                 newtooltypes[24]="(PREV=)";
  2443.             }
  2444.  
  2445.             if(param.findurl)
  2446.             {
  2447.                 strcpy(tttmp14,"SEARCHURL=");
  2448.                 newtooltypes[25] = strcat(tttmp14,param.findurl);
  2449.             }
  2450.                 else
  2451.             {
  2452.                 newtooltypes[25]="(SEARCHURL=)";
  2453.             }
  2454.  
  2455.             if(param.homeurl)
  2456.             {
  2457.                 strcpy(tttmp15,"HOMEURL=");
  2458.                 newtooltypes[26] = strcat(tttmp15,param.homeurl);
  2459.             }
  2460.                 else
  2461.             {
  2462.                 newtooltypes[26]="(HOMEURL=)";
  2463.             }
  2464.  
  2465.         if(!def)
  2466.         {
  2467.  
  2468.             if(param.to)
  2469.             {
  2470.                 strcpy(tttmp16,"TO=");
  2471.                 newtooltypes[27] = strcat(tttmp16,param.to);
  2472.             }
  2473.                 else
  2474.             {
  2475.                 newtooltypes[27]="(TO=)";
  2476.             }
  2477.  
  2478.             if(param.from)
  2479.             {
  2480.                 strcpy(tttmp17,"FILE=");
  2481.                 newtooltypes[28] = strcat(tttmp17,param.from);
  2482.             }
  2483.                 else
  2484.             {
  2485.                 newtooltypes[28]="(FILE=)";
  2486.             }
  2487.  
  2488.             dobj->do_DefaultTool = defaulttool;
  2489.             dobj->do_Type = WBPROJECT;
  2490.  
  2491.         }
  2492.         else
  2493.         {
  2494.             newtooltypes[27]=NULL;
  2495.         }
  2496.  
  2497.             newtooltypes[29] = NULL;
  2498.             dobj->do_ToolTypes = newtooltypes;
  2499.             PutIconTags(fname,dobj,NULL); //            PutDiskObject(fname,dobj); // PutDiskObject(wbarg->wa_Name,dobj);
  2500.             dobj->do_ToolTypes=oldtooltypes;
  2501.             dobj->do_DefaultTool=olddefaulttool;
  2502.             dobj->do_Type = oldtype;
  2503.             FreeDiskObject(dobj);
  2504.         }
  2505.  
  2506. // if(olddir!=-1) CurrentDir(olddir);
  2507.  
  2508. }
  2509.  
  2510. int saveas()
  2511. {
  2512.     BPTR fp;
  2513.     int t;
  2514.     char *filename[2048];
  2515.     char guidemlcmd[2048];
  2516.     struct FileRequester *req;
  2517.     struct TagItem asltags[] = {ASLFR_TitleText,(ULONG)"Save As...",
  2518.                              ASLFR_InitialShowVolumes,TRUE,
  2519.                              ASLFR_DoSaveMode,TRUE,TAG_DONE};
  2520.  
  2521.     req = (struct FileRequester *)AllocAslRequest(ASL_FileRequest,NULL);
  2522.     t = AslRequest(req,asltags);
  2523.  
  2524.     if (t==FALSE)
  2525.    {
  2526.         // user cancelled
  2527.         return(0);
  2528.     }
  2529.  
  2530.     strcpy((STRPTR)filename,req->fr_Drawer);
  2531.     AddPart((STRPTR)filename,req->fr_File,2048);
  2532.  
  2533.     FreeAslRequest(req);
  2534.  
  2535.     fp = Open((STRPTR)filename,MODE_NEWFILE);
  2536.  
  2537.     strcpy(guidemlcmd,"guideml \"");
  2538.     if(param.from) strcat(guidemlcmd,param.from);
  2539.     if(param.from) strcat(guidemlcmd,"\" ");
  2540.     if(param.to) strcat(guidemlcmd,"TO=\"");
  2541.     if(param.to) strcat(guidemlcmd,param.to);
  2542.     if(param.to) strcat(guidemlcmd,"\" ");
  2543.     if(param.homeurl) strcat(guidemlcmd,"HOMEURL=\"");
  2544.     if(param.homeurl) strcat(guidemlcmd,param.homeurl);
  2545.     if(param.homeurl) strcat(guidemlcmd,"\" ");
  2546.     if(param.prev) strcat(guidemlcmd,"PREV=\"");
  2547.     if(param.prev) strcat(guidemlcmd,param.prev);
  2548.     if(param.prev) strcat(guidemlcmd,"\" ");
  2549.     if(param.next) strcat(guidemlcmd,"NEXT=\"");
  2550.     if(param.next) strcat(guidemlcmd,param.next);
  2551.     if(param.next) strcat(guidemlcmd,"\" ");
  2552.     if(param.index) strcat(guidemlcmd,"INDEX=\"");
  2553.     if(param.index) strcat(guidemlcmd,param.index);
  2554.     if(param.index) strcat(guidemlcmd,"\" ");
  2555.     if(param.toc) strcat(guidemlcmd,"TOC=\"");
  2556.     if(param.toc) strcat(guidemlcmd,param.toc);
  2557.     if(param.toc) strcat(guidemlcmd,"\" ");
  2558.     if(param.help) strcat(guidemlcmd,"HELP=\"");
  2559.     if(param.help) strcat(guidemlcmd,param.help);
  2560.     if(param.help) strcat(guidemlcmd,"\" ");
  2561.     if(param.retrace) strcat(guidemlcmd,"RETRACE=\"");
  2562.     if(param.retrace) strcat(guidemlcmd,param.retrace);
  2563.     if(param.retrace) strcat(guidemlcmd,"\" ");
  2564.     if(param.home) strcat(guidemlcmd,"HOME=\"");
  2565.     if(param.home) strcat(guidemlcmd,param.home);
  2566.     if(param.home) strcat(guidemlcmd,"\" ");
  2567.     if(param.bar) strcat(guidemlcmd,"BAR=\"");
  2568.     if(param.bar) strcat(guidemlcmd,param.bar);
  2569.     if(param.bar) strcat(guidemlcmd,"\" ");
  2570.     if(param.bodyext) strcat(guidemlcmd,"BODY=\"");
  2571.     if(param.bodyext) strcat(guidemlcmd,param.bodyext);
  2572.     if(param.bodyext) strcat(guidemlcmd,"\" ");
  2573.     if(param.htmlheadf) strcat(guidemlcmd,"HTMLHEADF=\"");
  2574.     if(param.htmlheadf) strcat(guidemlcmd,param.htmlheadf);
  2575.     if(param.htmlheadf) strcat(guidemlcmd,"\" ");
  2576.     if(param.htmlfootf) strcat(guidemlcmd,"HTMLFOOTF=\"");
  2577.     if(param.htmlfootf) strcat(guidemlcmd,param.htmlfootf);
  2578.     if(param.htmlfootf) strcat(guidemlcmd,"\" ");
  2579.     if(param.cssurl) strcat(guidemlcmd,"CSS=\"");
  2580.     if(param.cssurl) strcat(guidemlcmd,param.cssurl);
  2581.     if(param.cssurl) strcat(guidemlcmd,"\" ");
  2582.  
  2583.     if(param.images) strcat(guidemlcmd,"IMAGES ");
  2584.     if(param.footer) strcat(guidemlcmd,"FOOTER ");
  2585.     if(param.nolink) strcat(guidemlcmd,"NOLINKS ");
  2586.     if(param.noemail) strcat(guidemlcmd,"NOEMAIL ");
  2587.     if(param.msdos) strcat(guidemlcmd,"MSDOS ");
  2588.     if(param.nonavbar) strcat(guidemlcmd,"NONAVBAR ");
  2589.     if(param.nomoznav) strcat(guidemlcmd,"NOMOZNAV ");
  2590.     if(param.showall) strcat(guidemlcmd,"SHOWALL ");
  2591.     if(param.wordwrap) strcat(guidemlcmd,"WORDWRAP ");
  2592.     if(param.smartwrap) strcat(guidemlcmd,"SMARTWRAP ");
  2593.     if(param.varwidth) strcat(guidemlcmd,"VARWIDTH ");
  2594.     if(param.noauto) strcat(guidemlcmd,"NOAUTO ");
  2595.     strcat(guidemlcmd,"\n");
  2596.  
  2597.  
  2598.     FPuts(fp,guidemlcmd);
  2599.  
  2600.     Close(fp);
  2601.  
  2602.     savetooltypes((STRPTR)filename,0);
  2603. }
  2604.  
  2605.  
  2606. void ui()
  2607. {
  2608.     long i=0; // temp variable
  2609.     struct List optlist;
  2610.     struct List navoptlist;
  2611.     struct List imgoptlist;
  2612.     struct List linkoptlist;
  2613.     struct List tablist;
  2614.     struct MsgPort *AppPort;
  2615.  
  2616.     struct Window *windows[WID_LAST];
  2617.     Object *objects[OID_LAST];
  2618.  
  2619.     UBYTE *opts[] = {"Auto","Wordwrap","Smartwrap","None",NULL};
  2620.     UBYTE *navopts[] = {"Header","Both","None",NULL};
  2621.     UBYTE *linkopts[] = {"Convert All","Not Email","Email Only","None",NULL};
  2622.     UBYTE *imgopts[] = {"Text","Images",NULL};
  2623.     UBYTE *tabs[] = {"Convert","Options",NULL};
  2624.         struct Menu *menustrip;
  2625.     UWORD menunum,itemnum,subnum; //menusel;
  2626.     struct MenuItem *item;
  2627.     int wrapm =0;
  2628.     int navm=0;
  2629.     int linkm=0;
  2630.  
  2631. if(param.noauto) wrapm = 3;
  2632. if(param.wordwrap) wrapm = 1;
  2633. if(param.smartwrap) wrapm = 2;
  2634. if(!param.noauto) wrapm = 0;
  2635.  
  2636. if(param.footer) navm = 1;
  2637. if(param.nonavbar) navm=2;
  2638.  
  2639. if(param.noemail) linkm=1;
  2640. if(param.nolink) linkm=linkm+2;
  2641.  
  2642. make_list(&optlist,opts);
  2643. make_list(&navoptlist,navopts);
  2644. make_list(&imgoptlist,imgopts);
  2645. make_list(&linkoptlist,linkopts);
  2646. maketablist(&tablist,tabs);
  2647.  
  2648.     if ( AppPort = CreateMsgPort() )
  2649.     {
  2650.         /* Create the window object.
  2651.          */
  2652.         objects[OID_MAIN] = WindowObject,
  2653.             WA_ScreenTitle, "GuideML " VERSIONSTR " (" VERSIONDATE ")",
  2654.             WA_Title, "GuideML",
  2655.             WA_Activate, TRUE,
  2656.             WA_DepthGadget, TRUE,
  2657.             WA_DragBar, TRUE,
  2658.             WA_CloseGadget, TRUE,
  2659.             WA_SizeGadget, TRUE,
  2660.             WA_SmartRefresh,TRUE,
  2661.             WA_IDCMP,IDCMP_MENUPICK,
  2662.             WINDOW_IconifyGadget, FALSE,
  2663.             WINDOW_IconTitle, "GuideML",
  2664.             WINDOW_AppPort, AppPort,
  2665.             WINDOW_Position, WPOS_CENTERMOUSE,
  2666.             WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  2667.                 LAYOUT_SpaceOuter, TRUE,
  2668.                 LAYOUT_AddChild, gadgets[GID_TABS] = ClickTabObject,
  2669.                     GA_ID, GID_TABS,
  2670.                   GA_RelVerify, TRUE,
  2671.                   CLICKTAB_Labels,&tablist,
  2672.                       CLICKTAB_PageGroup, PageObject,
  2673.                         PAGE_Add,LayoutObject,
  2674.                             LAYOUT_AddChild,VGroupObject,
  2675.                                     LAYOUT_SpaceOuter,TRUE,
  2676.                                 LAYOUT_AddChild, gadgets[GID_FILE] = GetFileObject,
  2677.                                     GA_ID, GID_FILE,
  2678.                                     GA_RelVerify, TRUE,
  2679.                                     GETFILE_TitleText,"GuideML",
  2680.                                         GETFILE_Pattern,"#?.guide",
  2681.                                         GETFILE_DoPatterns,TRUE,
  2682.                                         GETFILE_ReadOnly,FALSE,
  2683.                                         GETFILE_FullFile,param.from,
  2684.                                 End,
  2685.                                 CHILD_Label, LabelObject,
  2686.                                 LABEL_Text, "_Input File",
  2687.                                 LabelEnd,
  2688.                                 CHILD_NominalSize, TRUE,
  2689.                                 LAYOUT_AddChild, gadgets[GID_TO] = GetFileObject,
  2690.                                     GA_ID, GID_TO,
  2691.                                     GA_RelVerify, TRUE,
  2692.                                     GETFILE_TitleText,"GuideML",
  2693.                                         GETFILE_DoSaveMode,TRUE,
  2694.                                         GETFILE_DrawersOnly,TRUE,
  2695.                                         GETFILE_ReadOnly,FALSE,
  2696.                                         GETFILE_Drawer,param.to,
  2697.                                 End,
  2698.                                 CHILD_Label, LabelObject,
  2699.                                 LABEL_Text, "_Output Path",
  2700.                                 LabelEnd,
  2701.                                 CHILD_NominalSize, TRUE,
  2702.                                 LAYOUT_AddChild, gadgets[GID_HOMEURL] = StringObject,
  2703.                                     GA_ID, GID_HOMEURL,
  2704.                                     GA_RelVerify, TRUE,
  2705.                                     STRINGA_TextVal,param.homeurl,
  2706.                                     STRINGA_MaxChars,100,
  2707.                                 End,
  2708.                                 CHILD_Label, LabelObject,
  2709.                                 LABEL_Text, "_Home URL",
  2710.                                 LabelEnd,
  2711.                                 CHILD_NominalSize, TRUE,
  2712.                                 LAYOUT_AddChild, gadgets[GID_FINDURL] = StringObject,
  2713.                                     GA_ID, GID_FINDURL,
  2714.                                     GA_RelVerify, TRUE,
  2715.                                     STRINGA_TextVal,param.findurl,
  2716.                                     STRINGA_MaxChars,100,
  2717.                                 End,
  2718.                                 CHILD_Label, LabelObject,
  2719.                                 LABEL_Text, "_Search URL",
  2720.                                 LabelEnd,
  2721.                                 CHILD_NominalSize, TRUE,
  2722.                                 LAYOUT_AddChild, gadgets[GID_CSS] = StringObject,
  2723.                                     GA_ID, GID_CSS,
  2724.                                     GA_RelVerify, TRUE,
  2725.                                     STRINGA_TextVal,param.cssurl,
  2726.                                     STRINGA_MaxChars,100,
  2727.                                 End,
  2728.                                 CHILD_Label, LabelObject,
  2729.                                 LABEL_Text, "CSS _URL",
  2730.                                 LabelEnd,
  2731.                                 CHILD_NominalSize, TRUE,
  2732.                                 LAYOUT_AddChild, gadgets[GID_BODY] = StringObject,
  2733.                                     GA_ID, GID_BODY,
  2734.                                     GA_RelVerify, TRUE,
  2735.                                     STRINGA_TextVal,param.bodyext,
  2736.                                     STRINGA_MaxChars,100,
  2737.                                 End,
  2738.                                 CHILD_Label, LabelObject,
  2739.                                 LABEL_Text, "_Body",
  2740.                                 LabelEnd,
  2741.                                 CHILD_NominalSize, TRUE,
  2742.                                 LAYOUT_AddChild, gadgets[GID_HTMLHEADF] = GetFileObject,
  2743.                                     GA_ID, GID_HTMLHEADF,
  2744.                                     GA_RelVerify, TRUE,
  2745.                                     GETFILE_TitleText,"GuideML",
  2746.                                         GETFILE_Pattern,"#?.(s|%)htm(l|%)",
  2747.                                         GETFILE_DoPatterns,TRUE,
  2748.                                         GETFILE_ReadOnly,FALSE,
  2749.                                         GETFILE_FullFile,param.htmlheadf,
  2750.                                 End,
  2751.                                 CHILD_Label, LabelObject,
  2752.                                 LABEL_Text, "HTML H_eader",
  2753.                                 LabelEnd,
  2754.                                 LAYOUT_AddChild, gadgets[GID_HTMLFOOTF] = GetFileObject,
  2755.                                     GA_ID, GID_HTMLFOOTF,
  2756.                                     GA_RelVerify, TRUE,
  2757.                                     GETFILE_TitleText,"GuideML",
  2758.                                         GETFILE_Pattern,"#?.(s|%)htm(l|%)",
  2759.                                         GETFILE_DoPatterns,TRUE,
  2760.                                         GETFILE_ReadOnly,FALSE,
  2761.                                         GETFILE_FullFile,param.htmlfootf,
  2762.                                 End,
  2763.                                 CHILD_Label, LabelObject,
  2764.                                 LABEL_Text, "HTML _Footer",
  2765.                                 LabelEnd,
  2766.                                 LayoutEnd,
  2767.                             LayoutEnd,
  2768. //                        PageEnd,
  2769.  
  2770. //                      CLICKTAB_PageGroup, PageObject,
  2771.                         PAGE_Add,LayoutObject,
  2772.                            LAYOUT_AddChild,VGroupObject,
  2773. // wrap
  2774.                                LAYOUT_AddChild,HGroupObject,
  2775.                                      LAYOUT_AddChild,VGroupObject,
  2776.                                             LAYOUT_SpaceOuter,TRUE,
  2777.                                         LAYOUT_AddChild, gadgets[GID_WRAP] = ChooserObject,
  2778.                                             GA_ID, GID_WRAP,
  2779.                                             GA_RelVerify, TRUE,
  2780.                                           CHOOSER_PopUp,TRUE,
  2781.                                           CHOOSER_Labels,&optlist,
  2782.                                             CHOOSER_Selected,wrapm,
  2783.                                             CHOOSER_AutoFit,TRUE,
  2784.                                         ChooserEnd,
  2785.                                         CHILD_Label, LabelObject,
  2786.                                         LABEL_Text, "_Wrap mode",
  2787.                                         LabelEnd,
  2788.                                         CHILD_NominalSize, TRUE,
  2789.  
  2790.                                         LAYOUT_AddChild, gadgets[GID_NAVBAR] = ChooserObject,
  2791.                                             GA_ID, GID_NAVBAR,
  2792.                                             GA_RelVerify, TRUE,
  2793.                                           CHOOSER_PopUp,TRUE,
  2794.                                           CHOOSER_Labels,&navoptlist,
  2795.                                             CHOOSER_Selected,navm,
  2796.                                             CHOOSER_AutoFit,TRUE,
  2797.                                         ChooserEnd,
  2798.                                         CHILD_Label, LabelObject,
  2799.                                         LABEL_Text, "_Nav bar",
  2800.                                         LabelEnd,
  2801.                                         CHILD_NominalSize, TRUE,
  2802.  
  2803.                                         LAYOUT_AddChild, gadgets[GID_IMAGES] = ChooserObject,
  2804.                                             GA_ID, GID_IMAGES,
  2805.                                             GA_RelVerify, TRUE,
  2806.                                           CHOOSER_PopUp,TRUE,
  2807.                                           CHOOSER_Labels,&imgoptlist,
  2808.                                             CHOOSER_Selected,param.images,
  2809.                                             CHOOSER_AutoFit,TRUE,
  2810.                                         ChooserEnd,
  2811.                                         CHILD_Label, LabelObject,
  2812.                                         LABEL_Text, "_Style",
  2813.                                         LabelEnd,
  2814.                                         CHILD_NominalSize, TRUE,
  2815.  
  2816.                                         LAYOUT_AddChild, gadgets[GID_LINKS] = ChooserObject,
  2817.                                             GA_ID, GID_LINKS,
  2818.                                             GA_RelVerify, TRUE,
  2819.                                           CHOOSER_PopUp,TRUE,
  2820.                                           CHOOSER_Labels,&linkoptlist,
  2821.                                             CHOOSER_Selected,linkm,
  2822.                                             CHOOSER_AutoFit,TRUE,
  2823.                                         ChooserEnd,
  2824.                                         CHILD_Label, LabelObject,
  2825.                                         LABEL_Text, "_Links",
  2826.                                         LabelEnd,
  2827.                                         CHILD_NominalSize, TRUE,
  2828.  
  2829.                                         LAYOUT_AddChild, gadgets[GID_PREV] = StringObject,
  2830.                                             GA_ID, GID_PREV,
  2831.                                             GA_RelVerify, TRUE,
  2832.                                             STRINGA_TextVal,param.prev,
  2833.                                             STRINGA_MaxChars,100,
  2834.                                         End,
  2835.                                         CHILD_Label, LabelObject,
  2836.                                         LABEL_Text, "_Previous",
  2837.                                         LabelEnd,
  2838.                                             CHILD_NominalSize, TRUE,
  2839.                                         LAYOUT_AddChild, gadgets[GID_NEXT] = StringObject,
  2840.                                             GA_ID, GID_NEXT,
  2841.                                             GA_RelVerify, TRUE,
  2842.                                             STRINGA_TextVal,param.next,
  2843.                                             STRINGA_MaxChars,100,
  2844.                                         End,
  2845.                                         CHILD_Label, LabelObject,
  2846.                                         LABEL_Text, "Nex_t",
  2847.                                         LabelEnd,
  2848.                                             CHILD_NominalSize, TRUE,
  2849.                                         LAYOUT_AddChild, gadgets[GID_INDEX] = StringObject,
  2850.                                             GA_ID, GID_INDEX,
  2851.                                             GA_RelVerify, TRUE,
  2852.                                             STRINGA_TextVal,param.index,
  2853.                                             STRINGA_MaxChars,100,
  2854.                                         End,
  2855.                                         CHILD_Label, LabelObject,
  2856.                                         LABEL_Text, "Inde_x",
  2857.                                         LabelEnd,
  2858.                                             CHILD_NominalSize, TRUE,
  2859.                                         LAYOUT_AddChild, gadgets[GID_TOC] = StringObject,
  2860.                                             GA_ID, GID_TOC,
  2861.                                             GA_RelVerify, TRUE,
  2862.                                             STRINGA_TextVal,param.toc,
  2863.                                             STRINGA_MaxChars,100,
  2864.                                         End,
  2865.                                         CHILD_Label, LabelObject,
  2866.                                         LABEL_Text, "C_ontents",
  2867.                                         LabelEnd,
  2868.                                             CHILD_NominalSize, TRUE,
  2869.                                         LayoutEnd,
  2870.                                    LAYOUT_AddChild,VGroupObject,
  2871.                                         LAYOUT_AddChild, gadgets[GID_VARWIDTH] = CheckBoxObject,
  2872.                                             GA_ID, GID_VARWIDTH,
  2873.                                             GA_RelVerify, TRUE,
  2874.                                             GA_Text,"_Variable Width Font",
  2875.                                             GA_Selected,param.varwidth,
  2876.                                             CHECKBOX_TextPlace,PLACETEXT_LEFT,
  2877.                                         CheckBoxEnd,
  2878.                                         CHILD_NominalSize, TRUE,
  2879.                                         LAYOUT_AddChild, gadgets[GID_MOZNAV] = CheckBoxObject,
  2880.                                             GA_ID, GID_MOZNAV,
  2881.                                             GA_RelVerify, TRUE,
  2882.                                             GA_Text,"_Mozilla Site Navigation Bar",
  2883.                                             GA_Selected,param.nomoznav+1,
  2884.                                             CHECKBOX_TextPlace,PLACETEXT_LEFT,
  2885.                                         CheckBoxEnd,
  2886.                                         /*CHILD_Label, LabelObject,
  2887.                                         LABEL_Text, "_Site Nav",
  2888.                                         LabelEnd,*/
  2889.                                         CHILD_NominalSize, TRUE,
  2890.                                         LAYOUT_AddChild, gadgets[GID_SHOWALL] = CheckBoxObject,
  2891.                                             GA_ID, GID_SHOWALL,
  2892.                                             GA_RelVerify, TRUE,
  2893.                                             GA_Text,"Consistent _Across Pages",
  2894.                                             GA_Selected,param.showall,
  2895.                                             CHECKBOX_TextPlace,PLACETEXT_LEFT,
  2896.                                         CheckBoxEnd,
  2897.                                         /*CHILD_Label, LabelObject,
  2898.                                         LABEL_Text, "Show _All",
  2899.                                         LabelEnd,*/
  2900.                                         CHILD_NominalSize, TRUE,
  2901.                                         LAYOUT_AddChild, gadgets[GID_MSDOS] = CheckBoxObject,
  2902.                                             GA_ID, GID_MSDOS,
  2903.                                             GA_RelVerify, TRUE,
  2904.                                             GA_Text,"MS-_DOS Compatible Filenames",
  2905.                                             GA_Selected,param.msdos,
  2906.                                             CHECKBOX_TextPlace,PLACETEXT_LEFT,
  2907.                                         CheckBoxEnd,
  2908.                                         CHILD_NominalSize, TRUE,
  2909.                                         LAYOUT_AddChild, gadgets[GID_HELP] = StringObject,
  2910.                                             GA_ID, GID_HELP,
  2911.                                             GA_RelVerify, TRUE,
  2912.                                             STRINGA_TextVal,param.help,
  2913.                                             STRINGA_MaxChars,100,
  2914.                                         End,
  2915.                                         CHILD_Label, LabelObject,
  2916.                                         LABEL_Text, "H_elp",
  2917.                                         LabelEnd,
  2918.                                             CHILD_NominalSize, TRUE,
  2919.                                         LAYOUT_AddChild, gadgets[GID_RETRACE] = StringObject,
  2920.                                             GA_ID, GID_RETRACE,
  2921.                                             GA_RelVerify, TRUE,
  2922.                                             STRINGA_TextVal,param.retrace,
  2923.                                             STRINGA_MaxChars,100,
  2924.                                         End,
  2925.                                         CHILD_Label, LabelObject,
  2926.                                         LABEL_Text, "_Retrace",
  2927.                                         LabelEnd,
  2928.                                             CHILD_NominalSize, TRUE,
  2929.                                         LAYOUT_AddChild, gadgets[GID_HOME] = StringObject,
  2930.                                             GA_ID, GID_HOME,
  2931.                                             GA_RelVerify, TRUE,
  2932.                                             STRINGA_TextVal,param.home,
  2933.                                             STRINGA_MaxChars,100,
  2934.                                         End,
  2935.                                         CHILD_Label, LabelObject,
  2936.                                         LABEL_Text, "H_ome",
  2937.                                         LabelEnd,
  2938.                                             CHILD_NominalSize, TRUE,
  2939.                                         LAYOUT_AddChild, gadgets[GID_FIND] = StringObject,
  2940.                                             GA_ID, GID_FIND,
  2941.                                             GA_RelVerify, TRUE,
  2942.                                             STRINGA_TextVal,param.find,
  2943.                                             STRINGA_MaxChars,100,
  2944.                                         End,
  2945.                                         CHILD_Label, LabelObject,
  2946.                                         LABEL_Text, "S_earch",
  2947.                                         LabelEnd,
  2948.                                             CHILD_NominalSize, TRUE,
  2949.                                         LAYOUT_AddChild, gadgets[GID_BAR] = StringObject,
  2950.                                             GA_ID, GID_BAR,
  2951.                                             GA_RelVerify, TRUE,
  2952.                                             STRINGA_TextVal,param.bar,
  2953.                                             STRINGA_MaxChars,10,
  2954.                                         End,
  2955.                                         CHILD_Label, LabelObject,
  2956.                                         LABEL_Text, "_Bar",
  2957.                                         LabelEnd,
  2958.                                             CHILD_NominalSize, TRUE,
  2959.  
  2960.                                         LayoutEnd,
  2961.                                     LayoutEnd,
  2962.                                 LayoutEnd,
  2963.                             LayoutEnd,
  2964.                         PageEnd,
  2965.  
  2966.                    ClickTabEnd,
  2967.  
  2968.                 LAYOUT_AddChild, HGroupObject,
  2969.                     GA_BackFill, NULL,
  2970.                     LAYOUT_SpaceOuter, FALSE,
  2971.                     LAYOUT_VertAlignment, LALIGN_CENTER,
  2972.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  2973.                   //  LAYOUT_BevelStyle, BVS_FIELD,
  2974.                           LAYOUT_AddChild, gadgets[GID_CONV] = ButtonObject,
  2975.                             GA_ID, GID_CONV,
  2976.                             GA_RelVerify, TRUE,
  2977.                             GA_Text,"_Convert",
  2978.                         ButtonEnd,
  2979.                 LayoutEnd,
  2980.                 CHILD_WeightedHeight, 0,
  2981.             EndGroup,
  2982.         EndWindow;
  2983.  
  2984.  
  2985.          /*  Object creation sucessful?
  2986.           */
  2987.         if (objects[OID_MAIN])
  2988.         {
  2989.             /*  Open the window.
  2990.              */
  2991.             if (windows[WID_MAIN] = (struct Window *) RA_OpenWindow(objects[OID_MAIN]))
  2992.             {
  2993.                 ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  2994.                 ULONG done = FALSE;
  2995.                 ULONG result;
  2996.                 UWORD code;
  2997.  
  2998.                     menustrip = addmenu(windows[WID_MAIN]);
  2999.  
  3000.                  /* Obtain the window wait signal mask.
  3001.                  */
  3002.                 GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  3003.  
  3004.                 /* Input Event Loop
  3005.                  */
  3006.                 while (!done)
  3007.                 {
  3008.                     wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  3009.  
  3010.                             if(wait & SIGBREAKF_CTRL_C)
  3011.                                 {
  3012.                         done = TRUE;
  3013.                                 }
  3014.                             else
  3015.                                 {
  3016.                         while ( (result = RA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  3017.                         {
  3018.                             switch (result & WMHI_CLASSMASK)
  3019.                             {
  3020.                                 case WMHI_CLOSEWINDOW:
  3021.                                     windows[WID_MAIN] = NULL;
  3022.                                     done = TRUE;
  3023.                                     break;
  3024.  
  3025.                                 case WMHI_MENUPICK:
  3026.                                         while (code !=MENUNULL)
  3027.                                         {
  3028.                                             //menusel = code;
  3029.                                             item = ItemAddress(menustrip,code);
  3030.                                             menunum = MENUNUM(code);
  3031.                                             itemnum = ITEMNUM(code);
  3032.                                             subnum = SUBNUM(code);
  3033.  
  3034.                                             switch(menunum)
  3035.                                             {
  3036.                                                 case 0:  // Project
  3037.                                                     switch(itemnum)
  3038.                                                     {
  3039.  
  3040.                                                         case 0: // save
  3041.                                                                     SetWindowPointer(windows[WID_MAIN],WA_BusyPointer,TRUE,WA_PointerDelay,TRUE,TAG_DONE);
  3042.                                                                      saveas();
  3043.                                                                     SetWindowPointer(windows[WID_MAIN],TAG_DONE);
  3044.                                                         break;
  3045.  
  3046.                                                         case 2: // about
  3047.  
  3048.                                                             err("GuideML "VERSIONSTR"\n\n© 1997-8 Richard Körber\nhttp://www.shredzone.de\n\n© 2001-4 Chris Young\nhttp://www.unsatisfactorysoftware.co.uk","OK",0);
  3049.                                                         break;
  3050.  
  3051.                                                         case 4: // quit
  3052.  
  3053.                                                         windows[WID_MAIN] = NULL;
  3054.                                                         done = TRUE;
  3055.  
  3056.                                                         break;
  3057.  
  3058.                                                     }
  3059.                                                 break;
  3060.  
  3061.                                                 case 1: // Settings
  3062.                                                     switch(itemnum)
  3063.                                                     {
  3064.                                                         case 0:
  3065.                                                          // save defaults
  3066.                                                                 SetWindowPointer(windows[WID_MAIN],WA_BusyPointer,TRUE,WA_PointerDelay,TRUE,TAG_DONE);
  3067.                                                          savetooltypes(defname,1);
  3068.                                                                 SetWindowPointer(windows[WID_MAIN],TAG_DONE);
  3069.                                                         break;
  3070.                                                     }
  3071.                                                 break;
  3072.  
  3073.  
  3074.                                             }
  3075.  
  3076.  
  3077.                                             code = item->NextSelect;
  3078.                                         }
  3079.                                         break;
  3080.  
  3081.                                 case WMHI_GADGETUP:
  3082.                                     switch (result & WMHI_GADGETMASK)
  3083.                                     {
  3084.                                         case GID_FILE:
  3085.                                             if(DoMethod((Object *)gadgets[GID_FILE],GFILE_REQUEST,windows[WID_MAIN]))
  3086.                                             {
  3087.                                                 GetAttr(GETFILE_FullFile,gadgets[GID_FILE],(ULONG*)¶m.from);
  3088.                                             }
  3089.  
  3090.                                           break;
  3091.  
  3092.                                         case GID_TO:
  3093.                                             if(DoMethod((Object *)gadgets[GID_TO],GFILE_REQUEST,windows[WID_MAIN]))
  3094.                                             {
  3095.                                                 GetAttr(GETFILE_Drawer,gadgets[GID_TO],(ULONG*)¶m.to);
  3096.                                             }
  3097.  
  3098.                                           break;
  3099.                                         case GID_HTMLHEADF:
  3100.                                             if(DoMethod((Object *)gadgets[GID_HTMLHEADF],GFILE_REQUEST,windows[WID_MAIN]))
  3101.                                             {
  3102.                                                 GetAttr(GETFILE_FullFile,gadgets[GID_HTMLHEADF],(ULONG*)¶m.htmlheadf);
  3103.                                             }
  3104.                                               if(param.htmlheadf)
  3105.                                                   {
  3106.                                                       if(strlen(param.htmlheadf)==0) param.htmlheadf=0;
  3107.                                                   }
  3108.  
  3109.                                           break;
  3110.                                         case GID_HTMLFOOTF:
  3111.                                             if(DoMethod((Object *)gadgets[GID_HTMLFOOTF],GFILE_REQUEST,windows[WID_MAIN]))
  3112.                                             {
  3113.                                                 GetAttr(GETFILE_FullFile,gadgets[GID_HTMLFOOTF],(ULONG*)¶m.htmlfootf);
  3114.                                             }
  3115.                                               if(param.htmlfootf)
  3116.                                                   {
  3117.                                                       if(strlen(param.htmlfootf)==0) param.htmlfootf=0;
  3118.                                                             }
  3119.                                           break;
  3120.  
  3121.                                         case GID_BODY:
  3122.                                               GetAttr(STRINGA_TextVal,gadgets[GID_BODY],(ULONG*)¶m.bodyext);
  3123.                                               if(strlen(param.bodyext)==0) param.bodyext=0;
  3124.                                         break;
  3125.                                         case GID_CSS:
  3126.                                               GetAttr(STRINGA_TextVal,gadgets[GID_CSS],(ULONG*)¶m.cssurl);
  3127.                                               if(strlen(param.cssurl)==0) param.cssurl=0;
  3128.                                         break;
  3129.                                         case GID_HOMEURL:
  3130.                                               GetAttr(STRINGA_TextVal,gadgets[GID_HOMEURL],(ULONG*)¶m.homeurl);
  3131.                                               if(strlen(param.homeurl)==0) param.homeurl=0;
  3132.                                         break;
  3133.  
  3134.                                         case GID_FINDURL:
  3135.                                               GetAttr(STRINGA_TextVal,gadgets[GID_FINDURL],(ULONG*)¶m.findurl);
  3136.                                               if(strlen(param.findurl)==0) param.findurl=0;
  3137.                                         break;
  3138.  
  3139.                                         case GID_RETRACE:
  3140.                                               GetAttr(STRINGA_TextVal,gadgets[GID_RETRACE],(ULONG*)¶m.retrace);
  3141.                                               if(strlen(param.retrace)==0) param.retrace=0;
  3142.                                         break;
  3143.  
  3144.                                         case GID_PREV:
  3145.                                               GetAttr(STRINGA_TextVal,gadgets[GID_PREV],(ULONG*)¶m.prev);
  3146.                                               if(strlen(param.prev)==0) param.prev=0;
  3147.                                         break;
  3148.  
  3149.                                         case GID_NEXT:
  3150.                                               GetAttr(STRINGA_TextVal,gadgets[GID_NEXT],(ULONG*)¶m.next);
  3151.                                               if(strlen(param.next)==0) param.next=0;
  3152.                                         break;
  3153.  
  3154.                                         case GID_INDEX:
  3155.                                               GetAttr(STRINGA_TextVal,gadgets[GID_INDEX],(ULONG*)¶m.index);
  3156.                                               if(strlen(param.index)==0) param.index=0;
  3157.                                         break;
  3158.  
  3159.                                         case GID_TOC:
  3160.                                               GetAttr(STRINGA_TextVal,gadgets[GID_TOC],(ULONG*)¶m.toc);
  3161.                                               if(strlen(param.toc)==0) param.toc=0;
  3162.                                         break;
  3163.  
  3164.                                         case GID_HELP:
  3165.                                               GetAttr(STRINGA_TextVal,gadgets[GID_HELP],(ULONG*)¶m.help);
  3166.                                               if(strlen(param.help)==0) param.help=0;
  3167.                                         break;
  3168.  
  3169.                                         case GID_FIND:
  3170.                                               GetAttr(STRINGA_TextVal,gadgets[GID_FIND],(ULONG*)¶m.find);
  3171.                                               if(strlen(param.find)==0) param.find=0;
  3172.                                         break;
  3173.  
  3174.                                         case GID_HOME:
  3175.                                               GetAttr(STRINGA_TextVal,gadgets[GID_HOME],(ULONG*)¶m.home);
  3176.                                               if(strlen(param.home)==0) param.home=0;
  3177.                                         break;
  3178.  
  3179.                                         case GID_BAR:
  3180.                                               GetAttr(STRINGA_TextVal,gadgets[GID_BAR],(ULONG*)¶m.bar);
  3181.                                         break;
  3182.  
  3183.                                         case GID_CONV:
  3184.                                             if(!param.from)
  3185.                                                 {
  3186.                                                     err("You must select an AmigaGuide\ndocument to convert!","OK",0);
  3187.                                                 }
  3188.                                                 else
  3189.                                                 {
  3190.                                                                 SetWindowPointer(windows[WID_MAIN],WA_BusyPointer,TRUE,TAG_DONE);
  3191.                                                     main();
  3192.                                                                   param.prev = textlabs.prev;
  3193.                                                                   param.next = textlabs.next;
  3194.                                                                   param.index = textlabs.index;
  3195.                                                                   param.toc = textlabs.toc;
  3196.                                                                   param.home = textlabs.home;
  3197.                                                                   param.help = textlabs.help;
  3198.                                                                   param.find = textlabs.find;
  3199.                                                                   param.retrace = textlabs.retrace;
  3200.                                                                   param.bar = textlabs.bar;
  3201.                                                                 SetWindowPointer(windows[WID_MAIN],TAG_DONE);
  3202.                                                 }
  3203.                                         break;
  3204.  
  3205.                                         case GID_WRAP:
  3206.  
  3207.                                                         switch(code)
  3208.                                                         {
  3209.                                                             case 0:
  3210.                                                                 param.noauto=0;
  3211.                                                                 param.wordwrap=0;
  3212.                                                                 param.smartwrap=0;
  3213.                                                                 SetAttrs(gadgets[GID_VARWIDTH],GA_Disabled,FALSE,TAG_DONE);
  3214.                                                                   RethinkLayout(gadgets[GID_VARWIDTH],windows[WID_MAIN],NULL,TRUE);
  3215.                                                             break;
  3216.  
  3217.                                                             case 1:
  3218.                                                                 param.wordwrap=TRUE;
  3219.                                                                 param.smartwrap=FALSE;
  3220.                                                                 param.noauto=TRUE;
  3221.                                                                 SetAttrs(gadgets[GID_VARWIDTH],GA_Disabled,FALSE,TAG_DONE);
  3222.                                                                   RethinkLayout(gadgets[GID_VARWIDTH],windows[WID_MAIN],NULL,TRUE);
  3223.                                                             break;
  3224.  
  3225.                                                             case 2:
  3226.                                                                 param.wordwrap=FALSE;
  3227.                                                                 param.smartwrap=TRUE;
  3228.                                                                 param.noauto=TRUE;
  3229.                                                                 SetAttrs(gadgets[GID_VARWIDTH],GA_Disabled,FALSE,TAG_DONE);
  3230.                                                                   RethinkLayout(gadgets[GID_VARWIDTH],windows[WID_MAIN],NULL,TRUE);
  3231.                                                             break;
  3232.  
  3233.                                                             case 3:
  3234.                                                                 param.wordwrap=FALSE;
  3235.                                                                 param.smartwrap=FALSE;
  3236.                                                                 param.noauto=TRUE;
  3237.                                                                 SetAttrs(gadgets[GID_VARWIDTH],GA_Disabled,TRUE,TAG_DONE);
  3238.                                                                   RethinkLayout(gadgets[GID_VARWIDTH],windows[WID_MAIN],NULL,TRUE);
  3239.                                                             break;
  3240.  
  3241.                                                         }
  3242.  
  3243.                                         break;
  3244.  
  3245.                                         case GID_VARWIDTH:
  3246.                                             param.varwidth=code;
  3247.                                         break;
  3248.  
  3249.                                         case GID_NAVBAR:
  3250.  
  3251.                                                         switch(code)
  3252.                                                         {
  3253.                                                             case 0:
  3254.                                                                 param.nonavbar=FALSE;
  3255.                                                                 param.footer=FALSE;
  3256.                                                                 SetAttrs(gadgets[GID_IMAGES],GA_Disabled,FALSE,TAG_DONE);
  3257.                                                                   RethinkLayout(gadgets[GID_IMAGES],windows[WID_MAIN],NULL,TRUE);
  3258.                                                             break;
  3259.  
  3260.                                                             case 1:
  3261.                                                                 param.nonavbar=FALSE;
  3262.                                                                 param.footer=TRUE;
  3263.                                                                 SetAttrs(gadgets[GID_IMAGES],GA_Disabled,FALSE,TAG_DONE);
  3264.                                                                   RethinkLayout(gadgets[GID_IMAGES],windows[WID_MAIN],NULL,TRUE);
  3265.                                                             break;
  3266.  
  3267.                                                             case 2:
  3268.                                                                 param.nonavbar=TRUE;
  3269.                                                                 param.footer=FALSE;
  3270.                                                                 SetAttrs(gadgets[GID_IMAGES],GA_Disabled,TRUE,TAG_DONE);
  3271.                                                                   RethinkLayout(gadgets[GID_IMAGES],windows[WID_MAIN],NULL,TRUE);
  3272.                                                             break;
  3273.                                                         }
  3274.  
  3275.                                         break;
  3276.  
  3277.                                         case GID_LINKS:
  3278.  
  3279.                                                         switch(code)
  3280.                                                         {
  3281.                                                             case 0:
  3282.                                                                 param.noemail=FALSE;
  3283.                                                                 param.nolink=FALSE;
  3284.                                                             break;
  3285.  
  3286.                                                             case 1:
  3287.                                                                 param.noemail=TRUE;
  3288.                                                                 param.nolink=FALSE;
  3289.                                                             break;
  3290.  
  3291.                                                             case 2:
  3292.                                                                 param.noemail=FALSE;
  3293.                                                                 param.nolink=TRUE;
  3294.                                                             break;
  3295.  
  3296.                                                             case 3:
  3297.                                                                 param.noemail=TRUE;
  3298.                                                                 param.nolink=TRUE;
  3299.                                                             break;
  3300.                                                         }
  3301.                                         break;
  3302.  
  3303.                                         case GID_IMAGES:
  3304.                                             param.images=code;
  3305.                                         break;
  3306.  
  3307.                                         case GID_MOZNAV:
  3308.                                             param.nomoznav=code+1;
  3309.                                         break;
  3310.  
  3311.                                         case GID_SHOWALL:
  3312.                                             param.showall=code;
  3313.                                         break;
  3314.  
  3315.                                         case GID_MSDOS:
  3316.                                             param.msdos=code;
  3317.                                         break;
  3318.  
  3319.                                     }
  3320.                                     break;
  3321.  
  3322.                                 case WMHI_ICONIFY:
  3323.                                     RA_Iconify(objects[OID_MAIN]);
  3324.                                     windows[WID_MAIN] = NULL;
  3325.                                     break;
  3326.  
  3327.                                 case WMHI_UNICONIFY:
  3328.                                     windows[WID_MAIN] = (struct Window *) RA_OpenWindow(objects[OID_MAIN]);
  3329.  
  3330.                                     if (windows[WID_MAIN])
  3331.                                     {
  3332.                                         GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  3333.                                     }
  3334.                                     else
  3335.                                     {
  3336.                                         done = TRUE;    // error re-opening window!
  3337.                                     }
  3338.                                      break;
  3339.                             }
  3340.                         }
  3341.                     }
  3342.                 }
  3343.             }
  3344.  
  3345.             /* Disposing of the window object will also close the window if it is
  3346.              * already opened, and it will dispose of the layout object attached to it.
  3347.              */
  3348.             DisposeObject(objects[OID_MAIN]);
  3349.         }
  3350.  
  3351.         DeleteMsgPort(AppPort);
  3352.     }
  3353. free_list(&optlist);
  3354. freetablist(&tablist);
  3355. FreeMenus(menustrip); // menu
  3356. cleanup(0);
  3357.  
  3358. /*
  3359.     closelibs();
  3360.  
  3361.     return(0);
  3362. */
  3363.  }
  3364.  
  3365.  
  3366. void free_list(struct List *list)
  3367. {
  3368.     struct Node *node,*nextnode;
  3369.     node = list ->lh_Head;
  3370.     while (nextnode = node->ln_Succ)
  3371.     {
  3372.         FreeChooserNode(node);
  3373.         node=nextnode;
  3374.     }
  3375.     NewList(list);
  3376. }
  3377.  
  3378. void freetablist(struct List *list)
  3379. {
  3380.     struct Node *node,*nextnode;
  3381.     node = list ->lh_Head;
  3382.     while (nextnode = node->ln_Succ)
  3383.     {
  3384.         FreeClickTabNode(node);
  3385.         node=nextnode;
  3386.     }
  3387.     NewList(list);
  3388. }
  3389.  
  3390. BOOL make_list(struct List *list, UBYTE **labels1)
  3391. {
  3392.     struct Node *node;
  3393.     WORD i = 0;
  3394.     int ro=FALSE;
  3395.  
  3396.     NewList(list);
  3397.  
  3398.     while (*labels1)
  3399.     {
  3400.  
  3401.         if (node = AllocChooserNode(
  3402.                             CNA_Text, *labels1,
  3403.                             CNA_ReadOnly, ro,
  3404.                         TAG_DONE))
  3405.         {
  3406.             AddTail(list, node);
  3407.         }
  3408.         else
  3409.             break;
  3410.  
  3411.         labels1++;
  3412.         i++;
  3413.         ro=FALSE;
  3414.     }
  3415.     return(TRUE);
  3416. }
  3417.  
  3418. BOOL maketablist(struct List *list, UBYTE **labels1)
  3419. {
  3420.     struct Node *node;
  3421.     WORD i = 0;
  3422.  
  3423.     NewList(list);
  3424.  
  3425.     while (*labels1)
  3426.     {
  3427.  
  3428.         if (node = AllocClickTabNode(
  3429.                             TNA_Text, *labels1,
  3430.                             TNA_Number, i,
  3431.                         TAG_DONE))
  3432.         {
  3433.             AddTail(list, node);
  3434.         }
  3435.         else
  3436.             break;
  3437.  
  3438.         labels1++;
  3439.         i++;
  3440.     }
  3441.     return(TRUE);
  3442. }
  3443.  
  3444. struct Menu *addmenu(struct Window *win)
  3445. {
  3446.  
  3447.  
  3448. APTR vi;
  3449.     struct Menu *menustrip;
  3450.     struct NewMenu menu[] = {
  3451.                                       {NM_TITLE,"Project"           , 0 ,0,0,0,},
  3452.                                       { NM_ITEM,"Save As..."        ,"S",0,0,0,},
  3453.                                       { NM_ITEM,NM_BARLABEL         , 0 ,0,0,0,},
  3454.                                       { NM_ITEM,"About..."          ,"A",0,0,0,},
  3455.                                       { NM_ITEM,NM_BARLABEL         , 0 ,0,0,0,},
  3456.                                       { NM_ITEM,"Quit"              ,"Q",0,0,0,},
  3457.                                       {NM_TITLE,"Settings"          , 0 ,0,0,0,},
  3458.                                       { NM_ITEM,"Save As Defaults"   ,"D",0,0,0,},
  3459.                                       {  NM_END,0,0,0,0,0,},
  3460.                                      };
  3461.  
  3462.     menustrip = CreateMenus(menu,GTMN_FullMenu,TRUE,TAG_DONE);
  3463.     vi = GetVisualInfoA(win->WScreen,TAG_DONE);
  3464.     LayoutMenus(menustrip,vi,GTMN_NewLookMenus,TRUE,TAG_DONE);
  3465. //                SetAttrs(win,WINDOW_MenuStrip,menustrip,TAG_DONE);
  3466.   SetMenuStrip(win,menustrip);
  3467.  
  3468. return(menustrip);
  3469. }
  3470.  
  3471.  int err(char *errtxt,char *gadgtxt,int fail)
  3472. {
  3473.     int rc;
  3474.  
  3475.     if(intuitionbase)
  3476.     {
  3477.         struct EasyStruct errorreq =
  3478.             {
  3479.             sizeof(struct EasyStruct),
  3480.             0,
  3481.             "GuideML",
  3482.             errtxt,
  3483.             gadgtxt
  3484.             };
  3485.         rc = EasyRequest(NULL,&errorreq,NULL);
  3486.     }
  3487.     else
  3488.     {
  3489.         printf("%s\n",*errtxt);
  3490.     }
  3491.     if (fail) cleanup(fail);
  3492.  
  3493.     return(rc);
  3494. }
  3495.  
  3496. void cleanup(int fail)
  3497. {
  3498.     if(ttfrom) FreeMem(ttfrom,strlen(ttfrom)+1);
  3499.     if(ttto) FreeMem(ttto,strlen(ttto)+1);
  3500.     if(tthomeurl) FreeMem(tthomeurl,strlen(tthomeurl)+1);
  3501.     if(ttfindurl) FreeMem(ttfindurl,strlen(ttfindurl)+1);
  3502.     if(ttprev) FreeMem(ttprev,strlen(ttprev)+1);
  3503.     if(ttnext) FreeMem(ttnext,strlen(ttnext)+1);
  3504.     if(ttindex) FreeMem(ttindex,strlen(ttindex)+1);
  3505.     if(tttoc) FreeMem(tttoc,strlen(tttoc)+1);
  3506.     if(tthelp) FreeMem(tthelp,strlen(tthelp)+1);
  3507.     if(ttretrace) FreeMem(ttretrace,strlen(ttretrace)+1);
  3508.     if(tthome) FreeMem(tthome,strlen(tthome)+1);
  3509.     if(ttfind) FreeMem(ttfind,strlen(ttfind)+1);
  3510.     if(ttbar) FreeMem(ttbar,strlen(ttbar)+1);
  3511.     if(ttbody) FreeMem(ttbody,strlen(ttbody)+1);
  3512.     if(tthtmlheadf) FreeMem(tthtmlheadf,strlen(tthtmlheadf)+1);
  3513.     if(tthtmlfootf) FreeMem(tthtmlfootf,strlen(tthtmlfootf)+1);
  3514.     if(ttcss) FreeMem(ttcss,strlen(ttcss)+1);
  3515.  
  3516.      if(WindowBase) CloseLibrary(WindowBase);
  3517.      if(LayoutBase) CloseLibrary(LayoutBase);
  3518.      if(ButtonBase) CloseLibrary(ButtonBase);
  3519.      if(CheckBoxBase) CloseLibrary(CheckBoxBase);
  3520.      if(LabelBase) CloseLibrary(LabelBase);
  3521.      if(ChooserBase) CloseLibrary(ChooserBase);
  3522.      if(ClickTabBase) CloseLibrary(ClickTabBase);
  3523. //     if(IntegerBase) CloseLibrary(IntegerBase);
  3524. //     if(ListBrowserBase) CloseLibrary(ListBrowserBase);
  3525.      if(GetFileBase) CloseLibrary(GetFileBase);
  3526.      if(StringBase) CloseLibrary(StringBase);
  3527.      if(GadToolsBase) CloseLibrary(GadToolsBase);
  3528.      if(IconBase) CloseLibrary(IconBase);
  3529.  
  3530.  if(aslbase) CloseLibrary(aslbase);
  3531.  if(DOSBase) CloseLibrary(DOSBase);
  3532.  if(intuitionbase) CloseLibrary(intuitionbase);
  3533.  
  3534.  
  3535.  exit(fail);
  3536.  }
  3537.