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.
26 /* functions supported:
27 create a library (no extra operands required)
28 add a module from a library (requires filename and name to give mod.)
29 remove a module from a library (requires given name) (not implemented)
30 extract a module from the library (requires given name and filename)
35 " rdflib x libname [extra operands]\n\n"
36 " where x is one of:\n"
37 " c - create library\n"
38 " a - add module (operands = filename module-name)\n"
39 " r - remove (module-name) [not implemented]\n"
40 " x - extract (module-name filename)\n"
45 #define _ENDIANNESS 0 /* 0 for little, 1 for big */
47 static void longtolocal(long * l
)
51 unsigned char * p
= (unsigned char *) l
;
62 char copybytes(FILE *fp
, FILE *fp2
, int n
)
66 for (i
= 0 ; i
< n
; i
++ )
71 fprintf(stderr
,"rdflib: premature end of file in '%s'\n",
76 if (fputc(t
, fp2
) == EOF
)
78 fprintf(stderr
,"rdflib: write error\n");
82 return (char) t
; /* return last char read */
85 long copylong(FILE *fp
, FILE *fp2
)
89 unsigned char * p
= (unsigned char *) &l
;
92 for (i
= 0 ; i
< 4; i
++ ) /* skip magic no */
97 fprintf(stderr
,"rdflib: premature end of file in '%s'\n",
102 if (fputc(t
, fp2
) == EOF
)
104 fprintf(stderr
,"rdflib: write error\n");
113 int main(int argc
, char **argv
)
116 char *p
, buf
[256], c
;
122 if (argc
< 3 || !strncmp(argv
[1],"-h",2) || !strncmp(argv
[1],"--h",3))
130 case 'c': /* create library */
131 fp
= fopen(argv
[2],"wb");
133 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[2]);
140 case 'a': /* add module */
142 fprintf(stderr
,"rdflib: required parameter missing\n");
145 fp
= fopen(argv
[2],"ab");
148 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[2]);
153 fp2
= fopen(argv
[3],"rb");
156 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[3]);
163 if ( fputc(*p
,fp
) == EOF
) {
164 fprintf(stderr
,"rdflib: write error\n");
169 while (! feof (fp2
) ) {
175 if ( fputc(i
, fp
) == EOF
) {
176 fprintf(stderr
,"rdflib: write error\n");
186 fprintf(stderr
,"rdflib: required parameter missing\n");
191 fprintf(stderr
, "rdflib: required paramenter missing\n");
194 fp
= fopen(argv
[2],"rb");
197 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[2]);
203 while (! feof(fp
) ) {
206 while( ( *(p
++) = (char) fgetc(fp
) ) )
212 if (argv
[1][0] == 'x') {
213 /* check against desired name */
214 if (! strcmp(buf
,argv
[3]) )
216 fp2
= fopen(argv
[4],"wb");
219 fprintf(stderr
,"rdflib: could not open '%s'\n",argv
[4]);
226 printf("%-40s ", buf
);
228 /* step over the RDOFF file, extracting type information for
229 * the listing, and copying it if fp2 != NULL */
233 if (argv
[1][0] == 't')
234 for (i
= 0; i
< 6; i
++)
235 printf("%c", copybytes(fp
,fp2
,1));
239 l
= copylong(fp
,fp2
);
241 if (argv
[1][0] == 't') printf(" %ld bytes content\n", l
);
245 else if ((c
=copybytes(fp
,fp2
,6)) >= '2') /* version 2 or above */
247 l
= copylong(fp
,fp2
);
249 if (argv
[1][0] == 't')
250 printf("RDOFF%c %ld bytes content\n", c
, l
);
251 copybytes(fp
,fp2
, l
); /* entire object */
255 if (argv
[1][0] == 't')
258 * version 1 object, so we don't have an object content
261 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* header */
262 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* text */
263 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* data */
272 else if (argv
[1][0] == 'x')
274 fprintf(stderr
,"rdflib: module '%s' not found in '%s'\n",
281 fprintf(stderr
,"rdflib: command '%c' not recognised\n",