/src/front/frontcl/libqsys/iicbcomp.c

https://github.com/yorkhua/Ingres · C · 162 lines · 62 code · 19 blank · 81 comment · 5 complexity · 9c0314ea995176cfac5a797418b8246b MD5 · raw file

  1. # include <compat.h>
  2. # ifdef VMS
  3. /*
  4. +* Filename: IICOBPACK.C
  5. ** Purpose: Routines to allow Cobol scaled packed decimal variables to
  6. ** interface with our run-time modules as f8's. It seems that
  7. ** just assign them to f8's causes some truncation by the
  8. ** compiler.
  9. ** Defines:
  10. ** IIpktof8() - Convert scaled packed to f8.
  11. ** IIf8topk() - Convert f8 to scaled packed.
  12. ** IIcmptof8() - Convert scaled COMP to f8.
  13. ** IIf8tocmp() - Convert f8 to scaled COMP.
  14. **
  15. ** Notes: This routine is VMS dependent about the assumptions it makes
  16. ** about the internal storage of ceratin types.
  17. **
  18. ** COBOL Type VAX Type
  19. **
  20. ** comp (scaled) i2 or i4 - Work with f8 variable.
  21. ** comp-2 f8 - Is an f8 for use to use.
  22. -* comp-3 packed - Use f8 (if scaled or too large).
  23. **
  24. ** History:
  25. ** 23-may-1985 Written. (ncg)
  26. ** 02-aug-1989 Shut up ranlib (GordonW)
  27. **
  28. ** Copyright (c) 2004 Ingres Corporation
  29. ** 21-jan-1999 (hanch04)
  30. ** replace nat and longnat with i4
  31. ** 31-aug-2000 (hanch04)
  32. ** cross change to main
  33. ** replace nat and longnat with i4
  34. */
  35. # define COMP_3 char
  36. # define COMP char
  37. /*
  38. +* Procedure: IIpktof8
  39. ** Purpose: Format Packed Decimal (COMP-3) data into C f8.
  40. ** Parameters: dbl - f8 * - COMP-2 variable.
  41. ** pkvar - char *- Packed variable.
  42. ** precision - i4 - Full precision of COMP-3.
  43. ** scale - i4 - Scale factor.
  44. ** Returns: None
  45. ** Example:
  46. ** 01 P PIC S9(2)V9(3) USAGE COMP-3.
  47. -* CALL "IIPKTOF8" USING P IIF8 BY VALUE 5 3.
  48. */
  49. void
  50. IIpktof8( dbl, pkvar, precision, scale )
  51. f8 *dbl;
  52. COMP_3 *pkvar;
  53. i4 precision, scale;
  54. {
  55. i4 lprec = precision;
  56. i4 lscale = scale; /* so not to change original value */
  57. IIptod( dbl, pkvar, lprec, lscale );
  58. }
  59. /*
  60. +* Procedure: IIf8topk
  61. ** Purpose: Format C f8 data into Packed Decimal (COMP-3).
  62. ** Parameters: dbl - f8 * - COMP-2 variable.
  63. ** pkvar - char *- Packed variable.
  64. ** precision - i4 - Full precision of COMP-3.
  65. ** scale - i4 - Scale factor.
  66. ** Returns: None
  67. ** Example:
  68. ** 01 P PIC S9(2)V9(3) USAGE COMP-3.
  69. -* CALL "IIF8TOPK" USING P IIF8 BY VALUE 5 3.
  70. */
  71. void
  72. IIf8topk( dbl, pkvar, precision, scale )
  73. f8 *dbl;
  74. COMP_3 *pkvar;
  75. i4 precision, scale;
  76. {
  77. i4 lprec = precision;
  78. i4 lscale = scale; /* so not to change original value */
  79. IIdtop( *dbl, pkvar, lprec, lscale );
  80. }
  81. /*
  82. +* Procedure: IIcmptof8
  83. ** Purpose: Format COBOL scaled COMP data to C f8 data.
  84. ** Parameters: dbl - f8 * - COMP-2 variable.
  85. ** cmpvar - char *- COMP variable.
  86. ** precision - i4 - Full precision of COMP.
  87. ** scale - i4 - Scale factor.
  88. ** Returns: None
  89. ** Example:
  90. ** 01 C PIC S9(2)V9(3) USAGE COMP.
  91. -* CALL "IICMPTOF8" USING C IIF8 BY VALUE 5 3.
  92. */
  93. void
  94. IIcmptof8( dbl, cmpvar, precision, scale )
  95. f8 *dbl;
  96. COMP *cmpvar;
  97. i4 precision, scale;
  98. {
  99. f8 ldbl;
  100. i4 lscale = scale; /* So not to change original value */
  101. if (precision <= 4) /* Stored as an i2 */
  102. ldbl = (f8) (*(i2 *)cmpvar);
  103. else /* Stored as an i4 - quadword not sup */
  104. ldbl = (f8) (*(i4 *)cmpvar);
  105. while (lscale--) /* Scale the integer down */
  106. ldbl /= 10.0;
  107. *dbl = ldbl;
  108. }
  109. /*
  110. +* Procedure: IIf8tocmp
  111. ** Purpose: Format C f8 to COBOL scaled COMP data item.
  112. ** Parameters: dbl - f8 * - COMP-2 variable.
  113. ** cmpvar - char *- COMP variable.
  114. ** precision - i4 - Full precision of COMP.
  115. ** scale - i4 - Scale factor.
  116. ** Returns: None
  117. ** Example:
  118. ** 01 C PIC S9(2)V9(3) USAGE COMP.
  119. -* CALL "IIF8TOCMP" USING C IIF8 BY VALUE 5 3.
  120. */
  121. void
  122. IIf8tocmp( dbl, cmpvar, precision, scale )
  123. f8 *dbl;
  124. COMP *cmpvar;
  125. i4 precision, scale;
  126. {
  127. f8 ldbl = *dbl;
  128. i4 lscale = scale; /* So not to change original value */
  129. while (lscale--)
  130. ldbl *= 10.0;
  131. /* Now round value up just in case */
  132. if ( ldbl >= 0 )
  133. ldbl += 0.5;
  134. else
  135. ldbl -= 0.5;
  136. if (precision <= 4) /* Stored as an i2 */
  137. *(i2 *)cmpvar = ldbl;
  138. else
  139. *(i4 *)cmpvar = ldbl; /* As an i4 - quadword not supported */
  140. }
  141. # else
  142. static i4 ranlib_dummy;
  143. # endif /* VMS */