00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <iostream>
00026 #include <vector>
00027 #include "utils.h"
00028
00029 using std::istream;
00030 using std::cerr;
00031 using std::endl;
00032 using std::vector;
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 int Read_text_msg_file
00047 (
00048 istream& in,
00049 vector<char *>& strings
00050
00051 )
00052 {
00053 strings.resize(0);
00054 strings.reserve(2000);
00055 char buf[1024];
00056 int linenum = 0;
00057 #define NONEFOUND 0xffffffff
00058 unsigned long first = NONEFOUND;
00059 while (!in.eof())
00060 {
00061 ++linenum;
00062 in.get(buf, sizeof(buf));
00063 char delim;
00064 in.get(delim);
00065 if (delim != '\n' && !in.eof())
00066 {
00067 cerr << "Line #" << linenum << " is too long" << endl;
00068 return -1;
00069 }
00070 if (!buf[0])
00071 continue;
00072 char *ptr = &buf[0];
00073 char *endptr;
00074 long index = strtol(ptr, &endptr, 0);
00075 if (endptr == ptr)
00076 {
00077 if (*ptr == '#')
00078 continue;
00079 cerr << "Line " << linenum <<
00080 " doesn't start with a number" << endl;
00081 return -1;
00082 }
00083 if (*endptr != ':')
00084 {
00085 cerr << "Missing ':' in line " << linenum <<
00086 ". Ignoring line" << endl;
00087 continue;
00088 }
00089 if (index >= strings.size())
00090 strings.resize(index + 1);
00091 strings[index] = newstrdup(endptr + 1);
00092 if (index < first)
00093 first = index;
00094 }
00095 return first == NONEFOUND ? -1 : (int) first;
00096 }
00097