int main (int argc, char **argv) { int ret = EXIT_SUCCESS; Display *disp; Window root; char *newName; long pos = -1; int insert = 0; char *oldList; size_t oldLen; char *newList; size_t newLen; consume_arguments(argc, argv, &pos, &insert, &newName); disp = XOpenDisplay(NULL); if (disp == NULL) { fputs("Can't open display.\n", stderr); exit(EXIT_FAILURE); } root = DefaultRootWindow(disp); if (pos < 0) { pos = get_long_property(disp, root, "_NET_CURRENT_DESKTOP"); if (pos < 0) { fprintf(stderr, "Can't get _NET_CURRENT_DESKTOP.\n"); exit(EXIT_FAILURE); } } oldList = get_string_property(disp, root, "_NET_DESKTOP_NAMES", &oldLen); if (oldList == NULL) { fprintf(stderr, "Can't get _NET_DESKTOP_NAMES.\n"); exit(EXIT_FAILURE); } newList = add_name_to_list(oldList, oldLen, newName, pos, insert, &newLen); if (newList == NULL) { ret = EXIT_FAILURE; goto F1; } set_string_property(disp, root, "_NET_DESKTOP_NAMES", newList, newLen); XCloseDisplay(disp); free(newList); F1: free(oldList); exit(ret); }
void Sheet::get_col (const int source_col, char**& col, int &n_cols) { const int row_start = 2; n_cols= 0; for (int i = row_start; i <= n_rows; i++) add_name_to_list (data[i][source_col], &col, &n_cols); }
static int set_nameservice_server(const char *value, void *data, set_plugin_parameter_addon addon) { union olsr_ip_addr ip; struct name_entry **v = data; if (0 == strlen(value)) { *v = add_name_to_list(*v, "", addon.ui, NULL); OLSR_PRINTF(1, "%s got %s (main address)\n", "Got", value); return 0; } else if (0 < inet_pton(olsr_cnf->ip_version, value, &ip)) { *v = add_name_to_list(*v, "", addon.ui, &ip); OLSR_PRINTF(1, "%s got %s\n", "Got", value); return 0; } else { OLSR_PRINTF(0, "Illegal IP address \"%s\"", value); } return 1; }
static int set_nameservice_name(const char *value, void *data, set_plugin_parameter_addon addon) { struct name_entry **v = data; if (0 < strlen(value)) { *v = add_name_to_list(*v, value, addon.ui, NULL); OLSR_PRINTF(1, "%s got %s (main address)\n", "Got", value); return 0; } else { OLSR_PRINTF(0, "Illegal name \"%s\"", value); } return 1; }
static int set_nameservice_host(const char *value, void *data, set_plugin_parameter_addon addon) { union olsr_ip_addr ip; struct name_entry **v = data; if (0 < inet_pton(olsr_cnf->ip_version, addon.pc, &ip)) { // the IP is validated later *v = add_name_to_list(*v, value, NAME_HOST, &ip); OLSR_PRINTF(1, "%s: %s got %s\n", "Got", addon.pc, value); return 0; } else { OLSR_PRINTF(0, "%s: Illegal IP address \"%s\"", addon.pc, value); } return 1; }
void Sheet::get_col (const int source_col, char**& col, bool*& is_set) { const int row_start = 2; int col_len = 0; for (int i = row_start; i <= n_rows; i++) { char* txt; strcpy (&txt, data[i][source_col]); replace_string_in_string (txt, "\"", ""); replace_string_in_string (txt, ",", ""); bool set = *txt; add_name_to_list (data[i][source_col], &col, &col_len); --col_len; add_to_list (set, &is_set, &col_len); } }
void Template::read (const char* spec) { FILE* f = fopen (spec, "r"); if (!f) { printf ("error - cannot open '%s'\n", spec); exit (1); } n_lines = 0; for (;;) { char* line; fgets_no_control_m (&line, f); if (feof(f)) break; add_name_to_list (line, &lines, &n_lines); free (line); } fclose (f); }