test_physfs.c 20 KB

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