Beispiel #1
0
int main(int argc, char **argv)
{
     
     SymbolTable* symtbl = create_table(SYMTBL_UNIQUE_NAME);
     SymbolTable* reltbl = create_table(SYMTBL_UNIQUE_NAME);

     FILE* input1  = fopen("myinstr.txt", "r");
     FILE* output1 = fopen("res.txt", "w");
     pass_one(input1, output1, symtbl);

     fclose(input1);
     fclose(output1);
     FILE* input2 = fopen("res.txt", "r");
     FILE* output2 = fopen("final.txt", "w");
     
     pass_two(input2, output2,  symtbl, reltbl);
     
     // int ret = translate_inst(stdout, "addu", args,  3 , 0,  tb1, tb2);
     
     printf("symtbl:\n");
     write_table(symtbl, stdout);
     printf("reltbl:\n");
     write_table(reltbl, stdout);

     free_table(symtbl);
     free_table(reltbl);
     
     fclose(input2);
     fclose(output2);
     return 0;
}
Beispiel #2
0
static int acpi_dump_SDT(int fd, struct acpi_rsdp_descriptor *rsdp)
{
	struct acpi_table_header *sdt, *tbl = 0;
	int xsdt = 1, i, num;
	char *offset;
	unsigned long addr;
	if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
		tbl = acpi_map_table(rsdp->xsdt_physical_address, "XSDT");
	}
	if (!tbl && rsdp->rsdt_physical_address) {
		xsdt = 0;
		tbl = acpi_map_table(rsdp->rsdt_physical_address, "RSDT");
	}
	if (!tbl) return 0;
	sdt = malloc(tbl->length);
	memcpy(sdt, tbl, tbl->length);
	acpi_unmap_table(tbl);
	if (checksum((u8 *)sdt, sdt->length))
		fprintf(stderr, "Wrong checksum for %s!\n", (xsdt)?"XSDT":"RSDT");
	num = (sdt->length - sizeof(struct acpi_table_header))/((xsdt)?sizeof(u64):sizeof(u32));
	offset = (char *)sdt + sizeof(struct acpi_table_header);
	for (i = 0; i < num; ++i, offset += ((xsdt) ? sizeof(u64) : sizeof(u32))) {
		addr = (xsdt) ? (unsigned long)(*(u64 *)offset):
				(unsigned long)(*(u32 *)offset);
		if (!addr) continue;
		tbl = acpi_map_table(addr, 0);
		if (!tbl) continue;
		if (!memcmp(tbl->signature, FADT_SIG, 4)) {
			acpi_dump_FADT(fd, tbl, addr);
		} else {
			if (checksum((u8 *)tbl, tbl->length))
				fprintf(stderr, "Wrong checksum for generic table!\n");
			write_table(fd, tbl, addr);
		}
		acpi_unmap_table(tbl);
		if (connect) {
			if (xsdt)
				(*(u64*)offset) = lseek(fd, 0, SEEK_CUR);
			else
				(*(u32*)offset) = lseek(fd, 0, SEEK_CUR);
		}
	}
	if (xsdt) {
		addr = (unsigned long)rsdp->xsdt_physical_address;
		if (connect) {
			rsdp->xsdt_physical_address = lseek(fd, 0, SEEK_CUR);
		}
	} else {
		addr = (unsigned long)rsdp->rsdt_physical_address;
		if (connect) {
			rsdp->rsdt_physical_address = lseek(fd, 0, SEEK_CUR);
		}
	}
	write_table(fd, sdt, addr);
	free (sdt);
	return 1;
}
Beispiel #3
0
/*
Create and write a trie representing the data in 'aTheIndex'
The trie is of two levels, the first level indexed by the high 'aBlockBits' bits of the
character code, the second by the low bits. There is one wrinkle; if the index value, which is 16 bits,
has its top bit set, it is not an index but the actual data value for all entries in that block.

Thus the way to get the value for a code is:

int index = trie_index[code >> aBlockBits];
if (index & 0x8000)
	value = index & ~0x8000;
else
	value = aTrieData[code & (1 << (16 - aBlockBits))];

The data size in bytes is returned.
The argument 'aWrite' determines whether the data is written or not.
The arguments 'aTrie1Name' and 'aTrie2Name' are used as variable names in generated unitable.cpp.
*/
int write_trie(int aOutputEntrySize,int aBlockBits,bool aWrite, int *aTheIndex, int *aTrieData, char *aTrie1Name, char *aTrie2Name)
	{
	int n = 0; // number of entries used in trie_data

	int block_size = 1 << aBlockBits;
	int blocks = 1 << (16 - aBlockBits);

	int* trie_index = new int[blocks];
	int* block = new int[block_size];

	for (int block_index = 0; block_index < blocks; block_index++)
		{
		// Write the data for the current block.
		int block_start = block_index * block_size;
		bool all_the_same = true;
		for (int code = 0; code < block_size; code++)
			{
			block[code] = aTheIndex[block_start + code];
			if (block[code] != block[0])
				all_the_same = false;
			}

		// Try to find a match for it.
		int insert_at;
		if (all_the_same)
			trie_index[block_index] = block[0] | 0x8000;
		else
			{
			for (insert_at = 0; insert_at < n; insert_at++)
				{
				int entries = n - insert_at;
				if (entries > block_size)
					entries = block_size;
				int bytes = entries * sizeof(int);
				if (memcmp(block,aTrieData + insert_at,bytes) == 0)
					break;
				}

			memcpy(aTrieData + insert_at,block,block_size * sizeof(int));
			if (insert_at + block_size > n)
				n = insert_at + block_size;
			trie_index[block_index] = insert_at;
			}
		}

	if (aWrite)
		{
		write_table(trie_index,aTrie1Name,blocks,4,2,false,16,true);
		write_table(aTrieData,aTrie2Name,n,4,aOutputEntrySize,false,32,true);
		}

	delete [] trie_index;
	delete [] block;

	return blocks * 2 + n * aOutputEntrySize;
	}
Beispiel #4
0
static void acpi_dump_FADT(int fd, struct acpi_table_header *tbl, unsigned long xaddr) {
	struct acpi_fadt_descriptor x;
	unsigned long addr;
	size_t len = sizeof(struct acpi_fadt_descriptor);
	if (len > tbl->length) len = tbl->length;
	memcpy(&x, tbl, len);
	x.header.length = len;
	if (checksum((u8 *)tbl, len)) {
		fprintf(stderr, "Wrong checksum for FADT!\n");
	}
	if (x.header.length >= 148 && x.Xdsdt) {
		addr = (unsigned long)x.Xdsdt;
		if (connect) {
			x.Xdsdt = lseek(fd, 0, SEEK_CUR);
		}
	} else if (x.header.length >= 44 && x.dsdt) {
		addr = (unsigned long)x.dsdt;
		if (connect) {
			x.dsdt = lseek(fd, 0, SEEK_CUR);
		}
	} else {
		fprintf(stderr, "No DSDT in FADT!\n");
		goto no_dsdt;
	}
	tbl = acpi_map_table(addr, DSDT_SIG);
	if (!tbl) goto no_dsdt;
	if (checksum((u8 *)tbl, tbl->length))
		fprintf(stderr, "Wrong checksum for DSDT!\n");
	write_table(fd, tbl, addr);
	acpi_unmap_table(tbl);
no_dsdt:
	if (x.header.length >= 140 && x.xfirmware_ctrl) {
		addr = (unsigned long)x.xfirmware_ctrl;
		if (connect) {
			x.xfirmware_ctrl = lseek(fd, 0, SEEK_CUR);
		}
	} else if (x.header.length >= 40 && x.firmware_ctrl) {
		addr = (unsigned long)x.firmware_ctrl;
		if (connect) {
			x.firmware_ctrl = lseek(fd, 0, SEEK_CUR);
		}
	} else {
		fprintf(stderr, "No FACS in FADT!\n");
		goto no_facs;
	}
	tbl = acpi_map_table(addr, FACS_SIG);
	if (!tbl) goto no_facs;
	/* do not checksum FACS */
	write_table(fd, tbl, addr);
	acpi_unmap_table(tbl);
no_facs:
	write_table(fd, (struct acpi_table_header *)&x, xaddr);
}
Beispiel #5
0
/* Runs the two-pass assembler. Most of the actual work is done in pass_one()
   and pass_two().
 */
int assemble(const char* in_name, const char* tmp_name, const char* out_name) {
    FILE *src, *dst;
    int err = 0;
    SymbolTable* symtbl = create_table(SYMTBL_UNIQUE_NAME);
    SymbolTable* reltbl = create_table(SYMTBL_NON_UNIQUE);

    if (in_name) {
        printf("Running pass one: %s -> %s\n", in_name, tmp_name);
        if (open_files(&src, &dst, in_name, tmp_name) != 0) {
            free_table(symtbl);
            free_table(reltbl);
            exit(1);
        }

        if (pass_one(src, dst, symtbl) != 0) {
            err = 1;
        }
        close_files(src, dst);
    }

    if (out_name) {
        printf("Running pass two: %s -> %s\n", tmp_name, out_name);
        if (open_files(&src, &dst, tmp_name, out_name) != 0) {
            free_table(symtbl);
            free_table(reltbl);
            exit(1);
        }

        fprintf(dst, ".text\n");
        if (pass_two(src, dst, symtbl, reltbl) != 0) {
            err = 1;
        }
        
        fprintf(dst, "\n.symbol\n");
        write_table(symtbl, dst);

        fprintf(dst, "\n.relocation\n");
        write_table(reltbl, dst);

        close_files(src, dst);
    }
    
    free_table(symtbl);
    free_table(reltbl);
    return err;
}
Beispiel #6
0
static void acpi_dump_dynamic_SSDT(int fd)
{
	struct stat file_stat;
	char filename[256], *ptr;
	DIR *tabledir;
	struct dirent *entry;
	FILE *fp;
	int count, readcount, length;
	struct acpi_table_header table_header, *ptable;

	if (stat(DYNAMIC_SSDT, &file_stat) == -1) {
		/* The directory doesn't exist */
		return;
	}
	tabledir = opendir(DYNAMIC_SSDT);
	if(!tabledir){
		/*can't open the directory */
		return;
         }

	while ((entry = readdir(tabledir)) != 0){
		/* skip the file of . /.. */
		if (entry->d_name[0] == '.')
			continue;

		sprintf(filename, "%s/%s", DYNAMIC_SSDT, entry->d_name);
		fp = fopen(filename, "r");
		if (fp == NULL) {
			fprintf(stderr, "Can't open the file of %s\n",
						filename);
			continue;
		}
		/* Read the Table header to parse the table length */
		count = fread(&table_header, 1, sizeof(struct acpi_table_header), fp);
		if (count < sizeof(table_header)) {
			/* the length is lessn than ACPI table header. skip it */
			fclose(fp);
			continue;
		}
		length = table_header.length;
		ptr = malloc(table_header.length);
		fseek(fp, 0, SEEK_SET);
		readcount = 0;
		while(!feof(fp) && readcount < length) {
			count = fread(ptr + readcount, 1, 256, fp);
			readcount += count;
		}
		fclose(fp);
		ptable = (struct acpi_table_header *) ptr;
		if (checksum((u8 *) ptable, ptable->length))
			fprintf(stderr, "Wrong checksum "
					"for dynamic SSDT table!\n");
		write_table(fd, ptable, 0);
		free(ptr);
	}
	closedir(tabledir);
	return;
}
Beispiel #7
0
/* breakdown of charges within owning account within product line --
** individual sections very much like ProductSummary, but broken out
** by owning account.
*/
void FormatSubAccountSummary()
{
    NEW_CHARGE *new_chg;
    int count, index;
    int first = TRUE;
    char *owning_acct = NULL;
    
    trace("FormatSubAccountSummary","writing to page structure");
    
    /* reset formatted flag on new charge array */
    mark_unformatted(new_charge_array);

    g_curr_table = COMPONENT_TABLE;
    g_curr_page = PAGE_COMPONENT_SUMMARY;
    
    count = UsesRA(new_charge_array);
    for(index = 0; index <= count; index++) {
	new_chg = (NEW_CHARGE *) RAIndex(new_charge_array, index);
	if ((new_chg->is_formatted) ||
	    (new_chg->type_code == SUMMARY_TYPE) ||
	    (new_chg->type_code == UNIT_CREDIT_TYPE) ||
	    ((arb_num_is_zero (&new_chg->amount))))
	    continue;
    /* first one */
    if (owning_acct == NULL)
	owning_acct = new_chg->account_no_ext;
    else
    /* if they don't match, then print out the previous account */
	if (strcmp(new_chg->account_no_ext, owning_acct) != 0) {
	    if (first) {
		do_new_page();
		LINE_FEED(2);
	        first = FALSE; 
       	    }
	    g_curr_owning = owning_acct;
	    write_table(COMPONENT_TABLE, new_charge_array, component_table);
	    owning_acct = new_chg->account_no_ext; 
	}
    } /* looping through new charges looking for owning acct IDs */

    if ((owning_acct != NULL) && !first) {
      g_curr_owning = owning_acct;
      write_table(COMPONENT_TABLE, new_charge_array, component_table);
    }
}
Beispiel #8
0
int
main(int argc, char ** argv)
{
    if (argc != 4)
        fail ("too few arguments to makeucn");
    read_ucnid (argv[1]);
    read_table (argv[2]);
    read_derived (argv[3]);

    write_copyright ();
    write_table ();
    return 0;
}
Beispiel #9
0
void FormatAccountSummary()
{
    /* write summary charge info */
    g_curr_prod = -1;
    g_curr_page = 0;
    
    trace("FormatSummary","writing to page structure");
    
    /* write payments detail, adjustments detail, other charges detail
    * and new charges summary 
    */

    ARB_NUM_SET_ZERO (&g_table_grand_total);
    do_new_page();
    /* write balance brought forward, payment, adjustment, misc charges */
    write_section_balance_forward();
    write_table(PAYMENTS_TABLE, prev_charge_array, payments_table);
    write_table(ADJUSTMENTS_TABLE, prev_charge_array, adjustments_table);
    write_table(OCC_TABLE, new_charge_array, occ_table);
    g_curr_prod = 0;
    write_table(DISCOUNT_TABLE, new_charge_array, discount_table);
}
Beispiel #10
0
void
write_tables (void)
{
  list *l;
  definition *def;

  f_print (fout, "\n");
  for (l = defined; l != NULL; l = l->next) {
    def = (definition *) l->val;
    if (def->def_kind == DEF_PROGRAM) {
      write_table (def);
    }
  }
}
Beispiel #11
0
int _list_del_record(ALLOC * a, table_t * t, record_t * r)
{
    int changed = 0;
    if (r->prev != 0) {
        if (_record_setnext(a, r->prev, r->next) < 0)
            return -1;
    } else {
        t->head = r->next;
        changed = 1;
    }
    if (r->next != 0) {
        if (_record_setprev(a, r->next, r->prev) < 0)
            return -1;
    } else {
        t->tail = r->prev;
        changed = 1;
    }
    if (changed)
        return write_table(a, t->self, t);
    return 0;
}
Beispiel #12
0
int main()
{
     
     SymbolTable* tb1 = create_table(SYMTBL_UNIQUE_NAME);
     SymbolTable* tb2 = create_table(SYMTBL_UNIQUE_NAME);

     
     add_to_table(tb1, "Loop1", 0x400000);
     add_to_table(tb1, "Loop2", 0xF00000);
     add_to_table(tb1, "Loop3", 0xFF0000);
     add_to_table(tb1, "Loop4", 0xEF0000);
     add_to_table(tb1, "Done:", 0xEE0000);

     char str[255];
     strcpy(str, "Label0");
     
     for(int i = 0; i < 100; i++) {
	  str[5] = i;
	  add_to_table(tb1, str, 0xEFFF00);
	  add_to_table(tb2, str, 0xFFFFFF00);
     }
     
     write_table(tb1, stdout);
     
     int64_t res = get_addr_for_symbol(tb1, "Done:");

     if(res != -1) {
	  printf("Find symbol: addr: %lld\n", res);
     }
     else {
	  printf("No symbol in Table\n");	  
     }
     
     
     free_table(tb1);
     free_table(tb2);
     
     return 0;
}
Beispiel #13
0
static void write_variable( Transport *tpt, lua_State *L, int var_index )
{
  int stack_at_start = lua_gettop( L );
  
  switch( lua_type( L, var_index ) )
  {
    case LUA_TNUMBER:
      transport_write_uint8_t( tpt, RPC_NUMBER );
      transport_write_number( tpt, lua_tonumber( L, var_index ) );
      break;

    case LUA_TSTRING:
    {
      const char *s;
      uint32_t len;
      transport_write_uint8_t( tpt, RPC_STRING );
      s = lua_tostring( L, var_index );
      len = lua_strlen( L, var_index );
      transport_write_uint32_t( tpt, len );
      transport_write_string( tpt, s, len );
      break;
    }

    case LUA_TTABLE:
      transport_write_uint8_t( tpt, RPC_TABLE );
      write_table( tpt, L, var_index );
      transport_write_uint8_t( tpt, RPC_TABLE_END );
      break;

    case LUA_TNIL:
      transport_write_uint8_t( tpt, RPC_NIL );
      break;

    case LUA_TBOOLEAN:
      transport_write_uint8_t( tpt,RPC_BOOLEAN );
      transport_write_uint8_t( tpt, ( uint8_t )lua_toboolean( L, var_index ) );
      break;

    case LUA_TFUNCTION:
      transport_write_uint8_t( tpt, RPC_FUNCTION );
      write_function( tpt, L, var_index );
      transport_write_uint8_t( tpt, RPC_FUNCTION_END );
      break;

    case LUA_TUSERDATA:
      if( lua_isuserdata( L, var_index ) && ismetatable_type( L, var_index, "rpc.helper" ) )
      {
        transport_write_uint8_t( tpt, RPC_REMOTE );
        helper_remote_index( ( Helper * )lua_touserdata( L, var_index ) );        
      } else
        luaL_error( L, "userdata transmission unsupported" );
      break;

    case LUA_TTHREAD:
      luaL_error( L, "thread transmission unsupported" );
      break;

    case LUA_TLIGHTUSERDATA:
      luaL_error( L, "light userdata transmission unsupported" );
      break;
  }
  MYASSERT( lua_gettop( L ) == stack_at_start );
}
Beispiel #14
0
int main(int argc, char *argv[])
{
	FILE			*fp;
	unsigned long	time;
	unsigned long	addr;
	unsigned long	data;
	unsigned long	sel;
	char			module[256];
	char			buf[256];
	char			c;
	
	if ( argc < 2 )
	{
		return 1;
	}
	
	// 初期値読み込み
	if ( argc >= 3 )
	{
		if ( (fp = fopen(argv[2], "r")) == NULL )
		{
			return 1;
		}
		
		addr = 0;
		while ( fgets(buf, sizeof(buf), fp) != NULL )
		{
			if ( sscanf(buf, "%lx", &data) != 1 )
			{
				break;
			}
			table_valid[table_num] = 0xf;
			table_addr[table_num]  = addr;
			table_data[table_num]  = data;
			table_num++;
			addr += 4;
		}
		
		fclose(fp);
	}
	
	
	// チェック
	if ( (fp = fopen(argv[1], "r")) == NULL )
	{
		return 1;
	}
	while ( fgets(buf, sizeof(buf), fp) != NULL )
	{
		if ( sscanf(buf, "%ld %s %c %lx %lx %lx", &time, &module, &c, &addr, &data, &sel) != 6 )
		{
			printf("%s", buf);
		}
		
		if ( addr >= 0xf0000000 ) continue;

		if ( c == 'w' )
		{
			write_table(addr, data, sel);
		}
		else if ( c == 'r' )
		{
			if ( !read_table(addr, data, sel) )
			{
				printf("%s", buf);
			}
		}
	}

	return 0;
}
Beispiel #15
0
void FormatProductSummary()
{
  FORMAT_PRODUCTS_REC *prodptr;
  int i=0;
  char *money;

  trace("FormatProductSummary","writing to page structure");

  /* reset formatted flag on OCC array */
  mark_unformatted(new_charge_array);

  /* for each product, do RC, NRC, USAGE, DISCOUNT, and TAXES tables */
  for( i=0; i<=UsesRA(format_products_rec_array); i++)
  {
    prodptr = (FORMAT_PRODUCTS_REC *) RAIndex(format_products_rec_array, i);
    
    g_curr_prod = prodptr->product_line_id;
    ARB_NUM_SET_ZERO (&g_table_grand_total);
    /* supress automatic page handling on first page */
    g_curr_page = 0;
    if (/* bpr_table(new_charge_array, TABLE_COUNT) || all RCs are in rc_table */
	rc_table(new_charge_array, TABLE_COUNT) ||
	nrc_table(new_charge_array, TABLE_COUNT) ||
	usage_table(new_charge_array, TABLE_COUNT)) {
      do_new_page();
      LINE_FEED(2);
      write_product_header(g_curr_page, g_curr_prod); 
      /* enable automatic page handling */
      g_curr_page = PAGE_ACTIVITY_SUMMARY;
      /* write_table(BPR_TABLE, new_charge_array, bpr_table); all RCs are in rc_table */
      write_table(RC_TABLE, new_charge_array, rc_table);
      write_table(NRC_TABLE, new_charge_array, nrc_table);
      write_table(USAGE_TABLE, new_charge_array, usage_table);

      /* write the line if we've printed a table so far and we're 
       * going to be printing another table on the page
       */
      if ((!arb_num_is_zero (&g_table_grand_total)) && 
	  (discount_table(new_charge_array, TABLE_COUNT))) {
        safe_line_feed(3);
	put_bill_rectangle(COL_TABLE_RECT, 
				  TINY_AMOUNT_YOU_PAY_RECT, MONEY_ADJUST);
        put_bill_markup(get_markup(MARKUP_SUBTOTAL_NEW_CHARGES));
	LINE_FEED(-1);
	ALIGN(ALEFT);
        putf_bill(COL_TABLE_TOTAL,get_field(SUBTOTAL_NEW_CHARGES),
	    get_product_line_desc(prodptr->product_line_id));
	money=format_money(&g_table_grand_total,DOLLAR_SIGN,NULL,MINUS_POS, bill_inv.currency);
	flush_right(money);

	SET_CURRENCY(bill_inv.currency);

	set_generic_text(BOLD_FIXED, money);
	MONEY_put_bill(COL_TABLE_AMOUNT, get_generic(BOLD_FIXED), VOL);
	ALIGN(ALEFT);
        safe_line_feed(2);
      }
      
      write_table(DISCOUNT_TABLE, new_charge_array, discount_table);

      /* page footer */
      safe_line_feed(3);
      put_bill_rectangle(COL_TABLE_RECT, 
				TINY_AMOUNT_YOU_PAY_RECT, MONEY_ADJUST);
      put_bill_markup(get_markup(MARKUP_NET_NEW_CHARGES));
      LINE_FEED(-1);
      ALIGN(ALEFT);
      putf_bill(COL_TABLE_TOTAL, get_field(NET_NEW_CHARGES), 
	       get_product_line_desc(prodptr->product_line_id));
      money=format_money(&g_table_grand_total,DOLLAR_SIGN,NULL,MINUS_POS, bill_inv.currency);
      flush_right(money);

      SET_CURRENCY(bill_inv.currency);

      set_generic_text(BOLD_FIXED, money);
      ALIGN(AMONEY);
      put_bill(COL_TABLE_AMOUNT, get_generic(BOLD_FIXED), VOL);
      ALIGN(ALEFT);
    }
  }
  g_curr_page = 0;
}
Beispiel #16
0
// Write the output file.
void write_output()
	{
	int data_bytes = 0;

	// Write the comment at the top of the file
	fprintf(output_file, "// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).\n");
	fprintf(output_file, "// All rights reserved.\n");
	fprintf(output_file, "// This component and the accompanying materials are made available\n");
	fprintf(output_file, "// under the terms of the License \"Eclipse Public License v1.0\"\n");
	fprintf(output_file, "// which accompanies this distribution, and is available\n");
	fprintf(output_file, "// at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n");
	fprintf(output_file, "//\n");
	fprintf(output_file, "// Initial Contributors:\n");
	fprintf(output_file, "// Nokia Corporation - initial contribution.\n");
	fprintf(output_file, "//\n");
	fprintf(output_file, "// Contributors:\n");
	fprintf(output_file, "//\n");
	fprintf(output_file, "// Description:\n");

	fprintf(output_file,
			"// Unicode character information tables.\n"
			"// Written by the READTYPE program.\n"
			"// Please read the 'Unicode Character Data and Line Break data Update History.doc' file for detailed history of updates to this file.\n"
			"// This file was generated by the READTYPE tool using UCD 5.0.\n"
			"// The contents of this file were generated automatically. Please do not edit this manually.\n"
			"//\n"
			"//\n"
			"\n");

	// Write the directive to include the header file.
	fprintf(output_file,"#include <unicode.h>\n\n");

	// Export two variables for unicode.cpp.
	fprintf(output_file, "\n");
	fprintf(output_file, "// Declarations for tables held in unitable.cpp and used by unicode.cpp.\n");
	fprintf(output_file, "extern const TStandardUnicodeDataSet TheStandardUnicodeDataSet[];\n");
	fprintf(output_file, "extern const TUnicodePlane ThePlanes[17];\n\n\n");

	// Write the trie data.
	data_bytes += write_trie();

	// Write the character information table.
	fprintf(output_file,"static const TUnicodeData TheUnicodeData[] =\n\t{ // %d entries\n", Datas);
	int i;
	for (i = 0; i < Datas; i++)
		{
		fputc('\t',output_file);
		TheData[i].Write();
		if (i < Datas - 1)
			fputc(',',output_file);
		fprintf(output_file, "\t// 0x%X (%d)", i, i);
		fputc('\n',output_file);
		}
	fprintf(output_file,"\t};\n\n");
	data_bytes += Datas * sizeof(Data);

	// write plane properties
	fprintf(output_file, "const TUnicodePlane ThePlanes[%d] =\n\t{\n", PlaneCount);
	int plane;
	for (plane=0; plane<=16; plane++)
		{
		fprintf(output_file, "\t{%d, 0x%04X, 0x%04X }",
			ThePlanesInReadType[plane].iCodesPerBlock, ThePlanesInReadType[plane].iMaskForBlock, ThePlanesInReadType[plane].iMaskForCodePoint);
		if (plane < 16)
			fprintf(output_file, ",\n");
		}
	fprintf(output_file, "\n\t};\n\n");
	data_bytes += 5*PlaneCount;

	// Write a data structure referring to the trie data.
	fprintf(output_file,"const TStandardUnicodeDataSet TheStandardUnicodeDataSet[] =\n\t{ // %d entries\n", PlaneCount);
	for (plane=0; plane<=16; plane++)
		{
		fprintf(output_file,"\t{ ThePlane%02dTrieIndex1, ThePlane%02dTrieIndex2, TheUnicodeData }", plane, plane);
		if (plane < 16)
			fprintf(output_file, ",\n");
		}
	fprintf(output_file, "\n\t};\n\n");
	data_bytes += 12*PlaneCount;

	// Convert the fold table to lower case.
	for (i = 0; i < 256; i++)
		FoldTable[i] = LowerCaseTable[FoldTable[i]];

	// Make 00A0 (non-break space) fold to space.
	FoldTable[0xA0] = 0x20;

	// Make unassigned characters in the CJK width fold table fold to themselves.
	for (i = 0; i < 256; i++)
		if (CjkWidthFoldTable[i] == 0)
			CjkWidthFoldTable[i] = (TUint16)(0xFF00 + i);

	// Write the special tables
	data_bytes += write_table(FoldTable,"TUnicode::FoldTable",256,2,2,false,16,true);
	data_bytes += write_table(CjkWidthFoldTable,"TUnicode::CjkWidthFoldTable",256,2,2,false,16,true);

	// Write the number of data bytes at the end of the file.
	fprintf(output_file,"\n// The tables and structures contain %d bytes of data.\n",data_bytes);
	}
Beispiel #17
0
void Write_Hash_Table(Hash_Table *hash_table, FILE *output)
{ write_table(((Table *) hash_table),output); }