Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please, help me!!! ...to write implementation for this C function  RSS feed

 
Justin J.
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys

Maybe you could help me. This is the story. I need to write quite big program. In addition, it�s given a function in C. The problem is that that the last time I used C more than 18 months ago; I do not know it very well.
Therefore, I ask you to help me to write native method implementation of this function. What should I change in this *.c file:
The main idea is that we have char array. The value can be 0 or 1.
And this function has to make another similar array.
Here char *gg means input array, char *og means output array,
in is number of items in gg, on is number of items in og(in this function in is 36, on is 7). Gerai means nothing.

Please, write me a short example of that implementation. After four hours I really lost a hope to do it myself. I think the problem is because of these pointers (eg. *gg), I don�t know how they should interact with JVM.

Its very impotent for me, only one week left to do this, I need to present this to my lecture.

// -active visi
void funkcija(char *gg,char *og,int in,int on,int *gerai)
{
int _118gat,_119gat,_122gat,_123gat,_126gat;
int _127gat,_130gat,_131gat,_134gat,_135gat;
int _138gat,_139gat,_142gat,_143gat,_146gat;
int _147gat,_150gat,_151gat,_154gat,_157gat;
int _158gat,_159gat,_162gat,_165gat,_168gat;
int _171gat,_174gat,_177gat,_180gat,_183gat;
int _184gat,_185gat,_186gat,_187gat,_188gat;
int _189gat,_190gat,_191gat,_192gat,_193gat;
int _194gat,_195gat,_196gat,_197gat,_198gat;
int _199gat,_203gat,_213gat,_223gat,_224gat;
int _227gat,_230gat,_233gat,_236gat,_239gat;
int _242gat,_243gat,_246gat,_247gat,_250gat;
int _251gat,_254gat,_255gat,_256gat,_257gat;
int _258gat,_260gat,_263gat,_264gat,_267gat;
int _270gat,_273gat,_276gat,_279gat,_282gat;
int _285gat,_288gat,_289gat,_290gat,_291gat;
int _292gat,_293gat,_294gat,_295gat,_296gat;
int _300gat,_301gat,_302gat,_303gat,_304gat;
int _305gat,_306gat,_307gat,_308gat,_309gat;
int _319gat,_329gat,_330gat,_331gat,_332gat;
int _333gat,_334gat,_335gat,_336gat,_337gat;
int _338gat,_339gat,_340gat,_341gat,_342gat;
int _343gat,_344gat,_345gat,_346gat,_348gat;
int _349gat,_350gat,_351gat,_352gat,_353gat;
int _354gat,_355gat,_356gat,_357gat,_360gat;
int _370gat,_371gat,_372gat,_373gat,_374gat;
int _375gat,_376gat,_377gat,_378gat,_380gat;
int _381gat,_386gat,_393gat,_399gat,_404gat;
int _407gat,_411gat,_414gat,_415gat,_416gat;
int _417gat,_418gat,_419gat,_420gat,_421gat;
int _422gat,_425gat,_428gat,_429gat,_430gat;
int _431gat,_432gat;
// input 36, output 7
int ag[36],od[7],ii,m1=1;
*gerai=1;
for(ii=0;ii<in;ii++)
if(*(gg+ii)=='0')
*(ag+ii)=0;
else
*(ag+ii)=1;
_118gat=m1-*(ag+0);
_119gat=m1-*(ag+1);
_122gat=m1-*(ag+3);
_123gat=m1-*(ag+5);
_126gat=m1-*(ag+7);
_127gat=m1-*(ag+9);
_130gat=m1-*(ag+11);
_131gat=m1-*(ag+13);
_134gat=m1-*(ag+15);
_135gat=m1-*(ag+17);
_138gat=m1-*(ag+19);
_139gat=m1-*(ag+21);
_142gat=m1-*(ag+23);
_143gat=m1-*(ag+25);
_146gat=m1-*(ag+27);
_147gat=m1-*(ag+29);
_150gat=m1-*(ag+31);
_151gat=m1-*(ag+33);
_154gat=m1-(_118gat&*(ag+1));
_157gat=m1-(*(ag+2)|_119gat);
_158gat=m1-(*(ag+4)|_119gat);
_159gat=m1-(_122gat&*(ag+5));
_162gat=m1-(_126gat&*(ag+9));
_165gat=m1-(_130gat&*(ag+13));
_168gat=m1-(_134gat&*(ag+17));
_171gat=m1-(_138gat&*(ag+21));
_174gat=m1-(_142gat&*(ag+25));
_177gat=m1-(_146gat&*(ag+29));
_180gat=m1-(_150gat&*(ag+33));
_183gat=m1-(*(ag+6)|_123gat);
_184gat=m1-(*(ag+8)|_123gat);
_185gat=m1-(*(ag+10)|_127gat);
_186gat=m1-(*(ag+12)|_127gat);
_187gat=m1-(*(ag+14)|_131gat);
_188gat=m1-(*(ag+16)|_131gat);
_189gat=m1-(*(ag+18)|_135gat);
_190gat=m1-(*(ag+20)|_135gat);
_191gat=m1-(*(ag+22)|_139gat);
_192gat=m1-(*(ag+24)|_139gat);
_193gat=m1-(*(ag+26)|_143gat);
_194gat=m1-(*(ag+28)|_143gat);
_195gat=m1-(*(ag+30)|_147gat);
_196gat=m1-(*(ag+32)|_147gat);
_197gat=m1-(*(ag+34)|_151gat);
_198gat=m1-(*(ag+35)|_151gat);
_199gat=_154gat&_159gat&_162gat&_165gat&_168gat&_171gat&_174gat&_177gat&_180gat;
_203gat=m1-_199gat;
_213gat=m1-_199gat;
*(od+0)=m1-_199gat;
_224gat=_203gat^_154gat;
_227gat=_203gat^_159gat;
_230gat=_203gat^_162gat;
_233gat=_203gat^_165gat;
_236gat=_203gat^_168gat;
_239gat=_203gat^_171gat;
_242gat=m1-(*(ag+0)&_213gat);
_243gat=_203gat^_174gat;
_246gat=m1-(_213gat&*(ag+3));
_247gat=_203gat^_177gat;
_250gat=m1-(_213gat&*(ag+7));
_251gat=_203gat^_180gat;
_254gat=m1-(_213gat&*(ag+11));
_255gat=m1-(_213gat&*(ag+15));
_256gat=m1-(_213gat&*(ag+19));
_257gat=m1-(_213gat&*(ag+23));
_258gat=m1-(_213gat&*(ag+27));
_260gat=m1-(_224gat&_157gat);
_263gat=m1-(_224gat&_158gat);
_264gat=m1-(_227gat&_183gat);
_267gat=m1-(_230gat&_185gat);
_270gat=m1-(_233gat&_187gat);
_273gat=m1-(_236gat&_189gat);
_276gat=m1-(_239gat&_191gat);
_279gat=m1-(_243gat&_193gat);
_282gat=m1-(_247gat&_195gat);
_285gat=m1-(_251gat&_197gat);
_288gat=m1-(_227gat&_184gat);
_289gat=m1-(_230gat&_186gat);
_290gat=m1-(_233gat&_188gat);
_291gat=m1-(_236gat&_190gat);
_292gat=m1-(_239gat&_192gat);
_293gat=m1-(_243gat&_194gat);
_294gat=m1-(_247gat&_196gat);
_295gat=m1-(_251gat&_198gat);
_296gat=_260gat&_264gat&_267gat&_270gat&_273gat&_276gat&_279gat&_282gat&_285gat;
_300gat=m1-_263gat;
_301gat=m1-_288gat;
_302gat=m1-_289gat;
_303gat=m1-_290gat;
_304gat=m1-_291gat;
_305gat=m1-_292gat;
_306gat=m1-_293gat;
_307gat=m1-_294gat;
_308gat=m1-_295gat;
_309gat=m1-_296gat;
_319gat=m1-_296gat;
*(od+1)=m1-_296gat;
_330gat=_309gat^_260gat;
_331gat=_309gat^_264gat;
_332gat=_309gat^_267gat;
_333gat=_309gat^_270gat;
_334gat=m1-(*(ag+2)&_319gat);
_335gat=_309gat^_273gat;
_336gat=m1-(_319gat&*(ag+6));
_337gat=_309gat^_276gat;
_338gat=m1-(_319gat&*(ag+10));
_339gat=_309gat^_279gat;
_340gat=m1-(_319gat&*(ag+14));
_341gat=_309gat^_282gat;
_342gat=m1-(_319gat&*(ag+18));
_343gat=_309gat^_285gat;
_344gat=m1-(_319gat&*(ag+22));
_345gat=m1-(_319gat&*(ag+26));
_346gat=m1-(_319gat&*(ag+30));
_348gat=m1-(_330gat&_300gat);
_349gat=m1-(_331gat&_301gat);
_350gat=m1-(_332gat&_302gat);
_351gat=m1-(_333gat&_303gat);
_352gat=m1-(_335gat&_304gat);
_353gat=m1-(_337gat&_305gat);
_354gat=m1-(_339gat&_306gat);
_355gat=m1-(_341gat&_307gat);
_356gat=m1-(_343gat&_308gat);
_357gat=_348gat&_349gat&_350gat&_351gat&_352gat&_353gat&_354gat&_355gat&_356gat;
_360gat=m1-_357gat;
*(od+2)=m1-_357gat;
_371gat=m1-(*(ag+4)&_360gat);
_372gat=m1-(_360gat&*(ag+8));
_373gat=m1-(_360gat&*(ag+12));
_374gat=m1-(_360gat&*(ag+16));
_375gat=m1-(_360gat&*(ag+20));
_376gat=m1-(_360gat&*(ag+24));
_377gat=m1-(_360gat&*(ag+28));
_378gat=m1-(_360gat&*(ag+32));
_380gat=m1-(*(ag+1)&_242gat&_334gat&_371gat);
_381gat=m1-(_246gat&_336gat&_372gat&*(ag+5));
_386gat=m1-(_250gat&_338gat&_373gat&*(ag+9));
_393gat=m1-(_254gat&_340gat&_374gat&*(ag+13));
_399gat=m1-(_255gat&_342gat&_375gat&*(ag+17));
_404gat=m1-(_256gat&_344gat&_376gat&*(ag+21));
_407gat=m1-(_257gat&_345gat&_377gat&*(ag+25));
_411gat=m1-(_258gat&_346gat&_378gat&*(ag+29));
_414gat=m1-*(ag+33);
_415gat=m1-_380gat;
_416gat=_381gat&_386gat&_393gat&_399gat&_404gat&_407gat&_411gat&_414gat;
_417gat=m1-_393gat;
_418gat=m1-_404gat;
_419gat=m1-_407gat;
_420gat=m1-_411gat;
*(od+3)=m1-(_415gat|_416gat);
_422gat=m1-(_386gat&_417gat);
_425gat=m1-(_386gat&_393gat&_418gat&_399gat);
_428gat=m1-(_399gat&_393gat&_419gat);
_429gat=m1-(_386gat&_407gat&_420gat);
*(od+4)=m1-(_381gat&_386gat&_422gat&_399gat);
*(od+5)=m1-(_381gat&_386gat&_425gat&_428gat);
*(od+6)=m1-(_381gat&_422gat&_425gat&_429gat);

for(ii=0;ii<on;ii++)
if(*(od+ii)==0)
*(og+ii)='0';
else
*(og+ii)='1';
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Hoo boy.

Listen, in all seriousness, unless you have a family that's depending on you for income, my best advice to you is to run, fast and far. Today. This is an appalling example of man's inhumanity to man. Whoever did this should be indicted, summarily convicted, and hung, with their head subsequently displayed on a pike as a warning to other "programmers". You want to get as far away from this environment as possible, as quickly as you can. Someday you'll thank me for this.

In any case, I have no idea what your question is. Want to try explaining a little better?
 
Justin J.
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what you wanted to say either. From what should I run? Did you mean from JNI or from Java at all? Who should be convicted, me?
Do you think I am that �programmer�? Maybe you are right, I am just a student but I don�t think that programming will become my job.

P.S I cannot understand what you did not understand.
I want to know to changer that source code for compiling it to dll. I mean how to access these java char array elements from native side.
When changer the header in c file like this Java_HelloWorld_displayHelloWorld(JNIEnv *env,jobject obj,jchar *gg,jchar *og,jint in,jint on,jint *gerai)
And I leave for example *gg like this *(ag+ii) I get errors.
How should I call that *gg?
 
Peter Laurinec
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin J.:
I have no idea what you wanted to say either. From what should I run? Did you mean from JNI or from Java at all? Who should be convicted, me?
Do you think I am that �programmer�? Maybe you are right, I am just a student but I don�t think that programming will become my job.

P.S I cannot understand what you did not understand.
I want to know to changer that source code for compiling it to dll. I mean how to access these java char array elements from native side.
When changer the header in c file like this Java_HelloWorld_displayHelloWorld(JNIEnv *env,jobject obj,jchar *gg,jchar *og,jint in,jint on,jint *gerai)
And I leave for example *gg like this *(ag+ii) I get errors.
How should I call that *gg?


Hmm what about to start with reading something like
JNI tutorial from java.sun.com
Its a good start i would say.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!