conversion from c to java
Hi,
I'm working in conversion of code from c to java, what will be the equivelent for the following code.
typedef struct bit_file {
FILE *file;
unsigned char mask;
int rack;
int pacifier_counter;
} BIT_FILE;
void OutputCode( output_file, code )
BIT_FILE *output_file;
int code;
{
int top_of_range;
int abs_code;
int bit_count;
if ( code == 0 ) {
OutputRunLength++;
return;
}
if ( OutputRunLength != 0 ) {
while ( OutputRunLength > 0 ) {
OutputBits( output_file, 0L, 2 );
if ( OutputRunLength <= 16 ) {
OutputBits( output_file,
(unsigned long) ( OutputRunLength - 1 ), 4 );
OutputRunLength = 0;
} else {
OutputBits( output_file, 15L, 4 );
OutputRunLength -= 16;
}
}
}
if ( code < 0 )
abs_code = -code;
else
abs_code = code;
top_of_range = 1;
bit_count = 1;
while ( abs_code > top_of_range ) {
bit_count++;
top_of_range = ( ( top_of_range + 1 ) * 2 ) - 1;
}
if ( bit_count < 3 )
OutputBits( output_file, (unsigned long) ( bit_count + 1 ), 3 );
else
OutputBits( output_file, (unsigned long) ( bit_count + 5 ), 4 );
if ( code > 0 )
OutputBits( output_file, (unsigned long) code, bit_count );
else
OutputBits( output_file, (unsigned long) ( code + top_of_range ),
bit_count );
}
void OutputBits( bit_file, code, count )
BIT_FILE *bit_file;
unsigned long code;
int count;
{
unsigned long mask;
mask = 1L << ( count - 1 );
while ( mask != 0) {
if ( mask & code )
bit_file->rack |= bit_file->mask;
bit_file->mask >>= 1;
if ( bit_file->mask == 0 ) {
if ( putc( bit_file->rack, bit_file->file ) != bit_file->rack )
printf( "Fatal error in OutputBit!\n" );
else if ( ( bit_file->pacifier_counter++ & PACIFIER_COUNT ) == 0 )
putc( '.', stdout );
bit_file->rack = 0;
bit_file->mask = 0x80;
}
mask >>= 1;
}
}
Re: conversion from c to java
r_punidha, I don't believe there is a free C-to-Java translation service here.
If you show us what you've got so far, and what you're stuck on, we may be able to help you with it.
Reinventing the wheel is a process...
R. Elisha
Re: conversion from c to java
That's not valid C code.
e.g., the following makes no sense at all - since when can you define variables between the method header and the opening brace of the method?
[code]
void OutputCode( output_file, code )
BIT_FILE *output_file;
int code;
{
...
[/code/
Where did you get this C code?
Re: conversion from c to java
Quote:
Originally Posted by
David Anton
since when can you define variables between the method header and the opening brace of the method?
Since C was designed (around 1972). That is actually the declaration of the formal parameters passed to the method, not the definition of variables. I could agree with you that it is a bit old fashion, but it is still perfectly valid.
Re: conversion from c to java
Which compilers allow it?
I do most of my testing in VC++ and it doesn't compile there.
Re: conversion from c to java
Re: conversion from c to java
Quote:
Originally Posted by
r_punidha
Hi,
I'm working in conversion of code from c to java, what will be the equivelent for the following code.
Just an idea of a different approach. Java has an interface called JNI. It allows you to call code written in other languages, like C, from Java.
In your case it may be easier to collect a library of C code, and then use it from Java via JNI.
Say you have millions of lines of C code. Instead of turning them into Java you make a C library out of them and call them from Java instead.