test_physfs.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. /**
  2. * Test program for PhysicsFS. May only work on Unix.
  3. *
  4. * Please see the file LICENSE in the source's root directory.
  5. *
  6. * This file written by Ryan C. Gordon.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <errno.h>
  11. #include <string.h>
  12. #if (defined __MWERKS__)
  13. #include <SIOUX.h>
  14. #endif
  15. #if ((!defined WIN32) && (!defined __MACOS__))
  16. #define HAVE_READLINE
  17. #endif
  18. #if (defined HAVE_READLINE)
  19. #include <unistd.h>
  20. #include <readline.h>
  21. #include <history.h>
  22. #endif
  23. #include "physfs.h"
  24. #define TEST_VERSION_MAJOR 0
  25. #define TEST_VERSION_MINOR 1
  26. #define TEST_VERSION_PATCH 1
  27. static FILE *history_file = NULL;
  28. static void output_versions(void)
  29. {
  30. PHYSFS_Version compiled;
  31. PHYSFS_Version linked;
  32. PHYSFS_VERSION(&compiled);
  33. PHYSFS_getLinkedVersion(&linked);
  34. printf("test_physfs version %d.%d.%d.\n"
  35. " Compiled against PhysicsFS version %d.%d.%d,\n"
  36. " and linked against %d.%d.%d.\n\n",
  37. TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH,
  38. (int) compiled.major, (int) compiled.minor, (int) compiled.patch,
  39. (int) linked.major, (int) linked.minor, (int) linked.patch);
  40. } /* output_versions */
  41. static void output_archivers(void)
  42. {
  43. const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
  44. const PHYSFS_ArchiveInfo **i;
  45. printf("Supported archive types:\n");
  46. if (*rc == NULL)
  47. printf(" * Apparently, NONE!\n");
  48. else
  49. {
  50. for (i = rc; *i != NULL; i++)
  51. {
  52. printf(" * %s: %s\n Written by %s.\n %s\n",
  53. (*i)->extension, (*i)->description,
  54. (*i)->author, (*i)->url);
  55. } /* for */
  56. } /* else */
  57. printf("\n");
  58. } /* output_archivers */
  59. static int cmd_quit(char *args)
  60. {
  61. return(0);
  62. } /* cmd_quit */
  63. static int cmd_init(char *args)
  64. {
  65. if (*args == '\"')
  66. {
  67. args++;
  68. args[strlen(args) - 1] = '\0';
  69. } /* if */
  70. if (PHYSFS_init(args))
  71. printf("Successful.\n");
  72. else
  73. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  74. return(1);
  75. } /* cmd_init */
  76. static int cmd_deinit(char *args)
  77. {
  78. if (PHYSFS_deinit())
  79. printf("Successful.\n");
  80. else
  81. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  82. return(1);
  83. } /* cmd_deinit */
  84. static int cmd_addarchive(char *args)
  85. {
  86. char *ptr = strrchr(args, ' ');
  87. int appending = atoi(ptr + 1);
  88. *ptr = '\0';
  89. if (*args == '\"')
  90. {
  91. args++;
  92. *(ptr - 1) = '\0';
  93. } /* if */
  94. /*printf("[%s], [%d]\n", args, appending);*/
  95. if (PHYSFS_addToSearchPath(args, appending))
  96. printf("Successful.\n");
  97. else
  98. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  99. return(1);
  100. } /* cmd_addarchive */
  101. static int cmd_removearchive(char *args)
  102. {
  103. if (*args == '\"')
  104. {
  105. args++;
  106. args[strlen(args) - 1] = '\0';
  107. } /* if */
  108. if (PHYSFS_removeFromSearchPath(args))
  109. printf("Successful.\n");
  110. else
  111. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  112. return(1);
  113. } /* cmd_removearchive */
  114. static int cmd_enumerate(char *args)
  115. {
  116. char **rc;
  117. if (*args == '\"')
  118. {
  119. args++;
  120. args[strlen(args) - 1] = '\0';
  121. } /* if */
  122. rc = PHYSFS_enumerateFiles(args);
  123. if (rc == NULL)
  124. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  125. else
  126. {
  127. int file_count;
  128. char **i;
  129. for (i = rc, file_count = 0; *i != NULL; i++, file_count++)
  130. printf("%s\n", *i);
  131. printf("\n total (%d) files.\n", file_count);
  132. PHYSFS_freeList(rc);
  133. } /* else */
  134. return(1);
  135. } /* cmd_enumerate */
  136. static int cmd_getdirsep(char *args)
  137. {
  138. printf("Directory separator is [%s].\n", PHYSFS_getDirSeparator());
  139. return(1);
  140. } /* cmd_getdirsep */
  141. static int cmd_getlasterror(char *args)
  142. {
  143. printf("last error is [%s].\n", PHYSFS_getLastError());
  144. return(1);
  145. } /* cmd_getlasterror */
  146. static int cmd_getcdromdirs(char *args)
  147. {
  148. char **rc = PHYSFS_getCdRomDirs();
  149. if (rc == NULL)
  150. printf("Failure. Reason: [%s].\n", PHYSFS_getLastError());
  151. else
  152. {
  153. int dir_count;
  154. char **i;
  155. for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
  156. printf("%s\n", *i);
  157. printf("\n total (%d) drives.\n", dir_count);
  158. PHYSFS_freeList(rc);
  159. } /* else */
  160. return(1);
  161. } /* cmd_getcdromdirs */
  162. static int cmd_getsearchpath(char *args)
  163. {
  164. char **rc = PHYSFS_getSearchPath();
  165. if (rc == NULL)
  166. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  167. else
  168. {
  169. int dir_count;
  170. char **i;
  171. for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
  172. printf("%s\n", *i);
  173. printf("\n total (%d) directories.\n", dir_count);
  174. PHYSFS_freeList(rc);
  175. } /* else */
  176. return(1);
  177. } /* cmd_getcdromdirs */
  178. static int cmd_getbasedir(char *args)
  179. {
  180. printf("Base dir is [%s].\n", PHYSFS_getBaseDir());
  181. return(1);
  182. } /* cmd_getbasedir */
  183. static int cmd_getuserdir(char *args)
  184. {
  185. printf("User dir is [%s].\n", PHYSFS_getUserDir());
  186. return(1);
  187. } /* cmd_getuserdir */
  188. static int cmd_getwritedir(char *args)
  189. {
  190. printf("Write dir is [%s].\n", PHYSFS_getWriteDir());
  191. return(1);
  192. } /* cmd_getwritedir */
  193. static int cmd_setwritedir(char *args)
  194. {
  195. if (*args == '\"')
  196. {
  197. args++;
  198. args[strlen(args) - 1] = '\0';
  199. } /* if */
  200. if (PHYSFS_setWriteDir(args))
  201. printf("Successful.\n");
  202. else
  203. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  204. return(1);
  205. } /* cmd_setwritedir */
  206. static int cmd_permitsyms(char *args)
  207. {
  208. int num;
  209. if (*args == '\"')
  210. {
  211. args++;
  212. args[strlen(args) - 1] = '\0';
  213. } /* if */
  214. num = atoi(args);
  215. PHYSFS_permitSymbolicLinks(num);
  216. printf("Symlinks are now %s.\n", num ? "permitted" : "forbidden");
  217. return(1);
  218. } /* cmd_permitsyms */
  219. static int cmd_setsaneconfig(char *args)
  220. {
  221. char *org;
  222. char *appName;
  223. char *arcExt;
  224. int inclCD;
  225. int arcsFirst;
  226. char *ptr = args;
  227. /* ugly. */
  228. org = ptr;
  229. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
  230. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; arcExt = ptr;
  231. ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt);
  232. arcsFirst = atoi(ptr);
  233. if (strcmp(arcExt, "!") == 0)
  234. arcExt = NULL;
  235. if (PHYSFS_setSaneConfig(org, appName, arcExt, inclCD, arcsFirst))
  236. printf("Successful.\n");
  237. else
  238. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  239. return(1);
  240. } /* cmd_setsaneconfig */
  241. static int cmd_mkdir(char *args)
  242. {
  243. if (*args == '\"')
  244. {
  245. args++;
  246. args[strlen(args) - 1] = '\0';
  247. } /* if */
  248. if (PHYSFS_mkdir(args))
  249. printf("Successful.\n");
  250. else
  251. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  252. return(1);
  253. } /* cmd_mkdir */
  254. static int cmd_delete(char *args)
  255. {
  256. if (*args == '\"')
  257. {
  258. args++;
  259. args[strlen(args) - 1] = '\0';
  260. } /* if */
  261. if (PHYSFS_delete(args))
  262. printf("Successful.\n");
  263. else
  264. printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  265. return(1);
  266. } /* cmd_delete */
  267. static int cmd_getrealdir(char *args)
  268. {
  269. const char *rc;
  270. if (*args == '\"')
  271. {
  272. args++;
  273. args[strlen(args) - 1] = '\0';
  274. } /* if */
  275. rc = PHYSFS_getRealDir(args);
  276. if (rc)
  277. printf("Found at [%s].\n", rc);
  278. else
  279. printf("Not found.\n");
  280. return(1);
  281. } /* cmd_getrealdir */
  282. static int cmd_exists(char *args)
  283. {
  284. int rc;
  285. if (*args == '\"')
  286. {
  287. args++;
  288. args[strlen(args) - 1] = '\0';
  289. } /* if */
  290. rc = PHYSFS_exists(args);
  291. printf("File %sexists.\n", rc ? "" : "does not ");
  292. return(1);
  293. } /* cmd_exists */
  294. static int cmd_isdir(char *args)
  295. {
  296. int rc;
  297. if (*args == '\"')
  298. {
  299. args++;
  300. args[strlen(args) - 1] = '\0';
  301. } /* if */
  302. rc = PHYSFS_isDirectory(args);
  303. printf("File %s a directory.\n", rc ? "is" : "is NOT");
  304. return(1);
  305. } /* cmd_isdir */
  306. static int cmd_issymlink(char *args)
  307. {
  308. int rc;
  309. if (*args == '\"')
  310. {
  311. args++;
  312. args[strlen(args) - 1] = '\0';
  313. } /* if */
  314. rc = PHYSFS_isSymbolicLink(args);
  315. printf("File %s a symlink.\n", rc ? "is" : "is NOT");
  316. return(1);
  317. } /* cmd_issymlink */
  318. static int cmd_cat(char *args)
  319. {
  320. PHYSFS_file *f;
  321. if (*args == '\"')
  322. {
  323. args++;
  324. args[strlen(args) - 1] = '\0';
  325. } /* if */
  326. f = PHYSFS_openRead(args);
  327. if (f == NULL)
  328. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  329. else
  330. {
  331. while (1)
  332. {
  333. char buffer[128];
  334. PHYSFS_sint64 rc;
  335. PHYSFS_sint64 i;
  336. rc = PHYSFS_read(f, buffer, 1, sizeof (buffer));
  337. for (i = 0; i < rc; i++)
  338. fputc((int) buffer[i], stdout);
  339. if (rc < sizeof (buffer))
  340. {
  341. printf("\n\n");
  342. if (!PHYSFS_eof(f))
  343. {
  344. printf("\n (Error condition in reading. Reason: [%s])\n\n",
  345. PHYSFS_getLastError());
  346. } /* if */
  347. PHYSFS_close(f);
  348. return(1);
  349. } /* if */
  350. } /* while */
  351. } /* else */
  352. return(1);
  353. } /* cmd_cat */
  354. static int cmd_filelength(char *args)
  355. {
  356. PHYSFS_file *f;
  357. if (*args == '\"')
  358. {
  359. args++;
  360. args[strlen(args) - 1] = '\0';
  361. } /* if */
  362. f = PHYSFS_openRead(args);
  363. if (f == NULL)
  364. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  365. else
  366. {
  367. PHYSFS_sint64 len = PHYSFS_fileLength(f);
  368. if (len == -1)
  369. printf("failed to determine length. Reason: [%s].\n", PHYSFS_getLastError());
  370. else
  371. printf(" (cast to int) %d bytes.\n", (int) len);
  372. PHYSFS_close(f);
  373. } /* else */
  374. return(1);
  375. } /* cmd_filelength */
  376. #define WRITESTR "The cat sat on the mat.\n\n"
  377. static int cmd_append(char *args)
  378. {
  379. PHYSFS_file *f;
  380. if (*args == '\"')
  381. {
  382. args++;
  383. args[strlen(args) - 1] = '\0';
  384. } /* if */
  385. f = PHYSFS_openAppend(args);
  386. if (f == NULL)
  387. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  388. else
  389. {
  390. size_t bw = strlen(WRITESTR);
  391. PHYSFS_sint64 rc = PHYSFS_write(f, WRITESTR, 1, bw);
  392. if (rc != bw)
  393. {
  394. printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n", rc, bw,
  395. PHYSFS_getLastError());
  396. } /* if */
  397. else
  398. {
  399. printf("Successful.\n");
  400. } /* else */
  401. PHYSFS_close(f);
  402. } /* else */
  403. return(1);
  404. } /* cmd_append */
  405. static int cmd_write(char *args)
  406. {
  407. PHYSFS_file *f;
  408. if (*args == '\"')
  409. {
  410. args++;
  411. args[strlen(args) - 1] = '\0';
  412. } /* if */
  413. f = PHYSFS_openWrite(args);
  414. if (f == NULL)
  415. printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
  416. else
  417. {
  418. size_t bw = strlen(WRITESTR);
  419. PHYSFS_sint64 rc = PHYSFS_write(f, WRITESTR, 1, bw);
  420. if (rc != bw)
  421. {
  422. printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n", rc, bw,
  423. PHYSFS_getLastError());
  424. } /* if */
  425. else
  426. {
  427. printf("Successful.\n");
  428. } /* else */
  429. PHYSFS_close(f);
  430. } /* else */
  431. return(1);
  432. } /* cmd_write */
  433. /* must have spaces trimmed prior to this call. */
  434. static int count_args(const char *str)
  435. {
  436. int retval = 0;
  437. int in_quotes = 0;
  438. if (str != NULL)
  439. {
  440. for (; *str != '\0'; str++)
  441. {
  442. if (*str == '\"')
  443. in_quotes = !in_quotes;
  444. else if ((*str == ' ') && (!in_quotes))
  445. retval++;
  446. } /* for */
  447. retval++;
  448. } /* if */
  449. return(retval);
  450. } /* count_args */
  451. static int cmd_help(char *args);
  452. typedef struct
  453. {
  454. const char *cmd;
  455. int (*func)(char *args);
  456. int argcount;
  457. const char *usage;
  458. } command_info;
  459. static const command_info commands[] =
  460. {
  461. { "quit", cmd_quit, 0, NULL },
  462. { "q", cmd_quit, 0, NULL },
  463. { "help", cmd_help, 0, NULL },
  464. { "init", cmd_init, 1, "<argv0>" },
  465. { "deinit", cmd_deinit, 0, NULL },
  466. { "addarchive", cmd_addarchive, 2, "<archiveLocation> <append>" },
  467. { "removearchive", cmd_removearchive, 1, "<archiveLocation>" },
  468. { "enumerate", cmd_enumerate, 1, "<dirToEnumerate>" },
  469. { "getlasterror", cmd_getlasterror, 0, NULL },
  470. { "getdirsep", cmd_getdirsep, 0, NULL },
  471. { "getcdromdirs", cmd_getcdromdirs, 0, NULL },
  472. { "getsearchpath", cmd_getsearchpath, 0, NULL },
  473. { "getbasedir", cmd_getbasedir, 0, NULL },
  474. { "getuserdir", cmd_getuserdir, 0, NULL },
  475. { "getwritedir", cmd_getwritedir, 0, NULL },
  476. { "setwritedir", cmd_setwritedir, 1, "<newWriteDir>" },
  477. { "permitsymlinks", cmd_permitsyms, 1, "<1or0>" },
  478. { "setsaneconfig", cmd_setsaneconfig, 4, "<appName> <arcExt> <includeCdRoms> <archivesFirst>" },
  479. { "mkdir", cmd_mkdir, 1, "<dirToMk>" },
  480. { "delete", cmd_delete, 1, "<dirToDelete>" },
  481. { "getrealdir", cmd_getrealdir, 1, "<fileToFind>" },
  482. { "exists", cmd_exists, 1, "<fileToCheck>" },
  483. { "isdir", cmd_isdir, 1, "<fileToCheck>" },
  484. { "issymlink", cmd_issymlink, 1, "<fileToCheck>" },
  485. { "cat", cmd_cat, 1, "<fileToCat>" },
  486. { "filelength", cmd_filelength, 1, "<fileToCheck>" },
  487. { "append", cmd_append, 1, "<fileToAppend>" },
  488. { "write", cmd_write, 1, "<fileToCreateOrTrash>" },
  489. { NULL, NULL, -1, NULL }
  490. };
  491. static void output_usage(const char *intro, const command_info *cmdinfo)
  492. {
  493. if (cmdinfo->argcount == 0)
  494. printf("%s \"%s\" (no arguments)\n", intro, cmdinfo->cmd);
  495. else
  496. printf("%s \"%s %s\"\n", intro, cmdinfo->cmd, cmdinfo->usage);
  497. } /* output_usage */
  498. static int cmd_help(char *args)
  499. {
  500. const command_info *i;
  501. printf("Commands:\n");
  502. for (i = commands; i->cmd != NULL; i++)
  503. output_usage(" -", i);
  504. return(1);
  505. } /* output_cmd_help */
  506. static void trim_command(const char *orig, char *copy)
  507. {
  508. const char *i;
  509. char *writeptr = copy;
  510. int spacecount = 0;
  511. int have_first = 0;
  512. for (i = orig; *i != '\0'; i++)
  513. {
  514. if (*i == ' ')
  515. {
  516. if ((*(i + 1) != ' ') && (*(i + 1) != '\0'))
  517. {
  518. if ((have_first) && (!spacecount))
  519. {
  520. spacecount++;
  521. *writeptr = ' ';
  522. writeptr++;
  523. } /* if */
  524. } /* if */
  525. } /* if */
  526. else
  527. {
  528. have_first = 1;
  529. spacecount = 0;
  530. *writeptr = *i;
  531. writeptr++;
  532. } /* else */
  533. } /* for */
  534. *writeptr = '\0';
  535. /*
  536. printf("\n command is [%s].\n", copy);
  537. */
  538. } /* trim_command */
  539. static int process_command(char *complete_cmd)
  540. {
  541. const command_info *i;
  542. char *cmd_copy = malloc(strlen(complete_cmd) + 1);
  543. char *args;
  544. int rc = 1;
  545. if (cmd_copy == NULL)
  546. {
  547. printf("\n\n\nOUT OF MEMORY!\n\n\n");
  548. return(0);
  549. } /* if */
  550. trim_command(complete_cmd, cmd_copy);
  551. args = strchr(cmd_copy, ' ');
  552. if (args != NULL)
  553. {
  554. *args = '\0';
  555. args++;
  556. } /* else */
  557. if (cmd_copy[0] != '\0')
  558. {
  559. for (i = commands; i->cmd != NULL; i++)
  560. {
  561. if (strcmp(i->cmd, cmd_copy) == 0)
  562. {
  563. if ((i->argcount >= 0) && (count_args(args) != i->argcount))
  564. output_usage("usage:", i);
  565. else
  566. rc = i->func(args);
  567. break;
  568. } /* if */
  569. } /* for */
  570. if (i->cmd == NULL)
  571. printf("Unknown command. Enter \"help\" for instructions.\n");
  572. #if (defined HAVE_READLINE)
  573. add_history(complete_cmd);
  574. if (history_file)
  575. {
  576. fprintf(history_file, "%s\n", complete_cmd);
  577. fflush(history_file);
  578. } /* if */
  579. #endif
  580. } /* if */
  581. free(cmd_copy);
  582. return(rc);
  583. } /* process_command */
  584. static void open_history_file(void)
  585. {
  586. #if (defined HAVE_READLINE)
  587. #if 0
  588. const char *envr = getenv("TESTPHYSFS_HISTORY");
  589. if (!envr)
  590. return;
  591. #else
  592. char envr[256];
  593. strcpy(envr, PHYSFS_getUserDir());
  594. strcat(envr, ".testphys_history");
  595. #endif
  596. if (access(envr, F_OK) == 0)
  597. {
  598. char buf[512];
  599. FILE *f = fopen(envr, "r");
  600. if (!f)
  601. {
  602. printf("\n\n"
  603. "Could not open history file [%s] for reading!\n"
  604. " Will not have past history available.\n\n",
  605. envr);
  606. return;
  607. } /* if */
  608. do
  609. {
  610. fgets(buf, sizeof (buf), f);
  611. if (buf[strlen(buf) - 1] == '\n')
  612. buf[strlen(buf) - 1] = '\0';
  613. add_history(buf);
  614. } while (!feof(f));
  615. fclose(f);
  616. } /* if */
  617. history_file = fopen(envr, "ab");
  618. if (!history_file)
  619. {
  620. printf("\n\n"
  621. "Could not open history file [%s] for appending!\n"
  622. " Will not be able to record this session's history.\n\n",
  623. envr);
  624. } /* if */
  625. #endif
  626. } /* open_history_file */
  627. int main(int argc, char **argv)
  628. {
  629. char *buf = NULL;
  630. int rc = 0;
  631. #if (defined __MWERKS__)
  632. extern tSIOUXSettings SIOUXSettings;
  633. SIOUXSettings.asktosaveonclose = 0;
  634. SIOUXSettings.autocloseonquit = 1;
  635. SIOUXSettings.rows = 40;
  636. SIOUXSettings.columns = 120;
  637. #endif
  638. printf("\n");
  639. if (!PHYSFS_init(argv[0]))
  640. {
  641. printf("PHYSFS_init() failed!\n reason: %s.\n", PHYSFS_getLastError());
  642. return(1);
  643. } /* if */
  644. output_versions();
  645. output_archivers();
  646. open_history_file();
  647. printf("Enter commands. Enter \"help\" for instructions.\n");
  648. do
  649. {
  650. #if (defined HAVE_READLINE)
  651. buf = readline("> ");
  652. #else
  653. int i;
  654. buf = malloc(512);
  655. memset(buf, '\0', 512);
  656. printf("> ");
  657. for (i = 0; i < 511; i++)
  658. {
  659. int ch = fgetc(stdin);
  660. if (ch == EOF)
  661. {
  662. strcpy(buf, "quit");
  663. break;
  664. } /* if */
  665. else if ((ch == '\n') || (ch == '\r'))
  666. {
  667. buf[i] = '\0';
  668. break;
  669. } /* else if */
  670. else if (ch == '\b')
  671. {
  672. if (i > 0)
  673. i--;
  674. } /* else if */
  675. else
  676. {
  677. buf[i] = (char) ch;
  678. } /* else */
  679. } /* for */
  680. #endif
  681. rc = process_command(buf);
  682. free(buf);
  683. } while (rc);
  684. if (!PHYSFS_deinit())
  685. printf("PHYSFS_deinit() failed!\n reason: %s.\n", PHYSFS_getLastError());
  686. if (history_file)
  687. fclose(history_file);
  688. /*
  689. printf("\n\ntest_physfs written by ryan c. gordon.\n");
  690. printf(" it makes you shoot teh railgun bettar.\n");
  691. */
  692. return(0);
  693. } /* main */
  694. /* end of test_physfs.c ... */