Skip to content

Commit

Permalink
Switch to using a typedef (zbuff_t) for the z buffers. Makes it easier
Browse files Browse the repository at this point in the history
to distinguish low level from high level buffers.
  • Loading branch information
smaclennan committed Jul 15, 2018
1 parent e45bc43 commit 930fdb0
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 82 deletions.
44 changes: 22 additions & 22 deletions bcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ static char **Bnames; /* array of ptrs to buffer names */
static int Numbnames; /* number of buffers */
static int Maxbnames; /* max buffers Bnames can hold */

struct zbuff *Bufflist; /* the buffer list */
static struct zbuff *Bufflist_tail;
struct zbuff *Curbuff; /* the current buffer */
zbuff_t *Bufflist; /* the buffer list */
static zbuff_t *Bufflist_tail;
zbuff_t *Curbuff; /* the current buffer */
struct buff *Bbuff; /* the current low-level buffer */

/* Set Lbufname */
void set_last_bufname(struct zbuff *buff)
void set_last_bufname(zbuff_t *buff)
{
strlcpy(Lbufname, buff->bname, sizeof(Lbufname));
}
Expand Down Expand Up @@ -76,7 +76,7 @@ char *getbtxt(char txt[], int max)
static void switchto_part(void)
{
char word[STRMAX + 1];
struct zbuff *tbuff;
zbuff_t *tbuff;

getbtxt(word, STRMAX);
tbuff = cfindbuff(word);
Expand All @@ -92,7 +92,7 @@ static void switchto_part(void)
void Zswitch_to_buffer(void)
{
int rc;
struct zbuff *was = Curbuff;
zbuff_t *was = Curbuff;

Arg = 0;
Nextpart = switchto_part;
Expand All @@ -107,7 +107,7 @@ void Zswitch_to_buffer(void)

void Znext_buffer(void)
{
struct zbuff *next = Curbuff->next;
zbuff_t *next = Curbuff->next;

if (!next)
next = Bufflist;
Expand All @@ -120,7 +120,7 @@ void Znext_buffer(void)
tbell();
}

static void delbuff(struct zbuff *buff)
static void delbuff(zbuff_t *buff)
{
struct wdo *wdo;

Expand Down Expand Up @@ -148,7 +148,7 @@ static void delbuff(struct zbuff *buff)

void Zdelete_buffer(void)
{
struct zbuff *tbuff;
zbuff_t *tbuff;
char bname[BUFNAMMAX + 1];

if (Argp) {
Expand Down Expand Up @@ -178,7 +178,7 @@ char *limit(char *fname, int num)
return off > 0 ? fname + off : fname;
}

static void lstbuff(struct zbuff *tbuff)
static void lstbuff(zbuff_t *tbuff)
{
binstr(Bbuff, "%-16s %s%s %8u %s\n", tbuff->bname,
(tbuff->bmode & SYSBUFF) ? "S" : " ",
Expand All @@ -194,7 +194,7 @@ void Zlist_buffers(void)

if (wuseother(LISTBUFF)) {
for (i = 0; i < Numbnames; ++i) {
struct zbuff *tbuff = cfindbuff(Bnames[i]);
zbuff_t *tbuff = cfindbuff(Bnames[i]);
if (tbuff)
lstbuff(tbuff);
else if (strcmp(Bnames[i], "*paw*"))
Expand Down Expand Up @@ -295,17 +295,17 @@ static void binit(void)
}

/* Create a buffer and add to Bufflist. Do not switch to buffer. */
struct zbuff *zcreatebuff(const char *bname, char *fname)
zbuff_t *zcreatebuff(const char *bname, char *fname)
{
struct zbuff *bptr;
zbuff_t *bptr;

bptr = cfindbuff(bname);
if (bptr)
return bptr;

binit();

if (!(bptr = calloc(1, sizeof(struct zbuff))) ||
if (!(bptr = calloc(1, sizeof(zbuff_t))) ||
!(bptr->buff = bcreate()) ||
(fname && !(bptr->fname = strdup(fname)))) {
bdelbuff(bptr->buff);
Expand Down Expand Up @@ -344,14 +344,14 @@ struct zbuff *zcreatebuff(const char *bname, char *fname)
}

/* Create a buffer and add to Bufflist. Switch to buffer. */
struct zbuff *cmakebuff(const char *bname, char *fname)
zbuff_t *cmakebuff(const char *bname, char *fname)
{
struct zbuff *bptr = zcreatebuff(bname, fname);
zbuff_t *bptr = zcreatebuff(bname, fname);
zswitchto(bptr);
return bptr;
}

void zswitchto(struct zbuff *buf)
void zswitchto(zbuff_t *buf)
{
if (buf && buf != Curbuff) {
Curbuff = buf;
Expand All @@ -360,7 +360,7 @@ void zswitchto(struct zbuff *buf)
}
}

bool cdelbuff(struct zbuff *tbuff)
bool cdelbuff(zbuff_t *tbuff)
{
if (!tbuff)
return false;
Expand Down Expand Up @@ -409,19 +409,19 @@ bool cdelbuff(struct zbuff *tbuff)
}

/* Locate a given buffer */
struct zbuff *cfindbuff(const char *bname)
zbuff_t *cfindbuff(const char *bname)
{
struct zbuff *tbuff;
zbuff_t *tbuff;

foreachbuff(tbuff)
if (strncasecmp(tbuff->bname, bname, BUFNAMMAX) == 0)
return tbuff;
return NULL;
}

struct zbuff *cfindzbuff(struct buff *buff)
zbuff_t *cfindzbuff(struct buff *buff)
{
struct zbuff *tbuff;
zbuff_t *tbuff;

foreachbuff(tbuff)
if (tbuff->buff == buff)
Expand Down
6 changes: 3 additions & 3 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void Zset_mark(void)

void Zexit(void)
{
struct zbuff *tbuff;
zbuff_t *tbuff;
bool modf = false;

if (!saveall(Argp))
Expand Down Expand Up @@ -644,7 +644,7 @@ int ask(const char *msg)
* Always saves if 'must' is true or saveOnExit is set.
* Returns false if the user ABORTS the prompt.
*/
bool promptsave(struct zbuff *tbuff, bool must)
bool promptsave(zbuff_t *tbuff, bool must)
{
static int save_all;
char str[BUFNAMMAX + 20];
Expand Down Expand Up @@ -677,7 +677,7 @@ bool promptsave(struct zbuff *tbuff, bool must)
*/
bool saveall(bool must)
{
struct zbuff *tbuff, *bsave;
zbuff_t *tbuff, *bsave;

bsave = Curbuff;
foreachbuff(tbuff)
Expand Down
6 changes: 3 additions & 3 deletions comment.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void newcomment(struct mark *start)
}

/* Scan an entire buffer for comments. */
static void scanbuffer(struct zbuff *buff)
static void scanbuffer(zbuff_t *buff)
{
struct mark tmark, start;
Byte comchar = Curbuff->comchar;
Expand Down Expand Up @@ -143,7 +143,7 @@ void cprntchar(Byte ch)

if (!Comstate) {
struct wdo *wdo;
struct zbuff *was = Curbuff;
zbuff_t *was = Curbuff;

scanbuffer(Curbuff);
for (wdo = Whead; wdo; wdo = wdo->next)
Expand All @@ -166,7 +166,7 @@ void cprntchar(Byte ch)
}

/* Remove all comments from buffer and mark unscanned */
void uncomment(struct zbuff *buff)
void uncomment(zbuff_t *buff)
{
if (buff)
while (buff->chead) {
Expand Down
2 changes: 1 addition & 1 deletion cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void Zout_to(void)

void Zredisplay(void)
{
struct zbuff *buff;
zbuff_t *buff;

wsize();
redisplay();
Expand Down
8 changes: 4 additions & 4 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

static int innerdsp(int from, int to, struct mark *pmark);
static void modeflags(struct wdo *wdo);
static char *setmodes(struct zbuff *);
static char *setmodes(zbuff_t *);
static void pawdisplay(struct mark *, struct mark *);

struct mark *Sstart; /* Screen start */
Expand Down Expand Up @@ -52,7 +52,7 @@ static jmp_buf zrefresh_jmp;

static void huge_file_modified(struct buff *buff)
{
struct zbuff *zbuff = cfindzbuff(buff);
zbuff_t *zbuff = cfindzbuff(buff);
if (!zbuff) { /* can't happen */
printf("\n\nUnable to get zbuff for huge buffer\n\n\n");
exit(1);
Expand All @@ -77,7 +77,7 @@ static void huge_file_modified(struct buff *buff)

static void huge_file_io(struct buff *buff)
{
struct zbuff *zbuff = cfindzbuff(buff);
zbuff_t *zbuff = cfindzbuff(buff);
if (!zbuff) { /* can't happen */
printf("\n\nUnable to get zbuff for huge buffer\n\n\n");
exit(1);
Expand Down Expand Up @@ -507,7 +507,7 @@ static void modeflags(struct wdo *wdo)
#define PAWCAT(s) strcat(PawStr, s)

/* local routine to set PawStr to the correct mode */
static char *setmodes(struct zbuff *buff)
static char *setmodes(zbuff_t *buff)
{
*PawStr = 0;

Expand Down
8 changes: 4 additions & 4 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void Zrevert_file(void)
static bool readone(char *bname, char *path)
{
int rc;
struct zbuff *was = Curbuff;
zbuff_t *was = Curbuff;

if (cfindbuff(bname))
return true;
Expand Down Expand Up @@ -327,8 +327,8 @@ static bool readone(char *bname, char *path)
bool findfile(char *path)
{
char tbname[BUFNAMMAX + 1];
struct zbuff *tbuff;
struct zbuff *was = Curbuff;
zbuff_t *tbuff;
zbuff_t *was = Curbuff;

Arg = 0;

Expand Down Expand Up @@ -379,7 +379,7 @@ bool findfile(char *path)
void Zsave_all_files(void)
{
if (Argp) {
struct zbuff *tbuff;
zbuff_t *tbuff;

foreachbuff(tbuff)
if (!(tbuff->bmode & SYSBUFF) && tbuff->fname)
Expand Down
4 changes: 2 additions & 2 deletions getarg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
int InPaw;
bool First;
int Pawcol, Pawlen, Pshift;
struct zbuff *Paw;
struct zbuff *Buff_save;
zbuff_t *Paw;
zbuff_t *Buff_save;

/* globals for getplete */
static char **Carray;
Expand Down
2 changes: 1 addition & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void Zhelp_function(void)
return;

if (Argp) {
struct zbuff *buff = cmakebuff(HELPBUFF, NULL);
zbuff_t *buff = cmakebuff(HELPBUFF, NULL);
if (buff == NULL)
return;
cswitchto(buff);
Expand Down
2 changes: 1 addition & 1 deletion life.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void Zlife(void)
char *matrix1, *matrix2;
bool go = true, step = true;
unsigned cmd;
struct zbuff *buff;
zbuff_t *buff;

buff = zcreatebuff(LIFEBUFF, NULL);
if (buff == NULL) {
Expand Down
24 changes: 12 additions & 12 deletions proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,20 @@ void os_init(void);
int ask(const char *);
int bgetcol(bool, int);
int bmakecol(int);
void zswitchto(struct zbuff *);
struct zbuff *cfindbuff(const char *);
struct zbuff *cfindzbuff(struct buff *buff);
struct zbuff *zcreatebuff(const char *bname, char *fname);
struct zbuff *cmakebuff(const char *, char *);
bool cdelbuff(struct zbuff *buff);
void cswitchto(struct zbuff *);
void zswitchto(zbuff_t *);
zbuff_t *cfindbuff(const char *);
zbuff_t *cfindzbuff(struct buff *buff);
zbuff_t *zcreatebuff(const char *bname, char *fname);
zbuff_t *cmakebuff(const char *, char *);
bool cdelbuff(zbuff_t *buff);
void cswitchto(zbuff_t *);
void display_init(struct mark *mrk);
int delayprompt(const char *);
void delinit(void);
void delfini(void);
unsigned delpages(void);
bool delcmd(void);
int do_chdir(struct zbuff *buff);
int do_chdir(zbuff_t *buff);
void execute(void);
int readapipe(void);
bool fd_add(int fd);
Expand All @@ -197,7 +197,7 @@ char *limit(char *, int);
void makepaw(char *, bool);
char *nocase(const char *);
int pathfixup(char *, char *);
bool promptsave(struct zbuff *tbuff, bool must);
bool promptsave(zbuff_t *tbuff, bool must);
int prefline(void);
void putpaw(const char *fmt, ...);
void error(const char *fmt, ...);
Expand All @@ -224,7 +224,7 @@ void hang_up(int);
void dump_doc(const char *doc);
int zreadfile(char *fname);
void set_shell_mark(void);
void message(struct zbuff *buff, const char *str);
void message(zbuff_t *buff, const char *str);

int batoi(void);

Expand All @@ -240,7 +240,7 @@ void winit(void);

void checkpipes(int type);
void siginit(void);
bool unvoke(struct zbuff *);
bool unvoke(zbuff_t *);

/* for getfname */
int getfname(const char *, char *);
Expand All @@ -254,5 +254,5 @@ void wgoto(struct buff *);

/* COMMENTBOLD */
void resetcomments(void);
void uncomment(struct zbuff *buff);
void uncomment(zbuff_t *buff);
void cprntchar(Byte ch);
Loading

0 comments on commit 930fdb0

Please sign in to comment.