Пример #1
0
int get_key_len(const char **user){
    char section[50]; //nazwa sekcji
    char mobile[50]; //nazwa telefonu dla uzytkownika

	int key_len; // dlogosc klucza z konfigu
    int  s; //iterator sekcji
    int  b; // enabled, true/false

//  Szukaj uzytkownikow
	for (s = 0; ini_getsection(s, section, sizearray(section), inifile_users) > 0; s++) {
		printf("get_key_len() [%s] user: %s\n", section, *user);
		if (!strcmp(*user, section)){
			printf("user cfg exists\n");
			b = ini_getbool(section, "enabled", 0, inifile_users);
			if(b == 1){
			//pobierz nazwe telfonu przypisanego do uzytkownika
				ini_gets(section, "mobile", "0", mobile, sizearray(mobile), inifile_users);
			//  pobierz dlugosc klucza i klucz
				key_len = ini_getl(mobile, "key_len", 1, inifile_mobiles);
				printf("get_key_len(): key length: %d\n", key_len);
				return key_len;
			}
		}
	} /* for */
	return -1;
}
Пример #2
0
void actuator_initfunc(char *cfgfile, int devno) {
  char cmd[255];
  char *cmd_with_path;
  char *cmd_only;
  
  debug("[external actuator plugin] actuator_initfunc device %d\n",devno);

  if (devno==0) {
    ini_gets("actuator_plugin_external", "actuator_on", EXTACTON, ext_act_cfg.extactuatoron[0],
              sizearray(ext_act_cfg.extactuatoron[0]), cfgfile);
    ini_gets("actuator_plugin_external", "actuator_off", EXTACTOFF, ext_act_cfg.extactuatoroff[0],
              sizearray(ext_act_cfg.extactuatoroff[0]), cfgfile);
  }
  if (devno==1) {
    ini_gets("actuator_plugin_external", "stirring_device_on", EXTSTIRON,
              ext_act_cfg.extactuatoron[1], sizearray(ext_act_cfg.extactuatoron[1]), cfgfile);
    ini_gets("actuator_plugin_external", "stirring_device_off", EXTSTIRON,
              ext_act_cfg.extactuatoroff[1], sizearray(ext_act_cfg.extactuatoroff[1]), cfgfile);
  }
  // check if command is available in PATH
  strcpy(cmd,ext_act_cfg.extactuatoron[devno]);
  cmd_only=strtok(cmd," ");
  if (0==searchXfile(cmd_only,&cmd_with_path))
    free(cmd_with_path);
  else
    die("[external actuator plugin] can not find command >%s<\n",cmd_only);
}
Пример #3
0
// Property sheet
void preferenceCreate(HWND parent)
{
	HINSTANCE instance = FBALocaliseInstance();
	PROPSHEETPAGE psp[3];
	PROPSHEETHEADER psh;

	for (int i = 0; i < sizearray(psp); i++) {
		psp[i].dwSize = sizeof(PROPSHEETPAGE);
		psp[i].dwFlags = PSP_DEFAULT;
		psp[i].hInstance = instance;
		psp[i].lParam = 0;
		psp[i].pfnCallback = NULL;
	}
	psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREF_VIDEO);
	psp[0].pfnDlgProc = (DLGPROC)prefVideoDlgProc;
	psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREF_AUDIO);
	psp[1].pfnDlgProc = (DLGPROC)prefAudioDlgProc;
	psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PREF_MISC);
	psp[2].pfnDlgProc = (DLGPROC)prefMiscDlgProc;

	psh.dwSize = sizeof(PROPSHEETHEADER);
	psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
	psh.hwndParent = parent;
	psh.hInstance = instance;
	psh.pszCaption = FBALoadStringEx(IDS_PREF_SETTINGS);
	psh.nPages = sizearray(psp);
	psh.nStartPage = 0;
	psh.ppsp = (LPCPROPSHEETPAGE)&psp;
	psh.pfnCallback = NULL;
	PropertySheet(&psh);
}
Пример #4
0
int createDatfileWindows(int type)
{
    TCHAR szTitle[MAX_PATH];
    TCHAR szFilter[MAX_PATH];

    _sntprintf(szChoice, sizearray(szChoice), _T(APP_TITLE) _T(" v%.20s (%s).dat"), szAppBurnVer, _T("clrmamepro"));
    _sntprintf(szTitle, sizearray(szTitle), FBALoadStringEx(IDS_DAT_GENERATE), _T("clrmamepro"));

    _stprintf(szFilter, FBALoadStringEx(IDS_DISK_ALL_DAT), _T(APP_TITLE));
    memcpy(szFilter + _tcslen(szFilter), _T(" (*.dat)\0*.dat\0\0"), 16 * sizeof(TCHAR));

    memset(&ofn, 0, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hScrnWnd;
    ofn.lpstrFilter = szFilter;
    ofn.lpstrFile = szChoice;
    ofn.nMaxFile = sizearray(szChoice);
    ofn.lpstrInitialDir = _T(".");
    ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
    ofn.lpstrDefExt = _T("dat");
    ofn.lpstrTitle = szTitle;

    if (GetSaveFileName(&ofn) == 0)
        return 1;

    return create_datfile(szChoice, type);
}
Пример #5
0
int processPostData(char *postData)
{

    char *token;
    char buf[1024];
    char decodedToken[100];
    char action[80];
    char section[80];
    char field[80];
    char value[80];
    int smartDnsUpdatePerformed;
    char smartDnsProviderPrimary[1024];
    char smartDnsProviderSecondary[1024];
    int n;

    sscanf(postData, "action=%[0-9a-zA-Z]", &action);
    if(compStr(action, "update", sizearray(action)))
    {
        token = strtok (postData,"&");
        while (token != NULL)
        {
            //check if contains / so we know it's a var to update
            urldecode2(decodedToken, token);
            if(strstr(decodedToken, "/") != NULL)
            {
                sscanf(decodedToken, "%[0-9a-zA-Z]/%[0-9a-zA-Z]=%[0-9a-zA-Z.:/_%-]", section, field, value);
                //check if DNS update and allowed to perform
                if(compStr(section, "DNS", sizearray(section)) && !compStr(field, "useDHCP", sizearray(field)) && (smartDnsUpdatePerformed == 1))
                {
                    //do nothing
                }
                else
                {
                    n = write_config_var(section, field, value);
                }
                //Check if an update for smartDNS selected which is not set to other
                if(compStr(section, "SmartDNS", sizearray(section)) && compStr(field, "selected", sizearray(section)) && !compStr(value, "other", sizearray(section)))
                {
                    strcpy(buf, "SmartDNS-");
                    strcat(buf, value);
                    //get DNS details for SmartDNS provider
                    read_config_var(buf, "primary", smartDnsProviderPrimary);
                    read_config_var(buf, "secondary", smartDnsProviderSecondary);
                    //set DNS details to selected SmartDNS Provider
                    n = write_config_var("DNS", "primary", smartDnsProviderPrimary);
                    n = write_config_var("DNS", "secondary", smartDnsProviderSecondary);
                    //set that DNS update has been performed so any unwanted commits don't occur after
                    smartDnsUpdatePerformed=1;
                }
            }
            token = strtok (NULL, "&");
        }

    }
}
Пример #6
0
int FBAPopupAddText(int nFlags, TCHAR* pszFormat, ...)
{
	TCHAR szString[1024] = _T("");
	TCHAR* pszStringEnglish = NULL;

	va_list vaEnglish;
	va_start(vaEnglish, pszFormat);

	pszStringEnglish = pszFormat;
	 
	// See if we need to load strings from reources
	if (nFlags & PUF_TEXT_TRANSLATE) {
		TCHAR* pszStringLocal;

		va_list vaLocal;
		va_start(vaLocal, pszFormat);

		pszStringLocal = pszFormat;

		// Add the translated string if present
		if (bLanguageActive && (nFlags & PUF_TEXT_TRANSLATE) &&  pszStringLocal && *pszStringLocal) {
			// Add the translated string
			int nLen = _vsntprintf(szString, sizearray(szString), pszStringLocal, vaLocal);
			if (nLen > 0) {
				TCHAR* pszNewBuffer = (TCHAR*)realloc(pszBufferLocal, (nLen + nBufferLocalSize + 1) * sizeof(TCHAR));
				if (pszNewBuffer) {
					pszBufferLocal = pszNewBuffer;
					_tcsncpy(pszBufferLocal + nBufferLocalSize, szString, nLen);
					nBufferLocalSize += nLen;
					pszBufferLocal[nBufferLocalSize] = 0;
				}
			}
		}

		va_end(vaLocal);
	}

	// Add the English language string
	if (pszStringEnglish && *pszStringEnglish) {
		int nLen = _vsntprintf(szString, sizearray(szString), pszStringEnglish, vaEnglish);
		if (nLen > 0) {
			TCHAR* pszNewBuffer = (TCHAR*)realloc(pszBufferEnglish, (nLen + nBufferEnglishSize + 1) * sizeof(TCHAR));
			if (pszNewBuffer) {
				pszBufferEnglish = pszNewBuffer;
				_tcsncpy(pszBufferEnglish + nBufferEnglishSize, szString, nLen);
				nBufferEnglishSize += nLen;
				pszBufferEnglish[nBufferEnglishSize] = 0;
			}
		}
	}

	va_end(vaEnglish);

	return 0;
}
Пример #7
0
TCHAR* FBALoadStringEx(UINT id, bool translate)
{
	static TCHAR loadstr[2048] = _T("");

	if (translate) {
		FBALoadString(id, loadstr, sizearray(loadstr));
	} else {
		LoadString(hAppInst, id, loadstr, sizearray(loadstr));
	}

	return loadstr;
}
Пример #8
0
// Wejscie:
//      user - login
// Wyjscia
//      btaddr
//      port
//      mobile_id 
//      rssi
int get_user_data(const char **user, char* btaddr, int *port, char *mobile_id,
        float *rssi){
    char section[50]; //nazwa sekcji
    char mobile[50]; //nazwa telefonu dla uzytkownika
    char addr[18];

    int  s; //iterator sekcji
    int  b; // enabled, true/false
    int  p; // port
    float min_rssi; // rssi
    //char user_login[] = *user;

      for (s = 0; ini_getsection(s, section, sizearray(section), inifile_users) > 0; s++) {
        //printf("    [%s] user: %s\n", section, *user);

        if (!strcmp(*user, section)){
            printf("user cfg exists\n");

            b = ini_getbool(section, "enabled", 0, inifile_users);
            if(b == 1){
//pobierz nazwe telfonu przypisanego do uzytkownika
                ini_gets(section, "mobile", "0", mobile, sizearray(mobile), inifile_users);
//pobierrz btaddr i port telefonu o ww nazwie
                ini_gets(mobile, "btaddr", "999", addr, sizearray(addr),
                 inifile_mobiles);
                p = ini_getl(mobile, "port", 999, inifile_mobiles);
//  pobierz wartosc progu RSSI
                min_rssi = ini_getf(mobile, "min_rssi", "-5.0", inifile_users);
                
                printf("user %s enabled with mobile: %s\n", *user, mobile);
                printf("mobile btaddr: %s, port: %d\n", addr, p);
                printf("rssi threshold: %f\n", min_rssi);
                //printf("check_user(): key length: %d, key: %s\n", key_len, k);

//zapisz btaddr, port i klucz do adresow z argumetu
                strcpy(btaddr,addr);
                strcpy(mobile_id, mobile);
                *port = p;
                *rssi = min_rssi;
                return 0;
            }

            //for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
            //  printf("\t%s\n", str);
            //} /* for */
        }
      } /* for */
return E_INI_FILE;
}
Пример #9
0
int Profile_GetBoolean(const char *Section, const char *Key, int DefValue)
{
    char buff[64];
    int len = Profile_GetString(Section, Key, "", buff, sizearray(buff));
    int ret = 0;
    //  printf("int %s \n",buff);

    if (len == 0)
    {
        return DefValue;
    }

    if((buff[0] == 'y') || (buff[0] == 'Y') || (buff[0] == '1') || (buff[0] == 't') || (buff[0] == 'T'))
    {
        ret = 1 ;
    }
    else if((buff[0] == 'n') || (buff[0] == 'N') || (buff[0] == '0') || (buff[0] == 'f') || (buff[0] == 'F'))
    {
        ret = 0 ;
    }
    else
    {
        ret = DefValue ;
    }
    return ret;
}
Пример #10
0
static void mountCartridge(const bool& mount)
{
    if (mount) {
        if (BurnCartridgeGameLoaded) {
            memset(&ofn, 0, sizeof(ofn));
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = hScrnWnd;
            ofn.lpstrFilter = pBurnCartridgeFileExtFilter;
            ofn.lpstrFile = szChoice;
            ofn.nMaxFile = sizearray(szChoice);
            ofn.Flags = OFN_HIDEREADONLY;

            int bOldPause = bRunPause;
            bRunPause = 1;
            int nRet = GetOpenFileName(&ofn);
            bRunPause = bOldPause;
            if (nRet && pBurnInsertCartridgeCallBack) {
                pBurnInsertCartridgeCallBack(szChoice);
            }
        }
    } else {
        if (BurnCartridgeGameLoaded && pBurnInsertCartridgeCallBack) {
            pBurnInsertCartridgeCallBack(0);
        }
    }
}
Пример #11
0
void quickLoadFile()
{
    SplashDestroy(1);
    audio.stop();

    memset(&ofn, 0, sizeof(ofn));
    ofn.lpstrTitle = _T("Quick Load games");
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hScrnWnd;
    ofn.lpstrFilter = _T("All support types\0*.zip;*.7z;*.fr;*.fs\0") _T("Archive File (*.zip,*.7z)\0*.zip;*.7z\0\0");
    ofn.lpstrFile = szChoice;
    ofn.nMaxFile = sizearray(szChoice);
    ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY;

    int bOldPause = bRunPause;
    bRunPause = 1;
    int nRet = GetOpenFileName(&ofn);
    bRunPause = bOldPause;

    audio.play();

    if (nRet == 0)
        return;

    directLoadGame(szChoice);
}
Пример #12
0
int ini_getbool_OpenedFile(
		const mTCHAR *Section,
		const mTCHAR *Key,
		int DefValue,
		INI_FILETYPE* pFile
)
{
	TCHAR LocalBuffer[2];
	int ret;
	int pos = 0;

	(void) ini_seek(pFile, &pos);

	ini_gets_OpenedFile(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), pFile);

	LocalBuffer[0] = (TCHAR) toupper(LocalBuffer[0]);
	if (LocalBuffer[0] == 'Y' || LocalBuffer[0] == '1' || LocalBuffer[0] == 'T')
		ret = 1;
	else if (LocalBuffer[0] == 'N' || LocalBuffer[0] == '0' || LocalBuffer[0] == 'F')
		ret = 0;
	else
		ret = DefValue;

	return (ret);
}
Пример #13
0
/** ini_getl()
 * \param Section     the name of the section to search for
 * \param Key         the name of the entry to find the value of
 * \param DefValue    the default value in the event of a failed read
 * \param Filename    the name of the .ini file to read from
 *
 * \return            the value located at Key
 */
long ini_getl(const TCHAR *Section, const TCHAR *Key, long DefValue, const TCHAR *Filename)
{
  TCHAR LocalBuffer[64];
  int len = ini_gets(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), Filename);
  return (len == 0) ? DefValue : ((len >= 2 && _totupper(LocalBuffer[1]) == 'X') ? _tcstol(LocalBuffer, NULL, 16)
                                                                      : _tcstol(LocalBuffer, NULL, 10));
}
Пример #14
0
int main()
{
    sizearray();
    char * text = pointertest();
    printf("\nOutput of pointer: %s\n",text);
	printf("3x3x3=%d",do_pow(3)); 
    return 0;
}
Пример #15
0
static void localiseMakeOfn()
{
	memset(&ofn, 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hScrnWnd;
	ofn.lpstrFilter = _T("Language (*.dll)\0*.dll\0All Files (*.*)\0*.*\0\0");
	ofn.lpstrFile = szChoice;
	ofn.nMaxFile = sizearray(szChoice);
	ofn.lpstrInitialDir = _T("lang");
	ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	ofn.lpstrDefExt = _T("dll");
}
Пример #16
0
/** Profile_GetInteger()
* \param Section     the name of the section to search for
* \param Key         the name of the entry to find the value of
* \param DefValue    the default value in the event of a failed read
*
* \return            the value located at Key
*/
long Profile_GetInteger(const char *Section, const char *Key, long DefValue)
{
    char buff[64];
    int len = Profile_GetString(Section, Key, "", buff, sizearray(buff));
    //  printf("int %s \n",buff);

    if (len == 0)
    return DefValue;

    if (buff[0] == '0' && String_ToUpperCase(buff[1]) == 'X')
    return String_AParseHexU32(buff);
        else
            return _tcstol(buff,NULL,10);
}
Пример #17
0
long ini_getl_OpenedFile(
		const mTCHAR *Section,
		const mTCHAR *Key,
		long DefValue,
		INI_FILETYPE* pFile)
{
	TCHAR LocalBuffer[64];
	int pos = 0;

//	(void) ini_seek(pFile, &pos);

	int len = ini_gets_OpenedFile(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), pFile);
	return (len == 0) ? DefValue : ((len >= 2 && _totupper(LocalBuffer[1]) == 'X') ? _tcstol(LocalBuffer, NULL, 16)
																	  : _tcstol(LocalBuffer, NULL, 10));
}
Пример #18
0
static void audioFrameInit()
{
	if (!hAudioDlg) {
		return;
	}

	// Initialise slider
	TCHAR szText[MAX_PATH];
	_sntprintf(szText, sizearray(szText), FBALoadStringEx(IDS_NUMDLG_FRAME), nAudSegCount, int(1000.0 * (nAudSegCount - 1.0) / 60));
	SetDlgItemText(hAudioDlg, IDC_PREF_AUDFRAME_TEXT, szText);

	// limit in 2 - 10
	SendDlgItemMessage(hAudioDlg, IDC_PREF_AUDFRAME, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(2, 10));
	SendDlgItemMessage(hAudioDlg, IDC_PREF_AUDFRAME, TBM_SETTIC, 0, (LPARAM)6);
	SendDlgItemMessage(hAudioDlg, IDC_PREF_AUDFRAME, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)nAudSegCount);
}
Пример #19
0
static void WaveMakeOfn(TCHAR* pszFilter)
{
    _stprintf(pszFilter, FBALoadStringEx(IDS_DISK_FILE_SOUND), _T(APP_TITLE));
    memcpy(pszFilter + _tcslen(pszFilter), _T(" (*.wav)\0*.wav\0\0"), 16 * sizeof(TCHAR));

    memset(&ofn, 0, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hScrnWnd;
    ofn.lpstrFilter = pszFilter;
    ofn.lpstrFile = szChoice;
    ofn.nMaxFile = sizearray(szChoice);
    ofn.lpstrInitialDir = _T(".\\wav");
    ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = _T("wav");
    return;
}
Пример #20
0
/** ini_getbool()
 * \param Section     the name of the section to search for
 * \param Key         the name of the entry to find the value of
 * \param DefValue    default value in the event of a failed read; it should
 *                    zero (0) or one (1).
 * \param Buffer      a pointer to the buffer to copy into
 * \param BufferSize  the maximum number of characters to copy
 * \param Filename    the name and full path of the .ini file to read from
 *
 A true boolean is found if one of the following is matched:

  - A string starting with 'y'
  - A string starting with 'Y'
  - A string starting with 't'
  - A string starting with 'T'
  - A string starting with '1'

  A false boolean is found if one of the following is matched:

  - A string starting with 'n'
  - A string starting with 'N'
  - A string starting with 'f'
  - A string starting with 'F'
  - A string starting with '0'
 *
 * \return            the true/false flag as interpreted at Key
 */
int ini_getbool(const TCHAR *Section, const TCHAR *Key, int DefValue, const TCHAR *Filename)
{
  TCHAR buff[2];
  int ret;

  ini_gets(Section, Key, __T(""), buff, sizearray(buff), Filename);
  buff[0] = toupper(buff[0]);
  if (buff[0]=='Y' || buff[0]=='1' || buff[0]=='T')
    ret = 1;
  else if (buff[0]=='N' || buff[0]=='0' || buff[0]=='F')
    ret = 0;
  else
    ret = DefValue;

  return(ret);
}
Пример #21
0
static void miscSliderInit()
{
	if (!hMiscDlg) {
		return;
	}

	// Initialise slider
	TCHAR szText[16];
	_sntprintf(szText, sizearray(szText), _T("%d"), nAppThreadPriority);
	SetDlgItemText(hMiscDlg, IDC_PREF_THREADPRIORITY_TEXT, szText);

	// thread priority, limit in -15 ~ 1
	SendDlgItemMessage(hMiscDlg, IDC_PREF_THREADPRIORITY, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(-15, 1));
	SendDlgItemMessage(hMiscDlg, IDC_PREF_THREADPRIORITY, TBM_SETTIC, 0, 0);
	SendDlgItemMessage(hMiscDlg, IDC_PREF_THREADPRIORITY, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)nAppThreadPriority);
}
Пример #22
0
/** ini_getbool()
 * \param Section     the name of the section to search for
 * \param Key         the name of the entry to find the value of
 * \param DefValue    default value in the event of a failed read; it should
 *                    zero (0) or one (1).
 * \param Buffer      a pointer to the buffer to copy into
 * \param BufferSize  the maximum number of characters to copy
 * \param Filename    the name and full path of the .ini file to read from
 *
 * A true boolean is found if one of the following is matched:
 * - A string starting with 'y' or 'Y'
 * - A string starting with 't' or 'T'
 * - A string starting with '1'
 *
 * A false boolean is found if one of the following is matched:
 * - A string starting with 'n' or 'N'
 * - A string starting with 'f' or 'F'
 * - A string starting with '0'
 *
 * \return            the true/false flag as interpreted at Key
 */
int ini_getbool(const TCHAR *Section, const TCHAR *Key, int DefValue, const TCHAR *Filename)
{
  TCHAR LocalBuffer[2];
  int ret;

  ini_gets(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), Filename);
  LocalBuffer[0] = (TCHAR)toupper(LocalBuffer[0]);
  if (LocalBuffer[0] == 'Y' || LocalBuffer[0] == '1' || LocalBuffer[0] == 'T')
    ret = 1;
  else if (LocalBuffer[0] == 'N' || LocalBuffer[0] == '0' || LocalBuffer[0] == 'F')
    ret = 0;
  else
    ret = DefValue;

  return(ret);
}
Пример #23
0
int FBALocaliseInit(TCHAR* lanaugae)
{
	FBALocaliseExit();

	if (!lanaugae || !lanaugae[0]) {
		return 0;
	}

	hLanguage = LoadLibrary(lanaugae);
	if (!hLanguage) {
		FBAPopupAddText(PUF_TYPE_WARNING, _T("Language dll load failed!"));
		FBAPopupDisplay(PUF_TYPE_WARNING);
		return 1;
	}

	_tcsncpy(szLanguage, lanaugae, sizearray(szLanguage));
	bLanguageActive = true;
	return 0;
}
Пример #24
0
Файл: exptree.c Проект: pix/cppp
/* Inserts a subtree into the given expression tree, with pos being
 * the index of where to add the child branch.
 */
static int addchild(struct exptree *t, struct exptree *sub, int pos)
{
    int n;

    if (t->childcount == sizearray(t->child) || !sub)
	return FALSE;
    if (pos < -1 || pos > t->childcount)
	return FALSE;

    if (pos == -1 || pos == t->childcount) {
	t->child[t->childcount] = sub;
    } else {
	for (n = t->childcount ; n > pos ; --n)
	    t->child[n] = t->child[n - 1];
	t->child[pos] = sub;
    }
    ++t->childcount;
    return TRUE;
}
Пример #25
0
int scrnTitle()
{
    TCHAR szText[1024] = _T("");

    // Create window title
    if (bDrvOkay) {
        TCHAR* pszPosition = szText;
        TCHAR* pszName = transGameName(BurnDrvGetText(DRV_FULLNAME));

        if (bShowFPS) {
            extern TCHAR fpsString[];
            pszPosition += _sntprintf(szText, sizearray(szText), _T("%s"), pszName);
            _stprintf(pszPosition, _T(" ") _T("[") _T("%s") _T("]"), fpsString);
        } else {
            _stprintf(szText, _T("%s"), pszName);
        }
    } else {
        _stprintf(szText, _T(APP_TITLE) _T( " v%.20s"), szAppBurnVer);
    }

    SetWindowText(hScrnWnd, szText);
    return 0;
}
Пример #26
0
cell amx_exec_run(AMX *amx,cell *retval,unsigned char *data)
{
static const void * const amx_opcodelist[] = {
        /* core set */
        &&op_nop,         &&op_load_pri,    &&op_load_alt,    &&op_load_s_pri,
        &&op_load_s_alt,  &&op_lref_s_pri,  &&op_lref_s_alt,  &&op_load_i,
        &&op_lodb_i,      &&op_const_pri,   &&op_const_alt,   &&op_addr_pri,
        &&op_addr_alt,    &&op_stor,        &&op_stor_s,      &&op_sref_s,
        &&op_stor_i,      &&op_strb_i,      &&op_align_pri,   &&op_lctrl,
        &&op_sctrl,       &&op_xchg,        &&op_push_pri,    &&op_push_alt,
        &&op_pushr_pri,   &&op_pop_pri,     &&op_pop_alt,     &&op_pick,
        &&op_stack,       &&op_heap,        &&op_proc,        &&op_ret,
        &&op_retn,        &&op_call,        &&op_jump,        &&op_jzer,
        &&op_jnz,         &&op_shl,         &&op_shr,         &&op_sshr,
        &&op_shl_c_pri,   &&op_shl_c_alt,   &&op_smul,        &&op_sdiv,
        &&op_add,         &&op_sub,         &&op_and,         &&op_or,
        &&op_xor,         &&op_not,         &&op_neg,         &&op_invert,
        &&op_eq,          &&op_neq,         &&op_sless,       &&op_sleq,
        &&op_sgrtr,       &&op_sgeq,        &&op_inc_pri,     &&op_inc_alt,
        &&op_inc_i,       &&op_dec_pri,     &&op_dec_alt,     &&op_dec_i,
        &&op_movs,        &&op_cmps,        &&op_fill,        &&op_halt,
        &&op_bounds,      &&op_sysreq,      &&op_switch,      &&op_swap_pri,
        &&op_swap_alt,    &&op_break,       &&op_casetbl,
        /* patched instructions */
        /* if op_sysreq_d and/or op_sysreq_nd are not implemented, their entries
         * in this table must be NULL
         */
        &&op_sysreq_d,    &&op_sysreq_nd,
        /* overlay instructions */
        &&op_call_ovl,    &&op_retn_ovl,    &&op_switch_ovl,  &&op_casetbl_ovl,
        /* supplemental and macro instructions */
#if !defined AMX_NO_MACRO_INSTR
        &&op_lidx,        &&op_lidx_b,      &&op_idxaddr,     &&op_idxaddr_b,
        &&op_push_c,      &&op_push,        &&op_push_s,      &&op_push_adr,
        &&op_pushr_c,     &&op_pushr_s,     &&op_pushr_adr,   &&op_jeq,
        &&op_jneq,        &&op_jsless,      &&op_jsleq,       &&op_jsgrtr,
        &&op_jsgeq,       &&op_sdiv_inv,    &&op_sub_inv,     &&op_add_c,
        &&op_smul_c,      &&op_zero_pri,    &&op_zero_alt,    &&op_zero,
        &&op_zero_s,      &&op_eq_c_pri,    &&op_eq_c_alt,    &&op_inc,
        &&op_inc_s,       &&op_dec,         &&op_dec_s,       &&op_sysreq_n,
        &&op_pushm_c,     &&op_pushm,       &&op_pushm_s,     &&op_pushm_adr,
        &&op_pushrm_c,    &&op_pushrm_s,    &&op_pushrm_adr,  &&op_load2,
        &&op_load2_s,     &&op_const,       &&op_const_s,
#endif
#if !defined AMX_NO_PACKED_OPC
        &&op_load_p_pri,  &&op_load_p_alt,  &&op_load_p_s_pri,&&op_load_p_s_alt,
        &&op_lref_p_s_pri,&&op_lref_p_s_alt,&&op_lodb_p_i,    &&op_const_p_pri,
        &&op_const_p_alt, &&op_addr_p_pri,  &&op_addr_p_alt,  &&op_stor_p,
        &&op_stor_p_s,    &&op_sref_p_s,    &&op_strb_p_i,    &&op_lidx_p_b,
        &&op_idxaddr_p_b, &&op_align_p_pri, &&op_push_p_c,    &&op_push_p,
        &&op_push_p_s,    &&op_push_p_adr,  &&op_pushr_p_c,   &&op_pushr_p_s,
        &&op_pushr_p_adr, &&op_pushm_p_c,   &&op_pushm_p,     &&op_pushm_p_s,
        &&op_pushm_p_adr, &&op_pushrm_p_c,  &&op_pushrm_p_s,  &&op_pushrm_p_adr,
        &&op_stack_p,     &&op_heap_p,      &&op_shl_p_c_pri, &&op_shl_p_c_alt,
        &&op_add_p_c,     &&op_smul_p_c,    &&op_zero_p,      &&op_zero_p_s,
        &&op_eq_p_c_pri,  &&op_eq_p_c_alt,  &&op_inc_p,       &&op_inc_p_s,
        &&op_dec_p,       &&op_dec_p_s,     &&op_movs_p,      &&op_cmps_p,
        &&op_fill_p,      &&op_halt_p,      &&op_bounds_p,
#endif
};
  AMX_HEADER *hdr;
  cell pri,alt,stk,frm,hea;
  cell reset_stk, reset_hea, *cip;
  cell offs,val;
  int num,i;
  #if !defined AMX_NO_PACKED_OPC
    int op;
  #endif

  assert(amx!=NULL);
  /* HACK: return label table and opcode count (for VerifyPcode()) if amx
   * structure has the flags set to all ones (see amx_exec_list() above)
   */
  if (amx->flags==~0) {
    assert(sizeof(cell)==sizeof(void *));
    assert(data==NULL);
    assert(retval!=NULL);
    *retval=(cell)amx_opcodelist;
    return sizearray(amx_opcodelist);
  } /* if */

  /* set up the registers */
  hdr=(AMX_HEADER *)amx->base;
  assert(hdr->magic==AMX_MAGIC);
  assert(hdr->file_version>=11);
  cip=(cell*)amx->cip;
  hea=amx->hea;
  stk=amx->stk;
  reset_stk=stk;
  reset_hea=hea;
  alt=frm=pri=0;/* just to avoid compiler warnings */
  num=0;        /* just to avoid compiler warnings */

  /* start running */
  assert(amx->code!=NULL);
  assert(data!=NULL);
  cip=(cell *)(amx->code+(int)amx->cip);
  NEXT(cip,op);

  op_nop:
    NEXT(cip,op);
  op_load_pri:
    GETPARAM(offs);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_load_alt:
    GETPARAM(offs);
    alt=_R(data,offs);
    NEXT(cip,op);
  op_load_s_pri:
    GETPARAM(offs);
    pri=_R(data,frm+offs);
    NEXT(cip,op);
  op_load_s_alt:
    GETPARAM(offs);
    alt=_R(data,frm+offs);
    NEXT(cip,op);
  op_lref_s_pri:
    GETPARAM(offs);
    offs=_R(data,frm+offs);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_lref_s_alt:
    GETPARAM(offs);
    offs=_R(data,frm+offs);
    alt=_R(data,offs);
    NEXT(cip,op);
  op_load_i:
    /* verify address */
    if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    pri=_R(data,pri);
    NEXT(cip,op);
  op_lodb_i:
    GETPARAM(offs);
  __lodb_i:
    /* verify address */
    if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    switch (offs) {
    case 1:
      pri=_R8(data,pri);
      break;
    case 2:
      pri=_R16(data,pri);
      break;
    case 4:
      pri=_R32(data,pri);
      break;
    } /* switch */
    NEXT(cip,op);
  op_const_pri:
    GETPARAM(pri);
    NEXT(cip,op);
  op_const_alt:
    GETPARAM(alt);
    NEXT(cip,op);
  op_addr_pri:
    GETPARAM(pri);
    pri+=frm;
    NEXT(cip,op);
  op_addr_alt:
    GETPARAM(alt);
    alt+=frm;
    NEXT(cip,op);
  op_stor:
    GETPARAM(offs);
    _W(data,offs,pri);
    NEXT(cip,op);
  op_stor_s:
    GETPARAM(offs);
    _W(data,frm+offs,pri);
    NEXT(cip,op);
  op_sref_s:
    GETPARAM(offs);
    offs=_R(data,frm+offs);
    _W(data,offs,pri);
    NEXT(cip,op);
  op_stor_i:
    /* verify address */
    if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    _W(data,alt,pri);
    NEXT(cip,op);
  op_strb_i:
    GETPARAM(offs);
  __strb_i:
    /* verify address */
    if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    switch (offs) {
    case 1:
      _W8(data,alt,pri);
      break;
    case 2:
      _W16(data,alt,pri);
      break;
    case 4:
      _W32(data,alt,pri);
      break;
    } /* switch */
    NEXT(cip,op);
  op_align_pri:
    GETPARAM(offs);
    #if BYTE_ORDER==LITTLE_ENDIAN
      if (offs<(int)sizeof(cell))
        pri ^= sizeof(cell)-offs;
    #endif
    NEXT(cip,op);
  op_lctrl:
    GETPARAM(offs);
    switch (offs) {
    case 0:
      pri=hdr->cod;
      break;
    case 1:
      pri=hdr->dat;
      break;
    case 2:
      pri=hea;
      break;
    case 3:
      pri=amx->stp;
      break;
    case 4:
      pri=stk;
      break;
    case 5:
      pri=frm;
      break;
    case 6:
      pri=(cell)((unsigned char *)cip - amx->code);
      break;
    } /* switch */
    NEXT(cip,op);
  op_sctrl:
    GETPARAM(offs);
    switch (offs) {
    case 0:
    case 1:
    case 3:
      /* cannot change these parameters */
      break;
    case 2:
      hea=pri;
      break;
    case 4:
      stk=pri;
      break;
    case 5:
      frm=pri;
      break;
    case 6:
      cip=(cell *)(amx->code + (int)pri);
      break;
    } /* switch */
    NEXT(cip,op);
  op_xchg:
    offs=pri;         /* offs is a temporary variable */
    pri=alt;
    alt=offs;
    NEXT(cip,op);
  op_push_pri:
    PUSH(pri);
    NEXT(cip,op);
  op_push_alt:
    PUSH(alt);
    NEXT(cip,op);
  op_pushr_pri:
    PUSH(data+pri);
    NEXT(cip,op);
  op_pop_pri:
    POP(pri);
    NEXT(cip,op);
  op_pop_alt:
    POP(alt);
    NEXT(cip,op);
  op_pick:
    GETPARAM(offs);
    pri=_R(data,stk+offs);
    NEXT(cip,op);
  op_stack:
    GETPARAM(offs);
    alt=stk;
    stk+=offs;
    CHKMARGIN();
    CHKSTACK();
    NEXT(cip,op);
  op_heap:
    GETPARAM(offs);
    alt=hea;
    hea+=offs;
    CHKMARGIN();
    CHKHEAP();
    NEXT(cip,op);
  op_proc:
    PUSH(frm);
    frm=stk;
    CHKMARGIN();
    NEXT(cip,op);
  op_ret:
    POP(frm);
    POP(offs);
    /* verify the return address */
    if ((long)offs>=amx->codesize)
      ABORT(amx,AMX_ERR_MEMACCESS);
    cip=(cell *)(amx->code+(int)offs);
    NEXT(cip,op);
  op_retn:
    POP(frm);
    POP(offs);
    /* verify the return address */
    if ((long)offs>=amx->codesize)
      ABORT(amx,AMX_ERR_MEMACCESS);
    cip=(cell *)(amx->code+(int)offs);
    stk+= _R(data,stk) + sizeof(cell);  /* remove parameters from the stack */
    NEXT(cip,op);
  op_call:
    PUSH(((unsigned char *)cip-amx->code)+sizeof(cell));/* push address behind instruction */
    cip=JUMPREL(cip);                   /* jump to the address */
    NEXT(cip,op);
  op_jump:
    /* since the GETPARAM() macro modifies cip, you cannot
     * do GETPARAM(cip) directly */
    cip=JUMPREL(cip);
    NEXT(cip,op);
  op_jzer:
    if (pri==0)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_jnz:
    if (pri!=0)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_shl:
    pri<<=alt;
    NEXT(cip,op);
  op_shr:
    pri=(ucell)pri >> (ucell)alt;
    NEXT(cip,op);
  op_sshr:
    pri>>=alt;
    NEXT(cip,op);
  op_shl_c_pri:
    GETPARAM(offs);
    pri<<=offs;
    NEXT(cip,op);
  op_shl_c_alt:
    GETPARAM(offs);
    alt<<=offs;
    NEXT(cip,op);
  op_smul:
    pri*=alt;
    NEXT(cip,op);
  op_sdiv:
    if (pri==0)
      ABORT(amx,AMX_ERR_DIVIDE);
    /* use floored division and matching remainder */
    offs=pri;
    #if defined TRUNC_SDIV
      pri=alt/offs;
      alt=alt%offs;
    #else
      val=alt;                  /* portable routine for truncated division */
      pri=IABS(alt)/IABS(offs);
      if ((cell)(val ^ offs)<0)
        pri=-pri;
      alt=val-pri*offs;         /* calculate the matching remainder */
    #endif
    /* now "fiddle" with the values to get floored division */
    if (alt!=0 && (cell)(alt ^ offs)<0) {
      pri--;
      alt+=offs;
    } /* if */
    NEXT(cip,op);
  op_add:
    pri+=alt;
    NEXT(cip,op);
  op_sub:
    pri=alt-pri;
    NEXT(cip,op);
  op_and:
    pri&=alt;
    NEXT(cip,op);
  op_or:
    pri|=alt;
    NEXT(cip,op);
  op_xor:
    pri^=alt;
    NEXT(cip,op);
  op_not:
    pri=!pri;
    NEXT(cip,op);
  op_neg:
    pri=-pri;
    NEXT(cip,op);
  op_invert:
    pri=~pri;
    NEXT(cip,op);
  op_eq:
    pri= pri==alt ? 1 : 0;
    NEXT(cip,op);
  op_neq:
    pri= pri!=alt ? 1 : 0;
    NEXT(cip,op);
  op_sless:
    pri= pri<alt ? 1 : 0;
    NEXT(cip,op);
  op_sleq:
    pri= pri<=alt ? 1 : 0;
    NEXT(cip,op);
  op_sgrtr:
    pri= pri>alt ? 1 : 0;
    NEXT(cip,op);
  op_sgeq:
    pri= pri>=alt ? 1 : 0;
    NEXT(cip,op);
  op_inc_pri:
    pri++;
    NEXT(cip,op);
  op_inc_alt:
    alt++;
    NEXT(cip,op);
  op_inc_i:
    #if defined _R_DEFAULT
      *(cell *)(data+(int)pri) += 1;
    #else
      val=_R(data,pri);
      _W(data,pri,val+1);
    #endif
    NEXT(cip,op);
  op_dec_pri:
    pri--;
    NEXT(cip,op);
  op_dec_alt:
    alt--;
    NEXT(cip,op);
  op_dec_i:
    #if defined _R_DEFAULT
      *(cell *)(data+(int)pri) -= 1;
    #else
      val=_R(data,pri);
      _W(data,pri,val-1);
    #endif
    NEXT(cip,op);
  op_movs:
    GETPARAM(offs);
  __movs:
    /* verify top & bottom memory addresses, for both source and destination
     * addresses
     */
    if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if ((pri+offs)>hea && (pri+offs)<stk || (ucell)(pri+offs)>(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    #if defined _R_DEFAULT
      memcpy(data+(int)alt, data+(int)pri, (int)offs);
    #else
      for (i=0; i+4<offs; i+=4) {
        val=_R32(data,pri+i);
        _W32(data,alt+i,val);
      } /* for */
      for ( ; i<offs; i++) {
        val=_R8(data,pri+i);
        _W8(data,alt+i,val);
      } /* for */
    #endif
    NEXT(cip,op);
  op_cmps:
    GETPARAM(offs);
  __cmps:
    /* verify top & bottom memory addresses, for both source and destination
     * addresses
     */
    if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if ((pri+offs)>hea && (pri+offs)<stk || (ucell)(pri+offs)>(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    #if defined _R_DEFAULT
      pri=memcmp(data+(int)alt, data+(int)pri, (int)offs);
    #else
      pri=0;
      for (i=0; i+4<offs && pri==0; i+=4)
        pri=_R32(data,alt+i)-_R32(data,pri+i);
      for ( ; i<offs && pri==0; i++)
        pri=_R8(data,alt+i)-_R8(data,pri+i);
    #endif
    NEXT(cip,op);
  op_fill:
    GETPARAM(offs);
  __fill:
    /* verify top & bottom memory addresses */
    if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    for (i=(int)alt; offs>=(int)sizeof(cell); i+=sizeof(cell), offs-=sizeof(cell))
      _W32(data,i,pri);
    NEXT(cip,op);
  op_halt:
    GETPARAM(offs);
  __halt:
    if (retval!=NULL)
      *retval=pri;
    /* store complete status (stk and hea are already set in the ABORT macro) */
    amx->frm=frm;
    amx->pri=pri;
    amx->alt=alt;
    amx->cip=(cell)((unsigned char*)cip-amx->code);
    if (offs==AMX_ERR_SLEEP) {
      amx->stk=stk;
      amx->hea=hea;
      amx->reset_stk=reset_stk;
      amx->reset_hea=reset_hea;
      return (int)offs;
    } /* if */
    ABORT(amx,(int)offs);
  op_bounds:
    GETPARAM(offs);
    if ((ucell)pri>(ucell)offs) {
      amx->cip=(cell)((unsigned char *)cip-amx->code);
      ABORT(amx,AMX_ERR_BOUNDS);
    } /* if */
    NEXT(cip,op);
  op_sysreq:
    GETPARAM(offs);
    /* save a few registers */
    amx->cip=(cell)((unsigned char *)cip-amx->code);
    amx->hea=hea;
    amx->frm=frm;
    amx->stk=stk;
    num=amx->callback(amx,offs,&pri,(cell *)(data+(int)stk));
    if (num!=AMX_ERR_NONE) {
      if (num==AMX_ERR_SLEEP) {
        amx->pri=pri;
        amx->alt=alt;
        amx->reset_stk=reset_stk;
        amx->reset_hea=reset_hea;
        return num;
      } /* if */
      ABORT(amx,num);
    } /* if */
    NEXT(cip,op);
  op_switch: {
    cell *cptr=JUMPREL(cip)+1;  /* +1, to skip the "casetbl" opcode */
    cip=JUMPREL(cptr+1);        /* preset to "none-matched" case */
    num=(int)*cptr;             /* number of records in the case table */
    for (cptr+=2; num>0 && *cptr!=pri; num--,cptr+=2)
      /* nothing */;
    if (num>0)
      cip=JUMPREL(cptr+1);      /* case found */
    NEXT(cip,op);
    }
  op_swap_pri:
    offs=_R(data,stk);
    _W(data,stk,pri);
    pri=offs;
    NEXT(cip,op);
  op_swap_alt:
    offs=_R(data,stk);
    _W(data,stk,alt);
    alt=offs;
    NEXT(cip,op);
  op_break:
    assert((amx->flags & AMX_FLAG_VERIFY)==0);
    if (amx->debug!=NULL) {
      /* store status */
      amx->frm=frm;
      amx->stk=stk;
      amx->hea=hea;
      amx->cip=(cell)((unsigned char*)cip-amx->code);
      num=amx->debug(amx);
      if (num!=AMX_ERR_NONE) {
        if (num==AMX_ERR_SLEEP) {
          amx->pri=pri;
          amx->alt=alt;
          amx->reset_stk=reset_stk;
          amx->reset_hea=reset_hea;
          return num;
        } /* if */
        ABORT(amx,num);
      } /* if */
    } /* if */
    NEXT(cip,op);
  op_casetbl:
    assert(0);                  /* this should not occur during execution */
    ABORT(amx,AMX_ERR_INVINSTR);
  op_sysreq_d:          /* see op_sysreq */
    #if !defined AMX_DONT_RELOCATE
      GETPARAM(offs);
      /* save a few registers */
      amx->cip=(cell)((unsigned char *)cip-amx->code);
      amx->hea=hea;
      amx->frm=frm;
      amx->stk=stk;
      pri=((AMX_NATIVE)offs)(amx,(cell *)(data+(int)stk));
      if (amx->error!=AMX_ERR_NONE) {
        if (amx->error==AMX_ERR_SLEEP) {
          amx->pri=pri;
          amx->alt=alt;
          amx->reset_stk=reset_stk;
          amx->reset_hea=reset_hea;
          return AMX_ERR_SLEEP;
        } /* if */
        ABORT(amx,amx->error);
      } /* if */
      NEXT(cip,op);
    #else
      ABORT(amx,AMX_ERR_INVINSTR);
    #endif
  op_sysreq_nd:    /* see op_sysreq_n */
    #if !defined AMX_NO_MACRO_INSTR && !defined AMX_DONT_RELOCATE
      GETPARAM(offs);
      GETPARAM(val);
      PUSH(val);
      /* save a few registers */
      amx->cip=(cell)((unsigned char *)cip-amx->code);
      amx->hea=hea;
      amx->frm=frm;
      amx->stk=stk;
      pri=((AMX_NATIVE)offs)(amx,(cell *)(data+(int)stk));
      stk+=val+4;
      if (amx->error!=AMX_ERR_NONE) {
        if (amx->error==AMX_ERR_SLEEP) {
          amx->pri=pri;
          amx->alt=alt;
          amx->stk=stk;
          amx->reset_stk=reset_stk;
          amx->reset_hea=reset_hea;
          return AMX_ERR_SLEEP;
        } /* if */
        ABORT(amx,amx->error);
      } /* if */
      NEXT(cip,op);
    #else
      ABORT(amx,AMX_ERR_INVINSTR);
    #endif

    /* overlay instructions */
#if !defined AMX_NO_OVERLAY
  op_call_ovl:
    offs=(unsigned char *)cip-amx->code+sizeof(cell); /* skip address */
    assert(offs>=0 && offs<(1<<(sizeof(cell)*4)));
    PUSH((offs<<(sizeof(cell)*4)) | amx->ovl_index);
    amx->ovl_index=(int)*cip;
    assert(amx->overlay!=NULL);
    if ((num=amx->overlay(amx,amx->ovl_index))!=AMX_ERR_NONE)
      ABORT(amx,num);
    cip=(cell*)amx->code;
    NEXT(cip,op);
  op_retn_ovl:
    assert(amx->overlay!=NULL);
    POP(frm);
    POP(offs);
    amx->ovl_index=offs & (((ucell)~0)>>4*sizeof(cell));
    offs=(ucell)offs >> (sizeof(cell)*4);
    /* verify the index */
    stk+=_R(data,stk)+sizeof(cell);   /* remove parameters from the stack */
    num=amx->overlay(amx,amx->ovl_index); /* reload overlay */
    if (num!=AMX_ERR_NONE || (long)offs>=amx->codesize)
      ABORT(amx,AMX_ERR_MEMACCESS);
    cip=(cell *)(amx->code+(int)offs);
    NEXT(cip,op);
  op_switch_ovl: {
    cell *cptr=JUMPREL(cip)+1;  /* +1, to skip the "icasetbl" opcode */
    amx->ovl_index=*(cptr+1);   /* preset to "none-matched" case */
    num=(int)*cptr;             /* number of records in the case table */
    for (cptr+=2; num>0 && *cptr!=pri; num--,cptr+=2)
      /* nothing */;
    if (num>0)
      amx->ovl_index=*(cptr+1); /* case found */
    assert(amx->overlay!=NULL);
    if ((num=amx->overlay(amx,amx->ovl_index))!=AMX_ERR_NONE)
      ABORT(amx,num);
    cip=(cell*)amx->code;
    NEXT(cip,op);
    }
#else
  op_call_ovl:
  op_retn_ovl:
  op_switch_ovl:
    ABORT(amx,AMX_ERR_INVINSTR);
#endif
  op_casetbl_ovl:
    assert(0);                  /* this should not occur during execution */
    ABORT(amx,AMX_ERR_INVINSTR);

    /* supplemental and macro instructions */
#if !defined AMX_NO_MACRO_INSTR
  op_lidx:
    offs=pri*sizeof(cell)+alt;  /* implicit shift value for a cell */
    /* verify address */
    if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_lidx_b:
    GETPARAM(offs);
    offs=(pri << (int)offs)+alt;
    /* verify address */
    if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_idxaddr:
    pri=pri*sizeof(cell)+alt;
    NEXT(cip,op);
  op_idxaddr_b:
    GETPARAM(offs);
    pri=(pri << (int)offs)+alt;
    NEXT(cip,op);
  op_push_c:
    GETPARAM(offs);
    PUSH(offs);
    NEXT(cip,op);
  op_push:
    GETPARAM(offs);
    PUSH(_R(data,offs));
    NEXT(cip,op);
  op_push_s:
    GETPARAM(offs);
    PUSH(_R(data,frm+offs));
    NEXT(cip,op);
  op_push_adr:
    GETPARAM(offs);
    PUSH(frm+offs);
    NEXT(cip,op);
  op_pushr_c:
    GETPARAM(offs);
    PUSH(data+offs);
    NEXT(cip,op);
  op_pushr_s:
    GETPARAM(offs);
    PUSH(data+_R(data,frm+offs));
    NEXT(cip,op);
  op_pushr_adr:
    GETPARAM(offs);
    PUSH(data+frm+offs);
    NEXT(cip,op);
  op_jeq:
    if (pri==alt)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_jneq:
    if (pri!=alt)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_jsless:
    if (pri<alt)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_jsleq:
    if (pri<=alt)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_jsgrtr:
    if (pri>alt)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_jsgeq:
    if (pri>=alt)
      cip=JUMPREL(cip);
    else
      SKIPPARAM(1);
    NEXT(cip,op);
  op_sdiv_inv:
    if (alt==0)
      ABORT(amx,AMX_ERR_DIVIDE);
    /* use floored division and matching remainder */
    offs=alt;
    #if defined TRUNC_SDIV
      pri=pri/offs;
      alt=pri%offs;
    #else
      val=pri;                  /* portable routine for truncated division */
      pri=IABS(pri)/IABS(offs);
      if ((cell)(val ^ offs)<0)
        pri=-pri;
      alt=val-pri*offs;         /* calculate the matching remainder */
    #endif
    /* now "fiddle" with the values to get floored division */
    if (alt!=0 && (cell)(alt ^ offs)<0) {
      pri--;
      alt+=offs;
    } /* if */
    NEXT(cip,op);
  op_sub_inv:
    pri-=alt;
    NEXT(cip,op);
  op_add_c:
    GETPARAM(offs);
    pri+=offs;
    NEXT(cip,op);
  op_smul_c:
    GETPARAM(offs);
    pri*=offs;
    NEXT(cip,op);
  op_zero_pri:
    pri=0;
    NEXT(cip,op);
  op_zero_alt:
    alt=0;
    NEXT(cip,op);
  op_zero:
    GETPARAM(offs);
    _W(data,offs,0);
    NEXT(cip,op);
  op_zero_s:
    GETPARAM(offs);
    _W(data,frm+offs,0);
    NEXT(cip,op);
  op_eq_c_pri:
    GETPARAM(offs);
    pri= pri==offs ? 1 : 0;
    NEXT(cip,op);
  op_eq_c_alt:
    GETPARAM(offs);
    pri= alt==offs ? 1 : 0;
    NEXT(cip,op);
  op_inc:
    GETPARAM(offs);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)offs) += 1;
    #else
      val=_R(data,offs);
      _W(data,offs,val+1);
    #endif
    NEXT(cip,op);
  op_inc_s:
    GETPARAM(offs);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)(frm+offs)) += 1;
    #else
      val=_R(data,frm+offs);
      _W(data,frm+offs,val+1);
    #endif
    NEXT(cip,op);
  op_dec:
    GETPARAM(offs);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)offs) -= 1;
    #else
      val=_R(data,offs);
      _W(data,offs,val-1);
    #endif
    NEXT(cip,op);
  op_dec_s:
    GETPARAM(offs);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)(frm+offs)) -= 1;
    #else
      val=_R(data,frm+offs);
      _W(data,frm+offs,val-1);
    #endif
    NEXT(cip,op);
  op_sysreq_n:
    GETPARAM(offs);
    GETPARAM(val);
    PUSH(val);
    /* save a few registers */
    amx->cip=(cell)((unsigned char *)cip-amx->code);
    amx->hea=hea;
    amx->frm=frm;
    amx->stk=stk;
    num=amx->callback(amx,offs,&pri,(cell *)(data+(int)stk));
    stk+=val+4;
    if (num!=AMX_ERR_NONE) {
      if (num==AMX_ERR_SLEEP) {
        amx->pri=pri;
        amx->alt=alt;
        amx->stk=stk;
        amx->reset_stk=reset_stk;
        amx->reset_hea=reset_hea;
        return num;
      } /* if */
      ABORT(amx,num);
    } /* if */
    NEXT(cip,op);
  op_pushm_c:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(offs);
    } /* while */
    NEXT(cip,op);
  op_pushm:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(_R(data,offs));
    } /* while */
    NEXT(cip,op);
  op_pushm_s:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(_R(data,frm+offs));
    } /* while */
    NEXT(cip,op);
  op_pushm_adr:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(frm+offs);
    } /* while */
    NEXT(cip,op);
  op_pushrm_c:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(data+offs);
    } /* while */
    NEXT(cip,op);
  op_pushrm_s:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(data+_R(data,frm+offs));
    } /* while */
    NEXT(cip,op);
  op_pushrm_adr:
    GETPARAM(val);
    while (val--) {
      GETPARAM(offs);
      PUSH(data+frm+offs);
    } /* while */
    NEXT(cip,op);
  op_load2:
    GETPARAM(offs);
    pri=_R(data,offs);
    GETPARAM(offs);
    alt=_R(data,offs);
    NEXT(cip,op);
  op_load2_s:
    GETPARAM(offs);
    pri=_R(data,frm+offs);
    GETPARAM(offs);
    alt=_R(data,frm+offs);
    NEXT(cip,op);
  op_const:
    GETPARAM(offs);
    GETPARAM(val);
    _W(data,offs,val);
    NEXT(cip,op);
  op_const_s:
    GETPARAM(offs);
    GETPARAM(val);
    _W(data,frm+offs,val);
    NEXT(cip,op);
#endif

#if !defined AMX_NO_PACKED_OPC
  op_load_p_pri:
    GETPARAM_P(offs,op);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_load_p_alt:
    GETPARAM_P(offs,op);
    alt=_R(data,offs);
    NEXT(cip,op);
  op_load_p_s_pri:
    GETPARAM_P(offs,op);
    pri=_R(data,frm+offs);
    NEXT(cip,op);
  op_load_p_s_alt:
    GETPARAM_P(offs,op);
    alt=_R(data,frm+offs);
    NEXT(cip,op);
  op_lref_p_s_pri:
    GETPARAM_P(offs,op);
    offs=_R(data,frm+offs);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_lref_p_s_alt:
    GETPARAM_P(offs,op);
    offs=_R(data,frm+offs);
    alt=_R(data,offs);
    NEXT(cip,op);
  op_lodb_p_i:
    GETPARAM_P(offs,op);
    goto __lodb_i;
  op_const_p_pri:
    GETPARAM_P(pri,op);
    NEXT(cip,op);
  op_const_p_alt:
    GETPARAM_P(alt,op);
    NEXT(cip,op);
  op_addr_p_pri:
    GETPARAM_P(pri,op);
    pri+=frm;
    NEXT(cip,op);
  op_addr_p_alt:
    GETPARAM_P(alt,op);
    alt+=frm;
    NEXT(cip,op);
  op_stor_p:
    GETPARAM_P(offs,op);
    _W(data,offs,pri);
    NEXT(cip,op);
  op_stor_p_s:
    GETPARAM_P(offs,op);
    _W(data,frm+offs,pri);
    NEXT(cip,op);
  op_sref_p_s:
    GETPARAM_P(offs,op);
    offs=_R(data,frm+offs);
    _W(data,offs,pri);
    NEXT(cip,op);
  op_strb_p_i:
    GETPARAM_P(offs,op);
    goto __strb_i;
  op_lidx_p_b:
    GETPARAM_P(offs,op);
    offs=(pri << (int)offs)+alt;
    /* verify address */
    if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp)
      ABORT(amx,AMX_ERR_MEMACCESS);
    pri=_R(data,offs);
    NEXT(cip,op);
  op_idxaddr_p_b:
    GETPARAM_P(offs,op);
    pri=(pri << (int)offs)+alt;
    NEXT(cip,op);
  op_align_p_pri:
    GETPARAM_P(offs,op);
    #if BYTE_ORDER==LITTLE_ENDIAN
      if ((size_t)offs<sizeof(cell))
        pri ^= sizeof(cell)-offs;
    #endif
    NEXT(cip,op);
  op_push_p_c:
    GETPARAM_P(offs,op);
    PUSH(offs);
    NEXT(cip,op);
  op_push_p:
    GETPARAM_P(offs,op);
    PUSH(_R(data,offs));
    NEXT(cip,op);
  op_push_p_s:
    GETPARAM_P(offs,op);
    PUSH(_R(data,frm+offs));
    NEXT(cip,op);
  op_push_p_adr:
    GETPARAM_P(offs,op);
    PUSH(frm+offs);
    NEXT(cip,op);
  op_pushr_p_c:
    GETPARAM_P(offs,op);
    PUSH(data+offs);
    NEXT(cip,op);
  op_pushr_p_s:
    GETPARAM_P(offs,op);
    PUSH(data+_R(data,frm+offs));
    NEXT(cip,op);
  op_pushr_p_adr:
    GETPARAM_P(offs,op);
    PUSH(data+frm+offs);
    NEXT(cip,op);
  op_pushm_p_c:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(offs);
    } /* while */
    NEXT(cip,op);
  op_pushm_p:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(_R(data,offs));
    } /* while */
    NEXT(cip,op);
  op_pushm_p_s:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(_R(data,frm+offs));
    } /* while */
    NEXT(cip,op);
  op_pushm_p_adr:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(frm+offs);
    } /* while */
    NEXT(cip,op);
  op_pushrm_p_c:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(data+offs);
    } /* while */
    NEXT(cip,op);
  op_pushrm_p_s:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(data+_R(data,frm+offs));
    } /* while */
    NEXT(cip,op);
  op_pushrm_p_adr:
    GETPARAM_P(val,op);
    while (val--) {
      GETPARAM(offs);
      PUSH(data+frm+offs);
    } /* while */
    NEXT(cip,op);
  op_stack_p:
    GETPARAM_P(offs,op);
    alt=stk;
    stk+=offs;
    CHKMARGIN();
    CHKSTACK();
    NEXT(cip,op);
  op_heap_p:
    GETPARAM_P(offs,op);
    alt=hea;
    hea+=offs;
    CHKMARGIN();
    CHKHEAP();
    NEXT(cip,op);
  op_shl_p_c_pri:
    GETPARAM_P(offs,op);
    pri<<=offs;
    NEXT(cip,op);
  op_shl_p_c_alt:
    GETPARAM_P(offs,op);
    alt<<=offs;
    NEXT(cip,op);
  op_add_p_c:
    GETPARAM_P(offs,op);
    pri+=offs;
    NEXT(cip,op);
  op_smul_p_c:
    GETPARAM_P(offs,op);
    pri*=offs;
    NEXT(cip,op);
  op_zero_p:
    GETPARAM_P(offs,op);
    _W(data,offs,0);
    NEXT(cip,op);
  op_zero_p_s:
    GETPARAM_P(offs,op);
    _W(data,frm+offs,0);
    NEXT(cip,op);
  op_eq_p_c_pri:
    GETPARAM_P(offs,op);
    pri= pri==offs ? 1 : 0;
    NEXT(cip,op);
  op_eq_p_c_alt:
    GETPARAM_P(offs,op);
    pri= alt==offs ? 1 : 0;
    NEXT(cip,op);
  op_inc_p:
    GETPARAM_P(offs,op);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)offs) += 1;
    #else
      val=_R(data,offs);
      _W(data,offs,val+1);
    #endif
    NEXT(cip,op);
  op_inc_p_s:
    GETPARAM_P(offs,op);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)(frm+offs)) += 1;
    #else
      val=_R(data,frm+offs);
      _W(data,frm+offs,val+1);
    #endif
    NEXT(cip,op);
  op_dec_p:
    GETPARAM_P(offs,op);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)offs) -= 1;
    #else
      val=_R(data,offs);
      _W(data,offs,val-1);
    #endif
    NEXT(cip,op);
  op_dec_p_s:
    GETPARAM_P(offs,op);
    #if defined _R_DEFAULT
      *(cell *)(data+(int)(frm+offs)) -= 1;
    #else
      val=_R(data,frm+offs);
      _W(data,frm+offs,val-1);
    #endif
    NEXT(cip,op);
  op_movs_p:
    GETPARAM_P(offs,op);
    goto __movs;
  op_cmps_p:
    GETPARAM_P(offs,op);
    goto __cmps;
  op_fill_p:
    GETPARAM_P(offs,op);
    goto __fill;
  op_halt_p:
    GETPARAM_P(offs,op);
    goto __halt;
  op_bounds_p:
    GETPARAM_P(offs,op);
    if ((ucell)pri>(ucell)offs) {
      amx->cip=(cell)((unsigned char *)cip-amx->code);
      ABORT(amx,AMX_ERR_BOUNDS);
    } /* if */
    NEXT(cip,op);
#endif
}

void amx_exec_list(const AMX *amx,const cell **opcodelist,int *numopcodes)
{
  /* since the opcode list of the GNU GCC version of the abstract machine core
   * must be a local variable (as it references code labels, which are local
   * too), we use a trick to get the opcode list: call amx_Exec() while a
   * special flags value is set in the AMX header.
   */
   int orgflags;
   AMX *amxptr=(AMX*)amx;

   assert(amx!=NULL);
   assert(opcodelist!=NULL);
   assert(numopcodes!=NULL);
   orgflags=amx->flags;
   amxptr->flags=~0;
   *numopcodes=amx_exec_run(amxptr, (cell*)opcodelist, NULL);
   amxptr->flags=orgflags;
}
Пример #27
0
/*  error
 *
 *  Outputs an error message (note: msg is passed optionally).
 *  If an error is found, the variable "errflag" is set and subsequent
 *  errors are ignored until lex() finds a semicolon or a keyword
 *  (lex() resets "errflag" in that case).
 *
 *  Global references: inpfname   (reffered to only)
 *                     fline      (reffered to only)
 *                     fcurrent   (reffered to only)
 *                     errflag    (altered)
 */
SC_FUNC int error(long number,...)
{
static char *prefix[3]={ "error", "fatal error", "warning" };
static int lastline,errorcount;
static short lastfile;
  char *msg,*pre,*filename;
  va_list argptr;
  char string[256];
  int notice;

  /* split the error field between the real error/warning number and an optional
   * "notice" number
   */
  notice=number >> (sizeof(long)*4);
  number&=((unsigned long)~0) >> (sizeof(long)*4);
  assert(number>0 && number<300);

  /* errflag is reset on each semicolon.
   * In a two-pass compiler, an error should not be reported twice. Therefore
   * the error reporting is enabled only in the second pass (and only when
   * actually producing output). Fatal errors may never be ignored.
   */
  if ((errflag || sc_status!=statWRITE) && (number<100 || number>=200))
    return 0;

  /* also check for disabled warnings */
  if (number>=200) {
    int index=(number-200)/8;
    int mask=1 << ((number-200)%8);
    if ((warndisable[index] & mask)!=0) {
      errline=-1;
      errfile=-1;
      return 0;
    } /* if */
  } /* if */

  if (number<100){
    assert(number>0 && number<sizearray(errmsg));
    msg=errmsg[number];
    pre=prefix[0];
    errflag=TRUE;       /* set errflag (skip rest of erroneous expression) */
    errnum++;
  } else if (number<200) {
    assert((number-100)>=0 && (number-100)<sizearray(fatalmsg));
    msg=fatalmsg[number-100];
    pre=prefix[1];
    errnum++;           /* a fatal error also counts as an error */
  } else {
    assert((number-200)>=0 && (number-200)<sizearray(warnmsg));
    msg=warnmsg[number-200];
    pre=prefix[2];
    warnnum++;
  } /* if */

  strexpand(string,(unsigned char *)msg,sizeof string-2,SCPACK_TABLE);
  if (notice>0) {
    int len;
    assert(notice<sizearray(noticemsg));
    strcat(string,"; ");
    len=strlen(string);
    strexpand(string+len,(unsigned char *)noticemsg[notice],sizeof string-len-1,SCPACK_TABLE);
  } /* if */
  strcat(string,"\n");

  if (errline>0)
    errstart=errline;           /* forced error position, set single line destination */
  else
    errline=fline;              /* normal error, errstart may (or may not) have been marked, endpoint is current line */
  if (errstart>errline)
    errstart=errline;           /* special case: error found at end of included file */
  if (errfile>=0) {
    filename=get_inputfile(errfile);/* forced filename */
  } else {
    filename=inpfname;          /* current file */
    if (filename==NULL || strlen(filename)==0)
      filename=get_sourcefile(0);
    if (filename==NULL || strlen(filename)==0)
      filename="(none)";
  } /* if */
  assert(filename!=NULL);

  va_start(argptr,number);
  if (strlen(errfname)==0) {
    int start= (errstart==errline) ? -1 : errstart;
    if (pc_error((int)number,string,filename,start,errline,argptr)) {
      if (outf!=NULL) {
        pc_closeasm(outf,TRUE);
        outf=NULL;
      } /* if */
      longjmp(errbuf,3);        /* user abort */
    } /* if */
  } else {
    FILE *fp=fopen(errfname,"a");
    if (fp!=NULL) {
      if (errstart>=0 && errstart!=errline)
        fprintf(fp,"%s(%d -- %d) : %s %03d: ",filename,errstart,errline,pre,(int)number);
      else
        fprintf(fp,"%s(%d) : %s %03d: ",filename,errline,pre,(int)number);
      vfprintf(fp,string,argptr);
      fclose(fp);
    } /* if */
  } /* if */
  va_end(argptr);

  if (number>=100 && number<200 || errnum>25){
    if (strlen(errfname)==0) {
      va_start(argptr,number);
      pc_error(0,"\nCompilation aborted.",NULL,0,0,argptr);
      va_end(argptr);
    } /* if */
    if (outf!=NULL) {
      pc_closeasm(outf,TRUE);
      outf=NULL;
    } /* if */
    longjmp(errbuf,2);          /* fatal error, quit */
  } /* if */

  errline=-1;
  errfile=-1;
  /* check whether we are seeing many errors on the same line */
  if ((errstart<0 && lastline!=fline) || lastline<errstart || lastline>fline || fcurrent!=lastfile)
    errorcount=0;
  lastline=fline;
  lastfile=fcurrent;
  if (number<200)
    errorcount++;
  if (errorcount>=3)
    error(107);         /* too many error/warning messages on one line */

  return 0;
}
Пример #28
0
bool CXFFont::Read(const char *path)
{
  FILE *fp;
  if ((fp = fopen(path, "r")) == NULL)
    return false;

  bool result = true;
  char line[128]; /* lines in CXF fonts are short */
  while (fgets(line, sizearray(line), fp) != NULL && result) {
    if (line[0] == '#') {
      /* parse header line */
      char *ptr = line + 1;
      while (*ptr != '\0' && *ptr <= ' ')
        ptr++;
      if (strncasecmp(ptr, "LetterSpacing", 13) == 0) {
        ptr += 13;
        if (*ptr == ':')
          ptr++;
        m_LetterSpacing = (float)strtod(ptr, NULL);
      } else if (strncasecmp(ptr, "WordSpacing", 11) == 0) {
        ptr += 11;
        if (*ptr == ':')
          ptr++;
        m_WordSpacing = (float)strtod(ptr, NULL);
      } else if (strncasecmp(ptr, "LineSpacingFactor", 17) == 0) {
        ptr += 17;
        if (*ptr == ':')
          ptr++;
        m_LineSpacingFactor = (float)strtod(ptr, NULL);
      }
    } else if (line[0] == '[') {
      /* parse glyph */
      char *ptr;
      unsigned short code;
      if (line[1] == '#' && line[2] != ']') {
        /* Unicode character as a hexadecimal code */
        code = (unsigned short)strtol(line + 2, &ptr, 16);
      } else {
        /* ASCII character */
        code = line[1];
        ptr = line + 2;
      }
      if (*ptr != ']') {
        result = false; /* invalid (or unsupported) file format */
        break;
      }
      unsigned short count = (unsigned short)strtol(ptr + 1, NULL, 10);
      if (count == 0) {
        result = false; /* invalid (or unsupported) file format */
        break;
      }
      /* now parse the line segments, and collect consecutive segments into a
         polyline */
      CXFGlyph glyph(code);
      CXFPolyLine stroke;
      float xp = -1, yp = -1; /* force new stroke for the first coordinates */
      float width = 0;
      for (unsigned short i = 0; i < count; i++) {
        if (fgets(line, sizearray(line), fp) == 0)
          break;
        assert(line[0] == 'L');
        float x1, y1, x2, y2;
        sscanf(line, "L %f,%f,%f,%f", &x1, &y1, &x2, &y2);
        /* see whether we can continue the stroke, or whether a new one must be
           added */
        if (xp < x1 - EPSILON || xp > x1 + EPSILON || yp < y1 - EPSILON || yp > y1 + EPSILON) {
          /* non-continuous line segments, finish this polyline and start a new one */
          if (stroke.GetCount() > 0) {
            glyph.AddStroke(stroke);
            stroke.Clear();
          }
          stroke.AddPoint(CXFPoint(x1, y1));
          if (width < x1)
            width = x1;
        }
        stroke.AddPoint(CXFPoint(x2, y2));
        xp = x2;
        yp = y2;
        if (width < x2)
          width = x2;
      }
      if (stroke.GetCount() > 0)
        glyph.AddStroke(stroke);	/* add the final stroke */
      glyph.SetWidth(width);
      m_Glyphs.push_back(glyph);
    }
  }
  fclose(fp);

  /* analyze a few characters to find the typical font metrics */
  float dummy;
  GetGlyphVSize('A', &m_CapsHeight, &dummy);
  GetGlyphVSize('x', &m_XHeight, &dummy);
  GetGlyphVSize('h', &m_Ascender, &dummy);
  GetGlyphVSize('p', &dummy, &m_Descender);

  return result;
}
Пример #29
0
/** ini_puts()
 * \param Section     the name of the section to write the string in
 * \param Key         the name of the entry to write, or NULL to erase all keys in the section
 * \param Value       a pointer to the buffer the string, or NULL to erase the key
 * \param Filename    the name and full path of the .ini file to write to
 *
 * \return            1 if successful, otherwise 0
 */
int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const TCHAR *Filename)
{
  INI_FILETYPE rfp;
  INI_FILETYPE wfp;
  INI_FILEPOS mark;
  TCHAR *sp, *ep;
  TCHAR LocalBuffer[INI_BUFFERSIZE];
  int len, match, flag, cachelen;

  assert(Filename != NULL);
  if (!ini_openread(Filename, &rfp)) {
    /* If the .ini file doesn't exist, make a new file */
    if (Key != NULL && Value != NULL) {
      if (!ini_openwrite(Filename, &wfp))
        return 0;
      writesection(LocalBuffer, Section, &wfp);
      writekey(LocalBuffer, Key, Value, &wfp);
      (void)ini_close(&wfp);
    } /* if */
    return 1;
  } /* if */

  /* If parameters Key and Value are valid (so this is not an "erase" request)
   * and the setting already exists and it already has the correct value, do
   * nothing. This early bail-out avoids rewriting the INI file for no reason.
   */
  if (Key != NULL && Value != NULL) {
    (void)ini_tell(&rfp, &mark);
    match = getkeystring(&rfp, Section, Key, -1, -1, LocalBuffer, sizearray(LocalBuffer));
    if (match && _tcscmp(LocalBuffer,Value) == 0) {
      (void)ini_close(&rfp);
      return 1;
    } /* if */
    /* key not found, or different value -> proceed (but rewind the input file first) */
    (void)ini_seek(&rfp, &mark);
  } /* if */

  /* Get a temporary file name to copy to. Use the existing name, but with
   * the last character set to a '~'.
   */
  ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
  if (!ini_openwrite(LocalBuffer, &wfp)) {
    (void)ini_close(&rfp);
    return 0;
  } /* if */
  (void)ini_tell(&rfp, &mark);
  cachelen = 0;

  /* Move through the file one line at a time until a section is
   * matched or until EOF. Copy to temp file as it is read.
   */
  len = (Section != NULL) ? _tcslen(Section) : 0;
  if (len > 0) {
    do {
      if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
        /* Failed to find section, so add one to the end */
        flag = cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
        if (Key!=NULL && Value!=NULL) {
          if (!flag)
            (void)ini_write(INI_LINETERM, &wfp);  /* force a new line behind the last line of the INI file */
          writesection(LocalBuffer, Section, &wfp);
          writekey(LocalBuffer, Key, Value, &wfp);
        } /* if */
        return close_rename(&rfp, &wfp, Filename, LocalBuffer);  /* clean up and rename */
      } /* if */
      /* Copy the line from source to dest, but not if this is the section that
       * we are looking for and this section must be removed
       */
      sp = skipleading(LocalBuffer);
      ep = _tcschr(sp, ']');
      match = (*sp == '[' && ep != NULL && (int)(ep-sp-1) == len && _tcsnicmp(sp + 1,Section,len) == 0);
      if (!match || Key != NULL) {
        if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
          cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
          (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
          cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
        } /* if */
      } /* if */
    } while (!match);
  } /* if */
  cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
  /* when deleting a section, the section head that was just found has not been
   * copied to the output file, but because this line was not "accumulated" in
   * the cache, the position in the input file was reset to the point just
   * before the section; this must now be skipped (again)
   */
  if (Key == NULL) {
    (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
    (void)ini_tell(&rfp, &mark);
  } /* if */

  /* Now that the section has been found, find the entry. Stop searching
   * upon leaving the section's area. Copy the file as it is read
   * and create an entry if one is not found.
   */
  len = (Key!=NULL) ? _tcslen(Key) : 0;
  for( ;; ) {
    if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
      /* EOF without an entry so make one */
      flag = cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
      if (Key!=NULL && Value!=NULL) {
        if (!flag)
          (void)ini_write(INI_LINETERM, &wfp);  /* force a new line behind the last line of the INI file */
        writekey(LocalBuffer, Key, Value, &wfp);
      } /* if */
      return close_rename(&rfp, &wfp, Filename, LocalBuffer);  /* clean up and rename */
    } /* if */
    sp = skipleading(LocalBuffer);
    ep = _tcschr(sp, '='); /* Parse out the equal sign */
    if (ep == NULL)
      ep = _tcschr(sp, ':');
    match = (ep != NULL && (int)(skiptrailing(ep,sp)-sp) == len && _tcsnicmp(sp,Key,len) == 0);
    if ((Key != NULL && match) || *sp == '[')
      break;  /* found the key, or found a new section */
    /* copy other keys in the section */
    if (Key == NULL) {
      (void)ini_tell(&rfp, &mark);  /* we are deleting the entire section, so update the read position */
    } else {
      if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
        cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
        (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
        cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
      } /* if */
    } /* if */
  } /* for */
  /* the key was found, or we just dropped on the next section (meaning that it
   * wasn't found); in both cases we need to write the key, but in the latter
   * case, we also need to write the line starting the new section after writing
   * the key
   */
  flag = (*sp == '[');
  cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
  if (Key != NULL && Value != NULL)
    writekey(LocalBuffer, Key, Value, &wfp);
  /* cache_flush() reset the "read pointer" to the start of the line with the
   * previous key or the new section; read it again (because writekey() destroyed
   * the buffer)
   */
  (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
  if (flag) {
    /* the new section heading needs to be copied to the output file */
    cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
  } else {
    /* forget the old key line */
    (void)ini_tell(&rfp, &mark);
  } /* if */
  /* Copy the rest of the INI file */
  while (ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
    if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
      cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
      (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
      cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
    } /* if */
  } /* while */
  cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
  return close_rename(&rfp, &wfp, Filename, LocalBuffer);  /* clean up and rename */
}
Пример #30
0
/** ini_getf()
 * \param Section     the name of the section to search for
 * \param Key         the name of the entry to find the value of
 * \param DefValue    the default value in the event of a failed read
 * \param Filename    the name of the .ini file to read from
 *
 * \return            the value located at Key
 */
INI_REAL ini_getf(const TCHAR *Section, const TCHAR *Key, INI_REAL DefValue, const TCHAR *Filename)
{
  TCHAR LocalBuffer[64];
  int len = ini_gets(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), Filename);
  return (len == 0) ? DefValue : ini_atof(LocalBuffer);
}