--- tty.c.old Mon Dec 2 11:49:50 2002 +++ tty.c Mon Jan 6 23:31:07 2003 @@ -42,10 +42,15 @@ /* If nonzero, return an exit status but produce no output. */ static int silent; +/* If nonzero, print the name only, no leading /dev + * Addition by Alan Ford */ +static int nameonly; + static struct option const longopts[] = { {"silent", no_argument, NULL, 's'}, {"quiet", no_argument, NULL, 's'}, + {"name", no_argument, NULL, 'n'}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -64,6 +69,7 @@ Print the file name of the terminal connected to standard input.\n\ \n\ -s, --silent, --quiet print nothing, only return an exit status\n\ + -n, --name print name only, no leading /dev\n\ --help display this help and exit\n\ --version output version information and exit\n\ ")); @@ -85,7 +91,7 @@ silent = 0; - while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1) + while ((optc = getopt_long (argc, argv, "sn", longopts, NULL)) != -1) { switch (optc) { @@ -95,6 +101,10 @@ case 's': silent = 1; break; + + case 'n': + nameonly = 1; + break; case_GETOPT_HELP_CHAR; @@ -109,6 +119,16 @@ usage (2); tty = ttyname (0); + if (nameonly) { + tty++; + while (*tty != '\0') { + if (*tty == '/') + break; + else + tty++; + } + tty++; + } if (!silent) { if (tty)