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

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

unix.superglobalmegacorp.com

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