Annotation of MiNT/src/console.c, revision 1.1

1.1     ! root        1: /*
        !             2: 
        !             3: Copyright 1990,1991 Eric R. Smith. All rights reserved.
        !             4: 
        !             5: */
        !             6: 
        !             7: 
        !             8: 
        !             9: /* MiNT routines for doing console I/O */
        !            10: 
        !            11: 
        !            12: 
        !            13: #include "mint.h"
        !            14: 
        !            15: 
        !            16: 
        !            17: /*
        !            18: 
        !            19:  * These routines are what Cconout, Cauxout, etc. ultimately call.
        !            20: 
        !            21:  * They take an integer argument which is the user's file handle,
        !            22: 
        !            23:  * and do the translation to a file ptr (and return an appropriate error
        !            24: 
        !            25:  * message if necessary.
        !            26: 
        !            27:  * "mode" may be RAW, COOKED, ECHO, or COOKED|ECHO.
        !            28: 
        !            29:  * note that the user may call them directly via Finstat(), Foutstat(),
        !            30: 
        !            31:  * Fgetchar(), and Fputchar()
        !            32: 
        !            33:  */
        !            34: 
        !            35: 
        !            36: 
        !            37: long
        !            38: 
        !            39: file_instat(h)
        !            40: 
        !            41:        int h;
        !            42: 
        !            43: {
        !            44: 
        !            45:        FILEPTR *f;
        !            46: 
        !            47:        long r;
        !            48: 
        !            49:        PROC *proc;
        !            50: 
        !            51:        int fh = h;
        !            52: 
        !            53: 
        !            54: 
        !            55: #if O_GLOBAL
        !            56: 
        !            57:        if (fh >= 100) {
        !            58: 
        !            59:                proc = rootproc;
        !            60: 
        !            61:                fh -= 100;
        !            62: 
        !            63:        } else
        !            64: 
        !            65: #endif
        !            66: 
        !            67:                proc = curproc;
        !            68: 
        !            69: 
        !            70: 
        !            71:        if (fh < MIN_HANDLE || fh >=MAX_OPEN || !(f = proc->handle[fh])) {
        !            72: 
        !            73:                DEBUG("Finstat: bad handle %d", h);
        !            74: 
        !            75:                return EIHNDL;
        !            76: 
        !            77:        }
        !            78: 
        !            79:        r = 1;          /* default is to assume input waiting (e.g. TOS files)*/
        !            80: 
        !            81:        (void)(*f->dev->ioctl)(f, FIONREAD, &r);
        !            82: 
        !            83: 
        !            84: 
        !            85:        return r;
        !            86: 
        !            87: }
        !            88: 
        !            89: 
        !            90: 
        !            91: long
        !            92: 
        !            93: file_outstat(h)
        !            94: 
        !            95:        int h;
        !            96: 
        !            97: {
        !            98: 
        !            99:        FILEPTR *f;
        !           100: 
        !           101:        long r;
        !           102: 
        !           103:        int fh = h;
        !           104: 
        !           105:        PROC *proc;
        !           106: 
        !           107: #if O_GLOBAL
        !           108: 
        !           109:        if (fh >= 100) {
        !           110: 
        !           111:                fh -= 100;
        !           112: 
        !           113:                proc = rootproc;
        !           114: 
        !           115:        } else
        !           116: 
        !           117: #endif
        !           118: 
        !           119:                proc = curproc;
        !           120: 
        !           121: 
        !           122: 
        !           123:        if (fh < MIN_HANDLE || fh >=MAX_OPEN || !(f = proc->handle[fh])) {
        !           124: 
        !           125:                DEBUG("Foutstat: bad handle %d", h);
        !           126: 
        !           127:                return EIHNDL;
        !           128: 
        !           129:        }
        !           130: 
        !           131:        r = 1;          /* default is to assume output OK (e.g. TOS files) */
        !           132: 
        !           133:        (void)(*f->dev->ioctl)(f, FIONWRITE, &r);
        !           134: 
        !           135:        return r;
        !           136: 
        !           137: }
        !           138: 
        !           139: 
        !           140: 
        !           141: long
        !           142: 
        !           143: file_getchar(h, mode)
        !           144: 
        !           145:        int h, mode;
        !           146: 
        !           147: {
        !           148: 
        !           149:        FILEPTR *f;
        !           150: 
        !           151:        char c;
        !           152: 
        !           153:        long r;
        !           154: 
        !           155:        int fh = h;
        !           156: 
        !           157:        PROC *proc;
        !           158: 
        !           159: 
        !           160: 
        !           161: #if O_GLOBAL
        !           162: 
        !           163:        if (fh >= 100) {
        !           164: 
        !           165:                fh -= 100;
        !           166: 
        !           167:                proc = rootproc;
        !           168: 
        !           169:        } else
        !           170: 
        !           171: #endif
        !           172: 
        !           173:                proc = curproc;
        !           174: 
        !           175:        if (fh < MIN_HANDLE || fh >=MAX_OPEN || !(f = proc->handle[fh])) {
        !           176: 
        !           177:                DEBUG("Fgetchar: bad handle %d", h);
        !           178: 
        !           179:                return EIHNDL;
        !           180: 
        !           181:        }
        !           182: 
        !           183:        if (is_terminal(f)) {
        !           184: 
        !           185:                return tty_getchar(f, mode);
        !           186: 
        !           187:        }
        !           188: 
        !           189:        r = (*f->dev->read)(f, &c, 1L);
        !           190: 
        !           191:        if (r != 1)
        !           192: 
        !           193:                return MiNTEOF;
        !           194: 
        !           195:        else
        !           196: 
        !           197:                return ((long)c) & 0xff;
        !           198: 
        !           199: }
        !           200: 
        !           201: 
        !           202: 
        !           203: long
        !           204: 
        !           205: file_putchar(h, c, mode)
        !           206: 
        !           207:        int h;
        !           208: 
        !           209:        long c;
        !           210: 
        !           211:        int mode;
        !           212: 
        !           213: {
        !           214: 
        !           215:        FILEPTR *f;
        !           216: 
        !           217:        char ch;
        !           218: 
        !           219:        int fh = h;
        !           220: 
        !           221:        PROC *proc;
        !           222: 
        !           223: 
        !           224: 
        !           225: #if O_GLOBAL
        !           226: 
        !           227:        if (fh >= 100) {
        !           228: 
        !           229:                fh -= 100;
        !           230: 
        !           231:                proc = rootproc;
        !           232: 
        !           233:        } else
        !           234: 
        !           235: #endif
        !           236: 
        !           237:                proc = curproc;
        !           238: 
        !           239: 
        !           240: 
        !           241:        if (fh < MIN_HANDLE || fh >=MAX_OPEN || !(f = proc->handle[fh])) {
        !           242: 
        !           243:                DEBUG("Fputchar: bad handle %d", h);
        !           244: 
        !           245:                return EIHNDL;
        !           246: 
        !           247:        }
        !           248: 
        !           249:        if (is_terminal(f)) {
        !           250: 
        !           251:                return tty_putchar(f, c & 0x7fffffffL, mode);
        !           252: 
        !           253:        }
        !           254: 
        !           255:        ch = c & 0x00ff;
        !           256: 
        !           257:        return (*f->dev->write)(f, &ch, 1L);
        !           258: 
        !           259: }
        !           260: 
        !           261: 
        !           262: 
        !           263: /*
        !           264: 
        !           265:  * OK, here are the GEMDOS console I/O routines
        !           266: 
        !           267:  */
        !           268: 
        !           269: 
        !           270: 
        !           271: long
        !           272: 
        !           273: c_conin()
        !           274: 
        !           275: {
        !           276: 
        !           277:        return file_getchar(0, COOKED|ECHO);
        !           278: 
        !           279: }
        !           280: 
        !           281: 
        !           282: 
        !           283: long
        !           284: 
        !           285: c_conout(c)
        !           286: 
        !           287:        int c;
        !           288: 
        !           289: {
        !           290: 
        !           291:        return file_putchar(1, (long)c, COOKED);
        !           292: 
        !           293: }
        !           294: 
        !           295: 
        !           296: 
        !           297: long
        !           298: 
        !           299: c_auxin()
        !           300: 
        !           301: {
        !           302: 
        !           303:        return file_getchar(2, RAW);
        !           304: 
        !           305: }
        !           306: 
        !           307: 
        !           308: 
        !           309: long
        !           310: 
        !           311: c_auxout(c)
        !           312: 
        !           313:        int c;
        !           314: 
        !           315: {
        !           316: 
        !           317:        return file_putchar(2, (long)c, RAW);
        !           318: 
        !           319: }
        !           320: 
        !           321: 
        !           322: 
        !           323: long
        !           324: 
        !           325: c_prnout(c)
        !           326: 
        !           327:        int c;
        !           328: 
        !           329: {
        !           330: 
        !           331:        return file_putchar(3, (long)c, RAW);
        !           332: 
        !           333: }
        !           334: 
        !           335: 
        !           336: 
        !           337: long
        !           338: 
        !           339: c_rawio(c)
        !           340: 
        !           341:        int c;
        !           342: 
        !           343: {
        !           344: 
        !           345:        long r;
        !           346: 
        !           347: 
        !           348: 
        !           349:        if (c == 0x00ff) {
        !           350: 
        !           351:                if (!file_instat(0))
        !           352: 
        !           353:                        return 0;
        !           354: 
        !           355:                r = file_getchar(0, RAW);
        !           356: 
        !           357:                if (r <= 0)
        !           358: 
        !           359:                        return 0;
        !           360: 
        !           361:                return r;
        !           362: 
        !           363:        }
        !           364: 
        !           365:        else
        !           366: 
        !           367:                return file_putchar(1, (long)c, RAW);
        !           368: 
        !           369: }
        !           370: 
        !           371: 
        !           372: 
        !           373: long
        !           374: 
        !           375: c_rawcin()
        !           376: 
        !           377: {
        !           378: 
        !           379:        return file_getchar(0, RAW);
        !           380: 
        !           381: }
        !           382: 
        !           383: 
        !           384: 
        !           385: long
        !           386: 
        !           387: c_necin()
        !           388: 
        !           389: {
        !           390: 
        !           391:        return file_getchar(0,COOKED|NOECHO);
        !           392: 
        !           393: }
        !           394: 
        !           395: 
        !           396: 
        !           397: long
        !           398: 
        !           399: c_conws(str)
        !           400: 
        !           401:        const char *str;
        !           402: 
        !           403: {
        !           404: 
        !           405:        const char *p = str;
        !           406: 
        !           407:        long cnt = 0;
        !           408: 
        !           409: 
        !           410: 
        !           411:        while (*p++) cnt++;
        !           412: 
        !           413:        return f_write(1, cnt, str);
        !           414: 
        !           415: }
        !           416: 
        !           417: 
        !           418: 
        !           419: long
        !           420: 
        !           421: c_conrs(buf)
        !           422: 
        !           423:        char *buf;
        !           424: 
        !           425: {
        !           426: 
        !           427:        long size, r;
        !           428: 
        !           429:        char *s;
        !           430: 
        !           431: 
        !           432: 
        !           433:        size = ((long)*buf) & 0xff;
        !           434: 
        !           435:        r = f_read(0, size, buf+2);
        !           436: 
        !           437:        if (r < 0) {
        !           438: 
        !           439:                buf[1] = 0;
        !           440: 
        !           441:                return r;
        !           442: 
        !           443:        }
        !           444: 
        !           445: /* if reading from a file, stop at first CR or LF encountered */
        !           446: 
        !           447:        s = buf+2;
        !           448: 
        !           449:        size = 0;
        !           450: 
        !           451:        while(r-- > 0) {
        !           452: 
        !           453:                if (*s == '\r' || *s == '\n')
        !           454: 
        !           455:                        break;
        !           456: 
        !           457:                s++; size++;
        !           458: 
        !           459:        }
        !           460: 
        !           461:        buf[1] = (char)size;
        !           462: 
        !           463:        return 0;
        !           464: 
        !           465: }
        !           466: 
        !           467: 
        !           468: 
        !           469: long
        !           470: 
        !           471: c_conis()
        !           472: 
        !           473: {
        !           474: 
        !           475:        return -(!!file_instat(0));
        !           476: 
        !           477: }
        !           478: 
        !           479: 
        !           480: 
        !           481: long
        !           482: 
        !           483: c_conos()
        !           484: 
        !           485: {
        !           486: 
        !           487:        return -(!!file_outstat(1));
        !           488: 
        !           489: }
        !           490: 
        !           491: 
        !           492: 
        !           493: long
        !           494: 
        !           495: c_prnos()
        !           496: 
        !           497: {
        !           498: 
        !           499:        return -(!!file_outstat(3));
        !           500: 
        !           501: }
        !           502: 
        !           503: 
        !           504: 
        !           505: long
        !           506: 
        !           507: c_auxis()
        !           508: 
        !           509: {
        !           510: 
        !           511:        return -(!!file_instat(2));
        !           512: 
        !           513: }
        !           514: 
        !           515: 
        !           516: 
        !           517: long
        !           518: 
        !           519: c_auxos()
        !           520: 
        !           521: {
        !           522: 
        !           523:        return -(!!file_outstat(2));
        !           524: 
        !           525: }
        !           526: 

unix.superglobalmegacorp.com

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