1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
|
/* GNU Robbo
* Copyright (C) 2002-2010 The GNU Robbo Team (see AUTHORS).
*
* GNU Robbo is free software - you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Robbo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the impled warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU CC; see the file COPYING. If not, write to the
* Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "game.h"
/* Defines */
/*
#define DEBUG_LOAD_SELECTED_LOCALE
#define DEBUG_READ_LOCALERC_FILE
#define DEBUG_SET_LOCALE_TO_LANG
*/
#define LOCALES_DIR "locales"
#define LOCALERC_FILE "localerc"
#define LOCALE_TEXT_FILE "text"
/* Variables */
extern char *data_state[];
/* Function prototypes */
/***************************************************************************
* Find All Locales *
***************************************************************************/
/* Searches PACKAGE_DATA_DIR LOCALES_DIR for locale folders.
On exit: returns 1 on error */
int
find_all_locales (void)
{
FILE *fp;
char filename[256];
DIR *dir;
struct dirent *currentdirent;
int default_locale_found = FALSE;
/* Open the locales directory */
if ((dir = opendir (PACKAGE_DATA_DIR "/" LOCALES_DIR)) == NULL)
{
fprintf (stdout, "Couldn't open locales folder: %s\n",
PACKAGE_DATA_DIR "/" LOCALES_DIR);
return 1;
}
/* Now search the directory for locale folders */
while ((currentdirent = readdir (dir)) != NULL)
{
if ((strcmp (currentdirent->d_name, "."))
&& (strcmp (currentdirent->d_name, "..")))
{
if (locale_count < MAX_LOCALES)
{
/* Attempt to open currentdirent->d_name/localerc to verify it's a valid locale folder */
strcpy (filename, PACKAGE_DATA_DIR "/" LOCALES_DIR "/");
strcat (filename, currentdirent->d_name);
strcat (filename, "/");
strcat (filename, LOCALERC_FILE);
if ((fp = fopen (filename, "r")) != NULL)
{
if (!strcmp (currentdirent->d_name, DEFAULT_LOCALE))
{
default_locale_found = TRUE;
}
else
{
strncpy (locales[locale_count].foldername,
currentdirent->d_name, 100);
locales[locale_count].foldername[99] = 0; /* Just in case we read all chars */
locale_count++;
}
fclose (fp);
}
}
}
}
closedir (dir);
if (!default_locale_found)
{
fprintf (stdout, "Cannot find the default locale: %s\n",
PACKAGE_DATA_DIR "/" LOCALES_DIR "/" DEFAULT_LOCALE);
return 1;
}
else
{
return 0;
}
}
/***************************************************************************
* Sort Locales *
***************************************************************************/
/* Sorts found locales alphanumerically by name remembering to preserve the selected locale :)
This must be done last after find_all_locales(), read_localerc_files() and read_resource_file() */
void
sort_locales (void)
{
struct locale swap_locale;
int swapped, count;
/* Bubble sort */
do
{
swapped = FALSE;
for (count = 0; count < locale_count - 1; count++)
{
if (strcmp (locales[count].name, locales[count + 1].name) > 0)
{
swapped = TRUE;
swap_locale = locales[count + 1];
locales[count + 1] = locales[count];
locales[count] = swap_locale;
/* Preserve selected locale */
if (selected_locale == count + 1)
{
selected_locale = count;
}
else if (selected_locale == count)
{
selected_locale = count + 1;
}
}
}
}
while (swapped);
}
/***************************************************************************
* Read localerc Files *
***************************************************************************/
/* Reads all localerc files and populates the locale list. At the time this is
called, we already know that the default locale has been found so nothing
here is fatal. Anything not found will be set to SINGLE_SPACE */
void
read_localerc_files (void)
{
FILE *fp;
char filename[256], line[1024]; /* 1024 because if fgets returns a partial line then line_count will be incremented again */
int count, count2, line_count = 0;
int name_read = DATA_UNREAD;
int author_read = DATA_UNREAD;
#ifdef DEBUG_READ_LOCALERC_FILE
printf ("*** Start %s ***\n", __func__);
#endif
for (count = 0; count < locale_count; count++)
{
/* Reset these because we'll be using them more than once */
line_count = 0;
name_read = DATA_UNREAD;
author_read = DATA_UNREAD;
/* Initialise everything to some defaults */
strcpy (locales[count].name, SINGLE_SPACE);
strcpy (locales[count].author, SINGLE_SPACE);
/* Attempt to open the localerc file */
strcpy (filename, PACKAGE_DATA_DIR "/" LOCALES_DIR "/");
strcat (filename, locales[count].foldername);
strcat (filename, "/");
strcat (filename, LOCALERC_FILE);
if ((fp = fopen (filename, "r")) == NULL)
{
fprintf (stdout, "Cannot read from file %s\n", filename);
}
else
{
/* Read lines including the [CR]LFs until we have what we need or reach the end of file (line == NULL).
We are looking for all of these things :-
[name]
[author] */
while ((fgets (line, 1024, fp)) != NULL)
{
line_count++;
/* fgets will get [CR]LFs too so they should be removed */
for (count2 = strlen (line) - 1; count2 >= 0; count2--)
if (line[count2] == 13 || line[count2] == 10)
line[count2] = 0;
/* Use the tags as switches so we know what to read */
/* NOTE: Reading consecutive (dataless) tags means that the previous tag may still be marked as DATA_READING */
if ((!strncmp (line, "[name]", 6)) ||
(!strncmp (line, "[author]", 8)))
{
/* If a tag is being read and we read another tag then mark it as something else */
if (name_read == DATA_READING)
{
name_read = DATA_INCOMPLETE;
}
else if (author_read == DATA_READING)
{
author_read = DATA_INCOMPLETE;
}
/* If the found tag is DATA_UNREAD then mark it for DATA_READING */
if (!strncmp (line, "[name]", 6))
{
if (name_read == DATA_UNREAD)
name_read = DATA_READING;
}
else if (!strncmp (line, "[author]", 8))
{
if (author_read == DATA_UNREAD)
author_read = DATA_READING;
}
}
else
{
/* It's not a tag but data (or newline) so we need to find what to do with it */
if (name_read == DATA_READING)
{
if (strlen (line) != 0)
{
strncpy (locales[count].name, line, 60); /* Prevent overruns */
locales[count].name[59] = 0; /* Just in case we read all chars */
}
name_read = DATA_READ;
#ifdef DEBUG_READ_LOCALERC_FILE
printf ("%i: name=%s\n", line_count, line);
#endif
}
else if (author_read == DATA_READING)
{
if (strlen (line) != 0)
{
strncpy (locales[count].author, line, 60); /* Prevent overruns */
locales[count].author[59] = 0; /* Just in case we read all chars */
}
author_read = DATA_READ;
#ifdef DEBUG_READ_LOCALERC_FILE
printf ("%i: author=%s\n", line_count, line);
#endif
}
}
}
/* Dump info to the console */
fprintf (stdout, "Locale found: %s\n", locales[count].foldername);
fclose (fp);
#ifdef DEBUG_READ_LOCALERC_FILE
printf ("name_read=%s\n", data_state[name_read]);
printf ("author_read=%s\n\n", data_state[author_read]);
#endif
}
}
#ifdef DEBUG_READ_LOCALERC_FILE
printf ("*** Stop %s ***\n", __func__);
#endif
}
/***************************************************************************
* Load Selected Locale *
***************************************************************************/
/* Loads all text data from the selected locale folder.
* Now fixes all strings to the size TXT_MAX_COLS to make the code easier to
* read and to make initialisation of the config_items less prone to errors.
* We're only dealing with 6KB of memory so even if half of it's empty it
* won't matter :)
*
* This function :-
* * Won't write further than the bounds of the array (strings will be
* * chopped off)
* * Can place one or more strings into a char array
* * Will at least place a space into each destination so not to cause seg
* faults with SDL_ttf
* * Records what was unread, read and partially read (incomplete) if you
* require this information */
void load_selected_locale (void)
{
FILE *fp;
/* line[1024] because if fgets returns a partial line then line_count
* will be incremented again */
char filename[256], line[1024];
int count, count2, line_count = 0, tag_found, tag_index, row = 0;
#define CONFIG_ITEM_COUNT (6+7+59+6+2+5+5+41+49)
struct config_item
{
char name[60];
int state;
/* Points to an array of chars which could hold more than one string */
char *destination;
/* 1 or more rows within this array of chars of fixed length TXT_MAX_COLS */
int max_rows;
};
struct config_item config_items[CONFIG_ITEM_COUNT];
/* Initialise the state and most common max_rows to reduce the
* initialisation code below */
for (count = 0; count < CONFIG_ITEM_COUNT; count++)
{
config_items[count].state = DATA_UNREAD;
config_items[count].max_rows = 1;
}
/* Initialise config_item struct with search and destination data */
row = -1;
strcpy (config_items[++row].name, "[txt_intro_story]");
config_items[row].destination = txt_intro_story;
config_items[row].max_rows = TXT_INTRO_STORY_ROWS;
#if defined(PLATFORM_WIN32) || defined(PLATFORM_PC)
strcpy (config_items[++row].name, "[txt_intro_keys_PLATFORM_PC]");
config_items[row].destination = txt_intro_keys;
config_items[row].max_rows = TXT_INTRO_KEYS_ROWS;
#elif defined(PLATFORM_GP2X)
strcpy (config_items[++row].name, "[txt_intro_keys_PLATFORM_GP2X]");
config_items[row].destination = txt_intro_keys;
config_items[row].max_rows = TXT_INTRO_KEYS_ROWS;
#elif defined(PLATFORM_ZAURUS)
strcpy (config_items[++row].name, "[txt_intro_keys_PLATFORM_ZAURUS]");
config_items[row].destination = txt_intro_keys;
config_items[row].max_rows = TXT_INTRO_KEYS_ROWS;
#elif defined(PLATFORM_FREMANTLE)
strcpy (config_items[++row].name, "[txt_intro_keys_PLATFORM_FREMANTLE]");
config_items[row].destination = txt_intro_keys;
config_items[row].max_rows = TXT_INTRO_KEYS_ROWS;
#elif defined(PLATFORM_PSP)
strcpy (config_items[++row].name, "[txt_intro_keys_PLATFORM_PSP]");
config_items[row].destination = txt_intro_keys;
config_items[row].max_rows = TXT_INTRO_KEYS_ROWS;
#endif
strcpy (config_items[++row].name, "[txt_intro_keys_description]");
config_items[row].destination = txt_intro_keys_description;
config_items[row].max_rows = TXT_INTRO_KEYS_DESCRIPTION_ROWS;
strcpy (config_items[++row].name, "[txt_intro_menu]");
config_items[row].destination = txt_intro_menu;
config_items[row].max_rows = TXT_INTRO_MENU_ROWS;
strcpy (config_items[++row].name, "[txt_of]");
config_items[row].destination = txt_of;
strcpy (config_items[++row].name, "[txt_intro_credits]");
config_items[row].destination = txt_intro_credits;
config_items[row].max_rows = TXT_INTRO_CREDITS_ROWS;
strcpy (config_items[++row].name, "[txt_help_page0]");
config_items[row].destination = txt_help_page0;
config_items[row].max_rows = TXT_HELP_PAGE0_ROWS;
strcpy (config_items[++row].name, "[txt_help_page1]");
config_items[row].destination = txt_help_page1;
config_items[row].max_rows = TXT_HELP_PAGE1_ROWS;
strcpy (config_items[++row].name, "[txt_help_page2]");
config_items[row].destination = txt_help_page2;
config_items[row].max_rows = TXT_HELP_PAGE2_ROWS;
strcpy (config_items[++row].name, "[txt_help_page3]");
config_items[row].destination = txt_help_page3;
config_items[row].max_rows = TXT_HELP_PAGE3_ROWS;
strcpy (config_items[++row].name, "[txt_Back]");
config_items[row].destination = txt_Back;
strcpy (config_items[++row].name, "[txt_Next]");
config_items[row].destination = txt_Next;
strcpy (config_items[++row].name, "[txt_Exit]");
config_items[row].destination = txt_Exit;
strcpy (config_items[++row].name, "[txt_options_page1]");
config_items[row].destination = txt_options_page1;
config_items[row].max_rows = TXT_OPTIONS_PAGE1_ROWS;
strcpy (config_items[++row].name, "[txt_Save]");
config_items[row].destination = txt_Save;
strcpy (config_items[++row].name, "[txt_Game_Speed]");
config_items[row].destination = txt_Game_Speed;
strcpy (config_items[++row].name, "[txt_Fast]");
config_items[row].destination = txt_Fast;
strcpy (config_items[++row].name, "[txt_Normal]");
config_items[row].destination = txt_Normal;
strcpy (config_items[++row].name, "[txt_Slow]");
config_items[row].destination = txt_Slow;
strcpy (config_items[++row].name, "[txt_Key_Repeat]");
config_items[row].destination = txt_Key_Repeat;
strcpy (config_items[++row].name, "[txt_Delay]");
config_items[row].destination = txt_Delay;
strcpy (config_items[++row].name, "[txt_Interval]");
config_items[row].destination = txt_Interval;
strcpy (config_items[++row].name, "[txt_Default_Joystick]");
config_items[row].destination = txt_Default_Joystick;
strcpy (config_items[++row].name, "[txt_No_joystick_found]");
config_items[row].destination = txt_No_joystick_found;
strcpy (config_items[++row].name, "[txt_Joystick_Axes_Dead_Zone]");
config_items[row].destination = txt_Joystick_Axes_Dead_Zone;
strcpy (config_items[++row].name, "[txt_Language]");
config_items[row].destination = txt_Language;
strcpy (config_items[++row].name, "[txt_Translation_by]");
config_items[row].destination = txt_Translation_by;
strcpy (config_items[++row].name, "[txt_Save_Frequency]");
config_items[row].destination = txt_Save_Frequency;
strcpy (config_items[++row].name, "[txt_On_Exit]");
config_items[row].destination = txt_On_Exit;
strcpy (config_items[++row].name, "[txt_On_Change]");
config_items[row].destination = txt_On_Change;
strcpy (config_items[++row].name, "[txt_Move_Up]");
config_items[row].destination = txt_Move_Up;
strcpy (config_items[++row].name, "[txt_Move_Up_Right]");
config_items[row].destination = txt_Move_Up_Right;
strcpy (config_items[++row].name, "[txt_Move_Right]");
config_items[row].destination = txt_Move_Right;
strcpy (config_items[++row].name, "[txt_Move_Down_Right]");
config_items[row].destination = txt_Move_Down_Right;
strcpy (config_items[++row].name, "[txt_Move_Down]");
config_items[row].destination = txt_Move_Down;
strcpy (config_items[++row].name, "[txt_Move_Down_Left]");
config_items[row].destination = txt_Move_Down_Left;
strcpy (config_items[++row].name, "[txt_Move_Left]");
config_items[row].destination = txt_Move_Left;
strcpy (config_items[++row].name, "[txt_Move_Up_Left]");
config_items[row].destination = txt_Move_Up_Left;
strcpy (config_items[++row].name, "[txt_Shoot_Up]");
config_items[row].destination = txt_Shoot_Up;
strcpy (config_items[++row].name, "[txt_Shoot_Down]");
config_items[row].destination = txt_Shoot_Down;
strcpy (config_items[++row].name, "[txt_Shoot_Left]");
config_items[row].destination = txt_Shoot_Left;
strcpy (config_items[++row].name, "[txt_Shoot_Right]");
config_items[row].destination = txt_Shoot_Right;
strcpy (config_items[++row].name, "[txt_Restart]");
config_items[row].destination = txt_Restart;
strcpy (config_items[++row].name, "[txt_Confirm]");
config_items[row].destination = txt_Confirm;
strcpy (config_items[++row].name, "[txt_Help]");
config_items[row].destination = txt_Help;
strcpy (config_items[++row].name, "[txt_Options]");
config_items[row].destination = txt_Options;
strcpy (config_items[++row].name, "[txt_Previous_Level]");
config_items[row].destination = txt_Previous_Level;
strcpy (config_items[++row].name, "[txt_Next_Level]");
config_items[row].destination = txt_Next_Level;
strcpy (config_items[++row].name, "[txt_Previous_Pack]");
config_items[row].destination = txt_Previous_Pack;
strcpy (config_items[++row].name, "[txt_Next_Pack]");
config_items[row].destination = txt_Next_Pack;
strcpy (config_items[++row].name, "[txt_Toggle_Fullscreen]");
config_items[row].destination = txt_Toggle_Fullscreen;
strcpy (config_items[++row].name, "[txt_Home]");
config_items[row].destination = txt_Home;
strcpy (config_items[++row].name, "[txt_End]");
config_items[row].destination = txt_End;
strcpy (config_items[++row].name, "[txt_Page_Up]");
config_items[row].destination = txt_Page_Up;
strcpy (config_items[++row].name, "[txt_Page_Down]");
config_items[row].destination = txt_Page_Down;
strcpy (config_items[++row].name, "[txt_Volume_Up]");
config_items[row].destination = txt_Volume_Up;
strcpy (config_items[++row].name, "[txt_Volume_Down]");
config_items[row].destination = txt_Volume_Down;
strcpy (config_items[++row].name, "[txt_Modifier]");
config_items[row].destination = txt_Modifier;
strcpy (config_items[++row].name, "[txt_Restore_Default_Controls]");
config_items[row].destination = txt_Restore_Default_Controls;
strcpy (config_items[++row].name, "[txt_Toggle_Designer]");
config_items[row].destination = txt_Toggle_Designer;
strcpy (config_items[++row].name, "[txt_Scroll_Up]");
config_items[row].destination = txt_Scroll_Up;
strcpy (config_items[++row].name, "[txt_Scroll_Down]");
config_items[row].destination = txt_Scroll_Down;
strcpy (config_items[++row].name, "[txt_Primary_Click]");
config_items[row].destination = txt_Primary_Click;
strcpy (config_items[++row].name, "[txt_System_Pointer");
config_items[row].destination = txt_System_Pointer;
strcpy (config_items[++row].name, "[txt_Disabled]");
config_items[row].destination = txt_Disabled;
strcpy (config_items[++row].name, "[txt_Enabled]");
config_items[row].destination = txt_Enabled;
strcpy (config_items[++row].name, "[txt_Pointer_Controls_Pad_Type]");
config_items[row].destination = txt_Pointer_Controls_Pad_Type;
strcpy (config_items[++row].name, "[txt_Viewport]");
config_items[row].destination = txt_Viewport;
strcpy (config_items[++row].name, "[txt_Screen]");
config_items[row].destination = txt_Screen;
strcpy (config_items[++row].name, "[txt_Sound]");
config_items[row].destination = txt_Sound;
strcpy (config_items[++row].name, "[txt_Sfx_Volume]");
config_items[row].destination = txt_Sfx_Volume;
strcpy (config_items[++row].name, "[txt_Simulated_Pointer]");
config_items[row].destination = txt_Simulated_Pointer;
strcpy (config_items[++row].name, "[txt_Key]");
config_items[row].destination = txt_Key;
strcpy (config_items[++row].name, "[txt_Joy]");
config_items[row].destination = txt_Joy;
strcpy (config_items[++row].name, "[txt_Ptr]");
config_items[row].destination = txt_Ptr;
strcpy (config_items[++row].name, "[txt_Mod]");
config_items[row].destination = txt_Mod;
strcpy (config_items[++row].name, "[txt_Skin]");
config_items[row].destination = txt_Skin;
strcpy (config_items[++row].name, "[txt_By]");
config_items[row].destination = txt_By;
strcpy (config_items[++row].name, "[txt_Level_Author]");
config_items[row].destination = txt_Level_Author;
strcpy (config_items[++row].name, "[txt_endscreen_congrats]");
config_items[row].destination = txt_endscreen_congrats;
config_items[row].max_rows = TXT_ENDSCREEN_CONGRATS_ROWS;
strcpy (config_items[++row].name, "[txt_Volume]");
config_items[row].destination = txt_Volume;
strcpy (config_items[++row].name, "[txt_Changes_saved]");
config_items[row].destination = txt_Changes_saved;
strcpy (config_items[++row].name, "[txt_Default_controls_restored]");
config_items[row].destination = txt_Default_controls_restored;
strcpy (config_items[++row].name, "[txt_Press_something_and_release]");
config_items[row].destination = txt_Press_something_and_release;
strcpy (config_items[++row].name, "[txt_No_input_was_detected]");
config_items[row].destination = txt_No_input_was_detected;
strcpy (config_items[++row].name, "[txt_ptr_BtnLeft]");
config_items[row].destination = txt_ptr_BtnLeft;
strcpy (config_items[++row].name, "[txt_ptr_BtnMiddle]");
config_items[row].destination = txt_ptr_BtnMiddle;
strcpy (config_items[++row].name, "[txt_ptr_BtnRight]");
config_items[row].destination = txt_ptr_BtnRight;
strcpy (config_items[++row].name, "[txt_ptr_WheelUp]");
config_items[row].destination = txt_ptr_WheelUp;
strcpy (config_items[++row].name, "[txt_ptr_WheelDown]");
config_items[row].destination = txt_ptr_WheelDown;
strcpy (config_items[++row].name, "[txt_key_Backspace]");
config_items[row].destination = txt_key_Backspace;
strcpy (config_items[++row].name, "[txt_key_Tab]");
config_items[row].destination = txt_key_Tab;
strcpy (config_items[++row].name, "[txt_key_Clear]");
config_items[row].destination = txt_key_Clear;
strcpy (config_items[++row].name, "[txt_key_Return]");
config_items[row].destination = txt_key_Return;
strcpy (config_items[++row].name, "[txt_key_Pause]");
config_items[row].destination = txt_key_Pause;
strcpy (config_items[++row].name, "[txt_key_Escape]");
config_items[row].destination = txt_key_Escape;
strcpy (config_items[++row].name, "[txt_key_Space]");
config_items[row].destination = txt_key_Space;
strcpy (config_items[++row].name, "[txt_key_Delete]");
config_items[row].destination = txt_key_Delete;
strcpy (config_items[++row].name, "[txt_key_KP]");
config_items[row].destination = txt_key_KP;
strcpy (config_items[++row].name, "[txt_key_Up]");
config_items[row].destination = txt_key_Up;
strcpy (config_items[++row].name, "[txt_key_Down]");
config_items[row].destination = txt_key_Down;
strcpy (config_items[++row].name, "[txt_key_Right]");
config_items[row].destination = txt_key_Right;
strcpy (config_items[++row].name, "[txt_key_Left]");
config_items[row].destination = txt_key_Left;
strcpy (config_items[++row].name, "[txt_key_Insert]");
config_items[row].destination = txt_key_Insert;
strcpy (config_items[++row].name, "[txt_key_Home]");
config_items[row].destination = txt_key_Home;
strcpy (config_items[++row].name, "[txt_key_End]");
config_items[row].destination = txt_key_End;
strcpy (config_items[++row].name, "[txt_key_PgUp]");
config_items[row].destination = txt_key_PgUp;
strcpy (config_items[++row].name, "[txt_key_PgDn]");
config_items[row].destination = txt_key_PgDn;
strcpy (config_items[++row].name, "[txt_key_NumLk]");
config_items[row].destination = txt_key_NumLk;
strcpy (config_items[++row].name, "[txt_key_CapsLk]");
config_items[row].destination = txt_key_CapsLk;
strcpy (config_items[++row].name, "[txt_key_ScrlLk]");
config_items[row].destination = txt_key_ScrlLk;
strcpy (config_items[++row].name, "[txt_key_RShift]");
config_items[row].destination = txt_key_RShift;
strcpy (config_items[++row].name, "[txt_key_LShift]");
config_items[row].destination = txt_key_LShift;
strcpy (config_items[++row].name, "[txt_key_RCtrl]");
config_items[row].destination = txt_key_RCtrl;
strcpy (config_items[++row].name, "[txt_key_LCtrl]");
config_items[row].destination = txt_key_LCtrl;
strcpy (config_items[++row].name, "[txt_key_RAlt]");
config_items[row].destination = txt_key_RAlt;
strcpy (config_items[++row].name, "[txt_key_LAlt]");
config_items[row].destination = txt_key_LAlt;
strcpy (config_items[++row].name, "[txt_key_RMeta]");
config_items[row].destination = txt_key_RMeta;
strcpy (config_items[++row].name, "[txt_key_LMeta]");
config_items[row].destination = txt_key_LMeta;
strcpy (config_items[++row].name, "[txt_key_LSuper]");
config_items[row].destination = txt_key_LSuper;
strcpy (config_items[++row].name, "[txt_key_RSuper]");
config_items[row].destination = txt_key_RSuper;
#if defined(PLATFORM_FREMANTLE)
strcpy (config_items[++row].name, "[txt_key_AltGr_PLATFORM_FREMANTLE]");
config_items[row].destination = txt_key_AltGr;
#else
strcpy (config_items[++row].name, "[txt_key_AltGr]");
config_items[row].destination = txt_key_AltGr;
#endif
strcpy (config_items[++row].name, "[txt_key_Compose]");
config_items[row].destination = txt_key_Compose;
strcpy (config_items[++row].name, "[txt_key_Help]");
config_items[row].destination = txt_key_Help;
strcpy (config_items[++row].name, "[txt_key_PrScr]");
config_items[row].destination = txt_key_PrScr;
strcpy (config_items[++row].name, "[txt_key_SysRq]");
config_items[row].destination = txt_key_SysRq;
strcpy (config_items[++row].name, "[txt_key_Break]");
config_items[row].destination = txt_key_Break;
strcpy (config_items[++row].name, "[txt_key_Menu]");
config_items[row].destination = txt_key_Menu;
strcpy (config_items[++row].name, "[txt_key_Power]");
config_items[row].destination = txt_key_Power;
strcpy (config_items[++row].name, "[txt_key_Euro]");
config_items[row].destination = txt_key_Euro;
strcpy (config_items[++row].name, "[txt_key_Undo]");
config_items[row].destination = txt_key_Undo;
strcpy (config_items[++row].name, "[txt_konstruktor_Ground]");
config_items[row].destination = txt_konstruktor_Ground;
strcpy (config_items[++row].name, "[txt_konstruktor_Stop]");
config_items[row].destination = txt_konstruktor_Stop;
strcpy (config_items[++row].name, "[txt_konstruktor_Radioactive_Field]");
config_items[row].destination = txt_konstruktor_Radioactive_Field;
strcpy (config_items[++row].name, "[txt_konstruktor_Push_Box]");
config_items[row].destination = txt_konstruktor_Push_Box;
strcpy (config_items[++row].name, "[txt_konstruktor_Capsule]");
config_items[row].destination = txt_konstruktor_Capsule;
strcpy (config_items[++row].name, "[txt_konstruktor_Bomb]");
config_items[row].destination = txt_konstruktor_Bomb;
strcpy (config_items[++row].name, "[txt_konstruktor_Bomb2]");
config_items[row].destination = txt_konstruktor_Bomb2;
strcpy (config_items[++row].name, "[txt_konstruktor_Door]");
config_items[row].destination = txt_konstruktor_Door;
strcpy (config_items[++row].name, "[txt_konstruktor_Box]");
config_items[row].destination = txt_konstruktor_Box;
strcpy (config_items[++row].name, "[txt_konstruktor_Empty_Field]");
config_items[row].destination = txt_konstruktor_Empty_Field;
strcpy (config_items[++row].name, "[txt_konstruktor_Butterfly]");
config_items[row].destination = txt_konstruktor_Butterfly;
strcpy (config_items[++row].name, "[txt_konstruktor_Gun_Fire]");
config_items[row].destination = txt_konstruktor_Gun_Fire;
strcpy (config_items[++row].name, "[txt_konstruktor_Force_Field]");
config_items[row].destination = txt_konstruktor_Force_Field;
strcpy (config_items[++row].name, "[txt_konstruktor_Screw]");
config_items[row].destination = txt_konstruktor_Screw;
strcpy (config_items[++row].name, "[txt_konstruktor_Wall]");
config_items[row].destination = txt_konstruktor_Wall;
strcpy (config_items[++row].name, "[txt_konstruktor_Black_Wall]");
config_items[row].destination = txt_konstruktor_Black_Wall;
strcpy (config_items[++row].name, "[txt_konstruktor_Teleport]");
config_items[row].destination = txt_konstruktor_Teleport;
strcpy (config_items[++row].name, "[txt_konstruktor_Gun]");
config_items[row].destination = txt_konstruktor_Gun;
strcpy (config_items[++row].name, "[txt_konstruktor_Magnet]");
config_items[row].destination = txt_konstruktor_Magnet;
strcpy (config_items[++row].name, "[txt_konstruktor_Bear]");
config_items[row].destination = txt_konstruktor_Bear;
strcpy (config_items[++row].name, "[txt_konstruktor_Black_Bear]");
config_items[row].destination = txt_konstruktor_Black_Bear;
strcpy (config_items[++row].name, "[txt_konstruktor_Bird]");
config_items[row].destination = txt_konstruktor_Bird;
strcpy (config_items[++row].name, "[txt_konstruktor_Key]");
config_items[row].destination = txt_konstruktor_Key;
strcpy (config_items[++row].name, "[txt_konstruktor_Bullets]");
config_items[row].destination = txt_konstruktor_Bullets;
strcpy (config_items[++row].name, "[txt_konstruktor_on_map]");
config_items[row].destination = txt_konstruktor_on_map;
strcpy (config_items[++row].name, "[txt_konstruktor_Laser_Gun]");
config_items[row].destination = txt_konstruktor_Laser_Gun;
strcpy (config_items[++row].name, "[txt_konstruktor_Blaster_Gun]");
config_items[row].destination = txt_konstruktor_Blaster_Gun;
strcpy (config_items[++row].name, "[txt_konstruktor_Regular_Gun]");
config_items[row].destination = txt_konstruktor_Regular_Gun;
strcpy (config_items[++row].name, "[txt_konstruktor_Fixed]");
config_items[row].destination = txt_konstruktor_Fixed;
strcpy (config_items[++row].name, "[txt_konstruktor_Moveable]");
config_items[row].destination = txt_konstruktor_Moveable;
strcpy (config_items[++row].name, "[txt_konstruktor_Rotating]");
config_items[row].destination = txt_konstruktor_Rotating;
strcpy (config_items[++row].name, "[txt_konstruktor_Moveable_Rotating]");
config_items[row].destination = txt_konstruktor_Moveable_Rotating;
strcpy (config_items[++row].name, "[txt_konstruktor_Direction_right]");
config_items[row].destination = txt_konstruktor_Direction_right;
strcpy (config_items[++row].name, "[txt_konstruktor_Direction_down]");
config_items[row].destination = txt_konstruktor_Direction_down;
strcpy (config_items[++row].name, "[txt_konstruktor_Direction_left]");
config_items[row].destination = txt_konstruktor_Direction_left;
strcpy (config_items[++row].name, "[txt_konstruktor_Direction_up]");
config_items[row].destination = txt_konstruktor_Direction_up;
strcpy (config_items[++row].name, "[txt_konstruktor_Welcome_to_GNU_Robbo_Designer]");
config_items[row].destination = txt_konstruktor_Welcome_to_GNU_Robbo_Designer;
strcpy (config_items[++row].name, "[txt_konstruktor_Exit_designer_select_again_to_exit]");
config_items[row].destination = txt_konstruktor_Exit_designer_select_again_to_exit;
strcpy (config_items[++row].name, "[txt_konstruktor_Reload_level_select_again_to_reload]");
config_items[row].destination = txt_konstruktor_Reload_level_select_again_to_reload;
strcpy (config_items[++row].name, "[txt_konstruktor_Level_reloaded]");
config_items[row].destination = txt_konstruktor_Level_reloaded;
strcpy (config_items[++row].name, "[txt_konstruktor_New_level_select_again_to_create]");
config_items[row].destination = txt_konstruktor_New_level_select_again_to_create;
strcpy (config_items[++row].name, "[txt_konstruktor_Level_created]");
config_items[row].destination = txt_konstruktor_Level_created;
strcpy (config_items[++row].name, "[txt_konstruktor_Save_select_again_to_save_new_level]");
config_items[row].destination = txt_konstruktor_Save_select_again_to_save_new_level;
strcpy (config_items[++row].name, "[txt_konstruktor_New_level_appended_to_pack]");
config_items[row].destination = txt_konstruktor_New_level_appended_to_pack;
strcpy (config_items[++row].name, "[txt_konstruktor_Clear_level_select_again_to_clear]");
config_items[row].destination = txt_konstruktor_Clear_level_select_again_to_clear;
strcpy (config_items[++row].name, "[txt_konstruktor_Level_cleared]");
config_items[row].destination = txt_konstruktor_Level_cleared;
strcpy (config_items[++row].name, "[txt_konstruktor_Save_select_again_to_save_changes]");
config_items[row].destination = txt_konstruktor_Save_select_again_to_save_changes;
strcpy (config_items[++row].name, "[txt_konstruktor_Changes_saved]");
config_items[row].destination = txt_konstruktor_Changes_saved;
strcpy (config_items[++row].name, "[txt_konstruktor_Level_resized_to]");
config_items[row].destination = txt_konstruktor_Level_resized_to;
#ifdef DEBUG_LOAD_SELECTED_LOCALE
printf ("*** Start %s ***\n", __func__);
#endif
/* Initialise all the config_item destination strings to SINGLE_SPACE */
for (count = 0; count < CONFIG_ITEM_COUNT; count++)
{
for (row = 0; row < config_items[count].max_rows; row++)
{
strcpy (&(config_items[count].destination)
[TXT_MAX_COLS * row], SINGLE_SPACE);
#ifdef DEBUG_LOAD_SELECTED_LOCALE
printf ("%s: %p=\"%s\"\n", config_items[count].name,
&(config_items[count].destination)[TXT_MAX_COLS * row],
&(config_items[count].destination[TXT_MAX_COLS * row]));
#endif
}
}
#ifdef DEBUG_LOAD_SELECTED_LOCALE
printf ("\n");
#endif
/* Attempt to open the text file */
strcpy (filename, PACKAGE_DATA_DIR "/" LOCALES_DIR "/");
strcat (filename, locales[selected_locale].foldername);
strcat (filename, "/");
strcat (filename, LOCALE_TEXT_FILE);
if ((fp = fopen (filename, "r")) == NULL)
{
fprintf (stdout, "Cannot read from file %s\n", filename);
}
else
{
/* Read lines including the [CR]LFs until we have what we need
* or reach the end of file (line == NULL) */
while ((fgets (line, 1024, fp)) != NULL)
{
line_count++;
/* fgets will get [CR]LFs too so they should be removed */
for (count2 = strlen (line) - 1; count2 >= 0; count2--)
if (line[count2] == 13 || line[count2] == 10)
line[count2] = 0;
/* Are we reading a tag? */
tag_found = FALSE;
for (tag_index = 0; tag_index < CONFIG_ITEM_COUNT; tag_index++)
{
if (!strncmp (line, config_items[tag_index].name,
strlen (config_items[tag_index].name)))
{
tag_found = TRUE;
break;
}
}
if (tag_found)
{
/* If a tag is being read and we read another tag
* then mark it as something else */
for (count = 0; count < CONFIG_ITEM_COUNT; count++)
{
if (config_items[count].state == DATA_READING)
config_items[count].state = DATA_INCOMPLETE;
}
/* If the found tag is DATA_UNREAD then mark it for DATA_READING */
if (config_items[tag_index].state == DATA_UNREAD)
{
config_items[tag_index].state = DATA_READING;
row = 0;
}
}
else
{
/* It's not a tag but data (or newline) so we need
* to find what to do with it */
for (count = 0; count < CONFIG_ITEM_COUNT; count++)
{
if (config_items[count].state == DATA_READING)
{
if (strlen (line) > 0)
{ /* We've already set the strings to
* SINGLE_SPACE, don't empty them here */
strncpy (&(config_items[count].destination)
[TXT_MAX_COLS * row], line, TXT_MAX_COLS); /* Prevent overruns */
config_items[count].destination[TXT_MAX_COLS *
(row + 1) - 1] = 0; /* Just in case we read all chars */
}
#ifdef DEBUG_LOAD_SELECTED_LOCALE
printf ("%s: %p=\"%s\"\n", config_items[count].name,
&(config_items[count].destination)[TXT_MAX_COLS * row],
&(config_items[count].destination[TXT_MAX_COLS * row]));
#endif
if (++row == config_items[count].max_rows)
config_items[count].state = DATA_READ;
break;
}
}
}
}
fclose (fp);
#ifdef DEBUG_LOAD_SELECTED_LOCALE
printf ("\n");
for (count = 0; count < CONFIG_ITEM_COUNT; count++)
{
printf ("%s=%s\n", config_items[count].name,
data_state[config_items[count].state]);
}
printf ("\n");
#endif
}
#ifdef DEBUG_LOAD_SELECTED_LOCALE
printf ("*** Stop %s ***\n", __func__);
#endif
}
/***************************************************************************
* Set Locale to LANG *
***************************************************************************/
/* This will attempt to set the default locale to something equivalent to
* whatever is present within the LANG environment variable. This must be
* called after read_localerc_files and before read_resource_file so that
* if an rcfile is found and a locale is set within it then that will
* override any default set here */
void set_locale_to_LANG(void) {
int count, length = 0, found = FALSE;
char *envlang = getenv("LANG");
#ifdef DEBUG_SET_LOCALE_TO_LANG
printf("%s: locales[selected_locale].foldername=%s\n", __func__,
locales[selected_locale].foldername);
printf("%s: LANG=%s\n", __func__, envlang);
#endif
/* On my GP2X getenv("LANG") returns NULL and using any string
* functions on NULL will cause a segfault. Actually this is an
* issue for any platform and really the return value from getenv
* should always be checked for NULL before using it in any string
* functions */
if (envlang != NULL) length = strlen(envlang);
if (length >= 5) {
length = 5; /* en_GB is 5 chars */
} else if (length >= 2) {
length = 2; /* en is 2 chars */
} else {
length = 0;
}
while (!found && length) {
for (count = 0; count < locale_count; count++) {
if (!strncmp(locales[count].foldername, envlang, length)) {
found = TRUE;
selected_locale = count;
#ifdef DEBUG_SET_LOCALE_TO_LANG
printf("%s: A %i-char match was found\n", __func__, length);
#endif
}
}
if (length > 2) {
length = 2;
} else {
length = 0;
}
}
#ifdef DEBUG_SET_LOCALE_TO_LANG
printf("%s: locales[selected_locale].foldername=%s\n", __func__,
locales[selected_locale].foldername);
if (!found) printf("%s: No match was found\n", __func__);
#endif
}
|