示例#1
0
long *
DCirfile::IntArrRight(void)
{
	if (SecFound)
		return SecFile->IntArrRight();
	if (CurrRight == NULL)
		return NULL;
	if (!ListRight())
		return NULL;

	long count = 0;
	char *chp = NULL;
	while ((chp = ListItem()) != NULL) {
		count++;
		DeleteName(chp);
	}

	long *ptr = new long[count + 1];
	ListRight();

	for (long i = 0; i < count; i++) {
		ptr[i] = atol(chp = ListItem());
		DeleteName(chp);
	}

	ptr[count] = 0;
	return ptr;
}
示例#2
0
DCirfile::DCirfile(const char *fname, const char *sn) : DCrfile(fname)
{
  CurrSect = CurrLeft = CurrRight = CurrSectName = NULL;
	CurrPos = 0;
	CurrFile = SecSect = SecNext = SecFound = SecList = false;
	SubType = CurrSubSect = NULL;
	SubSect = SubNext = SubFound = false;

	if (sn) {
		char *per = strrchr(sn, '.');
		if (per) {
			SecName = NewName((per - sn) + 5);
			strncpy(SecName, sn, per - sn);
		}
		else {
			SecName = NewName(strlen(sn) + 5);
			strcpy(SecName, sn);
		}
		strcat(SecName, ".ini");
		if (_stricmp(fname, SecName)) { // prevent recursion
			SecFile = new DCirfile(SecName);
			if (SecFile->FErr() != fok) {
				delete SecFile;
				SecFile = NULL;
				DeleteName(SecName);
				SecName = NULL;
			}
		}
		else {
			SecFile = NULL;
			DeleteName(SecName);
			SecName = NULL;
		}
	}
	else {
		SecFile = NULL;
		SecName = NULL;
	}

  if (Ferr)
    return;

  if ((BufMax = getSize()) == 0) {
    Ferr = frd;
    return;
  }

	CurrFile = true;
  Buf = new char[BufMax + 2];
  getBlock(Buf, (size_t) BufMax);
  Buf[BufMax] = '\n';
  Buf[BufMax + 1] = '\0';
	SetSectPos();
}
示例#3
0
static INDEX CPROC DeleteATexture( INDEX iTexture, uintptr_t psv )
{
	INDEX iWorld = (INDEX)psv;
	GETWORLD( iWorld );
	PFLATLAND_TEXTURE texture = GetSetMember( FLATLAND_TEXTURE, &world->textures, iTexture );
	if( texture )
		DeleteName( iWorld, texture->iName );
	DeleteFromSet( FLATLAND_TEXTURE, world->textures, texture );
	return INVALID_INDEX;
}
示例#4
0
char *
DCirfile::PathRight(void)
{
	if (SecFound)
		return SecFile->PathRight();
	if (CurrRight == NULL)
		return NULL;

	char *chp = strncpy(NewName(RightLen + 1), CurrRight, RightLen);
	chp[RightLen] = '\0';

	char *currdir = _getcwd(NewName(1024), 1024);
	char *inidir = this->getBasePath();
	int currdrive = _getdrive();
	int inidrive = 0;

	if (stricmp(currdir, inidir)
	 && !PathIsURL(chp)
	 && PathIsRelative(chp)) { // fix rel path
		if (*(inidir + 1) == ':')
			inidrive = (toupper(*inidir) - 'A') + 1;
		if (inidrive
		 && (currdrive != inidrive))
			_chdrive(inidrive);
		_chdir(inidir);
		char *nref = NewName(MAX_PATH);
		if (_fullpath(nref, chp, MAX_PATH)) {
			DeleteName(chp);
			chp = NewName(nref);
		}
		DeleteName(nref);
		if (inidrive
		 && (currdrive != inidrive))
			_chdrive(currdrive);
		_chdir(currdir);
	}
	DeleteName(currdir);

	return chp;
}
示例#5
0
void netbios_name::Destroy()
{
	// Запрос останова рабочего потока-слушателя
	if ( m_term ) SetEvent( m_term );

	// Удаление имени (если не удалить, то слушатель не завершиться)
	UCHAR ret = DeleteName ();
	LOG("Unregister NetBIOS name \"%s\" on lana %d num=%d : 0x%02x \"%s\"", GetANSIFullName(), m_lana, netbiosed.name_num, ret, GetNetbiosError( ret ) );
	m_registered = !(ret == NRC_GOODRET);
	if ( m_duplicated )
	{
		// Восстановление имени
		m_duplicated = false;

		// NOTE: Восстанавливать не надо - проблем больше
		//	uReturn = AddName ();
		//	LOG("Restore NetBIOS name \"%s\" on lana %d : 0x%02x", GetANSIFullName(), m_lana, uReturn);
	}

	// Ожидание, а затем принудительный останов
	if ( m_listener )
	{
		if ( m_term ) SetEvent( m_term );
		if (WaitForSingleObject (m_listener, ALMOST_INFINITE) == WAIT_TIMEOUT)
		{
			LOG("Terminate NetBIOS listener!");
			TerminateThread (m_listener, 0);
		}
		m_listener = NULL;
	}

	if ( m_dgreceiver )
	{
		if ( m_term ) SetEvent( m_term );
		if (WaitForSingleObject (m_dgreceiver, ALMOST_INFINITE) == WAIT_TIMEOUT)
		{
			LOG("Terminate NetBIOS datagram receiver!");
			TerminateThread (m_dgreceiver, 0);
		}
		m_dgreceiver = NULL;
	}

	if ( m_term )
	{
		CloseHandle (m_term);
		m_term = NULL;
	}
}
示例#6
0
bool
DCirfile::FindElemPath(const char *name)
{
	bool ret = false;

	if (!name)
		return false;

	InElemPath = true;
	ret = Find(&name, 1, true);
	InElemPath = false;
	return ret;

#if 0
	char **paths = NULL;
	char *hat = NULL;
	short cnt = 0;
	short i = 0;

	hat = strchr(name, '^');
	if (!hat)
		return Find(&name, 1);

	cnt = 2;  // name plus one variant
	while ((hat = strchr(hat + 1, '^')) != NULL)
		cnt++;

	paths = (char **) new char[sizeof(char *) * cnt];
	paths[0] = (char *) name;
	for (i = 1; i < cnt; i++) {  // change left to right
		paths[i] = NewName(paths[i - 1]);
		*(hat = strchr(paths[i], '^')) = '/';
	}

	ret = Find((const char **) paths, cnt);

	for (i = 1; i < cnt; i++)
		DeleteName(paths[i]);
	delete [] paths;

	return ret;
#endif
}
示例#7
0
void RunDOSCommand(const char *cmd, const char *dir,
                   bool hide, bool keep, bool synch)
{
	char *command = NULL;

	if (!cmd
	 || (*cmd == '\0'))
		return;

	if (ComSpec == NULL) {
		ComSpec = getenv("comspec");
		if (ComSpec == NULL)
			strcpy(ComSpec, "command");
	}

	command = NewName(ComSpec, strlen(ComSpec) + strlen(cmd) + 5);
	strcat(command, keep ? " /k " : " /c ");
	strcat(command, cmd);

	RunCommand(command, dir, hide, synch);

	DeleteName(command);
}
示例#8
0
bool
DCirfile::Section(const char *name)
{
	if (!name)
		return false;

  CurrSect = CurrSubSect = NULL;
	CurrPos = 0;
  CurrLeft = Buf;
	if (CurrSectName
	 && stricmp(CurrSectName, name)) {
		DeleteName(CurrSectName);
		CurrSectName = NULL;
	}
	if (!CurrSectName)
		CurrSectName = NewName(name);
  uns len = strlen(name);
	uns sublen = 0;

	SubSect = SubNext = SubFound = false;

	if (SecFile
	 && ((SecSect = SecFile->Section(name)) == true))
		SecNext = true;
	SecFound = false;

	if (CurrFile == false)
		return SecSect;

  // scan for section [name]
  // if not found by EOF, return false

	while (CurrLeft && *CurrLeft != '\0') {
		CurrLeft = GetSectPos(CurrLeft);
    if (CurrLeft
     && !_strnicmp(CurrLeft, name, len)) {  // match
      if (*(CurrLeft + len) == ']') {
				if (!CurrSect)
					CurrSect = CurrLeft;
				if (!SubType)
					break;
			}
			else if ((*(CurrLeft + len) == '-')  // check sub
			 && (SubType != NULL)
			 && ((sublen = strlen(SubType)) != 0)
			 && !_strnicmp(CurrLeft + len + 1, SubType, sublen)
			 && (*(CurrLeft + len + sublen + 1) == ']')) {
				CurrSubSect = CurrLeft;
				SubSect = SubNext = true;
				SubFound = false;
				break;
			}
		}
    //skipLine();
  }

  CurrLeft = CurrRight = NULL;
  LeftLen = RightLen = 0;
	if (CurrSect || CurrSubSect)
		return true;
  return SecSect;
}
示例#9
0
DCirfile *
DCirfile::SetConfigTemplate(const char *sect, const char *setting,
		                        bool link)
{
	DCirfile *bottomIni = SecFile ? SecFile : this;
	bool secfound = false;
	char *startdir =  _getcwd(NewName(1024), 1024);
	char *currdir = startdir;
	char *newdir = NULL;
	int startdrive = _getdrive();
	int currdrive = startdrive;
	int newdrive = 0;

	IniLevel = 0;

	if (!LogEventFunc)
		LastConfigSetting = NewName(setting);

	if (SecFile != NULL) {
		IniFileList.add(SecFile, ++IniLevel);
		IniNameList.add(SecFile->getBaseName(), IniLevel);
		IniChainList.add(SecFile->getFilePath(), IniLevel);
	}
	IniFileList.add(this, ++IniLevel);
	IniNameList.add(getBaseName(), IniLevel);
	IniChainList.add(getFilePath(), IniLevel);

	DCirfile *configTpl = NULL;
	char *configTplName = NULL;

	// SecFile (specific ini) overrides tpl choice in this
	DCirfile *topIni = this;
	secfound = Section(sect);

	if (secfound
	 && Find("Scope"))
		Scope = StrRight();

	if (secfound
	 && !stricmp(setting, "configs")
	 && Find("Document")) {   // insert document chain here
		DCirfile *topdoc = this;
		while (topdoc->Section(sect)) {
			if (!topdoc->Find("Document"))
				break;  // end of chain with no end flag ****
			char *nm = topdoc->StrRight();
			if (!nm)
				break;  // end of chain with no end flag ****
			if (!stricmp(nm, "end")) {
				DeleteName(nm);
				topdoc->ChainEnded = true;
				break;  // end of chain with end flag
			}
			DeleteName(nm);
			if ((configTplName = topdoc->PathRight()) == NULL)
				break;  // end of chain with no end flag ****
			if ((configTpl = new DCirfile(configTplName)) == NULL) {
				LogEvent(logwarn, 1, topdoc->getFilePath(), " refers to unopenable ",
					"Document template", " ", NewName(configTplName));
				DeleteName(configTplName);
				configTplName = NULL;
				break;
			}
			if (configTpl->FErr() != fok) {
				LogEvent(logwarn, 1, topdoc->getFilePath(), " refers to nonexistent ",
					"Document template", " ", NewName(configTpl->getFilePath()));
				DeleteName(configTplName);
				configTplName = NULL;
				delete configTpl;
				break;  // file not found
			}
			newdir = configTpl->getBasePath();
			if (*(newdir + 1) == ':')
				newdrive = (toupper(*newdir) - 'A') + 1;
			if (newdrive
			 && (currdrive != newdrive))
				_chdrive(currdrive = newdrive);
			if (stricmp(newdir, currdir))
				_chdir(currdir = newdir);

			if (IniNameList(configTpl->getBaseName())) {
				LogEvent(logwarn, 1, topdoc->getFilePath(), " repeats ",
					"Document template", " ", NewName(configTpl->getFilePath()));
				DeleteName(configTplName);
				configTplName = NULL;
				delete configTpl;
				break;  // deja vu, end of the line
			}

			topdoc = configTpl;  // step up
			if (topdoc->Section("Templates")
			 && topdoc->Find("Scope"))
				topdoc->Scope = topdoc->StrRight();
			DeleteName(configTplName);
			configTplName = NULL;
			IniFileList.add(topdoc, ++IniLevel);
			IniNameList.add(topdoc->getBaseName(), IniLevel);
			IniChainList.add(topdoc->getFilePath(), IniLevel);
		}
	}

	if (!secfound
	 || !Find(setting)) {  // check for old setting
		if (!stricmp(setting, "configs")) {
			if (Section("Setup")
			 && Find("ConfigTemplate")) {
				sect = "Setup";
				setting = "ConfigTemplate";
			}
			else if (Section("FDK")
			 && Find("ConfigTemplate")) {
				sect = "FDK";
				setting = "ConfigTemplate";
			}
		}
		else if (!stricmp(setting, "languages")) {
			if (Section("Setup")
			 && Find("LanguageText"))
				sect = "Setup";
				setting = "LanguageText";
		}
		else if (!stricmp(setting, "macros")) {
			if (Section("Macros")
			 && Find("MacroFile")) {
				sect = "Macros";
				setting = "MacroFile";
			}
		}
	}

	while (topIni->Section(sect)) {
		if (!topIni->Find(setting))
			break;  // end of chain with no end flag ****
		char *nm = topIni->StrRight();
		if (!nm)
			break;  // end of chain with no end flag ****
		if (!stricmp(nm, "end")) {
			DeleteName(nm);
			topIni->ChainEnded = true;
			break;  // end of chain with end flag
		}
		DeleteName(nm);
		if ((configTplName = topIni->PathRight()) == NULL)
			break;  // end of chain with no end flag ****
		if ((configTpl = new DCirfile(configTplName)) == NULL) {
			LogEvent(logwarn, 1, topIni->getFilePath(), " refers to unopenable ",
				setting, " ", NewName(configTplName));
			DeleteName(configTplName);
			configTplName = NULL;
			break;  // can't open file
		}
		if (configTpl->FErr() != fok) {
			LogEvent(logwarn, 1, topIni->getFilePath(), " refers to nonexistent ",
				setting, " ", NewName(configTpl->getFilePath()));
			DeleteName(configTplName);
			configTplName = NULL;
			delete configTpl;
			break;  // file not found
		}
		newdir = configTpl->getBasePath();
		if (*(newdir + 1) == ':')
			newdrive = (toupper(*newdir) - 'A') + 1;
		if (newdrive
		 && (currdrive != newdrive))
			_chdrive(currdrive = newdrive);
		if (stricmp(newdir, currdir))
			_chdir(currdir = newdir);

		if (IniNameList(configTpl->getBaseName())) {
			LogEvent(logwarn, 1, topIni->getFilePath(), " repeats ",
				setting, " ", NewName(configTpl->getFilePath()));
			DeleteName(configTplName);
			configTplName = NULL;
			delete configTpl;
			break;  // deja vu, end of the line
		}

		topIni = configTpl;  // step up
		if (topIni->Section("Templates")
		 && topIni->Find("Scope"))
			topIni->Scope = topIni->StrRight();
		DeleteName(configTplName);
		configTplName = NULL;
		IniFileList.add(topIni, ++IniLevel);
		IniNameList.add(topIni->getBaseName(), IniLevel);
		IniChainList.add(topIni->getFilePath(), IniLevel);
	}

	// topIni is now at the top of the chain, and
	// bottomIni is at the bottom, which may be same.
	if (link) {
		DCirfile *ifl = bottomIni;
		DCirfile *ift = NULL;
		for (long ilev = 1; ilev < IniLevel; ilev++) {
			ift = (DCirfile *) IniFileList.find(ilev + 1);
			if (!ift)
				break;
			ift->SetSecFile(ifl);
			ifl = ift;
			//if (ifl == topIni)
			//	break;
		}
	}

	WriteIniChain(setting);

	if (currdrive != startdrive)
		_chdrive(startdrive);
	if (stricmp(startdir, currdir))
		_chdir(startdir);

	if (this != topIni) {
		topIni->IniFileList = IniFileList;
		topIni->IniNameList = IniNameList;
		topIni->IniChainList = IniChainList;
		topIni->IniLevel = IniLevel;
	}

	return topIni;
}
示例#10
0
bool
DCelem::setType(void)
{
	if (epset)
		return true;

	if (!ElemTypes
	 || !classatt)
		return false;

	// normalize the class attribute

	char *eclass = classatt;
	if ((*eclass == '-')
	 || (*eclass == '+'))
		eclass++;

	while (isspace(*eclass))
		eclass++;

	char *ecend = eclass + strlen(eclass) - 1;

	while (isspace(*ecend))
		ecend--;

	char *nclass = NewName((ecend - eclass) + 1);
	char *nptr = nclass;
	char *eptr = eclass;
	while (eptr <= ecend) {
		if (isspace(*eptr)) {
			*nptr++ = *eptr++;
		  while (isspace(*eptr))  // make spaces single
				eptr++;
		}
		*nptr++ = *eptr++;
	}
	*nptr = '\0';

	etype **ep = NULL;
	bool last = false;

	if (LastClass
	 && !strcmp(LastClass, nclass)) {  // same class as last
		ep = LastEP;                     // use same properties
		last = true;
		DeleteName(nclass);
	}
	else {
		if (LastClass)
			DeleteName(LastClass);
		LastClass = nclass;

		etype *key = new etype;
		key->ename = nclass;

		etype **arr = ElemTypes;
		int cnt = ElemTypesCount;

		ep = (etype **) bsearch(&key, arr, cnt, sizeof(etype *),
																	CompElemTypes);

		if (!ep) {  // not in list, trim class attrs from right
			char *space = NULL;
			while (nptr > nclass) {
				while ((*nptr != ' ')
				 && (nptr > nclass))
					nptr--;             // nptr is at space between parts
				if (nptr > nclass) {  // use classes right to left
					char *elem = NewName(nclass, nptr - nclass);
					key->ename = elem;
					ep = (etype **) bsearch(&key, arr, cnt, sizeof(etype *),
															 CompElemTypes);
					DeleteName(elem);
				}
				if (ep)  // found base class of current class
					break;
				nptr--;  // move off the space
			}
		}
		delete key;
		LastEP = ep;
	}

	if (ep) {  // found, store it
		epcnt = (*ep)->cnt;
		eprop = (*ep)->eprop;
		epset = true;
	}
	else {
		epset = true;  // avoid another failed lookup
		epcnt = 0;
		if (!last)
			return false;
	}
	return true;
}