comm: add -Wall
[unleashed.git] / usr / src / cmd / cdrw / options.c
blobe72b68c3272ffe3c23ec59b2f31a6a9275469376
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <string.h>
31 #include "options.h"
33 static uchar_t bitlocation[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
36 * Create a bytemask to store the command line options.
38 void
39 set_options_mask(options *msk, char *str)
41 int i;
42 (void) memset(msk, 0, sizeof (*msk));
43 for (i = 0; str[i] != 0; i++) {
44 add_option(msk, str[i]);
48 void
49 add_option(options *msk, char option)
51 uint_t loc;
52 loc = (uint_t)option;
53 loc &= 0x7f;
54 /* put option into the correct bucket */
55 msk->bitmap[loc >> 3] |= bitlocation[loc & 7];
59 * Compare the bytemask of the command line options used with
60 * acceptable options. If an invalid option is found use it as
61 * the return value.
63 int
64 compare_options_mask(options *msk, options *specified)
66 int i, j;
67 uchar_t bmap = 0;
69 for (i = 0; i < 16; i++) {
70 if (msk->bitmap[i] == specified->bitmap[i])
71 continue;
72 bmap = msk->bitmap[i] | specified->bitmap[i];
73 bmap ^= msk->bitmap[i];
74 if (bmap)
75 break;
77 if (i == 16) {
78 /* no invalid options found */
79 return (0);
82 for (j = 0; j < 8; j++) {
83 if (bmap & bitlocation[j])
84 break;
86 return ((i*8) + j);