home *** CD-ROM | disk | FTP | other *** search
/ Launch & Play / spustahrej2.iso / Egoboo / code / lin-file.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-03  |  2.3 KB  |  115 lines

  1. // lin-file.c
  2.  
  3. // Egoboo, Copyright (C) 2000 Aaron Bishop
  4.  
  5. #include "egoboo.h"
  6. #include <stdio.h>
  7. #include <sys/types.h>
  8. #include <sys/dir.h>
  9.  
  10. char command[500];
  11. FILE *DirFiles;
  12. char DirRead[100];
  13.  
  14. //File Routines-----------------------------------------------------------
  15. void make_directory(char *dirname)
  16. {
  17.     // ZZ> This function makes a new directory
  18.     sprintf(command,"mkdir -p %s\n",dirname);
  19.     system(command);
  20. }
  21.  
  22. void remove_directory(char *dirname)
  23. {
  24.     // ZZ> This function removes a directory
  25.     sprintf(command,"rm -rf %s\n",dirname);
  26.     system(command);
  27. }
  28.  
  29. void delete_file(char *filename)
  30. {
  31.     // ZZ> This function deletes a file
  32.     sprintf(command,"rm -f %s\n",filename);
  33.     system(command);
  34. }
  35.  
  36. void copy_file(char *source, char *dest)
  37. {
  38.     // ZZ> This function copies a file on the local machine
  39.     sprintf(command,"cp -f %s %s\n",source,dest);
  40.     system(command);
  41. }
  42.  
  43. void delete_directory(char *dirname)
  44. {
  45.     // ZZ> This function deletes all files in a directory,
  46.     //     and the directory itself
  47.     sprintf(command,"rm -rf %s\n",dirname);
  48.     system(command);
  49. }
  50.  
  51. void copy_directory(char *dirname, char *todirname)
  52. {
  53.     // ZZ> This function copies all files in a directory
  54.     sprintf(command,"cp -fr %s %s\n",dirname,todirname);
  55.     system(command);
  56. }
  57.  
  58. void empty_import_directory(void)
  59. {
  60.     // ZZ> This function deletes all the TEMP????.OBJ subdirectories in the IMPORT directory
  61.     sprintf(command,"rm -rf import/temp*.obj\n");
  62.     system(command);
  63. }
  64.  
  65. // Read the first directory entry
  66. char *DirGetFirst(char *search)
  67. {
  68.   sprintf(command,"find %s -maxdepth 0 -printf \"%%f\\n\"  ",search);
  69.   DirFiles=popen(command,"r");
  70.   if(!feof(DirFiles))
  71.   {
  72.     fscanf(DirFiles,"%s\n",DirRead);
  73.     return(DirRead);
  74.   }
  75.   else
  76.   {
  77.     return(NULL);
  78.   }
  79. }
  80.  
  81. // Read the next directory entry (NULL if done)
  82. char *DirGetNext(void)
  83. {
  84.   if(!feof(DirFiles))
  85.   { 
  86.     fscanf(DirFiles,"%s\n",DirRead);
  87.     return(DirRead);
  88.   }
  89.   else
  90.   {
  91.     return(NULL);
  92.   }
  93. }
  94.  
  95. // Close anything left open
  96. void DirClose()
  97. {
  98.   fclose(DirFiles);
  99. }
  100.  
  101. int ClockGetTick()
  102. {
  103.   return(clock());
  104. }
  105.  
  106. int DirGetAttrib(char *fromdir)
  107. {
  108.   int tmp;
  109. #define FILE_ATTRIBUTE_DIRECTORY 0x10
  110. #define FILE_ATTRIBUTE_NORMAL 0x0
  111. #define FILE_ATTRIBUTE_ERROR 0xffffffff
  112.  
  113.   return(0);
  114. }
  115.