summaryrefslogtreecommitdiff
path: root/support/dktools/dk3maod8.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/dk3maod8.c
Initial commit
Diffstat (limited to 'support/dktools/dk3maod8.c')
-rw-r--r--support/dktools/dk3maod8.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/support/dktools/dk3maod8.c b/support/dktools/dk3maod8.c
new file mode 100644
index 0000000000..afa4de204c
--- /dev/null
+++ b/support/dktools/dk3maod8.c
@@ -0,0 +1,148 @@
+/*
+ WARNING: This file was generated by dkct.
+ Changes you make here will be lost if dkct is run again!
+ You should modify the original source and run dkct on it.
+ Original source: dk3maod8.ctr
+*/
+
+/*
+Copyright (C) 2014-2017, Dirk Krause
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above opyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+* Neither the name of the author nor the names of contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/** @file dk3maod8.c The dk3maod8 module.
+*/
+
+
+#line 65 "dk3maod8.ctr"
+
+#include "dk3ma.h"
+
+
+
+
+
+#line 71 "dk3maod8.ctr"
+
+
+
+/** Size correction for alignment.
+*/
+#define DK3MAOD8_ALIGN(sz,al) \
+((0 == (sz % al)) ? (sz) : (((sz / al) + 1) * al))
+
+
+int
+dk3ma_um_to_c8_string(char *rb, size_t sz, dk3_um_t va)
+{
+ char buf[DK3MAOD8_ALIGN((8*DK3_SIZEOF_UM),16)];
+ char *ptr;
+ dk3_um_t x;
+ size_t szmax = sizeof(buf);
+ size_t szused = 0;
+ size_t i;
+ int back = 1;
+ char c;
+
+ if ((NULL != rb) && (0 < sz)) {
+ rb[0] = '\0';
+ ptr = buf;
+ if (2 <= szmax) {
+ do {
+ x = va % 10;
+ va = va / 10;
+ c = '\0';
+ switch((int)x) {
+ case 0: { c = '0'; } break;
+ case 1: { c = '1'; } break;
+ case 2: { c = '2'; } break;
+ case 3: { c = '3'; } break;
+ case 4: { c = '4'; } break;
+ case 5: { c = '5'; } break;
+ case 6: { c = '6'; } break;
+ case 7: { c = '7'; } break;
+ case 8: { c = '8'; } break;
+ case 9: { c = '9'; } break;
+ }
+ if (szused < szmax) {
+ *(ptr++) = c;
+ szused++;
+ } else {
+ back = 0;
+ }
+ } while((DK3_UM_0 != va) && (szused < szmax) && (1 == back));
+ if (szused < szmax) {
+ buf[szused] = '\0';
+ } else {
+ back = 0;
+ buf[szmax - 1] = '\0';
+ }
+ if (1 == back) {
+ if (szused < sz) {
+ for (i = 0; i < szused; i++) {
+ rb[i] = buf[szused - i - 1];
+ }
+ rb[szused] = '\0';
+ } else {
+ back = 0;
+ }
+ }
+ }
+ }
+ return back;
+}
+
+
+
+int
+dk3ma_im_to_c8_string(char *rb, size_t sz, dk3_im_t va)
+{
+ char *orb;
+ dk3_um_t umva;
+ int back = 0;
+ if ((NULL != rb) && (0 < sz)) {
+ orb = rb;
+ rb[0] = '\0';
+ if (2 < sz) {
+ if (DK3_IM_0 > va) {
+ *(rb++) = '-';
+ sz--;
+ if (DK3_IM_MIN == va) {
+ umva = (dk3_um_t)DK3_IM_MAX;
+ umva++;
+ } else {
+ umva = (dk3_um_t)(DK3_IM_0 - va);
+ }
+ } else {
+ umva = (dk3_um_t)va;
+ }
+ back = dk3ma_um_to_c8_string(rb, sz, umva);
+ }
+ if (0 == back) { *orb = '\0'; }
+ }
+ return back;
+}
+