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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
39 #include "bitstring.h"
46 #define CH_BYTE_MIN 0xffffff80L
47 #define CH_BYTE_MAX 0x0000007fL
48 #define CH_UBYTE_MAX 0x000000ffUL
49 #define CH_INT_MIN 0xffff8000L
50 #define CH_INT_MAX 0x00007fffL
51 #define CH_UINT_MAX 0x0000ffffUL
52 #define CH_LONG_MIN 0x80000000L
53 #define CH_LONG_MAX 0x7fffffffL
54 #define CH_ULONG_MAX 0xffffffffUL
57 #define M_LN2 0.69314718055994530942
60 #define M_LN10 2.30258509299404568402
63 #define DMANTDIGS (1 + (int)(DBL_MANT_DIG * M_LN2 / M_LN10))
64 #define FMANTDIGS (1 + (int)(FLT_MANT_DIG * M_LN2 / M_LN10))
66 /* float register length */
82 #define isDEC(c) ( chartab[(c)] & DEC )
83 #define isCVC(c) ( chartab[(c)] & CVC )
84 #define isEDC(c) ( chartab[(c)] & EDC )
85 #define isIOC(c) ( chartab[(c)] & IOC )
87 #define isXXX(c,XXX) ( chartab[(c)] & XXX )
94 short int chartab
[256] = {
95 0, 0, 0, 0, 0, 0, 0, 0,
96 0, SPC
, SPC
, SPC
, SPC
, SPC
, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0,
101 SPC
, IOC
, 0, 0, 0, 0, 0, 0,
102 SCS
, SCS
, SCS
, SCS
+IOC
, SCS
, SCS
+IOC
, SCS
, SCS
+IOC
,
103 BIN
+OCT
+DEC
+HEX
, BIN
+OCT
+DEC
+HEX
, OCT
+DEC
+HEX
, OCT
+DEC
+HEX
, OCT
+DEC
+HEX
,
104 OCT
+DEC
+HEX
, OCT
+DEC
+HEX
, OCT
+DEC
+HEX
,
105 DEC
+HEX
, DEC
+HEX
, SCS
, SCS
, SCS
+EDC
, SCS
+IOC
, SCS
+EDC
, IOC
,
107 0, LET
+HEX
+BIL
, LET
+HEX
+BIL
+CVC
, LET
+HEX
+BIL
+CVC
, LET
+HEX
+BIL
, LET
+HEX
,
109 LET
+BIL
+CVC
, LET
, LET
, LET
, LET
, LET
, LET
, LET
+CVC
,
111 LET
, LET
, LET
, LET
, LET
+EDC
, LET
, LET
, LET
,
112 LET
+EDC
, LET
, LET
, SCS
, 0, SCS
, 0, USC
,
114 0, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
+HEX
, LET
,
115 LET
, LET
, LET
, LET
, LET
, LET
, LET
, LET
,
117 LET
, LET
, LET
, LET
, LET
, LET
, LET
, LET
,
118 LET
, LET
, LET
, 0, 0, 0, 0, 0
122 FormatText
, FirstPercent
, RepFact
, ConvClause
, EditClause
, ClauseEnd
,
123 AfterWidth
, FractWidth
, FractWidthCont
, ExpoWidth
, ExpoWidthCont
,
124 ClauseWidth
, CatchPadding
, LastPercent
127 #define CONVERSIONCODES "CHOBF"
129 DefaultConv
, HexConv
, OctalConv
, BinaryConv
, ScientConv
133 short int base
[4] = { 10, 16, 8, 2 };
136 short int dset
[4] = { DEC
, HEX
, OCT
, BIN
};
138 #define EDITCODES "X<>T"
140 SpaceSkip
, SkipLeft
, SkipRight
, Tabulation
143 #define IOCODES "/+-?!="
145 NextRecord
, NextPage
, CurrentLine
, Prompt
, Emit
, EndPage
149 ConvAct
, EditAct
, IOAct
153 NormalEnd
, EndAtParen
, TextFailEnd
158 1e0
, 1e1
, 1e2
, 1e3
, 1e4
, 1e5
, 1e6
, 1e7
, 1e8
, 1e9
};
161 1e0
, 1e10
, 1e20
, 1e30
, 1e40
, 1e50
, 1e60
, 1e70
, 1e80
, 1e90
};
163 double ep_100
= 1e100
;
167 unsigned char floatdig
[MAXPREC
];
170 * global io variables
173 static Text_Mode
* textptr
= NULL
;
174 static VarString
* textrecptr
;
176 static int actual_index
;
177 static int maximum_index
;
178 static int iolist_index
;
180 static __tmp_IO_list
* iolistptr
;
181 static int iolistlen
;
182 static char* iostrptr
;
186 static convcode_t convcode
;
187 static editcode_t editcode
;
188 static iocode_t iocode
;
189 static unsigned long repetition
;
190 static Boolean leftadjust
;
191 static Boolean overflowev
;
192 static Boolean dynamicwid
;
193 static Boolean paddingdef
;
194 static char paddingchar
;
195 static Boolean fractiondef
;
196 static unsigned long fractionwidth
;
197 static Boolean exponentdef
;
198 static unsigned long exponentwidth
;
199 static unsigned long clausewidth
;
200 static signed long textindex
;
203 __tmp_IO_enum_table_type bool_tab
[] =
209 * case insensitive compare: s1 is zero delimited, s2 has n chars
212 int casncmp( const char* s1
, const char* s2
, int n
)
217 if( (res
= toupper(*s1
++) - toupper(*s2
++)) )
224 * skip spaces with blank equal to tab
227 int skip_space( int limit
)
230 while( actual_index
< limit
&&
231 (iostrptr
[actual_index
] == ' ' || iostrptr
[actual_index
] == '\t' ) )
240 * skip leading pad characters
243 int skip_pad( int limit
)
246 while( actual_index
< limit
&& iostrptr
[actual_index
] == paddingchar
)
252 printf( "skipping '%c' until %d: %d\n", paddingchar
, limit
, skipped
);
258 * backup trailing pad characters
261 int piks_pad( int start
, int limit
)
264 while( start
>/***=*/ limit
&& iostrptr
[--start
] == paddingchar
)
269 printf( "piksing '%c' from %d until %d: %d\n",
270 paddingchar
, start
, limit
, skipped
);
279 int parse_int( int limit
, int SET
, int base
,
280 unsigned long* valptr
, int* signptr
)
282 int parsed
= actual_index
;
283 Boolean digits
= False
;
284 unsigned long value
= 0;
288 if( actual_index
>= limit
)
289 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_INT
);
291 if( iostrptr
[actual_index
] == '+' )
294 if( iostrptr
[actual_index
] == '-' )
299 for( ; actual_index
< limit
; actual_index
++ )
301 curr
= iostrptr
[actual_index
];
302 if( curr
== '_' ) continue;
303 if( isXXX(curr
,SET
) )
306 dig
= curr
<= '9' ? curr
- '0' : toupper(curr
) - 'A' + 10;
307 if( value
> (ULONG_MAX
- dig
)/base
)
308 IOEXCEPTION( TEXTFAIL
, INT_VAL_OVERFLOW
);
309 value
= value
*base
+ dig
;
315 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_INT
);
319 printf( "parsing for int until %d, base %d: %u\n", limit
, base
, value
);
321 return actual_index
- parsed
;
326 make_float( int dexp
, int sign
)
328 double value
= atof( floatdig
);
330 printf( " value = %25.20e, dexp = %d\n", value
, dexp
);
333 value
*= ep_100
, dexp
-= 100;
335 value
*= ep_10
[dexp
/10], dexp
%= 10;
339 while( dexp
<= -100 )
340 value
/= ep_100
, dexp
+= 100;
342 value
/= ep_10
[-dexp
/10], dexp
%= 10;
344 value
/= ep_1
[-dexp
];
346 return sign
? -value
: value
;
349 /* %C -> fixed point [+|-]<digit>+[.<digit>*] */
351 int parse_fixedpoint( int limit
, double* valptr
)
353 int parsed
= actual_index
;
354 Boolean digits
= False
;
361 if( actual_index
>= limit
)
362 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_FLOAT
);
363 if( iostrptr
[actual_index
] == '+' )
366 if( iostrptr
[actual_index
] == '-' )
373 for( ; actual_index
< limit
; actual_index
++ )
375 curr
= iostrptr
[actual_index
];
379 if( sdig
< MAXPREC
- 1 )
381 if( sdig
|| curr
!= '0' )
383 floatdig
[++sdig
] = curr
;
391 if( digits
&& curr
== '.' )
394 for( ; actual_index
< limit
; actual_index
++ )
396 curr
= iostrptr
[actual_index
];
399 if( sdig
< MAXPREC
- 1 )
401 if( sdig
|| curr
!= '0' )
402 floatdig
[++sdig
] = curr
;
408 floatdig
[++sdig
] = '\0';
411 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_FLOAT
);
413 *valptr
= make_float( expo
, sign
);
414 return actual_index
- parsed
;
419 s_sign
, s_dig
, s_period
, s_fraca
, s_fracb
, s_expo
, s_exposign
,
423 /* %C -> scientific [+|-]<digit>[.<digit>*]E[=|-]<digit>+ */
425 int parse_scientific( int limit
, double* valptr
, double dmin
, double dmax
)
427 int parsed
= actual_index
;
435 scient_t state
= s_sign
;
437 if( actual_index
>= limit
)
438 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_FLOAT
);
441 for( ; actual_index
< limit
; actual_index
++ )
443 curr
= iostrptr
[actual_index
];
447 if( iostrptr
[actual_index
] == '+' )
452 if( iostrptr
[actual_index
] == '-' )
458 /* fall through - no break */
460 if( isDEC(curr
) && curr
> '0' )
462 floatdig
[++sdig
] = curr
;
466 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_FLOAT
);
478 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
482 floatdig
[++sdig
] = curr
;
486 IOEXCEPTION( TEXTFAIL
, NO_DIGITS_FOR_FLOAT
);
490 if( sdig
< MAXPREC
- 1 )
491 floatdig
[++sdig
] = curr
;
499 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
501 if( iostrptr
[actual_index
] == '+' )
506 if( iostrptr
[actual_index
] == '-' )
519 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
521 expo
= expo
*10 + (curr
- '0');
523 IOEXCEPTION( TEXTFAIL
, REAL_OVERFLOW
);
526 if( state
!= s_expob
)
527 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
532 floatdig
[++sdig
] = '\0';
534 *valptr
= make_float( expo
, sign
);
535 return actual_index
- parsed
;
540 int parse_set( int limit
, __tmp_IO_enum_table_type
* tabptr
,
541 unsigned long* valptr
)
543 int parsed
= actual_index
;
545 __tmp_IO_enum_table_type
* etptr
;
547 if( actual_index
>= limit
)
548 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_SET
);
550 curr
= iostrptr
[actual_index
];
551 if( isXXX(curr
,LET
+USC
) )
554 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_SET
);
556 for( ; actual_index
< limit
; actual_index
++ )
558 if( ! isXXX(iostrptr
[actual_index
],LET
+DEC
+USC
) )
563 while( tabptr
->name
)
565 if( !casncmp( tabptr
->name
, &iostrptr
[parsed
], actual_index
-parsed
) )
567 *valptr
= tabptr
->value
;
569 printf( "parsing set value until %d: %u\n", limit
, tabptr
->value
);
571 return actual_index
- parsed
;
575 IOEXCEPTION( TEXTFAIL
, SET_CONVERSION_ERROR
);
579 int parse_bit( int limit
, char* bitptr
)
581 int parsed
= actual_index
;
585 if( actual_index
>= limit
)
586 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_BOOLS
);
588 for( ; actual_index
< limit
; actual_index
++ )
590 curr
= iostrptr
[actual_index
] - '0';
591 if( curr
== 0 || curr
== 1 )
592 /* __setbitinset( i++, bitptr, limit, curr ); */
593 __setbitpowerset (bitptr
, limit
, 0, i
++, curr
, __FILE__
, __LINE__
);
597 return actual_index
- parsed
;
601 char* myultoa( unsigned long ul
, char* buf
, int base
)
604 unsigned long h
= ul
/base
;
607 while( h
>= q
) q
*= base
;
610 *buf
++ = "0123456789ABCDEF"[ul
/q
];
619 * convert a bit string from src, bit offset up to len
622 char* bitput( char* dst
, char* src
, int offset
, int len
)
626 for( i
= offset
; i
< len
; i
++ )
628 *dst
++ = __inpowerset( i
, src
, len
, 0 ) ? '1' : '0';
634 * dround: round decimal register *digptr starting at digit mdigs,
635 * on carry advance begin of digit sequence and bump exponent
639 dround( char* digptr
, int mdigs
, int* deptr
)
643 printf( "Rounding from %d\n", mdigs
);
645 if( digptr
[mdigs
] >= 5 )
651 if( digptr
[mdigs
] >= 10 )
668 * mydtoa: convert val with a precision of mantdigs to a decimal fraction
669 * first digit is at **fstdiptr, decimal exponent is at *deptr
673 mydtoa( double val
, int mantdigs
, int* deptr
, int* sgnptr
)
680 char* digptr
= floatdig
+2;
682 floatdig
[0] = floatdig
[1] = 0;
685 *sgnptr
= -1, val
= fabs( val
);
689 /* split the value */
690 m
= frexp( val
, &be
) * 10.0;
692 /* 5.0 <= m < 10.0 */
695 de
++; be
--; m
/= 5.0;
701 de
--; be
++; m
*= 5.0;
706 for( idig
= 0; idig
< mantdigs
; idig
++ )
708 digptr
[idig
] = (int)m
;
709 m
= (m
- digptr
[idig
])*10.0;
711 digptr
[idig
] = (int)m
;
714 return dround( digptr
, mantdigs
, deptr
);
718 { if( ifst <= ++iprt && iprt <= ilst ) *dst++ = c; }
722 fixput( char* dst
, char* src
,
724 int sign
, int fst
, int lst
,
733 for( idig
= nid
; idig
>= -nfd
; idig
-- )
737 PUT( idig
> fst
|| lst
>= idig
? '0': '0' + *src
++ );
744 sciput( char* dst
, char* src
, char* expbeg
,
746 int sign
, int de
, int expwid
)
750 int nfd
= fractionwidth
;
751 int explen
= strlen( expbeg
);
761 PUT( de
>= 0 ? '+' : '-' );
762 while( expwid
> explen
)
773 * handle dynamic field width
776 get_field_width( void )
779 unsigned long ulongval
;
784 if( ++iolist_index
> iolistlen
)
785 IOEXCEPTION( TEXTFAIL
, IOLIST_EXHAUSTED
);
789 /* must be integer, >= 0 */
793 longval
= io
.__t
.__valbyte
;
794 goto signed_fieldwidth
;
796 width
= io
.__t
.__valubyte
;
797 goto unsigned_fieldwidth
;
799 longval
= io
.__t
.__valint
;
800 goto signed_fieldwidth
;
802 width
= io
.__t
.__valuint
;
803 goto unsigned_fieldwidth
;
805 longval
= io
.__t
.__vallong
;
806 goto signed_fieldwidth
;
808 width
= io
.__t
.__valulong
;
809 goto unsigned_fieldwidth
;
811 longval
= *(signed char*)io
.__t
.__locint
;
812 goto signed_fieldwidth
;
814 width
= *(unsigned char*)io
.__t
.__locint
;
815 goto unsigned_fieldwidth
;
817 longval
= *(signed short*)io
.__t
.__locint
;
818 goto signed_fieldwidth
;
820 width
= *(unsigned short*)io
.__t
.__locint
;
821 goto unsigned_fieldwidth
;
823 longval
= *(signed long*) io
.__t
.__locint
;
824 goto signed_fieldwidth
;
826 width
= *(unsigned long*)io
.__t
.__locint
;
827 goto unsigned_fieldwidth
;
829 IOEXCEPTION( TEXTFAIL
, NON_INT_FIELD_WIDTH
);
834 IOEXCEPTION( TEXTFAIL
, NEGATIVE_FIELD_WIDTH
);
837 unsigned_fieldwidth
: ;
866 __tmp_IO_enum_table_type
* settabptr
;
868 while( repetition
-- )
870 if( ++iolist_index
> iolistlen
)
871 IOEXCEPTION( TEXTFAIL
, IOLIST_EXHAUSTED
);
876 width
= get_field_width();
880 bypass
= skipped
= 0;
883 if( actual_index
+ width
> iostrlen
)
884 IOEXCEPTION( TEXTFAIL
, NOT_ENOUGH_CHARS
);
889 case __IO_CharRangeLoc
:
893 case __IO_CharStrLoc
:
895 fixedlen
= io
.__t
.__loccharstring
.string_length
;
904 skiplim
= fixedchars
? actual_index
+ fixedlen
906 bypass
= skipped
= piks_pad( actual_index
+ width
, skiplim
);
910 skiplim
= fixedchars
? actual_index
+ width
- fixedlen
911 : actual_index
+ width
;
912 skipped
= skip_pad( skiplim
);
915 limit
= actual_index
+ width
;
919 if( paddingdef
|| !( io
.__descr
== __IO_CharLoc
||
920 io
.__descr
== __IO_CharRangeLoc
||
921 io
.__descr
== __IO_CharStrLoc
||
922 io
.__descr
== __IO_CharVaryingLoc
) )
923 if( paddingchar
== ' ' || paddingchar
== '\t' )
924 skip_space( iostrlen
);
926 skip_pad( iostrlen
);
936 goto parse_signed_int
;
941 goto parse_unsigned_int
;
946 goto parse_signed_int
;
951 goto parse_unsigned_int
;
956 goto parse_signed_int
;
961 goto parse_unsigned_int
;
963 case __IO_ByteRangeLoc
:
965 smin
= io
.__t
.__locintrange
.lower
.slong
;
966 smax
= io
.__t
.__locintrange
.upper
.slong
;
967 goto parse_signed_int
;
968 case __IO_UByteRangeLoc
:
970 umin
= io
.__t
.__locintrange
.lower
.ulong
;
971 umax
= io
.__t
.__locintrange
.upper
.ulong
;
972 goto parse_unsigned_int
;
973 case __IO_IntRangeLoc
:
975 smin
= io
.__t
.__locintrange
.lower
.slong
;
976 smax
= io
.__t
.__locintrange
.upper
.slong
;
977 goto parse_signed_int
;
978 case __IO_UIntRangeLoc
:
980 umin
= io
.__t
.__locintrange
.lower
.ulong
;
981 umax
= io
.__t
.__locintrange
.upper
.ulong
;
982 goto parse_unsigned_int
;
983 case __IO_LongRangeLoc
:
985 smin
= io
.__t
.__locintrange
.lower
.slong
;
986 smax
= io
.__t
.__locintrange
.upper
.slong
;
987 goto parse_signed_int
;
988 case __IO_ULongRangeLoc
:
990 umin
= io
.__t
.__locintrange
.lower
.ulong
;
991 umax
= io
.__t
.__locintrange
.upper
.ulong
;
992 goto parse_unsigned_int
;
998 settabptr
= bool_tab
;
1000 case __IO_BoolRangeLoc
:
1002 umin
= io
.__t
.__locboolrange
.lower
;
1003 umax
= io
.__t
.__locboolrange
.upper
;
1004 settabptr
= bool_tab
;
1008 ilen
= io
.__t
.__locsetrange
.length
;
1009 settabptr
= io
.__t
.__locsetrange
.name_table
;
1011 umax
= CH_ULONG_MAX
;
1013 case __IO_SetRangeLoc
:
1014 ilen
= io
.__t
.__locsetrange
.length
;
1015 settabptr
= io
.__t
.__locsetrange
.name_table
;
1016 umin
= io
.__t
.__locsetrange
.lower
;
1017 umax
= io
.__t
.__locsetrange
.upper
;
1024 case __IO_CharRangeLoc
:
1025 umin
= io
.__t
.__loccharrange
.lower
;
1026 umax
= io
.__t
.__loccharrange
.upper
;
1029 case __IO_CharVaryingLoc
:
1030 if( convcode
!= DefaultConv
)
1031 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1032 slen
= io
.__t
.__loccharstring
.string_length
;
1033 if( (parsed
= limit
- actual_index
) < slen
)
1037 memcpy( io
.__t
.__loccharstring
.string
+ 2,
1038 &iostrptr
[actual_index
], parsed
);
1039 MOV2(io
.__t
.__loccharstring
.string
,&slen
);
1040 actual_index
+= parsed
;
1041 goto check_field_complete
;
1044 case __IO_CharStrLoc
:
1045 if( convcode
!= DefaultConv
)
1046 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1047 if( actual_index
+ io
.__t
.__loccharstring
.string_length
> limit
)
1048 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_CHARS
);
1049 memcpy( io
.__t
.__loccharstring
.string
,
1050 &iostrptr
[actual_index
],
1051 parsed
= io
.__t
.__loccharstring
.string_length
);
1052 actual_index
+= parsed
;
1053 goto check_field_complete
;
1055 case __IO_BitStrLoc
:
1056 if( convcode
!= DefaultConv
)
1057 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1058 parsed
= parse_bit( limit
, io
.__t
.__loccharstring
.string
);
1059 if( parsed
< io
.__t
.__loccharstring
.string_length
)
1060 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_BOOLS
);
1061 goto check_field_complete
;
1063 case __IO_LongRealLoc
:
1068 parse_scientific( limit
, &dval
, DBL_MIN
, DBL_MAX
);
1071 parse_fixedpoint( limit
, &dval
);
1074 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1076 if( io
.__descr
== __IO_LongRealLoc
)
1077 memcpy( io
.__t
.__loclongreal
, &dval
, sizeof(double) );
1081 MOV4(io
.__t
.__locreal
,&fval
);
1083 goto check_field_complete
;
1085 IOEXCEPTION( TEXTFAIL
, INVALID_IO_LIST
);
1090 if( convcode
== ScientConv
)
1091 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1092 parsed
= parse_int( limit
, dset
[convcode
], base
[convcode
],
1093 &lval
.ulong
, &sign
);
1096 if( lval
.ulong
> (unsigned long)CH_LONG_MIN
)
1097 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1098 lval
.slong
= -lval
.ulong
;
1102 /* not needed: lval.slong = lval.ulong; */
1103 /* Hack: sign extension for bin/oct/dec if no sign present */
1104 if( convcode
!= DefaultConv
&& lval
.ulong
& (1 << (ilen
*8-1)) )
1107 lval
.ulong
|= 0xFFFFFFFF << ilen
*8;
1110 if( lval
.ulong
> (unsigned long)CH_LONG_MAX
)
1111 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1113 if( lval
.slong
< smin
|| smax
< lval
.slong
)
1114 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1117 parse_unsigned_int
: ;
1118 if( convcode
== ScientConv
)
1119 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1120 parsed
= parse_int( limit
, dset
[convcode
], base
[convcode
],
1121 &lval
.ulong
, &sign
);
1122 if( sign
< 0 || lval
.ulong
< umin
|| umax
< lval
.ulong
)
1123 IOEXCEPTION( TEXTFAIL
, INTEGER_RANGE_ERROR
);
1127 if( convcode
!= DefaultConv
)
1128 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1129 parsed
= parse_set( limit
, settabptr
, &lval
.ulong
);
1130 if( lval
.ulong
< umin
|| umax
< lval
.ulong
)
1131 IOEXCEPTION( TEXTFAIL
, SET_RANGE_ERROR
);
1138 *(unsigned char*)io
.__t
.__locint
= lval
.ulong
;
1142 MOV2(io
.__t
.__locint
,&slen
);
1145 MOV4(io
.__t
.__locint
,&lval
.ulong
);
1148 IOEXCEPTION( TEXTFAIL
, INTERNAL_ERROR
);
1150 goto check_field_complete
;
1153 if( convcode
!= DefaultConv
)
1154 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1155 if( actual_index
>= limit
)
1156 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_CHARS
);
1157 curr
= iostrptr
[actual_index
++];
1159 if( curr
< umin
|| umax
< curr
)
1160 IOEXCEPTION( TEXTFAIL
, CHAR_RANGE_ERROR
);
1161 *io
.__t
.__locchar
= curr
;
1162 goto check_field_complete
;
1164 check_field_complete
: ;
1165 actual_index
+= bypass
;
1166 if( width
> parsed
)
1167 IOEXCEPTION( TEXTFAIL
, INVALID_CHAR
);
1172 void inpedit( void )
1177 clausewidth
= get_field_width();
1182 nchars
= repetition
*clausewidth
;
1183 if( actual_index
+ nchars
> iostrlen
)
1184 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_EDIT
);
1185 for( ; nchars
; nchars
-- )
1186 if( iostrptr
[actual_index
++] != ' ' )
1187 IOEXCEPTION( TEXTFAIL
, NO_SPACE_TO_SKIP
);
1191 nchars
= repetition
*clausewidth
;
1192 if( (actual_index
-= nchars
) < 0 )
1193 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_EDIT
);
1197 nchars
= repetition
*clausewidth
;
1198 if( (actual_index
+= nchars
) > iostrlen
)
1199 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_EDIT
);
1203 if( (actual_index
= clausewidth
) > iostrlen
)
1204 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1210 void outconv( void )
1212 unsigned long width
;
1214 unsigned long ulongval
;
1217 __tmp_IO_enum_table_type
* etptr
;
1219 unsigned long itemlen
;
1228 unsigned int expwid
;
1230 while( repetition
-- )
1232 if( ++iolist_index
> iolistlen
)
1233 IOEXCEPTION( TEXTFAIL
, IOLIST_EXHAUSTED
);
1236 width
= dynamicwid
? get_field_width() : clausewidth
;
1241 switch( io
.__descr
)
1244 longval
= io
.__t
.__valbyte
;
1245 goto signed_conversion
;
1247 ulongval
= io
.__t
.__valubyte
;
1248 goto unsigned_conversion
;
1250 longval
= io
.__t
.__valint
;
1251 goto signed_conversion
;
1253 ulongval
= io
.__t
.__valuint
;
1254 goto unsigned_conversion
;
1256 longval
= io
.__t
.__vallong
;
1257 goto signed_conversion
;
1259 ulongval
= io
.__t
.__valulong
;
1260 goto unsigned_conversion
;
1263 switch( io
.__t
.__valbool
)
1274 IOEXCEPTION( TEXTFAIL
, BOOL_CONVERSION_ERROR
);
1278 itembeg
= &io
.__t
.__valchar
;
1283 /* locate name string using set mode name table */
1286 if( (etptr
= io
.__t
.__valset
.name_table
) )
1287 while( etptr
->name
)
1289 if( etptr
->value
== io
.__t
.__valset
.value
)
1291 itembeg
= etptr
->name
;
1292 itemlen
= strlen( itembeg
);
1297 IOEXCEPTION( TEXTFAIL
, SET_CONVERSION_ERROR
);
1299 case __IO_CharVaryingLoc
:
1302 itembeg
= (char*)io
.__t
.__loccharstring
.string
;
1309 case __IO_CharStrLoc
:
1310 itembeg
= io
.__t
.__loccharstring
.string
;
1311 itemlen
= io
.__t
.__loccharstring
.string_length
;
1314 case __IO_BitStrLoc
:
1315 itemlen
= io
.__t
.__loccharstring
.string_length
;
1316 itembeg
= io
.__t
.__loccharstring
.string
;
1321 /* check remaining space */
1322 if( actual_index
+ width
> iostrlen
)
1323 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1325 if( itemlen
== width
)
1326 bitput( iostrptr
+ actual_index
, itembeg
, 0, itemlen
);
1328 if( itemlen
< width
)
1330 memset( bitput( iostrptr
+ actual_index
, itembeg
, 0, itemlen
)
1332 paddingchar
, width
- itemlen
);
1334 bitput( memset( iostrptr
+ actual_index
,
1335 paddingchar
, width
- itemlen
)
1337 itembeg
, itemlen
- width
, itemlen
);
1340 memset( iostrptr
+ actual_index
, '*', width
);
1343 bitput( iostrptr
+ actual_index
, itembeg
, 0, width
);
1345 bitput( iostrptr
+ actual_index
, itembeg
,
1346 itemlen
- width
, itemlen
);
1350 doubleval
= io
.__t
.__valreal
;
1351 mantdigs
= FMANTDIGS
;
1352 goto fixed_point_conversion
;
1353 case __IO_LongRealVal
:
1354 doubleval
= io
.__t
.__vallongreal
;
1356 goto fixed_point_conversion
;
1360 IOEXCEPTION( TEXTFAIL
, INVALID_IO_LIST
);
1366 switch( io
.__descr
)
1370 ulongval
= io
.__t
.__valubyte
;
1374 ulongval
= io
.__t
.__valuint
;
1378 ulongval
= io
.__t
.__valulong
;
1381 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1383 itembeg
= myultoa( ulongval
, itembuf
, base
[convcode
] );
1384 itemlen
= strlen( itembeg
);
1388 switch( io
.__descr
)
1391 doubleval
= io
.__t
.__valreal
;
1392 mantdigs
= FMANTDIGS
;
1394 fractionwidth
= FMANTDIGS
- 1;
1395 goto scientific_conversion
;
1396 case __IO_LongRealVal
:
1397 doubleval
= io
.__t
.__vallongreal
;
1400 fractionwidth
= DBL_DIG
- 1;
1401 goto scientific_conversion
;
1404 IOEXCEPTION( TEXTFAIL
, CONVCODE_MODE_MISFIT
);
1408 fixed_point_conversion
: ;
1409 itembeg
= mydtoa( doubleval
, mantdigs
, &de
, &sign
);
1410 if( fractiondef
&& de
>= -fractionwidth
- 1
1411 && -fractionwidth
> de
- mantdigs
)
1412 itembeg
= dround( itembeg
, de
+ fractionwidth
+ 1, &de
);
1414 nid
= de
>= 0 ? de
: 0;
1415 nfd
= fractiondef
? fractionwidth
1416 : ( de
+ 1 - mantdigs
> 0 ? 0 : mantdigs
- de
- 1 );
1417 itemlen
= ( sign
< 0 ? 1 : 0 ) + 2 + nid
+ nfd
;
1419 printf( "fixed item length %d\n", itemlen
);
1424 printf( "fixed item width %d\n", width
);
1426 /* check remaining space */
1427 if( actual_index
+ width
> iostrlen
)
1428 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1430 if( itemlen
== width
)
1431 fixput( iostrptr
+ actual_index
, itembeg
,
1432 1, itemlen
, sign
, de
, de
- mantdigs
, nid
, nfd
);
1434 if( itemlen
< width
)
1436 memset( fixput( iostrptr
+ actual_index
, itembeg
,
1437 1, itemlen
, sign
, de
, de
- mantdigs
, nid
, nfd
)
1439 paddingchar
, width
- itemlen
);
1441 fixput( memset( iostrptr
+ actual_index
,
1442 paddingchar
, width
- itemlen
)
1444 itembeg
, 1, itemlen
, sign
, de
, de
- mantdigs
, nid
, nfd
);
1447 memset( iostrptr
+ actual_index
, '*', width
);
1450 fixput( iostrptr
+ actual_index
, itembeg
,
1451 1, width
, sign
, de
, de
- mantdigs
, nid
, nfd
);
1453 fixput( iostrptr
+ actual_index
, itembeg
,
1454 itemlen
- width
+ 1, itemlen
,
1455 sign
, de
, de
- mantdigs
, nid
, nfd
);
1458 scientific_conversion
: ;
1459 itembeg
= mydtoa( doubleval
, mantdigs
, &de
, &sign
);
1461 if( fractiondef
&& fractionwidth
< mantdigs
)
1462 itembeg
= dround( itembeg
, fractionwidth
+ 1, &de
);
1464 expbeg
= myultoa( abs(de
), itembuf
, 10 );
1465 explen
= strlen( expbeg
);
1467 expwid
= explen
> exponentwidth
? explen
: exponentwidth
;
1468 itemlen
= ( sign
< 0 ? 1 : 0 ) + 2 + fractionwidth
+ 2 + expwid
;
1470 printf( "floating item length %d, fraction %d, exponent %d\n",
1471 itemlen
, fractionwidth
, expwid
);
1476 printf( "floating item width %d\n", width
);
1478 /* check remaining space */
1479 if( actual_index
+ width
> iostrlen
)
1480 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1482 if( itemlen
== width
)
1483 sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1484 1, itemlen
, sign
, de
, expwid
);
1486 if( itemlen
< width
)
1488 memset( sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1489 1, itemlen
, sign
, de
, expwid
)
1491 paddingchar
, width
- itemlen
);
1493 sciput( memset( iostrptr
+ actual_index
,
1494 paddingchar
, width
- itemlen
)
1496 itembeg
, expbeg
, 1, itemlen
, sign
, de
, expwid
);
1499 memset( iostrptr
+ actual_index
, '*', width
);
1502 sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1503 1, width
, sign
, de
, expwid
);
1505 sciput( iostrptr
+ actual_index
, itembeg
, expbeg
,
1506 itemlen
- width
+ 1, itemlen
,
1510 signed_conversion
: ;
1512 itembeg
= myultoa( longval
, itembuf
, 10 );
1516 myultoa( -longval
, itembuf
+1, 10 );
1519 itemlen
= strlen( itembeg
);
1522 unsigned_conversion
: ;
1523 itembeg
= myultoa( ulongval
, itembuf
, 10 );
1524 itemlen
= strlen( itembeg
);
1531 /* check remaining space */
1532 if( actual_index
+ width
> iostrlen
)
1533 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1535 /* move item, filling or truncating or overflow-evidencing */
1536 if( itemlen
== width
)
1537 memcpy( iostrptr
+ actual_index
, itembeg
, itemlen
);
1539 if( itemlen
< width
)
1541 memset( memcpy( iostrptr
+ actual_index
, itembeg
, itemlen
)
1543 paddingchar
, width
- itemlen
);
1545 memcpy( memset( iostrptr
+ actual_index
,
1546 paddingchar
, width
- itemlen
)
1551 memset( iostrptr
+ actual_index
, '*', width
);
1554 memcpy( iostrptr
+ actual_index
, itembeg
, width
);
1556 memcpy( iostrptr
+ actual_index
,
1557 itembeg
+ itemlen
- width
, width
);
1563 actual_index
+= width
;
1564 if( actual_index
> maximum_index
)
1565 maximum_index
= actual_index
;
1570 void outedit( void )
1575 clausewidth
= get_field_width();
1579 nchars
= repetition
*clausewidth
;
1580 if( actual_index
+ nchars
> iostrlen
)
1581 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1582 memset( iostrptr
+ actual_index
, ' ', nchars
);
1583 actual_index
+= nchars
;
1584 if( actual_index
> maximum_index
)
1585 maximum_index
= actual_index
;
1589 nchars
= repetition
*clausewidth
;
1590 if( actual_index
- nchars
< 0 )
1591 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1592 actual_index
-= nchars
;
1596 nchars
= repetition
*clausewidth
;
1597 if( actual_index
+ nchars
> iostrlen
)
1598 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1599 actual_index
+= nchars
;
1600 if( actual_index
> maximum_index
)
1602 memset( iostrptr
+ maximum_index
, ' ', actual_index
- maximum_index
);
1603 maximum_index
= actual_index
;
1608 if( clausewidth
>= iostrlen
)
1609 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1610 actual_index
= clausewidth
;
1611 if( actual_index
> maximum_index
)
1613 memset( iostrptr
+ maximum_index
, ' ', actual_index
- maximum_index
);
1614 maximum_index
= actual_index
;
1622 void inpioctrl( void )
1624 unsigned short hlen
;
1626 IOEXCEPTION( TEXTFAIL
, IO_CONTROL_NOT_VALID
);
1627 if( iocode
!= EndPage
)
1632 if (textptr
->access_sub
->association
)
1634 if( (info
= setjmp( ioerror
)) )
1635 IOEXCEPTION( info
>>16, info
& 0xffff );
1636 while( repetition
-- )
1638 __readrecord( textptr
->access_sub
, textindex
,
1639 (char*)textptr
->text_record
,
1640 __FILE__
, __LINE__
);
1642 MOV2(&hlen
,&textptr
->text_record
->len
);
1647 IOEXCEPTION (NOTCONNECTED
, IS_NOT_CONNECTED
);
1651 /* specify pre/post in the order "/+-?!" */
1653 char* pre_char
= "\0\f\0\r\0"; /* Z.200: "\n\f\0\n\0" */
1655 char* post_char
= "\n\n\r\0\0"; /* Z.200: "\r\r\r\0\0" */
1658 void outioctrl( void )
1660 Association_Mode
* assoc
;
1661 unsigned short hlen
;
1663 IOEXCEPTION( TEXTFAIL
, IO_CONTROL_NOT_VALID
);
1664 if( (assoc
= textptr
->access_sub
->association
) )
1668 if( (info
= setjmp( ioerror
)) )
1669 IOEXCEPTION( info
>>16, info
& 0xffff );
1671 while( repetition
-- )
1673 if( iocode
!= EndPage
)
1675 if( TEST_FLAG( assoc
, IO_FIRSTLINE
) )
1677 CLR_FLAG( assoc
, IO_FIRSTLINE
);
1678 assoc
->ctl_pre
= '\0';
1682 if( TEST_FLAG( assoc
, IO_FORCE_PAGE
) )
1684 CLR_FLAG( assoc
, IO_FORCE_PAGE
);
1685 assoc
->ctl_pre
= '\f';
1688 assoc
->ctl_pre
= pre_char
[iocode
];
1690 assoc
->ctl_post
= post_char
[iocode
];
1691 hlen
= actual_index
;
1692 MOV2(&textptr
->text_record
->len
,&hlen
);
1693 __writerecord( textptr
->access_sub
, textindex
,
1694 (char*)textptr
->text_record
,
1695 textptr
->text_record
->len
,
1696 __FILE__
, __LINE__
);
1697 hlen
= actual_index
= 0;
1698 MOV2(&textptr
->text_record
->len
,&hlen
);
1700 else if( !TEST_FLAG( textptr
, IO_FIRSTLINE
) )
1701 SET_FLAG( textptr
, IO_FORCE_PAGE
);
1702 assoc
->ctl_pre
= assoc
->ctl_post
= '\0';
1706 IOEXCEPTION (NOTCONNECTED
, IS_NOT_CONNECTED
);
1710 void (**actionptr
)( void );
1712 void (*readactions
[])( void ) = { inpconv
, inpedit
, inpioctrl
};
1714 void (*writeactions
[])( void ) = { outconv
, outedit
, outioctrl
};
1718 void emitstr( char* begtxt
, char* endtxt
)
1721 int nchars
= endtxt
- begtxt
;
1722 if( actual_index
+ nchars
> iostrlen
)
1723 IOEXCEPTION( TEXTFAIL
, TEXT_LOC_OVERFLOW
);
1724 memcpy( iostrptr
+ actual_index
, begtxt
, nchars
);
1725 actual_index
+= nchars
;
1726 if( actual_index
> maximum_index
)
1727 maximum_index
= actual_index
;
1731 void scanstr( char* begtxt
, char* endtxt
)
1733 int nchars
= endtxt
- begtxt
;
1734 if( actual_index
+ nchars
> iostrlen
)
1735 IOEXCEPTION( TEXTFAIL
, NO_CHARS_FOR_TEXT
);
1736 if( strncmp( iostrptr
+ actual_index
, begtxt
, nchars
) )
1737 IOEXCEPTION( TEXTFAIL
, FORMAT_TEXT_MISMATCH
);
1738 actual_index
+= nchars
;
1741 void (*ftextptr
) ( char*, char* );
1744 formatexit_t
scanformcont( char* fcs
, int len
,
1745 char** fcsptr
, int* lenptr
)
1748 fcsstate_t state
= FormatText
;
1762 ftextptr( begtxt
, fcs
-1 );
1763 state
= FirstPercent
;
1767 after_first_percent
: ;
1784 repetition
= curr
- '0';
1790 test_for_control_codes
: ;
1795 convcode
= strchr( CONVERSIONCODES
, curr
) - CONVERSIONCODES
;
1801 fractiondef
= False
;
1802 /* fractionwidth = 0; default depends on mode ! */
1803 exponentdef
= False
;
1812 editcode
= strchr( EDITCODES
, curr
) - EDITCODES
;
1814 clausewidth
= editcode
== Tabulation
? 0 : 1;
1821 iocode
= strchr( IOCODES
, curr
) - IOCODES
;
1826 unsigned long times
= repetition
;
1831 if( scanformcont( fcs
, len
, &cntfcs
, &cntlen
) != EndAtParen
)
1832 IOEXCEPTION( TEXTFAIL
, UNMATCHED_OPENING_PAREN
);
1840 IOEXCEPTION( TEXTFAIL
, BAD_FORMAT_SPEC_CHAR
);
1846 if( repetition
> (ULONG_MAX
- dig
)/10 )
1847 IOEXCEPTION( TEXTFAIL
, REPFAC_OVERFLOW
);
1848 repetition
= repetition
*10 + dig
;
1851 goto test_for_control_codes
;
1856 state
= ClauseWidth
;
1857 clausewidth
= curr
- '0';
1863 IOEXCEPTION( TEXTFAIL
, DUPLICATE_QUALIFIER
);
1870 IOEXCEPTION( TEXTFAIL
, DUPLICATE_QUALIFIER
);
1877 IOEXCEPTION( TEXTFAIL
, DUPLICATE_QUALIFIER
);
1879 state
= CatchPadding
;
1883 test_for_variable_width
: ;
1890 goto test_for_fraction_width
;
1896 if( clausewidth
> (ULONG_MAX
- dig
)/10 )
1897 IOEXCEPTION( TEXTFAIL
, CLAUSE_WIDTH_OVERFLOW
);
1898 clausewidth
= clausewidth
*10 + dig
;
1903 test_for_fraction_width
: ;
1907 if( convcode
!= DefaultConv
&& convcode
!= ScientConv
)
1908 IOEXCEPTION( TEXTFAIL
, NO_FRACTION
);
1913 goto test_for_exponent_width
;
1918 state
= FractWidthCont
;
1919 fractionwidth
= curr
- '0';
1923 IOEXCEPTION( TEXTFAIL
, NO_FRACTION_WIDTH
);
1925 case FractWidthCont
:
1929 if( fractionwidth
> (ULONG_MAX
- dig
)/10 )
1930 IOEXCEPTION( TEXTFAIL
, FRACTION_WIDTH_OVERFLOW
);
1931 fractionwidth
= fractionwidth
*10 + dig
;
1935 test_for_exponent_width
: ;
1938 if( convcode
!= ScientConv
)
1939 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT
);
1944 goto test_for_final_percent
;
1949 state
= ExpoWidthCont
;
1950 exponentwidth
= curr
- '0';
1954 IOEXCEPTION( TEXTFAIL
, NO_EXPONENT_WIDTH
);
1960 if( exponentwidth
> (ULONG_MAX
- dig
)/10 )
1961 IOEXCEPTION( TEXTFAIL
, EXPONENT_WIDTH_OVERFLOW
);
1962 exponentwidth
= exponentwidth
*10 + dig
;
1967 test_for_final_percent
: ;
1971 state
= LastPercent
;
1976 actionptr
[action
]();
1989 state
= ClauseWidth
;
1990 clausewidth
= curr
- '0';
1993 goto test_for_variable_width
;
1996 actionptr
[action
]();
2003 goto after_first_percent
;
2006 IOEXCEPTION( TEXTFAIL
, INTERNAL_ERROR
);
2012 ftextptr( begtxt
, fcs
);
2019 IOEXCEPTION( TEXTFAIL
, BAD_FORMAT_SPEC_CHAR
);
2021 IOEXCEPTION( TEXTFAIL
, NO_PAD_CHAR
);
2023 actionptr
[action
]();
2033 __read_format (char* fmtptr
,
2035 __tmp_IO_list
* ioptr
,
2043 iostrptr
= (char*)inpptr
;
2046 /* initialisation */
2051 actionptr
= readactions
;
2054 if( (res
= scanformcont( fmtptr
, fmtlen
, &fmtptr
, &fmtlen
)) == EndAtParen
)
2055 IOEXCEPTION( TEXTFAIL
, UNMATCHED_CLOSING_PAREN
);
2057 if( iolist_index
!= iolen
)
2058 IOEXCEPTION( TEXTFAIL
, EXCESS_IOLIST_ELEMENTS
);
2064 __readtext_f( Text_Mode
* the_text_loc
,
2065 signed long the_index
,
2068 __tmp_IO_list
* ioptr
,
2075 if( (info
= setjmp( __io_exception
)) )
2076 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2078 textptr
= the_text_loc
;
2079 textrecptr
= textptr
->text_record
;
2080 actual_index
= textptr
->actual_index
;
2081 textindex
= the_index
;
2083 __read_format ( fmtptr
, fmtlen
, ioptr
, iolen
,
2084 (char*)textrecptr
+ 2, textptr
->text_record
->len
);
2085 textptr
->actual_index
= actual_index
;
2089 __readtext_s( void* string_ptr
,
2093 __tmp_IO_list
* ioptr
,
2100 if( (info
= setjmp( __io_exception
)) )
2101 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2106 __read_format ( fmtptr
, fmtlen
, ioptr
, iolen
, string_ptr
, string_len
);
2111 __write_format (char* fmtptr
,
2113 __tmp_IO_list
* ioptr
,
2121 /* initialisation */
2122 maximum_index
= actual_index
;
2125 actionptr
= writeactions
;
2129 iostrptr
= (char *)outptr
+ 2;
2132 if( (res
= scanformcont( fmtptr
, fmtlen
, &fmtptr
, &fmtlen
)) == EndAtParen
)
2133 IOEXCEPTION( TEXTFAIL
, UNMATCHED_CLOSING_PAREN
);
2135 if( iolist_index
!= iolen
)
2136 IOEXCEPTION( TEXTFAIL
, EXCESS_IOLIST_ELEMENTS
);
2138 /* set length of output string */
2140 printf( "maximum index = %d\n", maximum_index
);
2148 __writetext_f( Text_Mode
* the_text_loc
,
2149 signed long the_index
,
2152 __tmp_IO_list
* ioptr
,
2159 if( (info
= setjmp( __io_exception
)) )
2160 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2162 textptr
= the_text_loc
;
2163 textrecptr
= the_text_loc
->text_record
;
2164 textindex
= the_index
;
2168 actual_index
= textptr
->actual_index
;
2169 __write_format ( fmtptr
, fmtlen
, ioptr
, iolen
,
2170 textrecptr
, textptr
->access_sub
->reclength
- 2 );
2171 textptr
->actual_index
= actual_index
;
2175 __writetext_s( void* string_ptr
,
2179 __tmp_IO_list
* ioptr
,
2186 if( (info
= setjmp( __io_exception
)) )
2187 CHILLEXCEPTION( file
, line
, info
>>16, info
& 0xffff );
2192 __write_format ( fmtptr
, fmtlen
, ioptr
, iolen
, string_ptr
, string_len
);