test_physfs.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <readline.h>
  4. #include <history.h>
  5. #include "physfs.h"
  6. #define TEST_VERSION_MAJOR 0
  7. #define TEST_VERSION_MINOR 1
  8. #define TEST_VERSION_PATCH 0
  9. static void output_versions(void)
  10. {
  11. PHYSFS_Version compiled;
  12. PHYSFS_Version linked;
  13. PHYSFS_VERSION(&compiled);
  14. PHYSFS_getLinkedVersion(&linked);
  15. printf("test_physfs version %d.%d.%d.\n"
  16. " Compiled against PhysicsFS version %d.%d.%d,\n"
  17. " and linked against %d.%d.%d.\n\n",
  18. TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH,
  19. compiled.major, compiled.minor, compiled.patch,
  20. linked.major, linked.minor, linked.patch);
  21. } /* output_versions */
  22. static void output_archivers(void)
  23. {
  24. const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
  25. const PHYSFS_ArchiveInfo **i;
  26. printf("Supported archive types:\n");
  27. if (*rc == NULL)
  28. printf(" * Apparently, NONE!\n");
  29. else
  30. {
  31. for (i = rc; *i != NULL; i++)
  32. {
  33. printf(" * %s: %s\n Written by %s.\n %s\n",
  34. (*i)->extension, (*i)->description,
  35. (*i)->author, (*i)->url);
  36. } /* for */
  37. } /* else */
  38. printf("\n");
  39. } /* output_archivers */
  40. static int cmd_help(char *cmdstr)
  41. {
  42. printf("Commands:\n"
  43. " quit - exit this program.\n"
  44. " help - this information.\n");
  45. return(1);
  46. } /* output_cmd_help */
  47. static int cmd_quit(char *cmdstr)
  48. {
  49. return(0);
  50. } /* cmd_quit */
  51. typedef struct
  52. {
  53. const char *cmd;
  54. int (*func)(char *cmdstr);
  55. } command_info;
  56. static command_info commands[] =
  57. {
  58. {"quit", cmd_quit},
  59. {"q", cmd_quit},
  60. {"help", cmd_help},
  61. {NULL, NULL}
  62. };
  63. static int process_command(char *complete_cmd)
  64. {
  65. command_info *i;
  66. char *ptr = strchr(complete_cmd, ' ');
  67. char *cmd = NULL;
  68. int rc = 1;
  69. if (ptr == NULL)
  70. {
  71. cmd = malloc(strlen(complete_cmd) + 1);
  72. strcpy(cmd, complete_cmd);
  73. } /* if */
  74. else
  75. {
  76. *ptr = '\0';
  77. cmd = malloc(strlen(complete_cmd) + 1);
  78. strcpy(cmd, complete_cmd);
  79. *ptr = ' ';
  80. } /* else */
  81. for (i = commands; i->cmd != NULL; i++)
  82. {
  83. if (strcmp(i->cmd, cmd) == 0)
  84. {
  85. rc = i->func(complete_cmd);
  86. break;
  87. } /* if */
  88. } /* for */
  89. if (i->cmd == NULL)
  90. printf("Unknown command. Enter \"help\" for instructions.\n");
  91. free(cmd);
  92. return(rc);
  93. } /* process_command */
  94. int main(int argc, char **argv)
  95. {
  96. char *buf = NULL;
  97. int rc = 0;
  98. printf("\n");
  99. if (!PHYSFS_init(argv[0]))
  100. {
  101. printf("PHYSFS_init() failed!\n reason: %s\n", PHYSFS_getLastError());
  102. return(1);
  103. } /* if */
  104. output_versions();
  105. output_archivers();
  106. printf("Enter commands. Enter \"help\" for instructions.\n");
  107. do
  108. {
  109. buf = readline("> ");
  110. rc = process_command(buf);
  111. free(buf);
  112. } while (rc);
  113. return(0);
  114. } /* main */
  115. /* end of test_physfs.c ... */