Ignore:
Timestamp:
Oct 7, 2007, 12:04:05 AM (18 years ago)
Author:
bird
Message:

moving globals into shinstance...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/output.c

    r1198 r1199  
    7171#include "error.h"
    7272
    73 
    74 #define OUTBUFSIZ BUFSIZ
     73#include "shinstance.h"
     74
     75//#define OUTBUFSIZ BUFSIZ
    7576#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 */
    7778#define OUTPUT_ERR 01           /* error occurred on output */
    7879
    7980
    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;
    8586
    8687
     
    9293
    9394RESET {
    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;
    99100        }
    100101}
     
    120121
    121122void
    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);
     123out1str(shinstance *psh, const char *p)
     124{
     125        outstr(p, psh->out1);
     126}
     127
     128
     129void
     130out2str(shinstance *psh, const char *p)
     131{
     132        outstr(p, psh->out2);
    132133}
    133134
     
    138139        while (*p)
    139140                outc(*p++, file);
    140         if (file == out2)
     141        if (file == file->psh->out2)
    141142                flushout(file);
    142143}
     
    150151{
    151152        int offset;
     153        shinstance *psh = dest->psh;
    152154
    153155        if (dest->fd == BLOCK_OUT) {
     
    177179
    178180void
    179 output_flushall(void)
    180 {
    181         flushout(&output);
    182         flushout(&errout);
     181output_flushall(shinstance *psh)
     182{
     183        flushout(&psh->output);
     184        flushout(&psh->errout);
    183185}
    184186
     
    190192        if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
    191193                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)
    193195                dest->flags |= OUTPUT_ERR;
    194196        dest->nextc = dest->buf;
     
    198200
    199201void
    200 freestdout(void)
     202freestdout(shinstance *psh)
    201203{
    202204        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;
    207209        }
    208210        INTON;
     
    222224
    223225void
    224 out1fmt(const char *fmt, ...)
     226out1fmt(shinstance *psh, const char *fmt, ...)
    225227{
    226228        va_list ap;
    227229
    228230        va_start(ap, fmt);
    229         doformat(out1, fmt, ap);
     231        doformat(psh->out1, fmt, ap);
    230232        va_end(ap);
    231233}
    232234
    233235void
    234 dprintf(const char *fmt, ...)
     236dprintf(shinstance *psh, const char *fmt, ...)
    235237{
    236238        va_list ap;
    237239
    238240        va_start(ap, fmt);
    239         doformat(out2, fmt, ap);
     241        doformat(psh->out2, fmt, ap);
    240242        va_end(ap);
    241         flushout(out2);
     243        flushout(psh->out2);
    242244}
    243245
     
    250252        va_start(ap, fmt);
    251253        strout.nextc = outbuf;
    252         strout.nleft = length;
     254        strout.nleft = (int)length;
    253255        strout.fd = BLOCK_OUT;
    254256        strout.flags = 0;
     
    414416                                num /= base;
    415417                        }
    416                         len = (temp + TEMPSIZE - 1) - p;
     418                        len = (int)((temp + TEMPSIZE - 1) - p);
    417419                        if (prec < 0)
    418420                                prec = 1;
     
    445447                        pad = 0;
    446448                        if (width) {
    447                                 len = strlen(p);
     449                                len = (int)strlen(p);
    448450                                if (prec >= 0 && len > prec)
    449451                                        len = prec;
     
    480482
    481483int
    482 xwrite(shinstance *psh, int fd, char *buf, int nbytes)
     484xwrite(shinstance *psh, int fd, char *buf, size_t nbytes)
    483485{
    484486        int ntry;
    485         int i;
    486         int n;
     487        long i;
     488        size_t n;
    487489
    488490        n = nbytes;
     
    492494                if (i > 0) {
    493495                        if ((n -= i) <= 0)
    494                                 return nbytes;
     496                                return (int)nbytes;
    495497                        buf += i;
    496498                        ntry = 0;
    497499                } else if (i == 0) {
    498500                        if (++ntry > 10)
    499                                 return nbytes - n;
     501                                return (int)(nbytes - n);
    500502                } else if (errno != EINTR) {
    501503                        return -1;
     
    505507
    506508
     509#ifdef not_used
    507510/*
    508511 * Version of ioctl that retries after a signal is caught.
     
    518521        return i;
    519522}
     523#endif /* not_used */
Note: See TracChangeset for help on using the changeset viewer.