Github user mike-jumper commented on a diff in the pull request:
https://github.com/apache/guacamole-server/pull/132#discussion_r189474404
--- Diff: src/terminal/terminal.c ---
@@ -255,53 +260,252 @@ void* guac_terminal_thread(void* data) {
}
-guac_terminal* guac_terminal_create(guac_client* client,
- const char* font_name, int font_size, int dpi,
- int width, int height, const char* color_scheme,
- const int backspace) {
+/**
+ * Compare a non-null-terminated string to a null-terminated literal, in
the
+ * same manner as strcmp().
+ *
+ * @param str_start
+ * Start of the non-null-terminated string.
+ *
+ * @param str_end
+ * End of the non-null-terminated string, after the last character.
+ *
+ * @param literal
+ * The null-terminated literal to compare against.
+ *
+ * @return
+ * Zero if the two strings are equal and non-zero otherwise.
+ */
+static int guac_terminal_color_scheme_compare_token(const char* str_start,
+ const char* str_end, const char* literal) {
- int default_foreground;
- int default_background;
+ const int result = strncmp(literal, str_start, str_end - str_start);
+ if (result != 0)
+ return result;
- /* Default to "gray-black" color scheme if no scheme provided */
- if (color_scheme == NULL || color_scheme[0] == '\0') {
- default_foreground = GUAC_TERMINAL_COLOR_GRAY;
- default_background = GUAC_TERMINAL_COLOR_BLACK;
- }
+ /* At this point, literal is same length or longer than
+ * | str_end - str_start |, so if the two are equal, literal should
+ * have its null-terminator at | str_end - str_start |. */
+ return (int) (unsigned char) literal[str_end - str_start];
+}
- /* Otherwise, parse color scheme */
- else if (strcmp(color_scheme, GUAC_TERMINAL_SCHEME_GRAY_BLACK) == 0) {
- default_foreground = GUAC_TERMINAL_COLOR_GRAY;
- default_background = GUAC_TERMINAL_COLOR_BLACK;
+/**
+ * Strip the leading and trailing spaces of a bounded string.
+ *
+ * @param[in,out] str_start
+ * Address of a pointer to the start of the string. On return, the
pointer
+ * is advanced to after any leading spaces.
+ *
+ * @param[in,out] str_end
+ * Address of a pointer to the end of the string, after the last
character.
+ * On return, the pointer is moved back to before any trailing spaces.
+ */
+static void guac_terminal_color_scheme_strip_spaces(const char** str_start,
+ const char** str_end) {
+
+ /* Strip leading spaces. */
+ while (*str_start < *str_end && isspace(**str_start))
+ (*str_start)++;
+
+ /* Strip trailing spaces. */
+ while (*str_end > *str_start && isspace(*(*str_end - 1)))
+ (*str_end)--;
+}
+
+/**
+ * Parse the name part of the name-value pair within the color-scheme
+ * configuration.
+ *
+ * @param client
--- End diff --
Please document this parameter as well.
---