// http://www.w3.org/TR/css3-syntax/#consume-a-name CSSParserString CSSTokenizer::consumeName() { // Names without escapes get handled without allocations for (unsigned size = 0; ; ++size) { UChar cc = m_input.peekWithoutReplacement(size); if (cc == '\0' || cc == '\\') break; if (!isNameChar(cc)) { unsigned startOffset = m_input.offset(); m_input.advance(size); return m_input.rangeAsCSSParserString(startOffset, size); } } StringBuilder result; while (true) { UChar cc = consume(); if (isNameChar(cc)) { result.append(cc); continue; } if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) { result.append(consumeEscape()); continue; } reconsume(cc); return registerString(result.toString()); } }
/**************************************************************************** Desc: Returns TRUE if the name is a valid XML name ****************************************************************************/ FLMBOOL FLMAPI F_XML::isNameValid( FLMUNICODE * puzName, FLMBYTE * pszName) { FLMBOOL bValid = FALSE; if( puzName) { FLMUNICODE * puzTmp; if( !isLetter( *puzName) && *puzName != FLM_UNICODE_UNDERSCORE && *puzName != FLM_UNICODE_COLON) { goto Exit; } puzTmp = &puzName[ 1]; while( *puzTmp) { if( !isNameChar( *puzTmp)) { goto Exit; } puzTmp++; } } if( pszName) { FLMBYTE * pszTmp; if( !isLetter( *pszName) && *pszName != FLM_UNICODE_UNDERSCORE && *pszName != FLM_UNICODE_COLON) { goto Exit; } pszTmp = &pszName[ 1]; while( *pszTmp) { if( !isNameChar( *pszTmp)) { goto Exit; } pszTmp++; } } bValid = TRUE; Exit: return( bValid); }
const char *XMLProcedureCall::MakeValid(const char *pzName, GString &strDestination) { if ( !isLetter(pzName[0]) ) { // prefix invalid XML tag strDestination = "Param_"; } // Replace any other invalid chars with '_' __int64 nLen = (pzName) ? strlen(pzName) : 0; for(int i=0; i < nLen; i++) { if ( isNameChar(pzName[i]) ) strDestination << pzName[i]; else strDestination << '_'; } // If the entire name is invalid - example "12345" // (since an XML Element cannot start with a number XML 1.0) // replace the invalid name with a valid one. if (strDestination.IsEmpty()) strDestination = "Parameter"; return (const char *)strDestination; }
CSSParserToken CSSTokenizer::hash(UChar cc) { UChar nextChar = m_input.nextInputChar(); if (isNameChar(nextChar) || twoCharsAreValidEscape(nextChar, m_input.peek(1))) { HashTokenType type = nextCharsAreIdentifier() ? HashTokenId : HashTokenUnrestricted; return CSSParserToken(type, consumeName()); } return CSSParserToken(DelimiterToken, cc); }
Token *parseName( Tokenizer *tokenizer ) { StatefulString *ss = tokenizer->ss_; assert( isNameChar( ss_peek( ss ) ) || isUnicodeSequenceStart( ss, 0 ) ); int start, length; StatefulStringPosition pos1, pos2; start = ss->next_index; length = 0; pos1 = ss->next_position; while ( isNameChar( ss_peek( ss ) ) || isUnicodeSequenceStart( ss, 0 ) ) { length += processChar( ss ); } if ( ss_peek( ss ) == L'(' ) { ss_getchar( ss ); length++; } pos2 = ss->next_position; return token_new( ss_substr( ss, start, length ), length, NAME, pos1, pos2 ); }
/* * check one character */ int genxCharClass(genxWriter w, int c) { int ret = 0; if (isXMLChar(w, c)) ret |= GENX_XML_CHAR; if (isNameChar(w, c)) ret |= GENX_NAMECHAR; if (isLetter(w, c)) ret |= GENX_LETTER; return ret; }
// http://www.w3.org/TR/css3-syntax/#consume-a-name String MediaQueryTokenizer::consumeName() { // FIXME: Is this as efficient as it can be? // The possibility of escape chars mandates a copy AFAICT. StringBuilder result; while (true) { UChar cc = consume(); if (isNameChar(cc)) { result.append(cc); continue; } if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) { result.append(consumeEscape()); continue; } reconsume(cc); return result.toString(); } }
Token *parseNumber( Tokenizer *tokenizer ) { StatefulString *ss = tokenizer->ss_; assert( isNumberStart( ss, 0 ) ); int start, length; StatefulStringPosition pos1, pos2; start = ss->next_index; length = 0; pos1 = ss->next_position; TokenType type = NUMBER; int isFloat = 0; wchar_t temp; while ( isNumeric( ss_peek( ss ) ) || ( ss_peek( ss ) == L'-' && length == 0 ) || ( ss_peek( ss ) == L'.' && !isFloat ) ) { temp = ss_getchar( ss ); if ( temp == L'.' ) { isFloat = 1; } length++; } // Is the number followed by a percentage? if ( ss_peek( ss ) == L'%' ) { ss_getchar( ss ); length++; type = PERCENTAGE; } // Is the number followed by a dimension? else if ( isIdentifierStart( ss, 0 ) ) { while ( isNameChar( ss_peek( ss ) ) ) { ss_getchar( ss ); length++; } type = DIMENSION; } pos2 = ss->next_position; return token_new( ss_substr( ss, start, length ), length, type, pos1, pos2 ); }
static genxStatus checkNCName(genxWriter w, constUtf8 name) { int c; if (name == NULL || *name == 0) return GENX_BAD_NAME; c = genxNextUnicodeChar(&name); if (!isLetter(w, c) && c != ':' && c != '_') return GENX_BAD_NAME; while (*name) { c = genxNextUnicodeChar(&name); if (c == -1) return GENX_BAD_UTF8; if (!isNameChar(w, c)) return GENX_BAD_NAME; } return GENX_SUCCESS; }
int vfsscanf_(const char *buf, const char *format, va_list arg){ int buffer_pos = 0; int format_pos = 0; int string_pos = 0; int ret = 0; int found = 0; int *i; float *f; char *c; int invert; float tf; int state = 0; // 0 = last char = normal char // 1 = last char = '%' // 2 = last char = '\' while(format[format_pos]){ found = 0; switch(state){ case 0: switch(format[format_pos]){ case '%': state = 1; format_pos++; continue; break; case '\'': state = 2; format_pos++; continue; break; case ' ': // parse whithespaces while(isWhitespace(buf[buffer_pos])){ buffer_pos++; found++; } found++; break; default: if(format[format_pos] != buf[buffer_pos++]){ return(ret); } found++; } break; case 1: switch(format[format_pos]){ case '%': if(buf[buffer_pos++] != '%'){ return(ret); } found++; break; case 'c': c = va_arg(arg, char *); *c = buf[buffer_pos++]; found++; break; case 's': string_pos = 0; c = va_arg(arg, char *); //while(isChar(buf[buffer_pos])){ while(!isWhitespace(buf[buffer_pos])){ c[string_pos] = buf[buffer_pos++]; string_pos++; c[string_pos] = '\0'; found++; } break; case 'N': string_pos = 0; c = va_arg(arg, char *); //while(isChar(buf[buffer_pos])){ while(isNameChar(buf[buffer_pos])){ c[string_pos] = buf[buffer_pos++]; string_pos++; c[string_pos] = '\0'; found++; } break; case 'i': i = va_arg(arg, int *); *i = 0; invert = 1; if(buf[buffer_pos] == '-'){ invert = -1; buffer_pos++; } else if(buf[buffer_pos] == '+'){ buffer_pos++; } while(isDecDigit(buf[buffer_pos])){ *i *= 10; *i += buf[buffer_pos++] - '0'; found++; } *i *= invert; break; case 'b': i = va_arg(arg, int *); *i = 0; invert = 1; if(buf[buffer_pos] == '-'){ invert = -1; buffer_pos++; } else if(buf[buffer_pos] == '+'){ buffer_pos++; } if(!(buf[buffer_pos] == 'b' || buf[buffer_pos] == 'B')){ return(ret); } buffer_pos++; while(isBinDigit(buf[buffer_pos])){ *i *= 2; *i += buf[buffer_pos++] - '0'; found++; } *i *= invert; break; case 'h': i = va_arg(arg, int *); *i = 0; invert = 1; if(buf[buffer_pos] == '-'){ invert = -1; buffer_pos++; } else if(buf[buffer_pos] == '+'){ buffer_pos++; } if(buf[buffer_pos++] != '0'){ return(ret); } if(buf[buffer_pos++] != 'x'){ return(ret); } while(isHexDigit(buf[buffer_pos])){ *i *= 16; if(buf[buffer_pos] < 'A'){ *i += buf[buffer_pos++] - '0'; } else if(buf[buffer_pos] < 'a'){ *i += buf[buffer_pos++] - 'A' + 10; } else{ *i += buf[buffer_pos++] - 'a' + 10; } found++; } *i *= invert; break; case 'f': f = va_arg(arg, float *); *f = 0; tf = 10; invert = 1; if(buf[buffer_pos] == '-'){ invert = -1; buffer_pos++; } else if(buf[buffer_pos] == '+'){ buffer_pos++; } while(isDecDigit(buf[buffer_pos])){ *f *= 10; *f += buf[buffer_pos++] - '0'; found++; } if(buf[buffer_pos] == '.'){ buffer_pos++; while(isDecDigit(buf[buffer_pos])){ *f += (buf[buffer_pos++] - '0') / tf; tf *= 10; found++; } } *f *= invert; break; default: return(ret); break; } state = 0; break; case 2: switch(format[format_pos]){ case '\'': if(buf[buffer_pos++] != '\''){ return(ret); } found++; break; case 'n': if(buf[buffer_pos++] != '\n'){ return(ret); } found++; break; default: return(ret); break; } state = 0; break; default: break; } format_pos++; if(!found){ return(ret); } ret++; } return(ret); }
void xml::lex::getContent(xml::token *tok) { static const char* s_emptyElement = "/>"; static const char* s_endElement = "</"; static const char* s_elementEnd = ">"; static const char* s_cdataStart = "<![CDATA["; int nEndlessLoopDetection = 0; if (m_s != 0) { contentTop:; if (nEndlessLoopDetection++ > 1000) { // When parsing a XML with an invalid element <@CustomerID> // 1000 is well beyond any normal behavior of stream stacks. throw GException("XML Parser", 27, m_line, m_byte); } switch (m_sstate) { case xml::_xml_element_start : if (!m_s) throw GException("XML Parser", 28, m_line, m_byte); if ((m_s->m_xml[m_s->m_offset] == '<') && (isNameChar(m_s->m_xml[m_s->m_offset + 1]))) { m_s->m_offset++; offsetLine(); tok->m_type = _startTag; if (getName(tok) != false) { GStackPush(m_tagStack,tok->get()); m_sstate = _xml_element_attribute; if ((m_tagStack.m_nNext == 1) && (m_documentType != 0)) { if (memcmp(m_documentType, tok->get(), tok->length()) != 0) { throw GException("XML Parser", 16, m_line, m_byte); } } } else { throw GException("XML Parser", 11, m_line, m_byte); } } else { // make sure that the next tag isn't a > if (m_s->m_xml[m_s->m_offset + 1] == *s_elementEnd) throw GException("XML Parser", 11, m_line, m_byte); m_sstate = _xml_element_content; goto contentTop; } break; case xml::_xml_element_attribute : if (handleWhitespace() != false) { if (getName(tok) != false) { tok->m_type = _attributeName; m_sstate = _xml_element_attribute_value; } else { m_sstate = _xml_element_start_end; goto contentTop; } } else { m_sstate = _xml_element_start_end; goto contentTop; } break; case xml::_xml_element_start_end : if (handleReserved(s_emptyElement) != false) { // return an empty end tag token tok->m_type = _emptyEndTag; m_sstate = _xml_element_start; } else if (handleReserved(s_elementEnd) != false) { m_sstate = _xml_element_content; goto contentTop; } else { throw GException("XML Parser", 8, m_line, m_byte); } break; case xml::_xml_element_attribute_value : getEqual(); getQuote(); tok->m_type = _pcdata; getAttribute(tok); getQuote(); m_sstate = _xml_element_attribute; break; case xml::_xml_element_content : if (getCharacterData(tok) != false) tok->m_type = _pcdata; else if (handleReserved(s_cdataStart) != false) { getCData(tok); tok->m_type = _cdata; } else { getMisc(tok); if (tok->m_type == _unknown) { m_sstate = _xml_element_end_tag; goto contentTop; } } break; case xml::_xml_element_end_tag : handleWhitespace(); if (handleReserved(s_endElement) != false) { tok->m_type = _endTag; getName(tok); m_sstate = _xml_element_end_end; } else if (m_tagStack.m_nNext) { m_sstate = _xml_element_start; goto contentTop; } break; case xml::_xml_element_end_end : handleWhitespace(); if (handleReserved(s_elementEnd) == false) { throw GException("XML Parser", 8, m_line, m_byte); } m_sstate = _xml_element_start; goto contentTop; break; } } if ((tok->m_type == _endTag) || (tok->m_type == _emptyEndTag)) { // throw an exception if the end tag // doesn't match the last start tag GStackPopType(m_tagStack,tag,char *) if ( (tok->isEmpty() == false) && (tag != 0) ) { if (memcmp(tag, tok->get(), tok->length()) != 0) { GString strStartTag; while ((tag) && (*tag != '>') && (!isWhitespace(*tag))) { strStartTag += *tag; tag++; } GString strEndTag(tok->get(), tok->length()); throw GException("XML Parser", 12, (const char *)strEndTag, (const char *)strStartTag,m_line, m_byte); } } if (m_tagStack.m_nNext == 0) { m_state = xml::_finished; m_nextState = xml::_finished; if ((tok->m_type == _endTag) && (handleReserved(s_elementEnd) == false)) { throw GException("XML Parser", 8, m_line, m_byte); } } }
void GdbDebugger::handleResponse(const QByteArray &buff) { if (buff.isEmpty() || buff == "(gdb) ") return; const char *from = buff.constData(); const char *to = from + buff.size(); const char *inner; int token = -1; // Token is a sequence of numbers. for (inner = from; inner != to; ++inner) if (*inner < '0' || *inner > '9') break; if (from != inner) { token = QByteArray(from, inner - from).toInt(); from = inner; } // Next char decides kind of response. const char c = *from++; switch (c) { case '*': case '+': case '=': { QByteArray asyncClass; for (; from != to; ++from) { const char c = *from; if (!isNameChar(c)) break; asyncClass += *from; } GdbMiValue result; while (from != to) { GdbMiValue data; if (*from != ',') { // happens on archer where we get // 23^running <NL> *running,thread-id="all" <NL> (gdb) result.m_type = GdbMiValue::Tuple; break; } ++from; // skip ',' data.parseResultOrValue(from, to); if (data.isValid()) { //qDebug() << "parsed result:" << data.toString(); result.m_children += data; result.m_type = GdbMiValue::Tuple; } } handleAsyncClass(asyncClass,result); break; } case '~': handleConsoleStream(GdbMiValue::parseCString(from, to)); break; case '@': handleTargetStream(GdbMiValue::parseCString(from, to)); break; case '&': handleLogStream(GdbMiValue::parseCString(from, to)); break; case '^': { GdbResponse response; response.token = token; for (inner = from; inner != to; ++inner) if (*inner < 'a' || *inner > 'z') break; QByteArray resultClass = QByteArray::fromRawData(from, inner - from); if (resultClass == "done") { response.resultClass = GdbResultDone; } else if (resultClass == "running") { response.resultClass = GdbResultRunning; } else if (resultClass == "connected") { response.resultClass = GdbResultConnected; } else if (resultClass == "error") { response.resultClass = GdbResultError; } else if (resultClass == "exit") { response.resultClass = GdbResultExit; } else { response.resultClass = GdbResultUnknown; } from = inner; if (from != to) { if (*from == ',') { ++from; response.data.parseTuple_helper(from, to); response.data.m_type = GdbMiValue::Tuple; response.data.m_name = "data"; } else { // Archer has this. response.data.m_type = GdbMiValue::Tuple; response.data.m_name = "data"; } } if (m_tokenCookieMap.contains(token)) { response.cookie = m_tokenCookieMap.take(token); } handleResultRecord(response); break; } default: { from--; QByteArray out(from,to-from); out.append("\n"); emit debugLog(LiteApi::DebugApplationLog,QString::fromUtf8(out)); break; } } }
XMLCToken xmlcTokenizerNextToken(XMLCTokenizer *s) { XMLCCharacter ch; XMLCCharacter *mark = s->token_start = s->buffer_position; XMLCUInt i; while (s->buffer_position < s->buffer_end) { getChar(ch); /* states that do their own getChar aren't allowed to eat these */ if (ch == '\n' || ch == '\r') { s->line_number++; s->line_start = s->buffer_position; } /* printf("char '%c' props %x s->tokState: %@", ch, characterPropertiesTable[ch], [_tokenStateNameStrings objectAtIndex:s->tokState]); */ switch (s->tokState) { /* FIXME: do I need this state? */ case T_IN_START_PCDATA: s->token_start = mark; s->tokState = T_IN_PCDATA; /* fall through */ case T_IN_PCDATA: if (ch == '<') { /* ^<Marker */ unGetChar(ch); s->tokState = T_IN_TAG; if (s->buffer_position > s->token_start) { if(s->isWhiteSpaceToken) return s->tokType = WHITESPACE_TOKEN; else return s->tokType = PCDATA_TOKEN; } } if(!isWhiteSpace(ch)) s->isWhiteSpaceToken = 0; break; case T_IN_TAG: /* ^<Marker */ if (ch == '<') { getChar(ch); if (ch == '?') { /* <? */ s->token_start = mark; s->tokState = T_IN_COMMAND; } else if (ch == '/') { return s->tokType = OPEN_SLASH_ELEMENT_TOKEN; /* </ */ } else if (ch == '!') { s->token_start = mark; s->tokState = T_IN_DECLARATION; getChar(ch); if (ch =='-') { getChar(ch); if (ch == '-') { /* <!-- */ s->token_start = mark; s->tokState = T_IN_COMMENT; } } else if (ch == '[') { s->tokState = T_IN_CDATA; for(i=0; i<6 && s->tokState == T_IN_CDATA; i++) { getChar(ch); if (!ch == "CDATA["[i]) s->tokState = T_IN_DECLARATION; } if (s->tokState == T_IN_CDATA) s->token_start = mark; } else { /* <! */ unGetChar(ch); s->token_start = mark; s->tokState = T_IN_DECLARATION; } } if (s->tokState == T_IN_TAG) { /* < */ unGetChar(ch); return s->tokType = OPEN_ELEMENT_TOKEN; } } else if (ch == '>') { s->token_start = s->buffer_position; s->isWhiteSpaceToken = 1; s->tokState = T_IN_PCDATA; return s->tokType = CLOSE_ELEMENT_TOKEN; } else if (ch == '/') { getChar(ch); if (ch =='>') { s->token_start = mark; s->tokState = T_IN_PCDATA; return s->tokType = SLASH_CLOSE_ELEMENT_TOKEN; } else { unGetChar(ch); return s->tokType = '/'; /* FIXME: is this an error, the parser should complain */ } } else if (ch == '=') { s->token_start = mark; return s->tokType = '='; } else if (ch == '"') { s->token_start = mark; s->end_quote_char = '"'; s->tokState = T_IN_QUOTE_STRING; } else if (ch == 0x0027) { /*# APOSTROPHE */ s->token_start = mark; s->end_quote_char = 0x0027; s->tokState = T_IN_QUOTE_STRING; } else if (isNameStartChar(ch)) { /* FIXME: whitespace tokens inside tags aren't recognized */ /* need to handle whitespace tokens in tags, could eliminate s->buffer_position-1 and use _mark */ s->token_start = s->buffer_position-1; s->tokState = T_IN_NAME_STRING; } else if (!isWhiteSpace(ch)) { /* don't know what this is, return it as itself, let the parser deal with it */ return s->tokType = ch; } else { mark = s->buffer_position; } break; case T_IN_DECLARATION: /* scan until > FIXME: allow everything? */ if (ch == '>') { s->tokState = T_IN_START_PCDATA; return s->tokType = DECLARATION_TOKEN; } case T_IN_COMMENT: /* scan until --> allow everything */ if (ch == '-') { getChar(ch); if (ch == '-') { getChar(ch); if (ch == '>') { s->tokState = T_IN_START_PCDATA; return s->tokType = COMMENT_TOKEN; } } } break; case T_IN_COMMAND: /* scan until ?> FIXME: allow everything? */ if (ch == '?') { getChar(ch); if (ch == '>') { s->tokState = T_IN_START_PCDATA; return s->tokType = COMMAND_TOKEN; } } break; case T_IN_CDATA: /* scan until ]]> allow everything */ if (ch == ']') { getChar(ch); if (ch == ']') { getChar(ch); if (ch == '>') { s->tokState = T_IN_START_PCDATA; return s->tokType = CDATA_TOKEN; } } } break; case T_IN_NAME_STRING: /* <M^arker */ if (!(isNameChar(ch))) { unGetChar(ch); s->tokState = T_IN_TAG; return s->tokType = NAME_TOKEN; } break; case T_IN_QUOTE_STRING: /* FIXME: handle "e; type things (and whitespace eating?) */ if (ch == s->end_quote_char) { s->tokState = T_IN_TAG; return s->tokType = QUOTE_STRING_TOKEN; } break; } } return s->tokType = s->tokState != T_IN_PCDATA ? PARTIAL_TOKEN : EOF_TOKEN; }
static struct parseNode *repairPT(struct parseNode *node) { struct parseNode *a=node,*prev=NULL,*b,*c; /// name /// ( expr ) /// ( type ) { object literal } /// (digit1) { _nex = (digit){} } while(a!=NULL) { if(a->type==13) // ( ... ) { a->dat.n=repairPT(a->dat.n); b=a->dat.n; if(b!=NULL && b->next==NULL && b->type==0 && isNameChar(b->dat.s[0])) if(a->next!=NULL) { b=a->next; if(b->type==17) { b->dat.n=repairPT(b->dat.n); a->dat.n->next=b; a->next=b->next; b->next=NULL; } } } a=a->next; } /// expr . name /// expr ( expr ) a=node; prev=NULL; while(a!=NULL) { int notOp=(a->type!=0 || isNameChar(a->dat.s[0])); b=a->next; if(b==NULL) break; if(notOp && b->type==0 && strcmp(b->dat.s,".")==0) { // expr . name c=b->next; if(c==NULL || c->type!=0 || !isNameChar(c->dat.s[0]) || isdigit(c->dat.s[0])) { error2nd("Error! expected identifier after . at %d\n", b->lineno); } free(b->dat.s); b->type=23; b->dat.n=a; if(c==NULL) b->next=NULL; else b->next=c->next; if(prev==NULL) node=b; else prev->next=b; a->next=c; if(c!=NULL) c->next=NULL; a=b; } else if(notOp && b->type==13) { // expr ( expr ) b->type=25; c=b->dat.n; b->dat.n=a; a->next=c; if(prev==NULL) node=b; else prev->next=b; a=b; } else { prev=a; a=a->next; } } /// new expr a=prev=node; c=NULL; while(a!=NULL) { if(c==NULL) b=a->next; else b=c; if(b==NULL) break; if(a->type==0 && strcmp(a->dat.s,"new")==0) { // new expr free(a->dat.s); a->type=27; a->dat.n=b; prev->next=c=b->next; a=b; b->next=NULL; } /*else if(a->type==13 && a->dat.n!=NULL && a->dat.n->type==0 && a->dat.n->next==NULL) { // (type) expr a->type=29; a->dat.n->next=b; prev->next=c=b->next; a=b; b->next=NULL; }*/ else { c=NULL; a=b; prev=a; } } /// expr = expr struct parseNode e,*next=node,*f=NULL; do { a=next;b=NULL; prev=&e; e.next=NULL; while(a!=NULL) { b=a->next; if(b==NULL) { prev->next=a; prev=a; next=NULL; break; } if(b->type==0 && strcmp(b->dat.s,"=")==0) { prev->next=b; free(b->dat.s); b->dat.n=a; b->type=31; a->next=NULL; prev=a; } else { prev->next=a; prev=a; next=b; a->next=NULL; break; } a=b->next; b->next=NULL; } if(a==NULL && b!=NULL) { error2nd("Error! Missing expression after = at %d\n", b->lineno); next=NULL; } prev->next=NULL; if(f==NULL) node=e.next; else f->next=e.next; f=e.next; } while(next!=NULL); if(f!=NULL) f->next=NULL; /// expr , expr a=node; prev=NULL; while(a!=NULL) { b=a->next; if(b==NULL) break; if(b->type==0 && strcmp(b->dat.s,",")==0) { c=b->next; free(b->dat.s); b->type=33; b->dat.n=a; if(c==NULL) { b->next=NULL; } else b->next=c->next; if(prev==NULL) node=b; else prev->next=b; a->next=c; if(c!=NULL) c->next=NULL; a=b; } else { prev=a; a=a->next; } } return node; }
static struct parseNode *repairPTStmt(struct parseNode *pn) { int yeah=1; struct parseNode *ptr=pn,*newPtr=pn,*prev=NULL,*prevNewPtr=NULL; while(ptr!=NULL) // semicolon ; separated nodes { if(ptr->type==0 && ptr->dat.s[0]==';') { ptr->type=19; // statement free(ptr->dat.s); if(newPtr==ptr) { ptr->dat.n=NULL; } else { ptr->dat.n=newPtr; if(prev!=NULL) prev->next=NULL; } newPtr=ptr->next; if(prevNewPtr==NULL) pn=ptr; else prevNewPtr->next=ptr; prevNewPtr=ptr; yeah=1; } else yeah=0; prev=ptr; ptr=ptr->next; } if(!yeah) { error2nd("Error! Missing semicolon ; at %d\n",prev->lineno); return pn; } ptr=pn; while(ptr!=NULL) { newPtr=ptr->dat.n; if(newPtr==NULL); else if(!(newPtr->type & 1) && isNameChar(newPtr->dat.s[0])) { if(strcmp(newPtr->dat.s,"return")==0) { // return statement ptr->type=21; ptr->dat.n=repairPT(newPtr->next); newPtr->next=NULL; freeAll(newPtr); } else { struct parseNode *q=newPtr->next; if(q!=NULL && !(q->type & 1) && isNameChar(q->dat.s[0])) { // variable declaration ptr->type=5; newPtr->next=repairPT(newPtr->next); } else { // normal statement ptr->dat.n=repairPT(ptr->dat.n); } } } else { // normal statement ptr->dat.n=repairPT(ptr->dat.n); } ptr=ptr->next; } return pn; }