1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include "cmd_sincedata.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/file.hxx>
28 #include <cosv/tpl/tpltools.hxx>
29 #include "adc_cmds.hxx"
30 
31 
32 
33 namespace autodoc
34 {
35 namespace command
36 {
37 
SinceTagTransformationData()38 SinceTagTransformationData::SinceTagTransformationData()
39     :   aTransformationTable()
40 {
41 }
42 
~SinceTagTransformationData()43 SinceTagTransformationData::~SinceTagTransformationData()
44 {
45 }
46 
47 bool
DoesTransform() const48 SinceTagTransformationData::DoesTransform() const
49 {
50     return NOT aTransformationTable.empty();
51 }
52 
53 const String &
DisplayOf(const String & i_versionNumber) const54 SinceTagTransformationData::DisplayOf( const String & i_versionNumber ) const
55 {
56     if (DoesTransform())
57     {
58         StreamLock
59             sl(200);
60         sl() << i_versionNumber;
61         sl().strip_frontback_whitespace();
62         String
63             sVersionNumber(sl().c_str());
64 
65         const String *
66             ret = csv::find_in_map(aTransformationTable, sVersionNumber);
67         return ret != 0
68                 ?   *ret
69                 :   String::Null_();
70     }
71     else
72     {
73         return i_versionNumber;
74     }
75 }
76 
77 void
do_Init(opt_iter & it,opt_iter itEnd)78 SinceTagTransformationData::do_Init( opt_iter &  it,
79 									 opt_iter    itEnd )
80 {
81     ++it;   // Cur is since-file path.
82 
83     CHECKOPT(   it != itEnd ,
84               "file path",
85               C_opt_SinceFile );
86 
87     csv::File           aSinceFile(*it);
88     csv::OpenCloseGuard aSinceFileGuard(aSinceFile);
89     StreamStr           sLine(200);
90 
91     if (aSinceFileGuard)
92     {
93         for ( sLine.operator_read_line(aSinceFile);
94               NOT sLine.empty();
95               sLine.operator_read_line(aSinceFile) )
96         {
97 
98             if (*sLine.begin() != '"')
99                 continue;
100 
101             const char * pVersion = sLine.c_str() + 1;
102             const char * pVersionEnd = strchr(pVersion, '"');
103             if (pVersionEnd == 0)
104                 continue;
105             const char * pDisplay = strchr(pVersionEnd+1, '"');
106             if (pDisplay == 0)
107                 continue;
108             ++pDisplay;
109             const char * pDisplayEnd = strchr(pDisplay, '"');
110             if (pDisplayEnd == 0)
111                 continue;
112 
113             aTransformationTable[ String(pVersion,pVersionEnd) ]
114                                         = String(pDisplay,pDisplayEnd);
115             sLine.clear();
116         }   // end for
117     }   // end if
118 
119     ++it;   // Cur is next option.
120 }
121 
122 }   // namespace command
123 }   // namespace autodoc
124