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