src/lib/iconv/euro/utils/gentbl/rewritetbl.c
changeset 470 15a9be57131d
equal deleted inserted replaced
469:0060f3cc1da4 470:15a9be57131d
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 /*
       
    22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       
    23  */
       
    24 
       
    25 #include <stdio.h>
       
    26 #include <stdlib.h>
       
    27 #include <errno.h>
       
    28 #include <sys/fcntl.h>
       
    29 #include <sys/stat.h>
       
    30 
       
    31 int main(int argc, char ** argv) {
       
    32 	char *inbuf;
       
    33 	size_t inbytesleft;
       
    34 	int fd, i;
       
    35 	struct stat s;
       
    36 
       
    37 	if (argc < 2) {
       
    38 		fprintf(stderr, "Usage: %s input\n", argv[0]);
       
    39 		exit(-1);
       
    40 	}
       
    41 	if ((fd = open(argv[1], O_RDONLY)) == -1) {
       
    42 		perror("open");
       
    43 		exit(-2);
       
    44 	}
       
    45 	if (fstat(fd, &s) == -1) {
       
    46 		perror("stat");
       
    47 		exit(-3);
       
    48 	}
       
    49 	inbytesleft = s.st_size;
       
    50 	inbuf = (char *)malloc(inbytesleft);
       
    51 	if (read(fd, inbuf, inbytesleft) != inbytesleft) {
       
    52 		perror("read");
       
    53 		exit(-4);
       
    54 	}
       
    55 	/* Output tbl[] contents. */
       
    56 	for (i = 0; i < s.st_size; i++)
       
    57 		i == s.st_size-1 ?
       
    58 			printf("/* 0x%02X */  {  0x%02X, %d  }\n",  i, \
       
    59 			    (unsigned char) *(inbuf+i), sizeof (*(inbuf+i))) :
       
    60 			printf("/* 0x%02X */  {  0x%02X, %d  },\n", i, \
       
    61 			    (unsigned char) *(inbuf+i), sizeof (*(inbuf+i)));
       
    62 	free(inbuf);
       
    63 	close(fd);
       
    64 }