-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyansi.c
2979 lines (2447 loc) · 51 KB
/
Myansi.c
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
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stddef.h> // for size_t
#include <assert.h>
#include <stdarg.h>
#include "myansi.h"
#include <sys/stat.h>
#include <windows.h>
#include <winuser.h> /* includes the common control header */
#include <time.h>
// use this from config.cpp
extern long OutDebugs( const char *txt, ... );
static char tempReturnStr[32];
static int DaysToYear[] = { // From 1970
0, 365, 730, 1096, 1461, 1826, 2191, 2557, 2922, 3287,
3652, 4018, 4383, 4748, 5113, 5479, 5844, 6209, 6574, 6940,
7305, 7670, 8035, 8401, 8766, 9131, 9496, 9862, 10227, 10592,
10957, 11323, 11688, 12053, 12418, 12784, 13149, 13514, 13879, 14245,
14610, 14975, 15340, 15706, 16071, 16436, 16801, 17167, 17532, 17897,
18262, 18628, 18993, 19358, 19723, 20089, 20454, 20819, 21184, 21550,
21915, 22280, 22645, 23011, 23376, 23741, 0
};
size_t DaysToYearSince1970(size_t nYear)
{
QS_ASSERT(nYear>=1970);
QS_ASSERT(nYear<=2035);
return DaysToYear[nYear-1970];
}
size_t DaystoPreviousSunday(size_t nWeekNum, size_t nYear)
{
size_t nDays = 0;
size_t nDayOffset;
nDays += DaysToYearSince1970(nYear); // # days from 1970 to nYear.
nDays += (nWeekNum * 7);
nDayOffset = (nDays % 7);
if (nDayOffset > 3) // the 1st sunday in 1970 is '3' days into the year!
{
nDays -= nDayOffset; // This may take us into the previous year!
nDays += 3;
}
else
{
nDays -= nDayOffset; // This may take us into the previous year!
nDays -= 4;
}
return nDays;
}
// 0 = Success, -1 = Failure.
int
GetStartOfWeek(struct tm* ptmDest, size_t nWeekNum, size_t nYear)
{
struct tm* ptm = NULL;
time_t tTimeSunday = 0;
size_t nDays = 0;
nDays = DaystoPreviousSunday(nWeekNum, nYear);
tTimeSunday += (ONEDAY * nDays);
ptm = localtime(&tTimeSunday); // and create the struct tm.
*ptmDest = *ptm;
return 0;
}
//
//
// DO not EVER delete this function it is really needed
//
//
long SwapEndian( long x )
{
long a;
a = (x >> 16)&0xff;
a |= x&0xff00;
a |= (x&0xff) << 16;
return a;
}
long ReadLong( unsigned char *data )
{
long x;
x = data[0];
x = x<<8 | data[1];
x = x<<8 | data[2];
x = x<<8 | data[3];
return x;
}
#ifndef QS_MAC
void SysBeep( int _type )
{
#if QS_WINDOWS
MessageBeep( _type );
#elif QS_UNIX
printf( "\07" );
#endif
}
#endif
long NotifyMsg( const char *fmt, ... )
{
char txt[4000];
if ( fmt ){
va_list args;
va_start( args, fmt );
vsprintf( txt, fmt, args );
va_end( args );
}
#if QS_WINDOWS
return WinNotifyMsg( txt );
#elif QS_UNIX
return UnixNotifyMsg( txt );
#elif QS_MAC
NotifyUser (txt, 0);
return (0);
#endif
}
long CautionMsg( const char *fmt, ... )
{
char txt[4000];
if ( fmt ){
va_list args;
va_start( args, fmt );
vsprintf( txt, fmt, args );
va_end( args );
}
#if QS_WINDOWS
return WinCautionMsg( txt );
#elif QS_UNIX
return UnixCautionMsg( txt );
#elif QS_MAC
//return MacCautionMsg( txt );
NotifyUser (txt, 0); // have to use NotifyUser for now, as CautionUser takes a constant, not a string
return (0);
#endif
}
long ErrorMsg( const char *fmt, ... )
{
char txt[4000];
if ( fmt ){
va_list args;
va_start( args, fmt );
vsprintf( txt, fmt, args );
va_end( args );
}
#if QS_WINDOWS
return WinErrorMsg( txt );
#elif QS_UNIX
return UnixErrorMsg( txt );
#elif QS_MAC
//return MacErrorMsg( txt );
//NotifyUser (txt, 0); // have to use NotifyUser for now, as CautionUser takes a constant, not a string
HandleProcessError (txt);
return (0);
#endif
}
void UprString( char *txt, int flag )
{
long len;
if ( txt ) {
len = strlen( (const char *)txt );
while( *txt && len>0 ){
if ( *txt >= 'a' && *txt <= 'z' )
*txt -= ('a'-'A');
txt++; len--;
}
}
}
void SleepTicks( long length )
{
#if QS_WINDOWS
Sleep( length * 17 );
#endif
#if QS_UNIX // UNIX sleep method
usleep( length * 17 );
#endif
#if QS_MAC
MacSleep( length);
#endif
}
void SleepSecs( long length )
{
#if QS_WINDOWS
Sleep( length * 1000 );
#endif
#if QS_UNIX // UNIX sleep method
sleep( length );
#endif
#if QS_MAC
MacSleep( length * 60 );
#endif
}
#if QS_WINDOWS
#include <intshcut.h>
int RunSelf( const char *param )
{
char dir[320] = "c:\\";
char *appexe = __argv[0];
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
long ret;
dir[0] = appexe[0];
//CreateProcessAsUser
sprintf( dir, "\"%s\" %s", appexe, param );
//return system( dir );
// ShellExecute( NULL, oper, doc, param, dir, SW_SHOW );
memset( &siStartInfo, 0, sizeof(STARTUPINFO ) );
siStartInfo.cb = sizeof(STARTUPINFO);
ret = CreateProcess( appexe, dir,
NULL, NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL, NULL,
&siStartInfo,
&piProcInfo );
while( WaitForInputIdle(piProcInfo.hProcess,1000) != -1 )
Sleep(1);
return ret;
}
#else
int RunSelf( const char *param )
{
char newparam[320];
sprintf( newparam, "fweb %s", param );
return system( newparam );
}
#endif
__int64 GetDiskFreeSpace95( const char *drive )
{
#if QS_WINDOWS
DWORD sec,byte,freeb,total;
GetDiskFreeSpace( drive, &sec,&byte, &freeb, &total );
return (__int64)(sec*byte*freeb);
#endif
return 0;
}
__int64 GetDiskFree( const char *path )
{
__int64 free = -1,tot,freedisk;
double freespace = -1;
char dir[256];
#if QS_WINDOWS
if ( path[0] == '\\' )
PathFromFullPath( (char*)path, dir ); // safe cast as dir is non-null.
else {
dir[0] = path[0];
dir[1] = ':';
dir[2] = 0;
}
GetDiskFreeSpaceEx( dir, (PULARGE_INTEGER)&free, (PULARGE_INTEGER)&tot, (PULARGE_INTEGER)&freedisk );
if ( free < 0 )
free = GetDiskFreeSpace95( dir );
#endif
return free;
}
// search stringpointer 'string' for word 'key' and replace it with 'newkey' and put the result
// in 'newstring'
//
// if FLAG is true then test if the 'key' is a word on its own or not else just blindly
// search/replace the key
//
// If the destination is NULL, then we just replace the source, assuming the source is big
// enough to handle the result.... we hope... (that is the requirement)
//
long ReplaceStr( char *srcstring, char *newstring, const char *key, const char *newkey, short wordflag )
{
char *oldkey, *p, *string, *ram, prevC=0, nextC=0, doit=TRUE;
long oldlen, len, ret=0, rep=0;
oldlen = strlen( key );
if ( !newstring )
p = ram = (char *)malloc( 10000 );
else
p = newstring;
string = srcstring;
if ( !p ) return 0;
while ( oldkey = strstr( (char*)string, key ) ){
len = oldkey - string;
if ( wordflag ){
if ( len ) prevC = *(oldkey-1);
nextC = oldkey[oldlen];
if ( prevC== '\"' || (isalpha( prevC ) || isalpha( nextC )) || nextC=='/' || nextC=='.' )
doit = FALSE;
else doit = TRUE;
}
if ( doit ){
mystrncpy( p, string, (short)len );
p += len;
p += mystrcpy( p, newkey );
string = oldkey + oldlen;
ret++; rep++;
} else {
mystrncpy( p, string, (short)len );
p += len;
p += mystrncpy( p, oldkey, (short)oldlen );
string = oldkey + oldlen;
rep++;
}
}
if ( ret )
p += mystrcpy( p, string );
*p = 0;
if ( !newstring )
{
if ( ret )
mystrcpy( srcstring, ram );
free( ram );
}
return ret;
}
// added in rev 8
char *CopyLine( char *d, char *s )
{
char* s_orig=s;
assert( d );
assert( s );
while( *s && *s!='\r' && *s!='\n' )
{
*d++ = *s++;
}
*d='\0';
while( *s=='\r' || *s=='\n' )
{
++s;
}
if( *s )
{
return s;
}
// mimic somewhat strange behavior of previous version of this function
if( s!=s_orig && *(s-1)=='\n' )
{
*(s-1)='\0';
}
return 0;
}
short countchar(char *buffer,char ch)
{
long n;
short c=0;
n=mystrlen(buffer);
while (n--) {
if ( *buffer == ch) {
c++;
}
*buffer++;
}
return c;
}
// get substring enclosed in inverted commas ""
void getsub( char *src, char *dst )
{
int s=0;
char c;
if ( src && dst){
while( c=*src ) {
if (c=='"') {
if (s==0) {
s=1;
src++;
} else {
s=0;
*dst=0; //last " found so terminate and return
return;
}
}
if (s==1)
*dst++=*src;
src++;
}
}
}
void strip(char *src, char *dst)
{
int i=0;
char c;
if ( src && dst){
while ( c=*src ) {
if (i>3) *dst++=c;
i++;
src++;
}
*dst=0; //terminate string
}
}
/************************************************************************************/
short pstrlen( unsigned char * str ) // p-string length function
{
return( str[0] );
}
/************************************************************************************/
void pstrcpy( unsigned char * dst, unsigned char * src ) // p-string copy function
{
short i = *src;
do { dst[i] = src[i]; } while (i--);
}
void strcpyc2p(unsigned char *dst, char *src)
{
short len=0;
unsigned char *p=dst;
if ( src && dst ) {
p++;
while(( *p++ = *src++ ) != 0) { len++; };
}
dst[0]=(unsigned char)len;
}
void strcatc2p( unsigned char * dst, char *src)
{
short len=0;
unsigned char *p=dst+dst[0];
if ( src && dst ) {
p++;
while(( *p++ = *src++ ) != 0) { len++; };
}
dst[0]=(unsigned char)len+dst[0];
}
void strcpyp2c(char *dst, unsigned char * src)
{
short i=1,len=src[0];
while (i<=len) {
dst[i-1] = src[i];
i++;
}
dst[i-1]=0;
}
void swaplong( long *l1, long *l2 )
{
long x;
if ( l1 && l2 ){
x = *l1;
*l1 = *l2;
*l2 = x;
}
}
long GetTimeFromFilename( char *filename )
{
char *p = filename,c, numbers[32], num=0;
long jd=0;
while( c=*p ){
if ( isdigit( c ) ){
numbers[num++] = c;
}
if ( num>=6 ){
long dd,mm,yy;
char txt[32];
mystrncpy( txt, &numbers[0], 2 ); txt[2]=0; dd = myatoi( txt );
mystrncpy( txt, &numbers[2], 2 ); txt[2]=0; mm = myatoi( txt );
mystrncpy( txt, &numbers[4], 2 ); txt[2]=0; yy = myatoi( txt );
if ( dd>31 && yy<=31 ) swaplong( &dd, &yy );
if ( dd<=31 && mm>12 && yy<=12 ) swaplong( &mm, &yy );
//year 2000 compliant
if (yy<70)
yy+=2000;
else if (yy<1000)
yy+=1900;
sprintf( txt, "%02d/%02d/%04d", dd,mm,yy );
jd = DateStringToCTime( txt );
}
p++;
}
return jd;
}
//basicly convert this Long to a String
char *Long2Str( long val, long totdigit )
{
long num, digits=0, val2;
unsigned char temp[17], digit;
val2 = val;
if ( val < 0 )
val = -val;
//convert long into backword text
for ( num=0; num<15; )
{
digits++;
digit = (unsigned char)(val%10);
temp[num++] = digit+0x30;
val = val / 10;
if ( val == 0 )
break;
}
// fill in preceding 0's
if ( digits < totdigit ){
for( ;digits<totdigit;){
digits++;
temp[num++] = '0';
}
}
if ( val2 < 0 ) {
digits++;
temp[num++] = '-';
}
//copy backword text digits to output text...
for ( num=0; num<digits; num++){
tempReturnStr[num] = temp[ digits-(num+1) ];
}
tempReturnStr[num] = 0;
return tempReturnStr;
}
//basicly convert this 64Long to a String
char *LLong2Str( __int64 *valPtr, long totdigit )
{
__int64 val,val2;
long num, digits=0;
short digit;
char temp[32];
val = *valPtr;
val2 = val;
if ( val < 0 ) val = -val;
//convert long into backword text
for ( num=0; num<20; ) {
digits++;
digit = (short)(val %10);
temp[num++] = digit+'0';
val = val / 10;
if ( val == 0 )
break;
}
// fill in preceding 0's
if ( digits < totdigit ){
for( ;digits<totdigit;){
digits++;
temp[num++] = '0';
}
}
if ( val2 < 0 ) {
digits++;
temp[num++] = '-';
}
//copy backword text digits to output text...
for ( num=0; num<digits; num++){
tempReturnStr[num] = temp[ digits-(num+1) ];
}
tempReturnStr[num] = 0;
return tempReturnStr;
}
/* 1,234,567,890,123 */
long FormatNum( char *txt, long x)
{
char newStr[128], *p, *dot;
int intlen, len,count,idx,newlen=0;
len=mystrcpy( newStr, txt );
dot = strrchr( (char*)newStr, '.' );
if ( dot ) intlen = dot-newStr; else intlen = len;
p = txt;
for( count=0; count < len ; count++ )
{
idx = (intlen - count);
if ( count>0 && idx>0 )
{
if ( idx%3 == 0 )
{
*p++ = ',';
newlen++;
}
}
*p++ = newStr[count];
newlen++;
*(p+1)=0;
}
return newlen;
}
long FormatLongNum( long n, char *txt )
{
strcpy(txt,Long2Str( n, 0 ));
return FormatNum(txt, 0);
}
long FormatLong64Num( __int64 n, char *txt )
{
strcpy( txt,LLong2Str( &n, 0 ));
return FormatNum(txt, 0);
}
long FormatDoubleNum( double n, char *txt )
{
Double2CStr( n, txt,1);
return FormatNum(txt, 0);
}
long ULong2CStr( unsigned long x, char *dest )
{
if ( dest )
return mystrcpy(dest,Long2Str( x, 0 ));
return 0;
}
long Double2CStr( double x, char *dest, short type )
{
if ( dest )
{
if( type )
return sprintf( dest, "%.2f", x );
else
return sprintf( dest, "%.0f", x );
}
return 0;
}
// ********************************************************
// Compare 2 date strings.
// ********************************************************
int mydatecmp(const char* szDate1, const char* szDate2)
{
int i;
int iDate1[3], iDate2[3];
if (1) // Month/Day/Year !
{
if (sscanf(szDate1, "%d/%d/%d", &iDate1[1], &iDate1[0], &iDate1[2]) != 3)
return 0;
if (sscanf(szDate2, "%d/%d/%d", &iDate2[1], &iDate2[0], &iDate2[2]) != 3)
return 0;
}
else // Day/Month/Year
{
if (sscanf(szDate1, "%d/%d/%d", &iDate1[0], &iDate1[1], &iDate1[2]) != 3)
return 0;
if (sscanf(szDate2, "%d/%d/%d", &iDate2[0], &iDate2[1], &iDate2[2]) != 3)
return 0;
}
for (i=2;i>0;--i)
{
if (iDate1[i] > iDate2[i])
return 1;
if (iDate1[i] < iDate2[i])
return -1;
}
return 0;
}
/************************************************************************************/
void pstrcat( unsigned char * dst, unsigned char * src ) // concatenate src with dst p-string
{
short i;
for (i = 0; i < src[0]; )
dst[ ++dst[0] ] = src[++i];
}
/************************************************************************************/
size_t mystrlen( const char *str ) // c-string length function
{
size_t i = 0;
if ( str ){
while( *str++ )
i++;
}
return( i );
}
/************************************************************************************/
long mystrcpy( char *dst, const char *src ) // c-string copy function
{
long len=0;
if ( src && dst )
while(( *dst++ = *src++ ) != 0){ len++; };
return len;
}
void strcpybreak( char *dst, char *src, char brk, int len) // c-string copy function
{
char c;
short cnt=0;
if ( dst && src ) {
while((c=*src) && cnt++<len) {
if ( c == brk ) break;
*dst++ = c;
src++;
}
*dst++ = 0;
}
}
long mystrcpylower( char *dst, const char *src ) // c-string copy function
{
long len=0;
if( dst && src )
{
while( *dst = *src++ )
{
*dst=mytolower(*dst);
++dst;
++len;
};
}
return len;
}
//case insensitive
char * strstrn(const char * str, const char * pat, int n)
{
unsigned char * s1 = (unsigned char *) str;
unsigned char * p1 = (unsigned char *) pat;
unsigned char firstc, c1, c2;
if (!(firstc = tolower(*p1))) /* if pat is an empty string we return str */
return((char *) str);
p1++;
while(c1 = tolower(*s1)) {
s1++;
if (c1 == firstc)
{
const unsigned char * s2 = s1;
const unsigned char * p2 = p1;
short cnt=0;
while ((c1 = tolower(*s2)) == (c2 = tolower(*p2)) && c1 && cnt++<n) {
s2++;
p2++;
}
if (!c2 || cnt==n-1)
return((char *) s1 - 1);
}
}
return(NULL);
}
char *strstri(const char * str, const char * pat )
{
unsigned char * s1 = (unsigned char *) str;
unsigned char * p1 = (unsigned char *) pat;
unsigned char firstc, c1, c2;
if ( str && pat ){
if ( !(firstc = tolower(*p1)) ) /* if pat is an empty string we return str */
return((char *) str);
p1++;
while(c1 = tolower(*s1) ){
s1++;
if (c1 == firstc)
{
const unsigned char * s2 = s1;
const unsigned char * p2 = p1;
short cnt=0;
while ( (c1 = tolower(*s2) ) == (c2 = tolower(*p2) ) && c1 ){
s2++;
p2++;
}
if (!c2)
return((char *) s1 - 1);
}
}
}
return(NULL);
}
char *mystrstr(const char * str, const char * pat )
{
unsigned char * s1 = (unsigned char *) str;
unsigned char * p1 = (unsigned char *) pat;
unsigned char firstc, c1, c2;
if ( str && pat ){
if ( !(firstc = *p1) ) /* if pat is an empty string we return str */
return((char *) str);
p1++;
while(c1 = *s1 ){
s1++;
if (c1 == firstc)
{
const unsigned char * s2 = s1;
const unsigned char * p2 = p1;
short cnt=0;
while ( (c1 = *s2 ) == (c2 = *p2 ) && c1 ){
s2++;
p2++;
}
if (!c2)
return((char *) s1 - 1);
}
}
}
return(NULL);
}
long mystrncpyNull( char *dst, const char *src, int max ) // c-string copy function
{
long numCopied=mystrncpy( dst, src, max );
dst[numCopied]=0;
return numCopied;
}
long mystrncpy( char *dst, const char *src, int max ) // c-string copy function
{
long numCopied=0;
QS_PRECONDITION(dst);
QS_PRECONDITION(src);
QS_PRECONDITION(max>=0); // crappy signed integers
if( dst && src ) // damn, still have to perform this check for old code compatability in release mode
{
while( numCopied<max && (*dst++=*src++) )
{
numCopied++;
}
}
return numCopied;
}
// copy string of N limit and turn to lower case.
long mystrncpylower( char *dst, const char *src, int max )
{
long numCopied=0;
QS_PRECONDITION(dst);
QS_PRECONDITION(src);
QS_PRECONDITION(max>=0); // crappy signed integers
if( dst && src ) // damn, still have to perform this check for old code compatability in release mode
{
while( numCopied<max && (*dst++=tolower(*src) ) )
{
src++;
numCopied++;
}
}
*dst = 0;
return numCopied;
}
/************************************************************************************/
void mystrcat( char *dst, const char *src ) // concatenate src with dst c-string
{
if ( src && dst ){
while( *dst )
dst++;
while(( *dst++ = *src++ ) != 0){};
}
}
long mystrncatNull( char *dst, const char *src, int dstSize ) // concatenate src with dst c-string, but knowing dst size
{
char *p = dst;
long len = 0;
if ( src && dst )
{
while( *dst )
{
len++;
dst++;
}
while( *src != 0 )