summaryrefslogtreecommitdiff
blob: 31f6145d57916871b694aa1e431c52642c6027d1 (plain)
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
import java.io.FileNotFoundException;
import java.io.IOException;

import java.util.Map;
import java.util.HashMap;

public class Strings
{
   private static final Map<String, String> FROM_ID;

   static
   {
      FROM_ID = new HashMap<String, String>();
   }

   private static void add_mapping (final String id, final String str)
   {
      FROM_ID.put(id, str);
   }

   public static String get_string_from_id (final String id)
   {
      return FROM_ID.get(id);
   }

   private static boolean handle_mapping_instruction (final String... instr)
   {
      if (instr.length < 3)
      {
         return false;
      }

      if (!instr[0].equals("string->instr"))
      {
         return false;
      }

      add_mapping(instr[2], instr[1]);

      return true;
   }

   public static boolean load_file (final String filename)
   throws FileNotFoundException
   {
      final QuickParser qp;
      String[] input;

      qp = new QuickParser(filename);

      for (;;)
      {
         try
         {
            input = qp.parse_line();

            if (input == null)
            {
               qp.finalize();

               return false;
            }
            else if (input.length == 0)
            {
               qp.finalize();

               break;
            }
         }
         catch (final IOException e)
         {
            System.err.println
            (
               "[E] IO error while parsing file \""
               + filename
               + "\":"
               /* FIXME: can be null */
               + e.getMessage()
            );

            return false;
         }

         handle_mapping_instruction(input);
      }

      return true;
   }
}