📄 test_physfs.c
字号:
/** * Test program for PhysicsFS. May only work on Unix. * * Please see the file LICENSE in the source's root directory. * * This file written by Ryan C. Gordon. */#if HAVE_CONFIG_H# include <config.h>#endif#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h>#if (defined __MWERKS__)#include <SIOUX.h>#endif#if (defined PHYSFS_HAVE_READLINE)#include <unistd.h>#include <readline/readline.h>#include <readline/history.h>#endif#include <time.h>#include "physfs.h"#define TEST_VERSION_MAJOR 0#define TEST_VERSION_MINOR 1#define TEST_VERSION_PATCH 7static FILE *history_file = NULL;static void output_versions(void){ PHYSFS_Version compiled; PHYSFS_Version linked; PHYSFS_VERSION(&compiled); PHYSFS_getLinkedVersion(&linked); printf("test_physfs version %d.%d.%d.\n" " Compiled against PhysicsFS version %d.%d.%d,\n" " and linked against %d.%d.%d.\n\n", TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH, (int) compiled.major, (int) compiled.minor, (int) compiled.patch, (int) linked.major, (int) linked.minor, (int) linked.patch);} /* output_versions */static void output_archivers(void){ const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes(); const PHYSFS_ArchiveInfo **i; printf("Supported archive types:\n"); if (*rc == NULL) printf(" * Apparently, NONE!\n"); else { for (i = rc; *i != NULL; i++) { printf(" * %s: %s\n Written by %s.\n %s\n", (*i)->extension, (*i)->description, (*i)->author, (*i)->url); } /* for */ } /* else */ printf("\n");} /* output_archivers */static int cmd_quit(char *args){ return(0);} /* cmd_quit */static int cmd_init(char *args){ if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ if (PHYSFS_init(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_init */static int cmd_deinit(char *args){ if (PHYSFS_deinit()) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_deinit */static int cmd_addarchive(char *args){ char *ptr = strrchr(args, ' '); int appending = atoi(ptr + 1); *ptr = '\0'; if (*args == '\"') { args++; *(ptr - 1) = '\0'; } /* if */ /*printf("[%s], [%d]\n", args, appending);*/ if (PHYSFS_addToSearchPath(args, appending)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_addarchive */static int cmd_removearchive(char *args){ if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ if (PHYSFS_removeFromSearchPath(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_removearchive */static int cmd_enumerate(char *args){ char **rc; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ rc = PHYSFS_enumerateFiles(args); if (rc == NULL) printf("Failure. reason: %s.\n", PHYSFS_getLastError()); else { int file_count; char **i; for (i = rc, file_count = 0; *i != NULL; i++, file_count++) printf("%s\n", *i); printf("\n total (%d) files.\n", file_count); PHYSFS_freeList(rc); } /* else */ return(1);} /* cmd_enumerate */static int cmd_getdirsep(char *args){ printf("Directory separator is [%s].\n", PHYSFS_getDirSeparator()); return(1);} /* cmd_getdirsep */static int cmd_getlasterror(char *args){ printf("last error is [%s].\n", PHYSFS_getLastError()); return(1);} /* cmd_getlasterror */static int cmd_getcdromdirs(char *args){ char **rc = PHYSFS_getCdRomDirs(); if (rc == NULL) printf("Failure. Reason: [%s].\n", PHYSFS_getLastError()); else { int dir_count; char **i; for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++) printf("%s\n", *i); printf("\n total (%d) drives.\n", dir_count); PHYSFS_freeList(rc); } /* else */ return(1);} /* cmd_getcdromdirs */static int cmd_getsearchpath(char *args){ char **rc = PHYSFS_getSearchPath(); if (rc == NULL) printf("Failure. reason: %s.\n", PHYSFS_getLastError()); else { int dir_count; char **i; for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++) printf("%s\n", *i); printf("\n total (%d) directories.\n", dir_count); PHYSFS_freeList(rc); } /* else */ return(1);} /* cmd_getcdromdirs */static int cmd_getbasedir(char *args){ printf("Base dir is [%s].\n", PHYSFS_getBaseDir()); return(1);} /* cmd_getbasedir */static int cmd_getuserdir(char *args){ printf("User dir is [%s].\n", PHYSFS_getUserDir()); return(1);} /* cmd_getuserdir */static int cmd_getwritedir(char *args){ printf("Write dir is [%s].\n", PHYSFS_getWriteDir()); return(1);} /* cmd_getwritedir */static int cmd_setwritedir(char *args){ if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ if (PHYSFS_setWriteDir(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_setwritedir */static int cmd_permitsyms(char *args){ int num; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ num = atoi(args); PHYSFS_permitSymbolicLinks(num); printf("Symlinks are now %s.\n", num ? "permitted" : "forbidden"); return(1);} /* cmd_permitsyms */static int cmd_setsaneconfig(char *args){ char *org; char *appName; char *arcExt; int inclCD; int arcsFirst; char *ptr = args; /* ugly. */ org = ptr; ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr; ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; arcExt = ptr; ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt); arcsFirst = atoi(ptr); if (strcmp(arcExt, "!") == 0) arcExt = NULL; if (PHYSFS_setSaneConfig(org, appName, arcExt, inclCD, arcsFirst)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_setsaneconfig */static int cmd_mkdir(char *args){ if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ if (PHYSFS_mkdir(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_mkdir */static int cmd_delete(char *args){ if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ if (PHYSFS_delete(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1);} /* cmd_delete */static int cmd_getrealdir(char *args){ const char *rc; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ rc = PHYSFS_getRealDir(args); if (rc) printf("Found at [%s].\n", rc); else printf("Not found.\n"); return(1);} /* cmd_getrealdir */static int cmd_exists(char *args){ int rc; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ rc = PHYSFS_exists(args); printf("File %sexists.\n", rc ? "" : "does not "); return(1);} /* cmd_exists */static int cmd_isdir(char *args){ int rc; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ rc = PHYSFS_isDirectory(args); printf("File %s a directory.\n", rc ? "is" : "is NOT"); return(1);} /* cmd_isdir */static int cmd_issymlink(char *args){ int rc; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ rc = PHYSFS_isSymbolicLink(args); printf("File %s a symlink.\n", rc ? "is" : "is NOT"); return(1);} /* cmd_issymlink */static int cmd_cat(char *args){ PHYSFS_file *f; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ f = PHYSFS_openRead(args); if (f == NULL) printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError()); else { while (1) { char buffer[128]; PHYSFS_sint64 rc; PHYSFS_sint64 i; rc = PHYSFS_read(f, buffer, 1, sizeof (buffer)); for (i = 0; i < rc; i++) fputc((int) buffer[i], stdout); if (rc < sizeof (buffer)) { printf("\n\n"); if (!PHYSFS_eof(f)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -