static void show_nodes (GType type, GType sibling, const gchar *indent) { GType *children; guint i; if (!type) return; children = g_type_children (type, NULL); if (type != root) for (i = 0; i < spacing; i++) g_fprintf (f_out, "%s%s\n", indent, O_VLINE); g_fprintf (f_out, "%s%s%s%s", indent, sibling ? O_BRANCH : (type != root ? O_LLEAF : O_SPACE), O_ESPACE, g_type_name (type)); for (i = strlen (g_type_name (type)); i <= strlen (indent_inc); i++) fputs (O_KEY_FILL, f_out); fputc ('\n', f_out); if (children && recursion) { gchar *new_indent; GType *child; if (sibling) new_indent = g_strconcat (indent, O_VLINE, indent_inc, NULL); else new_indent = g_strconcat (indent, O_SPACE, indent_inc, NULL); for (child = children; *child; child++) show_nodes (child[0], child[1], new_indent); g_free (new_indent); } g_free (children); }
void redis_reshard::run() { if (get_masters_info() == false) return; show_nodes(); fflush(stdout); char buf[1024]; int nslots = 0; while (true) { printf("How many slots do you want to move (from 1 to 16384) ? "); fflush(stdout); int ret = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf)); if (ret == ACL_VSTREAM_EOF) exit(1); acl_mystr_trim(buf); nslots = atoi(buf); if (nslots > 0 && nslots < 16384) break; printf("invalid value: %d\r\n", ret); } acl::redis_node* target = NULL; while (true) { printf("What is the receiving node ID? "); fflush(stdout); int ret = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf)); if (ret == ACL_VSTREAM_EOF) exit(1); acl_mystr_trim(buf); target = find_node(buf); if (target != NULL) break; printf("...The specified node(%s) is not known or not " "a master, please try again.\r\n", buf); } assert(target != NULL); printf("Please input all the source node IDs.\r\n"); printf(" Type 'all' to use all the nodes as source nodes for the hash slots\r\n"); printf(" Type 'done' once you entered all the source node IDs.\r\n"); std::vector<acl::redis_node*> sources; while (true) { printf("Source node #%d: ", (int) sources.size() + 1); fflush(stdout); int ret = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf)); if (ret == ACL_VSTREAM_EOF) exit(1); acl_mystr_trim(buf); if (strcasecmp(buf, "done") == 0) break; if (strcasecmp(buf, "all") == 0) { copy_all(sources, target->get_id()); break; } acl::redis_node* source = find_node(buf); if (source == NULL) { printf("...The source node(%s) is not known\r\n", buf); continue; } if (strcmp(target->get_id(), buf) == 0) { printf("... It is not possible to use the target node as source node\r\n"); continue; } sources.push_back(source); } if (sources.empty()) { printf("*** No source nodes given, operation aborted\r\n"); exit(1); } redis_migrate migrate(masters_); migrate.move_slots(sources, *target, nslots); }
int main() { typedef quan::atomicstring<char> node; typedef quan::digraph<node > graph; graph g; g.insert("S","a"); g.insert("S","x"); g.insert("x","b"); g.insert("b","S"); show_nodes(g,std::cout); #if(1) bool f = create_dot_file("dot.txt",g, "test1"); if (f){ int res = system("dot -Tpng -o graph.png dot.txt"); if ( res == 0){ std::cout << "graph written successfully\n"; }else{ std::cout << "graph writing failed with " << res << "\n"; } } #endif graph::node_set_type roots = get_root_nodes(g); int num_roots = roots.size(); if ( num_roots ==1){ std::cout << "root is "<< *roots.begin() << "\n"; }else{ if ( num_roots == 0){ std::cout << "no root node found\n"; } else { std::string str = " multiple roots - {"; for ( auto i = roots.begin(), begin = i,end = roots.end(); i != end; ++i){ if ( i != begin){ str += ", "; } str += i->to_c_str(); } str += "}"; std::cout << str <<'\n'; } } if ( has_cycles(g)){ auto nodes = g.get_node_set(); for ( auto i = nodes.begin(),ei = nodes.end(); i!= ei; ++i){ quan::cycle_viewer<node> g1(g,*i); if( ! g1.g_out.get_node_set().empty()){ std::cout << "Have cycles\n "; quan::create_dot_file("cycles.txt" ,g1.g_out, i->to_c_str()); system("dot -Tpng -o cycles.png cycles.txt"); break; } } }else { std::cout << "no cycles\n"; // make empty dot file graph dummy; quan::create_dot_file("cycles.txt" ,dummy, "dummy"); system("dot -Tpng -o cycles.png cycles.txt"); } }
int main (int argc, char *argv[]) { const char *options = "VHaslpmfe:v:hin:o:"; char *endptr; int opt; int votes = 0; int ret = 0; uint32_t nodeid = 0; uint32_t nodeid_set = 0; nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL; name_format_t address_format = ADDRESS_FORMAT_NAME; command_t command_opt = CMD_SHOWSTATUS; sorttype_t sort_opt = SORT_ADDR; char sortchar; long int l; if (init_all()) { close_all(); exit(1); } while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 'f': if (using_votequorum() > 0) { command_opt = CMD_UNREGISTER_QDEVICE; } else { fprintf(stderr, "You cannot unregister quorum device, corosync is not using votequorum\n"); exit(2); } break; case 's': command_opt = CMD_SHOWSTATUS; break; case 'a': g_show_all_addrs = 1; break; case 'm': command_opt = CMD_MONITOR; break; case 'i': address_format = ADDRESS_FORMAT_IP; break; case 'H': nodeid_format = NODEID_FORMAT_HEX; break; case 'l': command_opt = CMD_SHOWNODES; break; case 'p': machine_parsable = 1; break; case 'e': if (using_votequorum() > 0) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes <= 0) { fprintf(stderr, "New expected votes value was not valid, try a positive number\n"); } else { command_opt = CMD_SETEXPECTED; } } else { fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n"); exit(2); } break; case 'n': l = strtol(optarg, &endptr, 0); if ((l == 0 && endptr == optarg) || l < 0) { fprintf(stderr, "The nodeid was not valid, try a positive number\n"); exit(2); } nodeid = l; nodeid_set = 1; break; case 'v': if (using_votequorum() > 0) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes < 0) { fprintf(stderr, "New votes value was not valid, try a positive number or zero\n"); exit(2); } else { command_opt = CMD_SETVOTES; } } else { fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n"); exit(2); } break; case 'o': sortchar = optarg[0]; switch (sortchar) { case 'a': sort_opt = SORT_ADDR; break; case 'i': sort_opt = SORT_NODEID; break; case 'n': sort_opt = SORT_NODENAME; break; default: fprintf(stderr, "Invalid ordering option. valid orders are a(address), i(node ID) or n(name)\n"); exit(2); break; } break; case 'V': printf("corosync-quorumtool version: %s\n", VERSION); exit(0); case ':': case 'h': case '?': default: command_opt = CMD_UNKNOWN; break; } } switch (command_opt) { case CMD_UNKNOWN: show_usage(argv[0]); ret = -1; break; case CMD_SHOWNODES: ret = show_nodes(nodeid_format, address_format, sort_opt); break; case CMD_SHOWSTATUS: ret = show_status(nodeid_format, address_format, sort_opt); break; case CMD_SETVOTES: if (!nodeid_set) { nodeid = our_nodeid; } ret = set_votes(nodeid, votes); break; case CMD_SETEXPECTED: ret = set_expected(votes); break; case CMD_MONITOR: ret = monitor_status(nodeid_format, address_format, sort_opt); break; case CMD_UNREGISTER_QDEVICE: ret = unregister_qdevice(); break; } close_all(); return (ret); }
int main(int argc, char **argv) { dbc_t *dbc; char *filename = NULL; /* default: stdin */ int c; #if 0 extern int yydebug; yydebug = 1; #endif verbose_flag = 0; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"verbose", no_argument, &verbose_flag, 1}, {"brief", no_argument, &verbose_flag, 0}, /* These options don't set a flag. We distinguish them by their indices. */ {"dbc", required_argument, 0, 'd'}, {"networks",no_argument, &networks_flag, 'N'}, {"nodes" ,no_argument, &nodes_flag, 'n'}, {"envvars" ,no_argument, &envvars_flag, 'e'}, {"messages",no_argument, &messages_flag, 'm'}, {"signals" ,no_argument, &signals_flag, 's'}, {"valtables" ,no_argument, &valtables_flag, 't'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "d:Nnemst", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 'd': filename = optarg; break; case 'N': networks_flag = 1; break; case 'n': nodes_flag = 1; break; case 'e': envvars_flag = 1; break; case 'm': messages_flag = 1; break; case 's': signals_flag = 1; break; case 't': valtables_flag = 1; break; case 'h': help(); exit(0); break; case '?': /* getopt_long already printed an error message. */ fprintf(stderr, "Typ `dbcls --help' for more information\n"); abort(); break; default: abort(); break; } } if(NULL != (dbc = dbc_read_file(filename))) { if(networks_flag) show_network(dbc); if(messages_flag) show_message_list(dbc->message_list); if(signals_flag) show_signals(dbc); if(nodes_flag) show_nodes(dbc); if(envvars_flag) show_envvars(dbc->envvar_list); if(valtables_flag) show_valtable_list(dbc->valtable_list); dbc_free(dbc); } return 0; }
int main (gint argc, gchar *argv[]) { GLogLevelFlags fatal_mask; gboolean gen_froots = 0; gboolean gen_tree = 0; gint i; gchar *iindent = ""; f_out = stdout; fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; g_log_set_always_fatal (fatal_mask); root = G_TYPE_OBJECT; for (i = 1; i < argc; i++) { if (strcmp ("-s", argv[i]) == 0) { i++; if (i < argc) spacing = atoi (argv[i]); } else if (strcmp ("-i", argv[i]) == 0) { i++; if (i < argc) { char *p; guint n; p = argv[i]; while (*p) p++; n = p - argv[i]; indent_inc = g_new (gchar, n * strlen (O_SPACE) + 1); *indent_inc = 0; while (n) { n--; strcpy (indent_inc, O_SPACE); } } } else if (strcmp ("-b", argv[i]) == 0) { i++; if (i < argc) iindent = argv[i]; } else if (strcmp ("-r", argv[i]) == 0) { i++; if (i < argc) root = g_type_from_name (argv[i]); } else if (strcmp ("-n", argv[i]) == 0) { recursion = FALSE; } else if (strcmp ("froots", argv[i]) == 0) { gen_froots = 1; } else if (strcmp ("tree", argv[i]) == 0) { gen_tree = 1; } else if (strcmp ("-h", argv[i]) == 0) { return help (NULL); } else if (strcmp ("--help", argv[i]) == 0) { return help (NULL); } else return help (argv[i]); } if (!gen_froots && !gen_tree) return help (argv[i-1]); if (!indent_inc) { indent_inc = g_new (gchar, strlen (O_SPACE) + 1); *indent_inc = 0; strcpy (indent_inc, O_SPACE); } if (gen_tree) show_nodes (root, 0, iindent); if (gen_froots) { root = ~0; for (i = 0; i <= G_TYPE_FUNDAMENTAL_MAX; i += G_TYPE_MAKE_FUNDAMENTAL (1)) { const gchar *name = g_type_name (i); if (name) show_nodes (i, 0, iindent); } } return 0; }
int main (int argc, char *argv[]) { const char *options = "VHsle:v:hin:d:"; char *endptr; int opt; int votes = 0; int ret = 0; uint32_t nodeid = VOTEQUORUM_NODEID_US; nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL; name_format_t address_format = ADDRESS_FORMAT_NAME; command_t command_opt = CMD_UNKNOWN; if (argc == 1) { show_usage (argv[0]); exit(0); } while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 's': command_opt = CMD_SHOWSTATUS; break; case 'i': address_format = ADDRESS_FORMAT_IP; break; case 'h': nodeid_format = NODEID_FORMAT_HEX; break; case 'l': command_opt = CMD_SHOWNODES; break; case 'e': if (using_votequorum()) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes <= 0) { fprintf(stderr, "New expected votes value was not valid, try a positive number\n"); } else { command_opt = CMD_SETEXPECTED; } } else { fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n"); exit(2); } break; case 'n': nodeid = strtol(optarg, &endptr, 0); if ((nodeid == 0 && endptr == optarg) || nodeid <= 0) { fprintf(stderr, "The nodeid was not valid, try a positive number\n"); } break; case 'v': if (using_votequorum()) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes < 0) { fprintf(stderr, "New votes value was not valid, try a positive number or zero\n"); } else { command_opt = CMD_SETVOTES; } } else { fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n"); exit(2); } break; case 'H': case '?': default: break; } } switch (command_opt) { case CMD_UNKNOWN: show_usage(argv[0]); break; case CMD_SHOWNODES: ret = show_nodes(nodeid_format, address_format); break; case CMD_SHOWSTATUS: show_status(); break; case CMD_SETVOTES: ret = set_votes(nodeid, votes); break; case CMD_SETEXPECTED: ret = set_expected(votes); break; } return (ret); }
/*Cargar desde un archivo*/ void cargarFile(GtkWidget *widget, gpointer user_data){ int cantidad; cantidad = tamanio; int** matriz; filename=gtk_file_chooser_get_filename (fileChooser); printf("leer floyd \n"); printf("nombre archivo %s\n", filename); FILE *fp; fp = fopen(filename, "r"); char ch; char* palabra; int largo = 0; palabra = (char*)calloc(1, sizeof(char)); int i,j; int numero; int max; int nodo1; int nodo2; while((ch=fgetc(fp)) != '\n'){ largo++; palabra = (char*) realloc(palabra,largo * sizeof(char)); palabra[largo-1] = ch; } largo = 0; numero = atoi(palabra); printf("tamanio %d\n",numero); int cuantas=0; gtk_spin_button_set_value(spinNodos,numero); show_nodes(); int f=0; while((ch=fgetc(fp)) != '\n'){ if (ch == ',') { printf("nom:%s\n", palabra); gtk_entry_set_text(nombres[f],palabra); largo =0; f++; } else{ largo++; palabra = (char*) realloc(palabra,largo * sizeof(char)); palabra[largo-1] = ch; } } printf("nom:%s\n", palabra); gtk_entry_set_text(nombres[f],palabra); largo = 0; generate_table(); for (i = 0; i < numero; ++i) { for (j = 0; j < numero; ++j) { gtk_entry_set_text(distancias[i][j],g_strdup_printf("%d",9999)); } } while(!feof(fp)) { ch = fgetc(fp); if(ch == '\n' ){ printf("%d",atoi(palabra)); printf("\n"); // matriz[nodo1-1][nodo2-1] =atoi(palabra); gtk_entry_set_text(distancias[nodo2-1][nodo1-1],g_strdup_printf("%d",atoi(palabra))); largo=0; palabra = (char*) realloc(palabra,1); } else if (ch == '-'){ fseek( fp, ftell(fp)-2, SEEK_SET ); nodo1 = fgetc(fp)- '0'; printf("nodo1:%d - ",nodo1); fgetc(fp); largo=0; palabra = (char*) realloc(palabra,0); } else if (ch == '='){ fseek( fp, ftell(fp)-2, SEEK_SET ); nodo2 = fgetc(fp)- '0'; printf("nodo2:%d - ",nodo2); fgetc(fp); largo=0; palabra = (char*) realloc(palabra,0); } else{ largo++; palabra = (char*) realloc(palabra,largo * sizeof(char)); palabra[largo-1] = ch; } } fclose(fp); printf("\n"); }
static int rt_cmd(CIRCUIT *circuit) { CIRCUIT *c; USER *user, *su; char *f1, *f2; user = circuit->u.user; switch(tolower(circuit->buf[1])) { case 'b' : return FALSE; case 'e' : user->flags flipbit u_echo; return true; case 'h' : tputs("/U - Show Users.\n/N - Enter your Name.\n/Q - Enter your QTH.\n/T - Show Topics.\n"); tputs("/T Name - Join Topic or Create new Topic.\n/P - Show Ports and Links.\n"); tputs("/E - Toggle Echo.\n/S CALL Text - Send Text to that station only.\n"); tputs("/F - Force all links to be made.\n/K - Show Known nodes.\n"); tputs("/B - Leave RoundTable and return to node.\n"); return true; case 'k' : show_nodes(); return true; case 'n' : strnew(&user->name, circuit->buf + 3); saydone(); upduser(user); user_tell(user, id_user); return true; case 'p' : show_circuits(); return true; case 'q' : strnew(&user->qth, circuit->buf + 3); saydone(); upduser(user); user_tell(user, id_user); return true; case 's' : strcat(circuit->buf, "\n"); f1 = strlop(circuit->buf, ' '); // To. if (!f1) break; f2 = strlop(f1, ' '); // Text to send. if (!f2) break; strupr(f1); su = user_find(f1); if (!su) { tputs("*** That user is not logged in.\n"); return true; } // Send to the desired user only. if (su->circuit->flags & p_user) text_tellu(user, f2, f1, o_one); else text_xmit(user, su, f2); return true; case 't' : f1 = strlop(circuit->buf, ' '); if (f1) { topic_chg(user, f1); // Tell all link circuits about the change of topic. for (c = circuit_hd; c; c = c->next) if (c->flags & p_linked) topic_xmit(user, c); } else show_topics(); return true; case 'u' : show_users(); return true; default : break; } saywhat(); return true; }