Пример #1
0
static int dumpDevices(FILE * of)
{
	int i;
	struct io_device * d;
	devlib_ent_t * dd;
	char configStr[128];
	bool nullConfig;

	d = ke_get_device_list(proxy_adapter->kernel);

	for(i=0; i<IO_MAX_DEVICES; i++, d++){
		if(!(d->features & IO_DEVICE_PRESENT)){
			continue;
		}
		dd = blklib_get_dev_by_id(&d->clsid);
		if(dd && !strcmpi(dd->name, "none")){
			continue;
		}

		{
			int j;
			char * p;
			p=configStr;
			nullConfig=true;
			for(j=0;j<DEV_CONFIG_LEN;j++){
				p+=sprintf(p,"%02x", d->configData[j]);
				if(d->configData[j]){
					nullConfig=false;
				}
			}
		}
		
		if(dd){
			if(of==stdout)
				utils_trace("device %d %s %s\n", i, dd->name, nullConfig? "" : configStr);
			else
				fprintf(of, "device %d %s %s\n", i, dd->name, nullConfig? "" : configStr);
		}else{
			char uid[128];
			f8_uuid_to_string(&d->clsid, uid, sizeof(uid));
			if(of==stdout)
				utils_trace("device %d %s %s\n", i, uid, nullConfig? "" : configStr);
			else
				fprintf(of, "device %d %s %s\n", i, uid, nullConfig? "" : configStr);
		}
	}

	return 0;
}
Пример #2
0
static int UTILS_API _e_file(
	const char * szBaseDir,
	const char * szFullPath,
	const char * szRelativePath,
	const void * pvSearchContext
	)
{
	IBlk * blk;
	char buf[128];
	IFileStream *fs;
	IF8Stream *s;
	int roffset;

	fs = IFileStream_from_file(szFullPath, "rb");
	if(!fs){
		return 1;
	}
	s = __ucast__(IFileStream, IF8Stream, (fs));
	blk = IBlk_from_stream(s);
	if(!blk){
		__delete__(fs);
		return 1;
	}
	roffset = __vcall__(s, tell, (s));
	load_res_stream(s);
	probe_blk_resources(blk);
	
	fprintf(fdb, 
		"%d=%s,%c%c,%s", 
		count,
		IBlk_class_name(blk),
		blk->h.magic >> 8,
		blk->h.magic & 0xff,
		szRelativePath
		);
	f8_uuid_to_string(&blk->h.uuid, buf, sizeof(buf));
	fprintf(fdb, ",%s", buf);
	fprintf(fdb, ",%d", roffset);
	fprintf(fdb, "\n");
	
	delete_blk(blk);
	__delete__(fs);

	count++;
	return 1;
}
Пример #3
0
int main(int c, char **v)
{
	char	buf[128];
	__bool	bClipBoard=__false;
	f8_uuid	uuid;

	BEGIN_ARGS
		ARG("-c", bClipBoard, "tbool", "copy result to clipboard")
	END_ARGS

	if(process_args_1(c, v)){
		print_usage_1();
		return -1;
	}

	create_f8_uuid(&uuid);
	f8_uuid_to_string(&uuid, buf, sizeof(buf));
	printf("%s\n", buf);

#ifdef _WIN32
	//if(bClipBoard)
	{
		if( !OpenClipboard(NULL) ){
			return -1;
		}
		EmptyClipboard();
		HANDLE h = GlobalAlloc(GMEM_MOVEABLE, strlen(buf) + 1);
		char * p = (char *)GlobalLock(h);
		if(p){
			GlobalUnlock(h);
			strcpy(p, buf);
			SetClipboardData(CF_TEXT, h);
		}
		CloseClipboard();
	}
#endif

	return 0;
}
Пример #4
0
/*
	import a resource from disk, and if the resource has
	already been loaded, increment its reference count.

	2005/6/24
	the load_from_disk branch is obsolete.
*/
F8RES_API __bool load_resource(
	const f8_uuid * id
	)
{
	RESMAP::iterator it;
	it = g_Resources.find(*id);
	if(it != g_Resources.end()){
		it->second.refcount++;
		return __true;
	}
	return __false;
#if 0
	IFileStream *fs;
	IF8Stream * str;
	char buf[43];
	
	f8_uuid_to_string(id, buf, sizeof(buf));
	strcat(buf, ".res");
	fs = IFileStream_from_file(buf, "rb");
	if(!fs){
		return __false;
	}
	str = __ucast__(IFileStream, IF8Stream, fs);
	h = _load_res_stream(str);
	if(h){
		if(*id != h->id){
			/* error in library */
			unload_resource(&h->id);
			h = 0;
		}		
	}

	__delete__(fs);
	return h? __true : __false;
#endif
}
Пример #5
0
__bool CRegRequirementList::Add(struct blk_var_t * v)
{
	var_item	item;
	varlist::iterator vit;
	pair<varlist::iterator, bool> pi;

	vit = m_vlist.find(v->uuid);
	if(vit == m_vlist.end()){
		item.blk_id = v->blk->uuid;
		item.var = v;
		item.ref_count = 1;
		pi = m_vlist.insert(varlist::value_type(v->uuid, item));
		if(!pi.second){
			m_errcode = F8_LOW_MEMORY;
			char idName[F8_MAX_PATH];
			f8_uuid_to_string(&v->uuid, idName, sizeof(idName));
			utils_error("unable to add variable %s(%s)\n", v->name, idName);
		}
	}else{
		vit->second.ref_count++;
	}	

	return __true;
}
Пример #6
0
static void dumpBblk(IBlk * b, FILE * of)
{
	const char * name;
	char path[F8_MAX_PATH];
	char buf[1024];
	char idName[128];
	struct blk_ent_t be;
	struct blk_pin_t * p;

	*buf=0;
	if(!(parent_blk(b)->h.flags & BLK_F_READONLY)){
		name = IBlk_name(b);
		IBlk_path_by_blk(parent_blk(b), path, sizeof(buf));
		if(blklib_query(&b->h.uuid, &be)){
			sprintf(buf, "mount  path=\"%s\" type=\"%s.%s\" name=\"%s\"", path, be.dir, be.name, name);
		}else{
			f8_uuid_to_string(&b->h.uuid, idName, sizeof(idName));
			sprintf(buf, "mount  path=\"%s\" id=%s name=\"%s\" ", path, idName, name);
		}
		if(of==stdout)
			utils_trace("%s\n", buf);
		else
			fprintf(of, "%s\n", buf);
		IBlk_path_by_blk(b, path, sizeof(path));
		sprintf(buf, "place block \"%s\" (%d,%d)", path, get_res_int(&b->uuid, "x", 0), get_res_int(&b->uuid, "y", 0));
		if (of==stdout)
			utils_trace("%s\n", buf);
		else
			fprintf(of, "%s\n", buf);		
	}
	
	for(p = __vcall__(b, first_pin, (b)); p; p = __vcall__(b, next_pin, (p))){
		if(p->_class != PIN_CLASS_DI && p->_class != PIN_CLASS_DO){
			continue;
		}
		IBlk_path_by_pin(p, path, sizeof(path));
		// dump binding
		*buf = 0;
		if(p->binding == PIN_B_CONST){
			switch(p->type){
			case  PIN_T_INTEGER	:
				if(p->dp->u.d.i32 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.i32);
				}
				break;
			case  PIN_T_BOOL		:
				if(p->dp->u.d.ui8 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.ui8);
				}
				break;
			case  PIN_T_FLOAT		:
				if(p->dp->u.d.flt != 0){
					sprintf(buf, "bind \"%s\" %f", path, p->dp->u.d.flt);
				}
				break;
			case  PIN_T_BYTE		:
				if(p->dp->u.d.ui8 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.ui8);
				}
				break;
			case  PIN_T_WORD		:
				if(p->dp->u.d.ui16 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.ui16);
				}
				break;
			case  PIN_T_DOUBLE	:
				if(p->dp->u.d.dbl != 0){
					sprintf(buf, "bind \"%s\" %.15f", path, p->dp->u.d.dbl);
				}
				break;
			case  PIN_T_DATE		:
				if(fabs(p->dp->u.d.dbl) > 1e-9){
					if(p->dp->u.d.dbl > 2.0){
						sprintf(buf, "bind \"%s\" t#%fs", path, p->dp->u.d.dbl);
					}else{
						sprintf(buf, "bind \"%s\" t#%fms", path, p->dp->u.d.dbl*1000);
					}
				}
				break;
			case  PIN_T_CHAR		:
				if(p->dp->u.d.i8 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.i8);
				}
				break;
			case  PIN_T_SHORT		:
				if(p->dp->u.d.i16 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.ui16);
				}
				break;
			case  PIN_T_DWORD		:
				if(p->dp->u.d.ui32 != 0){
					sprintf(buf, "bind \"%s\" %d", path, p->dp->u.d.ui32);
				}
				break;
			}
		}else {
			struct blk_var_t * v;
			v = query_var_by_pin(p);
			if(v){
				char vpath[F8_MAX_PATH];
				IBlk_path_by_blk(v->blk, vpath, sizeof(vpath));
				sprintf(buf, "bind \"%s\" %s.%s", path, vpath, v->name);
				// on_bind
			}
		}

		if(*buf){
			if(of==stdout)
				utils_trace("%s\n", buf);
			else
				fprintf(of, "%s\n", buf);
		}
		
		if(p->type==PIN_T_BOOL && (p->flags & PIN_F_INVERTED)){
			sprintf(buf, "invert \"%s\"", path);
			if(of==stdout)
				utils_trace("%s\n", buf);
			else
				fprintf(of, "%s\n", buf);
		}
		
	}
}
Пример #7
0
static void dumpCblk(IBlk * b, __bool firstVisit, FILE * of)
{
	const char * name;
	char path[F8_MAX_PATH];
	char buf[1024];
	char idName[128];
	struct blk_ent_t be;

	if(firstVisit){
		name = IBlk_name(b);
		IBlk_path_by_blk(parent_blk(b), path, sizeof(path));
		if(parent_blk(b) && !(parent_blk(b)->h.flags & BLK_F_READONLY)){
			if(b->h.flags & BLK_F_READONLY){
				if(blklib_query(&b->h.uuid, &be)){
					sprintf(buf, "mount  path=\"%s\" type=\"%s.%s\" name=\"%s\"", path, be.dir, be.name, name);
				}else{
					f8_uuid_to_string(&b->h.uuid, idName, sizeof(idName));
					sprintf(buf, "mount  path=\"%s\" id=%s name=\"%s\"", path, idName, name);
				}
				if(of==stdout)
					utils_trace("%s\n",buf);
				else
					fprintf(of, "%s\n", buf);
				return;
			}else{
				sprintf(buf, "mount path=\"%s\" file=blank.blk name=\"%s\" rw", path, name);
			}
			if (of==stdout)
				utils_trace("%s\n",buf);
			else
				fprintf(of, "%s\n", buf);
			IBlk_path_by_blk(b, path, sizeof(path));
			sprintf(buf, "place block \"%s\" (%d,%d)", path, get_res_int(&b->uuid, "x", 0), get_res_int(&b->uuid, "y", 0));
			if(of==stdout)
				utils_trace("%s\n",buf);
			else
				fprintf(of, "%s\n", buf);
		}

		enum_variables(b, defineVariable, (__uint)of);
	}else{
		/*
			dump links positions/export pins
		*/
		if(b->h.flags & BLK_F_READONLY){
			return;
		}
		ICBlk * cb = __dcast__(IBlk, ICBlk, b);
		struct cblk_link_t * l;
		for(l=ICBlk_first_link(cb); l; l=ICBlk_next_link(l)){
			char p1[F8_MAX_PATH];
			char p2[F8_MAX_PATH];
			IBlk_path_by_pin(l->s.pin, p1, sizeof(p1));
			IBlk_path_by_pin(l->t.pin, p2, sizeof(p2));
			sprintf(buf, "link \"%s\" \"%s\"", p1, p2);
			if(of==stdout)
				utils_trace("%s\n",buf);
			else
				fprintf(of, "%s\n", buf);

			TLinkMetrics *m;
			m = (TLinkMetrics *)get_res_buf(&l->uuid, 0, "metrics");
			if(m){
				char *p;
				p = buf;
				p += sprintf(p, "place link \"%s\" %d ", p2, m->count);
				int i;
				for(i=0; i<m->count; i++){
					p += sprintf(p, "(%d,%d) ", m->coord[i].x, m->coord[i].y);
				}
				if(of==stdout)
					utils_trace("%s\n",buf);
				else
					fprintf(of, "%s\n", buf);
			}
		}
	}
}