Пример #1
0
int main(int argc, const char *argv[]) {
    char from[MAX_GROUP_NAME];
    char message[MAX_MESSLEN];
    membership_info memb_info;
    int num_groups;
    char target_groups[100][MAX_GROUP_NAME];
    int16 mess_type;
    int endian_mismatch;

    int service_type;
    int loop = 1;
    int rc;
    int ret;
    int i;

    sqlite3 *mydb;
    char *dbName;
    char *zErrMsg;

    connectionStatus status = UNKNOWN;

    char buffer[MAX_GROUP_NAME];
    char sqlBuffer[1024];
    char *member;
    char *host;
    char *tok;
    char ch;
    extern char *optarg;

    char scratch[255];

    global.connected=0;
    global.Group=(char *)NULL;
    global.configFileName=(char *)NULL;
    global.locked = 0;
    global.rawClient =1;
    global.debug = 0;

#ifdef FICL
    global.appDir=(char *)NULL;
#endif

    char *group=(char *)NULL;

    setSymbol("BUILD",__DATE__,LOCK,LOCAL);
    setSymbol("CLIENT","raw",UNLOCK,GLOBAL);
    setSymbol("SPREAD_SERVER","4803",UNLOCK,GLOBAL);
    setSymbol("GROUP","global",UNLOCK,GLOBAL);
    setSymbol("USER","dbCache",LOCK,GLOBAL);
    setSymbol("DEBUG","false",UNLOCK,GLOBAL);
    setSymbol("MODE","local",UNLOCK,GLOBAL);
    setSymbol("START_FILE","./dbCache.rc",UNLOCK,GLOBAL);

    while((ch = getopt(argc, ( char **)argv,"dhc:")) != -1) {
        switch(ch) {
            case 'c':
                setSymbol("START_FILE", optarg,LOCK,GLOBAL);
                break;
            case 'd':
                global.debug=1;
                break;
            case 'h':
                usage();
                exit(0);
                break;
        }
    }

    loadFile(getSymbol("START_FILE"));

    if( global.debug ) {
        setBoolean("DEBUG",1);
    }

    global.debug = getBoolean("DEBUG");

    if(global.debug) {
        dumpGlobals();
        dumpSymbols();
    }

    dbName = getSymbol("DATABASE");

    connectToSpread();

    while(loop) {
        status = UNKNOWN;
        ret = SP_receive(global.Mbox, &service_type, from, 100,
                &num_groups, target_groups,
                &mess_type, &endian_mismatch, sizeof(message), message);

        if (Is_membership_mess (service_type)) {
            ret = SP_get_memb_info(message, service_type, &memb_info);

            if (Is_caused_join_mess(service_type)) {
                status=JOINED;
            } 
            if (Is_caused_leave_mess (service_type)) {
                status = LEFT;
            } 
            if (Is_caused_disconnect_mess (service_type)) {
                status = DISCONNECTED;
            } 
            if (Is_caused_network_mess (service_type)) {
                status = NETWORK;
            }

            rc = sqlite3_open(dbName, &mydb);
            for (i = 0; i < num_groups; i++) {

                if( global.debug) {
                    printf("\t%s\n",(char *) &target_groups[i][0]);
                }

                strcpy(buffer, &target_groups[i][1]);

                member=strtok(buffer,"#");
                host=strtok(NULL,"#");

                if( global.debug) {
                    printf("\t\tMember:%s\n", member);
                    printf("\t\tHost  :%s\n", host);
                }

                statusToText( status, scratch );

                if (JOINED == status ) {
                    sprintf( sqlBuffer,"insert or replace into status  ( member, host, grp, state ) values ( '%s','%s','%s','%s');", member, host,from,scratch);
                }
                if( global.debug) {
                    printf ("%s\n",sqlBuffer);
                }
                rc = sqlite3_exec(mydb, sqlBuffer, 0, 0, &zErrMsg);
            }
            strcpy(buffer, &memb_info.changed_member[1]);
            member=strtok(buffer,"#");
            host=strtok(NULL,"#");

            statusToText( status, scratch );
            sprintf( sqlBuffer, "update status set state='%s' where member = '%s' and host ='%s';",scratch, member,host);

            if( global.debug) {
                printf("CHANGE: %s %s\n",member,host);
                printf("CHANGE: %s\n", scratch);
                printf ("%s\n",sqlBuffer);
            }

            rc = sqlite3_exec(mydb, sqlBuffer, 0, 0, &zErrMsg);

            sqlite3_close(mydb);

        }

    }


    printf("============ After\n");
    dumpGlobals();

    printf("Sender %s\n",from);
    printf("Message >%s<\n",message);

    toSpread(from,"Message recieved\n");

    spreadJoin("TEST");

    sleep(2);

    spreadLeave("TEST");

    sleep(2);

    spreadDisconnect();
}
Пример #2
0
int qml_interface::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            itFogz();
            break;
        case 1:
            destroyAll();
            break;
        case 2:
            fair();
            break;
        case 3:
            pCloudy();
            break;
        case 4:
            cloudy();
            break;
        case 5:
            rain();
            break;
        case 6:
            thunder();
            break;
        case 7:
            snow();
            break;
        case 8:
            updateSlot();
            break;
        case 9:
            replyFinished((*reinterpret_cast< QNetworkReply*(*)>(_a[1])));
            break;
        case 10: {
            QString _r = getWindSpeed();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 11: {
            QString _r = getWindDirection();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 12: {
            QString _r = getTemperature();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 13: {
            QString _r = getTime();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 14: {
            QString _r = depsurx();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 15: {
            QString _r = arvsurx();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 16: {
            QString _r = depsury();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 17: {
            QString _r = arvsury();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 18: {
            QString _r = depsurz();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 19: {
            QString _r = arvsurz();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 20: {
            QString _r = getNextUpdate();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 21: {
            QString _r = getFrequence();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 22: {
            QString _r = getSymbol();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 23:
            ItFogs();
            break;
        case 24: {
            int _r = getPositionCiel();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r;
        }
        break;
        case 25:
            setSymbol();
            break;
        case 26: {
            QString _r = getRandomInteger();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        default:
            ;
        }
        _id -= 27;
    }
#ifndef QT_NO_PROPERTIES
    else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0:
            *reinterpret_cast< Forecast*>(_v) = getCurrentForecast();
            break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::WriteProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 1;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #3
0
void Entity::dumpObjectData() {
	std::cout << "\tname: " << getName() << std::endl;
	std::cout << "\tsymbol: " << getSymbol() << std::endl;
}
Пример #4
0
String Grammar::getProductionString(int prod) const {
  return getSymbol(m_productions[prod].m_leftSide).m_name
       + _T(" -> ")
       + getRightSide(prod);
}
Пример #5
0
void GetRexxBlock( ss_block *ss_new, char *start, line *line, linenum line_no )
{
    line = line;
    line_no = line_no;

    if( start[0] == '\0' ) {
        if( firstNonWS == start ) {
            // line is empty -
            // do not flag following line as having anything to do
            // with an unterminated " or # or // from previous line
            flags.inString = flags.inPreprocessor = flags.inCPPComment = false;
        }
        getBeyondText( ss_new );
        return;
    }

    if( flags.inCComment ) {
        getCComment( ss_new, start, 0 );
        return;
    }
    if( flags.inCPPComment ) {
        getCPPComment( ss_new, start );
        return;
    }
    if( flags.inPreprocessor ) {
        getPreprocessor( ss_new, start );
        return;
    }
    if( flags.inString ) {
        getString( ss_new, start, 0 );
        return;
    }

    if( isspace( start[0] ) ) {
        getWhiteSpace( ss_new, start );
        return;
    }

    if( *firstNonWS == '#' &&
        (!EditFlags.PPKeywordOnly || firstNonWS == start) ) {
        getPreprocessor( ss_new, start );
        return;
    }

    switch( start[0] ) {
        case '"':
            getString( ss_new, start, 1 );
            return;
        case '/':
            if( start[1] == '*' ) {
                getCComment( ss_new, start, 2 );
                return;
            } else if( start[1] == '/' ) {
                getCPPComment( ss_new, start );
                return;
            }
            break;
        case '\'':
            getChar( ss_new, start, 1 );
            return;
        case 'L':
            if( start[1] == '\'' ) {
                // wide char constant
                getChar( ss_new, start, 2 );
                return;
            }
            break;
        case '.':
            if( isdigit( start[1] ) ) {
                getFloat( ss_new, start, 1, AFTER_DOT );
                return;
            }
            break;
        case '0':
            if( start[1] == 'x' || start[1] == 'X' ) {
                getHex( ss_new, start );
                return;
            } else {
                getNumber( ss_new, start, '7' );
                return;
            }
            break;
    }

    if( issymbol( start[0] ) ) {
        getSymbol( ss_new );
        return;
    }

    if( isdigit( start[0] ) ) {
        getNumber( ss_new, start, '9' );
        return;
    }

    if( isalpha( *start ) || ( *start == '_' ) ) {
        getText( ss_new, start );
        return;
    }

    getInvalidChar( ss_new );
}
Пример #6
0
void GetPerlBlock( ss_block *ss_new, char *start, line *line, linenum line_no )
{
    line = line;
    line_no = line_no;

    if( start[0] == '\0' ) {
        if( firstNonWS == start ) {
            // line is empty -
            // do not flag following line as having anything to do
            // with an unterminated " or # or // from previous line
            flags.inString = false;
        }
        getBeyondText( ss_new );
        return;
    }

    if( flags.inString ) {
        getString( ss_new, start, 0 );
        return;
    }

    if( isspace( start[0] ) ) {
        getWhiteSpace( ss_new, start );
        return;
    }

    switch( start[0] ) {
        case '#':
            getPerlComment( ss_new, start );
            return;
        case '"':
            getString( ss_new, start, 1 );
            return;
        case '/':
            if( flags.beforeRegExp ) {
                getRegExp( ss_new, start );
                return;
            }
            break;
        case '$':
        case '@':
        case '%':
            if( isalpha( start[1] ) || (start[0] == '$' && start[1] == '#') ) {
                getVariable( ss_new, start );
                return;
            } else if( start[0] == '$' &&
                       (isdigit( start[1] ) || isspecvar( start[1] )) ) {
                getSpecialVariable( ss_new, start );
                return;
            }
            break;
        case '\'':
            getChar( ss_new, start, 1 );
            return;
        case '.':
            if( isdigit( start[1] ) ) {
                getFloat( ss_new, start, 1, AFTER_DOT );
                return;
            }
            break;
        case '0':
            if( start[1] == 'x' || start[1] == 'X' ) {
                getHex( ss_new, start );
                return;
            } else {
                getNumber( ss_new, start, '7' );
                return;
            }
            break;
    }

    if( issymbol( start[0] ) ) {
        getSymbol( ss_new, start );
        return;
    }

    if( isdigit( start[0] ) ) {
        getNumber( ss_new, start, '9' );
        return;
    }

    if( isalpha( *start ) || (*start == '_') ) {
        getText( ss_new, start );
        return;
    }

    getInvalidChar( ss_new );
}
Пример #7
0
void Player::start() {
    isOn_ = true;
    isEndOfWord_ = false;
    character_ = message_;
    getSymbol();
}
Пример #8
0
bool VariableTable::isNestedStatic(const string &name) const {
  const Symbol *sym = getSymbol(name);
  return sym && sym->isNestedStatic();
}
Пример #9
0
bool VariableTable::isLvalParam(const string &name) const {
  const Symbol *sym = getSymbol(name);
  return sym && sym->isLvalParam();
}
Пример #10
0
	//----------------------------------------------------------------------------------
	Result Plugin::initialize(PropertyList* params)
	{
		NR_Log(Log::LOG_ENGINE, Log::LL_DEBUG, "Check if the loaded library is valid plugin");

		// get version information
		m_plgEngineVersion = (plgEngineVersion)getSymbol("plgEngineVersion");
		m_plgVersionString = (plgVersionString)getSymbol("plgVersionString");

		if (!m_plgEngineVersion || !m_plgVersionString)
		{
			NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, "Plugin seems not to be written for the nrEngine");
			NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, "plgVersionString/plgEngineVersion symbols were not found!!!");
			return PLG_SYMBOL_NOT_FOUND;
		}

		// Log this
		NR_Log(Log::LOG_ENGINE, "Plugin found: %s written for nrEngine v%s", m_plgVersionString(), convertVersionToString(m_plgEngineVersion()).c_str());

		// check if plugin is working with the current engine version
		if (m_plgEngineVersion() > nrEngineVersion){
			NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, "Plugin has got greater version as the engine, so plugin not loaded");
			return PLG_WRONG_VERSION;
		}

		// log something
		NR_Log(Log::LOG_PLUGIN, "Initialize plugin %s", getResourceName().c_str());

#define GET_SYMBOL(var, type)\
		{\
			NR_Log(Log::LOG_ENGINE, Log::LL_DEBUG, "Get plugin symbol %s", #type);\
			var = (type)getSymbol(#type);\
			if (!var){\
				NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, "Plugin symbol %s was not found", #type);\
				return PLG_SYMBOL_NOT_FOUND;\
			}\
		}

		// Get plugin symbols
		GET_SYMBOL(m_plgInitialize, plgInitialize);
		GET_SYMBOL(m_plgError, plgError);
		GET_SYMBOL(m_plgRelease, plgRelease);
#undef GET_SYMBOL

		// call the function and check for return code
		int result = m_plgInitialize(Engine::instance(), params);

		// check for error
		if (result != 0){
			NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, "Plugin returns error %d (%s). See plugin log for more detail information", result, m_plgError(result));
			return PLG_EXTERNAL_ERROR;
		}

		// now get some extra symbols
		/*m_plgGetMethods = (plgGetMethods)getSymbol("plgGetMethods");
		m_plgCall = (plgCall)getSymbol("plgCall");

		if (m_plgGetMethods){

			// get the list of methods provided by this plugin
			m_plgGetMethods(mPlgMethods);

			NR_Log(Log::LOG_ENGINE, Log::LL_DEBUG, "Plugin provides following symbols: ");

			// now go through each of this method and print some log info about it
			for (uint32 i=0; i < mPlgMethods.size(); i++){
				std::string params;				
				for (uint32 j=0; j < mPlgMethods[i].param.size(); j++){
					params += mPlgMethods[i].param[j].name;
					if (j < mPlgMethods[i].param.size() - 1) params += ", ";
				}
				NR_Log(Log::LOG_ENGINE, Log::LL_DEBUG, "  found  -  %s (%s)", mPlgMethods[i].name.c_str(), params.c_str());
			}		
		}*/
		
		// all right!
		return OK;
	}
Пример #11
0
bool VariableTable::isPrivate(const string &name) const {
  const Symbol *sym = getSymbol(name);
  return sym && sym->isPrivate();
}
Пример #12
0
	char * getCommandName(){
		return getSymbol(0);
	}	
Пример #13
0
	char * getArgument(int i){
		return getSymbol( i +1);
	}
Пример #14
0
void statement(int varCount)
{
    int changeSpot = 0;
    int sym;
    symbol localSymbolHolder;
    int localVarCount = varCount;
    if(token.sym == identsym)
    {
        //printf("\n\nThe token word is : %s\n\n", token.word);
        //printf("The symbol word is : %s\n", symbol_table[1].name);
        if(isSymbol(token.word))
            localSymbolHolder = symbol_table[getSymbol(token.word)];
        else
            getError(11);
        getToken();
    if(token.sym != becomessym)
        getError(5);
    getToken();
    expression();
    enter(var,localSymbolHolder.name,0,0,getTop());
    emit(4, 0, localSymbolHolder.addr);
   // printf("\n\nThe TOS IS %d\n\n", getTop());
    }
    else if(token.sym == callsym)
    {
        getToken();
        if(token.sym != identsym)
            getError(2);
        getToken();
    }
    else if(token.sym == beginsym)
    {
        emit(6, 0, 4 + localVarCount);
        getToken();
        statement(localVarCount);
        while(token.sym == semicolonsym)
        {
            getToken();
            statement(localVarCount);
        }
        if(token.sym != endsym)
             getError(6);
        getToken();
    }
    else if(token.sym == ifsym)
    {
        getToken();
        changeSpot = condition();
        if(token.sym != thensym)
            getError(6);
        getToken();
        statement(localVarCount);
    }
    else if(token.sym == whilesym)
    {
        getToken();
        condition();
        if(token.sym != dosym)
            getError(7);
        getToken();
        statement(localVarCount);
    }
   // printf("\n\nThe change spot and codespot  is: %d, %d\n\n", changeSpot, codeSpot);
    if(changeSpot != 0)
        code3[(changeSpot * 3) + 2] =codeSpot;
}
Пример #15
0
void GetFORTRANBlock( ss_block *ss_new, char *start, int text_col )
{
    int length = 0;
    if( start[0] == '\0' ) {
        if( text_col == 0 ) {
            // line is empty -
            // do not flag following line as having anything to do
            // with an unterminated string from previous line
            flags.inString = false;
        }
        getBeyondText( ss_new );
        return;
    }

    if( iscomment( firstChar ) ) {
        getComment( ss_new, start );
        return;
    }

    if( text_col <= 4 ) {
        getLabelOrWS( ss_new, start, text_col );
        return;
    }

    if( text_col == 5 ) {
        getContinuationOrWS( ss_new, start );
        return;
    }

    if( flags.inString ) {
        getLiteral( ss_new, start, 0 );
        return;
    }

    if( isspace( start[0] ) ) {
        getWhiteSpace( ss_new, start );
        return;
    }

    switch( start[0] ) {

    case '!':
        getComment( ss_new, start );
        return;
    case '\'':
        getLiteral( ss_new, start, 1 );
        return;
    case '.':
        if( isdigit( start[1] ) ) {
            getFloat( ss_new, start, 1, AFTER_DOT );
            return;
        }
        length = islogical( start );
        if( length > 0 ){
            getSymbol( ss_new, length );
            return;
        }
    }

    if( issymbol( start[0] ) ) {
        getSymbol( ss_new, 1 );
        return;
    }

    if( isdigit( *start ) ) {
        getNumber( ss_new, start );
        return;
    }

    if( isalpha( *start ) || (*start == '_') || (*start == '$') ) {
        getText( ss_new, start );
        return;
    }

    getInvalidChar( ss_new );
}
Пример #16
0
bool VariableTable::isNeeded(const string &name) const {
  const Symbol *sym = getSymbol(name);
  return sym && sym->isNeeded();
}
Пример #17
0
void Rest::layout()
      {
      if (staff() && staff()->isTabStaff()) {
            // no rests for tablature
            _space.setLw(0.0);
            _space.setRw(0.0);
            return;
            }
      switch(durationType().type()) {
            case TDuration::V_64TH:
            case TDuration::V_32ND:
                  dotline = -3;
                  break;
            case TDuration::V_256TH:
            case TDuration::V_128TH:
                  dotline = -5;
                  break;
            default:
                  dotline = -1;
                  break;
            }
      qreal _spatium = spatium();
      int stepOffset     = 0;
      if (staff())
            stepOffset = staff()->staffType()->stepOffset();
      int line        = lrint(userOff().y() / _spatium); //  + ((staff()->lines()-1) * 2);
      int lineOffset  = 0;

      int lines = staff() ? staff()->lines() : 5;
      if (segment() && measure() && measure()->mstaff(staffIdx())->hasVoices) {
            // move rests in a multi voice context
            bool up = (voice() == 0) || (voice() == 2);       // TODO: use style values
            switch(durationType().type()) {
                  case TDuration::V_LONG:
                        lineOffset = up ? -3 : 5;
                        break;
                  case TDuration::V_BREVE:
                        lineOffset = up ? -3 : 5;
                        break;
                  case TDuration::V_MEASURE:
                        if (duration() >= Fraction(2, 1))    // breve symbol
                              lineOffset = up ? -3 : 5;
                        // fall through
                  case TDuration::V_WHOLE:
                        lineOffset = up ? -4 : 6;
                        break;
                  case TDuration::V_HALF:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_QUARTER:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_EIGHT:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_16TH:
                        lineOffset = up ? -6 : 4;
                        break;
                  case TDuration::V_32ND:
                        lineOffset = up ? -6 : 6;
                        break;
                  case TDuration::V_64TH:
                        lineOffset = up ? -8 : 6;
                        break;
                  case TDuration::V_128TH:
                        lineOffset = up ? -8 : 8;
                        break;
                  case TDuration::V_256TH:             // not available
                        lineOffset = up ? -10 : 6;
                        break;
                  default:
                        break;
                  }
            }
      else {
            switch(durationType().type()) {
                  case TDuration::V_LONG:
                  case TDuration::V_BREVE:
                  case TDuration::V_MEASURE:
                  case TDuration::V_WHOLE:
                        if (lines == 1)
                              lineOffset = -2;
                        break;
                  case TDuration::V_HALF:
                  case TDuration::V_QUARTER:
                  case TDuration::V_EIGHT:
                  case TDuration::V_16TH:
                  case TDuration::V_32ND:
                  case TDuration::V_64TH:
                  case TDuration::V_128TH:
                  case TDuration::V_256TH:             // not available
                        if (lines == 1)
                              lineOffset = -4;
                        break;
                  default:
                        break;
                  }
            }

      int yo;
      _sym = getSymbol(durationType().type(), line + lineOffset/2, lines, &yo);
      layoutArticulations();
      rypos() = (qreal(yo) + qreal(lineOffset + stepOffset) * .5) * _spatium;

      Spatium rs;
      if (dots()) {
            rs = Spatium(score()->styleS(ST_dotNoteDistance)
               + dots() * score()->styleS(ST_dotDotDistance));
            }
      Segment* s = segment();
      if (s && s->measure() && s->measure()->multiMeasure()) {
            qreal _spatium = spatium();
            qreal h = _spatium * 6.5;
            qreal w = point(score()->styleS(ST_minMMRestWidth));
            setbbox(QRectF(-w * .5, -h + 2 * _spatium, w, h));
            }
      else {
            if (dots()) {
                  rs = Spatium(score()->styleS(ST_dotNoteDistance)
                     + dots() * score()->styleS(ST_dotDotDistance));
                  }
            setbbox(symbols[score()->symIdx()][_sym].bbox(magS()));
            }
      _space.setLw(0.0);
      _space.setRw(width() + point(rs));
      }
Пример #18
0
bool VariableTable::isSuperGlobal(const string &name) const {
  const Symbol *sym = getSymbol(name);
  return sym && sym->isSuperGlobal();
}
Пример #19
0
void evaluateNextOperation() {
    
    Operator operator = popOperatorFromStack(&operatorStack, &operatorFunctionIndex);
    
    if (operator != oprOpenParenthesis && operator != oprComma) {
        
        // Function call
        if (operator == oprFunctionCall) {
            
            SymbolTableRow* functionSymbol = getSymbol(operatorFunctionIndex, 0);
            SymbolTableId functionSymbolTable = functionSymbol->symbolTable;
            
            int parameterCount = functionSymbol->dimensionSizes->Integer;
            
            OperandStack* parameters = NULL;
            
            // Reverse parameters order
            for (int i = 0; i < parameterCount; i++) {
                pushOperandToStack(&parameters, popOperandFromStack(&operandStack));
            }
            
            int parameterId = 0;
            SymbolTableRow* parameterSymbol = getSymbol(parameterId, functionSymbolTable);
            
            while (parameterSymbol->category == scParameter) {
                Operand parameter = popOperandFromStack(&parameters);
                generatePassingParameter(parameter, parameterSymbol->address, parameterSymbol->totalSize);
                parameterId++;
                parameterSymbol = getSymbol(parameterId, functionSymbolTable);
            }
            
            temporaryVariablesCounter++;
            
            generateFunctionCall(functionSymbol->address, cumulativeAddress + temporaryVariablesCounter, functionSymbol->totalSize);
            
            generateNewTemporaryVariable();
            
            Operand result = { opdtTemporary, functionSymbol->type, cumulativeAddress + temporaryVariablesCounter };
            pushOperandToStack(&operandStack, result);

        }
        // Scan
        else if (operator == oprScan) {
        
            OperandStack* inputVariables = NULL;
        
            while (operandStack != NULL) pushOperandToStack(&inputVariables, popOperandFromStack(&operandStack));
            
            while (inputVariables != NULL) {
                Operand input = popOperandFromStack(&inputVariables);
                if (input.operandSymbolType == stString) {
                    generateStringScan(input.value);
                } else if (input.operandSymbolType == stInt) {
                    generateIntScan(input.value);
                } else if (input.operandSymbolType == stBoolean) {
                    generateBooleanScan(input.value);
                }
                else {
                    // Error: invalid type
                }
            }
            
        }
        // Print
        else if (operator == oprPrint) {
            
            OperandStack* outputOperands = NULL;
            
            while (operandStack != NULL) pushOperandToStack(&outputOperands, popOperandFromStack(&operandStack));
            
            while (outputOperands != NULL) {
                Operand output = popOperandFromStack(&outputOperands);
                if (output.type == opdtString || output.operandSymbolType == stString) generateStringPrint(output);
                else if (output.type == opdtInteger || output.operandSymbolType == stInt) generateIntPrint(output);
                else if (output.type == opdtBoolean || output.operandSymbolType == stBoolean) generateBooleanPrint(output);
            }
            
        }
        // Operations
        else {
            
            Operand leftOperand;
            Operand rightOperand = popOperandFromStack(&operandStack);
            
            // Attribution
            if (operator == oprEqualSign) {
                
                // Pop left operand
                leftOperand = popOperandFromStack(&operandStack);
                
                if (leftOperand.type == opdtVariable) generateAttribution(leftOperand, rightOperand);
                else {
                    // Error: invalid operation
                }
                
            } else {
                
                int resultType = -1;
                
                // Binary operators
                if (operator > oprMinus) {
                    
                    // Pop left operand
                    leftOperand = popOperandFromStack(&operandStack);
                    
                    // If both operands are not temporary variables, create a new temporary variable
                    temporaryVariablesCounter++;
                    if (leftOperand.type != opdtTemporary && rightOperand.type != opdtTemporary) generateNewTemporaryVariable();
                    else temporaryVariablesCounter --;
                    
                    // Generate code
                    switch (operator) {
                            
                        case oprAdd:
                        case oprSubtract:
                        case oprMultiply:
                        case oprDivide:
                            generateArithmeticOperation(operator, leftOperand, rightOperand,  cumulativeAddress + temporaryVariablesCounter);
                            resultType = stInt;
                            break;
                            
                            
                        case oprSmallerThan:
                        case oprSmallerOrEqualThan:
                        case oprBiggerThan:
                        case oprBiggerOrEqualThan:
                            generateRelationalComparison(operator, leftOperand, rightOperand, cumulativeAddress + temporaryVariablesCounter);
                            resultType = stBoolean;
                            break;
                            
                        case oprLogicAnd:
                        case oprLogicOr:
                            generateLogicalOperation(operator, leftOperand, rightOperand, cumulativeAddress + temporaryVariablesCounter);
                            resultType = stBoolean;
                            break;
                            
                        default:
                            // Error: invalid operator
                            break;
                            
                    }
                    
                }
                // Unary operators
                else {
                    
                    // If operand is not a temporary variable, create a new temporary variable.
                    temporaryVariablesCounter++;
                    if (rightOperand.type != opdtTemporary) generateNewTemporaryVariable();
                    else temporaryVariablesCounter --;
                    
                    // Generate code
                    switch (operator) {
                            
                        default:
                            // Error: invalid operator
                            break;
                            
                    }
                    
                }
                
                // Push result operand to stack
                Operand result = { opdtTemporary, resultType, cumulativeAddress + temporaryVariablesCounter };
                pushOperandToStack(&operandStack, result);
                
            }
            
        }
        
    }

}
Пример #20
0
bool VariableTable::isLocal(const string &name) const {
  return isLocal(getSymbol(name));
}
Пример #21
0
void Grammar::checkStateIsConsistent(const LR1State &state, StateResult &result) {
  BitSet symbolsDone(getSymbolCount());
  const int itemCount = (int)state.m_items.size();

  for(int i = 0; i < itemCount; i++) {
    const LR1Item &item = state.m_items[i];
    if(isShiftItem(item)) {
      const int t = getShiftSymbol(item);
      if(symbolsDone.contains(t)) {
        continue;
      }
      for(int j = 0; j < itemCount; j++) {
        if(j == i) {
          continue;
        }
        const LR1Item &item1 = state.m_items[j];
        if(isReduceItem(item1) && item1.m_la.contains(t)) {
          const GrammarSymbol &terminal = getSymbol(t);
          switch(resolveShiftReduceConflict(terminal, item1)) {
          case CONFLICT_NOT_RESOLVED:
            m_SRconflicts++;
            result.m_errors.add(format(_T("Shift/reduce conflict. Shift or reduce by prod %-3d (prec=%d) on '%s' (prec=%d, %s).")
                                      ,item1.m_prod
                                      ,getProduction(item1).m_precedence
                                      ,terminal.m_name.cstr()
                                      ,terminal.m_precedence
                                      ,terminal.getTypeString()));
            break;
          case CHOOSE_SHIFT:
            result.m_actions.add(ParserAction(t, item.getSuccessor()));
            symbolsDone += t;
            result.m_warnings.add(format(_T("Shift/reduce conflict on %s (prec=%d, %s). Choose shift instead of reduce by prod %d (prec=%d).")
                                        ,terminal.m_name.cstr()
                                        ,terminal.m_precedence
                                        ,terminal.getTypeString()
                                        ,item1.m_prod
                                        ,getProduction(item1).m_precedence));
            m_warningCount++;
            break;
          case CHOOSE_REDUCE:
            result.m_actions.add(ParserAction(t, -item1.m_prod));
            symbolsDone += t;
            result.m_warnings.add(format(_T("Shift/reduce conflict on %s (prec=%d, %s). Choose reduce by prod %d (prec=%d).")
                                        ,terminal.m_name.cstr()
                                        ,terminal.m_precedence
                                        ,terminal.getTypeString()
                                        ,item1.m_prod
                                        ,getProduction(item1).m_precedence));
            m_warningCount++;
            break;
          }
        }
      }
      if(!symbolsDone.contains(t)) {
        if(item.m_succ >= 0) {
          result.m_actions.add(ParserAction(t, item.getSuccessor()));
        }
        symbolsDone += t;
        continue;
      }
    }
  }

  for(int i = 0; i < itemCount; i++) {
    const LR1Item &itemi = state.m_items[i];
    if(isReduceItem(itemi)) {
      BitSet tokensReducedByOtherItems(getTerminalCount());
      if(isAcceptItem(itemi)) {  // check if this is start -> S . [EOI]
        result.m_actions.add(ParserAction(0, 0));
        if(symbolsDone.contains(0)) {
          throwException(_T("Token EOI already done in state %d while generating Acceptitem"), state.m_index);
        }
        symbolsDone += 0;
        continue;
      }
      for(int j = 0; j < itemCount; j++) {
        if(j == i) {
          continue;
        }
        const LR1Item &itemj = state.m_items[j];
        if(isReduceItem(itemj)) {
          const BitSet intersection(itemi.m_la & itemj.m_la);
          if(!intersection.isEmpty()) {
            if(itemj.m_prod < itemi.m_prod) {
              tokensReducedByOtherItems += intersection;
              result.m_warnings.add(format(_T("Reduce/reduce conflict on %s between prod %d and prod %d. Choose prod %d.")
                                          ,symbolSetToString(intersection).cstr()
                                          ,itemj.m_prod
                                          ,itemi.m_prod
                                          ,itemj.m_prod));
              m_warningCount++;
            }
          }
        }
      }
      BitSet itemTokens(itemi.m_la - tokensReducedByOtherItems);
      for(Iterator<size_t> it = itemTokens.getIterator(); it.hasNext(); ) {
        const unsigned short t = (unsigned short)it.next();
        if(!symbolsDone.contains(t)) {
          result.m_actions.add(ParserAction(t, -itemi.m_prod));
          symbolsDone += t;
        }
      }
    }
  }

  for(int i = 0; i < itemCount; i++) {
    const LR1Item &itemi = state.m_items[i];
    if(!isShiftItem(itemi) && !isReduceItem(itemi)) {
      const int nt = getShiftSymbol(itemi);
      if(!symbolsDone.contains(nt)) {
        if(itemi.getSuccessor() >= 0) {
          result.m_succs.add(ParserAction(nt, itemi.getSuccessor()));
        }
        symbolsDone += nt;
      }
    }
  } // for

  result.m_actions.sort(parserActionCompareToken); // sort actions by symbolnumber (lookahead symbol)
  result.m_succs.sort(  parserActionCompareToken); // sort result by symbolnumber  (nonTerminal)
}
Пример #22
0
bool VariableTable::needLocalCopy(const string &name) const {
  return needLocalCopy(getSymbol(name));
}
Пример #23
0
Animation_block* Variable::getAnimationBlock() {
	return getSymbol()->get_animation_block_value();
}
Пример #24
0
bool VariableTable::isInherited(const string &name) const {
  const Symbol *sym = getSymbol(name);
  return !sym ||
    (!sym->isGlobal() && !sym->isSystem() && !sym->getDeclaration());
}
Пример #25
0
Файл: c8c.c Проект: c8c/c8c
int ex(nodeType *p) {
    int lblx, lbly, lbl1, lbl2, lblz, lbl3;
    int i,j;
    SymbolType type;
    char* fun_name;
    int numofparas;
    FunNode* func;
    nodeType* paras;
    int *size;
    if (!p) return 0;
    switch(p->type) {
        case typeCon:       
        printf("\tpush\t%d\n", p->con.value); 
        break;  
        case typeId:
        printf("\tpush\tfp[%d]\n",getSymbol(p->id.i)->index);
        break;
        case typeStr:
        printf("\tpush\t\"%s\"\n",p->str.value);// " not include in con.value
        break;
        case typeArr:
        storeOffsetInIn(p);
        testOutofBoundary(p);
        printf("\tpush\tfp[in]\n");
        break;
        case typeOpr:
            switch(p->opr.oper) {
                case INT: 
                case CHAR://Declaration
                    if(p->opr.oper == INT)
                        type = INTTYPE;
                    else if(p->opr.oper == CHAR)
                        type = CHARTYPE;
                    else{
                        printf("Compile Error(1072): Unknown indentifier type\n");
                        exit(-1);
                    }
                    switch(p->opr.op[0]->type){
                        case typeId://A variable
                            printf("\tpush\tsp\n");//allocate space in stack
                            printf("\tpush\t1\n");
                            printf("\tadd\t\n");
                            printf("\tpop\tsp\n");
                            break;
                        case typeArr://An array
                            size = (int *)malloc(sizeof(int) * p->opr.op[0]->arr.dimension);
                            for(i = 0; i < p->opr.op[0]->arr.dimension; i++){
                                ex(p->opr.op[0]->arr.index[i]);
                            }
                            for(i = 0; i < p->opr.op[0]->arr.dimension - 1; i++){
                                printf("\tmul\t\n");
                                }
                            printf("\tpush\tsp\n");
                            printf("\tadd\t\n");
                            printf("\tpop\tsp\n");
                            break;
                        default:
                            printf("Compile Error(1070): Unknown declaration type. <%d>\n",p->opr.op[0]->type);
                            exit(-1);
                            break;
                    }
                    break;
                case CODEBLOCK:
                    ex(p->opr.op[0]);
                    ex(p->opr.op[1]);
                    break;
                case FOR:
                    ex(p->opr.op[0]);
                    printf("L%03d:\n", lblx = lbl++);
                    ex(p->opr.op[1]);
                    printf("\tj0\tL%03d\n", lbly = lbl++);
                    lblz = lbl++;
                    push(lblz,lbly);        
                    ex(p->opr.op[3]);
                    printf("L%03d:\n", lblz);
                    ex(p->opr.op[2]);
                    printf("\tjmp\tL%03d\n", lblx);
                    printf("L%03d:\n", lbly);
                    pop();
                    break;
                case CALL:
                    fun_name = p->opr.op[0]->id.i;//get function name;
                    numofparas = 0;
                    /*push parameters in stack*/
                    for(paras = p->opr.op[1];paras != NULL;paras = paras->para.next){
                        storeOffsetInIn(paras->para.name);
                        if(paras->para.name->type == typeArr)
                            testOutofBoundary(paras->para.name);
                        printf("\tpush\tfp[in]\n");//push para in stack
                        numofparas++;
                    }
                    /*actually, this exist check should be done in c8.y*/
                    if(func = getFunc(fun_name) == NULL){ 
                        printf("Error 1051: function (%s())not declared.\n",fun_name);
                        exit(-1);
                    }
                    printf("\tcall\tL%03d,%d\n",func->label,numofparas);
                break;
                case WHILE:
                    printf("L%03d:\n", lbl1 = lbl++);
                    ex(p->opr.op[0]);
                    printf("\tj0\tL%03d\n", lbl2 = lbl++);
                    push(lbl1,lbl2);
                    ex(p->opr.op[1]);
                    printf("\tjmp\tL%03d\n", lbl1);
                    printf("L%03d:\n", lbl2);
                    pop();
                break;
                case DO-WHILE:
                    lbl1 = lbl++;
                    lbl2 = lbl++;
                    lbl3 = lbl++;
                    push(lbl3,lbl2);
                    printf("L%03d:\n",lbl1);
                    ex(p->opr.op[0]);
                    printf("L%03d:\n", lbl3);
                    ex(p->opr.op[1]);
                    printf("\tj0\tL%03d\n", lbl2);
                    printf("\tjmp\tL%03d\n", lbl1);
                    printf("L%03d:\n", lbl2);
                    pop();
                break;
                case BREAK: printf("\tjmp\tL%03d\n", top(1)); break;
                case CONTINUE: printf("\tjmp\tL%03d\n", top(0)); break;
                case IF:
                ex(p->opr.op[0]);
                if (p->opr.nops > 2) {
                    printf("\tj0\tL%03d\n", lbl1 = lbl++);
                    ex(p->opr.op[1]);
                    printf("\tjmp\tL%03d\n", lbl2 = lbl++);
                    printf("L%03d:\n", lbl1);
                    ex(p->opr.op[2]);
                    printf("L%03d:\n", lbl2);
                } else {
                    printf("\tj0\tL%03d\n", lbl1 = lbl++);
                    ex(p->opr.op[1]);
                    printf("L%03d:\n", lbl1);
                }
                break;
                case READ:
                    printf("\tgeti\n");
                    storeOffsetInIn(p->opr.op[0]); 
                    if(p->opr.op[0]->type == typeArr)
                        testOutofBoundary(p->opr.op[0]);               
                    printf("\tpop\tfp[in]\n");
                break;
                case PRINT:     
                    ex(p->opr.op[0]);
                    printf("\tputi\n");
                break;
                case '=':
                    ex(p->opr.op[1]);
                    storeOffsetInIn(p->opr.op[0]);
                    if(p->opr.op[0]->type == typeArr)
                        testOutofBoundary(p->opr.op[0]);
                    printf("\tpop\tfp[in]\n");
                break;
                case UMINUS:    
                    ex(p->opr.op[0]);
                    printf("\tneg\n");
                break;
            default:/*Expr*/
/*semicolon*/
        ex(p->opr.op[0]);
        ex(p->opr.op[1]);
        switch(p->opr.oper) {
            case '+':   printf("\tadd\n"); break;
            case '-':   printf("\tsub\n"); break; 
            case '*':   printf("\tmul\n"); break;
            case '/':   printf("\tdiv\n"); break;
            case '%':   printf("\tmod\n"); break;
            case '<':   printf("\tcomplt\n"); break;
            case '>':   printf("\tcompgt\n"); break;
            case GE:    printf("\tcompge\n"); break;
            case LE:    printf("\tcomple\n"); break;
            case NE:    printf("\tcompne\n"); break;
            case EQ:    printf("\tcompeq\n"); break;
            case AND:   printf("\tand\n"); break;
            case OR:    printf("\tor\n"); break;
        }
    }
}
return 0;
}
Пример #26
0
ConstructPtr VariableTable::getClassInitVal(string varName) {
  if (Symbol *sym = getSymbol(varName)) {
    return sym->getClassInitVal();
  }
  return ConstructPtr();
}
Пример #27
0
void Rest::layout()
      {
      _space.setLw(0.0);

      if (parent() && measure() && measure()->multiMeasure()) {
            _space.setRw(point(score()->styleS(ST_minMMRestWidth)));
            return;
            }

      rxpos() = 0.0;
      if (staff() && staff()->isTabStaff()) {
            StaffTypeTablature* tab = (StaffTypeTablature*)staff()->staffType();
            // if rests are shown and note values are shown as duration symbols
            if(tab->showRests() &&tab->genDurations()) {
                  // symbol needed; if not exist, create, if exists, update duration
                  if (!_tabDur)
                        _tabDur = new TabDurationSymbol(score(), tab, durationType().type(), dots());
                  else
                        _tabDur->setDuration(durationType().type(), dots(), tab);
                  _tabDur->setParent(this);
// needed?        _tabDur->setTrack(track());
                  _tabDur->layout();
                  setbbox(_tabDur->bbox());
                  setPos(0.0, 0.0);             // no rest is drawn: reset any position might be set for it
                  _space.setLw(0.0);
                  _space.setRw(width());
                  return;
                  }
            // if no rests or no duration symbols, delete any dur. symbol and chain into standard staff mngmt
            // this is to ensure horiz space is reserved for rest, even if they are not diplayed
            // Rest::draw() will skip their drawing, if not needed
            if(_tabDur) {
                  delete _tabDur;
                  _tabDur = 0;
                  }
            }

      switch(durationType().type()) {
            case TDuration::V_64TH:
            case TDuration::V_32ND:
                  dotline = -3;
                  break;
            case TDuration::V_256TH:
            case TDuration::V_128TH:
                  dotline = -5;
                  break;
            default:
                  dotline = -1;
                  break;
            }
      qreal _spatium = spatium();
      int stepOffset = 0;
      if (staff())
            stepOffset = staff()->staffType()->stepOffset();
      int line       = lrint(userOff().y() / _spatium); //  + ((staff()->lines()-1) * 2);
      qreal lineDist = staff() ? staff()->staffType()->lineDistance().val() : 1.0;
      int lineOffset = 0;

      int lines = staff() ? staff()->lines() : 5;
      if (segment() && measure() && measure()->mstaff(staffIdx())->hasVoices) {
            // move rests in a multi voice context
            bool up = (voice() == 0) || (voice() == 2);       // TODO: use style values
            switch(durationType().type()) {
                  case TDuration::V_LONG:
                        lineOffset = up ? -3 : 5;
                        break;
                  case TDuration::V_BREVE:
                        lineOffset = up ? -3 : 5;
                        break;
                  case TDuration::V_MEASURE:
                        if (duration() >= Fraction(2, 1))    // breve symbol
                              lineOffset = up ? -3 : 5;
                        // fall through
                  case TDuration::V_WHOLE:
                        lineOffset = up ? -4 : 6;
                        break;
                  case TDuration::V_HALF:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_QUARTER:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_EIGHT:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_16TH:
                        lineOffset = up ? -6 : 4;
                        break;
                  case TDuration::V_32ND:
                        lineOffset = up ? -6 : 6;
                        break;
                  case TDuration::V_64TH:
                        lineOffset = up ? -8 : 6;
                        break;
                  case TDuration::V_128TH:
                        lineOffset = up ? -8 : 8;
                        break;
                  case TDuration::V_256TH:             // not available
                        lineOffset = up ? -10 : 6;
                        break;
                  default:
                        break;
                  }
            }
      else {
            switch(durationType().type()) {
                  case TDuration::V_LONG:
                  case TDuration::V_BREVE:
                  case TDuration::V_MEASURE:
                  case TDuration::V_WHOLE:
                        if (lines == 1)
                              lineOffset = -2;
                        break;
                  case TDuration::V_HALF:
                  case TDuration::V_QUARTER:
                  case TDuration::V_EIGHT:
                  case TDuration::V_16TH:
                  case TDuration::V_32ND:
                  case TDuration::V_64TH:
                  case TDuration::V_128TH:
                  case TDuration::V_256TH:             // not available
                        if (lines == 1)
                              lineOffset = -4;
                        break;
                  default:
                        break;
                  }
            }

      int yo;
      _sym = getSymbol(durationType().type(), line + lineOffset/2, lines, &yo);
      layoutArticulations();
      rypos() = (qreal(yo) + qreal(lineOffset + stepOffset) * .5) * lineDist * _spatium;

      Spatium rs;
      if (dots()) {
            rs = Spatium(score()->styleS(ST_dotNoteDistance)
               + dots() * score()->styleS(ST_dotDotDistance));
            }
      if (dots()) {
            rs = Spatium(score()->styleS(ST_dotNoteDistance)
               + dots() * score()->styleS(ST_dotDotDistance));
            }
      setbbox(symbols[score()->symIdx()][_sym].bbox(magS()));
      _space.setRw(width() + point(rs));
      }
void loadConfig(CString& configFile)
{
	FILE*	f = fopen(configFile, "rt");

	if (f)
		{
		lineno = 0;

		while (!feof(f))
			{
			char* p = getSymbol(f);

			if (p)
				{
				if (strcmpi(p, "Style") == 0)
					{
					char* styleName = getSymbol(f);
					Style* newStyle = 0;

					if (strcmpi(styleName, "Default") != 0)
						{
						SListIterator<Style>	styleIterator(styles);
						Style*					style;

						for (style = styleIterator.GoHead(); style; style = styleIterator.GetNext())
							{
							if (strcmpi(style->iStyleName, styleName) == 0)
								{
								newStyle = style;
								break;
								}
							}

						if (!newStyle)
							{
							newStyle = new Style(styleName);
							styles.Add(newStyle);
							}
						}
					else
						{
						newStyle = gDefaultStyle;
						}

					styleSec = SS_UNKNOWN;

					if (strcmp(getSymbol(f), "(") != 0)
						{
						cprintf("%s(%i): '(' expected\n", (const char*)configFile, lineno);
						exit(3);
						}

					char* ext;

					do
						{
						ext = getSymbol(f);

						if (*ext != '.' && *ext != ')' && *ext != '*')
							{
							cprintf("%s(%i): file extension expected\n", (const char*)configFile, lineno);
							exit(3);
							}

						if (*ext == '.' || *ext == '*')
							{
							newStyle->AddExtensions(CString(ext));
							}
						}
					while (*ext != ')');

					char* baseStyles = getSymbol(f);

					if (strcmp(baseStyles, "{") != 0)
						{
						// we have base styles

						while (strcmp(baseStyles, "{") != 0)
							{
							Style*	sty;
							SListIterator<Style> styleIterator(styles);

							for (sty = styleIterator.GoHead();
								sty;
								sty = styleIterator.GetNext())
								{
								if (strcmpi(sty->iStyleName, baseStyles) == 0)
									newStyle->AddBaseStyle(sty);
								}

							baseStyles = getSymbol(f);
							}
						}

					char* sym = 0;

					do
						{
						sym = getSymbol(f);

						if (strcmp(sym, "=>") == 0)
							{
							sym = getSymbol(f, 1);

							switch (styleSec)
								{
								case SS_SYMBOLSCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iSymbolsColor.SetItem(BYTE(color));
									}
								break;
								case SS_COMMENTCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iCommentColor.SetItem(BYTE(color));
									}
								break;
								case SS_STRINGCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iStringColor.SetItem(BYTE(color));
									}
								break;
								case SS_RESERVEDCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iReservedColor.SetItem(BYTE(color));
									}
								break;
								case SS_PREPROCESSORCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iPreprocessorColor.SetItem(BYTE(color));
									}
								break;
								case SS_NUMBERCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iNumberColor.SetItem(BYTE(color));
									}
								break;
								case SS_IDENTCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iIdentColor.SetItem(BYTE(color));
									}
								break;
								case SS_FOREGNDCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iForeGndColor.SetItem(BYTE(color));
									}
								break;
								case SS_BACKGNDCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iBackGndColor.SetItem(BYTE(color));
									}
								break;
								case SS_SELECTEDFOREGNDCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iSelectedForeGndColor.SetItem(BYTE(color));
									}
								break;
								case SS_SELECTEDBACKGNDCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iSelectedBackGndColor.SetItem(BYTE(color));
									}
								break;
								case SS_BOLDCOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iBoldColor.SetItem(BYTE(color));
									}
								break;
								case SS_UNDERLINECOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iUnderlineColor.SetItem(BYTE(color));
									}
								break;
								case SS_BOLDUNDERLINECOLOR:
									{
									int color = GetColor(sym);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									newStyle->iBoldUnderlineColor.SetItem(BYTE(color));
									}
								break;
								case SS_EXPANDTABS:
									{
									if (IsOnOrYes(sym))
										newStyle->iExpandTabs.SetItem(TRUE);
									else
									if (IsOffOrNo(sym))
										newStyle->iExpandTabs.SetItem(FALSE);
									else
										{
										cprintf("%s(%i): Tabs must be set to either ON or OFF\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_HIGHBITFILTER:
									{
									if (IsOnOrYes(sym))
										newStyle->iHighBitFilter.SetItem(TRUE);
									else
									if (IsOffOrNo(sym))
										newStyle->iHighBitFilter.SetItem(FALSE);
									else
										{
										cprintf("%s(%i): Highbit filter must be set to either ON or OFF\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_TEXTWITHLAYOUT:
									{
									if (IsOnOrYes(sym) || strcmp(sym, "1") == 0)
										newStyle->iTextWithLayout.SetItem(TRUE);
									else
									if (IsOffOrNo(sym))
										newStyle->iTextWithLayout.SetItem(FALSE);
									else
										{
										cprintf("%s(%i): TextWithLayout must be set to either ON or OFF\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_TABWIDTH:
									{
									newStyle->iTabWidth.SetItem(atoi(sym));

									if (*newStyle->iTabWidth.GetItem() < 1 ||
										*newStyle->iTabWidth.GetItem() > 20)
										{
										cprintf("%s(%i): TabWidth must be between 1 and 20\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_DISPLAYMODE:
									{
									newStyle->iDisplayMode.SetItem(DM_TEXT);

									if (strcmpi(sym, "TEXT") == 0)
										newStyle->iDisplayMode.SetItem(DM_TEXT);
									else
									if (strcmpi(sym, "HEX") == 0)
										newStyle->iDisplayMode.SetItem(DM_HEX);
									else
										{
										cprintf("%s(%i): DisplayMode must be set to either TEXT or HEX\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_WORDBREAK:
									{
									if (IsOnOrYes(sym) || strcmp(sym, "1") == 0)
										newStyle->iWordBreak.SetItem(TRUE);
									else
									if (IsOffOrNo(sym))
										newStyle->iWordBreak.SetItem(FALSE);
									else
										{
										cprintf("%s(%i): WorkBreak must be set to either ON or OFF\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_TOPLINEFORMAT:
									{
									newStyle->iTopLineFormat.SetItem(atoi(sym));

									if (*newStyle->iTopLineFormat.GetItem() < 0 ||
										*newStyle->iTopLineFormat.GetItem() > 2)
										{
										cprintf("%s(%i): TopLineFormat must be between 0, 1 or 2\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_RESERVED:
									{
									if (*sym)
										{
										newStyle->AddReservedWord(CString(sym));
										}
									}
								break;
								case SS_OPENCOMMENT:
									{
									if (*sym)
										newStyle->AddOpenComment(CString(sym));
									}
								break;
								case SS_STRINGS:
									{
									if (*sym)
										{
										newStyle->iString.SetItem(sym);
										}
									}
								break;
								case SS_ESCAPE:
									{
									if (*sym)
										newStyle->iEscape.SetItem(*sym);
									}
								break;
								case SS_SYMBOLS:
									{
									if (*sym)
										newStyle->iSymbols.SetItem(sym);
									}
								break;
								case SS_CLOSECOMMENT:
									{
									if (*sym)
										newStyle->AddCloseComment(CString(sym));
									}
								break;
								case SS_SINGLELINECOMMENT:
									{
									if (*sym)
										newStyle->AddEolComment(CString(sym));
									}
								break;
								case SS_NUMBERPREFIX:
									{
									if (*sym)
										newStyle->AddNumericPrefix(CString(sym));
									}
								break;
								case SS_OPENPREPROCESSOR:
									{
									if (*sym)
										newStyle->iOpenPreprocessor.SetItem(sym);
									}
								break;
								case SS_CLOSEPREPROCESSOR:
									{
									if (*sym)
										newStyle->iClosePreprocessor.SetItem(sym);
									}
								break;
								case SS_COMMENTCOLUMN:
									{
									if (*sym)
										newStyle->iCommentColumn.SetItem(atoi(sym));
									}
								break;
								case SS_LINECONTINUATION:
									{
									if (*sym)
										newStyle->iLineContinuation.SetItem(*sym);
									}
								break;
								case SS_CASESENSITIVE:
									{
									if (IsOnOrYes(sym))
										newStyle->iCaseSensitive.SetItem(TRUE);
									else
									if (IsOffOrNo(sym))
										newStyle->iCaseSensitive.SetItem(FALSE);
									else
										{
										cprintf("%s(%i): CaseSensitive must be set to either YES or NO\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_CASECONVERT:
									{
									if (IsOnOrYes(sym))
										newStyle->iCaseConvert.SetItem(TRUE);
									else
									if (IsOffOrNo(sym))
										newStyle->iCaseConvert.SetItem(FALSE);
									else
										{
										cprintf("%s(%i): CaseConvert must be set to either YES or NO\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SS_EXTERNALFILTER:
									{
									if (*sym)
										newStyle->iExternalFilterCmd.SetItem(sym);
									else
										newStyle->iExternalFilterCmd.SetItem("");
									}
								break;
								case SS_EDITOR:
									{
									if (*sym)
										newStyle->iEditor.SetItem(sym);
									else
										newStyle->iEditor.SetItem("");
									}
								break;
								case SS_UNKNOWN:
									{
									// just ignore => found before a section
									// has been defined
									}
								break;
								}

							sym = "";
							}
						else
							{
							styleSec = GetSection(sym);

							if (styleSec == SS_UNKNOWN && strcmp(sym, "}") != 0)
								{
								cprintf("%s(%i): undefined style element '%s'\n", (const char*)configFile, lineno, sym);
								exit(3);
								}
							}
						}
					while (strcmp(sym, "}") != 0);

					if (newStyle->iReserved.Size() > 0)
						{
						// switch syntax highlighting on for styles
						// with reserved words.
						newStyle->iSyntaxHighlightEnabled.SetItem(TRUE);

						if (!*newStyle->iCaseSensitive.GetItem())
							{
							newStyle->iReserved.sort(cstrcmpi);
							}
						else
							{
							newStyle->iReserved.sort();
							}
						}
					}
				else
				if (strcmpi(p, "Settings") == 0)
					{
					char* setting = getSymbol(f);
					char* sym;
					char* value;

					if (strcmp(setting, "{") != 0)
						{
						cprintf("%s(%i): '{' expected\n", (const char*)configFile, lineno);
						exit(3);
						}

					do
						{
						setting = getSymbol(f);

						if (strcmp(setting, "}") != 0)
							{
							SettingSection section = GetSetting(setting);
							sym = getSymbol(f);

							if (strcmp(sym, "=>") != 0)
								{
								cprintf("%s(%i): '=>' expected\n", (const char*)configFile, lineno);
								exit(3);
								}

							value = getSymbol(f);

							switch (section)
								{
								case SET_SOUND:
									{
									if (IsOffOrNo(value))
										setupInfo.soundOn = FALSE;
									else
									if (IsOnOrYes(value))
										setupInfo.soundOn = TRUE;
									else
										{
										cprintf("%s(%i): Sound must be set to either ON or OFF\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SET_SEARCH:
									{
									if (strcmpi(value, "regexp") == 0)
										setupInfo.regexpSearch = TRUE;
									else
									if (strcmpi(value, "plain") == 0)
										setupInfo.regexpSearch = FALSE;
									else
										{
										cprintf("%s(%i): Search must be set to either REGEXP or PLAIN\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SET_KEEPFILESLOADED:
									{
									if (IsOffOrNo(value))
										setupInfo.keepFilesLoaded = FALSE;
									else
									if (IsOnOrYes(value))
										setupInfo.keepFilesLoaded = TRUE;
									else
										{
										cprintf("%s(%i): KeepFilesLoaded must be set to either ON or OFF\n", (const char*)configFile, lineno);
										exit(3);
										}
									}
								break;
								case SET_STATUSTEXTFORECOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.statusTextForeColor = color;
									}
								break;
								case SET_STATUSTEXTBACKCOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.statusTextBackColor = color;
									}
								break;
								case SET_DISKTEXTFORECOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.diskTextForeColor = color;
									}
								break;
								case SET_DISKTEXTBACKCOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.diskTextBackColor = color;
									}
								break;
								case SET_CURDISKTEXTFORECOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.curDiskTextForeColor = color;
									}
								break;
								case SET_CURDISKTEXTBACKCOLOR :
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.curDiskTextBackColor = color;
									}
								break;
								case SET_FILETEXTFORECOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.fileTextForeColor = color;
									}
								break;
								case SET_FILETEXTBACKCOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.fileTextBackColor = color;
									}
								break;
								case SET_CURFILETEXTFORECOLOR :
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.curFileTextForeColor = color;
									}
								break;
								case SET_CURFILETEXTBACKCOLOR:
									{
									int color = GetColor(value);

									if (color == -1)
										{
										cprintf("%s(%i): Invalid color '%s'\n", (const char*)configFile, lineno, sym);
										exit(3);
										}

									setupInfo.curFileTextBackColor = color;
									}
								break;
								default:
									cprintf("%s(%i): Unknown setting '%s'\n", (const char*)configFile, lineno, setting);
									exit(3);
								}
							}
						}
					while (strcmp(setting, "}") != 0);
					}
				else
					{
					cprintf("%s(%i): 'Style' expected\n", (const char*)configFile, lineno);
					exit(3);
					}
				}
			}

		fclose(f);
		}
}
Пример #29
0
void Entity::writeDataAsFragment( std::ostream & output ) {
	output << "\t\t<name>" << getName() << "</name>" << std::endl;
	output << "\t\t<symbol>" << getSymbol() << "</symbol>" << std::endl;
}
Пример #30
0
int
getFrameSync (dsd_opts * opts, dsd_state * state)
{
  /* detects frame sync and returns frame type
   *  0 = +P25p1
   *  1 = -P25p1
   *  2 = +X2-TDMA (non inverted signal data frame)
   *  3 = -X2-TDMA (inverted signal data frame)
   *  4 = +DMR (non inverted signal data frame)
   *  5 = -DMR (inverted signal data frame)
   *  6 = +NXDN (non inverted data frame)
   *  7 = -NXDN (inverted data frame)
   *  8 = +D-STAR
   *  9 = -D-STAR
   * 10 = +D-STAR_HD
   * 11 = -D-STAR_HD
   * 12 = +DMR (non inverted signal voice frame)
   * 13 = -DMR (inverted signal voice frame)
   * 14 = +X2-TDMA (non inverted signal voice frame)
   * 15 = -X2-TDMA (inverted signal voice frame)
   * 16 = +NXDN (non inverted voice frame)
   * 17 = -NXDN (inverted voice frame)
   */

  int i, t, dibit, sync, symbol, synctest_pos, lastt;
  char synctest[25];
  char *synctest_p;
  char synctest_buf[10240];
  int lmin, lmax, lidx;
  int lbuf[24], lbuf2[24];

  for (i = 18; i < 24; i++) {
      lbuf[i] = 0;
      lbuf2[i] = 0;
  }

  // detect frame sync
  t = 0;
  synctest[24] = 0;
  synctest_pos = 0;
  synctest_p = synctest_buf;
  sync = 0;
  lmin = 0;
  lmax = 0;
  lidx = 0;
  lastt = 0;

  while (sync == 0) {
      t++;
      symbol = getSymbol (opts, state, 0);

      lbuf[lidx] = symbol;
      state->sbuf[state->sidx] = symbol;
      if (lidx == 23) {
          lidx = 0;
      } else {
          lidx++;
      }

      if (state->sidx == (state->ssize - 1)) {
          state->sidx = 0;
      } else {
          state->sidx++;
      }

      if (lastt == 23) {
          lastt = 0;
          state->rf_mod = 2;
      } else {
          lastt++;
      }

      //determine dibit state
      if (symbol > 0) {
          dibit = 49;               // '1'
      } else {
          dibit = 51;               // '3'
      }

      *synctest_p = dibit;
      if (t >= 18) {
          for (i = 0; i < 24; i++) {
              lbuf2[i] = lbuf[i];
          }

          Shellsort_int (lbuf2, 24);
          lmin = (lbuf2[2] + lbuf2[3] + lbuf2[4]) / 3;
          lmax = (lbuf2[21] + lbuf2[20] + lbuf2[19]) / 3;
          if (opts->datascope && (lidx == 0)) {
            print_datascope(state, lbuf2, 24);
          }

          memcpy (synctest, (synctest_p - 23), 24);

          if ((memcmp (synctest, P25P1_SYNC, 24) == 0) || (memcmp (synctest, INV_P25P1_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            strcpy (state->ftype, "P25p1");
            if (synctest[0] == '1') {
                state->lastsynctype = 0;
            } else {
                state->lastsynctype = 1;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, DMR_MS_DATA_SYNC, 24) == 0) || (memcmp (synctest, DMR_BS_DATA_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '1');
            strcpy (state->ftype, "DMR  ");
            if (opts->inverted_dmr == 0) {
                // data frame
                if (state->lastsynctype != 4) {
                    state->firstframe = 1;
                }
                state->lastsynctype = 4;
            } else {
                // inverted voice frame
                if (state->lastsynctype != 13) {
                    state->firstframe = 1;
                }
                state->lastsynctype = 13;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, DMR_MS_VOICE_SYNC, 24) == 0) || (memcmp (synctest, DMR_BS_VOICE_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '3');
            strcpy (state->ftype, "DMR  ");
            if (opts->inverted_dmr == 0) {
                // voice frame
                if (state->lastsynctype != 12) {
                   state->firstframe = 1;
                }
                state->lastsynctype = 12;
            } else {
                // inverted data frame
                if (state->lastsynctype != 5) {
                    state->firstframe = 1;
                }
                state->lastsynctype = 5;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, X2TDMA_BS_DATA_SYNC, 24) == 0) || (memcmp (synctest, X2TDMA_MS_DATA_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '1');
            strcpy (state->ftype, "X2-TDMA ");
            if (opts->inverted_x2tdma == 0) {
                // data frame
                state->lastsynctype = 2;
            } else {
                // inverted voice frame
                if (state->lastsynctype != 15) {
                   state->firstframe = 1;
                }
                state->lastsynctype = 15;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest, X2TDMA_BS_VOICE_SYNC, 24) == 0) || (memcmp (synctest, X2TDMA_MS_VOICE_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            state->dmrMsMode = (synctest[22] == '3');
            strcpy (state->ftype, "X2-TDMA ");
            if (opts->inverted_x2tdma == 0) {
                // voice frame
                if (state->lastsynctype != 14) {
                   state->firstframe = 1;
                }
                state->lastsynctype = 14;
            } else {
                // inverted data frame
                state->lastsynctype = 3;
            }
            goto update_sync_and_return;
          }

          if ((memcmp (synctest+6, NXDN_BS_VOICE_SYNC, 18) == 0) ||
              (memcmp (synctest+6, NXDN_MS_VOICE_SYNC, 18) == 0) ||
              (memcmp (synctest+6, NXDN_BS_DATA_SYNC, 18) == 0)  ||
              (memcmp (synctest+6, NXDN_MS_DATA_SYNC, 18) == 0)) {
              if (synctest[21] == '1') {
                  state->lastsynctype = 6;
              } else {
                  state->lastsynctype = 16;
              }
              if ((state->lastsynctype == 6) || (state->lastsynctype == 16)) {
                  state->offset = synctest_pos;
                  strcpy (state->ftype, "NXDN96  ");
                  goto update_sync_and_return;
              }
          }
          if ((memcmp (synctest+6, INV_NXDN_BS_VOICE_SYNC, 18) == 0) || 
              (memcmp (synctest+6, INV_NXDN_MS_VOICE_SYNC, 18) == 0) ||
              (memcmp (synctest+6, INV_NXDN_BS_DATA_SYNC, 18) == 0) ||
              (memcmp (synctest+6, INV_NXDN_MS_DATA_SYNC, 18) == 0)) {
              if (synctest[21] == '3') {
                  state->lastsynctype = 7;
              } else {
                  state->lastsynctype = 17;
              }
              if ((state->lastsynctype == 7) || (state->lastsynctype == 17)) {
                  state->offset = synctest_pos;
                  strcpy (state->ftype, "NXDN96  ");
                  goto update_sync_and_return;
              }
          }

          if ((memcmp (synctest, DSTAR_SYNC, 24) == 0) || (memcmp (synctest, INV_DSTAR_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            strcpy (state->ftype, "D-STAR  ");
            if (synctest[0] == '3') {
                state->lastsynctype = 8;
            } else {
                state->lastsynctype = 9;
            }
            goto update_sync_and_return;
          }
          if ((memcmp (synctest, DSTAR_HD_SYNC, 24) == 0) || (memcmp (synctest, INV_DSTAR_HD_SYNC, 24) == 0)) {
            state->offset = synctest_pos;
            strcpy (state->ftype, "D-STARHD");
            if (synctest[0] == '1') {
                state->lastsynctype = 10;
            } else {
                state->lastsynctype = 11;
            }
            goto update_sync_and_return;
          }
      }

      if (exitflag == 1) {
          cleanupAndExit (opts, state);
      }

      if (synctest_pos < 10200) {
          synctest_pos++;
          synctest_p++;
      } else {
          // buffer reset
          synctest_pos = 0;
          synctest_p = synctest_buf;
          state->lastsynctype = -1;
      }

      if (state->lastsynctype != -1) {
          //if (synctest_pos >= 1800) {
          if (synctest_pos >= 9000) {
              if ((state->lastsynctype != -1) && !(opts->datascope)) {
                  printf ("Sync: no sync\n");
              }
              state->lastsynctype = -1;
#if 1
              state->max = 3000;
              state->min = -3000;
              state->umid = 1000;
              state->lmid = -1000;
              state->center = 0;
#endif
              return (-1);
          }
      }
  }

  return (-1);

update_sync_and_return:
   // recalibrate center/umid/lmid
   state->max = ((state->max) + (lmax)) / 2;
   state->min = ((state->min) + (lmin)) / 2;
   state->center = ((state->max) + (state->min)) / 2;
   state->umid = (((state->max) - state->center) * 5 / 8) + state->center;
   state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
   return state->lastsynctype;
}