diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2001-03-24 00:21:00 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2001-03-24 00:21:00 +0000 |
commit | 94089e320a4f38bc5785d2215799181bcb323150 (patch) | |
tree | 7558003ccdb27340ff972cfe8c466d5d011b312e | |
parent | ffb72f990c9933280de104024acf91acee02c1a5 (diff) |
Make the apple code compile for OpenBSD. These changes are mostly from maja.
-rw-r--r-- | sbin/pdisk/Makefile | 10 | ||||
-rw-r--r-- | sbin/pdisk/errors.c | 16 | ||||
-rw-r--r-- | sbin/pdisk/file_media.c | 20 | ||||
-rw-r--r-- | sbin/pdisk/io.c | 2 | ||||
-rw-r--r-- | sbin/pdisk/makefile | 197 | ||||
-rw-r--r-- | sbin/pdisk/pdisk.c | 70 |
6 files changed, 109 insertions, 206 deletions
diff --git a/sbin/pdisk/Makefile b/sbin/pdisk/Makefile new file mode 100644 index 00000000000..ee2535b800b --- /dev/null +++ b/sbin/pdisk/Makefile @@ -0,0 +1,10 @@ +# $Id: Makefile,v 1.1 2001/03/24 00:20:59 drahn Exp $ + +PROG= pdisk + +SRCS= pdisk.c dump.c partition_map.c convert.c io.c errors.c bitfield.c \ + deblock_media.c file_media.c media.c pathname.c util.c validate.c + +MAN= pdisk.8 + +.include <bsd.prog.mk> diff --git a/sbin/pdisk/errors.c b/sbin/pdisk/errors.c index 9f4051cc98d..4396fc2114d 100644 --- a/sbin/pdisk/errors.c +++ b/sbin/pdisk/errors.c @@ -78,7 +78,7 @@ extern const char * const sys_errlist[]; void init_program_name(char **argv) { -#ifdef __linux__ +#if defined(__linux__) || defined(__OpenBSD__) if ((program_name = strrchr(argv[0], '/')) != (char *)NULL) { program_name++; } else { @@ -93,11 +93,19 @@ init_program_name(char **argv) void do_help() { +#ifndef __OpenBSD__ printf("\t%s [-h|--help]\n", program_name); printf("\t%s [-v|--version]\n", program_name); printf("\t%s [-l|--list [name ...]]\n", program_name); printf("\t%s [-r|--readonly] name ...\n", program_name); printf("\t%s [-i|--interactive]\n", program_name); +#else + printf("\t%s [-h]\n", program_name); + printf("\t%s [-v]\n", program_name); + printf("\t%s [-l [name ...]]\n", program_name); + printf("\t%s [-r] name ...\n", program_name); + printf("\t%s [-i]\n", program_name); +#endif printf("\t%s name ...\n", program_name); } @@ -125,7 +133,7 @@ fatal(int value, char *fmt, ...) vfprintf(stderr, fmt, ap); va_end(ap); -#if defined(__linux__) || defined(NeXT) +#if defined(__linux__) || defined(NeXT) || defined(__OpenBSD__) if (value > 0 && value < sys_nerr) { fprintf(stderr, " (%s)\n", sys_errlist[value]); } else { @@ -135,7 +143,7 @@ fatal(int value, char *fmt, ...) fprintf(stderr, "\n"); #endif -#ifndef __linux__ +#if !defined(__linux__) && !defined(__OpenBSD__) printf("Processing stopped: Choose 'Quit' from the file menu to quit.\n\n"); #endif exit(value); @@ -157,7 +165,7 @@ error(int value, char *fmt, ...) vfprintf(stderr, fmt, ap); va_end(ap); -#if defined(__linux__) || defined(NeXT) +#if defined(__linux__) || defined(NeXT) || defined(__OpenBSD__) if (value > 0 && value < sys_nerr) { fprintf(stderr, " (%s)\n", sys_errlist[value]); } else { diff --git a/sbin/pdisk/file_media.c b/sbin/pdisk/file_media.c index 1b1e66f52fe..043bb0596bc 100644 --- a/sbin/pdisk/file_media.c +++ b/sbin/pdisk/file_media.c @@ -45,6 +45,10 @@ #include <sys/stat.h> #endif +#ifdef __OpenBSD__ +#include <sys/stat.h> +#endif + #include "file_media.h" #include "errors.h" @@ -195,7 +199,7 @@ open_file_as_media(char *file, int oflag) FILE_MEDIA a; int fd; loff_t off; -#ifdef __linux__ +#if defined(__linux__) || defined(__OpenBSD__) struct stat info; #endif @@ -224,7 +228,7 @@ open_file_as_media(char *file, int oflag) a->m.do_os_reload = os_reload_file_media; a->fd = fd; a->regular_file = 0; -#ifdef __linux__ +#if defined(__linux__) || defined(__OpenBSD__) if (fstat(fd, &info) < 0) { error(errno, "can't stat file '%s'", file); } else { @@ -489,13 +493,25 @@ step_file_iterator(MEDIA_ITERATOR m) */ switch (a->style) { case kSCSI_Disks: +#ifdef __OpenBSD__ + sprintf(result, "/dev/sd%dc", (int)a->index); +#else sprintf(result, "/dev/sd%c", 'a'+(int)a->index); +#endif break; case kATA_Devices: +#ifdef __OpenBSD__ + sprintf(result, "/dev/wd%dc", (int)a->index); +#else sprintf(result, "/dev/hd%c", 'a'+(int)a->index); +#endif break; case kSCSI_CDs: +#ifdef __OpenBSD__ + sprintf(result, "/dev/cd%dc", (int)a->index); +#else sprintf(result, "/dev/scd%c", '0'+(int)a->index); +#endif break; } if (stat(result, &info) < 0) { diff --git a/sbin/pdisk/io.c b/sbin/pdisk/io.c index 64d2ed495cb..47800bd314a 100644 --- a/sbin/pdisk/io.c +++ b/sbin/pdisk/io.c @@ -29,7 +29,7 @@ #include <stdio.h> // for malloc() & free() -#if !defined(__linux__) && !defined(__unix__) +#if !defined(__linux__) && !defined(__unix__) || defined(__OpenBSD__) #include <stdlib.h> #else #include <malloc.h> diff --git a/sbin/pdisk/makefile b/sbin/pdisk/makefile deleted file mode 100644 index 4b68e7be69b..00000000000 --- a/sbin/pdisk/makefile +++ /dev/null @@ -1,197 +0,0 @@ -# -# Makefile for pdisk -# - -MAN_PAGE= \ - pdisk.8 - -MAC_DOC= \ - pdisk.html - -DOCS= \ - HISTORY \ - README \ - $(MAN_PAGE) \ - $(MAC_DOC) - -SERVER_README = \ - dist.README - -SERVER_MESSAGE = \ - dist.message - -DOCS_INTERNAL= \ - HISTORY.ALL \ - HOWTO.DISTRIBUTE \ - To_do_list \ - command-language \ - pdisk.man.html \ - $(SERVER_README) \ - $(SERVER_MESSAGE) - -SUPPORT= \ - make_filename \ - make_depend \ - make_tags \ - checkin_files \ - MPWcompare \ - name_latest \ - next_release - -MAC_SOURCE= \ - ATA_media.c \ - ATA_media.h \ - DoSCSICommand.c \ - DoSCSICommand.h \ - MacSCSICommand.h \ - SCSI_media.c \ - SCSI_media.h \ - pdisk.r - -UNIX_SOURCE= \ - bitfield.c \ - bitfield.h \ - convert.c \ - convert.h \ - deblock_media.c \ - deblock_media.h \ - dpme.h \ - dump.c \ - dump.h \ - errors.c \ - errors.h \ - file_media.c \ - file_media.h \ - io.c \ - io.h \ - layout_dump.c \ - layout_dump.h \ - makefile \ - media.c \ - media.h \ - partition_map.c \ - partition_map.h \ - pathname.c \ - pathname.h \ - pdisk.c \ - pdisk.h \ - util.c \ - util.h \ - validate.c \ - validate.h \ - version.h - -UNIX_OBJECTS = \ - pdisk.o \ - dump.o \ - partition_map.o \ - convert.o \ - io.o \ - errors.o \ - bitfield.o \ - deblock_media.o \ - file_media.o \ - media.o \ - pathname.o \ - util.o \ - validate.o - - -ALL_FILES= $(DOCS) $(DOCS_INTERNAL) $(SUPPORT) $(MAC_SOURCE) $(UNIX_SOURCE) - -UNIX_BINARY= \ - pdisk - -# -# these names have '__' in place of ' ' to avoid quoting nightmares -# -MAC_PROJECT= \ - pdisk.mac.bin \ - pdisk.mac__Data/CW__Settings.stg.bin \ - pdisk.mac__Data/pdisk.tdt.bin \ - pdisk.mac__Data/pdisk__68k.tdt.bin - -# Constructed under MacOS using CodeWarrior from MAC_PROJECT & sources -MAC_BINARY= \ - pdisk.hqx - -MAC_68KBINARY= \ - pdisk_68k.hqx - - -CFLAGS = -Wall -DIST_TAR_FLAGS = cvf - - -all: pdisk - -pdisk: $(UNIX_OBJECTS) - -clean: - rm -f *.o $(UNIX_BINARY) list.src - -clobber: clean - rm -f $(ALL_FILES) $(MAC_BINARY) $(MAC_68KBINARY) tags - -# note the sed to reinsert the spaces in the Mac names -list.src: $(MAC_SOURCE) $(DOCS) $(UNIX_SOURCE) $(MAC_PROJECT) - echo $(MAC_SOURCE) $(DOCS) $(UNIX_SOURCE) $(MAC_PROJECT) |\ - tr ' ' '\n' | sed -e 's/__/ /g' -e 's,^,pdisk/,' >list.src - -# -# this depends on this source directory being named 'pdisk' -# -distribution: list.src - cd ..; tar $(DIST_TAR_FLAGS) pdisk/dist/pdisk.src.tar.`date +%y%m%d` --files-from pdisk/list.src - tar $(DIST_TAR_FLAGS) dist/pdisk.bin.tar.`date +%y%m%d` $(UNIX_BINARY) $(MAN_PAGE) - cp $(MAC_DOC) dist/$(MAC_DOC).`date +%y%m%d` - cp $(MAC_BINARY) dist/$(MAC_BINARY).`date +%y%m%d` - cp $(MAC_68KBINARY) dist/$(MAC_68KBINARY).`date +%y%m%d` - cp $(SERVER_README) dist/README - cp $(SERVER_MESSAGE) dist/.message - -checkin: - ./checkin_files $(ALL_FILES) - -checkout: $(ALL_FILES) - -diff: - rcsdiff $(ALL_FILES) 2>&1 - -name: - ./name_latest $(ALL_FILES) - -# -# in lieu of a real dependency generator -# -convert.h: dpme.h -deblock_media.h: media.h -dpme.h: bitfield.h -dump.h: partition_map.h -file_media.h: media.h -partition_map.h: dpme.h media.h -pathname.h: media.h -validate.h: partition_map.h - -bitfield.o: bitfield.c bitfield.h -convert.o: convert.c convert.h -deblock_media.o: deblock_media.c deblock_media.h -dump.o: dump.c dump.h pathname.h io.h errors.h -errors.o: errors.c errors.h -file_media.o: file_media.c file_media.h errors.h -io.o: io.c io.h errors.h -layout_dump.o: layout_dump.c layout_dump.h -media.o: media.c media.h -partition_map.o: partition_map.c partition_map.h pathname.h deblock_media.h io.h convert.h util.h errors.h -pathname.o: pathname.c pathname.h file_media.h -pdisk.o: pdisk.c pdisk.h io.h partition_map.h pathname.h errors.h dump.h validate.h version.h util.h -util.o: util.c version.h util.h -validate.o: validate.c validate.h deblock_media.h pathname.h convert.h io.h errors.h - - -# -# fake dependencies used only by list.src {for $(MAC_PROJECT)} -# -pdisk.mac__Data/CW__Settings.stg.bin: -pdisk.mac__Data/pdisk.tdt.bin: -pdisk.mac__Data/pdisk__68k.tdt.bin: diff --git a/sbin/pdisk/pdisk.c b/sbin/pdisk/pdisk.c index 033a16c1fe7..bba6273800e 100644 --- a/sbin/pdisk/pdisk.c +++ b/sbin/pdisk/pdisk.c @@ -33,6 +33,8 @@ #ifdef __linux__ #include <getopt.h> #include <malloc.h> +#elif defined(__OpenBSD__) +#include <stdlib.h> #else // for malloc() & free() #include <stdlib.h> @@ -139,7 +141,7 @@ void print_top_notes(); int main(int argc, char **argv) { -#ifdef __linux__ +#if defined(__linux__) || defined (__OpenBSD__) int name_index; #else printf("This app uses the SIOUX console library\n"); @@ -167,7 +169,7 @@ main(int argc, char **argv) VERSION, get_version_string()); } -#ifdef __linux__ +#if defined(__linux__) || defined(__OpenBSD__) name_index = get_options(argc, argv); if (vflag) { @@ -444,6 +446,68 @@ get_options(int argc, char **argv) } #endif +#ifdef __OpenBSD__ +int +get_options(int argc, char **argv) +{ + int c; + extern int optind; + extern char *optarg; + int flag = 0; + + lflag = LFLAG_DEFAULT; + lfile = NULL; + vflag = VFLAG_DEFAULT; + hflag = HFLAG_DEFAULT; + dflag = DFLAG_DEFAULT; + rflag = RFLAG_DEFAULT; + aflag = AFLAG_DEFAULT; + pflag = PFLAG_DEFAULT; + interactive = INTERACT_DEFAULT; + cflag = CFLAG_DEFAULT; + + optind = 1; // reset option scanner logic + while ((c = getopt(argc, argv, "hlvdric")) != -1) { + switch (c) { + case 'h': + hflag = (HFLAG_DEFAULT)?0:1; + break; + case 'l': + lflag = (LFLAG_DEFAULT)?0:1; + break; + case 'v': + vflag = (VFLAG_DEFAULT)?0:1; + break; + case 'd': + dflag = (DFLAG_DEFAULT)?0:1; + break; + case 'c': + cflag = (CFLAG_DEFAULT)?0:1; + break; + case 'r': + rflag = (RFLAG_DEFAULT)?0:1; + break; + case 'i': + interactive = (INTERACT_DEFAULT)?0:1; + break; + case 'a': + aflag = (AFLAG_DEFAULT)?0:1; + break; + case kLogicalOption: + pflag = (PFLAG_DEFAULT)?0:1; + break; + default: + flag = 1; + break; + } + } + if (flag) { + usage("bad arguments"); + } + return optind; +} +#endif + void print_edit_notes() @@ -872,7 +936,9 @@ do_expert(partition_map_header *map, char *name) do_examine_patch_partition(map); break; default: +#ifndef __OpenBSD__ do_error: +#endif bad_input("No such command (%c)", command); break; } |