Skip to content

Commit

Permalink
Merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Oct 18, 2024
2 parents 96fef99 + 5c28a90 commit 96eb7ea
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lang/cem/cpp.ansi/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "replace.h"
#include "domacro.h"

#define INP_PUSHBACK 3
#define INP_NPUSHBACK 3
#define INP_TYPE struct file_info
#define INP_VAR finfo
struct file_info finfo;
Expand All @@ -23,7 +23,6 @@ struct file_info finfo;
char* getwdir(register char* fn)
{
register char* p;
char* strrchr();

p = strrchr(fn, '/');
while (p && *(p + 1) == '\0')
Expand Down
1 change: 1 addition & 0 deletions lang/m2/comp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "f_info.h"
struct f_info file_info;
#include "input.h"
#include "error.h"
#include <inp_pkg.body>


Expand Down
1 change: 1 addition & 0 deletions lang/pc/comp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct f_info file_info;
#include "input.h"
#include <em_arith.h>
#include "idf.h"
#include "error.h"
#include <inp_pkg.body>


Expand Down
24 changes: 17 additions & 7 deletions modules/src/input/inp_pkg.body
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ struct INP_i_buf {

#endif /* not INP_READ_IN_ONE */

/* Used for the pushback buffer when between input files, where INP_head isn't
* valid. */
static char INP_pushbackbuf[INP_NPUSHBACK + 1];

char *_ipp;
INP_PRIVATE struct INP_buffer_header *INP_head, *INP_free;

Expand Down Expand Up @@ -331,6 +335,13 @@ int InsertText(char *text, int length)
return 1;
}

void INP_pushback(void)
{
if ((_ipp == INP_head->bh_text) || (_ipp == &INP_pushbackbuf[0]))
fatal("inp underflow\n");
_ipp--;
}

#define RAWLOAD(dest) \
((void)((dest = *_ipp++) || (dest = loadbuf())))

Expand Down Expand Up @@ -361,7 +372,6 @@ int loadchar(void)
int loadbuf(void)
{
register struct INP_buffer_header *bh = INP_head;
static char buf[INP_NPUSHBACK + 1];
int FromFile;

if (!bh) { /* stack exhausted, EOF on sourcefile */
Expand Down Expand Up @@ -404,7 +414,7 @@ int loadbuf(void)
#if INP_NPUSHBACK > 1
{
register char *so = &(bh->bh_text[bh->bh_size]);
register char *de = &buf[INP_NPUSHBACK - 1];
register char *de = &INP_pushbackbuf[INP_NPUSHBACK - 1];
register int i = INP_NPUSHBACK - 1;

if (i >= bh->bh_size) i = bh->bh_size - 1;
Expand All @@ -414,8 +424,8 @@ int loadbuf(void)
}
}
#endif
buf[INP_NPUSHBACK-1] = 0; /* make PushBack work on EOI */
_ipp = &buf[INP_NPUSHBACK];
INP_pushbackbuf[INP_NPUSHBACK-1] = 0; /* make PushBack work on EOI */
_ipp = &INP_pushbackbuf[INP_NPUSHBACK];

if (bh->bh_fd) { /* unstack a file */
#ifndef INP_READ_IN_ONE
Expand All @@ -428,7 +438,7 @@ int loadbuf(void)
free(bh->bh_text);
#endif /* INP_READ_IN_ONE */
}
bh->bh_text = buf;
bh->bh_text = INP_pushbackbuf;
bh->bh_size = INP_NPUSHBACK - 1;
if (FromFile) {
if (AtEoIF()) {
Expand All @@ -444,7 +454,7 @@ int loadbuf(void)
}
}

if (bh->bh_eofreturned && _ipp == &buf[INP_NPUSHBACK]) {
if (bh->bh_eofreturned && _ipp == &INP_pushbackbuf[INP_NPUSHBACK]) {
return EOI;
}

Expand All @@ -453,6 +463,6 @@ int loadbuf(void)
LoadChar(c);
return c;
}
_ipp = &buf[INP_NPUSHBACK];
_ipp = &INP_pushbackbuf[INP_NPUSHBACK];
return EOI;
}
7 changes: 5 additions & 2 deletions modules/src/input/inp_pkg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
/* INPUT PRIMITIVES */

#define LoadChar(dest) (dest = loadchar())
#define PushBack() (--_ipp)
#define ChPushBack(ch) (*--_ipp = (ch))

extern void INP_pushback(void);
#define PushBack INP_pushback

#define ChPushBack(ch) (INP_pushback(), *_ipp = (ch))

/* EOI may be defined as -1 in most programs but the character -1 may
be expanded to the int -1 which causes troubles with indexing.
Expand Down

0 comments on commit 96eb7ea

Please sign in to comment.