예제 #1
0
static struct font* font_load_header(struct font *pf)
{
    /* Check we have enough data */
    if (!HAVEBYTES(28))
        return NULL;

    /* read magic and version #*/
    if (memcmp(pf->buffer_position, VERSION, 4) != 0)
        return NULL;

    pf->buffer_position += 4;

    /* font info*/
    pf->maxwidth = readshort(pf);
    pf->height = readshort(pf);
    pf->ascent = readshort(pf);
    pf->buffer_position += 2; /* Skip padding */
    pf->firstchar = readlong(pf);
    pf->defaultchar = readlong(pf);
    pf->size = readlong(pf);

    /* get variable font data sizes*/
    /* # words of bitmap_t*/
    pf->bits_size = readlong(pf);

    return pf;
}
예제 #2
0
파일: zcv.c 프로젝트: momtx/meataxe
void conv1213()
{
   long nper, i;
   long *buf;
   long kk = 0, f1, f2;

   MESSAGE(0,("Permutation on %d points\n",nor));
   buf = NALLOC(long,nor);
   if (buf == NULL) {
      MTX_ERROR("Cannot allocate permutation: %S");
      return;
   }
   WriteHeader(-fl,nor,noc);
   for (nper = noc; nper != 0; --nper) {
      for (i = 0; i < nor; ++i) {
         switch (mod) {
            case 12:
               kk = readlong();
               break;
            case 13:
               f1 = readlong();
               f2 = readlong();
               kk = (f1 - 1) * fl + f2 + 1;
               break;
         }
         buf[i] = kk;
      }
      if (SysWriteLong(out,buf,nor) != nor) {
         MTX_ERROR1("Cannot write %s: %S",outname);
      }
   }
}
예제 #3
0
/* Load cached font */
static struct font* font_load_cached(struct font* pf)
{
    uint32_t noffset, nwidth;
    unsigned char* oldfileptr = pf->buffer_position;

    if (!HAVEBYTES(2 * sizeof(int32_t)))
        return NULL;

    /* # longs of offset*/
    noffset = readlong(pf);

    /* # bytes of width*/
    nwidth = readlong(pf);

    /* We are now at the bitmap data, this is fixed at 36.. */
    pf->bits = NULL;

    /* Calculate offset to offset data */
    pf->buffer_position += pf->bits_size * sizeof(unsigned char);

    if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS)
    {
        pf->long_offset = 0;
        /* pad to 16-bit boundary */
        pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 1) & ~1);
    }
    else
    {
        pf->long_offset = 1;
        /* pad to 32-bit boundary*/
        pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 3) & ~3);
    }

    if (noffset)
        pf->file_offset_offset = (uint32_t)(pf->buffer_position - pf->buffer_start);
    else
        pf->file_offset_offset = 0;

    /* Calculate offset to widths data */
    if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS)
        pf->buffer_position += noffset * sizeof(uint16_t);
    else
        pf->buffer_position += noffset * sizeof(uint32_t);

    if (nwidth)
        pf->file_width_offset = (uint32_t)(pf->buffer_position - pf->buffer_start);
    else
        pf->file_width_offset = 0;

    pf->buffer_position = oldfileptr;

    /* Create the cache */
    cache_create(pf, pf->maxwidth, pf->height);

    return pf;
}
예제 #4
0
파일: object.c 프로젝트: YamaArashi/rgbds
void 
obj_ReadRGB1(FILE * pObjfile)
{
	struct sSection *pFirstSection;
	SLONG nNumberOfSymbols, nNumberOfSections, i;

	nNumberOfSymbols = readlong(pObjfile);
	nNumberOfSections = readlong(pObjfile);

	/* First comes the symbols */

	if (nNumberOfSymbols) {
		tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
		if (!tSymbols) {
			err(1, NULL);
		}

		for (i = 0; i < nNumberOfSymbols; i += 1)
			tSymbols[i] = obj_ReadSymbol(pObjfile);
	} else
		tSymbols = (struct sSymbol **) & dummymem;

	/* Next we have the sections */

	pFirstSection = NULL;
	while (nNumberOfSections--) {
		struct sSection *pNewSection;

		pNewSection = obj_ReadRGB1Section(pObjfile);
		pNewSection->nNumberOfSymbols = nNumberOfSymbols;
		if (pFirstSection == NULL)
			pFirstSection = pNewSection;
	}

	/*
	 * Fill in the pSection entry in the symbolstructure.
	 * This REALLY needs some cleaning up... but, hey, it works
	 *
	 */

	for (i = 0; i < nNumberOfSymbols; i += 1) {
		struct sSection *pConvSect = pFirstSection;

		if (tSymbols[i]->Type != SYM_IMPORT
		    && tSymbols[i]->nSectionID != -1) {
			SLONG j = 0;
			while (j != tSymbols[i]->nSectionID) {
				j += 1;
				pConvSect = pConvSect->pNext;
			}
			tSymbols[i]->pSection = pConvSect;
		} else
			tSymbols[i]->pSection = NULL;
	}
}
예제 #5
0
static void bit_savi2c_setsda(void *data, int val)
{
	unsigned int r;
	r = readlong();
	if(val)
		r |= I2C_SDA_OUT;
	else
		r &= ~I2C_SDA_OUT;
	outlong(r);
	readlong();	/* flush posted write */
}
예제 #6
0
파일: zcv.c 프로젝트: momtx/meataxe
static void ConvertPermutation()
{
   long i;
   long *buf;
   long kk;

   MESSAGE(0,("Permutation on %d points\n",nor));
   buf = NALLOC(long,nor);
   if (buf == NULL) {
      MTX_ERROR("Cannot allocate permutation: %S");
   }
   WriteHeader(-1,nor,1);

   for (i = 0; i < nor; ++i) {
      kk = readlong();
      buf[i] = kk - 1;
      if ((kk < 1) || (kk > nor)) {
         MTX_ERROR3("%s: Invalid point %d in permutation of degree %d",
                    inpname,(int)kk,nor);
      }
   }
   if (SysWriteLong(out,buf,nor) != nor) {
      MTX_ERROR1("Cannot write to %s",outname);
   }
}
예제 #7
0
static long readfile(int sock,FILE *f)
{
	int partition_id;
	if (!sendLong(sock, partition_id))
        return kReadFileFailure;
    long filesize;
    if (!readlong(sock, &filesize))
        return kReadFileFailure;
    if (filesize > 0)
    {
        char buffer[1024];
        do
        {
            int num = min(filesize, sizeof(buffer));
            if (!readdata(sock, buffer, num))
                return kReadFileFailure;
            int offset = 0;
            do
            {
                size_t written = fwrite(&buffer[offset], 1, num-offset, f);
                if (written < 1)
                    return kReadFileFailure;
                offset += written;
            }
            while (offset < num);
            filesize -= num;
        }
        while (filesize > 0);
    }
    return partition_id;
}
예제 #8
0
파일: read.c 프로젝트: UtahDave/iodine
END_TEST

START_TEST(test_read_putlong)
{
	uint32_t k;
	uint32_t l;
	char* p;
	int i;
	int j;

	for (i = 0; i < 32; i++) {
		p = (char*)&k;
		j = 0xf << i;

		putlong(&p, j);

		fail_unless(ntohl(k) == j,
				"Bad value on putlong for %d: %d != %d", i, ntohl(j), j);

		p = (char*)&k;
		readlong(NULL, &p, &l);

		fail_unless(l == j,
				"Bad value on readlong for %d: %d != %d", i, l, j);
	}
}
예제 #9
0
void readMidiFileHeader(FILE *fp, struct mhead *h)
{
    fread(h->chunktype, sizeof h->chunktype, 1, fp);
    h->length = readlong(fp);
    h->format = readshort(fp);
    h->ntrks = readshort(fp);
    h->division = readshort(fp);
}
예제 #10
0
파일: object.c 프로젝트: YamaArashi/rgbds
struct sSymbol *
obj_ReadSymbol(FILE * f)
{
	char s[256];
	struct sSymbol *pSym;

	pSym = malloc(sizeof *pSym);
	if (!pSym) {
		err(1, NULL);
	}

	readasciiz(s, f);
	pSym->pzName = malloc(strlen(s) + 1);
	if (!pSym->pzName) {
		err(1, NULL);
	}

	strcpy(pSym->pzName, s);
	if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
		pSym->nSectionID = readlong(f);
		pSym->nOffset = readlong(f);
	}
	return pSym;
}
예제 #11
0
파일: zcv.c 프로젝트: momtx/meataxe
static void ConvertIntMatrix()
{
   long i, j;
   long *x;

   MESSAGE(0,("%dx%d integer matrix\n",nor,noc));
   x = NALLOC(long,noc);
   WriteHeader(-8,nor,noc);         /* 8 = T_IMAT */
   for (i = 1; i <= nor; ++i) {
      for (j = 0; j < noc; ++j) {
         x[j] = readlong();
      }
      SysWriteLong(out,x,noc);
   }
   free(x);
}
예제 #12
0
파일: zcv.c 프로젝트: momtx/meataxe
static void ConvertPolynomial()
{
   long i;
   Poly_t *p;

   MESSAGE(0,("Polynomial of degree %d over GF(%d)\n",nor,fl));
   FfSetNoc(fl);
   p = PolAlloc(fl,nor);
   if ((out = SysFopen(outname,FM_CREATE)) == NULL) {
      MTX_ERROR1("Cannot open %s: %S",outname);
   }
   for (i = 0; i <= nor; ++i) {
      long kk = readlong();
      p->Data[i] = FfFromInt(kk);
   }
   PolWrite(p,out);
}
예제 #13
0
파일: zcv.c 프로젝트: momtx/meataxe
void convperm()
{
   long i, val;
   PTR m1;

   MESSAGE(0,("%dx%d permutation matrix over GF(%d)\n",nor,noc,fl));
   FfSetField(fl);
   FfSetNoc(noc);
   m1 = FfAlloc((long)1);
   WriteHeader(fl,nor,noc);
   for (i = 1; i <= nor; ++i) {
      val = readlong();
      FfMulRow(m1,FF_ZERO);
      FfInsert(m1,val - 1,FF_ONE);
      FfWriteRows(out,m1,1);
   }
}
int main()
{

    int n;
    n=readlong();
    int i,j;

    for(i=2; i<=100; i++)
    {
        number[0][i]=0;
    }

    for(i=1; i<=n; i++)
    {
        int a;
        a=readlong();
        for(j=1; j<=100; j++)
            number[i][j]=number[i-1][j];

        number[i][a]++;
    }

    int t;
    t=readlong();
    int l,r;
    long long MOD;
    while(t--)
    {
        l=readlong();
        r=readlong();
        MOD=readlong();


        long long ans=1;
        if(MOD==1)
            printf("%d\n",0);
        else
        {
            for(i=1; i<=100; i++)
            {
                if(number[r][i]-number[l-1][i])
                {
                    ans=ans*p(i,number[r][i]-number[l-1][i],MOD);
                    ans=ans%MOD;
                }
            }
            writeInt(ans);
        }
    }
    return 0;
}
예제 #15
0
파일: object.c 프로젝트: YamaArashi/rgbds
void 
lib_ReadXLB0(FILE * f)
{
	SLONG size;

	size = file_Length(f) - 4;
	while (size) {
		char name[256];

		size -= readasciiz(name, f);
		readword(f);
		size -= 2;
		readword(f);
		size -= 2;
		size -= readlong(f);
		size -= 4;
		obj_ReadOpenFile(f, name);
	}
}
예제 #16
0
파일: zcv.c 프로젝트: momtx/meataxe
static void ConvertMatrix()
{
   long i, j;
   PTR m1;
   long val;

   MESSAGE(0,("%dx%d matrix over GF(%d)\n",nor,noc,fl));
   FfSetField(fl);
   FfSetNoc(noc);
   m1 = FfAlloc((long)1);
   WriteHeader(fl,nor,noc);
   for (i = 1; i <= nor; ++i) {
      FfMulRow(m1,FF_ZERO);
      for (j = 0; j < noc; ++j) {
         val = readlong();
         FfInsert(m1,j,FfFromInt(val));
      }
      FfWriteRows(out,m1,1);
   }
}
int main()
{
	generate_hashmap();
	
	int n;
	n=readlong();
	int i,j;
	
	for(i=0;i<25;i++)
	{
		number[0][i]=0;
	}
	
	for(i=1;i<=n;i++)
	{
		int a;
		a=readlong();
		for(j=0;j<25;j++)
			number[i][j]=number[i-1][j]+hashmap[a][j];
	}
	
	int t;
	t=readlong();
	int l,r;
		long long MOD;
	while(t--)
	{
		l=readlong();
		r=readlong();
		MOD=readlong();
		
		
		long long ans=1;
		
		for(i=0;i<25;i++)
			{
				if(number[r][i]-number[l-1][i])
				{	
					ans=ans*p(prime[i],number[r][i]-number[l-1][i],MOD);
					ans=ans%MOD;
				}
			}
		writeInt(ans);
	}
	
	return 0;
}
예제 #18
0
void comp_fpp_opp (uae_u32 opcode, uae_u16 extra)
{
    int reg;
    int sreg, prec = 0;
    int	dreg = (extra >> 7) & 7;
    int source = (extra >> 13) & 7;
    int	opmode = extra & 0x7f;

    if (!currprefs.compfpu) {
		FAIL(1);
		return;
    }
    switch (source) {
	case 3: /* FMOVE FPx, <EA> */
		if (comp_fp_put(opcode,extra) < 0)
	    FAIL(1);
		return;
	case 4: /* FMOVE.L  <EA>, ControlReg */
		if (!(opcode & 0x30)) { /* Dn or An */
			if (extra & 0x1000) { /* FPCR */
		    	mov_l_mr((uae_u32)&regs.fpcr,opcode & 15);
#if USE_X86_FPUCW
		    	mov_l_rr(S1,opcode & 15);
		    	and_l_ri(S1,0xf0);
		    	fldcw_m_indexed(S1,(uae_u32)x86_fpucw);
#endif
				return;
			}
			if (extra & 0x0800) { /* FPSR */
				FAIL(1);
				return;
				// set_fpsr(m68k_dreg (regs, opcode & 15));
			}
			if (extra & 0x0400) { /* FPIAR */
				mov_l_mr((uae_u32)&regs.fpiar,opcode & 15); return;
			}
	}
	else if ((opcode & 0x3f) == 0x3c) {
			if (extra & 0x1000) { /* FPCR */
		    	uae_u32 val=comp_get_ilong((m68k_pc_offset+=4)-4);
		    	mov_l_mi((uae_u32)&regs.fpcr,val);
#if USE_X86_FPUCW
		    	mov_l_ri(S1,val&0xf0);
		    	fldcw_m_indexed(S1,(uae_u32)x86_fpucw);
#endif
				return;
			}
			if (extra & 0x0800) { /* FPSR */
			    FAIL(1);
			    return;
			}
			if (extra & 0x0400) { /* FPIAR */
				uae_u32 val=comp_get_ilong((m68k_pc_offset+=4)-4);
				mov_l_mi((uae_u32)&regs.fpiar,val);
				return;
			}
		}
		FAIL(1);
		return;
	case 5: /* FMOVE.L  ControlReg, <EA> */
		if (!(opcode & 0x30)) { /* Dn or An */
			if (extra & 0x1000) { /* FPCR */
				mov_l_rm(opcode & 15,(uae_u32)&regs.fpcr); return;
			}
			if (extra & 0x0800) { /* FPSR */
				FAIL(1);
				return;
			}
			if (extra & 0x0400) { /* FPIAR */
				mov_l_rm(opcode & 15,(uae_u32)&regs.fpiar); return;
			}
		}
		FAIL(1);
		return;
	case 6:
	case 7:
		{
	    uae_u32 list = 0;
	    int incr = 0;
	    if (extra & 0x2000) {
			uae_u32 ad;

			/* FMOVEM FPP->memory */
			switch ((extra >> 11) & 3) { /* Get out early if failure */
			case 0:
			case 2:
				break;
			case 1:
			case 3:
			default:
		    FAIL(1); return;
		}
		ad = comp_fp_adr (opcode);
		if (ad < 0) {
		    m68k_setpc (m68k_getpc () - 4);
		    op_illg (opcode);
		    return;
		}
		switch ((extra >> 11) & 3) {
		case 0:	/* static pred */
		    list = extra & 0xff;
		    incr = -1;
		    break;
		case 2:	/* static postinc */
		    list = extra & 0xff;
		    incr = 1;
		    break;
		case 1:	/* dynamic pred */
		case 3:	/* dynamic postinc */
		   abort();
		}
		if (incr < 0) { /* Predecrement */
			for (reg = 7; reg >= 0; reg--) {
				if (list & 0x80) {
					fmov_ext_mr((uintptr)temp_fp,reg);
					sub_l_ri(ad,4);
					mov_l_rm(S2,(uintptr)temp_fp);
					writelong_clobber(ad,S2,S3);
					sub_l_ri(ad,4);
					mov_l_rm(S2,(uintptr)temp_fp+4);
					writelong_clobber(ad,S2,S3);
					sub_l_ri(ad,4);
					mov_w_rm(S2,(uintptr)temp_fp+8);
					writeword_clobber(ad,S2,S3);
				}
				list <<= 1;
			}
		}
		else { /* Postincrement */
			for (reg = 0; reg <= 7; reg++) {
				if (list & 0x80) {
					fmov_ext_mr((uintptr)temp_fp,reg);
					mov_w_rm(S2,(uintptr)temp_fp+8);
					writeword_clobber(ad,S2,S3);
					add_l_ri(ad,4);
					mov_l_rm(S2,(uintptr)temp_fp+4);
					writelong_clobber(ad,S2,S3);
					add_l_ri(ad,4);
					mov_l_rm(S2,(uintptr)temp_fp);
					writelong_clobber(ad,S2,S3);
					add_l_ri(ad,4);
				}
				list <<= 1;
			}
		}
		if ((opcode & 0x38) == 0x18)
		    mov_l_rr((opcode & 7)+8,ad);
		if ((opcode & 0x38) == 0x20)
		    mov_l_rr((opcode & 7)+8,ad);
	    } else {
		/* FMOVEM memory->FPP */

		uae_u32 ad;
		switch ((extra >> 11) & 3) { /* Get out early if failure */
		case 0:
		case 2:
			break;
		case 1:
		case 3:
		default:
		    FAIL(1); return;
		}
		ad=comp_fp_adr (opcode);
		if (ad < 0) {
		    m68k_setpc (m68k_getpc () - 4);
		    op_illg (opcode);
		    return;
		}
		switch ((extra >> 11) & 3) {
		case 0:	/* static pred */
		    list = extra & 0xff;
		    incr = -1;
		    break;
		case 2:	/* static postinc */
		    list = extra & 0xff;
		    incr = 1;
		    break;
		case 1:	/* dynamic pred */
		case 3:	/* dynamic postinc */
			abort();
		}

		if (incr < 0) {
			// not reached
			for (reg = 7; reg >= 0; reg--) {
				if (list & 0x80) {
					sub_l_ri(ad,4);
					readlong(ad,S2,S3);
					mov_l_mr((uintptr)(temp_fp),S2);
					sub_l_ri(ad,4);
					readlong(ad,S2,S3);
					mov_l_mr((uintptr)(temp_fp)+4,S2);
					sub_l_ri(ad,4);
					readword(ad,S2,S3);
					mov_w_mr(((uintptr)temp_fp)+8,S2);
					fmov_ext_rm(reg,(uintptr)(temp_fp));
				}
				list <<= 1;
			}
		}
		else {
			for (reg = 0; reg <= 7; reg++) {
				if (list & 0x80) {
					readword(ad,S2,S3);
					mov_w_mr(((uintptr)temp_fp)+8,S2);
					add_l_ri(ad,4);
					readlong(ad,S2,S3);
					mov_l_mr((uintptr)(temp_fp)+4,S2);
					add_l_ri(ad,4);
					readlong(ad,S2,S3);
					mov_l_mr((uintptr)(temp_fp),S2);
					add_l_ri(ad,4);
					fmov_ext_rm(reg,(uintptr)(temp_fp));
				}
				list <<= 1;
			}
		}
		if ((opcode & 0x38) == 0x18)
		    mov_l_rr((opcode & 7)+8,ad);
		if ((opcode & 0x38) == 0x20)
		    mov_l_rr((opcode & 7)+8,ad);
	    }
	}
예제 #19
0
/* return the required floating point precision or -1 for failure, 0=E, 1=S, 2=D */
STATIC_INLINE int comp_fp_get (uae_u32 opcode, uae_u16 extra, int treg)
{
    int reg = opcode & 7;
    int mode = (opcode >> 3) & 7;
    int size = (extra >> 10) & 7;

    if (size == 3 || size == 7) /* 3 = packed decimal, 7 is not defined */
		return -1;
    switch (mode) {
	case 0: /* Dn */
		switch (size) {
		case 0: /* Long */
	    	mov_l_mr((uae_u32)temp_fp,reg);
	    	fmovi_rm(treg,(uae_u32)temp_fp);
	    	return 2;
		case 1: /* Single */
	    	mov_l_mr((uae_u32)temp_fp,reg);
	    	fmovs_rm(treg,(uae_u32)temp_fp);
	    	return 1;
		case 4: /* Word */
	    	sign_extend_16_rr(S1,reg);
	    	mov_l_mr((uae_u32)temp_fp,S1);
	    	fmovi_rm(treg,(uae_u32)temp_fp);
	    	return 1;
		case 6: /* Byte */
	    	sign_extend_8_rr(S1,reg);
	    	mov_l_mr((uae_u32)temp_fp,S1);
	    	fmovi_rm(treg,(uae_u32)temp_fp);
	    	return 1;
		default:
	    	return -1;
		}
	case 1: /* An,  invalid mode */
		return -1;
	case 2: /* (An) */
		mov_l_rr(S1,reg+8);
		break;
	case 3: /* (An)+ */
		mov_l_rr(S1,reg+8);
		lea_l_brr(reg+8,reg+8,(reg == 7?sz2[size]:sz1[size]));
		break;
	case 4: /* -(An) */
		lea_l_brr(reg+8,reg+8,-(reg == 7?sz2[size]:sz1[size]));
		mov_l_rr(S1,reg+8);
		break;
	case 5: /* (d16,An)  */
		{
		uae_u32 off=(uae_s32)(uae_s16)comp_get_iword((m68k_pc_offset+=2)-2);
		mov_l_rr(S1,reg+8);
		lea_l_brr(S1,S1,off);
		break;
		}
	case 6: /* (d8,An,Xn) or (bd,An,Xn) or ([bd,An,Xn],od) or ([bd,An],Xn,od) */
		{
		uae_u32 dp=comp_get_iword((m68k_pc_offset+=2)-2);
		calc_disp_ea_020(reg+8,dp,S1,S2);
		break;
     	}
	case 7:
		switch (reg) {
		case 0: /* (xxx).W */
	 		{
			uae_u32 off=(uae_s32)(uae_s16)comp_get_iword((m68k_pc_offset+=2)-2);
	     	mov_l_ri(S1,off);
	     	break;
	 		}
		case 1: /* (xxx).L */
			{
			uae_u32 off=comp_get_ilong((m68k_pc_offset+=4)-4);
			mov_l_ri(S1,off);
			break;
			}
		case 2: /* (d16,PC) */
			{
	     uae_u32 address=start_pc+((uae_char*)comp_pc_p-(uae_char*)start_pc_p)+
			m68k_pc_offset;
			uae_s32 PC16off =(uae_s32)(uae_s16)comp_get_iword((m68k_pc_offset+=2)-2);
			mov_l_ri(S1,address+PC16off);
			break;
			}
		case 3: /* (d8,PC,Xn) or (bd,PC,Xn) or ([bd,PC,Xn],od) or ([bd,PC],Xn,od) */
			return -1; /* rarely used, fallback to non-JIT */
		case 4: /* # < data >; Constants should be converted just once by the JIT */
			m68k_pc_offset+=sz2[size];
			switch (size) {
			case 0:
				{
		    	uae_s32 li = comp_get_ilong(m68k_pc_offset-4);
		    	float si = (float) li;

		    	if (li == (int) si) {
			//write_log (_T("converted immediate LONG constant to SINGLE\n"));
					fmovs_ri(treg,*(uae_u32 *)&si);
					return 1;
			    }
		    //write_log (_T("immediate LONG constant\n"));
		    	fmovl_ri(treg,li);
		    	return 2;
		  		}
			case 1:
		    //write_log (_T("immediate SINGLE constant\n"));
		    	fmovs_ri(treg,comp_get_ilong(m68k_pc_offset-4));
		    	return 1;
			case 2:
		    //write_log (_T("immediate LONG DOUBLE constant\n"));
		    	fmov_ext_ri(treg,comp_get_ilong(m68k_pc_offset-4),
				  comp_get_ilong(m68k_pc_offset-8),
				(comp_get_ilong(m68k_pc_offset-12)>>16)&0xffff);
	    		return 0;
			case 4:
				{
				float si = (float)(uae_s16)comp_get_iword(m68k_pc_offset-2);

		    //write_log (_T("converted immediate WORD constant to SINGLE\n"));
			    fmovs_ri(treg,*(uae_u32 *)&si);
			    return 1;
				}
			case 5:
				{
		    uae_u32 longarray[] = {comp_get_ilong(m68k_pc_offset-4),
					   comp_get_ilong(m68k_pc_offset-8)};
			    float si = (float)*(double *)longarray;

			    if (*(double *)longarray == (double)si) {
			//write_log (_T("SPEED GAIN: converted a DOUBLE constant to SINGLE\n"));
					fmovs_ri(treg,*(uae_u32 *)&si);
					return 1;
			    }
		    //write_log (_T("immediate DOUBLE constant\n"));
			    fmov_ri(treg,longarray[0],longarray[1]);
			    return 2;
			 }
			case 6:
		  		{
		    	float si = (float)(uae_s8)comp_get_ibyte(m68k_pc_offset-2);

		    //write_log (_T("immediate BYTE constant converted to SINGLE\n"));
			    fmovs_ri(treg,*(uae_u32 *)&si);
			    return 1;
			  }
			default: /* never reached */
			    return -1;
			}
		default: /* never reached */
			return -1;
		}
    }

    switch (size) {
	case 0: /* Long */
		readlong(S1,S2,S3);
		mov_l_mr((uae_u32)temp_fp,S2);
		fmovi_rm(treg,(uae_u32)temp_fp);
		return 2;
	case 1: /* Single */
		readlong(S1,S2,S3);
		mov_l_mr((uae_u32)temp_fp,S2);
		fmovs_rm(treg,(uae_u32)temp_fp);
		return 1;
	case 2: /* Long Double */
		readword(S1,S2,S3);
		mov_w_mr(((uae_u32)temp_fp)+8,S2);
		add_l_ri(S1,4);
		readlong(S1,S2,S3);
		mov_l_mr((uae_u32)(temp_fp)+4,S2);
		add_l_ri(S1,4);
		readlong(S1,S2,S3);
		mov_l_mr((uae_u32)(temp_fp),S2);
		fmov_ext_rm(treg,(uae_u32)(temp_fp));
	    return 0;
	case 4: /* Word */
		readword(S1,S2,S3);
		sign_extend_16_rr(S2,S2);
		mov_l_mr((uae_u32)temp_fp,S2);
		fmovi_rm(treg,(uae_u32)temp_fp);
		return 1;
	case 5: /* Double */
		readlong(S1,S2,S3);
		mov_l_mr(((uae_u32)temp_fp)+4,S2);
		add_l_ri(S1,4);
		readlong(S1,S2,S3);
		mov_l_mr((uae_u32)(temp_fp),S2);
		fmov_rm(treg,(uae_u32)(temp_fp));
		return 2;
	case 6: /* Byte */
		readbyte(S1,S2,S3);
		sign_extend_8_rr(S2,S2);
		mov_l_mr((uae_u32)temp_fp,S2);
		fmovi_rm(treg,(uae_u32)temp_fp);
		return 1;
	default:
		return -1;
    }
    return -1;
}
// ***********************************//
// ========= MAIN FUNCTION ========= //
// *********************************//
int main (int argc, char *argv[])
{
          
    // ***********************************//
    // ========== OPEN FILE ============ //
    // *********************************//
    unsigned char *f; // Store Whole File to Memory 
    unsigned char *fOrig;


    FILE *inFile, *outFile; 
    if(!(inFile = fopen (argv[1], "rb")))
    {
        printf("DOA5 Screenshot Converter\nBy: mario_kart64n\nDate: Sept 28 2012\n\nUsage: <Input> <Output>\n");
        return 1; 
    }

    if(!(outFile = fopen (argv[2], "wb")))
    { 
        printf("DOA5 Screenshot Converter\nBy: mario_kart64n\nDate: Sept 28 2012\n\nUsage: <Input> <Output>\n");
        return 2;
    }
    if(!(f=(unsigned char*) malloc(getfilesize (inFile))))
    { 
        printf("Not enough memory.\n"); 
        return(-1); 
    }
    if(!fread(f, 1, (getfilesize (inFile)), inFile))
    { 
        printf("Error reading file.\n"); 
        return(-1);
    }

    fOrig = f;

    // ***********************************//
    // ======== FILE OPERATION ========= //
    // *********************************//

    int cnt = 0;
    fseek(inFile, 0, SEEK_SET);
    fclose (inFile);

    f+=0xD010; // seek to texture data in the PIR
    int magic = readlong(f); 
    if (magic == 0x53584554)
    {
        f+=64;

        for (int i = 1; i-1 < 54; i++) 
        {
            fwrite(bmp_header+cnt, 1, 1, outFile);cnt+=1;	//Write BMP Header
        }

        for (int i = 0; i-1 < 230400; i++) { // 1280 x 0720 pixels
        cnt = ((untile_ARGB32_1280_0720b[i]-1)*4);

        fwrite(f+(cnt+3), 1, 1, outFile);	// Red
        fwrite(f+(cnt+2), 1, 1, outFile);	// Green
        fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

        cnt+=4;

        fwrite(f+(cnt+3), 1, 1, outFile);	// Red
        fwrite(f+(cnt+2), 1, 1, outFile);	// Green
        fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

        cnt+=4;

        fwrite(f+(cnt+3), 1, 1, outFile);	// Red
        fwrite(f+(cnt+2), 1, 1, outFile);	// Green
        fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

        cnt+=4;

        fwrite(f+(cnt+3), 1, 1, outFile);	// Red
        fwrite(f+(cnt+2), 1, 1, outFile);	// Green
        fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

        }
    } 
    else 
    {
        f+=0x1000;
        int magic = readlong(f); 
        if (magic == 0x53584554)
        {
            f+=64;

            for (int i = 1; i-1 < 54; i++)
            {
                fwrite(bmp_header+cnt, 1, 1, outFile);cnt+=1;	//Write BMP Header
            }

            for (int i = 0; i-1 < 230400; i++) { // 1280 x 0720 pixels
            cnt = ((untile_ARGB32_1280_0720c[i]-1)*4);

            fwrite(f+(cnt+3), 1, 1, outFile);	// Red
            fwrite(f+(cnt+2), 1, 1, outFile);	// Green
            fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

            cnt+=4;

            fwrite(f+(cnt+3), 1, 1, outFile);	// Red
            fwrite(f+(cnt+2), 1, 1, outFile);	// Green
            fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

            cnt+=4;

            fwrite(f+(cnt+3), 1, 1, outFile);	// Red
            fwrite(f+(cnt+2), 1, 1, outFile);	// Green
            fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

            cnt+=4;

            fwrite(f+(cnt+3), 1, 1, outFile);	// Red
            fwrite(f+(cnt+2), 1, 1, outFile);	// Green
            fwrite(f+(cnt+1), 1, 1, outFile);	// Blue

            }
        }
    }

    fclose(outFile);

    free(fOrig);
    return (0);
}
예제 #21
0
/* Load memory font */
static struct font* font_load_in_memory(struct font* pf)
{
    int32_t i, noffset, nwidth;

    if (!HAVEBYTES(4))
        return NULL;

    /* # longs of offset*/
    noffset = readlong(pf);

    /* # bytes of width*/
    nwidth = readlong(pf);

    /* variable font data*/
    pf->bits = (unsigned char *)pf->buffer_position;
    pf->buffer_position += pf->bits_size*sizeof(unsigned char);

    if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS)
    {
        /* pad to 16-bit boundary */
        pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 1) & ~1);
    }
    else
    {
        /* pad to 32-bit boundary*/
        pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 3) & ~3);
    }

    if (noffset)
    {
        if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS)
        {
            pf->long_offset = 0;
            pf->offset = (uint16_t*)pf->buffer_position;

            /* Check we have sufficient buffer */
            if (!HAVEBYTES(noffset * sizeof(uint16_t)))
                return NULL;

            for (i=0; i<noffset; ++i)
            {
                ((uint16_t*)(pf->offset))[i] = (uint16_t)readshort(pf);
            }
        }
        else
        {
            pf->long_offset = 1;
            pf->offset = (uint16_t*)pf->buffer_position;

            /* Check we have sufficient buffer */
            if (!HAVEBYTES(noffset * sizeof(int32_t)))
                return NULL;

            for (i=0; i<noffset; ++i)
            {
                ((uint32_t*)(pf->offset))[i] = (uint32_t)readlong(pf);
            }
        }
    }
    else
        pf->offset = NULL;

    if (nwidth) {
        pf->width = (unsigned char *)pf->buffer_position;
        pf->buffer_position += nwidth*sizeof(unsigned char);
    }
    else
        pf->width = NULL;

    if (pf->buffer_position > pf->buffer_end)
        return NULL;

    return pf;    /* success!*/
}
예제 #22
0
파일: dns.c 프로젝트: frekky/iodine
int
dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, size_t packetlen)
{
	char name[QUERY_NAME_SIZE];
	char rdata[4*1024];
	HEADER *header;
	short qdcount;
	short ancount;
	uint32_t ttl;
	unsigned short class;
	unsigned short type;
	char *data;
	unsigned short rlen;
	uint16_t id;
	int rv;

	rv = 0;
	header = (HEADER*)packet;

	/* Reject short packets */
	if (packetlen < sizeof(HEADER))
		return 0;

	if (header->qr != qr) {
		warnx("header->qr does not match the requested qr");
		return -1;
	}

	data = packet + sizeof(HEADER);
	qdcount = ntohs(header->qdcount);
	ancount = ntohs(header->ancount);

	id = ntohs(header->id);

	rlen = 0;

	if (q != NULL)
		q->rcode = header->rcode;

	switch (qr) {
	case QR_ANSWER:
		if(qdcount < 1) {
			/* We need a question */
			return -1;
		}

		if (q != NULL)
			q->id = id;

		/* Read name even if no answer, to give better error message */
		readname(packet, packetlen, &data, name, sizeof(name));
		CHECKLEN(4);
		readshort(packet, &data, &type);
		readshort(packet, &data, &class);

		/* if CHECKLEN okay, then we're sure to have a proper name */
		if (q != NULL) {
			/* We only need the first char to check it */
			q->name[0] = name[0];
			q->name[1] = '\0';
		}

		if (ancount < 1) {
			/* DNS errors like NXDOMAIN have ancount=0 and
			   stop here. CNAME may also have A; MX/SRV may have
			   multiple results. */
			return -1;
		}

		/* Here type is still the question type */
		if (type == T_NULL || type == T_PRIVATE) {
			/* Assume that first answer is what we wanted */
			readname(packet, packetlen, &data, name, sizeof(name));
			CHECKLEN(10);
			readshort(packet, &data, &type);
			readshort(packet, &data, &class);
			readlong(packet, &data, &ttl);
			readshort(packet, &data, &rlen);

			rv = MIN(rlen, sizeof(rdata));
			rv = readdata(packet, &data, rdata, rv);
			if (rv >= 2 && buf) {
				rv = MIN(rv, buflen);
				memcpy(buf, rdata, rv);
			} else {
				rv = 0;
			}
		}
		else if ((type == T_A || type == T_CNAME ||
예제 #23
0
void readMidiTrackHeader(FILE *fp, struct mtrack *t)
{
    fread(t->chunktype, sizeof t->chunktype, 1, fp);
    t->length = readlong(fp);
}
예제 #24
0
static int bit_savi2c_getsda(void *data)
{
	return (0 != (readlong() & I2C_SDA_IN));
}
예제 #25
0
void getoptions()
{
  /* interactively set options */
  long loopcount;
  Char ch;
  boolean done, gotopt;
  char input[100];

  how = arb;
  usertree = false;
  goteof = false;
  thresh = false;
  threshold = spp;
  weights = false;
  ancvar = false;
  factors = false;
  dollo = true;
  loopcount = 0;
  do {
    cleerhome();
    printf("\nInteractive Dollo or polymorphism parsimony,");
    printf(" version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  P                        Parsimony method?");
    printf("  %s\n",(dollo ? "Dollo" : "Polymorphism"));
    printf("  A                    Use ancestral states?  %s\n",
           ancvar ? "Yes" : "No");
    printf("  F                 Use factors information?  %s\n",
           factors ? "Yes" : "No");
    printf("  W                          Sites weighted?  %s\n",
           (weights ? "Yes" : "No"));
    printf("  T                 Use Threshold parsimony?");
    if (thresh)
      printf("  Yes, count steps up to%4.1f\n", threshold);
    else
      printf("  No, use ordinary parsimony\n");
    printf("  A      Use ancestral states in input file?");
    printf("  %s\n",(ancvar ? "Yes" : "No"));
    printf("  U Initial tree (arbitrary, user, specify)?");
    printf("  %s\n",(how == arb) ? "Arbitrary" :
                    (how == use) ? "User tree from tree file" :
                                   "Tree you specify");
    printf("  0      Graphics type (IBM PC, ANSI, none)?  %s\n",
           ibmpc ? "IBM PC" : ansi  ? "ANSI"   : "(none)");
    printf("  L               Number of lines on screen?%4ld\n",screenlines);
    printf("  S                Width of terminal screen?%4ld\n",screenwidth);
    printf(
      "\n\nAre these settings correct? (type Y or the letter for one to change)\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    getstryng(input);
    ch = input[0];
    uppercase(&ch);
    done = (ch == 'Y');
    gotopt = (strchr("SFTPULA0W",ch) != NULL) ? true : false;
    if (gotopt) {
      switch (ch) {

      case 'A':
        ancvar = !ancvar;
        break;

      case 'F':
        factors = !factors;
        break;

      case 'W':
        weights = !weights;
        break;
        
      case 'P':
        dollo = !dollo;
        break;

      case 'T':
        thresh = !thresh;
        if (thresh)
          initthreshold(&threshold);
        break;

      case 'U':
        if (how == arb)
          how = use;
        else if (how == use)
            how = spec;
          else
            how = arb;
        break;

      case '0':
        initterminal(&ibmpc, &ansi);
        break;

      case 'L':
        initnumlines(&screenlines);
        break;

      case 'S':
        screenwidth = readlong("Width of terminal screen (in characters)?\n");
      }
    }
    else  
      printf("Not a possible option!\n");
    countup(&loopcount, 100);
  } while (!done);
  if (scrollinc < screenwidth / 2.0)
    hscroll = scrollinc;
  else
    hscroll = screenwidth / 2;
  if (scrollinc < screenlines / 2.0)
    vscroll = scrollinc;
  else
    vscroll = screenlines / 2;
}  /* getoptions */
예제 #26
0
struct rtgui_font *fnt_font_create(const char* filename, const char* font_family)
{
	int fd = -1;
	rt_uint32_t index;
	struct rtgui_font *font = RT_NULL;
	struct fnt_font *fnt = RT_NULL;
	struct fnt_header *fnt_header;

	fd = open(filename, O_RDONLY, 0);
	if (fd < 0)
	{
		goto __exit;
	}

	font = (struct rtgui_font*) rtgui_malloc (sizeof(struct rtgui_font));
	if (font == RT_NULL) goto __exit;
	fnt = (struct fnt_font*) rtgui_malloc (sizeof(struct fnt_font));
	if (fnt == RT_NULL) goto __exit;
	rt_memset(fnt, 0x00, sizeof(struct fnt_font));
	font->data = (void*)fnt;

	fnt_header = &(fnt->header);
	if (readstr(fd, fnt_header->version, 4) != 4) goto __exit;
	if (!readshort(fd, &fnt_header->max_width)) goto __exit;
	if (!readshort(fd, &fnt_header->height)) goto __exit;
	if (!readshort(fd, &fnt_header->ascent)) goto __exit;
	if (!readshort(fd, &fnt_header->depth)) goto __exit;

	if (!readlong(fd, &fnt_header->first_char)) goto __exit;
	if (!readlong(fd, &fnt_header->default_char)) goto __exit;
	if (!readlong(fd, &fnt_header->size)) goto __exit;
	if (!readlong(fd, &fnt_header->nbits)) goto __exit;
	if (!readlong(fd, &fnt_header->noffset)) goto __exit;
	if (!readlong(fd, &fnt_header->nwidth)) goto __exit;

	fnt->bits = (MWIMAGEBITS*) rtgui_malloc (fnt_header->nbits * sizeof(MWIMAGEBITS));
	if (fnt->bits == RT_NULL) goto __exit;
	/* read data */
	if (readstr(fd, &(fnt->bits[0]), fnt_header->nbits) != fnt_header->nbits) goto __exit;

	/* check boundary */
	if (fnt_header->nbits & 0x01)
	{
		rt_uint16_t pad;
		readshort(fd, &pad);
		pad = pad; /* skip warning */
	}
	
	if (fnt_header->noffset != 0)
	{
		fnt->offset = rtgui_malloc (fnt_header->noffset * sizeof(rt_uint32_t));
		if (fnt->offset == RT_NULL) goto __exit;

		for (index = 0; index < fnt_header->noffset; index ++)
		{
			if (!readshort(fd, &(fnt->offset[index]))) goto __exit;
		}
	}

	if (fnt_header->nwidth != 0)
	{
		fnt->width = rtgui_malloc (fnt_header->nwidth * sizeof(rt_uint8_t));
		if (fnt->width == RT_NULL) goto __exit;

		for (index = 0; index < fnt_header->nwidth; index ++)
		{
			if (!readbyte(fd, &(fnt->width[index]))) goto __exit;
		}
	}

	close(fd);

	font->family = rt_strdup(font_family);
	font->height = fnt->header.height;
	font->refer_count = 0;
	font->engine = &fnt_font_engine;
	
	/* add to system */
	rtgui_font_system_add_font(font);

	return font;

__exit:
	if (fd >= 0) close(fd);
	if (fnt != RT_NULL)
	{
		if (fnt->bits != RT_NULL) rtgui_free(fnt->bits);
		if (fnt->offset != RT_NULL) rtgui_free(fnt->offset);
		if (fnt->width != RT_NULL) rtgui_free(fnt->width);

		rtgui_free(fnt);
	}

	if (font != RT_NULL)
	{
		rtgui_free(font);
	}
	return RT_NULL;
}
예제 #27
0
파일: db.c 프로젝트: po1vo/aide
db_line* db_char2line(char** ss,int db){

  int i;
  db_line* line=(db_line*)malloc(sizeof(db_line)*1);
  int* db_osize=0;
  DB_FIELD** db_order=NULL;

  switch (db) {
  case DB_OLD: {
    db_osize=&(conf->db_in_size);
    db_order=&(conf->db_in_order);
    break;
  }
  case DB_NEW: {
    db_osize=&(conf->db_new_size);
    db_order=&(conf->db_new_order);
    break;
  }
  }


  line->md5=NULL;
  line->sha1=NULL;
  line->rmd160=NULL;
  line->tiger=NULL;

  line->crc32=NULL; /* MHASH stuff.. */
  line->crc32b=NULL;
  line->haval=NULL;
  line->gost=NULL;
  line->whirlpool=NULL;
  
  line->sha256=NULL;
  line->sha512=NULL;
  line->perm=0;
  line->uid=0;
  line->gid=0;
  line->atime=0;
  line->ctime=0;
  line->mtime=0;
  line->inode=0;
  line->nlink=0;
  line->bcount=0;
  line->size=0;
  line->filename=NULL;
  line->fullpath=NULL;
  line->linkname=NULL;
  line->acl=NULL;
  line->xattrs=NULL;
  line->e2fsattrs=0;
  line->cntx=NULL;
  
  line->attr=conf->attr; /* attributes from @@dbspec */

  for(i=0;i<*db_osize;i++){
    switch ((*db_order)[i]) {
    case db_filename : {
      if(ss[(*db_order)[i]]!=NULL){
	decode_string(ss[(*db_order)[i]]);
	line->fullpath=strdup(ss[(*db_order)[i]]);
	line->filename=line->fullpath;
      } else {
	error(0,"db_char2line():Error while reading database\n");
	exit(EXIT_FAILURE);
      }
      break;
    }
    case db_linkname : {
      line->linkname = db_readchar(ss[(*db_order)[i]]);
      break;
    }
    case db_mtime : {
      line->mtime=base64totime_t(ss[(*db_order)[i]]);
      break;
    }
    case db_bcount : {
      line->bcount=readint(ss[(*db_order)[i]],"bcount");
      break;
    }
    case db_atime : {
      line->atime=base64totime_t(ss[(*db_order)[i]]);
      break;
    }
    case db_ctime : {
      line->ctime=base64totime_t(ss[(*db_order)[i]]);
      break;
    }
    case db_inode : {
      line->inode=readint(ss[(*db_order)[i]],"inode");
      break;
    }

    case db_uid : {
      line->uid=readint(ss[(*db_order)[i]],"uid");
      break;
    }
    case db_gid : {
      line->gid=readint(ss[(*db_order)[i]],"gid");
      break;
    }
    case db_size : {
      line->size=readlong(ss[(*db_order)[i]],"size");
      break;
    }
    case db_md5 : {
      line->md5=base64tobyte(ss[(*db_order)[i]],
			     strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_sha1 : {
      line->sha1=base64tobyte(ss[(*db_order)[i]],
			      strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_rmd160 : {
      line->rmd160=base64tobyte(ss[(*db_order)[i]],
				strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_tiger : {
      line->tiger=base64tobyte(ss[(*db_order)[i]],
			       strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
#ifdef WITH_MHASH
    case db_crc32 : {
      line->crc32=base64tobyte(ss[(*db_order)[i]],
			       strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_haval : {
      line->haval=base64tobyte(ss[(*db_order)[i]],
			       strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_gost : {
      line->gost=base64tobyte(ss[(*db_order)[i]],
			       strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_crc32b : {
      line->crc32b=base64tobyte(ss[(*db_order)[i]],
			       strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_whirlpool : {
      line->whirlpool=base64tobyte(ss[(*db_order)[i]],
                                   strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
#else
      WARN_ONCE(gost);
      WARN_ONCE(crc32b);
      WARN_ONCE(whirlpool);
#endif
    case db_sha256 : {
      line->sha256=base64tobyte(ss[(*db_order)[i]],
                                strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
    case db_sha512 : {
      line->sha512=base64tobyte(ss[(*db_order)[i]],
                                strlen(ss[(*db_order)[i]]), NULL);
      break;
    }
#ifdef WITH_SUN_ACL
    case db_acl : {
      char* endp,*pos;
      int entries,lc;
      line->acl=NULL;
      
      entries=strtol(ss[(*db_order)[i]],&endp,10);
      if (endp==ss[(*db_order)[i]]) {
 	/* Something went wrong */
	break;
      }
      pos=endp+1; /* Warning! if acl in database is corrupted then
		     this will break down. */
      
      line->acl=malloc(sizeof(acl_type));
      line->acl->entries=entries;
      line->acl->acl=malloc(sizeof(aclent_t)*entries);
      for (lc=0;lc<entries;lc++) {
	line->acl->acl[lc].a_type=strtol(pos,&endp,10);
	pos=endp+1;
	line->acl->acl[lc].a_id=strtol(pos,&endp,10);
	pos=endp+1;
	line->acl->acl[lc].a_perm=strtol(pos,&endp,10);
	pos=endp+1;
      }
      break;
    }
#endif
#ifdef WITH_POSIX_ACL
    case db_acl : {
      char *tval = NULL;
      
      tval = strtok(ss[(*db_order)[i]], ",");

      line->acl = NULL;

      if (tval[0] == '0')
        line->acl = NULL;
      else if (!strcmp(tval, "POSIX"))
      {
        line->acl = malloc(sizeof(acl_type));        
        line->acl->acl_a = NULL;
        line->acl->acl_d = NULL;
        
        tval = strtok(NULL, ",");
        line->acl->acl_a = (char *)base64tobyte(tval, strlen(tval), NULL);
        tval = strtok(NULL, ",");
        line->acl->acl_d = (char *)base64tobyte(tval, strlen(tval), NULL);
      }
      /* else, it's broken... */
      break;
    }
#endif
      case db_xattrs : {
        size_t num = 0;
        char *tval = NULL;
        
        tval = strtok(ss[(*db_order)[i]], ",");
        num = readlong(tval, "xattrs");
        if (num)
        {
          line->xattrs = malloc(sizeof(xattrs_type));
          line->xattrs->ents = calloc(sizeof(xattr_node), num);
          line->xattrs->sz  = num;
          line->xattrs->num = num;
          num = 0;
          while (num < line->xattrs->num)
          {
            byte  *val = NULL;
            size_t vsz = 0;
            
            tval = strtok(NULL, ",");
            line->xattrs->ents[num].key = db_readchar(strdup(tval));
            tval = strtok(NULL, ",");
            val = base64tobyte(tval, strlen(tval), &vsz);
            line->xattrs->ents[num].val = val;
            line->xattrs->ents[num].vsz = vsz;

            ++num;
          }
        }
        break;
      }

      case db_selinux : {
        byte  *val = NULL;
        
        val = base64tobyte(ss[(*db_order)[i]], strlen(ss[(*db_order)[i]]),NULL);
        line->cntx = (char *)val;
        break;
      }
      
    case db_perm : {
      line->perm=readoct(ss[(*db_order)[i]],"permissions");
      break;
    }
    
    case db_lnkcount : {
      line->nlink=readint(ss[(*db_order)[i]],"nlink");
      break;
    }

    case db_attr : {
      line->attr=readlong(ss[(*db_order)[i]],"attr");
      break;
    }
    
    case db_e2fsattrs : {
      line->e2fsattrs=readlong(ss[(*db_order)[i]],"e2fsattrs");
      break;
    }

    case db_unknown : {
      /* Unknown fields are ignored. */
      break;
    }
    
    default : {
      error(0,_("Not implemented in db_char2line %i \n"),(*db_order)[i]);
      return NULL;
    }
    
    }
    
  }

  return line;
}
예제 #28
0
파일: object.c 프로젝트: YamaArashi/rgbds
struct sSection *
obj_ReadRGB1Section(FILE * f)
{
	struct sSection *pSection;

	pSection = AllocSection();

	pSection->nByteSize = readlong(f);
	pSection->Type = (enum eSectionType) fgetc(f);
	/*
	 * And because of THIS new feature I'll have to rewrite loads and
	 * loads of stuff... oh well it needed to be done anyway
	 *
	 */
	pSection->nOrg = readlong(f);
	pSection->nBank = readlong(f);

	/* does the user want the -s mode? */

	if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) {
		pSection->Type = SECT_ROM0;
	}
	if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
		/*
		 * These sectiontypes contain data...
		 *
		 */
		if (pSection->nByteSize) {
			pSection->pData = malloc(pSection->nByteSize);
			if (!pSection->pData) {
				err(1, NULL);
			}

			SLONG nNumberOfPatches;
			struct sPatch **ppPatch, *pPatch;
			char s[256];

			fread(pSection->pData, sizeof(UBYTE),
			    pSection->nByteSize, f);
			nNumberOfPatches = readlong(f);
			ppPatch = &pSection->pPatches;

			/*
			 * And patches...
			 *
			 */
			while (nNumberOfPatches--) {
				pPatch = malloc(sizeof *pPatch);
				if (!pPatch) {
					err(1, NULL);
				}

				*ppPatch = pPatch;
				readasciiz(s, f);
				pPatch->pzFilename = malloc(strlen(s) + 1);
				if (!pPatch->pzFilename) {
					err(1, NULL);
				}

				strcpy(pPatch->pzFilename, s);
				pPatch->nLineNo = readlong(f);
				pPatch->nOffset = readlong(f);
				pPatch->Type = (enum ePatchType) fgetc(f);
				if ((pPatch->nRPNSize = readlong(f)) > 0) {
					pPatch->pRPN = malloc(pPatch->nRPNSize);
					if (!pPatch->pRPN) {
						err(1, NULL);
					}

					fread(pPatch->pRPN, sizeof(UBYTE),
					    pPatch->nRPNSize, f);
				} else
					pPatch->pRPN = NULL;

				pPatch->pNext = NULL;
				ppPatch = &(pPatch->pNext);
			}
		} else {
			/* Skip number of patches */
			readlong(f);
			pSection->pData = &dummymem;
		}
	}
	return pSection;
}