From 907a995b988e12f6f5b406b9a29940bfe335d0a1 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Mon, 15 Aug 2011 19:12:26 +1000 Subject: [PATCH] Refactor function names; "old_" functions will be removed Rename prepstr, vprepstr, chbufdup, center, center2, center3 and attrpr to mkchstr, vmkchstr, chstrdup, old_center, old_center2, old_center3 and old_attrpr respectively. --- src/exch.c | 74 ++++++++++++++++++++++++++-------------------------- src/game.c | 42 +++++++++++++++--------------- src/help.c | 14 +++++----- src/intf.c | 76 +++++++++++++++++++++++++++--------------------------- src/intf.h | 60 +++++++++++++++++++++--------------------- src/move.c | 50 +++++++++++++++++------------------ 6 files changed, 158 insertions(+), 158 deletions(-) diff --git a/src/exch.c b/src/exch.c index 5666742..5c50a46 100644 --- a/src/exch.c +++ b/src/exch.c @@ -93,8 +93,8 @@ void exchange_stock (void) werase(curwin); box(curwin, 0, 0); - center(curwin, 1, attr_title, " Interstellar Stock Exchange "); - center2(curwin, 2, attr_normal, attr_highlight, "Player: ", "%s", + old_center(curwin, 1, attr_title, " Interstellar Stock Exchange "); + old_center2(curwin, 2, attr_normal, attr_highlight, "Player: ", "%s", player[current_player].name); all_off_map = true; @@ -106,7 +106,7 @@ void exchange_stock (void) } if (all_off_map) { - center(curwin, 8, attr_normal, "No companies on the map"); + old_center(curwin, 8, attr_normal, "No companies on the map"); } else { char *buf = xmalloc(BUFSIZE); @@ -142,28 +142,28 @@ void exchange_stock (void) newtxwin(6, WIN_COLS, 18, WCENTER, true, attr_normal_window); wmove(curwin, 3, 2); - attrpr(curwin, attr_keycode, "<1>"); + old_attrpr(curwin, attr_keycode, "<1>"); waddstr(curwin, " Display stock portfolio"); wmove(curwin, 4, 2); - attrpr(curwin, attr_keycode, "<2>"); + old_attrpr(curwin, attr_keycode, "<2>"); waddstr(curwin, " Display galaxy map"); wmove(curwin, 3, 40); - attrpr(curwin, attr_keycode, "<3>"); + old_attrpr(curwin, attr_keycode, "<3>"); waddstr(curwin, " Visit the Trading Bank"); wmove(curwin, 4, 40); - attrpr(curwin, attr_keycode, "<4>"); + old_attrpr(curwin, attr_keycode, "<4>"); waddstr(curwin, " Exit the Stock Exchange"); mvwaddstr(curwin, 1, 18, "Enter selection "); waddstr(curwin, "["); - attrpr(curwin, attr_highlight, "Company letter"); + old_attrpr(curwin, attr_highlight, "Company letter"); waddstr(curwin, "/"); - attrpr(curwin, attr_keycode, "1"); + old_attrpr(curwin, attr_keycode, "1"); waddstr(curwin, "-"); - attrpr(curwin, attr_keycode, "4"); + old_attrpr(curwin, attr_keycode, "4"); waddstr(curwin, "]: "); curs_set(CURS_ON); @@ -264,21 +264,21 @@ void visit_bank (void) // Show the informational part of the Bank newtxwin(10, WIN_COLS - 4, 5, WCENTER, true, attr_normal_window); - center(curwin, 1, attr_title, " Interstellar Trading Bank "); + old_center(curwin, 1, attr_title, " Interstellar Trading Bank "); l_strfmon(buf, BUFSIZE, "%18n", player[current_player].cash); - center2(curwin, 3, attr_normal, attr_highlight, "Current cash: ", + old_center2(curwin, 3, attr_normal, attr_highlight, "Current cash: ", " %s ", buf); l_strfmon(buf, BUFSIZE, "%18n", player[current_player].debt); - center2(curwin, 4, attr_normal, attr_highlight, "Current debt: ", + old_center2(curwin, 4, attr_normal, attr_highlight, "Current debt: ", " %s ", buf); - center2(curwin, 5, attr_normal, attr_highlight, "Interest rate: ", + old_center2(curwin, 5, attr_normal, attr_highlight, "Interest rate: ", " %17.2f%% ", interest_rate * 100.0); l_strfmon(buf, BUFSIZE, "%18n", credit_limit); - center2(curwin, 7, attr_highlight, attr_title, "Credit limit: ", + old_center2(curwin, 7, attr_highlight, attr_title, "Credit limit: ", " %s ", buf); wrefresh(curwin); @@ -286,15 +286,15 @@ void visit_bank (void) // Show menu of choices for the player newtxwin(7, WIN_COLS - 4, 15, WCENTER, true, attr_normal_window); - center2(curwin, 3, attr_keycode, attr_normal, "<1>", " Borrow money "); - center2(curwin, 4, attr_keycode, attr_normal, "<2>", " Repay debt "); - center2(curwin, 5, attr_keycode, attr_normal, "<3>", " Exit from the Bank"); + old_center2(curwin, 3, attr_keycode, attr_normal, "<1>", " Borrow money "); + old_center2(curwin, 4, attr_keycode, attr_normal, "<2>", " Repay debt "); + old_center2(curwin, 5, attr_keycode, attr_normal, "<3>", " Exit from the Bank"); mvwaddstr(curwin, 1, 24, "Enter selection "); waddstr(curwin, "["); - attrpr(curwin, attr_keycode, "1"); + old_attrpr(curwin, attr_keycode, "1"); waddstr(curwin, "-"); - attrpr(curwin, attr_keycode, "3"); + old_attrpr(curwin, attr_keycode, "3"); waddstr(curwin, "]: "); curs_set(CURS_ON); @@ -473,35 +473,35 @@ void trade_shares (int num, bool *bid_used) // Show the informational part of the trade window newtxwin(9, WIN_COLS - 4, 5, WCENTER, true, attr_normal_window); - center(curwin, 1, attr_title, " Stock Transaction in %s ", + old_center(curwin, 1, attr_title, " Stock Transaction in %s ", company[num].name); mvwaddstr(curwin, 3, 2, "Shares issued: "); - attrpr(curwin, attr_highlight, "%'12ld", company[num].stock_issued); + old_attrpr(curwin, attr_highlight, "%'12ld", company[num].stock_issued); mvwaddstr(curwin, 4, 2, "Shares left: "); - attrpr(curwin, attr_highlight, "%'12ld", + old_attrpr(curwin, attr_highlight, "%'12ld", company[num].max_stock - company[num].stock_issued); mvwaddstr(curwin, 5, 2, "Price per share: "); l_strfmon(buf, BUFSIZE, "%12n", company[num].share_price); - attrpr(curwin, attr_highlight, "%12s", buf); + old_attrpr(curwin, attr_highlight, "%12s", buf); mvwaddstr(curwin, 6, 2, "Return: "); - attrpr(curwin, attr_highlight, "%11.2f%%", + old_attrpr(curwin, attr_highlight, "%11.2f%%", company[num].share_return * 100.0); mvwaddstr(curwin, 3, 38, "Current holdings: "); - attrpr(curwin, attr_highlight, " %'16ld ", + old_attrpr(curwin, attr_highlight, " %'16ld ", player[current_player].stock_owned[num]); mvwaddstr(curwin, 4, 38, "Percentage owned: "); - attrpr(curwin, attr_highlight, " %'15.2f%% ", ownership * 100.0); + old_attrpr(curwin, attr_highlight, " %'15.2f%% ", ownership * 100.0); wmove(curwin, 6, 38); - attrpr(curwin, attr_highlight, "Current cash: "); + old_attrpr(curwin, attr_highlight, "Current cash: "); l_strfmon(buf, BUFSIZE, "%16n", player[current_player].cash); - attrpr(curwin, attr_title, " %16s ", buf); + old_attrpr(curwin, attr_title, " %16s ", buf); wrefresh(curwin); @@ -509,26 +509,26 @@ void trade_shares (int num, bool *bid_used) newtxwin(7, WIN_COLS - 4, 14, WCENTER, true, attr_normal_window); wmove(curwin, 3, 2); - attrpr(curwin, attr_keycode, "<1>"); + old_attrpr(curwin, attr_keycode, "<1>"); waddstr(curwin, " Buy stock from company"); wmove(curwin, 4, 2); - attrpr(curwin, attr_keycode, "<2>"); + old_attrpr(curwin, attr_keycode, "<2>"); waddstr(curwin, " Sell stock back to company"); wmove(curwin, 3, 38); - attrpr(curwin, attr_keycode, "<3>"); + old_attrpr(curwin, attr_keycode, "<3>"); waddstr(curwin, " Bid company to issue more shares"); wmove(curwin, 4, 38); - attrpr(curwin, attr_keycode, "<4>"); + old_attrpr(curwin, attr_keycode, "<4>"); waddstr(curwin, " Exit to the Stock Exchange"); mvwaddstr(curwin, 1, 24, "Enter selection "); waddstr(curwin, "["); - attrpr(curwin, attr_keycode, "1"); + old_attrpr(curwin, attr_keycode, "1"); waddstr(curwin, "-"); - attrpr(curwin, attr_keycode, "4"); + old_attrpr(curwin, attr_keycode, "4"); waddstr(curwin, "]: "); curs_set(CURS_ON); @@ -586,7 +586,7 @@ void trade_shares (int num, bool *bid_used) werase(curwin); box(curwin, 0, 0); - center3(curwin, 2, attr_normal, attr_normal, attr_highlight, + old_center3(curwin, 2, attr_normal, attr_normal, attr_highlight, "You can purchase up to ", " shares.", "%'ld", maxshares); mvwprintw(curwin, 4, 10, "How many shares do you wish to purchase? "); @@ -616,7 +616,7 @@ void trade_shares (int num, bool *bid_used) werase(curwin); box(curwin, 0, 0); - center3(curwin, 2, attr_normal, attr_normal, attr_highlight, + old_center3(curwin, 2, attr_normal, attr_normal, attr_highlight, "You can sell up to ", " shares.", "%'ld", maxshares); mvwprintw(curwin, 4, 10, "How many shares do you wish to sell? "); diff --git a/src/game.c b/src/game.c index 7d1cc4e..93844aa 100644 --- a/src/game.c +++ b/src/game.c @@ -113,7 +113,7 @@ void init_game (void) chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype)); int lines, width; - lines = prepstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1, + lines = mkchstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1, WIN_COLS - 7, &width, 1, "Loading game %d... ", game_num); newtxwin(5, width + 5, 6, WCENTER, true, attr_status_window); @@ -148,7 +148,7 @@ void init_game (void) game_num = choice; - lines = prepstr(chbuf, BUFSIZE, attr_status_window, + lines = mkchstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1, WIN_COLS - 7, &width, 1, "Loading game %d... ", game_num); newtxwin(5, width + 5, 9, WCENTER, true, attr_status_window); @@ -249,7 +249,7 @@ static int ask_number_players (void) chbuf = xmalloc(BUFSIZE * sizeof(chtype)); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, sizeof(widthbuf) / sizeof(widthbuf[0]), WIN_COLS - 7, widthbuf, sizeof(widthbuf) / sizeof(widthbuf[0]), "Enter number of players [^{1^}-^{%d^}] " @@ -314,7 +314,7 @@ int ask_game_number (void) chbuf = xmalloc(BUFSIZE * sizeof(chtype)); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, sizeof(widthbuf) / sizeof(widthbuf[0]), WIN_COLS - 7, widthbuf, sizeof(widthbuf) / sizeof(widthbuf[0]), "Enter game number [^{1^}-^{9^}] " @@ -388,7 +388,7 @@ void ask_player_names (void) chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype)); int lines, width; - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, WIN_COLS - YESNO_COLS - 6, &width, 1, "Do you need any instructions? [^{Y^}/^{N^}] "); newtxwin(5, width + YESNO_COLS + 4, 6, WCENTER, true, @@ -411,7 +411,7 @@ void ask_player_names (void) newtxwin(number_players + 5, WIN_COLS - 4, 9, WCENTER, true, attr_normal_window); - lines = prepstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 8, + lines = mkchstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 8, &width, 1, " Enter Player Names "); pr_center(curwin, 1, 0, chbuf, lines, &width); @@ -494,7 +494,7 @@ void ask_player_names (void) } } - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, WIN_COLS - YESNO_COLS - 6, &width, 1, "Does any player need instructions? [^{Y^}/^{N^}] "); newtxwin(5, width + YESNO_COLS + 4, 6, WCENTER, true, @@ -552,15 +552,15 @@ void end_game (void) newtxwin(number_players + 10, WIN_COLS - 4, 3, WCENTER, true, attr_normal_window); - center(curwin, 1, attr_title, " Game Winner "); - center2(curwin, 3, attr_normal, attr_highlight, "The winner is ", + old_center(curwin, 1, attr_title, " Game Winner "); + old_center2(curwin, 3, attr_normal, attr_highlight, "The winner is ", "%s", player[0].name); if (player[0].sort_value == 0.0) { - center2(curwin, 4, attr_normal, attr_blink, "who is ", + old_center2(curwin, 4, attr_normal, attr_blink, "who is ", "*** BANKRUPT ***"); } else { l_strfmon(buf, BUFSIZE, "%1n", player[0].sort_value); - center2(curwin, 4, attr_normal, attr_highlight, + old_center2(curwin, 4, attr_normal, attr_highlight, "with a value of ", "%s", buf); } @@ -603,12 +603,12 @@ void show_map (bool closewin) mvwhline(curwin, 1, 2, ' ' | attr_mapwin_title, getmaxx(curwin) - 4); // Display current player and turn number - lines = prepstr(chbuf, BUFSIZE, attr_mapwin_title, attr_mapwin_highlight, + lines = mkchstr(chbuf, BUFSIZE, attr_mapwin_title, attr_mapwin_highlight, 0, 1, WIN_COLS - 4, &width, 1, " Player: ^{%s^} ", player[current_player].name); pr_left(curwin, 1, 2, chbuf, lines, &width); - lines = prepstr(chbuf, BUFSIZE, attr_mapwin_title, attr_mapwin_highlight, + lines = mkchstr(chbuf, BUFSIZE, attr_mapwin_title, attr_mapwin_highlight, attr_mapwin_blink, 1, WIN_COLS / 2, &width, 1, (turn_number != max_turn) ? " Turn: ^{%d^} " : " ^[*** Last Turn ***^] ", turn_number); @@ -679,18 +679,18 @@ void show_status (int num) attr_normal_window); chbuf = xmalloc(BUFSIZE * sizeof(chtype)); - lines = prepstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 4, + lines = mkchstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 4, &width, 1, " Stock Portfolio "); pr_center(curwin, 1, 0, chbuf, lines, &width); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1, WIN_COLS - 4, &width, 1, "Player: ^{%s^}", player[num].name); pr_center(curwin, 2, 0, chbuf, lines, &width); val = total_value(num); if (val == 0.0) { - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_highlight, attr_blink, 1, WIN_COLS - 4, &width, 1, "^[* * * B A N K R U P T * * *^]"); pr_center(curwin, 11, 0, chbuf, lines, &width); @@ -708,7 +708,7 @@ void show_status (int num) } if (none) { - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1, WIN_COLS - 4, &width, 1, "No companies on the map"); pr_center(curwin, 8, 0, chbuf, lines, &width); @@ -741,18 +741,18 @@ void show_status (int num) line = 15; l_strfmon(buf, BUFSIZE, "%18n", player[num].cash); - center2(curwin, line++, attr_normal, attr_highlight, "Current cash: ", + old_center2(curwin, line++, attr_normal, attr_highlight, "Current cash: ", " %s ", buf); if (player[num].debt != 0.0) { l_strfmon(buf, BUFSIZE, "%18n", player[num].debt); - center2(curwin, line++, attr_normal, attr_highlight, + old_center2(curwin, line++, attr_normal, attr_highlight, "Current debt: ", " %s ", buf); - center2(curwin, line++, attr_normal, attr_highlight, + old_center2(curwin, line++, attr_normal, attr_highlight, "Interest rate: ", " %17.2f%% ", interest_rate * 100.0); } l_strfmon(buf, BUFSIZE, "%18n", val); - center2(curwin, line + 1, attr_highlight, attr_title, + old_center2(curwin, line + 1, attr_highlight, attr_title, "Total value: ", " %s ", buf); free(buf); diff --git a/src/help.c b/src/help.c index dd78cf5..2dad035 100644 --- a/src/help.c +++ b/src/help.c @@ -182,20 +182,20 @@ void show_help (void) } // Prepare fixed-text strings - ln_title = prepstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 4, + ln_title = mkchstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 4, &w_title, 1, " How to Play "); - ch_title = chbufdup(chbuf, BUFSIZE); + ch_title = chstrdup(chbuf, BUFSIZE); - ln_contfirst = prepstr(chbuf, BUFSIZE, attr_waitforkey, 0, 0, 1, + ln_contfirst = mkchstr(chbuf, BUFSIZE, attr_waitforkey, 0, 0, 1, WIN_COLS - 4, &w_contfirst, 1, "[ Press to continue ] "); - ch_contfirst = chbufdup(chbuf, BUFSIZE); + ch_contfirst = chstrdup(chbuf, BUFSIZE); - ln_contnext = prepstr(chbuf, BUFSIZE, attr_waitforkey, 0, 0, 1, + ln_contnext = mkchstr(chbuf, BUFSIZE, attr_waitforkey, 0, 0, 1, WIN_COLS - 4, &w_contnext, 1, "[ Press to continue or " " for the previous page ] "); - ch_contnext = chbufdup(chbuf, BUFSIZE); + ch_contnext = chstrdup(chbuf, BUFSIZE); newtxwin(WIN_LINES - 1, WIN_COLS, 1, WCENTER, false, 0); @@ -207,7 +207,7 @@ void show_help (void) box(curwin, 0, 0); pr_center(curwin, 1, 0, ch_title, ln_title, &w_title); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1, WIN_COLS - 4, &width, 1, "Page %d of %d", curpage + 1, numpages); pr_center(curwin, 2, 0, chbuf, lines, &width); diff --git a/src/intf.c b/src/intf.c index 53a6909..8a26435 100644 --- a/src/intf.c +++ b/src/intf.c @@ -42,7 +42,7 @@ typedef struct txwin { } txwin_t; -// Declarations for argument processing in prepstr() +// Declarations for argument processing in mkchstr() #define MAXFMTARGS 8 // Maximum number of positional arguments @@ -170,7 +170,7 @@ static void txresize (void); /* - Function: prepstr_addch - Add a character to the prepstr buffer + Function: mkchstr_addch - Add a character to the mkchstr buffer Parameters: chbuf - Pointer to chtype pointer in which to store string chbufsize - Pointer to number of chtype elements in chbuf attr - Character rendition to use @@ -193,7 +193,7 @@ static void txresize (void); (if not on the last line). *line, *width, *lastspc, *widthspc and widthbuf[] are all updated appropriately. */ -static int prepstr_addch (chtype *restrict *restrict chbuf, +static int mkchstr_addch (chtype *restrict *restrict chbuf, int *restrict chbufsize, chtype attr, int maxlines, int maxwidth, int *restrict line, int *restrict width, @@ -204,17 +204,17 @@ static int prepstr_addch (chtype *restrict *restrict chbuf, /* - Function: prepstr_parse - Parse the format string for prepstr() - Parameters: format - Format string as described for prepstr() + Function: mkchstr_parse - Parse the format string for mkchstr() + Parameters: format - Format string as described for mkchstr() format_arg - Pointer to variable arguments array format_spec - Pointer to conversion specifiers array - args - Variable argument list passed to prepstr() + args - Variable argument list passed to mkchstr() Returns: int - 0 if OK, -1 if error (with errno set) - This helper function parses the format string passed to prepstr(), + This helper function parses the format string passed to mkchstr(), setting the format_arg and format_spec arrays appropriately. */ -static int prepstr_parse (const char *restrict format, +static int mkchstr_parse (const char *restrict format, struct argument *restrict format_arg, struct convspec *restrict format_spec, va_list args); @@ -416,7 +416,7 @@ void init_title (void) } chbuf = xmalloc(BUFSIZE * sizeof(chtype)); - lines = prepstr(chbuf, BUFSIZE, attr_game_title, 0, 0, 1, COLS, + lines = mkchstr(chbuf, BUFSIZE, attr_game_title, 0, 0, 1, COLS, &width, 1, _("Star Traders")); pr_center(stdscr, 0, 0, chbuf, lines, &width); attrset(attr_root_window); @@ -612,7 +612,7 @@ int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x, widthbuf = xmalloc(maxlines * sizeof(int)); va_start(args, format); - lines = vprepstr(chbuf, BUFSIZE, norm_attr, alt1_attr, alt2_attr, maxlines, + lines = vmkchstr(chbuf, BUFSIZE, norm_attr, alt1_attr, alt2_attr, maxlines, ncols - 4, widthbuf, maxlines, format, args); va_end(args); @@ -624,7 +624,7 @@ int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x, int titlewidth; int titlelines; - titlelines = prepstr(titlebuf, BUFSIZE, title_attr, 0, 0, 1, + titlelines = mkchstr(titlebuf, BUFSIZE, title_attr, 0, 0, 1, ncols - 4, &titlewidth, 1, boxtitle); pr_center(curwin, 1, 0, titlebuf, titlelines, &titlewidth); free(titlebuf); @@ -641,9 +641,9 @@ int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x, /***********************************************************************/ -// prepstr: Prepare a string for printing to screen +// mkchstr: Prepare a string for printing to screen -int prepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, +int mkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, chtype attr_alt1, chtype attr_alt2, int maxlines, int maxwidth, int *restrict widthbuf, int widthbufsize, const char *restrict format, ...) @@ -653,7 +653,7 @@ int prepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, va_start(args, format); - lines = vprepstr(chbuf, chbufsize, attr_norm, attr_alt1, attr_alt2, + lines = vmkchstr(chbuf, chbufsize, attr_norm, attr_alt1, attr_alt2, maxlines, maxwidth, widthbuf, widthbufsize, format, args); va_end(args); @@ -662,9 +662,9 @@ int prepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, /***********************************************************************/ -// prepstr_addch: Add a character to the prepstr buffer +// mkchstr_addch: Add a character to the mkchstr buffer -int prepstr_addch (chtype *restrict *restrict chbuf, int *restrict chbufsize, +int mkchstr_addch (chtype *restrict *restrict chbuf, int *restrict chbufsize, chtype attr, int maxlines, int maxwidth, int *restrict line, int *restrict width, chtype *restrict *restrict lastspc, int *restrict widthspc, @@ -747,9 +747,9 @@ int prepstr_addch (chtype *restrict *restrict chbuf, int *restrict chbufsize, /***********************************************************************/ -// prepstr_parse: Parse the format string for prepstr() +// mkchstr_parse: Parse the format string for mkchstr() -int prepstr_parse (const char *restrict format, +int mkchstr_parse (const char *restrict format, struct argument *restrict format_arg, struct convspec *restrict format_spec, va_list args) { @@ -991,9 +991,9 @@ int prepstr_parse (const char *restrict format, /***********************************************************************/ -// vprepstr: Prepare a string for printing to screen +// vmkchstr: Prepare a string for printing to screen -int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, +int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, chtype attr_alt1, chtype attr_alt2, int maxlines, int maxwidth, int *restrict widthbuf, int widthbufsize, const char *restrict format, va_list args) @@ -1017,7 +1017,7 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, assert(widthbufsize >= maxlines); assert(format != NULL); - if (prepstr_parse(format, format_arg, format_spec, args) < 0) { + if (mkchstr_parse(format, format_arg, format_spec, args) < 0) { goto error; } @@ -1038,7 +1038,7 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, } else { switch (*format) { case '^': - if (prepstr_addch(&chbuf, &chbufsize, curattr, maxlines, + if (mkchstr_addch(&chbuf, &chbufsize, curattr, maxlines, maxwidth, &line, &width, &lastspc, &widthspc, widthbuf, widthbufsize, &format) < 0) { @@ -1073,7 +1073,7 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, if (*++format == '\0') { goto error_inval; } else if (*format == '%') { - if (prepstr_addch(&chbuf, &chbufsize, curattr, maxlines, + if (mkchstr_addch(&chbuf, &chbufsize, curattr, maxlines, maxwidth, &line, &width, &lastspc, &widthspc, widthbuf, widthbufsize, &format) < 0) { goto error; @@ -1147,7 +1147,7 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, insertstr: // Insert the string pointed to by str while (*str != '\0' && chbufsize > 1 && line < maxlines) { - if (prepstr_addch(&chbuf, &chbufsize, curattr, + if (mkchstr_addch(&chbuf, &chbufsize, curattr, maxlines, maxwidth, &line, &width, &lastspc, &widthspc, widthbuf, widthbufsize, &str) < 0) { @@ -1172,7 +1172,7 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, default: // Process an ordinary character (including new-line) - if (prepstr_addch(&chbuf, &chbufsize, curattr, maxlines, maxwidth, + if (mkchstr_addch(&chbuf, &chbufsize, curattr, maxlines, maxwidth, &line, &width, &lastspc, &widthspc, widthbuf, widthbufsize, &format) < 0) { goto error; @@ -1195,14 +1195,14 @@ error_inval: errno = EINVAL; error: - errno_exit(_("prepstr: `%s'"), orig_format); + errno_exit(_("mkchstr: `%s'"), orig_format); } /***********************************************************************/ -// chbufdup: Duplicate a chtype buffer +// chstrdup: Duplicate a chtype buffer -chtype *chbufdup (const chtype *restrict chbuf, int chbufsize) +chtype *chstrdup (const chtype *restrict chbuf, int chbufsize) { const chtype *p; int len; @@ -1309,9 +1309,9 @@ int pr_right (WINDOW *win, int y, int x, const chtype *restrict chbuf, /***********************************************************************/ -// attrpr: Print a string with a particular character rendition +// old_attrpr: Print a string with a particular character rendition -int attrpr (WINDOW *win, chtype attr, const char *restrict format, ...) +int old_attrpr (WINDOW *win, chtype attr, const char *restrict format, ...) { va_list args; int ret; @@ -1340,9 +1340,9 @@ int attrpr (WINDOW *win, chtype attr, const char *restrict format, ...) /***********************************************************************/ -// center: Centre a string in a given window +// old_center: Centre a string in a given window -int center (WINDOW *win, int y, chtype attr, const char *restrict format, ...) +int old_center (WINDOW *win, int y, chtype attr, const char *restrict format, ...) { va_list args; int ret, len, x; @@ -1357,7 +1357,7 @@ int center (WINDOW *win, int y, chtype attr, const char *restrict format, ...) chtype oldattr = getattrs(win); chtype oldbkgd = getbkgd(win); - // Order is important: see attrpr() + // Order is important: see old_attrpr() wbkgdset(win, (oldbkgd & A_COLOR) | A_NORMAL); wattrset(win, attr); @@ -1383,9 +1383,9 @@ int center (WINDOW *win, int y, chtype attr, const char *restrict format, ...) /***********************************************************************/ -// center2: Centre two strings in a given window +// old_center2: Centre two strings in a given window -int center2 (WINDOW *win, int y, chtype attr1, chtype attr2, +int old_center2 (WINDOW *win, int y, chtype attr1, chtype attr2, const char *initial, const char *restrict format, ...) { va_list args; @@ -1431,9 +1431,9 @@ int center2 (WINDOW *win, int y, chtype attr1, chtype attr2, /***********************************************************************/ -// center3: Centre three strings in a given window +// old_center3: Centre three strings in a given window -int center3 (WINDOW *win, int y, chtype attr1, chtype attr3, chtype attr2, +int old_center3 (WINDOW *win, int y, chtype attr1, chtype attr3, chtype attr2, const char *initial, const char *final, const char *restrict format, ...) { @@ -2447,7 +2447,7 @@ void wait_for_key (WINDOW *win, int y, chtype attr) wtimeout(win, -1); chbuf = xmalloc(BUFSIZE * sizeof(chtype)); - lines = prepstr(chbuf, BUFSIZE, attr, 0, 0, 1, getmaxx(win) - 4, + lines = mkchstr(chbuf, BUFSIZE, attr, 0, 0, 1, getmaxx(win) - 4, &width, 1, _("[ Press to continue ] ")); pr_center(win, y, 0, chbuf, lines, &width); wrefresh(win); diff --git a/src/intf.h b/src/intf.h index 4aa9b8e..622c85f 100644 --- a/src/intf.h +++ b/src/intf.h @@ -288,7 +288,7 @@ extern int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x, /* - Function: prepstr - Prepare a string for printing to screen + Function: mkchstr - Prepare a string for printing to screen Parameters: chbuf - Pointer to chtype buffer in which to store string chbufsize - Number of chtype elements in chbuf attr_norm - Normal character rendition to use @@ -357,14 +357,14 @@ extern int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x, This function returns the actual number of lines used (from 0 to maxlines). If an error is detected, the application terminates. */ -extern int prepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, +extern int mkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, chtype attr_alt1, chtype attr_alt2, int maxlines, int maxwidth, int *restrict widthbuf, int widthbufsize, const char *restrict format, ...); /* - Function: vprepstr - Prepare a string for printing to screen + Function: vmkchstr - Prepare a string for printing to screen Parameters: chbuf - Pointer to chtype buffer in which to store string chbufsize - Number of chtype elements in chbuf attr_norm - Normal character rendition to use @@ -374,33 +374,33 @@ extern int prepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, maxwidth - Maximum width of each line, in chars widthbuf - Pointer to buffer to store widths of each line widthbufsize - Number of int elements in widthbuf - format - Format string as described for prepstr() + format - Format string as described for mkchstr() args - Variable argument list Returns: int - Number of lines actually used - This function is exactly the same as prepstr(), except that it is + This function is exactly the same as mkchstr(), except that it is called with a va_list parameter args instead of a variable number of arguments. Note that va_end() is NOT called on args, and that args is undefined after this function. */ -extern int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, +extern int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, chtype attr_alt1, chtype attr_alt2, int maxlines, int maxwidth, int *restrict widthbuf, int widthbufsize, const char *restrict format, va_list args); /* - Function: chbufdup - Duplicate a chtype buffer - Parameters: chbuf - Buffer to duplicate - chbufsize - Number of chtype elements in chbuf - Returns: chtype * - Pointer to new duplicated buffer + Function: chstrdup - Duplicate a chtype string + Parameters: chstr - String to duplicate + chstrsize - Maximum number of chtype elements in chstr + Returns: chtype * - Pointer to new (duplicated) string - This function returns a new buffer of type chtype * that contains a - copy of the string in chbuf. No errors are returned: if sufficient + This function returns a new string of type chtype * that contains a + copy of the string in chstr. No errors are returned: if sufficient memory is not available, the program terminates with an "Out of memory" message. */ -extern chtype *chbufdup (const chtype *restrict chbuf, int chbufsize); +extern chtype *chstrdup (const chtype *restrict chstr, int chstrsize); /* @@ -408,9 +408,9 @@ extern chtype *chbufdup (const chtype *restrict chbuf, int chbufsize); Parameters: win - Window to use (should be curwin) y - Line on which to print first string x - Starting column number for each line - chbuf - chtype buffer as returned from prepstr() - lines - Number of lines in chbuf (as returned from prepstr()) - widthbuf - Widths of each line (as returned from prepstr()) + chbuf - chtype buffer as returned from mkchstr() + lines - Number of lines in chbuf (as returned from mkchstr()) + widthbuf - Widths of each line (as returned from mkchstr()) Returns: int - Error code OK This function takes the strings in the chtype array chbuf and prints @@ -426,9 +426,9 @@ extern int pr_left (WINDOW *win, int y, int x, const chtype *restrict chbuf, Parameters: win - Window to use (should be curwin) y - Line on which to print first string offset - Column offset to add to position for each line - chbuf - chtype buffer as returned from prepstr() - lines - Number of lines in chbuf (as returned from prepstr()) - widthbuf - Widths of each line (as returned from prepstr()) + chbuf - chtype buffer as returned from mkchstr() + lines - Number of lines in chbuf (as returned from mkchstr()) + widthbuf - Widths of each line (as returned from mkchstr()) Returns: int - ERR if more lines in chbuf[] than lines, else OK This function takes the strings in the chtype array chbuf and prints @@ -446,9 +446,9 @@ extern int pr_center (WINDOW *win, int y, int offset, Parameters: win - Window to use (should be curwin) y - Line on which to print first string x - Ending column number for each line - chbuf - chtype buffer as returned from prepstr() - lines - Number of lines in chbuf (as returned from prepstr()) - widthbuf - Widths of each line (as returned from prepstr()) + chbuf - chtype buffer as returned from mkchstr() + lines - Number of lines in chbuf (as returned from mkchstr()) + widthbuf - Widths of each line (as returned from mkchstr()) Returns: int - ERR if more lines in chbuf[] than lines, else OK This function takes the strings in the chtype array chbuf and prints @@ -461,7 +461,7 @@ extern int pr_right (WINDOW *win, int y, int x, const chtype *restrict chbuf, /* - Function: attrpr - Print a string with a particular character rendition + Function: old_attrpr - Print a string with a particular character rendition Parameters: win - Window to use (should be curwin) attr - Character rendition to use for the string format - printf()-like format string @@ -473,12 +473,12 @@ extern int pr_right (WINDOW *win, int y, int x, const chtype *restrict chbuf, rendition. The return code is as returned from wprintw(). Note that wrefresh() is NOT called. */ -extern int attrpr (WINDOW *win, chtype attr, const char *restrict format, ...) +extern int old_attrpr (WINDOW *win, chtype attr, const char *restrict format, ...) __attribute__((format (printf, 3, 4))); /* - Function: center - Centre a string in a given window + Function: old_center - Centre a string in a given window Parameters: win - Window to use (should be curwin) y - Line on which to centre the string attr - Character rendition to use for the string @@ -495,13 +495,13 @@ extern int attrpr (WINDOW *win, chtype attr, const char *restrict format, ...) handle multibyte strings correctly: strlen() is used to determine the printing width of the string. */ -extern int center (WINDOW *win, int y, chtype attr, +extern int old_center (WINDOW *win, int y, chtype attr, const char *restrict format, ...) __attribute__((format (printf, 4, 5))); /* - Function: center2 - Centre two strings in a given window + Function: old_center2 - Centre two strings in a given window Parameters: win - Window to use (should be curwin) y - Line on which to centre the strings attr1 - Character rendition to use for initial string @@ -521,13 +521,13 @@ extern int center (WINDOW *win, int y, chtype attr, As with center(), the current implementation does NOT handle multibyte strings correctly. */ -extern int center2 (WINDOW *win, int y, chtype attr1, chtype attr2, +extern int old_center2 (WINDOW *win, int y, chtype attr1, chtype attr2, const char *initial, const char *restrict format, ...) __attribute__((format (printf, 6, 7))); /* - Function: center3 - Centre three strings in a given window + Function: old_center3 - Centre three strings in a given window Parameters: win - Window to use (should be curwin) y - Line on which to centre the strings attr1 - Character rendition to use for initial string @@ -552,7 +552,7 @@ extern int center2 (WINDOW *win, int y, chtype attr1, chtype attr2, strings correctly. */ -extern int center3 (WINDOW *win, int y, chtype attr1, chtype attr3, +extern int old_center3 (WINDOW *win, int y, chtype attr1, chtype attr3, chtype attr2, const char *initial, const char *final, const char *restrict format, ...) __attribute__((format (printf, 8, 9))); diff --git a/src/move.c b/src/move.c index 15faadb..f6e97f1 100644 --- a/src/move.c +++ b/src/move.c @@ -233,27 +233,27 @@ selection_t get_move (void) werase(curwin); box(curwin, 0, 0); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{<1>^} Display stock portfolio"); pr_left(curwin, 2, 2, chbuf, lines, &width); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{<2>^} Declare bankruptcy"); pr_left(curwin, 3, 2, chbuf, lines, &width); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{<3>^} Save and end the game"); pr_left(curwin, 2, getmaxx(curwin) / 2, chbuf, lines, &width); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{^} Quit the game"); pr_left(curwin, 3, getmaxx(curwin) / 2, chbuf, lines, &width); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, attr_choice, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, attr_choice, 1, getmaxx(curwin) / 2 - 4, &width, 1, "Select move [^[%c^]-^[%c^]/^{1^}-^{3^}/^{^}]: ", MOVE_TO_KEY(0), MOVE_TO_KEY(NUMBER_MOVES - 1)); @@ -270,7 +270,7 @@ selection_t get_move (void) selection = KEY_TO_MOVE(key); curs_set(CURS_OFF); - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_choice, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_choice, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "Move ^{%c^}", key); pr_left(curwin, 1, getmaxx(curwin) / 2, chbuf, lines, &width); @@ -286,7 +286,7 @@ selection_t get_move (void) selection = SEL_BANKRUPT; curs_set(CURS_OFF); - lines = prepstr(chbuf, BUFSIZE, attr_normal, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{<2>^} (Declare bankruptcy)"); @@ -297,7 +297,7 @@ selection_t get_move (void) selection = SEL_SAVE; curs_set(CURS_OFF); - lines = prepstr(chbuf, BUFSIZE, attr_normal, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{<3>^} (Save and end the game)"); @@ -313,7 +313,7 @@ selection_t get_move (void) selection = SEL_QUIT; curs_set(CURS_OFF); - lines = prepstr(chbuf, BUFSIZE, attr_normal, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "^{^} (Quit the game)"); @@ -331,7 +331,7 @@ selection_t get_move (void) mvwhline(curwin, 3, 2, ' ' | attr_normal, getmaxx(curwin) - 4); // Ask the player to confirm their choice - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, 1, getmaxx(curwin) / 2 - 4, &width, 1, "Are you sure? [^{Y^}/^{N^}] "); pr_right(curwin, 2, getmaxx(curwin) / 2, chbuf, lines, &width); @@ -347,7 +347,7 @@ selection_t get_move (void) if (game_loaded) { // Save the game to the same game number - lines = prepstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1, + lines = mkchstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1, WIN_COLS - 7, &width, 1, "Saving game %d... ", game_num); newtxwin(5, width + 5, 7, WCENTER, true, attr_status_window); @@ -369,7 +369,7 @@ selection_t get_move (void) int maxwidth; - lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, + lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0, sizeof(widthbuf) / sizeof(widthbuf[0]), WIN_COLS - 7, widthbuf, sizeof(widthbuf) / sizeof(widthbuf[0]), @@ -417,7 +417,7 @@ selection_t get_move (void) // Try to save the game, if possible game_num = key - '0'; - lines = prepstr(chbuf, BUFSIZE, attr_status_window, + lines = mkchstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1, WIN_COLS - 7, &width, 1, "Saving game %d... ", game_num); newtxwin(5, width + 5, 7, WCENTER, true, attr_status_window); @@ -775,15 +775,15 @@ void merge_companies (map_val_t a, map_val_t b) newtxwin(number_players + 14, WIN_COLS - 4, 9 - number_players, WCENTER, true, attr_normal_window); - center(curwin, 1, attr_title, " Company Merger "); - center3(curwin, 3, attr_highlight, attr_highlight, attr_normal, + old_center(curwin, 1, attr_title, " Company Merger "); + old_center3(curwin, 3, attr_highlight, attr_highlight, attr_normal, company[bb].name, company[aa].name, " has just merged into "); - center(curwin, 5, attr_normal, "Please note the following transactions:"); + old_center(curwin, 5, attr_normal, "Please note the following transactions:"); - center2(curwin, 7, attr_normal, attr_highlight, " Old stock: ", + old_center2(curwin, 7, attr_normal, attr_highlight, " Old stock: ", "%-20s", company[bb].name); - center2(curwin, 8, attr_normal, attr_highlight, " New stock: ", + old_center2(curwin, 8, attr_normal, attr_highlight, " New stock: ", "%-20s", company[aa].name); // Handle the locale's currency symbol @@ -947,25 +947,25 @@ void adjust_values (void) newtxwin(14, 60, 4, WCENTER, true, attr_error_window); - center(curwin, 1, attr_error_title, " Bankruptcy Court "); - center(curwin, 3, attr_error_highlight, "%s has been declared", + old_center(curwin, 1, attr_error_title, " Bankruptcy Court "); + old_center(curwin, 3, attr_error_highlight, "%s has been declared", company[which].name); - center(curwin, 4, attr_error_highlight, + old_center(curwin, 4, attr_error_highlight, "bankrupt by the Interstellar Trading Bank."); - center2(curwin, 6, attr_error_normal, attr_error_highlight, + old_center2(curwin, 6, attr_error_normal, attr_error_highlight, "The Bank has agreed to pay stock holders ", "%4.2f%%", rate * 100.0); - center(curwin, 7, attr_error_normal, + old_center(curwin, 7, attr_error_normal, "of the share value on each share owned."); l_strfmon(buf, BUFSIZE, "%12n", company[which].share_price); - center2(curwin, 9, attr_error_normal, attr_error_highlight, + old_center2(curwin, 9, attr_error_normal, attr_error_highlight, "Old share value: ", "%s", buf); l_strfmon(buf, BUFSIZE, "%12n", company[which].share_price * rate); - center2(curwin, 10, attr_error_normal, attr_error_highlight, + old_center2(curwin, 10, attr_error_normal, attr_error_highlight, "Amount paid per share: ", "%s", buf); wait_for_key(curwin, 12, attr_error_waitforkey);