Beispiel #1
0
/*
** handle_hsc_error
**
** user error message
*/
BOOL handle_hsc_message( INFILE *inpf, HSCTAG *tag )
{
    STRPTR msg_text  = get_vartext_byname( tag->attr, "TEXT" );
    STRPTR msg_class = get_vartext_byname( tag->attr, "CLASS" );

    if ( msg_text ) {

        ULONG msgid = ( MSG_USER_MESSAGE & MASK_MESSAGE );

        /* compute message id */
        if ( !upstrcmp( msg_class, "WARNING" ) )
            msgid |= WARN;
        else if ( !upstrcmp( msg_class, "ERROR" ) )
            msgid |= ERROR;
        else if ( !upstrcmp( msg_class, "FATAL" ) )
            msgid |= FATAL;
        else D( if ( upstrcmp( msg_class, "NOTE" ) )
            panic( "illegal user message class" ); );

        /* display message */
        message( msgid, inpf );
        errstr( "user message: " );
        errstr( msg_text );
        errlf();

    }
Beispiel #2
0
/*
 * gettimestr
 */
static EXPSTR *gettimestr(HSCPRC * hp, const struct tm *time) {
#define TIMEBUF_INC 20
   STRPTR timefmt = get_vartext_byname(hp->defattr, TIMEFORMAT_ATTR);
   EXPSTR *timebuf = init_estr(TIMEBUF_INC);
   BOOL strftrc = 0;            /* result of strftime() */
   size_t i;                    /* loop var */

   /* set default time format */
   if (!timefmt)
      timefmt = "%d-%b-%Y, %H:%M";

   while (!(hp->fatal) && !strftrc) {
      /* expand timebuffer */
      for (i = 0; i < TIMEBUF_INC; i++)
         app_estrch(timebuf, '.');

      D(fprintf(stderr, DHL "    timebuf: inc+%d\n", TIMEBUF_INC));

      /* output time */
      strftrc = strftime(estr2str(timebuf), estrlen(timebuf),
            timefmt, time);
   }

   if (!strftrc) {
      del_estr(timebuf);
      timebuf = NULL;
   }

   return (timebuf);
}
Beispiel #3
0
/*
 * getfilesize
 *
 * get size of a specific file
 *
 * templates for HSC.FORMAT.FILESIZE:
 * %b   size in byte
 * %k   size in Kbyte
 * %m   size in MByte
 * %g   size in Gbyte
 * %a   size, unit computed automatically
 * %u   unit for %A (none, "K", "M" or "G")
 */
static STRPTR getfilesize(HSCPRC * hp, EXPSTR * dest, STRPTR uri)
{
   STRPTR filesizestr = NULL;
   FILE *file = NULL;
   LONG filesize = 0;           /* filesize in byte */
   LONG filesize_k = 0;         /* filesize in Kbyte */
   LONG filesize_m = 0;         /* filesize in Mbyte */
   LONG filesize_g = 0;         /* filesize in Gbyte */
   LONG filesize_auto = 0;      /* filesize in auto-units (%A) */
   EXPSTR *efilename = init_estr(32);
   STRPTR filename = NULL;
   STRPTR sizeunit = "";
   STRPTR s = get_vartext_byname(hp->defattr,
                                 FILESIZEFORMAT_ATTR);

   conv_hscuri2file(hp, efilename, uri);
   filename = estr2str(efilename);

   D(fprintf(stderr, DHL "  GETFILESIZE(`%s')\n", filename));
   errno = 0;
   file = fopen(filename, "rb");
   if (file)
   {
      /* retrieve size */
      fseek(file, 0L, SEEK_END);
      filesize = ftell(file);
      fclose(file);

      /* compute size in units, */
      filesize_k = (filesize + 512) >> 10;
      filesize_m = (filesize_k + 512) >> 10;
      filesize_g = (filesize_m + 512) >> 10;

      /* compute auto-size */
      if (filesize_g > 10)
      {
         filesize_auto = filesize_g;
         sizeunit = "G";
      }
      else if (filesize_m > 10)
      {
         filesize_auto = filesize_m;
         sizeunit = "M";
      }
      else if (filesize_k > 10)
      {
         filesize_auto = filesize_k;
         sizeunit = "K";
      }
      else
      {
         filesize_auto = filesize;
         sizeunit = "";
      }
   }
   else
   {
Beispiel #4
0
/*
 * handle_base: tag handle for <BASE>
 *
 * enable switch docbase_set; this affects "uri.c"
 * and from now on, all relative uris will be absolute
 */
BOOL handle_base(HSCPRC * hp, HSCTAG * tag)
{
    STRPTR href_arg = get_vartext_byname(tag->attr, "HREF");

    if (href_arg)
    {
        D(fprintf(stderr, DHL "BASE SET `%s'\n", href_arg));
        hp->docbase_set = TRUE;
    }

    return (TRUE);
}
Beispiel #5
0
/*
** handle_hsc_include
**
** include a sub file
*/
BOOL handle_hsc_include( INFILE *inpf, HSCTAG *tag )
{
    STRPTR  fname  = get_vartext_byname( tag->attr, "FILE" );
    BOOL    source = get_varbool_byname( tag->attr, "SOURCE" );
    BOOL    pre    = get_varbool_byname( tag->attr, "PRE" );
    ULONG   optn   = 0;

    if ( source )
        optn |= IH_PARSE_SOURCE;
    if ( pre )
        include_hsc_string( "[include <PRE>]", "<PRE>\n",
                            outfile, IH_PARSE_HSC | IH_NO_STATUS );
    if ( fname )
        include_hsc_file( fname, outfile, optn );
    if ( pre )
        include_hsc_string( "[include </PRE>]", "</PRE>\n",
                            outfile, IH_PARSE_HSC | IH_NO_STATUS );

    return ( FALSE );
}