Guido van Rossum | d8eb211 | 1998-08-04 17:57:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** mwlib.h - POSIX 1003.2 "ar" command |
| 3 | ** |
| 4 | ** $Id$ |
| 5 | ** |
| 6 | ** This isn't a pure POSIX 1003.2 ar; it only manipulates Metrowerks |
| 7 | ** Library files, not general-purpose POSIX 1003.2 format archives. |
| 8 | ** |
| 9 | ** Dec. 14, 1997 Chris Herborth (chrish@qnx.com) |
| 10 | ** |
| 11 | ** This code is donated to the PUBLIC DOMAIN. You can use, abuse, modify, |
| 12 | ** redistribute, steal, or otherwise manipulate this code. No restrictions |
| 13 | ** at all. If you laugh at this code, you can't use it. |
| 14 | ** |
| 15 | ** This "ar" was implemented using IEEE Std 1003.2-1992 as the basis for |
| 16 | ** the interface, and Metrowerk's published docs detailing their library |
| 17 | ** format. Look inside for clues about how reality differs from MW's |
| 18 | ** documentation on BeOS... |
| 19 | */ |
| 20 | |
| 21 | #include <support/SupportDefs.h> |
| 22 | #include <time.h> |
| 23 | |
| 24 | /* ---------------------------------------------------------------------- |
| 25 | ** Constants |
| 26 | ** |
| 27 | */ |
| 28 | #define MWLIB_MAGIC_WORD 'MWOB' |
| 29 | #define MWLIB_MAGIC_PROC 'PPC ' |
| 30 | |
| 31 | /* ---------------------------------------------------------------------- |
| 32 | ** Structures |
| 33 | ** |
| 34 | ** This is based on the "Metrowerks CodeWarrior Library Reference |
| 35 | ** Specification", which isn't 100% accurate for BeOS. |
| 36 | */ |
| 37 | |
| 38 | typedef struct MWLibHeader { |
| 39 | uint32 magicword; |
| 40 | uint32 magicproc; |
| 41 | uint32 magicflags; |
| 42 | uint32 version; |
| 43 | |
| 44 | uint32 code_size; |
| 45 | uint32 data_size; |
| 46 | |
| 47 | uint32 num_objects; |
| 48 | } MWLibHeader; |
| 49 | |
| 50 | typedef struct MWLibFile { |
| 51 | time_t m_time; |
| 52 | |
| 53 | uint32 off_filename; |
| 54 | uint32 off_fullpath; |
| 55 | uint32 off_object; |
| 56 | uint32 object_size; |
| 57 | } MWLibFile; |
| 58 | |
| 59 | typedef struct MWLib { |
| 60 | MWLibHeader header; |
| 61 | |
| 62 | MWLibFile *files; |
| 63 | |
| 64 | char **names; |
| 65 | |
| 66 | char **data; |
| 67 | } MWLib; |
| 68 | |
| 69 | /* This bears no resemblance to what's in the Metrowerks docs. |
| 70 | ** |
| 71 | ** Note that this is incomplete; this is all the info I needed for |
| 72 | ** ar though. |
| 73 | */ |
| 74 | typedef struct MWObject { |
| 75 | uint32 magic_word; /* 'MWOB' */ |
| 76 | uint32 arch; /* 'PPC '; this isn't in the docs */ |
| 77 | uint32 version; |
| 78 | uint32 flags; |
| 79 | |
| 80 | uint32 code_size; |
| 81 | uint32 data_size; |
| 82 | } MWObject; |
| 83 | |
| 84 | /* ---------------------------------------------------------------------- |
| 85 | ** Function prototypes |
| 86 | ** |
| 87 | ** load_MW_lib() - load a Metrowerks library |
| 88 | ** |
| 89 | ** Returns: |
| 90 | ** B_OK - all is well |
| 91 | ** B_FILE_NOT_FOUND - can't open the given file |
| 92 | ** B_IO_ERROR - can't read from the given file |
| 93 | ** B_BAD_VALUE - invalid magic word in the file |
| 94 | ** B_MISMATCHED_VALUES - invalid processor value (ie, not a PowerPC lib), |
| 95 | ** or the magicflags member is not 0, or the file |
| 96 | ** version number isn't 1. |
| 97 | ** B_NO_MEMORY - unable to allocate memory while loading the lib |
| 98 | ** |
| 99 | ** write_MW_lib() - write a Metrowerks library |
| 100 | ** |
| 101 | ** Returns: |
| 102 | ** B_OK - all is well |
| 103 | ** |
| 104 | ** write_MW_lib() - write a Metrowerks library file |
| 105 | ** |
| 106 | ** Returns: |
| 107 | ** B_OK - all is well; doesn't necessarily mean the file was written |
| 108 | ** properly, just that you didn't lose any data |
| 109 | ** B_NO_MEMORY - unable to allocate offset buffers |
| 110 | ** B_ERROR - problem with backup file (can't rename existing file) |
| 111 | ** |
| 112 | ** Note: |
| 113 | ** If you use this in a long-lived program, it leaks memory; the MWLib |
| 114 | ** contents are never free()'d. |
| 115 | */ |
| 116 | status_t load_MW_lib( MWLib *lib, const char *filename ); |
| 117 | status_t write_MW_lib( MWLib *lib, const char *filename ); |
| 118 | void setfiletype( const char *filename, const char *type ); |