1*86d7f5d3SJohn Marino /* 2*86d7f5d3SJohn Marino * Copyright (c)2004 The DragonFly Project. All rights reserved. 3*86d7f5d3SJohn Marino * 4*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 5*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 6*86d7f5d3SJohn Marino * are met: 7*86d7f5d3SJohn Marino * 8*86d7f5d3SJohn Marino * Redistributions of source code must retain the above copyright 9*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 10*86d7f5d3SJohn Marino * 11*86d7f5d3SJohn Marino * Redistributions in binary form must reproduce the above copyright 12*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in 13*86d7f5d3SJohn Marino * the documentation and/or other materials provided with the 14*86d7f5d3SJohn Marino * distribution. 15*86d7f5d3SJohn Marino * 16*86d7f5d3SJohn Marino * Neither the name of the DragonFly Project nor the names of its 17*86d7f5d3SJohn Marino * contributors may be used to endorse or promote products derived 18*86d7f5d3SJohn Marino * from this software without specific prior written permission. 19*86d7f5d3SJohn Marino * 20*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21*86d7f5d3SJohn Marino * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*86d7f5d3SJohn Marino * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*86d7f5d3SJohn Marino * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24*86d7f5d3SJohn Marino * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25*86d7f5d3SJohn Marino * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26*86d7f5d3SJohn Marino * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27*86d7f5d3SJohn Marino * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*86d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29*86d7f5d3SJohn Marino * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30*86d7f5d3SJohn Marino * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31*86d7f5d3SJohn Marino * OF THE POSSIBILITY OF SUCH DAMAGE. 32*86d7f5d3SJohn Marino */ 33*86d7f5d3SJohn Marino 34*86d7f5d3SJohn Marino /* 35*86d7f5d3SJohn Marino * commands.h 36*86d7f5d3SJohn Marino * $Id: commands.h,v 1.14 2005/02/06 21:05:18 cpressey Exp $ 37*86d7f5d3SJohn Marino */ 38*86d7f5d3SJohn Marino 39*86d7f5d3SJohn Marino #include <stdio.h> 40*86d7f5d3SJohn Marino 41*86d7f5d3SJohn Marino #include "libdfui/dfui.h" 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino #ifndef __COMMANDS_H_ 44*86d7f5d3SJohn Marino #define __COMMANDS_H_ 45*86d7f5d3SJohn Marino 46*86d7f5d3SJohn Marino #include "diskutil.h" 47*86d7f5d3SJohn Marino 48*86d7f5d3SJohn Marino /*** TYPES ***/ 49*86d7f5d3SJohn Marino 50*86d7f5d3SJohn Marino #include "functions.h" 51*86d7f5d3SJohn Marino 52*86d7f5d3SJohn Marino struct commands; 53*86d7f5d3SJohn Marino struct command; 54*86d7f5d3SJohn Marino 55*86d7f5d3SJohn Marino #ifdef NEEDS_COMMANDS_STRUCTURE_DEFINITIONS 56*86d7f5d3SJohn Marino 57*86d7f5d3SJohn Marino struct commands { 58*86d7f5d3SJohn Marino struct command *head; 59*86d7f5d3SJohn Marino struct command *tail; 60*86d7f5d3SJohn Marino }; 61*86d7f5d3SJohn Marino 62*86d7f5d3SJohn Marino struct command { 63*86d7f5d3SJohn Marino struct command *next; 64*86d7f5d3SJohn Marino struct command *prev; 65*86d7f5d3SJohn Marino char *cmdline; /* command line to execute */ 66*86d7f5d3SJohn Marino char *desc; /* description displayed in progress bar */ 67*86d7f5d3SJohn Marino int log_mode; /* use a COMMAND_LOG_* constant here */ 68*86d7f5d3SJohn Marino int failure_mode; /* use a COMMAND_FAILURE_* constant here */ 69*86d7f5d3SJohn Marino char *tag; /* tag which is recorded on failure */ 70*86d7f5d3SJohn Marino int result; /* result code from executing command */ 71*86d7f5d3SJohn Marino char *output; /* output of command */ 72*86d7f5d3SJohn Marino }; 73*86d7f5d3SJohn Marino 74*86d7f5d3SJohn Marino #endif 75*86d7f5d3SJohn Marino 76*86d7f5d3SJohn Marino #define COMMAND_LOG_SILENT 0 77*86d7f5d3SJohn Marino #define COMMAND_LOG_QUIET 1 78*86d7f5d3SJohn Marino #define COMMAND_LOG_VERBOSE 2 79*86d7f5d3SJohn Marino 80*86d7f5d3SJohn Marino #define COMMAND_FAILURE_IGNORE 0 81*86d7f5d3SJohn Marino #define COMMAND_FAILURE_WARN 1 82*86d7f5d3SJohn Marino #define COMMAND_FAILURE_ABORT 2 83*86d7f5d3SJohn Marino 84*86d7f5d3SJohn Marino #define COMMAND_RESULT_NEVER_EXECUTED -1 85*86d7f5d3SJohn Marino #define COMMAND_RESULT_POPEN_ERR 256 86*86d7f5d3SJohn Marino #define COMMAND_RESULT_SELECT_ERR 257 87*86d7f5d3SJohn Marino #define COMMAND_RESULT_CANCELLED 512 88*86d7f5d3SJohn Marino #define COMMAND_RESULT_SKIPPED 513 89*86d7f5d3SJohn Marino 90*86d7f5d3SJohn Marino /*** PROTOTYPES ***/ 91*86d7f5d3SJohn Marino 92*86d7f5d3SJohn Marino struct commands *commands_new(void); 93*86d7f5d3SJohn Marino struct command *command_add(struct commands *, const char *, ...) 94*86d7f5d3SJohn Marino __printflike(2, 3); 95*86d7f5d3SJohn Marino 96*86d7f5d3SJohn Marino void command_set_log_mode(struct command *, int); 97*86d7f5d3SJohn Marino void command_set_failure_mode(struct command *, int); 98*86d7f5d3SJohn Marino void command_set_desc(struct command *, const char *, ...) 99*86d7f5d3SJohn Marino __printflike(2, 3); 100*86d7f5d3SJohn Marino void command_set_tag(struct command *, const char *, ...) 101*86d7f5d3SJohn Marino __printflike(2, 3); 102*86d7f5d3SJohn Marino 103*86d7f5d3SJohn Marino struct command *command_get_first(const struct commands *); 104*86d7f5d3SJohn Marino struct command *command_get_next(const struct command *); 105*86d7f5d3SJohn Marino 106*86d7f5d3SJohn Marino char *command_get_cmdline(const struct command *); 107*86d7f5d3SJohn Marino char *command_get_tag(const struct command *); 108*86d7f5d3SJohn Marino int command_get_result(const struct command *); 109*86d7f5d3SJohn Marino 110*86d7f5d3SJohn Marino void commands_preview(struct dfui_connection *, const struct commands *); 111*86d7f5d3SJohn Marino int commands_execute(struct i_fn_args *, struct commands *); 112*86d7f5d3SJohn Marino 113*86d7f5d3SJohn Marino void commands_free(struct commands *); 114*86d7f5d3SJohn Marino 115*86d7f5d3SJohn Marino void view_command_log(struct i_fn_args *); 116*86d7f5d3SJohn Marino 117*86d7f5d3SJohn Marino /* Command Generators */ 118*86d7f5d3SJohn Marino 119*86d7f5d3SJohn Marino void unmount_all_under(struct i_fn_args *, struct commands *, 120*86d7f5d3SJohn Marino const char *, ...) __printflike(3, 4); 121*86d7f5d3SJohn Marino 122*86d7f5d3SJohn Marino #endif /* !__COMMANDS_H_ */ 123