From d6e9eb25e92e548f86ffd78a604022c47303aacc Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Fri, 2 Apr 2010 22:27:59 -0400 Subject: [PATCH] Re-organize some code. This change causes no functional change at all. This simply groups some common variables into structs. --- src/ansi.c | 34 +++++++++++++++---------------- src/resize.c | 66 ++++++++++++++++++++++++++++++------------------------------ src/window.h | 32 ++++++++++++++++------------- 3 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/ansi.c b/src/ansi.c index 5f28346..685907a 100644 --- a/src/ansi.c +++ b/src/ansi.c @@ -200,7 +200,7 @@ register struct win *p; p->w_cursorkeys = 0; p->w_top = 0; p->w_bot = p->w_height - 1; - p->w_saved = 0; + p->w_saved.on = 0; p->w_x = p->w_y = 0; p->w_state = LIT; p->w_StringType = NONE; @@ -1435,7 +1435,7 @@ int c, intermediate; else LeaveAltScreen(curr); if (a1 == 47 && !i) - curr->w_saved = 0; + curr->w_saved.on = 0; LRefreshAll(&curr->w_layer, 0); LGotoPos(&curr->w_layer, curr->w_x, curr->w_y); } @@ -1757,14 +1757,14 @@ int n; static void SaveCursor() { - curr->w_saved = 1; - curr->w_Saved_x = curr->w_x; - curr->w_Saved_y = curr->w_y; - curr->w_SavedRend = curr->w_rend; + curr->w_saved.on = 1; + curr->w_saved.x = curr->w_x; + curr->w_saved.y = curr->w_y; + curr->w_saved.Rend = curr->w_rend; #ifdef FONT - curr->w_SavedCharset = curr->w_Charset; - curr->w_SavedCharsetR = curr->w_CharsetR; - bcopy((char *) curr->w_charsets, (char *) curr->w_SavedCharsets, + curr->w_saved.Charset = curr->w_Charset; + curr->w_saved.CharsetR = curr->w_CharsetR; + bcopy((char *) curr->w_charsets, (char *) curr->w_saved.Charsets, 4 * sizeof(int)); #endif } @@ -1772,17 +1772,17 @@ SaveCursor() static void RestoreCursor() { - if (!curr->w_saved) + if (!curr->w_saved.on) return; - LGotoPos(&curr->w_layer, curr->w_Saved_x, curr->w_Saved_y); - curr->w_x = curr->w_Saved_x; - curr->w_y = curr->w_Saved_y; - curr->w_rend = curr->w_SavedRend; + LGotoPos(&curr->w_layer, curr->w_saved.x, curr->w_saved.y); + curr->w_x = curr->w_saved.x; + curr->w_y = curr->w_saved.y; + curr->w_rend = curr->w_saved.Rend; #ifdef FONT - bcopy((char *) curr->w_SavedCharsets, (char *) curr->w_charsets, + bcopy((char *) curr->w_saved.Charsets, (char *) curr->w_charsets, 4 * sizeof(int)); - curr->w_Charset = curr->w_SavedCharset; - curr->w_CharsetR = curr->w_SavedCharsetR; + curr->w_Charset = curr->w_saved.Charset; + curr->w_CharsetR = curr->w_saved.CharsetR; curr->w_ss = 0; curr->w_FontL = curr->w_charsets[curr->w_Charset]; curr->w_FontR = curr->w_charsets[curr->w_CharsetR]; diff --git a/src/resize.c b/src/resize.c index 5d1df4b..0f24ca5 100644 --- a/src/resize.c +++ b/src/resize.c @@ -585,10 +585,10 @@ int wi; #ifdef COPY_PASTE RESET_LINES(p->w_hlines, p->w_histheight); - RESET_LINES(p->w_alt_hlines, p->w_alt_histheight); + RESET_LINES(p->w_alt.hlines, p->w_alt.histheight); #endif - RESET_LINES(p->w_alt_mlines, p->w_alt_height); + RESET_LINES(p->w_alt.mlines, p->w_alt.height); } } @@ -957,8 +957,8 @@ int wi, he, hi; } } - /* Change w_Saved_y - this is only an estimate... */ - p->w_Saved_y += ncy - p->w_y; + /* Change w_saved.y - this is only an estimate... */ + p->w_saved.y += ncy - p->w_y; p->w_x = ncx; p->w_y = ncy; @@ -970,12 +970,12 @@ int wi, he, hi; p->w_x = wi; if (p->w_y >= he) p->w_y = he - 1; - if (p->w_Saved_x > wi) - p->w_Saved_x = wi; - if (p->w_Saved_y < 0) - p->w_Saved_y = 0; - if (p->w_Saved_y >= he) - p->w_Saved_y = he - 1; + if (p->w_saved.x > wi) + p->w_saved.x = wi; + if (p->w_saved.y < 0) + p->w_saved.y = 0; + if (p->w_saved.y >= he) + p->w_saved.y = he - 1; /* reset scrolling region */ p->w_top = 0; @@ -1034,28 +1034,28 @@ struct win *p; { int i; - if (p->w_alt_mlines) + if (p->w_alt.mlines) { - for (i = 0; i < p->w_alt_height; i++) - FreeMline(p->w_alt_mlines + i); - free(p->w_alt_mlines); + for (i = 0; i < p->w_alt.height; i++) + FreeMline(p->w_alt.mlines + i); + free(p->w_alt.mlines); } - p->w_alt_mlines = 0; - p->w_alt_width = 0; - p->w_alt_height = 0; - p->w_alt_x = 0; - p->w_alt_y = 0; + p->w_alt.mlines = 0; + p->w_alt.width = 0; + p->w_alt.height = 0; + p->w_alt.x = 0; + p->w_alt.y = 0; #ifdef COPY_PASTE - if (p->w_alt_hlines) + if (p->w_alt.hlines) { - for (i = 0; i < p->w_alt_histheight; i++) - FreeMline(p->w_alt_hlines + i); - free(p->w_alt_hlines); + for (i = 0; i < p->w_alt.histheight; i++) + FreeMline(p->w_alt.hlines + i); + free(p->w_alt.hlines); } - p->w_alt_hlines = 0; - p->w_alt_histidx = 0; + p->w_alt.hlines = 0; + p->w_alt.histidx = 0; #endif - p->w_alt_histheight = 0; + p->w_alt.histheight = 0; } static void @@ -1065,7 +1065,7 @@ struct win *p; struct mline *ml; int t; -#define SWAP(item, t) do { (t) = p->w_alt_##item; p->w_alt_##item = p->w_##item; p->w_##item = (t); } while (0) +#define SWAP(item, t) do { (t) = p->w_alt. item; p->w_alt. item = p->w_##item; p->w_##item = (t); } while (0) SWAP(mlines, ml); SWAP(width, t); @@ -1086,7 +1086,7 @@ EnterAltScreen(p) struct win *p; { int ox = p->w_x, oy = p->w_y; - if (!p->w_alt_current) + if (!p->w_alt.on) { /* If not already using the alternate screen buffer, then create a new one and swap it with the 'real' screen buffer. */ @@ -1100,20 +1100,20 @@ struct win *p; p->w_height = 0; p->w_histheight = 0; } - ChangeWindowSize(p, p->w_alt_width, p->w_alt_height, p->w_alt_histheight); + ChangeWindowSize(p, p->w_alt.width, p->w_alt.height, p->w_alt.histheight); p->w_x = ox; p->w_y = oy; - p->w_alt_current = 1; + p->w_alt.on = 1; } void LeaveAltScreen(p) struct win *p; { - if (!p->w_alt_current) + if (!p->w_alt.on) return; SwapAltScreen(p); - ChangeWindowSize(p, p->w_alt_width, p->w_alt_height, p->w_alt_histheight); + ChangeWindowSize(p, p->w_alt.width, p->w_alt.height, p->w_alt.histheight); FreeAltScreen(p); - p->w_alt_current = 0; + p->w_alt.on = 0; } diff --git a/src/window.h b/src/window.h index 47f5c9e..07a8fa5 100644 --- a/src/window.h +++ b/src/window.h @@ -188,14 +188,16 @@ struct win int w_charsets[4]; /* Font = charsets[Charset] */ #endif int w_ss; - int w_saved; - int w_Saved_x, w_Saved_y; - struct mchar w_SavedRend; + struct { + int on; + int x, y; + struct mchar Rend; #ifdef FONT - int w_SavedCharset; - int w_SavedCharsetR; - int w_SavedCharsets[4]; + int Charset; + int CharsetR; + int Charsets[4]; #endif + } w_saved; int w_top, w_bot; /* scrollregion */ int w_wrap; /* autowrap */ int w_origin; /* origin mode */ @@ -276,16 +278,18 @@ struct win int w_telsubidx; struct event w_telconnev; #endif - struct mline *w_alt_mlines; - int w_alt_width; - int w_alt_height; - int w_alt_histheight; - int w_alt_x, w_alt_y; + struct { + int on; /* Is the alternate buffer currently being used? */ + struct mline *mlines; + int width; + int height; + int histheight; + int x, y; #ifdef COPY_PASTE - struct mline *w_alt_hlines; - int w_alt_histidx; + struct mline *hlines; + int histidx; #endif - int w_alt_current; /* Is the alternate buffer currently being used? */ + } w_alt; struct event w_destroyev; /* window destroy event */ #ifdef BSDWAIT -- 2.11.4.GIT