PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/source/tools/krkr.cpp

https://bitbucket.org/val_haris/asc-ai
C++ | 1359 lines | 877 code | 280 blank | 202 comment | 189 complexity | f60f4478e2309db08d4589505cc1b19e MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. /*
  2. This file is part of Advanced Strategic Command; http://www.asc-hq.de
  3. Copyright (C) 1994-1999 Martin Bickel and Marc Schellenberger
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  15. Boston, MA 02111-1307 USA
  16. */
  17. #include <stdarg.h>
  18. #include <string>
  19. #include "krkr.h"
  20. #include "..\basestrm.h"
  21. #define write(a) cprintf(a)
  22. #define left 0
  23. #define right 1
  24. #define up 1
  25. #define down -1
  26. #define reset 0
  27. #define insert 1
  28. #define on 1
  29. #define off 0
  30. #define sortname 1
  31. #define sorttime 2
  32. #define max_long 2147483647
  33. #define fgcolor 15
  34. #define bkcolor 1
  35. /*********************************************************************************************/
  36. /* setcurpos : setzt den Cursor an die Position x y */
  37. /* getcurpos : liefert die Cursorposition */
  38. /*********************************************************************************************/
  39. extern void setcurpos( int col, int row );
  40. #pragma aux setcurpos = \
  41. "push bp" \
  42. "shl edx,8" \
  43. "or edx, ebx" \
  44. "mov ah,2" \
  45. "mov bx,0" \
  46. "int 10h" \
  47. "pop bp" \
  48. parm [ebx] [edx] \
  49. modify [ax ebx];
  50. extern int biosgetcurpos( void );
  51. #pragma aux biosgetcurpos = \
  52. "push bp" \
  53. "mov ah,3" \
  54. "mov bx,0" \
  55. "int 10h" \
  56. "movzx eax, dx" \
  57. "pop bp" \
  58. modify [bx];
  59. tcurpos getcurpos (void)
  60. {
  61. tcurpos pos;
  62. int a = biosgetcurpos();
  63. pos.y = (a >> 8);
  64. pos.x = (a & 0xff);
  65. return pos;
  66. }
  67. /*********************************************************************************************/
  68. /* Wait : wartet auf einen Tastendruck */
  69. /*********************************************************************************************/
  70. void _wait(void)
  71. {
  72. while ( kbhit() ) getch();
  73. getch();
  74. while ( kbhit() ) getch();
  75. }
  76. /*********************************************************************************************/
  77. /* charcat : h„ngt einen Buchstaben an einen string an */
  78. /*********************************************************************************************/
  79. void charcat (char s[], char c)
  80. {
  81. int i = 0;
  82. while (s[i] != 0) {
  83. i++;
  84. } /* endwhile */
  85. s[i] = c;
  86. s[i+1] = 0;
  87. }
  88. /*********************************************************************************************/
  89. /* unpack_date : entpackt das datum (von zb dateien) */
  90. /*********************************************************************************************/
  91. void unpack_date (unsigned short packed, int &day, int &month, int &year)
  92. {
  93. year = packed >> 9;
  94. month = (packed - year*512) >> 5;
  95. day = packed - year*512 - month*32;
  96. year +=1980;
  97. }
  98. /*********************************************************************************************/
  99. /* unpack_time : entpackt die zeit (von zb dateien) */
  100. /*********************************************************************************************/
  101. void unpack_time (unsigned short packed, int &sec, int &min, int &hour)
  102. {
  103. hour = packed >> 11;
  104. min = (packed - hour*2048) >> 5;
  105. sec = packed - hour*2048 - min*32; // sekunden sind noch nicht getestet !!!
  106. }
  107. /*********************************************************************************************/
  108. /* num_ed : Editor fr Zahlen */
  109. /*********************************************************************************************/
  110. void num_ed ( long &sel, long min, long max)
  111. {
  112. tcurpos pos; // Pos des Eingabefieldes
  113. if (min>max) {
  114. int i;
  115. i = min;
  116. min = max;
  117. max = i;
  118. } /* endif */
  119. printf ("\n");
  120. cprintf (" (%i <= x <= %i) : ", min, max);
  121. pos = getcurpos ();
  122. _settextposition (pos.y+1, pos.x+1);
  123. _settextcolor (fgcolor);
  124. _setbkcolor (bkcolor);
  125. _outtext (" ");
  126. _settextcolor (7);
  127. _setbkcolor (0);
  128. setcurpos (pos.x, pos.y);
  129. cprintf ("%11i", sel);
  130. do {
  131. int input;
  132. if ((sel<min) || (sel>max)) {
  133. if (sel <min) sel = min;
  134. if (sel >max) sel = max;
  135. setcurpos (pos.x, pos.y);
  136. cprintf (" ");
  137. setcurpos (pos.x, pos.y);
  138. cprintf ("%11i", sel);
  139. } /* endif */
  140. do {
  141. input = getch ();
  142. if (isdigit(input) && (-214748363<=sel) && (sel<=214748363)) {
  143. if (sel>=0) {
  144. sel = sel*10 + (input-48);
  145. } else {
  146. sel = sel*10 - (input-48);
  147. } /* endif */
  148. setcurpos (pos.x, pos.y);
  149. cprintf ("%11i", sel);
  150. } /* endif */
  151. if ((input==8) && (sel!=0)) {
  152. sel /= 10;
  153. setcurpos (pos.x, pos.y);
  154. cprintf (" ");
  155. setcurpos (pos.x, pos.y);
  156. cprintf ("%11i", sel);
  157. } /* endif */
  158. if ((input==27) || (sel==0)) {
  159. sel = 0;
  160. setcurpos (pos.x, pos.y);
  161. cprintf ("%11i", sel);
  162. } /* endif */
  163. if ((input=='-') && (sel!=0) && (min<0)) {
  164. sel *= -1;
  165. setcurpos (pos.x, pos.y);
  166. cprintf (" ");
  167. setcurpos (pos.x, pos.y);
  168. cprintf ("%11i", sel);
  169. } /* endif */
  170. } while (input!=13); /* enddo */
  171. } while ((sel<min) || (sel>max)); /* enddo */
  172. printf("\n");
  173. }
  174. void num_ed ( unsigned short &sel, long min, long max)
  175. {
  176. long tmp = sel;
  177. num_ed ( tmp, min, max );
  178. sel = tmp;
  179. }
  180. void num_ed ( char &sel, long min, long max)
  181. {
  182. long tmp = sel;
  183. num_ed ( tmp, min, max );
  184. sel = tmp;
  185. }
  186. void num_ed ( int &sel, long min, long max)
  187. {
  188. long tmp = sel;
  189. num_ed ( tmp, min, max );
  190. sel = tmp;
  191. }
  192. /*********************************************************************************************/
  193. /* stredit : Editor fr dynamische strings (ruft die Funktionen von class cstredit auf) */
  194. /*********************************************************************************************/
  195. void stredit (pchar &string, char maxlength, char xpos, char ypos)
  196. {
  197. cstredit se;
  198. se.init (&string, maxlength, xpos, ypos);
  199. se.edit ();
  200. se.done ();
  201. }
  202. /*********************************************************************************************/
  203. /* stredit2 : Editor fr statische strings (ruft die Funktionen von class cstredit auf) */
  204. /*********************************************************************************************/
  205. void stredit2 (char *string, char maxlength, char xpos, char ypos)
  206. {
  207. char *c = strdup ( string );
  208. cstredit se;
  209. se.init (&c, maxlength, xpos, ypos);
  210. se.edit ();
  211. se.done ();
  212. strcpy ( string, c );
  213. free (c);
  214. }
  215. /*********************************************************************************************/
  216. /* bitselect : Bit-Editor (ruft die Funktionen von class cbitselect auf) */
  217. /*********************************************************************************************/
  218. void bitselect (long &bits, const char *selection[], char bitnum)
  219. {
  220. cbitselect bs;
  221. tterrainbits bts ( bits );
  222. bs.init (bts, (char**) selection, bitnum);
  223. bs.select ();
  224. bs.done ();
  225. bits = bts.terrain1;
  226. }
  227. void bitselect ( unsigned short &bits, const char *selection[], char bitnum)
  228. {
  229. cbitselect bs;
  230. tterrainbits bts ( bits );
  231. /* char _selection[50][50]; // ??????????????????
  232. for (int i=0; *selection[i]!=NULL; i++) {
  233. strcpy(_selection[i] , selection[i] );
  234. }*/
  235. bs.init (bts, (char**) selection, bitnum);
  236. bs.select ();
  237. bs.done ();
  238. bits = bts.terrain1;
  239. }
  240. void bitselect (char &bits, const char *selection[], char bitnum)
  241. {
  242. cbitselect bs;
  243. tterrainbits bts ( bits );
  244. bs.init (bts, (char**) selection, bitnum);
  245. bs.select ();
  246. bs.done ();
  247. bits = bts.terrain1;
  248. }
  249. void bitselect (int &bits, const char *selection[], char bitnum)
  250. {
  251. cbitselect bs;
  252. tterrainbits bts ( bits );
  253. /* char _selection[50][50]; // ??????????????????
  254. for (int i=0; *selection[i]!=NULL; i++) {
  255. strcpy(_selection[i] , selection[i] );
  256. }
  257. */
  258. bs.init (bts, (char**) selection, bitnum);
  259. bs.select ();
  260. bs.done ();
  261. bits = bts.terrain1 ;
  262. }
  263. void bitselect ( tterrainbits &bits, const char *selection[], char bitnum)
  264. {
  265. cbitselect bs;
  266. bs.init (bits, (char**) selection, bitnum);
  267. bs.select ();
  268. bs.done ();
  269. }
  270. /*********************************************************************************************/
  271. /* yn_switch : schalter (ruft die Funktionen von class cyn_switch auf) */
  272. /*********************************************************************************************/
  273. void yn_switch (char *s1, char *s2, char v1, char v2, char &oldvalue)
  274. {
  275. fflush ( stdout );
  276. cyn_switch sw;
  277. sw.init (s1, s2, v1, v2, oldvalue);
  278. sw.select ();
  279. sw.done ();
  280. }
  281. /*********************************************************************************************/
  282. /* fileselect : dateimen (ruft Funktionen von class cfileselect auf) */
  283. /*********************************************************************************************/
  284. void fileselect (char *searchstr, unsigned attributes, tfile &file)
  285. {
  286. cfileselect fs;
  287. fs.init (searchstr, attributes);
  288. fs.select ();
  289. fs.done (file);
  290. }
  291. /*********************************************************************************************/
  292. /* class cstredit : Editor fr strings */
  293. /*********************************************************************************************/
  294. void cstredit :: init (char **_string, char _maxlength, char x, char y)
  295. {
  296. string = (char*) malloc ( _maxlength );
  297. oldstring = _string ;
  298. if ( *_string != NULL ) {
  299. strcpy ( string , *_string );
  300. } else {
  301. string[0]=0;
  302. *oldstring = (char*) malloc ( 1 ) ;
  303. (*oldstring)[0]=0;
  304. }
  305. maxlength = _maxlength;
  306. if ((x==255) || (y==255)) {
  307. printf ("\n ");
  308. textpos = getcurpos ();
  309. } else {
  310. textpos.x = x;
  311. textpos.y = y;
  312. } /* endif */
  313. pos = strlen (string);
  314. status = insert;
  315. _settextcolor (fgcolor);
  316. _setbkcolor (bkcolor);
  317. _settextposition (textpos.y+1, textpos.x+1);
  318. for (int i=0; i<=maxlength; i++) {
  319. _outtext(" ");
  320. } /* endfor */
  321. setcurpos (textpos.x, textpos.y);
  322. cprintf (string);
  323. }
  324. /*void cstredit :: showstr ()
  325. {
  326. setcurpos (textpos.x, textpos.y);
  327. cprintf ("%s", string);
  328. setcurpos (textpos.x+pos, textpos.y);
  329. }*/
  330. void cstredit :: addchar (char c)
  331. {
  332. int i=0;
  333. char s[255];
  334. strcpy (s, string);
  335. string[0] = 0;
  336. while (i<pos) {
  337. charcat (string, s[i]);
  338. i++;
  339. } /* endwhile */
  340. charcat (string, c);
  341. setcurpos (textpos.x + pos, textpos.y);
  342. putch (c);
  343. while ((i<=maxlength) && (i<=strlen (s))) {
  344. charcat (string, s[i]);
  345. putch (s[i]);
  346. i++;
  347. } /* endwhile */
  348. pos++;
  349. setcurpos (textpos.x + pos, textpos.y);
  350. }
  351. void cstredit :: delchar (char leftright)
  352. {
  353. int i=0;
  354. char s[255];
  355. strcpy (s, string);
  356. string[0] = 0;
  357. pos += leftright-1;
  358. while (i<pos) {
  359. charcat (string, s[i]);
  360. i++;
  361. } /* endwhile */
  362. i++;
  363. setcurpos(textpos.x + pos, textpos.y);
  364. while ((i<=maxlength) && (i<=strlen (s))) {
  365. charcat (string, s[i]);
  366. putch (s[i]);
  367. i++;
  368. } /* endwhile */
  369. putch (' ');
  370. setcurpos (textpos.x + pos, textpos.y);
  371. }
  372. void cstredit :: overwrite (char c)
  373. {
  374. if (string[pos]==0) {
  375. string[pos+1] = 0;
  376. } /* endif */
  377. string[pos] = c;
  378. putch (c);
  379. pos++;
  380. }
  381. void cstredit :: changecursor (void)
  382. {
  383. status *= -1;
  384. if (status==insert) {
  385. _settextcursor (0x0607); // normal underline cursor
  386. } else {
  387. _settextcursor (0x0007); // full block cursor
  388. } /* endif */
  389. }
  390. void cstredit :: setoldstr (void)
  391. {
  392. strcpy (string, *oldstring);
  393. pos = strlen (string);
  394. setcurpos (textpos.x, textpos.y);
  395. for (int i=0; i<maxlength; i++) {
  396. putch (' ');
  397. } /* endfor */
  398. setcurpos (textpos.x, textpos.y);
  399. cprintf (string);
  400. }
  401. void cstredit :: edit (void)
  402. {
  403. char input;
  404. do {
  405. input = getch ();
  406. if ((input!=8) && (input!=0) && (input!=27) && (input!=255) && (input != 13)) {
  407. if ((status == insert) && (strlen(string)<maxlength)) addchar (input);
  408. if ((status != insert) && (pos<maxlength)) overwrite (input);
  409. } /* endif */
  410. if ((input==8) && (pos>0)) {
  411. delchar (left);
  412. } /* endif */
  413. if ((input==27) && (strcmp (string, *oldstring)!=0)) {
  414. setoldstr ();
  415. } /* endif */
  416. if (input==255) {
  417. putch (7);
  418. } /* endif */
  419. if (input==0) {
  420. input = getch ();
  421. if ((input==75) && (pos>0)) pos--;
  422. if ((input==77) && (pos<strlen(string))) pos++;
  423. if (input==71) pos=0;
  424. if (input==79) pos=strlen(string);
  425. setcurpos (textpos.x+pos, textpos.y);
  426. if (input==82) {
  427. changecursor ();
  428. } /* endif */
  429. if ((input==83) && (pos<strlen(string))) {
  430. delchar (right);
  431. } /* endif */
  432. } /* endif */
  433. } while (input != 13); /* enddo */
  434. }
  435. void cstredit :: done ()
  436. {
  437. free (*oldstring);
  438. *oldstring = string;
  439. int length=strlen (string);
  440. setcurpos (textpos.x+length, textpos.y);
  441. printf("\n");
  442. _settextcolor (7);
  443. _setbkcolor (0);
  444. _settextcursor (0x0607); // normal underline cursor
  445. };
  446. /*********************************************************************************************/
  447. /* class cbitselect : Bit-Editor */
  448. /*********************************************************************************************/
  449. void cbitselect :: init (tterrainbits &_bits, char *selection[], char bitnum)
  450. {
  451. int i = 0;
  452. oldbits = &_bits;
  453. bits = _bits;
  454. sel = 0;
  455. quantity = bitnum;
  456. for (i=0; i<quantity+4; i++) printf ("\n");
  457. position = getcurpos ();
  458. position.y -= quantity;
  459. for (i=0; i<quantity; i++) {
  460. _settextposition (position.y+i+1, position.x+5);
  461. _settextcolor (fgcolor);
  462. _setbkcolor (bkcolor);
  463. tterrainbits bts;
  464. if ( i < 32 )
  465. bts.set ( 1 << i, 0 );
  466. else
  467. bts.set ( 0, 1 << ( i - 32));
  468. if (bits & bts) {
  469. _outtext ("[X]");
  470. } else {
  471. _outtext ("[ ]");
  472. } /* endif */
  473. setcurpos (position.x+7, position.y+i);
  474. cprintf (" ÄÄ %s", selection[i]);
  475. } /* endfor */
  476. _settextcursor (0x0007); // full block cursor
  477. setpos (reset);
  478. }
  479. void cbitselect :: setpos (char updown)
  480. {
  481. switch (updown) {
  482. case up:
  483. if (sel>0) {
  484. sel--;
  485. } else {
  486. sel=quantity-1;
  487. } /* endif */
  488. break;
  489. case down:
  490. if (sel<quantity-1) {
  491. sel++;
  492. } else {
  493. sel=0;
  494. } /* endif */
  495. break;
  496. } /* endswitch */
  497. setcurpos (position.x+5, position.y+sel);
  498. }
  499. void cbitselect :: changebit (void)
  500. {
  501. tterrainbits bts;
  502. int i = sel;
  503. if ( i < 32 )
  504. bts.set ( 1 << i, 0 );
  505. else
  506. bts.set ( 0, 1 << ( i - 32));
  507. if (bits & bts) {
  508. bits = bits ^ bts;
  509. cprintf (" ");
  510. } else {
  511. bits = bits | bts;
  512. cprintf ("X");
  513. } /* endif */
  514. setpos (reset);
  515. }
  516. void cbitselect :: setoldbits (void)
  517. {
  518. // if (bits != *oldbits) {
  519. bits = *oldbits;
  520. for (int i=0; i<quantity; i++) {
  521. setcurpos (position.x+5, position.y+i);
  522. tterrainbits bts;
  523. if ( i < 32 )
  524. bts.set ( 1 << i, 0 );
  525. else
  526. bts.set ( 0, 1 << ( i - 32));
  527. if (bits & bts) {
  528. _outtext ("[X]");
  529. } else {
  530. _outtext ("[ ]");
  531. } /* endif */
  532. } /* endfor */
  533. // } /* endif */
  534. setcurpos (position.x+5, position.y+sel);
  535. }
  536. void cbitselect :: select (void)
  537. {
  538. char input;
  539. do {
  540. input = getch ();
  541. if (input==32) changebit ();
  542. if (input==27) setoldbits ();
  543. if (input==0) {
  544. input = getch ();
  545. if (input==72) setpos (up);
  546. if (input==80) setpos (down);
  547. } /* endif */
  548. } while (input != 13); /* enddo */
  549. }
  550. void cbitselect :: done ()
  551. {
  552. setcurpos (0, position.y+quantity);
  553. _settextcursor (0x0607); // normal underline cursor
  554. _settextcolor (7);
  555. _setbkcolor (0);
  556. *oldbits = bits;
  557. }
  558. /*********************************************************************************************/
  559. /* class cyn_switch : YES - NO Schalter */
  560. /*********************************************************************************************/
  561. void cyn_switch :: init (char *s1, char *s2, char v1, char v2, char &_oldvalue)
  562. {
  563. cprintf ("\n\n");
  564. position = getcurpos ();
  565. if (s1[0] != 0) {
  566. strncpy (button[0].string, s1, 13);
  567. button[0].string[13] = 0;
  568. } else {
  569. strcpy (button[0].string, " YES ");
  570. } /* endif */
  571. if (s2[0] != 0) {
  572. strncpy (button[1].string, s2, 13);
  573. button[1].string[13] = 0;
  574. } else {
  575. strcpy (button[1].string, " NO ");
  576. } /* endif */
  577. button[0].value = v1;
  578. button[1].value = v2;
  579. if (v1==v2) {
  580. button[0].value++;
  581. } /* endif */
  582. oldvalue = &_oldvalue;
  583. if (_oldvalue==v1) {
  584. sel = left;
  585. } else {
  586. sel = right;
  587. } /* endif */
  588. paintbutton (left);
  589. paintbutton (right);
  590. _settextcursor (0x2000); // cursor off
  591. }
  592. void cyn_switch :: paintbutton (char pbutton)
  593. {
  594. if (pbutton==sel) {
  595. _settextcolor(fgcolor);
  596. _setbkcolor(bkcolor);
  597. } else {
  598. _settextcolor(8);
  599. _setbkcolor(0);
  600. } /* endif */
  601. if (pbutton==left) {
  602. _settextposition (position.y, 10);
  603. _outtext (button[0].string);
  604. } else {
  605. _settextposition (position.y, 35);
  606. _outtext (button[1].string);
  607. } /* endif */
  608. }
  609. void cyn_switch :: select (void)
  610. {
  611. char input;
  612. do {
  613. input = getch ();
  614. if (input == 0) {
  615. input = getch();
  616. if ((input==75) && (sel != left)) {
  617. sel=left;
  618. paintbutton (left);
  619. paintbutton (right);
  620. } /* endif */
  621. if ((input==77) && (sel != right)) {
  622. sel=right;
  623. paintbutton (left);
  624. paintbutton (right);
  625. } /* endif */
  626. } /* endif */
  627. } while (input != 13); /* enddo */
  628. }
  629. void cyn_switch :: done (void)
  630. {
  631. _settextcolor(7);
  632. _setbkcolor(0);
  633. _settextcursor (0x0607); // normal underline cursor
  634. setcurpos (79, position.y);
  635. cprintf ("\n");
  636. *oldvalue = button[sel].value;
  637. }
  638. #define num_odf 45 // Anzahl der angezeigten dateien (20 bei 25 zeilen-modus)
  639. /*********************************************************************************************/
  640. /* class cfileselect : dateimen */
  641. /*********************************************************************************************/
  642. void cfileselect :: init (char *searchstr, unsigned attributes)
  643. {
  644. search_files (searchstr, attributes);
  645. if (quantity>0) {
  646. position = 0;
  647. sel = 0;
  648. if (quantity>=num_odf) {
  649. maxposition = quantity-num_odf;
  650. maxsel = num_odf-1;
  651. } else {
  652. maxposition = 0;
  653. maxsel = quantity -1;
  654. } /* endif */
  655. clearscreen ();
  656. sort (sortname);
  657. setcurpos (0,0);
  658. printf (" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n");
  659. printf (" filename size date time \n");
  660. printf (" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n");
  661. displayallfiles ();
  662. printf (" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n");
  663. cprintf (" %3i files of %-12s ", quantity, searchstr);
  664. _settextcursor (0x2000); // cursor off
  665. bar (on);
  666. } /* endif */
  667. };
  668. void cfileselect :: search_files (char *searchstr, unsigned attributes)
  669. {
  670. quantity = 0;
  671. { // count
  672. tfindfile ff ( searchstr );
  673. string filename = ff.getnextname();
  674. while( !filename.empty() ) {
  675. quantity++;
  676. filename = ff.getnextname();
  677. }
  678. }
  679. if (quantity>0) {
  680. int i=0;
  681. file = new tfile[quantity];
  682. tfindfile ff ( searchstr );
  683. string filename = ff.getnextname();
  684. while( !filename.empty() ) {
  685. strcpy (file[i].name, filename.c_str() );
  686. /*
  687. file[i].size = fileinfo.size;
  688. file[i].date = fileinfo.wr_date;
  689. file[i].time = fileinfo.wr_time;
  690. */
  691. file[i].size = 0;
  692. file[i].date = 0;
  693. file[i].time = 0;
  694. i++;
  695. filename = ff.getnextname();
  696. }
  697. } /* endif */
  698. }
  699. void cfileselect :: displayallfiles (void)
  700. {
  701. char string[100];
  702. setcurpos (0,3);
  703. for (long i=position; i<position+num_odf; i++) {
  704. if (i<quantity) {
  705. getinfostr (string, i);
  706. printf (" %s", string);
  707. } else {
  708. printf ("\n");
  709. } /* endif */
  710. } /* endfor */
  711. }
  712. void cfileselect :: getinfostr (char *displaystr, long filenum)
  713. {
  714. if (filenum<quantity) {
  715. int day, month, year;
  716. int min, hour, sec;
  717. unpack_date (file[filenum].date, day, month, year);
  718. unpack_time (file[filenum].time, sec, min, hour);
  719. char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
  720. _splitpath (file[filenum].name, drive, dir, fname, ext );
  721. sprintf (displaystr, " %-8s%-4s %10ld %2i.%2i.%4i %2i:%2i \n", fname, ext, file[filenum].size, day, month, year, hour,min );
  722. } else {
  723. strcpy (displaystr, "");
  724. } /* endif */
  725. }
  726. void cfileselect :: bar (char onoff)
  727. {
  728. if (onoff==on) {
  729. _settextcolor (fgcolor);
  730. _setbkcolor (bkcolor);
  731. } else {
  732. _settextcolor (7);
  733. _setbkcolor (0);
  734. } /* endif */
  735. char string[80];
  736. getinfostr (string, sel+position);
  737. _settextposition (4+sel, 2);
  738. _outtext (string);
  739. }
  740. void cfileselect :: sort (char option)
  741. {
  742. tfile *sortfile = (tfile*) malloc (sizeof(tfile)*quantity);
  743. char lastname[13] = "";
  744. char foundname[13] = "ţţţţţţţţţţţţ";
  745. long lastdate = max_long;
  746. long founddate = 0;
  747. for (long _new=0; _new<quantity; _new++) {
  748. long found;
  749. for (long searcher=0; searcher<quantity; searcher++) {
  750. int cond1, cond2;
  751. if (option==sortname) {
  752. cond1 = strcmp (file[searcher].name, lastname);
  753. cond2 = strcmp (foundname, file[searcher].name);
  754. } else {
  755. cond1 = lastdate >= file[searcher].date * 100000 + file[searcher].time;
  756. cond2 = founddate <= file[searcher].date * 100000 + file[searcher].time;
  757. } /* endif */
  758. if ((cond1 == 1) && (cond2 == 1)) {
  759. found = searcher;
  760. strcpy (foundname, file[found].name);
  761. founddate = file[searcher].date * 100000 + file[searcher].time;
  762. } /* endif */
  763. } /* endfor */
  764. strcpy (sortfile[_new].name, file[found].name);
  765. sortfile[_new].size = file[found].size;
  766. sortfile[_new].date = file[found].date;
  767. sortfile[_new].time = file[found].time;
  768. strcpy (file[found].name, ""); // dateiinfos werden "entwertet"
  769. file[found].date = 65535; // dateiinfos werden "entwertet"
  770. strcpy (lastname, foundname);
  771. strcpy (foundname, "ţţţţţţţţţţţţ");
  772. lastdate = founddate;
  773. founddate = 0;
  774. } /* endfor */
  775. free (file);
  776. file = sortfile;
  777. _settextcolor (fgcolor);
  778. _setbkcolor (0);
  779. if (option==sortname) {
  780. _settextposition (2,5);
  781. _outtext ("filename");
  782. _settextcolor (7);
  783. _settextposition (2,37);
  784. _outtext ("date");
  785. sortstatus = sortname;
  786. } else {
  787. _settextposition (2,37);
  788. _outtext ("date");
  789. _settextcolor (7);
  790. _settextposition (2,5);
  791. _outtext ("filename");
  792. sortstatus = sorttime;
  793. } /* endif */
  794. }
  795. void cfileselect :: select (void)
  796. {
  797. if (quantity>0) {
  798. char input;
  799. do {
  800. input = getch ();
  801. if ((toupper(input) == 'N') && (sortstatus != sortname)) { // left key
  802. sort (sortname);
  803. displayallfiles ();
  804. } /* endif */
  805. if ((toupper(input) == 'D') && (sortstatus != sorttime)) { // right key
  806. sort (sorttime);
  807. displayallfiles ();
  808. } /* endif */
  809. if (input==0) {
  810. input = getch ();
  811. if (input==72) { // up key
  812. if (sel>0) {
  813. bar (off);
  814. sel--;
  815. bar (on);
  816. } else {
  817. if (position>0) {
  818. position--;
  819. displayallfiles ();
  820. } /* endif */
  821. } /* endif */
  822. } /* endif */
  823. if (input==80) { // down key
  824. if (sel<maxsel) {
  825. bar (off);
  826. sel++;
  827. bar (on);
  828. } else {
  829. if (position<maxposition) {
  830. position++;
  831. displayallfiles ();
  832. } /* endif */
  833. } /* endif */
  834. } /* endif */
  835. if (input==71) { // pos1
  836. if (sel != 0) {
  837. bar (off);
  838. sel=0;
  839. bar (on);
  840. } /* endif */
  841. if (position>0) {
  842. position=0;
  843. displayallfiles ();
  844. } /* endif */
  845. } /* endif */
  846. if (input==79) { //ende
  847. if (sel != maxsel) {
  848. bar (off);
  849. sel=maxsel;
  850. bar (on);
  851. } /* endif */
  852. if (position != maxposition) {
  853. position = maxposition;
  854. displayallfiles ();
  855. } /* endif */
  856. } /* endif */
  857. if (input==73) { //Bild up
  858. if (position>0) {
  859. if (position>=num_odf) {
  860. position -= num_odf;
  861. } else {
  862. position = 0;
  863. } /* endif */
  864. displayallfiles ();
  865. } else {
  866. if (sel>0) {
  867. bar (off);
  868. sel=0;
  869. bar (on);
  870. } /* endif */
  871. } /* endif */
  872. } /* endif */
  873. if (input==81) { //Bild down
  874. if (position<maxposition) {
  875. if (position<=maxposition-num_odf) {
  876. position += num_odf;
  877. } else {
  878. position = maxposition;
  879. } /* endif */
  880. displayallfiles ();
  881. } else {
  882. if (sel<maxsel) {
  883. bar (off);
  884. sel=maxsel;
  885. bar (on);
  886. } /* endif */
  887. } /* endif */
  888. } /* endif */
  889. if ((input==75) && (sortstatus != sortname)) { // left key
  890. sort (sortname);
  891. displayallfiles ();
  892. } /* endif */
  893. if ((input==77) && (sortstatus != sorttime)) { // right key
  894. sort (sorttime);
  895. displayallfiles ();
  896. } /* endif */
  897. } /* endif input == 0 */
  898. } while (input != 13); /* enddo */
  899. } else {
  900. printf ("\n cfileselect - Error : no files found ! \n");
  901. putch (7);
  902. char terminate=1;
  903. yn_switch (" CONTINUE ", " TERMINATE ", 0,1, terminate);
  904. if (terminate==1) exit (1);
  905. } /* endif */
  906. }
  907. void cfileselect :: done (tfile &selected_file)
  908. {
  909. if (quantity>0) {
  910. strcpy (selected_file.name, file[position+sel].name);
  911. selected_file.size = file[position+sel].size;
  912. selected_file.date = file[position+sel].date;
  913. selected_file.time = file[position+sel].time;
  914. free (file);
  915. _settextcolor (7);
  916. _setbkcolor (0);
  917. _settextcursor (0x0607); // normal underline cursor
  918. clearscreen ();
  919. } else {
  920. strcpy (selected_file.name, "");
  921. selected_file.size = 0;
  922. selected_file.date = 0;
  923. selected_file.time = 0;
  924. } /* endif */
  925. }
  926. /*
  927. //------------------------------------------------------------------------------
  928. void settxtmode33;
  929. char z12 [255,11];
  930. char z14 [255,13];
  931. char a;
  932. var az12:z12;pz14:^z14;a:byte;r: registers ;pz12:pointer;
  933. {
  934. r.ax:=$1130;
  935. r.bh:=2;
  936. intr($10,r);
  937. pz14:=ptr(r.es,r.bp);
  938. for a:=0 to 255 do move(pz14^[a,1],az12[a,0],12);
  939. pz12:=@az12;
  940. asm
  941. push bp
  942. mov ax,$1110
  943. mov bx,$0C00
  944. mov cx,256
  945. mov dx,0
  946. les bp,pz12
  947. int $10
  948. pop bp
  949. end;
  950. };
  951. //------------------------------------------------------------------------------
  952. */
  953. /*
  954. boolean AnhangTest(char * s,
  955. Byte i)
  956. {
  957. int * untyped file * F1;
  958. Byte Counter;
  959. Char c;
  960. int size;
  961. Integer i2;
  962. return false;
  963. size = 0;
  964. assign(F1,paramstr(0));
  965. reset(&F1,1);
  966. for (i2 = 1; i2 <= i; i2++) {
  967. Counter = 0;
  968. do {
  969. BlockRead(F1,c,1);
  970. if (c == '') inc(Counter);
  971. else Counter = 0;
  972. inc(size);
  973. } while (!((Counter == 10) || (size > FileSize(F1))));
  974. if (Counter == 10)
  975. return true;
  976. else {
  977. return false;
  978. fclose(F1);
  979. return;
  980. }
  981. }
  982. fclose(F1);
  983. }
  984. void Anhaengen(char * s,
  985. Byte Pos)
  986. {
  987. int * untyped file / F1, F2, F3;
  988. Pointer p;
  989. Word NumRead, NumWritten;
  990. if (AnhangTest(s,Pos) == false) {
  991. GetMem(p,500);
  992. assign(F3,paramstr(0));
  993. assign(F2,s);
  994. assign(F1,paramstr(0));
  995. Rename(F3,"*.tmp");
  996. reset(&F2);
  997. rewrite(&F1);
  998. do {
  999. BlockRead(F3,*p,500,NumRead);
  1000. BlockWrite(F1,*p,NumRead,NumWritten);
  1001. } while (!((NumRead == 0) || (NumWritten != NumRead)));
  1002. fclose(F3);
  1003. sbld(s,"%s",s);
  1004. BlockWrite(F1,s,22);
  1005. do {
  1006. BlockRead(F2,*p,500,NumRead);
  1007. BlockWrite(F1,*p,NumRead,NumWritten);
  1008. } while (!((NumRead == 0) || (NumWritten != NumRead)));
  1009. }
  1010. }
  1011. */
  1012. void settxt50mode ( void )
  1013. {
  1014. /*
  1015. ah = 11
  1016. al = 12
  1017. bl = 0
  1018. int 10
  1019. */
  1020. REGS regs;
  1021. regs.w.ax = 0x3;
  1022. int386 ( 0x10, &regs, &regs );
  1023. regs.w.ax = 0x1112;
  1024. regs.w.bx = 0x0;
  1025. int386 ( 0x10, &regs, &regs );
  1026. /*
  1027. regs.w.ax = 0x1202;
  1028. regs.w.bx = 0x30;
  1029. int386 ( 0x10, &regs, &regs );
  1030. regs.w.ax = 0x03;
  1031. int386 ( 0x10, &regs, &regs );
  1032. regs.w.ax = 0x1112;
  1033. int386 ( 0x10, &regs, &regs );
  1034. */
  1035. /* initsvga ( 0x108 ); */
  1036. }
  1037. void terrainaccess_ed ( TerrainAccess* ft, char* name )
  1038. {
  1039. printf ("\n Terrain the %s can drive on / be build on \n"
  1040. " (for many %ss it is enough to specify only this field): \n", name, name );
  1041. bitselect (ft->terrain, cbodenarten, cbodenartennum);
  1042. printf ("\n ALL these selected terrain-bits are necessary for the %s to drive / be build there : \n", name);
  1043. bitselect (ft->terrainreq, cbodenarten, cbodenartennum);
  1044. printf ("\n NONE of these bits must be set for the %s to drive / be build there\n"
  1045. " if you are creating a vehicle: \n"
  1046. " all ships (except icebreaker) must have the ice/snow bits set here) \n", name);
  1047. bitselect (ft->terrainnot, cbodenarten, cbodenartennum);
  1048. printf ("\n the %s dies on ... ( only if it cannot enter, see enntries above): \n"
  1049. " most land based %ss should have the water-bits set here \n", name, name);
  1050. bitselect (ft->terrainkill, cbodenarten, cbodenartennum);
  1051. }
  1052. #if 0
  1053. void fatalError ( const char* formatstring, ... )
  1054. {
  1055. va_list paramlist;
  1056. va_start ( paramlist, formatstring );
  1057. char tempbuf[1000];
  1058. int lng = vsprintf( tempbuf, formatstring, paramlist );
  1059. va_end ( paramlist );
  1060. fprintf(stderr, tempbuf );
  1061. exit(1);
  1062. }
  1063. #endif