Changeset 1199 for trunk/src/kash/output.c
- Timestamp:
- Oct 7, 2007, 12:04:05 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/output.c
r1198 r1199 71 71 #include "error.h" 72 72 73 74 #define OUTBUFSIZ BUFSIZ 73 #include "shinstance.h" 74 75 //#define OUTBUFSIZ BUFSIZ 75 76 #define BLOCK_OUT -2 /* output to a fixed block of memory */ 76 #define MEM_OUT -3 /* output to dynamically allocated memory */77 //#define MEM_OUT -3 /* output to dynamically allocated memory */ 77 78 #define OUTPUT_ERR 01 /* error occurred on output */ 78 79 79 80 80 struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};81 struct output errout = {NULL, 0, NULL, 100, 2, 0};82 struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};83 struct output *out1 = &output;84 struct output *out2 = &errout;81 //struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0}; 82 //struct output errout = {NULL, 0, NULL, 100, 2, 0}; 83 //struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0}; 84 //struct output *out1 = &output; 85 //struct output *out2 = &errout; 85 86 86 87 … … 92 93 93 94 RESET { 94 out1 = &output;95 out2 = &errout;96 if ( memout.buf != NULL) {97 ckfree( memout.buf);98 memout.buf = NULL;95 psh->out1 = &psh->output; 96 psh->out2 = &psh->errout; 97 if (psh->memout.buf != NULL) { 98 ckfree(psh->memout.buf); 99 psh->memout.buf = NULL; 99 100 } 100 101 } … … 120 121 121 122 void 122 out1str( const char *p)123 { 124 outstr(p, out1);125 } 126 127 128 void 129 out2str( const char *p)130 { 131 outstr(p, out2);123 out1str(shinstance *psh, const char *p) 124 { 125 outstr(p, psh->out1); 126 } 127 128 129 void 130 out2str(shinstance *psh, const char *p) 131 { 132 outstr(p, psh->out2); 132 133 } 133 134 … … 138 139 while (*p) 139 140 outc(*p++, file); 140 if (file == out2)141 if (file == file->psh->out2) 141 142 flushout(file); 142 143 } … … 150 151 { 151 152 int offset; 153 shinstance *psh = dest->psh; 152 154 153 155 if (dest->fd == BLOCK_OUT) { … … 177 179 178 180 void 179 output_flushall( void)180 { 181 flushout(& output);182 flushout(& errout);181 output_flushall(shinstance *psh) 182 { 183 flushout(&psh->output); 184 flushout(&psh->errout); 183 185 } 184 186 … … 190 192 if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0) 191 193 return; 192 if (xwrite( psh, dest->fd, dest->buf, dest->nextc - dest->buf) < 0)194 if (xwrite(dest->psh, dest->fd, dest->buf, dest->nextc - dest->buf) < 0) 193 195 dest->flags |= OUTPUT_ERR; 194 196 dest->nextc = dest->buf; … … 198 200 199 201 void 200 freestdout( void)202 freestdout(shinstance *psh) 201 203 { 202 204 INTOFF; 203 if ( output.buf) {204 ckfree( output.buf);205 output.buf = NULL;206 output.nleft = 0;205 if (psh->output.buf) { 206 ckfree(psh->output.buf); 207 psh->output.buf = NULL; 208 psh->output.nleft = 0; 207 209 } 208 210 INTON; … … 222 224 223 225 void 224 out1fmt( const char *fmt, ...)226 out1fmt(shinstance *psh, const char *fmt, ...) 225 227 { 226 228 va_list ap; 227 229 228 230 va_start(ap, fmt); 229 doformat( out1, fmt, ap);231 doformat(psh->out1, fmt, ap); 230 232 va_end(ap); 231 233 } 232 234 233 235 void 234 dprintf( const char *fmt, ...)236 dprintf(shinstance *psh, const char *fmt, ...) 235 237 { 236 238 va_list ap; 237 239 238 240 va_start(ap, fmt); 239 doformat( out2, fmt, ap);241 doformat(psh->out2, fmt, ap); 240 242 va_end(ap); 241 flushout( out2);243 flushout(psh->out2); 242 244 } 243 245 … … 250 252 va_start(ap, fmt); 251 253 strout.nextc = outbuf; 252 strout.nleft = length;254 strout.nleft = (int)length; 253 255 strout.fd = BLOCK_OUT; 254 256 strout.flags = 0; … … 414 416 num /= base; 415 417 } 416 len = ( temp + TEMPSIZE - 1) - p;418 len = (int)((temp + TEMPSIZE - 1) - p); 417 419 if (prec < 0) 418 420 prec = 1; … … 445 447 pad = 0; 446 448 if (width) { 447 len = strlen(p);449 len = (int)strlen(p); 448 450 if (prec >= 0 && len > prec) 449 451 len = prec; … … 480 482 481 483 int 482 xwrite(shinstance *psh, int fd, char *buf, int nbytes)484 xwrite(shinstance *psh, int fd, char *buf, size_t nbytes) 483 485 { 484 486 int ntry; 485 inti;486 int n;487 long i; 488 size_t n; 487 489 488 490 n = nbytes; … … 492 494 if (i > 0) { 493 495 if ((n -= i) <= 0) 494 return nbytes;496 return (int)nbytes; 495 497 buf += i; 496 498 ntry = 0; 497 499 } else if (i == 0) { 498 500 if (++ntry > 10) 499 return nbytes - n;501 return (int)(nbytes - n); 500 502 } else if (errno != EINTR) { 501 503 return -1; … … 505 507 506 508 509 #ifdef not_used 507 510 /* 508 511 * Version of ioctl that retries after a signal is caught. … … 518 521 return i; 519 522 } 523 #endif /* not_used */
Note:
See TracChangeset
for help on using the changeset viewer.