OpenCOBOL 1.1pre-rel
codegen.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006-2009 Roger While
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public License
00006  * as published by the Free Software Foundation; either version 2.1,
00007  * or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; see the file COPYING.LIB.  If not write to
00016  * the Free Software Foundation, 51 Franklin Street, Fifth Floor
00017  * Boston, MA 02110-1301 USA
00018  */
00019 
00020 #ifndef COB_CODEGEN_H
00021 #define COB_CODEGEN_H
00022 
00023 #ifdef  COB_LOCAL_INLINE
00024 #define COB_STATIC      static
00025 #else
00026 #define COB_STATIC
00027 extern int cob_get_numdisp              (const unsigned char *, const size_t);
00028 extern int cob_cmp_packed_int           (const cob_field *, const int);
00029 extern int cob_get_packed_int           (const cob_field *);
00030 extern int cob_add_packed_int           (cob_field *, const int);
00031 
00032 extern int cob_cmp_u8_binary            (const unsigned char *, const int);
00033 extern int cob_cmp_s8_binary            (const unsigned char *, const int);
00034 extern int cob_cmp_u16_binary           (const unsigned char *, const int);
00035 extern int cob_cmp_s16_binary           (const unsigned char *, const int);
00036 extern int cob_cmp_u24_binary           (const unsigned char *, const int);
00037 extern int cob_cmp_s24_binary           (const unsigned char *, const int);
00038 extern int cob_cmp_u32_binary           (const unsigned char *, const int);
00039 extern int cob_cmp_s32_binary           (const unsigned char *, const int);
00040 extern int cob_cmp_u40_binary           (const unsigned char *, const int);
00041 extern int cob_cmp_s40_binary           (const unsigned char *, const int);
00042 extern int cob_cmp_u48_binary           (const unsigned char *, const int);
00043 extern int cob_cmp_s48_binary           (const unsigned char *, const int);
00044 extern int cob_cmp_u56_binary           (const unsigned char *, const int);
00045 extern int cob_cmp_s56_binary           (const unsigned char *, const int);
00046 extern int cob_cmp_u64_binary           (const unsigned char *, const int);
00047 extern int cob_cmp_s64_binary           (const unsigned char *, const int);
00048 
00049 extern int cob_cmp_align_u16_binary     (const unsigned char *, const int);
00050 extern int cob_cmp_align_s16_binary     (const unsigned char *, const int);
00051 extern int cob_cmp_align_u32_binary     (const unsigned char *, const int);
00052 extern int cob_cmp_align_s32_binary     (const unsigned char *, const int);
00053 extern int cob_cmp_align_u64_binary     (const unsigned char *, const int);
00054 extern int cob_cmp_align_s64_binary     (const unsigned char *, const int);
00055 
00056 extern void cob_add_u8_binary           (unsigned char *, const int);
00057 extern void cob_add_s8_binary           (unsigned char *, const int);
00058 extern void cob_add_u16_binary          (unsigned char *, const int);
00059 extern void cob_add_s16_binary          (unsigned char *, const int);
00060 extern void cob_add_u24_binary          (unsigned char *, const int);
00061 extern void cob_add_s24_binary          (unsigned char *, const int);
00062 extern void cob_add_u32_binary          (unsigned char *, const int);
00063 extern void cob_add_s32_binary          (unsigned char *, const int);
00064 extern void cob_add_u40_binary          (unsigned char *, const int);
00065 extern void cob_add_s40_binary          (unsigned char *, const int);
00066 extern void cob_add_u48_binary          (unsigned char *, const int);
00067 extern void cob_add_s48_binary          (unsigned char *, const int);
00068 extern void cob_add_u56_binary          (unsigned char *, const int);
00069 extern void cob_add_s56_binary          (unsigned char *, const int);
00070 extern void cob_add_u64_binary          (unsigned char *, const int);
00071 extern void cob_add_s64_binary          (unsigned char *, const int);
00072 
00073 extern void cob_add_align_u16_binary    (unsigned char *, const int);
00074 extern void cob_add_align_s16_binary    (unsigned char *, const int);
00075 extern void cob_add_align_u32_binary    (unsigned char *, const int);
00076 extern void cob_add_align_s32_binary    (unsigned char *, const int);
00077 extern void cob_add_align_u64_binary    (unsigned char *, const int);
00078 extern void cob_add_align_s64_binary    (unsigned char *, const int);
00079 
00080 extern void cob_sub_u8_binary           (unsigned char *, const int);
00081 extern void cob_sub_s8_binary           (unsigned char *, const int);
00082 extern void cob_sub_u16_binary          (unsigned char *, const int);
00083 extern void cob_sub_s16_binary          (unsigned char *, const int);
00084 extern void cob_sub_u24_binary          (unsigned char *, const int);
00085 extern void cob_sub_s24_binary          (unsigned char *, const int);
00086 extern void cob_sub_u32_binary          (unsigned char *, const int);
00087 extern void cob_sub_s32_binary          (unsigned char *, const int);
00088 extern void cob_sub_u40_binary          (unsigned char *, const int);
00089 extern void cob_sub_s40_binary          (unsigned char *, const int);
00090 extern void cob_sub_u48_binary          (unsigned char *, const int);
00091 extern void cob_sub_s48_binary          (unsigned char *, const int);
00092 extern void cob_sub_u56_binary          (unsigned char *, const int);
00093 extern void cob_sub_s56_binary          (unsigned char *, const int);
00094 extern void cob_sub_u64_binary          (unsigned char *, const int);
00095 extern void cob_sub_s64_binary          (unsigned char *, const int);
00096 
00097 extern void cob_sub_align_u16_binary    (unsigned char *, const int);
00098 extern void cob_sub_align_s16_binary    (unsigned char *, const int);
00099 extern void cob_sub_align_u32_binary    (unsigned char *, const int);
00100 extern void cob_sub_align_s32_binary    (unsigned char *, const int);
00101 extern void cob_sub_align_u64_binary    (unsigned char *, const int);
00102 extern void cob_sub_align_s64_binary    (unsigned char *, const int);
00103 
00104 #ifndef WORDS_BIGENDIAN
00105 extern int cob_cmpswp_u16_binary        (const unsigned char *, const int);
00106 extern int cob_cmpswp_s16_binary        (const unsigned char *, const int);
00107 extern int cob_cmpswp_u24_binary        (const unsigned char *, const int);
00108 extern int cob_cmpswp_s24_binary        (const unsigned char *, const int);
00109 extern int cob_cmpswp_u32_binary        (const unsigned char *, const int);
00110 extern int cob_cmpswp_s32_binary        (const unsigned char *, const int);
00111 extern int cob_cmpswp_u40_binary        (const unsigned char *, const int);
00112 extern int cob_cmpswp_s40_binary        (const unsigned char *, const int);
00113 extern int cob_cmpswp_u48_binary        (const unsigned char *, const int);
00114 extern int cob_cmpswp_s48_binary        (const unsigned char *, const int);
00115 extern int cob_cmpswp_u56_binary        (const unsigned char *, const int);
00116 extern int cob_cmpswp_s56_binary        (const unsigned char *, const int);
00117 extern int cob_cmpswp_u64_binary        (const unsigned char *, const int);
00118 extern int cob_cmpswp_s64_binary        (const unsigned char *, const int);
00119 
00120 extern int cob_cmpswp_align_u16_binary  (const unsigned char *, const int);
00121 extern int cob_cmpswp_align_s16_binary  (const unsigned char *, const int);
00122 extern int cob_cmpswp_align_u32_binary  (const unsigned char *, const int);
00123 extern int cob_cmpswp_align_s32_binary  (const unsigned char *, const int);
00124 extern int cob_cmpswp_align_u64_binary  (const unsigned char *, const int);
00125 extern int cob_cmpswp_align_s64_binary  (const unsigned char *, const int);
00126 
00127 extern void cob_addswp_u16_binary       (unsigned char *, const int);
00128 extern void cob_addswp_s16_binary       (unsigned char *, const int);
00129 extern void cob_addswp_u24_binary       (unsigned char *, const int);
00130 extern void cob_addswp_s24_binary       (unsigned char *, const int);
00131 extern void cob_addswp_u32_binary       (unsigned char *, const int);
00132 extern void cob_addswp_s32_binary       (unsigned char *, const int);
00133 extern void cob_addswp_u40_binary       (unsigned char *, const int);
00134 extern void cob_addswp_s40_binary       (unsigned char *, const int);
00135 extern void cob_addswp_u48_binary       (unsigned char *, const int);
00136 extern void cob_addswp_s48_binary       (unsigned char *, const int);
00137 extern void cob_addswp_u56_binary       (unsigned char *, const int);
00138 extern void cob_addswp_s56_binary       (unsigned char *, const int);
00139 extern void cob_addswp_u64_binary       (unsigned char *, const int);
00140 extern void cob_addswp_s64_binary       (unsigned char *, const int);
00141 
00142 extern void cob_subswp_u16_binary       (unsigned char *, const int);
00143 extern void cob_subswp_s16_binary       (unsigned char *, const int);
00144 extern void cob_subswp_u24_binary       (unsigned char *, const int);
00145 extern void cob_subswp_s24_binary       (unsigned char *, const int);
00146 extern void cob_subswp_u32_binary       (unsigned char *, const int);
00147 extern void cob_subswp_s32_binary       (unsigned char *, const int);
00148 extern void cob_subswp_u40_binary       (unsigned char *, const int);
00149 extern void cob_subswp_s40_binary       (unsigned char *, const int);
00150 extern void cob_subswp_u48_binary       (unsigned char *, const int);
00151 extern void cob_subswp_s48_binary       (unsigned char *, const int);
00152 extern void cob_subswp_u56_binary       (unsigned char *, const int);
00153 extern void cob_subswp_s56_binary       (unsigned char *, const int);
00154 extern void cob_subswp_u64_binary       (unsigned char *, const int);
00155 extern void cob_subswp_s64_binary       (unsigned char *, const int);
00156 
00157 extern void cob_setswp_u16_binary       (unsigned char *, const int);
00158 extern void cob_setswp_s16_binary       (unsigned char *, const int);
00159 extern void cob_setswp_u24_binary       (unsigned char *, const int);
00160 extern void cob_setswp_s24_binary       (unsigned char *, const int);
00161 extern void cob_setswp_u32_binary       (unsigned char *, const int);
00162 extern void cob_setswp_s32_binary       (unsigned char *, const int);
00163 extern void cob_setswp_u40_binary       (unsigned char *, const int);
00164 extern void cob_setswp_s40_binary       (unsigned char *, const int);
00165 extern void cob_setswp_u48_binary       (unsigned char *, const int);
00166 extern void cob_setswp_s48_binary       (unsigned char *, const int);
00167 extern void cob_setswp_u56_binary       (unsigned char *, const int);
00168 extern void cob_setswp_s56_binary       (unsigned char *, const int);
00169 extern void cob_setswp_u64_binary       (unsigned char *, const int);
00170 extern void cob_setswp_s64_binary       (unsigned char *, const int);
00171 #endif
00172 #endif
00173 
00174 #if     defined(COB_LOCAL_INLINE) || defined(COB_LIB_INCLUDE)
00175 
00176 #if !defined(__i386__) && !defined(__x86_64__) && !defined(__powerpc__) && !defined(__powerpc64__) && !defined(__ppc__) && !defined(__amd64__)
00177         #if defined(_MSC_VER)
00178                 #define ALLOW_MISALIGNED
00179                 #define MISALIGNED __unaligned
00180         #else
00181                 #define MISALIGNED
00182         #endif
00183 #else
00184         #define ALLOW_MISALIGNED
00185         #define MISALIGNED
00186 #endif
00187 
00188 COB_STATIC int
00189 cob_get_numdisp (const unsigned char *data, const size_t size)
00190 {
00191         int     retval = 0;
00192         size_t  n;
00193 
00194         for (n = 0; n < size; ++n, ++data) {
00195                 retval *= 10;
00196                 if (*data > '9') {
00197                         retval += 10;
00198                 } else {
00199                         retval += (*data - (unsigned char)'0');
00200                 }
00201         }
00202         return retval;
00203 }
00204 
00205 COB_STATIC int
00206 cob_cmp_packed_int (const cob_field *f, const int n)
00207 {
00208         unsigned char   *p;
00209         size_t          size;
00210         int             val = 0;
00211 
00212         p = f->data;
00213         for (size = 0; size < f->size - 1; ++size, ++p) {
00214                 val *= 10;
00215                 val += *p >> 4;
00216                 val *= 10;
00217                 val += *p & 0x0f;
00218         }
00219         val *= 10;
00220         val += *p >> 4;
00221         if ((*p & 0x0f) == 0x0d) {
00222                 val = -val;
00223         }
00224         return (val < n) ? -1 : (val > n);
00225 }
00226 
00227 COB_STATIC int
00228 cob_get_packed_int (const cob_field *f)
00229 {
00230         unsigned char   *p;
00231         size_t          size;
00232         int             val = 0;
00233 
00234         p = f->data;
00235         for (size = 0; size < f->size - 1; ++size, ++p) {
00236                 val *= 10;
00237                 val += *p >> 4;
00238                 val *= 10;
00239                 val += *p & 0x0f;
00240         }
00241         val *= 10;
00242         val += *p >> 4;
00243         if ((*p & 0x0f) == 0x0d) {
00244                 val = -val;
00245         }
00246         return val;
00247 }
00248 
00249 COB_STATIC int
00250 cob_add_packed_int (cob_field *f, const int val)
00251 {
00252         unsigned char   *p;
00253         size_t          size;
00254         int             carry = 0;
00255         int             n;
00256         int             inc;
00257 
00258         if (val == 0) {
00259                 return 0;
00260         }
00261         p = f->data + f->size - 1;
00262         if ((*p & 0x0f) == 0x0d) {
00263                 if (val > 0) {
00264                         return cob_add_int (f, val);
00265                 }
00266                 n = -val;
00267         } else {
00268                 if (val < 0) {
00269                         return cob_add_int (f, val);
00270                 }
00271                 n = val;
00272         }
00273         inc = (*p >> 4) + (n % 10);
00274         n /= 10;
00275         carry = inc / 10;
00276         *p = ((inc % 10) << 4) | (*p & 0x0f);
00277         p--;
00278 
00279         for (size = 0; size < f->size - 1; ++size, --p) {
00280                 if (!carry && !n) {
00281                         break;
00282                 }
00283                 inc = ((*p >> 4) * 10) + (*p & 0x0f) + carry + (n % 100);
00284                 carry = inc / 100;
00285                 n /= 100;
00286                 inc %= 100;
00287                 *p = ((inc / 10) << 4) | (inc % 10);
00288         }
00289         return 0;
00290 }
00291 
00292 /* Aligned variants */
00293 
00294 #ifndef ALLOW_MISALIGNED
00295 
00296 /* Aligned compares */
00297 
00298 COB_STATIC int
00299 cob_cmp_align_u16_binary (const unsigned char *p, const int n)
00300 {
00301         unsigned short  val;
00302 
00303         if (n < 0) {
00304                 return 1;
00305         }
00306         val = *(unsigned short MISALIGNED *)p;
00307         return (val < n) ? -1 : (val > n);
00308 }
00309 
00310 COB_STATIC int
00311 cob_cmp_align_s16_binary (const unsigned char *p, const int n)
00312 {
00313         short   val;
00314 
00315         val = *(short MISALIGNED *)p;
00316         return (val < n) ? -1 : (val > n);
00317 }
00318 
00319 COB_STATIC int
00320 cob_cmp_align_u32_binary (const unsigned char *p, const int n)
00321 {
00322         unsigned int    val;
00323 
00324         if (n < 0) {
00325                 return 1;
00326         }
00327         val = *(unsigned int MISALIGNED *)p;
00328         return (val < n) ? -1 : (val > n);
00329 }
00330 
00331 COB_STATIC int
00332 cob_cmp_align_s32_binary (const unsigned char *p, const int n)
00333 {
00334         int     val;
00335 
00336         val = *(int MISALIGNED *)p;
00337         return (val < n) ? -1 : (val > n);
00338 }
00339 
00340 COB_STATIC int
00341 cob_cmp_align_u64_binary (const unsigned char *p, const int n)
00342 {
00343         unsigned long long      val;
00344 
00345         if (n < 0) {
00346                 return 1;
00347         }
00348         val = *(unsigned long long MISALIGNED *)p;
00349         return (val < n) ? -1 : (val > n);
00350 }
00351 
00352 COB_STATIC int
00353 cob_cmp_align_s64_binary (const unsigned char *p, const int n)
00354 {
00355         long long       val;
00356 
00357         val = *(long long MISALIGNED *)p;
00358         return (val < n) ? -1 : (val > n);
00359 }
00360 
00361 /* Aligned adds */
00362 
00363 COB_STATIC void
00364 cob_add_align_u16_binary (unsigned char *p, const int val)
00365 {
00366         *(unsigned short MISALIGNED *)p += val;
00367 }
00368 
00369 COB_STATIC void
00370 cob_add_align_s16_binary (unsigned char *p, const int val)
00371 {
00372         *(short MISALIGNED *)p += val;
00373 }
00374 
00375 COB_STATIC void
00376 cob_add_align_u32_binary (unsigned char *p, const int val)
00377 {
00378         *(unsigned int MISALIGNED *)p += val;
00379 }
00380 
00381 COB_STATIC void
00382 cob_add_align_s32_binary (unsigned char *p, const int val)
00383 {
00384         *(int MISALIGNED *)p += val;
00385 }
00386 
00387 COB_STATIC void
00388 cob_add_align_u64_binary (unsigned char *p, const int val)
00389 {
00390         *(unsigned long long MISALIGNED *)p += val;
00391 }
00392 
00393 COB_STATIC void
00394 cob_add_align_s64_binary (unsigned char *p, const int val)
00395 {
00396         *(long long MISALIGNED *)p += val;
00397 }
00398 
00399 /* Aligned subtracts */
00400 
00401 COB_STATIC void
00402 cob_sub_align_u16_binary (unsigned char *p, const int val)
00403 {
00404         *(unsigned short MISALIGNED *)p -= val;
00405 }
00406 
00407 COB_STATIC void
00408 cob_sub_align_s16_binary (unsigned char *p, const int val)
00409 {
00410         *(short MISALIGNED *)p -= val;
00411 }
00412 
00413 COB_STATIC void
00414 cob_sub_align_u32_binary (unsigned char *p, const int val)
00415 {
00416         *(unsigned int MISALIGNED *)p -= val;
00417 }
00418 
00419 COB_STATIC void
00420 cob_sub_align_s32_binary (unsigned char *p, const int val)
00421 {
00422         *(int MISALIGNED *)p -= val;
00423 }
00424 
00425 COB_STATIC void
00426 cob_sub_align_u64_binary (unsigned char *p, const int val)
00427 {
00428         *(unsigned long long MISALIGNED *)p -= val;
00429 }
00430 
00431 COB_STATIC void
00432 cob_sub_align_s64_binary (unsigned char *p, const int val)
00433 {
00434         *(long long MISALIGNED *)p -= val;
00435 }
00436 
00437 #ifndef WORDS_BIGENDIAN
00438 COB_STATIC int
00439 cob_cmpswp_align_u16_binary (const unsigned char *p, const int n)
00440 {
00441         unsigned short  val;
00442 
00443         if (n < 0) {
00444                 return 1;
00445         }
00446         val = COB_BSWAP_16 (*(unsigned short MISALIGNED *)p);
00447         return (val < n) ? -1 : (val > n);
00448 }
00449 
00450 COB_STATIC int
00451 cob_cmpswp_align_s16_binary (const unsigned char *p, const int n)
00452 {
00453         short   val;
00454 
00455         val = COB_BSWAP_16 (*(short MISALIGNED *)p);
00456         return (val < n) ? -1 : (val > n);
00457 }
00458 
00459 COB_STATIC int
00460 cob_cmpswp_align_u32_binary (const unsigned char *p, const int n)
00461 {
00462         unsigned int    val;
00463 
00464         if (n < 0) {
00465                 return 1;
00466         }
00467         val = COB_BSWAP_32 (*(unsigned int MISALIGNED *)p);
00468         return (val < n) ? -1 : (val > n);
00469 }
00470 
00471 COB_STATIC int
00472 cob_cmpswp_align_s32_binary (const unsigned char *p, const int n)
00473 {
00474         int     val;
00475 
00476         val = COB_BSWAP_32 (*(int MISALIGNED *)p);
00477         return (val < n) ? -1 : (val > n);
00478 }
00479 
00480 COB_STATIC int
00481 cob_cmpswp_align_u64_binary (const unsigned char *p, const int n)
00482 {
00483         unsigned long long      val;
00484 
00485         if (n < 0) {
00486                 return 1;
00487         }
00488         val = COB_BSWAP_64 (*(unsigned long long MISALIGNED *)p);
00489         return (val < n) ? -1 : (val > n);
00490 }
00491 
00492 COB_STATIC int
00493 cob_cmpswp_align_s64_binary (const unsigned char *p, const int n)
00494 {
00495         long long       val;
00496 
00497         val = COB_BSWAP_64 (*(long long MISALIGNED *)p);
00498         return (val < n) ? -1 : (val > n);
00499 }
00500 
00501 #endif  /* WORDS_BIGENDIAN */
00502 #endif  /* ALLOW_MISALIGNED */
00503 
00504 /* Binary compare */
00505 
00506 COB_STATIC int
00507 cob_cmp_u8_binary (const unsigned char *p, const int n)
00508 {
00509         if (n < 0) {
00510                 return 1;
00511         }
00512         return (*p < n) ? -1 : (*p > n);
00513 }
00514 
00515 COB_STATIC int
00516 cob_cmp_s8_binary (const unsigned char *p, const int n)
00517 {
00518         return (*(const signed char *)p < n) ? -1 : (*(const signed char *)p > n);
00519 }
00520 
00521 COB_STATIC int
00522 cob_cmp_u16_binary (const unsigned char *p, const int n)
00523 {
00524 #ifndef ALLOW_MISALIGNED
00525         unsigned char   *x;
00526 #endif
00527         unsigned short  val;
00528 
00529         if (n < 0) {
00530                 return 1;
00531         }
00532 #ifdef ALLOW_MISALIGNED
00533         val = *(const unsigned short MISALIGNED *)p;
00534 #else
00535         x = (unsigned char *)&val;
00536         *x = *p;
00537         *(x + 1) = *(p + 1);
00538 #endif
00539         return (val < n) ? -1 : (val > n);
00540 }
00541 
00542 COB_STATIC int
00543 cob_cmp_s16_binary (const unsigned char *p, const int n)
00544 {
00545         short   val;
00546 
00547 #ifdef ALLOW_MISALIGNED
00548         val = *(const short MISALIGNED *)p;
00549 #else
00550         unsigned char   *x;
00551 
00552         x = (unsigned char *)&val;
00553         *x = *p;
00554         *(x + 1) = *(p + 1);
00555 #endif
00556         return (val < n) ? -1 : (val > n);
00557 }
00558 
00559 COB_STATIC int
00560 cob_cmp_u24_binary (const unsigned char *p, const int n)
00561 {
00562         unsigned char   *x;
00563         unsigned int    val = 0;
00564 
00565         if (n < 0) {
00566                 return 1;
00567         }
00568 #ifdef  WORDS_BIGENDIAN
00569         x = ((unsigned char *)&val) + 1;
00570 #else
00571         x = (unsigned char *)&val;
00572 #endif
00573         *x = *p;
00574         *(x + 1) = *(p + 1);
00575         *(x + 2) = *(p + 2);
00576         return (val < n) ? -1 : (val > n);
00577 }
00578 
00579 COB_STATIC int
00580 cob_cmp_s24_binary (const unsigned char *p, const int n)
00581 {
00582         unsigned char   *x;
00583         int             val = 0;
00584 
00585 #ifdef  WORDS_BIGENDIAN
00586         x = (unsigned char *)&val;
00587 #else
00588         x = ((unsigned char *)&val) + 1;
00589 #endif
00590         *x = *p;
00591         *(x + 1) = *(p + 1);
00592         *(x + 2) = *(p + 2);
00593         val >>= 8;      /* shift with sign */
00594         return (val < n) ? -1 : (val > n);
00595 }
00596 
00597 COB_STATIC int
00598 cob_cmp_u32_binary (const unsigned char *p, const int n)
00599 {
00600 #ifndef ALLOW_MISALIGNED
00601         unsigned char   *x;
00602 #endif
00603         unsigned int    val;
00604 
00605         if (n < 0) {
00606                 return 1;
00607         }
00608 #ifdef ALLOW_MISALIGNED
00609         val = *(const unsigned int MISALIGNED *)p;
00610 #else
00611         x = (unsigned char *)&val;
00612         *x = *p;
00613         *(x + 1) = *(p + 1);
00614         *(x + 2) = *(p + 2);
00615         *(x + 3) = *(p + 3);
00616 #endif
00617         return (val < n) ? -1 : (val > n);
00618 }
00619 
00620 COB_STATIC int
00621 cob_cmp_s32_binary (const unsigned char *p, const int n)
00622 {
00623         int     val;
00624 
00625 #ifdef ALLOW_MISALIGNED
00626         val = *(const int MISALIGNED *)p;
00627 #else
00628         unsigned char   *x;
00629 
00630         x = (unsigned char *)&val;
00631         *x = *p;
00632         *(x + 1) = *(p + 1);
00633         *(x + 2) = *(p + 2);
00634         *(x + 3) = *(p + 3);
00635 #endif
00636         return (val < n) ? -1 : (val > n);
00637 }
00638 
00639 COB_STATIC int
00640 cob_cmp_u40_binary (const unsigned char *p, const int n)
00641 {
00642         unsigned long long      val = 0;
00643         unsigned char           *x;
00644 
00645         if (n < 0) {
00646                 return 1;
00647         }
00648 #ifdef  WORDS_BIGENDIAN
00649         x = ((unsigned char *)&val) + 3;
00650 #else
00651         x = (unsigned char *)&val;
00652 #endif
00653         *x = *p;
00654         *(x + 1) = *(p + 1);
00655         *(x + 2) = *(p + 2);
00656         *(x + 3) = *(p + 3);
00657         *(x + 4) = *(p + 4);
00658         return (val < n) ? -1 : (val > n);
00659 }
00660 
00661 COB_STATIC int
00662 cob_cmp_s40_binary (const unsigned char *p, const int n)
00663 {
00664         long long               val = 0;
00665         unsigned char           *x;
00666 
00667 #ifdef  WORDS_BIGENDIAN
00668         x = (unsigned char *)&val;
00669 #else
00670         x = ((unsigned char *)&val) + 3;
00671 #endif
00672         *x = *p;
00673         *(x + 1) = *(p + 1);
00674         *(x + 2) = *(p + 2);
00675         *(x + 3) = *(p + 3);
00676         *(x + 4) = *(p + 4);
00677         val >>= 24;     /* shift with sign */
00678         return (val < n) ? -1 : (val > n);
00679 }
00680 
00681 COB_STATIC int
00682 cob_cmp_u48_binary (const unsigned char *p, const int n)
00683 {
00684         unsigned long long      val = 0;
00685         unsigned char           *x;
00686 
00687         if (n < 0) {
00688                 return 1;
00689         }
00690 #ifdef  WORDS_BIGENDIAN
00691         x = ((unsigned char *)&val) + 2;
00692 #else
00693         x = (unsigned char *)&val;
00694 #endif
00695         *x = *p;
00696         *(x + 1) = *(p + 1);
00697         *(x + 2) = *(p + 2);
00698         *(x + 3) = *(p + 3);
00699         *(x + 4) = *(p + 4);
00700         *(x + 5) = *(p + 5);
00701         return (val < n) ? -1 : (val > n);
00702 }
00703 
00704 COB_STATIC int
00705 cob_cmp_s48_binary (const unsigned char *p, const int n)
00706 {
00707         long long               val = 0;
00708         unsigned char           *x;
00709 
00710 #ifdef  WORDS_BIGENDIAN
00711         x = (unsigned char *)&val;
00712 #else
00713         x = ((unsigned char *)&val) + 2;
00714 #endif
00715         *x = *p;
00716         *(x + 1) = *(p + 1);
00717         *(x + 2) = *(p + 2);
00718         *(x + 3) = *(p + 3);
00719         *(x + 4) = *(p + 4);
00720         *(x + 5) = *(p + 5);
00721         val >>= 16;     /* shift with sign */
00722         return (val < n) ? -1 : (val > n);
00723 }
00724 
00725 COB_STATIC int
00726 cob_cmp_u56_binary (const unsigned char *p, const int n)
00727 {
00728         unsigned long long      val = 0;
00729         unsigned char           *x;
00730 
00731         if (n < 0) {
00732                 return 1;
00733         }
00734 #ifdef  WORDS_BIGENDIAN
00735         x = ((unsigned char *)&val) + 1;
00736 #else
00737         x = (unsigned char *)&val;
00738 #endif
00739         *x = *p;
00740         *(x + 1) = *(p + 1);
00741         *(x + 2) = *(p + 2);
00742         *(x + 3) = *(p + 3);
00743         *(x + 4) = *(p + 4);
00744         *(x + 5) = *(p + 5);
00745         *(x + 6) = *(p + 6);
00746         return (val < n) ? -1 : (val > n);
00747 }
00748 
00749 COB_STATIC int
00750 cob_cmp_s56_binary (const unsigned char *p, const int n)
00751 {
00752         long long               val = 0;
00753         unsigned char           *x;
00754 
00755 #ifdef  WORDS_BIGENDIAN
00756         x = (unsigned char *)&val;
00757 #else
00758         x = ((unsigned char *)&val) + 1;
00759 #endif
00760         *x = *p;
00761         *(x + 1) = *(p + 1);
00762         *(x + 2) = *(p + 2);
00763         *(x + 3) = *(p + 3);
00764         *(x + 4) = *(p + 4);
00765         *(x + 5) = *(p + 5);
00766         *(x + 6) = *(p + 6);
00767         val >>= 8;      /* shift with sign */
00768         return (val < n) ? -1 : (val > n);
00769 }
00770 
00771 COB_STATIC int
00772 cob_cmp_u64_binary (const unsigned char *p, const int n)
00773 {
00774 #ifndef ALLOW_MISALIGNED
00775         unsigned char           *x;
00776 #endif
00777         unsigned long long      val;
00778 
00779         if (n < 0) {
00780                 return 1;
00781         }
00782 #ifdef ALLOW_MISALIGNED
00783         val = *(const unsigned long long MISALIGNED *)p;
00784 #else
00785         x = (unsigned char *)&val;
00786         *x = *p;
00787         *(x + 1) = *(p + 1);
00788         *(x + 2) = *(p + 2);
00789         *(x + 3) = *(p + 3);
00790         *(x + 4) = *(p + 4);
00791         *(x + 5) = *(p + 5);
00792         *(x + 6) = *(p + 6);
00793         *(x + 7) = *(p + 7);
00794 #endif
00795         return (val < n) ? -1 : (val > n);
00796 }
00797 
00798 COB_STATIC int
00799 cob_cmp_s64_binary (const unsigned char *p, const int n)
00800 {
00801         long long       val;
00802 
00803 #ifdef ALLOW_MISALIGNED
00804         val = *(const long long MISALIGNED *)p;
00805 #else
00806         unsigned char           *x;
00807 
00808         x = (unsigned char *)&val;
00809         *x = *p;
00810         *(x + 1) = *(p + 1);
00811         *(x + 2) = *(p + 2);
00812         *(x + 3) = *(p + 3);
00813         *(x + 4) = *(p + 4);
00814         *(x + 5) = *(p + 5);
00815         *(x + 6) = *(p + 6);
00816         *(x + 7) = *(p + 7);
00817 #endif
00818         return (val < n) ? -1 : (val > n);
00819 }
00820 
00821 /* Add/Subtract */
00822 
00823 COB_STATIC void
00824 cob_add_u8_binary (unsigned char *p, const int val)
00825 {
00826         *p += val;
00827 }
00828 
00829 COB_STATIC void
00830 cob_add_s8_binary (unsigned char *p, const int val)
00831 {
00832         *(signed char *)p += val;
00833 }
00834 
00835 COB_STATIC void
00836 cob_add_u16_binary (unsigned char *p, const int val)
00837 {
00838 #ifdef ALLOW_MISALIGNED
00839         *(unsigned short MISALIGNED *)p += val;
00840 #else
00841         unsigned char   *x;
00842         unsigned short  n;
00843 
00844         x = (unsigned char *)&n;
00845         *x = *p;
00846         *(x + 1) = *(p + 1);
00847         n += val;
00848         *p = *x;
00849         *(p + 1) = *(x + 1);
00850 #endif
00851 }
00852 
00853 COB_STATIC void
00854 cob_add_s16_binary (unsigned char *p, const int val)
00855 {
00856 #ifdef ALLOW_MISALIGNED
00857         *(short MISALIGNED *)p += val;
00858 #else
00859         unsigned char   *x;
00860         short           n;
00861 
00862         x = (unsigned char *)&n;
00863         *x = *p;
00864         *(x + 1) = *(p + 1);
00865         n += val;
00866         *p = *x;
00867         *(p + 1) = *(x + 1);
00868 #endif
00869 }
00870 
00871 COB_STATIC void
00872 cob_add_u24_binary (unsigned char *p, const int val)
00873 {
00874         unsigned char   *x;
00875         unsigned int    n = 0;
00876 
00877 #ifdef  WORDS_BIGENDIAN
00878         x = ((unsigned char *)&n) + 1;
00879 #else
00880         x = (unsigned char *)&n;
00881 #endif
00882         *x = *p;
00883         *(x + 1) = *(p + 1);
00884         *(x + 2) = *(p + 2);
00885         n += val;
00886         *p = *x;
00887         *(p + 1) = *(x + 1);
00888         *(p + 2) = *(x + 2);
00889 }
00890 
00891 COB_STATIC void
00892 cob_add_s24_binary (unsigned char *p, const int val)
00893 {
00894         unsigned char   *x;
00895         int             n = 0;
00896 
00897 #ifdef  WORDS_BIGENDIAN
00898         x = (unsigned char *)&n;
00899 #else
00900         x = ((unsigned char *)&n) + 1;
00901 #endif
00902         *x = *p;
00903         *(x + 1) = *(p + 1);
00904         *(x + 2) = *(p + 2);
00905         n >>= 8;        /* shift with sign */
00906         n += val;
00907 #ifdef  WORDS_BIGENDIAN
00908         x = ((unsigned char *)&n) + 1;
00909 #else
00910         x = (unsigned char *)&n;
00911 #endif
00912         *p = *x;
00913         *(p + 1) = *(x + 1);
00914         *(p + 2) = *(x + 2);
00915 }
00916 
00917 COB_STATIC void
00918 cob_add_u32_binary (unsigned char *p, const int val)
00919 {
00920 #ifdef ALLOW_MISALIGNED
00921         *(unsigned int MISALIGNED *)p += val;
00922 #else
00923         unsigned char   *x;
00924         unsigned int    n;
00925 
00926         x = (unsigned char *)&n;
00927         *x = *p;
00928         *(x + 1) = *(p + 1);
00929         *(x + 2) = *(p + 2);
00930         *(x + 3) = *(p + 3);
00931         n += val;
00932         *p = *x;
00933         *(p + 1) = *(x + 1);
00934         *(p + 2) = *(x + 2);
00935         *(p + 3) = *(x + 3);
00936 #endif
00937 }
00938 
00939 COB_STATIC void
00940 cob_add_s32_binary (unsigned char *p, const int val)
00941 {
00942 #ifdef ALLOW_MISALIGNED
00943         *(int MISALIGNED *)p += val;
00944 #else
00945         unsigned char   *x;
00946         int             n;
00947 
00948         x = (unsigned char *)&n;
00949         *x = *p;
00950         *(x + 1) = *(p + 1);
00951         *(x + 2) = *(p + 2);
00952         *(x + 3) = *(p + 3);
00953         n += val;
00954         *p = *x;
00955         *(p + 1) = *(x + 1);
00956         *(p + 2) = *(x + 2);
00957         *(p + 3) = *(x + 3);
00958 #endif
00959 }
00960 
00961 COB_STATIC void
00962 cob_add_u40_binary (unsigned char *p, const int val)
00963 {
00964         unsigned long long      n = 0;
00965         unsigned char           *x;
00966 
00967 #ifdef  WORDS_BIGENDIAN
00968         x = ((unsigned char *)&n) + 3;
00969 #else
00970         x = (unsigned char *)&n;
00971 #endif
00972         *x = *p;
00973         *(x + 1) = *(p + 1);
00974         *(x + 2) = *(p + 2);
00975         *(x + 3) = *(p + 3);
00976         *(x + 4) = *(p + 4);
00977         n += val;
00978         *p = *x;
00979         *(p + 1) = *(x + 1);
00980         *(p + 2) = *(x + 2);
00981         *(p + 3) = *(x + 3);
00982         *(p + 4) = *(x + 4);
00983 }
00984 
00985 COB_STATIC void
00986 cob_add_s40_binary (unsigned char *p, const int val)
00987 {
00988         long long               n = 0;
00989         unsigned char           *x;
00990 
00991 #ifdef  WORDS_BIGENDIAN
00992         x = (unsigned char *)&n;
00993 #else
00994         x = ((unsigned char *)&n) + 3;
00995 #endif
00996         *x = *p;
00997         *(x + 1) = *(p + 1);
00998         *(x + 2) = *(p + 2);
00999         *(x + 3) = *(p + 3);
01000         *(x + 4) = *(p + 4);
01001         n >>= 24;       /* shift with sign */
01002         n += val;
01003 #ifdef  WORDS_BIGENDIAN
01004         x = ((unsigned char *)&n) + 3;
01005 #else
01006         x = (unsigned char *)&n;
01007 #endif
01008         *p = *x;
01009         *(p + 1) = *(x + 1);
01010         *(p + 2) = *(x + 2);
01011         *(p + 3) = *(x + 3);
01012         *(p + 4) = *(x + 4);
01013 }
01014 
01015 COB_STATIC void
01016 cob_add_u48_binary (unsigned char *p, const int val)
01017 {
01018         unsigned long long      n = 0;
01019         unsigned char           *x;
01020 
01021 #ifdef  WORDS_BIGENDIAN
01022         x = ((unsigned char *)&n) + 2;
01023 #else
01024         x = (unsigned char *)&n;
01025 #endif
01026         *x = *p;
01027         *(x + 1) = *(p + 1);
01028         *(x + 2) = *(p + 2);
01029         *(x + 3) = *(p + 3);
01030         *(x + 4) = *(p + 4);
01031         *(x + 5) = *(p + 5);
01032         n += val;
01033         *p = *x;
01034         *(p + 1) = *(x + 1);
01035         *(p + 2) = *(x + 2);
01036         *(p + 3) = *(x + 3);
01037         *(p + 4) = *(x + 4);
01038         *(p + 5) = *(x + 5);
01039 }
01040 
01041 COB_STATIC void
01042 cob_add_s48_binary (unsigned char *p, const int val)
01043 {
01044         long long               n = 0;
01045         unsigned char           *x;
01046 
01047 #ifdef  WORDS_BIGENDIAN
01048         x = (unsigned char *)&n;
01049 #else
01050         x = ((unsigned char *)&n) + 2;
01051 #endif
01052         *x = *p;
01053         *(x + 1) = *(p + 1);
01054         *(x + 2) = *(p + 2);
01055         *(x + 3) = *(p + 3);
01056         *(x + 4) = *(p + 4);
01057         *(x + 5) = *(p + 5);
01058         n >>= 16;       /* shift with sign */
01059         n += val;
01060 #ifdef  WORDS_BIGENDIAN
01061         x = ((unsigned char *)&n) + 2;
01062 #else
01063         x = (unsigned char *)&n;
01064 #endif
01065         *p = *x;
01066         *(p + 1) = *(x + 1);
01067         *(p + 2) = *(x + 2);
01068         *(p + 3) = *(x + 3);
01069         *(p + 4) = *(x + 4);
01070         *(p + 5) = *(x + 5);
01071 }
01072 
01073 COB_STATIC void
01074 cob_add_u56_binary (unsigned char *p, const int val)
01075 {
01076         unsigned long long      n = 0;
01077         unsigned char           *x;
01078 
01079 #ifdef  WORDS_BIGENDIAN
01080         x = ((unsigned char *)&n) + 1;
01081 #else
01082         x = (unsigned char *)&n;
01083 #endif
01084         *x = *p;
01085         *(x + 1) = *(p + 1);
01086         *(x + 2) = *(p + 2);
01087         *(x + 3) = *(p + 3);
01088         *(x + 4) = *(p + 4);
01089         *(x + 5) = *(p + 5);
01090         *(x + 6) = *(p + 6);
01091         n += val;
01092         *p = *x;
01093         *(p + 1) = *(x + 1);
01094         *(p + 2) = *(x + 2);
01095         *(p + 3) = *(x + 3);
01096         *(p + 4) = *(x + 4);
01097         *(p + 5) = *(x + 5);
01098         *(p + 6) = *(x + 6);
01099 }
01100 
01101 COB_STATIC void
01102 cob_add_s56_binary (unsigned char *p, const int val)
01103 {
01104         long long               n = 0;
01105         unsigned char           *x;
01106 
01107 #ifdef  WORDS_BIGENDIAN
01108         x = (unsigned char *)&n;
01109 #else
01110         x = ((unsigned char *)&n) + 1;
01111 #endif
01112         *x = *p;
01113         *(x + 1) = *(p + 1);
01114         *(x + 2) = *(p + 2);
01115         *(x + 3) = *(p + 3);
01116         *(x + 4) = *(p + 4);
01117         *(x + 5) = *(p + 5);
01118         *(x + 6) = *(p + 6);
01119         n >>= 8;        /* shift with sign */
01120         n += val;
01121 #ifdef  WORDS_BIGENDIAN
01122         x = ((unsigned char *)&n) + 1;
01123 #else
01124         x = (unsigned char *)&n;
01125 #endif
01126         *p = *x;
01127         *(p + 1) = *(x + 1);
01128         *(p + 2) = *(x + 2);
01129         *(p + 3) = *(x + 3);
01130         *(p + 4) = *(x + 4);
01131         *(p + 5) = *(x + 5);
01132         *(p + 6) = *(x + 6);
01133 }
01134 
01135 COB_STATIC void
01136 cob_add_u64_binary (unsigned char *p, const int val)
01137 {
01138 #ifdef ALLOW_MISALIGNED
01139         *(unsigned long long MISALIGNED *)p += val;
01140 #else
01141         unsigned char           *x;
01142         unsigned long long      n;
01143 
01144         x = (unsigned char *)&n;
01145         *x = *p;
01146         *(x + 1) = *(p + 1);
01147         *(x + 2) = *(p + 2);
01148         *(x + 3) = *(p + 3);
01149         *(x + 4) = *(p + 4);
01150         *(x + 5) = *(p + 5);
01151         *(x + 6) = *(p + 6);
01152         *(x + 7) = *(p + 7);
01153         n += val;
01154         *p = *x;
01155         *(p + 1) = *(x + 1);
01156         *(p + 2) = *(x + 2);
01157         *(p + 3) = *(x + 3);
01158         *(p + 4) = *(x + 4);
01159         *(p + 5) = *(x + 5);
01160         *(p + 6) = *(x + 6);
01161         *(p + 7) = *(x + 7);
01162 #endif
01163 }
01164 
01165 COB_STATIC void
01166 cob_add_s64_binary (unsigned char *p, const int val)
01167 {
01168 #ifdef ALLOW_MISALIGNED
01169         *(long long MISALIGNED *)p += val;
01170 #else
01171         unsigned char           *x;
01172         long long               n;
01173 
01174         x = (unsigned char *)&n;
01175         *x = *p;
01176         *(x + 1) = *(p + 1);
01177         *(x + 2) = *(p + 2);
01178         *(x + 3) = *(p + 3);
01179         *(x + 4) = *(p + 4);
01180         *(x + 5) = *(p + 5);
01181         *(x + 6) = *(p + 6);
01182         *(x + 7) = *(p + 7);
01183         n += val;
01184         *p = *x;
01185         *(p + 1) = *(x + 1);
01186         *(p + 2) = *(x + 2);
01187         *(p + 3) = *(x + 3);
01188         *(p + 4) = *(x + 4);
01189         *(p + 5) = *(x + 5);
01190         *(p + 6) = *(x + 6);
01191         *(p + 7) = *(x + 7);
01192 #endif
01193 }
01194 
01195 COB_STATIC void
01196 cob_sub_u8_binary (unsigned char *p, const int val)
01197 {
01198         *p -= val;
01199 }
01200 
01201 COB_STATIC void
01202 cob_sub_s8_binary (unsigned char *p, const int val)
01203 {
01204         *(signed char *)p -= val;
01205 }
01206 
01207 COB_STATIC void
01208 cob_sub_u16_binary (unsigned char *p, const int val)
01209 {
01210 #ifdef ALLOW_MISALIGNED
01211         *(unsigned short MISALIGNED *)p -= val;
01212 #else
01213         unsigned char   *x;
01214         unsigned short  n;
01215 
01216         x = (unsigned char *)&n;
01217         *x = *p;
01218         *(x + 1) = *(p + 1);
01219         n -= val;
01220         *p = *x;
01221         *(p + 1) = *(x + 1);
01222 #endif
01223 }
01224 
01225 COB_STATIC void
01226 cob_sub_s16_binary (unsigned char *p, const int val)
01227 {
01228 #ifdef ALLOW_MISALIGNED
01229         *(short MISALIGNED *)p -= val;
01230 #else
01231         unsigned char   *x;
01232         short           n;
01233 
01234         x = (unsigned char *)&n;
01235         *x = *p;
01236         *(x + 1) = *(p + 1);
01237         n -= val;
01238         *p = *x;
01239         *(p + 1) = *(x + 1);
01240 #endif
01241 }
01242 
01243 COB_STATIC void
01244 cob_sub_u24_binary (unsigned char *p, const int val)
01245 {
01246         unsigned char   *x;
01247         unsigned int    n = 0;
01248 
01249 #ifdef  WORDS_BIGENDIAN
01250         x = ((unsigned char *)&n) + 1;
01251 #else
01252         x = (unsigned char *)&n;
01253 #endif
01254         *x = *p;
01255         *(x + 1) = *(p + 1);
01256         *(x + 2) = *(p + 2);
01257         n -= val;
01258         *p = *x;
01259         *(p + 1) = *(x + 1);
01260         *(p + 2) = *(x + 2);
01261 }
01262 
01263 COB_STATIC void
01264 cob_sub_s24_binary (unsigned char *p, const int val)
01265 {
01266         unsigned char   *x;
01267         int             n = 0;
01268 
01269 #ifdef  WORDS_BIGENDIAN
01270         x = (unsigned char *)&n;
01271 #else
01272         x = ((unsigned char *)&n) + 1;
01273 #endif
01274         *x = *p;
01275         *(x + 1) = *(p + 1);
01276         *(x + 2) = *(p + 2);
01277         n >>= 8;        /* shift with sign */
01278         n -= val;
01279 #ifdef  WORDS_BIGENDIAN
01280         x = ((unsigned char *)&n) + 1;
01281 #else
01282         x = (unsigned char *)&n;
01283 #endif
01284         *p = *x;
01285         *(p + 1) = *(x + 1);
01286         *(p + 2) = *(x + 2);
01287 }
01288 
01289 COB_STATIC void
01290 cob_sub_u32_binary (unsigned char *p, const int val)
01291 {
01292 #ifdef ALLOW_MISALIGNED
01293         *(unsigned int MISALIGNED *)p -= val;
01294 #else
01295         unsigned char   *x;
01296         unsigned int    n;
01297 
01298         x = (unsigned char *)&n;
01299         *x = *p;
01300         *(x + 1) = *(p + 1);
01301         *(x + 2) = *(p + 2);
01302         *(x + 3) = *(p + 3);
01303         n -= val;
01304         *p = *x;
01305         *(p + 1) = *(x + 1);
01306         *(p + 2) = *(x + 2);
01307         *(p + 3) = *(x + 3);
01308 #endif
01309 }
01310 
01311 COB_STATIC void
01312 cob_sub_s32_binary (unsigned char *p, const int val)
01313 {
01314 #ifdef ALLOW_MISALIGNED
01315         *(int MISALIGNED *)p -= val;
01316 #else
01317         unsigned char   *x;
01318         int             n;
01319 
01320         x = (unsigned char *)&n;
01321         *x = *p;
01322         *(x + 1) = *(p + 1);
01323         *(x + 2) = *(p + 2);
01324         *(x + 3) = *(p + 3);
01325         n -= val;
01326         *p = *x;
01327         *(p + 1) = *(x + 1);
01328         *(p + 2) = *(x + 2);
01329         *(p + 3) = *(x + 3);
01330 #endif
01331 }
01332 
01333 COB_STATIC void
01334 cob_sub_u40_binary (unsigned char *p, const int val)
01335 {
01336         unsigned long long      n = 0;
01337         unsigned char           *x;
01338 
01339 #ifdef  WORDS_BIGENDIAN
01340         x = ((unsigned char *)&n) + 3;
01341 #else
01342         x = (unsigned char *)&n;
01343 #endif
01344         *x = *p;
01345         *(x + 1) = *(p + 1);
01346         *(x + 2) = *(p + 2);
01347         *(x + 3) = *(p + 3);
01348         *(x + 4) = *(p + 4);
01349         n -= val;
01350         *p = *x;
01351         *(p + 1) = *(x + 1);
01352         *(p + 2) = *(x + 2);
01353         *(p + 3) = *(x + 3);
01354         *(p + 4) = *(x + 4);
01355 }
01356 
01357 COB_STATIC void
01358 cob_sub_s40_binary (unsigned char *p, const int val)
01359 {
01360         long long               n = 0;
01361         unsigned char           *x;
01362 
01363 #ifdef  WORDS_BIGENDIAN
01364         x = (unsigned char *)&n;
01365 #else
01366         x = ((unsigned char *)&n) + 3;
01367 #endif
01368         *x = *p;
01369         *(x + 1) = *(p + 1);
01370         *(x + 2) = *(p + 2);
01371         *(x + 3) = *(p + 3);
01372         *(x + 4) = *(p + 4);
01373         n >>= 24;       /* shift with sign */
01374         n -= val;
01375 #ifdef  WORDS_BIGENDIAN
01376         x = ((unsigned char *)&n) + 3;
01377 #else
01378         x = (unsigned char *)&n;
01379 #endif
01380         *p = *x;
01381         *(p + 1) = *(x + 1);
01382         *(p + 2) = *(x + 2);
01383         *(p + 3) = *(x + 3);
01384         *(p + 4) = *(x + 4);
01385 }
01386 
01387 COB_STATIC void
01388 cob_sub_u48_binary (unsigned char *p, const int val)
01389 {
01390         unsigned long long      n = 0;
01391         unsigned char           *x;
01392 
01393 #ifdef  WORDS_BIGENDIAN
01394         x = ((unsigned char *)&n) + 2;
01395 #else
01396         x = (unsigned char *)&n;
01397 #endif
01398         *x = *p;
01399         *(x + 1) = *(p + 1);
01400         *(x + 2) = *(p + 2);
01401         *(x + 3) = *(p + 3);
01402         *(x + 4) = *(p + 4);
01403         *(x + 5) = *(p + 5);
01404         n -= val;
01405         *p = *x;
01406         *(p + 1) = *(x + 1);
01407         *(p + 2) = *(x + 2);
01408         *(p + 3) = *(x + 3);
01409         *(p + 4) = *(x + 4);
01410         *(p + 5) = *(x + 5);
01411 }
01412 
01413 COB_STATIC void
01414 cob_sub_s48_binary (unsigned char *p, const int val)
01415 {
01416         long long               n = 0;
01417         unsigned char           *x;
01418 
01419 #ifdef  WORDS_BIGENDIAN
01420         x = (unsigned char *)&n;
01421 #else
01422         x = ((unsigned char *)&n) + 2;
01423 #endif
01424         *x = *p;
01425         *(x + 1) = *(p + 1);
01426         *(x + 2) = *(p + 2);
01427         *(x + 3) = *(p + 3);
01428         *(x + 4) = *(p + 4);
01429         *(x + 5) = *(p + 5);
01430         n >>= 16;       /* shift with sign */
01431         n -= val;
01432 #ifdef  WORDS_BIGENDIAN
01433         x = ((unsigned char *)&n) + 2;
01434 #else
01435         x = (unsigned char *)&n;
01436 #endif
01437         *p = *x;
01438         *(p + 1) = *(x + 1);
01439         *(p + 2) = *(x + 2);
01440         *(p + 3) = *(x + 3);
01441         *(p + 4) = *(x + 4);
01442         *(p + 5) = *(x + 5);
01443 }
01444 
01445 COB_STATIC void
01446 cob_sub_u56_binary (unsigned char *p, const int val)
01447 {
01448         unsigned long long      n = 0;
01449         unsigned char           *x;
01450 
01451 #ifdef  WORDS_BIGENDIAN
01452         x = ((unsigned char *)&n) + 1;
01453 #else
01454         x = (unsigned char *)&n;
01455 #endif
01456         *x = *p;
01457         *(x + 1) = *(p + 1);
01458         *(x + 2) = *(p + 2);
01459         *(x + 3) = *(p + 3);
01460         *(x + 4) = *(p + 4);
01461         *(x + 5) = *(p + 5);
01462         *(x + 6) = *(p + 6);
01463         n -= val;
01464         *p = *x;
01465         *(p + 1) = *(x + 1);
01466         *(p + 2) = *(x + 2);
01467         *(p + 3) = *(x + 3);
01468         *(p + 4) = *(x + 4);
01469         *(p + 5) = *(x + 5);
01470         *(p + 6) = *(x + 6);
01471 }
01472 
01473 COB_STATIC void
01474 cob_sub_s56_binary (unsigned char *p, const int val)
01475 {
01476         long long               n = 0;
01477         unsigned char           *x;
01478 
01479 #ifdef  WORDS_BIGENDIAN
01480         x = (unsigned char *)&n;
01481 #else
01482         x = ((unsigned char *)&n) + 1;
01483 #endif
01484         *x = *p;
01485         *(x + 1) = *(p + 1);
01486         *(x + 2) = *(p + 2);
01487         *(x + 3) = *(p + 3);
01488         *(x + 4) = *(p + 4);
01489         *(x + 5) = *(p + 5);
01490         *(x + 6) = *(p + 6);
01491         n >>= 8;        /* shift with sign */
01492         n -= val;
01493 #ifdef  WORDS_BIGENDIAN
01494         x = ((unsigned char *)&n) + 1;
01495 #else
01496         x = (unsigned char *)&n;
01497 #endif
01498         *p = *x;
01499         *(p + 1) = *(x + 1);
01500         *(p + 2) = *(x + 2);
01501         *(p + 3) = *(x + 3);
01502         *(p + 4) = *(x + 4);
01503         *(p + 5) = *(x + 5);
01504         *(p + 6) = *(x + 6);
01505 }
01506 
01507 COB_STATIC void
01508 cob_sub_u64_binary (unsigned char *p, const int val)
01509 {
01510 #ifdef ALLOW_MISALIGNED
01511         *(unsigned long long MISALIGNED *)p -= val;
01512 #else
01513         unsigned char           *x;
01514         unsigned long long      n;
01515 
01516         x = (unsigned char *)&n;
01517         *x = *p;
01518         *(x + 1) = *(p + 1);
01519         *(x + 2) = *(p + 2);
01520         *(x + 3) = *(p + 3);
01521         *(x + 4) = *(p + 4);
01522         *(x + 5) = *(p + 5);
01523         *(x + 6) = *(p + 6);
01524         *(x + 7) = *(p + 7);
01525         n -= val;
01526         *p = *x;
01527         *(p + 1) = *(x + 1);
01528         *(p + 2) = *(x + 2);
01529         *(p + 3) = *(x + 3);
01530         *(p + 4) = *(x + 4);
01531         *(p + 5) = *(x + 5);
01532         *(p + 6) = *(x + 6);
01533         *(p + 7) = *(x + 7);
01534 #endif
01535 }
01536 
01537 COB_STATIC void
01538 cob_sub_s64_binary (unsigned char *p, const int val)
01539 {
01540 #ifdef ALLOW_MISALIGNED
01541         *(long long MISALIGNED *)p -= val;
01542 #else
01543         unsigned char           *x;
01544         long long               n;
01545 
01546         x = (unsigned char *)&n;
01547         *x = *p;
01548         *(x + 1) = *(p + 1);
01549         *(x + 2) = *(p + 2);
01550         *(x + 3) = *(p + 3);
01551         *(x + 4) = *(p + 4);
01552         *(x + 5) = *(p + 5);
01553         *(x + 6) = *(p + 6);
01554         *(x + 7) = *(p + 7);
01555         n -= val;
01556         *p = *x;
01557         *(p + 1) = *(x + 1);
01558         *(p + 2) = *(x + 2);
01559         *(p + 3) = *(x + 3);
01560         *(p + 4) = *(x + 4);
01561         *(p + 5) = *(x + 5);
01562         *(p + 6) = *(x + 6);
01563         *(p + 7) = *(x + 7);
01564 #endif
01565 }
01566 
01567 #ifndef WORDS_BIGENDIAN
01568 
01569 /* Binary swapped compare */
01570 COB_STATIC int
01571 cob_cmpswp_u16_binary (const unsigned char *p, const int n)
01572 {
01573 #ifndef ALLOW_MISALIGNED
01574         unsigned char   *x;
01575 #endif
01576         unsigned short  val;
01577 
01578         if (n < 0) {
01579                 return 1;
01580         }
01581 #ifdef ALLOW_MISALIGNED
01582         val = COB_BSWAP_16 (*(unsigned short MISALIGNED *)p);
01583 #else
01584         x = (unsigned char *)&val;
01585         *x = *p;
01586         *(x + 1) = *(p + 1);
01587         val = COB_BSWAP_16 (val);
01588 #endif
01589         return (val < n) ? -1 : (val > n);
01590 }
01591 
01592 COB_STATIC int
01593 cob_cmpswp_s16_binary (const unsigned char *p, const int n)
01594 {
01595         short   val;
01596 
01597 #ifdef ALLOW_MISALIGNED
01598         val = COB_BSWAP_16 (*(short MISALIGNED *)p);
01599 #else
01600         unsigned char   *x;
01601 
01602         x = (unsigned char *)&val;
01603         *x = *p;
01604         *(x + 1) = *(p + 1);
01605         val = COB_BSWAP_16 (val);
01606 #endif
01607         return (val < n) ? -1 : (val > n);
01608 }
01609 
01610 COB_STATIC int
01611 cob_cmpswp_u24_binary (const unsigned char *p, const int n)
01612 {
01613         unsigned char   *x;
01614         unsigned int    val = 0;
01615 
01616         if (n < 0) {
01617                 return 1;
01618         }
01619         x = ((unsigned char *)&val) + 1;
01620         *x = *p;
01621         *(x + 1) = *(p + 1);
01622         *(x + 2) = *(p + 2);
01623         val = COB_BSWAP_32 (val);
01624         return (val < n) ? -1 : (val > n);
01625 }
01626 
01627 COB_STATIC int
01628 cob_cmpswp_s24_binary (const unsigned char *p, const int n)
01629 {
01630         unsigned char   *x;
01631         int             val = 0;
01632 
01633         x = (unsigned char *)&val;
01634         *x = *p;
01635         *(x + 1) = *(p + 1);
01636         *(x + 2) = *(p + 2);
01637         val = COB_BSWAP_32 (val);
01638         val >>= 8;      /* shift with sign */
01639         return (val < n) ? -1 : (val > n);
01640 }
01641 
01642 COB_STATIC int
01643 cob_cmpswp_u32_binary (const unsigned char *p, const int n)
01644 {
01645 #ifndef ALLOW_MISALIGNED
01646         unsigned char   *x;
01647 #endif
01648         unsigned int    val;
01649 
01650         if (n < 0) {
01651                 return 1;
01652         }
01653 #ifdef ALLOW_MISALIGNED
01654         val = COB_BSWAP_32 (*(const unsigned int MISALIGNED *)p);
01655 #else
01656         x = (unsigned char *)&val;
01657         *x = *p;
01658         *(x + 1) = *(p + 1);
01659         *(x + 2) = *(p + 2);
01660         *(x + 3) = *(p + 3);
01661         val = COB_BSWAP_32 (val);
01662 #endif
01663         return (val < n) ? -1 : (val > n);
01664 }
01665 
01666 COB_STATIC int
01667 cob_cmpswp_s32_binary (const unsigned char *p, const int n)
01668 {
01669         int     val;
01670 
01671 #ifdef ALLOW_MISALIGNED
01672         val = COB_BSWAP_32 (*(const int MISALIGNED *)p);
01673 #else
01674         unsigned char   *x;
01675 
01676         x = (unsigned char *)&val;
01677         *x = *p;
01678         *(x + 1) = *(p + 1);
01679         *(x + 2) = *(p + 2);
01680         *(x + 3) = *(p + 3);
01681         val = COB_BSWAP_32 (val);
01682 #endif
01683         return (val < n) ? -1 : (val > n);
01684 }
01685 
01686 COB_STATIC int
01687 cob_cmpswp_u40_binary (const unsigned char *p, const int n)
01688 {
01689         unsigned long long      val = 0;
01690         unsigned char   *x;
01691 
01692         if (n < 0) {
01693                 return 1;
01694         }
01695         x = ((unsigned char *)&val) + 3;
01696         *x = *p;
01697         *(x + 1) = *(p + 1);
01698         *(x + 2) = *(p + 2);
01699         *(x + 3) = *(p + 3);
01700         *(x + 4) = *(p + 4);
01701         val = COB_BSWAP_64 (val);
01702         return (val < n) ? -1 : (val > n);
01703 }
01704 
01705 COB_STATIC int
01706 cob_cmpswp_s40_binary (const unsigned char *p, const int n)
01707 {
01708         long long       val = 0;
01709         unsigned char   *x;
01710 
01711         x = (unsigned char *)&val;
01712         *x = *p;
01713         *(x + 1) = *(p + 1);
01714         *(x + 2) = *(p + 2);
01715         *(x + 3) = *(p + 3);
01716         *(x + 4) = *(p + 4);
01717         val = COB_BSWAP_64 (val);
01718         val >>= 24;     /* shift with sign */
01719         return (val < n) ? -1 : (val > n);
01720 }
01721 
01722 COB_STATIC int
01723 cob_cmpswp_u48_binary (const unsigned char *p, const int n)
01724 {
01725         unsigned long long      val = 0;
01726         unsigned char   *x;
01727 
01728         if (n < 0) {
01729                 return 1;
01730         }
01731         x = ((unsigned char *)&val) + 2;
01732         *x = *p;
01733         *(x + 1) = *(p + 1);
01734         *(x + 2) = *(p + 2);
01735         *(x + 3) = *(p + 3);
01736         *(x + 4) = *(p + 4);
01737         *(x + 5) = *(p + 5);
01738         val = COB_BSWAP_64 (val);
01739         return (val < n) ? -1 : (val > n);
01740 }
01741 
01742 COB_STATIC int
01743 cob_cmpswp_s48_binary (const unsigned char *p, const int n)
01744 {
01745         long long       val = 0;
01746         unsigned char   *x;
01747 
01748         x = (unsigned char *)&val;
01749         *x = *p;
01750         *(x + 1) = *(p + 1);
01751         *(x + 2) = *(p + 2);
01752         *(x + 3) = *(p + 3);
01753         *(x + 4) = *(p + 4);
01754         *(x + 5) = *(p + 5);
01755         val = COB_BSWAP_64 (val);
01756         val >>= 16;     /* shift with sign */
01757         return (val < n) ? -1 : (val > n);
01758 }
01759 
01760 COB_STATIC int
01761 cob_cmpswp_u56_binary (const unsigned char *p, const int n)
01762 {
01763         unsigned long long      val = 0;
01764         unsigned char   *x;
01765 
01766         if (n < 0) {
01767                 return 1;
01768         }
01769         x = ((unsigned char *)&val) + 1;
01770         *x = *p;
01771         *(x + 1) = *(p + 1);
01772         *(x + 2) = *(p + 2);
01773         *(x + 3) = *(p + 3);
01774         *(x + 4) = *(p + 4);
01775         *(x + 5) = *(p + 5);
01776         *(x + 6) = *(p + 6);
01777         val = COB_BSWAP_64 (val);
01778         return (val < n) ? -1 : (val > n);
01779 }
01780 
01781 COB_STATIC int
01782 cob_cmpswp_s56_binary (const unsigned char *p, const int n)
01783 {
01784         long long       val = 0;
01785         unsigned char   *x;
01786 
01787         x = (unsigned char *)&val;
01788         *x = *p;
01789         *(x + 1) = *(p + 1);
01790         *(x + 2) = *(p + 2);
01791         *(x + 3) = *(p + 3);
01792         *(x + 4) = *(p + 4);
01793         *(x + 5) = *(p + 5);
01794         *(x + 6) = *(p + 6);
01795         val = COB_BSWAP_64 (val);
01796         val >>= 8;      /* shift with sign */
01797         return (val < n) ? -1 : (val > n);
01798 }
01799 
01800 COB_STATIC int
01801 cob_cmpswp_u64_binary (const unsigned char *p, const int n)
01802 {
01803 #ifndef ALLOW_MISALIGNED
01804         unsigned char           *x;
01805 #endif
01806         unsigned long long      val;
01807 
01808         if (n < 0) {
01809                 return 1;
01810         }
01811 #ifdef ALLOW_MISALIGNED
01812         val = COB_BSWAP_64 (*(const unsigned long long MISALIGNED *)p);
01813 #else
01814         x = (unsigned char *)&val;
01815         *x = *p;
01816         *(x + 1) = *(p + 1);
01817         *(x + 2) = *(p + 2);
01818         *(x + 3) = *(p + 3);
01819         *(x + 4) = *(p + 4);
01820         *(x + 5) = *(p + 5);
01821         *(x + 6) = *(p + 6);
01822         *(x + 7) = *(p + 7);
01823         val = COB_BSWAP_64 (val);
01824 #endif
01825         return (val < n) ? -1 : (val > n);
01826 }
01827 
01828 COB_STATIC int
01829 cob_cmpswp_s64_binary (const unsigned char *p, const int n)
01830 {
01831         long long       val;
01832 
01833 #ifdef ALLOW_MISALIGNED
01834         val = COB_BSWAP_64 (*(const long long MISALIGNED *)p);
01835 #else
01836         unsigned char   *x;
01837         x = (unsigned char *)&val;
01838         *x = *p;
01839         *(x + 1) = *(p + 1);
01840         *(x + 2) = *(p + 2);
01841         *(x + 3) = *(p + 3);
01842         *(x + 4) = *(p + 4);
01843         *(x + 5) = *(p + 5);
01844         *(x + 6) = *(p + 6);
01845         *(x + 7) = *(p + 7);
01846         val = COB_BSWAP_64 (val);
01847 #endif
01848         return (val < n) ? -1 : (val > n);
01849 }
01850 
01851 /* Binary swapped add */
01852 COB_STATIC void
01853 cob_addswp_u16_binary (unsigned char *p, const int val)
01854 {
01855         unsigned short  n;
01856 
01857 #ifdef ALLOW_MISALIGNED
01858         n = COB_BSWAP_16 (*(unsigned short MISALIGNED *)p);
01859         n += val;
01860         *(unsigned short MISALIGNED *)p = COB_BSWAP_16(n);
01861 #else
01862         n = (unsigned short)((p[0] << 8) | p[1]);
01863         n += val;
01864         p[0] = (unsigned char)(n >> 8);
01865         p[1] = (unsigned char)n;
01866 #endif
01867 }
01868 
01869 COB_STATIC void
01870 cob_addswp_s16_binary (unsigned char *p, const int val)
01871 {
01872         short           n;
01873 
01874 #ifdef ALLOW_MISALIGNED
01875         n = COB_BSWAP_16 (*(short MISALIGNED *)p);
01876         n += val;
01877         *(short MISALIGNED *)p = COB_BSWAP_16(n);
01878 #else
01879         n = (short)((p[0] << 8) | p[1]);
01880         n += val;
01881         p[0] = (unsigned char)(n >> 8);
01882         p[1] = (unsigned char)n;
01883 #endif
01884 }
01885 
01886 COB_STATIC void
01887 cob_addswp_u24_binary (unsigned char *p, const int val)
01888 {
01889         unsigned char   *x;
01890         unsigned int    n = 0;
01891 
01892         x = (unsigned char *)&n;
01893         *x = *(p + 2);
01894         *(x + 1) = *(p + 1);
01895         *(x + 2) = *p;
01896         n += val;
01897         *p = *(x + 2);
01898         *(p + 1) = *(x + 1);
01899         *(p + 2) = *x;
01900 }
01901 
01902 COB_STATIC void
01903 cob_addswp_s24_binary (unsigned char *p, const int val)
01904 {
01905         unsigned char   *x;
01906         int             n = 0;
01907 
01908         x = ((unsigned char *)&n) + 1;
01909         *x = *(p + 2);
01910         *(x + 1) = *(p + 1);
01911         *(x + 2) = *p;
01912         n >>= 8;        /* shift with sign */
01913         n += val;
01914         x = (unsigned char *)&n;
01915         *p = *(x + 2);
01916         *(p + 1) = *(x + 1);
01917         *(p + 2) = *x;
01918 }
01919 
01920 COB_STATIC void
01921 cob_addswp_u32_binary (unsigned char *p, const int val)
01922 {
01923         unsigned int    n;
01924 
01925 #ifdef ALLOW_MISALIGNED
01926         n = COB_BSWAP_32 (*(unsigned int MISALIGNED *)p);
01927         n += val;
01928         *(unsigned int MISALIGNED *)p = COB_BSWAP_32(n);
01929 #else
01930         n = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
01931         n += val;
01932         *p++ = (unsigned char)(n >> 24);
01933         *p++ = (unsigned char)(n >> 16);
01934         *p++ = (unsigned char)(n >> 8);
01935         *p = (unsigned char)n;
01936 #endif
01937 }
01938 
01939 COB_STATIC void
01940 cob_addswp_s32_binary (unsigned char *p, const int val)
01941 {
01942         int             n;
01943 
01944 #ifdef ALLOW_MISALIGNED
01945         n = COB_BSWAP_32 (*(int MISALIGNED *)p);
01946         n += val;
01947         *(int MISALIGNED *)p = COB_BSWAP_32(n);
01948 #else
01949         n = (int)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
01950         n += val;
01951         *p++ = (unsigned char)(n >> 24);
01952         *p++ = (unsigned char)(n >> 16);
01953         *p++ = (unsigned char)(n >> 8);
01954         *p = (unsigned char)n;
01955 #endif
01956 }
01957 
01958 COB_STATIC void
01959 cob_addswp_u40_binary (unsigned char *p, const int val)
01960 {
01961         unsigned long long      n = 0;
01962         unsigned char           *x;
01963 
01964         x = (unsigned char *)&n;
01965         *x = *(p + 4);
01966         *(x + 1) = *(p + 3);
01967         *(x + 2) = *(p + 2);
01968         *(x + 3) = *(p + 1);
01969         *(x + 4) = *p;
01970         n += val;
01971         *p = *(x + 4);
01972         *(p + 1) = *(x + 3);
01973         *(p + 2) = *(x + 2);
01974         *(p + 3) = *(x + 1);
01975         *(p + 4) = *x;
01976 }
01977 
01978 COB_STATIC void
01979 cob_addswp_s40_binary (unsigned char *p, const int val)
01980 {
01981         long long               n = 0;
01982         unsigned char           *x;
01983 
01984         x = ((unsigned char *)&n) + 3;
01985         *x = *(p + 4);
01986         *(x + 1) = *(p + 3);
01987         *(x + 2) = *(p + 2);
01988         *(x + 3) = *(p + 1);
01989         *(x + 4) = *p;
01990         n >>= 24;       /* shift with sign */
01991         n += val;
01992         x = (unsigned char *)&n;
01993         *p = *(x + 4);
01994         *(p + 1) = *(x + 3);
01995         *(p + 2) = *(x + 2);
01996         *(p + 3) = *(x + 1);
01997         *(p + 4) = *x;
01998 }
01999 
02000 COB_STATIC void
02001 cob_addswp_u48_binary (unsigned char *p, const int val)
02002 {
02003         unsigned long long      n = 0;
02004         unsigned char           *x;
02005 
02006         x = (unsigned char *)&n;
02007         *x = *(p + 5);
02008         *(x + 1) = *(p + 4);
02009         *(x + 2) = *(p + 3);
02010         *(x + 3) = *(p + 2);
02011         *(x + 4) = *(p + 1);
02012         *(x + 5) = *p;
02013         n += val;
02014         *p = *(x + 5);
02015         *(p + 1) = *(x + 4);
02016         *(p + 2) = *(x + 3);
02017         *(p + 3) = *(x + 2);
02018         *(p + 4) = *(x + 1);
02019         *(p + 5) = *x;
02020 }
02021 
02022 COB_STATIC void
02023 cob_addswp_s48_binary (unsigned char *p, const int val)
02024 {
02025         long long               n = 0;
02026         unsigned char           *x;
02027 
02028         x = ((unsigned char *)&n) + 2;
02029         *x = *(p + 5);
02030         *(x + 1) = *(p + 4);
02031         *(x + 2) = *(p + 3);
02032         *(x + 3) = *(p + 2);
02033         *(x + 4) = *(p + 1);
02034         *(x + 5) = *p;
02035         n >>= 16;       /* shift with sign */
02036         n += val;
02037         x = (unsigned char *)&n;
02038         *p = *(x + 5);
02039         *(p + 1) = *(x + 4);
02040         *(p + 2) = *(x + 3);
02041         *(p + 3) = *(x + 2);
02042         *(p + 4) = *(x + 1);
02043         *(p + 5) = *x;
02044 }
02045 
02046 COB_STATIC void
02047 cob_addswp_u56_binary (unsigned char *p, const int val)
02048 {
02049         unsigned long long      n = 0;
02050         unsigned char           *x;
02051 
02052         x = (unsigned char *)&n;
02053         *x = *(p + 6);
02054         *(x + 1) = *(p + 5);
02055         *(x + 2) = *(p + 4);
02056         *(x + 3) = *(p + 3);
02057         *(x + 4) = *(p + 2);
02058         *(x + 5) = *(p + 1);
02059         *(x + 6) = *p;
02060         n += val;
02061         *p = *(x + 6);
02062         *(p + 1) = *(x + 5);
02063         *(p + 2) = *(x + 4);
02064         *(p + 3) = *(x + 3);
02065         *(p + 4) = *(x + 2);
02066         *(p + 5) = *(x + 1);
02067         *(p + 6) = *x;
02068 }
02069 
02070 COB_STATIC void
02071 cob_addswp_s56_binary (unsigned char *p, const int val)
02072 {
02073         long long               n = 0;
02074         unsigned char           *x;
02075 
02076         x = ((unsigned char *)&n) + 1;
02077         *x = *(p + 6);
02078         *(x + 1) = *(p + 5);
02079         *(x + 2) = *(p + 4);
02080         *(x + 3) = *(p + 3);
02081         *(x + 4) = *(p + 2);
02082         *(x + 5) = *(p + 1);
02083         *(x + 6) = *p;
02084         n >>= 8;        /* shift with sign */
02085         n += val;
02086         x = (unsigned char *)&n;
02087         *p = *(x + 6);
02088         *(p + 1) = *(x + 5);
02089         *(p + 2) = *(x + 4);
02090         *(p + 3) = *(x + 3);
02091         *(p + 4) = *(x + 2);
02092         *(p + 5) = *(x + 1);
02093         *(p + 6) = *x;
02094 }
02095 
02096 COB_STATIC void
02097 cob_addswp_u64_binary (unsigned char *p, const int val)
02098 {
02099 #ifdef ALLOW_MISALIGNED
02100         unsigned long long      n;
02101 
02102         n = COB_BSWAP_64 (*(unsigned long long MISALIGNED *)p);
02103         n += val;
02104         *(unsigned long long MISALIGNED *)p = COB_BSWAP_64(n);
02105 #else
02106         size_t  i;
02107         union {
02108                 unsigned long long      n;
02109                 unsigned char           c[8];
02110         } u;
02111 
02112         for (i = 0; i < 8; ++i) {
02113                 u.c[7-i] = p[i];
02114         }
02115         u.n += val;
02116         for (i = 0; i < 8; ++i) {
02117                 p[i] = u.c[7-i];
02118         }
02119 #endif
02120 }
02121 
02122 COB_STATIC void
02123 cob_addswp_s64_binary (unsigned char *p, const int val)
02124 {
02125 #ifdef ALLOW_MISALIGNED
02126         long long       n;
02127 
02128         n = COB_BSWAP_64 (*(long long MISALIGNED *)p);
02129         n += val;
02130         *(long long MISALIGNED *)p = COB_BSWAP_64(n);
02131 #else
02132         size_t  i;
02133         union {
02134                 long long       n;
02135                 unsigned char   c[8];
02136         } u;
02137 
02138         for (i = 0; i < 8; ++i) {
02139                 u.c[7-i] = p[i];
02140         }
02141         u.n += val;
02142         for (i = 0; i < 8; ++i) {
02143                 p[i] = u.c[7-i];
02144         }
02145 #endif
02146 }
02147 
02148 /* Binary swapped subtract */
02149 COB_STATIC void
02150 cob_subswp_u16_binary (unsigned char *p, const int val)
02151 {
02152         unsigned short  n;
02153 
02154 #ifdef ALLOW_MISALIGNED
02155         n = COB_BSWAP_16 (*(unsigned short MISALIGNED *)p);
02156         n -= val;
02157         *(unsigned short MISALIGNED *)p = COB_BSWAP_16(n);
02158 #else
02159         n = (unsigned short)((p[0] << 8) | p[1]);
02160         n -= val;
02161         p[0] = (unsigned char)(n >> 8);
02162         p[1] = (unsigned char)n;
02163 #endif
02164 }
02165 
02166 COB_STATIC void
02167 cob_subswp_s16_binary (unsigned char *p, const int val)
02168 {
02169         short           n;
02170 
02171 #ifdef ALLOW_MISALIGNED
02172         n = COB_BSWAP_16 (*(short MISALIGNED *)p);
02173         n -= val;
02174         *(short MISALIGNED *)p = COB_BSWAP_16(n);
02175 #else
02176         n = (short)((p[0] << 8) | p[1]);
02177         n -= val;
02178         p[0] = (unsigned char)(n >> 8);
02179         p[1] = (unsigned char)n;
02180 #endif
02181 }
02182 
02183 COB_STATIC void
02184 cob_subswp_u24_binary (unsigned char *p, const int val)
02185 {
02186         unsigned char   *x;
02187         unsigned int    n = 0;
02188 
02189         x = (unsigned char *)&n;
02190         *x = *(p + 2);
02191         *(x + 1) = *(p + 1);
02192         *(x + 2) = *p;
02193         n -= val;
02194         *p = *(x + 2);
02195         *(p + 1) = *(x + 1);
02196         *(p + 2) = *x;
02197 }
02198 
02199 COB_STATIC void
02200 cob_subswp_s24_binary (unsigned char *p, const int val)
02201 {
02202         unsigned char   *x;
02203         int             n = 0;
02204 
02205         x = ((unsigned char *)&n) + 1;
02206         *x = *(p + 2);
02207         *(x + 1) = *(p + 1);
02208         *(x + 2) = *p;
02209         n >>= 8;        /* shift with sign */
02210         n -= val;
02211         x = (unsigned char *)&n;
02212         *p = *(x + 2);
02213         *(p + 1) = *(x + 1);
02214         *(p + 2) = *x;
02215 }
02216 
02217 COB_STATIC void
02218 cob_subswp_u32_binary (unsigned char *p, const int val)
02219 {
02220         unsigned int    n;
02221 
02222 #ifdef ALLOW_MISALIGNED
02223         n = COB_BSWAP_32 (*(unsigned int MISALIGNED *)p);
02224         n -= val;
02225         *(unsigned int MISALIGNED *)p = COB_BSWAP_32(n);
02226 #else
02227         n = (unsigned int)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
02228         n -= val;
02229         *p++ = (unsigned char)(n >> 24);
02230         *p++ = (unsigned char)(n >> 16);
02231         *p++ = (unsigned char)(n >> 8);
02232         *p = (unsigned char)n;
02233 #endif
02234 }
02235 
02236 COB_STATIC void
02237 cob_subswp_s32_binary (unsigned char *p, const int val)
02238 {
02239         int             n;
02240 
02241 #ifdef ALLOW_MISALIGNED
02242         n = COB_BSWAP_32 (*(int MISALIGNED *)p);
02243         n -= val;
02244         *(int MISALIGNED *)p = COB_BSWAP_32(n);
02245 #else
02246         n = (int)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
02247         n -= val;
02248         *p++ = (unsigned char)(n >> 24);
02249         *p++ = (unsigned char)(n >> 16);
02250         *p++ = (unsigned char)(n >> 8);
02251         *p = (unsigned char)n;
02252 #endif
02253 }
02254 
02255 COB_STATIC void
02256 cob_subswp_u40_binary (unsigned char *p, const int val)
02257 {
02258         unsigned long long      n = 0;
02259         unsigned char           *x;
02260 
02261         x = (unsigned char *)&n;
02262         *x = *(p + 4);
02263         *(x + 1) = *(p + 3);
02264         *(x + 2) = *(p + 2);
02265         *(x + 3) = *(p + 1);
02266         *(x + 4) = *p;
02267         n -= val;
02268         *p = *(x + 4);
02269         *(p + 1) = *(x + 3);
02270         *(p + 2) = *(x + 2);
02271         *(p + 3) = *(x + 1);
02272         *(p + 4) = *x;
02273 }
02274 
02275 COB_STATIC void
02276 cob_subswp_s40_binary (unsigned char *p, const int val)
02277 {
02278         long long               n = 0;
02279         unsigned char           *x;
02280 
02281         x = ((unsigned char *)&n) + 3;
02282         *x = *(p + 4);
02283         *(x + 1) = *(p + 3);
02284         *(x + 2) = *(p + 2);
02285         *(x + 3) = *(p + 1);
02286         *(x + 4) = *p;
02287         n >>= 24;       /* shift with sign */
02288         n -= val;
02289         x = (unsigned char *)&n;
02290         *p = *(x + 4);
02291         *(p + 1) = *(x + 3);
02292         *(p + 2) = *(x + 2);
02293         *(p + 3) = *(x + 1);
02294         *(p + 4) = *x;
02295 }
02296 
02297 COB_STATIC void
02298 cob_subswp_u48_binary (unsigned char *p, const int val)
02299 {
02300         unsigned long long      n = 0;
02301         unsigned char           *x;
02302 
02303         x = (unsigned char *)&n;
02304         *x = *(p + 5);
02305         *(x + 1) = *(p + 4);
02306         *(x + 2) = *(p + 3);
02307         *(x + 3) = *(p + 2);
02308         *(x + 4) = *(p + 1);
02309         *(x + 5) = *p;
02310         n -= val;
02311         *p = *(x + 5);
02312         *(p + 1) = *(x + 4);
02313         *(p + 2) = *(x + 3);
02314         *(p + 3) = *(x + 2);
02315         *(p + 4) = *(x + 1);
02316         *(p + 5) = *x;
02317 }
02318 
02319 COB_STATIC void
02320 cob_subswp_s48_binary (unsigned char *p, const int val)
02321 {
02322         long long               n = 0;
02323         unsigned char           *x;
02324 
02325         x = ((unsigned char *)&n) + 2;
02326         *x = *(p + 5);
02327         *(x + 1) = *(p + 4);
02328         *(x + 2) = *(p + 3);
02329         *(x + 3) = *(p + 2);
02330         *(x + 4) = *(p + 1);
02331         *(x + 5) = *p;
02332         n >>= 16;       /* shift with sign */
02333         n -= val;
02334         x = (unsigned char *)&n;
02335         *p = *(x + 5);
02336         *(p + 1) = *(x + 4);
02337         *(p + 2) = *(x + 3);
02338         *(p + 3) = *(x + 2);
02339         *(p + 4) = *(x + 1);
02340         *(p + 5) = *x;
02341 }
02342 
02343 COB_STATIC void
02344 cob_subswp_u56_binary (unsigned char *p, const int val)
02345 {
02346         unsigned long long      n = 0;
02347         unsigned char           *x;
02348 
02349         x = (unsigned char *)&n;
02350         *x = *(p + 6);
02351         *(x + 1) = *(p + 5);
02352         *(x + 2) = *(p + 4);
02353         *(x + 3) = *(p + 3);
02354         *(x + 4) = *(p + 2);
02355         *(x + 5) = *(p + 1);
02356         *(x + 6) = *p;
02357         n -= val;
02358         *p = *(x + 6);
02359         *(p + 1) = *(x + 5);
02360         *(p + 2) = *(x + 4);
02361         *(p + 3) = *(x + 3);
02362         *(p + 4) = *(x + 2);
02363         *(p + 5) = *(x + 1);
02364         *(p + 6) = *x;
02365 }
02366 
02367 COB_STATIC void
02368 cob_subswp_s56_binary (unsigned char *p, const int val)
02369 {
02370         long long               n = 0;
02371         unsigned char           *x;
02372 
02373         x = ((unsigned char *)&n) + 1;
02374         *x = *(p + 6);
02375         *(x + 1) = *(p + 5);
02376         *(x + 2) = *(p + 4);
02377         *(x + 3) = *(p + 3);
02378         *(x + 4) = *(p + 2);
02379         *(x + 5) = *(p + 1);
02380         *(x + 6) = *p;
02381         n >>= 8;        /* shift with sign */
02382         n -= val;
02383         x = (unsigned char *)&n;
02384         *p = *(x + 6);
02385         *(p + 1) = *(x + 5);
02386         *(p + 2) = *(x + 4);
02387         *(p + 3) = *(x + 3);
02388         *(p + 4) = *(x + 2);
02389         *(p + 5) = *(x + 1);
02390         *(p + 6) = *x;
02391 }
02392 
02393 COB_STATIC void
02394 cob_subswp_u64_binary (unsigned char *p, const int val)
02395 {
02396 #ifdef ALLOW_MISALIGNED
02397         unsigned long long      n;
02398 
02399         n = COB_BSWAP_64 (*(unsigned long long MISALIGNED *)p);
02400         n -= val;
02401         *(unsigned long long MISALIGNED *)p = COB_BSWAP_64(n);
02402 #else
02403         size_t  i;
02404         union {
02405                 unsigned long long      n;
02406                 unsigned char           c[8];
02407         } u;
02408 
02409         for (i = 0; i < 8; ++i) {
02410                 u.c[7-i] = p[i];
02411         }
02412         u.n -= val;
02413         for (i = 0; i < 8; ++i) {
02414                 p[i] = u.c[7-i];
02415         }
02416 #endif
02417 }
02418 
02419 COB_STATIC void
02420 cob_subswp_s64_binary (unsigned char *p, const int val)
02421 {
02422 #ifdef ALLOW_MISALIGNED
02423         long long       n;
02424 
02425         n = COB_BSWAP_64 (*(long long MISALIGNED *)p);
02426         n -= val;
02427         *(long long MISALIGNED *)p = COB_BSWAP_64(n);
02428 #else
02429         size_t  i;
02430         union {
02431                 long long       n;
02432                 unsigned char   c[8];
02433         } u;
02434 
02435         for (i = 0; i < 8; ++i) {
02436                 u.c[7-i] = p[i];
02437         }
02438         u.n -= val;
02439         for (i = 0; i < 8; ++i) {
02440                 p[i] = u.c[7-i];
02441         }
02442 #endif
02443 }
02444 
02445 COB_STATIC void
02446 cob_setswp_u16_binary (unsigned char *p, const int val)
02447 {
02448         unsigned short  n;
02449 
02450 #ifdef ALLOW_MISALIGNED
02451         n = val;
02452         *(unsigned short MISALIGNED *)p = COB_BSWAP_16(n);
02453 #else
02454         n = val;
02455         p[0] = (unsigned char)(n >> 8);
02456         p[1] = (unsigned char)n;
02457 #endif
02458 }
02459 
02460 COB_STATIC void
02461 cob_setswp_s16_binary (unsigned char *p, const int val)
02462 {
02463         short           n;
02464 
02465 #ifdef ALLOW_MISALIGNED
02466         n = val;
02467         *(short MISALIGNED *)p = COB_BSWAP_16(n);
02468 #else
02469         n = val;
02470         p[0] = (unsigned char)(n >> 8);
02471         p[1] = (unsigned char)n;
02472 #endif
02473 }
02474 
02475 COB_STATIC void
02476 cob_setswp_u24_binary (unsigned char *p, const int val)
02477 {
02478         unsigned char   *x;
02479         unsigned int    n;
02480 
02481         n = val;
02482         x = (unsigned char *)&n;
02483         *p = *(x + 2);
02484         *(p + 1) = *(x + 1);
02485         *(p + 2) = *x;
02486 }
02487 
02488 COB_STATIC void
02489 cob_setswp_s24_binary (unsigned char *p, const int val)
02490 {
02491         unsigned char   *x;
02492         int             n;
02493 
02494         n = val;
02495         x = (unsigned char *)&n;
02496         *p = *(x + 2);
02497         *(p + 1) = *(x + 1);
02498         *(p + 2) = *x;
02499 }
02500 
02501 COB_STATIC void
02502 cob_setswp_u32_binary (unsigned char *p, const int val)
02503 {
02504         unsigned int    n;
02505 
02506 #ifdef ALLOW_MISALIGNED
02507         n = val;
02508         *(unsigned int MISALIGNED *)p = COB_BSWAP_32(n);
02509 #else
02510         n = val;
02511         *p++ = (unsigned char)(n >> 24);
02512         *p++ = (unsigned char)(n >> 16);
02513         *p++ = (unsigned char)(n >> 8);
02514         *p = (unsigned char)n;
02515 #endif
02516 }
02517 
02518 COB_STATIC void
02519 cob_setswp_s32_binary (unsigned char *p, const int val)
02520 {
02521         int             n;
02522 
02523 #ifdef ALLOW_MISALIGNED
02524         n = val;
02525         *(int MISALIGNED *)p = COB_BSWAP_32(n);
02526 #else
02527         n = val;
02528         *p++ = (unsigned char)(n >> 24);
02529         *p++ = (unsigned char)(n >> 16);
02530         *p++ = (unsigned char)(n >> 8);
02531         *p = (unsigned char)n;
02532 #endif
02533 }
02534 
02535 COB_STATIC void
02536 cob_setswp_u40_binary (unsigned char *p, const int val)
02537 {
02538         unsigned long long      n;
02539         unsigned char           *x;
02540 
02541         n = val;
02542         x = (unsigned char *)&n;
02543         *p = *(x + 4);
02544         *(p + 1) = *(x + 3);
02545         *(p + 2) = *(x + 2);
02546         *(p + 3) = *(x + 1);
02547         *(p + 4) = *x;
02548 }
02549 
02550 COB_STATIC void
02551 cob_setswp_s40_binary (unsigned char *p, const int val)
02552 {
02553         long long               n;
02554         unsigned char           *x;
02555 
02556         n = val;
02557         x = (unsigned char *)&n;
02558         *p = *(x + 4);
02559         *(p + 1) = *(x + 3);
02560         *(p + 2) = *(x + 2);
02561         *(p + 3) = *(x + 1);
02562         *(p + 4) = *x;
02563 }
02564 
02565 COB_STATIC void
02566 cob_setswp_u48_binary (unsigned char *p, const int val)
02567 {
02568         unsigned long long      n;
02569         unsigned char           *x;
02570 
02571         n = val;
02572         x = (unsigned char *)&n;
02573         *p = *(x + 5);
02574         *(p + 1) = *(x + 4);
02575         *(p + 2) = *(x + 3);
02576         *(p + 3) = *(x + 2);
02577         *(p + 4) = *(x + 1);
02578         *(p + 5) = *x;
02579 }
02580 
02581 COB_STATIC void
02582 cob_setswp_s48_binary (unsigned char *p, const int val)
02583 {
02584         long long               n;
02585         unsigned char           *x;
02586 
02587         n = val;
02588         x = (unsigned char *)&n;
02589         *p = *(x + 5);
02590         *(p + 1) = *(x + 4);
02591         *(p + 2) = *(x + 3);
02592         *(p + 3) = *(x + 2);
02593         *(p + 4) = *(x + 1);
02594         *(p + 5) = *x;
02595 }
02596 
02597 COB_STATIC void
02598 cob_setswp_u56_binary (unsigned char *p, const int val)
02599 {
02600         unsigned long long      n;
02601         unsigned char           *x;
02602 
02603         n = val;
02604         x = (unsigned char *)&n;
02605         *p = *(x + 6);
02606         *(p + 1) = *(x + 5);
02607         *(p + 2) = *(x + 4);
02608         *(p + 3) = *(x + 3);
02609         *(p + 4) = *(x + 2);
02610         *(p + 5) = *(x + 1);
02611         *(p + 6) = *x;
02612 }
02613 
02614 COB_STATIC void
02615 cob_setswp_s56_binary (unsigned char *p, const int val)
02616 {
02617         long long               n;
02618         unsigned char           *x;
02619 
02620         n = val;
02621         x = (unsigned char *)&n;
02622         *p = *(x + 6);
02623         *(p + 1) = *(x + 5);
02624         *(p + 2) = *(x + 4);
02625         *(p + 3) = *(x + 3);
02626         *(p + 4) = *(x + 2);
02627         *(p + 5) = *(x + 1);
02628         *(p + 6) = *x;
02629 }
02630 
02631 COB_STATIC void
02632 cob_setswp_u64_binary (unsigned char *p, const int val)
02633 {
02634 #ifdef ALLOW_MISALIGNED
02635         unsigned long long      n;
02636 
02637         n = val;
02638         *(unsigned long long MISALIGNED *)p = COB_BSWAP_64(n);
02639 #else
02640         size_t  i;
02641         union {
02642                 unsigned long long      n;
02643                 unsigned char           c[8];
02644         } u;
02645 
02646         u.n = val;
02647         for (i = 0; i < 8; ++i) {
02648                 p[i] = u.c[7-i];
02649         }
02650 #endif
02651 }
02652 
02653 COB_STATIC void
02654 cob_setswp_s64_binary (unsigned char *p, const int val)
02655 {
02656 #ifdef ALLOW_MISALIGNED
02657         long long       n;
02658 
02659         n = val;
02660         *(long long MISALIGNED *)p = COB_BSWAP_64(n);
02661 #else
02662         size_t  i;
02663         union {
02664                 long long       n;
02665                 unsigned char   c[8];
02666         } u;
02667 
02668         u.n = val;
02669         for (i = 0; i < 8; ++i) {
02670                 p[i] = u.c[7-i];
02671         }
02672 #endif
02673 }
02674 
02675 #endif  /* WORDS_BIGENDIAN */
02676 
02677 #endif  /* COB_LOCAL_INLINE || COB_LIB_INCLUDE */
02678 
02679 #endif  /* COB_CODEGEN_H */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines