1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
30 extern bool LinkWithAiSpawnCommands
;
31 extern bool LinkWithAiActionCommands
;
32 extern bool LinkWithPrimitiveParser
;
33 extern NLLIGO::CLigoConfig
*LigoConfig
;
35 inline void init(NLLIGO::CLigoConfig
*config
)
37 // this code forces the linker to link in files that would otherwise be lost
38 // these files use constructors of static objects to instantiate objects
39 LinkWithAiSpawnCommands
=true;
40 LinkWithAiActionCommands
=true;
41 LinkWithPrimitiveParser
=true;
45 // the parser for '.primitive' files
46 extern void parsePrimFile(const std::string
&filename
);
48 // the parser for 'AiActions' stream in pdr (R2 format)
49 extern void parsePrimStream(NLMISC::IStream
& stream
, const std::string
& streamName
);
51 // the parser for 'AiActions' primitives in pdr (R2 format)
52 extern void parsePrimNoStream( NLLIGO::CPrimitives
* primDoc
, const std::string
& streamName
);
54 //-------------------------------------------------------------------------------------------------
55 // some handy utilities
56 //-------------------------------------------------------------------------------------------------
58 // dumb routine to simplify repetitive text parsing code
59 inline bool isWhiteSpace(char c
)
61 return (c
==' ' || c
=='\t');
64 // -- stringToKeywordAndTail() --
65 // The following routine splits a text string into a keyword and a tail.
66 // A ':' is used as separator between keyword and tail
67 // All leading and trailing ' ' and '\t' round keyword and tail characters are stripped
68 // If no keyword is found routine retuns false (keyword and tail retain previous content)
69 inline bool stringToKeywordAndTail(const std::string
&input
,std::string
&keyword
, std::string
&tail
)
74 while (i
<input
.size() && isWhiteSpace(input
[i
])) ++i
; // i points to start of keyword
76 // look for the end of the keyword
77 for (j
=i
;j
<input
.size() && input
[j
]!=':';) ++j
; // j points to ':' after keyword
79 // prune any unnecessary white space before ':'
80 for (k
=j
; k
>i
&& isWhiteSpace(input
[k
-1]);)--k
; // k points to character after end of keyword
82 // if no keyword found then give up
83 if (k
==i
) return false;
85 // copy out the keyword
86 keyword
=input
.substr(i
,k
-i
);
88 // find the end of the tail text
89 for (k
=(uint
)input
.size();k
>j
&& isWhiteSpace(input
[k
-1]);) --k
; // k points to character after end of tail text
91 // find start of tail text
92 do { ++j
; } while(j
<k
&& isWhiteSpace(input
[j
])); // j points to start of tail text
94 // copy out the tail (or clear if no tail found in input)
96 tail
=input
.substr(j
,k
-j
);
103 // -- stringToWordAndTail() --
104 // The following routine splits a text string into a keyword and a tail.
105 // A white space is used as separator between keyword and tail
106 // All leading and trailing ' ' and '\t' round keyword and tail characters are stripped
107 // If no keyword is found routine retuns false (keyword and tail retain previous content)
108 inline bool stringToWordAndTail(const std::string
&input
,std::string
&word
, std::string
&tail
)
113 while (i
<input
.size() && isWhiteSpace(input
[i
])) ++i
; // i points to start of word
115 // look for the end of the word
116 for (j
=i
;j
<input
.size() && !isWhiteSpace(input
[j
]);) ++j
; // j points to next character after word
118 // if no word found then give up
119 if (j
==i
) return false;
122 word
=input
.substr(i
,j
-i
);
124 // find the end of the tail text
125 for (i
=(uint
)input
.size();i
>j
&& isWhiteSpace(input
[i
-1]);) --i
; // i points to character after end of tail text
127 // find start of tail text
128 do { ++j
; } while(j
<i
&& isWhiteSpace(input
[j
])); // j points to start of tail text
130 // copy out the tail (or clear if no tail found in input)
132 tail
=input
.substr(j
,i
-j
);
140 } // end of namespace