AmendHub

Download:

jcs

/

subtext

/

amendments

/

21

all: err(1, ...) -> panic()


jcs made amendment 21 over 2 years ago
--- console.c Tue Dec 7 15:02:14 2021 +++ console.c Wed Dec 8 14:39:08 2021 @@ -27,6 +27,7 @@ #define FONT_HEIGHT 11 struct node_funcs console_node_funcs = { + NULL, console_input, console_output, console_close @@ -61,13 +62,13 @@ console_init(struct console **cur_console) bounds.bottom = bounds.top + height; if (sprintf(title, "%s: console", PROGRAM_NAME) > sizeof(title)) - err(1, "sprintf overflow!"); + panic("sprintf overflow!"); CtoPstr(title); console->win = NewWindow(0L, &bounds, title, false, noGrowDocProc, (WindowPtr)-1L, true, 0); if (!console->win) - err(1, "Can't create window"); + panic("Can't create window"); SetPort(console->win); bounds.right = console->win->portRect.right; --- db.c Mon Dec 6 14:25:11 2021 +++ db.c Wed Dec 8 14:39:24 2021 @@ -37,11 +37,11 @@ load_db_tmpls(void) ntmpls = Count1Resources('TMPL'); if (ntmpls > nitems(tmpls)) - err(1, "ntmpls %d > %d", ntmpls, nitems(tmpls)); + panic("ntmpls %d > %d", ntmpls, nitems(tmpls)); for (n = 0; n < ntmpls; n++) { tmpls[n].h = GetIndResource('TMPL', n + 1); if (tmpls[n].h == NULL) - err(1, "Failed fetching TMPL %d", n + 1); + panic("Failed fetching TMPL %d", n + 1); GetResInfo(tmpls[n].h, &tmpls[n].id, &tmpls[n].type, &tmpls[n].name); DetachResource(tmpls[n].h); @@ -110,20 +110,20 @@ db_create(void) if (error == dupFNErr) { error = FSDelete(reply.fName, reply.vRefNum); if (error) - err(1, "Failed to re-create file %s: %d", PtoCstr(reply.fName), + panic("Failed to re-create file %s: %d", PtoCstr(reply.fName), error); error = Create(reply.fName, reply.vRefNum, SUBTEXT_CREATOR, DB_TYPE); } if (error) - err(1, "Failed to create %s: %d", PtoCstr(reply.fName), error); + panic("Failed to create %s: %d", PtoCstr(reply.fName), error); getpath(reply.vRefNum, reply.fName, &path, 1); CtoPstr(path); CreateResFile(path); if (ResError() != 0) - err(1, "Failed to create DB %s: %d", PtoCstr(path), ResError()); + panic("Failed to create DB %s: %d", PtoCstr(path), ResError()); PtoCstr(path); ret = db_init(path, 1); @@ -144,7 +144,7 @@ db_init(char *path, short is_new) CtoPstr(ppath); fh = OpenResFile(ppath); if (fh == -1) - err(1, "Failed to open %s: %d", path, ResError()); + panic("Failed to open %s: %d", path, ResError()); /* we got this far, store it as the last-accessed file */ UseResFile(mainResFile); @@ -210,7 +210,7 @@ db_migrate(struct db *tdb, short is_new) /* create a default sysop user */ user = user_build(tdb, "sysop", &error); if (!user) - err(1, "Failed creating initial sysop user: %s", error); + panic("Failed creating initial sysop user: %s", error); user_set_password(tdb, user, "p4ssw0rd"); user->is_sysop = DB_TRUE; user_save(tdb, user); @@ -269,7 +269,7 @@ db_config_save(struct db *tdb) hconfig = Get1Resource(DB_CONFIG_RTYPE, 1); if (hconfig) { if (sizeof(tdb->config) != GetHandleSize(hconfig)) - err(1, "db_config_save: handle size %ld, struct size %ld", + panic("db_config_save: handle size %ld, struct size %ld", GetHandleSize(hconfig), sizeof(tdb->config)); } else { hconfig = xNewHandle(sizeof(tdb->config)); @@ -283,7 +283,7 @@ db_config_save(struct db *tdb) if (is_new) { AddResource(hconfig, DB_CONFIG_RTYPE, 1, "\p"); if (ResError()) - err(1, "db_config_save: failed to AddResource: %d", + panic("db_config_save: failed to AddResource: %d", ResError()); } else { ChangedResource(hconfig); @@ -291,7 +291,7 @@ db_config_save(struct db *tdb) WriteResource(hconfig); if (ResError()) - err(1, "db_config_save: failed to WriteResource: %d", ResError()); + panic("db_config_save: failed to WriteResource: %d", ResError()); ReleaseResource(hconfig); } @@ -302,7 +302,7 @@ db_config_load(struct db *tdb) hconfig = Get1Resource(DB_CONFIG_RTYPE, 1); if (!hconfig) - err(1, "db_config_load: no config in existing db!"); + panic("db_config_load: no config in existing db!"); HLock(hconfig); memcpy(&tdb->config, *hconfig, sizeof(tdb->config)); --- session.c Tue Dec 7 13:20:38 2021 +++ session.c Thu Dec 9 16:40:57 2021 @@ -62,7 +62,15 @@ session_run(struct uthread *uthread, void *arg) Handle h; char *view; size_t len; - + + /* until we negotiate otherwise */ + s->terminal_cols = 80; + s->terminal_rows = 24; + sprintf(s->terminal_type, "xterm-color"); + + if (s->node_funcs->setup) + s->node_funcs->setup(s); + len = session_load_view(s, DB_TEXT_ISSUE_ID, &view); if (len) { session_output_formatted(s, view, len); @@ -126,7 +134,7 @@ session_output(struct session *session, const char *fo len = vsprintf(session_tbuf, format, ap); va_end(ap); if (len >= sizeof(session_tbuf)) - err(1, "sprintf overflow in session_output!"); + panic("sprintf overflow in session_output!"); return session_output_formatted(session, session_tbuf, len); } @@ -163,8 +171,9 @@ session_output_formatted(struct session *session, cons char session_input_char(struct session *session) { - char ret; + unsigned char ret; +wait_for_char: while (session->ibuflen == 0) { session->node_funcs->input(session); uthread_yield(); @@ -178,6 +187,14 @@ session_input_char(struct session *session) session->ibuflen--; } + if (session->last_input == '\r' && ret == '\n') { + /* we already responded to the \r, just ignore this */ + session->last_input = ret; + goto wait_for_char; + } + + session->last_input = ret; + return ret; } @@ -192,8 +209,9 @@ session_field_input(struct session *session, unsigned for (;;) { c = session_input_char(session); - switch (c) { - case 8: + switch ((unsigned char)c) { + case 8: /* backspace / ^H */ + case 127: /* delete, backspace through telnet */ if (ipos == 0) continue; @@ -211,10 +229,11 @@ session_field_input(struct session *session, unsigned if (redraw) { /* TODO */ } else - /* back one, space, back one */ - session_output(session, "\e[D \e[D"); + /* back one, space, back one (\33 oct = \e) */ + session_output_formatted(session, "\33[D \33[D", 7); break; + case '\r': case '\n': return field; default: --- session.h Tue Dec 7 08:40:19 2021 +++ session.h Thu Dec 9 16:41:34 2021 @@ -32,6 +32,7 @@ enum session_input_state { }; struct node_funcs { + void (*setup)(struct session *session); short (*input)(struct session *session); short (*output)(struct session *session); void (*close)(struct session *session); @@ -39,12 +40,16 @@ struct node_funcs { struct session { char node[10]; - char obuf[512]; - char ibuf[64]; + unsigned char obuf[256]; /* telnet.obuf must be double this */ + unsigned char ibuf[64]; enum session_state state; enum session_input_state input_state; short obuflen; short ibuflen; + unsigned char last_input; + unsigned short terminal_cols; + unsigned short terminal_rows; + char terminal_type[20]; void *cookie; struct node_funcs *node_funcs; struct uthread *uthread; --- user.c Sun Dec 5 20:21:25 2021 +++ user.c Wed Dec 8 14:39:50 2021 @@ -69,7 +69,7 @@ user_save(struct db *tdb, struct user *user) if (user->id) { huser = Get1Resource(DB_USER_RTYPE, user->id); if (!huser) - err(1, "user_save: user %s has id %d but no resource", + panic("user_save: user %s has id %d but no resource", user->username, user->id); hsize = GetHandleSize(huser); } else { @@ -106,7 +106,7 @@ user_save(struct db *tdb, struct user *user) datapos += sizeof(user->is_sysop); if (datapos != hsize) - err(1, "user_save handle size %ld, data position %ld", + panic("user_save handle size %ld, data position %ld", hsize, datapos); HUnlock(huser); @@ -121,7 +121,7 @@ user_save(struct db *tdb, struct user *user) if (is_new) { AddResource(huser, DB_USER_RTYPE, user->id, lusername); if (ResError()) - err(1, "user_save: failed to AddResource: %d", ResError()); + panic("user_save: failed to AddResource: %d", ResError()); } else { SetResInfo(huser, user->id, lusername); ChangedResource(huser); @@ -129,7 +129,7 @@ user_save(struct db *tdb, struct user *user) WriteResource(huser); if (ResError()) - err(1, "user_save: failed to WriteResource: %d", ResError()); + panic("user_save: failed to WriteResource: %d", ResError()); ReleaseResource(huser); tdb->nusers = Count1Resources(DB_USER_RTYPE); @@ -195,7 +195,7 @@ user_parse(struct db *tdb, Handle huser) datapos += sizeof(user->is_sysop); if (datapos != hlen) - err(1, "user_parse handle len %d, data position %d", hlen, datapos); + panic("user_parse handle len %d, data position %d", hlen, datapos); HUnlock(huser); ReleaseResource(huser);