10 #include <sys/types.h>
13 #define OUTBUFSIZE 512
16 PRIVATE
int forceupper
= FALSE
;
17 PRIVATE
int someupper
= FALSE
;
18 PRIVATE
int stringcount
= 0;
19 PRIVATE
char *string_ptr
= NULL
; /* stringptr ambiguous at 8th char */
20 PRIVATE
char *stringstart
= NULL
;
22 PRIVATE
char outbuf
[OUTBUFSIZE
];
23 PRIVATE
FILE *cmdfile
= stdin
;
24 PRIVATE
FILE *outfile
= stdout
;
25 PRIVATE
FILE *logfile
;
28 _PROTOTYPE( int _doprnt
, (const char *format
, va_list ap
, FILE *stream
));
30 PUBLIC
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 PUBLIC
int Printf(const char *format
, ...)
82 tmp_stream
._flags
= _IOWRITE
+ _IONBF
+ _IOWRITING
;
83 tmp_stream
._buf
= (unsigned char *) outbuf
;
84 tmp_stream
._ptr
= (unsigned char *) outbuf
;
85 tmp_stream
._count
= 512;
87 retval
= _doprnt(format
, ap
, &tmp_stream
);
88 putc('\0',&tmp_stream
);
100 PUBLIC
void logging( c
, name
)
106 if ( c
== 'q' && logfile
!= NULL
) {
111 if ((t
= strchr(name
,'\n')) != NULL
) *t
= '\0';
112 if ((t
= strchr(name
,' ' )) != NULL
) *t
= '\0';
113 if ( logfile
!= NULL
) fclose(logfile
);
115 if ( strlen(name
) > 0 ) {
116 logfile
= fopen(name
,"w");
118 if (logfile
== NULL
) {
119 Printf("Cannot open %s for output\n",name
);
123 /* Close standard output file for L */
132 if ( logfile
!= NULL
) fclose(logfile
);
139 /* Output system error string */
140 PUBLIC
void do_error(m
)
145 outstr(strerror(errno
));
149 PUBLIC
void closestring()
151 /* close string device */
154 stringstart
= string_ptr
= NULL
;
157 PUBLIC
int mytolower(ch
)
160 /* convert char to lower case */
162 if (ch
>= 'A' && ch
<= 'Z')
168 PUBLIC
void openstring(string
)
171 /* open string device */
174 stringstart
= string_ptr
= string
;
177 PUBLIC
void outbyte(byte
)
180 /* print char to currently open output devices */
182 if (forceupper
&& byte
>= 'a' && byte
<= 'z')
184 if (string_ptr
!= NULL
)
186 if ((*string_ptr
++ = byte
) == '\t')
187 stringcount
= 8 * (stringcount
/ 8 + 1);
193 if ( paging
&& byte
== '\n' ) {
195 if ( lineno
>= PAGESIZE
) {
196 if ( cmdfile
== stdin
) {
197 printf("\nMore...any key to continue");
198 fgets( outbuf
, OUTBUFSIZE
-1, cmdfile
);
204 if ( outfile
!= NULL
)
207 if ( logfile
!= NULL
&& byte
!= '\r' )
213 PUBLIC
void outcomma()
220 PRIVATE
char hexdigits
[] = "0123456789ABCDEF";
221 PUBLIC
void outh4(num
)
224 /* print 4 bits hex */
226 outbyte(hexdigits
[num
% 16]);
229 PUBLIC
void outh8(num
)
232 /* print 8 bits hex */
238 PUBLIC
void outh16(num
)
241 /* print 16 bits hex */
247 PUBLIC
void outh32(num
)
250 /* print 32 bits hex */
252 outh16((u16_t
) (num
>> 16));
256 PUBLIC
void outspace()
263 PUBLIC
void outstr(s
)
279 PUBLIC
void outustr(s
)
282 /* print string, perhaps converting case to upper */
284 forceupper
= someupper
;
291 PUBLIC
int stringpos()
293 /* return current offset of string device */
295 return string_ptr
- stringstart
;
298 PUBLIC
int stringtab()
300 /* return current "tab" spot of string device */