Skip to content

Commit

Permalink
kernel: change GetHelp to produce string obj
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored and ChrisJefferson committed Apr 22, 2018
1 parent dbcdcf0 commit b03bc7b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ typedef struct GAPState {
/* From scanner.c */
Obj ValueObj;
Char Value[MAX_VALUE_LEN];
UInt ValueLen;
UInt NrError;
UInt NrErrLine;
UInt Symbol;
Expand Down
6 changes: 2 additions & 4 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2569,10 +2569,8 @@ void ReadTryNext (

void ReadHelp(TypSymbolSet follow)
{
Obj topic;

C_NEW_STRING(topic, STATE(ValueLen), (void *)STATE(Value));
TRY_READ { IntrHelp(topic); };
TRY_READ { IntrHelp(STATE(ValueObj)); }
STATE(ValueObj) = 0;
}

/****************************************************************************
Expand Down
32 changes: 21 additions & 11 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,20 +887,30 @@ static void GetChar(void)

static void GetHelp(void)
{
Int i = 0;
Obj string = 0;
Char buf[1024];
UInt i;

/* Skip the first ? */
// Skip the leading '?'
Char c = GET_NEXT_CHAR();
while (i < SAFE_VALUE_SIZE-1 &&
c != '\n' &&
c != '\r' &&
c != '\377') {
STATE(Value)[i] = c;
i++;

for (i = 0; c != '\n' && c != '\r' && c != '\377'; i++) {
// if 'buf' is full, copy it into 'string' and then reset it
if (i >= sizeof(buf)) {
string = AppendBufToString(string, buf, i);
i = 0;
}
buf[i] = c;
c = GET_NEXT_CHAR();
}
STATE(Value)[i] = '\0';
STATE(ValueLen) = i;
string = AppendBufToString(string, buf, i);

// ensure that the string has a terminator
const UInt len = GET_LEN_STRING(string);
CSTR_STRING(string)[len] = '\0';

STATE(ValueObj) = string;
STATE(Symbol) = S_HELP;
}

/****************************************************************************
Expand Down Expand Up @@ -996,7 +1006,7 @@ static void NextSymbol(void)
case '^': STATE(Symbol) = S_POW; GET_NEXT_CHAR(); break;

case '~': STATE(Symbol) = S_TILDE; GET_NEXT_CHAR(); break;
case '?': STATE(Symbol) = S_HELP; GetHelp(); break;
case '?': GetHelp(); break;
case '"': GetMaybeTripStr(); break;
case '\'': GetChar(); break;
case '\\': GetIdent(0); break;
Expand Down
1 change: 0 additions & 1 deletion src/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ typedef UInt TypSymbolSet;
** it hard for the scanner to carry on correctly.
*/
/* TL: extern Char Value [1030]; */
/* TL: extern UInt ValueLen; */

#define SAFE_VALUE_SIZE 1024

Expand Down

0 comments on commit b03bc7b

Please sign in to comment.