1 /* |
1 /* |
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
206 } |
208 } |
207 |
209 |
208 |
210 |
209 void OutputHelp() |
211 void OutputHelp() |
210 { |
212 { |
211 cerr << "Resource compiler version " << version << " (Build " << build << ") (C) 1997-2009 Nokia Corporation." << endl; |
213 cerr << "Resource compiler version " << version << " (Build " << build << ") (C) 1997-2010 Nokia Corporation." << endl; |
212 cerr << "Usage: rcomp [-vpul] [-force] [-oRSCFile] [-{uid2,uid3}] [-hHeaderFile] [-sSourceFile] [-iBaseInputFileName]" << endl; |
214 cerr << "Usage: rcomp [-vpul] [-force] [-oRSCFile] [-{uid2,uid3}] [-hHeaderFile] [-sSourceFile] [-iBaseInputFileName]" << endl; |
213 cerr << "\tv" << "\tverbose" << endl; |
215 cerr << "\tv" << "\tverbose" << endl; |
214 cerr << "\tp" << "\tParser debugging" << endl; |
216 cerr << "\tp" << "\tParser debugging" << endl; |
215 cerr << "\tl" << "\tCheck localisation comments" << endl; |
217 cerr << "\tl" << "\tCheck localisation comments" << endl; |
216 cerr << "\tforce" << "\tEmit localisation warnings even if no localisation tags are present" << endl; |
218 cerr << "\tforce" << "\tEmit localisation warnings even if no localisation tags are present" << endl; |
357 } |
359 } |
358 } |
360 } |
359 } |
361 } |
360 if(SourceFileName.Length() == 0) |
362 if(SourceFileName.Length() == 0) |
361 { |
363 { |
362 pSourceFile = stdin; |
364 pSourceFile = NULL ; //stdin; |
363 } |
365 } |
364 else |
366 else |
365 { |
367 { |
366 if((pSourceFile = fopen(SourceFileName.GetAssertedNonEmptyBuffer(), "r") ) == NULL) |
368 if((pSourceFile = fopen(SourceFileName.GetAssertedNonEmptyBuffer(), "r") ) == NULL) |
367 { |
369 { |
368 cerr << "Failed to open " << SourceFileName << endl; |
370 cerr << "Failed to open " << SourceFileName << endl; |
369 exit(-2); |
371 exit(-2); |
370 } |
372 } |
371 } |
373 //Searchig for BOM signature which if found will be ignored |
372 //Searchig for BOM signature which if found will be ignored |
374 unsigned char buffer[3]; |
373 |
375 fread( buffer, sizeof( char ), 3, pSourceFile); |
374 unsigned char buffer[3]; |
376 if((buffer[0]!=239) && (buffer[1]!=187) && (buffer[2]!=191)) |
375 fread( buffer, sizeof( char ), 3, pSourceFile); |
377 { |
376 |
378 // BOM not found. Set the file-position indicator to 0 |
377 if((buffer[0]!=239) && (buffer[1]!=187) && (buffer[2]!=191)) |
379 filePositionIndicator = fpos_t(); |
378 { |
380 if(fsetpos(pSourceFile, &filePositionIndicator) !=0) |
379 // BOM not found. Set the file-position indicator to 0 |
381 { |
380 filePositionIndicator = fpos_t(); |
382 perror("fsetpos error"); |
381 if(fsetpos(pSourceFile, &filePositionIndicator) !=0) |
383 exit(-2); |
382 { |
|
383 perror("fsetpos error"); |
|
384 } |
384 } |
385 } |
385 } |
|
386 } |
|
387 |
386 verbose = vParam; |
388 verbose = vParam; |
387 |
|
388 pG = new GlobalData; |
389 pG = new GlobalData; |
389 if (pG==NULL) |
390 if (pG==NULL) |
390 exit(-4); |
391 exit(-4); |
|
392 |
|
393 if(NULL == pSourceFile){ // Cache the standard input |
|
394 pG->StdInBufLength = 0; |
|
395 unsigned long allocSize = 0x100000 ; // 1M bytes |
|
396 pG->StdInfBufPos = 0 ; |
|
397 pG->StdInBuffer = (char*)malloc(allocSize); |
|
398 if(NULL == pG->StdInBuffer){ |
|
399 delete pG ; |
|
400 exit(-4); |
|
401 } |
|
402 int result = 1; |
|
403 char* buffer = pG->StdInBuffer; |
|
404 FILE *file = stdin ; |
|
405 const int KIOBytes = 0x20000 ; |
|
406 while(1) { |
|
407 result = fread(buffer, 1, KIOBytes, file); |
|
408 if(result == 0){ |
|
409 *buffer = 0; |
|
410 break ; |
|
411 } |
|
412 buffer += result ; |
|
413 pG->StdInBufLength += result ; |
|
414 if((pG->StdInBufLength + KIOBytes) > allocSize) { |
|
415 allocSize += KIOBytes ; |
|
416 pG->StdInBuffer = (char*)realloc(pG->StdInBuffer,allocSize); |
|
417 if(NULL == pG->StdInBuffer){ |
|
418 delete pG ; |
|
419 exit(-4); |
|
420 } |
|
421 buffer = pG->StdInBuffer + pG->StdInBufLength; |
|
422 } |
|
423 |
|
424 } |
|
425 const unsigned char BOM[] = {0xef , 0xbb, 0xbf, 0x0 }; |
|
426 if(0 == memcmp(pG->StdInBuffer,BOM,3)) |
|
427 pG->StdInfBufPos = 3 ; |
|
428 } |
|
429 else { |
|
430 pG->StdInBuffer = 0 ; |
|
431 pG->StdInBufLength = 0; |
|
432 } |
391 |
433 |
392 Tokenize(MessageSuppressionList); |
434 Tokenize(MessageSuppressionList); |
393 |
435 |
394 pGL = new GlobalLocalisationData; |
436 pGL = new GlobalLocalisationData; |
395 if(pG==NULL) |
437 if(pG==NULL) |
401 #ifdef __TOOLS2__ |
443 #ifdef __TOOLS2__ |
402 pG->FileLineHandler.SetBase(SourceFileName,0); |
444 pG->FileLineHandler.SetBase(SourceFileName,0); |
403 #endif |
445 #endif |
404 |
446 |
405 int ret=ParseSourceFile(pSourceFile, pParam); |
447 int ret=ParseSourceFile(pSourceFile, pParam); |
406 fclose(pSourceFile); |
448 if(pSourceFile != NULL) |
|
449 fclose(pSourceFile); |
|
450 if(pG->StdInBuffer != NULL) |
|
451 free(pG->StdInBuffer); |
407 |
452 |
408 pGL->StoreFinalComment(); // final comment not stored during running of lex and yacc |
453 pGL->StoreFinalComment(); // final comment not stored during running of lex and yacc |
409 if(lParam && (pGL->LocalisationCommentsExist() || lForce)) |
454 if(lParam && (pGL->LocalisationCommentsExist() || lForce)) |
410 { |
455 { |
411 pGL->AnalyseLocalisationData(); |
456 pGL->AnalyseLocalisationData(); |
437 |
482 |
438 std::string totalpath(s.substr( 0, s.rfind("/")+1 )); |
483 std::string totalpath(s.substr( 0, s.rfind("/")+1 )); |
439 const char* uidTool = "uidcrc"; |
484 const char* uidTool = "uidcrc"; |
440 |
485 |
441 #else |
486 #else |
|
487 |
442 std::string totalpath(s.substr( 0, s.rfind("\\")+1 )); |
488 std::string totalpath(s.substr( 0, s.rfind("\\")+1 )); |
443 const char* uidTool = "uidcrc.exe"; |
489 const char* uidTool = "uidcrc.exe"; |
444 |
490 |
|
491 // in case unix style of seperator is used in windows. |
|
492 if(!totalpath.length()){ |
|
493 totalpath = s.substr( 0, s.rfind("/")+1 ); |
|
494 } |
|
495 |
445 #endif |
496 #endif |
446 |
497 |
447 // Calls the uidcrc tool with the full path to where RCOMP resides in |
|
448 std::string uidpath(uidTool); |
498 std::string uidpath(uidTool); |
449 totalpath += uidpath; |
499 |
|
500 // try to call the uidcrc tool with the full path to where RCOMP resides in |
|
501 // if does not exists, search uidcrc in PATH |
|
502 if(totalpath.length()){ |
|
503 |
|
504 std::string trypath(totalpath); |
|
505 trypath += uidpath; |
|
506 |
|
507 std::fstream _file; |
|
508 _file.open(trypath.c_str(), std::ios::in); |
|
509 if(!_file){ |
|
510 // try to search from PATH |
|
511 totalpath = uidpath; |
|
512 } |
|
513 else{ |
|
514 _file.close(); |
|
515 // invoke from the path RCOMP resides in |
|
516 totalpath += uidpath; |
|
517 } |
|
518 } |
|
519 else{ |
|
520 // search from PATH |
|
521 totalpath = uidpath; |
|
522 } |
450 |
523 |
451 // Find and replace all occurences of \ with / |
524 // Find and replace all occurences of \ with / |
452 std::string searchString( "\\" ); |
525 std::string searchString( "\\" ); |
453 std::string replaceString( "/" ); |
526 std::string replaceString( "/" ); |
454 std::string::size_type pos = 0; |
527 std::string::size_type pos = 0; |
501 if (verbose) |
574 if (verbose) |
502 { |
575 { |
503 MOFF; cout << uidcrcTool << " " << uidcrcUIDs[0] << " " << uidcrcUIDs[1] << " " << uidcrcUIDs[2] << " " << DataOutputFileName.GetAssertedNonEmptyBuffer(); cout << endl; MON; |
576 MOFF; cout << uidcrcTool << " " << uidcrcUIDs[0] << " " << uidcrcUIDs[1] << " " << uidcrcUIDs[2] << " " << DataOutputFileName.GetAssertedNonEmptyBuffer(); cout << endl; MON; |
504 } |
577 } |
505 |
578 |
506 #ifndef __LINUX__ |
579 char uidcrc_params[512]; |
507 const int error = _spawnlp (_P_WAIT, |
|
508 uidcrcTool, |
|
509 uidcrcTool, |
|
510 uidcrcUIDs[0], |
|
511 uidcrcUIDs[1], |
|
512 uidcrcUIDs[2], |
|
513 DataOutputFileName.GetAssertedNonEmptyBuffer(), |
|
514 NULL); |
|
515 #else |
|
516 char uidcrc_params[256]; |
|
517 const int ret = snprintf(uidcrc_params, |
580 const int ret = snprintf(uidcrc_params, |
518 sizeof(uidcrc_params), |
581 sizeof(uidcrc_params), |
519 "%s %s %s %s %s", |
582 "%s %s %s %s %s", |
520 uidcrcTool, |
583 uidcrcTool, |
521 uidcrcUIDs[0], |
584 uidcrcUIDs[0], |