1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
/***************************************************************
LanceMan's quickplot --- a fast interactive 2D plotter
Copyright (C) 1998, 1999 Lance Arsenault
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Or look at http://www.gnu.org/copyleft/gpl.html .
**********************************************************************/
/* $Id: get_options.c,v 1.9 1999/03/01 01:57:30 lance Exp $ */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include "data.h"
#include "option.h"
#include "version.h"
extern void usage(const char *argv0, FILE *fileptr);
extern int add_plots_list(Plot *plot,
const char *plot_list,
int plot_options);
extern void read_in_data(int argc, const char **argv, Plot *plot);
extern int get_num_lines_to_skip(Plot *plot, const char *optarg);
/***********************************/
/****** QuickPlot options **********/
/***********************************/
struct option long_options[] =
{
{"no-axes" , 0, 0, 'a'},
{"binary", 0, 0, 'b'},
{"function-plot", 1, 0, 'f'},
{"help", 0, 0, 'h'},
{"labels", 1, 0, 'l'},
{"no-lines", 0, 0, 'n'},
{"phase-plot", 1, 0, 'p'},
{"no-pixmap", 0, 0, 'X'},
{"same-scale", 0, 0, 's'},
{"verbose", 0, 0, 'v'},
{"black-and-white", 0, 0, 'B'},
{"label-seperator", 1, 0, 'L'},
{"no-pipe", 0, 0, 'N'},
{"pipe", 0, 0, 'P'},
{"read-labels", 0, 0, 'R'},
{"skip-lines", 1, 0, 'S'},
{"version", 0, 0, 'V'},
{0, 0, 0, 0}
};
char * short_options = {"abf:hl:np:svBL:NPRS:VX"};
void make_default_plots_list(Plot *plot)
{
char s[64];
int i;
for(i=1;i<plot->dim;i++)
{
sprintf(s,"%d %d ",i,0);
if(add_plots_list(plot,s,0))/* function plots */
{
fprintf(stderr,
"quickplot ERROR: invalid OPTION -f \"%s\"\n",s);
fprintf(stderr,
"Opps the programmer messed up make_default_plots_list() in %s\n\n",
__FILE__);
exit(1);
}
}
}
static void print_version(const char *argv0, FILE *fileptr)
{
fprintf(fileptr,
"LANCEMAN's quickplot\n version: %s\n compiled by:"
" %s, %s on: %s\n the Quickplot homepage is at: "
"\n http://www.KachinaTech.COM/~quickplot/\n\nCopyright "
"(C) 1998, 1999 Lance Arsenault\nquickplot comes with "
"ABSOLUTELY NO WARRANTY.\nThis is free software, and "
"you are welcome to\nredistribute it under certain "
"conditions.\nIt is Licensed under the GNU GENERAL "
"PUBLIC\nLICENSE, Version 2, June 1991.\n",
_VERSION,_USERNAME,__DATE__,_HOSTNAME);
}
void get_options(int argc, char **argv, Plot *plot)
{
if(argc < 2)
return;
while (1)
{
int c;
int option_index = 1;
c = GNUgetopt_long (argc, argv, short_options,
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 'a':
plot->flag |= NO_AXES;
break;
case 'b':
plot->flag |= BINARY_DATA;
break;
case 'f':
if(add_plots_list(plot,optarg,0))
{
fprintf(stderr,
"quickplot ERROR: invalid OPTION -f \"%s\"\n",
optarg);
fprintf(stderr,
" there must be an even number of "
"non-negitive integers\n seperated by"
" space in this option argument\n\n");
usage(argv[0],stderr);
exit(1);
}
break;
case 'h':
usage(argv[0],stderr);
exit(1);
break;
case 'l':
if(plot->labels == NULL)
{
plot->flag |= LABELS;
assert(NULL != (plot->labels = (char *) malloc((strlen(optarg) +1)
*sizeof(char))));
plot->labels[0] = '\0';
}
else
assert(NULL != (plot->labels = (char *)
realloc((void *) plot->labels ,
(strlen(plot->labels)+strlen(optarg)+1)
*sizeof(char))));
(void) strcpy(&(plot->labels[strlen(plot->labels)]),optarg);
/*printf("plot->labels = <%s>\n",plot->labels);*/
break;
case 'n':
plot->flag |= NO_LINES;
break;
case 'p':
if(add_plots_list(plot,optarg,PHASE_PLOT))
{
fprintf(stderr,
"quickplot ERROR: invalid OPTION -p \"%s\"\n",optarg);
fprintf(stderr,
" there must be an even number of non-negitive integers\n seperated by space in this option argument\n\n");
usage(argv[0],stderr);
exit(1);
}
break;
case 's':
plot->flag |= SAME_SCALE;
break;
case 'v':
plot->flag |= VERBOSE;
break;
case 'B':
plot->flag |= BLACK_WHITE;
break;
case 'L':
if(strlen(optarg) > 1)
{
fprintf(stderr,
"quickplot ERROR: invalid OPTION -L\"%s\": "
"The label seperator must be one charactor "
"long\n",optarg);
exit(1);
}
plot->label_seperator = optarg[0];
break;
case 'N':
plot->flag |= NO_PIPE_IN;
break;
case 'P':
plot->flag |= PIPE_IN;
break;
case 'R':
plot->flag |= READ_LABELS;
break;
case 'S':
if(get_num_lines_to_skip(plot,optarg))
{
fprintf(stderr,
"quickplot ERROR: invalid OPTION -S \"%s\"\n",optarg);
fprintf(stderr,
" this option arguement must be a positive integer\n");
exit(0);
}
break;
case 'V':
print_version(argv[0],stdout);
exit(0);
break;
case 'X':
plot->flag |= NO_PIXMAP0;
break;
case ':':
fprintf(stderr,"quickplot ERROR: missing argument to option -%c \n", c);
usage(argv[0],stderr);
exit(1);
break;
case '?':
default:
/* fprintf(stderr,"quickplot ERROR: option case '?'\n");
usage(argv[0],stderr);
exit(1);*/
break;
}
}
}
|