Check-in [a7c3ea759b]
Overview
SHA1:a7c3ea759b85d6ceed9ffe91dec7d8dd8f644a6d
Date: 2014-10-29 18:09:02
User: rkeene
Comment:Added basic support for "stty"
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2014-10-29
18:14
[ee22fadb48] Removed skipping of "size" request (user: rkeene, tags: trunk)
18:09
[a7c3ea759b] Added basic support for "stty" (user: rkeene, tags: trunk)
16:17
[50eb7273e9] Added support for device name loading (user: rkeene, tags: trunk)
Changes

Modified tuapi.c from [d8491577f6] to [774f54baad].

     1      1   #define _LINUX_SOURCE 1
     2      2   #include <sys/syscall.h>
            3  +#include <sys/termios.h>
     3      4   #include <netinet/in.h>
     4      5   #include <arpa/inet.h>
     5      6   #include <sys/socket.h>
     6      7   #include <sys/select.h>
     7      8   #include <sys/mount.h>
     8      9   #include <sys/types.h>
     9     10   #include <sys/ioctl.h>
................................................................................
  1874   1875   
  1875   1876   	if (sock_v6 != -1) {
  1876   1877   		close(sock_v6);
  1877   1878   	}
  1878   1879   
  1879   1880   	return(retval);
  1880   1881   }
         1882  +
         1883  +static int tuapi_stty(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
         1884  +	Tcl_Obj *obj, *retobj = NULL;
         1885  +	struct termios terminal_information;
         1886  +	struct winsize terminal_size;
         1887  +	unsigned long obj_hash;
         1888  +	int fd, idx;
         1889  +	int ioctl_ret;
         1890  +	int retval = TCL_OK;
         1891  +
         1892  +	fd = STDIN_FILENO;
         1893  +
         1894  +	for (idx = 1; idx < objc; idx++) {
         1895  +		obj = objv[idx];
         1896  +		obj_hash = tuapi_internal_simplehash_obj(obj);
         1897  +
         1898  +		if (obj_hash == 0xe7a7d65) { /* size */
         1899  +			continue;
         1900  +		}
         1901  +
         1902  +		switch (obj_hash) {
         1903  +			case 0xe7a7d65: /* size */
         1904  +				ioctl_ret = ioctl(fd, TIOCGWINSZ, &terminal_size);
         1905  +				if (ioctl_ret != 0) {
         1906  +					Tcl_SetObjResult(interp, Tcl_NewStringObj("ioctl failed", -1));
         1907  +
         1908  +					return(TCL_ERROR);
         1909  +				}
         1910  +
         1911  +				if (retobj == NULL) {
         1912  +					retobj = Tcl_NewObj();
         1913  +				}
         1914  +
         1915  +				Tcl_ListObjAppendElement(interp, retobj, Tcl_NewLongObj(terminal_size.ws_row));
         1916  +				Tcl_ListObjAppendElement(interp, retobj, Tcl_NewLongObj(terminal_size.ws_col));
         1917  +				break;
         1918  +			case 0x5bcb0f7: /* -raw */
         1919  +			case 0x1cb0f7: /* raw */
         1920  +			case 0xdcb8f56f: /* -echo */
         1921  +			case 0xcb8f46f: /* echo */
         1922  +				ioctl_ret = ioctl(fd, TCGETS, &terminal_information);
         1923  +				if (ioctl_ret != 0) {
         1924  +					Tcl_SetObjResult(interp, Tcl_NewStringObj("ioctl failed", -1));
         1925  +
         1926  +					return(TCL_ERROR);
         1927  +				}
         1928  +
         1929  +				switch (obj_hash) {
         1930  +					case 0x5bcb0f7: /* -raw */
         1931  +						terminal_information.c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;
         1932  +						terminal_information.c_oflag |= OPOST;
         1933  +						terminal_information.c_lflag |= ISIG | ICANON;
         1934  +#if VMIN == VEOF
         1935  +						terminal_information.c_cc[VEOF] = CEOF;
         1936  +#endif
         1937  +#if VTIME == VEOL
         1938  +						terminal_information.c_cc[VEOL] = CEOL;
         1939  +#endif
         1940  +						break;
         1941  +					case 0x1cb0f7: /* raw */
         1942  +						terminal_information.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
         1943  +						terminal_information.c_oflag &= ~OPOST;
         1944  +						terminal_information.c_lflag &= ~(ISIG | ICANON);
         1945  +						terminal_information.c_cc[VMIN] = 1;
         1946  +						terminal_information.c_cc[VTIME] = 0;
         1947  +						break;
         1948  +					case 0xdcb8f56f: /* -echo */
         1949  +						terminal_information.c_lflag &= ~ECHO;
         1950  +						break;
         1951  +					case 0xcb8f46f: /* echo */
         1952  +						terminal_information.c_lflag |= ECHO;
         1953  +						break;
         1954  +				}
         1955  +
         1956  +				ioctl_ret = ioctl(fd, TCSETS, &terminal_information);
         1957  +				if (ioctl_ret != 0) {
         1958  +					Tcl_SetObjResult(interp, Tcl_NewStringObj("ioctl failed", -1));
         1959  +
         1960  +					return(TCL_ERROR);
         1961  +				}
         1962  +
         1963  +				break;
         1964  +			default:
         1965  +				Tcl_SetObjResult(interp, Tcl_NewStringObj("subcommand not implemented", -1));
         1966  +				return(TCL_ERROR);
         1967  +		}
         1968  +	}
         1969  +
         1970  +	if (retobj != NULL) {
         1971  +		Tcl_SetObjResult(interp, retobj);
         1972  +	}
         1973  +
         1974  +	return(retval);
         1975  +}
  1881   1976   
  1882   1977   #ifndef DISABLE_UNIX_SOCKETS
  1883   1978   struct tuapi_socket_unix__chan_id {
  1884   1979   	int fd;
  1885   1980   	Tcl_Channel chan;
  1886   1981   };
  1887   1982   
................................................................................
  2593   2688   
  2594   2689   	/* Network related commands */
  2595   2690   	Tcl_CreateObjCommand(interp, "::tuapi::syscall::ifconfig", tuapi_ifconfig, NULL, NULL);
  2596   2691   	Tcl_CreateObjCommand(interp, "::tuapi::syscall::route", tuapi_route, NULL, NULL);
  2597   2692   	Tcl_CreateObjCommand(interp, "::tuapi::syscall::brctl", tuapi_brctl, NULL, NULL);
  2598   2693   	Tcl_CreateObjCommand(interp, "::tuapi::syscall::vconfig", tuapi_vconfig, NULL, NULL);
  2599   2694   
         2695  +	/* Terminal related commands */
         2696  +	Tcl_CreateObjCommand(interp, "::tuapi::syscall::stty", tuapi_stty, NULL, NULL);
         2697  +
  2600   2698   	/* Needed commands for basic services Tcl lacks */
  2601   2699   	Tcl_CreateObjCommand(interp, "::tuapi::syscall::socket_unix", tuapi_socket_unix, NULL, NULL);
  2602   2700   
  2603   2701   	/* Service (TSMF) related commands */
  2604   2702   	Tcl_CreateObjCommand(interp, "::tuapi::syscall::tsmf_start_svc", tuapi_tsmf_start_svc, NULL, NULL);
  2605   2703   
  2606   2704   	/* Internal functions */