README: explain further musl-specific tweaks
[rofl0r-df-libgraphics.git] / g_src / command_line.cpp
blob8bce8fcc291f9d25651921394c98fd237bd06633
1 #include "platform.h"
2 #include <string.h>
3 #include <math.h>
4 #include <iosfwd>
5 #include <iostream>
6 #include <ios>
7 #include <streambuf>
8 #include <istream>
9 #include <ostream>
10 #include <iomanip>
11 #include <sstream>
12 #include <cstdlib>
13 #include <fstream>
14 #include <zlib.h>
16 #include "svector.h"
17 using std::string;
19 #include "endian.h"
21 #include "files.h"
23 #include "enabler.h"
25 #include "textlines.h"
27 #include "basics.h"
29 #include "command_line.h"
31 void command_linest::init(const string &str)
33 original=str;
35 //BUILD THE TOKEN LIST
36 long pos=0;
37 while(grab_arg(original,pos));
39 //HANDLE EACH TOKEN
40 long l;
41 for(l=0;l<arg_vect.str.size();l++)
43 handle_arg(arg_vect.str[l]->dat);
47 char command_linest::grab_arg(string &source,long &pos)
49 string dest;
51 while(pos<source.length())
53 //HIT A NEW ARGUMENT? RETURN, OTHERWISE SKIP AND START UP
54 if(source[pos]=='-')
56 if(dest.empty()){pos++;continue;}
57 else
59 pos++;
60 arg_vect.add_string(dest);
61 return 1;
65 dest+=source[pos];
67 pos++;
70 if(!dest.empty())arg_vect.add_string(dest);
71 return 0;
74 void command_linest::handle_arg(string &arg)
76 long pos=0;
77 string dest;
79 grab_token_string_pos(dest,arg,pos,' ');
80 pos+=dest.length();
82 short arg_pos=0;
83 if(dest=="gen")
85 //KEEP GOING FOR A NUMBER
86 while(pos+1<arg.length())
88 dest.erase();
89 pos++;
90 auto s=arg.begin(),e=arg.end();
91 s+=pos;
92 bool quote=false;
93 for(;s<e;++s)
95 if((*s)=='"')
97 if(quote)break;
98 else quote=true;
99 ++pos;
100 continue;
102 else if((*s)==' '&&!quote)break;
103 dest+=(*s);
105 pos+=dest.length();
108 if(!dest.empty())
110 if(arg_pos==0)gen_id=convert_string_to_long(dest);
111 if(arg_pos==1)
113 if(dest!="RANDOM")
115 world_seed=convert_string_to_ulong(dest);
116 use_seed=1;
119 if(arg_pos==2)
121 if(dest!="NONE")
123 world_param=dest;
124 use_param=1;
128 arg_pos++;