139214Sgibbs/* 239214Sgibbs * Written By Julian ELischer 339214Sgibbs * Copyright julian Elischer 1993. 439214Sgibbs * Permission is granted to use or redistribute this file in any way as long 539214Sgibbs * as this notice remains. Julian Elischer does not guarantee that this file 639214Sgibbs * is totally correct for any given task and users of this file must 739214Sgibbs * accept responsibility for any damage that occurs from the application of this 839214Sgibbs * file. 939214Sgibbs * 1039214Sgibbs * (julian@tfs.com julian@dialix.oz.au) 1139214Sgibbs * 1239214Sgibbs * User SCSI hooks added by Peter Dufault: 1339214Sgibbs * 1439214Sgibbs * Copyright (c) 1994 HD Associates 1539214Sgibbs * (contact: dufault@hda.com) 1639214Sgibbs * All rights reserved. 1739214Sgibbs * 1839214Sgibbs * Redistribution and use in source and binary forms, with or without 1939214Sgibbs * modification, are permitted provided that the following conditions 2039214Sgibbs * are met: 2139214Sgibbs * 1. Redistributions of source code must retain the above copyright 2239214Sgibbs * notice, this list of conditions and the following disclaimer. 2339214Sgibbs * 2. Redistributions in binary form must reproduce the above copyright 2439214Sgibbs * notice, this list of conditions and the following disclaimer in the 2539214Sgibbs * documentation and/or other materials provided with the distribution. 2639214Sgibbs * 3. The name of HD Associates 2739214Sgibbs * may not be used to endorse or promote products derived from this software 2839214Sgibbs * without specific prior written permission. 2939214Sgibbs * 3039214Sgibbs * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES ``AS IS'' AND 3139214Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3239214Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3339214Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES BE LIABLE 3439214Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3539214Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3639214Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3739214Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3839214Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3939214Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 4039214Sgibbs * SUCH DAMAGE. 4139214Sgibbs */ 4239214Sgibbs/* 4339214Sgibbs * Taken from the original scsi(8) program. 4439214Sgibbs * from: scsi.c,v 1.17 1998/01/12 07:57:57 charnier Exp $"; 4539214Sgibbs */ 46114513Sobrien#include <sys/cdefs.h> 47114513Sobrien__FBSDID("$FreeBSD$"); 4839214Sgibbs 49111195Sjohan#include <sys/stdint.h> 50111195Sjohan#include <sys/types.h> 51111195Sjohan 5239214Sgibbs#include <stdlib.h> 5339214Sgibbs#include <stdio.h> 5464382Skbyanc#include <string.h> 5539214Sgibbs 5639214Sgibbs#include <camlib.h> 5739214Sgibbs#include "camcontrol.h" 5839214Sgibbs 5964382Skbyancint verbose; 6039214Sgibbs 6139214Sgibbs/* iget: Integer argument callback 6239214Sgibbs */ 6339214Sgibbsint 6439214Sgibbsiget(void *hook, char *name) 6539214Sgibbs{ 6639214Sgibbs struct get_hook *h = (struct get_hook *)hook; 6739214Sgibbs int arg; 6839214Sgibbs 6939214Sgibbs if (h->got >= h->argc) 7039214Sgibbs { 7139214Sgibbs fprintf(stderr, "Expecting an integer argument.\n"); 7246938Sken usage(0); 7339214Sgibbs exit(1); 7439214Sgibbs } 7539214Sgibbs arg = strtol(h->argv[h->got], 0, 0); 7639214Sgibbs h->got++; 7739214Sgibbs 7839214Sgibbs if (verbose && name && *name) 7939214Sgibbs printf("%s: %d\n", name, arg); 8039214Sgibbs 8139214Sgibbs return arg; 8239214Sgibbs} 8339214Sgibbs 8439214Sgibbs/* cget: char * argument callback 8539214Sgibbs */ 8639214Sgibbschar * 8739214Sgibbscget(void *hook, char *name) 8839214Sgibbs{ 8939214Sgibbs struct get_hook *h = (struct get_hook *)hook; 9039214Sgibbs char *arg; 9139214Sgibbs 9239214Sgibbs if (h->got >= h->argc) 9339214Sgibbs { 9439214Sgibbs fprintf(stderr, "Expecting a character pointer argument.\n"); 9546938Sken usage(0); 9639214Sgibbs exit(1); 9739214Sgibbs } 9839214Sgibbs arg = h->argv[h->got]; 9939214Sgibbs h->got++; 10039214Sgibbs 10139214Sgibbs if (verbose && name) 10239214Sgibbs printf("cget: %s: %s", name, arg); 10339214Sgibbs 10439214Sgibbs return arg; 10539214Sgibbs} 10639214Sgibbs 10739214Sgibbs/* arg_put: "put argument" callback 10839214Sgibbs */ 10939214Sgibbsvoid 110118478Sjohanarg_put(void *hook __unused, int letter, void *arg, int count, char *name) 11139214Sgibbs{ 11239214Sgibbs if (verbose && name && *name) 11339214Sgibbs printf("%s: ", name); 11439214Sgibbs 11539214Sgibbs switch(letter) 11639214Sgibbs { 11739214Sgibbs case 'i': 11839214Sgibbs case 'b': 119111195Sjohan printf("%jd ", (intmax_t)(intptr_t)arg); 12039214Sgibbs break; 12139214Sgibbs 12239214Sgibbs case 'c': 12339214Sgibbs case 'z': 12439214Sgibbs { 12539214Sgibbs char *p; 12639214Sgibbs 12739214Sgibbs p = malloc(count + 1); 12869471Sjedgar if (p == NULL) { 12969471Sjedgar fprintf(stderr, "can't malloc memory for p\n"); 13069471Sjedgar exit(1); 13169471Sjedgar } 13239214Sgibbs 13339214Sgibbs bzero(p, count +1); 13439214Sgibbs strncpy(p, (char *)arg, count); 13539214Sgibbs if (letter == 'z') 13639214Sgibbs { 13739214Sgibbs int i; 13839214Sgibbs for (i = count - 1; i >= 0; i--) 13939214Sgibbs if (p[i] == ' ') 14039214Sgibbs p[i] = 0; 14139214Sgibbs else 14239214Sgibbs break; 14339214Sgibbs } 14439214Sgibbs printf("%s ", p); 14539214Sgibbs 14639214Sgibbs free(p); 14739214Sgibbs } 14839214Sgibbs 14939214Sgibbs break; 15039214Sgibbs 15139214Sgibbs default: 15239214Sgibbs printf("Unknown format letter: '%c'\n", letter); 15339214Sgibbs } 15439214Sgibbs if (verbose) 15539214Sgibbs putchar('\n'); 15639214Sgibbs} 157227961Semaste 158227961Semaste/* 159227961Semaste * Get confirmation from user 160227961Semaste * Return values: 161227961Semaste * 1: confirmed 162227961Semaste * 0: unconfirmed 163227961Semaste */ 164227961Semasteint 165227963Sdelphijget_confirmation(void) 166227961Semaste{ 167227961Semaste char str[1024]; 168227961Semaste int response = -1; 169227961Semaste 170227961Semaste do { 171227961Semaste fprintf(stdout, "Are you SURE you want to do this? (yes/no) "); 172227961Semaste if (fgets(str, sizeof(str), stdin) != NULL) { 173227961Semaste if (strncasecmp(str, "yes", 3) == 0) 174227961Semaste response = 1; 175227961Semaste else if (strncasecmp(str, "no", 2) == 0) 176227961Semaste response = 0; 177227961Semaste else 178227961Semaste fprintf(stdout, 179227961Semaste "Please answer \"yes\" or \"no\"\n"); 180227961Semaste } else 181227961Semaste response = 0; 182227961Semaste } while (response == -1); 183227961Semaste return (response); 184227961Semaste} 185