home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / file.lzh / file.h < prev    next >
Text File  |  1995-04-27  |  6KB  |  230 lines

  1. /************************************************************************ 
  2.  * file.h                                                               *
  3.  ************************************************************************
  4.  * header file for file utility code.                                   *
  5.  ************************************************************************
  6.  * Original code: Scott McGee  4/1/93 (moved from file.c 9/5/93)        *
  7.  ***********************************************************************/
  8.  
  9.  /***********************************************************************
  10.  * NOTE: if compiling on a "Little Endian" machine, _LIL_END must be    *
  11.  *       defined to insure correct byte ordering! (This definition is   *
  12.  *       automatic with Microware's Ultra C compiler)                   *
  13.  ***********************************************************************/
  14.  
  15. #include <stdio.h>
  16. #if defined(__ANSI__) || defined(_UCC)
  17. #    include <stdlib.h>
  18. #endif
  19. #ifdef _BSD
  20. #    include <strings.h>
  21. #    include <ctype.h>
  22. #    define strrchr    rindex
  23. #    define strchr  index
  24. void *malloc();
  25. char *getenv();
  26. int  strspn();
  27. char *strtok();
  28. #else
  29. #    include <string.h>
  30. #endif 
  31. #include <errno.h>
  32. #ifdef _OSK
  33. #    include <dir.h>
  34. #    include <modes.h>
  35. #    define READ_ONLY S_IREAD
  36. #    define swap(a,b) a
  37. #    define MAGIC_DEFAULT "/dd/SYS/magic"
  38. #else
  39. #    ifdef _OS9000
  40. #        include <dir.h>
  41. #        include <modes.h>
  42. #        define READ_ONLY S_IREAD
  43. #        ifdef _LIL_END
  44. #            define swap(a,b) byteSwap(a,b)
  45. #        else
  46. #            define swap(a,b) a
  47. #        endif
  48. #        define MAGIC_DEFAULT "/dd/SYS/magic"
  49. #    else
  50. #        include <dirent.h>
  51. #        include <fcntl.h>
  52. #       include <unistd.h>    /* defines SEEK_SET */
  53. #        define READ_ONLY O_RDONLY
  54. #        ifdef _LIL_END
  55. #            define swap(a,b) byteSwap(a,b)
  56. #        else
  57. #            define swap(a,b) a
  58. #        endif
  59. #        define MAGIC_DEFAULT "/etc/magic"
  60. #    endif
  61. #endif
  62.  
  63. #ifndef SEEK_BEG
  64. #    define SEEK_BEG    0
  65. #endif
  66. #ifndef SEEK_SET
  67. #    define SEEK_SET    1
  68. #endif
  69. #ifndef SEEK_END
  70. #    define SEEK_END    2
  71. #endif
  72.  
  73. #define MAXLINELEN 160
  74. #define TRUE    1
  75. #define FALSE   0
  76. #define SUCCESS 1
  77. #define ERROR   0
  78.  
  79. #define TAR_MAGIC         "ustar  " /* 7 character (2 spaces) and a null */
  80. #define TAR_MAGIC_OFFSET  257
  81. #define TAR_MAGIC_SIZE    8
  82. #define TAR_REC_SIZE      512
  83. #define TAR_CHKSUM_OFFSET 148
  84. #define TAR_CHKSUM_SIZE   8
  85.  
  86. #define NOT_TAR   0
  87. #define POSIX_TAR 1
  88. #define OLD_TAR   2
  89.  
  90. typedef enum MAGIC_TYPE{
  91.     BYTE,
  92.     SHORT,
  93.     BESHORT,
  94.     LESHORT,
  95.     LONG,
  96.     BELONG,
  97.     LELONG,
  98.     STRING
  99. } MagicType;
  100.  
  101.  
  102. typedef enum OP_TYPE{
  103.     NONE,
  104.     EQUAL,
  105.     LESS,
  106.     GREATER,
  107.     AND,
  108.     OR,
  109.     ANY
  110. } OpType;
  111.  
  112. typedef enum FTYPE{
  113.     DIRECTORY,                    /* Directory */
  114.     NOSUCHFILE,                    /* No such file */
  115.     UNKNOWN,                    /* Unknown type */
  116.     NOPERMIT,                    /* Permission denied to read */
  117.     EMPTY,                        /* an empty file */
  118.     MISC,                        /* Unidentified file type */
  119.     ASM_SOURCE,                    /* assembly source code file */
  120.     MAKEFILE,                    /* generic makefile */
  121.     TEXT,                        /* Text file */
  122.     C_SOURCE,                    /* C source file */
  123.     C_HEADER,                    /* C header file */
  124.     TAR,                        /* tar file */
  125.     BIN,                        /* unidentified binary file */
  126.     UME                         /* Ultimuse music file */
  127. } fType;
  128.  
  129.  
  130. typedef struct MAGICLIST MagicList;
  131. struct MAGICLIST{
  132.     int           continuation;
  133.     MagicType     type;
  134.     int           maskFlag;
  135.     int           mask;
  136.     OpType        op;
  137.     unsigned long offset;
  138.     unsigned long value;
  139.     char          *stringValue;
  140.     char          *message;
  141.     MagicList     *next;
  142. };
  143.  
  144. /* partial module structure common to both OS-9 and OS-9000 */
  145. typedef struct modhead {
  146.     short       sync,      /* sync bytes ($4afc)          */
  147.                 sysrev;       /* system revision check value */
  148.     long        size,      /* module size                 */
  149.                 owner,     /* owner id                    */
  150.                 name;       /* offset to module name       */
  151.     short        access,    /* access permission           */
  152.                 tylan,     /* type/lang                   */
  153.                 attrev,    /* rev/attr                    */
  154.                 edit;      /* edition                     */
  155. } modhead;
  156.  
  157. #ifdef __STDC__
  158. #    define PROTO
  159. #else
  160. #    ifdef _UCC
  161. #        define PROTO
  162. #    endif
  163. #endif
  164.  
  165. /* function declarations */
  166. #ifdef PROTO                /* prototyping allowed */
  167.     /* from readmagic.c */
  168.     MagicList *readMagic(char *filename);
  169.     MagicList *decodeLine(char *buf);
  170.     char      *stringDecode(char *str);
  171.     /* from file.c */
  172.     char      *byteSwap(char *buf, int count);
  173.     int       strucmp(char *str1, char *str2);
  174.     int       struncmp(char *str1, char *str2, int count);
  175.     void      readFile(char *filename);
  176.     void      getFileNames(char *filename);
  177.     int       checkMagic(char *filename, char *buf, int size);
  178.     void      dirFiles(char *filename, DIR *dp);
  179.     /* from help.c */
  180.     void      optparse(char *);
  181.     void      printUsage(void);
  182.     void      printHelp(void);
  183.     void      *grab(unsigned int);
  184.     char      *_prgname(void);
  185.     int       _errmsg(int, char *, ...);
  186.     /* from istar.c */
  187.     int       istar(char *buf, int size);
  188. #else
  189.     /* from readmagic.c */
  190.     MagicList *readMagic();
  191.     MagicList *decodeLine();
  192.     char      *stringDecode();
  193.     /* from file.c */
  194.     char      *byteSwap();
  195.     int       strucmp();
  196.     int       struncmp();
  197.     void      readFile();
  198.     void      getFileNames();
  199.     int       checkMagic();
  200.     void      dirFiles();
  201.     /* from help.c */
  202.     void      optparse();
  203.     void      printUsage();
  204.     void      printHelp();
  205.     void      *grab();
  206.     char      *_prgname();
  207.     int       _errmsg();
  208.     /* from istar.c */
  209.     int       istar();
  210. #endif
  211.  
  212. #ifdef MAIN
  213.     MagicList *magicList;
  214.     char      *progname;
  215.     char      *magic_file;
  216.     char      *file_path = NULL;
  217.     int       recursive = FALSE;
  218.     int       use_stdin = FALSE;
  219.     int       exec_relative = FALSE;
  220. #else
  221.     extern MagicList *magicList;
  222.     extern char      *progname;
  223.     extern char      *magic_file;
  224.     extern char      *file_path;
  225.     extern int       recursive;
  226.     extern int       use_stdin;
  227.     extern int       exec_relative;
  228. #endif
  229.  
  230.