Annotation of coherent/g/usr/lib/ncurses/lib_trace.c, revision 1.1

1.1     ! root        1: /*********************************************************************
        !             2: *                         COPYRIGHT NOTICE                           *
        !             3: **********************************************************************
        !             4: *        This software is copyright (C) 1982 by Pavel Curtis         *
        !             5: *                                                                    *
        !             6: *        Permission is granted to reproduce and distribute           *
        !             7: *        this file by any means so long as no fee is charged         *
        !             8: *        above a nominal handling fee and so long as this            *
        !             9: *        notice is always included in the copies.                    *
        !            10: *                                                                    *
        !            11: *        Other rights are reserved except as explicitly granted      *
        !            12: *        by written permission of the author.                        *
        !            13: *                Pavel Curtis                                        *
        !            14: *                Computer Science Dept.                              *
        !            15: *                405 Upson Hall                                      *
        !            16: *                Cornell University                                  *
        !            17: *                Ithaca, NY 14853                                    *
        !            18: *                                                                    *
        !            19: *                Ph- (607) 256-4934                                  *
        !            20: *                                                                    *
        !            21: *                Pavel.Cornell@Udel-Relay   (ARPAnet)                *
        !            22: *                decvax!cornell!pavel       (UUCPnet)                *
        !            23: *********************************************************************/
        !            24: 
        !            25: /*
        !            26:  *     lib_trace.c - Tracing/Debugging routines
        !            27:  *
        !            28:  *  $Log:      lib_trace.c,v $
        !            29:  * Revision 1.8  93/04/12  14:14:36  bin
        !            30:  * Udo: third color update
        !            31:  * 
        !            32:  * Revision 1.2  92/04/13  14:38:45  bin
        !            33:  * update by vlad
        !            34:  * 
        !            35:  * Revision 2.2  91/04/20  22:00:18  munk
        !            36:  * Usage of register variables
        !            37:  * Made the large arrays static
        !            38:  *
        !            39:  * Revision 2.1  82/10/25  14:49:35  pavel
        !            40:  * Added Copyright Notice
        !            41:  * 
        !            42:  * Revision 2.0  82/10/24  15:18:09  pavel
        !            43:  * Beta-one Test Release
        !            44:  * 
        !            45:  * Revision 1.3  82/08/23  22:30:57  pavel
        !            46:  * The REAL Alpha-one Release Version
        !            47:  * 
        !            48:  * Revision 1.2  82/08/19  19:11:41  pavel
        !            49:  * Alpha Test Release One
        !            50:  * 
        !            51:  * Revision 1.1  82/08/15  17:59:45  pavel
        !            52:  * Initial revision
        !            53:  * 
        !            54:  *
        !            55:  */
        !            56: 
        !            57: #ifdef RCSHDR
        !            58: static char RCSid[] =
        !            59:     "$Header: /src386/usr/lib/ncurses/RCS/lib_trace.c,v 1.8 93/04/12 14:14:36 bin Exp Locker: bin $";
        !            60: #endif
        !            61: 
        !            62: #include "term.h"
        !            63: #include "curses.h"
        !            64: #include "curses.priv.h"
        !            65: 
        !            66: static int     tracefd;
        !            67: 
        !            68: 
        !            69: _init_trace()
        !            70: {
        !            71:        static int      been_here = 0;
        !            72:        extern int      errno;
        !            73:        extern char     *sys_errlist[];
        !            74: 
        !            75:        if (! been_here)
        !            76:        {
        !            77:            _tracing = been_here = 1;
        !            78: 
        !            79:            if ((tracefd = creat("trace", 0644)) < 0)
        !            80:            {
        !            81:                write(2, "curses: Can't open 'trace' file: ", 33);
        !            82:                write(2, sys_errlist[errno], strlen(sys_errlist[errno]));
        !            83:                write(2, "\n", 1);
        !            84:                exit(1);
        !            85:            }
        !            86: 
        !            87:            _tracef("_init_trace() called");
        !            88:        }
        !            89: }
        !            90: 
        !            91: 
        !            92: traceon()
        !            93: {
        !            94:        _tracef("traceon() called");
        !            95: 
        !            96:        _tracing = 1;
        !            97: }
        !            98: 
        !            99: 
        !           100: traceoff()
        !           101: {
        !           102:        _tracef("traceoff() called");
        !           103: 
        !           104:        _tracing = 0;
        !           105: }
        !           106: 
        !           107: 
        !           108: _tracef(fmt, args)
        !           109: register char  *fmt;
        !           110: int            args;
        !           111: {
        !           112:        char            *strcpy();
        !           113:        int             *parm = &args;
        !           114:        static char     buffer[256];
        !           115:        char            *bufp = buffer;
        !           116: 
        !           117:        while (*fmt)
        !           118:        {
        !           119:            if (*fmt == '%')
        !           120:            {
        !           121:                fmt++;
        !           122:                switch (*fmt)
        !           123:                {
        !           124:                    case 'd':
        !           125:                        addnum(&bufp, *(parm++), 10);
        !           126:                        break;
        !           127: 
        !           128:                    case 'o':
        !           129:                        addnum(&bufp, *(parm++), 8);
        !           130:                        break;
        !           131: 
        !           132:                    case 'c':
        !           133:                        *(bufp++) = *(parm++);
        !           134:                        break;
        !           135: 
        !           136:                    case 's':
        !           137:                        if (*parm)
        !           138:                        {
        !           139:                            *(bufp++) = '"';
        !           140:                            strcpy(bufp, *parm);
        !           141:                            bufp += strlen(*parm);
        !           142:                            *(bufp++) = '"';
        !           143:                        }
        !           144:                        else
        !           145:                        {
        !           146:                            strcpy(bufp, "NULL");
        !           147:                            bufp += 4;
        !           148:                        }
        !           149:                        parm++;
        !           150:                        break;
        !           151:                }
        !           152:            }
        !           153:            else
        !           154:                *(bufp++) = *fmt;
        !           155: 
        !           156:            fmt++;
        !           157:        }
        !           158: 
        !           159:        *(bufp++) = '\n';
        !           160:        *bufp = '\0';
        !           161:        write(tracefd, buffer, strlen(buffer));
        !           162: }
        !           163: 
        !           164: 
        !           165: static addnum(bufp, num, base)
        !           166: char           **bufp;
        !           167: register int   num, base;
        !           168: {
        !           169:        int     a;
        !           170: 
        !           171:        if (num < 0)
        !           172:        {
        !           173:            num = -num;
        !           174:            *((*bufp)++) = '-';
        !           175:        }
        !           176: 
        !           177:        if ((a = num / base) != 0)
        !           178:            addnum(bufp, a, base);
        !           179:        *((*bufp)++) = '0' + (num % base);
        !           180: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.