Example #1
0
void DoFixOffs(FIXOFFS *fix)
{
    S32 value,newoffset;

    if(fix) {
        while(fix) {
            value = GetLabelObjectOffset(fix->data, fix->type);
            if(fix->size==FIXOFFS_NEAR) {
                newoffset = (S32)value-fix->org;
                if(newoffset<-128||newoffset>127) {
                    errorf(fix->filename,fix->line,ERR_FIXOFFSNEAR,GetLabelObjectName(fix->data, fix->type));
                } else
                    PUTB(fix->ptr, (U8)newoffset);
            } else if(fix->size==FIXOFFS_FAR) {
                PUTW(fix->ptr, (U16)value);
            } else if(fix->size==FIXOFFS_WORD) {
                PUTW(fix->ptr, (U16)value);
            } else if(fix->size==FIXOFFS_BYTE) {
                PUTB(fix->ptr, (U8)value);
            } else {
                newoffset = AccOpNum(fix->size-FIXOFFS_ARITH, (U16)value);
                PUTB(fix->ptr, (U8)newoffset);
            }
            fix = fix->prev;
        }
    }
}
Example #2
0
/**
 * debuggable_memset
 *
 * Our own memset(), existing solely so we can watch each byte get set
 */
void debuggable_memset(void* addr, unsigned char value, size_t len)
{
	unsigned char *byte_pointer = addr;

	TRACE("------ YOU ARE NOW IN DEBUGGABLE_MEMSET. LOVE IT, FEAR IT, HATE IT. ------\n");

	/* I don't know if standard memset does any safety checks, but this one
		sure as hell doesn't */
	while (byte_pointer < addr + len) {
		PUTB(byte_pointer, value);
		byte_pointer++;
	}
	TRACE("...... ok, dun memsetting ......\n");
}
Example #3
0
BOOL FASTCALL comProc_IfLoop(U16 flags, S16 *brackCnt)
{
    BOOL        BRACK=FALSE,FAR_BRANCH=FALSE,FLIPOP;
    S32         start,whilestart,offset;
    BANK        *bank;
    U8          *condPtr,*elsePtr;
    int         index,mode;

    CheckCurBank();

    if((mode=StrInStrint(szTemp,siIffys))!=-1) {

        if(mode==IFMODE_DOWHILE) {  
            bank        = curBank;
            start       = GetBankOffset();
            if(STRCMP(GetNextWord(),"while")) {
                // 'ist der code block!
                GetCode(flags|CF_BRACEOK, brackCnt);
                if(STRCMP(GetNextWord(),"while"))
                    error(ERR_WHILEEXP,szTemp);
            }
        }

        if(GetNextWord()[0]!='(')
            error(ERR_INVCOND,szTemp);
        else {
            GetNextWord();
            BRACK = TRUE;
        }

        USE_DEFS        = FALSE;
        if(!STRCMP(szTemp,"far")) {
            FAR_BRANCH = TRUE;
            GetNextWord();
        } else if(!STRCMP(szTemp,"near")) {
            GetNextWord();
        }

        // parse the "is" "is not" "not" "no", etc.
        FLIPOP = FALSE;
        while((index=StrInStrint(szTemp,siIsNot))!=-1) {
            if(!siIsNot[index].index)
                FLIPOP = !FLIPOP;
            GetNextWord();
        }
                            
        USE_DEFS        = TRUE;
        if(!PRECOMPILING) {   
            if((index=StrInStrint(szTemp,siConditions))==-1) {
                error(ERR_INVALIDCOND,szTemp);
                condPtr = NULL;
            } else {
                if(mode==IFMODE_IF || mode==IFMODE_WHILE)
                    FLIPOP = !FLIPOP;
                index = (FLIPOP)?
                    RelSwapOp(siConditions[index].index):
                    siConditions[index].index;

                if(mode==IFMODE_WHILE)
                    whilestart = GetBankOffset();

                if(FAR_BRANCH) {
                    WriteOpcodeB(RelSwapOp(index),3);
                    WriteOpcode(opJMP_ABS);
                    condPtr = curBank->ptr;
                    WriteCodeW(0);
                } else {
                    condPtr = curBank->ptr+1;
                    WriteOpcodeB(index,0);
                }
            }    
            if(mode!=IFMODE_DOWHILE) {
                bank    = curBank;
                start   = GetBankOffset();
            }
        }
                         
        if(BRACK && GetNextWord()[0]!=')') {
            error(ERR_IFCONDCLOSEEXP,szTemp);
        }
          
        if(mode!=IFMODE_DOWHILE)
            GetCode(flags|CF_BRACEOK|CF_GETNEXTWORD, brackCnt);

        elsePtr = NULL;
        if(!STRCMP(PeekNextWord(),"else")) {
            GetNextWord();
            if(mode!=IFMODE_IF)
                error(ERR_ONLYIFSELSE);
            else {         
                if(!PRECOMPILING)
                    WriteOpcode(opJMP_ABS);
                elsePtr = curBank->ptr;
                if(!PRECOMPILING)
                    WriteCodeW(0);
            }
        }

        if(!PRECOMPILING) {
            if(bank     != curBank)
                error(ERR_FOREVEROUTOFBANK,bank->label,curBank->label);
            else if(condPtr) {
                if(mode==IFMODE_WHILE) {
                    WriteOpcodeW(opJMP_ABS,whilestart);
                }
                if(FAR_BRANCH) {  
                    if(mode==IFMODE_DOWHILE) {
                        PUTW(condPtr,start);
                    } else {
                        PUTW(condPtr,GetBankOffset());
                    }
                } else {
                    offset = mode==IFMODE_DOWHILE?
                        start-GetBankOffset():
                        GetBankOffset()-start;

                    if((offset<-128 || offset>127))
                        error(ERR_BRANCHOUTOFRANGE);
                    else
                        PUTB(condPtr,(U8)offset);
                }
            }
        }
        if(elsePtr) {
            GetCode(flags|CF_BRACEOK|CF_GETNEXTWORD, brackCnt);
            if(!PRECOMPILING)
                PUTW(elsePtr,GetBankOffset());
        }

    } else if(!STRCMP(szTemp,"forever")) {

        bank    = curBank;
        start   = GetBankOffset();

        GetCode(flags|CF_BRACEOK|CF_GETNEXTWORD, brackCnt);

        if(bank != curBank)
            error(ERR_FOREVEROUTOFBANK,bank->label,curBank->label);
        else
            WriteOpcodeW(opJMP_ABS,start);

    } else
        return FALSE;
    return TRUE;
}
Example #4
0
PRIVATE int SGML_write (HTStream * context, const char * b, int l)
    {
	const SGML_dtd	*dtd = context->dtd;
	HTChunk	*string = context->string;
	const char *text = b;
	int count = 0;
	
	while (l-- > 0)
	    {
		char c = *b++;
		switch(context->state)
		    {
		    got_element_open:
			/*
			** The label is jumped when the '>' of a the element
			** start tag has been detected. This DOES NOT FALL TO
			** THE CODE S_after_open, only processes the tag and
			** sets the state (c should still contain the
			** terminating character of the tag ('>'))
			*/
			if (context->current_tag && context->current_tag->name)
				start_element(context);
			context->state = S_after_open;
			break;

		    case S_after_open:
			/*
			** State S_after_open is entered only for single
			** character after the element opening tag to test
			** against newline. Strip one trainling newline only
			** after opening nonempty element.  - SGML: Ugh!
			*/
			text = b;
			count = 0;
			if (c == '\n' && (context->contents != SGML_EMPTY))
			    {
				context->state = S_text;
				break;
			    }
			--text;
			goto S_text;

		    S_text:
			context->state = S_text;
		    case S_text:
#ifdef ISO_2022_JP
			if (c == '\033')
			    {
				context->state = S_esc;
				++count;
				break;
			    }
#endif /* ISO_2022_JP */
			if (c == '&')
			    {
				if (count > 0)
					PUTB(text, count);
				count = 0;
				HTChunk_clear(string);
				context->state = S_ero;
			    }
			else if (c == '<')
			    {
				if (count > 0)
					PUTB(text, count);
				count = 0;
				HTChunk_clear(string);
				/* should scrap LITERAL, and use CDATA and
				   RCDATA -- msa */
				context->state =
					(context->contents == SGML_LITERAL) ?
						S_literal : S_tag;
			    }
			else if (c == '\n')
			    	/* Newline - ignore if before end tag! */
				context->state = S_nl;
			else
				++count;
			break;

		    case S_nl:
			if (c == '<')
			    {
				if (count > 0)
					PUTB(text, count);
				count = 0;
				HTChunk_clear(string);
				context->state =
					(context->contents == SGML_LITERAL) ?
						S_literal : S_nl_tago;
			    }
			else
			    {
				++count;
				goto S_text;
			    }
			break;

		    case S_nl_tago:	/* Had newline and tag opener */
			if (c != '/')
				PUTC('\n'); /* Only ignore newline before </ */
			context->state = S_tag;
			goto handle_S_tag;

#ifdef ISO_2022_JP
		    case S_esc:
			if (c=='$')
				context->state = S_dollar;
			else if (c=='(')
				context->state = S_paren;
			else
				context->state = S_text;
			++count;
			break;

		    case S_dollar:
			if (c=='@' || c=='B')
				context->state = S_nonascii_text;
			else
				context->state = S_text;
			++count;
			break;

		    case S_paren:
			if (c=='B' || c=='J')
				context->state = S_text;
			else
				context->state = S_text;
			++count;
			break;

		    case S_nonascii_text:
			if (c == '\033')
				context->state = S_esc;
			++count;
			break;
#endif /* ISO_2022_JP */

			/* In literal mode, waits only for specific end tag!
			** Only foir compatibility with old servers.
			*/
		    case S_literal:
			HTChunk_putc(string, c);
			if ( TOUPPER(c) !=
			    ((HTChunk_size(string) == 1) ? '/'
			     : context->current_tag->name[HTChunk_size(string)-2]))
			    {

				/* If complete match, end literal */
				if ((c == '>') &&
				    (!context->current_tag->name[HTChunk_size(string)-2]))
				    {
					end_element
						(context,context->current_tag);
					/*
					  ...setting SGML_MIXED below is a
					  bit of kludge, but a good guess that
					  currently works, anything other than
					  SGML_LITERAL would work... -- msa */
					context->contents = SGML_MIXED;
				    }
				else
				    {
					/* If Mismatch: recover string. */
					PUTC( '<');
					PUTB(HTChunk_data(string), HTChunk_size(string));
				    }
				context->state = S_text;
				text = b;
				count = 0;
			    }
			break;

			/*
			** Character reference or Entity
			*/
		    case S_ero:
			if (c == '#')
			    {
				/*   &# is Char Ref Open */ 
				context->state = S_cro;
				break;
			    }
			context->state = S_entity;

			/** FALL THROUGH TO S_entity !! ***/

			/*
			** Handle Entities
			*/
		    case S_entity:
			if (isalnum((int) c))
				HTChunk_putc(string, c);
			else
			    {
				HTChunk_terminate(string);
				handle_entity(context);
				text = b;
				count = 0;
				if (c != ';')
				    {
					--text;
					goto S_text;
				    }
				context->state = S_text;
			    }
			break;

			/*	Character reference
			 */
		    case S_cro:
			if (isalnum((int)c))
				/* accumulate a character NUMBER */
				HTChunk_putc(string, c);
			else
			    {
				int value;
				HTChunk_terminate(string);
				if (sscanf(HTChunk_data(string), "%d", &value)==1)
					PUTC((char)value);
				else
				    {
					PUTB("&#", 2);
					PUTB(HTChunk_data(string), HTChunk_size(string)-1);
				    }
				text = b;
				count = 0;
				if (c != ';')
				    {
					--text;
					goto S_text;
				    }
				context->state = S_text;
			    }
			break;

		    case S_tag:		/* new tag */
		    handle_S_tag:
			if (isalnum((int)c))
				HTChunk_putc(string, c);
			else { /* End of tag name */
			    int i;
			    if (c == '/') {
				if (HTChunk_size(string) > 0)
				    HTTRACE(SGML_TRACE, "`<%s/' found!\n" _ HTChunk_data(string));
				context->state = S_end;
				break;
			    } else if (c == '!') {
				if (HTChunk_size(string) > 0)
				    HTTRACE(SGML_TRACE, " `<%s!' found!\n" _ HTChunk_data(string));
				context->state = S_md;
				break;
			    }
			    HTChunk_terminate(string);
			    context->current_tag  = SGMLFindTag(dtd, HTChunk_data(string));
			    if (context->current_tag == NULL) {
				HTTRACE(SGML_TRACE, "*** Unknown element %s\n" _ HTChunk_data(string));
				(*context->actions->unparsed_begin_element)
				    (context->target, HTChunk_data(string), HTChunk_size(string));
			    } else {
				for (i=0; i<context->current_tag->number_of_attributes; i++) {
				    context->present[i] = NO;
				    context->value[i] = -1;
				}
			    }
			    context->token = 0;
			    HTChunk_clear(string);
			    context->current_attribute_number = INVALID;
			    goto S_tag_gap;
			}
			break;

		    S_tag_gap:
			context->state = S_tag_gap;
		    case S_tag_gap:		/* Expecting attribute or > */
			if (isspace((int) c))
				break;	/* Gap between attributes */

			if (c == '>')
				goto got_element_open;
			else
				goto S_attr;

		    S_attr:
			/*
			** Start collecting the attribute name and collect
			** it in S_attr.
			*/
			context->state = S_attr;
			HTChunk_truncate(string, context->token);
		    case S_attr:
			if (isspace((int) c) || c == '>' || c == '=')
				goto got_attribute_name;
			else
				HTChunk_putc(string, c);
			break;

		    got_attribute_name:
			/*
			** This label is entered when attribute name has been
			** collected. Process it and enter S_attr_gap for
			** potential value or start of the next attribute.
			*/
			HTChunk_terminate(string) ;
			handle_attribute_name
				(context, HTChunk_data(string) + context->token);
			HTChunk_truncate(string, context->token);
			context->state = S_attr_gap;
		    case S_attr_gap:	/* Expecting attribute or = or > */
			if (isspace((int) c))
				break;	/* Gap after attribute */

			if (c == '>')
				goto got_element_open;
			else if (c == '=')
				context->state = S_equals;
			else
				goto S_attr; /* Get next attribute */
			break;

		    case S_equals:	/* After attr = */ 
			if (isspace((int) c))
				break;	/* Before attribute value */

			if (c == '>')
			    {		/* End of tag */
				HTTRACE(SGML_TRACE, "found = but no value\n");
				goto got_element_open;
			    }
			else if (c == '\'')
				context->state = S_squoted;
			else if (c == '"')
				context->state = S_dquoted;
			else
				goto S_value;
			break;

		    S_value:
			context->state = S_value;
			HTChunk_truncate(string, context->token);
		    case S_value:
			if (isspace((int) c) || c == '>')
			    {
				HTChunk_terminate(string);
				handle_attribute_value(context);
				context->token = HTChunk_size(string);
				goto S_tag_gap;
			    }
			else
				HTChunk_putc(string, c);
			break;
		
		    case S_squoted:	/* Quoted attribute value */
			if (c == '\'')
			    {
				HTChunk_terminate(string);
				handle_attribute_value(context);
				context->token = HTChunk_size(string);
				context->state = S_tag_gap;
			    }
			else if (c && c != '\n' && c != '\r')
				HTChunk_putc(string, c);
			break;
	
		    case S_dquoted:	/* Quoted attribute value */
			if (c == '"')
			    {
				HTChunk_terminate(string);
				handle_attribute_value(context);
				context->token = HTChunk_size(string);
				context->state = S_tag_gap;
			    }
			else if (c && c != '\n' && c != '\r')
				HTChunk_putc(string, c);
			break;

		    case S_end:	/* </ */
			if (isalnum((int) c))
				HTChunk_putc(string, c);
			else
			    {		/* End of end tag name */
				HTTag *t;
				char * first;
				HTChunk_terminate(string);
				if ((first=HTChunk_data(string))!=NULL && *first != '\0')
				        t = SGMLFindTag(dtd, HTChunk_data(string));
				else
				    	/* Empty end tag */
					/* Original code popped here one
					   from the stack. If this feature
					   is required, I have to put the
					   stack back... -- msa */
					t = NULL;
				if (!t) {
				    HTTRACE(SGML_TRACE, "Unknown end tag </%s>\n" _ HTChunk_data(string));
				    (*context->actions->unparsed_end_element)
					(context->target, HTChunk_data(string), HTChunk_size(string));
				} else {
				    context->current_tag = NULL;
				    end_element(context, t);
				}
				HTChunk_clear(string);
				context->current_attribute_number = INVALID;
				if (c != '>')
				    {
					if (!isspace((int) c))
					    HTTRACE(SGML_TRACE, "`</%s%c' found!\n" _ HTChunk_data(string) _ c);
					context->state = S_junk_tag;
				    }
				else
				    {
					text = b;
					count = 0;
					context->state = S_text;
				    }
			    }
			break;

		    case S_junk_tag:
			if (c == '>')
			    {
				text = b;
				count = 0;
				context->state = S_text;
			    }
			break;

			/*
			** Scanning (actually skipping) declarations
			*/
		    case S_md:
			if (c == '-')
				context->state = S_com_1;
			else if (c == '"')
				context->state = S_md_dqs;
			else if (c == '\'')
				context->state = S_md_sqs;
			else if (c == '>')
			    {
				text = b;
				count = 0;
				context->state = S_text;
			    }
			break;

		    case S_md_dqs: /* Skip double quoted string */
			if (c == '"')
				context->state = S_md;
			else if (c == '>')
			    {
				text = b;
				count = 0;
				context->state = S_text;
			    }
			break;

		    case S_md_sqs: /* Skip single quoted string */
			if (c == '\'')
				context->state = S_md;
			else if (c == '>')
			    {
				text = b;
				count = 0;
				context->state = S_text;
			    }
			break;

		    case S_com_1: /* Starting a comment? */
			context->state = (c == '-') ? S_com : S_md;
			if (c == '>')
			    {
				text = b;
				count = 0;
				context->state = S_text;
			    }
			break;

		    case S_com: /* ..within comment */
			if (c == '-')
				context->state = S_com_2;
			break;

		    case S_com_2: /* Ending a comment ? */
			context->state = (c == '-') ? S_com_2a : S_com;
			break;
		    
		    case S_com_2a:
			if (c == '>') {
			    text = b;
			    count = 0;
			    context->state = S_text;
			} else if (c == '-') {
			    context->state = S_com_2a;
			} else
			    context->state = S_com;
			break;
		    }
	    }
	if (count > 0)
		PUTB(text, count);
	return HT_OK;
    }