Ejemplo n.º 1
0
static void opensamples () {
	int fd = open("1", O_RDWR);
	if (fd < 0) return;
	int ns = filelen(fd);
   byte *s = mmap(NULL, nsamples, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	if (!s) return;
	puts("opened"),samples=s,nsamples=ns; }
Ejemplo n.º 2
0
int fnumlines(char const *filename) {
  int len = filelen(filename);
  if (len == ERROR) return ERROR;
  else {
    char buf[len];
    getfile(filename,sizeof buf,buf);
    return numlines(sizeof buf,buf);
  }
}
Ejemplo n.º 3
0
int copy(char *dest, char *src)
{
	FILE *in, *out;
	int ret;
	char *actualdest = dest;

	if(samefile(dest, src)){
		eprintf("`%s' and `%s' are the same file", dest, src);
		return 1;
	}

	if(!(in = fopen(src, "r"))){
		perrorf("open (for read): `%s'", src);
		return 1;
	}

	/* TODO: make dir if it doesn't exist */
	if(!(out = fopen(dest, "w"))){
		if(errno == EISDIR){
			char *srcbase = strrchr(src, '/');

			if(!srcbase)
				srcbase = src;

			actualdest = alloca(strlen(dest) + strlen(srcbase) + 2);
			sprintf(actualdest, "%s/%s", dest, srcbase);

			if(samefile(actualdest, src)){
				eprintf("`%s' and `%s' are the same file", actualdest, src);
				fclose(in);
				return 1;
			}

			out = fopen(actualdest, "w");
			if(!out){
				perrorf("open (for write): `%s'", actualdest);
				fclose(in);
				return 1;
			}
		}else{
			perrorf("open (for write): `%s'", dest);
			fclose(in);
			return 1;
		}
	}

	ret = filecopy(in, out, actualdest, filelen(src));

	fclose(in);
	fclose(out);

	if(!i_am_cp && remove(src))
		perrorf("non-fatal: remove: `%s'", src);

	return ret;
}
Ejemplo n.º 4
0
void CGraphicsBuffer::LoadEFP(const std::string& aFilename, CPalette* aPalette)
{
	ASSERT(aFilename.length()>0);

	unsigned int p;
	unsigned short w,h;

	int tavu,tavu2;
	int length = filelen(aFilename.c_str()), cnt=0;

	ASSERT(length<10*1024*1024); // less than 10 megabytes
	FILE *efp=fopen(aFilename.c_str(),"rb");
	if (!efp) error("CGraphicsBuffer::LoadEFP: File %s couldn't be opened!\n",aFilename.c_str());

	unsigned char *filebuffer= new unsigned char[length];
	fread(filebuffer,length,1,efp);
	fclose(efp);
	
	if (strncmp((char*)filebuffer,KEFPTag,6) ) 
		error("CGraphicsBuffer::LoadEFP: File %s is not an EFP file!\n",aFilename.c_str());

	cnt+=6;
	w = *(short*)(filebuffer+cnt);cnt+=2;
	h = *(short*)(filebuffer+cnt);cnt+=2;

	Resize(w,h);

	for(p=0;p<(unsigned int)w*h;)
	{
		tavu=filebuffer[cnt++];
		if (tavu>192)
		{
			tavu2=filebuffer[cnt++];
			memset(iBuf+p,tavu2,tavu-192);
			p+=tavu-192;
		} 
		else 
			iBuf[p++]=(char)tavu;
	} 

	if (aPalette)
	{
		aPalette->CopyPalette(filebuffer+cnt);
		aPalette->FourMultiply();
	}

	delete[] filebuffer;
}
void		ft_display_hexdump(char *file)
{
	if (g_add == 0)
		g_total_size = 0;
	g_total_size = g_total_size + filelen(file);
	if (g_option)
	{
		g_n = 8;
		read_display(file, &hex_print_c);
	}
	else
	{
		g_n = 7;
		read_display(file, &hex_print);
	}
}
Ejemplo n.º 6
0
void COptions::Load() 
{
	FILE *cfg;

	if (filelen(getsavepath(KOptionsFilename).c_str())==sizeof(COptionsData))
	{
		cfg = fopen(getsavepath(KOptionsFilename).c_str(), "rb");
		if (cfg) 
		{
			fread(&iData,sizeof(COptionsData), 1,cfg);
			fclose(cfg);
		}
	}

	iMusicThemeList->LoadThemes();
	UpdateAudioChanges();
}
Ejemplo n.º 7
0
void
DeclareLabels(ParserState *P)
{
    unsigned asmpc = 0;
    unsigned datoff = 0;
    unsigned inc = 0;
    unsigned delta;

    AST *ast = NULL;
    AST *pendingLabels = NULL;

    for (ast = P->datblock; ast; ast = ast->right) {
        switch (ast->kind) {
        case AST_BYTELIST:
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_byte);
            replaceHereDataList(ast->left, asmpc, 1);
            INCPC(dataListLen(ast->left, 1));
            break;
        case AST_WORDLIST:
            ALIGNPC(2);
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_word);
            replaceHereDataList(ast->left, asmpc, 2);
            INCPC(dataListLen(ast->left, 2));
            break;
        case AST_LONGLIST:
            ALIGNPC(4);
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_long);
            replaceHereDataList(ast->left, asmpc, 4);
            INCPC(dataListLen(ast->left, 4));
            break;
        case AST_INSTRHOLDER:
            ALIGNPC(4);
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_long);
            replaceHeres(ast->left, asmpc/4);
            INCPC(4);
            break;
        case AST_IDENTIFIER:
            pendingLabels = AddToList(pendingLabels, NewAST(AST_LISTHOLDER, ast, NULL));
            break;
        case AST_ORG:
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_long);
            if (ast->left) {
                replaceHeres(ast->left, asmpc/4);
                asmpc = 4*EvalPasmExpr(ast->left);
            } else {
                asmpc = 0;
            }
            break;
        case AST_RES:
            asmpc = align(asmpc, 4);
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_long);
            delta = EvalPasmExpr(ast->left);
            asmpc += 4*delta;
            break;
        case AST_FIT:
            asmpc = align(asmpc, 4);
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_long);
            if (ast->left) {
                int32_t max = EvalPasmExpr(ast->left);
                int32_t cur = (asmpc) / 4;
                if ( cur > max ) {
                    ERROR(ast, "fit %d failed: pc is %d", max, cur);
                }
            }
            break;
        case AST_FILE:
            pendingLabels = emitPendingLabels(P, pendingLabels, datoff, asmpc, ast_type_byte);
            INCPC(filelen(ast->left));
            break;
        default:
            ERROR(ast, "unknown element %d in data block", ast->kind);
            break;
        }
    }
}