ali@103: #include ali@103: #include ali@103: #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: const char *s; ali@103: gunichar c; ali@103: if (aline) ali@103: { ali@103: s=aline; ali@103: while (*s==' ') ali@103: s++; ali@103: c=g_utf8_get_char(s); ali@103: } ali@103: else ali@103: { ali@103: s=NULL; ali@103: c='\0'; ali@103: } 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@103: if (c!=CHAR_DQUOTE || pswit[QPARA_SWITCH]) 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@103: if (!CHAR_IS_SQUOTE(c) || pswit[QPARA_SWITCH] || pending->squot) 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@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@103: void check_for_mismatched_quotes(const struct counters *counters, ali@103: struct pending *pending) ali@103: { ali@103: int squote_straight,squote_curved,difference; ali@103: if (counters->quot%2) ali@103: pending->dquote= ali@103: g_strdup_printf(" Line %ld - Mismatched quotes",linecnt); ali@103: if (pswit[SQUOTE_SWITCH]) ali@103: { ali@103: if (matching_count(counters,CHAR_SQUOTE,TRUE)) ali@103: squote_straight=matching_difference(counters,CHAR_SQUOTE); ali@103: else ali@103: squote_straight=0; ali@103: if (matching_count(counters,CHAR_LS_QUOTE,TRUE)) ali@103: squote_curved=matching_difference(counters,CHAR_LS_QUOTE); ali@103: else ali@103: squote_curved=0; ali@103: if (squote_straight || squote_curved) ali@103: pending->squote= ali@103: g_strdup_printf(" Line %ld - Mismatched singlequotes?", ali@103: linecnt); ali@103: if (squote_straight && squote_straight!=1 || ali@103: squote_curved && squote_curved!=1) ali@103: /* ali@103: * Flag it to be noted regardless of the ali@103: * first char of the next para. ali@103: */ ali@103: pending->squot=1; 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: }