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

  1. /*
  2.  * hsclib/message.c
  3.  *
  4.  * message functions for hsc
  5.  *
  6.  * Copyright (C) 1995,96  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: 25-Jan-1997
  23.  * created: 10-Mar-1996
  24.  *
  25.  * NOTE: see "hsclib/msgid.h" for message-id's and
  26.  *       how a message-id is build.
  27.  */
  28.  
  29. #define NOEXTERN_HSCLIB_MESSAGE_H
  30.  
  31. #include "hsclib/inc_base.h"
  32.  
  33. #include "ugly/returncd.h"
  34.  
  35. static VOID msg_tag(EXPSTR * msgstr, CONSTRPTR tagname)
  36. {
  37.     app_estr(msgstr, "tag <");
  38.     app_estr(msgstr, tagname);
  39.     app_estr(msgstr, ">");
  40. }
  41.  
  42. static VOID msg_endtag(EXPSTR * msgstr, CONSTRPTR tagname)
  43. {
  44.     app_estr(msgstr, "end tag </");
  45.     app_estr(msgstr, tagname);
  46.     app_estr(msgstr, ">");
  47. }
  48.  
  49. static VOID msg_attr(EXPSTR * msgstr, CONSTRPTR attrname)
  50. {
  51.     app_estr(msgstr, "attribute ");
  52.     app_estr(msgstr, attrname);
  53. }
  54.  
  55. static VOID msg_entity(EXPSTR * msgstr, CONSTRPTR entname)
  56. {
  57.     app_estr(msgstr, "entity `");
  58.     app_estr(msgstr, entname);
  59.     app_estr(msgstr, "'");
  60. }
  61.  
  62. static VOID msg_idname(EXPSTR * msgstr, CONSTRPTR idname)
  63. {
  64.     app_estr(msgstr, "id ");
  65.     app_estr(msgstr, "\"#");
  66.     app_estr(msgstr, idname);
  67.     app_estrch(msgstr, '"');
  68. }
  69.  
  70. /*
  71.  * hsc_message
  72.  *
  73.  * create message string and send it to call-back
  74.  *
  75.  * legal placeholders inside format:
  76.  *  %A ptr to HSCATTR
  77.  *  %a string for attribute-name
  78.  *  %d dezimal number (LONG)
  79.  *  %E ptr to HSCENT
  80.  *  %e string to entity-name
  81.  *  %i string to id-name
  82.  *  %q quoted string
  83.  *  %s string
  84.  *  %T ptr to HSCTAG
  85.  *  %t string for tag-name
  86.  *
  87.  * example:
  88.  * ---
  89.  *  HSCTAG *mytag;
  90.  *  STRPTR expected_tag = "dummy";
  91.  *
  92.  *  hsc_message( hp, MSG_my_tag_expected,
  93.  *               "Expected tag %T insted of %t",
  94.  *               mytag, expected_tag );
  95.  * ---
  96.  */
  97. VOID hsc_message(HSCPRC * hp, HSCMSG_ID msg_id, const char *format,...)
  98. {
  99.     HSCMSG_CLASS msg_class = hsc_get_msg_class(hp, msg_id);
  100.     INFILE *msg_inpf = NULL;
  101.     STRPTR msg_fname = "unknown";
  102.     ULONG msg_x = 0;
  103.     ULONG msg_y = 0;
  104.     BOOL disp_msg = TRUE;       /* flag, if message really */
  105.     /* should be displayed */
  106.     if (hp->fatal)
  107.     {
  108.  
  109.         /* oppress all messages after fatal errors */
  110.         disp_msg = FALSE;
  111.     }
  112.     else if (
  113.                 (hsc_get_msg_ignore(hp, msg_id))
  114.                 &&
  115.                 (hsc_get_msg_class(hp, msg_id) <= MSG_WARN)
  116.         )
  117.     {
  118.         /* oppress message if it is marked as ignored
  119.          * and it is no ERROR/FATAL message
  120.          */
  121.         D(fprintf(stderr, DHL "ignore msg#%ld: ignore enabled\n",
  122.                   msg_id & MASK_MESSAGE));
  123.         disp_msg = FALSE;
  124.     }
  125.     else if (((msg_class == MSG_NOTE) && (hp->msg_ignore_notes))
  126.              || ((msg_class == MSG_STYLE) && (hp->msg_ignore_style))
  127.              || ((msg_class == MSG_PORT) && (hp->msg_ignore_port))
  128.         )
  129.     {
  130.         /* oppress message if it's class is
  131.          * marked as to be ignored */
  132.         D(fprintf(stderr, DHL "ignore msg#%ld: ignore whole class\n",
  133.                   msg_id & MASK_MESSAGE));
  134.         disp_msg = FALSE;
  135.     }
  136.  
  137.     if (disp_msg)
  138.     {
  139.         va_list ap;
  140.  
  141.         /* increase message-counter */
  142.         hp->msg_count++;
  143.  
  144.         /* set fatal-flag, if this is a fatal message */
  145.         if (msg_id > MSG_FATAL)
  146.             hp->fatal = TRUE;
  147.  
  148.         /* clear message buffer */
  149.         clr_estr(hp->curr_msg);
  150.  
  151.         /* create message string */
  152.         va_start(ap, format);
  153.         while (format[0])
  154.         {
  155.             if (format[0] == '%')
  156.             {
  157.                 STRPTR s = NULL;
  158.                 HSCTAG *tag = NULL;
  159.                 HSCATTR *attr = NULL;
  160.                 HSCENT *ent = NULL;
  161.  
  162.                 format++;
  163.                 switch (format[0])
  164.                 {
  165.  
  166.                 case 'd':
  167.                     /*
  168.                      * append decimal number
  169.                      */
  170.                     app_estr(hp->curr_msg,
  171.                              long2str(va_arg(ap, LONG)));
  172.                     break;
  173.  
  174.                 case 'q':
  175.                     /*
  176.                      * append quoted string
  177.                      */
  178.                     s = va_arg(ap, STRPTR);
  179.  
  180.                     app_estrch(hp->curr_msg, '`');
  181.                     while (s[0])
  182.                     {
  183.                         switch (s[0])
  184.                         {
  185.  
  186.                         case '\n':
  187.                             app_estr(hp->curr_msg, "\\n");
  188.                             break;
  189.                         case '\"':
  190.                             app_estr(hp->curr_msg, "\\\"");
  191.                             break;
  192.                         default:
  193.                             if (s[0] < ' ')
  194.                             {
  195.                                 app_estrch(hp->curr_msg, '\\');
  196.                                 app_estr(hp->curr_msg,
  197.                                          long2str((LONG) s[0]));
  198.                                 app_estrch(hp->curr_msg, ';');
  199.                             }
  200.                             else
  201.                                 app_estrch(hp->curr_msg, s[0]);
  202.                         }
  203.                         s++;    /* process next char */
  204.                     }
  205.                     app_estrch(hp->curr_msg, '\'');
  206.  
  207.                     break;
  208.  
  209.                 case 's':
  210.                     /*
  211.                      * append simple string
  212.                      */
  213.                     app_estr(hp->curr_msg, va_arg(ap, STRPTR));
  214.                     break;
  215.  
  216.                 case 'T':
  217.                     /* append tag-pointer */
  218.                     tag = va_arg(ap, HSCTAG *);
  219.                     msg_tag(hp->curr_msg, tag->name);
  220.                     break;
  221.  
  222.                 case 't':
  223.                     /* append tag */
  224.                     msg_tag(hp->curr_msg, va_arg(ap, STRPTR));
  225.                     break;
  226.  
  227.                 case 'C':
  228.                     /* append end tag-pointer */
  229.                     tag = va_arg(ap, HSCTAG *);
  230.                     msg_endtag(hp->curr_msg, tag->name);
  231.                     break;
  232.  
  233.                 case 'c':
  234.                     /* append end tag */
  235.                     msg_endtag(hp->curr_msg, va_arg(ap, STRPTR));
  236.                     break;
  237.  
  238.                 case 'A':
  239.                     /* append attribute-pointer */
  240.                     attr = va_arg(ap, HSCATTR *);
  241.                     msg_attr(hp->curr_msg, attr->name);
  242.                     break;
  243.  
  244.                 case 'a':
  245.                     /* append attribute */
  246.                     msg_attr(hp->curr_msg, va_arg(ap, STRPTR));
  247.                     break;
  248.  
  249.                 case 'E':
  250.                     /* append entity-pointer */
  251.                     ent = va_arg(ap, HSCENT *);
  252.                     msg_entity(hp->curr_msg, ent->name);
  253.                     break;
  254.  
  255.                 case 'e':
  256.                     /* append entity */
  257.                     msg_entity(hp->curr_msg, va_arg(ap, STRPTR));
  258.                     break;
  259.  
  260.                 case 'i':
  261.                     /* append ID */
  262.                     msg_idname(hp->curr_msg, va_arg(ap, STRPTR));
  263.                     break;
  264.  
  265.                 case 'j':
  266.                     /* append jerk/prostitute */
  267.                     if (hp->prostitute)
  268.                         app_estr(hp->curr_msg, "prostitute");
  269.                     else
  270.                         app_estr(hp->curr_msg, "jerk");
  271.                     break;
  272.  
  273.                 default:
  274.                     /*
  275.                      * append unknown
  276.                      */
  277.                     app_estrch(hp->curr_msg, '%');
  278.                     if (format[0] && (format[0] != '%'))
  279.                     {
  280.                         app_estrch(hp->curr_msg, '%');
  281.                         format--;
  282.                     }
  283.                     break;
  284.                 }
  285.             }
  286.             else
  287.                 app_estrch(hp->curr_msg, format[0]);
  288.  
  289.             if (format[0])
  290.                 format++;
  291.         }
  292.         va_end(format);
  293.  
  294.         /* evaluate message position */
  295.         if (hp->inpf)
  296.         {
  297.             msg_inpf = hp->inpf;
  298.             msg_fname = infget_fname(msg_inpf);
  299.  
  300.             /* is parent file for position? */
  301.             if (!strncmp(msg_fname, PARENT_FILE_ID,
  302.                          strlen(PARENT_FILE_ID)))
  303.             {
  304.                 /* use position of first file on stack */
  305.                 msg_inpf = (INFILE *) dln_data(dll_first(hp->inpf_stack));
  306.                 msg_fname = infget_fname(msg_inpf);
  307.                 D(fprintf(stderr, DHL "msg from spec.file\n"));
  308.             }
  309.             msg_x = infget_wx(msg_inpf) + 1;
  310.             msg_y = infget_wy(msg_inpf) + 1;
  311.         }
  312.         else
  313.         {
  314.             msg_fname = NULL;
  315.             msg_x = 0;
  316.             msg_y = 0;
  317.         }
  318.  
  319.         /* send message via callback */
  320.         if (hp->CB_message)
  321.  
  322.             (*(hp->CB_message))
  323.                 (hp,
  324.                  msg_class,
  325.                  msg_id & MASK_MESSAGE,
  326.                  msg_fname, msg_x, msg_y,
  327.                  estr2str(hp->curr_msg)
  328.                 );
  329.  
  330.         /* process nested files */
  331.         if (hp->CB_message_ref)
  332.         {
  333.             DLNODE *nd = dll_first(hp->inpf_stack);
  334.  
  335.             while (nd)
  336.             {
  337.                 msg_inpf = dln_data(nd);
  338.                 msg_fname = infget_fname(msg_inpf);
  339.                 msg_x = infget_wx(msg_inpf) + 1;
  340.                 msg_y = infget_wy(msg_inpf) + 1;
  341.  
  342.                 (*(hp->CB_message_ref))
  343.                     (hp,
  344.                      msg_class,
  345.                      msg_id & MASK_MESSAGE,
  346.                      msg_fname, msg_x, msg_y,
  347.                      ""
  348.                     );
  349.  
  350.                 nd = dln_next(nd);
  351.             }
  352.         }
  353.     }
  354.     else
  355.     {
  356.         D(fprintf(stderr, DHL "suppressed msg#%ld\n", msg_id & MASK_MESSAGE));
  357.     }
  358. }
  359.  
  360. /*
  361.  *-------------------------------------
  362.  * often occurable errors & messages
  363.  *-------------------------------------
  364.  */
  365.  
  366. VOID hsc_msg_eof(HSCPRC * hp, STRPTR descr)
  367. {
  368.     STRPTR eoftxt = "unexpected end of file";
  369.  
  370.     if (descr)
  371.         hsc_message(hp, MSG_UNEX_EOF, "%s (%s)", eoftxt, descr);
  372.     else
  373.         hsc_message(hp, MSG_UNEX_EOF, "%s", eoftxt);
  374. }
  375.  
  376. VOID hsc_msg_illg_whtspc(HSCPRC * hp)
  377. {
  378.     hsc_message(hp, MSG_ILLG_WHTSPC, "illegal white space");
  379. }
  380.  
  381. VOID hsc_msg_stripped_tag(HSCPRC * hp, HSCTAG * tag, STRPTR why)
  382. {
  383.     if (why)
  384.         hsc_message(hp, MSG_TAG_STRIPPED,
  385.                     "stripped tag %T (%s)", tag, why);
  386.     else
  387.         hsc_message(hp, MSG_TAG_STRIPPED,
  388.                     "stripped tag %T", tag);
  389. }
  390.  
  391. VOID hsc_msg_unkn_attr(HSCPRC * hp, STRPTR attr)
  392. {
  393.     hsc_message(hp, MSG_UNKN_ATTR,
  394.                 "unknown %a", attr);
  395. }
  396.  
  397. #if 1                           /* TODO: get rid of this */
  398. VOID hsc_msg_eol(HSCPRC * hp)
  399. {
  400.     hsc_message(hp, MSG_UNEX_EOL,
  401.                 "unexpected end of line");
  402. }
  403. #endif
  404.  
  405. VOID hsc_msg_noinput(HSCPRC * hp, STRPTR filename)
  406. {
  407.     hsc_message(hp, MSG_NO_INPUT,
  408.                 "can not open %q for input: %s",
  409.                 filename, strerror(errno));
  410. }
  411.  
  412. VOID hsc_msg_nouri(HSCPRC * hp, STRPTR filename, STRPTR uriname, STRPTR note)
  413. {
  414.     if (note)
  415.     {
  416.         hsc_message(hp, MSG_NO_URIPATH,
  417.                     "file %q for URI %q not found (%s)",
  418.                     filename, uriname, note);
  419.     }
  420.     else
  421.     {
  422.         hsc_message(hp, MSG_NO_URIPATH,
  423.                     "file %q for URI %q not found",
  424.                     filename, uriname);
  425.     }
  426. }
  427.  
  428. /*
  429.  * show up enforcer hit
  430.  */
  431. VOID enforcerHit(VOID)
  432. {
  433.     fputs("WORD-WRITE to  00000000        data=0000       PC: 0325B854\n"
  434.           "USP:  034735C8 SR: 0004 SW: 0729  (U0)(-)(-)  TCB: 03349A28\n"
  435.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 00000074\n"
  436.           "\n"
  437.           "LONG-READ from AAAA4444                        PC: 0325B858\n"
  438.           "USP:  034735C8 SR: 0015 SW: 0749  (U0)(F)(-)  TCB: 03349A28\n"
  439.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 00000078\n"
  440.           "\n"
  441.           "BYTE-WRITE to  00000101        data=11         PC: 0325B862\n"
  442.           "USP:  034735C8 SR: 0010 SW: 0711  (U0)(F)(D)  TCB: 03349A28\n"
  443.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 00000082\n"
  444.           "\n"
  445.           "LONG-WRITE to  00000102        data=00000000   PC: 0325B86A\n"
  446.           "USP:  034735C8 SR: 0014 SW: 0709  (U0)(-)(D)  TCB: 03349A28\n"
  447.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 0000008A\n"
  448.           "\n"
  449.           "Alert !! Alert 35000000     TCB: 03349A28     USP: 034735C4\n"
  450.           "Data: 00000000 DDDD1111 DDDD2222 DDDD3333 0325B802 DDDD5555 DDDD6666 35000000\n"
  451.           "Addr: AAAA0000 AAAA1111 AAAA2222 AAAA3333 AAAA4444 0325B802 00200810 --------\n"
  452.           "Stck: 0325B878 00000000 00FA06D6 00010000 0334A40C 03F46630 00AC4C20 00000000\n",
  453.           stderr);
  454.     strcpy((STRPTR) hsc_message, "die for oil, sucker");        /* crash machine */
  455.     exit(RC_FAIL);              /* just for the case we are still there.. */
  456. }
  457.  
  458.