1 /* rdflib - manipulate RDOFF library files (.rdl) */
3 /* an rdoff library is simply a sequence of RDOFF object files, each
4 preceded by the name of the module, an ASCII string of up to 255
5 characters, terminated by a zero. There may be an optional
6 directory placed on the end of the file. The format of the
7 directory will be 'RDL' followed by a version number, followed by
8 the length of the directory, and then the directory, the format of
9 which has not yet been designed. */
15 /* functions supported:
16 create a library (no extra operands required)
17 add a module from a library (requires filename and name to give mod.)
18 remove a module from a library (requires given name)
19 extract a module from the library (requires given name and filename)
24 " rdflib x libname [extra operands]\n\n"
25 " where x is one of:\n"
26 " c - create library\n"
27 " a - add module (operands = filename module-name)\n"
28 " r - remove (module-name)\n"
29 " x - extract (module-name filename)\n"
34 #define _ENDIANNESS 0 /* 0 for little, 1 for big */
36 static void longtolocal(long * l
)
40 unsigned char * p
= (unsigned char *) l
;
51 void copybytes(FILE *fp
, FILE *fp2
, int n
)
55 for (i
= 0 ; i
< n
; i
++ )
60 fprintf(stderr
,"ldrdf: premature end of file in '%s'\n",
65 if (fputc(t
, fp2
) == EOF
)
67 fprintf(stderr
,"ldrdf: write error\n");
73 long copylong(FILE *fp
, FILE *fp2
)
77 unsigned char * p
= (unsigned char *) &l
;
80 for (i
= 0 ; i
< 4; i
++ ) /* skip magic no */
85 fprintf(stderr
,"ldrdf: premature end of file in '%s'\n",
90 if (fputc(t
, fp2
) == EOF
)
92 fprintf(stderr
,"ldrdf: write error\n");
101 int main(int argc
, char **argv
)
109 if (argc
< 3 || !strncmp(argv
[1],"-h",2) || !strncmp(argv
[1],"--h",3))
117 case 'c': /* create library */
118 fp
= fopen(argv
[2],"wb");
120 fprintf(stderr
,"ldrdf: could not open '%s'\n",argv
[2]);
127 case 'a': /* add module */
129 fprintf(stderr
,"ldrdf: required parameter missing\n");
132 fp
= fopen(argv
[2],"ab");
135 fprintf(stderr
,"ldrdf: could not open '%s'\n",argv
[2]);
140 fp2
= fopen(argv
[3],"rb");
143 fprintf(stderr
,"ldrdf: could not open '%s'\n",argv
[3]);
150 if ( fputc(*p
,fp
) == EOF
) {
151 fprintf(stderr
,"ldrdf: write error\n");
156 while (! feof (fp2
) ) {
162 if ( fputc(i
, fp
) == EOF
) {
163 fprintf(stderr
,"ldrdf: write error\n");
173 fprintf(stderr
,"ldrdf: required parameter missing\n");
177 fp
= fopen(argv
[2],"rb");
180 fprintf(stderr
,"ldrdf: could not open '%s'\n",argv
[2]);
186 while (! feof(fp
) ) {
189 while( ( *(p
++) = (char) fgetc(fp
) ) )
194 /* check against desired name */
195 if (! strcmp(buf
,argv
[3]) )
197 fp2
= fopen(argv
[4],"wb");
200 fprintf(stderr
,"ldrdf: could not open '%s'\n", argv
[4]);
208 /* step over the RDOFF file, copying it if fp2 != NULL */
209 copybytes(fp
,fp2
,6); /* magic number */
210 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* header */
211 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* text */
212 copybytes(fp
,fp2
, copylong(fp
,fp2
)); /* data */
222 fprintf(stderr
,"ldrdf: module '%s' not found in '%s'\n",
229 fprintf(stderr
,"ldrdf: command '%c' not recognised\n",