Esempio n. 1
0
/*
** handle_hsc_time
**
** insert current time
*/
BOOL handle_hsc_time( INFILE *inpf, HSCTAG *tag )
{
    STRPTR  timefmt = get_vartext( tag->attr, "FORMAT" );
    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 ( !fatal_error && !strftrc ) {

        /* expand timebuffer */
        for ( i=0; i<TIMEBUF_INC; i++ )
            if ( !app_estrch( timebuf, '.' ) )
                err_mem( inpf );

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

        /* output time */
        strftrc = strftime( estr2str( timebuf ), estrlen( timebuf ),
                            timefmt, localtime(&now) );

    }

    if ( strftrc )
        include_hsc_string( "[insert TIME]", estr2str( timebuf ),
                            outfile, IH_PARSE_HSC );

    del_estr( timebuf );

    return (TRUE);
}
Esempio n. 2
0
void CreateLCObjects()
{
	int n;
	int obj;
	char c;

	for(obj=1; obj<=app_num_objects; obj++)
	{
		Print("+ Encoding Object #%-2d:   ",obj);

		n=create_lc_object(obj);
		if(n!=0)
		{
			Print("Error!     \n");
			if(n==-1) err_seek(tempname1);
			if(n==-2) err_read(tempname1);
			if(n==-3) err_mem();
			if(n==-4) err_write(tempname2);
			if(n==-5) err_lcobjhdr(tempname1);
		}

		c = app_obj_seekattr[obj] ? '*':' ';

		if(!quiet)
		{
			printf("[û]  ");
			if(!verbose) printf("(%1.1f%%)\n", ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100);
			else
			{	  		 printf("Old=%7d,   New=%7d,   (%1.1f%%)  (%s)%c\n", obj_old_size,obj_new_size, ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100, encodetype[app_enc_status], c);
			if(verbxtra) printf("                               ** %s **,   ** %s **,   %7d - fixups\n", app_obj_iscode ? "CODE":"DATA", app_obj_is32bit ? "32bit":"16bit", app_obj_seekattr[obj]);
			}
		}
	}
}
Esempio n. 3
0
/*
**-------------------------------------
** <$LET> set a new global attribute
**        or overwrite a defined one
**-------------------------------------
*/
BOOL handle_hsc_let( INFILE *inpf, HSCTAG *tag )
{
    STRPTR varname = infgetw( inpf );
    BOOL   ok = FALSE;

    /* create copy of varname */
    if ( varname )
        varname = strclone( varname );
    else
        err_eof( inpf, "missing attribute name" );

    if ( varname ) {

        ok = parse_wd( inpf, ":" );
        if ( ok && define_var( varname, vars, inpf, 0 ) )
            ok = TRUE;
        if ( ok )
            ok = parse_gt( inpf );
    } else
        err_mem( inpf );

    /* release mem */
    ufreestr( varname );

    /* if error occured, skip rest of tag */
    if ( !ok )
        skip_until_eot( inpf );

    return ( ok );
}
Esempio n. 4
0
/*
** set_vartext
**
** set value of a var
**
** params: var......var to set
**         newtext..new text to set
** result: value of new text set
** errors: return NULL if out of mem, display error message
*/
STRPTR set_vartext( HSCVAR *var, STRPTR newtext )
{
    ufreestr( var->text );
    if ( newtext ) {

        var->text = strclone( newtext );
        if ( !var->text )
            err_mem( NULL );

    }

    return (var->text);
}
Esempio n. 5
0
/*
** check_enumstr: check if a given value is a legal enum value
*/
BOOL check_enumstr( HSCVAR *var, STRPTR value, INFILE *inpf )
{
    STRPTR enumcp = strclone( var->enumstr ); /* clone of enumstr */
    BOOL   found  = FALSE; /* flag: TRUE, if value found within enumstr */
    BOOL   any    = FALSE; /* flag: TRUE, if "*" was within enumstr */

    if ( enumcp ) {

        STRPTR word = strtok( enumcp, "|" );

        /* search for value in enumcp */
        while ( word && !found ) {

            if ( !strcmp( word, "*" ) )
                any = TRUE;
            if ( !upstrcmp( word, value ) )
                found = TRUE;
            word = strtok( NULL, "|" );

        }
        ufreestr( enumcp );

        /* check result, display messages if neccessary */
        if ( !found ) {

            if ( !any ) {

                /* unknown enum value */
                message( MSG_ENUM_UNKN, inpf );
                errstr( "unknown" );

            } else {

                /* suspicious enum value */
                message( MSG_ENUM_SUSPICIOUS, inpf );
                errstr( "suspicious" );

            }
            errstr( " value " );
            errqstr( value );
            errstr( " for" );
            errsym( var->name );
            errlf();

        } else DDA( fprintf( stderr, "**   enum \"%s\" ok for %s\n",
                             value, var->name ) );
    } else
        err_mem( inpf );

    return( found );
}
Esempio n. 6
0
/* is_pop: remove first value of the if-stack */
BOOL is_pop( VOID )
{
    BOOL value = is_get();

    if ( !strlen(estr2str(IF_stack)) )
        DIF( panic( "Popping empty IF_stack" ) );

    if ( !get_left_estr( IF_stack, IF_stack, strlen(estr2str(IF_stack))-1 ) )
        err_mem( NULL );

    DIF( fprintf( stderr, "** pop  IF-stack: \"%s\"\n", estr2str( IF_stack ) ) );

    return( value );
}
Esempio n. 7
0
/* is_push: add a new value to the if-stack */
VOID is_push( BOOL value )
{
    BYTE ch;

    if ( value ) ch = ISTK_TRUE;
    else         ch = ISTK_FALSE;

    if ( !app_estrch( IF_stack, ch ) )
        err_mem( NULL );

    DIF( fprintf( stderr, "** push IF-stack: \"%s\"\n", estr2str( IF_stack ) ) );


}
Esempio n. 8
0
/*
** read_enum_str
**
** sidefx: modifies tmpstr
*/
BOOL read_enum_str( HSCVAR *var, INFILE *inpf )
{
    BOOL ok;
    int  ch;

    ok = parse_wd( inpf, "(" );        /* check for "(" */
    ok &= clr_estr( tmpstr );          /* reset string */

    ch = infgetc( inpf );
    while ( ok && (ch!=')') && (ch!=EOF) && (ch!=CH_LF) ) {

        if ( (ch!=')') && (ch!=' ') )
            ok &= app_estrch( tmpstr, ch );
        ch = infgetc( inpf );

    }; 

    /* check result */
    if ( !ok )
        err_mem( inpf );
    else if ( ch == EOF )
        err_eof( inpf, "reading enumerator" );
    else if ( ch ==CH_LF )
        err_eol( inpf );

    /* store enumstr in var-struct */
    if ( ok ) {

        DDA( fprintf( stderr, "**   enum: %s\n", estr2str( tmpstr ) ) );
        var->enumstr = strclone( estr2str( tmpstr ) );
        if ( !(var->enumstr) )
            err_mem( inpf );
    }


    return( (BOOL)(!fatal_error) );
}
Esempio n. 9
0
/*
** app_tag
**
** create a new tag and append it to tag-list
**
** params: tagid..name of the new tag (eg "IMG")
** result: ptr to the new tag or NULL if no mem
*/
HSCTAG *app_tag( DLLIST *taglist, STRPTR tagid )
{
    HSCTAG *newtag;

    newtag = new_hsctag( tagid );
    if ( newtag ) {
        if (app_dlnode( taglist, newtag ) == NULL ) {

            del_tag( (APTR) newtag );
            newtag = NULL;

        }
    } else
        err_mem( NULL );

    return (newtag);
}
Esempio n. 10
0
/*
** copy_local_var
**
** copies a local attribute to the global attribute list
**
** NOTE: the VF_MACRO-flag of the copy is enabled!
*/
HSCVAR *copy_local_var( DLLIST *destlist, HSCVAR *locvar, ULONG mci )
{
    HSCVAR *var = app_var( destlist, locvar->name );

    if ( var ) {

        var->macro_id = mci;
        var->vartype = locvar->vartype;
        var->varflag = locvar->varflag & (~VF_MACRO) ; /* disable VF_MACRO */
        set_vartext( var, locvar->text );
        var->quote = locvar->quote;

    } else
        err_mem( NULL );

    return( var );
}
Esempio n. 11
0
/*
** handle_hsc_exec
**
** exec a sub file
*/
BOOL handle_hsc_exec( INFILE *inpf, HSCTAG *tag )
{
    STRPTR cmd = get_vartext( tag->attr, "COMMAND" );

    if ( cmd ) {

        int     result;
        EXPSTR *msg = init_estr( 0 );

        if ( msg
             && app_estr( msg, "execute: " )
             && app_estr( msg, cmd ) )
        {

            /* status message */
            status_msg( estr2str( msg ) );
            if ( verbose )
                status_lf();

            /* call command */
            result = system( cmd );

            /* check for non-zero-result */
            if ( result ) {

                 message( MSG_SYSTEM_RETURN, inpf );
                 errstr( "Calling external command returned " );
                 errstr( long2str( (LONG) result ) );
                 errlf();

            }

        } else
            err_mem( inpf );

        del_estr( msg );

    }

    return (TRUE);
}
Esempio n. 12
0
void CreateLCFixups()
{
	int n;

	Print("+ Encoding LC Fixups :   ");
	n=create_lc_fixups();
	if(n!=0)
	{
		Print("Error!\n");
		if(n==-1) err_seek(tempname1);
		if(n==-2) err_read(tempname1);
		if(n==-3) err_mem();
		if(n==-4) err_write(tempname2);
	}

	if(quiet!=TRUE)
	{
		printf("[û]  ");
		if(!verbose) printf("(%1.1f%%)\n", ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100);
		else	     printf("Old=%7d,   New=%7d,   (%1.1f%%)  (%s)\n", obj_old_size,obj_new_size, ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100, encodetype[app_enc_status]);
	}
}
Esempio n. 13
0
/*
**-------------------------------------
** <$SOURCE> include a source part
**-------------------------------------
*/
BOOL handle_hsc_source( INFILE *inpf, HSCTAG *tag )
{
    BOOL    pre     = get_varbool( tag->attr, "PRE" );
    BOOL    ok      = TRUE;
    EXPSTR *bufstr = NULL;
    EXPSTR *srcstr  = NULL;
    LONG    nesting = 0;
    BYTE    state   = SRST_TEXT;
    STRPTR  nw      = NULL;

    /*
    ** read until </$SOURCE> found
    */

    /* init bufstr */
    bufstr = init_estr( ES_STEP_SOURCE );
    srcstr  = init_estr( ES_STEP_SOURCE );

    if ( !(bufstr && srcstr ) )
        err_mem( inpf );

    while ( !(fatal_error || (state==SRST_CSOURCE) ) ) {

        /* read next word */
        if ( state == SRST_SLASH )
            nw = infget_tagid( inpf  );
        else if ( state != SRST_TAG )
            nw = infgetw( inpf  );

        if ( nw ) {

            if ( state == SRST_TAG ) {

                /*
                ** skip inside tags
                */
                BYTE   tag_state = TGST_TAG; /* state var passe to */
                                             /*     eot_reached() */

                do {

                    if ( eot_reached( inpf, &tag_state ) );
                        state = SRST_TEXT;

                    if ( !( app_estr( srcstr, infgetcws( inpf ) )
                            && app_estr( srcstr, infgetcw( inpf ) )
                    ) )
                        err_mem( inpf );

                } while ( (tag_state!=TGST_END) && !fatal_error );

            } else {

                switch ( state ) {

                    case SRST_TEXT:
                        if ( !strcmp( nw, "<" ) )
                            state = SRST_LT;
                        break;

                    case SRST_LT:
                        if ( !strcmp( nw, "/" ) )
                            state = SRST_SLASH;
                        else if ( !upstrcmp( nw, HSC_COMMENT_STR ) ) {

                            state = SRST_COMT;

                        } else {

                            /* handle "<$SOURCE" (open source) */
                            if ( !upstrcmp( nw, HSC_SOURCE_STR ) )
                                nesting++; /* incr. source nesting */
                            state = SRST_TAG;

                        }
                        break;

                    case SRST_SLASH:
                        if ( !upstrcmp( nw, HSC_SOURCE_STR ) )

                            /* handle "</$SOURCE" (close source) */
                            if ( nesting )
                                nesting--;   /* decr. source nesting */
                            else
                                state = SRST_CSOURCE; /* end of source */
                        else
                            state = SRST_TAG;
                        break;

                }

                if ( state == SRST_TEXT ) {

                    /* append current white spaces & word to srcstr */
                    if ( !( app_estr( srcstr, infgetcws( inpf ) )
                            && app_estr( srcstr, infgetcw( inpf ) )
                    ) )
                        err_mem( inpf );

                } else if ( ( state == SRST_COMT )
                            || ( state == SRST_TAG ) )
                {

                    /* append bufstr to srcstr, clear bufstr,
                    ** append current word to srcstr
                    */
                    if ( !( app_estr( srcstr, estr2str(bufstr) )
                            && set_estr( bufstr, "" )
                            && app_estr( srcstr, infgetcws( inpf ) )
                            && app_estr( srcstr, infgetcw( inpf ) )
                    ) )
                        err_mem( inpf );

                } else {

                    /* append current white spaces & word to srcstr */
                    if ( !( app_estr( bufstr, infgetcws( inpf ) )
                            && app_estr( bufstr, infgetcw( inpf ) )
                    ) )
                        err_mem( inpf );

                }

                /*
                ** skip hsc comment
                */
                if ( state == SRST_COMT ) {

                    BYTE cstate = CMST_TEXT; /* vars for eoc_reached() */
                    LONG cnest  = 0;
                    BOOL end    = FALSE;     /* end of comment reached? */

                    while ( !end && !fatal_error ) {

                        end = eoc_reached( inpf, &cstate, &cnest );
                        if ( !( app_estr( srcstr, infgetcws( inpf ) )
                                && app_estr( srcstr, infgetcw( inpf ) )
                        ) )
                            err_mem( inpf );

                    }

                    state = SRST_TEXT; /* reset state after comment */
                }
            }
        } else {

            err_eof( inpf, "missing </" HSC_SOURCE_STR ">" );
            state = SRST_ERR;

        }

    } /* while */

    /* check for legal end state */
    if ( state == SRST_CSOURCE ) {

        ok = parse_wd( inpf, ">" );

    }

    /* include source */
    if ( ok ) {

        if ( pre )
            include_hsc_string( "[include <PRE>]", "<PRE>\n",
                                outfile, IH_PARSE_HSC );
        include_hsc_string( "[SOURCE]", estr2str( srcstr ),
                                outfile, IH_PARSE_SOURCE );
        if ( pre )
            include_hsc_string( "[include </PRE>]", "</PRE>\n",
                                outfile, IH_PARSE_HSC );


    }

    del_estr( bufstr );
    del_estr( srcstr );

    return ( ok );
}
Esempio n. 14
0
/*
** parse_tag
**
** parse tag (after "<")
*/
BOOL parse_tag( INFILE *inpf)
{
    if ( !fatal_error ) {

        STRPTR  nxtwd;
        DLNODE *nd;

        /* write white space (if any) */
        outstr( infgetcws( inpf ) );

        strcpy( this_tag, infgetcw( inpf ) );

        /* get tag id */
        nxtwd = infgetw( inpf );                 /* get tag id */

        /* remember tag id (used by some handlers, which have */
        /* HT_NOCOPY set, but need to write tagid (eg <A>) */
        strcat( this_tag, infgetcws( inpf ) );
        strcat( this_tag, infgetcw( inpf ) );
        this_tag_data = NULL;

        if ( debug )                         /* debug msg */
            fprintf( stderr, "** tag ", this_tag );

        if ( strcmp( "/", nxtwd ) ) {            /* is it a closing tag? */

            /*
            **
            ** process non-closing tag
            **
            */

            if ( debug )                         /* debug msg */
                fprintf( stderr, "%s>\n", this_tag );

            /* search for tag in list */
            nd = find_dlnode( deftag->first, (APTR) nxtwd, cmp_strtag );
            if ( nd == NULL ) {

                message( WARN_UNKN_TAG, inpf );      /* tag not found */
                errstr( "Unknown tag " );
                errtag( nxtwd );
                errlf();

                outstr( this_tag );                  /* copy whole tag */
                copy_until_gt( inpf );

            } else {

                HSCTAG *tag = (HSCTAG*)nd->data;
                BOOL   (*hnd)(INFILE *inpf) = tag->o_handle;

                /* set global pointer to tag */
                this_tag_data = tag;

                /*
                ** handle options
                */

                /* only-once-tag occured twice? */
                if ( (tag->option & HT_ONLYONCE ) && (tag->occured) ) {

                    message( ERROR_TOO_OFTEN, inpf );
                    errstr( "tag " );
                    errtag( nxtwd );
                    errstr( "occured too often\n" );

                }

                /* set occured-flag */
                if ( tag->option & (HT_ONLYONCE | HT_REQUIRED) )
                    tag->occured = TRUE;

                /* closing tag required? */
                if ( tag->option & HT_CLOSE ) {
                    /* TODO: handle out of mem */
                    if ( !app_dlnode( cltags, (APTR) tag->name ) )
                        err_mem( inpf );
                }

                /* write out tag? */
                if ( !(tag->option & HT_NOCOPY) )
                    outstr( this_tag );                        /* write out tag */

                /*
                ** call handle if available
                */
                if ( hnd && !fatal_error)
                    (*hnd)( inpf );                            /* call handle */

                /*
                ** copy rest of tag if HT_COPY-bit not set
                */
                if ( !(tag->option & HT_NOCOPY) )              /* write out '>' */
                    copy_until_gt( inpf );

            }

        } else {

            /*
            **
            ** process closing tag
            **
            */

            /* TODO: handle </HR> */
            /* TODO: check why ^ this TODO is here?! */

            /* get tag id */
            nxtwd = infgetw( inpf );           /* get tag id */

            /* remember tag id */
            strcat( this_tag, infgetcws( inpf ) );
            strcat( this_tag, infgetcw( inpf ) );

            if ( debug )                         /* debug msg */
                fprintf( stderr, "%s>\n", this_tag );

            /* search for tag in deftag list */
            /* (see if it exists at all) */
            nd = find_dlnode( deftag->first, (APTR) nxtwd, cmp_strtag );
            if ( nd == NULL ) {

                /* closing tag is absolutely unknown */
                message( WARN_UNKN_TAG, inpf );      /* tag not found */
                errstr( "Unknown closing tag " );
                errctag( nxtwd );
                errlf();

                outstr( this_tag );                  /* copy whole tag */
                copy_until_gt( inpf );

            } else {

                HSCTAG *tag = (HSCTAG*)nd->data; /* fitting tag in deftag-list */
                BOOL   (*hnd)(INFILE *inpf) = tag->c_handle; /* closing handle */

                /* set global pointer to tag */
                this_tag_data = tag;

                /* search for tag on stack of occured tags */
                nd = find_dlnode( cltags->first, (APTR) nxtwd, cmp_strctg );
                if ( nd == NULL ) {

                    /* closing tag not found on stack */
                    /* ->unmatched closing tag without previous opening tag */
                    message( WARN_UNMA_CTAG, inpf );
                    errstr( "Unmatched closing tag " );
                    errctag( nxtwd );
                    errlf();

                } else {

                    /* closing tag found on stack */
                    STRPTR foundnm = (STRPTR) nd->data;
                    STRPTR lastnm  = (STRPTR) cltags->last->data;

                    /* check if name of closing tag is -not- equal
                    /* to the name of the last tag last on stack */
                    /* ->illegal tag nesting */
                    if ( upstrcmp(lastnm, foundnm)
                         && !(tag->option | HT_MACRO) )
                    {

                        message( WARN_NEST_TAG, inpf );
                        errstr( "Illegal closing tag nesting (expected " );
                        errctag( lastnm );
                        errstr( ", found " );
                        errctag( nxtwd );
                        errch( ')' );
                        errlf();

                    }

                    /* call closing handle if available */
                    if ( hnd )
                        (*hnd)( inpf );
                }

                /* write out whole closing tag */
                if ( !(tag->option & HT_NOCOPY) ) {

                    outstr( this_tag );
                    copy_until_gt( inpf );

                }

                /* remove node for closing tag from cltags-list */
                del_dlnode( cltags, nd );
            }
        }
    }

    return (BOOL)( !fatal_error );
}
Esempio n. 15
0
/*
** define_var
**
** define a new var with reading its def from input file
** (starts parsing after ":", so ":" has to be read before)
**
** params: varname..name of new var
**         varlist..list new var should be inserted at the beginning
**         inpf.....input file where to read def from
**         flag.....flags: VF_ONLYONCE to avoid re-definition of a var
** result: ptr to new var
**
** definition syntax in input file:
**   <vartype>[/flag]["="<deftext value>]
**   legal vartypes: see VT_STR_xx in "vars.h"
**   legal flags   : see VF_STR_xx in "vars.h"
*/
HSCVAR *define_var( STRPTR varname, DLLIST *varlist, INFILE *inpf, UBYTE flag )
{
    HSCVAR *var        = NULL;                   /* result */
    BOOL    ok         = FALSE;
    STRPTR str_vartype = infgetw( inpf );        /* var-type (string) */
    BYTE   val_vartype = VT_NONE;                /* var-type (numeric) */

    /* evaluate var type */
    if ( str_vartype )
        val_vartype = str2vartype( str_vartype );
    else
        err_eof( inpf, "defining attribute" );

    if ( val_vartype == VT_NONE ) {

        /* illegal var type */
        message( MSG_ILLEGAL_SYMB_TYPE, inpf );
        errstr( "Illegal variable type \"" );
        errstr( str_vartype );
        errstr( "\"\n" );

    } else {

        /* look if var already exist, */
        /* create new var if neccessary */
        var = find_varname( varlist, varname );
        if ( !var ) {

            DDA( fprintf( stderr, "** new var: %s\n", varname ) );
            var = app_var( varlist, varname );

        }

        if ( !var )
            err_mem( inpf );
        else {

            STRPTR nw;                 /* next word from input file */

            /* set vartype */
            var->vartype = val_vartype;

            /* init enum-attribute */
            if ( var->vartype == VT_ENUM ) {

                var->varflag |= VF_NOQUOTE;
                read_enum_str( var, inpf );

            }

            /* get next word */
            nw = infgetw( inpf );
            if ( !nw )
                err_eof( inpf, "defining attribute" );

            /*
            ** loop: handle flags and deftext value
            */
            while ( nw ) {

                if ( !strcmp( nw, "=" ) ) {

                    /* get new deftext value */
                    STRPTR new_deftext;

                    if ( !(var->deftext) )
                        new_deftext = parse_vararg( var, inpf );
                    else {

                        message( MSG_SYMB_2ND_DEFAULT, inpf  );
                        errstr( "Default value for" );
                        errsym( var->name );
                        errstr( "already set\n" );

                    }

                    /* store default text value */
                    if ( new_deftext )
                        var->deftext = strclone( new_deftext );

                    /* check deftext value */
                    if ( var->deftext && clr_vartext( var ) ) {

                        if ( var->vartype == VT_BOOL ) {

                            /* check boolean value */
                            message( MSG_SYMB_BOOL_DEFAULT, inpf );
                            errstr( "No default value for boolean" );
                            errsym( var->name );
                            errstr( "allowed\n" );

                        } else if ( var->vartype == VT_NUM ) {

                            /* check numeric value */
                            LONG num;

                            if ( sscanf( var->text, "%d", &num ) != strlen(var->text) ) {

                                ok = FALSE;
                                message( MSG_ILLEGAL_NUM, inpf );
                                errstr( "Illegal numeric value: " );
                                errstr( var->text );
                                errlf();

                            }
                        }
                    } else
                        err_mem( inpf );

                    /* clear boolean var */
                    if ( var->vartype == VT_BOOL ) {

                        var->quote = VQ_NO_QUOTE;
                        var->deftext = strclone( "" );
                        if ( !var->deftext )
                            err_mem( inpf );

                    }

                } else if ( !strcmp( nw, "/" ) ) {

                    /* set flag */
                    nw = infgetw( inpf );
                    if ( nw ) {

                        BOOL ok = FALSE;

                        ok |= check_attr_option( nw, var,
                                  VF_JERK_STR, VF_JERK_SHT, VF_JERK );
                        ok |= check_attr_option( nw, var,
                                  VF_NOQUOTE_STR, VF_NOQUOTE_SHT, VF_NOQUOTE );
                        ok |= check_attr_option( nw, var,
                                  VF_ONLYONCE_STR, VF_ONLYONCE_SHT, VF_ONLYONCE );
                        ok |= check_attr_option( nw, var,
                                  VF_REQUIRED_STR, VF_REQUIRED_SHT, VF_REQUIRED );
                        if ( !ok ) {

                            message( MSG_UNKN_ATTR_OPTION, inpf );
                            errstr( "Unknown attribute option " );
                            errqstr( nw );
                            errlf();

                        }

                    } else
                        err_eof( inpf, "defining attribute" );

                } else {

                    /* end of var definition reached */
                    inungets( nw, inpf );
                    nw = NULL;
                    ok = TRUE;

                }

                /* get next word */
                if ( nw )
                    nw = infgetw( inpf );

            } /* while(nw) */
        } /* if(!var) */
    } /* if(val_vartype..) */

    if ( !ok && var ) {

        del_dlnode( varlist, (APTR) var );
        var = NULL;
    }

    return (var);
}
Esempio n. 16
0
/*
** parse_vararg: read & check a attribute value
*/
STRPTR parse_vararg( HSCVAR *var, INFILE *inpf )
{
    STRPTR str_vararg = NULL;          /* return value */
    int    ch;                         /* char read from input */

    /* TODO: handle "<>" (reset var->text to NULL) */

    infskip_ws( inpf );

    /* disable log */
    inflog_disable( inpf );

    /* read var->quote char */
    ch = infgetc( inpf );
    if ( !strchr( VQ_STR_QUOTE, ch ) )
        if ( ch != EOF )
            var->quote = VQ_NO_QUOTE;
        else
            err_eof( inpf, "reading attribute" );
    else
        var->quote = ch;

    /* warning if no quote */
    if ( ( var->quote == VQ_NO_QUOTE )
         && !( var->varflag & VF_NOQUOTE ) )
    {

        message( MSG_ARG_NO_QUOTE, inpf );
        errstr( "Argument without quote\n" );

    }

    /* read arg string */
    if ( var->quote == '<' ) {

        /*
        ** get arg from other var
        */
        STRPTR nw = infgetw( inpf );

        if ( nw ) {

            HSCVAR *refvar = find_varname( vars, nw );

            if ( refvar ) {

                /* TODO: type checking */
                var->quote = refvar->quote;
                str_vararg = refvar->text;

                /* check empty/circular reference */
                if ( !str_vararg ) {

                    message( MSG_EMPTY_SYMB_REF, inpf );
                    errstr( "Empty reference to" );
                    errsym( var->name );
                    errlf();

                }

                /* debugging message */
                DDA( fprintf( stderr, "**    %s refers to <%s>\n",
                              var->name, refvar->name ) );

            } else {

                /* reference to unknown var */
                message( MSG_UNKN_SYMB_REF, inpf );
                errstr( "reference to unknown" );
                errsym( nw );
                errlf();

            }

            if ( (!refvar) || (!str_vararg ) ) {

                /* return empty var */
                var->quote = '"';
                str_vararg = "";
            }

            parse_gt( inpf );

        } else
            err_eof( inpf, "reading attribute" );

    } else if ( var->quote != EOF ) {

        /*
        ** get arg from input file
        */
        BOOL   end = FALSE;

        /* clear vararg or set with first char read */
        if ( var->quote == VQ_NO_QUOTE )
            end = !set_estr( vararg, ch2str( ch ) );
        else
            end = !clr_estr( vararg );
        if ( end )
            err_mem( inpf );

        /*
        ** read next char from input file until a
        ** closing quote if found.
        ** if the arg had no quote, a white space
        ** or a '>' is used to detect end of arg.
        ** if a LF is found, view error message
        */
        while ( !end ) {

            ch = infgetc( inpf );

            end = TRUE;

            if ( ch == EOF )
                err_eof( inpf, "reading attribute" );
            else if ( (ch==var->quote)
                      || ( ch==CH_LF )
                      || ( (var->quote==VQ_NO_QUOTE)
                           && ( inf_isws(ch,inpf) || ( ch=='>' ) ) )
                    )
            {

                /* end of arg reached */
                str_vararg = estr2str( vararg );
                if ( var->quote == VQ_NO_QUOTE ) {

                    if ( ch==CH_LF )
                        err_streol( inpf );
                    inungetc( ch, inpf );

                }

            } else {

                /* append next char to vararg */
                if ( !app_estrch( vararg, ch ) )
                    err_mem( inpf );
                else
                    end = FALSE; /* continue loop */

            }
        }
    }

    if ( str_vararg && var )
        /*
        ** check enum type
        */
        if (var->vartype == VT_ENUM)
            check_enumstr( var, str_vararg, inpf );
        /*
        ** parse uri (only if no macro-attr)
        ** (convert abs.uris, check existence)
        */
        else if (var->vartype == VT_URI )

            if ( !(var->varflag & VF_MACRO) )
                str_vararg = parse_uri( str_vararg, inpf );
            else {

                DDA( fprintf( stderr, "**    didn't parse uri \"%s\"\n",
                              str_vararg ) );

            }

    /* update and enable log */
    if ( !fatal_error ) {

        BOOL ok = TRUE;

        if ( var->quote != VQ_NO_QUOTE )                   
            ok &= inflog_app( inpf, ch2str( var->quote ) );/* append quote */
        inflog_app( inpf, str_vararg );                    /* append arg */
        if ( var->quote != VQ_NO_QUOTE )
            ok &= inflog_app( inpf, ch2str( var->quote ) );/* append quote */
        inflog_enable( inpf );                             /* enable log */

        if ( !ok )
            err_mem( NULL );
    }

    return ( str_vararg );
}
Esempio n. 17
0
ListInt* ListInt_Constructor(){
	ListInt *l = (ListInt*)malloc(sizeof(ListInt));
	if( !l ) err_mem("error constructing ListPtr");
	memset(l, 0, sizeof(ListInt));
	return l;
}
Esempio n. 18
0
/*
**---------------------------
** remove closing tag
**---------------------------
** params: tagname..tag to remove
**         check....show messages
*/
VOID remove_ctag( HSCTAG *tag, INFILE *inpf )
{
    /* search for tag on stack of occured tags */
    DLNODE *nd = find_dlnode( cltags->first, (APTR) tag->name, cmp_strtag );
    if ( nd == NULL ) {

        /* closing tag not found on stack */
        /* ->unmatched closing tag without previous opening tag */
        if ( !( tag->option & HT_SMARTCLOSE ) ) {

            message( MSG_UNMA_CTAG, inpf );
            errstr( "Unmatched closing tag " );
            errctag( tag->name );
            errlf();

        }

    } else {

        /* closing tag found on stack */
        HSCTAG *ctag    = (HSCTAG*) nd->data;
        STRPTR  foundnm = (STRPTR)  ctag->name;
        STRPTR  lastnm  = (STRPTR)  cltags->last->data;

        /* check if name of closing tag is -not- equal
        /* to the name of the last tag last on stack */
        /* ->illegal tag nesting */
        if ( upstrcmp(lastnm, foundnm)
                && !(tag->option | HT_MACRO)
                && !(is_hsc_tag( tag )) )
        {

            message( MSG_CTAG_NESTING, inpf );
            errstr( "Illegal closing tag nesting (expected " );
            errctag( lastnm );
            errstr( ", found " );
            errctag( tag->name );
            errch( ')' );
            errlf();

        }

        /* if closing tag has any attributes defined,
        ** it must be a closing macto tag. so copy
        ** the attributes of the closing tag to the
        ** attributes of the macro tag. therefor,
        ** the closing macro tag inherits the
        ** attributes of his opening macro
        */
        if ( ctag->attr ) {

            if ( !set_local_varlist( tag->attr, ctag->attr, MCI_APPCTAG ) )
                err_mem( inpf );

        }

        /* remove node for closing tag from cltags-list */
        del_dlnode( cltags, nd );

    }
}