Skip to content

Commit

Permalink
[hyper] SpadStatus: distinct type for spad server status (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielDosReis authored Jan 1, 2024
1 parent 374da06 commit b0863d9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 47 deletions.
21 changes: 9 additions & 12 deletions src/hyper/htinp.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ char buf_for_record_commands[256];
void
make_record()
{
int i;
for (i=0;i<input_file_count;i++){
for (int i=0;i<input_file_count;i++){
send_lisp_command("(|clearCmdCompletely|)");
send_lisp_command("(setq |$testingSystem| T)");
send_lisp_command("(setq |$printLoadMsgs| NIL)");
Expand All @@ -88,8 +87,8 @@ make_record()
send_lisp_command(buf_for_record_commands);
}
if (kill_spad){
i = connect_spad();
if (i != NotConnected && i != SpadBusy)
auto status = connect_spad();
if (status != SpadStatus::NotConnected && status != SpadStatus::SpadBusy)
send_int(spad_socket, KillLispSystem);
}

Expand All @@ -98,8 +97,7 @@ make_record()
void
verify_record()
{
int i;
for (i=0;i<input_file_count;i++){
for (int i=0;i<input_file_count;i++){
send_lisp_command("(|clearCmdCompletely|)");
send_lisp_command("(setq |$testingSystem| T)");
send_lisp_command("(setq |$printLoadMsgs| NIL)");
Expand All @@ -109,8 +107,8 @@ verify_record()
send_lisp_command(buf_for_record_commands);
}
if (kill_spad) {
i = connect_spad();
if (i != NotConnected && i != SpadBusy)
auto status = connect_spad();
if (status != SpadStatus::NotConnected && status != SpadStatus::SpadBusy)
send_int(spad_socket, KillLispSystem);
}
}
Expand All @@ -121,19 +119,18 @@ ht2_input()
{
HashTable *table;
HashEntry *entry;
int i;

bsdSignal(SIGUSR2, SIG_IGN,RestartSystemCalls);
gWindow = alloc_hd_window();
init_group_stack();
table = gWindow->fPageHashTable;
make_input_file_list();
for (i = 0; i < table->size; i++)
for (int i = 0; i < table->size; i++)
for (entry = table->table[i]; entry != NULL; entry = entry->next)
make_the_input_file((UnloadedPage *) entry->data);
if (kill_spad){
i = connect_spad();
if (i != NotConnected && i != SpadBusy)
auto status = connect_spad();
if (status != SpadStatus::NotConnected && status != SpadStatus::SpadBusy)
send_int(spad_socket, KillLispSystem);
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/hyper/hyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,12 @@ extern int space_width;
#define KeyDefsHelpPage "ugHyperKeysPage"
#define InputAreaHelpPage "ugHyperInputPage"

/* definitions for connecting to the Axiom server */

#define Connected 0
#define NotConnected 1
#define SpadBusy 2

/* some GUI-dependent stuff */

#define BeepAtTheUser() /* (XBell(gXDisplay, 5)) */
#define LoudBeepAtTheUser() /* (XBell(gXDisplay, 50)) */

extern int connect_spad();
extern OpenAxiom::SpadStatus connect_spad();


/*** default fonts ***/
Expand Down
13 changes: 7 additions & 6 deletions src/hyper/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ namespace OpenAxiom {
Footer = 3,
Title = 4
};

// Definition for connection status to the OpenAxiom server
enum class SpadStatus {
Connected = 0,
NotConnected = 1,
SpadBusy = 2,
};
}

/* structure for a hyper text link */
Expand Down Expand Up @@ -406,12 +413,6 @@ using ParameterList = parameter_list_type*;
#define KeyDefsHelpPage "ugHyperKeysPage"
#define InputAreaHelpPage "ugHyperInputPage"

/* definitions for connecting to the Axiom server */

#define Connected 0
#define NotConnected 1
#define SpadBusy 2

/* some GUI-dependent stuff */

#define BeepAtTheUser() /* (XBell(gXDisplay, 5)) */
Expand Down
2 changes: 1 addition & 1 deletion src/hyper/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ reset_connection()
purpose_table[spad_socket->purpose] = NULL;
close(spad_socket->socket);
spad_socket->socket = 0;
spad_socket->nbytes_pending = 0;
spad_socket = NULL;
input_string = nullptr;
spad_socket->nbytes_pending = 0;
connect_spad();
}
}
Expand Down
36 changes: 15 additions & 21 deletions src/hyper/spadint.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,24 @@ typedef struct sock_list { /* linked list of openaxiom_sio */

Sock_List *plSock = (Sock_List *) 0;

/* connect to OpenAxiom , return 0 if succesful, 1 if not */
int
connect_spad()
/* Attempt to connect to OpenAxiom , return connection status. */
SpadStatus connect_spad()
{
if (!MenuServerOpened) {
fprintf(stderr, "(HyperDoc) Warning: Not connected to OpenAxiom Server!\n");
LoudBeepAtTheUser();
return NotConnected;
return SpadStatus::NotConnected;
}
if (spad_socket == NULL) {
spad_socket = connect_to_local_server(SpadServer, MenuServer, Forever);
if (spad_socket == NULL) {
fprintf(stderr, "(HyperDoc) Warning: Could not connect to OpenAxiom Server!\n");
LoudBeepAtTheUser();
return NotConnected;
return SpadStatus::NotConnected;
}
}
/* if (spad_busy()) return SpadBusy; */
return Connected;
return SpadStatus::Connected;
}

/* returns true if spad is currently computing */
Expand All @@ -104,15 +103,14 @@ issue_spadcommand(HyperDocPage *page, TextNode *command, int immediate,
TokenType type)
{
char *buf;
int ret_val;

ret_val = connect_spad();
if (ret_val == NotConnected || ret_val == SpadBusy)
auto status = connect_spad();
if (status == SpadStatus::NotConnected || status == SpadStatus::SpadBusy)
return;

if (page->sock == NULL)
start_user_buffer(page);
ret_val = send_int(page->sock, TestLine);
auto ret_val = send_int(page->sock, TestLine);
if (ret_val == -1) {
page->sock = NULL;
clear_execution_marks(page->depend_hash);
Expand Down Expand Up @@ -675,18 +673,17 @@ HyperDocPage *
issue_server_command(HyperLink *link)
{
TextNode *command = (TextNode *) link->reference.node;
int ret_val;
char *buf;
HyperDocPage *page;

ret_val = connect_spad();
if (ret_val == NotConnected) {
auto status = connect_spad();
if (status == SpadStatus::NotConnected) {
page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, "SpadNotConnectedPage");
if (page == NULL)
fprintf(stderr, "No SpadNotConnectedPage found\n");
return page;
}
if (ret_val == SpadBusy) {
if (status == SpadStatus::SpadBusy) {
page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, "SpadBusyPage");
if (page == NULL)
fprintf(stderr, "No SpadBusyPage found\n");
Expand Down Expand Up @@ -726,10 +723,9 @@ int
issue_serverpaste(TextNode *command)
{
char *buf;
int ret_val;

ret_val = connect_spad();
if (ret_val == NotConnected || ret_val == SpadBusy)
auto status = connect_spad();
if (status == SpadStatus::NotConnected || status == SpadStatus::SpadBusy)
return 1;
switch_frames();
send_int(spad_socket, LispCommand);
Expand Down Expand Up @@ -832,10 +828,8 @@ switch_frames()

void send_lisp_command(const char* command)
{
int ret_val;

ret_val = connect_spad();
if (ret_val == NotConnected || ret_val == SpadBusy) {
auto status = connect_spad();
if (status == SpadStatus::NotConnected || status == SpadStatus::SpadBusy) {
return;
}
send_int(spad_socket, LispCommand);
Expand Down

0 comments on commit b0863d9

Please sign in to comment.