4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #define TABLE_NAME "mcc_mnc_oper_list"
25 #define TABLE_SCHEMA "create table " TABLE_NAME " (id integer primary key, country char(3), mcc integer, mnc char(3), oper char(45) );"
27 #define dbg(fmt,args...) fprintf(stderr, fmt, ##args);
29 int main(int argc, char *argv[])
43 printf("%s filename.csv\n", argv[0]);
47 fp_in = fopen(argv[1], "r");
53 printf("%s\n", TABLE_SCHEMA);
57 fgets (buf, 255, fp_in);
64 buf[strlen(buf)-1] = '\0';
68 pos1 = strchr (buf, ',');
69 memset (country, 0, 10);
70 memcpy(country, buf, pos1-buf);
72 dbg("country=[%s]\n", country);
74 sscanf (pos1+1, "%d", &mcc);
75 dbg("mcc=[%d]\n", mcc);
78 pos1 = strchr (pos1+1, ',');
79 pos2 = strchr (pos1+1, ',');
81 dbg("mnc=[%s]\n", pos1+1);
84 strncpy (mnc, pos1+1, pos2-pos1-1);
88 pos2 = strchr (pos1+1, ',');
90 dbg("brand=[%s]\n", pos1+1);
92 memset (brand, 0, 255);
93 strncpy (brand, pos1+1, pos2-pos1-1);
97 pos2 = strchr (pos1+1, ',');
99 dbg("oper=[%s]\n", pos1+1);
101 memset (oper, 0, 255);
102 strcpy (oper, pos1+1);
105 if (strlen(brand) == 0)
108 if (oper_select[0] == '\"') {
110 snprintf(buf, strlen(oper_select)-2, "%s", oper_select+1);
111 snprintf(oper_select, 255, "%s", buf);
114 snprintf(buf, 255, "insert into %s "
115 " (country, mcc, mnc, oper) "
116 " values (\"%s\", %d, \"%s\", \"%s\");",
117 TABLE_NAME, country, mcc, mnc, oper_select);