void ui_dbase_pgdata_usb_to_db(void) { comm_dlg_data_t dlg_data_copy = { ROOT_ID_BACKGROUND, DLG_FOR_SHOW | DLG_STR_MODE_STATIC, COMM_DLG_X, COMM_DLG_Y, COMM_DLG_W, COMM_DLG_H, IDS_IMPORTING_PRESET_CHANNEL, 0, }; hfile_t file = NULL; channel_data_t * p_channel_data = NULL; u32 channel_data_size = 0; u8 pg_view_id = 0xFF, tp_view_id = 0xFF; u16 pg_total = 0, tp_total = 0, i = 0, j = 0; u32 len = 0; dvbs_tp_node_t* p_tp; prog_node_t * p_pg_node; u16 filename[MAX_DB_FILE_NAME_LENGTH] = {0}; //u16 bouquet_name_unistr[64] = {0}; bouquet_group_t *g_bouquet_grp = NULL; //u8 bouquet_name[64] = {0}; //u16 bouquet_id[32]; ui_close_all_mennus(); ui_comm_dlg_open(&dlg_data_copy); ui_dbase_mk_db_filename(filename, IW_CHANNEL_DATA_FILE_NAME); channel_data_size = sizeof(channel_data_t); p_channel_data = mtos_malloc(channel_data_size); if(NULL == p_channel_data) { OS_PRINTF("@@ %s, p_channel_data malloc failed, size = %d \n", __FUNCTION__, channel_data_size); return; } memset(p_channel_data, 0, channel_data_size); //open file -- file = vfs_open(filename, VFS_READ); if(file != NULL) { len = vfs_read(p_channel_data, channel_data_size, 1, file); if(len != channel_data_size) { OS_PRINTF("@@ %s :%d \n", __FUNCTION__, __LINE__); vfs_close(file); mtos_free(p_channel_data); return; } } else { OS_PRINTF("@@ %s :%d \n", __FUNCTION__, __LINE__); vfs_close(file); mtos_free(p_channel_data); return; } db_reset_prog_before_copy(); tp_view_id = db_dvbs_create_view(DB_DVBS_ALL_TP, 0, NULL); tp_total = p_channel_data->total_tp_num; pg_view_id = ui_dbase_create_view(DB_DVBS_ALL_PG, 0, NULL); pg_total = p_channel_data->total_pg_num; if(tp_total == 0 || pg_total == 0) { mtos_free(p_channel_data); return; } //add tp for(i = 0; i < tp_total; i++) { db_dvbs_add_tp(tp_view_id, &(p_channel_data->tp_list[i])); } //add tp for(i = 0; i < pg_total; i++) { p_pg_node = &(p_channel_data->pg_list[i]); for(j = 0; j < tp_total; j++) { p_tp = &(p_channel_data->tp_list[j]); if(p_pg_node->freq == p_tp->freq && p_pg_node->sym == p_tp->sym && p_pg_node->nim_modulate== p_tp->nim_modulate) { p_pg_node->pg.tp_id = p_tp->id; break; } } db_dvbs_add_program(pg_view_id, &(p_pg_node->pg)); } db_dvbs_save(tp_view_id); db_dvbs_save(pg_view_id); g_bouquet_grp = get_bouquet_group(); g_bouquet_grp->bouquet_count = p_channel_data->categories_count; for(i=0; i<g_bouquet_grp->bouquet_count; i++) { memcpy(g_bouquet_grp->bouquet_name[i],p_channel_data->bouquet_name[i],32); g_bouquet_grp->bouquet_id[i] = p_channel_data->bouquet_id[i]; } categories_set_loaded_flag(TRUE); ui_cache_view(); create_categories(); ui_restore_view(); //ui_dbase_pg_sort(DB_DVBS_ALL_PG); sys_status_set_curn_group(GROUP_T_ALL); ui_dbase_play_first_pg(pg_view_id); mtos_free(p_channel_data); ui_comm_dlg_close(); return; }
/* parses the FreeBSD ports INDEX file and creates a list of categories with dedicated ports, it also creates a meta-category "all", all lists and categories are sorted ascending. */ int parse_index() { FILE *fd; int c, i, readyToken; int pipes = 0; char tok[MAX_TOKEN]; extern Config config; extern List *lprts; extern List *lcats; extern void *exists; extern TNode *tcat; TNode *tdirs; TNode *tprt = NULL; List *lpdir = (List *)malloc(sizeof(List)); Port *p, *dprt; int num_of_inst_ports = 0; /* init */ p = NULL; tcat = NULL; lpdir->num_of_items = 0; lpdir->head = NULL; lpdir->tail = NULL; if ((fd = fopen(config.index_file, "r")) == NULL) return ERROR_OPEN_INDEX; /* error */ /* parse installed pkgs */ tdirs = parse_dir(config.inst_pkg_dir); /* parse ports dir and create list */ create_inorder_list(lpdir, parse_dir(config.ports_dir)); i = 0; readyToken = 0; /* token not ready */ while (feof(fd) == 0) { c = fgetc(fd); /* get next char */ switch (c) { case '|': /* next token */ readyToken = 1; /* ready token */ break; case '\n': /* end of port */ #if defined(__FreeBSD__) if (pipes != PORT_URL) /* seems to be some strange INDEX */ return ERROR_CORRUPT_INDEX; #endif readyToken = 1; /* tail token of port ready */ break; default: if ((pipes != PORT_CATEGORY) && (pipes != PORT_BUILD_DEPENDENCY) && (pipes != PORT_RUN_DEPENDENCY)) /* default, no port category, build dep or run dep modus */ tok[i++] = (char)c; break; } /* to speed up the parsing, we also parse categories here, I guessed if it'll be senseful to also parse BDEP and RDEP, but this makes no sense until there aren't all entries scanned */ if (pipes == PORT_CATEGORY) { /* port category mode */ if ((c == ' ') || (c == '|')) { if (i > 0) { /* maybe there're ports without a category */ tok[i] = '\0'; /* terminate current cat token */ add_list_item(p->lcats, add_category(tok, lpdir)); i = 0; /* reset i */ } } else { /* inside a token */ tok[i++] = (char)c; } } else if ((pipes == PORT_BUILD_DEPENDENCY) || (pipes == PORT_RUN_DEPENDENCY)) { /* port build/run dep mode */ if ((c == ' ') || (c == '|')) { if (i > 0) { /* maybe there're ports without a build dep */ tok[i] = '\0'; dprt = create_port(tok, tdirs); exists = NULL; tprt = add_tree_item(tprt, dprt, cmp_name); if (exists != NULL) { free_port(dprt); dprt = (Port *)((TNode *)exists)->item; } else { if (dprt->state >= STATE_INSTALLED) num_of_inst_ports++; } if (pipes == PORT_BUILD_DEPENDENCY) { add_list_item(p->lbdep, dprt); } else if (pipes == PORT_RUN_DEPENDENCY) { add_list_item(p->lrdep, dprt); } /* add also p to dprt->ldep, so that dprt knows the port for which dprt is a dependency, this helps seeking for unused ports */ add_list_item(dprt->ldep, p); i = 0; /* reset i */ } } else { /* inside a token */ tok[i++] = (char)c; } } if (readyToken == 1) { /* a new token is ready */ tok[i] = '\0'; /* terminate current token */ switch (pipes) { case PORT_NAME_VERSION: p = create_port(tok, tdirs); /* add the port */ exists = NULL; tprt = add_tree_item(tprt, p, cmp_name); if (exists != NULL) { free_port(p); p = (Port *)((TNode *)exists)->item; } else { if (p->state >= STATE_INSTALLED) num_of_inst_ports++; } break; case PORT_PATH: p->path = strdup(tok); break; #if defined(__FreeBSD__) case PORT_INSTALL_PREFIX: p->instpfx = strdup(tok); break; #endif case PORT_DESCR: p->descr = strdup(tok); break; case PORT_PKGDESCR: p->pathpkgdesc = strdup(tok); break; case PORT_MAINTAINER: p->maintainer = strdup(tok); break; #if defined(__FreeBSD__) case PORT_URL: p->url = strdup(tok); pipes = -1; break; #endif } readyToken = i = 0; /* token processed, not ready token anymore */ pipes++; } } fclose(fd); /* close INDEX file */ create_inorder_list(lcats, tcat); create_inorder_list(lprts, tprt); create_categories(num_of_inst_ports); free_tree(tdirs); /* finished */ return (0); }