/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Written By Julian ELischer4* Copyright julian Elischer 1993.5* Permission is granted to use or redistribute this file in any way as long6* as this notice remains. Julian Elischer does not guarantee that this file7* is totally correct for any given task and users of this file must8* accept responsibility for any damage that occurs from the application of this9* file.10*11* ([email protected] [email protected])12*13* User SCSI hooks added by Peter Dufault:14*15* Copyright (c) 1994 HD Associates16* (contact: [email protected])17* All rights reserved.18*19* Redistribution and use in source and binary forms, with or without20* modification, are permitted provided that the following conditions21* are met:22* 1. Redistributions of source code must retain the above copyright23* notice, this list of conditions and the following disclaimer.24* 2. Redistributions in binary form must reproduce the above copyright25* notice, this list of conditions and the following disclaimer in the26* documentation and/or other materials provided with the distribution.27* 3. The name of HD Associates28* may not be used to endorse or promote products derived from this software29* without specific prior written permission.30*31* THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES ``AS IS'' AND32* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE33* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE34* ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES BE LIABLE35* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL36* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS37* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)38* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT39* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY40* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF41* SUCH DAMAGE.42*/43/*44* Taken from the original scsi(8) program.45* from: scsi.c,v 1.17 1998/01/12 07:57:57 charnier Exp $";46*/47#include <sys/cdefs.h>48#include <sys/stdint.h>49#include <sys/types.h>5051#include <stdlib.h>52#include <stdio.h>53#include <string.h>5455#include <camlib.h>56#include "ctladm.h"5758static int verbose;5960/* iget: Integer argument callback61*/62int63iget(void *hook, char *name)64{65struct get_hook *h = (struct get_hook *)hook;66int arg;6768if (h->got >= h->argc)69{70fprintf(stderr, "Expecting an integer argument.\n");71usage(0);72exit(1);73}74arg = strtol(h->argv[h->got], 0, 0);75h->got++;7677if (verbose && name && *name)78printf("%s: %d\n", name, arg);7980return arg;81}8283/* cget: char * argument callback84*/85char *86cget(void *hook, char *name)87{88struct get_hook *h = (struct get_hook *)hook;89char *arg;9091if (h->got >= h->argc)92{93fprintf(stderr, "Expecting a character pointer argument.\n");94usage(0);95exit(1);96}97arg = h->argv[h->got];98h->got++;99100if (verbose && name)101printf("cget: %s: %s", name, arg);102103return arg;104}105106/* arg_put: "put argument" callback107*/108void109arg_put(void *hook __unused, int letter, void *arg, int count, char *name)110{111if (verbose && name && *name)112printf("%s: ", name);113114switch(letter)115{116case 'i':117case 'b':118printf("%jd ", (intmax_t)(intptr_t)arg);119break;120121case 'c':122case 'z':123{124char *p;125126p = malloc(count + 1);127if (p == NULL) {128fprintf(stderr, "can't malloc memory for p\n");129exit(1);130}131132bzero(p, count +1);133strncpy(p, (char *)arg, count);134if (letter == 'z')135{136int i;137for (i = count - 1; i >= 0; i--)138if (p[i] == ' ')139p[i] = 0;140else141break;142}143printf("%s ", p);144145free(p);146}147148break;149150default:151printf("Unknown format letter: '%c'\n", letter);152}153if (verbose)154putchar('\n');155}156157158