TransDB.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // TransDB.cpp
  20. //
  21. #include "stdAfx.h"
  22. #include "transdb.h"
  23. #include "noxstringdlg.h"
  24. #include "noxstring.h"
  25. #include "assert.h"
  26. #include "bin.h"
  27. #include "list.h"
  28. static char buffer[100*1024];
  29. static List DataBases;
  30. static LANGINFO langinfo[] =
  31. {
  32. { LANGID_US, "US", "us", "e"},
  33. { LANGID_UK, "UK", "uk", "e" },
  34. { LANGID_GERMAN, "German", "ge", "g" },
  35. { LANGID_FRENCH, "French", "fr", "f" },
  36. { LANGID_SPANISH, "Spanish", "sp", "s" },
  37. { LANGID_ITALIAN, "Italian", "it", "i" },
  38. { LANGID_JAPANESE, "Japanese", "ja", "j" },
  39. { LANGID_KOREAN, "Korean", "ko", "k" },
  40. { LANGID_CHINESE, "Chinese", "ch", "c" },
  41. { LANGID_JABBER, "Jabberwockie", "jb", "e" },
  42. { LANGID_UNKNOWN, "Unknown", NULL, NULL }
  43. };
  44. LANGINFO *GetLangInfo ( int index )
  45. {
  46. if ( (index >= 0) && (index < (sizeof ( langinfo ) / sizeof (LANGINFO )) -1) )
  47. {
  48. return &langinfo[index];
  49. }
  50. return NULL;
  51. }
  52. LANGINFO *GetLangInfo ( LangID langid )
  53. {
  54. LANGINFO *item;
  55. item = langinfo;
  56. while ( item->langid != LANGID_UNKNOWN )
  57. {
  58. if ( item->langid == langid )
  59. {
  60. return item;
  61. }
  62. item++;
  63. }
  64. return NULL;
  65. }
  66. char *GetLangName ( LangID langid )
  67. {
  68. LANGINFO *item;
  69. if ( ( item = GetLangInfo ( langid )) )
  70. {
  71. return item->name;
  72. }
  73. return "unknown";
  74. }
  75. LANGINFO *GetLangInfo ( char *language )
  76. {
  77. LANGINFO *item;
  78. item = langinfo;
  79. while ( item->langid != LANGID_UNKNOWN )
  80. {
  81. if ( !stricmp ( language, item->name ) )
  82. {
  83. return item;
  84. }
  85. item++;
  86. }
  87. return NULL;
  88. }
  89. TransDB* FirstTransDB ( void )
  90. {
  91. ListNode *first;
  92. first = DataBases.Next ();
  93. if ( first )
  94. {
  95. return (TransDB *) first->Item ();
  96. }
  97. return NULL;
  98. }
  99. TransDB::TransDB ( char *cname )
  100. {
  101. text_bin = new Bin ();
  102. text_id_bin = new BinID ();
  103. label_bin = new Bin ();
  104. obsolete_bin = new Bin ();
  105. strncpy ( name, cname, sizeof ( name ) -1 );
  106. name[sizeof(name)-1] = 0;
  107. node.SetItem ( this );
  108. DataBases.AddToTail ( &node );
  109. next_string_id = -1;
  110. valid = TRUE;
  111. num_obsolete = 0;
  112. checked_for_errors = FALSE;
  113. flags = TRANSDB_OPTION_NONE | TRANSDB_OPTION_DUP_TEXT;
  114. }
  115. TransDB:: ~TransDB ( )
  116. {
  117. Clear ();
  118. node.Remove ();
  119. delete text_bin;
  120. delete text_id_bin;
  121. delete label_bin;
  122. delete obsolete_bin;
  123. }
  124. void TransDB::AddLabel ( NoxLabel *label )
  125. {
  126. ListNode *node = new ListNode ();
  127. node->SetItem ( label );
  128. label_bin->Add ( label, label->Name() );
  129. labels.AddToTail ( node );
  130. label->SetDB ( this );
  131. Changed ();
  132. }
  133. void TransDB::AddText ( NoxText *text )
  134. {
  135. text_bin->Add ( text, text->Get() );
  136. if ( text->ID () > 0 )
  137. {
  138. text_id_bin->Add ( text, text->ID ());
  139. }
  140. }
  141. void TransDB::AddObsolete ( NoxText *text )
  142. {
  143. ListNode *node = new ListNode ();
  144. node->SetItem ( text );
  145. obsolete_bin->Add ( text, text->Get() );
  146. if ( text->ID () > 0 )
  147. {
  148. text_id_bin->Add ( text, text->ID ());
  149. }
  150. num_obsolete++;
  151. text->SetParent ( (DBAttribs *)this );
  152. text->Changed ();
  153. obsolete.AddToTail ( node );
  154. Changed ();
  155. }
  156. void TransDB::RemoveLabel ( NoxLabel *label )
  157. {
  158. ListNode *node;
  159. if ( (node = labels.Find ( label )) )
  160. {
  161. node->Remove ();
  162. label->SetDB ( NULL );
  163. label_bin->Remove ( label );
  164. delete node;
  165. Changed ();
  166. }
  167. }
  168. void TransDB::RemoveText ( NoxText *text )
  169. {
  170. text_bin->Remove ( text );
  171. text_id_bin->Remove ( text );
  172. }
  173. void TransDB::RemoveObsolete ( NoxText *text )
  174. {
  175. ListNode *node;
  176. if ( (node = obsolete.Find ( text )) )
  177. {
  178. node->Remove ();
  179. obsolete_bin->Remove ( text );
  180. text_id_bin->Remove ( text );
  181. num_obsolete--;
  182. delete node;
  183. Changed ();
  184. }
  185. }
  186. int TransDB::NumLabelsChanged ( void )
  187. {
  188. NoxLabel *label;
  189. ListSearch sh;
  190. int changed = 0;
  191. label = FirstLabel ( sh );
  192. while ( label )
  193. {
  194. if ( label->IsChanged ())
  195. {
  196. changed++;
  197. }
  198. label = NextLabel ( sh );
  199. }
  200. return changed;
  201. }
  202. int TransDB::NumLabels ( void )
  203. {
  204. return labels.NumItems();
  205. }
  206. NoxLabel* TransDB::FirstLabel ( ListSearch& sh )
  207. {
  208. ListNode *node;
  209. if ( ( node = sh.FirstNode ( &labels )))
  210. {
  211. return (NoxLabel *) node->Item ();
  212. }
  213. return NULL;
  214. }
  215. NoxLabel* TransDB::NextLabel ( ListSearch& sh)
  216. {
  217. ListNode *node;
  218. if ( ( node = sh.Next ()))
  219. {
  220. return (NoxLabel *) node->Item ();
  221. }
  222. return NULL;
  223. }
  224. NoxText* TransDB::FirstObsolete ( ListSearch& sh )
  225. {
  226. ListNode *node;
  227. if ( ( node = sh.FirstNode ( &obsolete )))
  228. {
  229. return (NoxText *) node->Item ();
  230. }
  231. return NULL;
  232. }
  233. NoxText* TransDB::NextObsolete ( ListSearch& sh)
  234. {
  235. ListNode *node;
  236. if ( ( node = sh.Next ()))
  237. {
  238. return (NoxText *) node->Item ();
  239. }
  240. return NULL;
  241. }
  242. NoxLabel* TransDB::FindLabel ( OLECHAR *name )
  243. {
  244. return (NoxLabel *) label_bin->Get ( name );
  245. }
  246. NoxText* TransDB::FindText ( OLECHAR *text )
  247. {
  248. return (NoxText *) text_bin->Get ( text );
  249. }
  250. NoxText* TransDB::FindSubText ( OLECHAR *pattern, int item )
  251. {
  252. NoxLabel *label;
  253. ListSearch sh;
  254. NoxText *text;
  255. ListSearch sh_text;
  256. int plen = wcslen ( pattern );
  257. label = FirstLabel ( sh );
  258. while ( label )
  259. {
  260. text = label->FirstText ( sh_text );
  261. while ( text )
  262. {
  263. if ( !wcsnicmp ( text->Get (), pattern, 15 ))
  264. {
  265. if ( !item )
  266. {
  267. return text;
  268. }
  269. item--;
  270. }
  271. text = label->NextText ( sh_text );
  272. }
  273. label = NextLabel ( sh );
  274. }
  275. return NULL;
  276. }
  277. NoxText* TransDB::FindText ( int id )
  278. {
  279. return (NoxText *) text_id_bin->Get ( id );
  280. }
  281. NoxText* TransDB::FindNextText ( void )
  282. {
  283. return (NoxText *) text_bin->GetNext ( );
  284. }
  285. NoxText* TransDB::FindObsolete ( OLECHAR *name )
  286. {
  287. return (NoxText *) obsolete_bin->Get ( name );
  288. }
  289. NoxText* TransDB::FindNextObsolete ( void )
  290. {
  291. return (NoxText *) obsolete_bin->GetNext ( );
  292. }
  293. int TransDB::Clear ( void )
  294. {
  295. ListSearch sh;
  296. NoxLabel *label;
  297. NoxText *text;
  298. ListNode *node;
  299. int count = 0;
  300. text_bin->Clear ();
  301. text_id_bin->Clear ();
  302. label_bin->Clear ();
  303. obsolete_bin->Clear ();
  304. while ( node = sh.FirstNode ( &labels ) )
  305. {
  306. node->Remove ();
  307. label = (NoxLabel *) node->Item ();
  308. count++;
  309. delete label;
  310. delete node;
  311. }
  312. while ( node = sh.FirstNode ( &obsolete ) )
  313. {
  314. node->Remove ();
  315. text = (NoxText *) node->Item ();
  316. count++;
  317. delete text;
  318. delete node;
  319. }
  320. num_obsolete = 0;
  321. if ( next_string_id != -1 )
  322. {
  323. next_string_id = START_STRING_ID;
  324. }
  325. if ( count )
  326. {
  327. Changed ();
  328. }
  329. valid = TRUE;
  330. return count;
  331. }
  332. void TransDB::ClearChanges ( void )
  333. {
  334. ListSearch sh;
  335. NoxLabel *label;
  336. label = FirstLabel ( sh );
  337. while ( label )
  338. {
  339. label->ClearChanges ();
  340. label = NextLabel ( sh );
  341. }
  342. NoxText *text = FirstObsolete ( sh );
  343. while ( text )
  344. {
  345. text->ClearChanges ();
  346. text = NextObsolete ( sh );
  347. }
  348. NotChanged ();
  349. }
  350. void TransDB::ClearProcessed ( void )
  351. {
  352. ListSearch sh;
  353. NoxLabel *label;
  354. label = FirstLabel ( sh );
  355. while ( label )
  356. {
  357. label->ClearProcessed ();
  358. label = NextLabel ( sh );
  359. }
  360. NotProcessed ();
  361. }
  362. void TransDB::ClearMatched ( void )
  363. {
  364. ListSearch sh;
  365. NoxLabel *label;
  366. label = FirstLabel ( sh );
  367. while ( label )
  368. {
  369. label->ClearMatched ();
  370. label = NextLabel ( sh );
  371. }
  372. NotMatched ();
  373. }
  374. void TransDB::AddToTree ( CTreeCtrl *tc, HTREEITEM parent, int changes, void (*cb) ( void ) )
  375. {
  376. HTREEITEM item;
  377. HTREEITEM ilabels, iobsolete;
  378. ListSearch sh;
  379. NoxLabel *label;
  380. NoxText *txt;
  381. sprintf ( buffer, "%s%c (%d/%d)",name, ChangedSymbol(), NumLabelsChanged(), NumLabels() );
  382. item = tc->InsertItem ( buffer, parent );
  383. ilabels = tc->InsertItem ( "Labels", item );
  384. label = FirstLabel ( sh );
  385. while ( label )
  386. {
  387. if ( !changes || label->IsChanged ())
  388. {
  389. label->AddToTree ( tc, ilabels, changes );
  390. }
  391. if ( cb )
  392. {
  393. cb ( );
  394. }
  395. label = NextLabel ( sh );
  396. }
  397. if ( num_obsolete )
  398. {
  399. iobsolete = tc->InsertItem ( "Obsolete Strings", item );
  400. txt = FirstObsolete ( sh );
  401. while ( txt )
  402. {
  403. if ( !changes || txt->IsChanged ())
  404. {
  405. txt->AddToTree ( tc, iobsolete );
  406. }
  407. if ( cb )
  408. {
  409. cb ( );
  410. }
  411. txt = NextObsolete ( sh );
  412. }
  413. }
  414. }
  415. TransDB* TransDB::Next ( void )
  416. {
  417. ListNode *next;
  418. next = node.Next ();
  419. if ( next )
  420. {
  421. return (TransDB *) next->Item ();
  422. }
  423. return NULL;
  424. }
  425. void NoxLabel::init ( void )
  426. {
  427. db = NULL;
  428. comment = NULL;
  429. line_number = -1;
  430. max_len = 0;
  431. name = NULL;
  432. }
  433. NoxLabel::NoxLabel ( void )
  434. {
  435. init ();
  436. name = new OLEString ( );
  437. comment = new OLEString ( );
  438. context = new OLEString ( );
  439. speaker = new OLEString ( );
  440. listener = new OLEString ( );
  441. }
  442. NoxLabel::~NoxLabel ( )
  443. {
  444. Clear ();
  445. delete name;
  446. delete comment;
  447. delete context;
  448. delete speaker;
  449. delete listener;
  450. }
  451. void NoxLabel::Remove ( void )
  452. {
  453. if ( db )
  454. {
  455. db->RemoveLabel ( this );
  456. }
  457. }
  458. void NoxLabel::RemoveText ( NoxText *txt )
  459. {
  460. ListNode *node;
  461. if ( (node = text.Find ( txt )) )
  462. {
  463. node->Remove ();
  464. txt->SetDB ( NULL );
  465. txt->SetLabel ( NULL );
  466. txt->SetParent ( NULL );
  467. delete node;
  468. Changed ();
  469. }
  470. }
  471. void NoxLabel::AddText ( NoxText *new_text )
  472. {
  473. TransDB *db = DB();
  474. ListNode *node = new ListNode ();
  475. node->SetItem ( new_text );
  476. text.AddToTail ( node );
  477. Changed ();
  478. new_text->SetDB ( db );
  479. new_text->SetParent ( (DBAttribs *) this );
  480. new_text->SetLabel ( this );
  481. }
  482. int NoxLabel::Clear ( void )
  483. {
  484. ListSearch sh;
  485. NoxText *txt;
  486. ListNode *node;
  487. int count = 0;
  488. while ( node = sh.FirstNode ( &text ) )
  489. {
  490. node->Remove ();
  491. txt = (NoxText *) node->Item ();
  492. delete txt;
  493. delete node;
  494. count++;
  495. }
  496. if ( count )
  497. {
  498. Changed ();
  499. }
  500. return count;
  501. }
  502. NoxLabel* NoxLabel::Clone ( void )
  503. {
  504. NoxLabel *clone = new NoxLabel();
  505. NoxText *txt;
  506. ListSearch sh;
  507. clone->SetName ( Name());
  508. clone->SetComment ( Comment ());
  509. clone->SetListener ( Listener ());
  510. clone->SetSpeaker ( Speaker ());
  511. clone->SetMaxLen ( MaxLen ());
  512. clone->SetContext ( Context ());
  513. txt = FirstText ( sh );
  514. while ( txt )
  515. {
  516. clone->AddText ( txt->Clone ());
  517. txt = NextText ( sh );
  518. }
  519. return clone;
  520. }
  521. NoxText* NoxLabel::FirstText ( ListSearch& sh )
  522. {
  523. ListNode *node;
  524. if ( ( node = sh.FirstNode ( &text )))
  525. {
  526. return (NoxText *) node->Item ();
  527. }
  528. return NULL;
  529. }
  530. NoxText* NoxLabel::NextText ( ListSearch& sh)
  531. {
  532. ListNode *node;
  533. if ( ( node = sh.Next ( )))
  534. {
  535. return (NoxText *) node->Item ();
  536. }
  537. return NULL;
  538. }
  539. NoxText* NoxLabel::FindText ( OLECHAR *find_text )
  540. {
  541. ListSearch sh;
  542. NoxText *txt;
  543. txt = FirstText ( sh );
  544. while ( txt )
  545. {
  546. if ( !wcscmp ( txt->Get(), find_text ))
  547. {
  548. return txt;
  549. }
  550. txt = NextText ( sh );
  551. }
  552. return NULL;
  553. }
  554. void NoxLabel::SetDB ( TransDB *new_db )
  555. {
  556. NoxText *ntext;
  557. ListSearch sh;
  558. db = new_db;
  559. SetParent ( (DBAttribs *) new_db );
  560. ntext = FirstText ( sh );
  561. while ( ntext )
  562. {
  563. ntext->SetDB ( new_db );
  564. ntext = NextText ( sh );
  565. }
  566. }
  567. void NoxLabel::ClearChanges ( void )
  568. {
  569. NoxText *ntext;
  570. ListSearch sh;
  571. ntext = FirstText ( sh );
  572. while ( ntext )
  573. {
  574. ntext->ClearChanges();
  575. ntext = NextText ( sh );
  576. }
  577. NotChanged();
  578. }
  579. void NoxLabel::ClearProcessed ( void )
  580. {
  581. NoxText *ntext;
  582. ListSearch sh;
  583. ntext = FirstText ( sh );
  584. while ( ntext )
  585. {
  586. ntext->ClearProcessed();
  587. ntext = NextText ( sh );
  588. }
  589. NotProcessed();
  590. }
  591. void NoxLabel::ClearMatched ( void )
  592. {
  593. NoxText *ntext;
  594. ListSearch sh;
  595. ntext = FirstText ( sh );
  596. while ( ntext )
  597. {
  598. ntext->ClearMatched();
  599. ntext = NextText ( sh );
  600. }
  601. NotMatched();
  602. }
  603. int NoxLabel::AllMatched ( void )
  604. {
  605. NoxText *ntext;
  606. ListSearch sh;
  607. ntext = FirstText ( sh );
  608. while ( ntext )
  609. {
  610. if ( !ntext->Matched() )
  611. {
  612. return FALSE;
  613. }
  614. ntext = NextText ( sh );
  615. }
  616. return TRUE;
  617. }
  618. NoxText::NoxText( void )
  619. {
  620. init ();
  621. text = new OLEString ( );
  622. wavefile = new OLEString ( );
  623. }
  624. int NoxText::IsSent ( void )
  625. {
  626. return sent;
  627. }
  628. void NoxText::Sent ( int val )
  629. {
  630. sent = val;
  631. }
  632. void NoxLabel::AddToTree ( CTreeCtrl *tc, HTREEITEM parent, int changes )
  633. {
  634. HTREEITEM litem;
  635. ListSearch sh;
  636. NoxText *txt;
  637. sprintf ( buffer, "%s%c", NameSB(), ChangedSymbol() );
  638. litem = tc->InsertItem ( buffer, parent );
  639. txt = FirstText ( sh );
  640. while ( txt )
  641. {
  642. if ( !changes || txt->IsChanged ())
  643. {
  644. txt->AddToTree ( tc, litem );
  645. }
  646. txt = NextText ( sh );
  647. }
  648. if ( strcmp ( CommentSB(), "" ) )
  649. {
  650. sprintf ( buffer, "COMMENT : %s", CommentSB() );
  651. tc->InsertItem ( buffer, litem );
  652. }
  653. if ( strcmp ( ContextSB(), "" ) )
  654. {
  655. sprintf ( buffer, "CONTEXT : %s", ContextSB() );
  656. tc->InsertItem ( buffer, litem );
  657. }
  658. if ( strcmp ( SpeakerSB(), "" ) )
  659. {
  660. sprintf ( buffer, "SPEAKER : %s", SpeakerSB() );
  661. tc->InsertItem ( buffer, litem );
  662. }
  663. if ( strcmp ( ListenerSB(), "" ) )
  664. {
  665. sprintf ( buffer, "LISTENER: %s", ListenerSB() );
  666. tc->InsertItem ( buffer, litem );
  667. }
  668. if ( line_number != -1 )
  669. {
  670. sprintf ( buffer, "LINE : %d", line_number );
  671. tc->InsertItem ( buffer, litem );
  672. }
  673. if ( max_len )
  674. {
  675. sprintf ( buffer, "MAX LEN : %d", max_len );
  676. tc->InsertItem ( buffer, litem );
  677. }
  678. }
  679. void NoxText::init ( void )
  680. {
  681. db = NULL;
  682. label = NULL;
  683. line_number = -1;
  684. revision = 1;
  685. text = NULL;
  686. wavefile = NULL;
  687. id = -1;
  688. retranslate = FALSE;
  689. sent = FALSE;
  690. }
  691. NoxText::~NoxText( )
  692. {
  693. Clear();
  694. delete text;
  695. delete wavefile;
  696. }
  697. void NoxText::SetDB ( TransDB *new_db )
  698. {
  699. Translation *trans;
  700. ListSearch sh;
  701. if ( db )
  702. {
  703. db->RemoveText ( this );
  704. }
  705. if ( (db = new_db) )
  706. {
  707. AssignID ();
  708. db->AddText ( this );
  709. }
  710. trans = FirstTranslation ( sh );
  711. while ( trans )
  712. {
  713. trans->SetDB ( new_db );
  714. trans = NextTranslation ( sh );
  715. }
  716. }
  717. void NoxText::Remove ( void )
  718. {
  719. if ( label )
  720. {
  721. label->RemoveText ( this );
  722. }
  723. }
  724. int NoxText::IsDialog ( void )
  725. {
  726. return strcmp (WaveSB(), "" );
  727. }
  728. int NoxText::DialogIsValid ( const char *path, LangID langid, int check )
  729. {
  730. LANGINFO *linfo;
  731. CWaveInfo *winfo;
  732. DBAttribs *attribs;
  733. linfo = GetLangInfo ( langid );
  734. if ( langid == LANGID_US )
  735. {
  736. winfo = &WaveInfo;
  737. attribs = (DBAttribs *) this;
  738. }
  739. else
  740. {
  741. Translation *trans = GetTranslation ( langid );
  742. if ( !trans )
  743. {
  744. return FALSE;
  745. }
  746. attribs = (DBAttribs *) trans;
  747. winfo = &trans->WaveInfo;
  748. }
  749. if ( winfo->Valid () && check )
  750. {
  751. WIN32_FIND_DATA info;
  752. HANDLE handle;
  753. winfo->SetValid ( FALSE );
  754. winfo->SetMissing ( TRUE );
  755. sprintf ( buffer, "%s%s\\%s%s.wav", path, linfo->character, WaveSB(), linfo->character );
  756. if ( (handle = FindFirstFile ( buffer, &info )) != INVALID_HANDLE_VALUE )
  757. {
  758. if ( ! (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
  759. {
  760. if ( winfo->Lo () == info.nFileSizeLow && winfo->Hi() == info.nFileSizeHigh )
  761. {
  762. winfo->SetValid ( TRUE );
  763. }
  764. winfo->SetMissing ( FALSE );
  765. }
  766. FindClose ( handle );
  767. }
  768. }
  769. return winfo->Valid ();
  770. }
  771. int NoxText::ValidateDialog ( const char *path, LangID langid )
  772. {
  773. WIN32_FIND_DATA info;
  774. HANDLE handle;
  775. CWaveInfo *winfo;
  776. LANGINFO *linfo;
  777. DBAttribs *attribs;
  778. linfo = GetLangInfo ( langid );
  779. if ( langid == LANGID_US )
  780. {
  781. winfo = &WaveInfo;
  782. attribs = (DBAttribs *) this;
  783. }
  784. else
  785. {
  786. Translation *trans = GetTranslation ( langid );
  787. if ( !trans )
  788. {
  789. return FALSE;
  790. }
  791. attribs = (DBAttribs *) trans;
  792. winfo = &trans->WaveInfo;
  793. }
  794. winfo->SetValid ( FALSE );
  795. winfo->SetMissing ( TRUE );
  796. sprintf ( buffer, "%s%s\\%s%s.wav", path, linfo->character , WaveSB(), linfo->character );
  797. if ( (handle = FindFirstFile ( buffer, &info )) != INVALID_HANDLE_VALUE )
  798. {
  799. if ( ! (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
  800. {
  801. winfo->SetLo ( info.nFileSizeLow );
  802. winfo->SetHi ( info.nFileSizeHigh );
  803. winfo->SetValid ( TRUE );
  804. winfo->SetMissing ( FALSE );
  805. attribs->Changed();
  806. }
  807. FindClose ( handle );
  808. }
  809. return winfo->Valid ();
  810. }
  811. int NoxText::DialogIsPresent ( const char *path, LangID langid )
  812. {
  813. WIN32_FIND_DATA info;
  814. HANDLE handle;
  815. int present = FALSE;
  816. LANGINFO *linfo = GetLangInfo ( langid );
  817. sprintf ( buffer, "%s%s\\%s%s.wav", path, linfo->character , WaveSB(), linfo->character );
  818. if ( (handle = FindFirstFile ( buffer, &info )) != INVALID_HANDLE_VALUE )
  819. {
  820. if ( ! (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
  821. {
  822. present = TRUE;
  823. }
  824. FindClose ( handle );
  825. }
  826. return present;
  827. }
  828. void NoxText::AddTranslation ( Translation *trans )
  829. {
  830. ListNode *node = new ListNode ();
  831. node->SetItem ( trans );
  832. translations.AddToTail ( node );
  833. Changed ();
  834. trans->SetDB ( DB() );
  835. trans->SetParent ( (DBAttribs *) this );
  836. }
  837. Translation* NoxText::FirstTranslation ( ListSearch& sh )
  838. {
  839. ListNode *node;
  840. if ( ( node = sh.FirstNode ( &translations )))
  841. {
  842. return (Translation *) node->Item ();
  843. }
  844. return NULL;
  845. }
  846. Translation* NoxText::NextTranslation ( ListSearch& sh)
  847. {
  848. ListNode *node;
  849. if ( ( node = sh.Next ( )))
  850. {
  851. return (Translation *) node->Item ();
  852. }
  853. return NULL;
  854. }
  855. Translation* NoxText::GetTranslation ( LangID langid )
  856. {
  857. ListSearch sh;
  858. Translation *trans;
  859. trans = FirstTranslation ( sh );
  860. while ( trans )
  861. {
  862. if ( langid == trans->GetLangID())
  863. {
  864. break;
  865. }
  866. trans = NextTranslation ( sh );
  867. }
  868. return trans;
  869. }
  870. int NoxText::Clear ( void )
  871. {
  872. ListSearch sh;
  873. Translation *trans;
  874. ListNode *node;
  875. int count = 0;
  876. while ( node = sh.FirstNode ( &translations ) )
  877. {
  878. node->Remove ();
  879. trans = (Translation *) node->Item ();
  880. delete trans;
  881. delete node;
  882. count++;
  883. }
  884. if ( count )
  885. {
  886. Changed ();
  887. }
  888. return count;
  889. }
  890. NoxText* NoxText::Clone ( void )
  891. {
  892. NoxText *clone = new NoxText();
  893. Translation *trans;
  894. ListSearch sh;
  895. clone->Set ( Get ());
  896. clone->SetWave ( Wave ());
  897. clone->SetRevision ( Revision ());
  898. trans = FirstTranslation ( sh );
  899. while ( trans )
  900. {
  901. clone->AddTranslation ( trans->Clone ());
  902. trans = NextTranslation ( sh );
  903. }
  904. return clone;
  905. }
  906. void NoxText::ClearChanges ( void )
  907. {
  908. Translation *trans;
  909. ListSearch sh;
  910. trans = FirstTranslation ( sh );
  911. while ( trans )
  912. {
  913. trans->ClearChanges();
  914. trans = NextTranslation ( sh );
  915. }
  916. NotChanged();
  917. }
  918. void NoxText::ClearProcessed ( void )
  919. {
  920. Translation *trans;
  921. ListSearch sh;
  922. trans = FirstTranslation ( sh );
  923. while ( trans )
  924. {
  925. trans->ClearProcessed();
  926. trans = NextTranslation ( sh );
  927. }
  928. NotProcessed();
  929. }
  930. void NoxText::ClearMatched ( void )
  931. {
  932. Translation *trans;
  933. ListSearch sh;
  934. trans = FirstTranslation ( sh );
  935. while ( trans )
  936. {
  937. trans->ClearMatched();
  938. trans = NextTranslation ( sh );
  939. }
  940. NotMatched();
  941. }
  942. void NoxText::AssignID ( void )
  943. {
  944. if ( id != -1 )
  945. {
  946. return; // already assigned
  947. }
  948. if ( db )
  949. {
  950. SetID ( db->NewID ());
  951. }
  952. }
  953. void NoxText::Set ( OLECHAR *string )
  954. {
  955. if ( db )
  956. {
  957. db->RemoveText ( this );
  958. }
  959. text->Set ( string );
  960. InvalidateWave ( );
  961. if ( db )
  962. {
  963. db->AddText ( this );
  964. }
  965. Changed ();
  966. }
  967. void NoxText::Set ( char *string )
  968. {
  969. if ( db )
  970. {
  971. db->RemoveText ( this );
  972. }
  973. text->Set ( string );
  974. InvalidateWave ();
  975. if ( db )
  976. {
  977. db->AddText ( this );
  978. }
  979. Changed ();
  980. }
  981. void NoxText::InvalidateAllWaves ( void )
  982. {
  983. Translation *trans;
  984. ListSearch sh;
  985. WaveInfo.SetValid ( FALSE );
  986. trans = FirstTranslation ( sh );
  987. while ( trans )
  988. {
  989. trans->WaveInfo.SetValid ( FALSE );
  990. trans = NextTranslation ( sh );
  991. }
  992. }
  993. void NoxText::InvalidateWave ( void )
  994. {
  995. WaveInfo.SetValid ( FALSE );
  996. }
  997. void NoxText::InvalidateWave ( LangID langid )
  998. {
  999. WaveInfo.SetValid ( FALSE );
  1000. if ( langid == LANGID_US )
  1001. {
  1002. InvalidateWave ();
  1003. }
  1004. else
  1005. {
  1006. Translation *trans = GetTranslation ( langid );
  1007. if ( trans )
  1008. {
  1009. trans->WaveInfo.SetValid ( FALSE );
  1010. }
  1011. }
  1012. }
  1013. void NoxText::AddToTree ( CTreeCtrl *tc, HTREEITEM parent, int changes )
  1014. {
  1015. HTREEITEM item;
  1016. ListSearch sh;
  1017. Translation *trans;
  1018. sprintf ( buffer, "TEXT %c : %s", ChangedSymbol() ,GetSB ());
  1019. item = tc->InsertItem ( buffer, parent );
  1020. trans = FirstTranslation ( sh );
  1021. while ( trans )
  1022. {
  1023. if ( !changes || trans->IsChanged ())
  1024. {
  1025. trans->AddToTree ( tc, item );
  1026. }
  1027. trans = NextTranslation ( sh );
  1028. }
  1029. if ( ID() != -1 )
  1030. {
  1031. sprintf ( buffer, "ID : %d", ID ());
  1032. tc->InsertItem ( buffer, item );
  1033. }
  1034. if ( strcmp ( WaveSB(), "" ) )
  1035. {
  1036. sprintf ( buffer, "WAVE : %s", WaveSB() );
  1037. tc->InsertItem ( buffer, item );
  1038. }
  1039. if ( line_number != -1 )
  1040. {
  1041. sprintf ( buffer, "LINE : %d", line_number );
  1042. tc->InsertItem ( buffer, item );
  1043. }
  1044. sprintf ( buffer, "REV : %d", revision );
  1045. tc->InsertItem ( buffer, item );
  1046. sprintf ( buffer, "LEN : %d", this->Len() );
  1047. tc->InsertItem ( buffer, item );
  1048. }
  1049. Translation::Translation ( void )
  1050. {
  1051. text = new OLEString ( );
  1052. comment = new OLEString ( );
  1053. revision = 0;
  1054. sent = FALSE;
  1055. }
  1056. Translation::~Translation ( )
  1057. {
  1058. delete text;
  1059. delete comment;
  1060. }
  1061. int Translation::IsSent ( void )
  1062. {
  1063. return sent;
  1064. }
  1065. void Translation::Sent ( int val )
  1066. {
  1067. sent = val;
  1068. }
  1069. void Translation::SetDB ( TransDB *new_db )
  1070. {
  1071. db = new_db;
  1072. }
  1073. Translation* Translation::Clone ( void )
  1074. {
  1075. Translation *clone = new Translation();
  1076. clone->Set ( Get ());
  1077. clone->SetComment ( Comment ());
  1078. clone->SetLangID ( GetLangID ());
  1079. clone->SetRevision ( Revision ());
  1080. return clone;
  1081. }
  1082. void Translation::AddToTree ( CTreeCtrl *tc, HTREEITEM parent, int changes )
  1083. {
  1084. HTREEITEM item;
  1085. sprintf ( buffer, "%s%c : %s", Language(), ChangedSymbol(), GetSB ());
  1086. item = tc->InsertItem ( buffer, parent );
  1087. if ( strcmp ( CommentSB(), "" ) )
  1088. {
  1089. sprintf ( buffer, "COMMENT: %s", CommentSB() );
  1090. tc->InsertItem ( buffer, item );
  1091. }
  1092. sprintf ( buffer, "REV : %d", revision );
  1093. tc->InsertItem ( buffer, item );
  1094. sprintf ( buffer, "LEN : %d", Len() );
  1095. tc->InsertItem ( buffer, item );
  1096. }
  1097. int Translation::TooLong ( int maxlen )
  1098. {
  1099. return maxlen != 0 && text->Len () > maxlen;
  1100. }
  1101. int Translation::ValidateFormat ( NoxText *ntext )
  1102. {
  1103. return SameFormat ( text->Get(), ntext->Get ());
  1104. }
  1105. int TransDB::Warnings ( CNoxstringDlg *dlg )
  1106. {
  1107. NoxLabel *label;
  1108. ListSearch sh_label;
  1109. int count = 0;
  1110. int warnings = 0;
  1111. List dups;
  1112. if ( dlg )
  1113. {
  1114. dlg->InitProgress ( NumLabels ());
  1115. dlg->Log ("");
  1116. dlg->Log ("Generals.str Warnigs:");
  1117. dlg->Status ( "Creating warnings report...", FALSE );
  1118. }
  1119. text_bin->Clear();
  1120. label = FirstLabel ( sh_label );
  1121. while ( label )
  1122. {
  1123. NoxText *text;
  1124. NoxText *existing_text;
  1125. ListSearch sh_text;
  1126. text = label->FirstText ( sh_text );
  1127. while ( text )
  1128. {
  1129. if ( text->Len ( ) == 0 )
  1130. {
  1131. if ( dlg )
  1132. {
  1133. sprintf ( buffer, "Warning:: text at line %5d is NULL",
  1134. text->LineNumber());
  1135. dlg->Log ( buffer );
  1136. }
  1137. warnings++;
  1138. }
  1139. else if ( !DuplicatesAllowed() && ( existing_text = FindText ( text->Get () )))
  1140. {
  1141. warnings++;
  1142. if ( dlg )
  1143. {
  1144. DupNode *dup = new DupNode ( text, existing_text );
  1145. dups.Add ( dup );
  1146. }
  1147. }
  1148. else
  1149. {
  1150. text_bin->Add ( text, text->Get() );
  1151. }
  1152. text = label->NextText ( sh_text );
  1153. }
  1154. count++;
  1155. if ( dlg )
  1156. {
  1157. dlg->SetProgress ( count );
  1158. }
  1159. label = NextLabel ( sh_label );
  1160. }
  1161. if ( dlg )
  1162. {
  1163. DupNode *dup;
  1164. while ( (dup = (DupNode*)dups.LastNode ()))
  1165. {
  1166. sprintf ( buffer, "Warning:: text at line %5d is a duplicate of text on line %5d",
  1167. dup->Duplicate()->LineNumber(), dup->Original()->LineNumber());
  1168. dlg->Log ( buffer );
  1169. dup->Remove ();
  1170. delete dup;
  1171. }
  1172. sprintf ( buffer, "Total warnings: %d", warnings );
  1173. dlg->Log ( buffer );
  1174. dlg->Ready();
  1175. }
  1176. return warnings;
  1177. }
  1178. int TransDB::Errors ( CNoxstringDlg *dlg )
  1179. {
  1180. NoxLabel *label;
  1181. NoxLabel *existing_label;
  1182. ListSearch sh_label;
  1183. Bin *tbin = new Bin ();
  1184. int count = 0;
  1185. int errors = 0;
  1186. if ( dlg )
  1187. {
  1188. dlg->InitProgress ( NumLabels ());
  1189. dlg->Log ("");
  1190. dlg->Log ("Generals.str Errors:");
  1191. dlg->Status ( "Creating error report...", FALSE );
  1192. }
  1193. label_bin->Clear();
  1194. label = FirstLabel ( sh_label );
  1195. while ( label )
  1196. {
  1197. NoxText *text;
  1198. NoxText *existing_text;
  1199. ListSearch sh_text;
  1200. if ( !MultiTextAllowed () && label->NumStrings () > 1 )
  1201. {
  1202. errors++;
  1203. if ( dlg )
  1204. {
  1205. sprintf ( buffer, "Error : Label \"%s\" at line %d is has more than 1 string defined",
  1206. label->NameSB(), label->LineNumber());
  1207. dlg->Log ( buffer );
  1208. }
  1209. }
  1210. if ( ( existing_label = FindLabel ( label->Name () )))
  1211. {
  1212. errors++;
  1213. if ( dlg )
  1214. {
  1215. sprintf ( buffer, "Error : Label \"%s\" at line %d is already defined on line %d",
  1216. label->NameSB(), label->LineNumber(), existing_label->LineNumber());
  1217. dlg->Log ( buffer );
  1218. }
  1219. }
  1220. label_bin->Add ( label, label->Name());
  1221. tbin->Clear ();
  1222. text = label->FirstText ( sh_text );
  1223. while ( text )
  1224. {
  1225. if ( ( existing_text = (NoxText *) tbin->Get ( text->Get () )))
  1226. {
  1227. errors++;
  1228. if ( dlg )
  1229. {
  1230. sprintf ( buffer, "Error : Label \"%s\" has duplicate text at line %d",
  1231. label->NameSB(), text->LineNumber());
  1232. dlg->Log ( buffer );
  1233. }
  1234. }
  1235. tbin->Add ( text, text->Get() );
  1236. // check string length against max len
  1237. if ( label->MaxLen () )
  1238. {
  1239. if ( text->Len () > label->MaxLen ())
  1240. {
  1241. errors++;
  1242. if ( dlg )
  1243. {
  1244. sprintf ( buffer, "Error : The US text at line %d (for label \"%s\") exceeds the max length",
  1245. text->LineNumber(), label->NameSB());
  1246. dlg->Log ( buffer );
  1247. }
  1248. }
  1249. }
  1250. text = label->NextText ( sh_text );
  1251. }
  1252. count++;
  1253. if ( dlg )
  1254. {
  1255. dlg->SetProgress ( count );
  1256. }
  1257. label = NextLabel ( sh_label );
  1258. }
  1259. if ( dlg )
  1260. {
  1261. sprintf ( buffer, "Total errors: %d", errors );
  1262. dlg->Log ( buffer );
  1263. dlg->Ready();
  1264. }
  1265. delete tbin;
  1266. last_error_count = errors;
  1267. checked_for_errors = TRUE;
  1268. return errors;
  1269. }
  1270. CWaveInfo::CWaveInfo ( void )
  1271. {
  1272. wave_valid = FALSE;
  1273. missing = TRUE;
  1274. }
  1275. void TransDB::VerifyDialog( LangID langid, void (*cb) (void) )
  1276. {
  1277. NoxLabel *label;
  1278. ListSearch sh_label;
  1279. int count = 0;
  1280. LANGINFO *linfo = GetLangInfo ( langid );
  1281. label = FirstLabel ( sh_label );
  1282. while ( label )
  1283. {
  1284. NoxText *text;
  1285. ListSearch sh_text;
  1286. text = label->FirstText ( sh_text );
  1287. while ( text )
  1288. {
  1289. if ( text->IsDialog ())
  1290. {
  1291. if ( text->DialogIsPresent ( DialogPath, langid ))
  1292. {
  1293. text->DialogIsValid ( DialogPath, langid );
  1294. }
  1295. }
  1296. text = label->NextText ( sh_text );
  1297. }
  1298. if ( cb )
  1299. {
  1300. cb();
  1301. }
  1302. label = NextLabel ( sh_label );
  1303. }
  1304. }
  1305. void TransDB::InvalidateDialog( LangID langid )
  1306. {
  1307. NoxLabel *label;
  1308. ListSearch sh_label;
  1309. label = FirstLabel ( sh_label );
  1310. while ( label )
  1311. {
  1312. NoxText *text;
  1313. ListSearch sh_text;
  1314. text = label->FirstText ( sh_text );
  1315. while ( text )
  1316. {
  1317. if ( text->IsDialog ())
  1318. {
  1319. text->InvalidateWave ( langid );
  1320. }
  1321. text = label->NextText ( sh_text );
  1322. }
  1323. label = NextLabel ( sh_label );
  1324. }
  1325. }
  1326. int TransDB::ReportDialog( DLGREPORT *report, LangID langid, void (*print) ( const char *), PMASK pmask )
  1327. {
  1328. NoxLabel *label;
  1329. ListSearch sh_label;
  1330. int count = 0;
  1331. DLGREPORT _info;
  1332. DLGREPORT *info = &_info;
  1333. int skip_verify = FALSE;
  1334. LANGINFO *linfo = GetLangInfo ( langid );
  1335. if ( report )
  1336. {
  1337. info = report;
  1338. }
  1339. memset ( info, 0, sizeof ( DLGREPORT ));
  1340. label = FirstLabel ( sh_label );
  1341. while ( label )
  1342. {
  1343. NoxText *text;
  1344. ListSearch sh_text;
  1345. text = label->FirstText ( sh_text );
  1346. while ( text )
  1347. {
  1348. if ( text->IsDialog ())
  1349. {
  1350. if ( text->DialogIsPresent ( DialogPath, langid))
  1351. {
  1352. if ( !text->DialogIsValid ( DialogPath, langid, FALSE ) )
  1353. {
  1354. if ( print && pmask & PMASK_UNRESOLVED )
  1355. {
  1356. sprintf ( buffer, "%d: audio file \"%s%s.wav\" not verified", text->ID(), text->WaveSB (), linfo->character);
  1357. print ( buffer );
  1358. }
  1359. info->unresolved++;
  1360. }
  1361. else
  1362. {
  1363. info->resolved++;
  1364. }
  1365. }
  1366. else
  1367. {
  1368. if ( print && pmask & PMASK_MISSING )
  1369. {
  1370. sprintf ( buffer, "%d: audio file \"%s%s.wav\" missing", text->ID(), text->WaveSB (), linfo->character);
  1371. print ( buffer );
  1372. }
  1373. info->missing++;
  1374. }
  1375. info->numdialog++;
  1376. }
  1377. text = label->NextText ( sh_text );
  1378. }
  1379. label = NextLabel ( sh_label );
  1380. }
  1381. return info->missing + info->unresolved + info->errors ;
  1382. }
  1383. int TransDB::ReportTranslations( TRNREPORT *report, LangID langid, void (*print) ( const char *buffer), PMASK pmask )
  1384. {
  1385. NoxLabel *label;
  1386. ListSearch sh_label;
  1387. int count = 0;
  1388. int first_error = FALSE;
  1389. TRNREPORT _info;
  1390. TRNREPORT *info = &_info;
  1391. if ( report )
  1392. {
  1393. info = report;
  1394. }
  1395. memset ( info, 0, sizeof ( TRNREPORT ));
  1396. label = FirstLabel ( sh_label );
  1397. while ( label )
  1398. {
  1399. NoxText *text;
  1400. ListSearch sh_text;
  1401. int maxlen = label->MaxLen ();
  1402. text = label->FirstText ( sh_text );
  1403. while ( text )
  1404. {
  1405. int textnum = 0;
  1406. Translation *trans;
  1407. int too_big = FALSE;
  1408. if ( text->Len ())
  1409. {
  1410. info->numstrings++;
  1411. if ( langid != LANGID_US )
  1412. {
  1413. if ( (trans = text->GetTranslation ( langid ) ))
  1414. {
  1415. if ( maxlen && trans->Len() > maxlen )
  1416. {
  1417. if ( print && pmask & PMASK_TOOLONG )
  1418. {
  1419. sprintf ( buffer, "%d: translation is too long by %d characters", text->ID (), trans->Len() - maxlen);
  1420. print ( buffer );
  1421. }
  1422. too_big = TRUE;
  1423. }
  1424. if ( text->Revision () > trans->Revision ())
  1425. {
  1426. if ( print && pmask & PMASK_RETRANSLATE )
  1427. {
  1428. sprintf ( buffer, "%d: needs re-translation", text->ID () );
  1429. print ( buffer );
  1430. }
  1431. info->retranslate++;
  1432. }
  1433. else
  1434. {
  1435. info->translated++;
  1436. if ( !trans->ValidateFormat ( text ) )
  1437. {
  1438. if ( print && pmask & PMASK_BADFORMAT )
  1439. {
  1440. sprintf ( buffer, "%d: translation has differring formating to original", text->ID () );
  1441. print ( buffer );
  1442. }
  1443. info->bad_format++;
  1444. }
  1445. }
  1446. }
  1447. else
  1448. {
  1449. if ( print && pmask & PMASK_MISSING )
  1450. {
  1451. sprintf ( buffer, "%d: not translated", text->ID ());
  1452. print ( buffer );
  1453. }
  1454. info->missing++;
  1455. }
  1456. }
  1457. else
  1458. {
  1459. // check maxlen
  1460. if ( maxlen )
  1461. {
  1462. if ( text->Len() > maxlen )
  1463. {
  1464. if ( print && pmask & PMASK_TOOLONG )
  1465. {
  1466. sprintf ( buffer, "%d: is too long by %d characters", text->ID (), text->Len() - maxlen);
  1467. print ( buffer );
  1468. }
  1469. too_big = TRUE;
  1470. }
  1471. }
  1472. }
  1473. }
  1474. if ( too_big )
  1475. {
  1476. info->too_big++;
  1477. }
  1478. text = label->NextText ( sh_text );
  1479. }
  1480. info->numlabels++;
  1481. label = NextLabel ( sh_label );
  1482. }
  1483. info->errors = info->too_big + info->bad_format;
  1484. return info->missing + info->too_big + info->retranslate + info->bad_format;
  1485. }