rtltype.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "platform.h"
  14. #include <math.h>
  15. #include <stdio.h>
  16. #include "jmisc.hpp"
  17. #include "jlib.hpp"
  18. #include "rtltype.hpp"
  19. //=============================================================================
  20. // Pascal string helper functions...
  21. typedef unsigned char pascalLengthField;
  22. unsigned rtlGetPascalLength(unsigned len, const void * data)
  23. {
  24. return sizeof(pascalLengthField) + *(pascalLengthField *)data;
  25. }
  26. void rtlPascalToString(unsigned & tgtLen, char * & tgt, unsigned, const void * src)
  27. {
  28. unsigned len = *(pascalLengthField *)src;
  29. char * buff = (char *)malloc(len);
  30. memcpy(buff, (const char *)src+sizeof(pascalLengthField), len);
  31. tgtLen = len;
  32. tgt = buff;
  33. }
  34. void rtlStringToPascal(unsigned & tgtLen, void * & tgt, unsigned srcLen, const char * src)
  35. {
  36. if (srcLen > (pascalLengthField)-1)
  37. srcLen = (pascalLengthField)-1;
  38. unsigned size = srcLen + sizeof(pascalLengthField);
  39. char * buff = (char *)malloc(size);
  40. *(pascalLengthField *)buff = (pascalLengthField)srcLen;
  41. memcpy(buff + sizeof(pascalLengthField), src, srcLen);
  42. tgtLen = size;
  43. tgt = buff;
  44. }
  45. //=============================================================================
  46. void rtlPadTruncString(unsigned & tgtLen, char * & tgt, unsigned newLen, unsigned len, const char * src)
  47. {
  48. if (len > newLen)
  49. len = newLen;
  50. char * buff = (char *)malloc(len);
  51. memcpy(buff, src, len);
  52. if (len < newLen)
  53. memset(buff+len, ' ', newLen - len);
  54. tgtLen = newLen;
  55. tgt = buff;
  56. }
  57. //=============================================================================
  58. __int64 rtlBcdToInteger(unsigned len, char * src)
  59. {
  60. unsigned char * cur = (unsigned char *)src;
  61. __int64 value = 0;
  62. while (len--)
  63. {
  64. unsigned next = *cur++;
  65. value = value * 100 + (next >> 4) * 10 + (next & 0xf);
  66. }
  67. return value;
  68. }
  69. void rtlIntegerToBcd(unsigned & tgtLen, char * & tgt, unsigned digits, __int64 value)
  70. {
  71. }
  72. void rtlIntegerToBcdFixed(char * tgt, unsigned digits, __int64 value)
  73. {
  74. }
  75. //=============================================================================