Develop and Download Open Source Software

Browse CVS Repository

Contents of /autocoast/src/lib/opt.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Fri Nov 26 09:22:38 2004 UTC (19 years, 4 months ago) by tmurakam
Branch: MAIN
CVS Tags: v0_3, v0_2, HEAD
Changes since 1.5: +5 -0 lines
File MIME type: text/x-c++src
support split bgl

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "opt.hpp"
6
7 Options::~Options()
8 {
9 delete [] argv;
10 }
11
12 char *Options::shift(void)
13 {
14 char *ret = argv[1];
15 argc--;
16 memcpy(argv + 1, argv + 2, sizeof(char *) * (argc - 1));
17
18 return ret;
19 }
20
21 void Options::parse(int *c, char ***v)
22 {
23 argc = *c;
24 argv = new char * [argc];
25
26 memcpy(argv, *v, sizeof(char *) * argc);
27
28 while (argc >= 2 && argv[1][0] == '-') {
29 checkOptions(); // should be override this...
30 }
31
32 *c = argc;
33 *v = argv;
34 }
35
36 int Options::check(const char *shortopt, const char *longopt)
37 {
38 if (shortopt && strcmp(&argv[1][1], shortopt) == 0) {
39 shift();
40 return 1;
41 }
42 if (longopt && argv[1][1] == '-' && strcmp(&argv[1][2], longopt) == 0) {
43 shift();
44 return 1;
45 }
46 return 0;
47 }
48
49 void Options::checkOptions(void)
50 {
51 if (check("h", "help")) {
52 usage();
53 exit(1);
54 }
55
56 fprintf(stderr, "Unknown opts: %s\n", argv[1]);
57 exit(1);
58 }
59
60 void Options::usage(void)
61 {
62 fprintf(stderr, "Usage: %s [options] %s\n", argv[0], arg_help_string);
63 fprintf(stderr, "options:\n");
64
65 optusage("h", "help", "Show this help");
66 }
67
68 void Options::optusage(const char *shortopt, const char *longopt, const char *desc)
69 {
70 if (longopt) {
71 fprintf(stderr, " -%s, --%-16s %s\n", shortopt, longopt, desc);
72 } else {
73 fprintf(stderr, " -%s %-16s %s\n", shortopt, "", desc);
74 }
75 }
76
77 ///////////////////////////////////////////////////////////////////////
78 // autocoast opts
79 AcOptions::AcOptions()
80 {
81 useDegree = false;
82 landWidth = 1;
83 textureName = "1029";
84 textureWidth = 80;
85 splitBgl = false;
86 }
87
88 void AcOptions::checkOptions(void)
89 {
90 if (check("d", "degree")) {
91 // use degree
92 useDegree = true;
93 }
94 else if (check("l", "landwidth")) {
95 // Cell distance from shoreline to be filled with land texture
96 landWidth = atoi(shift());
97 }
98 else if (check("t", "texture-name")) {
99 // texture names
100 textureName = shift();
101 }
102 else if (check("w", "texture-width")) {
103 textureWidth = atoi(shift());
104 }
105 else if (check("s", "split-bgl")) {
106 splitBgl = true;
107 }
108 else {
109 Options::checkOptions();
110 }
111 }
112
113 void AcOptions::usage(void)
114 {
115 Options::usage();
116
117 optusage("s", "split-bgl", "Split BGL files");
118 optusage("d", "degree", "Specify range in degree");
119 optusage("l", "landwidth", "Cell distance from shoreline to be filled with land texture");
120 optusage("t", "texture-name", "Specify VTP texture name");
121 optusage("w", "texture-width", "Specify VTP texture width");
122 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26