diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hyper/event.c | 10 | ||||
-rw-r--r-- | src/hyper/lex.c | 16 | ||||
-rw-r--r-- | src/hyper/lex.h | 3 | ||||
-rw-r--r-- | src/hyper/node.h | 5 | ||||
-rw-r--r-- | src/hyper/parse-aux.c | 20 | ||||
-rw-r--r-- | src/hyper/parse-paste.c | 28 | ||||
-rw-r--r-- | src/hyper/parse.c | 8 | ||||
-rw-r--r-- | src/hyper/parse.h | 4 | ||||
-rw-r--r-- | src/hyper/token.h | 22 |
9 files changed, 60 insertions, 56 deletions
diff --git a/src/hyper/event.c b/src/hyper/event.c index 3e90e5ad..c390d6d2 100644 --- a/src/hyper/event.c +++ b/src/hyper/event.c @@ -240,7 +240,7 @@ static HyperDocPage * paste_button(PasteNode * paste) { HyperDocPage *page = NULL; - int pastewhere=paste->where; + auto pastewhere = paste->where; if ( paste->end_node ==NULL || paste->begin_node==NULL || paste->arg_node==NULL ){ @@ -251,7 +251,7 @@ paste_button(PasteNode * paste) page=parse_patch(paste); /* paste has changed after this call so use pastewhere*/ - if (pastewhere && page ) { + if (pastewhere != SourceInputKind{ } && page ) { if (0 == strcmp(page->name, "ErrorPage")) page = NULL; } @@ -866,7 +866,7 @@ get_new_window(void) init_top_window(NULL); val = get_int(spad_socket); init_scanner(); - input_type = openaxiom_FromSpadSocket_input; + input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); gWindow->fAxiomFrame = frame; @@ -885,7 +885,7 @@ get_new_window(void) init_form_window(NULL, val); send_int(spad_socket, gWindow->fMainWindow); init_scanner(); - input_type = openaxiom_FromSpadSocket_input; + input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); compute_form_page(gWindow->page); @@ -935,7 +935,7 @@ get_new_window(void) wid = (Window) get_int(spad_socket); set_window(wid); init_scanner(); - input_type = openaxiom_FromSpadSocket_input; + input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); display_page(gWindow->page); diff --git a/src/hyper/lex.c b/src/hyper/lex.c index 85e3d511..f06a498d 100644 --- a/src/hyper/lex.c +++ b/src/hyper/lex.c @@ -103,7 +103,7 @@ long page_start_fpos; /* where the current pages fpos started */ long keyword_fpos; /* fpos of beginning of most recent keyword */ Token token; /* most recently read token */ int last_token; /* most recently read token for unget_token */ -int input_type; /* indicates where to read input */ +SourceInputKind input_type; /* indicates where to read input */ char *input_string; /* input string read when from_string is true */ int last_ch; /* last character read, for unget_char */ int last_command; /* the last socket command */ @@ -265,7 +265,7 @@ init_scanner(void) keyword = 0; last_ch = NoChar; last_token = 0; - input_type = openaxiom_FromFile_input; + input_type = SourceInputKind::File; fpos = 0; keyword_fpos = 0; last_command = -1; @@ -396,23 +396,23 @@ get_char1(void) return c; } switch (input_type) { - case openaxiom_FromUnixFD_input: + case SourceInputKind::UnixFD: c = getc(unixfd); if (c == '\n') line_number++; return c; - case openaxiom_FromString_input: + case SourceInputKind::String: c = (*input_string ? *input_string++ : EOF); if (c == '\n') line_number++; return c; - case openaxiom_FromFile_input: + case SourceInputKind::File: c = getc(cfile); fpos++; if (c == '\n') line_number++; return c; - case openaxiom_FromSpadSocket_input: + case SourceInputKind::SpadSocket: AGAIN: if (*input_string) { /* this should never happen for the first character */ @@ -512,14 +512,14 @@ get_token(void) *buf++ = 0; keyword = 0; - if (input_type != openaxiom_FromSpadSocket_input && c == '%') { + if (input_type != SourceInputKind::SpadSocket && c == '%') { while ((c = get_char()) != '\n' && c != EOF); /* trying to fix the comment problem: a comment line forces words on either side together*/ /* try returning the eol */ unget_char(c); return get_token(); } - if (input_type == openaxiom_FromFile_input && c == '$') { + if (input_type == SourceInputKind::File && c == '$') { token.type = openaxiom_Dollar_token; return 0; } diff --git a/src/hyper/lex.h b/src/hyper/lex.h index 3a7fd8f9..ce518341 100644 --- a/src/hyper/lex.h +++ b/src/hyper/lex.h @@ -67,7 +67,8 @@ extern void print_next_ten_tokens(void); extern long fpos, keyword_fpos; extern Token token; -extern int last_token, input_type, last_ch; +extern int last_token, last_ch; +extern SourceInputKind input_type; extern char *input_string; extern FILE *cfile; extern short int gInSpadsrc; diff --git a/src/hyper/node.h b/src/hyper/node.h index fadc575f..9573d80d 100644 --- a/src/hyper/node.h +++ b/src/hyper/node.h @@ -81,7 +81,8 @@ struct GroupItem; /** I am implementing a state node stack, this is the structure I store **/ typedef struct StateNode { - int last_ch, last_token, input_type; + int last_ch, last_token; + SourceInputKind input_type; long fpos, keyword_fpos; long page_start_fpos; Token token; @@ -124,7 +125,7 @@ typedef struct ItemStack { typedef struct PasteNode { char *name; - int where; /* where should I be parsing from? */ + SourceInputKind where; /* where should I be parsing from? */ short int hasbutton; short int haspaste; struct GroupItem *group; diff --git a/src/hyper/parse-aux.c b/src/hyper/parse-aux.c index 30957cce..df268c05 100644 --- a/src/hyper/parse-aux.c +++ b/src/hyper/parse-aux.c @@ -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-2016, Gabriel Dos Reis. All rights reverved. Redistribution and use in source and binary forms, with or without @@ -575,33 +575,33 @@ get_input_string(void) * tries to determine if there is an optional argument for where I should be * parsing from. If so it then tries to determine which */ -int -get_where(void) +SourceInputKind +get_where() { - int tw; + SourceInputKind tw; get_token(); if (token.type != openaxiom_Word_token) - return -1; + return SourceInputKind::Error; /* Now try to determine if it is a good type */ if (!strcmp(token.id, "lisp")) { - tw = openaxiom_FromSpadSocket_input; + tw = SourceInputKind::SpadSocket; } else if (!strcmp(token.id, "unix")) { - tw = openaxiom_FromUnixFD_input; + tw = SourceInputKind::UnixFD; } else if (!strcmp(token.id, "ht")) { - tw = openaxiom_FromFile_input; + tw = SourceInputKind::File; } else { - return -1; + return SourceInputKind::Error; } /* now check to see if I got a closing square brace */ get_token(); if (token.type != openaxiom_Rsquarebrace_token) - return -1; + return SourceInputKind::Error; return tw; } diff --git a/src/hyper/parse-paste.c b/src/hyper/parse-paste.c index c8d67c85..f129f474 100644 --- a/src/hyper/parse-paste.c +++ b/src/hyper/parse-paste.c @@ -61,7 +61,7 @@ parse_paste(void) { TextNode *pn = curr_node; PasteNode *paste; - int where; + SourceInputKind where; if (gParserRegion != Scrolling) { fprintf(stderr, "(HyperDoc) Paste areas are only allowed in the scrolling area:"); @@ -101,8 +101,8 @@ parse_paste(void) if (token.type == openaxiom_Lsquarebrace_token) { /* user wishes to specify a where to send the command */ where = get_where(); - if (where == -1) { - paste->where = -1; + if (where == SourceInputKind::Error) { + paste->where = where; fprintf(stderr, "(HyperDoc) \\begin{paste} was expecting [lisp|unix|ht]\n"); print_next_ten_tokens(); print_page_and_filename(); @@ -113,11 +113,11 @@ parse_paste(void) get_token(); } else - paste->where = openaxiom_FromFile_input; + paste->where = SourceInputKind::File; /* now try to get the command argument or page name */ if (token.type != openaxiom_Lbrace_token) { - paste->where = 0; + paste->where = { }; fprintf(stderr, "(HyperDoc) \\begin{paste} was expecting an argument\n"); print_next_ten_tokens(); print_page_and_filename(); @@ -216,7 +216,7 @@ parse_patch(PasteNode *paste) TextNode *old; TextNode *next_node; InputItem *paste_item = paste->paste_item; - int where = paste->where; + SourceInputKind where = paste->where; GroupItem *g = paste->group; ItemStack *is = paste->item_stack; PatchStore *patch; @@ -233,7 +233,7 @@ parse_patch(PasteNode *paste) /* now read the new stuff and add it in between all this stuff */ switch (where) { - case openaxiom_FromFile_input: + case SourceInputKind::File: patch_name = print_to_string(arg_node); patch = (PatchStore *) hash_find(gWindow->fPatchHashTable, patch_name); if (!patch) { @@ -243,11 +243,11 @@ parse_patch(PasteNode *paste) } if (!patch->loaded) load_patch(patch); - input_type = openaxiom_FromString_input; + input_type = SourceInputKind::String; input_string = patch->string; break; - case openaxiom_FromSpadSocket_input: - input_type = openaxiom_FromSpadSocket_input; + case SourceInputKind::SpadSocket: + input_type = SourceInputKind::SpadSocket; ret_value = issue_serverpaste(arg_node); if (ret_value < 0) { paste->where = where; @@ -259,8 +259,8 @@ parse_patch(PasteNode *paste) return 0; } break; - case openaxiom_FromUnixFD_input: - input_type = openaxiom_FromUnixFD_input; + case SourceInputKind::UnixFD: + input_type = SourceInputKind::UnixFD; issue_unixpaste(arg_node); break; default: @@ -269,7 +269,7 @@ parse_patch(PasteNode *paste) break; } - paste->where = 0; + paste->where = { }; paste->end_node = paste->arg_node = paste->begin_node = 0; paste->group = 0; paste->item_stack = 0; @@ -296,7 +296,7 @@ parse_patch(PasteNode *paste) paste->name); jump(); } - if (input_type == openaxiom_FromString_input) { + if (input_type == SourceInputKind::String) { get_token(); if (token.type != openaxiom_Lbrace_token) { token_name(token.type); diff --git a/src/hyper/parse.c b/src/hyper/parse.c index 69527334..e53242e8 100644 --- a/src/hyper/parse.c +++ b/src/hyper/parse.c @@ -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-2016, Gabriel Dos Reis. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -234,7 +234,7 @@ parse_from_string(char *str) last_ch = NoChar; last_token = 0; input_string = str; - input_type = openaxiom_FromString_input; + input_type = SourceInputKind::String; parse_HyperDoc(); restore_scanner_state(); } @@ -711,7 +711,7 @@ parse_page_from_socket(void) HyperDocPage *hpage; init_scanner(); - input_type = openaxiom_FromSpadSocket_input; + input_type = SourceInputKind::SpadSocket; input_string = ""; cur_spadcom = NULL; gLinkHashTable = page->fLinkHashTable; @@ -755,7 +755,7 @@ parse_page_from_unixfd(void) HyperDocPage *page = alloc_page((char *) NULL); init_scanner(); - input_type = openaxiom_FromUnixFD_input; + input_type = SourceInputKind::UnixFD; cur_spadcom = NULL; gLinkHashTable = page->fLinkHashTable; hash_init( diff --git a/src/hyper/parse.h b/src/hyper/parse.h index 3c9b90bd..90374ac7 100644 --- a/src/hyper/parse.h +++ b/src/hyper/parse.h @@ -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-2016, Gabriel Dos Reis. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -81,7 +81,7 @@ extern void read_ht_db(HashTable * page_hash , HashTable * macro_hash , HashTabl extern int get_filename(void); extern int is_number(const char * str); extern void parser_error(char * str); -extern int get_where(void); +extern SourceInputKind get_where(); extern void scan_HyperDoc(void); extern int number(const char * str); extern ParameterList init_parameter_elem(int number); diff --git a/src/hyper/token.h b/src/hyper/token.h index c9bdf121..b40d069a 100644 --- a/src/hyper/token.h +++ b/src/hyper/token.h @@ -49,15 +49,15 @@ /* HyperDoc parser tokens */ -typedef struct Token { +struct Token { int type; /* token type. One of those listed below */ const char *id; /* string value if type == Identifier */ -} Token; +}; /* User tokens. ie, these can be found on a page */ -typedef enum openaxiom_token_kind { +enum openaxiom_token_kind { openaxiom_Word_token = 1, openaxiom_Page_token = 2, openaxiom_Lispcommandquit_token = 3, @@ -236,19 +236,21 @@ typedef enum openaxiom_token_kind { openaxiom_Endmath_token = 4016, openaxiom_Endpaste_token = 4029, openaxiom_Endspadsrc_token = 4030 -} openaxiom_token_kind; +}; extern const char *token_table[]; /* places from which input may be read */ -typedef enum openaxiom_input_kind { - openaxiom_FromFile_input = 1, - openaxiom_FromString_input = 2, - openaxiom_FromSpadSocket_input = 3, - openaxiom_FromUnixFD_input = 4 -} openaxiom_input_kind; +enum class SourceInputKind { + Error = -1, + + File = 1, + String = 2, + SpadSocket = 3, + UnixFD = 4 +}; extern FILE *unixfd; |