File: ting.c

package info (click to toggle)
mcl 1%3A14-137-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd, stretch
  • size: 10,704 kB
  • ctags: 5,125
  • sloc: ansic: 53,217; sh: 4,448; perl: 3,967; makefile: 422
file content (957 lines) | stat: -rw-r--r-- 19,900 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
/*   (C) Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 Stijn van Dongen
 *   (C) Copyright 2006, 2007, 2008, 2009  Stijn van Dongen
 *
 * This file is part of tingea.  You can redistribute and/or modify tingea
 * under the terms of the GNU General Public License; either version 3 of the
 * License or (at your option) any later version.  You should have received a
 * copy of the GPL along with tingea, in the file COPYING.
*/

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>

#include "../config.h"
#include "ting.h"
#include "ding.h"
#include "minmax.h"
#include "alloc.h"
#include "array.h"
#include "hash.h"
#include "types.h"
#include "err.h"
#include "tr.h"



void mcxTingRelease
(  void* tingv
)
   {  if (tingv && ((mcxTing*)tingv)->str)
      mcxFree(((mcxTing*)tingv)->str)
;  }


void mcxTingFree
(  mcxTing            **tingpp
)
   {  mcxTing*  ting   =    *tingpp

   ;  if (ting)
      {  if (ting->str)
         mcxFree(ting->str)
      ;  mcxFree(ting)
      ;  *tingpp = NULL
   ;  }
   }


void mcxTingFree_v
(  void  *tingpp
)
   {  mcxTingFree((mcxTing**) tingpp)
;  }


#if 0
void mcxTingAbandon
(  void  *tingpp
)
   {  mcxTing* ting = *((mcxTing**) tingpp)
   ;  mcxFree(ting)
;  }
#endif


mcxTing* mcxTingShrink
(  mcxTing*    ting
,  ofs         offset
)
   {  if (offset < 0)
      offset = ting->len + offset      /* fixme conversion? */

   ;  if (offset < 0 || (dim) offset > ting->len)
      {  mcxErr
         (  "mcxTingShrink"
         ,  "funny offset <%lu> newlen <%ld> combo"
         ,  (ulong) ting->len
         ,  (long) offset
         )
      ;  return ting
   ;  }
      else
      {  *(ting->str+offset) = '\0'
      ;  ting->len = offset;
   ;  }
      return ting
;  }


mcxTing* mcxTingEnsure
(  mcxTing*    ting
,  dim         len
)  
   {  if (!ting && !(ting = (mcxTing*) mcxTingInit(NULL)))
      return NULL
   
   ;  if (len <= ting->mxl)
   ;  else
      {  char* t = mcxRealloc(ting->str, len+1, RETURN_ON_FAIL)
      ;  if (!t)
         return NULL
      ;  ting->str = t
      ;  ting->mxl = len
      ;  if (1)
         *(ting->str+ting->mxl) =  '\0'

        /* there should be no need to do this;
         * and for large allocations this may fail.
        */
   ;  }

      return ting
;  }

#ifndef HAVE_VA_COPY
#define HAVE_VA_COPY 1
#endif

                                    /* todo nul hardening */
static mcxTing*  mcx_ting_print
(  mcxTing*    dst
,  const char* fmt
,  va_list     *args
)
#define PRINT_BUF_SIZE 512
   {  char buf[PRINT_BUF_SIZE], *src
   ;  mcxTing* txtbuf = NULL
   ;  dim m = PRINT_BUF_SIZE
   ;  int npf

         /* Perhaps hook this #definery with configure options that
          * benefit from autoconf machinery.
         */
#if HAVE_VA_COPY
   ;  va_list  args2
   ;  va_copy(args2, *args)
   ;  npf = vsnprintf(buf, PRINT_BUF_SIZE, fmt, args2)
   ;  va_end(args2)
#else
   ;  npf = vsnprintf(buf, PRINT_BUF_SIZE, fmt, *args)
#endif

         /* from reading standards it seems that npf >= PRINT_BUF_SIZE
          * should be sufficient. However, alpha OSF1 provides
          * a counterexample. And from reading standard annotations
          * it seems that vsnprintf is widely ill-implemented
         */

   ;  if (npf < 0 || npf >= PRINT_BUF_SIZE - 1)
      {  
         m  =  (npf >= 0 && npf >= PRINT_BUF_SIZE - 1) ?  ((dim) npf) + 1 : 2 * m

         /* Suppose m is set to npf+1. Then mcxTingEmpty will malloc npf+2
          * bytes and vnsprintf is given m+1=npf+2 as size argument,
          * which is > PRINT_BUF_SIZE.
         */
      ;  while (1)
         {  if (!(txtbuf = mcxTingEmpty(txtbuf, m)))
            {  mcxTingFree(&txtbuf)
            ;  return NULL
         ;  }
#if HAVE_VA_COPY
            va_copy(args2, *args)
         ;  npf = vsnprintf(txtbuf->str, m+1, fmt, args2)
         ;  va_end(args2)
#else
         ;  npf = vsnprintf(txtbuf->str, m+1, fmt, *args)
#endif

            /* Only the npf < 0 case is expected below.
             * The other check is defensive coding. We gave
             * vsnprintf m+1 as size argument, so the check is
             * against one less than that (alpha OSF1 example).
            */
         ;  if (npf < 0 || (dim) npf >= m)
            m *= 2
         ;  else
            break
      ;  }
         src = txtbuf->str
   ;  }
      else
      src = buf

   ;  dst = mcxTingWrite(dst, src)

   ;  mcxTingFree(&txtbuf)
   ;  return dst
;  }


mcxTing*  mcxTingPrintSplice
(  mcxTing*    dst
,  ofs         offset
,  ofs         delete
,  const char* fmt
,  ...
)
   {  va_list  args
   ;  mcxTing *infix = NULL

   ;  va_start(args, fmt)
   ;  infix = mcx_ting_print(NULL, fmt, &args)
   ;  va_end(args)

   ;  if (!infix)
      return NULL

   ;  if (!dst)
      return infix

   ;  if
      (  mcxTingSplice(dst, infix->str, offset, delete, infix->len)
      != STATUS_OK
      )
      {  mcxTingFree(&infix)
      ;  return NULL
   ;  }

      mcxTingFree(&infix)
   ;  return dst
;  }


mcxTing*  mcxTingPrint
(  mcxTing*    dst
,  const char* fmt
,  ...
)
   {  va_list  args

   ;  va_start(args, fmt)
   ;  dst = mcx_ting_print(dst, fmt, &args)
   ;  va_end(args)
   ;  return dst
;  }


mcxTing*  mcxTingPrintAfter
(  mcxTing*    dst
,  const char* fmt
,  ...
)
   {  va_list  args
   ;  mcxTing *affix = NULL

   ;  va_start(args, fmt)
   ;  affix = mcx_ting_print(affix, fmt, &args)
   ;  va_end(args)

   ;  if (!dst)
      return affix

   ;  if (!affix)    /* presumably malloc failure */
      return NULL

   ;  if (!mcxTingAppend(dst, affix->str))
      {  mcxTingFree(&affix)
      ;  return NULL
   ;  }

      mcxTingFree(&affix)
   ;  return dst
;  }


static const char* roman[40] =
{  "" , "i" , "ii", "iii", "iv"  , "v" , "vi", "vii", "viii", "ix"
,  "" , "x" , "xx", "xxx", "xl"  , "l" , "lx", "lxx", "lxxx", "xc"
,  "" , "c" , "cc", "ccc", "cd"  , "d" , "dc", "dcc", "dccc", "cm"
,  "" , "m" , "mm", "mmm", "mmmm", ""  ,  "" ,    "",     "", ""
}  ;


mcxTing*  mcxTingRoman
(  mcxTing*  dst
,  long      a
,  mcxbool   ucase
)
   {  long i, x, c, m
   ;  char* p

   ;  if (a >= 5000 || a <= 0)
      return mcxTingWrite(dst, "-")

   ;  i  =  a % 10
   ;  a /=  10
   ;  x  =  a % 10
   ;  a /=  10
   ;  c  =  a % 10
   ;  a /=  10
   ;  m  =  a

   ;  dst = mcxTingPrint
      (  dst
      ,  "%s%s%s%s"
      ,  roman[30+m]
      ,  roman[20+c]
      ,  roman[10+x]
      ,  roman[ 0+i]
      )
   ;  if (dst && ucase)
      for (p=dst->str;p<dst->str+dst->len;p++)
      *p += 'A' - 'a'

   ;  return dst
;  }


mcxTing*  mcxTingDouble
(  mcxTing* dst
,  double   x
,  int      decimals
)
   {  char num[500]
   ;  char* p
   ;  int len = snprintf(num, 500, "%.*f", decimals, x)

   ;  if (decimals < 0)
      {  mcxErr("mcxTingDouble PBD", "negative decimals arg")
      ;  decimals = 6
   ;  }

      if (len < 0 || len >= 500)
      return mcxTingWrite(dst, "[]")

   ;  p = num+len-1
                              /* GNU libcx bug workaround         */
                              /* it returns 2 for length of 'inf' */ 
   ;  if (decimals && strcmp(num, "inf"))
      {  while (*p == '0')
         p--
      ;  if (*p == '.')
         *++p = '0'
      ;  *++p = '\0'
   ;  }

      return mcxTingWrite(dst, num)
;  }


mcxTing*  mcxTingInteger
(  mcxTing*  dst
,  long     x
)
   {  char num[128]
   ;  int len = snprintf(num, 128, "%ld", x)
   ;  if (len < 0 || len >= 128)
      return mcxTingWrite(dst, "[]")
   ;  return mcxTingWrite(dst, num)
;  }


void* mcxTingInit
(  void *  tingv
)
   {  mcxTing *ting = tingv

   ;  if (!ting)
      {  if (!(ting =  mcxAlloc(sizeof(mcxTing), RETURN_ON_FAIL)))
         return NULL
   ;  }

      if (!(ting->str  =  (char*) mcxAlloc(sizeof(char), RETURN_ON_FAIL)))
      return NULL

   ;  *(ting->str+0) =  '\0'
   ;  ting->len      =  0
   ;  ting->mxl      =  0

   ;  return  ting
;  }


/*
 *    Take string into an existing ting or into a new ting
*/

mcxTing* mcxTingInstantiate
(  mcxTing*          ting
,  const char*       string
)
                                    /* strnotice strlen */
   {  dim length = string ? strlen(string) : 0

                     /* ensure handles ting==NULL and/or length==0  cases */

   ;  if (!(ting = mcxTingEnsure(ting, length)))
      return NULL
                                    /* strnotice strncpy */
	;  if (string)
      {  strncpy(ting->str, string, length)
      ;  *(ting->str+length)  =  '\0'
   ;  }

      ting->len = length
	;  return ting
;  }


int mcxTingRevCmp
(  const void* t1
,  const void* t2
)
   {  return (strcmp(((mcxTing*)t2)->str, ((mcxTing*)t1)->str))
;  }


int mcxTingCmp
(  const void* t1
,  const void* t2
)
   {  return (strcmp(((mcxTing*)t1)->str, ((mcxTing*)t2)->str))
;  }


int mcxTingPCmp
(  const void* t1
,  const void* t2
)
   {  return (strcmp(((mcxTing**)t1)[0]->str, ((mcxTing**)t2)[0]->str))
;  }


int mcxTingPRevCmp
(  const void* t1
,  const void* t2
)
   {  return (strcmp(((mcxTing**)t2)[0]->str, ((mcxTing**)t1)[0]->str))
;  }


int mcxPKeyTingCmp
(  const void* k1
,  const void* k2
)
   {  return
      strcmp
      (  ((mcxTing*) ((mcxKV**)k1)[0]->key)->str
      ,  ((mcxTing*) ((mcxKV**)k2)[0]->key)->str
      )
;  }


int mcxPKeyTingRevCmp
(  const void* k1
,  const void* k2
)
   {  return
      strcmp
      (  ((mcxTing*) ((mcxKV**)k2)[0]->key)->str
      ,  ((mcxTing*) ((mcxKV**)k1)[0]->key)->str
      )
;  }


mcxstatus mcxTingSplice
(  mcxTing*       ting
,  const char*    pstr
,  ofs            offset
,  ofs            n_delete
,  dim            n_copy
)
   {  dim newlen

   ;  if (!ting)
      {  mcxErr("mcxTingSplice PBD", "void ting argument")
      ;  return STATUS_FAIL
   ;  }

              /* offset -1 denotes appending at the end,
               * offset -2 denotes inserting at the last-but-one position.
               * etc
              */
      if (offset < 0)
      {  if ((dim) -offset > ting->len + 1)
         offset = 0
      ;  else
         offset = ting->len + offset + 1
   ;  }
      else if ((dim) offset > ting->len)
      offset = ting->len

   ;  if (n_delete == TING_INS_CENTER)
      {  n_delete = MCX_MIN(ting->len, n_copy)
      ;  offset = (ting->len - n_delete) / 2    /* n_delete <= ting->len */
   ;  }

      else if (n_delete == TING_INS_OVERWRITE)
      n_delete = MCX_MIN(ting->len - offset, n_copy)  /* offset <= ting->len */

   ;  else if (n_delete == TING_INS_OVERRUN || n_delete < 0)
      n_delete = ting->len - offset               /* offset <= ting->len */

   ;  else if (n_delete < 0)
      {  mcxErr
         (  "mcxTingSplice PBD"
         ,  "unsupported delete mode %ld"
         ,  (long) n_delete
         )
      ;  return STATUS_FAIL
   ;  }

      else if ((dim) (offset + n_delete) > ting->len)
      n_delete = ting->len - offset

   ;  if (ting->len + n_copy < (dim) n_delete)  /* now spurious? */
      {  mcxErr("mcxTingSplice PBD", "arguments result in negative length")
      ;  return STATUS_FAIL
   ;  }
           /*
            *  essential: mcxSplice does not know to allocate room for '\0'
           */
      newlen = ting->len - n_delete + n_copy
   ;  if (!mcxTingEnsure(ting, newlen))
      return STATUS_FAIL

   ;  if
      (  mcxSplice
         (  &(ting->str)
         ,  pstr
         ,  sizeof(char)
         ,  &(ting->len)
         ,  &(ting->mxl)
         ,  offset
         ,  (dim) n_delete
         ,  n_copy
         )
      != STATUS_OK
      )
      return STATUS_FAIL

  /*
   *  essential: mcxSplice might have realloced, so has to be done afterwards.
  */
   ;  *(ting->str+newlen)  =  '\0'

   ;  if (ting->len != newlen)
      {  mcxErr("mcxTingSplice panic", "mcxSplice gives unexpected result")
      ;  return STATUS_FAIL
   ;  }
      return STATUS_OK
;  }


mcxTing* mcxTingNew
(  const char* str
)
   {  return mcxTingInstantiate(NULL, str)
;  }


mcxTing* mcxTingNNew
(  const char* str
,  dim         sz
)
   {  mcxTing* ting = mcxTingEnsure(NULL, sz)

   ;  if (!ting)
      return NULL
                                    /* strnotice memcpy */
   ;  if (str && sz)
      memcpy(ting->str, str, sz)
   ;  *(ting->str+sz) = '\0'
   ;  ting->len = sz
   ;  return ting
;  }


mcxTing* mcxTingEmpty
(  mcxTing*    ting
,  dim         len
)
   {  if (!(ting = mcxTingEnsure(ting, len)))
      return NULL

   ;  *(ting->str+0)     =  '\0'
   ,  ting->len          =  0
   ;  return ting
;  }


mcxTing* mcxTingWrite
(  mcxTing*          ting
,  const char*       str
)
   {  return mcxTingInstantiate(ting, str)
;  }


mcxTing* mcxTingNWrite
(  mcxTing*          ting
,  const char*       str
,  dim               sz
)
   {  if (!(ting = mcxTingEnsure(ting, sz)))
      return NULL
                                    /* strnotice strncpy */
   ;  memcpy(ting->str, str, sz)

   ;  *(ting->str+sz) = '\0'
   ;  ting->len = sz

   ;  return ting
;  }


char* mcxTingSubStr
(  const mcxTing*    ting
,  ofs               offset  
,  ofs               length
)
   {  char* str

   ;  if (offset < 0 || (dim) offset > ting->len)
      offset = ting->len

   ;  if (length < 0 || (dim) (offset+length) > ting->len)
      length = ting->len - offset
      
   ;  if (!(str = mcxAlloc((dim) (length+1), RETURN_ON_FAIL)))
      return NULL

   ;  if (length)
      memcpy(str, ting->str+offset, (dim) length)

   ;  *(str+length) = '\0'
   ;  return str
;  }


mcxTing* mcxTingify
(  char* str
)
   {  mcxTing* ting = mcxAlloc(sizeof(mcxTing), RETURN_ON_FAIL)
   ;  ting->str = str
                                    /* strnotice strlen; ? tingify2 */
   ;  ting->len = strlen(str)
   ;  return ting
;  }


char* mcxTinguish
(  mcxTing*    ting
)
   {  char* str = ting->str
   ;  mcxFree(ting)
   ;  return str
;  }


char* mcxTingStr
(  const mcxTing*       ting
)
   {  ofs slen = ting->len
   ;  return mcxTingSubStr(ting, 0, slen)
;  }



mcxTing* mcxTingAppend
(  mcxTing*             ting
,  const char*          str
)
   {  if (!ting)
      return mcxTingNew(str)
                                          /* strnotice strlen */
   ;  if
      (  mcxTingSplice
         (  ting
         ,  str
         , -1                             /*    splice offset     */
         ,  0                             /*    delete nothing    */
         ,  str? strlen(str) : 0          /*    string length     */
         )
      != STATUS_OK
      )
      return NULL

   ;  return ting
;  }


mcxTing* mcxTingKAppend
(  mcxTing*    ting
,  const char* str
,  dim         sz
)
   {  dim len = strlen(str)

   ;  if (!ting && !sz)
      return mcxTingEmpty(NULL, 0)

   ;  if (!sz)
      return ting

   ;  while (sz-- > 0)                    /* careful with unsignedness */
      if (!(ting = mcxTingNAppend(ting, str, len)))
      return NULL

   ;  return ting
;  }


mcxTing* mcxTingNAppend
(  mcxTing*      ting
,  const char*   str
,  dim           sz
)
   {  if (!ting)
      return mcxTingNWrite(NULL, str, sz)

   ;  if
      (  mcxTingSplice
         (  ting
         ,  str
         , -1                             /*    splice offset     */
         ,  0                             /*    delete nothing    */
         ,  sz
         )
      != STATUS_OK
      )
      return NULL

   ;  return ting
;  }


mcxTing* mcxTingInsert
(  mcxTing*             ting
,  const char*          str
,  ofs                  offset
)
   {  if (!ting)
      return mcxTingNew(str)

                                          /* strnotice strlen */
   ;  if
      (  mcxTingSplice
         (  ting
         ,  str
         ,  offset                        /*    splice offset     */
         ,  0                             /*    delete nothing    */
         ,  str ? strlen(str) : 0         /*    string length     */
         )
      != STATUS_OK
      )
      return NULL

   ;  return ting
;  }


mcxTing* mcxTingNInsert
(  mcxTing*          ting
,  const char*       str
,  ofs               offset
,  dim               length
)
   {  if (!ting)
      return mcxTingNWrite(NULL, str, length)

   ;  if
      (  mcxTingSplice
         (  ting
         ,  str
         ,  offset                        /*    splice offset     */
         ,  0                             /*    delete nothing    */
         ,  length                        /*    length of str     */
         )
      != STATUS_OK
      )
      return NULL

   ;  return ting
;  }


mcxTing* mcxTingDelete
(  mcxTing*          ting
,  ofs               offset
,  dim               width
)
   {  ofs swidth =   width
   ;  if (!ting)
      return NULL

   ;  if
      (  mcxTingSplice
         (  ting
         ,  NULL
         ,  offset                        /*    splice offset     */
         ,  swidth                        /*    delete width      */
         ,  0                             /*    string length     */
         )
      != STATUS_OK
      )
      return NULL

   ;  return ting
;  }


u32 mcxTingDJBhash
(  const void* ting
)
   {  return(mcxBJhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingBDBhash
(  const void* ting
)
   {  return(mcxBDBhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingBJhash
(  const void* ting
)
   {  return(mcxBJhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingCThash
(  const void* ting
)
   {  return(mcxCThash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingDPhash
(  const void* ting
)
   {  return(mcxDPhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingGEhash
(  const void* ting
)
   {  return(mcxGEhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingOAThash
(  const void* ting
)
   {  return(mcxOAThash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingELFhash
(  const void* ting
)
   {  return(mcxELFhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingFNVhash
(  const void* ting
)
   {  return(mcxFNVhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 (*mcxTingHFieByName(const char* id))(const void* ting)
   {  if (!strcmp(id, "dp"))
      return mcxTingDPhash
   ;  else if (!strcmp(id, "bj"))
      return mcxTingBJhash
   ;  else if (!strcmp(id, "elf"))
      return mcxTingELFhash
   ;  else if (!strcmp(id, "djb"))
      return mcxTingDJBhash
   ;  else if (!strcmp(id, "bdb"))
      return mcxTingBDBhash
   ;  else if (!strcmp(id, "ge"))
      return mcxTingGEhash
   ;  else if (!strcmp(id, "oat"))
      return mcxTingOAThash
   ;  else if (!strcmp(id, "svd"))
      return mcxTingSvDhash
   ;  else if (!strcmp(id, "svd2"))
      return mcxTingSvD2hash
   ;  else if (!strcmp(id, "svd1"))
      return mcxTingSvD1hash
   ;  else if (!strcmp(id, "ct"))
      return mcxTingCThash
   ;  else if (!strcmp(id, "fnv"))
      return mcxTingFNVhash
   ;  else
      return NULL
;  }


u32 mcxTingSvDhash
(  const void* ting
)
   {  return(mcxSvDhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingSvD2hash
(  const void* ting
)
   {  return(mcxSvD2hash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingSvD1hash
(  const void* ting
)
   {  return(mcxSvD1hash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }


u32 mcxTingHash
(  const void* ting
)
   {  return(mcxDPhash(((mcxTing*) ting)->str, ((mcxTing*) ting)->len))
;  }



/* Fails only for memory reason */

mcxstatus mcxTingTackc
(  mcxTing*  ting
,  unsigned char c
)
   {  if (!ting || !mcxTingEnsure(ting, ting->len+1))
      return STATUS_FAIL
   ;  ting->str[ting->len] = c
   ;  ting->str[ting->len+1] = '\0'
   ;  ting->len += 1
   ;  return STATUS_OK
;  }


/* Fails if last char is not the same as c */

mcxstatus mcxTingTickc
(  mcxTing*  ting
,  unsigned char c
)
   {  if (!ting || !ting->len)
      return STATUS_FAIL
   ;  if ((unsigned char) ting->str[ting->len-1] == c)
      {  mcxTingShrink(ting, -1)
      ;  return STATUS_OK
   ;  }
      return STATUS_FAIL
;  }