From patchwork Fri Dec 13 18:10:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1209337 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515923-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mQ4nlsTM"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="ivoFYplG"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZJgZ0Z0Zz9sPV for ; Sat, 14 Dec 2019 05:13:13 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=qr4Why6w57vg13ZgHpKlIrI2jwJpVuFZhlGX/j1Di77f6IetM4z9v /ky87g3J6KXTVhUNY4wlMHqqbxKWxI28pU+EEuJzK5ipCOf9PgyiIyhzVrJfT8Jl 1+8boq3v+6eumYGntPOF4gsIPJ+7v4EzjHJhh6C7dflQdtXqcGZ8xo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=xO0bIH4Q18iZoFSxkfUPjbbyXGs=; b=mQ4nlsTM7FCdNujlMHEQTfzwJeex OszuErBeLsyFxz5kimt/XS69SYoWQRtLMlAD+ZUpxuxUNU2kUcOkal1GjHU8VAxx lAy2YMcdsSY7DvpK2iO/xTWTdC10hroTNVPdqWUYOA2Hq6asgtuR8qmaVrFTOKwm c50dGsrXPsu9xjI= Received: (qmail 99817 invoked by alias); 13 Dec 2019 18:11:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 99731 invoked by uid 89); 13 Dec 2019 18:11:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=START, escaped, sk:wwwgra, 3938 X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2019 18:11:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576260705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hNfw5hMTBAWfuJB4gPE+EEcw03T0RrP4hPycna4quYw=; b=ivoFYplGnSiOcQGSOrpBJoELjpOoXLa8q75zd8vp7kLQoIQlWNT+ba+Muozg7Ymz6wAvsh dG0gjHnmjXAWc4OcW6LRD7XPH1gLINojXqihdeRieLa1x2ANizzkMR3oVqON6lqpCF1mLv a13gIA8FqUXOJV5pChPwp3F6gwikYwE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-xHCZVTX5Nt-mkQhDayRmLw-1; Fri, 13 Dec 2019 13:11:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91B67800EB4 for ; Fri, 13 Dec 2019 18:11:40 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-164.phx2.redhat.com [10.3.117.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F40D5C241; Fri, 13 Dec 2019 18:11:40 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 05/45] Add pp_write_text_as_html_like_dot_to_stream Date: Fri, 13 Dec 2019 13:10:54 -0500 Message-Id: <20191213181134.1830-6-dmalcolm@redhat.com> In-Reply-To: <20191213181134.1830-1-dmalcolm@redhat.com> References: <20191213181134.1830-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes gcc/ChangeLog: * pretty-print.c (pp_write_text_as_html_like_dot_to_stream): New function. * pretty-print.h (pp_write_text_as_html_like_dot_to_stream): New decl. --- gcc/pretty-print.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/pretty-print.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 084e03c73c78..2ecb0343ba05 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -907,6 +907,54 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record) pp_clear_output_area (pp); } +/* As pp_write_text_to_stream, but for GraphViz HTML-like strings. + + Flush the formatted text of pretty-printer PP onto the attached stream, + escaping these characters + " & < > + using XML escape sequences. + + http://www.graphviz.org/doc/info/lang.html#html states: + special XML escape sequences for ", &, <, and > may be necessary in + order to embed these characters in attribute values or raw text + This doesn't list "'" (which would normally be escaped in XML + as "'" or in HTML as "'");. + + Experiments show that escaping "'" doesn't seem to be necessary. */ + +void +pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp) +{ + const char *text = pp_formatted_text (pp); + const char *p = text; + FILE *fp = pp_buffer (pp)->stream; + + for (;*p; p++) + { + switch (*p) + { + case '"': + fputs (""", fp); + break; + case '&': + fputs ("&", fp); + break; + case '<': + fputs ("<", fp); + break; + case '>': + fputs (">",fp); + break; + + default: + fputc (*p, fp); + break; + } + } + + pp_clear_output_area (pp); +} + /* Wrap a text delimited by START and END into PRETTY-PRINTER. */ static void pp_wrap_text (pretty_printer *pp, const char *start, const char *end) diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 493507d41419..86b9e869eeb7 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -393,8 +393,11 @@ extern void pp_indent (pretty_printer *); extern void pp_newline (pretty_printer *); extern void pp_character (pretty_printer *, int); extern void pp_string (pretty_printer *, const char *); + extern void pp_write_text_to_stream (pretty_printer *); extern void pp_write_text_as_dot_label_to_stream (pretty_printer *, bool); +extern void pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp); + extern void pp_maybe_space (pretty_printer *); extern void pp_begin_quote (pretty_printer *, bool);