#include #include #include #include #include "bookloupe.h" #include "pending.h" /* * print_pending: * * If we are in a state of unbalanced quotes, and this line * doesn't begin with a quote, output the stored error message. * If the -p switch was used, print the warning even if the * new para starts with quotes. */ void print_pending(const char *aline,const char *parastart, struct pending *pending) { if (aline) while (g_unichar_isspace(g_utf8_get_char(aline))) aline=g_utf8_next_char(aline); if (pending->illustration.warning_text) { if (aline) { if (pswit[ECHO_SWITCH] && !pending->illustration.queried_line) pending->illustration.queried_line=g_strdup(parastart); } else { if (!pswit[OVERVIEW_SWITCH]) { if (pending->illustration.queried_line) g_print("\n%s\n",pending->illustration.queried_line); g_print("%s\n",pending->illustration.warning_text); } else cnt_brack++; g_free(pending->illustration.warning_text); pending->illustration.warning_text=NULL; g_free(pending->illustration.queried_line); pending->illustration.queried_line=NULL; } } if (pending->quote) { if (!pending->continuing_quote || !aline || !g_str_has_prefix(aline,pending->continuing_quote)) { if (!pswit[OVERVIEW_SWITCH]) { if (pswit[ECHO_SWITCH]) g_print("\n%s\n",parastart); g_print("%s\n",pending->quote); } else cnt_quote++; } g_free(pending->quote); pending->quote=NULL; } g_free(pending->continuing_quote); pending->continuing_quote=NULL; if (pending->rbrack) { if (!pswit[OVERVIEW_SWITCH]) { if (pswit[ECHO_SWITCH]) g_print("\n%s\n",parastart); g_print("%s\n",pending->rbrack); } else cnt_brack++; g_free(pending->rbrack); pending->rbrack=NULL; } if (pending->sbrack) { if (!pswit[OVERVIEW_SWITCH]) { if (pswit[ECHO_SWITCH]) g_print("\n%s\n",parastart); g_print("%s\n",pending->sbrack); } else cnt_brack++; g_free(pending->sbrack); pending->sbrack=NULL; } if (pending->cbrack) { if (!pswit[OVERVIEW_SWITCH]) { if (pswit[ECHO_SWITCH]) g_print("\n%s\n",parastart); g_print("%s\n",pending->cbrack); } else cnt_brack++; g_free(pending->cbrack); pending->cbrack=NULL; } if (pending->unders) { if (!pswit[OVERVIEW_SWITCH]) { if (pswit[ECHO_SWITCH]) g_print("\n%s\n",parastart); g_print("%s\n",pending->unders); } else cnt_brack++; g_free(pending->unders); pending->unders=NULL; } } void reset_pending(struct pending *pending) { memset(pending,0,sizeof(*pending)); } /* * check_for_mismatched_quotes: * * At end of paragraph, check for mismatched quotes. * * We don't want to report an error immediately, since it is a * common convention to omit the quotes at end of paragraph if * the next paragraph is a continuation of the same speaker. * Where this is the case, the next para should begin with a * quote, so we store the warning message and only display it * at the top of the next iteration if the new para doesn't * start with a quote. * The -p switch overrides this default, and warns of unclosed * quotes on _every_ paragraph, whether the next begins with a * quote or not. */ void check_for_mismatched_quotes(struct counters *counters, struct pending *pending) { gboolean all_single; gunichar c; int difference; const char *quote_type; GString *str; if (counters->open_quotes) { str=g_string_new(NULL); counters->open_quotes=g_slist_reverse(counters->open_quotes); all_single=TRUE; while(counters->open_quotes) { c=GPOINTER_TO_INT(counters->open_quotes->data); if (!CHAR_IS_SQUOTE(c)) all_single=FALSE; g_string_append_unichar(str,c); counters->open_quotes=g_slist_delete_link(counters->open_quotes, counters->open_quotes); } pending->continuing_quote=g_string_free(str,FALSE); if (all_single) quote_type="singlequotes?"; else quote_type="quotes"; pending->quote=g_strdup_printf(" Line %ld - Mismatched %s",linecnt, quote_type); } difference=matching_difference(counters,COUNTER_ILLUSTRATION); if (difference) { if (difference<0 && pending->illustration.warning_text) { difference++; g_free(pending->illustration.queried_line); pending->illustration.queried_line=NULL; g_free(pending->illustration.warning_text); pending->illustration.warning_text=NULL; } if (difference<0) { increment_matching(counters,CHAR_OPEN_SBRACK,FALSE); difference++; } if (difference) { if (pending->illustration.warning_text) { if (!pswit[OVERVIEW_SWITCH]) { if (pending->illustration.queried_line) g_print("\n%s\n",pending->illustration.queried_line); g_print("%s\n",pending->illustration.warning_text); } else cnt_brack++; g_free(pending->illustration.warning_text); } pending->illustration.warning_text=g_strdup_printf( " Line %ld - Mismatched illustration tag?",linecnt); g_free(pending->illustration.queried_line); pending->illustration.queried_line=NULL; } } if (matching_difference(counters,CHAR_OPEN_RBRACK)) pending->rbrack= g_strdup_printf(" Line %ld - Mismatched round brackets?",linecnt); if (matching_difference(counters,CHAR_OPEN_SBRACK)) pending->sbrack= g_strdup_printf(" Line %ld - Mismatched square brackets?",linecnt); if (matching_difference(counters,CHAR_OPEN_CBRACK)) pending->cbrack= g_strdup_printf(" Line %ld - Mismatched curly brackets?",linecnt); if (counters->c_unders%2) pending->unders= g_strdup_printf(" Line %ld - Mismatched underscores?",linecnt); }