mktable.c
来自「ESS3890+SL原代码(1*16内存)」· C语言 代码 · 共 1,775 行 · 第 1/4 页
C
1,775 行
return (i * sizeof(char)); }#endif FLASH_UPDATE/* write OSD message */PRIVATE unsigned long write_osdmsg(osdmsg, index, fp)OSDMSG * osdmsg;int index;FILE * fp;{ int num_msg = tables[index].entries; unsigned int len, newlen; int i, j; uchar cbuf[30], *cptr; for (i = len = 0; i < num_msg; i++) { cptr = osdmsg[i].osd; j = 0; do {#ifndef USE_CN_HEADER if (*cptr != CN_HEADER)#endif /* !USE_CN_HEADER */ { cbuf[j++] = *cptr; } } while (*cptr++); fprintf(fp, "%s%c", cbuf, '\000'); len += (strlen(cbuf)+1); } /* Align length to 4B boundary */ if (len & 0x3) { newlen = len + 4; newlen &= ~3; } else newlen = len; for (i = newlen - len; i > 0; i --) fputc('\000', fp); tables[index].size = newlen; /* Fill the length of data! */ return(newlen);}/* write VFD message */PRIVATE unsigned long write_vfdmsg(vfdmsg, index, fp)VFD_MSG * vfdmsg;int index;FILE * fp;{ int num_msg = tables[index].entries; unsigned int len,newlen; int i, j; for (i = len = 0; i < num_msg; i++) { j = 0; do { write_short((unsigned short *) & vfdmsg[i].msg[j], 1, fp ); } while (vfdmsg[i].msg[j++] != CHAR_end); len += (j*2); } /* Align length to 4B boundary */ if (len & 0x3) { newlen = len + 4; newlen &= ~3; } else newlen = len; for (i = newlen - len; i > 0; i --) fputc('\000', fp); tables[index].size = newlen; /* Fill the length of data! */ return(newlen);}/* write VFD icons */PRIVATE unsigned long write_vfdicon(vfdicon, index, fp)VFD_ICON * vfdicon;int index;FILE * fp;{ int num_msg = tables[index].entries; unsigned int len, newlen; unsigned char i,j,k; unsigned char size; /* * Entry 0 of icontbl is reserved as termincation symbol. * Entry 1 of icontbl is reserved for ICON_empty. */ tbl_len = 2; icontbl[1] = ICON_empty; /* Reserve the first entry of VFDICON_array for empty/empty */ fputc(0, fp); fputc(0, fp); len = 2; for (i = 0; i < num_msg; i++, vfdicon++) { /* * We only process non-trivial case (i.e. at least one non-empty * case). Trivial case is reserved already. */ if ((vfdicon->lite[0] != ICON_empty) || (vfdicon->clear[0] != ICON_empty)) { /* First check icons to be turned on */ for (j = 0; j < sizeof(vfdicon->lite)/sizeof(vfdicon->lite[0]); j++) { len++; if (vfdicon->lite[j] == ICON_empty) { if (vfdicon->lite[j+1] == 0) { /* Normal empty line case */ fputc(0, fp); break; } else { /* Specification is wrong! */ fprintf(stderr, "Incorrect VFD specification: %s ", vfdicon->name); fprintf(stderr, "(ICON_empty follows by other icon!)\n"); exit(1); } } else if (vfdicon->lite[j] == 0) { fputc(0, fp); break; } for (k = 1; k < tbl_len; k++) if (vfdicon->lite[j] == icontbl[k]) break; if (k == tbl_len) icontbl[tbl_len++] = vfdicon->lite[j]; fputc(k, fp); } /* next check icons to be turned off */ for (j = 0; j < sizeof(vfdicon->clear)/sizeof(vfdicon->clear[0]); j++) { len++; if (vfdicon->clear[j] == ICON_empty) { if (vfdicon->clear[j+1] == 0) { /* Normal empty line case */ fputc(0, fp); break; } else { /* Specification is wrong! */ fprintf(stderr, "Incorrect VFD specification: %s ", vfdicon->name); fprintf(stderr, "(ICON_empty follows by other icon!)\n"); exit(1); } } else if (vfdicon->clear[j] == 0) { fputc(0, fp); break; } for (k = 1; k < tbl_len; k++) if (vfdicon->clear[j] == icontbl[k]) break; if (k == tbl_len) icontbl[tbl_len++] = vfdicon->clear[j]; fputc(k, fp); } } } /* Align length to 4B boundary */ if (len & 0x3) { newlen = len + 4; newlen &= ~3; } else newlen = len; for (i = newlen - len; i > 0; i --) fputc('\000', fp); tables[index].size = newlen; /* Fill the length of data! */ return(newlen);}/* write icon table */PRIVATE unsigned long write_icontbl(table, index, fp)unsigned short * table;int index;FILE * fp;{ unsigned int len, newlen; int i; for (i = 0; i < tbl_len; i++) write_short(table+i,1,fp); len = tbl_len*sizeof(short); /* Align length to 4B boundary */ if (len & 0x3) { newlen = len + 4; newlen &= ~3; } else newlen = len; for (i = newlen - len; i > 0; i --) fputc('\000', fp); tables[index].size = newlen; /* Fill the length of data! */ return(newlen);}/* Output #define's for message */PRIVATE void write_message_defines(index, fp)int index;FILE * fp;{ int num_msg = tables[index].entries; int i, j, len, type = tables[index].type; uchar cbuf[30], *cptr; if (type == OSDMESSAGE) { OSDMSG * ptr = (OSDMSG *)(tables[index].table); for (i = len = 0; i < num_msg; i++) { cptr = ptr[i].osd; j = 0; do {#ifndef USE_CN_HEADER if (*cptr != CN_HEADER)#endif /* !USE_CN_HEADER */ { cbuf[j++] = *cptr; } } while (*cptr++); fprintf(fp, "#define MSG_%-20s (&MSG_array[%4d])\n", ptr[i].name, len); len += (strlen(cbuf) + 1); } } else if (type == VFDMSG) { VFD_MSG * ptr = (VFD_MSG *)(tables[index].table); for (i = len = 0; i < num_msg; i++) { fprintf(fp, "#define VFDMSG_%-17s (&VFDMSG_array[%4d])\n", ptr[i].name, len); j = 0; while (ptr[i].msg[j++] != CHAR_end); len += (j*2); } } else if (type == VFDICON) { /* Generate offset for VFDICON_xxxx */ VFD_ICON * ptr = (VFD_ICON *)(tables[index].table); len = 2; /* Reserve first 2 entries for empty/empty */ for (i = 0; i < num_msg; i++, ptr++) { /* * We reserve one slot (first slot) for empty/empty case. */ if ((ptr->lite[0] == ICON_empty) && (ptr->clear[0] == ICON_empty)) { fprintf(fp, "#define VFDICON_%-16s (&VFDICON_array[ 0])\n", ptr->name); } else { fprintf(fp, "#define VFDICON_%-16s (&VFDICON_array[%4d])\n", ptr->name, len); for (j = 0; j < sizeof(ptr->lite)/sizeof(ptr->lite[0]); j++) { len++; if ((ptr->lite[j] == 0) || (ptr->lite[j] == ICON_empty)) break; } for (j = 0; j < sizeof(ptr->clear)/sizeof(ptr->clear[0]); j++){ len++; if ((ptr->clear[j] == 0) || (ptr->clear[j] == ICON_empty)) break; } } } }}#ifdef COMPRESS_MKTBL_DATAvoid register_for_compress(int index){ int found = 0, g_index, item_size, i; /*first search for registered group*/ for (i=0; i<compress_group_num; i++) if (!strcmp(tables[index].group_name, compress_group[i].name)) { found = 1; g_index = i; break; } if (found) { if (compress_group[g_index].item_num < MAX_COMPRESS_ITEM_NUM) { item_size = register_item(&(compress_group[g_index].item_table[compress_group[g_index].item_num]), index); compress_group[g_index].table_size += item_size; compress_group[g_index].item_num ++; } } else { if (compress_group_num < MAX_COMPRESS_GROUP_NUM) { i = compress_group_num; compress_group[i].item_num = 1; strcpy( compress_group[i].name, tables[index].group_name); compress_group[i].table_size = register_item(&(compress_group[i].item_table[0]), index); compress_group_num ++; } } return;}int register_item(COMPRESS_ITEM *c_item, int index){ strcpy(c_item->name, tables[index].name); c_item->type = tables[index].type - CTYPE_BASE; c_item->data = tables[index].table; c_item->size = tables[index].size; c_item->offset = tables[index].entries; /* preliminary usage */ return SIZE(c_item->size);}#if defined(COMPRESS_ALL_UCODE) || defined(COMPRESS_MP3_UCODE)void format_ucode_name(char *orig_name, char *dest_name){ int i, limit; /* add "r" to front of ucode name and cut-off "_ucode".. * i.e. "echo_ucode" becomes "recho" */ dest_name[0] = 'r'; limit = strlen(orig_name) - 6; for (i=0; i < limit; i++) { dest_name[i+1] = orig_name[i]; } dest_name[i+1] = 0;}#endif /* COMPRESS_ALL_UCODE || COMPRESS_MP3_UCODE */void output_compress_group(int index, FILE *fp){ int i; unsigned long ndata, offset=0, numread, fin_len; char orgfile[] = "_o.txt"; char comfile[] = "_c.txt"; char ucode_name[24]; COMPRESS_GROUP *cgroup = &compress_group[index]; unsigned char *compress_buf; /*[MAX_COMPRESSED_DATA_SIZE]; 32k enough ?*/ FILE *forg, *fcom, *fall_uc; forg = fopen(orgfile,"wb"); if (!forg) { fprintf(stderr,"Cannot open file: %s\n", orgfile); return; } fcom = fopen(comfile,"wb"); if (!fcom) { fprintf(stderr,"Cannot open file: %s\n", comfile); return; } fclose (fcom);#if defined(COMPRESS_ALL_UCODE) || defined(COMPRESS_MP3_UCODE) if ((fall_uc = fopen("reg_vpuc.h", "w")) == NULL) { fprintf(stderr, "reg_vpuc.h open error!\n"); exit(1); } else { fprintf(fall_uc, "/* Automatically generated file. DO NOT EDIT. */\n\n"); }#endif /* COMPRESS_ALL_UCODE || COMPRESS_MP3_UCODE */ for (i = 0; i < cgroup->item_num; i++) {#if defined(COMPRESS_ALL_UCODE) || defined(COMPRESS_MP3_UCODE) format_ucode_name(cgroup->item_table[i].name, ucode_name);#ifdef COMPRESS_MP3_UCODE fprintf(fall_uc,"\tregister_mp3_ucode(%s, 0, %d, %d);\n",ucode_name, cgroup->item_table[i].size>>2, cgroup->item_table[i].offset);#else fprintf(fall_uc,"\tregister_ucode(%s, 0, %d, %d);\n",ucode_name, cgroup->item_table[i].size>>2, cgroup->item_table[i].offset);#endif#endif /* COMPRESS_ALL_UCODE || COMPRESS_MP3_UCODE */ cgroup->item_table[i].offset = offset; switch (cgroup->item_table[i].type) { case SHORT: case USHORT: ndata = write_short((short *)cgroup->item_table[i].data, SIZE(cgroup->item_table[i].size) / sizeof(short), forg); break; case CHAR: case UCHAR: ndata = write_char(cgroup->item_table[i].data, SIZE(cgroup->item_table[i].size) , forg); break; case INT: case UINT: case LONG: case ULONG: ndata = write_long((long *) cgroup->item_table[i].data, SIZE(cgroup->item_table[i].size) / sizeof(long), forg); break; } offset += ndata; } fclose(forg); fclose (fall_uc); gzip(orgfile, comfile); fcom = fopen(comfile,"rb"); if (!fcom) { fprintf(stderr,"Cannot open file: %s\n", comfile); exit(-1); } fseek(fcom,0,2); fin_len = ftell(fcom); rewind(fcom); compress_buf = (char *)malloc(fin_len + 4); if (compress_buf==NULL) { fprintf(stderr, "Out of memory. Need %d\n", fin_len); exit(-1); } numread = fread(compress_buf,1,fin_len,fcom); fclose(fcom); fprintf(stderr,"Compressing %s: %6d bytes -> %6d bytes...\n", cgroup->name, offset, numread); fprintf(stderr,"Compressing ratio = %f\n", ((float)numread/(float)offset)); ndata = write_char(compress_buf, SIZE(numread), fp); free(compress_buf); cgroup->compress_size = numread; return;}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?