| 1 |
/* |
| 2 |
Copyright (C) 1995-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
/* |
| 20 |
* Copyright (c) 1983, 1993 |
| 21 |
* The Regents of the University of California. All rights reserved. |
| 22 |
* |
| 23 |
* Redistribution and use in source and binary forms, with or without |
| 24 |
* modification, are permitted provided that the following conditions |
| 25 |
* are met: |
| 26 |
* 1. Redistributions of source code must retain the above copyright |
| 27 |
* notice, this list of conditions and the following disclaimer. |
| 28 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 29 |
* notice, this list of conditions and the following disclaimer in the |
| 30 |
* documentation and/or other materials provided with the distribution. |
| 31 |
* 3. Neither the name of the University nor the names of its contributors |
| 32 |
* may be used to endorse or promote products derived from this software |
| 33 |
* without specific prior written permission. |
| 34 |
* |
| 35 |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 36 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 37 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 38 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 39 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 40 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 41 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 42 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 43 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 45 |
* SUCH DAMAGE. |
| 46 |
*/ |
| 47 |
|
| 48 |
#include <config.h> |
| 49 |
#include <stdlib.h> |
| 50 |
#include <unistd.h> |
| 51 |
#ifdef HAVE_LOCALE_H |
| 52 |
# include <locale.h> |
| 53 |
#endif |
| 54 |
|
| 55 |
#include "talk.h" |
| 56 |
#include <argp.h> |
| 57 |
#include <libinetutils.h> |
| 58 |
|
| 59 |
void usage (void); |
| 60 |
|
| 61 |
/* |
| 62 |
* talk: A visual form of write. Using sockets, a two way |
| 63 |
* connection is set up between the two people talking. |
| 64 |
* With the aid of curses, the screen is split into two |
| 65 |
* windows, and each users text is added to the window, |
| 66 |
* one character at a time... |
| 67 |
* |
| 68 |
* Written by Kipp Hickman |
| 69 |
* |
| 70 |
* Modified to run under 4.1a by Clem Cole and Peter Moore |
| 71 |
* Modified to run between hosts by Peter Moore, 8/19/82 |
| 72 |
* Modified to run under 4.1c by Peter Moore 3/17/83 |
| 73 |
*/ |
| 74 |
|
| 75 |
const char *program_authors[] = { |
| 76 |
"Kipp Hickman", |
| 77 |
"Clem Cole", |
| 78 |
"Peter Moore", |
| 79 |
NULL |
| 80 |
}; |
| 81 |
|
| 82 |
const char doc[] = "Talk to another user."; |
| 83 |
const char args_doc[] = "person [ttyname]"; |
| 84 |
static struct argp argp = { NULL, NULL, args_doc, doc, NULL, NULL, NULL }; |
| 85 |
|
| 86 |
int |
| 87 |
main (int argc, char *argv[]) |
| 88 |
{ |
| 89 |
int index; |
| 90 |
|
| 91 |
set_program_name (argv[0]); |
| 92 |
#ifdef HAVE_SETLOCALE |
| 93 |
setlocale (LC_ALL, ""); |
| 94 |
#endif |
| 95 |
iu_argp_init ("talk", program_authors); |
| 96 |
argp_parse (&argp, argc, argv, 0, &index, NULL); |
| 97 |
|
| 98 |
argc -= index; |
| 99 |
argv += index; |
| 100 |
|
| 101 |
if (argc == 0) |
| 102 |
{ |
| 103 |
printf ("Usage: talk user [ttyname]\n"); |
| 104 |
exit (-1); |
| 105 |
} |
| 106 |
if (!isatty (0)) |
| 107 |
{ |
| 108 |
printf ("Standard input must be a tty, not a pipe, nor a file.\n"); |
| 109 |
exit (-1); |
| 110 |
} |
| 111 |
|
| 112 |
get_names (argc, argv); |
| 113 |
|
| 114 |
/* Let them know we are working on connections. */ |
| 115 |
current_state = "No connection yet."; |
| 116 |
|
| 117 |
open_ctl (); |
| 118 |
open_sockt (); |
| 119 |
current_state = "Service connection established."; |
| 120 |
|
| 121 |
start_msgs (); |
| 122 |
if (!check_local ()) |
| 123 |
invite_remote (); |
| 124 |
end_msgs (); |
| 125 |
|
| 126 |
/* Our party is responding. Upgrade user interface. */ |
| 127 |
init_display (); |
| 128 |
set_edit_chars (); |
| 129 |
|
| 130 |
talk (); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
static const char usage_str[] = |
| 135 |
"Usage: talk [OPTIONS...] USER\n" |
| 136 |
"\n" |
| 137 |
"Options are:\n" |
| 138 |
" --help Display usage instructions\n" |
| 139 |
" --version Display program version\n"; |
| 140 |
|
| 141 |
void |
| 142 |
usage (void) |
| 143 |
{ |
| 144 |
printf ("%s\n" "Send bug reports to <%s>.\n", usage_str, PACKAGE_BUGREPORT); |
| 145 |
} |