Syntax.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. #include "stdafx.h"
  2. #include "syntax.h"
  3. CString g_strInString; //定义一个字符串值除了包含字符数字、下划线_外,还包含什么字符常量, C++还会包含#, 如#include
  4. TCHAR *g_BeginCommentExStr[2];//当前语言的多行注释规则:引起多行注释的字符串
  5. TCHAR *g_EndCommentExStr[2]; //当前语言的多行注释规则:结束多行注释的字符串
  6. TCHAR *g_LineCommentStr[2]; //当前语言的单行注释规则, 以行末为中止
  7. TCHAR *g_BeginStringStr[1]; //当前语言的字符规则, 引起字符串变量的字符串
  8. TCHAR *g_EndStringStr[1]; //当前语言的字符规则, 结束字符串变量的字符串
  9. TCHAR *g_BeginCharStr[1]; //当前语言的字符规则, 结束字符型常量的字符串
  10. TCHAR *g_EndCharStr[1]; //当前语言的字符规则, 结束字符型常量的字符串
  11. BOOL g_bControl; //控制字符,如C++中的\",因为控制字符\的存在其表示的是一个引号
  12. BOOL g_bCase; //在进行关键字比较时是否区分大小写
  13. int g_nstrInStringCount;
  14. int g_nBeginCommentExStrCount;
  15. int g_nEndCommentExStrCount;
  16. int g_nLineCommentStrCount;
  17. int g_nBeginStringStrCount;
  18. int g_nEndStringStrCount;
  19. int g_nBeginCharStrCount;
  20. int g_nEndCharStrCount;
  21. int g_nCurLanguage;
  22. void SetCurLanguage(int nLanguage)
  23. {
  24. g_nCurLanguage = nLanguage;
  25. }
  26. BOOL IsSynWord(CStringArray &m_strArrayKeyWords, CString &strReadyToTest)
  27. {
  28. int val;
  29. int low=0,hig=m_strArrayKeyWords.GetSize()-1;
  30. int mid=(low+hig)/2;
  31. while(low<=hig) {
  32. CString str = m_strArrayKeyWords[mid];
  33. if(g_bCase)
  34. val=strReadyToTest.Compare(m_strArrayKeyWords[mid]);
  35. else
  36. val=strReadyToTest.CompareNoCase(m_strArrayKeyWords[mid]);
  37. if(val>0)
  38. low=mid+1;
  39. else if(val<0)
  40. hig=mid-1;
  41. else
  42. return TRUE;
  43. mid=(low+hig)/2;
  44. }
  45. return FALSE;
  46. }
  47. BOOL IsNumber(CString &strReadyToTest)
  48. {
  49. int nLength = strReadyToTest.GetLength();
  50. //*
  51. switch (g_nCurLanguage)
  52. {
  53. case _BASIC:
  54. {
  55. if (nLength > 2 && strReadyToTest[0] == _T('&') &&
  56. (strReadyToTest[1] == _T('O') || strReadyToTest[1] == _T('H')))
  57. {
  58. for (int I = 2; I < nLength; I++)
  59. {
  60. if (_istdigit(strReadyToTest[I]) ||(strReadyToTest[I] >= _T('A') &&
  61. strReadyToTest[I] <= _T('F')) ||(strReadyToTest[I] >= _T('a') &&
  62. strReadyToTest[I] <= _T('f')))
  63. continue;
  64. return FALSE;
  65. }
  66. return TRUE;
  67. }
  68. }
  69. break;
  70. default:
  71. break;
  72. } // switch
  73. if (!_istdigit(strReadyToTest[0]))
  74. return FALSE;
  75. for (int I = 1; I < nLength; I++)
  76. {
  77. if (!_istdigit(strReadyToTest[I]) && strReadyToTest[I] != _T('+') &&
  78. strReadyToTest[I] != _T('-') && strReadyToTest[I] != _T('.') &&
  79. strReadyToTest[I] != _T('e') && strReadyToTest[I] != _T('E'))
  80. return FALSE;
  81. }
  82. //*/
  83. return TRUE;
  84. }
  85. //装入关键字列表及语法解析规则
  86. void LoadSynWord(CStringArray &m_strArrayKeyWords, int nLanguage)
  87. {
  88. LoadParseRule(nLanguage);
  89. CString strAllSynWord;
  90. m_strArrayKeyWords.RemoveAll();
  91. CWinApp *app = AfxGetApp();
  92. switch ( nLanguage ) {
  93. case _BASIC:
  94. strAllSynWord = _T(" Alias,And,Any,As,Base,Boolean,Byref,Byte,Byval,Call,Case,Close,Compare,Const,Currency,Data,Date,Declare,Defbool,Defbyte,Defcur,Defdate,Defdbl,Defdec,Defint,Deflng,Defobj,Defsng,Defstr,Defvar,Dim,Do,Double,Each,Else,Elseif,End,Enum,Eqv,Erase,Error,Event,Exit,Explicit,False,For,Function,Get,Global,Gosub,Goto,If,IIf,Imp,Implements,In,Integer,Is,Let,Lib,Line,Lock,Long,Loop,Lset,New,Next,Not,Object,On,Open,Option,Optional,Or,Preserve,Print,Private,Property,Public,Put,Raiseevent,Redim,Resume,Return,Rset,Select,Set,Single,Static,Stop,String,Sub,Then,To,True,Type,Ubound,Unload,Unlock,Var,Variant,Wend,While,With,Write,Xor,#if,#End,#else,Abs,Array,Asc,Atn,CBool,CByte,CCur,CDate,CDbl,Chr,CInt,CLng,Cos,CreateObject,CSng,CStr,Date,DateAdd,DateDiff,DatePart,DateSerial,DateValue,Day,Exp,Filter,Fix,FormatCurrency,FormatDateTime,FormatNumber,FormatPercent,GetObject,Hex,Hour,InputBox,InStr,InStrRev,Int,IsArray,IsDate,IsEmpty,IsNull,IsNumeric,IsObject,Join,LBound,LCase,Left,Len,LoadPicture,Log,LTrim,Mid,Minute,Month,MonthName,MsgBox,Now,Oct,Replace,RGB,Right,Rnd,Round,RTrim,ScriptEngine,ScriptEngineBuildVersion,ScriptEngineMajorVersion,ScriptEngineMinorVersion,Second,Sgn,Sin,Space,Split,Sqr,StrComp,StrReverse,String,Tan,Time,TimeSerial,TimeValue,Trim,TypeName,UBound,UCase,VarType,Weekday,WeekdayName,Year,SelectYK,ExecuteYK,MannulSetYX,MannulSetYC,IsMainServer,SelectYT,ExecuteYT,CancelMansetYX,CancelMansetYC,Sleeps,");
  95. strAllSynWord = app->GetProfileString(_T("Keywords"), _T("_BASIC"), strAllSynWord);
  96. break;
  97. default: //is NONE
  98. return;
  99. }
  100. if(!g_bCase) {
  101. strAllSynWord.MakeLower();
  102. }
  103. CString strTemp;
  104. int nPosPrior = 0;
  105. int nPos;
  106. nPos = strAllSynWord.Find(_T(","), nPosPrior);
  107. while(nPos!=-1)
  108. {
  109. strTemp = strAllSynWord.Mid(nPosPrior+1 , nPos - nPosPrior - 1);
  110. m_strArrayKeyWords.Add(strTemp);
  111. nPosPrior = nPos;
  112. nPos = strAllSynWord.Find(_T(","), nPosPrior + 1);
  113. }
  114. SortSynWordArray(m_strArrayKeyWords);
  115. }
  116. void SortSynWordArray(CStringArray &m_strArrayKeyWords)
  117. {
  118. int i,j,x, count = m_strArrayKeyWords.GetSize();
  119. CString strtmp;
  120. for(i=1;i<count;i++)
  121. {
  122. for(x=0;x<i;x++)
  123. {
  124. if(m_strArrayKeyWords.GetAt(i).Compare(m_strArrayKeyWords.GetAt(x))<=0)
  125. break;
  126. }
  127. strtmp=m_strArrayKeyWords.GetAt(i);
  128. for(j=i;j>x;j--)
  129. m_strArrayKeyWords.SetAt(j, m_strArrayKeyWords.GetAt(j-1));
  130. m_strArrayKeyWords.SetAt(x, strtmp);
  131. }
  132. }
  133. /*///////////////////////////////////////////////////////////////////////////////////////////////
  134. ParseLine(m_strArrayKeyWords, dwCookie, strLine, ColorInfo, nActualItems) );
  135. 功能:根据所给定的语言解析一行字符串,返回用颜色指示的字符串块,以及解析后的当前行的解析结果,
  136. 指示解析后当前行处于什么状态,是处于字符串中、注释中、多行注释中还是正常状态。
  137. 入口参数:
  138. m_strArrayKeyWords: 关键字列表
  139. dwCookie: 传入前一行的解析结果,如果前一行是多行注释的开始或者前一行是一软回车时有用
  140. strLine: 被解析的一行字符串
  141. ColorInfo: 解析后的颜色值,指定是关键字、字符串、注释还是正常的字符颜色
  142. nActualItems strLine被解析后的块数
  143. /////////////////////////////////////////////////////////////////////////////////////////////////*/
  144. DWORD ParseLine(CStringArray &m_strArrayKeyWords,
  145. DWORD dwCookie,
  146. CString &strLine,
  147. COLORINFO *ColorInfo,
  148. int &nActualItems)
  149. {
  150. //*
  151. if(g_nCurLanguage ==_HTML || g_nCurLanguage ==_XML) {
  152. int dwCookieTmp = ParseLineForHtml(m_strArrayKeyWords, dwCookie, strLine, ColorInfo, nActualItems);
  153. return dwCookieTmp;
  154. }
  155. //*/
  156. int nLength = strLine.GetLength();
  157. int nIdentBegin = -1;
  158. int i;
  159. BOOL bMatch;
  160. BOOL bInString; //定义一个字符串的界限
  161. BOOL bRedefineBlock = TRUE;
  162. BOOL bDecIndex = FALSE;
  163. BOOL bIsInTheControlChar = FALSE; //指示是否在\的控制中, strControl为空时无效, 初始化时必须为FALSE, 原因见结束定义字符串的处理代码
  164. if(nLength == 0)
  165. return dwCookie;
  166. int I = 0;
  167. for ( I = 0; ; I++)
  168. {
  169. if (bRedefineBlock) //如果开始定义颜色块向下做
  170. {
  171. int nPos = I;
  172. if (bDecIndex)
  173. nPos--;
  174. if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
  175. {
  176. DEFINE_BLOCK(nPos, COLORINDEX_COMMENT);
  177. }
  178. else {
  179. if (dwCookie & COOKIE_STRING)
  180. {
  181. DEFINE_BLOCK(nPos, COLORINDEX_STRING);
  182. }
  183. else
  184. {
  185. DEFINE_BLOCK(nPos, COLORINDEX_NORMAL);
  186. }
  187. }
  188. bRedefineBlock = FALSE;
  189. bDecIndex = FALSE;
  190. }
  191. if (I >= nLength)
  192. goto Out;
  193. //遇到双字节字体如中文直接跳过
  194. if(IsDBCSLeadByte(strLine[I])) //检查是不是中文字符
  195. {
  196. I += 2;
  197. if (I >= nLength)
  198. goto Out;
  199. else
  200. goto cmpnextchar; //继续处理strLine的下一个字符
  201. }
  202. //////////////////////////////
  203. if (dwCookie & COOKIE_COMMENT)
  204. {
  205. DEFINE_BLOCK(I, COLORINDEX_COMMENT);
  206. dwCookie |= COOKIE_COMMENT;
  207. goto Out;
  208. }
  209. //如果当前正处于字符串变量中,则应检查是否有结束字符串变量的字符串
  210. if (dwCookie & COOKIE_STRING)
  211. {
  212. if(g_bControl) { //处理控制字符,至少C++会用到(例\"表示引号而不是两个字符)
  213. if(I > 0) {
  214. if(strLine[I-1] != '\\') {
  215. if(strLine[I] != '\\')
  216. bIsInTheControlChar = FALSE;
  217. else
  218. bIsInTheControlChar = TRUE;
  219. }
  220. else {
  221. if(strLine[I] == '\\') {
  222. if(!bIsInTheControlChar)
  223. bIsInTheControlChar = TRUE;
  224. else
  225. bIsInTheControlChar = FALSE;
  226. }
  227. }
  228. }
  229. }
  230. int nlen;
  231. for (int i = 0; i < g_nEndStringStrCount; i++ ) {
  232. if(g_EndStringStr[i]==NULL)
  233. continue;
  234. nlen = strlen(g_EndStringStr[i]);
  235. bMatch = TRUE;
  236. //如果strLine的当前字符串值与结束定义字符规则中的一项相同则中止定义字符串
  237. if (I >= nlen - 1)
  238. {
  239. for(int k=0; k<nlen; k++) { //向前搜索字符串检查是否与结束定义的字符串相同
  240. if(strLine[I-nlen+1+k]!=g_EndStringStr[i][k]) {
  241. bMatch = FALSE; //如果不匹配,中断比较
  242. break;
  243. }
  244. }
  245. if(bMatch && !bIsInTheControlChar) {
  246. dwCookie &= ~COOKIE_STRING;
  247. bRedefineBlock = TRUE;
  248. goto cmpnextchar; //继续处理strLine的下一个字符
  249. }
  250. }
  251. }
  252. goto cmpnextchar; //如果没有结束定义字符串继续处理strLine的下一个字符
  253. }
  254. //如果当前正处于字符变量中,则应检查是否有结束字符变量的字符串
  255. if (dwCookie & COOKIE_CHAR)
  256. {
  257. if(g_bControl) { //处理控制字符,至少C++会用到(例\"表示引号而不是两个字符)
  258. if(I > 0) {
  259. if(strLine[I-1] != '\\') {
  260. if(strLine[I] != '\\')
  261. bIsInTheControlChar = FALSE;
  262. else
  263. bIsInTheControlChar = TRUE;
  264. }
  265. else {
  266. if(strLine[I] == '\\') {
  267. if(!bIsInTheControlChar)
  268. bIsInTheControlChar = TRUE;
  269. else
  270. bIsInTheControlChar = FALSE;
  271. }
  272. }
  273. }
  274. }
  275. int nlen;
  276. for (int i = 0; i < g_nEndCharStrCount; i++ ) {
  277. if(g_EndCharStr[i]==NULL)
  278. continue;
  279. nlen = strlen(g_EndCharStr[i]);
  280. bMatch = TRUE;
  281. //如果strLine的当前字符值与结束定义字符规则中的一项相同则中止定义字符串
  282. if (I >= nlen - 1)
  283. {
  284. for(int k=0; k<nlen; k++) { //向前搜索字符串检查是否与结束定义的字符相同
  285. if(strLine[I-nlen+1+k]!=g_EndCharStr[i][k]) {
  286. bMatch = FALSE; //如果不匹配,中断比较
  287. break;
  288. }
  289. }
  290. if(bMatch && !bIsInTheControlChar) {
  291. dwCookie &= ~COOKIE_CHAR;
  292. bRedefineBlock = TRUE;
  293. goto cmpnextchar; //继续处理strLine的下一个字符
  294. }
  295. }
  296. }
  297. goto cmpnextchar; //如果没有结束定义字符继续处理strLine的下一个字符
  298. }
  299. //如果当前正处于多行注释中,则应检查是否有结束多行注释的字符串
  300. if (dwCookie & COOKIE_EXT_COMMENT) {
  301. for (int i = 0; i < g_nEndCommentExStrCount; i++ ) {
  302. if(g_EndCommentExStr[i]==NULL)
  303. continue;
  304. bMatch = TRUE;
  305. int nlen = strlen(g_EndCommentExStr[i]);
  306. if(I >= nlen - 1)
  307. {
  308. for(int k=0; k<nlen; k++) {
  309. if(strLine[I-nlen+1+k]!=g_EndCommentExStr[i][k]) {
  310. bMatch = FALSE;
  311. break;
  312. }
  313. }
  314. if(bMatch) {
  315. dwCookie &= ~COOKIE_EXT_COMMENT;
  316. bRedefineBlock = TRUE;
  317. goto cmpnextchar;
  318. }
  319. }
  320. }
  321. goto cmpnextchar;
  322. }
  323. //处理单行注释
  324. for (i = 0; i < g_nLineCommentStrCount; i++ ) {
  325. if(g_LineCommentStr[i]==NULL)
  326. continue;
  327. int nlen = strlen(g_LineCommentStr[i]);
  328. bMatch = TRUE;
  329. if(I >= nlen - 1)
  330. {
  331. for(int k=0; k<nlen; k++) {
  332. if(strLine[I-nlen+1+k]!=g_LineCommentStr[i][k]) {
  333. bMatch = FALSE;
  334. break;
  335. }
  336. }
  337. if(bMatch) {
  338. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_COMMENT);
  339. dwCookie |= COOKIE_COMMENT;
  340. goto Out; //只要发现有单行注释的字符串则退出
  341. }
  342. }
  343. }
  344. //处理字符串变量的开始
  345. for (i = 0; i < g_nBeginStringStrCount; i++ ) {
  346. if(g_BeginStringStr[i]==NULL)
  347. continue;
  348. int nlen = strlen(g_BeginStringStr[i]);
  349. bMatch = TRUE;
  350. if(I >= nlen - 1)
  351. {
  352. for(int k=0; k<nlen; k++) {
  353. if(strLine[I-nlen+1+k]!=g_BeginStringStr[i][k]) {
  354. bMatch = FALSE;
  355. break;
  356. }
  357. }
  358. if(bMatch) {
  359. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_STRING);
  360. dwCookie |= COOKIE_STRING;
  361. goto cmpnextchar;
  362. }
  363. }
  364. }
  365. //处理字符型变量的开始
  366. for (i = 0; i < g_nBeginCharStrCount; i++ ) {
  367. if(g_BeginCharStr[i]==NULL)
  368. continue;
  369. int nlen = strlen(g_BeginCharStr[i]);
  370. bMatch = TRUE;
  371. if(I >= nlen - 1)
  372. {
  373. for(int k=0; k<nlen; k++) {
  374. if(strLine[I-nlen+1+k]!=g_BeginCharStr[i][k]) {
  375. bMatch = FALSE;
  376. break;
  377. }
  378. }
  379. if(bMatch) {
  380. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_CHAR);
  381. dwCookie |= COOKIE_CHAR;
  382. goto cmpnextchar;
  383. }
  384. }
  385. }
  386. //处理多行注释的开始
  387. for (i = 0; i < g_nBeginCommentExStrCount; i++ ) {
  388. if(g_BeginCommentExStr[i]==NULL)
  389. continue;
  390. int nlen = strlen(g_BeginCommentExStr[i]);
  391. bMatch = TRUE;
  392. if(I >= nlen - 1)
  393. {
  394. for(int k=0; k<nlen; k++) {
  395. if(strLine[I-nlen+1+k]!=g_BeginCommentExStr[i][k]) {
  396. bMatch = FALSE;
  397. break;
  398. }
  399. }
  400. if(bMatch) {
  401. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_COMMENT);
  402. dwCookie |= COOKIE_EXT_COMMENT;
  403. if(nlen>1) {
  404. if ( ++I>= nLength) // 考虑"/*/"的情况
  405. goto Out;
  406. }
  407. goto cmpnextchar;
  408. }
  409. }
  410. }
  411. bInString = FALSE;
  412. for ( i = 0; i < g_nstrInStringCount; i++ ) {
  413. BOOL b = ( strLine[I] == g_strInString.GetAt(i) ) ;
  414. bInString |= b;
  415. if(bInString)
  416. break;
  417. }
  418. if (isalnum(strLine[I]) || strLine[I] == '_' || bInString)
  419. {
  420. if (nIdentBegin == -1)
  421. nIdentBegin = I;
  422. }
  423. else
  424. {
  425. if (nIdentBegin >= 0)
  426. {
  427. CString strtmp= strLine.Mid(nIdentBegin, I - nIdentBegin);
  428. if (IsSynWord(m_strArrayKeyWords, strtmp))
  429. {
  430. DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX);
  431. }
  432. else if (IsNumber(strtmp))
  433. {
  434. DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
  435. }
  436. bRedefineBlock = TRUE;
  437. bDecIndex = TRUE;
  438. nIdentBegin = -1;
  439. }
  440. }
  441. cmpnextchar:
  442. i=0; //没有意义,为编译通过而准备
  443. }
  444. Out: //当遇到单行注释时会直接跳到这儿
  445. if (nIdentBegin >= 0)
  446. {
  447. CString strtmp = strLine.Mid(nIdentBegin, I - nIdentBegin);
  448. if (IsSynWord(m_strArrayKeyWords, strtmp))
  449. {
  450. DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX);
  451. }
  452. else if (IsNumber(strtmp))
  453. {
  454. DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
  455. }
  456. }
  457. return dwCookie;
  458. }
  459. DWORD ParseLineForHtml(CStringArray &m_strArrayKeyWords,
  460. DWORD dwCookie,
  461. CString &strLine,
  462. COLORINFO *ColorInfo,
  463. int &nActualItems)
  464. {
  465. //对于无多行注释的语法在只取当前行的解析结果时可直接返回
  466. if(g_nBeginCommentExStrCount==0 && ColorInfo==NULL)
  467. return dwCookie;
  468. int nLength = strLine.GetLength();
  469. int nIdentBegin = -1;
  470. int i;
  471. BOOL bMatch;
  472. BOOL bInString; //定义一个字符串的界限
  473. BOOL bRedefineBlock = TRUE;
  474. BOOL bDecIndex = FALSE;
  475. if(nLength == 0)
  476. return dwCookie;
  477. int I = 0;
  478. for ( I = 0; ; I++)
  479. {
  480. if (bRedefineBlock) //如果开始定义颜色块向下做
  481. {
  482. int nPos = I;
  483. if (bDecIndex)
  484. nPos--;
  485. if (dwCookie & COOKIE_EXT_COMMENT)
  486. {
  487. DEFINE_BLOCK(nPos, COLORINDEX_COMMENT);
  488. }
  489. else if (dwCookie & COOKIE_STRING)
  490. {
  491. DEFINE_BLOCK(nPos, COLORINDEX_STRING);
  492. }
  493. else if (dwCookie & COOKIE_SCRIPT)
  494. {
  495. DEFINE_BLOCK(nPos, COLORINDEX_STRING);
  496. }
  497. else
  498. {
  499. DEFINE_BLOCK(nPos, COLORINDEX_NORMAL);
  500. }
  501. bRedefineBlock = FALSE;
  502. bDecIndex = FALSE;
  503. }
  504. if (I >= nLength)
  505. goto Out;
  506. //遇到双字节字体如中文直接跳过
  507. if(IsDBCSLeadByte(strLine[I])) //检查是不是中文字符
  508. {
  509. I += 2;
  510. if (I >= nLength)
  511. goto Out;
  512. else
  513. goto cmpnextchar; //继续处理strLine的下一个字符
  514. }
  515. //////////////////////////////
  516. if ( !(dwCookie & COOKIE_TAG) )
  517. {
  518. if (dwCookie & COOKIE_SCRIPT)
  519. {
  520. if ( I + 7 < nLength)
  521. {// the string "</script" length is 7;
  522. if (strLine[I] != '<')
  523. continue;
  524. if (strLine[I+1] != '/')
  525. continue;
  526. if (strLine[I+2] != 's' && strLine[I+2] != 'S')
  527. continue;
  528. if (strLine[I+3] != 'c' && strLine[I+3] != 'C')
  529. continue;
  530. if (strLine[I+4] != 'r' && strLine[I+4] != 'R')
  531. continue;
  532. if (strLine[I+5] != 'i' && strLine[I+5] != 'I')
  533. continue;
  534. if (strLine[I+6] != 'p' && strLine[I+6] != 'P')
  535. continue;
  536. if (strLine[I+7] != 't' && strLine[I+7] != 'T')
  537. continue;
  538. dwCookie &= ~COOKIE_SCRIPT;
  539. goto con;
  540. }
  541. continue;
  542. }
  543. }
  544. con:
  545. if (strLine[I] == '<')
  546. {
  547. dwCookie |= COOKIE_TAG;
  548. DEFINE_BLOCK(I, COLORINDEX_SYNTAX);
  549. //DEFINE_BLOCK(I+1, COLORINDEX_NORMAL);
  550. }
  551. if (dwCookie & COOKIE_TAG)
  552. {
  553. //如果当前正处于字符串变量中,则应检查是否有结束字符串变量的字符串
  554. if ( dwCookie & COOKIE_STRING )
  555. {
  556. int nlen;
  557. for (int i = 0; i < g_nEndStringStrCount; i++ )
  558. {
  559. if(g_EndStringStr[i]==NULL)
  560. continue;
  561. nlen = strlen(g_EndStringStr[i]);
  562. bMatch = TRUE;
  563. //如果strLine的当前字符串值与结束定义字符规则中的一项相同则中止定义字符串
  564. if (I >= nlen - 1)
  565. {
  566. for(int k=0; k<nlen; k++) { //向前搜索字符串检查是否与结束定义的字符串相同
  567. if(strLine[I-nlen+1+k]!=g_EndStringStr[i][k])
  568. {
  569. bMatch = FALSE; //如果不匹配,中断比较
  570. break;
  571. }
  572. }
  573. if(bMatch) {
  574. dwCookie &= ~COOKIE_STRING;
  575. bRedefineBlock = TRUE;
  576. goto cmpnextchar; //继续处理strLine的下一个字符
  577. }
  578. }
  579. }
  580. goto cmpnextchar; //如果没有结束定义字符串继续处理strLine的下一个字符
  581. }
  582. //如果当前正处于字符变量中,则应检查是否有结束字符变量的字符串
  583. if ( dwCookie & COOKIE_CHAR )
  584. {
  585. int nlen;
  586. for (i = 0; i < g_nEndCharStrCount; i++ )
  587. {
  588. if(g_EndCharStr[i]==NULL)
  589. continue;
  590. nlen = strlen(g_EndCharStr[i]);
  591. bMatch = TRUE;
  592. //如果strLine的当前字符值与结束定义字符规则中的一项相同则中止定义字符串
  593. if (I >= nlen - 1)
  594. {
  595. for(int k=0; k<nlen; k++) { //向前搜索字符串检查是否与结束定义的字符相同
  596. if(strLine[I-nlen+1+k]!=g_EndCharStr[i][k])
  597. {
  598. bMatch = FALSE; //如果不匹配,中断比较
  599. break;
  600. }
  601. }
  602. if(bMatch) {
  603. dwCookie &= ~COOKIE_CHAR;
  604. bRedefineBlock = TRUE;
  605. goto cmpnextchar; //继续处理strLine的下一个字符
  606. }
  607. }
  608. }
  609. goto cmpnextchar; //如果没有结束定义字符继续处理strLine的下一个字符
  610. }
  611. //如果当前正处于多行注释中,则应检查是否有结束多行注释的字符串
  612. if ( dwCookie & COOKIE_EXT_COMMENT ) {
  613. for (i = 0; i < g_nEndCommentExStrCount; i++ )
  614. {
  615. if(g_EndCommentExStr[i]==NULL)
  616. continue;
  617. bMatch = TRUE;
  618. int nlen = strlen(g_EndCommentExStr[i]);
  619. if(I >= nlen - 1)
  620. {
  621. for(int k=0; k<nlen; k++) {
  622. if(strLine[I-nlen+1+k]!=g_EndCommentExStr[i][k])
  623. {
  624. bMatch = FALSE;
  625. break;
  626. }
  627. }
  628. if(bMatch) {
  629. dwCookie &= ~COOKIE_EXT_COMMENT;
  630. bRedefineBlock = TRUE;
  631. goto cmpnextchar;
  632. }
  633. }
  634. }
  635. goto cmpnextchar;
  636. }
  637. //处理字符串变量的开始
  638. for (i = 0; i < g_nBeginStringStrCount; i++ ) {
  639. if(g_BeginStringStr[i]==NULL)
  640. continue;
  641. int nlen = strlen(g_BeginStringStr[i]);
  642. bMatch = TRUE;
  643. if(I >= nlen - 1)
  644. {
  645. for(int k=0; k<nlen; k++)
  646. {
  647. if(strLine[I-nlen+1+k]!=g_BeginStringStr[i][k])
  648. {
  649. bMatch = FALSE;
  650. break;
  651. }
  652. }
  653. if(bMatch) {
  654. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_STRING);
  655. dwCookie |= COOKIE_STRING;
  656. goto cmpnextchar;
  657. }
  658. }
  659. }
  660. //处理字符型变量的开始
  661. for (i = 0; i < g_nBeginCharStrCount; i++ )
  662. {
  663. if(g_BeginCharStr[i]==NULL)
  664. continue;
  665. int nlen = strlen(g_BeginCharStr[i]);
  666. bMatch = TRUE;
  667. if(I >= nlen - 1)
  668. {
  669. for(int k=0; k<nlen; k++)
  670. {
  671. if(strLine[I-nlen+1+k]!=g_BeginCharStr[i][k])
  672. {
  673. bMatch = FALSE;
  674. break;
  675. }
  676. }
  677. if(bMatch) {
  678. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_CHAR);
  679. dwCookie |= COOKIE_CHAR;
  680. goto cmpnextchar;
  681. }
  682. }
  683. }
  684. //处理多行注释的开始
  685. for (i = 0; i < g_nBeginCommentExStrCount; i++ )
  686. {
  687. if(g_BeginCommentExStr[i]==NULL)
  688. continue;
  689. int nlen = strlen(g_BeginCommentExStr[i]);
  690. bMatch = TRUE;
  691. if(I >= nlen - 1)
  692. {
  693. for(int k=0; k<nlen; k++) {
  694. if(strLine[I-nlen+1+k]!=g_BeginCommentExStr[i][k])
  695. {
  696. bMatch = FALSE;
  697. break;
  698. }
  699. }
  700. if(bMatch)
  701. {
  702. nActualItems--;
  703. DEFINE_BLOCK(I - nlen + 1, COLORINDEX_COMMENT);
  704. dwCookie |= COOKIE_EXT_COMMENT;
  705. goto cmpnextchar;
  706. }
  707. }
  708. }
  709. bInString = FALSE;
  710. for ( i = 0; i < g_nstrInStringCount; i++ )
  711. {
  712. BOOL b = ( strLine[I] == g_strInString.GetAt(i) );
  713. bInString |= b;
  714. if(bInString)
  715. break;
  716. }
  717. if (isalnum(strLine[I]) || strLine[I] == '_' || bInString)
  718. {
  719. if (nIdentBegin == -1)
  720. nIdentBegin = I;
  721. }
  722. else
  723. {
  724. if (nIdentBegin >= 0)
  725. {
  726. CString strtmp= strLine.Mid(nIdentBegin, I - nIdentBegin);
  727. if (IsNumber(strtmp))
  728. {
  729. DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
  730. }//*
  731. else
  732. {
  733. if(strtmp.CompareNoCase(_T("script"))==0)
  734. {
  735. if( nIdentBegin > 0 && strLine[nIdentBegin-1] == '<')
  736. {
  737. dwCookie |= COOKIE_SCRIPT;
  738. }
  739. else if( nIdentBegin > 1 && strLine[nIdentBegin-1] == '/' && strLine[nIdentBegin-2] == '<')
  740. {
  741. dwCookie &= ~COOKIE_SCRIPT;
  742. DEFINE_BLOCK(nIdentBegin-2, COLORINDEX_SYNTAX);
  743. }
  744. }
  745. if( (nIdentBegin > 0) && (strLine[nIdentBegin-1] == '=') )
  746. {
  747. DEFINE_BLOCK(nIdentBegin, COLORINDEX_NORMAL);
  748. }
  749. else
  750. {
  751. DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX);
  752. }
  753. }
  754. bRedefineBlock = TRUE;
  755. bDecIndex = TRUE;
  756. nIdentBegin = -1;
  757. }
  758. }
  759. }
  760. if (strLine[I] == '>')
  761. {
  762. bRedefineBlock = FALSE;
  763. dwCookie &= ~COOKIE_TAG;
  764. DEFINE_BLOCK(I, COLORINDEX_SYNTAX);
  765. if(dwCookie & COOKIE_SCRIPT)
  766. {
  767. DEFINE_BLOCK(I+1, COLORINDEX_STRING);
  768. }
  769. else if( (I > 1) && (strLine[I-1]=='-') && (strLine[I-2]=='-') )
  770. {
  771. DEFINE_BLOCK(I, COLORINDEX_COMMENT);
  772. }
  773. else
  774. {
  775. DEFINE_BLOCK(I+1, COLORINDEX_NORMAL);
  776. }
  777. }
  778. cmpnextchar:
  779. i = 0;
  780. }
  781. Out: //当遇到单行注释时会直接跳到这儿
  782. if (dwCookie & COOKIE_TAG) {
  783. if (nIdentBegin >= 0)
  784. {
  785. CString strtmp = strLine.Mid(nIdentBegin, I - nIdentBegin);
  786. if (IsSynWord(m_strArrayKeyWords, strtmp))
  787. {
  788. if( (nIdentBegin > 0) && (strLine[nIdentBegin-1]=='/') ) {
  789. DEFINE_BLOCK(nIdentBegin-1, COLORINDEX_SYNTAX);
  790. }
  791. else {
  792. DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX);
  793. }
  794. if(strtmp.CompareNoCase(_T("script"))==0) {
  795. if( nIdentBegin > 0 && strLine[nIdentBegin-1] == '<') {
  796. dwCookie |= COOKIE_SCRIPT;
  797. }
  798. else if( nIdentBegin > 1 && strLine[nIdentBegin-1] == '/' && strLine[nIdentBegin-12] == '<') {
  799. dwCookie &= ~COOKIE_SCRIPT;
  800. DEFINE_BLOCK(nIdentBegin-2, COLORINDEX_NORMAL);
  801. }
  802. }
  803. }
  804. else if (IsNumber(strtmp))
  805. {
  806. DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
  807. }
  808. }
  809. }
  810. return dwCookie;
  811. }
  812. void LoadParseRule(int nlanguage)
  813. {
  814. g_strInString = _T("");
  815. g_nstrInStringCount = 0;
  816. g_nBeginCommentExStrCount = 0;
  817. g_nEndCommentExStrCount = 0;
  818. g_nLineCommentStrCount = 0;
  819. g_nBeginStringStrCount = 0;
  820. g_nEndStringStrCount = 0;
  821. g_nBeginCharStrCount = 0;
  822. g_nEndCharStrCount = 0;
  823. g_bControl = FALSE;
  824. g_bCase = FALSE;
  825. /////////////////////////////////////////////////////////////////////////////
  826. if(g_BeginCommentExStr[0]!= NULL) {delete g_BeginCommentExStr[0]; g_BeginCommentExStr[0] = NULL;}
  827. if(g_BeginCommentExStr[1]!= NULL) {delete g_BeginCommentExStr[1]; g_BeginCommentExStr[1] = NULL;}
  828. /////////////////////////////////////////////////////////////////////////////
  829. if(g_EndCommentExStr[0]!= NULL) {delete g_EndCommentExStr[0]; g_EndCommentExStr[0] = NULL;}
  830. if(g_EndCommentExStr[1]!= NULL) {delete g_EndCommentExStr[1]; g_EndCommentExStr[1] = NULL;}
  831. /////////////////////////////////////////////////////////////////////////////
  832. if(g_LineCommentStr[0]!= NULL) {delete g_LineCommentStr[0]; g_LineCommentStr[0] = NULL;}
  833. if(g_LineCommentStr[1]!= NULL) {delete g_LineCommentStr[1]; g_LineCommentStr[1] = NULL;}
  834. /////////////////////////////////////////////////////////////////////////////
  835. if(g_BeginStringStr[0]!= NULL) {delete g_BeginStringStr[0]; g_BeginStringStr[0] = NULL;}
  836. /////////////////////////////////////////////////////////////////////////////
  837. if(g_EndStringStr[0]!= NULL) {delete g_EndStringStr[0]; g_EndStringStr[0] = NULL;}
  838. /////////////////////////////////////////////////////////////////////////////
  839. if(g_BeginCharStr[0]!= NULL) {delete g_BeginCharStr[0]; g_BeginCharStr[0] = NULL;}
  840. /////////////////////////////////////////////////////////////////////////////
  841. if(g_EndCharStr[0]!= NULL) {delete g_EndCharStr[0]; g_EndCharStr[0] = NULL;}
  842. CString strInString = _T("");
  843. CString BeginCommentExStr0 = _T("");
  844. CString EndCommentExStr0 = _T("");
  845. CString BeginCommentExStr1 = _T("");
  846. CString EndCommentExStr1 = _T("");
  847. CString LineCommentStr0 = _T("");
  848. CString LineCommentStr1 = _T("");
  849. CString BeginStringStr0 = _T("");
  850. CString EndStringStr0 = _T("");
  851. CString BeginCharStr0 = _T("");
  852. CString EndCharStr0 = _T("");
  853. switch ( nlanguage ) {
  854. case _BASIC:
  855. strInString = _T("&#");
  856. LineCommentStr0=_T("\'");
  857. LineCommentStr1=_T("rem");
  858. BeginStringStr0=_T("\"");
  859. EndStringStr0=_T("\"");
  860. break;
  861. default: //is NONE
  862. return;
  863. }
  864. CString strLanguagePos = _T("icrEdit__ParseRule");
  865. strLanguagePos += GetLanguageString(nlanguage);
  866. CString strtmp;
  867. CWinApp *app = AfxGetApp();
  868. g_bCase = app->GetProfileInt( strLanguagePos, _T("g_bCase"), g_bCase);
  869. //一个单词包含的字符常量
  870. strtmp = app->GetProfileString( strLanguagePos, _T("strInString"), strInString);
  871. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  872. if(!strtmp.IsEmpty()) {
  873. g_strInString = strtmp;
  874. g_nstrInStringCount = g_strInString.GetLength();
  875. }
  876. //一个单词包含的字符常量
  877. //开始多行注释的字符串
  878. strtmp = app->GetProfileString( strLanguagePos, _T("BeginCommentExStr0"), BeginCommentExStr0);
  879. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  880. if(!strtmp.IsEmpty()) {
  881. g_BeginCommentExStr[0] = new TCHAR[strtmp.GetLength()+1];
  882. strcpy(g_BeginCommentExStr[0], strtmp);
  883. g_nBeginCommentExStrCount = 1;
  884. }
  885. strtmp = app->GetProfileString( strLanguagePos, _T("BeginCommentExStr1"), BeginCommentExStr1);
  886. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  887. if(!strtmp.IsEmpty()) {
  888. g_BeginCommentExStr[1] = new TCHAR[strtmp.GetLength()+1];
  889. strcpy(g_BeginCommentExStr[1], strtmp);
  890. g_nBeginCommentExStrCount = 2;
  891. }
  892. //开始多行注释的字符串
  893. //结束多行注释的字符串
  894. strtmp = app->GetProfileString( strLanguagePos, _T("EndCommentExStr0"), EndCommentExStr0);
  895. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  896. if(!strtmp.IsEmpty()) {
  897. g_EndCommentExStr[0] = new TCHAR[strtmp.GetLength()+1];
  898. strcpy(g_EndCommentExStr[0], strtmp);
  899. g_nEndCommentExStrCount = 1;
  900. }
  901. strtmp = app->GetProfileString( strLanguagePos, _T("EndCommentExStr1"), EndCommentExStr1);
  902. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  903. if(!strtmp.IsEmpty()) {
  904. g_EndCommentExStr[1] = new TCHAR[strtmp.GetLength()+1];
  905. strcpy(g_EndCommentExStr[1], strtmp);
  906. g_nEndCommentExStrCount = 2;
  907. }
  908. //结束多行注释的字符串
  909. //开始单行注释的字符串
  910. strtmp = app->GetProfileString( strLanguagePos, _T("LineCommentStr0"), LineCommentStr0);
  911. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  912. if(!strtmp.IsEmpty()) {
  913. g_LineCommentStr[0] = new TCHAR[strtmp.GetLength()+1];
  914. strcpy(g_LineCommentStr[0], strtmp);
  915. g_nLineCommentStrCount = 1;
  916. }
  917. strtmp = app->GetProfileString( strLanguagePos, _T("LineCommentStr1"), LineCommentStr1);
  918. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  919. if(!strtmp.IsEmpty()) {
  920. g_LineCommentStr[1] = new TCHAR[strtmp.GetLength()+1];
  921. strcpy(g_LineCommentStr[1], strtmp);
  922. g_nLineCommentStrCount = 2;
  923. }
  924. //开始单行注释的字符串
  925. //开始字符串变量的字符串
  926. strtmp = app->GetProfileString( strLanguagePos, _T("BeginStringStr0"), BeginStringStr0);
  927. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  928. if(!strtmp.IsEmpty()) {
  929. g_BeginStringStr[0] = new TCHAR[strtmp.GetLength()+1];
  930. strcpy(g_BeginStringStr[0], strtmp);
  931. g_nBeginStringStrCount = 1;
  932. }
  933. //开始字符串变量的字符串
  934. //结束字符串变量的字符串
  935. strtmp = app->GetProfileString( strLanguagePos, _T("EndStringStr0"), EndStringStr0);
  936. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  937. if(!strtmp.IsEmpty()) {
  938. g_EndStringStr[0] = new TCHAR[strtmp.GetLength()+1];
  939. strcpy(g_EndStringStr[0], strtmp);
  940. g_nEndStringStrCount = 1;
  941. }
  942. //结束字符串变量的字符串
  943. //开始字符型常量的字符串
  944. strtmp = app->GetProfileString( strLanguagePos, _T("BeginCharStr0"), BeginCharStr0);
  945. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  946. if(!strtmp.IsEmpty()) {
  947. g_BeginCharStr[0] = new TCHAR[strtmp.GetLength()+1];
  948. strcpy(g_BeginCharStr[0], strtmp);
  949. g_nBeginCharStrCount = 1;
  950. }
  951. //开始字符型常量的字符串
  952. //结束字符型常量的字符串
  953. strtmp = app->GetProfileString( strLanguagePos, _T("EndCharStr0"), EndCharStr0);
  954. strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9);
  955. if(!strtmp.IsEmpty()) {
  956. g_EndCharStr[0] = new TCHAR[strtmp.GetLength()+1];
  957. strcpy(g_EndCharStr[0], strtmp);
  958. g_nEndCharStrCount = 1;
  959. }
  960. //结束字符型常量的字符串
  961. }
  962. CString GetLanguageString(int nlanguage)
  963. {
  964. switch ( nlanguage ) {
  965. case _BASIC:
  966. return _T("_BASIC");
  967. default: //is NONE
  968. return _T("Plain text");
  969. }
  970. }
  971. void DeleteAllocString()
  972. {
  973. //删除分配的语法解析规则字符串指针以防止内存泄漏
  974. if(g_BeginCommentExStr[0]!= NULL) {delete g_BeginCommentExStr[0]; g_BeginCommentExStr[0] = NULL;}
  975. if(g_BeginCommentExStr[1]!= NULL) {delete g_BeginCommentExStr[1]; g_BeginCommentExStr[1] = NULL;}
  976. if(g_EndCommentExStr[0]!= NULL) {delete g_EndCommentExStr[0]; g_EndCommentExStr[0] = NULL;}
  977. if(g_EndCommentExStr[1]!= NULL) {delete g_EndCommentExStr[1]; g_EndCommentExStr[1] = NULL;}
  978. if(g_LineCommentStr[0]!= NULL) {delete g_LineCommentStr[0]; g_LineCommentStr[0] = NULL;}
  979. if(g_LineCommentStr[1]!= NULL) {delete g_LineCommentStr[1]; g_LineCommentStr[1] = NULL;}
  980. if(g_BeginStringStr[0]!= NULL) {delete g_BeginStringStr[0]; g_BeginStringStr[0] = NULL;}
  981. if(g_EndStringStr[0]!= NULL) {delete g_EndStringStr[0]; g_EndStringStr[0] = NULL;}
  982. if(g_BeginCharStr[0]!= NULL) {delete g_BeginCharStr[0]; g_BeginCharStr[0] = NULL;}
  983. if(g_EndCharStr[0]!= NULL) {delete g_EndCharStr[0]; g_EndCharStr[0] = NULL;}
  984. }
  985. CString GetLineCommentString(int nlanguage)
  986. {
  987. CString LineCommentStr0 = _T("");
  988. switch ( nlanguage ) {
  989. case _BASIC:
  990. LineCommentStr0=_T("\'");
  991. break;
  992. default: //is NONE
  993. return LineCommentStr0;
  994. }
  995. CString strLanguagePos = _T("icrEdit__ParseRule");
  996. strLanguagePos += GetLanguageString(nlanguage);
  997. CWinApp *app = AfxGetApp();
  998. LineCommentStr0 = app->GetProfileString( strLanguagePos, _T("LineCommentStr0"), LineCommentStr0);
  999. LineCommentStr0.TrimLeft();
  1000. LineCommentStr0.TrimRight();
  1001. LineCommentStr0.TrimLeft(0x9);
  1002. LineCommentStr0.TrimRight(0x9);
  1003. if(!LineCommentStr0.IsEmpty())
  1004. return LineCommentStr0;
  1005. LineCommentStr0 = app->GetProfileString( strLanguagePos, _T("LineCommentStr1"), LineCommentStr0);
  1006. LineCommentStr0.TrimLeft();
  1007. LineCommentStr0.TrimRight();
  1008. LineCommentStr0.TrimLeft(0x9);
  1009. LineCommentStr0.TrimRight(0x9);
  1010. return LineCommentStr0;
  1011. }
  1012. //根据显示给用户看的字符串取出语言
  1013. int GetLanguageByStringShow(CString strlanguage)
  1014. {
  1015. if(strlanguage==_T("Basic"))
  1016. return _BASIC;
  1017. return 0;
  1018. }
  1019. //根据语言返回给用户看的字符串
  1020. CString GetStringShowByLanguage(int nlanguage)
  1021. {
  1022. switch(nlanguage) {
  1023. case _BASIC:
  1024. return _T("Basic");
  1025. default:
  1026. return _T("Plain text");
  1027. }
  1028. }