1 /* rdflib - manipulate RDOFF library files (.rdl) */
4 * an rdoff library is simply a sequence of RDOFF object files, each
5 * preceded by the name of the module, an ASCII string of up to 255
6 * characters, terminated by a zero.
8 * There may be an optional
9 * directory placed on the end of the file. The format of the
10 * directory will be 'RDLDD' followed by a version number, followed by
11 * the length of the directory, and then the directory, the format of
12 * which has not yet been designed. The module name of the directory
15 * All module names beginning with '.' are reserved
16 * for possible future extensions. The linker ignores all such modules,
17 * assuming they have the format of a six byte type & version identifier
18 * followed by long content size, followed by data.
25 /* functions supported:
26 create a library (no extra operands required)
27 add a module from a library (requires filename and name to give mod.)
28 remove a module from a library (requires given name) (not implemented)
29 extract a module from the library (requires given name and filename)
34 " rdflib x libname [extra operands]\n\n"
35 " where x is one of:\n"
36 " c - create library\n"
37 " a - add module (operands = filename module-name)\n"
38 " r - remove (module-name) [not implemented]\n"
39 " x - extract (module-name filename)\n"
44 #define _ENDIANNESS 0 /* 0 for little, 1 for big */
46 static void longtolocal(long * l
)
50 unsigned char * p
= (unsigned char *) l
;
61 char copybytes(FILE *fp
, FILE *fp2
, int n
)
65 for (i
= 0 ; i
< n
; i
++ )
70 fprintf(stderr
,"rdflib: premature end of file in '%s'\n",
75 if (fputc(t
, fp2
) == EOF
)
77 fprintf(stderr
,"rdflib: write error\n");
81 return (char) t
; /* return last char read */
84 long copylong(FILE *fp
, FILE *fp2
)
88 unsigned char * p
= (unsigned char *) &l
;
91 for (i
= 0 ; i
< 4; i
++ ) /* skip magic no */
96 fprintf(stderr
,"rdflib: premature end of file in '%s'\n",
101 if (fputc(t
, fp2
) == EOF
)
103 fprintf(stderr
,"rdflib: write error\n");
112 int main(int argc
, char **argv
)
115 char *p
, buf
[256], c
;
121 if (argc
< 3 || !strncmp(argv
[1],"-h",2) || !strncmp(argv
[1],"--h",3))
129 case 'c': /* create library */
130 fp
= fopen(argv
[2],"wb");
132 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[2]);
139 case 'a': /* add module */
141 fprintf(stderr
,"rdflib: required parameter missing\n");
144 fp
= fopen(argv
[2],"ab");
147 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[2]);
152 fp2
= fopen(argv
[3],"rb");
155 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[3]);
162 if ( fputc(*p
,fp
) == EOF
) {
163 fprintf(stderr
,"rdflib: write error\n");
168 while (! feof (fp2
) ) {
174 if ( fputc(i
, fp
) == EOF
) {
175 fprintf(stderr
,"rdflib: write error\n");
185 fprintf(stderr
,"rdflib: required parameter missing\n");
190 fprintf(stderr
, "rdflib: required paramenter missing\n");
193 fp
= fopen(argv
[2],"rb");
196 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[2]);
202 while (! feof(fp
) ) {
205 while( ( *(p
++) = (char) fgetc(fp
) ) )
211 if (argv
[1][0] == 'x') {
212 /* check against desired name */
213 if (! strcmp(buf
,argv
[3]) )
215 fp2
= fopen(argv
[4],"wb");
218 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[4]);
225 printf("%-40s ", buf
);
227 /* step over the RDOFF file, extracting type information for
228 * the listing, and copying it if fp2 != NULL */
232 if (argv
[1][0] == 't')
233 for (i
= 0; i
< 6; i
++)
234 printf("%c", copybytes(fp
,fp2
,1));
238 l
= copylong(fp
,fp2
);
240 if (argv
[1][0] == 't') printf(" %ld bytes content\n", l
);
244 else if ((c
=copybytes(fp
,fp2
,6)) >= '2') /* version 2 or above */
246 l
= copylong(fp
,fp2
);
248 if (argv
[1][0] == 't')
249 printf("RDOFF%c %ld bytes content\n", c
, l
);
250 copybytes(fp
,fp2
, l
); /* entire object */
254 if (argv
[1][0] == 't')
257 * version 1 object, so we don't have an object content
260 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* header */
261 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* text */
262 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* data */
271 else if (argv
[1][0] == 'x')
273 fprintf(stderr
,"rdflib: module '%s' not found in '%s'\n",
280 fprintf(stderr
,"rdflib: command '%c' not recognised\n",