Skip to content

Commit

Permalink
Added "cat" command.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 9, 2001
1 parent 94406b6 commit b1c50bb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/test_physfs.c
Expand Up @@ -326,6 +326,38 @@ static int cmd_issymlink(char *args)
} /* cmd_issymlink */


static int cmd_cat(char *args)
{
PHYSFS_file *f = PHYSFS_openRead(args);
if (f == NULL)
printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
else
{
while (1)
{
char buffer[128];
int rc;
int 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))
printf("\n (Error condition in reading.)\n\n");
PHYSFS_close(f);
return(1);
} /* if */
} /* while */
} /* else */

return(1);
} /* cmd_cat */


/* must have spaces trimmed prior to this call. */
static int count_args(const char *str)
{
Expand Down Expand Up @@ -381,6 +413,7 @@ static const command_info commands[] =
{ "exists", cmd_exists, 1, "<fileToCheck>" },
{ "isdir", cmd_isdir, 1, "<fileToCheck>" },
{ "issymlink", cmd_issymlink, 1, "<fileToCheck>" },
{ "cat", cmd_cat, 1, "<fileToCat>" },
{ NULL, NULL, -1, NULL }
};

Expand Down

0 comments on commit b1c50bb

Please sign in to comment.