test/test_physfs.c
changeset 108 90f7ad8a0ab5
parent 101 bd18e17ad6ad
child 132 b53fa5093749
equal deleted inserted replaced
107:4fd38db4d6ab 108:90f7ad8a0ab5
   322 {
   322 {
   323     int rc = PHYSFS_isSymbolicLink(args);
   323     int rc = PHYSFS_isSymbolicLink(args);
   324     printf("File %s a symlink.\n", rc ? "is" : "is NOT");
   324     printf("File %s a symlink.\n", rc ? "is" : "is NOT");
   325     return(1);
   325     return(1);
   326 } /* cmd_issymlink */
   326 } /* cmd_issymlink */
       
   327 
       
   328 
       
   329 static int cmd_cat(char *args)
       
   330 {
       
   331     PHYSFS_file *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             int rc;
       
   340             int i;
       
   341             rc = PHYSFS_read(f, buffer, 1, sizeof (buffer));
       
   342 
       
   343             for (i = 0; i < rc; i++)
       
   344                 fputc((int) buffer[i], stdout);
       
   345 
       
   346             if (rc < sizeof (buffer))
       
   347             {
       
   348                 printf("\n\n");
       
   349                 if (!PHYSFS_eof(f))
       
   350                     printf("\n (Error condition in reading.)\n\n");
       
   351                 PHYSFS_close(f);
       
   352                 return(1);
       
   353             } /* if */
       
   354         } /* while */
       
   355     } /* else */
       
   356 
       
   357     return(1);
       
   358 } /* cmd_cat */
   327 
   359 
   328 
   360 
   329 /* must have spaces trimmed prior to this call. */
   361 /* must have spaces trimmed prior to this call. */
   330 static int count_args(const char *str)
   362 static int count_args(const char *str)
   331 {
   363 {
   379     { "delete",         cmd_delete,         1, "<dirToDelete>"              },
   411     { "delete",         cmd_delete,         1, "<dirToDelete>"              },
   380     { "getrealdir",     cmd_getrealdir,     1, "<fileToFind>"               },
   412     { "getrealdir",     cmd_getrealdir,     1, "<fileToFind>"               },
   381     { "exists",         cmd_exists,         1, "<fileToCheck>"              },
   413     { "exists",         cmd_exists,         1, "<fileToCheck>"              },
   382     { "isdir",          cmd_isdir,          1, "<fileToCheck>"              },
   414     { "isdir",          cmd_isdir,          1, "<fileToCheck>"              },
   383     { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
   415     { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
       
   416     { "cat",            cmd_cat,            1, "<fileToCat>"                },
   384     { NULL,             NULL,              -1, NULL                         }
   417     { NULL,             NULL,              -1, NULL                         }
   385 };
   418 };
   386 
   419 
   387 static void output_usage(const char *intro, const command_info *cmdinfo)
   420 static void output_usage(const char *intro, const command_info *cmdinfo)
   388 {
   421 {