[go: up one dir, main page]

File: ParseArgs.c

package info (click to toggle)
antennavis 0.3-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 968 kB
  • ctags: 669
  • sloc: ansic: 7,208; sh: 1,217; makefile: 109
file content (171 lines) | stat: -rw-r--r-- 6,717 bytes parent folder | download | duplicates (6)
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
/*****************************************************************************/
/*****************************************************************************/
/**                                                                         **/
/**  Antenna Visualization Toolkit                                          **/
/**                                                                         **/
/**  Copyright (C) 1998 Adrian Agogino, Ken Harker                          **/
/**  Copyright (C) 2005 Joop Stakenborg                                     **/
/**                                                                         **/
/*****************************************************************************/
/*****************************************************************************/

/*
 * 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 Library 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.
 */

#include <GL/gl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ParseArgs.h"
#include "MyTypes.h"


/*****************************************************************************/
/*****************************************************************************/
/**                                                                         **/
/**                                ParseArgs                                **/
/**                                                                         **/
/*****************************************************************************/
/*****************************************************************************/


GLint PA_ParseArgs(Tcl_Interp  *interp, 
                        GLint   argc, 
                         CONST84 char **argv,
             struct PA_Config  *cfg, 
                         void  *data) {

  GLint    i;       /**  Loop counter           **/
  GLint    n;       /**  Loop counter           **/
  GLfloat  f;       /**  Floating point number  **/
  bool     b;       /**  Flow control           **/
  char buffer[40];  /**  Input buffer           **/
  
  i = 0;
  if(argv[i] != NULL) {
    /**  Search for an entry with the same name  **/
    while(cfg->type != PA_END) {
      if(strcmp( argv[i], cfg->name) == 0) {
        i++;
        switch(cfg->type) {
          case PA_FLOAT:
            if(argv[i] != NULL) {
              f = atof(argv[i]);
              (*((GLfloat *)((char *) data + cfg->offset))) = f;
              i++;
            } else {
	      sprintf(buffer, "%f", 
		(double) (*((GLfloat *)( (char *) data + cfg->offset))));
    	      Tcl_SetResult( interp, buffer, TCL_VOLATILE);
            }  /**  Floating point  **/
            break;
  
          case PA_BOOL:
            if(argv[i] != NULL) {
              if(strcmp(argv[i], "0") == 0 
	        || strcmp(argv[i], "f") == 0 
                || strcmp(argv[i], "false") == 0 
		|| strcmp(argv[i], "False") == 0 
                || strcmp(argv[i], "FALSE") == 0 
		|| strcmp(argv[i], "F") == 0 )
                b = false;
              else
                b = true;
 
              (*((bool *)((char *) data + cfg->offset))) = b;
              i++;
            } else {
    	      Tcl_SetResult(interp, 
		  (bool)(*((bool *)((char *)data+cfg->offset))) ? 
                  "true" : "false",TCL_STATIC);
	    }  /**  Boolean  **/
            break;

          case PA_INT:
            if(argv[i] != NULL) {
              n = atoi(argv[i] );
              (*((GLint *)((char *)data + cfg->offset))) = n;
              i++;
            } else {
	      sprintf(buffer, "%d", 
		(int) (*((GLint *)((char *) data + cfg->offset))));
    	      Tcl_SetResult(interp, buffer, TCL_VOLATILE);
	    }  /**  Integer  **/
            break;
  
          case PA_RGB:
            if(argv[i] != NULL) {
              if(argc - i < 3) {
      	        Tcl_SetResult(interp,
                  "PA_ParseArgs ERROR: need three values for RGB", TCL_STATIC);
                return TCL_ERROR;
              }  /**  Error  **/
	      
              f = atof(argv[i]);
              (*((GLfloat *)((char *)data + cfg->offset))) = f;
              i++;
              f = atof(argv[i]);
              (*((GLfloat *)((char *)data + cfg->offset + sizeof(GLfloat))))=f;
              i++;
              f = atof(argv[i]);
              (*((GLfloat *)((char *)data + cfg->offset+2*sizeof(GLfloat))))=f;
              i++;
            } else {
	      sprintf(buffer, "%f %f %f", 
		(double)(*((GLfloat *)((char *)data+cfg->offset))),
		(double)(*((GLfloat *)((char *)data+cfg->offset+sizeof(GLfloat)))),
		(double)(*((GLfloat *)((char *)data+cfg->offset+2*sizeof(GLfloat)))));
    	      Tcl_SetResult(interp, buffer, TCL_VOLATILE);
	    }  /**  RGB  **/
            break;
  
          default:
  	    Tcl_SetResult(interp,
              "PA_ParseArgs ERROR: Illegal type!", TCL_STATIC);
            return TCL_ERROR;
        }  /**  Switch  **/
        
        if(argv[i] == NULL) {
          return PA_CHANGED;
	} else {
	  Tcl_SetResult(interp,
            "PA_ParseArgs ERROR: Too many arguments!", TCL_STATIC);
          return TCL_ERROR;
	}  /**  Changed  **/
      }  /**  Name OK  **/
      cfg++;
    }  /**  While not done  **/
  } else {
    while(cfg->type != PA_END) {
      Tcl_AppendElement(interp, cfg->name);
      cfg++;
    }  /**  Try all possible options  **/
    return TCL_OK;
  }  /**  Try all possible options  **/

  Tcl_SetResult(interp, "PA_ParseArgs ERROR: No option matches!", TCL_STATIC);
  return TCL_ERROR;

}  /**  End of ParseArgs  **/


/*****************************************************************************/
/*****************************************************************************/
/**                                                                         **/
/**                           End of ParseArgs.c                            **/
/**                                                                         **/
/*****************************************************************************/
/*****************************************************************************/