Exemplo n.º 1
0
void P_CCONV pLog(PLogVerbosityEnum verbosity, 
    PLogChannelEnum channel,
    const pchar *file, 
    puint32 line, 
    const pchar *format, 
    ...)
{
    // The global verbosity value controls which kinds of log can be 
    // printed.
    if (verbosity < g_logVerbosity)
    {
        return ;
    }

    static const pchar *verbosityText[] = 
    {
        "(debug)",
        "(info)",
        "(warning)",
        "(error)",
        "(fatal)",
    };

    va_list arguments;

    va_start(arguments, format);

    if (pstrlen(format) > 200)
    {
        pchar message[1024];
        puint32 nchars = psprintf(message, 1024, 
                "(warning)%s:%d,log buffer for formatting data is too small.",
                __FILE__, __LINE__);
        pLogOutput(P_LOG_CHANNEL2, message, nchars);
    }
    else
    {
        pchar msg[3000]; 
        puint32 nchars;
        if (verbosity == P_LOG_ERROR || verbosity == P_LOG_WARNING)
        {
            pchar fmt[256];
            psprintf(fmt, 256, "%s%s:%d,%s", 
                verbosityText[verbosity], file, line, format);
            nchars = pvsprintf(msg, 3000, fmt, arguments);
        }
        else 
        {
            nchars = pvsprintf(msg, 3000, format, arguments);
        }

        pLogOutput(channel, msg, nchars);
    }

    if (verbosity == P_LOG_FATAL)
    {
        // FIXME: make it more polite
        pabort();
    }
}
Exemplo n.º 2
0
Arquivo: sys.c Projeto: bsmr-haxe/hl
static pchar *pstrdup( const pchar *s, int len ) {
	pchar *ret;
	if( len < 0 ) len = (int)pstrlen(s);
	ret = (pchar*)hl_copy_bytes((vbyte*)s,sizeof(pchar)*(len+1));;
	ret[len] = 0;
	return ret;
}
Exemplo n.º 3
0
SNODE *snp_line(void)
/*
 * construct a statement for the beginning of a new line
 */
{
	SNODE *snp3 = 0;
				if (!incldepth && lineno != lastlineno && lastst != semicolon && lastst != begin) {
					int i = 0,j,l=pstrlen(inputline);
					snp3 = xalloc(sizeof(SNODE));
					snp3->next = 0;
					snp3->stype = st_line;
					snp3->exp = (ENODE *)lineno;
					snp3->next = 0;
					for (j=0; j<l; j++)
						i+= installphichar(inputline[j],phibuf,i);
					if (phibuf[i-1] == '\n')
						i--;
					phibuf[i] = 0;
					if ((phibuf[i-1] & 0xf0) == 0x90)
						phibuf[i-1] = 0x90;
					snp3->label = (SNODE *)xalloc(i+1);
					strcpy(snp3->label, phibuf);
					lastlineno = lineno;
				}
	return snp3;
}
Exemplo n.º 4
0
pbool PNetworkServer::send(PNetworkPeer *peer, const puint8 *message, pint32 length)
{
    if (m_state == NETWORK_CONNECTED)
    {
        PMap<puint32, PNetworkPeer*>::iterator it = m_peers.find(peer->id());
        if (it != m_peers.end())
        {
            if (length == -1)
            {
                m_data->packet->dataLength = pstrlen((const pchar *)message) + 1;
            }
            else
            {
                m_data->packet->dataLength = length;
            }
            
            pmemcpy(m_data->packet->data, message, m_data->packet->dataLength);
            if (enet_peer_send(peer->data()->peer, 0, m_data->packet) < 0)
            {
                PLOG_ERROR("Failed to send message to peer (%d).", peer->id());
                return false;
            }

            return true;
        }
    }

    return false;
}
Exemplo n.º 5
0
Arquivo: sys.c Projeto: bsmr-haxe/hl
vbyte *hl_sys_get_cwd() {
	pchar buf[256];
	int l;
	if( getcwd(buf,256) == NULL )
		return NULL;
	l = (int)pstrlen(buf);
	if( buf[l-1] != '/' && buf[l-1] != '\\' ) {
		buf[l] = '/';
		buf[l+1] = 0;
	}
	return (vbyte*)pstrdup(buf,-1);
}
Exemplo n.º 6
0
Arquivo: alloc.c Projeto: chrisnc/knrc
int main(void)
{
  int *x = alloc(sizeof(int));
  *x = 123456;
  printf("*x = %d\n", *x);
  afree(x);
  int *y = alloc(sizeof(int));
  printf("*y = %d\n", *y);

  char s[] = "hello, world";
  printf("pstrlen(\"%s\") = %zu\n", s, pstrlen(s));
}
Exemplo n.º 7
0
void PNetworkServer::broadcast(const puint8 *message, pint32 length)
{
    if (m_state == NETWORK_CONNECTED)
    {
        if (length == -1)
        {
            m_data->packet->dataLength = pstrlen((const pchar *)message) + 1;
        }
        else
        {
            m_data->packet->dataLength = length;
        }
        pmemcpy(m_data->packet->data, message, m_data->packet->dataLength);
        enet_host_broadcast(m_data->server, 0, m_data->packet);
        enet_host_flush(m_data->server);
    }
}
Exemplo n.º 8
0
int genstring(char *str, int uselong)
/*
 * Generate a string literal
 */
{
	if (uselong) {
		while  (*(short *)str) {
			genword(*((short *)str));
			str+=2;
		}
		return pstrlen(str)*2;
	}
	else {
		while (*str)
			genbyte(*str++);
		return strlen(str);
	}
}
Exemplo n.º 9
0
Arquivo: sys.c Projeto: bsmr-haxe/hl
varray *hl_sys_read_dir( vbyte *_path ) {
	pchar *path = (pchar*)_path;
	int count = 0;
	int pos = 0;
	varray *a = NULL;
	pchar **current = NULL;

#ifdef HL_WIN
	WIN32_FIND_DATAW d;
	HANDLE handle;
	hl_buffer *b = hl_alloc_buffer();
	int len = (int)pstrlen(path);
	hl_buffer_str(b,path);
	if( len && path[len-1] != '/' && path[len-1] != '\\' )
		hl_buffer_str(b,USTR("/*.*"));
	else
		hl_buffer_str(b,USTR("*.*"));
	path = hl_buffer_content(b,NULL);
	handle = FindFirstFileW(path,&d);
	if( handle == INVALID_HANDLE_VALUE )
		return NULL;
	while( true ) {
		// skip magic dirs
		if( d.cFileName[0] != '.' || (d.cFileName[1] != 0 && (d.cFileName[1] != '.' || d.cFileName[2] != 0)) ) {
			if( pos == count ) {
				int ncount = count == 0 ? 16 : count * 2;
				varray *narr = hl_alloc_array(&hlt_bytes,count);
				pchar **ncur = hl_aptr(narr,pchar*);
				memcpy(ncur,current,count*sizeof(void*));
				current = ncur;
				a = narr;
				count = ncount;
			}
			current[pos++] = pstrdup(d.cFileName,-1);
		}
		if( !FindNextFileW(handle,&d) )
			break;
	}