49 sprintf(TitleLine,
"%s%s [%s]",
NAME, Title, TX_Release(RELEASE));
50 fprintf(
Of,
"\n%s \t%s", TitleLine, ctime(&clock));
53 while ( Underline-- ) putc(
'-',
Of);
75 if ( OptNo >= Argc )
return '\00';
77 if ( *(
Option = Argv[OptNo++]) !=
'-' )
return '?';
79 for ( i = 0 ; Options[i] ; i++ )
81 if ( Options[i] ==
Option[1] )
83 OptArg = (
char *) ( Options[i+1] !=
'+' ?
Nil :
85 OptNo < Argc ? Argv[OptNo++] :
"0" );
108 if ( ! Bytes || (p = (
void *) malloc(Bytes)) )
124 if ( ! Bytes )
return Nil;
126 if ( ! Present )
return Pmalloc(Bytes);
128 if ( (p = (
void *) realloc(Present, Bytes)) )
139 void *
Pcalloc(
size_t Number,
unsigned int Size)
144 if ( ! Number || (p = (
void *) calloc(Number, Size)) )
160 while ( First <= Last )
205 DataMem->
Prev = Prev;
220 Prev = DataMem->
Prev;
244 #define Modify(F,S) if ( (F -= S) < 0 ) F += 1.0
251 static double URD[55];
267 URD[ j = (i * 21) % 55 ] = V1;
269 if ( V1 < 0 ) V1 += 1.0;
277 Modify(URD[i], URD[(i+30) % 55]);
315 Boolean Quit=
false, WarningOnly=
false;
316 char Buffer[10000], *Msg=Buffer;
319 if (
Of ) fprintf(
Of,
"\n");
323 sprintf(Msg,
"*** ");
329 Msg += strlen(Buffer);
469 sprintf(Msg,
" (%s `%s')\n", S1, S2);
476 if ( ! WarningOnly )
ErrMsgs++;
531 strcat(
Fn, Extension);
532 return fopen(
Fn, RW);
544 #include <sys/time.h>
550 struct timezone TZ={0,0};
552 gettimeofday(&TV, &TZ);
553 return TV.tv_sec + TV.tv_usec / 1000000.0;
568 double RoundErr, Accuracy;
571 Accuracy = fabs(Val) * 1E-6;
572 Val = modf(Val, &RoundErr);
574 for ( Mult = 100000 ; Mult >= 1 ; Mult /= 10 )
576 RoundErr = fabs(rint(Val * Mult) / Mult - Val);
577 if ( RoundErr > 2 * Accuracy )
602 if ( ! isdigit(*S) )
return 0;
604 Result = Result * 10 + (*S++ -
'0');
614 int Year, Month, Day;
616 if ( strlen(DS) != 10 )
return 0;
622 if ( ! ( DS[4] ==
'/' && DS[7] ==
'/' || DS[4] ==
'-' && DS[7] ==
'-' ) ||
623 Year < 0 || Month < 1 || Day < 1 ||
627 ( Month == 4 || Month == 6 || Month == 9 || Month == 11 ) ||
630 Day > 28 && ( Year % 4 != 0 ||
631 Year % 100 == 0 && Year % 400 != 0 ) ) )
636 if ( (Month -= 2) <= 0 )
642 return Year * 365 + Year / 4 - Year / 100 + Year / 400
652 int Year, Month, OrigDay=Day;
660 Year = (Day - 1) / 365.2425L;
661 Day -= Year * 365 + Year / 4 - Year / 100 + Year / 400;
666 Day = OrigDay - (Year * 365 + Year / 4 - Year / 100 + Year / 400);
671 ( (Year+1) % 4 != 0 || (Year+1) % 100 == 0 && (Year+1) % 400 != 0 ) )
674 Day = OrigDay - (Year * 365 + Year / 4 - Year / 100 + Year / 400);
677 Month = (Day + 30) * 12 / 367;
678 Day -= 367 * Month / 12 - 30;
692 sprintf(Date,
"%d/%d%d/%d%d", Year, Month/10, Month % 10, Day/10, Day % 10);
707 int Hour, Mins, Secs;
709 if ( strlen(TS) != 8 )
return -1;
715 if ( TS[2] !=
':' || TS[5] !=
':' ||
716 Hour >= 24 || Mins >= 60 || Secs >= 60 )
721 return Hour * 3600 + Mins * 60 + Secs;
732 Mins = (Secs % 3600) / 60;
735 sprintf(Time,
"%d%d:%d%d:%d%d",
736 Hour / 10, Hour % 10,
737 Mins / 10, Mins % 10,
738 Secs / 10, Secs % 10);
747 TSBase = y * 365 + y / 4 - y / 100 + y / 400 + (367 * 4) / 12 + 1 - 30;
759 if ( strlen(TS) < 19 || !
Space(TS[10]) )
return (1 << 30);
769 for ( i = 11 ; TS[i] &&
Space(TS[i]) ; i++ )
778 return ( Day < 1 || Sec < 0 ? (1 << 30) :
779 (Day -
TSBase) * 1440 + (Sec + 30) / 60 );
801 Mins = rint(CV) - floor(CV / 1440) * 1440;
816 sprintf(DS,
"%.*g",
PREC, CV);
832 if ( Val < Low || Val > High )
834 fprintf(
Of, TX_IllegalValue(Val, Low, High));
866 CheckClose(Uf); Uf =
Nil;
971 int UTF8CharWidth(
unsigned char *U)
974 int CWidth=0, Mask, This;
993 while ( Unicode & Mask )
999 while ( ((*(++U)) & 0xc0) == 0x80 )
1001 Unicode = (Unicode << 6) | (*U & 0x3f);
1004 if ( (This = wcwidth(Unicode)) > 0 ) CWidth += This;
1052 int wcwidth(
wchar_t ucs)
1055 static const struct interval {
1056 unsigned short first;
1057 unsigned short last;
1059 { 0x0300, 0x034E }, { 0x0360, 0x0362 }, { 0x0483, 0x0486 },
1060 { 0x0488, 0x0489 }, { 0x0591, 0x05A1 }, { 0x05A3, 0x05B9 },
1061 { 0x05BB, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
1062 { 0x05C4, 0x05C4 }, { 0x064B, 0x0655 }, { 0x0670, 0x0670 },
1063 { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
1064 { 0x0711, 0x0711 }, { 0x0730, 0x074A }, { 0x07A6, 0x07B0 },
1065 { 0x0901, 0x0902 }, { 0x093C, 0x093C }, { 0x0941, 0x0948 },
1066 { 0x094D, 0x094D }, { 0x0951, 0x0954 }, { 0x0962, 0x0963 },
1067 { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 },
1068 { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x0A02, 0x0A02 },
1069 { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 },
1070 { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 },
1071 { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 },
1072 { 0x0ACD, 0x0ACD }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C },
1073 { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D },
1074 { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
1075 { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
1076 { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBF, 0x0CBF },
1077 { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, { 0x0D41, 0x0D43 },
1078 { 0x0D4D, 0x0D4D }, { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 },
1079 { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A },
1080 { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 },
1081 { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 },
1082 { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 },
1083 { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 },
1084 { 0x0F90, 0x0F97 }, { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 },
1085 { 0x102D, 0x1030 }, { 0x1032, 0x1032 }, { 0x1036, 0x1037 },
1086 { 0x1039, 0x1039 }, { 0x1058, 0x1059 }, { 0x17B7, 0x17BD },
1087 { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x18A9, 0x18A9 },
1088 { 0x20D0, 0x20E3 }, { 0x302A, 0x302F }, { 0x3099, 0x309A },
1089 { 0xFB1E, 0xFB1E }, { 0xFE20, 0xFE23 }
1092 int max =
sizeof(combining) /
sizeof(
struct interval) - 1;
1098 if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
1102 if (ucs < combining[0].first)
1106 while (max >= min) {
1107 mid = (min + max) / 2;
1108 if (combining[mid].last < ucs)
1110 else if (combining[mid].first > ucs)
1112 else if (combining[mid].first <= ucs && combining[mid].last >= ucs)
1123 ((ucs >= 0x1100 && ucs <= 0x115f) ||
1124 (ucs >= 0x2e80 && ucs <= 0xa4cf && (ucs & ~0x0011) != 0x300a &&
1126 (ucs >= 0xac00 && ucs <= 0xd7a3) ||
1127 (ucs >= 0xf900 && ucs <= 0xfaff) ||
1128 (ucs >= 0xfe30 && ucs <= 0xfe6f) ||
1129 (ucs >= 0xff00 && ucs <= 0xff5f) ||
1130 (ucs >= 0xffe0 && ucs <= 0xffe6));
1134 int wcswidth(
const wchar_t *pwcs,
size_t n)
1138 for (;*pwcs && n-- > 0; pwcs++)
1139 if ((w = wcwidth(*pwcs)) < 0)