🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1603 lines
40 KiB

  1. /**
  2. * Test program for PhysicsFS. May only work on Unix.
  3. *
  4. * Please see the file LICENSE.txt in the source's root directory.
  5. *
  6. * This file written by Ryan C. Gordon.
  7. */
  8. #define _CRT_SECURE_NO_WARNINGS 1
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <errno.h>
  12. #include <string.h>
  13. #if (defined __MWERKS__)
  14. #include <SIOUX.h>
  15. #endif
  16. #if (defined PHYSFS_HAVE_READLINE)
  17. #include <unistd.h>
  18. #include <readline/readline.h>
  19. #include <readline/history.h>
  20. #endif
  21. #include <time.h>
  22. /* Define this, so the compiler doesn't complain about using old APIs. */
  23. #define PHYSFS_DEPRECATED
  24. #include "physfs.h"
  25. #define TEST_VERSION_MAJOR 3
  26. #define TEST_VERSION_MINOR 0
  27. #define TEST_VERSION_PATCH 2
  28. static FILE *history_file = NULL;
  29. static PHYSFS_uint32 do_buffer_size = 0;
  30. static void output_versions(void)
  31. {
  32. PHYSFS_Version compiled;
  33. PHYSFS_Version linked;
  34. PHYSFS_VERSION(&compiled);
  35. PHYSFS_getLinkedVersion(&linked);
  36. printf("test_physfs version %d.%d.%d.\n"
  37. " Compiled against PhysicsFS version %d.%d.%d,\n"
  38. " and linked against %d.%d.%d.\n\n",
  39. TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH,
  40. (int) compiled.major, (int) compiled.minor, (int) compiled.patch,
  41. (int) linked.major, (int) linked.minor, (int) linked.patch);
  42. } /* output_versions */
  43. static void output_archivers(void)
  44. {
  45. const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
  46. const PHYSFS_ArchiveInfo **i;
  47. printf("Supported archive types:\n");
  48. if (*rc == NULL)
  49. printf(" * Apparently, NONE!\n");
  50. else
  51. {
  52. for (i = rc; *i != NULL; i++)
  53. {
  54. printf(" * %s: %s\n Written by %s.\n %s\n",
  55. (*i)->extension, (*i)->description,
  56. (*i)->author, (*i)->url);
  57. printf(" %s symbolic links.\n",
  58. (*i)->supportsSymlinks ? "Supports" : "Does not support");
  59. } /* for */
  60. } /* else */
  61. printf("\n");
  62. } /* output_archivers */
  63. static int cmd_quit(char *args)
  64. {
  65. return 0;
  66. } /* cmd_quit */
  67. static int cmd_init(char *args)
  68. {
  69. if (*args == '\"')
  70. {
  71. args++;
  72. args[strlen(args) - 1] = '\0';
  73. } /* if */
  74. if (PHYSFS_init(args))
  75. printf("Successful.\n");
  76. else
  77. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  78. return 1;
  79. } /* cmd_init */
  80. static int cmd_deinit(char *args)
  81. {
  82. if (PHYSFS_deinit())
  83. printf("Successful.\n");
  84. else
  85. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  86. return 1;
  87. } /* cmd_deinit */
  88. static int cmd_addarchive(char *args)
  89. {
  90. char *ptr = strrchr(args, ' ');
  91. int appending = atoi(ptr + 1);
  92. *ptr = '\0';
  93. if (*args == '\"')
  94. {
  95. args++;
  96. *(ptr - 1) = '\0';
  97. } /* if */
  98. /*printf("[%s], [%d]\n", args, appending);*/
  99. if (PHYSFS_mount(args, NULL, appending))
  100. printf("Successful.\n");
  101. else
  102. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  103. return 1;
  104. } /* cmd_addarchive */
  105. /* wrap free() to avoid calling convention wankery. */
  106. static void freeBuf(void *buf)
  107. {
  108. free(buf);
  109. } /* freeBuf */
  110. typedef enum
  111. {
  112. MNTTYPE_PATH,
  113. MNTTYPE_MEMORY,
  114. MNTTYPE_HANDLE
  115. } MountType;
  116. static int cmd_mount_internal(char *args, const MountType mnttype)
  117. {
  118. char *ptr;
  119. char *mntpoint = NULL;
  120. int appending = 0;
  121. int rc = 0;
  122. if (*args == '\"')
  123. {
  124. args++;
  125. ptr = strchr(args, '\"');
  126. if (ptr == NULL)
  127. {
  128. printf("missing string terminator in argument.\n");
  129. return 1;
  130. } /* if */
  131. *(ptr) = '\0';
  132. } /* if */
  133. else
  134. {
  135. ptr = strchr(args, ' ');
  136. *ptr = '\0';
  137. } /* else */
  138. mntpoint = ptr + 1;
  139. if (*mntpoint == '\"')
  140. {
  141. mntpoint++;
  142. ptr = strchr(mntpoint, '\"');
  143. if (ptr == NULL)
  144. {
  145. printf("missing string terminator in argument.\n");
  146. return 1;
  147. } /* if */
  148. *(ptr) = '\0';
  149. } /* if */
  150. else
  151. {
  152. ptr = strchr(mntpoint, ' ');
  153. *(ptr) = '\0';
  154. } /* else */
  155. appending = atoi(ptr + 1);
  156. /*printf("[%s], [%s], [%d]\n", args, mntpoint, appending);*/
  157. if (mnttype == MNTTYPE_PATH)
  158. rc = PHYSFS_mount(args, mntpoint, appending);
  159. else if (mnttype == MNTTYPE_HANDLE)
  160. {
  161. PHYSFS_File *f = PHYSFS_openRead(args);
  162. if (f == NULL)
  163. {
  164. printf("PHYSFS_openRead('%s') failed. reason: %s.\n", args, PHYSFS_getLastError());
  165. return 1;
  166. } /* if */
  167. rc = PHYSFS_mountHandle(f, args, mntpoint, appending);
  168. if (!rc)
  169. PHYSFS_close(f);
  170. } /* else if */
  171. else if (mnttype == MNTTYPE_MEMORY)
  172. {
  173. FILE *in = fopen(args, "rb");
  174. void *buf = NULL;
  175. long len = 0;
  176. if (in == NULL)
  177. {
  178. printf("Failed to open %s to read into memory: %s.\n", args, strerror(errno));
  179. return 1;
  180. } /* if */
  181. if ( (fseek(in, 0, SEEK_END) != 0) || ((len = ftell(in)) < 0) )
  182. {
  183. printf("Failed to find size of %s to read into memory: %s.\n", args, strerror(errno));
  184. fclose(in);
  185. return 1;
  186. } /* if */
  187. buf = malloc(len);
  188. if (buf == NULL)
  189. {
  190. printf("Failed to allocate space to read %s into memory: %s.\n", args, strerror(errno));
  191. fclose(in);
  192. return 1;
  193. } /* if */
  194. if ((fseek(in, 0, SEEK_SET) != 0) || (fread(buf, len, 1, in) != 1))
  195. {
  196. printf("Failed to read %s into memory: %s.\n", args, strerror(errno));
  197. fclose(in);
  198. free(buf);
  199. return 1;
  200. } /* if */
  201. fclose(in);
  202. rc = PHYSFS_mountMemory(buf, len, freeBuf, args, mntpoint, appending);
  203. } /* else */
  204. if (rc)
  205. printf("Successful.\n");
  206. else
  207. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  208. return 1;
  209. } /* cmd_mount_internal */
  210. static int cmd_mount(char *args)
  211. {
  212. return cmd_mount_internal(args, MNTTYPE_PATH);
  213. } /* cmd_mount */
  214. static int cmd_mount_mem(char *args)
  215. {
  216. return cmd_mount_internal(args, MNTTYPE_MEMORY);
  217. } /* cmd_mount_mem */
  218. static int cmd_mount_handle(char *args)
  219. {
  220. return cmd_mount_internal(args, MNTTYPE_HANDLE);
  221. } /* cmd_mount_handle */
  222. static int cmd_getmountpoint(char *args)
  223. {
  224. if (*args == '\"')
  225. {
  226. args++;
  227. args[strlen(args) - 1] = '\0';
  228. } /* if */
  229. printf("Dir [%s] is mounted at [%s].\n", args, PHYSFS_getMountPoint(args));
  230. return 1;
  231. } /* cmd_getmountpoint */
  232. static int cmd_removearchive(char *args)
  233. {
  234. if (*args == '\"')
  235. {
  236. args++;
  237. args[strlen(args) - 1] = '\0';
  238. } /* if */
  239. if (PHYSFS_unmount(args))
  240. printf("Successful.\n");
  241. else
  242. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  243. return 1;
  244. } /* cmd_removearchive */
  245. static int cmd_enumerate(char *args)
  246. {
  247. char **rc;
  248. if (*args == '\"')
  249. {
  250. args++;
  251. args[strlen(args) - 1] = '\0';
  252. } /* if */
  253. rc = PHYSFS_enumerateFiles(args);
  254. if (rc == NULL)
  255. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  256. else
  257. {
  258. int file_count;
  259. char **i;
  260. for (i = rc, file_count = 0; *i != NULL; i++, file_count++)
  261. printf("%s\n", *i);
  262. printf("\n total (%d) files.\n", file_count);
  263. PHYSFS_freeList(rc);
  264. } /* else */
  265. return 1;
  266. } /* cmd_enumerate */
  267. static int cmd_getdirsep(char *args)
  268. {
  269. printf("Directory separator is [%s].\n", PHYSFS_getDirSeparator());
  270. return 1;
  271. } /* cmd_getdirsep */
  272. static int cmd_getlasterror(char *args)
  273. {
  274. printf("last error is [%s].\n", PHYSFS_getLastError());
  275. return 1;
  276. } /* cmd_getlasterror */
  277. static int cmd_getcdromdirs(char *args)
  278. {
  279. char **rc = PHYSFS_getCdRomDirs();
  280. if (rc == NULL)
  281. printf("Failure. Reason: [%s].\n", PHYSFS_getLastError());
  282. else
  283. {
  284. int dir_count;
  285. char **i;
  286. for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
  287. printf("%s\n", *i);
  288. printf("\n total (%d) drives.\n", dir_count);
  289. PHYSFS_freeList(rc);
  290. } /* else */
  291. return 1;
  292. } /* cmd_getcdromdirs */
  293. static int cmd_getsearchpath(char *args)
  294. {
  295. char **rc = PHYSFS_getSearchPath();
  296. if (rc == NULL)
  297. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  298. else
  299. {
  300. int dir_count;
  301. char **i;
  302. for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
  303. printf("%s\n", *i);
  304. printf("\n total (%d) directories.\n", dir_count);
  305. PHYSFS_freeList(rc);
  306. } /* else */
  307. return 1;
  308. } /* cmd_getcdromdirs */
  309. static int cmd_getbasedir(char *args)
  310. {
  311. printf("Base dir is [%s].\n", PHYSFS_getBaseDir());
  312. return 1;
  313. } /* cmd_getbasedir */
  314. static int cmd_getuserdir(char *args)
  315. {
  316. printf("User dir is [%s].\n", PHYSFS_getUserDir());
  317. return 1;
  318. } /* cmd_getuserdir */
  319. static int cmd_getprefdir(char *args)
  320. {
  321. char *org;
  322. char *appName;
  323. char *ptr = args;
  324. org = ptr;
  325. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
  326. printf("Pref dir is [%s].\n", PHYSFS_getPrefDir(org, appName));
  327. return 1;
  328. } /* cmd_getprefdir */
  329. static int cmd_getwritedir(char *args)
  330. {
  331. printf("Write dir is [%s].\n", PHYSFS_getWriteDir());
  332. return 1;
  333. } /* cmd_getwritedir */
  334. static int cmd_setwritedir(char *args)
  335. {
  336. if (*args == '\"')
  337. {
  338. args++;
  339. args[strlen(args) - 1] = '\0';
  340. } /* if */
  341. if (PHYSFS_setWriteDir(args))
  342. printf("Successful.\n");
  343. else
  344. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  345. return 1;
  346. } /* cmd_setwritedir */
  347. static int cmd_permitsyms(char *args)
  348. {
  349. int num;
  350. if (*args == '\"')
  351. {
  352. args++;
  353. args[strlen(args) - 1] = '\0';
  354. } /* if */
  355. num = atoi(args);
  356. PHYSFS_permitSymbolicLinks(num);
  357. printf("Symlinks are now %s.\n", num ? "permitted" : "forbidden");
  358. return 1;
  359. } /* cmd_permitsyms */
  360. static int cmd_setbuffer(char *args)
  361. {
  362. if (*args == '\"')
  363. {
  364. args++;
  365. args[strlen(args) - 1] = '\0';
  366. } /* if */
  367. do_buffer_size = (unsigned int) atoi(args);
  368. if (do_buffer_size)
  369. {
  370. printf("Further tests will set a (%lu) size buffer.\n",
  371. (unsigned long) do_buffer_size);
  372. } /* if */
  373. else
  374. {
  375. printf("Further tests will NOT use a buffer.\n");
  376. } /* else */
  377. return 1;
  378. } /* cmd_setbuffer */
  379. static int cmd_stressbuffer(char *args)
  380. {
  381. int num;
  382. if (*args == '\"')
  383. {
  384. args++;
  385. args[strlen(args) - 1] = '\0';
  386. } /* if */
  387. num = atoi(args);
  388. if (num < 0)
  389. printf("buffer must be greater than or equal to zero.\n");
  390. else
  391. {
  392. PHYSFS_File *f;
  393. int rndnum;
  394. printf("Stress testing with (%d) byte buffer...\n", num);
  395. f = PHYSFS_openWrite("test.txt");
  396. if (f == NULL)
  397. printf("Couldn't open test.txt for writing: %s.\n", PHYSFS_getLastError());
  398. else
  399. {
  400. int i, j;
  401. char buf[37];
  402. char buf2[37];
  403. if (!PHYSFS_setBuffer(f, num))
  404. {
  405. printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
  406. PHYSFS_close(f);
  407. PHYSFS_delete("test.txt");
  408. return 1;
  409. } /* if */
  410. strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789");
  411. srand((unsigned int) time(NULL));
  412. for (i = 0; i < 10; i++)
  413. {
  414. for (j = 0; j < 10000; j++)
  415. {
  416. PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
  417. PHYSFS_uint32 left = 36 - right;
  418. if (PHYSFS_writeBytes(f, buf, left) != left)
  419. {
  420. printf("PHYSFS_writeBytes() failed: %s.\n", PHYSFS_getLastError());
  421. PHYSFS_close(f);
  422. return 1;
  423. } /* if */
  424. rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
  425. if (rndnum == 42)
  426. {
  427. if (!PHYSFS_flush(f))
  428. {
  429. printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
  430. PHYSFS_close(f);
  431. return 1;
  432. } /* if */
  433. } /* if */
  434. if (PHYSFS_writeBytes(f, buf + left, right) != right)
  435. {
  436. printf("PHYSFS_writeBytes() failed: %s.\n", PHYSFS_getLastError());
  437. PHYSFS_close(f);
  438. return 1;
  439. } /* if */
  440. rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
  441. if (rndnum == 42)
  442. {
  443. if (!PHYSFS_flush(f))
  444. {
  445. printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
  446. PHYSFS_close(f);
  447. return 1;
  448. } /* if */
  449. } /* if */
  450. } /* for */
  451. if (!PHYSFS_flush(f))
  452. {
  453. printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
  454. PHYSFS_close(f);
  455. return 1;
  456. } /* if */
  457. } /* for */
  458. if (!PHYSFS_close(f))
  459. {
  460. printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
  461. return 1; /* oh well. */
  462. } /* if */
  463. printf(" ... test file written ...\n");
  464. f = PHYSFS_openRead("test.txt");
  465. if (f == NULL)
  466. {
  467. printf("Failed to reopen stress file for reading: %s.\n", PHYSFS_getLastError());
  468. return 1;
  469. } /* if */
  470. if (!PHYSFS_setBuffer(f, num))
  471. {
  472. printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
  473. PHYSFS_close(f);
  474. return 1;
  475. } /* if */
  476. for (i = 0; i < 10; i++)
  477. {
  478. for (j = 0; j < 10000; j++)
  479. {
  480. PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
  481. PHYSFS_uint32 left = 36 - right;
  482. if (PHYSFS_readBytes(f, buf2, left) != left)
  483. {
  484. printf("PHYSFS_readBytes() failed: %s.\n", PHYSFS_getLastError());
  485. PHYSFS_close(f);
  486. return 1;
  487. } /* if */
  488. rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
  489. if (rndnum == 42)
  490. {
  491. if (!PHYSFS_flush(f))
  492. {
  493. printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
  494. PHYSFS_close(f);
  495. return 1;
  496. } /* if */
  497. } /* if */
  498. if (PHYSFS_readBytes(f, buf2 + left, right) != right)
  499. {
  500. printf("PHYSFS_readBytes() failed: %s.\n", PHYSFS_getLastError());
  501. PHYSFS_close(f);
  502. return 1;
  503. } /* if */
  504. rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
  505. if (rndnum == 42)
  506. {
  507. if (!PHYSFS_flush(f))
  508. {
  509. printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
  510. PHYSFS_close(f);
  511. return 1;
  512. } /* if */
  513. } /* if */
  514. if (memcmp(buf, buf2, 36) != 0)
  515. {
  516. printf("readback is mismatched on iterations (%d, %d).\n", i, j);
  517. printf("wanted: [");
  518. for (i = 0; i < 36; i++)
  519. printf("%c", buf[i]);
  520. printf("]\n");
  521. printf(" got: [");
  522. for (i = 0; i < 36; i++)
  523. printf("%c", buf2[i]);
  524. printf("]\n");
  525. PHYSFS_close(f);
  526. return 1;
  527. } /* if */
  528. } /* for */
  529. if (!PHYSFS_flush(f))
  530. {
  531. printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
  532. PHYSFS_close(f);
  533. return 1;
  534. } /* if */
  535. } /* for */
  536. printf(" ... test file read ...\n");
  537. if (!PHYSFS_eof(f))
  538. printf("PHYSFS_eof() returned true! That's wrong.\n");
  539. if (!PHYSFS_close(f))
  540. {
  541. printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
  542. return 1; /* oh well. */
  543. } /* if */
  544. PHYSFS_delete("test.txt");
  545. printf("stress test completed successfully.\n");
  546. } /* else */
  547. } /* else */
  548. return 1;
  549. } /* cmd_stressbuffer */
  550. static int cmd_setsaneconfig(char *args)
  551. {
  552. char *org;
  553. char *appName;
  554. char *arcExt;
  555. int inclCD;
  556. int arcsFirst;
  557. char *ptr = args;
  558. /* ugly. */
  559. org = ptr;
  560. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
  561. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; arcExt = ptr;
  562. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt);
  563. arcsFirst = atoi(ptr);
  564. if (strcmp(arcExt, "!") == 0)
  565. arcExt = NULL;
  566. if (PHYSFS_setSaneConfig(org, appName, arcExt, inclCD, arcsFirst))
  567. printf("Successful.\n");
  568. else
  569. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  570. return 1;
  571. } /* cmd_setsaneconfig */
  572. static int cmd_mkdir(char *args)
  573. {
  574. if (*args == '\"')
  575. {
  576. args++;
  577. args[strlen(args) - 1] = '\0';
  578. } /* if */
  579. if (PHYSFS_mkdir(args))
  580. printf("Successful.\n");
  581. else
  582. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  583. return 1;
  584. } /* cmd_mkdir */
  585. static int cmd_delete(char *args)
  586. {
  587. if (*args == '\"')
  588. {
  589. args++;
  590. args[strlen(args) - 1] = '\0';
  591. } /* if */
  592. if (PHYSFS_delete(args))
  593. printf("Successful.\n");
  594. else
  595. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  596. return 1;
  597. } /* cmd_delete */
  598. static int cmd_getrealdir(char *args)
  599. {
  600. const char *rc;
  601. if (*args == '\"')
  602. {
  603. args++;
  604. args[strlen(args) - 1] = '\0';
  605. } /* if */
  606. rc = PHYSFS_getRealDir(args);
  607. if (rc)
  608. printf("Found at [%s].\n", rc);
  609. else
  610. printf("Not found.\n");
  611. return 1;
  612. } /* cmd_getrealdir */
  613. static int cmd_exists(char *args)
  614. {
  615. int rc;
  616. if (*args == '\"')
  617. {
  618. args++;
  619. args[strlen(args) - 1] = '\0';
  620. } /* if */
  621. rc = PHYSFS_exists(args);
  622. printf("File %sexists.\n", rc ? "" : "does not ");
  623. return 1;
  624. } /* cmd_exists */
  625. static int cmd_isdir(char *args)
  626. {
  627. PHYSFS_Stat statbuf;
  628. int rc;
  629. if (*args == '\"')
  630. {
  631. args++;
  632. args[strlen(args) - 1] = '\0';
  633. } /* if */
  634. rc = PHYSFS_stat(args, &statbuf);
  635. if (rc)
  636. rc = (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY);
  637. printf("File %s a directory.\n", rc ? "is" : "is NOT");
  638. return 1;
  639. } /* cmd_isdir */
  640. static int cmd_issymlink(char *args)
  641. {
  642. PHYSFS_Stat statbuf;
  643. int rc;
  644. if (*args == '\"')
  645. {
  646. args++;
  647. args[strlen(args) - 1] = '\0';
  648. } /* if */
  649. rc = PHYSFS_stat(args, &statbuf);
  650. if (rc)
  651. rc = (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK);
  652. printf("File %s a symlink.\n", rc ? "is" : "is NOT");
  653. return 1;
  654. } /* cmd_issymlink */
  655. static int cmd_cat(char *args)
  656. {
  657. PHYSFS_File *f;
  658. if (*args == '\"')
  659. {
  660. args++;
  661. args[strlen(args) - 1] = '\0';
  662. } /* if */
  663. f = PHYSFS_openRead(args);
  664. if (f == NULL)
  665. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  666. else
  667. {
  668. if (do_buffer_size)
  669. {
  670. if (!PHYSFS_setBuffer(f, do_buffer_size))
  671. {
  672. printf("failed to set file buffer. Reason: [%s].\n",
  673. PHYSFS_getLastError());
  674. PHYSFS_close(f);
  675. return 1;
  676. } /* if */
  677. } /* if */
  678. while (1)
  679. {
  680. char buffer[128];
  681. PHYSFS_sint64 rc;
  682. PHYSFS_sint64 i;
  683. rc = PHYSFS_readBytes(f, buffer, sizeof (buffer));
  684. for (i = 0; i < rc; i++)
  685. fputc((int) buffer[i], stdout);
  686. if (rc < sizeof (buffer))
  687. {
  688. printf("\n\n");
  689. if (!PHYSFS_eof(f))
  690. {
  691. printf("\n (Error condition in reading. Reason: [%s])\n\n",
  692. PHYSFS_getLastError());
  693. } /* if */
  694. PHYSFS_close(f);
  695. return 1;
  696. } /* if */
  697. } /* while */
  698. } /* else */
  699. return 1;
  700. } /* cmd_cat */
  701. static int cmd_cat2(char *args)
  702. {
  703. PHYSFS_File *f1 = NULL;
  704. PHYSFS_File *f2 = NULL;
  705. char *fname1;
  706. char *fname2;
  707. char *ptr;
  708. fname1 = args;
  709. if (*fname1 == '\"')
  710. {
  711. fname1++;
  712. ptr = strchr(fname1, '\"');
  713. if (ptr == NULL)
  714. {
  715. printf("missing string terminator in argument.\n");
  716. return 1;
  717. } /* if */
  718. *(ptr) = '\0';
  719. } /* if */
  720. else
  721. {
  722. ptr = strchr(fname1, ' ');
  723. *ptr = '\0';
  724. } /* else */
  725. fname2 = ptr + 1;
  726. if (*fname2 == '\"')
  727. {
  728. fname2++;
  729. ptr = strchr(fname2, '\"');
  730. if (ptr == NULL)
  731. {
  732. printf("missing string terminator in argument.\n");
  733. return 1;
  734. } /* if */
  735. *(ptr) = '\0';
  736. } /* if */
  737. if ((f1 = PHYSFS_openRead(fname1)) == NULL)
  738. printf("failed to open '%s'. Reason: [%s].\n", fname1, PHYSFS_getLastError());
  739. else if ((f2 = PHYSFS_openRead(fname2)) == NULL)
  740. printf("failed to open '%s'. Reason: [%s].\n", fname2, PHYSFS_getLastError());
  741. else
  742. {
  743. char *buffer1 = NULL;
  744. size_t buffer1len = 0;
  745. char *buffer2 = NULL;
  746. size_t buffer2len = 0;
  747. char *ptr = NULL;
  748. size_t i;
  749. if (do_buffer_size)
  750. {
  751. if (!PHYSFS_setBuffer(f1, do_buffer_size))
  752. {
  753. printf("failed to set file buffer for '%s'. Reason: [%s].\n",
  754. fname1, PHYSFS_getLastError());
  755. PHYSFS_close(f1);
  756. PHYSFS_close(f2);
  757. return 1;
  758. } /* if */
  759. else if (!PHYSFS_setBuffer(f2, do_buffer_size))
  760. {
  761. printf("failed to set file buffer for '%s'. Reason: [%s].\n",
  762. fname2, PHYSFS_getLastError());
  763. PHYSFS_close(f1);
  764. PHYSFS_close(f2);
  765. return 1;
  766. } /* if */
  767. } /* if */
  768. do
  769. {
  770. int readlen = 128;
  771. PHYSFS_sint64 rc;
  772. ptr = realloc(buffer1, buffer1len + readlen);
  773. if (!ptr)
  774. {
  775. printf("(Out of memory.)\n\n");
  776. free(buffer1);
  777. free(buffer2);
  778. PHYSFS_close(f1);
  779. PHYSFS_close(f2);
  780. return 1;
  781. } /* if */
  782. buffer1 = ptr;
  783. rc = PHYSFS_readBytes(f1, buffer1 + buffer1len, readlen);
  784. if (rc < 0)
  785. {
  786. printf("(Error condition in reading '%s'. Reason: [%s])\n\n",
  787. fname1, PHYSFS_getLastError());
  788. free(buffer1);
  789. free(buffer2);
  790. PHYSFS_close(f1);
  791. PHYSFS_close(f2);
  792. return 1;
  793. } /* if */
  794. buffer1len += (size_t) rc;
  795. ptr = realloc(buffer2, buffer2len + readlen);
  796. if (!ptr)
  797. {
  798. printf("(Out of memory.)\n\n");
  799. free(buffer1);
  800. free(buffer2);
  801. PHYSFS_close(f1);
  802. PHYSFS_close(f2);
  803. return 1;
  804. } /* if */
  805. buffer2 = ptr;
  806. rc = PHYSFS_readBytes(f2, buffer2 + buffer2len, readlen);
  807. if (rc < 0)
  808. {
  809. printf("(Error condition in reading '%s'. Reason: [%s])\n\n",
  810. fname2, PHYSFS_getLastError());
  811. free(buffer1);
  812. free(buffer2);
  813. PHYSFS_close(f1);
  814. PHYSFS_close(f2);
  815. return 1;
  816. } /* if */
  817. buffer2len += (size_t) rc;
  818. } while (!PHYSFS_eof(f1) || !PHYSFS_eof(f2));
  819. printf("file '%s' ...\n\n", fname1);
  820. for (i = 0; i < buffer1len; i++)
  821. fputc((int) buffer1[i], stdout);
  822. free(buffer1);
  823. printf("\n\nfile '%s' ...\n\n", fname2);
  824. for (i = 0; i < buffer2len; i++)
  825. fputc((int) buffer2[i], stdout);
  826. free(buffer2);
  827. printf("\n\n");
  828. } /* else */
  829. if (f1)
  830. PHYSFS_close(f1);
  831. if (f2)
  832. PHYSFS_close(f2);
  833. return 1;
  834. } /* cmd_cat2 */
  835. #define CRC32_BUFFERSIZE 512
  836. static int cmd_crc32(char *args)
  837. {
  838. PHYSFS_File *f;
  839. if (*args == '\"')
  840. {
  841. args++;
  842. args[strlen(args) - 1] = '\0';
  843. } /* if */
  844. f = PHYSFS_openRead(args);
  845. if (f == NULL)
  846. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  847. else
  848. {
  849. PHYSFS_uint8 buffer[CRC32_BUFFERSIZE];
  850. PHYSFS_uint32 crc = -1;
  851. PHYSFS_sint64 bytesread;
  852. while ((bytesread = PHYSFS_readBytes(f, buffer, CRC32_BUFFERSIZE)) > 0)
  853. {
  854. PHYSFS_uint32 i, bit;
  855. for (i = 0; i < bytesread; i++)
  856. {
  857. for (bit = 0; bit < 8; bit++, buffer[i] >>= 1)
  858. crc = (crc >> 1) ^ (((crc ^ buffer[i]) & 1) ? 0xEDB88320 : 0);
  859. } /* for */
  860. } /* while */
  861. if (bytesread < 0)
  862. {
  863. printf("error while reading. Reason: [%s].\n",
  864. PHYSFS_getLastError());
  865. return 1;
  866. } /* if */
  867. PHYSFS_close(f);
  868. crc ^= -1;
  869. printf("CRC32 for %s: 0x%08X\n", args, crc);
  870. } /* else */
  871. return 1;
  872. } /* cmd_crc32 */
  873. static int cmd_filelength(char *args)
  874. {
  875. PHYSFS_File *f;
  876. if (*args == '\"')
  877. {
  878. args++;
  879. args[strlen(args) - 1] = '\0';
  880. } /* if */
  881. f = PHYSFS_openRead(args);
  882. if (f == NULL)
  883. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  884. else
  885. {
  886. PHYSFS_sint64 len = PHYSFS_fileLength(f);
  887. if (len == -1)
  888. printf("failed to determine length. Reason: [%s].\n", PHYSFS_getLastError());
  889. else
  890. printf(" (cast to int) %d bytes.\n", (int) len);
  891. PHYSFS_close(f);
  892. } /* else */
  893. return 1;
  894. } /* cmd_filelength */
  895. #define WRITESTR "The cat sat on the mat.\n\n"
  896. static int cmd_append(char *args)
  897. {
  898. PHYSFS_File *f;
  899. if (*args == '\"')
  900. {
  901. args++;
  902. args[strlen(args) - 1] = '\0';
  903. } /* if */
  904. f = PHYSFS_openAppend(args);
  905. if (f == NULL)
  906. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  907. else
  908. {
  909. size_t bw;
  910. PHYSFS_sint64 rc;
  911. if (do_buffer_size)
  912. {
  913. if (!PHYSFS_setBuffer(f, do_buffer_size))
  914. {
  915. printf("failed to set file buffer. Reason: [%s].\n",
  916. PHYSFS_getLastError());
  917. PHYSFS_close(f);
  918. return 1;
  919. } /* if */
  920. } /* if */
  921. bw = strlen(WRITESTR);
  922. rc = PHYSFS_writeBytes(f, WRITESTR, bw);
  923. if (rc != bw)
  924. {
  925. printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n",
  926. (int) rc, (int) bw, PHYSFS_getLastError());
  927. } /* if */
  928. else
  929. {
  930. printf("Successful.\n");
  931. } /* else */
  932. PHYSFS_close(f);
  933. } /* else */
  934. return 1;
  935. } /* cmd_append */
  936. static int cmd_write(char *args)
  937. {
  938. PHYSFS_File *f;
  939. if (*args == '\"')
  940. {
  941. args++;
  942. args[strlen(args) - 1] = '\0';
  943. } /* if */
  944. f = PHYSFS_openWrite(args);
  945. if (f == NULL)
  946. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  947. else
  948. {
  949. size_t bw;
  950. PHYSFS_sint64 rc;
  951. if (do_buffer_size)
  952. {
  953. if (!PHYSFS_setBuffer(f, do_buffer_size))
  954. {
  955. printf("failed to set file buffer. Reason: [%s].\n",
  956. PHYSFS_getLastError());
  957. PHYSFS_close(f);
  958. return 1;
  959. } /* if */
  960. } /* if */
  961. bw = strlen(WRITESTR);
  962. rc = PHYSFS_writeBytes(f, WRITESTR, bw);
  963. if (rc != bw)
  964. {
  965. printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n",
  966. (int) rc, (int) bw, PHYSFS_getLastError());
  967. } /* if */
  968. else
  969. {
  970. printf("Successful.\n");
  971. } /* else */
  972. PHYSFS_close(f);
  973. } /* else */
  974. return 1;
  975. } /* cmd_write */
  976. static char* modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
  977. {
  978. if (modtime < 0)
  979. strncpy(modstr, "Unknown\n", strsize);
  980. else
  981. {
  982. time_t t = (time_t) modtime;
  983. char *str = ctime(&t);
  984. strncpy(modstr, str, strsize);
  985. } /* else */
  986. modstr[strsize-1] = '\0';
  987. return modstr;
  988. } /* modTimeToStr */
  989. static int cmd_getlastmodtime(char *args)
  990. {
  991. PHYSFS_Stat statbuf;
  992. if (!PHYSFS_stat(args, &statbuf))
  993. printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
  994. else
  995. {
  996. char modstr[64];
  997. modTimeToStr(statbuf.modtime, modstr, sizeof (modstr));
  998. printf("Last modified: %s (%ld).\n", modstr, (long) statbuf.modtime);
  999. } /* else */
  1000. return 1;
  1001. } /* cmd_getLastModTime */
  1002. static int cmd_stat(char *args)
  1003. {
  1004. PHYSFS_Stat stat;
  1005. char timestring[65];
  1006. if (*args == '\"')
  1007. {
  1008. args++;
  1009. args[strlen(args) - 1] = '\0';
  1010. } /* if */
  1011. if(!PHYSFS_stat(args, &stat))
  1012. {
  1013. printf("failed to stat. Reason [%s].\n", PHYSFS_getLastError());
  1014. return 1;
  1015. } /* if */
  1016. printf("Filename: %s\n", args);
  1017. printf("Size %d\n",(int) stat.filesize);
  1018. if(stat.filetype == PHYSFS_FILETYPE_REGULAR)
  1019. printf("Type: File\n");
  1020. else if(stat.filetype == PHYSFS_FILETYPE_DIRECTORY)
  1021. printf("Type: Directory\n");
  1022. else if(stat.filetype == PHYSFS_FILETYPE_SYMLINK)
  1023. printf("Type: Symlink\n");
  1024. else
  1025. printf("Type: Unknown\n");
  1026. printf("Created at: %s", modTimeToStr(stat.createtime, timestring, 64));
  1027. printf("Last modified at: %s", modTimeToStr(stat.modtime, timestring, 64));
  1028. printf("Last accessed at: %s", modTimeToStr(stat.accesstime, timestring, 64));
  1029. printf("Readonly: %s\n", stat.readonly ? "true" : "false");
  1030. return 1;
  1031. } /* cmd_filelength */
  1032. /* must have spaces trimmed prior to this call. */
  1033. static int count_args(const char *str)
  1034. {
  1035. int retval = 0;
  1036. int in_quotes = 0;
  1037. if (str != NULL)
  1038. {
  1039. for (; *str != '\0'; str++)
  1040. {
  1041. if (*str == '\"')
  1042. in_quotes = !in_quotes;
  1043. else if ((*str == ' ') && (!in_quotes))
  1044. retval++;
  1045. } /* for */
  1046. retval++;
  1047. } /* if */
  1048. return retval;
  1049. } /* count_args */
  1050. static int cmd_help(char *args);
  1051. typedef struct
  1052. {
  1053. const char *cmd;
  1054. int (*func)(char *args);
  1055. int argcount;
  1056. const char *usage;
  1057. } command_info;
  1058. static const command_info commands[] =
  1059. {
  1060. { "quit", cmd_quit, 0, NULL },
  1061. { "q", cmd_quit, 0, NULL },
  1062. { "help", cmd_help, 0, NULL },
  1063. { "init", cmd_init, 1, "<argv0>" },
  1064. { "deinit", cmd_deinit, 0, NULL },
  1065. { "addarchive", cmd_addarchive, 2, "<archiveLocation> <append>" },
  1066. { "mount", cmd_mount, 3, "<archiveLocation> <mntpoint> <append>" },
  1067. { "mountmem", cmd_mount_mem, 3, "<archiveLocation> <mntpoint> <append>" },
  1068. { "mounthandle", cmd_mount_handle, 3, "<archiveLocation> <mntpoint> <append>" },
  1069. { "removearchive", cmd_removearchive, 1, "<archiveLocation>" },
  1070. { "unmount", cmd_removearchive, 1, "<archiveLocation>" },
  1071. { "enumerate", cmd_enumerate, 1, "<dirToEnumerate>" },
  1072. { "ls", cmd_enumerate, 1, "<dirToEnumerate>" },
  1073. { "getlasterror", cmd_getlasterror, 0, NULL },
  1074. { "getdirsep", cmd_getdirsep, 0, NULL },
  1075. { "getcdromdirs", cmd_getcdromdirs, 0, NULL },
  1076. { "getsearchpath", cmd_getsearchpath, 0, NULL },
  1077. { "getbasedir", cmd_getbasedir, 0, NULL },
  1078. { "getuserdir", cmd_getuserdir, 0, NULL },
  1079. { "getprefdir", cmd_getprefdir, 2, "<org> <app>" },
  1080. { "getwritedir", cmd_getwritedir, 0, NULL },
  1081. { "setwritedir", cmd_setwritedir, 1, "<newWriteDir>" },
  1082. { "permitsymlinks", cmd_permitsyms, 1, "<1or0>" },
  1083. { "setsaneconfig", cmd_setsaneconfig, 5, "<org> <appName> <arcExt> <includeCdRoms> <archivesFirst>" },
  1084. { "mkdir", cmd_mkdir, 1, "<dirToMk>" },
  1085. { "delete", cmd_delete, 1, "<dirToDelete>" },
  1086. { "getrealdir", cmd_getrealdir, 1, "<fileToFind>" },
  1087. { "exists", cmd_exists, 1, "<fileToCheck>" },
  1088. { "isdir", cmd_isdir, 1, "<fileToCheck>" },
  1089. { "issymlink", cmd_issymlink, 1, "<fileToCheck>" },
  1090. { "cat", cmd_cat, 1, "<fileToCat>" },
  1091. { "cat2", cmd_cat2, 2, "<fileToCat1> <fileToCat2>" },
  1092. { "filelength", cmd_filelength, 1, "<fileToCheck>" },
  1093. { "stat", cmd_stat, 1, "<fileToStat>" },
  1094. { "append", cmd_append, 1, "<fileToAppend>" },
  1095. { "write", cmd_write, 1, "<fileToCreateOrTrash>" },
  1096. { "getlastmodtime", cmd_getlastmodtime, 1, "<fileToExamine>" },
  1097. { "setbuffer", cmd_setbuffer, 1, "<bufferSize>" },
  1098. { "stressbuffer", cmd_stressbuffer, 1, "<bufferSize>" },
  1099. { "crc32", cmd_crc32, 1, "<fileToHash>" },
  1100. { "getmountpoint", cmd_getmountpoint, 1, "<dir>" },
  1101. { NULL, NULL, -1, NULL }
  1102. };
  1103. static void output_usage(const char *intro, const command_info *cmdinfo)
  1104. {
  1105. if (cmdinfo->argcount == 0)
  1106. printf("%s \"%s\" (no arguments)\n", intro, cmdinfo->cmd);
  1107. else
  1108. printf("%s \"%s %s\"\n", intro, cmdinfo->cmd, cmdinfo->usage);
  1109. } /* output_usage */
  1110. static int cmd_help(char *args)
  1111. {
  1112. const command_info *i;
  1113. printf("Commands:\n");
  1114. for (i = commands; i->cmd != NULL; i++)
  1115. output_usage(" -", i);
  1116. return 1;
  1117. } /* output_cmd_help */
  1118. static void trim_command(const char *orig, char *copy)
  1119. {
  1120. const char *i;
  1121. char *writeptr = copy;
  1122. int spacecount = 0;
  1123. int have_first = 0;
  1124. for (i = orig; *i != '\0'; i++)
  1125. {
  1126. if (*i == ' ')
  1127. {
  1128. if ((*(i + 1) != ' ') && (*(i + 1) != '\0'))
  1129. {
  1130. if ((have_first) && (!spacecount))
  1131. {
  1132. spacecount++;
  1133. *writeptr = ' ';
  1134. writeptr++;
  1135. } /* if */
  1136. } /* if */
  1137. } /* if */
  1138. else
  1139. {
  1140. have_first = 1;
  1141. spacecount = 0;
  1142. *writeptr = *i;
  1143. writeptr++;
  1144. } /* else */
  1145. } /* for */
  1146. *writeptr = '\0';
  1147. /*
  1148. printf("\n command is [%s].\n", copy);
  1149. */
  1150. } /* trim_command */
  1151. static int process_command(char *complete_cmd)
  1152. {
  1153. const command_info *i;
  1154. char *cmd_copy;
  1155. char *args;
  1156. int rc = 1;
  1157. if (complete_cmd == NULL) /* can happen if user hits CTRL-D, etc. */
  1158. {
  1159. printf("\n");
  1160. return 0;
  1161. } /* if */
  1162. cmd_copy = (char *) malloc(strlen(complete_cmd) + 1);
  1163. if (cmd_copy == NULL)
  1164. {
  1165. printf("\n\n\nOUT OF MEMORY!\n\n\n");
  1166. return 0;
  1167. } /* if */
  1168. trim_command(complete_cmd, cmd_copy);
  1169. args = strchr(cmd_copy, ' ');
  1170. if (args != NULL)
  1171. {
  1172. *args = '\0';
  1173. args++;
  1174. } /* else */
  1175. if (cmd_copy[0] != '\0')
  1176. {
  1177. for (i = commands; i->cmd != NULL; i++)
  1178. {
  1179. if (strcmp(i->cmd, cmd_copy) == 0)
  1180. {
  1181. if ((i->argcount >= 0) && (count_args(args) != i->argcount))
  1182. output_usage("usage:", i);
  1183. else
  1184. rc = i->func(args);
  1185. break;
  1186. } /* if */
  1187. } /* for */
  1188. if (i->cmd == NULL)
  1189. printf("Unknown command. Enter \"help\" for instructions.\n");
  1190. #if (defined PHYSFS_HAVE_READLINE)
  1191. add_history(complete_cmd);
  1192. if (history_file)
  1193. {
  1194. fprintf(history_file, "%s\n", complete_cmd);
  1195. fflush(history_file);
  1196. } /* if */
  1197. #endif
  1198. } /* if */
  1199. free(cmd_copy);
  1200. return rc;
  1201. } /* process_command */
  1202. static void open_history_file(void)
  1203. {
  1204. #if (defined PHYSFS_HAVE_READLINE)
  1205. #if 0
  1206. const char *envr = getenv("TESTPHYSFS_HISTORY");
  1207. if (!envr)
  1208. return;
  1209. #else
  1210. char envr[256];
  1211. strcpy(envr, PHYSFS_getUserDir());
  1212. strcat(envr, ".testphys_history");
  1213. #endif
  1214. if (access(envr, F_OK) == 0)
  1215. {
  1216. char buf[512];
  1217. FILE *f = fopen(envr, "r");
  1218. if (!f)
  1219. {
  1220. printf("\n\n"
  1221. "Could not open history file [%s] for reading!\n"
  1222. " Will not have past history available.\n\n",
  1223. envr);
  1224. return;
  1225. } /* if */
  1226. do
  1227. {
  1228. if (fgets(buf, sizeof (buf), f) == NULL)
  1229. break;
  1230. if (buf[strlen(buf) - 1] == '\n')
  1231. buf[strlen(buf) - 1] = '\0';
  1232. add_history(buf);
  1233. } while (!feof(f));
  1234. fclose(f);
  1235. } /* if */
  1236. history_file = fopen(envr, "ab");
  1237. if (!history_file)
  1238. {
  1239. printf("\n\n"
  1240. "Could not open history file [%s] for appending!\n"
  1241. " Will not be able to record this session's history.\n\n",
  1242. envr);
  1243. } /* if */
  1244. #endif
  1245. } /* open_history_file */
  1246. int main(int argc, char **argv)
  1247. {
  1248. char *buf = NULL;
  1249. int rc = 0;
  1250. #if (defined __MWERKS__)
  1251. extern tSIOUXSettings SIOUXSettings;
  1252. SIOUXSettings.asktosaveonclose = 0;
  1253. SIOUXSettings.autocloseonquit = 1;
  1254. SIOUXSettings.rows = 40;
  1255. SIOUXSettings.columns = 120;
  1256. #endif
  1257. printf("\n");
  1258. if (!PHYSFS_init(argv[0]))
  1259. {
  1260. printf("PHYSFS_init() failed!\n reason: %s.\n", PHYSFS_getLastError());
  1261. return 1;
  1262. } /* if */
  1263. output_versions();
  1264. output_archivers();
  1265. open_history_file();
  1266. printf("Enter commands. Enter \"help\" for instructions.\n");
  1267. fflush(stdout);
  1268. do
  1269. {
  1270. #if (defined PHYSFS_HAVE_READLINE)
  1271. buf = readline("> ");
  1272. #else
  1273. int i;
  1274. buf = (char *) malloc(512);
  1275. memset(buf, '\0', 512);
  1276. printf("> ");
  1277. fflush(stdout);
  1278. for (i = 0; i < 511; i++)
  1279. {
  1280. int ch = fgetc(stdin);
  1281. if (ch == EOF)
  1282. {
  1283. strcpy(buf, "quit");
  1284. break;
  1285. } /* if */
  1286. else if ((ch == '\n') || (ch == '\r'))
  1287. {
  1288. buf[i] = '\0';
  1289. break;
  1290. } /* else if */
  1291. else if (ch == '\b')
  1292. {
  1293. if (i > 0)
  1294. i--;
  1295. } /* else if */
  1296. else
  1297. {
  1298. buf[i] = (char) ch;
  1299. } /* else */
  1300. } /* for */
  1301. #endif
  1302. rc = process_command(buf);
  1303. fflush(stdout);
  1304. if (buf != NULL)
  1305. free(buf);
  1306. } while (rc);
  1307. if (!PHYSFS_deinit())
  1308. printf("PHYSFS_deinit() failed!\n reason: %s.\n", PHYSFS_getLastError());
  1309. if (history_file)
  1310. fclose(history_file);
  1311. /*
  1312. printf("\n\ntest_physfs written by ryan c. gordon.\n");
  1313. printf(" it makes you shoot teh railgun bettar.\n");
  1314. */
  1315. return 0;
  1316. } /* main */
  1317. /* end of test_physfs.c ... */