コード例 #1
0
ファイル: wmo_message.c プロジェクト: Unidata/LDM
static const char *
grib_ident(size_t remaining, const char *const wmo_msg, const char *const ident)
{
	static const char nada[] = "";
	const char *cp;
	size_t len;

	cp = scanFor("GRIB", remaining, wmo_msg);
	if(!cp)
	{
		log_notice_q("%s: Can't find `GRIB'", ident);
		return nada;
	}
	remaining -= cp - wmo_msg;
	if(remaining < (8 + 28 +4))
	{
		log_notice_q("%s: way too short", ident);
		return NULL;
	}

	len = ids_len(cp);
	if(remaining < len)
	{
		log_notice_q("%s: %d bytes too short", ident, len - remaining);
		return NULL;
	}

         /* this assumes 7777\r\r\n ETX, however, some products
            may have extra \r\n's so this test is too rigid-
            The test for 7777 at expected len should suffice (Chiz)
	if(remaining > len + 8)
	{
		LOG_NOTICE("%s: garbled product", ident);
		LOG_NOTICE("remaining %d, ids_len %d", remaining, len);
		return NULL;
	} */

	if(scanFor("7777", 8, cp + len - 8) == NULL)
	{
		log_notice_q("%s: no end of product", ident);
		return NULL;
	}

	return pds_ident(cp + 8);
}
コード例 #2
0
void PluginListComponent::optionsMenuCallback (int result)
{
    switch (result)
    {
        case 0:   break;
        case 1:   list.clear(); break;
        case 2:   list.sort (KnownPluginList::sortAlphabetically); break;
        case 3:   list.sort (KnownPluginList::sortByCategory); break;
        case 4:   list.sort (KnownPluginList::sortByManufacturer); break;
        case 5:   removeSelected(); break;
        case 6:   showSelectedFolder(); break;
        case 7:   removeMissingPlugins(); break;

        default:  scanFor (formatManager.getFormat (result - 10)); break;
    }
}
コード例 #3
0
void PluginListComponent::optionsMenuCallback (int result)
{
    switch (result)
    {
        case 0:   break;
        case 1:   list.clear(); break;
        case 2:   removeSelectedPlugins(); break;
        case 3:   showSelectedFolder(); break;
        case 4:   removeMissingPlugins(); break;

        default:
            if (AudioPluginFormat* format = formatManager.getFormat (result - 10))
                scanFor (*format);

            break;
    }
}
コード例 #4
0
void PluginListComponent::timerCallback()
{
    stopTimer();
    scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
}
コード例 #5
0
ファイル: mprXml.c プロジェクト: ni-webtech/mpr-4
/*
    Lexical analyser for XML. Return the next token reading input as required. It uses a one token look ahead and 
    push back mechanism (LAR1 parser). Text token identifiers are left in the tokBuf parser buffer on exit. This Lex 
    has special cases for the states MPR_XML_ELT_DATA where we have an optimized read of element data, and 
    MPR_XML_AFTER_LS where we distinguish between element names, processing instructions and comments. 
 */
static MprXmlToken getXmlToken(MprXml *xp, int state)
{
    MprBuf      *tokBuf;
    char        *cp;
    int         c, rc;

    mprAssert(state >= 0);
    tokBuf = xp->tokBuf;

    if ((c = getNextChar(xp)) < 0) {
        return MPR_XMLTOK_EOF;
    }
    mprFlushBuf(tokBuf);

    /*
        Special case parsing for names and for element data. We do this for performance so we can return to the caller 
        the largest token possible.
     */
    if (state == MPR_XML_ELT_DATA) {
        /*
            Read all the data up to the start of the closing element "<" or the start of a sub-element.
         */
        if (c == '<') {
            if ((c = getNextChar(xp)) < 0) {
                return MPR_XMLTOK_EOF;
            }
            if (c == '/') {
                return MPR_XMLTOK_LS_SLASH;
            }
            putLastChar(xp, c);
            return MPR_XMLTOK_LS;
        }
        do {
            if (mprPutCharToBuf(tokBuf, c) < 0) {
                return MPR_XMLTOK_TOO_BIG;
            }
            if ((c = getNextChar(xp)) < 0) {
                return MPR_XMLTOK_EOF;
            }
        } while (c != '<');

        /*
            Put back the last look-ahead character
         */
        putLastChar(xp, c);

        /*
            If all white space, then zero the token buffer
         */
        for (cp = tokBuf->start; *cp; cp++) {
            if (!isspace((uchar) *cp & 0x7f)) {
                return MPR_XMLTOK_TEXT;
            }
        }
        mprFlushBuf(tokBuf);
        return MPR_XMLTOK_TEXT;
    }

    while (1) {
        switch (c) {
        case ' ':
        case '\n':
        case '\t':
        case '\r':
            break;

        case '<':
            if ((c = getNextChar(xp)) < 0) {
                return MPR_XMLTOK_EOF;
            }
            if (c == '/') {
                return MPR_XMLTOK_LS_SLASH;
            }
            putLastChar(xp, c);
            return MPR_XMLTOK_LS;
    
        case '=':
            return MPR_XMLTOK_EQ;

        case '>':
            return MPR_XMLTOK_GR;

        case '/':
            if ((c = getNextChar(xp)) < 0) {
                return MPR_XMLTOK_EOF;
            }
            if (c == '>') {
                return MPR_XMLTOK_SLASH_GR;
            }
            return MPR_XMLTOK_ERR;
        
        case '\"':
        case '\'':
            xp->quoteChar = c;
            /* Fall through */

        default:
            /*
                We handle element names, attribute names and attribute values 
                here. We do NOT handle data between elements here. Read the 
                token.  Stop on white space or a closing element ">"
             */
            if (xp->quoteChar) {
                if ((c = getNextChar(xp)) < 0) {
                    return MPR_XMLTOK_EOF;
                }
                while (c != xp->quoteChar) {
                    if (mprPutCharToBuf(tokBuf, c) < 0) {
                        return MPR_XMLTOK_TOO_BIG;
                    }
                    if ((c = getNextChar(xp)) < 0) {
                        return MPR_XMLTOK_EOF;
                    }
                }
                xp->quoteChar = 0;

            } else {
                while (!isspace((uchar) c) && c != '>' && c != '/' && c != '=') {
                    if (mprPutCharToBuf(tokBuf, c) < 0) {
                        return MPR_XMLTOK_TOO_BIG;
                    }
                    if ((c = getNextChar(xp)) < 0) {
                        return MPR_XMLTOK_EOF;
                    }
                }
                putLastChar(xp, c);
            }
            if (mprGetBufLength(tokBuf) < 0) {
                return MPR_XMLTOK_ERR;
            }
            mprAddNullToBuf(tokBuf);

            if (state == MPR_XML_AFTER_LS) {
                /*
                    If we are just inside an element "<", then analyze what we have to see if we have an element name, 
                    instruction or comment. Tokbuf will hold "?" for instructions or "!--" for comments.
                 */
                if (mprLookAtNextCharInBuf(tokBuf) == '?') {
                    /*  Just ignore processing instructions */
                    rc = scanFor(xp, "?>");
                    if (rc < 0) {
                        return MPR_XMLTOK_TOO_BIG;
                    } else if (rc == 0) {
                        return MPR_XMLTOK_ERR;
                    }
                    return MPR_XMLTOK_INSTRUCTIONS;

                } else if (mprLookAtNextCharInBuf(tokBuf) == '!') {
                    if (strncmp((char*) tokBuf->start, "![CDATA[", 8) == 0) {
                        mprAdjustBufStart(tokBuf, 8);
                        rc = scanFor(xp, "]]>");
                        if (rc < 0) {
                            return MPR_XMLTOK_TOO_BIG;
                        } else if (rc == 0) {
                            return MPR_XMLTOK_ERR;
                        }
                        return MPR_XMLTOK_CDATA;

                    } else {
                        mprFlushBuf(tokBuf);
                        rc = scanFor(xp, "-->");
                        if (rc < 0) {
                            return MPR_XMLTOK_TOO_BIG;
                        } else if (rc == 0) {
                            return MPR_XMLTOK_ERR;
                        }
                        return MPR_XMLTOK_COMMENT;
                    }
                }
            }
            trimToken(xp);
            return MPR_XMLTOK_TEXT;
        }
        if ((c = getNextChar(xp)) < 0) {
            return MPR_XMLTOK_EOF;
        }
    }

    /* Should never get here */
    mprAssert(0);
    return MPR_XMLTOK_ERR;
}
コード例 #6
0
ファイル: compiler.cpp プロジェクト: jimfinnis/lana-2
void Compiler::scanStmt() {
    char buf[256]; // temporary buffer
    int t;
    
    switch(tok->getnext()){
    case T_IDENT: // it's an expression
    case T_INT:
    case T_FLOAT:
    case T_SUB:
    case T_BITNOT:
    case T_PLING:
    case T_STRING:
    case T_BACKTICK:
    case T_OPREN:
        // deal with debugging words!
        if(!strcmp(tok->getstring(),"dumplocs")){
            cg->emit(OP_SPECIAL,0);break;
        }
        if(!strcmp(tok->getstring(),"breakpoint")){
            cg->emit(OP_SPECIAL,1);break;
        }
        
        tok->rewind(); // put the token back
        // scan the expression, might be a label
        if(!scanExpr(true))
            // clear all statements if not a func or other oddity,
            // or just a dummy for recreation purposes if in immediate mode.
            cg->emit(cg->isCompiling()?OP_ENDESTMT:OP_ENDESTMT2);
        break;
    case T_LOAD:
        {
            if(cg->isCompiling())
                error("can only run 'load' in interactive mode");
            Session *s;
            if(tok->getnext()!=T_STRING)
                error("expected a string after 'load'");
            try {
                s = new Session(ses->api);
                s->feedFile(tok->getstring());
            } catch(Exception &e){
                delete s;
                throw e;
            }
            delete s;
        }
        break;
    case T_SAVE:
        {
            if(cg->isCompiling())
                error("can only run 'save' in interactive mode");
            if(tok->getnext()!=T_STRING)
                error("expected a string after 'save'");
            const char *fname = tok->getstring();
            
            FILE *a;
            if(!strlen(fname))
                a = stdout;
            else
                a = fopen(fname,"w");
            
            if(!a)
                error("cannot open file '%s'",fname);
            
            Serialiser *ser = new Serialiser(ses);
            ser->write(a);
            if(strlen(fname))
                fclose(a);
            delete ser;
        }
        break;
    case T_SAVEVAR:
        {
            if(cg->isCompiling())
                error("can only run 'savevar' in interactive mode");
            if(tok->getnext()!=T_IDENT)
                error("expected a variable name after 'savevar'");
            const char *vname = tok->getstring();
            int vdesc = lana->consts->findOrCreateString(vname);
            if(tok->getnext()!=T_STRING)
                error("expected a string after 'savevar'");
            const char *fname = tok->getstring();
            
            // try to get the value
            Value *v;
            int id;
            id = lana->globs->find(vdesc);
            if(id>=0) {
                v = lana->globs->get(id); // it's a global
            } else {
                id = ses->findSesVar(vdesc);
                if(id<0)
                    error("variable not found: %s",lana->consts->getStr(vdesc));
                v = ses->getSesVar(id);
            }
            
            FILE *a;
            if(!strlen(fname))
                a = stdout;
            else
                a = fopen(fname,"w");
            
            if(!a)
                error("cannot open file '%s'",fname);
            
            Serialiser *ser = new Serialiser(ses);
            ser->serialiseValue(a,v,lana->consts->getStr(vdesc));
            if(strlen(fname))
                fclose(a);
            delete ser;
        }
        break;
    case T_FOR:
        scanFor();
        break;
    case T_ENDFOR:
        scanEndFor();
        break;
    case T_THIS:
        tok->rewind(); // put the token back
        if(!scanExpr(true))
            // clear all statements if not a func or other oddity,
            // or just a dummy for recreation purposes if in immediate mode.
            cg->emit(cg->isCompiling()?OP_ENDESTMT:OP_ENDESTMT2);
        break;
    case T_GOTO:
        if(!cg->isCompiling())
            error("must be compiling a function/procedure to use '%s'",tok->getstring());
        scanGoto();
        break;
    case T_ENDFUNC:
        scanEndFunc();
        break;
    case T_END:
        if(!(lana->opFlags & LOP_STRIPCOMMENTS))
            cg->emit(OP_BLANKLINE); // yes, these are wasteful .. very slightly
        break;
    case T_IF:
        // first we push a special value onto the compiler stack
        // to mark the start of this if..elseif..elseif..endif
        cg->current->cpush(-9999);
        // we scan the expression 
        if(scanExpr())
            error("cannot use a function/procedure expression in if");
        // stack and output an incomplete if - but this might be a normal if, or a quick if.
        cg->current->cpushhere();
        
        // now for some cleverness. Is the next token a colon?
        if(tok->getnext() == T_COLON){
            cg->emit(OP_QUICKIF,-100);
            // if so, parse the next statement recursively
            scanStmt();
            // note that we don't need to output a quick endif, since the recreator
            // doesn't need it!
            instruction *ptr = cg->current->cpoplocandcheck(OP_QUICKIF,OP_QUICKIF); // MUST be an OP_IF, no ELSE.
            if(!ptr)
                error("not a simple statement in quick-if");
            // write the IF, ELSE or ELSEIF again with the correct distance
            *ptr = INST(INSTOP(*ptr),cg->current->getdiff(ptr));
            // now pop off!
            int n;
            do{
                n = cg->current->cpop();
            }while(n!=-9999);
        } else {
            // not - put it back!
            tok->rewind();
            cg->emit(OP_IF,-100);
        }
        break;
    case T_ENDIF:
        {
            // get the corresponding OP_IF, OP_ELSEIF or OP_ELSE
            cg->emit(OP_ENDIF);
            instruction *ptr = cg->current->cpoplocandcheck(OP_IF,OP_ELSE);
            if(!ptr)
                error("mismatched endif");
            // write the IF, ELSE or ELSEIF again with the correct distance
            *ptr = INST(INSTOP(*ptr),cg->current->getdiff(ptr));
            
            // now pop and fixup OP_JMPELSEIFs until we get the special -9999 which marked the start
            
            for(;;){
                int n = cg->current->cpop();
                if(n==-9999)break; // we're done!
                // we're not done - get the code pointer
                instruction *ptr = cg->current->getPtr(n*sizeof(instruction));
                // make sure it's a OP_JMPELSEIF!
                if(INSTOP(*ptr)!=OP_JMPELSEIF)
                    error("badly formed conditional statement");
                // change it so that it jumps to the current location
                *ptr = INST(INSTOP(*ptr),cg->current->getdiff(ptr));
            }
        }
        break;
    case T_ELSEIF:
        {
            // pop the instruction off the stack, an OP_IF or OP_ELSEIF
            instruction *ptr = cg->current->cpoplocandcheck(OP_IF,OP_ELSEIF);
            // first we need to terminate the previous condition, so
            // push the location and output a OP_JMPELSEIF ready to fill in.
            // This will get left on the stack!
            cg->current->cpushhere();
            cg->emit(OP_JMPELSEIF,-100);
            // now make the IF or ELSEIF we popped jump to this point
            *ptr = INST(INSTOP(*ptr),cg->current->getdiff(ptr));
            
            // now scan the expression
            if(scanExpr())
                error("cannot use a function/procedure expression in if");
            // push the location, and..
            // output an OP_ELSEIF with a dummy jump
            cg->current->cpushhere();
            cg->emit(OP_ELSEIF,-100);
        }
        break;
    case T_ELSE:
        {
            // write the OP_ELSE which will become a jump forward,
            // but first recording the location
            int elseloc = cg->current->getloc();
            cg->emit(OP_ELSE,-100);
            // now we need to make the IF jump to here
            // get the corresponding OP_IF or OP_ELSEIF
            instruction *ptr = cg->current->cpoplocandcheck(OP_IF,OP_ELSEIF);
            if(!ptr)
                error("mismatched else");
            // write the IF again with the correct jump distance
            int diff = cg->current->getdiff(ptr);
            *ptr = INST(INSTOP(*ptr),diff);
            // now push the location of the OP_ELSE, which
            // will get processed by the OP_ENDIF
            cg->current->cpush(elseloc);
        }
        break;
        // pop the location
    case T_RETURN:
        if(!cg->isCompiling())
            error("must be compiling a function/procedure to use '%s'",tok->getstring());
        if(tok->getnext() == T_END){ // end of line?
            tok->rewind();
            // no return value
            if(cg->current->ldth.flags & LDTF_RETURNS)
                error("functions must return a value");
            cg->emit(OP_RETURN,0);
        } else {
            tok->rewind();
            if(!(cg->current->ldth.flags & LDTF_RETURNS))
                error("procedures cannot return a value");
            if(scanExpr())
                error("cannot directly return a function");
            cg->emit(OP_RETURN,1);
        }
        break;
    case T_WHILE:
        if(!cg->isCompiling())
            error("must be compiling a function/procedure to use '%s'",tok->getstring());
        // push the current location onto the stack - this is where ENDWHILE will
        // jump to
        cg->current->cpushhere();
        // we also create and push the loop data here, so that we can use break and
        // continue!
        cg->current->newloop();
        // scan and output the expression
        if(scanExpr())
            error("cannot use a function/procedure expression in `while`");
        // push the WHILE onto the stack so we can write the terminating jump into it
        cg->current->cpushhere();
        // output OP_WHILE with a dummy
        cg->emit(OP_WHILE,-100);
        break;
    case T_ENDWHILE:
        {
            // pop the location of the WHILE from the stack
            instruction *whileptr = cg->current->cpoplocandcheck(OP_WHILE,OP_WHILE);
            if(!whileptr)
                error("mismatched endwhile");
            // pop the location for the backward jump
            instruction *jumpdest = cg->current->cpoplocation();
            // output the endwhile, which will do the backward jump
            cg->emit(OP_ENDWHILE,cg->current->getdiff(jumpdest));
            // now patch the while instruction with the forward jump to use if the
            // condition is false
            *whileptr = INST(OP_WHILE,cg->current->getdiff(whileptr));
            /// and end the loop, setting the break label and popping the loop stack
            cg->current->endloop();
            break;
        }
        
    case T_REPEAT:
        if(!cg->isCompiling())
            error("must be compiling a function/procedure to use '%s'",tok->getstring());
        // output OP_REPEAT, pushing its location. We don't
        // jump to here, though - we jump to the following opcode.
        // This is done just so we can check that the until matches
        // a repeat. See T_UNTIL.
        cg->current->cpushhere();
        cg->current->newloop(); // push and initialise a new loop stack entry (see T_WHILE above)
        cg->emit(OP_REPEAT,0);
        break;
    case T_UNTIL:
        {
            // scan and output the expression
            if(scanExpr())
                error("cannot use a function/procedure expression in `until`");
            // pop the location of the OP_REPEAT from the stack
            instruction *ptr = cg->current->cpoplocandcheck(OP_REPEAT,OP_REPEAT);
            if(!ptr)
                error("mismatched `until'");
            // increment this, because we want to save cycles by
            // jumping past the OP_REPEAT (which is a kind of noop)
            ptr++;
            // and output the OP_UNTIL jump
            cg->emit(OP_UNTIL,cg->current->getdiff(ptr));
            cg->current->endloop(); // end the current loop stack entry (see T_ENDWHILE above)
            break;
        }
    case T_BREAK:
        {
            // we want to break out of the topmost loop on the loop stack
            
            // get address we're about to write to
            instruction *op = cg->current->getlocptr();
            // output the break which will be patched later
            cg->emit(OP_BREAK,-100);
            // and this jump as a jump to be patched when the break label is resolved
            LoopData *d = cg->current->loopstack.peekptr();
            if(!d)
                throw ParseException("break with no loop");
            d->breaklabel.jumpFrom(op);
        }
        break;
    case T_CONTINUE:
        {
            // we want to terminate the current iteration of the topmost loop on the loop stack
            // and immediately start the loop code again
            // get address we're about to write to
            instruction *op = cg->current->getlocptr();
            // output the break which will be patched later
            cg->emit(OP_CONTINUE,-100);
            // and this jump as a jump to be patched when the break label is resolved
            LoopData *d = cg->current->loopstack.peekptr();
            if(!d)
                throw ParseException("continue with no loop");
            d->continuelabel.jumpFrom(op);            
        }
        break;
    case T_COMMENT:
        scanComment(true);
        break;
    default:
        error("unexpected token '%s'",tok->getstring());
    }
    
    // see if there's a comment at the end
    scanPossibleComment();
    
    if(tok->getnext()!=T_END)
        error("trailing garbage at end of line");
}