#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->dquote) { 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->dquote); } else cnt_dquot++; } g_free(pending->dquote); pending->dquote=NULL; } if (pending->squote) { if (!pending->continuing_quote || !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->squote); } else cnt_squot++; } g_free(pending->squote); pending->squote=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) { int quote_straight,quote_curved,difference; quote_straight=matching_difference(counters,CHAR_DQUOTE); quote_curved=matching_difference(counters,CHAR_LD_QUOTE); if (quote_straight || quote_curved) { pending->dquote= g_strdup_printf(" Line %ld - Mismatched quotes",linecnt); if (pswit[QPARA_SWITCH] || quote_curved && quote_curved!=1 || quote_straight && quote_curved) /* * Flag it to be noted regardless of the * first line of the next para. */ pending->continuing_quote=NULL; else if (quote_straight) pending->continuing_quote=utf8_strnfill(quote_straight,CHAR_DQUOTE); else pending->continuing_quote=utf8_strnfill(quote_curved,CHAR_LD_QUOTE); } if (pswit[SQUOTE_SWITCH]) { if (matching_count(counters,CHAR_SQUOTE,TRUE)) quote_straight=matching_difference(counters,CHAR_SQUOTE); else quote_straight=0; if (matching_count(counters,CHAR_LS_QUOTE,TRUE)) quote_curved=matching_difference(counters,CHAR_LS_QUOTE); else quote_curved=0; if (quote_straight || quote_curved) pending->squote= g_strdup_printf(" Line %ld - Mismatched singlequotes?", linecnt); if (pending->continuing_quote) { /* * Flag it to be noted regardless of the * first line of the next para. */ g_free(pending->continuing_quote); pending->continuing_quote=NULL; } if (pswit[QPARA_SWITCH] || quote_straight && quote_straight!=1 || quote_curved && quote_curved!=1 || quote_straight && quote_curved) pending->continuing_quote=NULL; else if (quote_straight) pending->continuing_quote=utf8_strnfill(quote_straight,CHAR_SQUOTE); else pending->continuing_quote=utf8_strnfill(quote_curved,CHAR_LS_QUOTE); } 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); }