4 * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #define TABLE_NAME "mcc_mnc_oper_list"
23 #define TABLE_SCHEMA "create table " TABLE_NAME " (id integer primary key, country char(3), mcc integer, mnc char(3), oper char(45));"
25 #define dbg(fmt, args ...) fprintf(stderr, fmt, ## args)
27 int main(int argc, char *argv[])
41 printf("%s filename.csv\n", argv[0]);
45 fp_in = fopen(argv[1], "r");
51 printf("%s\n", TABLE_SCHEMA);
55 fgets(buf, 255, fp_in);
62 buf[strlen(buf) - 1] = '\0';
66 pos1 = strchr(buf, ',');
67 memset(country, 0, 10);
68 memcpy(country, buf, pos1 - buf);
70 dbg("country=[%s]\n", country);
72 sscanf(pos1 + 1, "%d", &mcc);
73 dbg("mcc=[%d]\n", mcc);
76 pos1 = strchr(pos1 + 1, ',');
77 pos2 = strchr(pos1 + 1, ',');
79 dbg("mnc=[%s]\n", pos1 + 1);
82 strncpy(mnc, pos1 + 1, pos2 - pos1 - 1);
86 pos2 = strchr(pos1 + 1, ',');
88 dbg("brand=[%s]\n", pos1 + 1);
90 memset(brand, 0, 255);
91 strncpy(brand, pos1 + 1, pos2 - pos1 - 1);
95 pos2 = strchr(pos1 + 1, ',');
97 dbg("oper=[%s]\n", pos1 + 1);
100 strcpy(oper, pos1 + 1);
103 if (strlen(brand) == 0)
106 if (oper_select[0] == '\"') {
108 snprintf(buf, strlen(oper_select) - 2, "%s", oper_select + 1);
109 snprintf(oper_select, 255, "%s", buf);
112 snprintf(buf, 255, "insert into %s "
113 " (country, mcc, mnc, oper) "
114 " values (\"%s\", %d, \"%s\", \"%s\");",
115 TABLE_NAME, country, mcc, mnc, oper_select);