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