PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/noah_palm/armlet/src/armlet-simple.c

https://github.com/kjk/noah-palm
C | 972 lines | 726 code | 109 blank | 137 comment | 101 complexity | d700af30e0813c10e6697faeb7b4b502 MD5 | raw file
  1. /******************************************************************************
  2. *
  3. * I M P O R T A N T
  4. *
  5. * If you want to test program on simulator remember to
  6. * copy armlet.dll to your simulator directory
  7. *
  8. * You can create dll using noah_palm/armlet/palmsimarmlet.dsp
  9. *
  10. *****************************************************************************/
  11. /******************************************************************************
  12. *
  13. * File: armlet-simple.c
  14. *
  15. * Copyright (C) 2000-2003 Krzysztof Kowalczyk
  16. * Author: szymon knitter (szknitter@wp.pl)
  17. *
  18. * Description:
  19. *
  20. * This is changed armlet example.
  21. * We will use it to build armlet code for our aplications
  22. * NativeFunction must be first!!!
  23. * Read more in ../../src/armlet_structures.h
  24. *
  25. *****************************************************************************/
  26. /****************************************************
  27. *
  28. * Number - Function - return value when executed
  29. * 1 - Test function - retrun 101
  30. * 10 - Format2OnSortedBuffer
  31. * 11 - Format1OnSortedBuffer
  32. * 20 - WhileLoopFrom Get_defs_record
  33. *
  34. ****************************************************/
  35. #include "PceNativeCall.h"
  36. #ifdef WIN32
  37. #include "SimNative.h"
  38. // #include <stdio.h>
  39. #endif
  40. unsigned long NativeFunctionAtTheEnd(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP);
  41. #ifndef WIN32
  42. unsigned long __ARMlet_Startup__(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP)
  43. #else
  44. unsigned long NativeFunction(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP)
  45. #endif
  46. {
  47. return NativeFunctionAtTheEnd(emulStateP, userData68KP, call68KFuncP);
  48. }
  49. #include "../../src/armlet_structures.h"
  50. #include "utils68k.h"
  51. /* FROM THIS POINT YOU CAN ADD YOUR OWN FUNCTIONS */
  52. void Function1(void *funData)
  53. {
  54. }
  55. /* Mem allocations */
  56. #define sysTrapMemPtrNew 0xA013 // we need this in order to call into MemPtrNew
  57. #define sysTrapMemPtrFree 0xA012 // we need this in order to call into MemPtrFree
  58. void new_free(void * ptr,const void *emulStateP,Call68KFuncType *call68KFuncP)
  59. {
  60. void* ptrSwaped; // array of Byte
  61. ptrSwaped = (void *)EndianSwap32(ptr);
  62. ((call68KFuncP)(emulStateP, PceNativeTrapNo(sysTrapMemPtrFree), &ptrSwaped, 4 | kPceNativeWantA0));
  63. }
  64. void * new_malloc(unsigned long setSize,const void *emulStateP,Call68KFuncType *call68KFuncP)
  65. {
  66. unsigned long size; // UInt32, must be stack based
  67. unsigned char* bufferP; // array of Byte
  68. // set the size to setSize bytes, byte swapped so it's in big-endian format
  69. // This will be the argument to MemPtrNew().
  70. size = EndianSwap32(setSize);
  71. // call MemPtrNew, using the 4 bytes of size directly from the stack
  72. // The 4 specifies the size of the arguments, and we need to OR the size
  73. // with kPceNativeWantA0 because the return value is a pointer type.
  74. bufferP = (unsigned char *)((call68KFuncP)(emulStateP, PceNativeTrapNo(sysTrapMemPtrNew), &size, 4 | kPceNativeWantA0));
  75. return (void *)bufferP; // return a pointer to the buffer
  76. }
  77. #ifndef WIN32
  78. void memmove(char *dst, char *src, int len)
  79. {
  80. int i;
  81. if(dst > src)
  82. {
  83. for(i=len-1;i>=0;i--)
  84. dst[i] = src[i];
  85. }
  86. else
  87. if(dst < src)
  88. {
  89. for(i=0;i<len;i++)
  90. dst[i] = src[i];
  91. }
  92. }
  93. #define memcpy memmove
  94. unsigned long strlen(char *str)
  95. {
  96. unsigned long i = 0;
  97. while(str[i] != '\0')
  98. i++;
  99. return i;
  100. }
  101. #endif
  102. /*strprintstr function <=> sprintf(dst,"%s",src);*/
  103. void strprintstr(char *dst, char *src)
  104. {
  105. int i = 0;
  106. while(src[i] != 0)
  107. {
  108. dst[i] = (char) src[i];
  109. i++;
  110. }
  111. dst[i] = 0;
  112. }
  113. /*straddstr function - add src to the end of dst*/
  114. /*void straddstr(char *dst, char *src)
  115. {
  116. unsigned long i,j = 0;
  117. i = strlen(dst);
  118. while(src[j]!='\0')
  119. {
  120. dst[i] = src[j];
  121. i++;
  122. j++;
  123. }
  124. dst[i] = 0;
  125. }*/
  126. /*strprintshortint - printf int < 1000 as asci*/
  127. void strprintshortint(char *dst, int number)
  128. {
  129. int i = 0;
  130. int j = 13;
  131. int number2;
  132. if(number >= 100)
  133. {
  134. number2 = number;
  135. j = 0;
  136. while(number2 >= 100)
  137. {
  138. j++;
  139. number2 -= 100;
  140. }
  141. dst[i++] = j + '0';
  142. number = number - j*100;
  143. }
  144. if(number >= 10)
  145. {
  146. number2 = number;
  147. j = 0;
  148. while(number2 >= 10)
  149. {
  150. j++;
  151. number2 -= 10;
  152. }
  153. dst[i++] = j + '0';
  154. number = number - j*10;
  155. }
  156. dst[i++] = number + '0';
  157. dst[i] = 0;
  158. }
  159. /* EBUF functions to handle buffer operations*/
  160. /* Extensible buffer for easier construction of string data
  161. of unknown length */
  162. typedef struct
  163. {
  164. int allocated; // how many bytes allocated
  165. char * data; // pointer to data
  166. int used; // how many bytes used (out of all allocated)
  167. //i dont use it!!! but it is needed
  168. int minSize; // how much memory to pre-allocated upon initialization
  169. } ExtensibleBuffer;
  170. void ebufReplaceChar(ExtensibleBuffer *buf, char c, int pos)
  171. {
  172. if (pos > buf->used)
  173. return;
  174. buf->data[pos] = c;
  175. }
  176. void ebufInsertChar(ExtensibleBuffer *buf, char c, int pos,const void *emulStateP,Call68KFuncType *call68KFuncP)
  177. {
  178. int newAllocated;
  179. char *newData;
  180. // we can only insert up to the last pos in the buffer
  181. if (pos > buf->used)
  182. return;
  183. if ((buf->used + 1) >= buf->allocated)
  184. {
  185. newAllocated = buf->allocated + 256;
  186. newData = (char *) new_malloc(newAllocated,emulStateP,call68KFuncP);
  187. if (!newData)
  188. return;
  189. if (buf->data)
  190. {
  191. memmove(newData, buf->data, buf->used);
  192. new_free(buf->data,emulStateP,call68KFuncP);
  193. }
  194. buf->allocated = newAllocated;
  195. buf->data = newData;
  196. }
  197. // make room if inserting
  198. if (pos < buf->used)
  199. {
  200. memmove(&(buf->data[pos + 1]), &(buf->data[pos]), buf->used - pos);
  201. }
  202. buf->data[pos] = c;
  203. ++buf->used;
  204. }
  205. void ebufAddChar(ExtensibleBuffer *buf, char c,const void *emulStateP,Call68KFuncType *call68KFuncP)
  206. {
  207. ebufInsertChar(buf, c, buf->used,emulStateP,call68KFuncP);
  208. }
  209. void ebufAddStrN(ExtensibleBuffer *buf, char *str, int strLen,const void *emulStateP,Call68KFuncType *call68KFuncP)
  210. {
  211. int i;
  212. for (i = 0; i < strLen; i++)
  213. ebufInsertChar(buf, str[i], buf->used,emulStateP,call68KFuncP);
  214. }
  215. void ebufAddStr(ExtensibleBuffer * buf, char *str,const void *emulStateP,Call68KFuncType *call68KFuncP)
  216. {
  217. ebufAddStrN(buf, str, strlen(str),emulStateP,call68KFuncP);
  218. }
  219. //delete one char from buffer
  220. //we will not free memory!!!
  221. void ebufDeleteChar(ExtensibleBuffer *buf, int pos)
  222. {
  223. if (pos < buf->used - 1)
  224. memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->used - pos - 1);
  225. buf->used--;
  226. }
  227. //insert string into buf[pos]
  228. void ebufInsertStringOnPos(ExtensibleBuffer *buf, char *string, int pos,const void *emulStateP,Call68KFuncType *call68KFuncP)
  229. {
  230. int i;
  231. i = strlen(string) - 1;
  232. if(i+1 + buf->used < buf->allocated)
  233. {
  234. memmove(&buf->data[pos+i+1],&buf->data[pos],buf->used-pos);
  235. buf->used += i+1;
  236. for(;i >= 0; i--)
  237. buf->data[pos+i] = string[i];
  238. }
  239. else
  240. {
  241. for(; i >= 0; i--)
  242. ebufInsertChar(buf, string[i], pos,emulStateP,call68KFuncP);
  243. }
  244. }
  245. //insert "Synonyms: " into buf[pos]
  246. void ebufInsertSynonymsOnPos(ExtensibleBuffer *buf, int pos,const void *emulStateP,Call68KFuncType *call68KFuncP)
  247. {
  248. char syn[11] = {"Synonyms: "};
  249. syn[0] = 'S';
  250. syn[1] = 'y';
  251. syn[2] = 'n';
  252. syn[3] = 'o';
  253. syn[4] = 'n';
  254. syn[5] = 'y';
  255. syn[6] = 'm';
  256. syn[7] = 's';
  257. syn[8] = ':';
  258. syn[9] = ' ';
  259. syn[10] = 0;
  260. ebufInsertStringOnPos(buf, syn, pos,emulStateP,call68KFuncP);
  261. // This is not working - char* in code is invalid???
  262. // ebufInsertStringOnPos(buf, "Synonyms: ", pos,emulStateP,call68KFuncP);
  263. }
  264. /*Called by Function10*/
  265. //formatting tag code (an unused in database asci code)
  266. //and DisplayPrefs structure
  267. #define FORMAT_TAG 152
  268. #define FORMAT_WORD 153
  269. #define FORMAT_DEFINITION 154
  270. #define FORMAT_EXAMPLE 155
  271. #define FORMAT_POS 156
  272. #define FORMAT_SYNONYM 157
  273. #define FORMAT_LIST 158
  274. #define FORMAT_BIG_LIST 159
  275. #define FORMAT_PRONUNCIATION 160
  276. // return true if a,b represents a tag
  277. // inline version to make it faster!
  278. static int IsTagInLine(char a, char b)
  279. {
  280. if(a != (char)FORMAT_TAG)
  281. return 0;
  282. switch(b)
  283. {
  284. case (char)FORMAT_POS:
  285. case (char)FORMAT_WORD:
  286. case (char)FORMAT_DEFINITION:
  287. case (char)FORMAT_LIST:
  288. case (char)FORMAT_BIG_LIST:
  289. case (char)FORMAT_SYNONYM:
  290. case (char)FORMAT_EXAMPLE:
  291. case (char)FORMAT_PRONUNCIATION:
  292. return 1;
  293. default:
  294. return 0;
  295. }
  296. }
  297. /*return: r<0 if pos1 < pos2
  298. r=0 if pos1 = pos2
  299. r>0 if pos1 > pos2 */
  300. int CmpPos(char *pos1, char *pos2)
  301. {
  302. int i,len1,len2;
  303. i = 1;
  304. while( !IsTagInLine(pos1[i],pos1[i+1]) && pos1[i+1]!='\0')
  305. i++;
  306. len1 = i;
  307. i = 1;
  308. while( !IsTagInLine(pos2[i],pos2[i+1]) && pos2[i+1]!='\0')
  309. i++;
  310. len2 = i;
  311. i = 0;
  312. while(pos1[i] == pos2[i] && i < len1 && i < len2)
  313. i++;
  314. //end of pos1 or end of pos2?
  315. if(i < len1 && i < len2)
  316. {
  317. if(pos1[i] < pos2[i])
  318. return (-1);
  319. if(pos1[i] > pos2[i])
  320. return (1);
  321. }
  322. return(len1 - len2);
  323. }
  324. //delete all text until tag or EOB is reached
  325. static void ebufDeletePos(ExtensibleBuffer *buf, int pos)
  326. {
  327. int i,j;
  328. char *data = buf->data;
  329. i = pos;
  330. j = buf->used;
  331. while(!IsTagInLine(data[pos],data[pos+1]) && pos < j)
  332. pos++;
  333. memmove(&(data[i]), &(data[pos]), j - pos);
  334. buf->used -= (pos-i);
  335. }
  336. /* Xchg AbcdEef -> EefAbcd return updated offset2 */
  337. /* |off1 |off2 |end2 */
  338. /* before: abCdefghijKlmnopqrstuwXyz */
  339. /* after: abKlmnopqrstuwCdefghijXyz */
  340. /* |off2 - return */
  341. //old version - in place
  342. int XchgInBuffer(char *txt, int offset1, int offset2, int end2)
  343. {
  344. int i;
  345. char z;
  346. char *txt1;
  347. char *txt2;
  348. int div2;
  349. //reverse all
  350. txt1 = txt + offset1;
  351. txt2 = txt + end2 - 1;
  352. div2 = (end2-offset1)>>1;
  353. for(i = 0; i < div2 ; i++)
  354. {
  355. z = txt1[0];
  356. txt1[0] = txt2[0];
  357. txt2[0] = z;
  358. txt1++;
  359. txt2--;
  360. }
  361. //mirror offset2
  362. i = offset2 - offset1;
  363. offset2 = end2 - i;
  364. //reverse 1st
  365. txt1 = txt + offset1;
  366. txt2 = txt + offset2 - 1;
  367. div2 = (offset2-offset1)>>1;
  368. for(i = 0; i < div2 ; i++)
  369. {
  370. z = txt1[0];
  371. txt1[0] = txt2[0];
  372. txt2[0] = z;
  373. txt1++;
  374. txt2--;
  375. }
  376. //reverse 2nd
  377. txt1 = txt + offset2;
  378. txt2 = txt + end2 - 1;
  379. div2 = (end2-offset2)>>1;
  380. for(i = 0; i < div2 ; i++)
  381. {
  382. z = txt1[0];
  383. txt1[0] = txt2[0];
  384. txt2[0] = z;
  385. txt1++;
  386. txt2--;
  387. }
  388. return offset2;
  389. }
  390. //word is marked as synonym! and synonyms are marked as words!
  391. //we need to change it... and sort synonyms after definition and examples
  392. //also add "synonyms:" text (but not in thes.).
  393. static void XchgWordsWithSynonyms(ExtensibleBuffer *buf,const void *emulStateP,Call68KFuncType *call68KFuncP)
  394. {
  395. int i, j, k;
  396. int used;
  397. char *data;
  398. char *dataCurr;
  399. char *dataEnd;
  400. i = 0;
  401. if(buf->data[1] == (char)FORMAT_SYNONYM /*|| buf->data[1] == (char)FORMAT_WORD*/)
  402. {
  403. buf->data[1] = (char)FORMAT_WORD;
  404. i = 2;
  405. }
  406. else
  407. return; //we dont have "word" at the begining. This is not Format1 or Format2...
  408. used = buf->used;
  409. data = buf->data;
  410. while(i < used)
  411. {
  412. //set i on word tag
  413. while(i < used && !(data[i]==(char)FORMAT_TAG && data[i+1]==(char)FORMAT_WORD))
  414. i++;
  415. if(i < used)
  416. {
  417. ebufReplaceChar(buf, FORMAT_SYNONYM, i + 1);
  418. #ifndef THESAURUS //why? think :)
  419. //ebufInsertStringOnPos(buf, "Synonyms: ", i + 2,emulStateP,call68KFuncP);
  420. ebufInsertSynonymsOnPos(buf, i + 2,emulStateP,call68KFuncP);
  421. used = buf->used;
  422. data = buf->data;
  423. #endif
  424. }
  425. //set j on next tag
  426. j = i+2;
  427. dataCurr = data+j;
  428. dataEnd = data+used;
  429. while(dataCurr < dataEnd && !IsTagInLine(dataCurr[0],dataCurr[1]))
  430. dataCurr++;
  431. j = dataCurr-data;
  432. //some problems with unformated data
  433. if(!(j+1 < used))
  434. return;
  435. k = j;
  436. //set k on pos //but not if its reached
  437. if(data[j+1] != (char)FORMAT_POS)
  438. {
  439. k = j+2;
  440. if(!(k+1 < used))
  441. return;
  442. }
  443. dataCurr = data+k;
  444. while(dataCurr < dataEnd && dataCurr[0]!='\0' && !(dataCurr[0]==(char)FORMAT_TAG && dataCurr[1]==(char)FORMAT_POS))
  445. dataCurr++;
  446. k = dataCurr - data;
  447. //(i,j)(j,k) ---> (j,k)(i,j)
  448. if(j < used && j!=k)
  449. XchgInBuffer(data, i, j, k);
  450. i = k+2;
  451. }
  452. }
  453. //format 1
  454. void Format1OnSortedBuffer(ExtensibleBuffer *buf,const void *emulStateP,Call68KFuncType *call68KFuncP)
  455. {
  456. int i, j;
  457. int first_pos;
  458. int number;
  459. char str_number[10];
  460. XchgWordsWithSynonyms(buf,emulStateP,call68KFuncP);
  461. i = 0;
  462. while((buf->data[i] != (char)FORMAT_TAG || buf->data[i+1] != (char)FORMAT_POS) && i+1 < buf->used)
  463. i++;
  464. first_pos = i + 2;
  465. if(first_pos > buf->used)
  466. return;
  467. i = first_pos;
  468. number = 1;
  469. while( i+1 < buf->used )
  470. {
  471. if(buf->data[i] == (char)FORMAT_TAG && buf->data[i+1] == (char)FORMAT_POS)
  472. {
  473. i += 2;
  474. if(CmpPos(&buf->data[i], &buf->data[first_pos])==0)
  475. {
  476. //add numbers to buff (2. 3. 4. etc)
  477. ebufDeletePos(buf, i);
  478. number++;
  479. strprintshortint(str_number,number);
  480. j = strlen(str_number);
  481. str_number[j++] = ':';
  482. str_number[j++] = ' ';
  483. str_number[j] = 0;
  484. ebufReplaceChar(buf, FORMAT_LIST, i - 1);
  485. ebufInsertStringOnPos(buf, str_number, i, emulStateP,call68KFuncP);
  486. j = strlen(str_number);
  487. i += j-1;
  488. }
  489. else
  490. {
  491. //put 1. in first_pos (if its not a single pos type)
  492. if(buf->data[first_pos] == (char)149)
  493. {
  494. ebufDeleteChar(buf, first_pos);
  495. ebufDeleteChar(buf, first_pos);
  496. i-=2;
  497. }
  498. j = 0;
  499. while( !IsTagInLine(buf->data[first_pos+j],buf->data[first_pos+j+1]) )
  500. {
  501. if(buf->data[first_pos+j] == ')' || buf->data[first_pos+j]== '(')
  502. {
  503. ebufDeleteChar(buf, first_pos+j);
  504. j--;
  505. i--;
  506. }
  507. j++;
  508. }
  509. j = first_pos + j;
  510. str_number[0] = FORMAT_TAG;
  511. str_number[1] = FORMAT_BIG_LIST;
  512. if(number > 1)
  513. {
  514. str_number[2] = '1';
  515. str_number[3] = ':';
  516. str_number[4] = ' ';
  517. str_number[5] = 0;
  518. i++;
  519. }
  520. else
  521. {
  522. str_number[2] = ':';
  523. str_number[3] = ' ';
  524. str_number[4] = 0;
  525. }
  526. ebufInsertStringOnPos(buf, str_number, j, emulStateP,call68KFuncP);
  527. i += 4;
  528. number = 1;
  529. first_pos = i;
  530. i++;
  531. }
  532. }
  533. else
  534. i++;
  535. }
  536. //put 1. in first_pos
  537. if(buf->data[first_pos] == (char)149)
  538. {
  539. ebufDeleteChar(buf, first_pos);
  540. ebufDeleteChar(buf, first_pos);
  541. }
  542. j = 0;
  543. while( !IsTagInLine(buf->data[first_pos+j],buf->data[first_pos+j+1]) )
  544. {
  545. if(buf->data[first_pos+j] == ')' || buf->data[first_pos+j]== '(')
  546. {
  547. ebufDeleteChar(buf, first_pos+j);
  548. j--;
  549. }
  550. j++;
  551. }
  552. j = first_pos + j;
  553. i = 0;
  554. str_number[i++] = FORMAT_TAG;
  555. str_number[i++] = FORMAT_BIG_LIST;
  556. if(number > 1)
  557. {
  558. str_number[i++] = '1';
  559. }
  560. str_number[i++] = ':';
  561. str_number[i++] = ' ';
  562. str_number[i] = 0;
  563. ebufInsertStringOnPos(buf, str_number, j, emulStateP,call68KFuncP);
  564. }
  565. /* Print roman in dst */
  566. void strprintroman(char *dst, int roman)
  567. {
  568. int i = 0;
  569. dst[i++] = ' ';
  570. switch(roman)
  571. {
  572. case 3:
  573. dst[i++] = 'I';
  574. case 2:
  575. dst[i++] = 'I';
  576. case 1:
  577. dst[i++] = 'I';
  578. break;
  579. case 4:
  580. dst[i++] = 'I';
  581. dst[i++] = 'V';
  582. break;
  583. //we dont need it!
  584. /*
  585. case 5:
  586. dst[i++] = 'V';
  587. break;
  588. case 6:
  589. dst[i++] = 'V';
  590. dst[i++] = 'I';
  591. break;
  592. case 7:
  593. dst[i++] = 'V';
  594. dst[i++] = 'I';
  595. dst[i++] = 'I';
  596. break;
  597. case 8:
  598. dst[i++] = 'V';
  599. dst[i++] = 'I';
  600. dst[i++] = 'I';
  601. dst[i++] = 'I';
  602. break;
  603. case 9:
  604. dst[i++] = 'I';
  605. dst[i++] = 'X';
  606. break;*/
  607. default: break;
  608. }
  609. dst[i++] = ' ';
  610. dst[i++] = 0;
  611. }
  612. /* Format 2 on sorted buffer*/
  613. void Format2onSortedBuffer(ExtensibleBuffer *buf,const void *emulStateP,Call68KFuncType *call68KFuncP)
  614. {
  615. int i, j, p;
  616. int first_pos;
  617. int number;
  618. int bignumber;
  619. char str_number[16];
  620. char *data;
  621. char *dataTest;
  622. XchgWordsWithSynonyms(buf,emulStateP,call68KFuncP);
  623. i = 0;
  624. while((buf->data[i] != (char)FORMAT_TAG || buf->data[i+1] != (char)FORMAT_POS) && i+1 < buf->used)
  625. i++;
  626. first_pos = i + 2;
  627. if(first_pos > buf->used)
  628. return;
  629. i = first_pos;
  630. number = 1;
  631. bignumber = 1;
  632. data = buf->data;
  633. data += i;
  634. dataTest = (buf->data) + (buf->used) - 1;
  635. while(data < dataTest)
  636. {
  637. if(data[0] == (char)FORMAT_TAG)
  638. {
  639. if(data[1] == (char)FORMAT_POS)
  640. {
  641. i = buf->used - (dataTest+1-data);
  642. i += 2;
  643. if(CmpPos(&buf->data[i], &buf->data[first_pos])==0)
  644. {
  645. //add numbers to buff (2. 3. 4. etc)
  646. ebufDeletePos(buf, i);
  647. number++;
  648. strprintshortint(str_number,number);
  649. p = strlen(str_number);
  650. str_number[p++] = ')';
  651. str_number[p++] = ' ';
  652. str_number[p++] = 0;
  653. ebufInsertStringOnPos(buf, str_number, i,emulStateP,call68KFuncP);
  654. j = strlen(str_number);
  655. ebufReplaceChar(buf, FORMAT_LIST, i - 1);
  656. i += j-1;
  657. }
  658. else
  659. {
  660. //put 1) in first_pos (if its not a single pos type)
  661. if(buf->data[first_pos] == (char)149)
  662. {
  663. ebufDeleteChar(buf, first_pos);
  664. ebufDeleteChar(buf, first_pos);
  665. i-=2;
  666. }
  667. j = first_pos;
  668. while( !IsTagInLine(buf->data[j],buf->data[j+1]) )
  669. {
  670. if(buf->data[j] == ')' || buf->data[j]== '(')
  671. {
  672. ebufDeleteChar(buf, j);
  673. j--;
  674. i--;
  675. }
  676. j++;
  677. }
  678. ebufInsertChar(buf, '\n', j,emulStateP,call68KFuncP);
  679. j++;
  680. i++;
  681. if(number > 1)
  682. {
  683. str_number[0] = FORMAT_TAG;
  684. str_number[1] = FORMAT_LIST;
  685. str_number[2] = '1';
  686. str_number[3] = ')';
  687. str_number[4] = ' ';
  688. str_number[5] = 0;
  689. ebufInsertStringOnPos(buf, str_number, j, emulStateP,call68KFuncP);
  690. i += 5;
  691. }
  692. str_number[0] = (char) FORMAT_TAG;
  693. str_number[1] = (char) FORMAT_BIG_LIST;
  694. str_number[2] = 0;
  695. strprintroman(&str_number[strlen(str_number)],bignumber);
  696. ebufInsertStringOnPos(buf, str_number, first_pos - 2, emulStateP,call68KFuncP);
  697. j = strlen(str_number);
  698. i += j-1;
  699. i++;
  700. number = 1;
  701. first_pos = i;
  702. i++;
  703. bignumber++;
  704. }
  705. data = buf->data + i;
  706. dataTest = (buf->data) + (buf->used) - 1;
  707. }
  708. else
  709. data++;
  710. }
  711. else
  712. data++;
  713. }
  714. //put 1) in first_pos (if its not a single pos type)
  715. if(buf->data[first_pos] == (char)149)
  716. {
  717. ebufDeleteChar(buf, first_pos);
  718. ebufDeleteChar(buf, first_pos);
  719. }
  720. j = first_pos;
  721. while( !IsTagInLine(buf->data[j],buf->data[j+1]) )
  722. {
  723. if(buf->data[j] == ')' || buf->data[j]== '(')
  724. {
  725. ebufDeleteChar(buf, j);
  726. j--;
  727. }
  728. j++;
  729. }
  730. //goto end of pos
  731. j = first_pos + 1;
  732. while( !IsTagInLine(buf->data[j], buf->data[j+1]) )
  733. j++;
  734. ebufInsertChar(buf, '\n', j,emulStateP,call68KFuncP);
  735. j++;
  736. if(number > 1)
  737. {
  738. str_number[0] = FORMAT_TAG;
  739. str_number[1] = FORMAT_LIST;
  740. str_number[2] = '1';
  741. str_number[3] = ')';
  742. str_number[4] = ' ';
  743. str_number[5] = 0;
  744. ebufInsertStringOnPos(buf, str_number, j, emulStateP,call68KFuncP);
  745. }
  746. if(bignumber > 1)
  747. {
  748. str_number[0] = (char) FORMAT_TAG;
  749. str_number[1] = (char) FORMAT_BIG_LIST;
  750. str_number[2] = 0;
  751. strprintroman(&str_number[strlen(str_number)],bignumber);
  752. ebufInsertStringOnPos(buf, str_number, first_pos - 2, emulStateP,call68KFuncP);
  753. }
  754. }
  755. /*Fasade on Format2OnSortedBuffer*/
  756. void Function10(void *funData,const void *emulStateP,Call68KFuncType *call68KFuncP)
  757. {
  758. armFunction10Input *input;
  759. ExtensibleBuffer buf;
  760. unsigned long temp;
  761. input = (armFunction10Input *) funData;
  762. buf.allocated = Read68KUnaligned32(&input->allocated);
  763. buf.data = (char *) Read68KUnaligned32(&input->data);
  764. buf.used = Read68KUnaligned32(&input->used);
  765. buf.minSize = 0;
  766. Format2onSortedBuffer(&buf,emulStateP,call68KFuncP);
  767. Write68KUnaligned32(&input->data,buf.data);
  768. temp = buf.allocated;
  769. Write68KUnaligned32(&input->allocated,temp);
  770. temp = buf.used;
  771. Write68KUnaligned32(&input->used,temp);
  772. }
  773. /*Fasade on Format1OnSortedBuffer*/
  774. void Function11(void *funData,const void *emulStateP,Call68KFuncType *call68KFuncP)
  775. {
  776. armFunction10Input *input;
  777. ExtensibleBuffer buf;
  778. unsigned long temp;
  779. input = (armFunction10Input *) funData;
  780. buf.allocated = Read68KUnaligned32(&input->allocated);
  781. buf.data = (char *) Read68KUnaligned32(&input->data);
  782. buf.used = Read68KUnaligned32(&input->used);
  783. buf.minSize = 0;
  784. Format1OnSortedBuffer(&buf,emulStateP,call68KFuncP);
  785. Write68KUnaligned32(&input->data,buf.data);
  786. temp = buf.allocated;
  787. Write68KUnaligned32(&input->allocated,temp);
  788. temp = buf.used;
  789. Write68KUnaligned32(&input->used,temp);
  790. }
  791. /*while from get_defs_record*/
  792. unsigned long CalculateOffsetGDR(unsigned long *current_entry,unsigned long *offset, unsigned long *curr_len,
  793. unsigned char **def_lens_fast, unsigned char *def_lens_fast_end,unsigned long synsetNoFast)
  794. {
  795. do
  796. {
  797. (*curr_len) = (unsigned long) ((unsigned char)(def_lens_fast[0])[0]);
  798. (def_lens_fast[0])++;
  799. if ((unsigned long)255 == (*curr_len))
  800. {
  801. (*curr_len) = (unsigned long)((unsigned char)((def_lens_fast[0])[0])) * 256;
  802. (def_lens_fast[0])++;
  803. (*curr_len) += (unsigned long)(unsigned char)((def_lens_fast[0])[0]);
  804. (def_lens_fast[0])++;
  805. }
  806. if ((*current_entry) == synsetNoFast)
  807. return ((unsigned long) 1);
  808. (*offset) += (*curr_len);
  809. if(def_lens_fast_end == (def_lens_fast[0]))
  810. return ((unsigned long) 2);
  811. (*current_entry)++;
  812. }
  813. while (1==1);//true
  814. }
  815. /*runner for CalculateOffsetGDR*/
  816. void FunctionGetDefsRecord(void *funData)
  817. {
  818. armFunctionGetDefsRecordInput *input = (armFunctionGetDefsRecordInput *) funData;
  819. unsigned long current_entry = Read68KUnaligned32(&input->current_entry);
  820. unsigned long offset = Read68KUnaligned32(&input->offset);
  821. unsigned long curr_len = Read68KUnaligned32(&input->curr_len);
  822. unsigned char *def_lens_fast;
  823. unsigned char *def_lens_fast_end;
  824. unsigned long synsetNoFast = Read68KUnaligned32(&input->synsetNoFast);
  825. unsigned long returnValue = 0;
  826. def_lens_fast = (unsigned char *) Read68KUnaligned32(&input->def_lens_fast);
  827. def_lens_fast_end = (unsigned char *) Read68KUnaligned32(&input->def_lens_fast_end);
  828. returnValue = CalculateOffsetGDR(&current_entry, &offset, &curr_len, &def_lens_fast, def_lens_fast_end, synsetNoFast);
  829. Write68KUnaligned32(&input->current_entry, current_entry);
  830. Write68KUnaligned32(&input->offset, offset);
  831. Write68KUnaligned32(&input->curr_len, curr_len);
  832. Write68KUnaligned32(&input->def_lens_fast, def_lens_fast);
  833. Write68KUnaligned32(&input->returnValue, returnValue);
  834. }
  835. /*THIS SHOULD BE LAST FUNCTION IN FILE*/
  836. unsigned long NativeFunctionAtTheEnd(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP)
  837. {
  838. unsigned long funID;
  839. armMainInput *inptr;
  840. inptr = (armMainInput*) userData68KP;
  841. funID = Read68KUnaligned32(&inptr->functionID);
  842. switch(funID)
  843. {
  844. case ARM_FUN_TESTIFPRESENT: //test function
  845. Function1((void*)Read68KUnaligned32(&inptr->functionData));
  846. Write68KUnaligned32(&inptr->functionID, funID+ARM_FUN_RETURN_OFFSET);
  847. break;
  848. case ARM_FUN_FORMAT2ONBUFF: //format 2 on sorted buffer
  849. Function10((void*)Read68KUnaligned32(&inptr->functionData),emulStateP,call68KFuncP);
  850. Write68KUnaligned32(&inptr->functionID, funID+ARM_FUN_RETURN_OFFSET);
  851. break;
  852. case ARM_FUN_FORMAT1ONBUFF: //format 1 on sorted buffer
  853. Function11((void*)Read68KUnaligned32(&inptr->functionData),emulStateP,call68KFuncP);
  854. Write68KUnaligned32(&inptr->functionID, funID+ARM_FUN_RETURN_OFFSET);
  855. break;
  856. case ARM_FUN_GETDEFSRECORD: //get defs record (while loop)
  857. FunctionGetDefsRecord((void*)Read68KUnaligned32(&inptr->functionData));
  858. Write68KUnaligned32(&inptr->functionID, funID+ARM_FUN_RETURN_OFFSET);
  859. break;
  860. default: break;
  861. }
  862. return (unsigned long)userData68KP;
  863. }