Пример #1
0
static void WarnPragma (StrBuf* B)
/* Enable/disable warnings */
{
    long   Val;
    int    Push;

    /* A warning name must follow */
    IntStack* S = GetWarning (B);
    if (S == 0) {
        return;
    }

    /* Comma follows */
    if (!GetComma (B)) {
        return;
    }

    /* Check for the "push" or "pop" keywords */
    switch (ParsePushPop (B)) {

        case PP_NONE:
            Push = 0;
            break;

        case PP_PUSH:
            Push = 1;
            break;

        case PP_POP:
            /* Pop the old value and bail out */
            PopInt (S);
            return;

        case PP_ERROR:
            /* Bail out */
            return;

        default:
            Internal ("Invalid result from ParsePushPop");
    }

    /* Boolean argument follows */
    if (HasStr (B, "true") || HasStr (B, "on")) {
        Val = 1;
    } else if (HasStr (B, "false") || HasStr (B, "off")) {
        Val = 0;
    } else if (!SB_GetNumber (B, &Val)) {
        Error ("Invalid pragma argument");
        return;
    }

    /* Set/push the new value */
    if (Push) {
        PushInt (S, Val);
    } else {
        IS_Set (S, Val);
    }
}
Пример #2
0
////////////////////////////////////////////////////////////////////////////////
//解释gps发出的数据
//0      7  0   4 6   0     6 8 0        90         0  3      0        9  	
//$GPRMC,091400,A,3958.9870,N,11620.3278,E,000.0,000.0,120302,005.6,W*62	
//$GPGGA,091400,3958.9870,N,11620.3278,E,1,03,1.9,114.2,M,-8.3,M,,*5E	
void gps_parse(char *line,GPS_INFO *GPS)
////////////////////////////////////////////////////////////////////////////////
{
	int i,tmp,start,end;
	char c;
	char* buf=line;
	c=buf[5];

	if(c=='C'){//"GPRMC"
		GPS->D.hour   =(buf[ 7]-'0')*10+(buf[ 8]-'0');
		GPS->D.minute =(buf[ 9]-'0')*10+(buf[10]-'0');
		GPS->D.second =(buf[11]-'0')*10+(buf[12]-'0');
		tmp = GetComma(9,buf);
		GPS->D.day    =(buf[tmp+0]-'0')*10+(buf[tmp+1]-'0');
		GPS->D.month  =(buf[tmp+2]-'0')*10+(buf[tmp+3]-'0');
		GPS->D.year   =(buf[tmp+4]-'0')*10+(buf[tmp+5]-'0')+2000;
		//------------------------------
		GPS->status	  =buf[GetComma(2,buf)];
		GPS->latitude =get_double_number(&buf[GetComma(3,buf)]);
		GPS->NS       =buf[GetComma(4,buf)];
		GPS->longitude=get_double_number(&buf[GetComma(5,buf)]);
		GPS->EW       =buf[GetComma(6,buf)];
#ifdef USE_BEIJING_TIMEZONE
		UTC2BTC(&GPS->D);
#endif
	}
	if(c=='A'){ //"$GPGGA"
		GPS->high     = get_double_number(&buf[GetComma(9,buf)]);
		
	}
}
Пример #3
0
static double get_double_number(char *s)
{
	char buf[128];
	int i;
	double rev;
	i=GetComma(1,s);
	strncpy(buf,s,i);
	buf[i]=0;
	rev=atof(buf);
//	printf("s=%s ,buf= %s,val= %f\n",s,buf,rev);
	return rev;
	
}
Пример #4
0
static void FlagPragma (StrBuf* B, IntStack* Stack)
/* Handle a pragma that expects a boolean paramater */
{
    StrBuf Ident = AUTO_STRBUF_INITIALIZER;
    long   Val;
    int    Push;


    /* Try to read an identifier */
    int IsIdent = SB_GetSym (B, &Ident, 0);

    /* Check if we have a first argument named "pop" */
    if (IsIdent && SB_CompareStr (&Ident, "pop") == 0) {
        PopInt (Stack);
        /* No other arguments allowed */
        return;
    }

    /* Check if we have a first argument named "push" */
    if (IsIdent && SB_CompareStr (&Ident, "push") == 0) {
        Push = 1;
        if (!GetComma (B)) {
            goto ExitPoint;
        }
        IsIdent = SB_GetSym (B, &Ident, 0);
    } else {
        Push = 0;
    }

    /* Boolean argument follows */
    if (IsIdent) {
        Val = BoolKeyword (&Ident);
    } else if (!GetNumber (B, &Val)) {
        goto ExitPoint;
    }

    /* Set/push the new value */
    if (Push) {
        PushInt (Stack, Val);
    } else {
        IS_Set (Stack, Val);
    }

ExitPoint:
    /* Free the identifier */
    SB_Done (&Ident);
}
Пример #5
0
double Get_Double_Number_time(char *s)  //for direction
{
	char buf[10];
	u8 i;
	double rev;
	unsigned long a;
	
	i = GetComma(1, s);
	i = i - 1;
	strncpy(buf, s, i);
	buf[i] = 0;
	rev = Str_To_Double(buf);
	
	a = rev/1;
	
	return a;	
}
Пример #6
0
double Get_Double_Number_sog(char *s)  //for sog
{
	char buf[10];
	u8 i;
	double rev;
	unsigned int a;
	
	i = GetComma(1, s);
	i = i - 1;
	strncpy(buf, s, i);
	buf[i] = 0;
	rev = Str_To_Double(buf);
	
	a = rev*10/1;
	
	return a;	
}
Пример #7
0
//====================================================================//
// 语法格式: static double Get_Double_Number(char *s)
// 实现功能:把给定字符串第一个逗号之前的字符转化成双精度型[有修改为返回值为long型整数]
// 参    数:字符串
// 返 回 值:转化后双精度值
//====================================================================//
double Get_Double_Number(char *s)
{
	char buf[10];
	u8 i;
	double rev;
	long a,temp;
	
	i = GetComma(1, s);
	i = i - 1;
	strncpy(buf, s, i);
	buf[i] = 0;
	rev = Str_To_Double(buf);
	
	temp = rev/100;
	a = temp*600000 + (rev - temp*100)*10000;
	
	return a;	
}
Пример #8
0
static void CharMapPragma (StrBuf* B)
/* Change the character map */
{
    long Index, C;

    /* Read the character index */
    if (!GetNumber (B, &Index)) {
        return;
    }
    if (Index < 0 || Index > 255) {
        Error ("Character index out of range");
        return;
    }

    /* Comma follows */
    if (!GetComma (B)) {
        return;
    }

    /* Read the character code */
    if (!GetNumber (B, &C)) {
        return;
    }
    if (C < 0 || C > 255) {
        Error ("Character code out of range");
        return;
    }

    /* Warn about remapping character code 0x00
    ** (except when remapping it back to itself).
    */
    if (Index + C != 0 && IS_Get (&WarnRemapZero)) {
        if (Index == 0) {
            Warning ("Remapping from 0 is dangerous with string functions");
        }
        else if (C == 0) {
            Warning ("Remapping to 0 can make string functions stop unexpectedly");
        }
    }

    /* Remap the character */
    TgtTranslateSet ((unsigned) Index, (unsigned char) C);
}
Пример #9
0
static void CharMapPragma (StrBuf* B)
/* Change the character map */
{
    long Index, C;

    /* Read the character index */
    if (!GetNumber (B, &Index)) {
        return;
    }
    if (Index < 1 || Index > 255) {
        if (Index == 0) {
            /* For groepaz */
            Error ("Remapping 0 is not allowed");
        } else {
            Error ("Character index out of range");
        }
        return;
    }

    /* Comma follows */
    if (!GetComma (B)) {
        return;
    }

    /* Read the character code */
    if (!GetNumber (B, &C)) {
        return;
    }
    if (C < 1 || C > 255) {
        if (C == 0) {
            /* For groepaz */
            Error ("Remapping 0 is not allowed");
        } else {
            Error ("Character code out of range");
        }
        return;
    }

    /* Remap the character */
    TgtTranslateSet ((unsigned) Index, (unsigned char) C);
}
Пример #10
0
static PushPopResult ParsePushPop (StrBuf* B)
/* Check for and parse the "push" and "pop" keywords. In case of "push", a
 * following comma is expected and skipped.
 */
{
    StrBuf Ident      = AUTO_STRBUF_INITIALIZER;
    PushPopResult Res = PP_NONE;

    /* Remember the current string index, so we can go back in case of errors */
    unsigned Index = SB_GetIndex (B);

    /* Try to read an identifier */
    if (SB_GetSym (B, &Ident, 0)) {

        /* Check if we have a first argument named "pop" */
        if (SB_CompareStr (&Ident, "pop") == 0) {

            Res = PP_POP;

        /* Check if we have a first argument named "push" */
        } else if (SB_CompareStr (&Ident, "push") == 0) {

            Res = PP_PUSH;

            /* Skip the following comma */
            if (!GetComma (B)) {
                /* Error already flagged by GetComma */
                Res = PP_ERROR;
            }

        } else {

            /* Unknown keyword, roll back */
            SB_SetIndex (B, Index);
        }
    }

    /* Free the string buffer and return the result */
    SB_Done (&Ident);
    return Res;
}
Пример #11
0
//機能:更新処理
//引数:なし
//戻値:成功か失敗か
HRESULT StageSelect::Update()
{
    //十字上キーが押されたら
    if (g_pInput->IsKeyTap(DIK_UP))
    {
        selectStage--;		//ステージ選択変数をカウントダウン
    }

    //十字下キーが押されたら
    if (g_pInput->IsKeyTap(DIK_DOWN))
    {
        selectStage++;		//ステージ選択変数をカウントアップ
    }

    //現在のカレントディレクトリのフォルダ名を覚えておく処理
    char  defaultCurrentDir[MAX_PATH];							//デフォルトのフォルダ名を入れる変数
    GetCurrentDirectory(MAX_PATH, defaultCurrentDir);			//現在のカレントディレクトリをGetCurrentDirectory関数で調べ変数に代入
    //この処理以降は↑で取得したフォルダ名のフォルダだけを使うするようにする
    SetCurrentDirectory(defaultCurrentDir);



    //変数selectStageが0でかつエンターキーが押されたとき
    if (selectStage == 0 && g_pInput->IsKeyTap(DIK_RETURN))
    {

        //ファイルを開く
        HANDLE hFile;
        hFile = CreateFile(
                    "sample1.stage",		//ファイル名
                    GENERIC_READ,			//アクセスモード(読み込み用)
                    0,						//共有(なし)
                    NULL,					//セキュリティ属性
                    OPEN_EXISTING,			//開く方法(ファイルがなければ失敗)
                    FILE_ATTRIBUTE_NORMAL,	//属性とフラグ(設定なし)
                    NULL
                );

        //開けなかったら中断
        if (hFile == 0) return S_OK;

        //ファイルサイズの取得
        DWORD fileSize = GetFileSize(hFile, &fileSize);

        //ファイルサイズ分メモリを確保
        char* data;
        data = new char[fileSize];

        //全部読み込む
        DWORD dwBytes = 0;	//読み込み位置
        ReadFile(
            hFile,					//ファイルハンドル
            data,					//データを入れる変数
            fileSize,				//読み込むサイズ
            &dwBytes,				//読み込んだサイズ(読み込み位置)
            NULL					//オーバーラップ度構造体(今回は使わない)
        );

        //ファイルハンドルの解放
        CloseHandle(hFile);


        int index = 0;									//ファイルの場所を示す変数
        int arraySize = GetComma(data, &index);			//ファイルにあるデータの数を取得

        int i = 0;

        //データの数だけループ
        while (i < arraySize)
        {
            //ファイルデータは「ブロックの種類(整数) ,(カンマ)」で区切られてるのでカンマごとに区切って配列に格納する
            stagePartsArray.push_back(GetComma(data, &index));
            StageData::GetInst()->data[i] = stagePartsArray[i];
            i++;

        }

        //最後をお知らせするために'\0'をいれる
        StageData::GetInst()->data[i] = 99;
        //デフォルトのディレクトリに戻す
        SetCurrentDirectory(defaultCurrentDir);


        SAFE_DELETE(data);			//変数dataを解放


        g_gameScene = SC_PLAY;					//プレイシーンに移行
    }

    //変数selectStageがでかつエンターキーが押されたとき
    if (selectStage == 1 && g_pInput->IsKeyTap(DIK_RETURN))
    {

        //ファイルを開く
        HANDLE hFile;
        hFile = CreateFile(
                    "sample2.stage",		//ファイル名
                    GENERIC_READ,			//アクセスモード(読み込み用)
                    0,						//共有(なし)
                    NULL,					//セキュリティ属性
                    OPEN_EXISTING,			//開く方法(ファイルがなければ失敗)
                    FILE_ATTRIBUTE_NORMAL,	//属性とフラグ(設定なし)
                    NULL
                );

        //開けなかったら中断
        if (hFile == 0) return S_OK;

        //ファイルサイズの取得
        DWORD fileSize = GetFileSize(hFile, &fileSize);

        //ファイルサイズ分メモリを確保
        char* data;
        data = new char[fileSize];

        //全部読み込む
        DWORD dwBytes = 0;	//読み込み位置
        ReadFile(
            hFile,					//ファイルハンドル
            data,					//データを入れる変数
            fileSize,				//読み込むサイズ
            &dwBytes,				//読み込んだサイズ(読み込み位置)
            NULL					//オーバーラップ度構造体(今回は使わない)
        );

        //ファイルハンドルの解放
        CloseHandle(hFile);


        int index = 0;									//ファイルの場所を示す変数
        int arraySize = GetComma(data, &index);			//ファイルにあるデータの数を取得

        int i = 0;

        //データの数だけループ
        while (i < arraySize)
        {
            //ファイルデータは「ブロックの種類(整数) ,(カンマ)」で区切られてるのでカンマごとに区切って配列に格納する
            stagePartsArray.push_back(GetComma(data, &index));
            StageData::GetInst()->data[i] = stagePartsArray[i];
            i++;

        }

        //最後をお知らせするために'\0'をいれる
        StageData::GetInst()->data[i] = 99;
        //デフォルトのディレクトリに戻す
        SetCurrentDirectory(defaultCurrentDir);

        //変数dataを解放
        SAFE_DELETE(data);

        g_gameScene = SC_PLAY;		//プレイシーンに移行
    }

    return S_OK;			//成功を返す
}
Пример #12
0
static void WrappedCallPragma (StrBuf* B)
/* Handle the wrapped-call pragma */
{
    StrBuf      S = AUTO_STRBUF_INITIALIZER;
    const char *Name;
    long Val;
    SymEntry *Entry;

    /* Check for the "push" or "pop" keywords */
    switch (ParsePushPop (B)) {

        case PP_NONE:
            Error ("Push or pop required");
            break;

        case PP_PUSH:
            break;

        case PP_POP:
            PopWrappedCall();

            /* Done */
            goto ExitPoint;

        case PP_ERROR:
            /* Bail out */
            goto ExitPoint;

        default:
            Internal ("Invalid result from ParsePushPop");

    }

    /* A symbol argument must follow */
    if (!SB_GetSym (B, &S, NULL)) {
        goto ExitPoint;
    }

    /* Skip the following comma */
    if (!GetComma (B)) {
        /* Error already flagged by GetComma */
        Error ("Value required for wrapped-call identifier");
        goto ExitPoint;
    }

    if (!GetNumber (B, &Val)) {
        Error ("Value required for wrapped-call identifier");
        goto ExitPoint;
    }

    if (Val < 0 || Val > 255) {
        Error ("Identifier must be between 0-255");
        goto ExitPoint;
    }

    /* Get the string */
    Name = SB_GetConstBuf (&S);
    Entry = FindSym(Name);

    /* Check if the name is valid */
    if (Entry && Entry->Flags & SC_FUNC) {

        PushWrappedCall(Entry, (unsigned char) Val);
        Entry->Flags |= SC_REF;
        Entry->V.F.Func->Flags |= FD_CALL_WRAPPER;

    } else {

        /* Segment name is invalid */
        Error ("Wrapped-call target does not exist or is not a function");

    }

ExitPoint:
    /* Call the string buf destructor */
    SB_Done (&S);
}