10 #include <sys/types.h>
13 #define OUTBUFSIZE 512
16 static int forceupper
= FALSE
;
17 static int someupper
= FALSE
;
18 static int stringcount
= 0;
19 static char *string_ptr
= NULL
; /* stringptr ambiguous at 8th char */
20 static char *stringstart
= NULL
;
22 static char outbuf
[OUTBUFSIZE
];
23 static FILE *cmdfile
= stdin
;
24 static FILE *outfile
= stdout
;
28 int _doprnt(const char *format
, va_list ap
, FILE *stream
);
30 char *get_cmd(cbuf
, csize
)
37 if( cmdfile
== stdin
&& outfile
== stdout
)
39 r
= fgets(cbuf
, csize
, cmdfile
);
40 if ( r
== NULL
&& cmdfile
!= stdin
) {
42 return get_cmd(cbuf
, csize
);
45 if ( logfile
!= NULL
) {
46 fprintf( logfile
, "%s", cbuf
);
58 if ((t
= strchr(s
,'\n')) != NULL
) *t
= '\0';
59 if ((t
= strchr(s
,' ')) != NULL
) *t
= '\0';
60 cmdfile
= fopen(s
,"r");
61 if (cmdfile
== NULL
) {
62 Printf("Cannot open %s for input\n",s
);
68 /* Special version of printf
71 * followed by outstr()
73 int Printf(const char *format
, ...)
83 tmp_stream
._flags
= _IOWRITE
+ _IONBF
+ _IOWRITING
;
84 tmp_stream
._buf
= (unsigned char *) outbuf
;
85 tmp_stream
._ptr
= (unsigned char *) outbuf
;
86 tmp_stream
._count
= 512;
88 retval
= _doprnt(format
, ap
, &tmp_stream
);
89 putc('\0',&tmp_stream
);
93 retval
= vsnprintf(outbuf
, OUTBUFSIZE
, format
, ap
);
103 * Set logging options
105 void logging( c
, name
)
111 if ( c
== 'q' && logfile
!= NULL
) {
116 if ((t
= strchr(name
,'\n')) != NULL
) *t
= '\0';
117 if ((t
= strchr(name
,' ' )) != NULL
) *t
= '\0';
118 if ( logfile
!= NULL
) fclose(logfile
);
120 if ( strlen(name
) > 0 ) {
121 logfile
= fopen(name
,"w");
123 if (logfile
== NULL
) {
124 Printf("Cannot open %s for output\n",name
);
128 /* Close standard output file for L */
137 if ( logfile
!= NULL
) fclose(logfile
);
144 /* Output system error string */
150 outstr(strerror(errno
));
156 /* close string device */
159 stringstart
= string_ptr
= NULL
;
165 /* convert char to lower case */
167 if (ch
>= 'A' && ch
<= 'Z')
173 void openstring(string
)
176 /* open string device */
179 stringstart
= string_ptr
= string
;
185 /* print char to currently open output devices */
187 if (forceupper
&& byte
>= 'a' && byte
<= 'z')
189 if (string_ptr
!= NULL
)
191 if ((*string_ptr
++ = byte
) == '\t')
192 stringcount
= 8 * (stringcount
/ 8 + 1);
198 if ( paging
&& byte
== '\n' ) {
200 if ( lineno
>= PAGESIZE
) {
201 if ( cmdfile
== stdin
) {
202 printf("\nMore...any key to continue");
203 fgets( outbuf
, OUTBUFSIZE
-1, cmdfile
);
209 if ( outfile
!= NULL
)
212 if ( logfile
!= NULL
&& byte
!= '\r' )
225 static char hexdigits
[] = "0123456789ABCDEF";
229 /* print 4 bits hex */
231 outbyte(hexdigits
[num
% 16]);
237 /* print 8 bits hex */
246 /* print 16 bits hex */
255 /* print 32 bits hex */
257 outh16((u16_t
) (num
>> 16));
287 /* print string, perhaps converting case to upper */
289 forceupper
= someupper
;
298 /* return current offset of string device */
300 return string_ptr
- stringstart
;
305 /* return current "tab" spot of string device */