转换.C到的.java [英] Convert .c to .java
本文介绍了转换.C到的.java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到C code转换成Java code的任何工具?我感兴趣的是这个转换code到Java:
************ ********* /
/ *
** UNECM - 德codeR的ECM(错误code建模)格式。
** 1.0版
**版权所有(C)2002尼尔科利特
**
**这个程序是免费软件;您可以重新分配和/或
**修改它在GNU通用公共许可证的条款
**由自由软件基金会发布;任一版本2
**的许可证,或(由你选择)任何更新的版本。
**
**这个程序是分布在希望这将是有益的,
**但没有任何担保;甚至没有的隐含担保
**适销性或适用于特定用途。查看
** GNU通用公共许可证的更多细节。
**
**你应该已经收到了GNU通用公共许可证的副本
**和程序一起;如果没有,请写信给自由软件
**基金公司,59庙广场 - 套房330,马萨诸塞州波士顿02111-1307,USA。
* /
/ ******************* ************ /
/ *
**便携笔记:
**
** - 假设一个32位或更高的整数大小
** - 关于字节顺序没有假设
** - 关于结构包装没有假设
** - 未对齐的内存访问
* /
/ ******************* ************ /#包括LT&;&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT;/ ******************* ************ /无效的旗帜(无效){
fprintf中(标准错误,
UNECM - 德codeR为错误code建模格式V1.0 \\ n
版权所有(C)2002年奥尼尔克里特\\ n \\ n
);
}/ ******************* ************ // *数据类型* /
#定义ecc_uint8 unsigned char型
#定义ecc_uint16无符号短
#定义ecc_uint32无符号/ *用于计算的LUT ECC / EDC * /
静态ecc_uint8 ecc_f_lut [256];
静态ecc_uint8 ecc_b_lut [256];
静态ecc_uint32 edc_lut [256];/ *初始化程序* /
静态无效eccedc_init(无效){
ecc_uint32 I,J,EDC;
对于(i = 0; I< 256;我++){
J =(I&所述;&。1)^(I和0x80的0x11D:0);
ecc_f_lut [I] = j的;
ecc_b_lut [I ^ J] =我;
EDC = I;
为(J = 0; J&下; 8; J ++)EDC =(EDC>→1)^(EDC&放大器; 1 0xD8018001:0);
edc_lut [I] = EDC;
}
}/ ******************* ************ /
/ *
**计算EDC为块
* /
ecc_uint32 edc_partial_computeblock(
ecc_uint32 EDC,
常量ecc_uint8 * SRC,
ecc_uint16大小
){
而(size--)EDC =(EDC>→8)^ edc_lut [(EDC ^(* SRC ++))及为0xFF];
返回EDC;
}无效edc_computeblock(
常量ecc_uint8 * SRC,
ecc_uint16大小,
ecc_uint8 * DEST
){
ecc_uint32 EDC = edc_partial_computeblock(0,SRC,大小);
DEST [0] =(EDC>大于0)及0xFF的;
DEST [1] =(EDC>→8)及0xFF的;
DEST [2] =(EDC>> 16)及0xFF的;
DEST [3] =(EDC>> 24)及0xFF的;
}/ ******************* ************ /
/ *
**计算的ECC块(可以做P或Q)
* /
静态无效ecc_computeblock(
ecc_uint8 * SRC,
ecc_uint32 major_count,
ecc_uint32 minor_count,
ecc_uint32 major_mult,
ecc_uint32 minor_inc,
ecc_uint8 * DEST
){
ecc_uint32大小= major_count * minor_count;
ecc_uint32主要,次要;
针对(主要= 0;&主要LT; major_count;主要++){
ecc_uint32指数=(主要与GT;→1)* major_mult +(主要与放大器; 1);
ecc_uint8 ecc_a = 0;
ecc_uint8 ecc_b = 0;
对于(次要= 0;&轻微LT; minor_count;次要++){
ecc_uint8 TEMP = SRC [指数]
指数+ = minor_inc;
如果(索引> =大小)指数 - =大小;
ecc_a ^ =温度;
ecc_b ^ =温度;
ecc_a = ecc_f_lut [ecc_a]
}
ecc_a = ecc_b_lut [ecc_f_lut [ecc_a] ^ ecc_b]
DEST [大] = ecc_a;
DEST [大+ major_count] = ecc_a ^ ecc_b;
}
}/ *
**生成ECC P和Q codeS为块
* /
静态无效ecc_generate(
ecc_uint8 *行业,
INT zeroaddress
){
ecc_uint8地址[4],I;
/ *保存的地址和零出来* /
如果(zeroaddress)为(I = 0; I&下; 4;我++){
解决由[i] =扇区12 + I];
扇区12 + I] = 0;
}
/ *计算ECC P code * /
ecc_computeblock(部门+ 0xC的,86,24,2,86,部门+ 0x81C);
/ *计算ECC Q code * /
ecc_computeblock(部门+ 0xC的,52,43,86,88,部门+ 0x8C8);
/ *恢复地址* /
如果(zeroaddress)为(I = 0; I&下; 4; i ++在)扇区12 + I] =地址[I];
}/ ******************* ************ /
/ *
**生成一个部门ECC / EDC信息(必须是2352 = 0x930字节)
**成功则返回0
* /
无效eccedc_generate(ecc_uint8 *行业,整型){
ecc_uint32我;
开关(类型){
案例1:/ *模式1 * /
/ *计算EDC * /
edc_computeblock(部门+ 0×00,0x810,部门+ 0x810);
/ *写出来零字节* /
对于(I = 0; I&下; 8;我++)扇区0x814 + I] = 0;
/ *生成ECC P / Q- codeS * /
ecc_generate(扇区,0);
打破;
案例2:/ *模式2表格1 * /
/ *计算EDC * /
edc_computeblock(部门+ 0×10,0x808,部门+ 0x818);
/ *生成ECC P / Q- codeS * /
ecc_generate(扇区,1);
打破;
案例3:/ *模式2形式2 * /
/ *计算EDC * /
edc_computeblock(部门+ 0×10,0x91C,部门+ 0x92C);
打破;
}
}/ ******************* ************ /无符号mycounter;
无符号mycounter_total;无效resetcounter(未签名的总计){
mycounter = 0;
mycounter_total =总;
}无效setcounter(无符号N){
如果((N GT;>!20)=(mycounter>→20)){
一个无符号=(N + 64)/ 128;
无符号D =(mycounter_total + 64)/ 128;
如果(!D)D = 1;
fprintf中(标准错误,解码(%02D %%)\\ r,即(100 * A)/天);
}
mycounter = N;
}诠释unecmify(
FILE *中,
FILE *出
){
无符号checkedc = 0;
unsigned char型行业[2352];
无符号类型;
无符号NUM;
fseek的(在,0,SEEK_END);
resetcounter(FTELL(在));
fseek的(在,0,SEEK_SET);
如果(
(龟etc(中)!='E')||
(龟etc(中)!='C')||
(龟etc(在)!='M')||
(龟etc(中)!= 0×00)
){
fprintf中(标准错误,页眉没有找到\\ n!);
转到腐败;
}
为(;;){
INT C =龟etc(中);
INT位= 5;
如果(C == EOF)转到uneof;
键入= C&放大器; 3;
NUM =(c取代;→2)及0x1F的;
而(C&安培; 0x80的){
C =龟etc(中);
如果(C == EOF)转到uneof;
NUM | =((符号)(C&安培; 0x7F的))≤;<位;
位+ = 7;
}
如果(NUM == 0xFFFFFFFF的)破;
NUM ++;
如果(NUM> =为0x80000000)转到腐败;
如果(!型){
而(NUM){
INT B = NUM;
如果(B> 2352)B = 2352;
如果(FREAD(部门,1,B,IN)= B!)转到uneof;
checkedc = edc_partial_computeblock(checkedc,部门,B);
FWRITE(部门,1,B,退出);
NUM - = B;
setcounter(FTELL(在));
}
}其他{
而(num--){
memset的(部门,0,sizeof的(部门));
memset的(扇区+ 1,为0xFF,10);
开关(类型){
情况1:
部门[为0x0F] = 0×01;
如果(FREAD(部门+量0x00C,1,0x003中)= 0x003!)转到uneof;
如果(FREAD(部门+量0x010,1,为0x800中)= 0x800开始!)转到uneof;
eccedc_generate(扇区,1);
checkedc = edc_partial_computeblock(checkedc,部门,2352);
FWRITE(部门,2352,1,出);
setcounter(FTELL(在));
打破;
案例2:
部门[为0x0F] = 0×02;
如果(FREAD(部门+量0x014,1,0x804中)= 0x804!)转到uneof;
部门[0×10] =部门[0×14];
部门[0×11 =扇区为0x15]
部门[0×12] =部门[0x16]
部门[0x13] =部门[0x17已]
eccedc_generate(扇区,2);
checkedc = edc_partial_computeblock(checkedc,部门+ 0×10,2336);
FWRITE(部门+ 0×10,2336,1,出);
setcounter(FTELL(在));
打破;
案例3:
部门[为0x0F] = 0×02;
如果(FREAD(部门+量0x014,1,0x918中)= 0x918!)转到uneof;
部门[0×10] =部门[0×14];
部门[0×11 =扇区为0x15]
部门[0×12] =部门[0x16]
部门[0x13] =部门[0x17已]
eccedc_generate(扇区,3);
checkedc = edc_partial_computeblock(checkedc,部门+ 0×10,2336);
FWRITE(部门+ 0×10,2336,1,出);
setcounter(FTELL(在));
打破;
}
}
}
}
如果(的fread(扇区,1,4,)= 4!)转到uneof;
fprintf中(标准错误,德codeD%ld位元组 - >%ld位元组\\ n,FTELL(中),FTELL(出));
如果(
(扇区[0] =((checkedc>!大于0)及为0xFF))||
(扇区[1] =((checkedc>!→8)及为0xFF))||
(扇区[2] =((checkedc>!> 16)及为0xFF))||
(扇区[3] =((checkedc>!> 24)及为0xFF))
){
fprintf中(标准错误,EDC错误(%08X,应该%02X%02X%02X%02X)\\ n
checkedc,
扇区[3],
扇区[2],
扇区[1],
扇区0]
);
转到腐败;
}
fprintf中(标准错误,完成,文件就OK \\ n);
返回0;
uneof:
fprintf中(标准错误,意外的EOF \\ n!);
腐败:
fprintf中(标准错误,损坏ECM档案\\ n!);
返回1;
}/ ******************* ************ /INT主(INT ARGC,字符** argv的){
FILE *翅,* FOUT;
字符* infilename;
字符* outfilename;
旗帜();
/ *
**初始化ECC / EDC表
* /
eccedc_init();
/ *
**检查命令行
* /
如果((argc个= 2)及!&放大器;!(的argc = 3)){
fprintf中(标准错误,用法:%s的ecmfile [OUTPUTFILE] \\ N的argv [0]);
返回1;
}
/ *
**确认输入文件名是有效的
* /
infilename =的argv [1];
如果(strlen的(infilename)小于5){
fprintf中(标准错误,文件名%s的太短\\ n,infilename);
返回1;
}
如果(strcasecmp(infilename +的strlen(infilename) - 4,.ecm)){
fprintf中(标准错误文件名必须.ecm \\ n结束);
返回1;
}
/ *
**找出输出文件名应该是什么
* /
如果(的argc == 3){
outfilename =的argv [2];
}其他{
outfilename =的malloc(strlen的(infilename) - 3);
如果(!outfilename)中止();
的memcpy(outfilename,infilename,strlen的(infilename) - 4);
outfilename [strlen的(infilename) - 4] = 0;
}
fprintf中(标准错误,解码%s到%s \\ n,infilename,outfilename);
/ *
**打开这两个文件
* /
鳍=的fopen(infilename,RB);
如果(!翅){
PERROR(infilename);
返回1;
}
FOUT = FOPEN(outfilename,WB);
如果(!FOUT){
PERROR(outfilename);
FCLOSE(翅);
返回1;
}
/ *
**德code
* /
unecmify(FIN,FOUT);
/ *
**关闭一切
* /
FCLOSE(FOUT);
FCLOSE(翅);
返回0;
}
解决方案
你有没有使用 JNI ,而不是做烦心事考虑翻译从C到Java?
Any tools to convert C code into Java code? I am interested in converting this code into Java:
***************************************************************************/
/*
** UNECM - Decoder for ECM (Error Code Modeler) format.
** Version 1.0
** Copyright (C) 2002 Neill Corlett
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/***************************************************************************/
/*
** Portability notes:
**
** - Assumes a 32-bit or higher integer size
** - No assumptions about byte order
** - No assumptions about struct packing
** - No unaligned memory access
*/
/***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/***************************************************************************/
void banner(void) {
fprintf(stderr,
"UNECM - Decoder for Error Code Modeler format v1.0\n"
"Copyright (C) 2002 Neill Corlett\n\n"
);
}
/***************************************************************************/
/* Data types */
#define ecc_uint8 unsigned char
#define ecc_uint16 unsigned short
#define ecc_uint32 unsigned
/* LUTs used for computing ECC/EDC */
static ecc_uint8 ecc_f_lut[256];
static ecc_uint8 ecc_b_lut[256];
static ecc_uint32 edc_lut[256];
/* Init routine */
static void eccedc_init(void) {
ecc_uint32 i, j, edc;
for(i = 0; i < 256; i++) {
j = (i << 1) ^ (i & 0x80 ? 0x11D : 0);
ecc_f_lut[i] = j;
ecc_b_lut[i ^ j] = i;
edc = i;
for(j = 0; j < 8; j++) edc = (edc >> 1) ^ (edc & 1 ? 0xD8018001 : 0);
edc_lut[i] = edc;
}
}
/***************************************************************************/
/*
** Compute EDC for a block
*/
ecc_uint32 edc_partial_computeblock(
ecc_uint32 edc,
const ecc_uint8 *src,
ecc_uint16 size
) {
while(size--) edc = (edc >> 8) ^ edc_lut[(edc ^ (*src++)) & 0xFF];
return edc;
}
void edc_computeblock(
const ecc_uint8 *src,
ecc_uint16 size,
ecc_uint8 *dest
) {
ecc_uint32 edc = edc_partial_computeblock(0, src, size);
dest[0] = (edc >> 0) & 0xFF;
dest[1] = (edc >> 8) & 0xFF;
dest[2] = (edc >> 16) & 0xFF;
dest[3] = (edc >> 24) & 0xFF;
}
/***************************************************************************/
/*
** Compute ECC for a block (can do either P or Q)
*/
static void ecc_computeblock(
ecc_uint8 *src,
ecc_uint32 major_count,
ecc_uint32 minor_count,
ecc_uint32 major_mult,
ecc_uint32 minor_inc,
ecc_uint8 *dest
) {
ecc_uint32 size = major_count * minor_count;
ecc_uint32 major, minor;
for(major = 0; major < major_count; major++) {
ecc_uint32 index = (major >> 1) * major_mult + (major & 1);
ecc_uint8 ecc_a = 0;
ecc_uint8 ecc_b = 0;
for(minor = 0; minor < minor_count; minor++) {
ecc_uint8 temp = src[index];
index += minor_inc;
if(index >= size) index -= size;
ecc_a ^= temp;
ecc_b ^= temp;
ecc_a = ecc_f_lut[ecc_a];
}
ecc_a = ecc_b_lut[ecc_f_lut[ecc_a] ^ ecc_b];
dest[major ] = ecc_a;
dest[major + major_count] = ecc_a ^ ecc_b;
}
}
/*
** Generate ECC P and Q codes for a block
*/
static void ecc_generate(
ecc_uint8 *sector,
int zeroaddress
) {
ecc_uint8 address[4], i;
/* Save the address and zero it out */
if(zeroaddress) for(i = 0; i < 4; i++) {
address[i] = sector[12 + i];
sector[12 + i] = 0;
}
/* Compute ECC P code */
ecc_computeblock(sector + 0xC, 86, 24, 2, 86, sector + 0x81C);
/* Compute ECC Q code */
ecc_computeblock(sector + 0xC, 52, 43, 86, 88, sector + 0x8C8);
/* Restore the address */
if(zeroaddress) for(i = 0; i < 4; i++) sector[12 + i] = address[i];
}
/***************************************************************************/
/*
** Generate ECC/EDC information for a sector (must be 2352 = 0x930 bytes)
** Returns 0 on success
*/
void eccedc_generate(ecc_uint8 *sector, int type) {
ecc_uint32 i;
switch(type) {
case 1: /* Mode 1 */
/* Compute EDC */
edc_computeblock(sector + 0x00, 0x810, sector + 0x810);
/* Write out zero bytes */
for(i = 0; i < 8; i++) sector[0x814 + i] = 0;
/* Generate ECC P/Q codes */
ecc_generate(sector, 0);
break;
case 2: /* Mode 2 form 1 */
/* Compute EDC */
edc_computeblock(sector + 0x10, 0x808, sector + 0x818);
/* Generate ECC P/Q codes */
ecc_generate(sector, 1);
break;
case 3: /* Mode 2 form 2 */
/* Compute EDC */
edc_computeblock(sector + 0x10, 0x91C, sector + 0x92C);
break;
}
}
/***************************************************************************/
unsigned mycounter;
unsigned mycounter_total;
void resetcounter(unsigned total) {
mycounter = 0;
mycounter_total = total;
}
void setcounter(unsigned n) {
if((n >> 20) != (mycounter >> 20)) {
unsigned a = (n+64)/128;
unsigned d = (mycounter_total+64)/128;
if(!d) d = 1;
fprintf(stderr, "Decoding (%02d%%)\r", (100*a) / d);
}
mycounter = n;
}
int unecmify(
FILE *in,
FILE *out
) {
unsigned checkedc = 0;
unsigned char sector[2352];
unsigned type;
unsigned num;
fseek(in, 0, SEEK_END);
resetcounter(ftell(in));
fseek(in, 0, SEEK_SET);
if(
(fgetc(in) != 'E') ||
(fgetc(in) != 'C') ||
(fgetc(in) != 'M') ||
(fgetc(in) != 0x00)
) {
fprintf(stderr, "Header not found!\n");
goto corrupt;
}
for(;;) {
int c = fgetc(in);
int bits = 5;
if(c == EOF) goto uneof;
type = c & 3;
num = (c >> 2) & 0x1F;
while(c & 0x80) {
c = fgetc(in);
if(c == EOF) goto uneof;
num |= ((unsigned)(c & 0x7F)) << bits;
bits += 7;
}
if(num == 0xFFFFFFFF) break;
num++;
if(num >= 0x80000000) goto corrupt;
if(!type) {
while(num) {
int b = num;
if(b > 2352) b = 2352;
if(fread(sector, 1, b, in) != b) goto uneof;
checkedc = edc_partial_computeblock(checkedc, sector, b);
fwrite(sector, 1, b, out);
num -= b;
setcounter(ftell(in));
}
} else {
while(num--) {
memset(sector, 0, sizeof(sector));
memset(sector + 1, 0xFF, 10);
switch(type) {
case 1:
sector[0x0F] = 0x01;
if(fread(sector + 0x00C, 1, 0x003, in) != 0x003) goto uneof;
if(fread(sector + 0x010, 1, 0x800, in) != 0x800) goto uneof;
eccedc_generate(sector, 1);
checkedc = edc_partial_computeblock(checkedc, sector, 2352);
fwrite(sector, 2352, 1, out);
setcounter(ftell(in));
break;
case 2:
sector[0x0F] = 0x02;
if(fread(sector + 0x014, 1, 0x804, in) != 0x804) goto uneof;
sector[0x10] = sector[0x14];
sector[0x11] = sector[0x15];
sector[0x12] = sector[0x16];
sector[0x13] = sector[0x17];
eccedc_generate(sector, 2);
checkedc = edc_partial_computeblock(checkedc, sector + 0x10, 2336);
fwrite(sector + 0x10, 2336, 1, out);
setcounter(ftell(in));
break;
case 3:
sector[0x0F] = 0x02;
if(fread(sector + 0x014, 1, 0x918, in) != 0x918) goto uneof;
sector[0x10] = sector[0x14];
sector[0x11] = sector[0x15];
sector[0x12] = sector[0x16];
sector[0x13] = sector[0x17];
eccedc_generate(sector, 3);
checkedc = edc_partial_computeblock(checkedc, sector + 0x10, 2336);
fwrite(sector + 0x10, 2336, 1, out);
setcounter(ftell(in));
break;
}
}
}
}
if(fread(sector, 1, 4, in) != 4) goto uneof;
fprintf(stderr, "Decoded %ld bytes -> %ld bytes\n", ftell(in), ftell(out));
if(
(sector[0] != ((checkedc >> 0) & 0xFF)) ||
(sector[1] != ((checkedc >> 8) & 0xFF)) ||
(sector[2] != ((checkedc >> 16) & 0xFF)) ||
(sector[3] != ((checkedc >> 24) & 0xFF))
) {
fprintf(stderr, "EDC error (%08X, should be %02X%02X%02X%02X)\n",
checkedc,
sector[3],
sector[2],
sector[1],
sector[0]
);
goto corrupt;
}
fprintf(stderr, "Done; file is OK\n");
return 0;
uneof:
fprintf(stderr, "Unexpected EOF!\n");
corrupt:
fprintf(stderr, "Corrupt ECM file!\n");
return 1;
}
/***************************************************************************/
int main(int argc, char **argv) {
FILE *fin, *fout;
char *infilename;
char *outfilename;
banner();
/*
** Initialize the ECC/EDC tables
*/
eccedc_init();
/*
** Check command line
*/
if((argc != 2) && (argc != 3)) {
fprintf(stderr, "usage: %s ecmfile [outputfile]\n", argv[0]);
return 1;
}
/*
** Verify that the input filename is valid
*/
infilename = argv[1];
if(strlen(infilename) < 5) {
fprintf(stderr, "filename '%s' is too short\n", infilename);
return 1;
}
if(strcasecmp(infilename + strlen(infilename) - 4, ".ecm")) {
fprintf(stderr, "filename must end in .ecm\n");
return 1;
}
/*
** Figure out what the output filename should be
*/
if(argc == 3) {
outfilename = argv[2];
} else {
outfilename = malloc(strlen(infilename) - 3);
if(!outfilename) abort();
memcpy(outfilename, infilename, strlen(infilename) - 4);
outfilename[strlen(infilename) - 4] = 0;
}
fprintf(stderr, "Decoding %s to %s.\n", infilename, outfilename);
/*
** Open both files
*/
fin = fopen(infilename, "rb");
if(!fin) {
perror(infilename);
return 1;
}
fout = fopen(outfilename, "wb");
if(!fout) {
perror(outfilename);
fclose(fin);
return 1;
}
/*
** Decode
*/
unecmify(fin, fout);
/*
** Close everything
*/
fclose(fout);
fclose(fin);
return 0;
}
解决方案
Have you considered using JNI instead of bothering doing the translation from C to Java?
这篇关于转换.C到的.java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文