Example #1
1
File: log.cpp Project: Fred50/acr
bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp)
{
    facility = facility_ & 7;
    timestamp = logtimestamp;
    if(consolethres >= 0) consolethreshold = min(consolethres, (int)ACLOG_NUM);
    if(filethres >= 0) filethreshold = min(filethres, (int)ACLOG_NUM);
    if(syslogthres >= 0) syslogthreshold = min(syslogthres, (int)ACLOG_NUM);
    if(ident != identity)
        copystring(ident, identity);
    formatstring(ident_full)("ACR[%s]", identity);
    if(syslogthreshold < ACLOG_NUM)
    {
#ifdef AC_USE_SYSLOG
        openlog(ident_full, LOG_NDELAY, facilities[facility]);
#else
        if((logsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM)) == ENET_SOCKET_NULL || enet_address_set_host(&logdest, "localhost") < 0) syslogthreshold = ACLOG_NUM;
#endif
    }
    static int lognum = 0;
    formatstring(filepath)("serverlog_%s_%s.part%d.txt", timestring(true), identity, ++lognum);
    if(fp) { fclose(fp); fp = NULL; }
    if(filethreshold < ACLOG_NUM)
    {
        fp = fopen(filepath, "w");
        if(!fp) printf("failed to open \"%s\" for writing\n", filepath);
    }
    defformatstring(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]);
    if(fp) concatformatstring(msg, ", \"%s\"", filepath);
    concatformatstring(msg, "), syslog(%s", levelname[syslogthreshold]);
    if(syslogthreshold < ACLOG_NUM) concatformatstring(msg, ", \"%s\", local%d", ident_full, facility);
    concatformatstring(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED");
    enabled = consolethreshold < ACLOG_NUM || fp || syslogthreshold < ACLOG_NUM;
    if(enabled) printf("%s\n", msg);
    return enabled;
}
Example #2
0
void backup(char *name, char *backupname)
{
    string backupfile;
    copystring(backupfile, findfile(backupname, "wb"));
    remove(backupfile);
    rename(findfile(name, "wb"), backupfile);
}
Example #3
0
char * expandEnv( char* in ) {
    char * out = in;
    int i;
    int possibleEnv = 0;
    int envStart;
    for (i = 0; i < strlen(out); i++) {
        if( out[i] == '$' ) {
            envStart = i;
        }
        if( out[i] == '{' && i == envStart+1 ) {
            possibleEnv = 1;
        }
        if( out[i] == '}' && possibleEnv ) {
            char temp[5000];
            char * envVar;

            memcpy( temp, &out[envStart], i-envStart+1 );
            temp[i-envStart+1] = '\0';
            copystring( envVar, temp );
            envVar = envVar + 2;
            envVar[i-envStart-2] = '\0';
            
            out = replace( out, temp, getenv(envVar) );
        }
    
    }
    return out;
}
Example #4
0
 void Client::loadScene(const char* name) {
     if(load_world(name)) {
         copystring(clientmap, name);
     }
     CubeJ::MsgDataType<CubeJ::MSG_SND_SCENEINFO> data(clientmap, getworldsize(), getmapversion());
     SendMessage(data);
 }
Example #5
0
OSStatus pathtofsref ( bigstring bspath, FSRef *ref ) {

	/*
	2009-08-30 aradke: mac-only helper function for converting from a pascal string (path) to an FSRef
	*/
	
	bigstring bs;
	CFStringRef csref;
	char str[256];

	copystring(bspath,  bs);

	// convert from colon-delimited to slash-delimited path

	stringswapall(':', '/', bs);

	insertstring ( BIGSTRING ( "\x09" "/Volumes/" ), bs );
	
	// convert from Mac Roman to UTF-8 */ 

	csref = CFStringCreateWithPascalString(kCFAllocatorDefault, bs, kCFStringEncodingMacRoman);
	
	CFStringGetCString(csref, str, sizeof(str), kCFStringEncodingUTF8);
		
	CFRelease(csref);

	// finally, pass our temporary copy of the string to the underlying system function
	
	return FSPathMakeRef((UInt8*) str, ref, NULL);
	} /*pathtofsref*/
Example #6
0
void FMetaTable::CopyMeta (const FMetaTable *other)
{
	const FMetaData *meta_src;
	FMetaData **meta_dest;

	FreeMeta ();

	meta_src = other->Meta;
	meta_dest = &Meta;
	while (meta_src != NULL)
	{
		FMetaData *newmeta = new FMetaData (meta_src->Type, meta_src->ID);
		switch (meta_src->Type)
		{
		case META_String:
			newmeta->Value.String = copystring (meta_src->Value.String);
			break;
		default:
			newmeta->Value = meta_src->Value;
			break;
		}
		*meta_dest = newmeta;
		meta_dest = &newmeta->Next;
		meta_src = meta_src->Next;
	}
	*meta_dest = NULL;
}
Example #7
0
static boolean odberrorroutine (bigstring bs, ptrvoid refcon) {
#pragma unused (refcon)

	copystring (bs, bserror);
	
	return (false); /*consume the error*/
	} /*odberrorroutine*/
Example #8
0
static boolean minimessage (bigstring bs, boolean flbackgroundmsg) {
#pragma unused (flbackgroundmsg)

	copystring (bs, (**minidata).bsmsg);
	
	return (minidrawmsg ());
	} /*minimessage*/
Example #9
0
char *ReadString (uint8_t **stream)
{
	char *string = *((char **)stream);

	*stream += strlen (string) + 1;
	return copystring (string);
}
static boolean compareforcopyvisit (hdlheadrecord hnode, ptrvoid refcon) {
	
	bigstring bs, bsnode;
	ptrdraginfo draginfo = (ptrdraginfo) refcon;
	
	if (hnode == (*draginfo).hcompare)
		return (true);
	
	opgetheadstring (hnode, bsnode);
	
	opgetheadstring ((*draginfo).hcompare, bs);
	
	if (!equalidentifiers (bsnode, bs)) 
		return (true);
	
	copystring (BIGSTRING ("\x06" "CanÕt "), bs);
	
	pushstring (pcommand, bs);
	
	pushstring (BIGSTRING ("\x35" " because there are two or more selected items named Ò"), bs);
	
	pushstring (bsnode, bs);
	
	pushstring (BIGSTRING ("\x02" "Ó."), bs);
	
	alertdialog (bs);
	
	return (false); /*stop both traversals*/
	} /*compareforcopyvisit*/
Example #11
0
    bool execcfg(const char *cfgfile, bool ignore_ret)
    {
        string s;
        copystring(s, cfgfile);
        char *buf = loadfile(path(s), NULL);
        if(!buf) return false;
        auto err = lapi::state.do_string(buf, lua::ERROR_TRACEBACK);
        if (types::get<0>(err))
            logger::log(logger::ERROR, "%s\n", types::get<1>(err));

        bool ret = true;
        if (!ignore_ret)
        {
            ret = lapi::state["OF_CFG_VERSION_PASSED"].to<bool>();
            if (!ret)
            {
                conoutf(
                    "Your OctaForge config file was too old to run with "
                    "your current client. Initializing a default set."
                );
            }
            lapi::state["OF_CFG_VERSION_PASSED"] = lua::nil;
        }

        delete[] buf;
        return ret;
    }
    void ControlNPC::connect(DynamicEntity* de)
    {
        if(!de) fatal("Controler::Character : no valid Dynamic Entity. Exit!");
        dynent = de;

///TODO: set name ActionInstance
		defformatstring(s)("%p", this);
        copystring(dynent->name, s);

///TODO: set and send basic infos like name, model ...

//        filtertext(dynent->name, lib.librarydescr, false, MAXNAMELEN);
        game::addmsg(SV_SWITCHNAME, "rs", dynent->name);

        dynent->controltype = CONTROL_NPC;
        dynent->lastupdate = lastmillis;

///TODO: spawn behaviour in edit and normal mode
        //first spawn, no actions defined in Actionlib
//        if(editmode)
//        {
            dynent->o = vec(game::player1->o);
            droptofloor(dynent->o, 0, 0);
            vec sp = vec(0,0,0);
            vecfromyawpitch(game::player1->yaw, 0, 50, 0, sp);
            dynent->o.add(sp);
            dynent->o.z += dynent->eyeheight;

            game::addmsg(SV_TRYSPAWN, "rc", dynent);
//        }
		Instance::init();
        isinit = true;
    }
Example #13
0
void
readin(void)
{
	int t;
	struct val *temp;

	if(absf==1) {
		if(xd.xlbf)
			absbot = xd.xlb;
		else if(xd.xf==log10)
			absbot = 1;
	}
	for(;;) {
		temp = (struct val *)realloc((char*)xx,
			(unsigned)(n+1)*sizeof(struct val));
		if(temp==0)
			return;
		xx = temp;
		if(absf)
			xx[n].xv = n*dx + absbot;
		else
			if(!getfloat(&xx[n].xv))
				return;
		if(!getfloat(&xx[n].yv))
			return;
		xx[n].lblptr = -1;
		t = getstring();
		if(t>0)
			xx[n].lblptr = copystring(t);
		n++;
		if(t<0)
			return;
	}
}
Example #14
0
static xml_data_node *add_child(xml_data_node *parent, const char *name, const char *value)
{
	xml_data_node **pnode;
	xml_data_node *node;

	/* new element: create a new node */
	node = (xml_data_node *)malloc(sizeof(*node));
	if (node == nullptr)
		return nullptr;

	/* initialize the members */
	node->next = nullptr;
	node->parent = parent;
	node->child = nullptr;
	node->name = copystring_lower(name);
	if (node->name == nullptr)
	{
		free(node);
		return nullptr;
	}
	node->value = copystring(value);
	if (node->value == nullptr && value != nullptr)
	{
		free((void *)node->name);
		free(node);
		return nullptr;
	}
	node->attribute = nullptr;

	/* add us to the end of the list of siblings */
	for (pnode = &parent->child; *pnode; pnode = &(*pnode)->next) { }
	*pnode = node;

	return node;
}
Example #15
0
const char *findfile(const char *filename, const char *mode)
{
    static string s;
    formatstring(s)("%s%s", homedir, filename);         // homedir may be ""
    if(fileexists(s, mode)) return s;
    if(mode[0]=='w' || mode[0]=='a')
    { // create missing directories, if necessary
        string dirs;
        copystring(dirs, s);
        char *dir = strchr(dirs[0]==PATHDIV ? dirs+1 : dirs, PATHDIV);
        while(dir)
        {
            *dir = '\0';
            if(!fileexists(dirs, "r") && !createdir(dirs)) return s;
            *dir = PATHDIV;
            dir = strchr(dir+1, PATHDIV);
        }
        return s;
    }
    loopv(packagedirs)
    {
        formatstring(s)("%s%s", packagedirs[i], filename);
        if(fileexists(s, mode)) return s;
    }
    return filename;
}
Example #16
0
void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type)
{
	if ((Flags & CVAR_NOSET) && m_DoNoSet)
	{
		return;
	}
	else if ((Flags & CVAR_LATCH) && gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP)
	{
		FLatchedValue latch;

		latch.Variable = this;
		latch.Type = type;
		if (type != CVAR_String)
			latch.Value = value;
		else
			latch.Value.String = copystring(value.String);
		LatchedValues.Push (latch);
	}
	else if ((Flags & CVAR_SERVERINFO) && gamestate != GS_STARTUP && !demoplayback)
	{
		if (netgame && !players[consoleplayer].settings_controller)
		{
			Printf ("Only setting controllers can change %s\n", Name);
			return;
		}
		D_SendServerInfoChange (this, value, type);
	}
	else
	{
		ForceSet (value, type);
	}
}
Example #17
0
void 	SetKeyValue( entity_t *ent, const char *key, const char *value ) {
	epair_t	*ep;
	
	for ( ep=ent->epairs ; ep ; ep=ep->next ) {
		if ( !strcmp (ep->key, key) ) {
			free (ep->value);
			ep->value = copystring(value);
			return;
		}
	}
	ep = malloc (sizeof(*ep));
	ep->next = ent->epairs;
	ent->epairs = ep;
	ep->key = copystring(key);
	ep->value = copystring(value);
}
Example #18
0
int FStringTable::LoadLanguage (DWORD code, bool exactMatch, BYTE *start, BYTE *end)
{
	const DWORD orMask = exactMatch ? 0 : MAKE_ID(0,0,0xff,0);
	int count = 0;

	code |= orMask;

	while (start < end)
	{
		const DWORD langLen = LELONG(*(DWORD *)&start[4]);

		if (((*(DWORD *)start) | orMask) == code)
		{
			start[3] = 1;

			const BYTE *probe = start + 8;

			while (probe < start + langLen)
			{
				int index = probe[0] | (probe[1]<<8);

				if (Strings[index] == NULL)
				{
					Strings[index] = copystring ((const char *)(probe + 2));
					++count;
				}
				probe += 3 + strlen ((const char *)(probe + 2));
			}
		}

		start += langLen + 8;
		start += (4 - (ptrdiff_t)start) & 3;
	}
	return count;
}
Example #19
0
char *path(const char *s, bool copy)
{
    static string tmp;
    copystring(tmp, s);
    path(tmp);
    return tmp;
}
Example #20
0
    static int next(lua_State * L)
    {
        directory_iterator * self = reinterpret_cast<directory_iterator *>(luaL_checkudata(L, 1, MT));
        if(!self->m_dir) return 0;
        struct dirent * entry = readdir(self->m_dir);
        if(!entry) return 0;
        
        char file[1024];
        copystring(file, self->m_dir_path, sizeof(file));
        concatstring(file, "/", sizeof(file));
        concatstring(file, entry->d_name, sizeof(file));
	    
        struct stat info;
        if (stat(file, &info)) return 0;
        
        unsigned char file_type = DT_UNKNOWN;
        if (S_ISREG(info.st_mode))       file_type = DT_REG;
        else if (S_ISDIR(info.st_mode))  file_type = DT_DIR;
        else if (S_ISFIFO(info.st_mode)) file_type = DT_FIFO;
        else if (S_ISLNK(info.st_mode))  file_type = DT_LNK;
        else if (S_ISBLK(info.st_mode))  file_type = DT_BLK;
        else if (S_ISCHR(info.st_mode))  file_type = DT_CHR;
        else if (S_ISSOCK(info.st_mode)) file_type = DT_SOCK;
	
        lua_pushinteger(L, file_type);
        lua_pushstring(L, entry->d_name);
        
        return 2;
    }
Example #21
0
static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, const char *value)
{
	xml_attribute_node *anode, **panode;

	/* allocate a new attribute node */
	anode = (xml_attribute_node *)malloc(sizeof(*anode));
	if (anode == nullptr)
		return nullptr;

	/* fill it in */
	anode->next = nullptr;
	anode->name = copystring_lower(name);
	if (anode->name == nullptr)
	{
		free(anode);
		return nullptr;
	}
	anode->value = copystring(value);
	if (anode->value == nullptr)
	{
		free((void *)anode->name);
		free(anode);
		return nullptr;
	}

	/* add us to the end of the list of attributes */
	for (panode = &node->attribute; *panode; panode = &(*panode)->next) { }
	*panode = anode;

	return anode;
}
Example #22
0
 void setdefaultvalue()
 {
     const char *p = defaultvalueexp;
     char *r = executeret(p);
     copystring(input.buf, r ? r : "");
     if(r) delete[] r;
 }
Example #23
0
boolean resolveHashTable(bigstring bsnodetype, bigstring bsadrnodepath) {
	bigstring bsname;
	hdlhashtable ht;
	hdlhashnode hn;
	tyvaluerecord iconvalue;
	boolean flexpanded = false;
	boolean fllookup = false;
	
	pushhashtable (roottable);
	
	disablelangerror ();
	
	flexpanded = langexpandtodotparams (bsadrnodepath, &ht, bsname);
	enablelangerror ();
	pophashtable ();
	
	fllookup = hashtablelookup (ht, bsnodetype, &iconvalue, &hn);

	if (fllookup && iconvalue.valuetype == addressvaluetype) {
		copystring(*iconvalue.data.stringvalue, bsadrnodepath);
		return resolveHashTable(bsnodetype, bsadrnodepath);
	}

	return fllookup;
}
Example #24
0
    void export_ents(const char *fname) {
        string tmp;
        copystring(tmp, curr_map_id);
        tmp[strlen(curr_map_id) - 7] = '\0';

        defformatstring(buf)("%smedia%c%s%c%s", homedir, PATHDIV, tmp,
            PATHDIV, fname);

        lua::push_external("entities_save_all");
        lua_call(lua::L, 0, 1);
        const char *data = lua_tostring(lua::L, -1);
        lua_pop(lua::L, 1);
        if (fileexists(buf, "r")) {
            defformatstring(buff)("%s-%d.bak", buf, (int)time(0));
            tools::fcopy(buf, buff);
        }

        FILE *f = fopen(buf, "w");
        if  (!f) {
            logger::log(logger::ERROR, "Cannot open file %s for writing.\n",
                buf);
            return;
        }
        fputs(data, f);
        fclose(f);
    }
Example #25
0
/*
=================
ParseEpair
=================
*/
epair_t *ParseEpair (void)
{
	epair_t	*e;
	
	e = malloc (sizeof(epair_t));
	memset (e, 0, sizeof(epair_t));
	
	if (strlen(token) >= MAX_KEY-1)
		Error ("ParseEpar: token too long");
	e->key = copystring(token);
	GetToken (false);
	if (strlen(token) >= MAX_VALUE-1)
		Error ("ParseEpar: token too long");
	e->value = copystring(token);

	return e;
}
void ControlAi::init(DynamicEntity* de)
{
	dynent = de;
    dynent->controltype = CONTROL_AI;
	copystring(dynent->name, "blood-ai");

	isinit = true;
}
Example #27
0
static void setstatsmessage (short id) {
	
	bigstring bs;
	
	getstatsstring (id, bs);
	
	copystring (bs, (**statsdata).bsmessage);
	} /*setstatsmessage*/
Example #28
0
void
SetKeyValue(int iEntity, char *key, char *value)
{
    epair_t *ep;

    for (ep = map.rgEntities[iEntity].epairs; ep; ep = ep->next)
	if (!strcmp(ep->key, key)) {
	    free(ep->value); /* FIXME */
	    ep->value = copystring(value);
	    return;
	}
    ep = AllocMem(OTHER, sizeof(epair_t), true);
    ep->next = map.rgEntities[iEntity].epairs;
    map.rgEntities[iEntity].epairs = ep;
    ep->key = copystring(key);
    ep->value = copystring(value);
}
Example #29
0
static char *ncopystring (const char *string)
{
	if (string == NULL || string[0] == 0)
	{
		return NULL;
	}
	return copystring (string);
}
Example #30
0
File: map.c Project: kellyrm/Q1
void 	SetKeyValue (entity_t *ent, char *key, char *value)
{
	epair_t	*ep;

	for (ep=ent->epairs ; ep ; ep=ep->next)
		if (!strcmp (ep->key, key) )
		{
			FreeOther (ep->value);
			ep->value = copystring(value);
			return;
		}
	ep = AllocOther (sizeof(*ep));
	ep->next = ent->epairs;
	ent->epairs = ep;
	ep->key = copystring(key);
	ep->value = copystring(value);
}