home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / __tioctl.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  7.9 KB  |  382 lines

  1. head    1.4;
  2. access;
  3. symbols
  4.     version39-41:1.3;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.4
  10. date    92.08.09.20.39.01;    author amiga;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    92.07.04.19.07.25;    author mwild;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    92.06.08.02.36.00;    author mwild;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    92.05.14.19.55.40;    author mwild;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @tty ioctl functions (termios etc.)
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @add a cast to get rid of a warning
  38. @
  39. text
  40. @/*
  41.  *  This file is part of ixemul.library for the Amiga.
  42.  *  Copyright (C) 1991, 1992  Markus M. Wild
  43.  *
  44.  *  This library is free software; you can redistribute it and/or
  45.  *  modify it under the terms of the GNU Library General Public
  46.  *  License as published by the Free Software Foundation; either
  47.  *  version 2 of the License, or (at your option) any later version.
  48.  *
  49.  *  This library is distributed in the hope that it will be useful,
  50.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  51.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  52.  *  Library General Public License for more details.
  53.  *
  54.  *  You should have received a copy of the GNU Library General Public
  55.  *  License along with this library; if not, write to the Free
  56.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  57.  *
  58.  *  $Id: __tioctl.c,v 1.3 1992/07/04 19:07:25 mwild Exp $
  59.  *
  60.  *  $Log: __tioctl.c,v $
  61.  *  Revision 1.3  1992/07/04  19:07:25  mwild
  62.  *  send DISK_INFO packet with synchronous port, async delivery seems to be
  63.  *  broken with CNC:
  64.  *
  65.  * Revision 1.2  1992/06/08  02:36:00  mwild
  66.  * fix TIOCGWINSZ, row/column was off by one
  67.  *
  68.  * Revision 1.1  1992/05/14  19:55:40  mwild
  69.  * Initial revision
  70.  *
  71.  */
  72.  
  73. #define KERNEL
  74. #include "ixemul.h"
  75. #include <sgtty.h>
  76. #define OB0    B0    
  77. #define OB50    B50    
  78. #define OB75    B75    
  79. #define OB110    B110    
  80. #define OB134    B134    
  81. #define OB150    B150    
  82. #define OB200    B200    
  83. #define OB300    B300    
  84. #define OB600    B600    
  85. #define OB1200    B1200    
  86. #define    OB1800    B1800    
  87. #define OB2400    B2400    
  88. #define OB4800    B4800    
  89. #define OB9600    B9600    
  90. #define OEXTA    EXTA    
  91. #define OEXTB    EXTB    
  92. #undef B0    
  93. #undef B50    
  94. #undef B75    
  95. #undef B110    
  96. #undef B134    
  97. #undef B150    
  98. #undef B200    
  99. #undef B300    
  100. #undef B600    
  101. #undef B1200    
  102. #undef B1800    
  103. #undef B2400    
  104. #undef B4800    
  105. #undef B9600    
  106. #undef EXTA    
  107. #undef EXTB    
  108. #include <sys/termios.h>
  109. #include <ctype.h>
  110. #include <devices/conunit.h>
  111.  
  112. #if __GNUC__ != 2
  113. #define alloca __builtin_alloca
  114. #endif
  115.  
  116. /* IOCTLs on "interactive" files */
  117.  
  118. int
  119. __tioctl(struct file *f, unsigned int cmd, unsigned int inout, 
  120.      unsigned int arglen, unsigned int arg)
  121. {
  122.   int omask, result, err;
  123.  
  124.   omask = syscall (SYS_sigsetmask, ~0);
  125.   __get_file (f);
  126.   result = -1;
  127.  
  128.   if (/*!IsInteractive(CTOBPTR(f->f_fh))*/ ! f->f_fh->fh_Port)
  129.     {
  130.       err = ENOTTY;
  131.       goto ret;
  132.     }
  133.  
  134.   switch (cmd)
  135.     {
  136.     case TIOCGETA:
  137.       {
  138.         struct termios *t = (struct termios *)arg;
  139.         unsigned char *cp;
  140.         t->c_iflag = IGNBRK|IGNPAR|ICRNL|IXON;
  141.         t->c_oflag = (f->f_flags & FTTYRAW) ? 0 : OPOST|ONLCR;
  142.         t->c_cflag = CS8|CLOCAL;
  143.         t->c_ispeed=
  144.         t->c_ospeed= B38400;
  145.     /* Conman does ECHOCTL, Commo doesn't.. I use Conman:-)) */
  146.         t->c_lflag = ECHOCTL|((f->f_flags & FTTYRAW)?0:ICANON|ECHO);
  147.     /* t->c_line  = 0; */
  148.     cp = t->c_cc;
  149.     cp[VSTART] = 'q' & 31;
  150.     cp[VSTOP] = 's' & 31;
  151.     cp[VSUSP] = 0; /* sneef.. would that be nice... */
  152.     cp[VDSUSP] = 0;
  153.     cp[VREPRINT] = 0;
  154.     cp[VDISCARD] = 'x' & 31;
  155.     cp[VWERASE] = 0;
  156.     cp[VLNEXT] = 0;
  157.     cp[VSTATUS] = 0;
  158.     cp[VINTR] = 3;
  159.     cp[VQUIT] = 0;
  160.     cp[VERASE] = 8;
  161.     cp[VKILL] = 'x' & 31;
  162.     cp[VEOF] = '\\' & 31;
  163.     cp[VEOL] = 10;
  164.     cp[VEOL2] = 0;
  165.     result = 0;
  166.     goto ret;
  167.       }
  168.  
  169.     case TIOCSETA:
  170.     case TIOCSETAW:
  171.     case TIOCSETAF:
  172.       {
  173.         struct termios *t = (struct termios *)arg;
  174.     /* the only thing that counts so far.. if ICANON is disabled,        
  175.      * we disable ECHO too, no matter what the user wanted, and 
  176.      * send a RAW-packet.. */
  177.     if ((t->c_lflag & ICANON) && (f->f_flags & FTTYRAW))
  178.           {
  179.         f->f_flags &= ~FTTYRAW;
  180.         __wait_packet(&f->f_sp);
  181.         SendPacket1(f,__rwport,ACTION_SCREEN_MODE,0);
  182.         __wait_packet(&f->f_sp);
  183.       }
  184.     else if (!(t->c_lflag & ICANON) && !(f->f_flags & FTTYRAW))
  185.       {
  186.         f->f_flags |= FTTYRAW;
  187.         __wait_packet(&f->f_sp);
  188.         SendPacket1(f,__rwport,ACTION_SCREEN_MODE,-1);
  189.         __wait_packet(&f->f_sp);
  190.       }
  191.     result = 0;
  192.     goto ret;
  193.       }
  194.  
  195.     case TIOCGETP:
  196.       {
  197.     struct sgttyb *s = (struct sgttyb *)arg;
  198.     s->sg_erase = 8;
  199.     s->sg_kill = 'x' & 31;
  200.     s->sg_flags = ODDP|EVENP|ANYP|
  201.               ((f->f_flags&FTTYRAW) ? (CBREAK|RAW) : (ECHO|CRMOD));
  202.     s->sg_ispeed =
  203.     s->sg_ospeed = OEXTB;
  204.     result = 0;
  205.     goto ret;
  206.       }
  207.  
  208.     case TIOCSETN:
  209.     case TIOCSETP:
  210.       {
  211.     struct sgttyb *s = (struct sgttyb *)arg;
  212.     if ((s->sg_flags & (RAW|CBREAK)) && !(f->f_flags & FTTYRAW))
  213.           {
  214.             f->f_flags |= FTTYRAW;
  215.         __wait_packet(&f->f_sp);
  216.         SendPacket1(f,__rwport,ACTION_SCREEN_MODE,-1);
  217.         __wait_packet(&f->f_sp);
  218.       }
  219.         else if (!(s->sg_flags & (RAW|CBREAK)) && (f->f_flags & FTTYRAW))
  220.       {
  221.         f->f_flags &= ~FTTYRAW;
  222.         SendPacket1(f,__rwport,ACTION_SCREEN_MODE,0);
  223.         __wait_packet(&f->f_sp);
  224.       }
  225.     result = 0;
  226.     goto ret;
  227.       }
  228.  
  229.     case TIOCGWINSZ:
  230.       {
  231.     struct winsize *ws = (struct winsize *) arg;
  232.     struct ConUnit *cu;
  233.     struct IOStdReq *ios;
  234.     struct InfoData *info;
  235.     struct Window *w;
  236.  
  237.     err = EINVAL;    /* default */
  238.     
  239.     info = alloca (sizeof (struct InfoData) + 2);
  240.     info = LONG_ALIGN (info);
  241.     bzero (info, sizeof (struct InfoData));
  242.     
  243.     /* VERY! strange.. CNC: won't act on the packet if it sent with the
  244.        async port as reply port! The error is OBJECT_IN_USE (202)... */
  245.  
  246.     __wait_packet (&f->f_sp);
  247.     LastResult (f) = 0; LastError (f) = 0;
  248.     SendPacket1 (f, u.u_sync_mp, ACTION_DISK_INFO, CTOBPTR (info));
  249.     __wait_sync_packet (&f->f_sp);
  250.     if (LastResult (f) != -1)
  251.       {
  252. /*        syscall (SYS_strncmp, "ACTION_DISK_INFO failed!", "", LastError(f));*/
  253.         goto ret;
  254.       }
  255.  
  256.     w = (struct Window *) info->id_VolumeNode;
  257.     if (! w) 
  258.       {
  259. /*        syscall (SYS_index, "No window in InfoData structure!", 0);*/
  260.         goto ret;
  261.       }
  262.     /* this information is from DevCon notes, not from the Bantam book */
  263.     ios = (struct IOStdReq *) info->id_InUse;
  264.     if (! ios || ((int)ios & 1)) 
  265.       {
  266. /*        syscall (SYS_index, "invalid ConUnit pointer in InfoData!", 0);*/
  267.         goto ret;
  268.       }
  269.     cu = (struct ConUnit *) ios->io_Unit;
  270.     if (!cu) 
  271.       {
  272. /*        syscall (SYS_index, "no ConUnit pointer in InfoData!", 0);*/
  273.         goto ret;
  274.       }
  275.  
  276.     /* paranoid check.. */
  277.     if (cu->cu_Window != w)
  278.       {
  279. /*        syscall (SYS_index, "incompatible ConUnit pointer in InfoData!", 0);*/
  280.         goto ret;
  281.       }
  282.  
  283.         ws->ws_xpixel = w->Width - w->BorderLeft - w->BorderRight;
  284.         ws->ws_ypixel = w->Height - w->BorderTop - w->BorderBottom;
  285.  
  286.     ws->ws_col = cu->cu_XMax + 1;    /* Thanks Rob! those values are off */
  287.     ws->ws_row = cu->cu_YMax + 1;    /* by one! */
  288.  
  289.     result = 0;
  290.     goto ret;
  291.       }
  292.  
  293.     case TIOCOUTQ:
  294.       {
  295.     int *count = (int *)arg;
  296.     *count = 0;
  297.     result = 0;
  298.     goto ret;
  299.       }
  300.  
  301.     case TIOCSWINSZ:
  302.       /* should I really try to resize the window ?? */
  303.  
  304.     default:
  305.       /* this is no error, but nevertheless we don't take any actions.. */      
  306.       result = 0;
  307.       goto ret;
  308.     }
  309.  
  310. ret:
  311.     LastResult(f) = 0;
  312.     __release_file (f);
  313.     syscall (SYS_sigsetmask, omask);
  314.     errno = err;
  315.     return result;
  316. }
  317. @
  318.  
  319.  
  320. 1.3
  321. log
  322. @send DISK_INFO packet with synchronous port, async delivery seems to be
  323. broken with CNC:
  324. @
  325. text
  326. @d19 1
  327. a19 1
  328.  *  $Id: __tioctl.c,v 1.2 1992/06/08 02:36:00 mwild Exp $
  329. d22 4
  330. d230 1
  331. a230 1
  332.     cu = ios->io_Unit;
  333. @
  334.  
  335.  
  336. 1.2
  337. log
  338. @fix TIOCGWINSZ, row/column was off by one
  339. @
  340. text
  341. @d19 1
  342. a19 1
  343.  *  $Id: __tioctl.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  344. d22 3
  345. d200 3
  346. a202 1
  347.     SendPacket1 (f, __rwport, ACTION_DISK_INFO, CTOBPTR (info));
  348. d204 8
  349. a211 1
  350.     if (LastResult (f) != -1) goto ret;
  351. d214 5
  352. a218 1
  353.     if (! w) goto ret;
  354. d221 5
  355. a225 1
  356.     if (! ios || ((int)ios & 1)) goto ret;
  357. d227 5
  358. a231 1
  359.     if (!cu) goto ret;
  360. d235 4
  361. a238 1
  362.       goto ret;
  363. @
  364.  
  365.  
  366. 1.1
  367. log
  368. @Initial revision
  369. @
  370. text
  371. @d19 1
  372. a19 1
  373.  *  $Id$
  374. d21 4
  375. a24 1
  376.  *  $Log$
  377. d216 2
  378. a217 2
  379.     ws->ws_col = cu->cu_XMax;
  380.     ws->ws_row = cu->cu_YMax;
  381. @
  382.