File: set_options.c

package info (click to toggle)
quickplot 0.4.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 352 kB
  • ctags: 276
  • sloc: ansic: 4,124; makefile: 124; sh: 12
file content (136 lines) | stat: -rw-r--r-- 4,091 bytes parent folder | download | duplicates (2)
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
/***************************************************************
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: set_options.c,v 1.5 1999/02/28 01:58:50 lance Exp $ */
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "option.h"

#define FILE_DEBUG 0

/***********************************/
/************ Xt options ***********/
/***********************************/

/* this is the first unique combination of characters of the Intrinsics
 * built-in command line options, i.e. just enough characters so
 * that they don't look like quickplot short_options[] below and you
 * can tell them apart from each other.
 *
 * see get_options.c for the quickplot options list in
 * struct option long_options[]
 */

static struct XtOpt XtOptions[] =
{
  { "-ba" , 1 },      /* background */
  { "-bg" , 1 },      /* background (other form) */
  { "-fo" , 1 },      /* foreground */
  { "-fg" , 1 },
  { "-bd" , 1 },
  { "-borderc" , 1 }, /* borderColor */
  { "-borderw" , 1 }, /* borderWidth */
  { "-bw" , 1 },
  { "-d" , 1 },       /* display */
  { "-fo" , 1 },      /* font */
  { "-fn" , 1 },
  { "-g" , 1 },       /* geometry */
  { "-i" , 0 },       /* iconic */
  { "-na" , 1 },       /* name */
  { "-r" , 0 },       /* reverse Video */
  { "+r" , 0 },       /* no reverse Video */
  { "-se" , 1 },      /* selection timeout */
  { "-sy" , 0 },      /* synchronous */
  { "+s" , 0 },       /* disable synchronous */
  { "-t" , 1 },       /* title */
  { "-xn" , 1 },      /* Applcation national language */
  { "-xr" , 1 },      /* resource declaration */
  { "-xt" , 1 },      /* xtsessionID - session ID - used to communicate with SM */
  { NULL , 0 }
};

/* put Xt options in Xt_options and Quickplot options in Qp_options
 * method: if it's not a Xt option it's a quickplot option
 */

void set_options(int *Xt_optcount,char ***Xt_options,
		 int *Qp_optcount,char ***Qp_options,
			  int argc, char **argv)
{
  int i,j,k,got_one;

  assert(NULL != (*Xt_options = (char **) malloc(sizeof(char *) * (argc + 1))));
  assert(NULL != (*Qp_options = (char **) malloc(sizeof(char *) * (argc + 1))));

  for(i=0;i<argc;i++)
    {
      (*Xt_options)[i] = NULL;
      (*Qp_options)[i] = NULL;
    }

  (*Xt_options)[0] = argv[0];
  (*Qp_options)[0] = argv[0];

  *Xt_optcount = 1;
  *Qp_optcount = 1;
 
  for(i=1;i<argc;i++)
    {
      got_one= 0;
      for(j=0;((XtOptions[j]).arg) != NULL;j++)
	{
	  if(strncmp(argv[i],(XtOptions[j]).arg,strlen((XtOptions[j]).arg)) == 0)
	    {
	      got_one = 1;
	      (*Xt_options)[(*Xt_optcount)++] = argv[i];
	      for(k=1;k<=(XtOptions[j]).num_vals && i<argc ;k++)
		(*Xt_options)[(*Xt_optcount)++] = argv[++i];
	      break;
	    }
	}
      if(!got_one)
	(*Qp_options)[(*Qp_optcount)++] = argv[i];
    }

  (*Xt_options)[(*Xt_optcount)] = NULL;
  (*Qp_options)[(*Qp_optcount)] = NULL;


#if (FILE_DEBUG)
  fprintf(stderr,"ARGS =");
  for(i=0;i<argc;i++)
     fprintf(stderr," %s",argv[i]);
  fprintf(stderr,"\n");

  fprintf(stderr,"QuickPlot ARGS =");
  for(i=0;i<(*Qp_optcount);i++)
    fprintf(stderr," %s",(*Qp_options)[i]);
  fprintf(stderr,"\n");

  fprintf(stderr,"Xt ARGS =");
  for(i=0;i<(*Xt_optcount);i++)
    fprintf(stderr," %s",(*Xt_options)[i]);
  fprintf(stderr,"\n");
#endif
}