home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / text / hyper / hsc_source.lha / hsc / source / hsclib / linit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-21  |  17.3 KB  |  647 lines

  1. /*
  2.  * hsclib/linit.c
  3.  *
  4.  * functions to init & read preferences for a hsc-process
  5.  *
  6.  * Copyright (C) 1996  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated: 21-Jan-1997
  23.  * created: 19-Feb-1996
  24.  */
  25.  
  26. #include "hsclib/inc_base.h"
  27.  
  28. #include "hsclib/deftag.h"
  29. #include "hsclib/include.h"
  30. #include "hsclib/parse.h"
  31.  
  32. #include "hsclib/tag_a.h"
  33. #include "hsclib/tag_hsc.h"
  34. #include "hsclib/tag_if.h"
  35. #include "hsclib/tag_macr.h"
  36. #include "hsclib/tag_misc.h"
  37.  
  38. #include "ugly/fname.h"
  39.  
  40. #if DEBUG
  41. /*
  42.  * debugging print functions
  43.  */
  44. static VOID prt_ent(FILE * stream, APTR data)
  45. {
  46.     HSCENT *ent = (HSCENT *) data;
  47.  
  48.     if (ent)
  49.     {
  50.         fprintf(stream, " %s", ent->name);
  51.         if (ent->replace)
  52.             fprintf(stream, "=%s", ent->replace);
  53.         if (ent->numeric)
  54.             fprintf(stream, "=%ld", ent->numeric);
  55.     }
  56.     else
  57.         fprintf(stream, " <NULL>");
  58. }
  59.  
  60. static VOID prt_tag(FILE * stream, APTR data)
  61. {
  62.     if (data)
  63.     {
  64.         HSCTAG *tag = (HSCTAG *) data;
  65.         fprintf(stream, " <");
  66.         if (tag->option & HT_CLOSE)
  67.             fprintf(stream, "/");
  68.         if (tag->o_handle)
  69.             fprintf(stderr, "*");
  70.         fprintf(stream, "%s", tag->name);
  71.         if (tag->c_handle)
  72.             fprintf(stderr, "*");
  73.         if (tag->option & HT_REQUIRED)
  74.             fprintf(stream, "/r");
  75.         if (tag->option & HT_RECOMMENDED)
  76.             fprintf(stream, "/rcmd");
  77.         if (tag->option & HT_ONLYONCE)
  78.             fprintf(stream, "/1");
  79.         if (tag->option & HT_AUTOCLOSE)
  80.             fprintf(stream, "/sc");
  81.         if (tag->option & HT_SPECIAL)
  82.             fprintf(stream, "/a");
  83.         fprintf(stream, ">");
  84.     }
  85.     else
  86.         fprintf(stream, " <NULL>");
  87. }
  88. #endif
  89.  
  90. /* function to temporarily disable debuggin output */
  91. #if 1
  92. static BOOL dbg_old = FALSE;
  93.  
  94. #define dbg_disable(hp) {dbg_old = hp->debug; hp->debug=FALSE;}
  95. #define dbg_restore(hp) {hp->debug=dbg_old;}
  96.  
  97. #else
  98. #define dbg_disable(hp)
  99. #define dbg_restore(hp)
  100. #endif
  101.  
  102. /*
  103.  * find_prefs_fname
  104.  *
  105.  * find preferences file: first check, if it is located
  106.  * somewhere in the paths given via CONFIG_PATH (which
  107.  * is a system depandent symbol); if not, check if it
  108.  * is in the path described in the envvar HSCPREFS
  109.  *
  110.  * result: full path & filename of prefs or NULL if not found
  111.  */
  112. static STRPTR find_prefs_fname(HSCPRC * hp)
  113. {
  114.     STRPTR prefs_fname = NULL;
  115.     STRPTR paths[] =            /* paths to search for config file */
  116.     {"", "", CONFIG_PATH,
  117.      NULL, NULL};
  118.     STRPTR path = NULL;
  119.     UBYTE path_ctr = 0;
  120.     FILE *cfgf = NULL;          /* prefs file */
  121.     STRPTR hscenv = NULL;
  122.     EXPSTR *hscpathstr = init_estr(32);         /* buffer to read $HSCPATH */
  123.  
  124.     static STRARR cfgfn[300];   /* TODO: expstr; buffer to create
  125.                                  *   filename of config file */
  126.     /* setup path from envvar */
  127.     hscenv = getenv(ENV_HSCPATH);
  128.     if (hscenv)
  129.     {
  130. #if 1
  131.         if (link_envfname(hscpathstr, ENV_HSCPATH, NULL, NULL))
  132.         {
  133.             /* add hscenv to paths */
  134.             paths[1] = estr2str(hscpathstr);
  135.         }
  136. #else
  137.         /* copy envvar to own memory area */
  138.         hscenv = strclone(hscenv);
  139.  
  140.         /* strip linefeeds from hscenv */
  141.         while (strlen(hscenv) && (hscenv[strlen(hscenv)] == '\n'))
  142.             hscenv[strlen(hscenv)] = '\0';
  143.  
  144.         /* add hscenv to paths */
  145.         paths[1] = hscenv;
  146. #endif
  147.     }
  148.  
  149.     /* try to open any prefs-file */
  150.     do
  151.     {                           /* loop: */
  152.         path = paths[path_ctr]; /*   get next path */
  153.         if (path)
  154.         {                       /*   is it the last one? */
  155.             strcpy(cfgfn, path);        /*   N->generate filename */
  156.             strcat(cfgfn, CONFIG_FILE);
  157.  
  158.             DC(fprintf(stderr, DHL "try \"%s\"\n", cfgfn));
  159.  
  160.             cfgf = fopen(cfgfn, "r");   /*      try to open file */
  161.         }
  162.         path_ctr++;             /*   process next path */
  163.     }
  164.     while (path && (!cfgf));    /* until no path left or file opened */
  165.  
  166.     if (cfgf)
  167.     {
  168.         prefs_fname = cfgfn;
  169.         fclose(cfgf);
  170.     }
  171.  
  172.     del_estr(hscpathstr);
  173.  
  174.     return (prefs_fname);
  175. }
  176.  
  177. /*
  178.  * hsc_read_base_info
  179.  *
  180.  * try to open base-file and read where in memory
  181.  * information about defined tags/attributes/entities
  182.  * is located.
  183.  *
  184.  * result: dummy-hsc-process that only contains
  185.  *   the information read from base-file
  186.  *
  187.  * see "LoadHscPrefs/LoadHscPrefs.c"
  188.  */
  189. HSCPRC *hsc_read_base_info(VOID)
  190. {
  191.     HSCPRC *dummy_hp = NULL;
  192.  
  193. #ifdef HSCBASE_FILE
  194.  
  195.     FILE *inpf = fopen(HSCBASE_FILE, "r");
  196.     DLLIST *hp_deftag = NULL;
  197.     DLLIST *hp_defattr = NULL;
  198.     DLLIST *hp_defent = NULL;
  199.  
  200.     if (inpf)
  201.     {
  202.         STRARR s[32];
  203.         APTR p = NULL;
  204.  
  205.         while (fscanf(inpf, "%s %p\n", &(s[0]), &p) != EOF)
  206.         {
  207.             if (!strcmp("DEFTAG", s))
  208.             {
  209.                 hp_deftag = (DLLIST *) p;
  210.                 printf(DHL "deftag  %p\n", hp_deftag);
  211.             }
  212.             else if (!strcmp("DEFATTR", s))
  213.             {
  214.                 hp_defattr = (DLLIST *) p;
  215.                 printf(DHL "defattr %p\n", hp_defattr);
  216.             }
  217.             else if (!strcmp("DEFENT", s))
  218.             {
  219.                 hp_defent = (DLLIST *) p;
  220.                 printf(DHL "defent  %p\n", hp_defent);
  221.             }
  222.             else
  223.             {
  224.                 printf(DHL "%s %p (unknown)\n", s, p);
  225.             }
  226.         }
  227.     }
  228.  
  229.     fclose(inpf);
  230.  
  231.     if (hp_deftag && hp_defattr && hp_defent)
  232.     {
  233.         /* assign information to dummy-process */
  234.         dummy_hp = new_hscprc();
  235.  
  236.         del_dllist(dummy_hp->defattr);
  237.         del_dllist(dummy_hp->defent);
  238.         del_dllist(dummy_hp->deftag);
  239.  
  240.         dummy_hp->deftag = hp_deftag;
  241.         dummy_hp->defattr = hp_defattr;
  242.         dummy_hp->defent = hp_defent;
  243.  
  244.         /* assign new del_data-methodes */
  245.         dummy_hp->defattr->del_data = del_hscattr;
  246.         dummy_hp->defent->del_data = del_entity;
  247.         dummy_hp->deftag->del_data = del_hsctag;
  248.     }
  249.  
  250. #endif
  251.     return (dummy_hp);
  252. }
  253.  
  254. BOOL hsc_copy_base_info(HSCPRC * dest_hp, HSCPRC * dummy_hp)
  255. {
  256.     DLNODE *nd = dummy_hp->deftag->first;
  257.  
  258.     /* copy defined tags */
  259.     while (nd)
  260.     {
  261.         HSCTAG *newtag = cpy_hsctag((HSCTAG *) nd->data);
  262.         app_dlnode(dest_hp->deftag, (APTR) newtag);
  263.         nd = nd->next;
  264.     }
  265.  
  266.     return (TRUE);
  267. }
  268.  
  269. /*
  270.  * hsc_read_prefs
  271.  *
  272.  * try to open (any) config file and read preferences
  273.  * from it
  274.  */
  275. BOOL hsc_read_prefs(HSCPRC * hp, STRPTR prefs_fname)
  276. {
  277.     BOOL ok = FALSE;
  278.  
  279.     /* find prefs file */
  280.     if (!prefs_fname)
  281.         prefs_fname = find_prefs_fname(hp);
  282.  
  283.     /* status message */
  284.     if (prefs_fname)
  285.     {
  286.         dbg_disable(hp);
  287.  
  288.         hsc_status_file_begin(hp, prefs_fname);
  289.         ok = hsc_include_file(hp, prefs_fname,
  290.                               IH_PARSE_HSC | IH_NO_STATUS);
  291.         dbg_restore(hp);
  292.  
  293.         if (ok)
  294.         {
  295.             EXPSTR *msg = init_estr(32);
  296.             set_estr(msg, prefs_fname);
  297.             app_estr(msg, ": preferences read");
  298.             hsc_status_misc(hp, estr2str(msg));
  299.             del_estr(msg);
  300.         }
  301.     }
  302.     else
  303.     {
  304.         hsc_message(hp, MSG_NO_CONFIG,
  305.                     "can not open preferences file");
  306.     }
  307.  
  308.     return (ok);
  309. }
  310.  
  311. /*
  312.  * callback to display "project-file corrupt"-message
  313.  */
  314. static VOID msg_corrupt_pf(HSCPRJ * project, STRPTR reason)
  315. {
  316.     STRPTR prjtxt = "project-file corrupt";
  317.     HSCPRC *hp = (HSCPRC *) project->user_data;
  318.  
  319.     if (reason)
  320.         hsc_message(hp, MSG_CORRUPT_PRJFILE, "%s (%s)", prjtxt, reason);
  321.     else
  322.         hsc_message(hp, MSG_CORRUPT_PRJFILE, "%s", prjtxt);
  323. }
  324.  
  325. /*
  326.  * hsc_init_project
  327.  *
  328.  * read project-file
  329.  */
  330. BOOL hsc_init_project(HSCPRC * hp, STRPTR project_fname)
  331. {
  332.     BOOL ok = FALSE;
  333.  
  334.     /* init project */
  335.     hp->project = new_project();
  336.     hp->project->user_data = (APTR) hp;
  337.     hp->project->debug = hp->debug;
  338.     hp->project->CB_msg_corrupt_pf = msg_corrupt_pf;
  339.  
  340.     if (project_fname)
  341.     {
  342.         /*
  343.          * read project-data
  344.          */
  345.         D(fprintf(stderr, DHL "read project-file `%s'\n", project_fname));
  346.  
  347.         hsc_status_file_begin(hp, project_fname);
  348.  
  349.         /* read project-file */
  350.         hp->inpf = infopen(project_fname, 0);
  351.  
  352.         if (hp->inpf)
  353.         {
  354.             ok = hsc_project_read_file(hp->project, hp->inpf);
  355.             infclose(hp->inpf);
  356.             if (ok)
  357.             {
  358.                 /* message about success */
  359.                 EXPSTR *msg = init_estr(32);
  360.                 set_estr(msg, project_fname);
  361.                 app_estr(msg, ": project-file read");
  362.                 hsc_status_misc(hp, estr2str(msg));
  363.                 del_estr(msg);
  364.             }
  365.  
  366.             hp->inpf = NULL;
  367.         }
  368.         else
  369.         {
  370.             D(fprintf(stderr, DHL "  can't read project-file\n"));
  371.             ok = TRUE;
  372.             /* TODO: message "creating new one" */
  373.         }
  374.     }
  375.     else
  376.     {
  377.         D(fprintf(stderr, DHL "no project-file to load\n"));
  378.         ok = TRUE;
  379.     }
  380.  
  381.     if (ok)
  382.     {
  383.         /* dettach current document */
  384.         hsc_project_set_document(hp->project, hp->filename_document);
  385.     }
  386.  
  387.     return (ok);
  388. }
  389.  
  390. /*
  391.  * hsc_set_tagCB
  392.  */
  393. VOID hsc_set_tagCB(HSCPRC * hp, STRPTR name,
  394.                    BOOL(*op_hnd) (HSCPRC * inpf, HSCTAG * tag),
  395.                    BOOL(*cl_hnd) (HSCPRC * inpf, HSCTAG * tag))
  396. {
  397.     HSCTAG *tag = find_strtag(hp->deftag, name);
  398.  
  399.     if (tag && !(tag->option & HT_NOHANDLE))
  400.     {
  401.         /* set handles */
  402.         DC(fprintf(stderr, DHL "add handles for <%s> (%p,%p)\n",
  403.                    name, op_hnd, cl_hnd));
  404.         tag->o_handle = op_hnd;
  405.         tag->c_handle = cl_hnd;
  406.     }
  407. }
  408.  
  409. /*
  410.  * init_hsctags
  411.  *
  412.  * define hsc tags & attributes; assign tagCBs for them
  413.  *
  414.  * NOTE: this ones tricky, but a bit perverted somehow
  415.  */
  416. BOOL hsc_init_tagsNattr(HSCPRC * hp)
  417. {
  418. #define INCLUDE_ATTR " PRE:bool SOURCE:bool TEMPORARY:bool" \
  419.                      " INDENT:num TABSIZE:num=\"4\" "
  420.     BYTE i = 0;
  421.     BOOL ok = TRUE;
  422.     BOOL open_tag;
  423.     HSCTAG *tag;
  424.  
  425.     /* define hsc internal tags */
  426.     STRPTR hsc_prefs[] =
  427.     {
  428.     /* tags with special chars as name
  429.      *
  430.      * IMPORTANT: When adding new tags with names not starting with
  431.      *   HSC_TAGID, make sure to update `tag.c:is_hsc_tag()'
  432.      */
  433.         HSC_COMMENT_STR " /SKIPLF /SPECIAL>",
  434.         HSC_ONLYCOPY_STR " /SPECIAL>",
  435.         HSC_INSEXPR_STR " /SPECIAL>",
  436.     /* tags starting with HSC_TAGID */
  437.         HSC_DEFENT_STR " /SKIPLF NAME:string/r RPLC:string NUM:num>",
  438.         HSC_DEFICON_STR " /SKIPLF NAME:string/r>",
  439.         HSC_DEFINE_STR " /SKIPLF /SPECIAL>",
  440.         HSC_DEFTAG_STR " /SKIPLF /SPECIAL>",
  441.         HSC_ELSE_STR " /SKIPLF /MBI=\"" HSC_IF_STR "\">",
  442.         HSC_ELSEIF_STR " /SKIPLF /MBI=\"" HSC_IF_STR "\"" CONDITION_ATTR ":bool>",
  443.         HSC_MESSAGE_STR " /SKIPLF TEXT:string/r CLASS:enum(\"note|warning|error|fatal\")='note'>",
  444.         HSC_EXEC_STR " /SKIPLF COMMAND:string/r REMOVE:enum(\"on|off|auto\")=\"auto\" ATTRIBUTE:string INCLUDE:bool FILE:string " INCLUDE_ATTR ">",
  445.         HSC_EXPORT_STR " /SKIPLF FILE:string/r DATA:string/r APPEND:bool>",
  446.         HSC_IF_STR " /SKIPLF /CLOSE " CONDITION_ATTR ":bool>",
  447.         HSC_INSERT_STR " /OBSOLETE TEXT:string TIME:bool FORMAT:string>",
  448.         HSC_INCLUDE_STR " /SKIPLF FILE:string/r " INCLUDE_ATTR ">",
  449.         HSC_LET_STR " /SKIPLF /SPECIAL>",
  450.         HSC_MACRO_STR " /SKIPLF /SPECIAL>",
  451.         HSC_SOURCE_STR " /SKIPLF PRE:bool>",
  452.         NULL
  453.     };
  454.  
  455.     STRPTR hsc_attribs[] =
  456.     {
  457.     /*
  458.      * define hsc attributes
  459.      */
  460.         SYSTEM_ATTR ":string/c=\"" SYSTEM_ATTR_ID "\">",
  461.         ANCHOR_ATTR ":string=\"this is a feature, not a bug\">",
  462.         RESULT_ATTR ":num=\"0\">",
  463.         FILESIZEFORMAT_ATTR ":string=\"%a%u\">",
  464.         TIMEFORMAT_ATTR ":string=\"%d-%b-%Y, %H:%M\">",
  465.         LINEFEED_ATTR ":string>",
  466.         NULL};
  467.  
  468.     /* temporarily disable debugging output */
  469.     dbg_disable(hp);
  470.  
  471.     /* define hsc-tags */
  472.     i = 0;
  473.     while (!(hp->fatal) && hsc_prefs[i])
  474.     {
  475.         STRARR infname[20];
  476.  
  477.         sprintf(infname, SPECIAL_FILE_ID "init%3d", i);
  478.         hp->inpf = infopen_str(infname, hsc_prefs[i], 60);
  479.  
  480.         if (hp->inpf)
  481.         {
  482.             tag = def_tag_name(hp, &open_tag);
  483.             ok = (tag && def_tag_args(hp, tag));
  484.             infclose(hp->inpf);
  485.         }
  486.  
  487.         i++;
  488.     }
  489.  
  490.     /* init hsc-attributes */
  491.     i = 0;
  492.     while (!(hp->fatal) && hsc_attribs[i])
  493.     {
  494.         hp->inpf =
  495.             infopen_str(SPECIAL_FILE_ID "init attr", hsc_attribs[i], 60);
  496.  
  497.         if (hp->inpf)
  498.         {
  499.             handle_hsc_define(hp, NULL);
  500.             infclose(hp->inpf);
  501.             hp->inpf = NULL;
  502.         }
  503.  
  504.         i++;
  505.     }
  506.  
  507.     /* assign "\n" to linefeed-attribute */
  508.     set_vartext(find_varname(hp->defattr, LINEFEED_ATTR), "\n");
  509.  
  510.     /* assign tag-callbacks to hsc-tags */
  511.     if (ok)
  512.     {
  513.         hsc_set_tagCB(hp, HSC_COMMENT_STR, handle_hsc_comment, NULL);
  514.         hsc_set_tagCB(hp, HSC_DEFENT_STR, handle_hsc_defent, NULL);
  515.         hsc_set_tagCB(hp, HSC_DEFICON_STR, handle_hsc_deficon, NULL);
  516.         hsc_set_tagCB(hp, HSC_DEFINE_STR, handle_hsc_define, NULL);
  517.         hsc_set_tagCB(hp, HSC_DEFTAG_STR, handle_hsc_deftag, NULL);
  518.         hsc_set_tagCB(hp, HSC_ELSE_STR, handle_hsc_else, NULL);
  519.         hsc_set_tagCB(hp, HSC_ELSEIF_STR, handle_hsc_elseif, NULL);
  520.         hsc_set_tagCB(hp, HSC_EXEC_STR, handle_hsc_exec, NULL);
  521.         hsc_set_tagCB(hp, HSC_EXPORT_STR, handle_hsc_export, NULL);
  522.         hsc_set_tagCB(hp, HSC_IF_STR, handle_hsc_if, handle_hsc_cif);
  523.         hsc_set_tagCB(hp, HSC_INCLUDE_STR, handle_hsc_include, NULL);
  524.         hsc_set_tagCB(hp, HSC_INSERT_STR, handle_hsc_insert, NULL);
  525.         hsc_set_tagCB(hp, HSC_INSEXPR_STR, handle_hsc_insert_expression, NULL);
  526.         hsc_set_tagCB(hp, HSC_COMMENT_STR, handle_hsc_comment, NULL);
  527.         hsc_set_tagCB(hp, HSC_LET_STR, handle_hsc_let, NULL);
  528.         hsc_set_tagCB(hp, HSC_MACRO_STR, handle_hsc_macro, NULL);
  529.         hsc_set_tagCB(hp, HSC_MESSAGE_STR, handle_hsc_message, NULL);
  530.         hsc_set_tagCB(hp, HSC_ONLYCOPY_STR, handle_hsc_onlycopy, NULL);
  531.         hsc_set_tagCB(hp, HSC_SOURCE_STR, handle_hsc_source, NULL);
  532.     }
  533.  
  534.     /* restore debugging output */
  535.     dbg_restore(hp);
  536.  
  537.     return (ok);
  538. }
  539.  
  540. /*
  541.  * hsc_init_basicEntities
  542.  *
  543.  * create basic entities (&, >, <, ")
  544.  * (should be called BEFORE hsc_read_prefs())
  545.  */
  546. BOOL hsc_init_basicEntities(HSCPRC * hp)
  547. {
  548.     BOOL ok = TRUE;
  549.  
  550.     /* entities */
  551.     ok &= add_ent(hp->defent, "amp", NULL, 0);  /* & */
  552.     ok &= add_ent(hp->defent, "lt", NULL, 0);   /* < */
  553.     ok &= add_ent(hp->defent, "gt", NULL, 0);   /* > */
  554.     ok &= add_ent(hp->defent, "quot", NULL, 0);         /* q */
  555.  
  556.     return (ok);
  557. }
  558.  
  559. /*
  560.  * hsc_assign_tagCBs
  561.  *
  562.  * assign tag-callbacks to standard html-tags
  563.  * (MUST ONLY be called AFTER hsc_read_prefs())
  564.  */
  565. BOOL hsc_assign_tagCBs(HSCPRC * hp)
  566. {
  567.     hsc_set_tagCB(hp, "!", handle_sgml_comment, NULL);
  568.     hsc_set_tagCB(hp, "A", handle_anchor, handle_canchor);
  569.     hsc_set_tagCB(hp, "BASE", handle_base, NULL);
  570.     hsc_set_tagCB(hp, "BLINK", handle_blink, NULL);
  571.     hsc_set_tagCB(hp, "H1", handle_heading, NULL);
  572.     hsc_set_tagCB(hp, "H2", handle_heading, NULL);
  573.     hsc_set_tagCB(hp, "H3", handle_heading, NULL);
  574.     hsc_set_tagCB(hp, "H4", handle_heading, NULL);
  575.     hsc_set_tagCB(hp, "H5", handle_heading, NULL);
  576.     hsc_set_tagCB(hp, "H6", handle_heading, NULL);
  577.     hsc_set_tagCB(hp, "IMG", handle_img, NULL);
  578.     hsc_set_tagCB(hp, "PRE", handle_pre, handle_end_pre);
  579.  
  580.     return (TRUE);
  581. }
  582.  
  583. /*
  584.  * hsc_init_hscprc
  585.  *
  586.  * - init all items of hsc-process
  587.  * - create hsc-tags & special atttributes
  588.  * - read preferences file
  589.  * - assign tag-callbacks
  590.  */
  591. BOOL hsc_init_hscprc(HSCPRC * hp, STRPTR prefs_fname)
  592. {
  593.     BOOL ok = FALSE;            /* return value */
  594.  
  595.     if (hsc_init_tagsNattr(hp)
  596.         && hsc_init_basicEntities(hp)
  597.         && hsc_read_prefs(hp, prefs_fname)
  598.         && hsc_assign_tagCBs(hp)
  599.         )
  600.     {
  601.         /* return sucess */
  602.         ok = TRUE;
  603.  
  604.         /* printf list of defined tags & entities */
  605.         DC(
  606.               {
  607.               DLNODE * nd;
  608.               HSCENT * ent;
  609.  
  610.               nd = hp->defent->first;
  611.               if (nd)
  612.               {
  613.               fprintf(stderr, DHL "Known entities:");
  614.  
  615.               while (nd)
  616.               {
  617.               ent = (HSCENT *) nd->data;
  618.               fprintf(stderr, " &%s;", ent->name);
  619.               nd = nd->next;
  620.               }
  621.               fprintf(stderr, "\n");
  622.               }
  623.  
  624.               nd = hp->deftag->first;
  625.               if (nd)
  626.               {
  627.               fprintf(stderr, DHL "Known tags:");
  628.               while (nd)
  629.               {
  630.               prt_tag(stderr, nd->data);
  631.               nd = nd->next;
  632.               }
  633.               fprintf(stderr, "\n");
  634.               }
  635.  
  636.               }
  637.         );                      /* DC */
  638.     }
  639.  
  640.     hp->click_here_str =
  641.         get_vartext_byname(hp->defattr, CLICK_HERE_ATTR);
  642.     hp->color_names =
  643.         get_vartext_byname(hp->defattr, COLOR_NAMES_ATTR);
  644.  
  645.     return (ok);
  646. }
  647.