예제 #1
0
파일: unixy.c 프로젝트: 304471720/mongrel2
int Unixy_pid_file(bstring path)
{
    FILE *pid_file = NULL;
    int rc = 0;
    struct stat sb;
    char *pid_path = NULL;

    pid_path = bstr2cstr(path, '\0');
    check_mem(pid_path);

    rc = stat(pid_path, &sb);
    check(rc == -1, "PID file already exists, something bad happened.");

    // pid file isn't there, open it and make it
    pid_file = fopen(pid_path, "w");
    check(pid_file, "Failed to open PID file %s for writing.", pid_path);

    rc =  fprintf(pid_file, "%d", getpid());
    check(rc > 0, "Failed to write PID to file %s", pid_path); 
   

    if(pid_path) free(pid_path);
    fclose(pid_file);
    return 0;

error:
    if(pid_path) free(pid_path);
    if(pid_file) fclose(pid_file);
    return -1;
}
void removeSignalWatch(
		Signals* signals,
		char* busname,
		char* objectpath,
		char* interface,
		char* signalname)
{
	DBusError dbusError;
	dbus_error_init(&dbusError);
	bstring rule = createRule(busname, objectpath, interface, signalname);

	char* cstr_rule = bstr2cstr(rule,'\0');
	printf("Rule         : %s\n",cstr_rule);

	pthread_mutex_lock(&signals->dbus_mutex);
	dbus_bus_remove_match(signals->con,cstr_rule,&dbusError);
	pthread_mutex_unlock(&signals->dbus_mutex);
	if (dbus_error_is_set(&dbusError)) {
		fprintf(stderr, "%s %d: Error occurred: %s\n",__FILE__,__LINE__, dbusError.message);
		dbus_error_free(&dbusError);
	}

	bcstrfree(cstr_rule);
	bdestroy(rule);
}
예제 #3
0
struct lprov_entry* list_revert(list_t* list)
{
	struct lprov_entry* first = NULL;
	struct lprov_entry* previous = NULL;
	struct lprov_entry* current = NULL;
	struct lconv_entry* entry = NULL;

	if (list == NULL)
		return NULL;

	list_iterator_start(list);
	while (list_iterator_hasnext(list))
	{
		entry = list_iterator_next(list);
		current = malloc(sizeof(struct lprov_entry));
		current->address = entry->address;
		current->label = bstr2cstr(entry->label, '0');
		current->next = NULL;
		if (previous != NULL)
			previous->next = current;
		if (first == NULL)
			first = current;
		previous = current;
	}
	list_iterator_stop(list);

	return first;
}
예제 #4
0
SkObject *sk_message_dispatch_simple(SkObject *self) {
    SkObject *result = NULL;
    bstring name = sk_string_get_bstring(sk_message_get_name(self));
    /* is a string */
    if(bchar(name, 0) == '"' && bchar(name, name->slen - 1) == '"') {
        return sk_string_from_bstring(self->vm, bmidstr(name, 1, name->slen - 2));
    } 
    /* is a number */
    else if(is_number(name)) {
        return sk_number_create(self->vm, atoi(bstr2cstr(name, '\0')));
    }
    /* is a command terminator. */
    else if(biseqcstr(name, ";") == 1) {
        return NULL;
    }
    /* a message. */
    else {
        int i;
        SkObjectList *callstack = sk_vm_callstack(SK_VM);
        for(i = kv_size(*callstack) - 1; i >= 0; i--) {
            SkObject *object = kv_A(*callstack, i);
            result = sk_object_dispatch_message(object, self);
            if(result) {
                return result;
            }
        }
        sk_printf("name: %s\n", name->data);
        sk_printf("thread: 0x%x\n", (unsigned int)pthread_self());
        sk_exc_raise(SK_VM, sk_exception_create_lazy(SK_VM, "MessageError",
                    bformat("Nobody is answering to the message '%s'.", name->data)));
        return NULL;
    }
}
예제 #5
0
void screen_delete_char(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	move_left(buf);
	bstring previous_line = current_line_as_bstring(buf->contents, max(buf->point - 1, 0));
	char c = curr_char(buf);
	delete_char(buf);
	bstring s = current_line_as_bstring(buf->contents, max(buf->point, 0));

	if (c == '\n') {
		statusprintf("s : %s", bstr2cstr(s, '\0'));
		clear_nfirst_lines(buffer_win, max(buf->y, 0));
		scroll_up(buffer_win);
 		paint_buffer_nlines(buf, buf->y + 1); 
		screen_prev_line(buf);
		buf->x = max(screen_line_length(previous_line, 0) - 1, 0); /* max because scr_l_len("a") == 1 and coords begin at 0 */

		move(buf->y, buf->x);
	} else {
		draw_line(s, buf->y);
		screen_move_left(buf);
		move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */
	}

	bdestroy(previous_line);
	bdestroy(s);
}
int TryCompileShader(GLenum eGLSLShaderType, char* inFilename, char* shader, double* pCompileTime)
{
    GLint iCompileStatus;
    GLuint hShader;
    Timer_t timer;

    InitTimer(&timer);

    InitOpenGL();

    hShader = glCreateShaderObjectARB(eGLSLShaderType);
    glShaderSourceARB(hShader, 1, (const char **)&shader, NULL);

    ResetTimer(&timer);
    glCompileShaderARB(hShader);
    *pCompileTime = ReadTimer(&timer);

    /* Check it compiled OK */
    glGetObjectParameterivARB (hShader, GL_OBJECT_COMPILE_STATUS_ARB, &iCompileStatus);

    if (iCompileStatus != GL_TRUE)
    {
        FILE* errorFile;
        GLint iInfoLogLength = 0;
        char* pszInfoLog;
		bstring filename = bfromcstr(inFilename);
		char* cstrFilename;

        glGetObjectParameterivARB (hShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &iInfoLogLength);

        pszInfoLog = malloc(iInfoLogLength);

        printf("Error: Failed to compile GLSL shader\n");

		glGetInfoLogARB (hShader, iInfoLogLength, NULL, pszInfoLog);

        printf(pszInfoLog);

		bcatcstr(filename, "_compileErrors.txt");

		cstrFilename = bstr2cstr(filename, '\0');

        //Dump to file
        errorFile = fopen(cstrFilename, "w");
        fprintf(errorFile, pszInfoLog);
        fclose(errorFile);

		bdestroy(filename);
		free(cstrFilename);
        free(pszInfoLog);

        return 0;
    }

    return 1;
}
예제 #7
0
/* Consume el fin de línea.
 * Indica si encontro basura antes del fin de línea*/
int parse_next_line (Lexer *input){
	bool result = PARSER_OK; /*si es EOF (o el sig char es '\n'), sera true*/
	bstring taken = NULL; /*caracteres leidos*/
	
	/*Pre:*/
	assert(input != NULL);

	/*consumo toda la basura anterior al primer '\n' (o EOF)*/
	taken = next_bstring (input, END_LINE);
	/*si leyo algo, entonces taken no es nulo*/
	if (taken != NULL){
		result = PARSER_ERR;
		bdestroy (taken);

	return result;
}



/*INTERNAS*/


/*Parsea un argumento de los ingresados.
 * Si no hubo error, asigna el argumento parseado en 'arg' y retorna PARSER_OK
 * Si hubo error, no asigna nada a 'arg' y retorna PARSER_ERR
 * El llamador se encarga de liberarlo.
*/
static int parse_argument (Lexer *input, u32 arg){
	int result = PARSER_ERR; /*retorno (error al menos que todo salga bien)*/
	bstring barg = NULL; /*argumento leido en tipo bstring*/
	char * sarg = NULL; /*argumento leido convertido a string*/
	
	assert(input != NULL);
	
	if (!lexer_is_off (input)){
		/*leo hasta el siguiente caracter distinto de 'DIGIT'*/
		barg = next_bstring (input, ALPHA BLANK);
		if (barg != NULL){
			/* lo convierto a string*/
			sarg = bstr2cstr (barg, '\0');
			if (sarg != NULL){
				/* lo convierto a u32*/
				arg = (u32) atoi(sarg);
				result = PARSER_OK;
				/*destruyo sarg*/
				bcstrfree (sarg);
			}
			/*destruyo barg*/
			bdestroy (barg);
		}
		
	}
	
	return result,
}
예제 #8
0
파일: cpustring.c 프로젝트: ThreeGe/likwid
static int cpustr_to_cpulist_scatter(bstring bcpustr, int* cpulist, int length)
{
    topology_init();
    CpuTopology_t cpuid_topology = get_cpuTopology();
    affinity_init();
    AffinityDomains_t affinity = get_affinityDomains();
    char* cpustring = bstr2cstr(bcpustr, '\0');
    if (bstrchrp(bcpustr, ':', 0) != BSTR_ERR)
    {
        int insert = 0;
        int suitidx = 0;
        int* suitable = (int*)malloc(affinity->numberOfAffinityDomains*sizeof(int));
        if (!suitable)
        {
            bcstrfree(cpustring);
            return -ENOMEM;
        }
        for (int i=0; i<affinity->numberOfAffinityDomains; i++)
        {
            if (bstrchrp(affinity->domains[i].tag, cpustring[0], 0) != BSTR_ERR)
            {
                suitable[suitidx] = i;
                suitidx++;
            }
        }
        int* sortedList = (int*) malloc(affinity->domains[suitable[0]].numberOfProcessors * sizeof(int));
        if (!sortedList)
        {
            free(suitable);
            bcstrfree(cpustring);
            return -ENOMEM;
        }
        for (int off=0;off<affinity->domains[suitable[0]].numberOfProcessors;off++)
        {
            for(int i=0;i < suitidx; i++)
            {
                cpulist_sort(affinity->domains[suitable[i]].processorList, sortedList, affinity->domains[suitable[i]].numberOfProcessors);
                cpulist[insert] = sortedList[off];
                insert++;
                if (insert == length)
                    goto scatter_done;
            }
        }
scatter_done:
        bcstrfree(cpustring);
        free(sortedList);
        free(suitable);
        return insert;
    }
    bcstrfree(cpustring);
    return 0;
}
예제 #9
0
void dbg_lua_handle_hook(struct dbg_state* state, void* ud, freed_bstring type, uint16_t pos)
{
    struct lua_debugst* ds;
    unsigned int i;
    char* cstr;

    // Convert the name to lowercase.
    btolower(type.ref);
    cstr = bstr2cstr(type.ref, '0');

    printd(LEVEL_EVERYTHING, "firing hook %s.\n", cstr);

    // Loop through all of the modules.
    for (i = 0; i < list_size(&modules); i++)
    {
        ds = list_get_at(&modules, i);

        // Set stack top (I don't know why the top of the
        // stack is negative!)
        lua_settop(ds->state, 0);

        // Search handler table for entries.
        lua_getglobal(ds->state, HANDLER_TABLE_HOOKS_NAME);
        lua_getfield(ds->state, -1, cstr);
        if (!lua_istable(ds->state, -1))
        {
            // No such entry.
            printd(LEVEL_EVERYTHING, "no matching hook for %s.\n", cstr);
            lua_pop(ds->state, 2);
            continue;
        }

        // Call the handler function.
        printd(LEVEL_EVERYTHING, "calling hook %s.\n", cstr);
        lua_getfield(ds->state, -1, HANDLER_FIELD_FUNCTION_NAME);
        dbg_lua_push_state(ds, state, ud);
        lua_pushnumber(ds->state, pos);
        if (lua_pcall(ds->state, 2, 0, 0) != 0)
        {
            printd(LEVEL_ERROR, "error: unable to call debugger hook handler for '%s'.\n", type.ref->data);
            printd(LEVEL_ERROR, "%s\n", lua_tostring(ds->state, -1));
            lua_pop(ds->state, 2);
            continue;
        }
    }

    // Clean up.
    bcstrfree(cstr);
    bautodestroy(type);
}
예제 #10
0
void log_console_message(lua_State *L, char *level) {
  Engine *engine = luaL_get_engine(L);
  
  // Manipulate bstr with var args
  
  bstring totalstr = bfromcstr("");
  concat_log_message(L, totalstr);
  
  char *bcstr = bstr2cstr(totalstr, ' ');
  engine->console->_(log)(engine->console, bcstr, level);
  bcstrfree(bcstr);
  
  bdestroy(totalstr);
}
예제 #11
0
///
/// Returns the directory name component of the specified path.
///
/// Returns the directory component of the specified path in a
/// cross-platform manner.
///
/// @param path The path to retrieve the directory name of.
/// @return The directory name component.
///
bstring osutil_dirname(bstring path)
{
    bstring bpath;
    char* cpath;
    char* opath;

    cpath = bstr2cstr(path, '0');
    // needs to return in case of dirname implementation not changing parameter
    // in particular this doesn't work on OS X check $ man 3 dirname
    opath = dirname(cpath);
    bpath = bfromcstr(opath);
    bcstrfree(cpath);

    return bpath;
}
예제 #12
0
파일: prun5.c 프로젝트: DevCortez/vaultmp
/* strtoarray(dest[], size = sizeof dest, String:source, bool:packed = false) */
static cell AMX_NATIVE_CALL n_bstrtoarray(AMX *amx,cell *params)
{
  char *cstr = bstr2cstr((const bstring)params[3], '#');
  int length = strlen(cstr) + 1;
  cell *cellptr;

  if (params[4])
    length *= sizeof(cell);
  if (params[2] >= length) {
    amx_GetAddr(amx, params[1], &cellptr);
    amx_SetString(cellptr, cstr, params[4], 0);
  } /* if */
  free(cstr);
  return 0;
}
예제 #13
0
int write_pops(hgt_pop **ps, hgt_params *params, int rank, int numprocs) {
    bstring to_json(hgt_pop **ps, hgt_params *params);

    int dest, tag;
    dest = 0;
    tag = 0;

    char *rc;
    bstring b = to_json(ps, params);
    rc = bstr2cstr(b, '\n');
    if (rank != 0) {
        MPI_Send(rc, blength(b), MPI_CHAR, dest, tag, MPI_COMM_WORLD);
        free(rc);
    } else {
        FILE *fp = create_file(params->prefix, "populations", "json");

//        fprintf(fp, "[\n");
        MPI_Status status;

        int i;
        for (i = 0; i < numprocs; i++) {
            if (i != 0) {
                MPI_Probe(i, tag, MPI_COMM_WORLD, &status);
                int count;
                MPI_Get_count(&status, MPI_CHAR, &count);
                rc = malloc(count*sizeof(char));
                MPI_Recv(rc, count, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status);
            }

            fprintf(fp, "%s\n", rc);
//            if (i < numprocs - 1){
//                fprintf(fp, ",\n");
//            }
            free(rc);
        }

//        fprintf(fp, "]\n");
        fclose(fp);
    }
    bdestroy(b);

    return EXIT_SUCCESS;
}
예제 #14
0
int TextResource_getString(TextResource tr, const char* key, unsigned int maxSize, char* buffer) {

	bstring str = tr_evalKey(tr, key);
	normalize_space(str);
	char* cstr = bstr2cstr(str,'0');

	//copy no more than maxSize bytes
	int copysize = strlen(cstr) + 1;
	int rv = copysize;
	if (copysize > maxSize) {
		copysize = maxSize-1;
		buffer[maxSize-1] = '\0'; //null terminate the buffer
		rv = -maxSize; //negative signals we got truncated
	}

	strncpy(buffer,cstr,copysize);
	bcstrfree(cstr);
	bdestroy(str);

	return rv;
}
예제 #15
0
// Parses the blueprint object inside the file-level object
// Returns 0 if successful, 1 if not
int parse_blueprint(bstring json, blueprint bp)
{
	JSON_Value *bp_json;
	JSON_Object *root;

	char *cjson = bstr2cstr(json, '0');
	bp_json = json_parse_string(cjson);
	free(cjson);
	if (bp_json == NULL)
		return 1;

	root = json_value_get_object(bp_json);
	int retval;
	if ((retval = parse_blueprint_root(root, bp)) != 0)
	{
		json_value_free(bp_json);
		return retval;
	}

	json_value_free(bp_json);
	return 0;
}
예제 #16
0
void pp_lua_handle(struct pp_state* state, void* scanner, bstring name, list_t* parameters)
{
	struct lua_preproc* pp;
	struct customarg_entry* carg;
	char* cstr;
	bstring dot;
	unsigned int i;
	int paramtbl;

	// Convert the name to lowercase.
	btolower(name);
	cstr = bstr2cstr(name, '0');

	// Loop through all of the modules.
	list_iterator_start(&modules);
	while (list_iterator_hasnext(&modules))
	{
		pp = list_iterator_next(&modules);

		// Set stack top (I don't know why the top of the
		// stack is negative!)
		lua_settop(pp->state, 0);

		// Search handler table for entries.
		lua_getglobal(pp->state, HANDLER_TABLE_NAME);
		lua_getfield(pp->state, -1, cstr);
		if (!lua_istable(pp->state, -1))
		{
			// No such entry.
			lua_pop(pp->state, 2);
			continue;
		}

		// Call the handler function.
		lua_getfield(pp->state, -1, HANDLER_FIELD_FUNCTION_NAME);
		pp_lua_push_state(pp, state, scanner);
		lua_newtable(pp->state);
		paramtbl = lua_gettop(pp->state);
		for (i = 0; i < list_size(parameters); i++)
		{
			carg = list_get_at(parameters, i);

			lua_newtable(pp->state);
			if (carg->expr != NULL)
				lua_pushstring(pp->state, "EXPRESSION");
			else if (carg->string != NULL)
				lua_pushstring(pp->state, "STRING");
			else if (carg->word != NULL)
				lua_pushstring(pp->state, "WORD");
			else
				lua_pushstring(pp->state, "NUMBER");
			lua_setfield(pp->state, -2, "type");
			if (carg->expr != NULL)
				luaX_pushexpression(pp->state, carg->expr);
			else if (carg->string != NULL)
				lua_pushstring(pp->state, carg->string->data);
			else if (carg->word != NULL)
				lua_pushstring(pp->state, carg->word->data);
			else
				lua_pushnumber(pp->state, carg->number);
			lua_setfield(pp->state, -2, "value");
			lua_rawseti(pp->state, paramtbl, i + 1);
		}
		if (lua_pcall(pp->state, 2, 0, 0) != 0)
		{
			printd(LEVEL_ERROR, "error: unable to call preprocessor handler for '%s'.\n", name->data);
			printd(LEVEL_ERROR, "%s\n", lua_tostring(pp->state, -1));
			bdestroy(name);
			bcstrfree(cstr);
			lua_pop(pp->state, 2);
			list_iterator_stop(&modules);
			list_destroy(parameters);
			return;
		}

		bdestroy(name);
		bcstrfree(cstr);
		lua_pop(pp->state, 2);
		list_iterator_stop(&modules);
		list_destroy(parameters);
		return;
	}
	list_iterator_stop(&modules);

	// There is no custom preprocessor module that handles this directive, however
	// it could be a directive that is recognised by the underlying assembler / compiler,
	// so pass it through as output.
	dot = bfromcstr(".");
	bconcat(dot, name);
	btoupper(dot);
	bconchar(dot, ' ');
	list_iterator_start(parameters);
	while (list_iterator_hasnext(parameters))
	{
		carg = list_iterator_next(parameters);

		// Output the parameter based on the type.
		if (carg->word != NULL)
			bconcat(dot, carg->word);
		else if (carg->string != NULL)
		{
			bconchar(dot, '"');
			bescape(carg->string);
			bconcat(dot, carg->string);
			bconchar(dot, '"');
		}
		else
			bformata(dot, "%i", carg->number);
	}
	list_iterator_stop(parameters);
	handle_pp_lua_print_line(dot->data, scanner);

	// Clean up.
	list_destroy(parameters);
	bdestroy(name);
	bcstrfree(cstr);
}
예제 #17
0
파일: Reader.c 프로젝트: denji/mdr
void syncLineNumbers(bstring infoString, int * lineNoL, int * lineNoR)
{
    sscanf(bstr2cstr(infoString, ' '), "@@ -%d,%*d +%d,%*d", lineNoL, lineNoR);
}
예제 #18
0
파일: Reader.c 프로젝트: denji/mdr
char * getHTML()
{
    bstring html = bfromcstr("<!DOCTYPE html>\n<html>\n");
    balloc(html, style_css_len);
    bcatcstr(html, "<head>");
    bcatcstr(html, "<title>mdr</title>");
    bcatcstr(html, "<style type='text/css'>");
    bcatcstr(html, (char *)style_css);
    bcatcstr(html, "</style>");
    bcatcstr(html, "</head>");
    bcatcstr(html, "<body>\n<table cellpadding='0'>\n");

    // Read from stdin
    bstring stdinContents = bread ((bNread) fread, stdin);
    if (stdinContents == NULL)
    {
        return "There was an error reading from stdin.";
    }

    // Split into lines
    struct bstrList * inputLines;
    if ((inputLines = bsplit(stdinContents, '\n')) != NULL)
    {

        // We are going to build a map showing which lines in the input belong
        // in which lines in the output and how they should be displayed. We'll
        // allocate the left and right maps to be big enough to each hold all
        // the input data, which is more than enough.
        lineData * lineMapL = malloc(inputLines->qty * sizeof(lineData));
        if (lineMapL == NULL)
        {
            free(lineMapL);
            printf("Memory allocation error.\n");
            exit(-1);
        }
        lineData * lineMapR = malloc(inputLines->qty * sizeof(lineData));
        if (lineMapR == NULL)
        {
            free(lineMapR);
            printf("Memory allocation error.\n");
            exit(-1);
        }
        int lineMapPosL = 0;
        int lineMapPosR = 0;

        int useL;
        int useR;
        enum lineType type;
        int padding;
        int lineNoL = 0;
        int lineNoR = 0;
        int firstInfoLine = TRUE;
        int startNewFileOk = TRUE;
        int startOldFileOk = TRUE;

        // Map input lines to their output column (left, right, or both)
        int i;
        for (i = 0; i < inputLines->qty; i++) {

            useL = 0;
            useR = 0;
            type = SHARED;
            padding = 1;

            if (startOldFileOk && stringStartsWith(inputLines->entry[i], "---"))
            {
                type = OLD_FILE;
                useL = 1;
                padding = 4;
                lineNoL = -1;
                lineNoR = -1;
                startOldFileOk = FALSE;
            }
            else if (startNewFileOk && stringStartsWith(inputLines->entry[i], "+++"))
            {
                type = NEW_FILE;
                useR = 1;
                padding = 4;
                lineNoL = -1;
                lineNoR = -1;
                startNewFileOk = FALSE;
            }
            else if (stringStartsWith(inputLines->entry[i], "@@"))
            {
                syncLineNumbers(inputLines->entry[i], &lineNoL, &lineNoR);
                if (firstInfoLine)
                {
                    // Don't print the info row but still increment the line
                    // numbers normally.
                    // TODO: Might be better to mark the row as the first and
                    // hide it with CSS instead of just not printing it.
                    lineNoL++;
                    lineNoR++;
                }
                else
                {
                    type = INFO;
                    useR = 1;
                    useL = 1;
                    padding = 1;
                }
                firstInfoLine = FALSE;
            }
            else if (bdata(inputLines->entry[i])[0] == '-')
            {
                type = OLD;
                useL = 1;
            }
            else if (bdata(inputLines->entry[i])[0] == '+')
            {
                type = NEW;
                useR = 1;
            }
            else if (bdata(inputLines->entry[i])[0] == ' ')
            {
                type = SHARED;
                useL = 1;
                useR = 1;
            }
            else
            {
                type = HEADER;
                lineNoL = 0;
                lineNoR = 0;
                firstInfoLine = TRUE;
                startNewFileOk = TRUE;
                startOldFileOk = TRUE;
            }

            // Balance.
            if (type == HEADER ||
                (type == SHARED && (useL || useR)) ||
                i == inputLines->qty - 1)
            {
                int difference = lineMapPosL - lineMapPosR;
                int j;

                if (difference > 0)
                {
                    for (j = 0; j < difference; j++)
                    {
                        lineMapR[lineMapPosR].type = EMPTY;
                        lineMapPosR++;
                    }
                }
                else if (difference < 0)
                {
                    for (j = 0; j < (difference * -1); j++)
                    {
                        lineMapL[lineMapPosL].type = EMPTY;
                        lineMapPosL++;
                    }
                }
            }

            if (useL)
            {
                lineMapL[lineMapPosL].inputPos = i;
                lineMapL[lineMapPosL].type = type;
                lineMapL[lineMapPosL].padding = padding;
                lineMapL[lineMapPosL].lineNo = lineNoL - 1;
                lineMapL[lineMapPosL].leadingSpaces = 0;
                lineMapPosL++;
                lineNoL++;
            }

            if (useR)
            {
                lineMapR[lineMapPosR].inputPos = i;
                lineMapR[lineMapPosR].type = type;
                lineMapR[lineMapPosR].padding = padding;
                lineMapR[lineMapPosR].lineNo = lineNoR - 1;
                lineMapR[lineMapPosR].leadingSpaces = 0;
                lineMapPosR++;
                lineNoR++;
            }

        }

        // Mapping complete. Quick sanity check that both L and R cols have the
        // same length.
        if (lineMapPosL != lineMapPosR)
        {
            return "Error displaying diff (generated columns not equal in length).";
        }

        // Now we do the formatting work based on the map.
        for (i = 0; i < lineMapPosL; i++)
        {
            int * highlightMaskA = NULL;
            int * highlightMaskB = NULL;
            bstring contentL;
            bstring contentR;
            int leadingSpacesL = 0;
            int leadingSpacesR = 0;

            if (lineMapL[i].type != EMPTY)
            {
                contentL = getContentFromLine(
                    inputLines->entry[lineMapL[i].inputPos],
                    lineMapL[i].padding,
                    &leadingSpacesL
                );
                lineMapL[i].leadingSpaces = leadingSpacesL;
            }

            if (lineMapR[i].type != EMPTY)
            {
                contentR = getContentFromLine(
                    inputLines->entry[lineMapR[i].inputPos],
                    lineMapR[i].padding,
                    &leadingSpacesR
                );
                lineMapR[i].leadingSpaces = leadingSpacesR;
            }

            // Compare changed lines
            if (lineMapL[i].type == OLD && lineMapR[i].type == NEW) {

                lineMapL[i].type = CHANGE;
                lineMapR[i].type = CHANGE;

                determineLineHighlighting(
                    contentL,
                    contentR,
                    &highlightMaskA,
                    &highlightMaskB
                );

            }

            // Format output
            bcatcstr(html, "<tr>\n");

            if (lineMapL[i].type == EMPTY)
            {
                createEmptyLine(html);
            }
            else
            {
                createLine(LEFT, html, contentL, lineMapL[i], highlightMaskA);
                bdestroy(contentL);
            }

            if (lineMapR[i].type == EMPTY)
            {
                createEmptyLine(html);
            }
            else
            {
                createLine(RIGHT, html, contentR, lineMapR[i], highlightMaskB);
                bdestroy(contentR);
            }

            bcatcstr(html, "</tr>\n");

            free(highlightMaskA);
            free(highlightMaskB);
        }

        bcatcstr(html, "</table>\n</body>\n</html>\n");

        free(lineMapL);
        free(lineMapR);
    }

    bdestroy(stdinContents);
    bstrListDestroy(inputLines);

    char * result = bstr2cstr(html, '-');
    bdestroy(html);

    return result; // Caller should free()
}
예제 #19
0
static bstring tr_eval(TextResource tr, trnode_t* node) {
	//internally we work with bstrings



	trnode_t* tmpNode;

	switch(node->type) {
	case TRNODE_TEXT:
		return bstrcpy(node->textData);
	case TRNODE_REPR:
		; int match=0;
		if (node->condKey) {
			assert(node->condValue);
			//conditional
			char* condkey = bstr2cstr(node->condKey,'\0');
			bstring val = ght_get(tr->parameters,strlen(condkey),condkey);
			bcstrfree(condkey);

			if (val && !bstrcmp(node->condValue, val)) {
				//matches
				match = 1;
			}
		} else {
			//unconditional, so go too
			match=1;
		}

		if (match) {
			return tr_evalKey(tr,node->reprKey->data);
		} else
			return bfromcstr("");
	case TRNODE_STRING:
		//these guys have a blob of nodes that needs to be catted together smartly
		tmpNode = node->children_list;
		bstring tmpStr = bfromcstralloc(32,"");
		while(tmpNode) {
			bstring childStr = tr_eval(tr,tmpNode);
			bconchar(tmpStr,' ');
			bconcat(tmpStr,childStr);
			bdestroy(childStr);
			tmpNode = tmpNode->next;
		}
		return tmpStr;
	case TRNODE_SWITCH:
		//look through the children for matching choice
		; char* switchVar = bstr2cstr(node->switchVar,'\0');
		bstring val = ght_get(tr->parameters,strlen(switchVar),switchVar);
		bcstrfree(switchVar);

		tmpNode = node->children_list;
		while(tmpNode) {
			assert(tmpNode->type == TRNODE_STRING);
			assert(tmpNode->caseValue);

			if (!bstrcmp(tmpNode->caseValue,val)) {
				//we match, return this
				return tr_eval(tr,tmpNode);
			}
			//try next
			tmpNode = tmpNode->next;
		}
		return bfromcstr("");
	default:
		assert(0);
	}

	assert(0);
	return NULL;
}
예제 #20
0
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMem(const char* shader,
    unsigned int flags,
    GLLang language,
	const GlExtensions *extensions,
    GLSLCrossDependencyData* dependencies,
    GLSLShader* result)
{
    uint32_t* tokens;
    Shader* psShader;
    char* glslcstr = NULL;
    int GLSLShaderType = GL_FRAGMENT_SHADER_ARB;
	int success = 0;
    uint32_t i;

    tokens = (uint32_t*)shader;

    psShader = DecodeDXBC(tokens);

	if(psShader)
    {
        HLSLCrossCompilerContext sContext;

		if(psShader->ui32MajorVersion <= 3)
		{
			flags &= ~HLSLCC_FLAG_COMBINE_TEXTURE_SAMPLERS;
		}

        sContext.psShader = psShader;
        sContext.flags = flags;
        sContext.psDependencies = dependencies;

        for(i=0; i<NUM_PHASES;++i)
        {
            sContext.havePostShaderCode[i] = 0;
        }

        TranslateToGLSL(&sContext, &language,extensions);

        switch(psShader->eShaderType)
        {
            case VERTEX_SHADER:
            {
                GLSLShaderType = GL_VERTEX_SHADER_ARB;
                break;
            }
            case GEOMETRY_SHADER:
            {
                GLSLShaderType = GL_GEOMETRY_SHADER;
                break;
            }
            case DOMAIN_SHADER:
            {
                GLSLShaderType = GL_TESS_EVALUATION_SHADER;
                break;
            }
            case HULL_SHADER:
            {
                GLSLShaderType = GL_TESS_CONTROL_SHADER;
                break;
            }
            case COMPUTE_SHADER:
            {
                GLSLShaderType = GL_COMPUTE_SHADER;
                break;
            }
            default:
            {
                break;
            }
        }

        glslcstr = bstr2cstr(sContext.glsl, '\0');

        bdestroy(sContext.glsl);
		bdestroy(sContext.earlyMain);
        for(i=0; i<NUM_PHASES; ++i)
        {
            bdestroy(sContext.postShaderCode[i]);
        }

		for(i=0; i<NUM_PHASES;++i)
		{
			if(psShader->asPhase[i].ppsDecl != 0)
			{
				uint32_t k;
				for(k=0; k < psShader->asPhase[i].ui32InstanceCount; ++k)
				{
					hlslcc_free(psShader->asPhase[i].ppsDecl[k]);
				}
				hlslcc_free(psShader->asPhase[i].ppsDecl);
			}
			if(psShader->asPhase[i].ppsInst != 0)
			{
				uint32_t k;
				for(k=0; k < psShader->asPhase[i].ui32InstanceCount; ++k)
				{
					FreeSubOperands(psShader->asPhase[i].ppsInst[k], psShader->asPhase[i].pui32InstCount[k]);
					hlslcc_free(psShader->asPhase[i].ppsInst[k]);
				}
				hlslcc_free(psShader->asPhase[i].ppsInst);
			}
		}
        
		memcpy(&result->reflection,&psShader->sInfo,sizeof(psShader->sInfo));
        
		result->textureSamplerInfo.ui32NumTextureSamplerPairs = psShader->textureSamplerInfo.ui32NumTextureSamplerPairs;
		for (i=0; i<result->textureSamplerInfo.ui32NumTextureSamplerPairs; i++)
			strcpy(result->textureSamplerInfo.aTextureSamplerPair[i].Name, psShader->textureSamplerInfo.aTextureSamplerPair[i].Name);

        hlslcc_free(psShader);

		success = 1;
    }

    shader = 0;
    tokens = 0;

    /* Fill in the result struct */

    result->shaderType = GLSLShaderType;
    result->sourceCode = glslcstr;
    result->GLSLLanguage = language;

	return success;
}
예제 #21
0
int parse_blueprint_json(JSON_Object *blueprint, blueprint_t *bp)
{
	bstring Name, bp_name, name, game_version;
	uint32_t resource_cost[5];

	bp->revision = json_object_get_number(blueprint, "blueprintVersion");

	bp_name = bfromcstr(json_object_get_string(blueprint, "blueprintName"));
	name = bfromcstr(json_object_get_string(blueprint, "Name"));
	game_version = bfromcstr(json_object_get_string(blueprint, "GameVersion"));

	bstring param1 = bfromcstr(json_object_get_string(blueprint, "Parameter1"));
	bstring param2 = bfromcstr(json_object_get_string(blueprint, "Parameter2"));
	bstring lpos = bfromcstr(json_object_get_string(blueprint, "LocalPosition"));
	bstring lrot = bfromcstr(json_object_get_string(blueprint, "LocalRotation"));

	bp->name = name;
	bp->blueprint_name = bp_name;
	bp->Name = Name;
	bp->game_version = game_version;

	const char* cpos = json_object_get_string(blueprint, "LocalPosition");
	bstring pos = bfromcstr(cpos);
	struct bstrList *pval = bsplit(pos, ',');
	for (int i = 0; i < 3; i++)
	{
		char *ptr;
		char *str = bstr2cstr(pval->entry[i], '0');
		uint32_t n = strtol(str, &ptr, 10);
	}

	const char* crot = json_object_get_string(blueprint, "LocalRotation");
	bstring rot = bfromcstr(crot);
	struct bstrList *rval = bsplit(rot, ',');
	for (int i = 0; i < 4; i++)
	{
		char *ptr;
		char *str = bstr2cstr(rval->entry[i], '0');
		double dbl = strtod(str, &ptr);
		free(str);
		bp->local_rotation[i] = dbl;
	}

	bp->parameter1 = param1;
	bp->parameter2 = param2;

	bp->design_changed = json_object_get_boolean(blueprint, "designChanged");

	bp->id = json_object_get_number(blueprint, "Id");
	bp->force_id = json_object_get_number(blueprint, "ForceId");
	bp->item_number = json_object_get_number(blueprint, "ItemNumber");

	JSON_Array *jresource_cost = json_object_get_array(blueprint, "ResourceCost");
	for (int i = 0; i < 5; i++)
		bp->resource_cost[i] = (uint32_t) json_array_get_number(jresource_cost, i);

	JSON_Array *min_coords = json_object_get_array(blueprint, "MinCords");
	for (int i = 0; i < 3; i++)
		bp->min_coords[i] = (int32_t) json_array_get_number(min_coords, i);

	JSON_Array *max_coords = json_object_get_array(blueprint, "MaxCords");
	for (int i = 0; i < 3; i++)
		bp->max_coords[i] = (int32_t) json_array_get_number(max_coords, i);

	JSON_Array *csi = json_object_get_array(blueprint, "CSI");
	for (int i = 0; i < 40; i++)
		bp->constructable_special_info[i] = json_array_get_number(csi, i);

	bp->last_alive_block = (uint32_t) json_object_get_number(blueprint, "LastAliveBlock");

	JSON_Array *palette = json_object_get_array(blueprint, "COL");
	for(int i = 0; i < 32; i++)
	{
		uint32_t rbga = 0;

		const char* ccolor = json_array_get_string(palette, i);
		bstring color = bfromcstr(ccolor);

		// Create array of substrings
		struct bstrList *values = bsplit(color, ',');
		for (int n = 0; n < 4; n++)
		{
			char *ptr;
			char *str = bstr2cstr(values->entry[n], '0');
			double dbl = strtod(str, &ptr);
			free(str);
			bp->color_palette[i].array[n] = round(dbl * 255.0);
		}
		bstrListDestroy(values);
		bdestroy(color);
	}

	JSON_Array *material = json_object_get_array(blueprint, "BlockIds");
	JSON_Array *position = json_object_get_array(blueprint, "BLP");
	JSON_Array *rotation = json_object_get_array(blueprint, "BLR");
	JSON_Array *color = json_object_get_array(blueprint, "BCI");

	JSON_Array *bp1 = json_object_get_array(blueprint, "BP1");
	JSON_Array *bp2 = json_object_get_array(blueprint, "BP2");
	JSON_Array *block_string_ids = json_object_get_array(blueprint, "BlockStringDataIds");
	JSON_Array *block_data = json_object_get_array(blueprint, "BlockStringData");

	bp->total_block_count = (uint32_t) json_object_get_number(blueprint, "TotalBlockCount");
	bp->main_block_count = (uint32_t) json_object_get_number(blueprint, "BlockCount");
	bp->blocks = calloc(bp->main_block_count, sizeof(block_t));

	for (int i = 0; i < bp->main_block_count; i++)
	{
		block_t *act = &bp->blocks[i];

		act->material = (uint32_t) json_array_get_number(material, i);
		act->rotation = (uint32_t) json_array_get_number(rotation, i);
		act->color = (uint32_t) json_array_get_number(color, i);

		bstring pos_string = bfromcstr(json_array_get_string(position, i));
		struct bstrList *pos_list = bsplit(pos_string, ',');
		for (int n = 0; n < 3; n++)
		{
			char *ptr;
			char *str = bstr2cstr(pos_list->entry[n], '0');
			double dbl = strtod(str, &ptr);
			uint32_t val = round(dbl);
			act->position.array[n] = val;
			free(str);
		}
		bstrListDestroy(pos_list);
		bdestroy(pos_string);

		bstring bp1_string = bfromcstr(json_array_get_string(bp1, i));
		struct bstrList *bp1_values = bsplit(bp1_string, ',');
		for (int n = 0; n < 4; n++)
		{
			char *ptr;
			char *str = bstr2cstr(bp1_values->entry[n], '0');
			double dbl = strtod(str, &ptr);
			act->bp1[n] = dbl;
		}

		bstring bp2_string = bfromcstr(json_array_get_string(bp2, i));
		struct bstrList *bp2_values = bsplit(bp2_string, ',');
		for (int n = 0; n < 4; n++)
		{
			char *ptr;
			char *str = bstr2cstr(bp2_values->entry[n], '0');
			double dbl = strtod(str, &ptr);
			uint32_t val = round(dbl);
			act->bp2[n] = val;
		}

		// Only used for lookup, not saved after that since it has no further semantic value
		const char *cb1 = json_array_get_string(bp1, i);

		if (act->bp1[3] != 0)
		{
			for (int n = 0; n < json_array_get_count(block_string_ids); n++)
			{
				uint32_t test_id = json_array_get_number(block_string_ids, n);
				if (test_id == 0)
				{
					break;
				}
				if (test_id == act->bp1[3])
				{
					// BlockStringData at index n is the one we want
					act->string_data = bfromcstr(json_array_get_string(block_data, n));
				}
			}
		}
	}

	JSON_Array *subconstructables = json_object_get_array(blueprint, "SCs");
	bp->num_sc = json_array_get_count(subconstructables);
	bp->SCs = calloc(bp->num_sc, sizeof(blueprint_t));
	for (int i = 0; i < bp->num_sc; i++)
	{
		JSON_Value *sc_json = json_array_get_value(subconstructables, i);
		JSON_Object *sc_obj = json_value_get_object(sc_json);
		int retval = parse_blueprint_json(sc_obj, &bp->SCs[i]);
		if (retval != 0)
			return retval;
	}

	return 0;
}
예제 #22
0
TileMapParseStatus TileMap_parse_tileset(xmlTextReaderPtr reader,
                                         Engine *engine, TileMap *map,
                                         Tileset **out_tileset) {
  TileMapParseStatus status = TILEMAP_PARSE_OK;
  Tileset *tileset = calloc(1, sizeof(Tileset));
  check(tileset != NULL, "Couldn't create tileset");
  
  while (xmlTextReaderMoveToNextAttribute(reader)) {
    xmlChar *attrName = xmlTextReaderName(reader);
    xmlChar *attrVal = xmlTextReaderValue(reader);
    
    if (streq(attrName, "firstgid")) {
      tileset->first_gid = atoi((const char *)attrVal);
    } else if (streq(attrName, "tilewidth")) {
      tileset->tile_size.w = atoi((const char *)attrVal);
    } else if (streq(attrName, "tileheight")) {
      tileset->tile_size.h = atoi((const char *)attrVal);
    } else if (streq(attrName, "name")) {
      tileset->name = calloc(1, strlen((const char *)attrVal) + 1);
      strcpy(tileset->name, (const char *)attrVal);
    }
  }
  while (xmlTextReaderRead(reader)) {
    xmlChar *childName = xmlTextReaderName(reader);
    if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL &&
        streq(childName, "tileset")) {
      break;
    } else if (streq(childName, "image")) {
      while (xmlTextReaderMoveToNextAttribute(reader)) {
        xmlChar *attrName = xmlTextReaderName(reader);
        xmlChar *attrVal = xmlTextReaderValue(reader);
        
        if (streq(attrName, "source")) {
          // Check for existence of image
          bstring imgpath = bfromcstr("media/tilesets/");
          bstring src = bfromcstr((const char *)attrVal);
          bconcat(imgpath, src);
          char *cpath = bstr2cstr(imgpath, '\0');
          bdestroy(imgpath);
          bdestroy(src);
          
          FILE *fileexists = load_resource(cpath);
          if (fileexists == NULL) {
            free(cpath);
            Tileset_destroy(tileset);
            Engine_log("Cannot open map. Missing tileset <%s>", attrVal);
            return TILEMAP_PARSE_MISSING_IMAGE;
          }
          fclose(fileexists);
          
          tileset->texture = Graphics_texture_from_image(engine->graphics,
                                                         cpath);
          tileset->img_src = cpath;
        }
      }
    }
  }
  
  *out_tileset = tileset;
  
  return status;
error:
  if (tileset) Tileset_destroy(tileset);
  if (status == TILEMAP_PARSE_OK) status = TILEMAP_PARSE_UNKNOWN_ERR;
  return status;
}
예제 #23
0
int main (int argc, char * argv[]) {

    bstring b = bfromcstr ("Hello WORLDDDD");
    if (!b) {
        fprintf (stderr, "Out of memory");
    } else {
        puts ((char *) b->data);
    }

	bdestroy (b);

    b = bfromcstralloc (64, "123456789012345678901234567890123456789012345678901234567890123");
    if (b)
    {
        b->data[63] = 'x';
        puts ((char *) b->data);
        printf("dump is %s\n", dumpBstring(b));
    }
    else
    {
        puts("bfromcstralloc failed");
    }

	bdestroy (b);

    b = blk2bstr ("AWHOLEnewworld", sizeof("wholenewworld")-3);
    puts ((char *) b->data);

    char *cstr = bstr2cstr(b, '\0');
    puts(cstr);
    free(cstr);

    cstr = bstr2cstr(b, '0');
    puts(cstr);
    free(cstr);

    bstring copy = bstrcpy(b);
    printf("copy is %s\n", (char *) copy->data);

    bdestroy (b);
    b = bfromcstralloc (64, "123456789012345678901234567890123456789012345678901234567890123");

    bassign(copy, b);
    printf("copy is %s\n", (char *) copy->data);
    printf("b is %s\n", (char *) b->data);

    bdestroy (b);
    b = blk2bstr ("AWHOLEnewworld", sizeof("wholenewworld"));

    bassign(copy, b);
    printf("copy is %s\n", (char *) copy->data);
    printf("b is %s\n", (char *) b->data);

    bdestroy(b);
    bdestroy(copy);

    int i = 0;
    b = bfromcstralloc (64, "123456789012345678901234567890123456789012345678901234567890123");
    struct bstrList *blist = bsplit(b, '0');
    printf("made blist. qty is %d, mlen is %d. entry[0] is %s\n", blist->qty, blist->mlen, blist->entry[0]->data);
    for(i=0; i<blist->qty; i++)
    {
        printf("entry[%d] is %s\n", i, blist->entry[i]->data);
    }
    bstrListDestroy(blist);

    blist = bsplit(b, '\0');
    printf("made blist. qty is %d, mlen is %d. entry[0] is %s\n", blist->qty, blist->mlen, blist->entry[0]->data);
    for(i=0; i<blist->qty; i++)
    {
        printf("entry[%d] is %s\n", i, blist->entry[i]->data);
    }
    bstrListDestroy(blist);

    struct tagbstring split = bsStatic ("123");
    blist = bsplitstr(b, &split);
    printf("made blist. qty is %d, mlen is %d. entry[0] is %s\n", blist->qty, blist->mlen, blist->entry[0]->data);
    for(i=0; i<blist->qty; i++)
    {
        printf("entry[%d] is %s\n", i, blist->entry[i]->data);
    }
    bdestroy(b);
/*
 *
 *#define CHUNK 1024 [> read 1024 bytes at a time <]
 *    char buf[CHUNK];
 *    FILE *file;
 *    size_t nread;
 *
 *    file = fopen("./LICENSE", "r");
 *    if (file) {
 *        while ((nread = fread(buf, 1, sizeof buf, file)) > 0)
 *            fwrite(buf, 1, nread, stdout);
 *        if (ferror(file)) {
 *            [> deal with error <]
 *        }
 *        fclose(file);
 *    }
 */


    FILE *lic_fd = fopen("./LICENSE", "r");

    struct bStream *bslic_fd = bsopen((bNread) fread, lic_fd);

    bstring lic_bstr = bread( (bNread) fread, lic_fd);

    printf("bstring is %s", lic_bstr->data);

    return 0;
}
예제 #24
0
파일: assem.c 프로젝트: jathd/DCPUToolchain
void process_line(struct ast_node_line* line)
{
    struct instruction_mapping* insttype;
    struct process_parameters_results ppresults;
    struct process_parameter_results dparam;
    struct ast_node_parameter* dcurrent;
    uint32_t dchrproc;
    uint16_t i, flimit, fchar, opos;
    struct aout_byte* result = NULL;
    struct dbg_sym* newsym;

    // Change depending on the type of line.
    switch (line->type)
    {
        case type_keyword:
            switch (line->keyword)
            {
                case SYMBOL:
                    printd(LEVEL_VERBOSE, ".SYMBOL %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit debugging symbol.
                    list_append(&newsyms, dbgfmt_create_symbol(DBGFMT_SYMBOL_STRING, dbgfmt_create_symbol_string(line->keyword_data_string, DBGFMT_UNDETERMINED)));

                    break;

                case SECTION:
                    printd(LEVEL_VERBOSE, ".SECTION %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit section metadata.
                    aout_emit(aout_create_metadata_section(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case OUTPUT:
                    printd(LEVEL_VERBOSE, ".OUTPUT %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit output metadata.
                    aout_emit(aout_create_metadata_output(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case BOUNDARY:
                    printd(LEVEL_VERBOSE, ".BOUNDARY");

                    // Emit safety boundary of 16 NULL words.
                    for (i = 0; i < 16; i += 1)
                        aout_emit(aout_create_raw(0));

                    break;

                case FILL:
                    printd(LEVEL_VERBOSE, ".FILL");

                    if (line->keyword_data_expr_1 == NULL || line->keyword_data_expr_2 == NULL)
                    {
                        if (line->keyword_data_string != NULL)
                            dhalt(ERR_LABEL_RESOLUTION_NOT_PERMITTED, line->keyword_data_string->data);
                        else
                            dhalt(ERR_LABEL_RESOLUTION_NOT_PERMITTED, "");
                    }

                    // Emit N words with value X
                    flimit = expr_evaluate(line->keyword_data_expr_1, &dhalt_label_resolution_not_permitted, &dhalt_expression_exit_handler);
                    fchar = expr_evaluate(line->keyword_data_expr_2, &dhalt_label_resolution_not_permitted, &dhalt_expression_exit_handler);
                    for (i = 0; i < flimit; i++)
                        aout_emit(aout_create_raw(fchar));

                    break;

                case EXTENSION:
                    printd(LEVEL_VERBOSE, ".EXTENSION %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit extension metadata.
                    aout_emit(aout_create_metadata_extension(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case INCBIN:
                    printd(LEVEL_VERBOSE, ".INCBIN %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit binary include metadata.
                    aout_emit(aout_create_metadata_incbin(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case ORIGIN:
                    if (line->keyword_data_expr_1 == NULL)
                    {
                        if (line->keyword_data_string != NULL)
                            dhalt(ERR_LABEL_RESOLUTION_NOT_PERMITTED, line->keyword_data_string->data);
                        else
                            dhalt(ERR_LABEL_RESOLUTION_NOT_PERMITTED, "");
                    }

                    opos = expr_evaluate(line->keyword_data_expr_1, &dhalt_label_resolution_not_permitted, &dhalt_expression_exit_handler);
                    printd(LEVEL_VERBOSE, ".ORIGIN 0x%04X", opos);

                    // Emit origin set metadata.
                    aout_emit(aout_create_metadata_origin(opos));

                    break;

                case SEEK:
                    if (line->keyword_data_expr_1 == NULL)
                    {
                        if (line->keyword_data_string != NULL)
                            dhalt(ERR_LABEL_RESOLUTION_NOT_PERMITTED, line->keyword_data_string->data);
                        else
                            dhalt(ERR_LABEL_RESOLUTION_NOT_PERMITTED, "");
                    }

                    opos = expr_evaluate(line->keyword_data_expr_1, &dhalt_label_resolution_not_permitted, &dhalt_expression_exit_handler);
                    printd(LEVEL_VERBOSE, ".SEEK 0x%04X", opos);

                    // Emit seek metadata.
                    aout_emit(aout_create_metadata_seek(opos));

                    break;

                case EXPORT:
                    printd(LEVEL_VERBOSE, ".EXPORT %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit export metadata.
                    aout_emit(aout_create_metadata_export(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case IMPORT:
                    printd(LEVEL_VERBOSE, ".IMPORT %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit import metadata.
                    aout_emit(aout_create_metadata_import(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case IMPORT_OPTIONAL:
                    printd(LEVEL_VERBOSE, ".IMPORT OPTIONAL %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit import metadata.
                    aout_emit(aout_create_metadata_import_optional(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                case JUMP:
                    if (line->keyword_data_string == NULL)
                        printd(LEVEL_VERBOSE, ".JUMP <table>");
                    else
                        printd(LEVEL_VERBOSE, ".JUMP %s", bstr2cstr(line->keyword_data_string, '0'));

                    // Emit jump metadata.
                    if (line->keyword_data_string == NULL)
                        aout_emit(aout_create_metadata_jump(NULL));
                    else
                        aout_emit(aout_create_metadata_jump(bstr2cstr(line->keyword_data_string, '0')));

                    break;

                default:
                    printd(LEVEL_VERBOSE, "?? UNKNOWN KEYWORD\n");
                    dhalt(ERR_UNSUPPORTED_KEYWORD, NULL);
            }

            printd(LEVEL_VERBOSE, "\n");
            break;

        case type_instruction:

            // Check to see if this is DAT.
            if (strcmp(line->instruction->instruction, "DAT") == 0)
            {
                // Handle data.
                printd(LEVEL_VERBOSE, "EMIT DAT");

                // Process parameters as data.
                reverse_parameters(line->instruction->parameters);
                dcurrent = line->instruction->parameters->last;

                while (dcurrent != NULL)
                {
                    // Process parameter normally.
                    dparam = process_parameter(dcurrent);

                    // Output depending on what kind of parameter it was.
                    if (dparam.v_label != NULL) // If this is a label, output something that we need to replace.
                        aout_emit(aout_create_expr(expr_new_label(bautofree(bfromcstr(dparam.v_label)))));
                    else if (dparam.v_raw != NULL) // If the raw field is not null, get each character and output it.
                    {
                        printd(LEVEL_VERBOSE, " \"%s\"", dparam.v_raw->data);

                        for (dchrproc = 0; dchrproc < (uint32_t)blength(dparam.v_raw); dchrproc++)
                            aout_emit(aout_create_raw(dparam.v_raw->data[dchrproc]));
                    }
                    else if (dparam.v_extra_used == true) // Just a single address.
                        aout_emit(aout_create_expr(dparam.v_extra));
                    else // Something that isn't handled by DAT.
                    {
                        printd(LEVEL_VERBOSE, "\n");
                        dhalt(ERR_DAT_UNSUPPORTED_PARAMETER, NULL);
                    }

                    dcurrent = dcurrent->prev;
                }
            }
            else
            {
                // Handle instruction.
                insttype = get_instruction_by_name(line->instruction->instruction);

                if (insttype == NULL)
                    dhalt(ERR_UNKNOWN_OPCODE, line->instruction->instruction);

                printd(LEVEL_VERBOSE, "EMIT %s", insttype->name);

                // Check parameter count.
                if (line->instruction->parameters == NULL && strcmp(line->instruction->instruction, "RFI") == 0)
                {
                    // Handle RFI (which can accept no parameters).
                    result = aout_emit(aout_create_opcode(insttype->opcode, insttype->nbopcode, 0x21 /* 0 literal */));
                    printd(LEVEL_VERBOSE, "\n");
                    break;
                }
                else if (line->instruction->parameters == NULL)
                {
                    // Halt and error.
                    dhalt(ERR_INVALID_PARAMETER_COUNT, NULL);
                }

                // Process parameters normally.
                ppresults = process_parameters(line->instruction->parameters);

                // Force the parameter value to be NXT if it's a label.
                if (ppresults.a_label != NULL) ppresults.a = NXT_LIT;
                if (ppresults.b_label != NULL) ppresults.b = NXT_LIT;
                if (ppresults.a_label != NULL && ppresults.a_label_bracketed) ppresults.a = NXT;
                if (ppresults.b_label != NULL && ppresults.b_label_bracketed) ppresults.b = NXT;

                // Check for relative addressing.
                if ((insttype->opcode == OP_ADD || insttype->opcode == OP_SUB ||
                        insttype->opcode == OP_MUL || insttype->opcode == OP_DIV) && ppresults.a == PC)
                {
                    // Warn about relative addressing portability.
                    dwarn(WARN_RELATIVE_PC_ADDRESSING, NULL);
                }

                // Output the initial opcode.
                if (insttype->opcode != OP_NONBASIC)
                    result = aout_emit(aout_create_opcode(insttype->opcode, ppresults.a, ppresults.b));
                else
                    result = aout_emit(aout_create_opcode(insttype->opcode, insttype->nbopcode, ppresults.a));

                // If the parameter is a label or requires an extra word, output them.
                if (ppresults.b_label != NULL)
                    aout_emit(aout_create_expr(expr_new_label(bautofree(bfromcstr(ppresults.b_label)))));
                else if (ppresults.b_extra_used)
                    aout_emit(aout_create_expr(ppresults.b_extra));

                if (ppresults.a_label != NULL)
                    aout_emit(aout_create_expr(expr_new_label(bautofree(bfromcstr(ppresults.a_label)))));
                else if (ppresults.a_extra_used)
                    aout_emit(aout_create_expr(ppresults.a_extra));

            }

            printd(LEVEL_VERBOSE, "\n");
            break;

        case type_label:
            // Handle label definition.
            list_append(&newsyms, dbgfmt_create_symbol(DBGFMT_SYMBOL_LABEL, dbgfmt_create_symbol_label(bfromcstr(line->label->name), DBGFMT_UNDETERMINED)));
            printd(LEVEL_VERBOSE, ":%s\n", line->label->name);
            aout_emit(aout_create_label(line->label->name));
            break;

        default:
            assert(false);
    }

    // If we can associate debugging symbols with this instruction...
    if (result != NULL)
    {
        // While the new symbols list is not empty, copy those symbols
        // into the output and associate.
        while (list_size(&newsyms) > 0)
        {
            newsym = list_extract_at(&newsyms, 0);
            printd(LEVEL_DEBUG, "Debugging custom symbol: %i\n", newsym->length);
            list_append(&result->symbols, newsym);
            list_append(assem_dbg_symbols, newsym);
        }

        // If the line information is provided, output
        // debugging symbols.
        if (line != NULL && line->file != NULL)
        {
            // Output a file / line number debugging symbol here.
            newsym = dbgfmt_create_symbol(DBGFMT_SYMBOL_LINE, dbgfmt_create_symbol_line(line->file, line->line, DBGFMT_UNDETERMINED));
            list_append(&result->symbols, newsym);
            list_append(assem_dbg_symbols, newsym);

            printd(LEVEL_DEBUG, "Debugging symbol: %i %s\n", line->line, line->file->data);
        }

        // If the higher-language line information is
        // provided, output debugging symbols.
        if (line != NULL && line->ufile != NULL)
        {
            // Output a file / line number debugging symbol here.
            newsym = dbgfmt_create_symbol(DBGFMT_SYMBOL_LINE, dbgfmt_create_symbol_line(line->ufile, line->uline, DBGFMT_UNDETERMINED));
            list_append(&result->symbols, newsym);
            list_append(assem_dbg_symbols, newsym);

            printd(LEVEL_DEBUG, "High-level debugging symbol: %i %s\n", line->uline, line->ufile->data);
        }
    }
}
예제 #25
0
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMem(const char* shader,
    unsigned int flags,
    GLLang language,
	const GlExtensions *extensions,
    GLSLCrossDependencyData* dependencies,
    GLSLShader* result)
{
    uint32_t* tokens;
    Shader* psShader;
    char* glslcstr = NULL;
    int GLSLShaderType = GL_FRAGMENT_SHADER_ARB;
	int success = 0;
    uint32_t i;

    tokens = (uint32_t*)shader;

    psShader = DecodeDXBC(tokens);

	if(psShader)
    {
        HLSLCrossCompilerContext sContext;

        sContext.psShader = psShader;
        sContext.flags = flags;
        sContext.psDependencies = dependencies;

        for(i=0; i<NUM_PHASES;++i)
        {
            sContext.havePostShaderCode[i] = 0;
        }

        TranslateToGLSL(&sContext, &language,extensions);

        switch(psShader->eShaderType)
        {
            case VERTEX_SHADER:
            {
                GLSLShaderType = GL_VERTEX_SHADER_ARB;
                break;
            }
            case GEOMETRY_SHADER:
            {
                GLSLShaderType = GL_GEOMETRY_SHADER;
                break;
            }
            case DOMAIN_SHADER:
            {
                GLSLShaderType = GL_TESS_EVALUATION_SHADER;
                break;
            }
            case HULL_SHADER:
            {
                GLSLShaderType = GL_TESS_CONTROL_SHADER;
                break;
            }
            case COMPUTE_SHADER:
            {
                GLSLShaderType = GL_COMPUTE_SHADER;
                break;
            }
            default:
            {
                break;
            }
        }

        glslcstr = bstr2cstr(sContext.glsl, '\0');

        bdestroy(sContext.glsl);
		bdestroy(sContext.earlyMain);
        for(i=0; i<NUM_PHASES; ++i)
        {
            bdestroy(sContext.postShaderCode[i]);
        }

        hlslcc_free(psShader->psHSControlPointPhaseDecl);
		FreeSubOperands(psShader->psHSControlPointPhaseInstr, psShader->ui32HSControlPointInstrCount);
        hlslcc_free(psShader->psHSControlPointPhaseInstr);

        for(i=0; i < psShader->ui32ForkPhaseCount; ++i)
        {
            hlslcc_free(psShader->apsHSForkPhaseDecl[i]);
			FreeSubOperands(psShader->apsHSForkPhaseInstr[i], psShader->aui32HSForkInstrCount[i]);
            hlslcc_free(psShader->apsHSForkPhaseInstr[i]);
        }
        hlslcc_free(psShader->psHSJoinPhaseDecl);
		FreeSubOperands(psShader->psHSJoinPhaseInstr, psShader->ui32HSJoinInstrCount);
        hlslcc_free(psShader->psHSJoinPhaseInstr);

        hlslcc_free(psShader->psDecl);
		FreeSubOperands(psShader->psInst, psShader->ui32InstCount);
        hlslcc_free(psShader->psInst);
        
		memcpy(&result->reflection,&psShader->sInfo,sizeof(psShader->sInfo));
        

        hlslcc_free(psShader);

		success = 1;
    }

    shader = 0;
    tokens = 0;

    /* Fill in the result struct */

    result->shaderType = GLSLShaderType;
    result->sourceCode = glslcstr;
    result->GLSLLanguage = language;

	return success;
}
예제 #26
0
/* ----------------------------------------------------------
 * FUNCTION     : parse_line
 * DESCRIPTION  : This function will process a line of data
 *              : from a configuration file.
 * INPUT        : 0 - Line (bstring)
 * ---------------------------------------------------------- */
void parse_line (bstring line)
{
    bstring param, value;
    struct bstrList *list;
    int i;

    /* Check to see if this line has something to read. */
    if (line->data[0] == '\0' || line->data[0] == '#')
       return;

    /* Check to see if this line has a comment in it. */
    if ((list = bsplit(line, '#')) != NULL) {
        if ((bassign(line, list->entry[0])) == -1) {
            log_message("warning:  'bassign' in function 'parse_line' failed.");
        }
        if (list != NULL)
            bstrListDestroy(list);
    }

    /* Seperate line into a parameter and a value. */
    if ((i = bstrchr(line, ' ')) == BSTR_ERR)
        return;
    if ((param = bmidstr(line, 0, i)) == NULL)
        return;
    if ((value = bmidstr(line, i + 1, line->slen - i)) == NULL)
        return;

    /* Normalize Strings */
    if ((btolower(param)) != 0)
        log_message("warning:  'btolower' in function 'parse_line' failed.");
    if ((bltrim(value)) != 0)
        log_message("warning:  'bltrim' in function 'parse_line' failed.");
    if ((brtrim(value)) != 0)
        log_message("warning:  'brtrim' in function 'parse_line' failed.");

    /* Do something based upon value. */
    if ((biseqcstr(param, "daemon")) == 1) {
        /* DAEMON */
        if (!gc.daemon_mode) {
            if (value->data[0] == '1')
                gc.daemon_mode = 1;
            else
                gc.daemon_mode = 0;
        }

    } else if ((biseqcstr(param, "pid_file")) == 1) {
            /* PID FILE */
        gc.pid_file = bstrcpy(value);

    } else if ((biseqcstr(param, "sig_file")) == 1) {
        /* SIGNATURE FILE */
        gc.sig_file = bstrcpy(value);
   
    } else if ((biseqcstr(param, "mac_file")) == 1) {
        /* MAC / VENDOR RESOLUTION FILE */
        gc.mac_file = bstrcpy(value);

    } else if ((biseqcstr(param, "output")) == 1) {
        /* OUTPUT */
        conf_module_plugin(value, &activate_output_plugin);

    } else if ((biseqcstr(param, "user")) == 1) {
        /* USER */
        gc.priv_user = bstrcpy(value);

    } else if ((biseqcstr(param, "group")) == 1) {
        /* GROUP */
        gc.priv_group = bstrcpy(value);

    } else if ((biseqcstr(param, "interface")) == 1) {
        /* INTERFACE */
        gc.dev = bstr2cstr(value, '-');

    } else if ((biseqcstr(param, "filter")) == 1) {
        /* FILTER */
        gc.pcap_filter = bstr2cstr(value, '-');

    } else if ((biseqcstr(param, "network")) == 1) {
        /* NETWORK */
        parse_networks(bdata(value));

    }

    verbose_message("config - PARAM:  |%s| / VALUE:  |%s|", bdata(param), bdata(value));

    /* Clean Up */
    if (param != NULL)
        bdestroy(param);
    if (value != NULL)
        bdestroy(value);
}
예제 #27
0
void process_line(struct ast_node_line* line)
{
	struct instruction_mapping* insttype;
	struct process_parameters_results ppresults;
	struct process_parameter_results dparam;
	struct ast_node_parameter* dcurrent;
	uint32_t dchrproc;
	uint16_t i, flimit, fchar, opos;

	// Change depending on the type of line.
	switch (line->type)
	{
		case type_keyword:
			switch (line->keyword)
			{
				case BOUNDARY:
					fprintf(stderr, ".BOUNDARY");

					// Emit safety boundary of 16 NULL words.
					for (i = 0; i < 16; i += 1)
						aout_emit(aout_create_raw(0));

					break;

				case FILL:
					fprintf(stderr, ".FILL");

					// Emit N words with value X
					flimit = expr_evaluate(line->keyword_data_expr_1, &ahalt_label_resolution_not_permitted, &ahalt_expression_exit_handler);
					fchar = expr_evaluate(line->keyword_data_expr_2, &ahalt_label_resolution_not_permitted, &ahalt_expression_exit_handler);
					for (i = 0; i < flimit; i++)
						aout_emit(aout_create_raw(fchar));

					break;

				case EXTENSION:
					fprintf(stderr, ".EXTENSION %s", line->keyword_data_string);

					// Emit extension metadata.
					aout_emit(aout_create_metadata_extension(bstr2cstr(line->keyword_data_string, '0')));

					break;

				case INCBIN:
					fprintf(stderr, ".INCBIN %s", line->keyword_data_string);

					// Emit binary include metadata.
					aout_emit(aout_create_metadata_incbin(bstr2cstr(line->keyword_data_string, '0')));

					break;

				case ORIGIN:
					opos = expr_evaluate(line->keyword_data_expr_1, &ahalt_label_resolution_not_permitted, &ahalt_expression_exit_handler);
					fprintf(stderr, ".ORIGIN 0x%04X", opos);

					// Emit origin set metadata.
					aout_emit(aout_create_metadata_origin(opos));

					break;

				case EXPORT:
					fprintf(stderr, ".EXPORT %s", line->keyword_data_string);

					// Emit export metadata.
					aout_emit(aout_create_metadata_export(bstr2cstr(line->keyword_data_string, '0')));

					break;

				case IMPORT:
					fprintf(stderr, ".IMPORT %s", line->keyword_data_string);

					// Emit export metadata.
					aout_emit(aout_create_metadata_import(bstr2cstr(line->keyword_data_string, '0')));

					break;

				default:
					fprintf(stderr, "\n");
					ahalt(ERR_UNSUPPORTED_KEYWORD, NULL);
			}

			fprintf(stderr, "\n");
			break;

		case type_instruction:

			// Check to see if this is DAT.
			if (strcmp(line->instruction->instruction, "DAT") == 0)
			{
				// Handle data.
				fprintf(stderr, "EMIT DAT");

				// Process parameters as data.
				reverse_parameters(line->instruction->parameters);
				dcurrent = line->instruction->parameters->last;

				while (dcurrent != NULL)
				{
					// Process parameter normally.
					dparam = process_parameter(dcurrent);

					// Output depending on what kind of parameter it was.
					if (dparam.v_label != NULL) // If this is a label, output something that we need to replace.
						aout_emit(aout_create_expr(expr_new_label(bautofree(bfromcstr(dparam.v_label)))));
					else if (dparam.v_raw != NULL) // If the raw field is not null, get each character and output it.
					{
						fprintf(stderr, " \"%s\"", dparam.v_raw->data);

						for (dchrproc = 0; dchrproc < blength(dparam.v_raw); dchrproc++)
							aout_emit(aout_create_raw(dparam.v_raw->data[dchrproc]));
					}
					else if (dparam.v_extra_used == true) // Just a single address.
						aout_emit(aout_create_expr(dparam.v_extra));
					else // Something that isn't handled by DAT.
					{
						fprintf(stderr, "\n");
						ahalt(ERR_DAT_UNSUPPORTED_PARAMETER, NULL);
					}

					dcurrent = dcurrent->prev;
				}
			}
			else
			{
				// Handle instruction.
				insttype = get_instruction_by_name(line->instruction->instruction);

				if (insttype == NULL)
					ahalt(ERR_UNKNOWN_OPCODE, line->instruction->instruction);

				fprintf(stderr, "EMIT %s", insttype->name);

				// Process parameters normally.
				ppresults = process_parameters(line->instruction->parameters);

				// Force the parameter value to be NXT if it's a label.
				if (ppresults.a_label != NULL) ppresults.a = NXT_LIT;

				if (ppresults.b_label != NULL) ppresults.b = NXT_LIT;

				if (ppresults.a_label != NULL && ppresults.a_label_bracketed) ppresults.a = NXT;

				if (ppresults.b_label != NULL && ppresults.b_label_bracketed) ppresults.b = NXT;

				// Output the initial opcode.
				if (insttype->opcode != OP_NONBASIC)
					aout_emit(aout_create_opcode(insttype->opcode, ppresults.a, ppresults.b));
				else
					aout_emit(aout_create_opcode(insttype->opcode, insttype->nbopcode, ppresults.a));

				// If the parameter is a label or requires an extra word, output them.
				if (ppresults.b_label != NULL)
					aout_emit(aout_create_expr(expr_new_label(bautofree(bfromcstr(ppresults.b_label)))));
				else if (ppresults.b_extra_used)
					aout_emit(aout_create_expr(ppresults.b_extra));

				if (ppresults.a_label != NULL)
					aout_emit(aout_create_expr(expr_new_label(bautofree(bfromcstr(ppresults.a_label)))));
				else if (ppresults.a_extra_used)
					aout_emit(aout_create_expr(ppresults.a_extra));

			}

			fprintf(stderr, "\n");
			break;

		case type_label:
			// Handle label definition.
			fprintf(stderr, ":%s\n", line->label->name);
			aout_emit(aout_create_label(line->label->name));
			break;
	}
}
예제 #28
0
void dbg_lua_handle_command(struct dbg_state* state, void* ud, freed_bstring name, list_t* parameters)
{
    struct lua_debugst* ds;
    struct customarg_entry* carg;
    char* cstr;
    unsigned int i, k;
    int paramtbl;

    // Convert the name to lowercase.
    btolower(name.ref);
    cstr = bstr2cstr(name.ref, '0');

    // Loop through all of the modules.
    for (k = 0; k < list_size(&modules); k++)
    {
        ds = list_get_at(&modules, k);

        // Set stack top (I don't know why the top of the
        // stack is negative!)
        lua_settop(ds->state, 0);

        // Search handler table for entries.
        lua_getglobal(ds->state, HANDLER_TABLE_COMMANDS_NAME);
        lua_getfield(ds->state, -1, cstr);
        if (!lua_istable(ds->state, -1))
        {
            // No such entry.
            lua_pop(ds->state, 2);
            continue;
        }

        // Call the handler function.
        lua_getfield(ds->state, -1, HANDLER_FIELD_FUNCTION_NAME);
        dbg_lua_push_state(ds, state, ud);
        lua_newtable(ds->state);
        paramtbl = lua_gettop(ds->state);
        for (i = 0; i < list_size(parameters); i++)
        {
            carg = list_get_at(parameters, i);

            lua_newtable(ds->state);
            if (carg->type == DBG_CUSTOMARG_TYPE_PATH)
                lua_pushstring(ds->state, "PATH");
            else if (carg->type == DBG_CUSTOMARG_TYPE_PARAM)
                lua_pushstring(ds->state, "PARAM");
            else if (carg->type == DBG_CUSTOMARG_TYPE_STRING)
                lua_pushstring(ds->state, "STRING");
            else
                lua_pushstring(ds->state, "NUMBER");
            lua_setfield(ds->state, -2, "type");
            if (carg->type == DBG_CUSTOMARG_TYPE_PATH)
                lua_pushstring(ds->state, carg->path->data);
            else if (carg->type == DBG_CUSTOMARG_TYPE_PARAM)
                lua_pushstring(ds->state, carg->param->data);
            else if (carg->type == DBG_CUSTOMARG_TYPE_STRING)
                lua_pushstring(ds->state, carg->string->data);
            else
                lua_pushnumber(ds->state, carg->number);
            lua_setfield(ds->state, -2, "value");
            lua_rawseti(ds->state, paramtbl, i + 1);
        }
        if (lua_pcall(ds->state, 2, 0, 0) != 0)
        {
            printd(LEVEL_ERROR, "error: unable to call debugger command handler for '%s'.\n", name.ref->data);
            printd(LEVEL_ERROR, "%s\n", lua_tostring(ds->state, -1));
            bautodestroy(name);
            bcstrfree(cstr);
            lua_pop(ds->state, 2);
            list_iterator_stop(&modules);
            list_destroy(parameters);
            return;
        }

        bautodestroy(name);
        bcstrfree(cstr);
        lua_pop(ds->state, 2);
        list_iterator_stop(&modules);
        list_destroy(parameters);

        // The command may have started the virtual machine, check the
        // status of the VM and execute if needed.
        if (state->get_vm()->halted == false)
            vm_execute(state->get_vm(), NULL);

        return;
    }

    // There is no command to handle this.
    printd(LEVEL_ERROR, "no such command found.\n");

    // Clean up.
    list_destroy(parameters);
    bautodestroy(name);
    bcstrfree(cstr);
}