rost@granite.UUCP (01/27/87)
This file contains the source and a man page for "offconv", a utility to convert Object File Format (OFF) files from ascii to binary or vice versa. # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by granite!rost on Tue Jan 27 12:08:08 PST 1987 # Contents: makefile offconv.1 offconv.c echo x - makefile sed 's/^@//' > "makefile" <<'@//E*O*F makefile//' #-------------# # Definitions # #-------------# # Distribution paths GINC_PATH= . # Global executable name GBIN_NAME= offconv # Global executable members GBIN_MEMS= offconv.o # Global libraries GLIBS= liboff.a # Global include files GINCS= $(GINC_PATH)/off.h # Standard libraries SLIBS= # Compilation flags CFLAGS= -I$(GINC_PATH) #--------------------# # Installation Rules # #--------------------# project: $(GBIN_NAME) $(GBIN_NAME): $(GBIN_MEMS) cc $(GBIN_MEMS) $(GLIBS) $(SLIBS) -o $(GBIN_NAME) $(GBIN_MEMS): $(LINCS) #------------------------# # Installation Utilities # #------------------------# clean: rm -f *.o $(GBIN_NAME) print: pr $(LDOCS) $(LINCS) *.c makefile | lpr @//E*O*F makefile// chmod u=rw,g=r,o= makefile echo x - offconv.1 sed 's/^@//' > "offconv.1" <<'@//E*O*F offconv.1//' .TH OFFCONV 1 "14 November 1986" .SH NAME offconv - OFF file conversion utility .SH SYNOPSIS .B offconv [options] inobj outobj .SH DESCRIPTION .I Offconv converts objects in OFF (Object File Format) from ASCII to binary or vice versa. If no options are given, or if the \fI-a\fP option is specified, \fIinobj\fP is read and written as \fIoutobj\fP in ASCII format. If the \fI-b\fP option is given, \fIinobj\fP is read and written as \fIoutobj\fP in binary format. .SH SEE ALSO OFF(3) .SH AUTHOR .PP Copyright 1986, Digital Equipment Corporation .PP .nf Randi J. Rost Digital Equipment Corporation Workstation Systems Engineering Palo Alto, CA .fi .SH BUGS \fIInobj\fP can be the same as \fIoutobj\fP. However, such usage is not recommended. In the event the process is halted (manually or by a system crash), the original file can be blown away. @//E*O*F offconv.1// chmod u=rw,g=r,o= offconv.1 echo x - offconv.c sed 's/^@//' > "offconv.c" <<'@//E*O*F offconv.c//' /* * * Name * offconv * * Description * Convert off (Object File Format) files from ASCII to binary * and vice versa * * Author * Randi J. Rost * Digital Equipment Corp. * Workstation Systems Engineering * Palo Alto, CA * * Diagnostics * Returns -1 if it blows up for any reason * * History * Randi J. Rost 14-Nov-1986 created * */ #include <stdio.h> #include "off.h" main(argc, argv) int argc; char *argv[]; { OFFObjDesc obj; char inbase[80], outbase[80]; char indir[80], outdir[80]; char inext[80], outext[80]; char newname[80]; int i; int first = 1; int toascii = 1; int type; char dir[80], base[80], ext[80]; OFFProperty *pProp; if ((argc < 3) || (argc > 4)) { fprintf(stderr, "usage: %s [-ab] inobj outobj\n", argv[ 0]); exit(-1); } if (argv[1][0] == '-') { switch (argv[1][1]) { case 'a': toascii = 1; first = 2; break; case 'b': toascii = 0; first = 2; break; default: fprintf(stderr, "Unknown option '%s'\n", argv[1]); fprintf(stderr, "usage: %s [-ab] inobj [outobj]\n", argv[0]); exit(-1); } } OFFReadObj(&obj, argv[first]); basename(argv[first], indir, inbase, inext); basename(argv[first + 1], outdir, outbase, outext); pProp = obj.FirstProp; while (pProp != NULL) { if (pProp->PropFileName != NULL) { basename(pProp->PropFileName, dir, base, ext); if (toascii) { strcpy(newname, outbase); strcat(newname, "."); /* The following kludge will not work if there are valid */ /* ASCII file extensions that begin with 'b'. Right now */ /* we assume that if the extension begins with 'b', the */ /* file is in binary. */ if (ext[0] == 'b') strcat(newname, &(ext[1])); else strcat(newname, ext); } else { strcpy(newname, outbase); strcat(newname, ".b"); strcat(newname, ext); } strcpy(pProp->PropFileName, newname); } pProp = pProp->NextProp; } strcat(outbase, ".obj"); if (toascii) type = OFF_ASCII; else type = OFF_BINARY; /* OFFWriteObj(&obj, argv[first + 1], outdir, type);*/ OFFWriteObj(&obj, argv[first + 1], "/", type); } basename(fullname, dir, base, ext) char *fullname; char *dir; char *base; char *ext; { int i, j; i = strlen(fullname); while ((i >= 0) && (fullname[i] != '.')) i--; if (i < 0) { i = 0; ext[0] = '\0'; } else strcpy(ext, &(fullname[i + 1])); j = i; while ((j >= 0) && (fullname[j] != '/')) j--; if (j < 0) { dir[0] = '\0'; } else { strncpy(dir, fullname, j); dir[j] = '\0'; } if ((j <= 0) && (i == 0)) strcpy(base, fullname); else { strncpy(base, &(fullname[j + 1]), i - j - 1); base[i - j - 1] = '\0'; } } @//E*O*F offconv.c// chmod u=rw,g=r,o= offconv.c exit 0