char *server_dispatch(struct nli *nli) { // put incoming command into array int ac = 0; int *acp = ∾ char **av = explode(nli->info->command, " ", acp); char *rmt = NULL; rmt = filter_specified_remote(ac, av, 0); // find out what group the command needs to be sent to int who = filter_who(ac, av, 0, rmt); // put the incoming command in the expected order char *buf = NULL; buf = sanitize_command(ac, av, 0); if (buf == NULL) { return strdup("no command"); } set_node_element(&nli->info->command, buf); // free all memory of the first explode array destroy_array(av, ac); // put sanitized command into array ac = 0; av = explode(buf, " ", acp); // filter the destination out of the command char *cmd = NULL; cmd = filter_command(ac, av, 0); // free all memory of the second explode array destroy_array(av, ac); // if nli->info isn't in rec_head nodelist // run the command or // send it to the right nodes char *r, *uq; if (find_node(nli, rec_head) == NULL) { append_to_received_command_list(nli->info); uq = strdup(nli->info->unique); r = route_command(nli, who, rmt, cmd, buf, uq); free(uq); } else { r = strdup("Already have it"); } if (rmt) free(rmt); if (buf) free(buf); if (cmd) free(cmd); return r; }
void jsbeautify_dialog(Tbfwin * bfwin) { #if GTK_CHECK_VERSION(3,0,0) GtkWidget *dialog, *grid, *hbox, *inselection, *usetabs, *tabsize, *nopreservenewline, *jslinthappy, *unescape_encoded_chars; #else GtkWidget *dialog, *table, *inselection, *usetabs, *tabsize, *nopreservenewline, *jslinthappy, *unescape_encoded_chars; #endif gint result, begin, end; gchar *command; dialog = gtk_dialog_new_with_buttons(_("Javascript Beautify"), GTK_WINDOW(bfwin->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); #if GTK_CHECK_VERSION(3,0,0) grid = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(grid), 12); gtk_grid_set_row_spacing(GTK_GRID(grid), 6); gtk_container_set_border_width(GTK_CONTAINER(grid), 6); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), grid, FALSE, FALSE, 0); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); tabsize = dialog_spin_button_labeled(1, 99, 3, _("_Indent size:"), hbox, 12); gtk_container_add(GTK_CONTAINER(grid), hbox); usetabs = dialog_check_button_new(_("Use _tabs to indent, not spaces"), TRUE); gtk_grid_attach_next_to(GTK_GRID(grid), usetabs, hbox, GTK_POS_BOTTOM, 1, 1); nopreservenewline = dialog_check_button_new(_("Do not _preserve existing line breaks"), FALSE); gtk_grid_attach_next_to(GTK_GRID(grid), nopreservenewline, usetabs, GTK_POS_BOTTOM, 1, 1); jslinthappy = dialog_check_button_new(_("More _jslint-compatible output"), FALSE); gtk_grid_attach_next_to(GTK_GRID(grid), jslinthappy, nopreservenewline, GTK_POS_BOTTOM, 1, 1); unescape_encoded_chars = dialog_check_button_new(_("_Decode printable chars encoded in \\\\xNN notation"), FALSE); gtk_grid_attach_next_to(GTK_GRID(grid), unescape_encoded_chars, jslinthappy, GTK_POS_BOTTOM, 1, 1); /* TODO: Is this a bug? Altering the option doesn't change anything */ if (doc_get_selection(DOCUMENT(bfwin->current_document), &begin, &end)) { inselection = dialog_check_button_new(_("Beautify only in _selection"), TRUE); gtk_grid_attach_next_to(GTK_GRID(grid), inselection, unescape_encoded_chars, GTK_POS_BOTTOM, 1, 1); } else { begin = 0; end = -1; } #else table = dialog_table_in_vbox_defaults(3, 2, 6, gtk_dialog_get_content_area(GTK_DIALOG(dialog))); if (doc_get_selection(DOCUMENT(bfwin->current_document), &begin, &end)) { inselection = dialog_check_button_in_table(_("Beautify only in _selection"), TRUE, table, 0, 2, 0, 1); } else { begin = 0; end = -1; } usetabs = dialog_check_button_in_table(_("Use _tabs to indent, not spaces"), TRUE, table, 0, 2, 1, 2); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("_Indent size")), 0, 1, 2, 3); tabsize = dialog_spin_button_in_table(1, 99, 3, table, 1, 2, 2, 3); nopreservenewline = dialog_check_button_in_table(_("Do not _preserve existing line breaks"), FALSE, table, 0, 2, 3, 4); jslinthappy = dialog_check_button_in_table(_("More _jslint-compatible output"), FALSE, table, 0, 2, 4, 5); unescape_encoded_chars = dialog_check_button_in_table(_("_Decode printable chars encoded in \\\\xNN notation"), FALSE, table, 0, 2, 5, 6); #endif /* in selection or all text -s, --indent-size=NUMBER indentation size. (default 4). -c, --indent-char=CHAR character to indent with. (default space). -t, --indent-with-tabs Indent with tabs, overrides -s and -c -d, --disable-preserve-newlines do not preserve existing line breaks. -j, --jslint-happy more jslint-compatible output -b, --brace-style=collapse brace style (collapse, expand, end-expand) -k, --keep-array-indentation keep array indentation. -o, --outfile=FILE specify a file to output to (default stdout) -f, --keep-function-indentation Do not re-indent function bodies defined in var lines. -x, --unescape-strings Decode printable chars encoded in \\xNN notation. */ gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: #ifdef WIN32 command = g_strdup_printf("|python " PKGDATADIR "/jsbeautify %s -s %d %s %s %s -|", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usetabs)) ? "-t" : "", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(tabsize)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nopreservenewline)) ? "-d" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(jslinthappy)) ? "-j" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(unescape_encoded_chars)) ? "-x" : ""); #else command = g_strdup_printf("|" PKGDATADIR "/jsbeautify %s -s %d %s %s %s -|", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usetabs)) ? "-t" : "", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(tabsize)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nopreservenewline)) ? "-d" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(jslinthappy)) ? "-j" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(unescape_encoded_chars)) ? "-x" : ""); #endif filter_command(bfwin, command, begin, end); g_free(command); break; default: break; } gtk_widget_destroy(dialog); }
Implementation(Bot *b) { _handler_id = add_handler(filter_command("005").from_bot(b), &Implementation<ISupport>::_populate); }