Style corrections in the two new functions

Style changes in the two new function:
cpy_hotkeys_and_msg() & console_dialog_alloc()
This commit is contained in:
Harsh Kumar 2014-05-05 02:23:05 +05:30 committed by Justin M. Keyes
parent af05207ce7
commit cfe57fdb60

View File

@ -70,24 +70,25 @@ static void redir_write(char_u *s, int maxlen);
/// ///
/// @param message Message which will be part of the confirm_msg /// @param message Message which will be part of the confirm_msg
/// @param buttons String containing button names /// @param buttons String containing button names
/// @param has_hotkey A element in this array is TRUE if corresponding button /// @param[out] has_hotkey A element in this array is set to true if
/// has a hotkey /// corresponding button has a hotkey
/// ///
/// @return Pointer to memory allocated for storing hotkeys /// @return Pointer to memory allocated for storing hotkeys
static char_u * console_dialog_alloc(const char_u *message, static char_u * console_dialog_alloc(const char_u *message,
char_u *buttons, char_u *buttons,
char_u has_hotkey[]); bool has_hotkey[]);
/// Copies hotkeys & dialog message into the memory allocated for it /// Copies hotkeys & dialog message into the memory allocated for it
/// ///
/// @param message Message which will be part of the confirm_msg /// @param message Message which will be part of the confirm_msg
/// @param buttons String containing button names /// @param buttons String containing button names
/// @param dfltbutton Number of default button /// @param default_button_idx Number of default button
/// @param hotkp Pointer to the memory location where hotkeys will be copied /// @param has_hotkey A element in this array is true if corresponding button
/// @param has_hotkey A element in this array is TRUE if corresponding button
/// has a hotkey /// has a hotkey
static void cpy_hotkeys_and_msg(const char_u *message, char_u *buttons, /// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied
int dfltbutton, char_u *hotkp, const char_u has_hotkey[]); static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
int default_button_idx, const bool has_hotkey[],
char_u *hotkeys_ptr);
static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, static char_u *msg_show_console_dialog(char_u *message, char_u *buttons,
int dfltbutton); int dfltbutton);
@ -2861,11 +2862,10 @@ copy_char (
static char_u * console_dialog_alloc(const char_u *message, static char_u * console_dialog_alloc(const char_u *message,
char_u *buttons, char_u *buttons,
char_u has_hotkey[]) bool has_hotkey[])
{ {
int lenhotkey = HOTK_LEN; /* count first button */ int lenhotkey = HOTK_LEN; // count first button
has_hotkey[0] = false;
has_hotkey[0] = FALSE;
// Compute the size of memory to allocate. // Compute the size of memory to allocate.
int len = 0; int len = 0;
@ -2873,40 +2873,41 @@ static char_u * console_dialog_alloc(const char_u *message,
char_u *r = buttons; char_u *r = buttons;
while (*r) { while (*r) {
if (*r == DLG_BUTTON_SEP) { if (*r == DLG_BUTTON_SEP) {
len += 3; /* '\n' -> ', '; 'x' -> '(x)' */ len += 3; // '\n' -> ', '; 'x' -> '(x)'
lenhotkey += HOTK_LEN; /* each button needs a hotkey */ lenhotkey += HOTK_LEN; // each button needs a hotkey
if (idx < HAS_HOTKEY_LEN - 1) if (idx < HAS_HOTKEY_LEN - 1) {
has_hotkey[++idx] = FALSE; has_hotkey[++idx] = false;
}
} else if (*r == DLG_HOTKEY_CHAR) { } else if (*r == DLG_HOTKEY_CHAR) {
++r; r++;
++len; /* '&a' -> '[a]' */ len++; // '&a' -> '[a]'
if (idx < HAS_HOTKEY_LEN - 1) if (idx < HAS_HOTKEY_LEN - 1) {
has_hotkey[idx] = TRUE; has_hotkey[idx] = true;
}
} }
/* advance to the next character */ // Advance to the next character
mb_ptr_adv(r); mb_ptr_adv(r);
} }
len += (int)(STRLEN(message) len += (int)(STRLEN(message)
+ 2 /* for the NL's */ + 2 // for the NL's
+ STRLEN(buttons) + STRLEN(buttons)
+ 3); /* for the ": " and NUL */ + 3); // for the ": " and NUL
lenhotkey++; /* for the NUL */ lenhotkey++; // for the NUL
/* If no hotkey is specified first char is used. */ // If no hotkey is specified, first char is used.
if (!has_hotkey[0]) { if (!has_hotkey[0]) {
len += 2; /* "x" -> "[x]" */ len += 2; // "x" -> "[x]"
} }
/*
* Now allocate space for the strings // Now allocate space for the strings
*/
free(confirm_msg); free(confirm_msg);
confirm_msg = alloc(len); confirm_msg = xmalloc(len);
*confirm_msg = NUL; *confirm_msg = NUL;
return alloc(lenhotkey); return xmalloc(lenhotkey);
} }
/* /*
@ -2920,35 +2921,36 @@ static char_u * console_dialog_alloc(const char_u *message,
*/ */
static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton) static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton)
{ {
char_u has_hotkey[HAS_HOTKEY_LEN]; bool has_hotkey[HAS_HOTKEY_LEN];
char_u *hotk = console_dialog_alloc(message, buttons, has_hotkey); char_u *hotk = console_dialog_alloc(message, buttons, has_hotkey);
cpy_hotkeys_and_msg(message, buttons, dfltbutton, hotk, has_hotkey); copy_hotkeys_and_msg(message, buttons, dfltbutton, has_hotkey, hotk);
display_confirm_msg(); display_confirm_msg();
return hotk; return hotk;
} }
static void cpy_hotkeys_and_msg(const char_u *message, char_u *buttons, static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
int dfltbutton, char_u *hotkp, const char_u has_hotkey[]) int default_button_idx, const bool has_hotkey[],
char_u *hotkeys_ptr)
{ {
*confirm_msg = '\n'; *confirm_msg = '\n';
STRCPY(confirm_msg + 1, message); STRCPY(confirm_msg + 1, message);
char_u *msgp = confirm_msg + 1 + STRLEN(message); char_u *msgp = confirm_msg + 1 + STRLEN(message);
/* Define first default hotkey. Keep the hotkey string NUL // Define first default hotkey. Keep the hotkey string NUL
* terminated to avoid reading past the end. */ // terminated to avoid reading past the end.
hotkp[copy_char(buttons, hotkp, TRUE)] = NUL; hotkeys_ptr[copy_char(buttons, hotkeys_ptr, TRUE)] = NUL;
/* Remember where the choices start, displaying starts here when // Remember where the choices start, displaying starts here when
* "hotkp" typed at the more prompt. */ // "hotkeys_ptr" typed at the more prompt.
confirm_msg_tail = msgp; confirm_msg_tail = msgp;
*msgp++ = '\n'; *msgp++ = '\n';
int first_hotkey = FALSE; /* Is the first char of button a hotkey */ bool first_hotkey = false; // Is the first char of button a hotkey
if (!has_hotkey[0]) { if (!has_hotkey[0]) {
first_hotkey = TRUE; /* If no hotkey is specified, first char is used */ first_hotkey = true; // If no hotkey is specified, first char is used
} }
int idx = 0; int idx = 0;
@ -2956,41 +2958,44 @@ static void cpy_hotkeys_and_msg(const char_u *message, char_u *buttons,
while (*r) { while (*r) {
if (*r == DLG_BUTTON_SEP) { if (*r == DLG_BUTTON_SEP) {
*msgp++ = ','; *msgp++ = ',';
*msgp++ = ' '; /* '\n' -> ', ' */ *msgp++ = ' '; // '\n' -> ', '
/* advance to next hotkey and set default hotkey */ // Advance to next hotkey and set default hotkey
if (has_mbyte) hotkeys_ptr += (has_mbyte) ? STRLEN(hotkeys_ptr): 1;
hotkp += STRLEN(hotkp); hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, TRUE)] = NUL;
else
++hotkp; if (default_button_idx) {
hotkp[copy_char(r + 1, hotkp, TRUE)] = NUL; default_button_idx--;
if (dfltbutton) }
--dfltbutton;
// If no hotkey is specified, first char is used.
if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx]) {
first_hotkey = true;
}
/* If no hotkey is specified first char is used. */
if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx])
first_hotkey = TRUE;
} else if (*r == DLG_HOTKEY_CHAR || first_hotkey) { } else if (*r == DLG_HOTKEY_CHAR || first_hotkey) {
if (*r == DLG_HOTKEY_CHAR) if (*r == DLG_HOTKEY_CHAR) {
++r; ++r;
first_hotkey = FALSE; }
if (*r == DLG_HOTKEY_CHAR) /* '&&a' -> '&a' */
*msgp++ = *r;
else {
/* '&a' -> '[a]' */
*msgp++ = (dfltbutton == 1) ? '[' : '(';
msgp += copy_char(r, msgp, FALSE);
*msgp++ = (dfltbutton == 1) ? ']' : ')';
/* redefine hotkey */ first_hotkey = false;
hotkp[copy_char(r, hotkp, TRUE)] = NUL; if (*r == DLG_HOTKEY_CHAR) { // '&&a' -> '&a'
*msgp++ = *r;
} else {
// '&a' -> '[a]'
*msgp++ = (default_button_idx == 1) ? '[' : '(';
msgp += copy_char(r, msgp, FALSE);
*msgp++ = (default_button_idx == 1) ? ']' : ')';
// redefine hotkey
hotkeys_ptr[copy_char(r, hotkeys_ptr, TRUE)] = NUL;
} }
} else { } else {
/* everything else copy literally */ // everything else copy literally
msgp += copy_char(r, msgp, FALSE); msgp += copy_char(r, msgp, FALSE);
} }
/* advance to the next character */ // advance to the next character
mb_ptr_adv(r); mb_ptr_adv(r);
} }