webengine/wmlengine/src/Unicode/tools/genRanges.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdlib.h>
       
    19 #include <stdio.h>
       
    20 #include <memory.h>
       
    21 
       
    22 void
       
    23 emitRange (long value,
       
    24            long& start,
       
    25            long& previous,
       
    26            long& increment)
       
    27 {
       
    28   if (value != previous + increment) {
       
    29     if (previous == start + increment) {
       
    30       if (start != ~0) {
       
    31 	printf ("  { 0x%08x, 0x%08x, 0x00 },\n", start, start);
       
    32         start = previous;
       
    33       } else {
       
    34         start = value;
       
    35       }
       
    36       increment = value - start;
       
    37     } else {
       
    38       printf ("  { 0x%08x, 0x%08x, 0x%02x },\n", start, previous, increment);
       
    39       start = value;
       
    40       increment = 0;
       
    41     }
       
    42   }
       
    43   previous = value;
       
    44 }
       
    45 
       
    46 int
       
    47 main (int argc,
       
    48       char* argv[])
       
    49 {
       
    50   long start = ~0;
       
    51   long previous = ~0;
       
    52   long increment = 0;
       
    53 
       
    54   while (!feof (stdin)) {
       
    55     char buffer[80];
       
    56     long value;
       
    57     char* endptr;
       
    58 
       
    59     (void) memset (buffer, 0, sizeof buffer);
       
    60     fgets (buffer, 80, stdin);
       
    61     value = strtol (buffer, &endptr, 16);
       
    62     if (endptr == buffer) {
       
    63       break;
       
    64     }
       
    65 
       
    66     if (increment == 0 && start != ~0) {
       
    67       increment = value - start;
       
    68     }
       
    69 
       
    70     emitRange (value, start, previous, increment);
       
    71   }
       
    72 
       
    73   do {
       
    74     emitRange (~0, start, previous, increment);
       
    75   } while (start != ~0);
       
    76 
       
    77   return EXIT_SUCCESS;
       
    78 }