| 1 | /******************************************************************** |
|---|
| 2 | * makeSymTbl.c |
|---|
| 3 | * - symbol.txt -> DMW_SymTbl.c |
|---|
| 4 | * |
|---|
| 5 | * Copyright (c)2004 Digital STREAM Tech, Inc. |
|---|
| 6 | * All Rights Reserved |
|---|
| 7 | * |
|---|
| 8 | * $Id: makeSymTbl.c,v 1.1 2011/07/08 03:12:19 megakiss Exp $ |
|---|
| 9 | * |
|---|
| 10 | *********************************************************************/ |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include <string.h> |
|---|
| 13 | #include <stdlib.h> |
|---|
| 14 | /* symbol types */ |
|---|
| 15 | #define SYM_UNDF 0x0 /* undefined */ |
|---|
| 16 | #define SYM_LOCAL 0x0 /* local */ |
|---|
| 17 | #define SYM_GLOBAL 0x1 /* global (external) (ORed) */ |
|---|
| 18 | #define SYM_ABS 0x2 /* absolute */ |
|---|
| 19 | #define SYM_TEXT 0x4 /* text */ |
|---|
| 20 | #define SYM_DATA 0x6 /* data */ |
|---|
| 21 | #define SYM_BSS 0x8 /* bss */ |
|---|
| 22 | #define SYM_COMM 0x12 /* common symbol */ |
|---|
| 23 | |
|---|
| 24 | #define MAX_EXCEPT_LIST 10000 |
|---|
| 25 | static char exclude_list[MAX_EXCEPT_LIST][256]; |
|---|
| 26 | |
|---|
| 27 | static char* GetExceptionFileName(char* strFileName) |
|---|
| 28 | { |
|---|
| 29 | char strBuff[1024]; |
|---|
| 30 | int i = strlen(strFileName); |
|---|
| 31 | static char strExceptionFileName[1024]; |
|---|
| 32 | |
|---|
| 33 | sprintf(strBuff, "%s", strFileName); |
|---|
| 34 | for (; i >= 0; i--) |
|---|
| 35 | { |
|---|
| 36 | if (strBuff[i] == '/') break; |
|---|
| 37 | strBuff[i] = 0; |
|---|
| 38 | } |
|---|
| 39 | sprintf(strExceptionFileName, "%s" "exclude_list.txt", strBuff); |
|---|
| 40 | return strExceptionFileName; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | const char * ConvertSymType(char * type) |
|---|
| 44 | { |
|---|
| 45 | switch (type[0]) |
|---|
| 46 | { |
|---|
| 47 | case 'T': |
|---|
| 48 | return "SYM_GLOBAL|SYM_TEXT"; |
|---|
| 49 | case 'D': |
|---|
| 50 | return "SYM_GLOBAL|SYM_DATA"; |
|---|
| 51 | case 'A': |
|---|
| 52 | return "SYM_GLOBAL|SYM_ABS"; |
|---|
| 53 | case 'B': |
|---|
| 54 | return "SYM_GLOBAL|SYM_BSS"; |
|---|
| 55 | case 'C': |
|---|
| 56 | return "SYM_GLOBAL|SYM_COMM"; |
|---|
| 57 | } |
|---|
| 58 | return "SYM_UNDF"; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | int get_line_num_of_file(FILE *fp) |
|---|
| 62 | { |
|---|
| 63 | int c; |
|---|
| 64 | long cnt=0; |
|---|
| 65 | while ((c=getc(fp))!=EOF) if (c=='\n') cnt++; |
|---|
| 66 | rewind(fp); |
|---|
| 67 | printf("%ld lines\n",cnt); |
|---|
| 68 | return cnt; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | int make_header(FILE *out_fp) |
|---|
| 72 | { |
|---|
| 73 | // fprintf(out_fp,"/********************************************************************\n"); |
|---|
| 74 | // fprintf(out_fp,"* DMW_SymTbl.c\n"); |
|---|
| 75 | // fprintf(out_fp,"* - This file is automatically generated at compile time.\n"); |
|---|
| 76 | // fprintf(out_fp,"* Do not Edit manually!!!\n"); |
|---|
| 77 | // fprintf(out_fp,"*\n"); |
|---|
| 78 | // fprintf(out_fp,"* Copyright (c)2004 Digital STREAM Tech, Inc.\n"); |
|---|
| 79 | // fprintf(out_fp,"* All Rights Reserved\n"); |
|---|
| 80 | // fprintf(out_fp,"*\n"); |
|---|
| 81 | // fprintf(out_fp,"* $Id: makeSymTbl.c,v 1.1 2011/07/08 03:12:19 megakiss Exp $\n"); |
|---|
| 82 | // fprintf(out_fp,"*\n"); |
|---|
| 83 | // fprintf(out_fp,"*********************************************************************/\n"); |
|---|
| 84 | // fprintf(out_fp,"\n\n"); |
|---|
| 85 | fprintf(out_fp,"#include \"DMW_SymTbl.h\"\n"); |
|---|
| 86 | return 0; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | int make_tail(FILE *out_fp) |
|---|
| 90 | { |
|---|
| 91 | fprintf(out_fp,"\n\n"); |
|---|
| 92 | // fprintf(out_fp,"/*************************************************************\n"); |
|---|
| 93 | // fprintf(out_fp,"*************************************************************/\n"); |
|---|
| 94 | return 0; |
|---|
| 95 | |
|---|
| 96 | } |
|---|
| 97 | int check_inlucde_dot_in_symbol(char *string) |
|---|
| 98 | { |
|---|
| 99 | int ret=0; |
|---|
| 100 | register char *s,*t; |
|---|
| 101 | s=string; |
|---|
| 102 | if(*s==0) |
|---|
| 103 | return 0; |
|---|
| 104 | t=s+strlen(s) -1; |
|---|
| 105 | while(t>s){ |
|---|
| 106 | if((*t)=='.'||(*t)=='~'){ |
|---|
| 107 | ret=1; |
|---|
| 108 | // printf("[INFO] found . string=%s\n",string); |
|---|
| 109 | break; |
|---|
| 110 | } |
|---|
| 111 | t--; |
|---|
| 112 | } |
|---|
| 113 | return ret; |
|---|
| 114 | } |
|---|
| 115 | //string is input/output |
|---|
| 116 | void get_demangle_symbol(char *string) |
|---|
| 117 | { |
|---|
| 118 | register char *s,*t; |
|---|
| 119 | s=string; |
|---|
| 120 | if(*s==0) |
|---|
| 121 | return ; |
|---|
| 122 | t=s+strlen(s)-1; |
|---|
| 123 | while(t>s){ |
|---|
| 124 | if((*t)==':'){ |
|---|
| 125 | (*t)='_'; |
|---|
| 126 | } |
|---|
| 127 | if((*t)=='('){ |
|---|
| 128 | (*t)='\0'; |
|---|
| 129 | } |
|---|
| 130 | t--; |
|---|
| 131 | } |
|---|
| 132 | return ; |
|---|
| 133 | // return s; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | int main(int argc, char *argv[]) |
|---|
| 137 | { |
|---|
| 138 | printf("%d", argc); |
|---|
| 139 | FILE *out_fp; |
|---|
| 140 | FILE *in_fp; |
|---|
| 141 | char address[200],type[2],symbolname[200]; |
|---|
| 142 | char *symbol; |
|---|
| 143 | int line_num; |
|---|
| 144 | int tem_line_num; |
|---|
| 145 | int i, k, flag; |
|---|
| 146 | |
|---|
| 147 | int exclude_list_count = 0; |
|---|
| 148 | FILE *exclude_fp; |
|---|
| 149 | |
|---|
| 150 | in_fp=fopen(argv[1]/*IN_NM_FILE_NAME*/,"r"); |
|---|
| 151 | out_fp=fopen(argv[2]/*(OUT_SYMBOL_TABLE_FILE_NAME*/,"w"); |
|---|
| 152 | if(in_fp==NULL){ |
|---|
| 153 | printf("[Error] Can't open symbol input file \n"); |
|---|
| 154 | return -1; |
|---|
| 155 | } |
|---|
| 156 | if(out_fp==NULL){ |
|---|
| 157 | printf("[Error] Can't open symbol output file \n"); |
|---|
| 158 | return -1; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | make_header(out_fp); |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | // ¿¹¿Ü ¸®½ºÆ®¸¦ ±¸¼ºÇÑ´Ù. |
|---|
| 165 | exclude_fp = fopen(GetExceptionFileName(argv[0]), "rt"); |
|---|
| 166 | while (1) |
|---|
| 167 | { |
|---|
| 168 | if (fscanf(exclude_fp, "%s", exclude_list[exclude_list_count]) < 1) break; |
|---|
| 169 | exclude_list_count++; |
|---|
| 170 | if (exclude_list_count >= MAX_EXCEPT_LIST) break; |
|---|
| 171 | } |
|---|
| 172 | fclose(exclude_fp); |
|---|
| 173 | printf("found %d exclude lists\n", exclude_list_count); |
|---|
| 174 | //¿©±â¿¡¼ º»¹® ¸¸µç´Ù. |
|---|
| 175 | line_num=get_line_num_of_file(in_fp); |
|---|
| 176 | tem_line_num=line_num; |
|---|
| 177 | |
|---|
| 178 | for(i=0;i<line_num;i++){ |
|---|
| 179 | fscanf(in_fp,"%s %s %s",address,type,symbolname); |
|---|
| 180 | flag = 0; |
|---|
| 181 | #ifdef USE_CYGWIN |
|---|
| 182 | symbol = &symbolname[1]; |
|---|
| 183 | #else |
|---|
| 184 | symbol = symbolname; |
|---|
| 185 | #endif |
|---|
| 186 | |
|---|
| 187 | // ¹®ÀÚ¿¾È¿¡ __ À̳ª $$°¡ ÀÖ´Ù¸é ¹«½ÃÇÏÀÚ |
|---|
| 188 | // 2010.6.24 megakiss |
|---|
| 189 | { |
|---|
| 190 | int nloop = 0; |
|---|
| 191 | if (symbol[nloop] == '_') flag = 1; |
|---|
| 192 | if (symbol[nloop] == 'p'&& symbol[nloop+1] == 'z' && symbol[nloop+2] == '_') flag = 1; |
|---|
| 193 | if (symbol[nloop] == 'F'&& symbol[nloop+1] == 'C' && symbol[nloop+2] == '_') flag = 1; |
|---|
| 194 | if (symbol[nloop] == 'F'&& symbol[nloop+1] == 'T' && symbol[nloop+2] == '_') flag = 1; |
|---|
| 195 | for (nloop =0; nloop < strlen(symbol) - 1; nloop++) |
|---|
| 196 | { |
|---|
| 197 | if (symbol[nloop] == '@') flag = 1; |
|---|
| 198 | if (symbol[nloop] == '_' && symbol[nloop+1] == '_') flag = 1; |
|---|
| 199 | if (symbol[nloop] == '$' && symbol[nloop+1] == '$') flag = 1; |
|---|
| 200 | if (symbol[nloop] == '3'&& symbol[nloop+1] == '2' && symbol[nloop+2] == '0') flag = 1; |
|---|
| 201 | if (flag == 1) break; |
|---|
| 202 | } |
|---|
| 203 | if (flag) |
|---|
| 204 | { |
|---|
| 205 | printf("%s removed\n", symbol); |
|---|
| 206 | } |
|---|
| 207 | else |
|---|
| 208 | { |
|---|
| 209 | //printf("%s pass\n", symbol); |
|---|
| 210 | } |
|---|
| 211 | if (flag) continue; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | for (k=0; k < exclude_list_count; k++) { |
|---|
| 215 | if ( strcmp(symbol, exclude_list[k]) == 0 ) { |
|---|
| 216 | flag = 1; |
|---|
| 217 | break; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | if ( flag ) |
|---|
| 221 | continue; |
|---|
| 222 | |
|---|
| 223 | //fprintf(out_fp,"extern %s;\n",symbol); |
|---|
| 224 | if(!check_inlucde_dot_in_symbol(symbol)){ |
|---|
| 225 | fprintf(out_fp,"extern int %s;\n",symbol); |
|---|
| 226 | } |
|---|
| 227 | } |
|---|
| 228 | rewind(in_fp); |
|---|
| 229 | |
|---|
| 230 | fprintf(out_fp,"DMW_SYMBOL_T DMW_SymbolTbl[]={\n"); |
|---|
| 231 | for(i=0;i<line_num;i++){ |
|---|
| 232 | fscanf(in_fp,"%s %s %s",address,type,symbolname); |
|---|
| 233 | flag = 0; |
|---|
| 234 | #ifdef USE_CYGWIN |
|---|
| 235 | symbol = &symbolname[1]; |
|---|
| 236 | #else |
|---|
| 237 | symbol = symbolname; |
|---|
| 238 | #endif |
|---|
| 239 | |
|---|
| 240 | // ¹®ÀÚ¿¾È¿¡ __ À̳ª $$°¡ ÀÖ´Ù¸é ¹«½ÃÇÏÀÚ |
|---|
| 241 | // 2010.6.24 megakiss |
|---|
| 242 | { |
|---|
| 243 | int nloop = 0; |
|---|
| 244 | if (symbol[nloop] == '_') flag = 1; |
|---|
| 245 | if (symbol[nloop] == 'p'&& symbol[nloop+1] == 'z' && symbol[nloop+2] == '_') flag = 1; |
|---|
| 246 | if (symbol[nloop] == 'F'&& symbol[nloop+1] == 'C' && symbol[nloop+2] == '_') flag = 1; |
|---|
| 247 | if (symbol[nloop] == 'F'&& symbol[nloop+1] == 'T' && symbol[nloop+2] == '_') flag = 1; |
|---|
| 248 | for (nloop =0; nloop < strlen(symbol) - 1; nloop++) |
|---|
| 249 | { |
|---|
| 250 | if (symbol[nloop] == '@') flag = 1; |
|---|
| 251 | if (symbol[nloop] == '_' && symbol[nloop+1] == '_') flag = 1; |
|---|
| 252 | if (symbol[nloop] == '$' && symbol[nloop+1] == '$') flag = 1; |
|---|
| 253 | if (symbol[nloop] == '3'&& symbol[nloop+1] == '2' && symbol[nloop+2] == '0') flag = 1; |
|---|
| 254 | if (flag == 1) break; |
|---|
| 255 | } |
|---|
| 256 | if (flag) |
|---|
| 257 | { |
|---|
| 258 | printf("%s removed\n", symbol); |
|---|
| 259 | } |
|---|
| 260 | else |
|---|
| 261 | { |
|---|
| 262 | //printf("%s pass\n", symbol); |
|---|
| 263 | } |
|---|
| 264 | if (flag) continue; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | for (k=0; k < exclude_list_count; k++) { |
|---|
| 268 | if ( strcmp(symbol, exclude_list[k]) == 0 ) { |
|---|
| 269 | flag = 1; |
|---|
| 270 | break; |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | if ( flag ) |
|---|
| 274 | continue; |
|---|
| 275 | |
|---|
| 276 | if(check_inlucde_dot_in_symbol(symbol)){ |
|---|
| 277 | if(tem_line_num>0) |
|---|
| 278 | tem_line_num--; |
|---|
| 279 | }else{ |
|---|
| 280 | fprintf(out_fp,"\t{\"%s\", (char*) &%s , %s},\n",symbol,symbol,ConvertSymType(type)); |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | //°Á¦·Î ¸¶Áö¸· ÀÎÀÚ¸¦ ³Ö¾îÁØ´Ù. |
|---|
| 284 | line_num +=1; //null |
|---|
| 285 | line_num = line_num -tem_line_num; |
|---|
| 286 | fprintf(out_fp,"\t{(char*) 0, (char*) 0, 0},\n"); |
|---|
| 287 | fprintf(out_fp,"};\n"); |
|---|
| 288 | fprintf(out_fp,"unsigned int DMW_SymbolTblSize = %d;\n\n",line_num); |
|---|
| 289 | make_tail(out_fp); |
|---|
| 290 | |
|---|
| 291 | fclose(in_fp); |
|---|
| 292 | fclose(out_fp); |
|---|
| 293 | return 0; |
|---|
| 294 | } |
|---|
| 295 | /************************************************************* |
|---|
| 296 | *Change Logs: |
|---|
| 297 | * $Log: makeSymTbl.c,v $ |
|---|
| 298 | * Revision 1.1 2011/07/08 03:12:19 megakiss |
|---|
| 299 | * *** empty log message *** |
|---|
| 300 | * |
|---|
| 301 | * Revision 1.4.4.5 2010/08/30 23:55:02 megakiss |
|---|
| 302 | * *** empty log message *** |
|---|
| 303 | * |
|---|
| 304 | * Revision 1.4.4.4 2010/06/29 05:03:11 megakiss |
|---|
| 305 | * *** empty log message *** |
|---|
| 306 | * |
|---|
| 307 | * Revision 1.4.4.3 2010/06/24 01:52:53 megakiss |
|---|
| 308 | * *** empty log message *** |
|---|
| 309 | * |
|---|
| 310 | * Revision 1.4.4.2 2010/03/18 08:28:06 megakiss |
|---|
| 311 | * *** empty log message *** |
|---|
| 312 | * |
|---|
| 313 | * Revision 1.4.4.1 2010/03/18 06:41:20 megakiss |
|---|
| 314 | * *** empty log message *** |
|---|
| 315 | * |
|---|
| 316 | * Revision 1.4 2009/07/07 08:13:19 kjkam |
|---|
| 317 | * - ADS ÄÄÆÄÀÏ ¿¡·¯ ¼öÁ¤ |
|---|
| 318 | * |
|---|
| 319 | * Revision 1.3 2009/03/11 23:01:32 hwatk |
|---|
| 320 | * Cygwin¿¡¼ main() ÀÌÀü¿¡ segmentation fault ³ª´Â ¹®Á¦ |
|---|
| 321 | * --> "__xxx symbolÀº exportÇÏÁö ¸»°Í." |
|---|
| 322 | * |
|---|
| 323 | * Revision 1.2 2009/02/23 06:43:59 hwatk |
|---|
| 324 | * libc Ãß°¡½Ã¸¦ À§ÇØ makeSymTbl ¼öÁ¤. |
|---|
| 325 | * |
|---|
| 326 | * Revision 1.1.1.1 2009/01/15 08:04:43 hwatk |
|---|
| 327 | * BASE DSTMW Initial |
|---|
| 328 | * |
|---|
| 329 | * Revision 1.1 2007/02/23 14:01:10 hwatk |
|---|
| 330 | * V0_10 |
|---|
| 331 | * |
|---|
| 332 | * Revision 1.3 2006/08/04 11:55:20 hwatk |
|---|
| 333 | * MW |
|---|
| 334 | * - Autoscan Áß¿¡ VCT/PAT/PMT µ¿½Ã¿¡ ¹Þ´Â ¹æ¾È Àû¿ë. (DMW_USE_CHANNEL_TABLES) |
|---|
| 335 | * - QAM Autodetection Àû¿ë. (USE_QAM_AUTODETECTION) |
|---|
| 336 | * - Analog Autoscan½Ã Full Search Çϵµ·Ï º¯°æ. |
|---|
| 337 | * - Autoscan ½Ã CancelÀÌ Áï½Ã Àû¿ëµÇµµ·Ï º¯°æ. (DMW_SCAN_USE_CANCEL) |
|---|
| 338 | * |
|---|
| 339 | * Revision 1.2 2006/02/14 05:48:37 hwatk |
|---|
| 340 | * *** empty log message *** |
|---|
| 341 | * |
|---|
| 342 | * Revision 1.1 2005/12/30 02:01:17 leon |
|---|
| 343 | * - position change |
|---|
| 344 | * |
|---|
| 345 | * Revision 1.1 2005/12/21 00:43:31 megakiss |
|---|
| 346 | * *** empty log message *** |
|---|
| 347 | * |
|---|
| 348 | * Revision 1.3 2005/07/15 01:13:18 megakiss |
|---|
| 349 | * 2005³â 7¿ù 15ÀÏ |
|---|
| 350 | * |
|---|
| 351 | * EA ¼öÁ¤ - Å×½ºÆ® ÇÊ¿ä |
|---|
| 352 | * ¹Ú±ÔÈ«ÁÖÀÓ ¼öÁ¤»çÇ× ¹Ý¿µ - ÀÚ¼¼ÇÑ ³»¿ë ±â¼ú ÇÊ¿ä |
|---|
| 353 | * ¸ðµç °æ°í ¸Þ½ÃÁö Á¦°Å |
|---|
| 354 | * |
|---|
| 355 | * Revision 1.4 2005/02/17 07:29:13 megakiss |
|---|
| 356 | * ¸ðµç °æ°í ¸Þ½ÃÁö Á¦°Å |
|---|
| 357 | * |
|---|
| 358 | * Revision 1.3 2004/11/26 01:45:09 yzyeo |
|---|
| 359 | * fix array size bug |
|---|
| 360 | * |
|---|
| 361 | * Revision 1.2 2004/10/26 00:07:39 leon |
|---|
| 362 | * - standaloneÀÏ °æ¿ì target shell Ãß°¡ ¹ö±× fix. |
|---|
| 363 | * |
|---|
| 364 | * Revision 1.4 2004/10/23 09:35:24 hwatk |
|---|
| 365 | * Do not add exit, abort symbol. |
|---|
| 366 | * |
|---|
| 367 | * Revision 1.3 2004/08/17 18:01:52 leon |
|---|
| 368 | * - c++ Áö¿ø(SABIN-app) |
|---|
| 369 | * |
|---|
| 370 | * Revision 1.2 2004/08/16 07:55:37 leon |
|---|
| 371 | * -add comment |
|---|
| 372 | * |
|---|
| 373 | * |
|---|
| 374 | *************************************************************/ |
|---|
| 375 | |
|---|