Skip to content

Commit

Permalink
[hyper] Token types are now of enum class type (#42)
Browse files Browse the repository at this point in the history
* Rename `openaxiom_token_kind` to `OpenAxiom::TokenType`.  Remove `_token` suffix of associated enumerators.

* This stronger typing catches various value confusions and an existing bug where `>=` was mistyped as `> -` and went undetected for as long as this component has existed.
  • Loading branch information
GabrielDosReis authored Dec 29, 2023
1 parent 0e43cf9 commit c18ddc9
Show file tree
Hide file tree
Showing 26 changed files with 1,597 additions and 1,602 deletions.
18 changes: 10 additions & 8 deletions src/hyper/cond.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
Copyright (C) 2007-2010, Gabriel Dos Reis.
Copyright (C) 2007-2023, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -49,6 +49,8 @@
#include "hyper.h"
#include "sockio.h"

using namespace OpenAxiom;

static int check_memostack(TextNode * node);

void
Expand Down Expand Up @@ -120,29 +122,29 @@ check_condition(TextNode *node)

/* checks the condition presented and returns a 1 or a 0 */
switch (node->type) {
case openaxiom_Cond_token:
case TokenType::Cond:
cond = (CondNode *) hash_find(gWindow->fCondHashTable, node->data.text);
if (!strcmp("0", cond->cond))
return 0;
else
return 1;
case openaxiom_Boxcond_token:
case TokenType::Boxcond:
box = (InputBox *) hash_find(gWindow->page->box_hash, node->data.text);
return (box->picked);
case openaxiom_Haslisp_token:
case TokenType::Haslisp:
if (spad_socket != NULL) {
ret_val = send_int(spad_socket, TestLine);
return (ret_val + 1);
}
else
return 0;
case openaxiom_Hasup_token:
case TokenType::Hasup:
return need_up_button;
case openaxiom_Hasreturn_token:
case TokenType::Hasreturn:
return gWindow->fMemoStackIndex;
case openaxiom_Hasreturnto_token:
case TokenType::Hasreturnto:
return (check_memostack(node));
case openaxiom_Lastwindow_token:
case TokenType::Lastwindow:
return (gSessionHashTable.num_entries == 1 || gParentWindow == gWindow);
default:
return 0;
Expand Down
19 changes: 10 additions & 9 deletions src/hyper/display.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
Copyright (C) 2007-2010, Gabriel Dos Reis.
Copyright (C) 2007-2023, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -65,6 +65,7 @@
#include "titlebar.h"
#include "parse-types.h"

using namespace OpenAxiom;

extern ItemStack *gTopOfItemStack;
short int gDisplayRegion = 0;
Expand Down Expand Up @@ -146,22 +147,22 @@ show_page(HyperDocPage *page)
gRegionOffset = 0;
y_off = 0;
gDisplayRegion = Header;
show_text(page->header->next, openaxiom_Endheader_token);
show_text(page->header->next, TokenType::Endheader);

if (doShowScrollBars && page->scrolling) {
/* Show the footer */
if (page->footer->next) {
gDisplayRegion = Footer;
gRegionOffset = gWindow->page->bot_scroll_margin +
(!((gWindow->page->page_flags & NOLINES)) ? ((int) line_height / 2) : (0));
show_text(page->footer->next, openaxiom_Endfooter_token);
show_text(page->footer->next, TokenType::Endfooter);
/* Show the scrolling region */
if (page->scrolling->next)
gDisplayRegion = Scrolling;
gRegionOffset = 0;
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
y_off = gWindow->page->scroll_off;
show_text(page->scrolling->next, openaxiom_Endscrolling_token);
show_text(page->scrolling->next, TokenType::Endscrolling);
showScrollBars(gWindow);
}
drawScrollLines();
Expand All @@ -188,7 +189,7 @@ expose_page(HyperDocPage *page)
gWindow->fDisplayedWindow = gWindow->fMainWindow;
gRegionOffset = 0;
gDisplayRegion = Header;
show_text(page->header->next, openaxiom_Endheader_token);
show_text(page->header->next, TokenType::Endheader);
getScrollBarMinimumSize(&width, &height);

/*
Expand All @@ -199,7 +200,7 @@ expose_page(HyperDocPage *page)
gDisplayRegion = Footer;
gRegionOffset = gWindow->page->bot_scroll_margin +
(!((gWindow->page->page_flags & NOLINES)) ? ((int) line_height / 2) : (0));
show_text(page->footer->next, openaxiom_Endfooter_token);
show_text(page->footer->next, TokenType::Endfooter);
}

if (height > gWindow->scrollheight) {
Expand All @@ -215,7 +216,7 @@ expose_page(HyperDocPage *page)
gRegionOffset = 0;
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
y_off = gWindow->page->scroll_off;
show_text(page->scrolling->next, openaxiom_Endscrolling_token);
show_text(page->scrolling->next, TokenType::Endscrolling);
if (doShowScrollBars)
showScrollBars(gWindow);
}
Expand All @@ -239,7 +240,7 @@ scroll_page(HyperDocPage *page)
gRegionOffset = 0;
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
y_off = gWindow->page->scroll_off;
show_text(page->scrolling->next, openaxiom_Endscrolling_token);
show_text(page->scrolling->next, TokenType::Endscrolling);
moveScroller(gWindow);
XFlush(gXDisplay);
}
Expand Down Expand Up @@ -282,7 +283,7 @@ paste_page(TextNode *node)
else
XClearWindow(gXDisplay, gWindow->fScrollWindow);

show_text(gWindow->page->scrolling->next, openaxiom_Endscrolling_token);
show_text(gWindow->page->scrolling->next, TokenType::Endscrolling);
XFlush(gXDisplay);
hideScrollBars(gWindow);

Expand Down
104 changes: 53 additions & 51 deletions src/hyper/event.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
Copyright (C) 2007-2010, Gabriel Dos Reis.
Copyright (C) 2007-2023, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -59,6 +59,8 @@
#include "lex.h"
#include "sockio.h"

using namespace OpenAxiom;

Window gActiveWindow;
int motion = 0;
int gNeedIconName = 0;
Expand Down Expand Up @@ -151,7 +153,7 @@ findButtonInList(HDWindow * window, int x, int y)
{
ButtonList *bl;

if (!window || window->page->type == UnloadedPageType)
if (!window || window->page->type == TokenType::UnloadedPageType)
return NULL;
for (bl = window->page->s_button_list; bl != NULL; bl = bl->next)
if (x >= bl->x0 && x <= bl->x1 && y >= bl->y0 && y <= bl->y1)
Expand Down Expand Up @@ -272,7 +274,7 @@ static void
kill_page(HyperDocPage * page)
{
page->scroll_off = 0;
if (page->type == SpadGen) {
if (page->type == TokenType::SpadGen) {
hash_delete(gWindow->fPageHashTable, page->name);
killAxiomPage(page);
free_page(page);
Expand Down Expand Up @@ -340,10 +342,10 @@ find_page(TextNode * node)
fprintf(stderr, "Unknown page name %s\n", page_name);
}
else {
if (page->type == UnloadedPageType)
page->type = UlUnknownPage;
if (page->type == TokenType::UnloadedPageType)
page->type = TokenType::UlUnknownPage;
else
page->type = UnknownPage;
page->type = TokenType::UnknownPage;
}
}
return page;
Expand Down Expand Up @@ -431,9 +433,9 @@ create_window()
*/

#define NotSpecial(t) \
((t == openaxiom_Quitbutton_token || t == openaxiom_Returnbutton_token \
|| t == openaxiom_Upbutton_token || t == UnknownPage \
|| t == UlUnknownPage || t == ErrorPage) \
((t == TokenType::Quitbutton || t == TokenType::Returnbutton \
|| t == TokenType::Upbutton || t == TokenType::UnknownPage \
|| t == TokenType::UlUnknownPage || t == TokenType::ErrorPage) \
?(0):(1))

/*
Expand All @@ -458,28 +460,28 @@ handle_button(int button, XButtonEvent * event)
}

switch (link->type) {
case openaxiom_Pastebutton_token:
case TokenType::Pastebutton:
page = paste_button(link->reference.paste);
break;
case openaxiom_Link_token:
case TokenType::Link:
page_name = print_to_string(link->reference.node);
page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, page_name);
break;
case openaxiom_Helpbutton_token:
case TokenType::Helpbutton:
helpForHyperDoc();
page = NULL;
break;
case openaxiom_Scrollbar_token:
case TokenType::Scrollbar:
scrollScroller(event);
break;
case Scrollupbutton:
case TokenType::Scrollupbutton:
scrollUp();
break;
case Scrolldownbutton:
case TokenType::Scrolldownbutton:
scrollDown();
break;

case openaxiom_Inputstring_token:
case TokenType::Inputstring:
/* We must be changing input focus or getting a selection */

change_input_focus(link);
Expand All @@ -491,86 +493,86 @@ handle_button(int button, XButtonEvent * event)
}
break;

case openaxiom_SimpleBox_token:
case TokenType::SimpleBox:
page = NULL;
toggle_input_box(link);
break;
case openaxiom_Radiobox_token:
case TokenType::Radiobox:
page = NULL;
toggle_radio_box(link);
break;
case openaxiom_Quitbutton_token:
case TokenType::Quitbutton:
quitHyperDoc();
break;
case openaxiom_Returnbutton_token: /* pop memo information */
case TokenType::Returnbutton: /* pop memo information */
page = returnlink();
break;
case openaxiom_Upbutton_token: /* pop downlink information */
case TokenType::Upbutton: /* pop downlink information */
page = uplink();
break;
case openaxiom_Downlink_token:
case TokenType::Downlink:
page = find_page(link->reference.node);
if (page && NotSpecial(page->type))
downlink();
break;
case openaxiom_Memolink_token:
case TokenType::Memolink:
page = find_page(link->reference.node);
if (page && NotSpecial(page->type))
memolink();
break;
case openaxiom_Windowlink_token:
case TokenType::Windowlink:
page = find_page(link->reference.node);
if (page && NotSpecial(page->type)) {
windowlink_handler(link->reference.node);
gNeedIconName = 1;
page = NULL;
}
break;
case openaxiom_Lispwindowlink_token:
case TokenType::Lispwindowlink:
lispwindowlink_handler(link);
gNeedIconName = 1;
page = NULL;
break;
case openaxiom_LispMemoLink_token:
case openaxiom_Spadmemolink_token:
case TokenType::LispMemoLink:
case TokenType::Spadmemolink:
page = issue_server_command(link);
if (page && NotSpecial(page->type))
memolink();
break;
case openaxiom_LispDownLink_token:
case openaxiom_Spaddownlink_token:
case TokenType::LispDownLink:
case TokenType::Spaddownlink:
page = issue_server_command(link);
if (page && NotSpecial(page->type))
downlink();
break;
case openaxiom_Spadlink_token:
case openaxiom_Lisplink_token:
case TokenType::Spadlink:
case TokenType::Lisplink:
page = issue_server_command(link);
break;
case openaxiom_Lispcommand_token:
case openaxiom_Qspadcall_token:
case openaxiom_Spadcall_token:
case TokenType::Lispcommand:
case TokenType::Qspadcall:
case TokenType::Spadcall:
page = issue_server_command(link);
break;
case openaxiom_Lispcommandquit_token:
case openaxiom_Spadcallquit_token:
case openaxiom_Qspadcallquit_token:
case TokenType::Lispcommandquit:
case TokenType::Spadcallquit:
case TokenType::Qspadcallquit:
page = issue_server_command(link);
exitHyperDoc();
break;
case openaxiom_Spadcommand_token:
case openaxiom_Spadgraph_token:
case openaxiom_Spadsrc_token:
case TokenType::Spadcommand:
case TokenType::Spadgraph:
case TokenType::Spadsrc:
issue_spadcommand(gWindow->page, link->reference.node,
button == Button1, link->type);
break;
case openaxiom_Unixlink_token:
case TokenType::Unixlink:
page = issue_unixlink(link->reference.node);
if (page && NotSpecial(page->type)) {
downlink();
}
break;
case openaxiom_Unixcommand_token:
case TokenType::Unixcommand:
issue_unixcommand(link->reference.node);
break;
default:
Expand All @@ -579,28 +581,28 @@ handle_button(int button, XButtonEvent * event)

if (page) {
switch (page->type) { /* check for special button types */
case openaxiom_Quitbutton_token:
case TokenType::Quitbutton:
exitHyperDoc();
return;
case openaxiom_Returnbutton_token:
case TokenType::Returnbutton:
gWindow->page = returnlink();
break;
case openaxiom_Upbutton_token:
case TokenType::Upbutton:
gWindow->page = uplink();
break;
case ErrorPage:
case UnknownPage:
case UlUnknownPage:
if (page->type == UlUnknownPage)
page->type = UnloadedPageType;
case TokenType::ErrorPage:
case TokenType::UnknownPage:
case TokenType::UlUnknownPage:
if (page->type == TokenType::UlUnknownPage)
page->type = TokenType::UnloadedPageType;
downlink();
gWindow->page = page;
break;
default: /* a normal link */
gWindow->page = page;
break;
}
if (link->type != openaxiom_Pastebutton_token)
if (link->type != TokenType::Pastebutton)
display_page(gWindow->page);
gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; /* reset the window hash */
}
Expand Down
Loading

0 comments on commit c18ddc9

Please sign in to comment.