Example #1
0
void file_view(const datat &data)
{
  std::ofstream out("file_view.html");

  out << "<html>\n<head>\n";
  out << "<title>" << html_escape(data.description) << "</title>\n";
  
  out << "<style type=\"text/css\">\n";
  out << "/* Source-code listing */\n";
  out << "div.file { float: left; padding-right: 20px; }\n";
  out << "div.listing { font-size: 3px; width: 150px; height: 400px; overflow-y: scroll; overflow-x: scroll; white-space: pre; }\n";
  out << "div.filename { text-align: center; font-size: 14px; width: 150px; }\n";

  out << "strong.alarm { font-style: normal; background-color: #ff6633; font-weight: normal; }\n";
  
  out << "/* Description of sw under test */\n";
  out << "div.description { float: center; font: 14px \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;  width=100%; text-align: center; }\n";
  
  out << "</style>\n";
  out << "</head>\n";
  
  out << "<body>\n";
  
  out << "<center><img src=\"http://www.deltacheck.org/deltacheck_logo_small.png\"></center>\n";
  
  out << "<div class=\"description\">\n";
  out << html_escape(data.description) << "\n";
  out << "</div>\n";
  
  std::set<irep_idt> files;
  
  for(datat::propertiest::const_iterator
      e_it=data.properties.begin();
      e_it!=data.properties.end();
      e_it++)
    files.insert(e_it->file);

  for(std::set<irep_idt>::const_iterator
      f_it=files.begin();
      f_it!=files.end();
      f_it++)
  {
    if(has_prefix(id2string(*f_it), "/usr/include/"))
      continue;
  
    if(has_prefix(id2string(*f_it), "<builtin-library>"))
      continue;
  
    print_file(data, *f_it, out);
  }
  
  out << "</body>\n</html>\n";
}
Example #2
0
void print_file(const datat &data, irep_idt file, std::ostream &out)
{
  out << "<div class=\"file\" onclick=\"location.href='"
      << html_escape(id2string(file)+".html")
      << "';\" style=\"cursor:pointer;\">\n";
  out << "<div class=\"filename\">" << html_escape(file) << "</div>\n";
  out << "<div class=\"listing\">\n";

  std::ifstream in(file.c_str());
  if(!in)
  {
  }
  else
  {
    // line to property number
    std::map<unsigned, std::vector<unsigned> > line_map;
    
    for(datat::propertiest::const_iterator
        e_it=data.properties.begin();
        e_it!=data.properties.end();
        e_it++)
      if(e_it->file==file)
      {
        line_map[e_it->line].push_back(e_it-data.properties.begin());
      }
  
    syntax_highlightingt syntax_highlighting(out);

    unsigned line_no=1;

    std::string line;
    while(std::getline(in, line))
    {
      syntax_highlighting.strong_class="";
      syntax_highlighting.line_no=line_no;
      
      std::vector<unsigned> &properties=line_map[line_no];
      
      if(!properties.empty())
      {
        syntax_highlighting.strong_class="alarm";
      }
      
      syntax_highlighting(line);
      
      line_no++;
    }
  }
  
  out << "</div></div>\n\n";
}
Example #3
0
static void report_section(std::ostringstream & out, const std::string & name, M & module, bool html)
{
    if (html)
    {
        out << "<h1 id=\"" << html_escape(name) << "\">" << html_escape(name) << "</h1>";
    }
    else
    {
        out << "# " << name << "\n";
    }
    module.report(out, html);
    if (!html)
    {
        out << "\n";
    }
}
Example #4
0
        void TemplateTagAttr::render(std::string &buffer, expr::Scope &scope)const
        {
            std::vector<ObjectPtr> values;
            for (auto &expr : dynamic_values)
            {
                auto val = expr->eval(scope);
                add_attr_value(values, val);
            }

            if (static_values.empty() && values.empty()) return;

            if (static_values.empty() && values.size() == 1)
            {
                if (values[0] == TRUE_VALUE)
                {
                    buffer += ' ' + attr;
                    return;
                }
                else if (values[0] == FALSE_VALUE || values[0] == NIL_VALUE) return;
            }

            std::vector<std::string> strings = static_values;
            for (auto &v : values) strings.push_back(html_escape(v));

            buffer += attr_str(attr, strings);
        }
Example #5
0
 std::string operator()(const lambda& value) const {
   template_type interpreted{value([this](const mstch::node& n) {
     return visit(render_node(ctx), n);
   })};
   auto rendered = render_context::push(ctx).render(interpreted);
   return (m_flag == flag::escape_html) ? html_escape(rendered) : rendered;
 }
Example #6
0
void GDBOutputWidget::newStdoutLine(const QString& line,
                                    bool internal)
{
    QString s = html_escape(line);
    if (s.startsWith("(gdb)"))
    {
        s = colorify(s, "blue");
    }

    allCommands_.append(s);
    allCommandsRaw_.append(line);
    trimList(allCommands_, maxLines_);
    trimList(allCommandsRaw_, maxLines_);

    if (!internal)
    {
        userCommands_.append(s);
        userCommandsRaw_.append(line);
        trimList(userCommands_, maxLines_);
        trimList(userCommandsRaw_, maxLines_);
    }

    if (!internal || showInternalCommands_)
        showLine(s);
}
Example #7
0
static int html_link(
  struct Blob *ob,
  struct Blob *link,
  struct Blob *title,
  struct Blob *content,
  void *opaque
){
  BLOB_APPEND_LITERAL(ob, "<a href=\"");
  html_escape(ob, blob_buffer(link), blob_size(link));
  if( title && blob_size(title)>0 ){
    BLOB_APPEND_LITERAL(ob, "\" title=\"");
    html_escape(ob, blob_buffer(title), blob_size(title));
  }
  BLOB_APPEND_LITERAL(ob, "\">");
  BLOB_APPEND_BLOB(ob, content);
  BLOB_APPEND_LITERAL(ob, "</a>");
  return 1;
}
Example #8
0
static int html_image(
  struct Blob *ob,
  struct Blob *link,
  struct Blob *title,
  struct Blob *alt,
  void *opaque
){
  BLOB_APPEND_LITERAL(ob, "<img src=\"");
  html_escape(ob, blob_buffer(link), blob_size(link));
  BLOB_APPEND_LITERAL(ob, "\" alt=\"");
  html_escape(ob, blob_buffer(alt), blob_size(alt));
  if( title && blob_size(title)>0 ){
    BLOB_APPEND_LITERAL(ob, "\" title=\"");
    html_escape(ob, blob_buffer(title), blob_size(title));
  }
  BLOB_APPEND_LITERAL(ob, "\" />");
  return 1;
}
Example #9
0
bool UatDialog::trySetErrorHintFromField(const QModelIndex &index)
{
    const QVariant &data = uat_model_->data(index, Qt::UserRole + 1);
    if (!data.isNull()) {
        // use HTML instead of PlainText because that handles wordwrap properly
        ui->hintLabel->setText(html_escape(data.toString()));
        return true;
    }
    return false;
}
Example #10
0
        void TemplateTagSplatAttrs::render(std::string &buffer, expr::Scope &scope)const
        {
            std::unordered_map<std::string, std::vector<Ptr<Object>>> attrs;
            //Determine all attributes
            for (auto &i : static_attrs)
                attrs[i.first].push_back(make_value(i.second));

            for (auto &i : dynamic_attrs)
            {
                auto &attr = attrs[i.first];
                auto val = i.second->eval(scope);
                add_attr_value(attr, val);
            }

            for (auto &splat : splat_attrs)
            {
                auto hash = coerce<Hash>(splat->eval(scope));
                for (auto &i : *hash)
                {
                    auto &attr = attrs[i.first->to_string()];
                    auto val = i.second;
                    add_attr_value(attr, val);
                }
            }
            //Output attributes
            for (auto &i : attrs)
            {
                auto &name = html_escape(i.first);
                auto &values = i.second;

                if (values.empty()) continue; //empty / no value
                else if (values.size() == 1)
                {
                    auto val = values[0];
                    if (val == TRUE_VALUE) //true boolean attr
                    {
                        buffer += ' ';
                        buffer += name;
                    }
                    else if (val == FALSE_VALUE || val == NIL_VALUE) //false boolean attr
                    {
                        continue;
                    }
                    else buffer += attr_str(name, {val->to_string()});
                }
                else
                {
                    //array of values, e.g. "class"
                    std::vector<std::string> strings;
                    for (auto &j : values) strings.push_back(j->to_string());
                    buffer += attr_str(name, strings);
                }
            }
        }
Example #11
0
static int html_autolink(
  struct Blob *ob,
  struct Blob *link,
  enum mkd_autolink type,
  void *opaque
){
  if( !link || blob_size(link)<=0 ) return 0;
  BLOB_APPEND_LITERAL(ob, "<a href=\"");
  if( type==MKDA_IMPLICIT_EMAIL ) BLOB_APPEND_LITERAL(ob, "mailto:");
  html_escape(ob, blob_buffer(link), blob_size(link));
  BLOB_APPEND_LITERAL(ob, "\">");
  if( type==MKDA_EXPLICIT_EMAIL && blob_size(link)>7 ){
    /* remove "mailto:" from displayed text */
    html_escape(ob, blob_buffer(link)+7, blob_size(link)-7);
  }else{
    html_escape(ob, blob_buffer(link), blob_size(link));
  }
  BLOB_APPEND_LITERAL(ob, "</a>");
  return 1;
}
Example #12
0
void GDBOutputWidget::slotReceivedStderr(const char* line)
{
    QString colored = colorify(html_escape(line), "red");
    // Errors are shown inside user commands too.
    allCommands_.append(colored);
    trimList(allCommands_, maxLines_);
    userCommands_.append(colored);
    trimList(userCommands_, maxLines_);

    allCommandsRaw_.append(line);
    trimList(allCommandsRaw_, maxLines_);
    userCommandsRaw_.append(line);
    trimList(userCommandsRaw_, maxLines_);

    showLine(colored);
}
Example #13
0
File: 905.c Project: shtyd/syspro
void
safe_print_string( char *str )
{
	char *safe_str ;

	if( str == 0 )
	{
		printf("(null)");
		return;
	}
	safe_str = html_escape( str );
	if( safe_str == 0 )
	{
		printf("(no memory)");
	}
	else
	{
		printf("%s",safe_str );
		free( safe_str );
	}
}
Example #14
0
std::string AI::describe_unit(df::unit *u, bool html)
{
    // Unknown Unit
    if (!u)
    {
        if (html)
        {
            return "<i>(unknown unit)</i>";
        }
        return "(unknown unit)";
    }

    // Name
    std::string s = describe_name(u->name);
    if (!s.empty())
    {
        s += ", ";
    }

    // Curse Name
    if (!u->curse.name.empty())
    {
        s += u->curse.name;
        s += " ";
    }

    // Profession Name
    s += Units::getProfessionName(u);
    if (html)
    {
        s = html_escape(s);
        if (u->hist_figure_id != -1)
        {
            s = stl_sprintf("<a href=\"fig-%d\">", u->hist_figure_id) + s + "</a>";
        }
    }
    return s;
}
Example #15
0
static void show_breadcrump_field (const char *str, /* {{{ */
    const char *field_name)
{
  if ((str == NULL) || (str[0] == 0))
    printf ("<em>none</em>");
  else if (IS_ANY (str))
    printf ("<em>any</em>");
  else if (IS_ALL (str))
    printf ("<em>all</em>");
  else
  {
    char *str_html = html_escape (str);

    if (field_name != NULL)
      printf ("<a href=\"%s?action=search;q=%s:%s\">%s</a>",
          script_name (), field_name, str_html, str_html);
    else
      printf ("<a href=\"%s?action=search;q=%s\">%s</a>",
          script_name (), str_html, str_html);

    free (str_html);
  }
} /* }}} void show_breadcrump_field */
Example #16
0
/* set an attribute */
static void attrsetn_internal(attrlist_t al, const char *name, int safe_fl, const _char *value, size_t len)
{
	attr_t *at;
	at=setup_access(al, name);
	/* a null value would delete the attribute */
	if(value==NULL) {
		if(at) attrdel(al, at); /* delete if there is no value */
		return;
	}
	/* discard the old attribute values */
	free(at->value);
	at->value=NULL;
	/* set the attribute */
	if(safe_fl) {
		at->len=html_escape_len(value, len);
		at->value=malloc(at->len+1);
		html_escape(at->value, at->len, value);
	} else {
		at->len=len;
		at->value=malloc(len+1);
		memcpy(at->value, value, at->len+1);
	}
}
Example #17
0
 void TemplateOutputExpr::render(std::string & buffer, expr::Scope &scope) const
 {
     auto val = expression->eval(scope);
     buffer += html_escape(val);
 }
Example #18
0
std::string html_escape(const dstring &src)
{
  return html_escape(as_string(src));
}
Example #19
0
/**
 * Writes the browse host data of the context ``ctx'' to the buffer
 * ``dest''. This must be called multiple times to retrieve the complete
 * data until zero is returned i.e., the end of file is reached.
 *
 * This routine deals with HTML data generation.
 *
 * @param ctx an initialized browse host context.
 * @param dest the destination buffer.
 * @param size the amount of bytes ``dest'' can hold.
 *
 * @return -1 on failure, zero at the end-of-file condition or if size
 *         was zero. On success, the amount of bytes copied to ``dest''
 *         is returned.
 */
static ssize_t
browse_host_read_html(struct special_upload *ctx,
	void *const dest, size_t size)
{
	static const char header[] =
		"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\r\n"
		"<html>\r\n"
		"<head>\r\n"
		"<title>Browse Host</title>\r\n"
		"</head>\r\n"
		"<body>\r\n";
	static const char trailer[] = "</ul>\r\n</body>\r\n</html>\r\n";
	struct browse_host_upload *bh = cast_to_browse_host_upload(ctx);
	char *p = dest;

	g_assert(NULL != bh);
	g_assert(NULL != dest);
	g_assert(size <= INT_MAX);

	g_assert(UNSIGNED(bh->state) < NUM_BH_STATES);
	g_assert(bh->b_size <= INT_MAX);
	g_assert(bh->b_offset <= bh->b_size);

	do {
		switch (bh->state) {
		case BH_STATE_HEADER:
			if (!bh->b_data) {
				bh->b_data = header;
				bh->b_size = CONST_STRLEN(header);
			}
			p += browse_host_read_data(bh, p, &size);
			if (bh->b_size == bh->b_offset)
				browse_host_next_state(bh, BH_STATE_LIBRARY_INFO);
			break;

		case BH_STATE_LIBRARY_INFO:
			if (!bh->b_data) {
				bh->w_buf_size = w_concat_strings(&bh->w_buf,
					"<h1>", product_get_name(), "</h1>\r\n"
					"<h3>", version_get_string(),
				   	" sharing ",
					uint64_to_string(shared_files_scanned()),
					" file",
					shared_files_scanned() == 1 ? "" : "s",
					" ",
					short_kb_size(shared_kbytes_scanned(),
						GNET_PROPERTY(display_metric_units)),
					" total</h3>\r\n"
					"<ul>\r\n", (void *) 0);
				bh->b_data = bh->w_buf;
				bh->b_size = bh->w_buf_size - 1; /* minus trailing NUL */
				bh->b_offset = 0;
			}
			p += browse_host_read_data(bh, p, &size);
			if (bh->b_size == bh->b_offset)
				browse_host_next_state(bh, BH_STATE_FILES);
			break;

		case BH_STATE_TRAILER:
			if (!bh->b_data) {
				bh->b_data = trailer;
				bh->b_size = CONST_STRLEN(trailer);
			}
			p += browse_host_read_data(bh, p, &size);
			if (bh->b_size == bh->b_offset)
				browse_host_next_state(bh, BH_STATE_EOF);
			break;

		case BH_STATE_FILES:
			if (bh->b_data && bh->b_size == bh->b_offset) {
				g_assert(bh->w_buf == bh->b_data);
				wfree(bh->w_buf, bh->w_buf_size);
				bh->w_buf = NULL;
				bh->w_buf_size = 0;
				bh->b_data = NULL;
			}

			if (!bh->b_data) {
				const shared_file_t *sf;

				bh->file_index++;
				sf = shared_file_sorted(bh->file_index);
				if (!sf) {
				   	if (bh->file_index > shared_files_scanned())
						browse_host_next_state(bh, BH_STATE_TRAILER);
					/* Skip holes in the file_index table */
				} else if (SHARE_REBUILDING == sf) {
					browse_host_next_state(bh, BH_STATE_REBUILDING);
				} else {
					const char * const name_nfc = shared_file_name_nfc(sf);
					const filesize_t file_size = shared_file_size(sf);
					size_t html_size;
					char *html_name;

					{
						const char *dir;
						char *name;
						
						dir = shared_file_relative_path(sf);
						if (dir) {
							name = h_strconcat(dir, "/", name_nfc, (void *) 0);
						} else {
							name = deconstify_char(name_nfc);
						}

						html_size = 1 + html_escape(name, NULL, 0);
						html_name = walloc(html_size);
						html_escape(name, html_name, html_size);
						if (name != name_nfc) {
							HFREE_NULL(name);
						}
					}

					if (sha1_hash_available(sf)) {
						const struct sha1 *sha1 = shared_file_sha1(sf);

						bh->w_buf_size = w_concat_strings(&bh->w_buf,
							"<li><a href=\"/uri-res/N2R?urn:sha1:",
							sha1_base32(sha1),
							"\">", html_name, "</a>&nbsp;[",
							short_html_size(file_size,
								GNET_PROPERTY(display_metric_units)),
							"]</li>\r\n",
							(void *) 0);
					} else {
						char *escaped;

						escaped = url_escape(name_nfc);
						bh->w_buf_size = w_concat_strings(&bh->w_buf,
							"<li><a href=\"/get/",
							uint32_to_string(shared_file_index(sf)),
							"/", escaped, "\">", html_name, "</a>"
							"&nbsp;[",
							short_html_size(file_size,
								GNET_PROPERTY(display_metric_units)),
							"]</li>\r\n", (void *) 0);

						if (escaped != name_nfc) {
							HFREE_NULL(escaped);
						}
					}

					wfree(html_name, html_size);
					bh->b_data = bh->w_buf;
					bh->b_size = bh->w_buf_size - 1; /* minus trailing NUL */
					bh->b_offset = 0;
				}
			}

			if (bh->b_data)
				p += browse_host_read_data(bh, p, &size);

			break;

		case BH_STATE_REBUILDING:
			if (!bh->b_data) {
				static const char msg[] =
					"<li>"
						"<b>"
							"The library is currently being rebuild. Please, "
							"try again in a moment."
						"</b>"
					"</li>";

				bh->b_data = msg;
				bh->b_size = CONST_STRLEN(msg);
			}
			p += browse_host_read_data(bh, p, &size);
			if (bh->b_size == bh->b_offset)
				browse_host_next_state(bh, BH_STATE_TRAILER);
			break;

		case BH_STATE_EOF:
			return p - cast_to_char_ptr(dest);

		case NUM_BH_STATES:
			g_assert_not_reached();
		}
	} while (size > 0);

	return p - cast_to_char_ptr(dest);
}
Example #20
0
static int html_code_span(struct Blob *ob, struct Blob *text, void *opaque){
  BLOB_APPEND_LITERAL(ob, "<code>");
  html_escape(ob, blob_buffer(text), blob_size(text));
  BLOB_APPEND_LITERAL(ob, "</code>");
  return 1;
}
Example #21
0
static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
  INTER_BLOCK(ob);
  BLOB_APPEND_LITERAL(ob, "<pre><code>");
  html_escape(ob, blob_buffer(text), blob_size(text));
  BLOB_APPEND_LITERAL(ob, "</code></pre>\n");
}
Example #22
0
 std::string operator()(const std::string& value) const {
   return (m_flag == flag::escape_html) ? html_escape(value) : value;
 }
Example #23
0
static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
  html_escape(ob, blob_buffer(text), blob_size(text));
}
/* Add a single preference to the QVBoxLayout of a preference page */
static guint
pref_show(pref_t *pref, gpointer layout_ptr)
{
    QVBoxLayout *vb = static_cast<QVBoxLayout *>(layout_ptr);

    if (!pref || !vb) return 0;

    // Convert the pref description from plain text to rich text.
    QString description = html_escape(prefs_get_description(pref));
    description.replace('\n', "<br>");
    QString tooltip = QString("<span>%1</span>").arg(description);

    switch (prefs_get_type(pref)) {
    case PREF_UINT:
    case PREF_DECODE_AS_UINT:
    {
        QHBoxLayout *hb = new QHBoxLayout();
        QLabel *label = new QLabel(prefs_get_title(pref));
        label->setToolTip(tooltip);
        hb->addWidget(label);
        QLineEdit *uint_le = new QLineEdit();
        uint_le->setToolTip(tooltip);
        uint_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        uint_le->setMinimumWidth(uint_le->fontMetrics().height() * 8);
        hb->addWidget(uint_le);
        hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
        vb->addLayout(hb);
        break;
    }
    case PREF_BOOL:
    {
        QCheckBox *bool_cb = new QCheckBox(title_to_shortcut(prefs_get_title(pref)));
        bool_cb->setToolTip(tooltip);
        bool_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        vb->addWidget(bool_cb);
        break;
    }
    case PREF_ENUM:
    {
        const enum_val_t *ev;
        if (prefs_get_enumvals(pref) == NULL) return 0;

        if (prefs_get_enum_radiobuttons(pref)) {
            QLabel *label = new QLabel(prefs_get_title(pref));
            label->setToolTip(tooltip);
            vb->addWidget(label);
            QButtonGroup *enum_bg = new QButtonGroup(vb);
            for (ev = prefs_get_enumvals(pref); ev && ev->description; ev++) {
                QRadioButton *enum_rb = new QRadioButton(title_to_shortcut(ev->description));
                enum_rb->setToolTip(tooltip);
                QStyleOption style_opt;
                enum_rb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
                enum_rb->setStyleSheet(QString(
                                      "QRadioButton {"
                                      "  margin-left: %1px;"
                                      "}"
                                      )
                                  .arg(enum_rb->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
                enum_bg->addButton(enum_rb, ev->value);
                vb->addWidget(enum_rb);
            }
        } else {
            QHBoxLayout *hb = new QHBoxLayout();
            QComboBox *enum_cb = new QComboBox();
            enum_cb->setToolTip(tooltip);
            enum_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
            for (ev = prefs_get_enumvals(pref); ev && ev->description; ev++) {
                enum_cb->addItem(ev->description, QVariant(ev->value));
            }
            hb->addWidget(new QLabel(prefs_get_title(pref)));
            hb->addWidget(enum_cb);
            hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
            vb->addLayout(hb);
        }
        break;
    }
    case PREF_STRING:
    {
        QHBoxLayout *hb = new QHBoxLayout();
        QLabel *label = new QLabel(prefs_get_title(pref));
        label->setToolTip(tooltip);
        hb->addWidget(label);
        QLineEdit *string_le = new QLineEdit();
        string_le->setToolTip(tooltip);
        string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
        hb->addWidget(string_le);
        hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
        vb->addLayout(hb);
        break;
    }
    case PREF_DECODE_AS_RANGE:
    case PREF_RANGE:
    {
        QHBoxLayout *hb = new QHBoxLayout();
        QLabel *label = new QLabel(prefs_get_title(pref));
        label->setToolTip(tooltip);
        hb->addWidget(label);
        SyntaxLineEdit *range_se = new SyntaxLineEdit();
        range_se->setToolTip(tooltip);
        range_se->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        range_se->setMinimumWidth(range_se->fontMetrics().height() * 20);
        hb->addWidget(range_se);
        hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
        vb->addLayout(hb);
        break;
    }
    case PREF_STATIC_TEXT:
    {
        QLabel *label = new QLabel(prefs_get_title(pref));
        label->setToolTip(tooltip);
        label->setWordWrap(true);
        vb->addWidget(label);
        break;
    }
    case PREF_UAT:
    {
        QHBoxLayout *hb = new QHBoxLayout();
        QLabel *label = new QLabel(prefs_get_title(pref));
        label->setToolTip(tooltip);
        hb->addWidget(label);
        QPushButton *uat_pb = new QPushButton(QObject::tr("Edit" UTF8_HORIZONTAL_ELLIPSIS));
        uat_pb->setToolTip(tooltip);
        uat_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        hb->addWidget(uat_pb);
        hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
        vb->addLayout(hb);
        break;
    }
    case PREF_SAVE_FILENAME:
    case PREF_OPEN_FILENAME:
    case PREF_DIRNAME:
    {
        QLabel *label = new QLabel(prefs_get_title(pref));
        label->setToolTip(tooltip);
        vb->addWidget(label);
        QHBoxLayout *hb = new QHBoxLayout();
        QLineEdit *path_le = new QLineEdit();
        path_le->setToolTip(tooltip);
        QStyleOption style_opt;
        path_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        path_le->setMinimumWidth(path_le->fontMetrics().height() * 20);
        path_le->setStyleSheet(QString(
                              "QLineEdit {"
                              "  margin-left: %1px;"
                              "}"
                              )
                          .arg(path_le->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
        hb->addWidget(path_le);
        QPushButton *path_pb = new QPushButton(QObject::tr("Browse" UTF8_HORIZONTAL_ELLIPSIS));
        path_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
        hb->addWidget(path_pb);
        hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
        vb->addLayout(hb);
        break;
    }
    case PREF_COLOR:
    {
        // XXX - Not needed yet. When it is needed we can add a label + QFrame which pops up a
        // color picker similar to the Font and Colors prefs.
        break;
    }
    default:
        break;
    }
    return 0;
}
Example #25
0
int
notify_html_listeners(int descr, dbref who, dbref xprog, dbref obj,
                      dbref room, const char *msg, int isprivate)
{
    char buf[BUFFER_LEN], *nohbuf, *noabuf, buf2[BUFFER_LEN];
    dbref ref;

    if (obj == NOTHING)
        return 0;

    nohbuf = html_escape(msg);
    noabuf = tct(buf2, nohbuf);

    if (tp_listeners && (tp_listeners_obj || Typeof(obj) == TYPE_ROOM)) {
        listenqueue(descr, who, room, obj, obj, xprog, "_listen", nohbuf,
                    tp_listen_mlev, 1, 0);
        listenqueue(descr, who, room, obj, obj, xprog, "_olisten", nohbuf,
                    tp_listen_mlev, 0, 0);
        listenqueue(descr, who, room, obj, obj, xprog, "~listen", nohbuf,
                    tp_listen_mlev, 1, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "~olisten", nohbuf,
                    tp_listen_mlev, 0, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "@listen", nohbuf,
                    tp_listen_mlev, 1, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "@olisten", nohbuf,
                    tp_listen_mlev, 0, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "_alisten", noabuf,
                    tp_listen_mlev, 1, 0);
        listenqueue(descr, who, room, obj, obj, xprog, "_aolisten", noabuf,
                    tp_listen_mlev, 0, 0);
        listenqueue(descr, who, room, obj, obj, xprog, "~alisten", noabuf,
                    tp_listen_mlev, 1, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "~aolisten", noabuf,
                    tp_listen_mlev, 0, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "@alisten", noabuf,
                    tp_listen_mlev, 1, 1);
        listenqueue(descr, who, room, obj, obj, xprog, "@aolisten", noabuf,
                    tp_listen_mlev, 0, 1);
        /* Loop up the environment only if tp_listeners_env is set and obj
         * is a room. Runs once otherwise. -brevantes */
        if (tp_listeners_env && (Typeof(obj) == TYPE_ROOM) ) {
            obj = DBFETCH(obj)->location;
            for (;obj != NOTHING;obj = DBFETCH(obj)->location) {
                listenqueue(descr, who, room, obj, obj, xprog, "_listen", nohbuf,
                            tp_listen_mlev, 1, 0);
                listenqueue(descr, who, room, obj, obj, xprog, "_olisten", nohbuf,
                            tp_listen_mlev, 0, 0);
                listenqueue(descr, who, room, obj, obj, xprog, "~listen", nohbuf,
                            tp_listen_mlev, 1, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "~olisten", nohbuf,
                            tp_listen_mlev, 0, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "@listen", nohbuf,
                            tp_listen_mlev, 1, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "@olisten", nohbuf,
                            tp_listen_mlev, 0, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "_alisten", noabuf,
                            tp_listen_mlev, 1, 0);
                listenqueue(descr, who, room, obj, obj, xprog, "_aolisten", noabuf,
                            tp_listen_mlev, 0, 0);
                listenqueue(descr, who, room, obj, obj, xprog, "~alisten", noabuf,
                            tp_listen_mlev, 1, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "~aolisten", noabuf,
                            tp_listen_mlev, 0, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "@alisten", noabuf,
                            tp_listen_mlev, 1, 1);
                listenqueue(descr, who, room, obj, obj, xprog, "@aolisten", noabuf,
                            tp_listen_mlev, 0, 1);
            }
            return 0;
        }
    }

    if (tp_zombies && (Typeof(obj) == TYPE_THING) && !isprivate
        && !(FLAGS(obj) & QUELL)) {
        if (FLAGS(obj) & VEHICLE) {
            if (getloc(who) == getloc(obj)) {
                char pbuf[BUFFER_LEN];
                const char *prefix;

                prefix = GETOECHO(obj);
                if (prefix && *prefix) {
                    prefix = do_parse_mesg(-1, who, obj, prefix,
                                           "(@Oecho)", pbuf, MPI_ISPRIVATE);
                }                if (!prefix || !*prefix)
                    prefix = "Outside>";
                sprintf(buf, "%s %.*s", prefix,
                        (int) (BUFFER_LEN - 2 - strlen(prefix)), msg);
                ref = DBFETCH(obj)->contents;
                while (ref != NOTHING) {
#ifdef IGNORE_SUPPORT
                    if (!ignorance(who, ref))
#endif /* IGNORE_SUPPORT */
                        notify_html_nolisten(ref, buf, isprivate);
                    ref = DBFETCH(ref)->next;
                }
            }
        }
    }

    if (Typeof(obj) == TYPE_PLAYER || Typeof(obj) == TYPE_THING) {
#ifdef IGNORE_SUPPORT
        if (ignorance(who, obj))
            return 0;
#endif
	if ( !isprivate && 
	     Typeof(obj) == TYPE_THING &&
	     FLAGS(obj) & ZOMBIE && 
	     LOCATION(obj) == LOCATION(OWNER(obj))
	   ) return 0;

        return notify_html_nolisten(obj, msg, isprivate);
    } else {
        return 0;
    }
}
Example #26
0
void bcp_implementation::scan_license(const fs::path& p, const fileview& v)
{
   std::pair<const license_info*, int> licenses = get_licenses();
   //
   // scan file for all the licenses in the list:
   //
   int license_count = 0;
   int author_count = 0;
   int nonbsl_author_count = 0;
   bool has_non_bsl_license = false;
   fileview::const_iterator start_of_license = v.begin(), 
                            end_of_license = v.end();
   bool start_in_middle_of_line = false;

   for(int i = 0; i < licenses.second; ++i)
   {
      boost::match_results<fileview::const_iterator> m;
      if(boost::regex_search(v.begin(), v.end(), m, licenses.first[i].license_signature))
      {
           start_of_license = m[0].first;
         end_of_license = m[0].second;

         if (is_non_bsl_license(i) && i < licenses.second - 1) 
           has_non_bsl_license = true;

         // add this license to the list:
         m_license_data[i].files.insert(p);
         ++license_count;
         //
         // scan for the associated copyright declarations:
         //
         boost::regex_iterator<const char*> cpy(v.begin(), v.end(), licenses.first[i].copyright_signature);
         boost::regex_iterator<const char*> ecpy;
         while(cpy != ecpy)
         {
#if 0
             // Not dealing with copyrights because we don't have the years
            if ((*cpy)[0].first < start_of_license) 
              start_of_license = (*cpy)[0].first;
            if ((*cpy)[0].second > end_of_license) 
              end_of_license = (*cpy)[0].second;
#endif

            // extract the copy holders as a list:
            std::string author_list = cpy->format(licenses.first[i].copyright_formatter, boost::format_all);
            // now enumerate that list for all the names:
            static const boost::regex author_separator("(?:\\s*,(?!\\s*(?:inc|ltd)\\b)\\s*|\\s+(,\\s*)?(and|&)\\s+)|by\\s+", boost::regex::perl | boost::regex::icase);
            boost::regex_token_iterator<std::string::const_iterator> atr(author_list.begin(), author_list.end(), author_separator, -1);
            boost::regex_token_iterator<std::string::const_iterator> eatr;
            while(atr != eatr)
            {
               // get the reformatted authors name:
               std::string name = format_authors_name(*atr);
               // add to list of authors for this file:
               if(name.size() && name[0] != '-')
               {
                  m_license_data[i].authors.insert(name);
                  // add file to author index:
                  m_author_data[name].insert(p);
                  ++author_count;

                  // If this is not the Boost Software License (license 0), and the author hasn't given 
                  // blanket permission, note this for the report.
                  if (has_non_bsl_license
                      && m_bsl_authors.find(name) == m_bsl_authors.end()) {
                    ++nonbsl_author_count;
                    m_authors_for_bsl_migration.insert(name);
                  }
               }
               ++atr;
            }
            ++cpy;
         }

         while (start_of_license != v.begin()
                && *start_of_license != '\r'
                && *start_of_license != '\n'
                && *start_of_license != '.')
           --start_of_license;

         if (start_of_license != v.begin()) {
           if (*start_of_license == '.')
             start_in_middle_of_line = true;
           ++start_of_license;
         }

         while (end_of_license != v.end()
                && *end_of_license != '\r'
                && *end_of_license != '\n')
           ++end_of_license;
      }
   }
   if(license_count == 0)
      m_unknown_licenses.insert(p);
   if(license_count && !author_count)
      m_unknown_authors.insert(p);

   if (has_non_bsl_license) {
     bool converted = false;
     if (nonbsl_author_count == 0 
         && license_count == 1) {
       // Grab a few lines of context
       fileview::const_iterator context_start = 
         context_before_license(v, start_of_license);
       fileview::const_iterator context_end = 
         context_after_license(v, end_of_license);

       // TBD: For files that aren't C++ code, this will have to
       // change.
       std::string prefix = find_prefix(v, start_of_license);

       // Create enough information to permit manual verification of
       // the correctness of the transformation
       std::string before_conversion = 
         html_escape(context_start, start_of_license);
       before_conversion += "<b>";
       before_conversion += html_escape(start_of_license, end_of_license);
       before_conversion += "</b>";
       before_conversion += html_escape(end_of_license, context_end);

       std::string after_conversion = 
         html_escape(context_start, start_of_license);
       if (start_in_middle_of_line)
         after_conversion += '\n';

       after_conversion += "<b>";
       for (int i = 0; i < boost_license_lines; ++i) {
         if (i > 0) after_conversion += '\n';
         after_conversion += prefix + boost_license_text[i];
       }
       after_conversion += "</b>";
       after_conversion += html_escape(end_of_license, context_end);

       m_converted_to_bsl[p] = 
         std::make_pair(before_conversion, after_conversion);

       // Perform the actual conversion
       if (m_bsl_convert_mode) {
          try{
             std::ofstream out((m_boost_path / p).string().c_str());
            if (!out) {
               std::string msg("Cannot open file for license conversion: ");
               msg += p.string();
               std::runtime_error e(msg);
               boost::throw_exception(e);
            }

            out << std::string(v.begin(), start_of_license);
            if (start_in_middle_of_line)
               out << std::endl;

            for (int j = 0; j < boost_license_lines; ++j) {
               if (j > 0) out << std::endl;
               out << prefix << boost_license_text[j];
            }
            out << std::string(end_of_license, v.end());

            converted = true;
       }
       catch(const std::exception& e)
       {
          std::cerr << e.what() << std::endl;
       }
      }
     }

     if (!converted) {
       if (nonbsl_author_count > 0) m_cannot_migrate_to_bsl.insert(p);
       else m_can_migrate_to_bsl.insert(p);
     }
   }
}
Example #27
0
int crad_get_status_xml(struct _crad_t *p_crad, char *xml_str, int max_size) {
    /*! sanity check - null ptr */
    if(p_crad == 0) { return CRAD_INVALID_PARAM; }

    /*! sanity check - initialization */
    if(!p_crad->is_initialized) { return CRAD_INVALID_CALL; }

    /*! write XML header */
    strncpy(xml_str, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", max_size);

    int status1     = QND_ReadReg(STATUS1);
    int strength    = QND_ReadReg(RSSISIG);
    int step        = QND_ReadReg(CH_STEP);
    struct rds_data data_copy;
    int radio_station = get_radio_station(p_crad);


    // If the RDS thread isn't running, make the RDS string be empty.
    // Otherwise, fill it in.
    if(!p_crad->rds_thread_running) {
        rds_string[0] = '\0';
    }
    else {

        pthread_mutex_lock(&p_crad->rds_mutex);
        data_copy = p_crad->rds_data;
        html_escape(psnescaped, sizeof(psnescaped), data_copy.program_service_name),
        html_escape(ptcescaped, sizeof(ptcescaped), data_copy.program_type_code),
        html_escape(rt0escaped, sizeof(rt0escaped), data_copy.radiotext_filled[0]),
        html_escape(rt1escaped, sizeof(rt1escaped), data_copy.radiotext_filled[1]),
        pthread_mutex_unlock(&p_crad->rds_mutex);

        snprintf(rds_string, sizeof(rds_string), 
                "callsign='%s' "
                "programservice='%s' "
                "ptycode='%s' "
                "radiotext0='%s' "
                "radiotext1='%s' "
                "juliandate='%d' "
                "hour='%d' "
                "minute='%d' "
                "localtime='%d:%02d' "
                ,
                data_copy.callsign,
                psnescaped,
                ptcescaped,
                rt0escaped,
                rt1escaped,
                data_copy.julian_date,
                data_copy.hour_code,
                data_copy.minute,
                data_copy.localtime_hours,
                data_copy.localtime_minutes
        );
    }


    snprintf(xml_str, max_size, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        "<radio found='1' tuned='%c' station='%d.%d' stereo='%c' "
        "signal='%d' signal_max='256' "
        "seek_threshold='%d' seek_threshold_max='255' "
        "spacing='%d' "
        "start='%d.%02d' stop='%d.%02d' "
        "band='%s' "
        "%s"
        ">\n"
        "%s"
        "</radio>\n"
        ,

        // tuned in or not?
        (strength>85?'1':'0'),

        // Current station frequency
        radio_station/100,
        radio_station-(100*(radio_station/100)),

        // Whether we're in stereo or not.  (Inverted bit, 0 = stereo.)
        (status1&1?'0':'1'),

        // Signal strength (in mysterious moon-units?)
        (strength),

        // Seek threshold (?)
        (0),

        // Channel spacing
        steparray[QND_CH_STEP]*10,

        // Start and stop frequencies
        QND_CH_START/100, QND_CH_START%100,
        QND_CH_STOP/100,  QND_CH_STOP%100,

        // Current band setting
        (qnd_Country==COUNTRY_CHINA?"China":
         (qnd_Country==COUNTRY_USA?"US":
           (qnd_Country==COUNTRY_JAPAN?"Japan":"Europe"))),

        // If we're monitoring RDS data, copy that over.
        rds_string,

        // Append the list of stations we've found.
        get_radio_stations(p_crad)

    );

    /*! if we didn't have room for a null terminator, we should just 
     *  fail instead of risking corrupting the XML with one */
    if(xml_str[max_size-1] != '\0') { return CRAD_FAIL; }

    return CRAD_OK;
}
Example #28
0
QByteArray TapParameterDialog::getTreeAsString(st_format_type format)
{
    QByteArray ba;
    QTreeWidgetItemIterator it(ui->statsTreeWidget, QTreeWidgetItemIterator::NotHidden);

    QList<int> col_widths;
    QByteArray footer;

    // Title + header
    switch (format) {
    case ST_FORMAT_PLAIN:
    {
        // Iterating over trees.
        QTreeWidgetItemIterator width_it(it);
        QString plain_header;
        while (*width_it) {
            // Iterating over items within this tree.
            for (int col=0; col < ui->statsTreeWidget->columnCount(); col++) {
                if (col_widths.size() <= col) {
                    col_widths.append(ui->statsTreeWidget->headerItem()->text(col).length());
                }
                QVariant var = ui->statsTreeWidget->headerItem()->data(col, Qt::DisplayRole);
                if (var.type() == QVariant::String) {
                    col_widths[col] = qMax(col_widths[col], itemDataToPlain(var).length());
                }
            }
            ++width_it;
        }
        QStringList ph_parts;
        for (int col = 0; col < ui->statsTreeWidget->columnCount() && col < col_widths.length(); col++) {
            ph_parts << ui->statsTreeWidget->headerItem()->text(col);
        }
        plain_header = ph_parts.join(plain_sep_);

        QByteArray top_separator;
        top_separator.fill('=', plain_header.length());
        top_separator.append('\n');
        QString file_header = QString("%1 - %2:\n").arg(windowSubtitle(), cap_file_.fileDisplayName());
        footer.fill('-', plain_header.length());
        footer.append('\n');
        plain_header.append('\n');

        ba.append(top_separator);
        ba.append(file_header);
        ba.append(plain_header);
        ba.append(footer);
        break;
    }
    case ST_FORMAT_CSV:
    {
        QString csv_header;
        QStringList ch_parts;
        for (int col = 0; col < ui->statsTreeWidget->columnCount(); col++) {
            ch_parts << QString("\"%1\"").arg(ui->statsTreeWidget->headerItem()->text(col));
        }
        csv_header = ch_parts.join(",");
        csv_header.append('\n');
        ba.append(csv_header.toUtf8().constData());
        break;
    }
    case ST_FORMAT_XML:
    {
        // XXX What's a useful format? This mostly conforms to DocBook.
        ba.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        QString title = html_escape(windowSubtitle());
        QString xml_header = QString("<table>\n<title>%1</title>\n").arg(title);
        ba.append(xml_header.toUtf8());
        ba.append("<thead>\n<row>\n");
        for (int col = 0; col < ui->statsTreeWidget->columnCount(); col++) {
            title = html_escape(ui->statsTreeWidget->headerItem()->text(col));
            title = QString("  <entry>%1</entry>\n").arg(title);
            ba.append(title.toUtf8());
        }
        ba.append("</row>\n</thead>\n");
        ba.append("<tbody>\n");
        footer = "</tbody>\n</table>\n";
        break;
    }
    case ST_FORMAT_YAML:
    {
        QString yaml_header;
        ba.append("---\n");
        yaml_header = QString("Description: \"%1\"\nFile: \"%2\"\nItems:\n").arg(windowSubtitle()).arg(cap_file_.fileDisplayName());
        ba.append(yaml_header.toUtf8());
        break;
    }
    default:
        break;
    }

    // Data
    while (*it) {
        QList<QVariant> tid = treeItemData((*it));
        if (tid.length() < 1) {
            ++it;
            continue;
        }

        if (tid.length() < ui->statsTreeWidget->columnCount()) {
            // Assume we have a header
        }

        // Assume var length == columnCount
        QString line;
        QStringList parts;

        switch (format) {
        case ST_FORMAT_PLAIN:
        {
            int i = 0;
            foreach (QVariant var, tid) {
                parts << itemDataToPlain(var, col_widths[i]);
                i++;
            }
            line = parts.join(plain_sep_);
            line.append('\n');
            break;
        }
        case ST_FORMAT_CSV:
            foreach (QVariant var, tid) {
                if (var.type() == QVariant::String) {
                    parts << QString("\"%1\"").arg(var.toString());
                } else {
                    parts << var.toString();
                }
            }
            line = parts.join(",");
            line.append('\n');
            break;
        case ST_FORMAT_XML:
        {
            line = "<row>\n";
            foreach (QVariant var, tid) {
                QString entry = html_escape(var.toString());
                line.append(QString("  <entry>%1</entry>\n").arg(entry));
            }
            line.append("</row>\n");
            break;
        }
        case ST_FORMAT_YAML:
        {
            int col = 0;
            QString indent = "-";
            foreach (QVariant var, tid) {
                QString entry;
                if (var.type() == QVariant::String) {
                    entry = QString("\"%1\"").arg(var.toString());
                } else {
                    entry = var.toString();
                }
                line.append(QString("  %1 %2: %3\n").arg(indent).arg(ui->statsTreeWidget->headerItem()->text(col), entry));
                indent = " ";
                col++;
            }
            break;
        }