From 44bf92b7e6214bf382dee472143cfe3d9dca02b4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 17 Nov 2010 11:19:59 +0000 Subject: [PATCH] 2010-11-17 12:19 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbzebra/pdf417.c * harbour/contrib/hbzebra/code128.c * harbour/contrib/hbzebra/eanupc.c * harbour/contrib/hbzebra/code11.c * harbour/contrib/hbzebra/itf.c * harbour/contrib/hbzebra/datamtrx.c * harbour/contrib/hbzebra/code39.c * harbour/contrib/hbzebra/code93.c * harbour/contrib/hbzebra/codabar.c % added const to all static table declarations and updated code to use const pointers to them. Please remember that memory regions declared as const can be better optimized by compiler during compilation and on some machines also on runtime because can be located in readonly area which is cached in more efficient way. ! fixed some non const declarations for pure "..." strings --- harbour/ChangeLog | 18 ++++++++++++++++++ harbour/contrib/hbzebra/codabar.c | 6 +++--- harbour/contrib/hbzebra/code11.c | 4 ++-- harbour/contrib/hbzebra/code128.c | 13 ++++++------- harbour/contrib/hbzebra/code39.c | 6 +++--- harbour/contrib/hbzebra/code93.c | 10 +++++----- harbour/contrib/hbzebra/datamtrx.c | 8 ++++---- harbour/contrib/hbzebra/eanupc.c | 18 +++++++++--------- harbour/contrib/hbzebra/itf.c | 2 +- harbour/contrib/hbzebra/pdf417.c | 22 +++++++++++----------- 10 files changed, 62 insertions(+), 45 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2e16f62930..d43ee337aa 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,24 @@ The license applies to all entries newer than 2009-04-28. */ +2010-11-17 12:19 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbzebra/pdf417.c + * harbour/contrib/hbzebra/code128.c + * harbour/contrib/hbzebra/eanupc.c + * harbour/contrib/hbzebra/code11.c + * harbour/contrib/hbzebra/itf.c + * harbour/contrib/hbzebra/datamtrx.c + * harbour/contrib/hbzebra/code39.c + * harbour/contrib/hbzebra/code93.c + * harbour/contrib/hbzebra/codabar.c + % added const to all static table declarations and updated + code to use const pointers to them. Please remember that + memory regions declared as const can be better optimized + by compiler during compilation and on some machines also + on runtime because can be located in readonly area which + is cached in more efficient way. + ! fixed some non const declarations for pure "..." strings + 2010-11-17 12:03 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * examples/terminal/trm_srv.prg * examples/terminal/readme.txt diff --git a/harbour/contrib/hbzebra/codabar.c b/harbour/contrib/hbzebra/codabar.c index 8c23947115..90c468284c 100644 --- a/harbour/contrib/hbzebra/codabar.c +++ b/harbour/contrib/hbzebra/codabar.c @@ -55,7 +55,7 @@ #include "hbapierr.h" -static char s_code[] = { +static const char s_code[] = { 0x60, /* 0 */ 0x30, /* 1 */ 0x48, /* 2 */ @@ -79,13 +79,13 @@ static char s_code[] = { static int _codabar_charno( char ch ) { - static char * s_symbols = "-$:/.+ABCD"; + static const char * s_symbols = "-$:/.+ABCD"; if( '0' <= ch && ch <= '9' ) return ch - '0'; else { - char * ptr = strchr( s_symbols, ch ); + const char * ptr = strchr( s_symbols, ch ); if( ptr && *ptr ) return ptr - s_symbols + 10; } diff --git a/harbour/contrib/hbzebra/code11.c b/harbour/contrib/hbzebra/code11.c index 8722725c97..275a691231 100644 --- a/harbour/contrib/hbzebra/code11.c +++ b/harbour/contrib/hbzebra/code11.c @@ -54,7 +54,7 @@ #include "hbapiitm.h" #include "hbapierr.h" -static char s_code[] = { +static const char s_code[] = { 0x10, /* 0 */ 0x11, /* 1 */ 0x12, /* 2 */ @@ -140,7 +140,7 @@ PHB_ZEBRA hb_zebra_create_code11( const char * szCode, HB_SIZE nLen, int iFlags _code11_add( pZebra->pBits, s_code[ 11 ], iFlags, HB_FALSE ); /* start */ csum = ksum = 0; - for( i = 0; i < iLen; i++ ) + for( i = 0; i < iLen; i++ ) { int no = _code11_charno( szCode[ i ] ); _code11_add( pZebra->pBits, s_code[ no ], iFlags, HB_FALSE ); diff --git a/harbour/contrib/hbzebra/code128.c b/harbour/contrib/hbzebra/code128.c index 7bc4a9cc0e..e739e60cc8 100644 --- a/harbour/contrib/hbzebra/code128.c +++ b/harbour/contrib/hbzebra/code128.c @@ -1,4 +1,4 @@ -/* +/* * $Id$ */ @@ -55,7 +55,7 @@ #include "hbapierr.h" -static unsigned short s_code[] = { +static const unsigned short s_code[] = { 00633, /* 00 */ 00663, /* ! ! 01 */ 01463, /* " " 02 */ @@ -159,8 +159,8 @@ static unsigned short s_code[] = { 01675, /* CodB FNC4 CodB 100 */ 01727, /* FNC4 CodA CodA 101 */ 01657, /* FNC1 FNC1 FNC1 102 */ - 00413, /* Start Code A 103 */ - 00113, /* Start Code B 104 */ + 00413, /* Start Code A 103 */ + 00113, /* Start Code B 104 */ 00713}; /* Start Code C 105 */ #define CODESET_A 0 @@ -179,9 +179,8 @@ static unsigned short s_code[] = { static int _code128_charno( char ch, int iCodeSet ) { - if( iCodeSet == CODESET_A ) - { + { if( ch >= ' ' && ch <= '_' ) return ch - ' '; else if( ( unsigned char ) ch <= 31 ) @@ -373,7 +372,7 @@ PHB_ZEBRA hb_zebra_create_code128( const char * szCode, HB_SIZE nLen, int iFlags pZebra->pBits = hb_bitbuffer_create(); csum = pCode[ 0 ]; - for( i = 0; i < iCodeLen; i++ ) + for( i = 0; i < iCodeLen; i++ ) { hb_bitbuffer_cat_int( pZebra->pBits, s_code[ pCode[ i ] ], 11 ); csum += i * pCode[ i ]; diff --git a/harbour/contrib/hbzebra/code39.c b/harbour/contrib/hbzebra/code39.c index 470357317f..b8c5e598de 100644 --- a/harbour/contrib/hbzebra/code39.c +++ b/harbour/contrib/hbzebra/code39.c @@ -57,7 +57,7 @@ /* Usually one character bitmap does not fit into 1 byte, but if we use enough good encoding, we can manage to fit :) [Mindaugas] */ -static HB_UCHAR s_code[] = +static const HB_UCHAR s_code[] = { 0x58, /* 0 */ 0x09, /* 1 */ @@ -105,7 +105,7 @@ static HB_UCHAR s_code[] = static int _code39_charno( char ch ) { - static char * s_symbols = "-. $/+%"; + static const char * s_symbols = "-. $/+%"; if( '0' <= ch && ch <= '9' ) return ch - '0'; @@ -113,7 +113,7 @@ static int _code39_charno( char ch ) return ch - 'A' + 10; else { - char * ptr = strchr( s_symbols, ch ); + const char * ptr = strchr( s_symbols, ch ); if( ptr && *ptr ) return ptr - s_symbols + 36; } diff --git a/harbour/contrib/hbzebra/code93.c b/harbour/contrib/hbzebra/code93.c index 0fa4976f12..1653665213 100644 --- a/harbour/contrib/hbzebra/code93.c +++ b/harbour/contrib/hbzebra/code93.c @@ -55,7 +55,7 @@ #include "hbapierr.h" -static char s_code[] = { +static const char s_code[] = { 0x28, /* 0 */ 0x12, /* 1 */ 0x22, /* 2 */ @@ -107,7 +107,7 @@ static char s_code[] = { static int _code93_charno( char ch ) { - static char * s_symbols = "-. $/+%"; + static const char * s_symbols = "-. $/+%"; if( '0' <= ch && ch <= '9' ) return ch - '0'; @@ -115,10 +115,10 @@ static int _code93_charno( char ch ) return ch - 'A' + 10; else { - char * ptr = strchr( s_symbols, ch ); + const char * ptr = strchr( s_symbols, ch ); if( ptr && *ptr ) return ptr - s_symbols + 36; - } + } return -1; } @@ -166,7 +166,7 @@ PHB_ZEBRA hb_zebra_create_code93( const char * szCode, HB_SIZE nLen, int iFlags csum = 0; ksum = 0; k++; - for( i = 0; i < iLen; i++ ) + for( i = 0; i < iLen; i++ ) { int no = _code93_charno( szCode[ i ] ); if( no >= 0 ) diff --git a/harbour/contrib/hbzebra/datamtrx.c b/harbour/contrib/hbzebra/datamtrx.c index e95cd13fa4..359bd0e178 100644 --- a/harbour/contrib/hbzebra/datamtrx.c +++ b/harbour/contrib/hbzebra/datamtrx.c @@ -92,7 +92,7 @@ typedef struct } DATAMATRIX_SIZE, * PDATAMATRIX_SIZE; -static DATAMATRIX_SIZE s_size[ SIZE_COUNT ] = { +static const DATAMATRIX_SIZE s_size[ SIZE_COUNT ] = { { 10, 10, 10, 10, 3, 3, 5 }, { 12, 12, 12, 12, 5, 5, 7 }, { 8, 18, 8, 18, 5, 5, 7 }, @@ -178,7 +178,7 @@ static void _reed_solomon_encode( unsigned char * pData, int iDataLen, unsigned } } -static void _datamatrix_reed_solomon( char * pData, PDATAMATRIX_SIZE pSize ) +static void _datamatrix_reed_solomon( char * pData, const DATAMATRIX_SIZE * pSize ) { int * pPoly, * pExp, * pLog; int i, j, iBits, iMod, iPoly, iECLen, iIndex, iBlocks; @@ -325,7 +325,7 @@ static void _datamatrix_place_d( int * pArr, int iPRow, int iPCol, int iIndex ) _datamatrix_place_bit( pArr, iPRow, iPCol, 1, iPCol - 1, ( iIndex << 3 ) + 0 ); } -static void _datamatrix_do_placement( PHB_BITBUFFER pBits, char * pCW, PDATAMATRIX_SIZE pSize ) +static void _datamatrix_do_placement( PHB_BITBUFFER pBits, char * pCW, const DATAMATRIX_SIZE * pSize ) { int * pArr; int i, iR, iC, iPRow, iPCol; @@ -403,7 +403,7 @@ static void _datamatrix_do_placement( PHB_BITBUFFER pBits, char * pCW, PDATAMATR PHB_ZEBRA hb_zebra_create_datamatrix( const char * szCode, HB_SIZE nLen, int iFlags ) { PHB_ZEBRA pZebra; - PDATAMATRIX_SIZE pSize; + const DATAMATRIX_SIZE * pSize; char * pCW; int i, j, iDataCount, iErrorSize, iLen = ( int ) nLen; diff --git a/harbour/contrib/hbzebra/eanupc.c b/harbour/contrib/hbzebra/eanupc.c index 8addabf38b..7083a93588 100644 --- a/harbour/contrib/hbzebra/eanupc.c +++ b/harbour/contrib/hbzebra/eanupc.c @@ -56,16 +56,16 @@ /* we do not store L-code, but just to bit inversion R-code to obtain it */ -static char s_first[] = { 0x00, 0x34, 0x2C, 0x1C, 0x32, 0x26, 0x0E, 0x2A, 0x1A, 0x16 }; -static char s_rcode[] = { 0x27, 0x33, 0x1B, 0x21, 0x1D, 0x39, 0x05, 0x11, 0x09, 0x17 }; -static char s_gcode[] = { 0x72, 0x66, 0x6C, 0x42, 0x5C, 0x4E, 0x50, 0x44, 0x48, 0x74 }; /* reversion of R-code */ +static const char s_first[] = { 0x00, 0x34, 0x2C, 0x1C, 0x32, 0x26, 0x0E, 0x2A, 0x1A, 0x16 }; +static const char s_rcode[] = { 0x27, 0x33, 0x1B, 0x21, 0x1D, 0x39, 0x05, 0x11, 0x09, 0x17 }; +static const char s_gcode[] = { 0x72, 0x66, 0x6C, 0x42, 0x5C, 0x4E, 0x50, 0x44, 0x48, 0x74 }; /* reversion of R-code */ static char _ean13_checksum( const char * szCode ) { int i, sum = 0; - - for ( i = 0; i < 12; i++ ) + + for ( i = 0; i < 12; i++ ) sum += ( szCode[ i ] - '0' ) * ( i & 1 ? 3 : 1 ); return '0' + ( 10000 - sum ) % 10; } @@ -73,8 +73,8 @@ static char _ean13_checksum( const char * szCode ) static char _ean8_checksum( const char * szCode ) { int i, sum = 0; - - for ( i = 0; i < 7; i++ ) + + for ( i = 0; i < 7; i++ ) sum += ( szCode[ i ] - '0' ) * ( i & 1 ? 1 : 3 ); return '0' + ( 10000 - sum ) % 10; } @@ -82,8 +82,8 @@ static char _ean8_checksum( const char * szCode ) static char _upca_checksum( const char * szCode ) { int i, sum = 0; - - for ( i = 0; i < 11; i++ ) + + for ( i = 0; i < 11; i++ ) sum += ( szCode[ i ] - '0' ) * ( i & 1 ? 1 : 3 ); return '0' + ( 10000 - sum ) % 10; } diff --git a/harbour/contrib/hbzebra/itf.c b/harbour/contrib/hbzebra/itf.c index 9b6f24d93c..6ccc70cb00 100644 --- a/harbour/contrib/hbzebra/itf.c +++ b/harbour/contrib/hbzebra/itf.c @@ -55,7 +55,7 @@ #include "hbapierr.h" -static char s_code[] = { 0x0C, 0x11, 0x12, 0x03, 0x14, 0x05, 0x06, 0x18, 0x09, 0x0A }; +static const char s_code[] = { 0x0C, 0x11, 0x12, 0x03, 0x14, 0x05, 0x06, 0x18, 0x09, 0x0A }; static char _itf_checksum( const char * szCode ) { diff --git a/harbour/contrib/hbzebra/pdf417.c b/harbour/contrib/hbzebra/pdf417.c index c63a5224de..419cebadc4 100644 --- a/harbour/contrib/hbzebra/pdf417.c +++ b/harbour/contrib/hbzebra/pdf417.c @@ -91,7 +91,7 @@ #define MAX_CODEWORD_COUNT 928 -static short s_code[ 3 ][ 929 ] = { +static const short s_code[ 3 ][ 929 ] = { { 0x03AB, 0x0F57, 0x3EAF, 0x072B, 0x1E57, 0x7CAF, 0x0315, 0x0E2B, 0x0615, 0x020A, 0x0C15, 0x040A, 0x03B5, 0x0F6B, 0x3ED7, 0x0735, @@ -447,29 +447,29 @@ static short s_code[ 3 ][ 929 ] = { 0x69C0, 0x6DE0, 0x2BE1, 0x4BE1, 0x29E0, 0x2DF0, 0x49E0, 0x4DF0, 0x57E3 }}; -static unsigned short s_rs0[] = { +static const unsigned short s_rs0[] = { 27, 917 }; -static unsigned short s_rs1[] = { +static const unsigned short s_rs1[] = { 522, 568, 723, 809 }; -static unsigned short s_rs2[] = { +static const unsigned short s_rs2[] = { 237, 308, 436, 284, 646, 653, 428, 379 }; -static unsigned short s_rs3[] = { +static const unsigned short s_rs3[] = { 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65 }; -static unsigned short s_rs4[] = { +static const unsigned short s_rs4[] = { 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, 273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410 }; -static unsigned short s_rs5[] = { +static const unsigned short s_rs5[] = { 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612, 723, 476, 462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31, 460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, 733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, 623, 264, 543 }; -static unsigned short s_rs6[] = { +static const unsigned short s_rs6[] = { 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415, 822, 93, 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704, 516, 258, 457, 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, @@ -479,7 +479,7 @@ static unsigned short s_rs6[] = { 157, 374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550, 86, 801, 4, 108, 539 }; -static unsigned short s_rs7[] = { +static const unsigned short s_rs7[] = { 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720, 858, 194, 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757, 710, 814, 919, 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, @@ -497,7 +497,7 @@ static unsigned short s_rs7[] = { 609, 829, 189, 20, 167, 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, 55, 497, 10 }; -static unsigned short s_rs8[] = { +static const unsigned short s_rs8[] = { 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492, 197, 265, 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520, 435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, @@ -1180,7 +1180,7 @@ static int _pdf417_encode( const char * szCode, int iLen, int * pCW ) static void _pdf417_reed_solomon( int * pCW, int iLen, int iLevel ) { int * pEC; - unsigned short * coef; + const unsigned short * coef; int i, j, iM, iECLen; iECLen = _pdf417_ec_size( iLevel );