Esempio n. 1
0
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
		    char *path, int pager, int commit_graph, int commit_sort)
{
	struct rev_info rev;
	struct commit *commit;
	struct vector vec = VECTOR_INIT(char *);
	int i, columns = 3;
	char *arg;

	/* First argv is NULL */
	vector_push(&vec, NULL, 0);

	if (!tip)
		tip = ctx.qry.head;
	tip = disambiguate_ref(tip);
	vector_push(&vec, &tip, 0);

	if (grep && pattern && *pattern) {
		pattern = xstrdup(pattern);
		if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
		    !strcmp(grep, "committer")) {
			arg = fmt("--%s=%s", grep, pattern);
			vector_push(&vec, &arg, 0);
		}
		if (!strcmp(grep, "range")) {
			/* Split the pattern at whitespace and add each token
			 * as a revision expression. Do not accept other
			 * rev-list options. Also, replace the previously
			 * pushed tip (it's no longer relevant).
			 */
			vec.count--;
			while ((arg = next_token(&pattern))) {
				if (*arg == '-') {
					fprintf(stderr, "Bad range expr: %s\n",
						arg);
					break;
				}
				vector_push(&vec, &arg, 0);
			}
		}
	}
	if (commit_graph) {
		static const char *graph_arg = "--graph";
		static const char *color_arg = "--color";
		vector_push(&vec, &graph_arg, 0);
		vector_push(&vec, &color_arg, 0);
		graph_set_column_colors(column_colors_html,
					COLUMN_COLORS_HTML_MAX);
	}

	if (commit_sort == 1) {
		static const char *date_order_arg = "--date-order";
		vector_push(&vec, &date_order_arg, 0);
	} else if (commit_sort == 2) {
		static const char *topo_order_arg = "--topo-order";
		vector_push(&vec, &topo_order_arg, 0);
	}

	if (path) {
		arg = "--";
		vector_push(&vec, &arg, 0);
		vector_push(&vec, &path, 0);
	}

	/* Make sure the vector is NULL-terminated */
	vector_push(&vec, NULL, 0);
	vec.count--;

	init_revisions(&rev, NULL);
	rev.abbrev = DEFAULT_ABBREV;
	rev.commit_format = CMIT_FMT_DEFAULT;
	rev.verbose_header = 1;
	rev.show_root_diff = 0;
	setup_revisions(vec.count, vec.data, &rev, NULL);
	load_ref_decorations(DECORATE_FULL_REFS);
	rev.show_decorations = 1;
	rev.grep_filter.regflags |= REG_ICASE;
	compile_grep_patterns(&rev.grep_filter);
	prepare_revision_walk(&rev);

	if (pager)
		html("<table class='list nowrap'>");

	html("<tr class='nohover'>");
	if (commit_graph)
		html("<th></th>");
	else
		html("<th class='left'>Age</th>");
	html("<th class='left'>Commit message");
	if (pager) {
		html(" (");
		cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
			      NULL, ctx.qry.head, ctx.qry.sha1,
			      ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep,
			      ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
		html(")");
	}
	html("</th><th class='left'>Author</th>");
	if (commit_graph)
		html("<th class='left'>Age</th>");
	if (ctx.repo->enable_log_filecount) {
		html("<th class='left'>Files</th>");
		columns++;
	}
	if (ctx.repo->enable_log_linecount) {
		html("<th class='left'>Lines</th>");
		columns++;
	}
	html("</tr>\n");

	if (ofs<0)
		ofs = 0;

	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
		free(commit->buffer);
		commit->buffer = NULL;
		free_commit_list(commit->parents);
		commit->parents = NULL;
	}

	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
		print_commit(commit, &rev);
		free(commit->buffer);
		commit->buffer = NULL;
		free_commit_list(commit->parents);
		commit->parents = NULL;
	}
	if (pager) {
		html("</table><div class='pager'>");
		if (ofs > 0) {
			cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
				      ctx.qry.sha1, ctx.qry.vpath,
				      ofs - cnt, ctx.qry.grep,
				      ctx.qry.search, ctx.qry.showmsg);
			html("&nbsp;");
		}
		if ((commit = get_revision(&rev)) != NULL) {
			cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
				      ctx.qry.sha1, ctx.qry.vpath,
				      ofs + cnt, ctx.qry.grep,
				      ctx.qry.search, ctx.qry.showmsg);
		}
		html("</div>");
	} else if ((commit = get_revision(&rev)) != NULL) {
		html("<tr class='nohover'><td colspan='3'>");
		cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL,
			      ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg);
		html("</td></tr>\n");
	}
}
Esempio n. 2
0
/* Create a sorted string_list with one entry per author. The util-field
 * for each author is another string_list which is used to calculate the
 * number of commits per time-interval.
 */
void cgit_show_stats(void)
{
    struct string_list authors;
    const struct cgit_period *period;
    int top, i;
    const char *code = "w";

    if (ctx.qry.period)
        code = ctx.qry.period;

    i = cgit_find_stats_period(code, &period);
    if (!i) {
        cgit_print_error_page(404, "Not found",
                              "Unknown statistics type: %c", code[0]);
        return;
    }
    if (i > ctx.repo->max_stats) {
        cgit_print_error_page(400, "Bad request",
                              "Statistics type disabled: %s", period->name);
        return;
    }
    authors = collect_stats(period);
    qsort(authors.items, authors.nr, sizeof(struct string_list_item),
          cmp_total_commits);

    top = ctx.qry.ofs;
    if (!top)
        top = 10;

    cgit_print_layout_start();
    html("<div class='cgit-panel'>");
    html("<b>stat options</b>");
    html("<form method='get'>");
    cgit_add_hidden_formfields(1, 0, "stats");
    html("<table><tr><td colspan='2'/></tr>");
    if (ctx.repo->max_stats > 1) {
        html("<tr><td class='label'>Period:</td>");
        html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>");
        for (i = 0; i < ctx.repo->max_stats; i++)
            html_option(fmt("%c", periods[i].code),
                        periods[i].name, fmt("%c", period->code));
        html("</select></td></tr>");
    }
    html("<tr><td class='label'>Authors:</td>");
    html("<td class='ctrl'><select name='ofs' onchange='this.form.submit();'>");
    html_intoption(10, "10", top);
    html_intoption(25, "25", top);
    html_intoption(50, "50", top);
    html_intoption(100, "100", top);
    html_intoption(-1, "all", top);
    html("</select></td></tr>");
    html("<tr><td/><td class='ctrl'>");
    html("<noscript><input type='submit' value='Reload'/></noscript>");
    html("</td></tr></table>");
    html("</form>");
    html("</div>");
    htmlf("<h2>Commits per author per %s", period->name);
    if (ctx.qry.path) {
        html(" (path '");
        html_txt(ctx.qry.path);
        html("')");
    }
    html("</h2>");
    print_authors(&authors, top, period);
    cgit_print_layout_end();
}
Esempio n. 3
0
Json::Document Stencil::call(const std::string& name, const Json::Document& args) {
	// TODO Apply new API here
	
	#if 0
	auto what = call.what();
	
	// Getting content
	if(what=="html():string"){
		return html();
	}
	else if(what=="cila():string"){
		return cila();
	}

	// Setting content
	else if(what=="html(string)"){
		std::string string = call.arg(0);
		           html(string);
	}
	else if(what=="cila(string)"){
		std::string string = call.arg(0);
		           cila(string);
	}

	// Patching content
	else if(what=="patch(string)"){
		std::string string = call.arg(0);
		           patch(string);	
	}

	// Saving
	else if(what=="html(string).write()"){
		std::string string = call.arg(0);
		           html(string).write();
	}
	else if(what=="cila(string).write()"){
		std::string string = call.arg(0);
		           cila(string).write();
	}

	// Conversion of content...
	// ... HTML to Cila
	else if(what=="html(string).cila():string"){
		std::string string = call.arg(0);
		return     html(string).cila();
	}
	// ... Cila to HTML
	else if(what=="cila(string).html():string"){
		std::string string = call.arg(0);
		return     cila(string).html();
	}

	// Rendering HTML
	else if(what=="html(string).render().html():string"){
		std::string string = call.arg(0);
		return     html(string).render().html();
	}
	else if(what=="html(string).refresh().html():string"){
		std::string string = call.arg(0);
		return     html(string).refresh().html();
	}

	// Rendering Cila
	else if(what=="cila(string).render().cila():string"){
		std::string string = call.arg(0);
		return     cila(string).render().cila();
	}

	// Update <input>s
	else if(what=="inputs({string,string}).render().html():string"){
		auto values = call.arg<std::map<std::string,std::string>>(0);
		return     inputs(     values    ).render().html();
	}
	
	// Restart
	else if(what=="restart().html():string"){
		return     restart().html();
	}    

	// Access to context
	else if(what=="interact(string):string"){
		std::string string = call.arg(0);
		return     interact(string);
	}

	else return Component::call(call);
	#endif

	return "";
}
void helpDownload::finished(QNetworkReply * nwrep)
{
  if(nwrep->header(QNetworkRequest::LocationHeader).isValid())
  {
    if(nwrep->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 301)
    {
      qDebug() << "301 Not found";
      _progress->setRange(0, 100);
      _progress->setValue(100);
      _label->setText("No documentation is currently available.");
      _button->setText(tr("Start"));
      _state = Idle;
    }
    else
    {
      QNetworkReply * newrep = nwam->get(QNetworkRequest(QUrl(nwrep->header(QNetworkRequest::LocationHeader).toString())));
      connect(newrep, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
      _nwrep = newrep;
    }
  }
  else
  {
    if(nwrep->error() == QNetworkReply::NoError)
    {
      QByteArray ba = nwrep->readAll();
      if(!ba.isEmpty())
      {
        if(ba[0] == '<')
        {
          QRegExp re("<a href=\"([^\"]+)\" class=\"direct-download\">");
          QString html(ba);
          re.indexIn(html);
          QStringList list = re.capturedTexts();
          if(list.size() > 1)
          {
            QString url = list.at(1);
            url = url.replace("&amp;", "&");
            qDebug() << "Redirecting to " << url;
            QNetworkReply * newrep = nwam->get(QNetworkRequest(QUrl(url)));
            connect(newrep, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
            _nwrep = newrep;
          }
          else
          {
            _label->setText(tr("Received unknown response from server."));
          }
        }        
        else
        {
          #if QT_VERSION >= 0x050000
          QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
          if(!dir.exists())
            dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
          QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/helpXTupleGUIClient-" + ver + ".tar.gz");
          #else
          QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
          if(!dir.exists())
             dir.mkpath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
          QFile file(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/helpXTupleGUIClient-" + ver + ".tar.gz");
          #endif
          if(file.open(QIODevice::WriteOnly | QIODevice::Truncate))
          {
            file.write(ba);
            file.close();
            QByteArray data = gunzipFile(file.fileName());
            if(!data.isEmpty())
            {
              TarFile *_files = new TarFile(data);
              if(_files->isValid())
              {
                bool error = false;
                QMapIterator<QString, QByteArray> i(_files->_list);
                while (i.hasNext())
                {
                  i.next();
                  //cout << i.key() << ": " << i.value() << endl;
                  #if QT_VERSION >= 0x050000
                  QFile ff(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + i.key());
                  #else
                  QFile ff(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + i.key());
                  #endif
                  if(ff.open(QIODevice::WriteOnly | QIODevice::Truncate))
                  {
                    ff.write(i.value());
                    ff.close();
                  }
                  else
                  {
                    error = true;
                  }
                }
                if(error)
                {
                  _label->setText(tr("Could not save one or more files."));
                }
                else
                {
                  _label->setText(tr("Documentation downloaded."));
                  xtHelp::reload();
                }
              }
              else
              {
                _label->setText(tr("Could not read archive format."));
              }
              delete _files;
            }
            else
            {
              _label->setText(tr("Could not uncompress file."));
            }
          }
          else
          {
            _label->setText(tr("Could not save file."));
          }
        }
      }
      else
      {
        _label->setText(tr("No documentation is currently available."));
      }
    }
    else
    {
      qDebug() << "Error: " << nwrep->error();
      _label->setText(tr("Could not retrieve documentation at this time."));
    }
    _progress->setRange(0, 100);
    _progress->setValue(100);
    _button->setText(tr("Start"));
    _state = Idle;
  }
  if(nwrep == _nwrep)
    _nwrep = 0;
  nwrep->deleteLater();
}
Esempio n. 5
0
int cgit_ref_path_exists(const char *path, const char *ref, int file_only)
{
	struct object_id oid;
	unsigned long size;
	struct pathspec_item path_items = {
		.match = xstrdup(path),
		.len = strlen(path)
	};
	struct pathspec paths = {
		.nr = 1,
		.items = &path_items
	};
	struct walk_tree_context walk_tree_ctx = {
		.match_path = path,
		.matched_oid = &oid,
		.found_path = 0,
		.file_only = file_only
	};

	if (get_oid(ref, &oid))
		goto done;
	if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT)
		goto done;
	read_tree_recursive(lookup_commit_reference(the_repository, &oid)->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);

done:
	free(path_items.match);
	return walk_tree_ctx.found_path;
}

int cgit_print_file(char *path, const char *head, int file_only)
{
	struct object_id oid;
	enum object_type type;
	char *buf;
	unsigned long size;
	struct commit *commit;
	struct pathspec_item path_items = {
		.match = path,
		.len = strlen(path)
	};
	struct pathspec paths = {
		.nr = 1,
		.items = &path_items
	};
	struct walk_tree_context walk_tree_ctx = {
		.match_path = path,
		.matched_oid = &oid,
		.found_path = 0,
		.file_only = file_only
	};

	if (get_oid(head, &oid))
		return -1;
	type = oid_object_info(the_repository, &oid, &size);
	if (type == OBJ_COMMIT) {
		commit = lookup_commit_reference(the_repository, &oid);
		read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
		if (!walk_tree_ctx.found_path)
			return -1;
		type = oid_object_info(the_repository, &oid, &size);
	}
	if (type == OBJ_BAD)
		return -1;
	buf = read_object_file(&oid, &type, &size);
	if (!buf)
		return -1;
	buf[size] = '\0';
	html_raw(buf, size);
	free(buf);
	return 0;
}

void cgit_print_blob(const char *hex, char *path, const char *head, int file_only)
{
	struct object_id oid;
	enum object_type type;
	char *buf;
	unsigned long size;
	struct commit *commit;
	struct pathspec_item path_items = {
		.match = path,
		.len = path ? strlen(path) : 0
	};
	struct pathspec paths = {
		.nr = 1,
		.items = &path_items
	};
	struct walk_tree_context walk_tree_ctx = {
		.match_path = path,
		.matched_oid = &oid,
		.found_path = 0,
		.file_only = file_only
	};

	if (hex) {
		if (get_oid_hex(hex, &oid)) {
			cgit_print_error_page(400, "Bad request",
					"Bad hex value: %s", hex);
			return;
		}
	} else {
		if (get_oid(head, &oid)) {
			cgit_print_error_page(404, "Not found",
					"Bad ref: %s", head);
			return;
		}
	}

	type = oid_object_info(the_repository, &oid, &size);

	if ((!hex) && type == OBJ_COMMIT && path) {
		commit = lookup_commit_reference(the_repository, &oid);
		read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
		type = oid_object_info(the_repository, &oid, &size);
	}

	if (type == OBJ_BAD) {
		cgit_print_error_page(404, "Not found",
				"Bad object name: %s", hex);
		return;
	}

	buf = read_object_file(&oid, &type, &size);
	if (!buf) {
		cgit_print_error_page(500, "Internal server error",
				"Error reading object %s", hex);
		return;
	}

	buf[size] = '\0';
	if (buffer_is_binary(buf, size))
		ctx.page.mimetype = "application/octet-stream";
	else
		ctx.page.mimetype = "text/plain";
	ctx.page.filename = path;

	html("X-Content-Type-Options: nosniff\n");
	html("Content-Security-Policy: default-src 'none'\n");
	cgit_print_http_headers();
	html_raw(buf, size);
	free(buf);
}
Esempio n. 6
0
///
/// Process a directory recursively.
///
void html_a_directory(TDirectory *f, TString path, TEnv *params)
{
  TCanvas *c_h1 = 0;
  if (c_h1 == 0) {
    int x = params->GetValue("H1.XSize", 150);
    int y = params->GetValue("H1.YSize", 100);
    c_h1 = new TCanvas ("c_h1", "1d plots", x, y);
  }

  ///
  /// Check how to make gif plots
  ///

  char command[512];
  sprintf(command, "which pstoimg &> /dev/null");
  bool UsePstoimg = ! system(command);

  ///
  /// Generate the output directory
  ///

  gSystem->MakeDirectory (path);

  ///
  /// Get the html started
  ///

  ofstream html (path + "/index.html");
  html << "<html><head><title>" << f->GetName() << "</title></head>" << endl;
  html << "<body>" << endl;
  html << "<h1>" << f->GetName() << "</h1>" << endl;
  cout << "Processing directory " << f->GetName() << endl;

  ///
  /// Now loop over all the keys in the directory
  ///

  f->cd();
  TList *objlist = f->GetListOfKeys();
  objlist->Sort(); // order alphabetically, instead of order in which they were written
  TIterator *itr = objlist->MakeIterator();
  TKey *key;
  while ((key = static_cast<TKey*>(itr->Next())) != 0) {
    TObject *obj = key->ReadObj();

    if (obj->IsA()->InheritsFrom("TDirectory")) {
      TDirectory *d = static_cast<TDirectory*>(obj);
      html << "<br><a href=\"" << d->GetName() << "/\">" << d->GetName() << "</a>" << endl;
      html_a_directory(d, path + "/" + d->GetName(), params);
    }

    else if (obj->IsA()->InheritsFrom("TObjString")) {
      TObjString *s = static_cast<TObjString*>(obj);
      html << "<p><h2>" << key->GetName() << "</h2>" << endl;
      //html << "<blockquote><pre>" << static_cast<char*>(s->GetString())
	  // << "</pre></blockquote></p>"
	  // << endl;
      html << "<blockquote><pre>" << (s->GetString()).Data() << "</pre></blockquote></p>"<< endl;
      

    }

    //    else if (obj->IsA()->InheritsFrom("CutFlowTable")) {
    //      CutFlowTable *c = static_cast<CutFlowTable*> (obj);
    //      
    //      html << "<p><h2>" << key->GetName() << "</h2>" << endl;
    //
    //      CFTPrinterHTML txt (html);
    //      f->cd();
    //      c->PrintGlobal (txt, "All Events", "");
    //      html << "</p>" << endl;
    //    }

    else if (obj->IsA()->InheritsFrom("TCanvas")) {
      TCanvas *cnv = static_cast<TCanvas*>(obj);

      cnv->Draw();
      cnv->SaveAs(path + "/" + key->GetName() + ".eps");
      if (UsePstoimg) {
	sprintf(command, "pstoimg -type=gif %s &> /dev/null",(path + "/" + key->GetName() + ".eps").Data());
	if (system(command) != 0) {
	  cout<<"Could not convert to gif: "<<path + "/" + key->GetName() + ".eps"<<endl;
	  abort();
	}
      } else cnv->SaveAs(path + "/" + key->GetName() + ".gif");

      cnv->Close();

      html << "<p><a href=\"" << key->GetName() << ".eps\">";
      html << "<img src=\"" << key->GetName() << ".gif\">";
      html << "</a> <br> " << key->GetName() << ".gif </p>" << endl;								   
    }

    else if (obj->IsA()->InheritsFrom("TH1") && !(obj->IsA()->InheritsFrom("TH2"))) {
      TH1 *h = static_cast<TH1*> (obj);

      c_h1->cd();
      h->Draw();
      c_h1->SaveAs(path + "/" + key->GetName() + ".eps");
      if (UsePstoimg) {
	sprintf(command, "pstoimg -type=gif %s &> /dev/null",(path + "/" + key->GetName() + ".eps").Data());
	if (system(command) != 0) {
	  cout<<"Could not convert to gif: "<<path + "/" + key->GetName() + ".eps"<<endl;
	  abort();
	}
      } else c_h1->SaveAs(path + "/" + key->GetName() + ".gif");

      html << "<p><a href=\"" << key->GetName() << ".eps\">";
      html << "<img src=\"" << key->GetName() << ".gif\">";
      html << "</a> <br> " << key->GetName() << ".gif </p>" << endl;
    }
    f->cd();
  }

  ///
  /// Done!
  ///

  html << "</body></html>" << endl;
  html.close();
}
Esempio n. 7
0
ShadowGUI::ShadowGUI(QWidget *parent):
    QMainWindow(parent),
    bridge(new ShadowBridge(this)),
    clientModel(0),
    walletModel(0),
    messageModel(0),
    encryptWalletAction(0),
    changePassphraseAction(0),
    unlockWalletAction(0),
    lockWalletAction(0),
    aboutQtAction(0),
    trayIcon(0),
    notificator(0),
    rpcConsole(0),
    nWeight(0)
{
    webView = new QWebView();

    webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

    webView->page()->action(QWebPage::Reload )->setVisible(false);
    webView->page()->action(QWebPage::Back   )->setVisible(false);
    webView->page()->action(QWebPage::Forward)->setVisible(false);

    connect(webView, SIGNAL(linkClicked(const QUrl&)), this, SLOT(urlClicked(const QUrl&)));

    setCentralWidget(webView);

    resize(1280, 720);
    setWindowTitle(tr("ZirkCoin") + " - " + tr("Client"));
#ifndef Q_OS_MAC
    qApp->setWindowIcon(QIcon(":icons/shadow"));
    setWindowIcon(QIcon(":icons/shadow"));
#else
    setUnifiedTitleAndToolBarOnMac(true);
    QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
#endif

    // Accept D&D of URIs
    setAcceptDrops(true);

    // Create actions for the toolbar, menu bar and tray/dock icon
    createActions();

    // Create application menu bar
    createMenuBar();

    // Create the tray icon (or setup the dock icon)
    createTrayIcon();

    signVerifyMessageDialog = new SignVerifyMessageDialog(this);

    rpcConsole = new RPCConsole(this);

    connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));

    documentFrame = webView->page()->mainFrame();

    QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

    //connect(webView->page()->action(QWebPage::Reload), SIGNAL(triggered()), SLOT(pageLoaded(bool)));

    connect(webView, SIGNAL(loadFinished(bool)),                    SLOT(pageLoaded(bool)));
    connect(documentFrame, SIGNAL(javaScriptWindowObjectCleared()), SLOT(addJavascriptObjects()));
    connect(documentFrame, SIGNAL(urlChanged(QUrl)),                SLOT(urlClicked(const QUrl&)));

#ifdef Q_OS_WIN
    QFile html("C:/shadow/index.html");
#else
    QFile html("/opt/shadow/index.html");
#endif

    if(html.exists())
        webView->setUrl(QUrl("file:///" + html.fileName()));
    else
        webView->setUrl(QUrl("qrc:///src/qt/res/index.html"));
}
Esempio n. 8
0
File: ui-diff.c Progetto: UniQP/cgit
void cgit_print_diffstat(const unsigned char *old_sha1,
			 const unsigned char *new_sha1, const char *prefix)
{
	int i, save_context = ctx.qry.context;

	html("<div class='diffstat-header'>");
	cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
		       ctx.qry.sha2, NULL, 0);
	if (prefix) {
		html(" (limited to '");
		html_txt(prefix);
		html("')");
	}
	html(" (");
	ctx.qry.context = (save_context > 0 ? save_context : 3) << 1;
	cgit_self_link("more", NULL, NULL, &ctx);
	html("/");
	ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1;
	cgit_self_link("less", NULL, NULL, &ctx);
	ctx.qry.context = save_context;
	html(" context)");
	html(" (");
	ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
	cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx);
	ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
	html(" whitespace changes)");
	html("</div>");
	html("<table summary='diffstat' class='diffstat'>");
	max_changes = 0;
	cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix,
		       ctx.qry.ignorews);
	for(i = 0; i<files; i++)
		print_fileinfo(&items[i]);
	html("</table>");
	html("<div class='diffstat-summary'>");
	htmlf("%d files changed, %d insertions, %d deletions",
	      files, total_adds, total_rems);
	html("</div>");
}
Esempio n. 9
0
File: ui-diff.c Progetto: UniQP/cgit
static void print_fileinfo(struct fileinfo *info)
{
	char *class;

	switch (info->status) {
	case DIFF_STATUS_ADDED:
		class = "add";
		break;
	case DIFF_STATUS_COPIED:
		class = "cpy";
		break;
	case DIFF_STATUS_DELETED:
		class = "del";
		break;
	case DIFF_STATUS_MODIFIED:
		class = "upd";
		break;
	case DIFF_STATUS_RENAMED:
		class = "mov";
		break;
	case DIFF_STATUS_TYPE_CHANGED:
		class = "typ";
		break;
	case DIFF_STATUS_UNKNOWN:
		class = "unk";
		break;
	case DIFF_STATUS_UNMERGED:
		class = "stg";
		break;
	default:
		die("bug: unhandled diff status %c", info->status);
	}

	html("<tr>");
	htmlf("<td class='mode'>");
	if (is_null_sha1(info->new_sha1)) {
		cgit_print_filemode(info->old_mode);
	} else {
		cgit_print_filemode(info->new_mode);
	}

	if (info->old_mode != info->new_mode &&
	    !is_null_sha1(info->old_sha1) &&
	    !is_null_sha1(info->new_sha1)) {
		html("<span class='modechange'>[");
		cgit_print_filemode(info->old_mode);
		html("]</span>");
	}
	htmlf("</td><td class='%s'>", class);
	cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
		       ctx.qry.sha2, info->new_path, 0);
	if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
		htmlf(" (%s from %s)",
		      info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
		      info->old_path);
	html("</td><td class='right'>");
	if (info->binary) {
		htmlf("bin</td><td class='graph'>%ld -> %ld bytes",
		      info->old_size, info->new_size);
		return;
	}
	htmlf("%d", info->added + info->removed);
	html("</td><td class='graph'>");
	htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
	htmlf("<td class='add' style='width: %.1f%%;'/>",
	      info->added * 100.0 / max_changes);
	htmlf("<td class='rem' style='width: %.1f%%;'/>",
	      info->removed * 100.0 / max_changes);
	htmlf("<td class='none' style='width: %.1f%%;'/>",
	      (max_changes - info->removed - info->added) * 100.0 / max_changes);
	html("</tr></table></td></tr>\n");
}
Esempio n. 10
0
void cgit_print_commit(char *hex)
{
	struct commit *commit, *parent;
	struct commitinfo *info;
	struct commit_list *p;
	unsigned char sha1[20];
	char *tmp;
	int parents = 0;

	if (!hex)
		hex = ctx.qry.head;

	if (get_sha1(hex, sha1)) {
		cgit_print_error(fmt("Bad object id: %s", hex));
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit) {
		cgit_print_error(fmt("Bad commit reference: %s", hex));
		return;
	}
	info = cgit_parse_commit(commit);

	html("<table summary='commit info' class='commit-info'>\n");
	html("<tr><th>author</th><td>");
	html_txt(info->author);
	html(" ");
	html_txt(info->author_email);
	html("</td><td class='right'>");
	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
	html("</td></tr>\n");
	html("<tr><th>committer</th><td>");
	html_txt(info->committer);
	html(" ");
	html_txt(info->committer_email);
	html("</td><td class='right'>");
	cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
	html("</td></tr>\n");
	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
	tmp = sha1_to_hex(commit->object.sha1);
	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
	html(" (");
	cgit_patch_link("patch", NULL, NULL, NULL, tmp);
	html(")</td></tr>\n");
	html("<tr><th>tree</th><td colspan='2' class='sha1'>");
	tmp = xstrdup(hex);
	cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
		       ctx.qry.head, tmp, NULL);
	html("</td></tr>\n");
      	for (p = commit->parents; p ; p = p->next) {
		parent = lookup_commit_reference(p->item->object.sha1);
		if (!parent) {
			html("<tr><td colspan='3'>");
			cgit_print_error("Error reading parent commit");
			html("</td></tr>");
			continue;
		}
		html("<tr><th>parent</th>"
		     "<td colspan='2' class='sha1'>");
		cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
				 ctx.qry.head, sha1_to_hex(p->item->object.sha1));
		html(" (");
		cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
			       sha1_to_hex(p->item->object.sha1), NULL);
		html(")</td></tr>");
		parents++;
	}
	if (ctx.repo->snapshots) {
		html("<tr><th>download</th><td colspan='2' class='sha1'>");
		cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
					  hex, ctx.repo->snapshots);
		html("</td></tr>");
	}
	html("</table>\n");
	html("<div class='commit-subject'>");
	html_txt(info->subject);
	html("</div>");
	html("<div class='commit-msg'>");
	html_txt(info->msg);
	html("</div>");
	if (parents < 3) {
		if (parents)
			tmp = sha1_to_hex(commit->parents->item->object.sha1);
		else
			tmp = NULL;
		cgit_print_diff(ctx.qry.sha1, tmp, NULL);
	}
	cgit_free_commitinfo(info);
}
Esempio n. 11
0
	// Display a link to the directory's contents as HTML on of
	virtual void html(FILE *of) const {
		html(of, name.c_str());
	}
Esempio n. 12
0
int main_html_server(int argc, char **argv)
{
	struct server server;
	unsigned i, playing = 0, spectating = 0;
	char *ip, *port;
	const char *addr;
	sqlite3_stmt *res;
	unsigned nrow;

	const char *query =
		"SELECT" ALL_EXTENDED_SERVER_COLUMNS
		" FROM servers"
		" WHERE ip = ? AND port = ?";

	if (argc != 2) {
		fprintf(stderr, "usage: %s <server_addr>\n", argv[0]);
		return EXIT_FAILURE;
	}

	if (!parse_addr(argv[1], &ip, &port))
		return EXIT_NOT_FOUND;

	foreach_extended_server(query, &server, "ss", ip, port);
	if (!res)
		return EXIT_FAILURE;
	if (!nrow)
		return EXIT_NOT_FOUND;
	if (!read_server_clients(&server))
		return EXIT_FAILURE;

	for (i = 0; i < server.num_clients; i++)
		server.clients[i].ingame ? playing++ : spectating++;

	/* Eventually, print them */
	CUSTOM_TAB.name = escape(server.name);
	CUSTOM_TAB.href = "";
	html_header(&CUSTOM_TAB, server.name, "/servers", NULL);
	html("<header id=\"server_header\">");
	html("<section id=\"serverinfo\">");
	html("<h2>%s</h2>", escape(server.name));

	html("<ul>");
	html("<li>%s</li><li>%s</li>", server.gametype, server.map);
	html("<li>%u / %u clients</li>", server.num_clients, server.max_clients);

	html("<li>");
	html("%u players", playing);
	if (spectating)
		html(" + %u spectators", spectating);
	html("</li>");
	html("</ul>");
	html("</section>");

	html("<section id=\"serveraddr\">");
	html("<label for=\"serveraddr_input\">Server address</label>");

	addr = build_addr(server.ip, server.port);
	html("<input type=\"text\" value=\"%s\" size=\"%u\" id=\"serveraddr_input\" readonly/>",
	     addr, strlen(addr));
	html("</section>");
	html("</header>");

	show_client_list(&server);

	html_footer("server", relurl("/servers/%s.json", addr));

	return EXIT_SUCCESS;
}
Esempio n. 13
0
int main() {
	Parser::HTMLParser html("address-book.xml");
}
Esempio n. 14
0
void print_commit(struct commit *commit, struct rev_info *revs)
{
	struct commitinfo *info;
	int cols = revs->graph ? 3 : 2;
	struct strbuf graphbuf = STRBUF_INIT;
	struct strbuf msgbuf = STRBUF_INIT;

	if (ctx.repo->enable_log_filecount)
		cols++;
	if (ctx.repo->enable_log_linecount)
		cols++;

	if (revs->graph) {
		/* Advance graph until current commit */
		while (!graph_next_line(revs->graph, &graphbuf)) {
			/* Print graph segment in otherwise empty table row */
			html("<tr class='nohover'><td class='commitgraph'>");
			html(graphbuf.buf);
			htmlf("</td><td colspan='%d' /></tr>\n", cols);
			strbuf_setlen(&graphbuf, 0);
		}
		/* Current commit's graph segment is now ready in graphbuf */
	}

	info = cgit_parse_commit(commit);
	htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");

	if (revs->graph) {
		/* Print graph segment for current commit */
		html("<td class='commitgraph'>");
		html(graphbuf.buf);
		html("</td>");
		strbuf_setlen(&graphbuf, 0);
	}
	else {
		html("<td>");
		cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
		html("</td>");
	}

	htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : "");
	if (ctx.qry.showmsg) {
		/* line-wrap long commit subjects instead of truncating them */
		size_t subject_len = strlen(info->subject);

		if (subject_len > ctx.cfg.max_msg_len &&
		    ctx.cfg.max_msg_len >= 15) {
			/* symbol for signaling line-wrap (in PAGE_ENCODING) */
			const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 };
			int i = ctx.cfg.max_msg_len - strlen(wrap_symbol);

			/* Rewind i to preceding space character */
			while (i > 0 && !isspace(info->subject[i]))
				--i;
			if (!i) /* Oops, zero spaces. Reset i */
				i = ctx.cfg.max_msg_len - strlen(wrap_symbol);

			/* add remainder starting at i to msgbuf */
			strbuf_add(&msgbuf, info->subject + i, subject_len - i);
			strbuf_trim(&msgbuf);
			strbuf_add(&msgbuf, "\n\n", 2);

			/* Place wrap_symbol at position i in info->subject */
			strcpy(info->subject + i, wrap_symbol);
		}
	}
	cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
			 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
	show_commit_decorations(commit);
	html("</td><td>");
	html_txt(info->author);

	if (revs->graph) {
		html("</td><td>");
		cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
	}

	if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) {
		files = 0;
		add_lines = 0;
		rem_lines = 0;
		cgit_diff_commit(commit, inspect_files, ctx.qry.vpath);
	}

	if (ctx.repo->enable_log_filecount)
		htmlf("</td><td>%d", files);
	if (ctx.repo->enable_log_linecount)
		htmlf("</td><td>-%d/+%d", rem_lines, add_lines);

	html("</td></tr>\n");

	if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */
		html("<tr class='nohover'>");

		if (ctx.qry.showmsg) {
			/* Concatenate commit message + notes in msgbuf */
			if (info->msg && *(info->msg)) {
				strbuf_addstr(&msgbuf, info->msg);
				strbuf_addch(&msgbuf, '\n');
			}
			format_note(NULL, commit->object.sha1, &msgbuf,
			            PAGE_ENCODING,
			            NOTES_SHOW_HEADER | NOTES_INDENT);
			strbuf_addch(&msgbuf, '\n');
			strbuf_ltrim(&msgbuf);
		}

		if (revs->graph) {
			int lines = 0;

			/* Calculate graph padding */
			if (ctx.qry.showmsg) {
				/* Count #lines in commit message + notes */
				const char *p = msgbuf.buf;
				lines = 1;
				while ((p = strchr(p, '\n'))) {
					p++;
					lines++;
				}
			}

			/* Print graph padding */
			html("<td class='commitgraph'>");
			while (lines > 0 || !graph_is_commit_finished(revs->graph)) {
				if (graphbuf.len)
					html("\n");
				strbuf_setlen(&graphbuf, 0);
				graph_next_line(revs->graph, &graphbuf);
				html(graphbuf.buf);
				lines--;
			}
			html("</td>\n");
		}
		else
			html("<td/>"); /* Empty 'Age' column */

		/* Print msgbuf into remainder of table row */
		htmlf("<td colspan='%d'%s>\n", cols,
			ctx.qry.showmsg ? " class='logmsg'" : "");
		html_txt(msgbuf.buf);
		html("</td></tr>\n");
	}

	strbuf_release(&msgbuf);
	strbuf_release(&graphbuf);
	cgit_free_commitinfo(info);
}
Esempio n. 15
0
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// EXPORT HTML //////////
void File::exportStructure(string path) {
	//open file buffer
	std::filebuf fb;
	fb.open(ofToDataPath(path, true).c_str(), std::ios::out);
	std::ostream html(&fb);

	html << "<html><head><title>ofxBlender file structure export</title>";
	html << "<style type=\"text/css\">";
	//styles
	html << "html,body{font-family:monospace}" << endl;
	html << "a{color: #000;}" << endl;
	html << "h2{padding:0;margin: 20px 0 5px 0;}" << endl;
	html << "h3{padding:0;margin: 10px 0 5px 0;}" << endl;
	html << "h3.type{font-weight:normal;}" << endl;
	html << "tr{}" << endl;
	html << "th,td{text-align:left;padding: 7px;border-bottom:1px solid #ccc;margin:0;}" << endl;
	html << "td.center, th.center{text-align:center;}" << endl;
	html << "</style></head><body>";

	html << "<h1>ofxBlender</h1>" << endl;

	html << "<h2>File info</h2>" << endl;
	html << "<h3>version</h3> " << version;
	string pType = "unsigned int";
	if(pointerSize == 8)
		pType = "unsigned long";
	html << "<h3>pointer type</h3> " << pType;


	//write all structures
	html << "<h2>Structures (Size)</h2>" << endl;

	for(vector<DNAStructure>::iterator it = catalog.structures.begin(); it<catalog.structures.end(); it++) {
		html << "<h3 class='type'><a id=\"" << (*it).type->name << "\">";
		html << (*it).type->id << " <b>" << (*it).type->name << "</b> (" << (*it).type->size << ")";
		html << "</a></h3>";
		html << "<table cellspacing='0'><tr><th>TYPE</th><th>NAME CLEAN</th><th>NAME</th><th class='center'>[]</th><th class='center'>*</th><th>SIZE</th><th>OFFSET</th></tr>" << endl;
		for(vector<DNAField>::iterator jt = (*it).fields.begin(); jt<(*it).fields.end(); jt++) {
			html << "<tr>";
			html << "<td>";
			//TYPE
			bool makeLink = catalog.hasStructure((*jt).type->name);
			if(makeLink)
				html << "<a href=\"#" << (*jt).type->name << "\">";
			html << (*jt).type->name;
			if(makeLink)
				html << "</a>";
			html << "</td>";

			//NAME
			html << "<td>" << (*jt).name->nameClean << "</td>";
			html << "<td>" << (*jt).name->name << "</td>";

			//IS ARRAY
			string arrayTxt = "";
			if((*jt).isArray) {
				//arrayTxt = "" + ofToString((*jt).arrayDimensions) + "";
				arrayTxt = "[";
				for(int i: (*jt).arraySizes)
					arrayTxt += ofToString(i) + ",";
				arrayTxt = arrayTxt.substr(0, arrayTxt.size()-1);
				arrayTxt += "]";
			}
			html << "<td class='center'>" << arrayTxt << "</td>";

			//IS POINTER
			string ptrTxt = "";
			if((*jt).isPointer)
				ptrTxt = "&#10003;";
			html << "<td class='center'>" << ptrTxt << "</td>";

			//SIZE
			html << "<td>" << (*jt).type->size << "</td>";
			html << "<td>" << (*jt).offset << "</td>";
			html << "</tr>" << endl;
		}
		html << "</table><br />" << endl;
	}

	//write all data blocks
	html << "<h2>Blocks</h2>" << endl;
	html << "<table cellspacing='0'><tr><th>NAME</th><th>TYPE</th><th>COUNT</th><th>SIZE</th><th>OFFSET</th><th>OLD ADDRESS</th></tr>" << endl;
	for(vector<Block>::iterator it = blocks.begin(); it<blocks.end(); it++) {
		DNAStructure& structure = catalog.structures[(*it).SDNAIndex];
		if(structure.type->name != "ScrVert" && structure.type->name != "Panel" && structure.type->name != "ScrEdge" && structure.type->name != "ARegion") {
			html << "<tr>";
			html << "<td>" << (*it).code << "</td>";
			html << "<td><a href=\"#" << structure.type->name << "\">" << structure.type->name << "</a></td>";
			html << "<td>" << (*it).count << "</td>";
			html << "<td>" << (*it).size << "</td>";
			html << "<td>" << (*it).offset << "</td>";
			html << "<td>" << (*it).address << "</td>";
			html << "</tr>" << endl;
		}
	}
	html << "</table>" << endl;

	//write all types
	/*
	html << "<h2>Types</h2>" << endl;
	html << "<table><tr><th>NAME</th><th>SIZE</th></tr>" << endl;
	for(vector<DNAType>::iterator it = catalog.types.begin(); it<catalog.types.end(); it++){
		html << "<tr>";
		html << "<td>" << (*it).name << "</td>";
		html << "<td>" << (*it).size << "</td>";
		html << "</tr>" << endl;
	}
	html << "</table>" << endl;
	*/

	//write all names
	/*
	html << "<h2>Names</h2>" << endl;
	html << "<p>" << endl;
	for(vector<DNAName>::iterator it = catalog.names.begin(); it<catalog.names.end(); it++){
		html << (*it).name;
		if(it != catalog.names.end() - 1)
			html << ", ";
		html << endl;
	}
	html << "</p>" << endl;
	*/

	//finish html
	html << "</body></html>" << endl;
	fb.close();
}
  void process() {
    doctype();
    html();

  }
Esempio n. 17
0
main(int argc, char *argv[])
{
	int i;
	int parse_parse();

	Debug::db_read();
	// Pass 1: scan files
	Block::enter();		// Linkage unit
	for (i = 1; i < argc; i++) {
		if (argv[i] == "-") {	// Linkage unit separator
			Block::exit();
			Block::enter();
			continue;
		}
		Block::enter();	// Compilation unit
		Fchar::set_input(argv[i]);
		Fchar::push_input("/dds/src/research/ie/refactor/wdefs.h");
		Fchar::push_input("/dds/src/research/ie/refactor/wincs.h");
		Pdtoken::macros_clear();
		if (parse_parse() != 0)
			exit(1);
		Block::exit();	// Compilation unit
	}
	Block::exit();		// Linkage unit

	// Pass 2: go through the files annotating identifiers
	deque_string color_names;
	// Some nice HTML colors
	color_names.push_back("ff0000");
	color_names.push_back("bf0000");
	color_names.push_back("00af00");
	color_names.push_back("00ef00");
	color_names.push_back("0000ff");
	color_names.push_back("bfbf00");
	color_names.push_back("00ffff");
	color_names.push_back("ff00ff");

	ifstream in;
	Fileid fi;
	Colormap cm;
	deque_string::const_iterator c = color_names.begin();
	cout << "<html><title>Identifier groups</title>\n"
		"<body bgcolor=\"#ffffff\">\n";
	for (i = 1; i < argc; i++) {
		if (argv[i] == "-") {	// Linkage unit separator
			cout << "<p><hr><p>\n";
			continue;
		}
		if (in.is_open())
			in.close();
		in.clear();		// Otherwise flags are dirty and open fails
		in.open(argv[i], ios::binary);
		if (in.fail()) {
			perror(argv[i]);
			exit(1);
		}
		cout << "<h2>" << argv[i] << "</h2>\n";
		fi = Fileid(argv[i]);
		// Go through the file character by character
		for (;;) {
			Tokid ti;
			int val, len;

			ti = Tokid(fi, in.tellg());
			if ((val = in.get()) == EOF)
				break;
			Eclass *ec;
			if ((ec = ti.check_ec()) && ec->get_size() > 1) {
				Colormap::const_iterator ci;
				ci = cm.find(ec);
				if (ci == cm.end()) {
					// Allocate new color
					cm[ec] = (*c);
					c++;
					if (c == color_names.end())
						c = color_names.begin();
					ci = cm.find(ec);
				}
				cout << "<font color=\"#" << (*ci).second << "\">";
				int len = ec->get_len();
				cout << (char)val;
				for (int j = 1; j < len; j++)
					cout << html((char)in.get());
				cout << "</font>";
				continue;
			}
			cout << html((char)val);
		}
	}
	cout << "</body></html>\n";
	return (0);
}
Esempio n. 18
0
int main(int argc,char *argv[]) 
{
	//
	// Some initialization for the common library
	//
	SetApplicationParameters(
		"MemMap",
		TOOL_VERSION_MAJOR,
		TOOL_VERSION_MINOR,
		"{ApplicationName} - Version {ApplicationVersion} - This program is a part of the OSDK\r\n"
		"\r\n"
		"Author:\r\n"
		"  Pointier Mickael\r\n"
		"\r\n"
		"Switches:\r\n"
		" -f   Format\r\n"
		"       -f0 => XA (Oric) [default]\r\n"
		"       -f1 => Devpac (Atari ST)\r\n"
		"\r\n"
		);


	INPUT_FORMAT inputFormat=INPUT_FORMAT_ORIC_XA;		// 0=XA / 1=Devpac

	ArgumentParser cArgumentParser(argc,argv);

	while (cArgumentParser.ProcessNextArgument())
	{
		if (cArgumentParser.IsSwitch("-f"))
		{
			//format: [-f]
			//	0 => XA (Oric)
			// 	1 => Devpac (Atari)
			inputFormat=(INPUT_FORMAT)cArgumentParser.GetIntegerValue(INPUT_FORMAT_ORIC_XA);
		}
	}


    if (cArgumentParser.GetParameterCount()!=NB_ARG)
    {
		ShowError(0);
    }


	//
	// Copy last parameters
	//
	std::string	source_name(cArgumentParser.GetParameter(0));
	std::string	dest_name(cArgumentParser.GetParameter(1));
	std::string	project_name(cArgumentParser.GetParameter(2));
	std::string	css_name(cArgumentParser.GetParameter(3));

	/*
	printf("\n0=%s\n",source_name.c_str());
	printf("\n1=%s\n",dest_name.c_str());
	printf("\n2=%s\n",project_name.c_str());
	printf("\n3=%s\n",css_name.c_str());
	*/

	void* ptr_buffer_void;
	size_t size_buffer_src;

	//
	// Load the file
	//
	if (!LoadFile(source_name.c_str(),ptr_buffer_void,size_buffer_src))
	{
		printf("\nUnable to load file '%s'",source_name.c_str());
		printf("\n");
		exit(1);
	}

	unsigned char *ptr_buffer=(unsigned char*)ptr_buffer_void;

	//
	// Parse the file, and generate the list of values
	//
	std::map<std::string,Section>	Sections;

	switch (inputFormat)
	{
	case INPUT_FORMAT_ORIC_XA:
		{
			Section& section_zeropage=Sections["Zero"];
			section_zeropage.m_anchor_name	="Zero";
			section_zeropage.m_section_name	="Zero page";
			section_zeropage.m_adress_size	=2;
			section_zeropage.m_begin_adress	=0x0;
			section_zeropage.m_end_adress	=0xFF;

			Section& section_normal=Sections["Normal"];
			section_normal.m_anchor_name	="Normal";
			section_normal.m_section_name	="Normal memory";
			section_normal.m_adress_size	=4;
			section_normal.m_begin_adress	=0x400;
			section_normal.m_end_adress		=0xBFFF;

			Section& section_overlay=Sections["Overlay"];
			section_overlay.m_anchor_name	="Overlay";
			section_overlay.m_section_name	="Overlay memory";
			section_overlay.m_adress_size	=4;
			section_overlay.m_begin_adress	=0xC000;
			section_overlay.m_end_adress	=0xFFFF;
		}
		break;

	case INPUT_FORMAT_ATARI_DEVPAC:
		{
			Section& section_zeropage=Sections["Text"];
			section_zeropage.m_anchor_name	="Text";
			section_zeropage.m_section_name	="Section TEXT";
			section_zeropage.m_adress_size	=4;
			section_zeropage.m_begin_adress	=0x00;
			section_zeropage.m_end_adress	=0xFFFFFF;

			Section& section_normal=Sections["Data"];
			section_normal.m_anchor_name	="Data";
			section_normal.m_section_name	="Section DATA";
			section_normal.m_adress_size	=4;
			section_normal.m_begin_adress	=0x00;
			section_normal.m_end_adress		=0xFFFFFF;

			Section& section_overlay=Sections["Bss"];
			section_overlay.m_anchor_name	="Bss";
			section_overlay.m_section_name	="Section BSS";
			section_overlay.m_adress_size	=4;
			section_overlay.m_begin_adress	=0x00;
			section_overlay.m_end_adress	=0xFFFFFF;

			Section& section_rs=Sections["RS"];
			section_rs.m_anchor_name	="RS";
			section_rs.m_section_name	="RS offsets";
			section_rs.m_adress_size	=4;
			section_rs.m_begin_adress	=0x00;
			section_rs.m_end_adress	=0xFFFFFF;
		}
		break;
	}


	char *ptr_tok=strtok((char*)ptr_buffer," \r\n");
	while (ptr_tok)
	{
		// Address
		int value=strtol(ptr_tok,0,16);

		switch (inputFormat)
		{
		case INPUT_FORMAT_ORIC_XA:
			{
				ptr_tok=strtok(0," \r\n");
				// Name
				if (value<256)
				{
					// Zero page
					Sections["Zero"].GetMap()[value]=ptr_tok;
				}
				else
				if (value>=0xc000)
				{
					// Overlay memory
					Sections["Overlay"].GetMap()[value]=ptr_tok;
				}
				else
				{
					Sections["Normal"].GetMap()[value]=ptr_tok;
				}
			}
			break;
		case INPUT_FORMAT_ATARI_DEVPAC:
			{
				// ptr_tok:
				// A=Absolute (rs/offsets/computations)
				// R=Relocatable (addresses)
				// T=TEXT
				// D=DATA
				// B=BSS
				std::string section="Text";

				std::string token;
				do
				{
					ptr_tok=strtok(0," \r\n");
					token=ptr_tok;
					if (token=="A")			section="RS";
					else if (token=="B")	section="Bss";
					else if (token=="T")	section="Text";
					else if (token=="D")	section="Data";
				}
				while (token.size()==1);

				Sections[section].GetMap()[value]=token;
			}
		}
		ptr_tok=strtok(0," \r\n");
	}


	//
	// Generate the html file
	//
	std::string html(gHtmlHeader);

	StringReplace(html,"{PageTitle}"	,project_name);
	StringReplace(html,"{CssLink}"		,css_name);

	/*
	html+="<A href=\"#Zero\">Zero page</A><br>";
	html+="<A href=\"#Normal\">Normal memory</A><br>";
	html+="<A href=\"#Overlay\">Overlay memory</A><br>";
	*/

	html+="<table>\r\n";
	html+="<tr>\r\n";

	std::map<std::string,Section>::const_iterator it(Sections.begin());
	while (it!=Sections.end())
	{
		const Section& section=it->second;
		html+="<td valign=top>\r\n";
		section.Generate(html);
		html+="</td>\r\n";
		++it;
	}

	html+="</tr>\r\n";
	html+="</table>\r\n";

	html=html+gHtmlFooter;

	unsigned char *ptr_buffer_dst=new unsigned char[size_buffer_src+8];
	int size_buffer_dst=size_buffer_src/2;

	unsigned char *ptr_src=ptr_buffer;
	unsigned char *ptr_dst=ptr_buffer_dst;
	int i;
	for (i=0;i<size_buffer_dst;i++)
	{
		unsigned char b0=*ptr_src++;
		unsigned char b1=*ptr_src++;
		unsigned char b=(b1&0xF0)|(b0>>4);
		*ptr_dst++=b;
	}

	if (!SaveFile(dest_name.c_str(),html.c_str(),html.size()))
	{
		printf("\nUnable to save file '%s'",source_name.c_str());
		printf("\n");
		exit(1);
	}

	//
	// Make some cleaning
	//
	delete[] ptr_buffer;
	delete[] ptr_buffer_dst;

	return 0;
}
Esempio n. 19
0
void cgit_print_tag(char *revname)
{
	struct strbuf fullref = STRBUF_INIT;
	unsigned char sha1[20];
	struct object *obj;

	if (!revname)
		revname = ctx.qry.head;

	strbuf_addf(&fullref, "refs/tags/%s", revname);
	if (get_sha1(fullref.buf, sha1)) {
		cgit_print_error_page(404, "Not found",
			"Bad tag reference: %s", revname);
		goto cleanup;
	}
	obj = parse_object(sha1);
	if (!obj) {
		cgit_print_error_page(500, "Internal server error",
			"Bad object id: %s", sha1_to_hex(sha1));
		goto cleanup;
	}
	if (obj->type == OBJ_TAG) {
		struct tag *tag;
		struct taginfo *info;

		tag = lookup_tag(sha1);
		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
			cgit_print_error_page(500, "Internal server error",
				"Bad tag object: %s", revname);
			goto cleanup;
		}
		cgit_print_layout_start();
		html("<table class='commit-info'>\n");
		htmlf("<tr><td>tag name</td><td>");
		html_txt(revname);
		htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
		if (info->tagger_date > 0) {
			html("<tr><td>tag date</td><td>");
			html_txt(show_date(info->tagger_date, info->tagger_tz,
						cgit_date_mode(DATE_ISO8601)));
			html("</td></tr>\n");
		}
		if (info->tagger) {
			html("<tr><td>tagged by</td><td>");
			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
			html_txt(info->tagger);
			if (info->tagger_email && !ctx.cfg.noplainemail) {
				html(" ");
				html_txt(info->tagger_email);
			}
			cgit_close_filter(ctx.repo->email_filter);
			html("</td></tr>\n");
		}
		html("<tr><td>tagged object</td><td class='sha1'>");
		cgit_object_link(tag->tagged);
		html("</td></tr>\n");
		if (ctx.repo->snapshots)
			print_download_links(revname);
		html("</table>\n");
		print_tag_content(info->msg);
		cgit_print_layout_end();
		cgit_free_taginfo(info);
	} else {
		cgit_print_layout_start();
		html("<table class='commit-info'>\n");
		htmlf("<tr><td>tag name</td><td>");
		html_txt(revname);
		html("</td></tr>\n");
		html("<tr><td>Tagged object</td><td class='sha1'>");
		cgit_object_link(obj);
		html("</td></tr>\n");
		if (ctx.repo->snapshots)
			print_download_links(revname);
		html("</table>\n");
		cgit_print_layout_end();
	}

cleanup:
	strbuf_release(&fullref);
}
Esempio n. 20
0
/* Create a sorted string_list with one entry per author. The util-field
 * for each author is another string_list which is used to calculate the
 * number of commits per time-interval.
 */
void cgit_show_stats(struct cgit_context *ctx)
{
	struct string_list authors;
	struct cgit_period *period;
	int top, i;
	const char *code = "w";

	if (ctx->qry.period)
		code = ctx->qry.period;

	i = cgit_find_stats_period(code, &period);
	if (!i) {
		cgit_print_error(fmt("Unknown statistics type: %c", code));
		return;
	}
	if (i > ctx->repo->max_stats) {
		cgit_print_error(fmt("Statistics type disabled: %s",
				     period->name));
		return;
	}
	authors = collect_stats(ctx, period);
	qsort(authors.items, authors.nr, sizeof(struct string_list_item),
		cmp_total_commits);

	top = ctx->qry.ofs;
	if (!top)
		top = 10;
	htmlf("<h2>Commits per author per %s", period->name);
	if (ctx->qry.path) {
		html(" (path '");
		html_txt(ctx->qry.path);
		html("')");
	}
	html("</h2>");

	html("<form method='get' action='' style='float: right; text-align: right;'>");
	cgit_add_hidden_formfields(1, 0, "stats");
	if (ctx->repo->max_stats > 1) {
		html("Period: ");
		html("<select name='period' onchange='this.form.submit();'>");
		for (i = 0; i < ctx->repo->max_stats; i++)
			htmlf("<option value='%c'%s>%s</option>",
				periods[i].code,
				period == &periods[i] ? " selected" : "",
				periods[i].name);
		html("</select><br/><br/>");
	}
	html("Authors: ");
	html("");
	html("<select name='ofs' onchange='this.form.submit();'>");
	htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : "");
	htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : "");
	htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : "");
	htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : "");
	htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : "");
	html("</select>");
	html("<noscript>&nbsp;&nbsp;<input type='submit' value='Reload'/></noscript>");
	html("</form>");
	print_authors(&authors, top, period);
}
Esempio n. 21
0
void cgit_print_repolist()
{
	int i, columns = 4, hits = 0, header = 0;
	char *last_section = NULL;
	char *section;
	int sorted = 0;

	if (ctx.cfg.enable_index_links)
		columns++;

	ctx.page.title = ctx.cfg.root_title;
	cgit_print_http_headers(&ctx);
	cgit_print_docstart(&ctx);
	cgit_print_pageheader(&ctx);

	if (ctx.cfg.index_header)
		html_include(ctx.cfg.index_header);

	if(ctx.qry.sort)
		sorted = sort_repolist(ctx.qry.sort);
	else if (ctx.cfg.sort_sections)
		sort_repolist("section");

	html("<table summary='repository list' class='list nowrap'>");
	for (i=0; i<cgit_repolist.count; i++) {
		ctx.repo = &cgit_repolist.repos[i];
		if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
			continue;
		hits++;
		if (hits <= ctx.qry.ofs)
			continue;
		if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
			continue;
		if (!header++)
			print_header(columns);
		section = ctx.repo->section;
		if (section && !strcmp(section, ""))
			section = NULL;
		if (!sorted &&
		    ((last_section == NULL && section != NULL) ||
		    (last_section != NULL && section == NULL) ||
		    (last_section != NULL && section != NULL &&
		     strcmp(section, last_section)))) {
			htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
			      columns);
			html_txt(section);
			html("</td></tr>");
			last_section = section;
		}
		htmlf("<tr><td class='%s'>",
		      !sorted && section ? "sublevel-repo" : "toplevel-repo");
		cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
		html("</td><td>");
		html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
		html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
		html_link_close();
		html("</td><td>");
		html_txt(ctx.repo->owner);
		html("</td><td>");
		print_modtime(ctx.repo);
		html("</td>");
		if (ctx.cfg.enable_index_links) {
			html("<td>");
			cgit_summary_link("summary", NULL, "button", NULL);
			cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
				      0, NULL, NULL, ctx.qry.showmsg);
			cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
			html("</td>");
		}
		html("</tr>\n");
	}
	html("</table>");
	if (!hits)
		cgit_print_error("No repositories found");
	else if (hits > ctx.cfg.max_repo_count)
		print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort);
	cgit_print_docend();
}
Esempio n. 22
0
static void print_object(const unsigned char *sha1, const char *path,
			 const char *basename, const char *rev)
{
	enum object_type type;
	char *buf;
	unsigned long size;
	struct argv_array rev_argv = ARGV_ARRAY_INIT;
	struct rev_info revs;
	struct blame_scoreboard sb;
	struct blame_origin *o;
	struct blame_entry *ent = NULL;

	type = sha1_object_info(sha1, &size);
	if (type == OBJ_BAD) {
		cgit_print_error_page(404, "Not found", "Bad object name: %s",
				      sha1_to_hex(sha1));
		return;
	}

	buf = read_sha1_file(sha1, &type, &size);
	if (!buf) {
		cgit_print_error_page(500, "Internal server error",
			"Error reading object %s", sha1_to_hex(sha1));
		return;
	}

	argv_array_push(&rev_argv, "blame");
	argv_array_push(&rev_argv, rev);
	init_revisions(&revs, NULL);
	revs.diffopt.flags.allow_textconv = 1;
	setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL);
	init_scoreboard(&sb);
	sb.revs = &revs;
	setup_scoreboard(&sb, path, &o);
	o->suspects = blame_entry_prepend(NULL, 0, sb.num_lines, o);
	prio_queue_put(&sb.commits, o->commit);
	blame_origin_decref(o);
	sb.ent = NULL;
	sb.path = path;
	assign_blame(&sb, 0);
	blame_sort_final(&sb);
	blame_coalesce(&sb);

	cgit_set_title_from_path(path);

	cgit_print_layout_start();
	htmlf("blob: %s (", sha1_to_hex(sha1));
	cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path);
	html(") (");
	cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path);
	html(")\n");

	if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
		htmlf("<div class='error'>blob size (%ldKB)"
		      " exceeds display size limit (%dKB).</div>",
		      size / 1024, ctx.cfg.max_blob_size);
		return;
	}

	html("<table class='blame blob'>\n<tr>\n");

	/* Commit hashes */
	html("<td class='hashes'>");
	for (ent = sb.ent; ent; ent = ent->next) {
		html("<div class='alt'><pre>");
		emit_blame_entry_hash(ent);
		html("</pre></div>");
	}
	html("</td>\n");

	/* Line numbers */
	if (ctx.cfg.enable_tree_linenumbers) {
		html("<td class='linenumbers'>");
		for (ent = sb.ent; ent; ent = ent->next) {
			html("<div class='alt'><pre>");
			emit_blame_entry_linenumber(ent);
			html("</pre></div>");
		}
		html("</td>\n");
	}

	html("<td class='lines'><div>");

	/* Colored bars behind lines */
	html("<div>");
	for (ent = sb.ent; ent; ) {
		struct blame_entry *e = ent->next;
		html("<div class='alt'><pre>");
		emit_blame_entry_line_background(&sb, ent);
		html("</pre></div>");
		free(ent);
		ent = e;
	}
	html("</div>");

	free((void *)sb.final_buf);

	/* Lines */
	html("<pre><code>");
	if (ctx.repo->source_filter) {
		char *filter_arg = xstrdup(basename);
		cgit_open_filter(ctx.repo->source_filter, filter_arg);
		html_raw(buf, size);
		cgit_close_filter(ctx.repo->source_filter);
		free(filter_arg);
	} else {
		html_txt(buf);
	}
	html("</code></pre>");

	html("</div></td>\n");

	html("</tr>\n</table>\n");

	cgit_print_layout_end();
}
Esempio n. 23
0
   ConvolutionFilterCodeDialog::ConvolutionFilterCodeDialog( String mode, const Filter& _filter ) : Dialog(), filter( _filter )
   {
      // ### TextBox
      FilterCode_TextBox.SetScaledMinSize( 700, 300 );
      FilterCode_TextBox.OnCaretPositionUpdated( (TextBox::caret_event_handler)&ConvolutionFilterCodeDialog::__TextBox_CaretPosition, *this );

      if ( mode == "Edit" )
      {
         FilterCode_TextBox.SetReadWrite();
         FilterCode_TextBox.SetText( filter.ToSource() );
      }

      tableRow = 0;
      String s;
      String html( "<html style=\"white-space:pre;text-align:right;\">"
                     "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" );

      StringList cols;
      UpdateTableColors();

      if ( mode == "View" )
      {
         FilterCode_TextBox.SetReadOnly();
         if ( filter.IsSeparable() )
         {
            SeparableFilter fs( filter.Separable() );
            float element;

            // Rows
            for ( int i = 0; i < fs.Size(); ++i )
            {
               // Cols
               for ( int j = 0; j < fs.Size(); ++j )
               {
                  // Calculus of each coefficient of the separable filter
                  element = Round( fs.ColFilter()[i] * fs.RowFilter()[j], 6 );
                  cols.Add( String().Format( "%10.6f", element ) );


               }
               html += TR( cols );
               cols.Clear();
            }
         }
         else
         {
            KernelFilter k( filter.Kernel() );

            for ( int i = 0; i < k.Size(); ++i )
            {
               for ( int j = 0; j < k.Size(); ++j )
               {
                  float element = Round( k.Coefficients()[i][j], 6 );
                  // The elements of the KernelFilter can be accessed directly God thanks and the [] operator.
                  cols.Add( String().Format( "%10.6f", element ) );
               }
               html += TR( cols );
               cols.Clear();
            }
         }
         html += "</table></html>";
         // We got it!! we set the TextBox text by passing the composed String s.
         FilterCode_TextBox.SetText( html );
         UpdateTableColors();
      }

      if ( mode == "View" )
         LineCol_Label.Hide();
      else
         LineCol_Label.Show();

      LineCol_Sizer.SetSpacing( 4 );
      LineCol_Sizer.Add( LineCol_Label );
      LineCol_Sizer.AddStretch();

      // ### Save PushButton
      Save_PushButton.SetText( "Save" );
      Save_PushButton.SetCursor( StdCursor::Checkmark );
      Save_PushButton.OnClick( (Button::click_event_handler)&ConvolutionFilterCodeDialog::__Button_Click, *this );
      if ( mode == "View" )
         Save_PushButton.Hide();
      else
         Save_PushButton.SetDefault();

      if ( mode == "View" )
      {
         Cancel_PushButton.SetText( "Close" );
         Cancel_PushButton.SetCursor( StdCursor::Checkmark );
         Cancel_PushButton.SetDefault();
      }
      else
      {
         Cancel_PushButton.SetText( "Cancel" );
         Cancel_PushButton.SetCursor( StdCursor::Crossmark );
      }
      Cancel_PushButton.OnClick( (Button::click_event_handler)&ConvolutionFilterCodeDialog::__Button_Click, *this );

      DialogButtons_Sizer.SetSpacing( 8 );
      DialogButtons_Sizer.AddStretch();
      DialogButtons_Sizer.Add( Save_PushButton );
      DialogButtons_Sizer.Add( Cancel_PushButton );
      DialogButtons_Sizer.AddStretch();

      Global_Sizer.SetMargin( 4 );
      Global_Sizer.SetSpacing( 4 );
      Global_Sizer.Add( FilterCode_TextBox );
      Global_Sizer.Add( LineCol_Sizer );
      Global_Sizer.Add( DialogButtons_Sizer );

      SetSizer( Global_Sizer );
      EnableUserResizing();
      AdjustToContents();
      BringToFront();
      //SetFixedSize();

      if ( mode == "View" )
         SetWindowTitle( '\"' + filter.Name() + '\"' + " filter elements" );
      else if ( mode == "Edit" )
         SetWindowTitle( '\"' + filter.Name() + '\"' + " edit" );
      else if ( mode == "New" )
         SetWindowTitle( "New filter" );
      else
         throw Error( "Internal error: Invalid dialog operation mode in ConvolutionFilterCodeDialog" );
   }
Esempio n. 24
0
static void print_refs_link(char *path)
{
	html("<tr class='nohover'><td colspan='5'>");
	cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path);
	html("</td></tr>");
}
Esempio n. 25
0
static void print_authors(struct string_list *authors, int top,
                          const struct cgit_period *period)
{
    struct string_list_item *author;
    struct authorstat *authorstat;
    struct string_list *items;
    struct string_list_item *date;
    time_t now;
    long i, j, total;
    struct tm *tm;
    char *tmp;

    time(&now);
    tm = gmtime(&now);
    period->trunc(tm);
    for (i = 1; i < period->count; i++)
        period->dec(tm);

    html("<table class='stats'><tr><th>Author</th>");
    for (j = 0; j < period->count; j++) {
        tmp = period->pretty(tm);
        htmlf("<th>%s</th>", tmp);
        period->inc(tm);
    }
    html("<th>Total</th></tr>\n");

    if (top <= 0 || top > authors->nr)
        top = authors->nr;

    for (i = 0; i < top; i++) {
        author = &authors->items[i];
        html("<tr><td class='left'>");
        html_txt(author->string);
        html("</td>");
        authorstat = author->util;
        items = &authorstat->list;
        total = 0;
        for (j = 0; j < period->count; j++)
            period->dec(tm);
        for (j = 0; j < period->count; j++) {
            tmp = period->pretty(tm);
            period->inc(tm);
            date = string_list_lookup(items, tmp);
            if (!date)
                html("<td>0</td>");
            else {
                htmlf("<td>%lu</td>", (uintptr_t)date->util);
                total += (uintptr_t)date->util;
            }
        }
        htmlf("<td class='sum'>%ld</td></tr>", total);
    }

    if (top < authors->nr)
        print_combined_authorrow(authors, top, authors->nr - 1,
                                 "Others (%ld)", "left", "", "sum", period);

    print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
                             "total", "sum", "sum", period);
    html("</table>");
}
Esempio n. 26
0
void MainWidget::request( QTcpSocket *id,
                          const QHttpRequestHeader &header )
{
   mpMessageBuffer->addItem( header.toString() );
   while( mpMessageBuffer->count() > 200 )
   {
      QListWidgetItem *item = mpMessageBuffer->takeItem( 0 );
      if( item )
      {
         delete item;
      }
   }
   mpMessageBuffer->scrollToBottom();

#if 0
   if( header.path() == "/favicon.ico" )
   {
      QFile file( ":/favicon.ico" );
      file.open( QIODevice::ReadOnly | QIODevice::Text );
      emit response( id,
                     QHttpResponseHeader( 200, "OK" ),
                     file.readAll() );
      file.close();
      return;
   }
#endif
   if( header.path() == "/wait" )
   {
      mDelayList.append( id );
      return;
   }
   if( header.path() == "/get" )
   {
      QString reply( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
                     "<response>\n"
                     " <reply>%1</reply>\n"
                     " <artist>%2</artist>\n"
                     " <title>%3</title>\n"
                     " <album>%4</album>\n"
                     " <track>%5</track>\n"
                     "</response>\n" );
      QByteArray replyMsg( reply.arg( Qt::escape( QString::fromUtf8(mMsg.constData()) ),
                                      Qt::escape( mTrackInfo.mArtist ),
                                      Qt::escape( mTrackInfo.mTitle ),
                                      Qt::escape( mTrackInfo.mAlbum ),
                                      QString::number(mTrackInfo.mTrackNr) ).toUtf8() );
      emit response( id,
                     QHttpResponseHeader( 200, "OK XML" ),
                     replyMsg );
      return;
   }
   QString html("<html>\n<head>\n<title>%1</title>\n"
         "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>\n"
         "<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'>\n"
         "<script src='ajax.js' type='text/javascript'>\n"
         "</script>\n"
         "</head>\n<body>\n"
         "<h1>%2</h1>\n"
         "<p>HTTP Request: %3 %4</p>\n"
         "<table border='1'>\n"
         "<tr valign='top'><td>Artist:</td><td><textarea cols='80' rows='1' name='artist' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Title:</td><td><textarea cols='80' rows='1' name='title' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Album:</td><td><textarea cols='80' rows='1' name='album' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Track:</td><td><textarea cols='80' rows='1' name='track' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Reply:</td><td><textarea cols='80' rows='5' name='reply' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Status:</td><td><input name='status' size='12' readonly>"
         "<input type='button' value='refresh' onclick='loadFields();'></td></tr>\n"
         "</table></body></html>\n"
         );
   html = html.arg( QApplication::organizationName() + ": " + QApplication::applicationName(),
                    QApplication::organizationName() + ": " + QApplication::applicationName(),
                    header.method(),
                    header.path() );

   emit response( id,
                  QHttpResponseHeader( 200, "OK" ),
                  html.toUtf8() );
}
Esempio n. 27
0
void cgit_print_commit(char *hex, const char *prefix)
{
	struct commit *commit, *parent;
	struct commitinfo *info, *parent_info;
	struct commit_list *p;
	struct strbuf notes = STRBUF_INIT;
	unsigned char sha1[20];
	char *tmp, *tmp2;
	int parents = 0;

	if (!hex)
		hex = ctx.qry.head;

	if (get_sha1(hex, sha1)) {
		cgit_print_error("Bad object id: %s", hex);
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit) {
		cgit_print_error("Bad commit reference: %s", hex);
		return;
	}
	info = cgit_parse_commit(commit);

	format_display_notes(sha1, &notes, PAGE_ENCODING, 0);

	load_ref_decorations(DECORATE_FULL_REFS);

	cgit_print_diff_ctrls();
	html("<table summary='commit info' class='commit-info'>\n");
	html("<tr><th>author</th><td>");
	html_txt(info->author);
	if (!ctx.cfg.noplainemail) {
		html(" ");
		html_txt(info->author_email);
	}
	html("</td><td class='right'>");
	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
	html("</td></tr>\n");
	html("<tr><th>committer</th><td>");
	html_txt(info->committer);
	if (!ctx.cfg.noplainemail) {
		html(" ");
		html_txt(info->committer_email);
	}
	html("</td><td class='right'>");
	cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
	html("</td></tr>\n");
	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
	tmp = sha1_to_hex(commit->object.sha1);
	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
	html(" (");
	cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
	html(")</td></tr>\n");
	html("<tr><th>tree</th><td colspan='2' class='sha1'>");
	tmp = xstrdup(hex);
	cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
		       ctx.qry.head, tmp, NULL);
	if (prefix) {
		html(" /");
		cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
	}
	free(tmp);
	html("</td></tr>\n");
	for (p = commit->parents; p; p = p->next) {
		parent = lookup_commit_reference(p->item->object.sha1);
		if (!parent) {
			html("<tr><td colspan='3'>");
			cgit_print_error("Error reading parent commit");
			html("</td></tr>");
			continue;
		}
		html("<tr><th>parent</th>"
		     "<td colspan='2' class='sha1'>");
		tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
		if (ctx.repo->enable_subject_links) {
			parent_info = cgit_parse_commit(parent);
			tmp2 = parent_info->subject;
		}
		cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
		html(" (");
		cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
			       sha1_to_hex(p->item->object.sha1), prefix, 0);
		html(")</td></tr>");
		parents++;
	}
	if (ctx.repo->snapshots) {
		html("<tr><th>download</th><td colspan='2' class='sha1'>");
		cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
					  hex, ctx.repo->snapshots);
		html("</td></tr>");
	}
	html("</table>\n");
	html("<div class='commit-subject'>");
	if (ctx.repo->commit_filter)
		cgit_open_filter(ctx.repo->commit_filter);
	html_txt(info->subject);
	if (ctx.repo->commit_filter)
		cgit_close_filter(ctx.repo->commit_filter);
	show_commit_decorations(commit);
	html("</div>");
	html("<div class='commit-msg'>");
	if (ctx.repo->commit_filter)
		cgit_open_filter(ctx.repo->commit_filter);
	html_txt(info->msg);
	if (ctx.repo->commit_filter)
		cgit_close_filter(ctx.repo->commit_filter);
	html("</div>");
	if (notes.len != 0) {
		html("<div class='notes-header'>Notes</div>");
		html("<div class='notes'>");
		if (ctx.repo->commit_filter)
			cgit_open_filter(ctx.repo->commit_filter);
		html_txt(notes.buf);
		if (ctx.repo->commit_filter)
			cgit_close_filter(ctx.repo->commit_filter);
		html("</div>");
		html("<div class='notes-footer'></div>");
	}
	if (parents < 3) {
		if (parents)
			tmp = sha1_to_hex(commit->parents->item->object.sha1);
		else
			tmp = NULL;
		cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
	}
	strbuf_release(&notes);
	cgit_free_commitinfo(info);
}
Esempio n. 28
0
File: ui-log.c Progetto: p00ya/cgit
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
		    char *path, int pager)
{
	struct rev_info rev;
	struct commit *commit;
	const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
	int argc = 2;
	int i, columns = 3;

	if (!tip)
		tip = ctx.qry.head;

	argv[1] = disambiguate_ref(tip);

	if (grep && pattern) {
		if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
		    !strcmp(grep, "committer"))
			argv[argc++] = fmt("--%s=%s", grep, pattern);
		if (!strcmp(grep, "range"))
			argv[1] = pattern;
	}

	if (path) {
		argv[argc++] = "--";
		argv[argc++] = path;
	}
	init_revisions(&rev, NULL);
	rev.abbrev = DEFAULT_ABBREV;
	rev.commit_format = CMIT_FMT_DEFAULT;
	rev.verbose_header = 1;
	rev.show_root_diff = 0;
	setup_revisions(argc, argv, &rev, NULL);
	load_ref_decorations(DECORATE_FULL_REFS);
	rev.show_decorations = 1;
	rev.grep_filter.regflags |= REG_ICASE;
	compile_grep_patterns(&rev.grep_filter);
	prepare_revision_walk(&rev);

	if (pager)
		html("<table class='list nowrap'>");

	html("<tr class='nohover'><th class='left'>Age</th>"
	      "<th class='left'>Commit message");
	if (pager) {
		html(" (");
		cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
			      NULL, ctx.qry.head, ctx.qry.sha1,
			      ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep,
			      ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
		html(")");
	}
	html("</th><th class='left'>Author</th>");
	if (ctx.repo->enable_log_filecount) {
		html("<th class='left'>Files</th>");
		columns++;
		if (ctx.repo->enable_log_linecount) {
			html("<th class='left'>Lines</th>");
			columns++;
		}
	}
	html("</tr>\n");

	if (ofs<0)
		ofs = 0;

	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
		free(commit->buffer);
		commit->buffer = NULL;
		free_commit_list(commit->parents);
		commit->parents = NULL;
	}

	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
		print_commit(commit);
		free(commit->buffer);
		commit->buffer = NULL;
		free_commit_list(commit->parents);
		commit->parents = NULL;
	}
	if (pager) {
		htmlf("</table><div class='pager'>",
		     columns);
		if (ofs > 0) {
			cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
				      ctx.qry.sha1, ctx.qry.vpath,
				      ofs - cnt, ctx.qry.grep,
				      ctx.qry.search, ctx.qry.showmsg);
			html("&nbsp;");
		}
		if ((commit = get_revision(&rev)) != NULL) {
			cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
				      ctx.qry.sha1, ctx.qry.vpath,
				      ofs + cnt, ctx.qry.grep,
				      ctx.qry.search, ctx.qry.showmsg);
		}
		html("</div>");
	} else if ((commit = get_revision(&rev)) != NULL) {
		html("<tr class='nohover'><td colspan='3'>");
		cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL,
			      ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg);
		html("</td></tr>\n");
	}
}
Esempio n. 29
0
std::string Stencil::request(const std::string& verb,const std::string& method,const std::string& body){
	Json::Document request;
	if(verb=="GET"){
		// FIXME
		// Need to parse out request queries
	}
	else if(body.length()){
		request.load(body);
	}
	Json::Document response = Json::Object();
	std::string signature = verb + " " + method;
	
	// FIXME
	// This is currently a POST but should be changed to a GET
	// after fix above is done
	if(signature=="POST content"){
		auto format = request["format"].as<std::string>();
		auto pretty = request["pretty"].as<bool>();

		std::string content;
		if(format=="html" or format=="") content = html(false,pretty);
		else if(format=="cila") content = cila();
		else {
			response.append("error","format is not 'cila' or 'html'");
		}
		response.append("format",format);
		response.append("content",content);
	}
	else if(signature=="PUT content"){
		auto format = request["format"].as<std::string>();
		auto content = request["content"].as<std::string>();

		html(content).write();
	}
	else if(signature=="PUT render"){
		auto format = request["format"].as<std::string>();
		auto content = request["content"].as<std::string>();
		if(content.length()){
			if(format=="html") html(content);
			else if(format=="cila") cila(content);
			else {
				response.append("error","format is not 'cila' or 'html'");
			}
		}
		
		render();

		response.append("format","html");
		response.append("content",html());
	}
	else if(signature=="PUT boot"){
		response = Component::call("boot","{}");
	}
	else if(signature=="PUT write"){
		write();
	}
	else if(signature=="PUT store"){
		store();
	}
	else if(signature=="PUT restore"){
		restore();
	}
	else {
		throw RequestInvalidException();
	}

	return response.dump();
}
Esempio n. 30
0
void add_entry(struct commit *commit, char *host)
{
	char delim = '&';
	char *hex;
	char *mail, *t, *t2;
	struct commitinfo *info;

	info = cgit_parse_commit(commit);
	hex = sha1_to_hex(commit->object.sha1);
	html("<entry>\n");
	html("<title>");
	html_txt(info->subject);
	html("</title>\n");
	html("<updated>");
	cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time);
	html("</updated>\n");
	html("<author>\n");
	if (info->author) {
		html("<name>");
		html_txt(info->author);
		html("</name>\n");
	}
	if (info->author_email) {
		mail = xstrdup(info->author_email);
		t = strchr(mail, '<');
		if (t)
			t++;
		else
			t = mail;
		t2 = strchr(t, '>');
		if (t2)
			*t2 = '\0';
		html("<email>");
		html_txt(t);
		html("</email>\n");
		free(mail);
	}
	html("</author>\n");
	html("<published>");
	cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time);
	html("</published>\n");
	if (host) {
		html("<link rel='alternate' type='text/html' href='http://");
		html_attr(host);
		html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL));
		if (ctx.cfg.virtual_root)
			delim = '?';
		htmlf("%cid=%s", delim, hex);
		html("'/>\n");
	}
	htmlf("<id>%s</id>\n", hex);
	html("<content type='text'>\n");
	html_txt(info->msg);
	html("</content>\n");
	html("<content type='xhtml'>\n");
	html("<div xmlns='http://www.w3.org/1999/xhtml'>\n");
	html("<pre>\n");
	html_txt(info->msg);
	html("</pre>\n");
	html("</div>\n");
	html("</content>\n");
	html("</entry>\n");
	cgit_free_commitinfo(info);
}