Ejemplo n.º 1
0
static char * variable_get( const char *name, int line, int withquotes )
{
	char buffer[100];
	int arg;

	if(!strcmp(name,"$")) {
		sprintf(buffer,"%d",(int)getpid());
		return xxstrdup(buffer);
	} else if(!strcmp(name,"#")) {
		sprintf(buffer,"%d",head->argc-1);
		return xxstrdup(buffer);
	} else if(!strcmp(name,"@")) {
		return variable_print_argv(withquotes);
	} else if(!strcmp(name,"*")) {
		return variable_print_argv(0);
	} else if( sscanf(name,"%d",&arg)==1 ) {
		if(arg>=head->argc) {
			return xxstrdup("");
		} else {
			return xxstrdup(head->argv[arg]);
		}
	} else if( isvalid(name) ) {
		char *result = getenv(name);
		if(result) return xxstrdup(result);
		result = buffer_load(name);
		if(result) string_chomp(result);
		return result;
	} else {
		ftsh_fatal(line,"${%s} is an invalid variable name!",name);
		return 0;
	}
}
Ejemplo n.º 2
0
/* Load code.bin file through boot (reset) interface. */
static int cycx_code_boot(void __iomem *addr, u8 *code, u32 len)
{
	void __iomem *pt_boot_cmd = addr + CMD_OFFSET;
	u32 i;

	/* boot buffer lenght */
	writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
	writew(GEN_DEFPAR, pt_boot_cmd);

	if (wait_cyc(addr) < 0)
		return -1;

	writew(0x0000, pt_boot_cmd + sizeof(u16));
	writew(0xc400, pt_boot_cmd + 2 * sizeof(u16));
	writew(GEN_SET_SEG, pt_boot_cmd);

	if (wait_cyc(addr) < 0)
		return -1;

	for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ)
		if (buffer_load(addr, code + i,
				min_t(u32, CFM_LOAD_BUFSZ, (len - i)))) {
			printk(KERN_ERR "%s: Error !!\n", modname);
			return -1;
		}

	return 0;
}
/* Load data.bin file through boot (reset) interface. */
static int cycx_data_boot(void __iomem *addr, u8 *code, u32 len)
{
	void __iomem *pt_boot_cmd = addr + CMD_OFFSET;
	u32 i;

	/* boot buffer length */
	writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
	writew(GEN_DEFPAR, pt_boot_cmd);

	if (wait_cyc(addr) < 0)
		return -1;

	writew(0, pt_boot_cmd + sizeof(u16));
	writew(0x4000, pt_boot_cmd + 2 * sizeof(u16));
	writew(GEN_SET_SEG, pt_boot_cmd);

	if (wait_cyc(addr) < 0)
		return -1;

	for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ)
		if (buffer_load(addr, code + i,
				min_t(u32, CFM_LOAD_BUFSZ, (len - i))) < 0) {
			pr_err("Error !!\n");
			return -1;
		}

	return 0;
}
Ejemplo n.º 4
0
/* Load data.bin file through boot (reset) interface. */
static int cycx_data_boot(u32 addr, u8 *code, u32 len)
{
	u32 pt_boot_cmd = addr + CMD_OFFSET;
	u32 i;

	/* boot buffer lenght */
	cyc2x_writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
	cyc2x_writew(GEN_DEFPAR, pt_boot_cmd);

	if (wait_cyc(addr) < 0)
		return -1;

	cyc2x_writew(0, pt_boot_cmd + sizeof(u16));
	cyc2x_writew(0x4000, pt_boot_cmd + 2 * sizeof(u16));
	cyc2x_writew(GEN_SET_SEG, pt_boot_cmd);

	if (wait_cyc(addr) < 0)
		return -1;

	for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ)
		if (buffer_load(addr, code + i,
				MIN(CFM_LOAD_BUFSZ, (len - i))) < 0) {
			printk(KERN_ERR "%s: Error !!\n", modname);
			return -1;
		}

	return 0;
}
static inline void
recv_port_copy(struct recv_port* p, unsigned int i, void* data)
{
    unsigned int rd   = recv_port_index(p, i);
    unsigned int token_size = p->token_size;
    buffer_address addr = p->buffer + (rd * token_size);
    buffer_load(addr, data, token_size);
}
Ejemplo n.º 6
0
static int builtin_export( int line, int argc, char **argv, time_t stoptime )
{
    char *expr;
    char *name;
    char *value;

    if(argc<2) {
        ftsh_error(FTSH_ERROR_SYNTAX,line,"export: exactly one argument needed");
        return 0;
    } else if(argc>2) {
        ftsh_error(FTSH_ERROR_SYNTAX,line,"export: too many arguments");
        return 0;
    }

    name = argv[1];

    value = buffer_load(name);
    if(!value) value = xxstrdup("");

    expr = malloc(strlen(name)+strlen(value)+3);
    if(!expr) {
        free(name);
        free(value);
        return 0;
    }

    ftsh_error(FTSH_ERROR_COMMAND,line,"EXPORT %s (%s)",name,value);

    sprintf(expr,"%s=%s",name,value);

    /* Depending on the libc, this call may leak memory */
    /* by leaving multiple exprs allocated.  No solution */
    /* except to leak.  Don't export in an infinite loop. */

    putenv(expr);

    free(name);
    free(value);

    return 1;
}
Ejemplo n.º 7
0
/* Use our buffer library to slurp a file into a string */
size_t buffer_load_string(gc_type *gc, char *file, char **str) {
    size_t count = 0;
    buffer_type *buf = 0;

    gc_register_root(gc, &buf);
    buffer_create(gc, (void **)&buf);

    /* Convert to a single string */
    count = buffer_load(buf, file);

    /* Make sure we could read the file */
    if (count == -1 ) {
        printf("Unable to load file: %s\n", file);
        exit(-2);
    }

    gc_alloc(gc, 0, count+1, (void **)str);

    buffer_read(buf, (uint8_t *)*str, count);

    gc_unregister_root(gc, &buf);
    
    return count;
}