fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 123 lines 2.8 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: pcemsg.c * 7 * Created: 2018-12-23 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 *****************************************************************************/ 10 11/***************************************************************************** 12 * This program is free software. You can redistribute it and / or modify it * 13 * under the terms of the GNU General Public License version 2 as published * 14 * by the Free Software Foundation. * 15 * * 16 * This program is distributed in the hope that it will be useful, but * 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 * Public License for more details. * 20 *****************************************************************************/ 21 22 23#include <stdio.h> 24 25#include "config.h" 26#include "pce.h" 27 28 29const char *arg0 = NULL; 30 31 32static 33void print_help (void) 34{ 35 fputs ( 36 "pcemsg: send messages to the emulator\n" 37 "\n" 38 "usage: pcemsg [options] message [arg]\n" 39 " -h Print help\n" 40 " -V Print version information\n", 41 stdout 42 ); 43 44 fflush (stdout); 45} 46 47static 48void print_version (void) 49{ 50 fputs ("pcemsg version " PCEUTILS_VERSION_STR "\n", stdout); 51 fflush (stdout); 52} 53 54int main (int argc, char **argv) 55{ 56 int i; 57 const char *s; 58 const char *msg, *val; 59 60 arg0 = argv[0]; 61 62 msg = NULL; 63 val = NULL; 64 65 i = 1; 66 while (i < argc) { 67 if (argv[i][0] == '-') { 68 s = argv[i] + 1; 69 70 while (*s != 0) { 71 if (*s == 'h') { 72 print_help(); 73 return (0); 74 } 75 else if (*s == 'V') { 76 print_version(); 77 return (0); 78 } 79 else { 80 fprintf (stderr, 81 "%s: unknown option (%s)\n", 82 arg0, argv[i] 83 ); 84 85 return (1); 86 } 87 88 s += 1; 89 } 90 } 91 else if (msg == NULL) { 92 msg = argv[i]; 93 } 94 else if (val == NULL) { 95 val = argv[i]; 96 } 97 else { 98 fprintf (stderr, "%s: too many arguments (%s)\n", 99 arg0, argv[i] 100 ); 101 102 return (1); 103 } 104 105 i += 1; 106 } 107 108 if (msg == NULL) { 109 print_help(); 110 return (1); 111 } 112 113 if (val == NULL) { 114 val = ""; 115 } 116 117 if (pce_set_msg (msg, val)) { 118 fprintf (stderr, "error\n"); 119 return (1); 120 } 121 122 return (0); 123}