[8] | 1 | /*
|
---|
| 2 | * TOPPERS Software
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
|
---|
| 6 | *
|
---|
| 7 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 8 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 9 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 10 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 11 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 12 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 13 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 14 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 15 | gip
|
---|
| 16 | * Ò}j
|
---|
| 17 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 18 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 19 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 20 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 21 | * ÆD
|
---|
| 22 | * (a) Äzzɺ¤hL
|
---|
| 23 | gipÒ}j
|
---|
| 24 | AÈÇjÉCãLÌ
|
---|
| 25 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 26 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 27 | * ñ·é±ÆD
|
---|
| 28 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 29 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 30 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 31 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 32 | * ÆÓ·é±ÆD
|
---|
| 33 | *
|
---|
| 34 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 35 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 36 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 37 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
| 38 | * ÌÓCðíÈ¢D
|
---|
| 39 | *
|
---|
| 40 | */
|
---|
| 41 | /*!
|
---|
| 42 | * \file toppers/cpp.hpp
|
---|
| 43 | * \brief CvvZbTãÖ@\ÉÖ·éé¾è`
|
---|
| 44 | */
|
---|
| 45 | #ifndef TOPPERS_CPP_HPP_
|
---|
| 46 | #define TOPPERS_CPP_HPP_
|
---|
| 47 |
|
---|
| 48 | #include "toppers/codeset.hpp"
|
---|
| 49 | #include <boost/utility.hpp>
|
---|
| 50 | #include <boost/filesystem/path.hpp>
|
---|
| 51 | #include <boost/filesystem/operations.hpp>
|
---|
| 52 | #include <boost/filesystem/exception.hpp>
|
---|
| 53 |
|
---|
| 54 | namespace toppers
|
---|
| 55 | {
|
---|
| 56 |
|
---|
| 57 | /*!
|
---|
| 58 | * \brief RgÌ
|
---|
| 59 | * \param[in] first üͳÌæªÊu
|
---|
| 60 | * \param[in] last üͳÌI[ÊuÌ
|
---|
| 61 | * \param[out] result ÊÌoÍæ
|
---|
| 62 | * \param[in] codeset ¶R[h
|
---|
| 63 | * \return ®¹ãÌ result Ìl
|
---|
| 64 | *
|
---|
| 65 | * CX^CÌubNRgÆC++X^CÌsRgðæè«Ü·B
|
---|
| 66 | * sRgÍAsÌ \\ ª ÁÄàÌsÉͱ«Ü¹ñB
|
---|
| 67 | */
|
---|
| 68 | template < class ForwardIterator, class OutputIterator >
|
---|
| 69 | OutputIterator remove_comment( ForwardIterator first, ForwardIterator last, OutputIterator result, codeset_t codeset = ascii )
|
---|
| 70 | {
|
---|
| 71 | enum { none, line_comment, block_comment, single_quote, double_quote } state = none;
|
---|
| 72 | char prev = '\0';
|
---|
| 73 |
|
---|
| 74 | for ( ; first != last; ++first, ++result )
|
---|
| 75 | {
|
---|
| 76 | char c = *first;
|
---|
| 77 | ForwardIterator next_iter = boost::next( first );
|
---|
| 78 | char next = ( next_iter != last ? *next_iter : '\0' );
|
---|
| 79 |
|
---|
| 80 | switch ( state )
|
---|
| 81 | {
|
---|
| 82 | case line_comment:
|
---|
| 83 | if ( c == '\n' )
|
---|
| 84 | {
|
---|
| 85 | state = none;
|
---|
| 86 | *result = c;
|
---|
| 87 | }
|
---|
| 88 | break;
|
---|
| 89 | case block_comment:
|
---|
| 90 | if ( c == '*' && next == '/' )
|
---|
| 91 | {
|
---|
| 92 | state = none;
|
---|
| 93 | ++first;
|
---|
| 94 | }
|
---|
| 95 | else if ( c == '\n' )
|
---|
| 96 | {
|
---|
| 97 | *result = c;
|
---|
| 98 | }
|
---|
| 99 | break;
|
---|
| 100 | case single_quote:
|
---|
| 101 | if ( c == '\\'
|
---|
| 102 | && !( codeset == shift_jis && is_lead< shift_jis >( prev ) )
|
---|
| 103 | && next == '\'' ) // '`\'` Ìê
|
---|
| 104 | {
|
---|
| 105 | *result++ = *first++;
|
---|
| 106 | }
|
---|
| 107 | else if ( c == '\'' )
|
---|
| 108 | {
|
---|
| 109 | state = none;
|
---|
| 110 | }
|
---|
| 111 | *result = *first;
|
---|
| 112 | break;
|
---|
| 113 | case double_quote:
|
---|
| 114 | if ( c == '\\'
|
---|
| 115 | && !( codeset == shift_jis && is_lead< shift_jis >( prev ) )
|
---|
| 116 | && next == '\"' ) // "`\"` Ìê
|
---|
| 117 | {
|
---|
| 118 | *result++ = *first++;
|
---|
| 119 | }
|
---|
| 120 | else if ( c == '\"' )
|
---|
| 121 | {
|
---|
| 122 | state = none;
|
---|
| 123 | }
|
---|
| 124 | *result = *first;
|
---|
| 125 | break;
|
---|
| 126 | default:
|
---|
| 127 | switch ( c )
|
---|
| 128 | {
|
---|
| 129 | case '/': // RgJnÌo
|
---|
| 130 | if ( next == '*' )
|
---|
| 131 | {
|
---|
| 132 | state = block_comment;
|
---|
| 133 | ++first;
|
---|
| 134 | }
|
---|
| 135 | else if ( next == '/' )
|
---|
| 136 | {
|
---|
| 137 | state = line_comment;
|
---|
| 138 | ++first;
|
---|
| 139 | }
|
---|
| 140 | else
|
---|
| 141 | {
|
---|
| 142 | *result = *first;
|
---|
| 143 | }
|
---|
| 144 | break;
|
---|
| 145 | case '\'':
|
---|
| 146 | state = single_quote;
|
---|
| 147 | *result = c;
|
---|
| 148 | break;
|
---|
| 149 | case '\"':
|
---|
| 150 | state = double_quote;
|
---|
| 151 | *result = c;
|
---|
| 152 | break;
|
---|
| 153 | default:
|
---|
| 154 | *result = c;
|
---|
| 155 | break;
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 | prev = *first;
|
---|
| 159 | }
|
---|
| 160 | return result;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /*!
|
---|
| 164 | * \brief CN[hpXÌTõ
|
---|
| 165 | * \param[in] first TõÎÛfBNgñÌæªÊu
|
---|
| 166 | * \param[in] last TõÎÛfBNgñÌI[ÊuÌ
|
---|
| 167 | * \param[in] headername TõÎÛÌwb_¼
|
---|
| 168 | * \return Tõɬ÷·êÎwb_ÖÌÎܽÍtpXðÔ·B¸sµ½êÍó¶ñðÔ·B
|
---|
| 169 | */
|
---|
| 170 | template < class InputIterator >
|
---|
| 171 | std::string search_include_file( InputIterator first, InputIterator last, std::string const& headername )
|
---|
| 172 | {
|
---|
| 173 | namespace fs = boost::filesystem;
|
---|
| 174 | fs::path filename( headername, fs::native );
|
---|
| 175 |
|
---|
| 176 | if ( fs::exists( filename ) && !fs::is_directory( filename ) )
|
---|
| 177 | {
|
---|
| 178 | return headername;
|
---|
| 179 | }
|
---|
| 180 | while ( first != last )
|
---|
| 181 | {
|
---|
| 182 | fs::path pathname = fs::path( *first, fs::native )/filename;
|
---|
| 183 | if ( fs::exists( pathname ) && !fs::is_directory( pathname ) )
|
---|
| 184 | {
|
---|
| 185 | return pathname.native_file_string();
|
---|
| 186 | }
|
---|
| 187 | ++first;
|
---|
| 188 | }
|
---|
| 189 | return std::string();
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | std::string expand_quote( std::string const& str );
|
---|
| 193 | std::string quote_string( std::string const& str );
|
---|
| 194 |
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | #endif // ! TOPPERS_CPP_HPP_
|
---|