1 /* Implement Input/Output runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
3 Author: Wilfried Moser, et al
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
40 #include "bitstring.h"
47 #define CH_BYTE_MIN 0xffffff80L
48 #define CH_BYTE_MAX 0x0000007fL
49 #define CH_UBYTE_MAX 0x000000ffUL
50 #define CH_INT_MIN 0xffff8000L
51 #define CH_INT_MAX 0x00007fffL
52 #define CH_UINT_MAX 0x0000ffffUL
53 #define CH_LONG_MIN 0x80000000L
54 #define CH_LONG_MAX 0x7fffffffL
55 #define CH_ULONG_MAX 0xffffffffUL
58 #define M_LN2 0.69314718055994530942
61 #define M_LN10 2.30258509299404568402
64 #define DMANTDIGS (1 + (int)(DBL_MANT_DIG * M_LN2 / M_LN10))
65 #define FMANTDIGS (1 + (int)(FLT_MANT_DIG * M_LN2 / M_LN10))
67 /* float register length */
83 #define isDEC(c) ( chartab[(c)] & DEC )
84 #define isCVC(c) ( chartab[(c)] & CVC )
85 #define isEDC(c) ( chartab[(c)] & EDC )
86 #define isIOC(c) ( chartab[(c)] & IOC )
88 #define isXXX(c,XXX) ( chartab[(c)] & XXX )
95 short int chartab
[256] = {
96 0, 0, 0, 0, 0, 0, 0, 0,
97 0, SPC
, SPC
, SPC
, SPC
, SPC
, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0,
102 SPC
, IOC
, 0, 0, 0, 0, 0, 0,
103 SCS
, SCS
, SCS
, SCS
+IOC
, SCS
, SCS
+IOC
, SCS
, SCS
+IOC
,
104 BIN
+OCT
+DEC
+HEX
, BIN
+OCT
+DEC
+HEX
, OCT
+DEC
+HEX
, OCT
+DEC
+HEX
, OCT
+DEC
+HEX
,
105 OCT
+DEC
+HEX
, OCT
+DEC
+HEX
, OCT
+DEC
+HEX
,
106 DEC
+HEX
, DEC
+HEX
, SCS
, SCS
, SCS
+EDC
, SCS
+IOC
, SCS
+EDC
, IOC
,
108 0, LET
+HEX
+BIL
, LET
+HEX
+BIL
+CVC
, LET
+HEX
+BIL
+CVC
, LET
+HEX
+BIL
, LET
+HEX
,
110 LET
+BIL
+CVC
, LET
, LET
, LET
, LET
, LET
, LET
, LET
+CVC
,
112 LET
, LET
, LET
, LET
, LET
+EDC
, LET
, LET
, LET
,
113 LET
+EDC
, LET
, LET
, SCS
, 0, SCS
, 0, USC
,
115 0, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
,
116 LET
, LET
, LET
, LET
, LET
, LET
, LET
, LET
,
118 LET
, LET
, LET
, LET
, LET
, LET
, LET
, LET
,
119 LET
, LET
, LET
, 0, 0, 0, 0, 0
123 FormatText
, FirstPercent
, RepFact
, ConvClause
, EditClause
, ClauseEnd
,
124 AfterWidth
, FractWidth
, FractWidthCont
, ExpoWidth
, ExpoWidthCont
,
125 ClauseWidth
, CatchPadding
, LastPercent
128 #define CONVERSIONCODES "CHOBF"
130 DefaultConv
, HexConv
, OctalConv
, BinaryConv
, ScientConv
134 short int base
[4] = { 10, 16, 8, 2 };
137 short int dset
[4] = { DEC
, HEX
, OCT
, BIN
};
139 #define EDITCODES "X<>T"
141 SpaceSkip
, SkipLeft
, SkipRight
, Tabulation
144 #define IOCODES "/+-?!="
146 NextRecord
, NextPage
, CurrentLine
, Prompt
, Emit
, EndPage
150 ConvAct
, EditAct
, IOAct
154 NormalEnd
, EndAtParen
, TextFailEnd
159 1e0
, 1e1
, 1e2
, 1e3
, 1e4
, 1e5
, 1e6
, 1e7
, 1e8
, 1e9
};
162 1e0
, 1e10
, 1e20
, 1e30
, 1e40
, 1e50
, 1e60
, 1e70
, 1e80
, 1e90
};
164 double ep_100
= 1e100
;
168 unsigned char floatdig
[MAXPREC
];
171 * global io variables
174 static Text_Mode
* textptr
= NULL
;
175 static VarString
* textrecptr
;
177 static int actual_index
;
178 static int maximum_index
;
179 static int iolist_index
;
181 static __tmp_IO_list
* iolistptr
;
182 static int iolistlen
;
183 static char* iostrptr
;
187 static convcode_t convcode
;
188 static editcode_t editcode
;
189 static iocode_t iocode
;
190 static unsigned long repetition
;
191 static Boolean leftadjust
;
192 static Boolean overflowev
;
193 static Boolean dynamicwid
;
194 static Boolean paddingdef
;
195 static char paddingchar
;
196 static Boolean fractiondef
;
197 static unsigned long fractionwidth
;
198 static Boolean exponentdef
;
199 static unsigned long exponentwidth
;
200 static unsigned long clausewidth
;
201 static signed long textindex
;
204 __tmp_IO_enum_table_type bool_tab
[] =
210 * case insensitive compare: s1 is zero delimited, s2 has n chars
213 int casncmp( const char* s1
, const char* s2
, int n
)
218 if( (res
= toupper(*s1
++) - toupper(*s2
++)) )
225 * skip spaces with blank equal to tab
228 int skip_space( int limit
)
231 while( actual_index
< limit
&&
232 (iostrptr
[actual_index
] == ' ' || iostrptr
[actual_index
] == '\t' ) )
241 * skip leading pad characters
244 int skip_pad( int limit
)
247 while( actual_index
< limit
&& iostrptr
[actual_index
] == paddingchar
)
253 printf( "skipping '%c' until %d: %d\n", paddingchar
, limit
, skipped
);
259 * backup trailing pad characters
262 int piks_pad( int start
, int limit
)
265 while( start
>/***=*/ limit
&& iostrptr
[--start
] == paddingchar
)
270 printf( "piksing '%c' from %d until %d: %d\n",
271 paddingchar
, start
, limit
, skipped
);
280 int parse_int( int limit
, int SET
, int base
,
281 unsigned long* valptr
, int* signptr
)
283 int parsed
= actual_index
;
284 Boolean digits
= False
;
285 unsigned long value
= 0;
289 if( actual_index
>= limit
)
290 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_INT
);
292 if( iostrptr
[actual_index
] == '+' )
295 if( iostrptr
[actual_index
] == '-' )
300 for( ; actual_index
< limit
; actual_index
++ )
302 curr
= iostrptr
[actual_index
];
303 if( curr
== '_' ) continue;
304 if( isXXX(curr
,SET
) )
307 dig
= curr
<= '9' ? curr
- '0' : toupper(curr
) - 'A' + 10;
308 if( value
> (ULONG_MAX
- dig
)/base
)
309 IOEXCEPTION( TEXTFAIL
, INT_VAL_OVERFLOW
);
310 value
= value
*base
+ dig
;
316 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_INT
);
320 printf( "parsing for int until %d, base %d: %u\n", limit
, base
, value
);
322 return actual_index
- parsed
;
327 make_float( int dexp
, int sign
)
329 double value
= atof( floatdig
);
331 printf( " value = %25.20e, dexp = %d\n", value
, dexp
);
334 value
*= ep_100
, dexp
-= 100;
336 value
*= ep_10
[dexp
/10], dexp
%= 10;
340 while( dexp
<= -100 )
341 value
/= ep_100
, dexp
+= 100;
343 value
/= ep_10
[-dexp
/10], dexp
%= 10;
345 value
/= ep_1
[-dexp
];
347 return sign
? -value
: value
;
350 /* %C -> fixed point [+|-]<digit>+[.<digit>*] */
352 int parse_fixedpoint( int limit
, double* valptr
)
354 int parsed
= actual_index
;
355 Boolean digits
= False
;
362 if( actual_index
>= limit
)
363 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_FLOAT
);
364 if( iostrptr
[actual_index
] == '+' )
367 if( iostrptr
[actual_index
] == '-' )
374 for( ; actual_index
< limit
; actual_index
++ )
376 curr
= iostrptr
[actual_index
];
380 if( sdig
< MAXPREC
- 1 )
382 if( sdig
|| curr
!= '0' )
384 floatdig
[++sdig
] = curr
;
392 if( digits
&& curr
== '.' )
395 for( ; actual_index
< limit
; actual_index
++ )
397 curr
= iostrptr
[actual_index
];
400 if( sdig
< MAXPREC
- 1 )
402 if( sdig
|| curr
!= '0' )
403 floatdig
[++sdig
] = curr
;
409 floatdig
[++sdig
] = '\0';
412 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_FLOAT
);
414 *valptr
= make_float( expo
, sign
);
415 return actual_index
- parsed
;
420 s_sign
, s_dig
, s_period
, s_fraca
, s_fracb
, s_expo
, s_exposign
,
424 /* %C -> scientific [+|-]<digit>[.<digit>*]E[=|-]<digit>+ */
426 int parse_scientific( int limit
, double* valptr
, double dmin
, double dmax
)
428 int parsed
= actual_index
;
436 scient_t state
= s_sign
;
438 if( actual_index
>= limit
)
439 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_FLOAT
);
442 for( ; actual_index
< limit
; actual_index
++ )
444 curr
= iostrptr
[actual_index
];
448 if( iostrptr
[actual_index
] == '+' )
453 if( iostrptr
[actual_index
] == '-' )
459 /* fall through - no break */
461 if( isDEC(curr
) && curr
> '0' )
463 floatdig
[++sdig
] = curr
;
467 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_FLOAT
);
479 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
483 floatdig
[++sdig
] = curr
;
487 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_FLOAT
);
491 if( sdig
< MAXPREC
- 1 )
492 floatdig
[++sdig
] = curr
;
500 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
502 if( iostrptr
[actual_index
] == '+' )
507 if( iostrptr
[actual_index
] == '-' )
520 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
522 expo
= expo
*10 + (curr
- '0');
524 IOEXCEPTION( TEXTFAIL
, REAL_OVERFLOW
);
527 if( state
!= s_expob
)
528 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
533 floatdig
[++sdig
] = '\0';
535 *valptr
= make_float( expo
, sign
);
536 return actual_index
- parsed
;
541 int parse_set( int limit
, __tmp_IO_enum_table_type
* tabptr
,
542 unsigned long* valptr
)
544 int parsed
= actual_index
;
546 __tmp_IO_enum_table_type
* etptr
;
548 if( actual_index
>= limit
)
549 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_SET
);
551 curr
= iostrptr
[actual_index
];
552 if( isXXX(curr
,LET
+USC
) )
555 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_SET
);
557 for( ; actual_index
< limit
; actual_index
++ )
559 if( ! isXXX(iostrptr
[actual_index
],LET
+DEC
+USC
) )
564 while( tabptr
->name
)
566 if( !casncmp( tabptr
->name
, &iostrptr
[parsed
], actual_index
-parsed
) )
568 *valptr
= tabptr
->value
;
570 printf( "parsing set value until %d: %u\n", limit
, tabptr
->value
);
572 return actual_index
- parsed
;
576 IOEXCEPTION( TEXTFAIL
, SET_CONVERSION_ERROR
);
580 int parse_bit( int limit
, char* bitptr
)
582 int parsed
= actual_index
;
586 if( actual_index
>= limit
)
587 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_BOOLS
);
589 for( ; actual_index
< limit
; actual_index
++ )
591 curr
= iostrptr
[actual_index
] - '0';
592 if( curr
== 0 || curr
== 1 )
593 /* __setbitinset( i++, bitptr, limit, curr ); */
594 __setbitpowerset (bitptr
, limit
, 0, i
++, curr
, __FILE__
, __LINE__
);
598 return actual_index
- parsed
;
602 char* myultoa( unsigned long ul
, char* buf
, int base
)
605 unsigned long h
= ul
/base
;
608 while( h
>= q
) q
*= base
;
611 *buf
++ = "0123456789ABCDEF"[ul
/q
];
620 * convert a bit string from src, bit offset up to len
623 char* bitput( char* dst
, char* src
, int offset
, int len
)
627 for( i
= offset
; i
< len
; i
++ )
629 *dst
++ = __inpowerset( i
, src
, len
, 0 ) ? '1' : '0';
635 * dround: round decimal register *digptr starting at digit mdigs,
636 * on carry advance begin of digit sequence and bump exponent
640 dround( char* digptr
, int mdigs
, int* deptr
)
644 printf( "Rounding from %d\n", mdigs
);
646 if( digptr
[mdigs
] >= 5 )
652 if( digptr
[mdigs
] >= 10 )
669 * mydtoa: convert val with a precision of mantdigs to a decimal fraction
670 * first digit is at **fstdiptr, decimal exponent is at *deptr
674 mydtoa( double val
, int mantdigs
, int* deptr
, int* sgnptr
)
681 char* digptr
= floatdig
+2;
683 floatdig
[0] = floatdig
[1] = 0;
686 *sgnptr
= -1, val
= fabs( val
);
690 /* split the value */
691 m
= frexp( val
, &be
) * 10.0;
693 /* 5.0 <= m < 10.0 */
696 de
++; be
--; m
/= 5.0;
702 de
--; be
++; m
*= 5.0;
707 for( idig
= 0; idig
< mantdigs
; idig
++ )
709 digptr
[idig
] = (int)m
;
710 m
= (m
- digptr
[idig
])*10.0;
712 digptr
[idig
] = (int)m
;
715 return dround( digptr
, mantdigs
, deptr
);
719 { if( ifst <= ++iprt && iprt <= ilst ) *dst++ = c; }
723 fixput( char* dst
, char* src
,
725 int sign
, int fst
, int lst
,
734 for( idig
= nid
; idig
>= -nfd
; idig
-- )
738 PUT( idig
> fst
|| lst
>= idig
? '0': '0' + *src
++ );
745 sciput( char* dst
, char* src
, char* expbeg
,
747 int sign
, int de
, int expwid
)
751 int nfd
= fractionwidth
;
752 int explen
= strlen( expbeg
);
762 PUT( de
>= 0 ? '+' : '-' );
763 while( expwid
> explen
)
774 * handle dynamic field width
777 get_field_width( void )
780 unsigned long ulongval
;
785 if( ++iolist_index
> iolistlen
)
786 IOEXCEPTION( TEXTFAIL
, IOLIST_EXHAUSTED
);
790 /* must be integer, >= 0 */
794 longval
= io
.__t
.__valbyte
;
795 goto signed_fieldwidth
;
797 width
= io
.__t
.__valubyte
;
798 goto unsigned_fieldwidth
;
800 longval
= io
.__t
.__valint
;
801 goto signed_fieldwidth
;
803 width
= io
.__t
.__valuint
;
804 goto unsigned_fieldwidth
;
806 longval
= io
.__t
.__vallong
;
807 goto signed_fieldwidth
;
809 width
= io
.__t
.__valulong
;
810 goto unsigned_fieldwidth
;
812 longval
= *(signed char*)io
.__t
.__locint
;
813 goto signed_fieldwidth
;
815 width
= *(unsigned char*)io
.__t
.__locint
;
816 goto unsigned_fieldwidth
;
818 longval
= *(signed short*)io
.__t
.__locint
;
819 goto signed_fieldwidth
;
821 width
= *(unsigned short*)io
.__t
.__locint
;
822 goto unsigned_fieldwidth
;
824 longval
= *(signed long*) io
.__t
.__locint
;
825 goto signed_fieldwidth
;
827 width
= *(unsigned long*)io
.__t
.__locint
;
828 goto unsigned_fieldwidth
;
830 IOEXCEPTION( TEXTFAIL
, NON_INT_FIELD_WIDTH
);
835 IOEXCEPTION( TEXTFAIL
, NEGATIVE_FIELD_WIDTH
);
838 unsigned_fieldwidth
: ;
867 __tmp_IO_enum_table_type
* settabptr
;
869 while( repetition
-- )
871 if( ++iolist_index
> iolistlen
)
872 IOEXCEPTION( TEXTFAIL
, IOLIST_EXHAUSTED
);
877 width
= get_field_width();
881 bypass
= skipped
= 0;
884 if( actual_index
+ width
> iostrlen
)
885 IOEXCEPTION( TEXTFAIL
, NOT_ENOUGH_CHARS
);
890 case __IO_CharRangeLoc
:
894 case __IO_CharStrLoc
:
896 fixedlen
= io
.__t
.__loccharstring
.string_length
;
905 skiplim
= fixedchars
? actual_index
+ fixedlen
907 bypass
= skipped
= piks_pad( actual_index
+ width
, skiplim
);
911 skiplim
= fixedchars
? actual_index
+ width
- fixedlen
912 : actual_index
+ width
;
913 skipped
= skip_pad( skiplim
);
916 limit
= actual_index
+ width
;
920 if( paddingdef
|| !( io
.__descr
== __IO_CharLoc
||
921 io
.__descr
== __IO_CharRangeLoc
||
922 io
.__descr
== __IO_CharStrLoc
||
923 io
.__descr
== __IO_CharVaryingLoc
) )
924 if( paddingchar
== ' ' || paddingchar
== '\t' )
925 skip_space( iostrlen
);
927 skip_pad( iostrlen
);
937 goto parse_signed_int
;
942 goto parse_unsigned_int
;
947 goto parse_signed_int
;
952 goto parse_unsigned_int
;
957 goto parse_signed_int
;
962 goto parse_unsigned_int
;
964 case __IO_ByteRangeLoc
:
966 smin
= io
.__t
.__locintrange
.lower
.slong
;
967 smax
= io
.__t
.__locintrange
.upper
.slong
;
968 goto parse_signed_int
;
969 case __IO_UByteRangeLoc
:
971 umin
= io
.__t
.__locintrange
.lower
.ulong
;
972 umax
= io
.__t
.__locintrange
.upper
.ulong
;
973 goto parse_unsigned_int
;
974 case __IO_IntRangeLoc
:
976 smin
= io
.__t
.__locintrange
.lower
.slong
;
977 smax
= io
.__t
.__locintrange
.upper
.slong
;
978 goto parse_signed_int
;
979 case __IO_UIntRangeLoc
:
981 umin
= io
.__t
.__locintrange
.lower
.ulong
;
982 umax
= io
.__t
.__locintrange
.upper
.ulong
;
983 goto parse_unsigned_int
;
984 case __IO_LongRangeLoc
:
986 smin
= io
.__t
.__locintrange
.lower
.slong
;
987 smax
= io
.__t
.__locintrange
.upper
.slong
;
988 goto parse_signed_int
;
989 case __IO_ULongRangeLoc
:
991 umin
= io
.__t
.__locintrange
.lower
.ulong
;
992 umax
= io
.__t
.__locintrange
.upper
.ulong
;
993 goto parse_unsigned_int
;
999 settabptr
= bool_tab
;
1001 case __IO_BoolRangeLoc
:
1003 umin
= io
.__t
.__locboolrange
.lower
;
1004 umax
= io
.__t
.__locboolrange
.upper
;
1005 settabptr
= bool_tab
;
1009 ilen
= io
.__t
.__locsetrange
.length
;
1010 settabptr
= io
.__t
.__locsetrange
.name_table
;
1012 umax
= CH_ULONG_MAX
;
1014 case __IO_SetRangeLoc
:
1015 ilen
= io
.__t
.__locsetrange
.length
;
1016 settabptr
= io
.__t
.__locsetrange
.name_table
;
1017 umin
= io
.__t
.__locsetrange
.lower
;
1018 umax
= io
.__t
.__locsetrange
.upper
;
1025 case __IO_CharRangeLoc
:
1026 umin
= io
.__t
.__loccharrange
.lower
;
1027 umax
= io
.__t
.__loccharrange
.upper
;
1030 case __IO_CharVaryingLoc
:
1031 if( convcode
!= DefaultConv
)
1032 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1033 slen
= io
.__t
.__loccharstring
.string_length
;
1034 if( (parsed
= limit
- actual_index
) < slen
)
1038 memcpy( io
.__t
.__loccharstring
.string
+ 2,
1039 &iostrptr
[actual_index
], parsed
);
1040 MOV2(io
.__t
.__loccharstring
.string
,&slen
);
1041 actual_index
+= parsed
;
1042 goto check_field_complete
;
1045 case __IO_CharStrLoc
:
1046 if( convcode
!= DefaultConv
)
1047 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1048 if( actual_index
+ io
.__t
.__loccharstring
.string_length
> limit
)
1049 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_CHARS
);
1050 memcpy( io
.__t
.__loccharstring
.string
,
1051 &iostrptr
[actual_index
],
1052 parsed
= io
.__t
.__loccharstring
.string_length
);
1053 actual_index
+= parsed
;
1054 goto check_field_complete
;
1056 case __IO_BitStrLoc
:
1057 if( convcode
!= DefaultConv
)
1058 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1059 parsed
= parse_bit( limit
, io
.__t
.__loccharstring
.string
);
1060 if( parsed
< io
.__t
.__loccharstring
.string_length
)
1061 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_BOOLS
);
1062 goto check_field_complete
;
1064 case __IO_LongRealLoc
:
1069 parse_scientific( limit
, &dval
, DBL_MIN
, DBL_MAX
);
1072 parse_fixedpoint( limit
, &dval
);
1075 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1077 if( io
.__descr
== __IO_LongRealLoc
)
1078 memcpy( io
.__t
.__loclongreal
, &dval
, sizeof(double) );
1082 MOV4(io
.__t
.__locreal
,&fval
);
1084 goto check_field_complete
;
1086 IOEXCEPTION( TEXTFAIL
, INVALID_IO_LIST
);
1091 if( convcode
== ScientConv
)
1092 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1093 parsed
= parse_int( limit
, dset
[convcode
], base
[convcode
],
1094 &lval
.ulong
, &sign
);
1097 if( lval
.ulong
> (unsigned long)CH_LONG_MIN
)
1098 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1099 lval
.slong
= -lval
.ulong
;
1103 /* not needed: lval.slong = lval.ulong; */
1104 /* Hack: sign extension for bin/oct/dec if no sign present */
1105 if( convcode
!= DefaultConv
&& lval
.ulong
& (1 << (ilen
*8-1)) )
1108 lval
.ulong
|= 0xFFFFFFFF << ilen
*8;
1111 if( lval
.ulong
> (unsigned long)CH_LONG_MAX
)
1112 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1114 if( lval
.slong
< smin
|| smax
< lval
.slong
)
1115 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1118 parse_unsigned_int
: ;
1119 if( convcode
== ScientConv
)
1120 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1121 parsed
= parse_int( limit
, dset
[convcode
], base
[convcode
],
1122 &lval
.ulong
, &sign
);
1123 if( sign
< 0 || lval
.ulong
< umin
|| umax
< lval
.ulong
)
1124 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1128 if( convcode
!= DefaultConv
)
1129 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1130 parsed
= parse_set( limit
, settabptr
, &lval
.ulong
);
1131 if( lval
.ulong
< umin
|| umax
< lval
.ulong
)
1132 IOEXCEPTION( TEXTFAIL
, SET_RANGE_ERROR
);
1139 *(unsigned char*)io
.__t
.__locint
= lval
.ulong
;
1143 MOV2(io
.__t
.__locint
,&slen
);
1146 MOV4(io
.__t
.__locint
,&lval
.ulong
);
1149 IOEXCEPTION( TEXTFAIL
, INTERNAL_ERROR
);
1151 goto check_field_complete
;
1154 if( convcode
!= DefaultConv
)
1155 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1156 if( actual_index
>= limit
)
1157 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_CHARS
);
1158 curr
= iostrptr
[actual_index
++];
1160 if( curr
< umin
|| umax
< curr
)
1161 IOEXCEPTION( TEXTFAIL
, CHAR_RANGE_ERROR
);
1162 *io
.__t
.__locchar
= curr
;
1163 goto check_field_complete
;
1165 check_field_complete
: ;
1166 actual_index
+= bypass
;
1167 if( width
> parsed
)
1168 IOEXCEPTION( TEXTFAIL
, INVALID_CHAR
);
1173 void inpedit( void )
1178 clausewidth
= get_field_width();
1183 nchars
= repetition
*clausewidth
;
1184 if( actual_index
+ nchars
> iostrlen
)
1185 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_EDIT
);
1186 for( ; nchars
; nchars
-- )
1187 if( iostrptr
[actual_index
++] != ' ' )
1188 IOEXCEPTION( TEXTFAIL
, NO_SPACE_TO_SKIP
);
1192 nchars
= repetition
*clausewidth
;
1193 if( (actual_index
-= nchars
) < 0 )
1194 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_EDIT
);
1198 nchars
= repetition
*clausewidth
;
1199 if( (actual_index
+= nchars
) > iostrlen
)
1200 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_EDIT
);
1204 if( (actual_index
= clausewidth
) > iostrlen
)
1205 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1211 void outconv( void )
1213 unsigned long width
;
1215 unsigned long ulongval
;
1218 __tmp_IO_enum_table_type
* etptr
;
1220 unsigned long itemlen
;
1229 unsigned int expwid
;
1231 while( repetition
-- )
1233 if( ++iolist_index
> iolistlen
)
1234 IOEXCEPTION( TEXTFAIL
, IOLIST_EXHAUSTED
);
1237 width
= dynamicwid
? get_field_width() : clausewidth
;
1242 switch( io
.__descr
)
1245 longval
= io
.__t
.__valbyte
;
1246 goto signed_conversion
;
1248 ulongval
= io
.__t
.__valubyte
;
1249 goto unsigned_conversion
;
1251 longval
= io
.__t
.__valint
;
1252 goto signed_conversion
;
1254 ulongval
= io
.__t
.__valuint
;
1255 goto unsigned_conversion
;
1257 longval
= io
.__t
.__vallong
;
1258 goto signed_conversion
;
1260 ulongval
= io
.__t
.__valulong
;
1261 goto unsigned_conversion
;
1264 switch( io
.__t
.__valbool
)
1275 IOEXCEPTION( TEXTFAIL
, BOOL_CONVERSION_ERROR
);
1279 itembeg
= &io
.__t
.__valchar
;
1284 /* locate name string using set mode name table */
1287 if( (etptr
= io
.__t
.__valset
.name_table
) )
1288 while( etptr
->name
)
1290 if( etptr
->value
== io
.__t
.__valset
.value
)
1292 itembeg
= etptr
->name
;
1293 itemlen
= strlen( itembeg
);
1298 IOEXCEPTION( TEXTFAIL
, SET_CONVERSION_ERROR
);
1300 case __IO_CharVaryingLoc
:
1303 itembeg
= (char*)io
.__t
.__loccharstring
.string
;
1310 case __IO_CharStrLoc
:
1311 itembeg
= io
.__t
.__loccharstring
.string
;
1312 itemlen
= io
.__t
.__loccharstring
.string_length
;
1315 case __IO_BitStrLoc
:
1316 itemlen
= io
.__t
.__loccharstring
.string_length
;
1317 itembeg
= io
.__t
.__loccharstring
.string
;
1322 /* check remaining space */
1323 if( actual_index
+ width
> iostrlen
)
1324 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1326 if( itemlen
== width
)
1327 bitput( iostrptr
+ actual_index
, itembeg
, 0, itemlen
);
1329 if( itemlen
< width
)
1331 memset( bitput( iostrptr
+ actual_index
, itembeg
, 0, itemlen
)
1333 paddingchar
, width
- itemlen
);
1335 bitput( memset( iostrptr
+ actual_index
,
1336 paddingchar
, width
- itemlen
)
1338 itembeg
, itemlen
- width
, itemlen
);
1341 memset( iostrptr
+ actual_index
, '*', width
);
1344 bitput( iostrptr
+ actual_index
, itembeg
, 0, width
);
1346 bitput( iostrptr
+ actual_index
, itembeg
,
1347 itemlen
- width
, itemlen
);
1351 doubleval
= io
.__t
.__valreal
;
1352 mantdigs
= FMANTDIGS
;
1353 goto fixed_point_conversion
;
1354 case __IO_LongRealVal
:
1355 doubleval
= io
.__t
.__vallongreal
;
1357 goto fixed_point_conversion
;
1361 IOEXCEPTION( TEXTFAIL
, INVALID_IO_LIST
);
1367 switch( io
.__descr
)
1371 ulongval
= io
.__t
.__valubyte
;
1375 ulongval
= io
.__t
.__valuint
;
1379 ulongval
= io
.__t
.__valulong
;
1382 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1384 itembeg
= myultoa( ulongval
, itembuf
, base
[convcode
] );
1385 itemlen
= strlen( itembeg
);
1389 switch( io
.__descr
)
1392 doubleval
= io
.__t
.__valreal
;
1393 mantdigs
= FMANTDIGS
;
1395 fractionwidth
= FMANTDIGS
- 1;
1396 goto scientific_conversion
;
1397 case __IO_LongRealVal
:
1398 doubleval
= io
.__t
.__vallongreal
;
1401 fractionwidth
= DBL_DIG
- 1;
1402 goto scientific_conversion
;
1405 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1409 fixed_point_conversion
: ;
1410 itembeg
= mydtoa( doubleval
, mantdigs
, &de
, &sign
);
1411 if( fractiondef
&& de
>= -fractionwidth
- 1
1412 && -fractionwidth
> de
- mantdigs
)
1413 itembeg
= dround( itembeg
, de
+ fractionwidth
+ 1, &de
);
1415 nid
= de
>= 0 ? de
: 0;
1416 nfd
= fractiondef
? fractionwidth
1417 : ( de
+ 1 - mantdigs
> 0 ? 0 : mantdigs
- de
- 1 );
1418 itemlen
= ( sign
< 0 ? 1 : 0 ) + 2 + nid
+ nfd
;
1420 printf( "fixed item length %d\n", itemlen
);
1425 printf( "fixed item width %d\n", width
);
1427 /* check remaining space */
1428 if( actual_index
+ width
> iostrlen
)
1429 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1431 if( itemlen
== width
)
1432 fixput( iostrptr
+ actual_index
, itembeg
,
1433 1, itemlen
, sign
, de
, de
- mantdigs
, nid
, nfd
);
1435 if( itemlen
< width
)
1437 memset( fixput( iostrptr
+ actual_index
, itembeg
,
1438 1, itemlen
, sign
, de
, de
- mantdigs
, nid
, nfd
)
1440 paddingchar
, width
- itemlen
);
1442 fixput( memset( iostrptr
+ actual_index
,
1443 paddingchar
, width
- itemlen
)
1445 itembeg
, 1, itemlen
, sign
, de
, de
- mantdigs
, nid
, nfd
);
1448 memset( iostrptr
+ actual_index
, '*', width
);
1451 fixput( iostrptr
+ actual_index
, itembeg
,
1452 1, width
, sign
, de
, de
- mantdigs
, nid
, nfd
);
1454 fixput( iostrptr
+ actual_index
, itembeg
,
1455 itemlen
- width
+ 1, itemlen
,
1456 sign
, de
, de
- mantdigs
, nid
, nfd
);
1459 scientific_conversion
: ;
1460 itembeg
= mydtoa( doubleval
, mantdigs
, &de
, &sign
);
1462 if( fractiondef
&& fractionwidth
< mantdigs
)
1463 itembeg
= dround( itembeg
, fractionwidth
+ 1, &de
);
1465 expbeg
= myultoa( abs(de
), itembuf
, 10 );
1466 explen
= strlen( expbeg
);
1468 expwid
= explen
> exponentwidth
? explen
: exponentwidth
;
1469 itemlen
= ( sign
< 0 ? 1 : 0 ) + 2 + fractionwidth
+ 2 + expwid
;
1471 printf( "floating item length %d, fraction %d, exponent %d\n",
1472 itemlen
, fractionwidth
, expwid
);
1477 printf( "floating item width %d\n", width
);
1479 /* check remaining space */
1480 if( actual_index
+ width
> iostrlen
)
1481 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1483 if( itemlen
== width
)
1484 sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1485 1, itemlen
, sign
, de
, expwid
);
1487 if( itemlen
< width
)
1489 memset( sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1490 1, itemlen
, sign
, de
, expwid
)
1492 paddingchar
, width
- itemlen
);
1494 sciput( memset( iostrptr
+ actual_index
,
1495 paddingchar
, width
- itemlen
)
1497 itembeg
, expbeg
, 1, itemlen
, sign
, de
, expwid
);
1500 memset( iostrptr
+ actual_index
, '*', width
);
1503 sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1504 1, width
, sign
, de
, expwid
);
1506 sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1507 itemlen
- width
+ 1, itemlen
,
1511 signed_conversion
: ;
1513 itembeg
= myultoa( longval
, itembuf
, 10 );
1517 myultoa( -longval
, itembuf
+1, 10 );
1520 itemlen
= strlen( itembeg
);
1523 unsigned_conversion
: ;
1524 itembeg
= myultoa( ulongval
, itembuf
, 10 );
1525 itemlen
= strlen( itembeg
);
1532 /* check remaining space */
1533 if( actual_index
+ width
> iostrlen
)
1534 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1536 /* move item, filling or truncating or overflow-evidencing */
1537 if( itemlen
== width
)
1538 memcpy( iostrptr
+ actual_index
, itembeg
, itemlen
);
1540 if( itemlen
< width
)
1542 memset( memcpy( iostrptr
+ actual_index
, itembeg
, itemlen
)
1544 paddingchar
, width
- itemlen
);
1546 memcpy( memset( iostrptr
+ actual_index
,
1547 paddingchar
, width
- itemlen
)
1552 memset( iostrptr
+ actual_index
, '*', width
);
1555 memcpy( iostrptr
+ actual_index
, itembeg
, width
);
1557 memcpy( iostrptr
+ actual_index
,
1558 itembeg
+ itemlen
- width
, width
);
1564 actual_index
+= width
;
1565 if( actual_index
> maximum_index
)
1566 maximum_index
= actual_index
;
1571 void outedit( void )
1576 clausewidth
= get_field_width();
1580 nchars
= repetition
*clausewidth
;
1581 if( actual_index
+ nchars
> iostrlen
)
1582 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1583 memset( iostrptr
+ actual_index
, ' ', nchars
);
1584 actual_index
+= nchars
;
1585 if( actual_index
> maximum_index
)
1586 maximum_index
= actual_index
;
1590 nchars
= repetition
*clausewidth
;
1591 if( actual_index
- nchars
< 0 )
1592 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1593 actual_index
-= nchars
;
1597 nchars
= repetition
*clausewidth
;
1598 if( actual_index
+ nchars
> iostrlen
)
1599 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1600 actual_index
+= nchars
;
1601 if( actual_index
> maximum_index
)
1603 memset( iostrptr
+ maximum_index
, ' ', actual_index
- maximum_index
);
1604 maximum_index
= actual_index
;
1609 if( clausewidth
>= iostrlen
)
1610 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1611 actual_index
= clausewidth
;
1612 if( actual_index
> maximum_index
)
1614 memset( iostrptr
+ maximum_index
, ' ', actual_index
- maximum_index
);
1615 maximum_index
= actual_index
;
1623 void inpioctrl( void )
1625 unsigned short hlen
;
1627 IOEXCEPTION( TEXTFAIL
, IO_CONTROL_NOT_VALID
);
1628 if( iocode
!= EndPage
)
1633 if (textptr
->access_sub
->association
)
1635 if( (info
= setjmp( ioerror
)) )
1636 IOEXCEPTION( info
>>16, info
& 0xffff );
1637 while( repetition
-- )
1639 __readrecord( textptr
->access_sub
, textindex
,
1640 (char*)textptr
->text_record
,
1641 __FILE__
, __LINE__
);
1643 MOV2(&hlen
,&textptr
->text_record
->len
);
1648 IOEXCEPTION (NOTCONNECTED
, IS_NOT_CONNECTED
);
1652 /* specify pre/post in the order "/+-?!" */
1654 char* pre_char
= "\0\f\0\r\0"; /* Z.200: "\n\f\0\n\0" */
1656 char* post_char
= "\n\n\r\0\0"; /* Z.200: "\r\r\r\0\0" */
1659 void outioctrl( void )
1661 Association_Mode
* assoc
;
1662 unsigned short hlen
;
1664 IOEXCEPTION( TEXTFAIL
, IO_CONTROL_NOT_VALID
);
1665 if( (assoc
= textptr
->access_sub
->association
) )
1669 if( (info
= setjmp( ioerror
)) )
1670 IOEXCEPTION( info
>>16, info
& 0xffff );
1672 while( repetition
-- )
1674 if( iocode
!= EndPage
)
1676 if( TEST_FLAG( assoc
, IO_FIRSTLINE
) )
1678 CLR_FLAG( assoc
, IO_FIRSTLINE
);
1679 assoc
->ctl_pre
= '\0';
1683 if( TEST_FLAG( assoc
, IO_FORCE_PAGE
) )
1685 CLR_FLAG( assoc
, IO_FORCE_PAGE
);
1686 assoc
->ctl_pre
= '\f';
1689 assoc
->ctl_pre
= pre_char
[iocode
];
1691 assoc
->ctl_post
= post_char
[iocode
];
1692 hlen
= actual_index
;
1693 MOV2(&textptr
->text_record
->len
,&hlen
);
1694 __writerecord( textptr
->access_sub
, textindex
,
1695 (char*)textptr
->text_record
,
1696 textptr
->text_record
->len
,
1697 __FILE__
, __LINE__
);
1698 hlen
= actual_index
= 0;
1699 MOV2(&textptr
->text_record
->len
,&hlen
);
1701 else if( !TEST_FLAG( textptr
, IO_FIRSTLINE
) )
1702 SET_FLAG( textptr
, IO_FORCE_PAGE
);
1703 assoc
->ctl_pre
= assoc
->ctl_post
= '\0';
1707 IOEXCEPTION (NOTCONNECTED
, IS_NOT_CONNECTED
);
1711 void (**actionptr
)( void );
1713 void (*readactions
[])( void ) = { inpconv
, inpedit
, inpioctrl
};
1715 void (*writeactions
[])( void ) = { outconv
, outedit
, outioctrl
};
1719 void emitstr( char* begtxt
, char* endtxt
)
1722 int nchars
= endtxt
- begtxt
;
1723 if( actual_index
+ nchars
> iostrlen
)
1724 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1725 memcpy( iostrptr
+ actual_index
, begtxt
, nchars
);
1726 actual_index
+= nchars
;
1727 if( actual_index
> maximum_index
)
1728 maximum_index
= actual_index
;
1732 void scanstr( char* begtxt
, char* endtxt
)
1734 int nchars
= endtxt
- begtxt
;
1735 if( actual_index
+ nchars
> iostrlen
)
1736 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_TEXT
);
1737 if( strncmp( iostrptr
+ actual_index
, begtxt
, nchars
) )
1738 IOEXCEPTION( TEXTFAIL
, FORMAT_TEXT_MISMATCH
);
1739 actual_index
+= nchars
;
1742 void (*ftextptr
) ( char*, char* );
1745 formatexit_t
scanformcont( char* fcs
, int len
,
1746 char** fcsptr
, int* lenptr
)
1749 fcsstate_t state
= FormatText
;
1763 ftextptr( begtxt
, fcs
-1 );
1764 state
= FirstPercent
;
1768 after_first_percent
: ;
1785 repetition
= curr
- '0';
1791 test_for_control_codes
: ;
1796 convcode
= strchr( CONVERSIONCODES
, curr
) - CONVERSIONCODES
;
1802 fractiondef
= False
;
1803 /* fractionwidth = 0; default depends on mode ! */
1804 exponentdef
= False
;
1813 editcode
= strchr( EDITCODES
, curr
) - EDITCODES
;
1815 clausewidth
= editcode
== Tabulation
? 0 : 1;
1822 iocode
= strchr( IOCODES
, curr
) - IOCODES
;
1827 unsigned long times
= repetition
;
1832 if( scanformcont( fcs
, len
, &cntfcs
, &cntlen
) != EndAtParen
)
1833 IOEXCEPTION( TEXTFAIL
, UNMATCHED_OPENING_PAREN
);
1841 IOEXCEPTION( TEXTFAIL
, BAD_FORMAT_SPEC_CHAR
);
1847 if( repetition
> (ULONG_MAX
- dig
)/10 )
1848 IOEXCEPTION( TEXTFAIL
, REPFAC_OVERFLOW
);
1849 repetition
= repetition
*10 + dig
;
1852 goto test_for_control_codes
;
1857 state
= ClauseWidth
;
1858 clausewidth
= curr
- '0';
1864 IOEXCEPTION( TEXTFAIL
, DUPLICATE_QUALIFIER
);
1871 IOEXCEPTION( TEXTFAIL
, DUPLICATE_QUALIFIER
);
1878 IOEXCEPTION( TEXTFAIL
, DUPLICATE_QUALIFIER
);
1880 state
= CatchPadding
;
1884 test_for_variable_width
: ;
1891 goto test_for_fraction_width
;
1897 if( clausewidth
> (ULONG_MAX
- dig
)/10 )
1898 IOEXCEPTION( TEXTFAIL
, CLAUSE_WIDTH_OVERFLOW
);
1899 clausewidth
= clausewidth
*10 + dig
;
1904 test_for_fraction_width
: ;
1908 if( convcode
!= DefaultConv
&& convcode
!= ScientConv
)
1909 IOEXCEPTION( TEXTFAIL
, NO_FRACTION
);
1914 goto test_for_exponent_width
;
1919 state
= FractWidthCont
;
1920 fractionwidth
= curr
- '0';
1924 IOEXCEPTION( TEXTFAIL
, NO_FRACTION_WIDTH
);
1926 case FractWidthCont
:
1930 if( fractionwidth
> (ULONG_MAX
- dig
)/10 )
1931 IOEXCEPTION( TEXTFAIL
, FRACTION_WIDTH_OVERFLOW
);
1932 fractionwidth
= fractionwidth
*10 + dig
;
1936 test_for_exponent_width
: ;
1939 if( convcode
!= ScientConv
)
1940 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
1945 goto test_for_final_percent
;
1950 state
= ExpoWidthCont
;
1951 exponentwidth
= curr
- '0';
1955 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT_WIDTH
);
1961 if( exponentwidth
> (ULONG_MAX
- dig
)/10 )
1962 IOEXCEPTION( TEXTFAIL
, EXPONENT_WIDTH_OVERFLOW
);
1963 exponentwidth
= exponentwidth
*10 + dig
;
1968 test_for_final_percent
: ;
1972 state
= LastPercent
;
1977 actionptr
[action
]();
1990 state
= ClauseWidth
;
1991 clausewidth
= curr
- '0';
1994 goto test_for_variable_width
;
1997 actionptr
[action
]();
2004 goto after_first_percent
;
2007 IOEXCEPTION( TEXTFAIL
, INTERNAL_ERROR
);
2013 ftextptr( begtxt
, fcs
);
2020 IOEXCEPTION( TEXTFAIL
, BAD_FORMAT_SPEC_CHAR
);
2022 IOEXCEPTION( TEXTFAIL
, NO_PAD_CHAR
);
2024 actionptr
[action
]();
2034 __read_format (char* fmtptr
,
2036 __tmp_IO_list
* ioptr
,
2044 iostrptr
= (char*)inpptr
;
2047 /* initialisation */
2052 actionptr
= readactions
;
2055 if( (res
= scanformcont( fmtptr
, fmtlen
, &fmtptr
, &fmtlen
)) == EndAtParen
)
2056 IOEXCEPTION( TEXTFAIL
, UNMATCHED_CLOSING_PAREN
);
2058 if( iolist_index
!= iolen
)
2059 IOEXCEPTION( TEXTFAIL
, EXCESS_IOLIST_ELEMENTS
);
2065 __readtext_f( Text_Mode
* the_text_loc
,
2066 signed long the_index
,
2069 __tmp_IO_list
* ioptr
,
2076 if( (info
= setjmp( __io_exception
)) )
2077 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2079 textptr
= the_text_loc
;
2080 textrecptr
= textptr
->text_record
;
2081 actual_index
= textptr
->actual_index
;
2082 textindex
= the_index
;
2084 __read_format ( fmtptr
, fmtlen
, ioptr
, iolen
,
2085 (char*)textrecptr
+ 2, textptr
->text_record
->len
);
2086 textptr
->actual_index
= actual_index
;
2090 __readtext_s( void* string_ptr
,
2094 __tmp_IO_list
* ioptr
,
2101 if( (info
= setjmp( __io_exception
)) )
2102 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2107 __read_format ( fmtptr
, fmtlen
, ioptr
, iolen
, string_ptr
, string_len
);
2112 __write_format (char* fmtptr
,
2114 __tmp_IO_list
* ioptr
,
2122 /* initialisation */
2123 maximum_index
= actual_index
;
2126 actionptr
= writeactions
;
2130 iostrptr
= (char *)outptr
+ 2;
2133 if( (res
= scanformcont( fmtptr
, fmtlen
, &fmtptr
, &fmtlen
)) == EndAtParen
)
2134 IOEXCEPTION( TEXTFAIL
, UNMATCHED_CLOSING_PAREN
);
2136 if( iolist_index
!= iolen
)
2137 IOEXCEPTION( TEXTFAIL
, EXCESS_IOLIST_ELEMENTS
);
2139 /* set length of output string */
2141 printf( "maximum index = %d\n", maximum_index
);
2149 __writetext_f( Text_Mode
* the_text_loc
,
2150 signed long the_index
,
2153 __tmp_IO_list
* ioptr
,
2160 if( (info
= setjmp( __io_exception
)) )
2161 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2163 textptr
= the_text_loc
;
2164 textrecptr
= the_text_loc
->text_record
;
2165 textindex
= the_index
;
2169 actual_index
= textptr
->actual_index
;
2170 __write_format ( fmtptr
, fmtlen
, ioptr
, iolen
,
2171 textrecptr
, textptr
->access_sub
->reclength
- 2 );
2172 textptr
->actual_index
= actual_index
;
2176 __writetext_s( void* string_ptr
,
2180 __tmp_IO_list
* ioptr
,
2187 if( (info
= setjmp( __io_exception
)) )
2188 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2193 __write_format ( fmtptr
, fmtlen
, ioptr
, iolen
, string_ptr
, string_len
);