mirror of
https://github.com/wrog/lambdamoo
synced 2026-08-13 00:26:05 -04:00
Phase one = use the various API calls everywhere, but define them all
as inline routines that perform the straight-ASCII functions we were
doing before, so as to make this is a grand no-op to re create the
non-Unicode server we already had previously.
Important differences from the original implementation:
(1)
In this timeline, HPA's libucd (Unicode Character Database) and the
inclusion of a subdirectory to build it in (ucd/) NEVER HAPPENED;
In phase two, we'll instead go straight to an implementation using
GNU libunistring as a shared lib, only (re-)introducing libucd and
libicuuc as alternatives later.
(...in other news we have *always* been at war with Eastasia.
Also, Bobby Ewing is dead; as you may recall, Dallas received a
long-overdue cancellation at the end of its 8th season.
Alsoalso, Skywalker Ranch was struck by a meteor in 1981,
so the Star Wars series ended with The Empire Strikes Back;
Ron Moore is currently busy on a reboot/reimagining....)
(2)
There is no skip_utf(). Instead, we have
(*) utf_byte_index(),
a re-arranged version that is more explicit about
the mission of converting character indices to byte indices
and can be used prior to any range checking,
(*) utf_byte_range()
converts *pairs* of char indices to byte indices
since this seems to come up a lot.
(*) utf_char_index(),
goes the other way, but with fewer traversals
(3)
my-ctype.h retains its role of working around mistakes in ctype.h on
broken systems. All changes you might have thought you made there are
actually in utf-ctype.h, which, oddly enough serves as the header file
for the new functions being introduced in utf-ctype.c
Original commits cannibalized from the codepoint branch:
. Initial work on Unicode compatibility
-- hpa
. fix ok_identifier (was: Correct which ctype to use ...)
revised to leave my-ctype.h reference in db_io.c alone
since it is solely there to provide (ascii) isspace().
-- hpa
. Kenny's fixes to get it to load Minimal.db and JHCore. (2)
-- james <james@nanaka.home.place.org>
. Slew a few bugs, made string handling unicode-y.
--james <james@nanaka.home.place.org>
. make NET_SINGLE do utf8
--wrog <crew@cs.stanford.edu>
(since, among other things, fixing net_single.c
should have been done at the same time.)
. Don't consider U+007F or surrogates to be printable
--Rob Leslie <rob@mars.org>
(changes my_is_printable())
This commit alters my_is_printable() to reject surrogate code
points, in part so that bf_tochar() doesn't end up returning an
empty string instead of generating an error. (Surrogates are
already rejected by put_utf().)
. Caused online programming of verbs containing unicode to stop almost
working for the wrong reasons and, along with reading of verbs
containing unicode from saved databases, start working for the right
reasons.
--james <james@nanaka.home.place.org>
(adds a number of stream_add_utf() uses to parser.y --wrog)
. Let stream_add_utf() return the result of put_utf()
--Rob Leslie <rob@mars.org>
There's no point duplicating all the validity checks in put_utf()
elsewhere.
291 lines
6.7 KiB
C
291 lines
6.7 KiB
C
/******************************************************************************
|
|
Copyright (c) 1992, 1995, 1996 Xerox Corporation. All rights reserved.
|
|
Portions of this code were written by Stephen White, aka ghond.
|
|
Use and copying of this software and preparation of derivative works based
|
|
upon this software are permitted. Any distribution of this software or
|
|
derivative works must comply with all applicable United States export
|
|
control laws. This software is made available AS IS, and Xerox Corporation
|
|
makes no warranty about the software, its performance or its conformity to
|
|
any specification. Any person obtaining a copy of this software is requested
|
|
to send their name and post office or electronic mail address to:
|
|
Pavel Curtis
|
|
Xerox PARC
|
|
3333 Coyote Hill Rd.
|
|
Palo Alto, CA 94304
|
|
Pavel@Xerox.Com
|
|
*****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "my-ctype.h"
|
|
#include "my-fcntl.h"
|
|
#include "my-stdio.h"
|
|
#include "my-unistd.h"
|
|
|
|
#include "log.h"
|
|
#include "network.h"
|
|
#include "server.h"
|
|
#include "streams.h"
|
|
#include "structures.h"
|
|
#include "utf.h"
|
|
#include "utf-ctype.h"
|
|
#include "utils.h"
|
|
|
|
static enum {
|
|
STATE_OPEN, STATE_CLOSED
|
|
} state = STATE_CLOSED;
|
|
static int listening = 0;
|
|
static server_listener slistener;
|
|
static int binary = 0;
|
|
static char excess_utf[4];
|
|
static int excess_utf_count = 0;
|
|
|
|
const char *
|
|
network_protocol_name(void)
|
|
{
|
|
return "single-user";
|
|
}
|
|
|
|
const char *
|
|
network_usage_string(void)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
int
|
|
network_initialize(int argc, char **argv UNUSED_, Var * desc)
|
|
{
|
|
*desc = zero;
|
|
if (argc != 0)
|
|
return 0;
|
|
else
|
|
return 1;
|
|
}
|
|
|
|
enum error
|
|
network_make_listener(server_listener sl, Var desc UNUSED_,
|
|
network_listener * nl,
|
|
Var * canon, const char **name)
|
|
{
|
|
if (listening)
|
|
return E_PERM;
|
|
|
|
listening = 1;
|
|
slistener = sl;
|
|
nl->ptr = 0;
|
|
*canon = zero;
|
|
*name = "standard input";
|
|
return E_NONE;
|
|
}
|
|
|
|
int
|
|
network_listen(network_listener nl UNUSED_)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
network_send_line(network_handle nh UNUSED_, const char *line,
|
|
int flush_ok UNUSED_)
|
|
{
|
|
printf("%s\n", line);
|
|
fflush(stdout);
|
|
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
network_send_bytes(network_handle nh UNUSED_, const char *buffer, size_t buflen,
|
|
int flush_ok UNUSED_)
|
|
{
|
|
/* Cast to (void *) to discard `const' on some systems */
|
|
fwrite((void *) buffer, sizeof(char), buflen, stdout);
|
|
fflush(stdout);
|
|
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
network_buffered_output_length(network_handle nh UNUSED_)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
const char *
|
|
network_connection_name(network_handle nh UNUSED_)
|
|
{
|
|
return "standard input";
|
|
}
|
|
|
|
void
|
|
network_set_connection_binary(network_handle nh UNUSED_, int do_binary)
|
|
{
|
|
binary = do_binary;
|
|
}
|
|
|
|
#define NETWORK_CO_TABLE(DEFINE, nh, value, _)
|
|
/* No network-specific connection options */
|
|
|
|
|
|
void
|
|
network_close(network_handle nh UNUSED_)
|
|
{
|
|
state = STATE_CLOSED;
|
|
}
|
|
|
|
void
|
|
network_close_listener(network_listener nl UNUSED_)
|
|
{
|
|
listening = 0;
|
|
}
|
|
|
|
void
|
|
network_shutdown(void)
|
|
{
|
|
int flags;
|
|
|
|
if ((flags = fcntl(0, F_GETFL)) < 0
|
|
|| fcntl(0, F_SETFL, flags & ~NONBLOCK_FLAG) < 0)
|
|
log_perror("Setting standard input blocking again");
|
|
}
|
|
|
|
static int input_suspended = 0;
|
|
|
|
void
|
|
network_suspend_input(network_handle nh UNUSED_)
|
|
{
|
|
input_suspended = 1;
|
|
}
|
|
|
|
void
|
|
network_resume_input(network_handle nh UNUSED_)
|
|
{
|
|
input_suspended = 0;
|
|
}
|
|
|
|
int
|
|
network_process_io(int timeout)
|
|
{
|
|
network_handle nh;
|
|
static server_handle sh;
|
|
static Stream *s = 0;
|
|
char buffer[1024];
|
|
ssize_t count;
|
|
const char *ptr, *end;
|
|
int got_some = 0;
|
|
|
|
if (s == 0) {
|
|
int flags;
|
|
|
|
s = new_stream(1000);
|
|
|
|
if ((flags = fcntl(0, F_GETFL)) < 0
|
|
|| fcntl(0, F_SETFL, flags | NONBLOCK_FLAG) < 0) {
|
|
log_perror("Setting standard input non-blocking");
|
|
return 0;
|
|
}
|
|
}
|
|
switch (state) {
|
|
case STATE_CLOSED:
|
|
if (listening) {
|
|
sh = server_new_connection(slistener, nh, 0);
|
|
state = STATE_OPEN;
|
|
binary = 0;
|
|
excess_utf_count = 0;
|
|
got_some = 1;
|
|
} else if (timeout != 0)
|
|
sleep(timeout);
|
|
break;
|
|
|
|
case STATE_OPEN:
|
|
for (;;) {
|
|
while (!input_suspended &&
|
|
((void)(excess_utf_count
|
|
&& memcpy(buffer, excess_utf, excess_utf_count)),
|
|
count = read(0, buffer + excess_utf_count,
|
|
sizeof(buffer) - excess_utf_count)) > 0) {
|
|
got_some = 1;
|
|
if (binary) {
|
|
stream_add_moobinary_from_raw_bytes(s, buffer, count);
|
|
server_receive_line(sh, reset_stream(s));
|
|
excess_utf_count = 0;
|
|
} else {
|
|
for (ptr = buffer, end = buffer + count;
|
|
ptr < end && ptr + clearance_utf(*ptr) <= end;
|
|
) {
|
|
int c = get_utf(&ptr);
|
|
|
|
if (my_is_printable(c))
|
|
stream_add_utf(s, c);
|
|
#ifdef INPUT_APPLY_BACKSPACE
|
|
else if (c == 0x08 || c == 0x7F)
|
|
stream_delete_utf(s);
|
|
#endif
|
|
else if (c == '\n')
|
|
server_receive_line(sh, reset_stream(s));
|
|
}
|
|
if (ptr < end)
|
|
memcpy(excess_utf, ptr, end - ptr);
|
|
excess_utf_count = end - ptr;
|
|
}
|
|
}
|
|
|
|
if (got_some || timeout == 0)
|
|
goto done;
|
|
|
|
sleep(1);
|
|
timeout--;
|
|
}
|
|
}
|
|
|
|
done:
|
|
return got_some;
|
|
}
|
|
|
|
|
|
/*
|
|
* $Log$
|
|
* Revision 2.4 1996/03/10 01:23:12 pavel
|
|
* Added support for `connection_option()'. Added missing include of
|
|
* "utils.h". Release 1.8.0.
|
|
*
|
|
* Revision 2.3 1996/02/08 06:38:35 pavel
|
|
* Added network_set_connection_binary() and network_connection_options().
|
|
* Updated copyright notice for 1996. Release 1.8.0beta1.
|
|
*
|
|
* Revision 2.2 1996/01/11 07:44:12 pavel
|
|
* Added support for binary I/O. Added network_buffered_output_length().
|
|
* Removed one more `unsigned' from the server. Release 1.8.0alpha5.
|
|
*
|
|
* Revision 2.1 1995/12/30 23:56:29 pavel
|
|
* Added support for the new multiple-listening-points interface.
|
|
* Release 1.8.0alpha4.
|
|
*
|
|
* Revision 2.0 1995/11/30 04:45:25 pavel
|
|
* New baseline version, corresponding to release 1.8.0alpha1.
|
|
*
|
|
* Revision 1.8 1992/10/23 23:03:47 pavel
|
|
* Added copyright notice.
|
|
*
|
|
* Revision 1.7 1992/10/21 03:02:35 pavel
|
|
* Converted to use new automatic configuration system.
|
|
*
|
|
* Revision 1.6 1992/10/17 20:45:28 pavel
|
|
* Changed to use generic support for POSIX-style non-blocking in "my-fcntl.h"
|
|
* instead of a separate, different version.
|
|
*
|
|
* Revision 1.5 1992/10/06 18:20:11 pavel
|
|
* Moved code to set stdin nonblocking out of the initialization routine and
|
|
* into the first time that network_process_io() is called.
|
|
* Also fixed up that routine to obviously return a value, circumventing a
|
|
* warning from dumb compilers.
|
|
*
|
|
* Revision 1.4 1992/09/26 02:21:07 pavel
|
|
* Added support for printing the network protocol name on server start-up.
|
|
*
|
|
* Revision 1.3 1992/09/11 21:23:52 pavel
|
|
* Tracked change to network.h.
|
|
*
|
|
* Revision 1.2 1992/09/03 23:52:00 pavel
|
|
* Added RCS Id and Log strings.
|
|
*/
|