/* * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ #include #include #include #include #include "enums.h" #include "structs.h" #include "bless.h" #define xstr(s) str(s) #define str(s) #s struct clopt commandlineopts[klast]; struct clarg actargs[klast]; int modeInfo(BLContext context, struct clopt commandlineopts[klast], struct clarg actargs[klast]); int modeDevice(BLContext context, struct clopt commandlineopts[klast], struct clarg actargs[klast]); int modeFolder(BLContext context, struct clopt commandlineopts[klast], struct clarg actargs[klast]); int blesslog(void *context, int loglevel, const char *string); static void initConfig(); void usage(struct clopt[]); int main (int argc, const char * argv[]) { int i; BLContextStruct context; struct blesscon bcon; bcon.quiet = 0; bcon.verbose = 0; context.logstring = blesslog; context.logrefcon = &bcon; #ifndef __ppc__ // yay, this works on ppc-based arches fprintf(stderr, xstr(PROGRAM) " only runs on PowerPC-based Darwin machines\n"); exit(1); #endif initConfig(); if(argc == 1) { usage(commandlineopts); } /* start at 1, since argc >=2 */ for(i=1; i < argc; i++) { int j; int found = 0; /* check against each option */ for(j=0; j < klast; j++) { /* if it matches the option text */ if(!strcmp(&(argv[i][1]), commandlineopts[j].flag)) { if(commandlineopts[j].takesarg == aRequired) { i++; if(i >= argc ) usage(commandlineopts); /* no arg given */ strncpy(actargs[j].argument, argv[i], kMaxArgLength-1); actargs[j].argument[kMaxArgLength-1] = '\0'; actargs[j].hasArg = 1; found = 1; break; } else if(commandlineopts[j].takesarg == aOptional) { if((i+1>=argc) || ((i+1