/* * Copyright (c) 2001-2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The 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, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * bless.c * bless * * Created by Shantonu Sen on Wed Nov 14 2001. * Copyright (c) 2001-2003 Apple Computer, Inc. All rights reserved. * * $Id: bless.c,v 1.58 2003/08/04 06:38:45 ssen Exp $ * */ #include #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(BLContextPtr context, struct clopt commandlineopts[klast], struct clarg actargs[klast]); int modeDevice(BLContextPtr context, struct clopt commandlineopts[klast], struct clarg actargs[klast]); int modeFolder(BLContextPtr 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[]); void usage_short(); void arg_err(char *message, char *opt); int main (int argc, char * argv[]) { int i; BLContext context; struct blesscon bcon; bcon.quiet = 0; bcon.verbose = 0; context.version = 0; context.logstring = blesslog; context.logrefcon = &bcon; initConfig(); if(argc == 1) { arg_err(NULL, NULL); } /* 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(!strcasecmp(&(argv[i][1]), commandlineopts[j].flag)) { if(commandlineopts[j].takesarg == aRequired) { if(i+1 >= argc) { arg_err("Missing argument for option", argv[i]); /* no arg given */ } i++; 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+1logstring(context->logrefcon, loglevel, "Memory error, log entry not available"); } ret = context->logstring(context->logrefcon, loglevel, out); free(out); return ret; } void arg_err(char *message, char *opt) { if(!(message == NULL && opt == NULL)) fprintf(stderr, "%s \"%s\"\n", message, opt); usage_short(); }