Exemple #1
0
static struct room *room_new(void)
{
	struct room *r;

	r = calloc(sizeof(struct room), 1);

	r->exits = table_new();
	r->furniture = table_new();
	r->chars = table_new();
	r->objects = table_new();

	return r;
}
Exemple #2
0
menu* menu_init(int x, int y) {
	menu *pMenu = (menu*) malloc(sizeof(menu));
	
	pMenu->m_iCursorPos = 0;
	pMenu->m_iX = x;
	pMenu->m_iY = y;
	pMenu->m_iWidth = 0;
	pMenu->m_iHeight = 0;
	pMenu->m_iValueX = 0;
	pMenu->m_aColors = table_new(sizeof(Uint32), 0, 0);
	pMenu->m_aEntries = table_new(sizeof(char*), 0, 0);
	pMenu->m_aValues = table_new(sizeof(char*), 0, 0);
	
	return pMenu;
}
Exemple #3
0
static void os_cmd_tabletest(sourceinfo_t *si, int parc, char *parv[])
{
	table_t *t = table_new("Table \2test\2");
	table_row_t *r = table_row_new(t);

	table_cell_associate(r, "foo", "bar");
	table_cell_associate(r, "F", "-");
	table_cell_associate(r, "baz", "splork");

	r = table_row_new(t);

	table_cell_associate(r, "foo", "1");
	table_cell_associate(r, "F", "+");
	table_cell_associate(r, "baz", "2");

	r = table_row_new(t);

	table_cell_associate(r, "foo", "beagle4");
	table_cell_associate(r, "F", "+");
	table_cell_associate(r, "baz", "boo");

	command_success_table(si, t);

	object_unref(t);
}
Exemple #4
0
void my_engine_settings(GtkWidget * hbox, gboolean active)
{
    GtkWidget * vbox;
    GtkWidget * scroller;
#if GTK_CHECK_VERSION(3, 0, 0)
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
#else
    vbox = gtk_vbox_new(FALSE,2);
#endif
    gtk_box_pack_startC(hbox, vbox, TRUE, TRUE, 0);
    gtk_box_pack_startC(vbox, gtk_label_new(active?"Active Window":"Inactive Window"), FALSE, FALSE, 0);
#if GTK_CHECK_VERSION(3, 2, 0)
    gtk_box_pack_startC(vbox, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 0);
#else
    gtk_box_pack_startC(vbox, gtk_hseparator_new(), FALSE, FALSE, 0);
#endif
    scroller = gtk_scrolled_window_new(NULL,NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_box_pack_startC(vbox, scroller, TRUE, TRUE, 0);

    table_new(3, FALSE, FALSE);

#if GTK_CHECK_VERSION(3, 8, 0)
    gtk_container_add(GTK_CONTAINER(scroller), GTK_WIDGET(get_current_table()));
#else
    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller), GTK_WIDGET(get_current_table()));
#endif

    make_labels(_("Colors"));
    table_append_separator();
    ACAV(_("Outer Frame Blend"), "border", SECT);
	ACAV(_("Title Bar"), "title_bar", SECT);
}
Exemple #5
0
mapper_receiver mapper_receiver_new(mapper_device device, const char *host,
                                    int port, const char *name, int default_scope)
{
    char str[16];
    mapper_receiver r = (mapper_receiver) calloc(1, sizeof(struct _mapper_link));
    sprintf(str, "%d", port);
    r->props.src_addr = lo_address_new(host, str);
    r->props.src_name = strdup(name);
    if (default_scope) {
        r->props.num_scopes = 1;
        r->props.scope_names = (char **) malloc(sizeof(char *));
        r->props.scope_names[0] = strdup(name);
        r->props.scope_hashes = (int *) malloc(sizeof(int));
        r->props.scope_hashes[0] = crc32(0L, (const Bytef *)name, strlen(name));;
    }
    else {
        r->props.num_scopes = 0;
    }
    r->props.extra = table_new();
    r->device = device;
    r->signals = 0;
    r->n_connections = 0;

    if (!r->props.src_addr) {
        mapper_receiver_free(r);
        return 0;
    }
    return r;
}
Exemple #6
0
boolean table_test(void)
#endif
  {
/*
  int           i, j;
*/
  TableStruct	*table;

  printf("Testing my table routines.\n");
  printf("FIXME: Actually add some tests!\n");

  table = table_new();
  table_set_size(table, 200);

/*
vpointer table_remove_index(TableStruct *table, unsigned int id);
vpointer table_get_data(TableStruct *table, unsigned int id);
unsigned int table_add(TableStruct *table, vpointer data);
*/

  table_destroy(table);

#ifdef TABLE_COMPILE_MAIN
  exit(EXIT_SUCCESS);
#else
  return TRUE;
#endif
  }
int main(int argc, char**argv)
{  
    int err;
    sqlite3 *conn;
    char *errmsg;
    
    err = sqlite3_open("test.sl3",&conn);

    Table *t = table_new(TableCsv | TableColumns);
    
    err = sqlite3_exec(conn,"select * from test",
        table_add_row,t,&errmsg);
    
    if (err) {
        printf("err '%s'\n",errmsg);
        return 1;
    }

    table_finish_rows(t);
    
    DUMPA(float,(float*)t->cols[1],"%f");
  
    sqlite3_close(conn);
    unref(t);
    
    DI(obj_kount());
    return 0;
}
Exemple #8
0
static int load_module(void) {
	contracts = table_new(cmpstr, hashmurmur2, NULL, vfree);
	load_config();
	if (msgs_hook(&default_msgs, csi300_exec, NULL) == -1)
		return MODULE_LOAD_FAILURE;
	return register_application(app, csi300_exec, desc, fmt, mod_info->self);
}
Exemple #9
0
mapper_connection mapper_receiver_add_connection(mapper_receiver r,
                                                 mapper_signal sig,
                                                 const char *src_name,
                                                 char src_type,
                                                 int src_length)
{
    /* Currently, fail if lengths don't match.  TODO: In the future,
     * we'll have to examine the expression to see if its input and
     * output lengths are compatible. */
    if (sig->props.length != src_length) {
        char n[1024];
        msig_full_name(sig, n, 1024);
        trace("rejecting connection %s -> %s%s because lengths "
              "don't match (not yet supported)\n",
              n, r->props.src_name, src_name);
        return 0;
    }

    // find signal in signal connection list
    mapper_receiver_signal rs = r->signals;
    while (rs && rs->signal != sig)
        rs = rs->next;

    // if not found, create a new list entry
    if (!rs) {
        rs = (mapper_receiver_signal)
            calloc(1, sizeof(struct _mapper_link_signal));
        rs->signal = sig;
        rs->next = r->signals;
        r->signals = rs;
    }

    mapper_connection c = (mapper_connection)
        calloc(1, sizeof(struct _mapper_connection));

    c->props.src_name = strdup(src_name);
    c->props.src_type = src_type;
    c->props.src_length = src_length;
    c->props.dest_name = strdup(sig->props.name);
    c->props.dest_type = sig->props.type;
    c->props.dest_length = sig->props.length;
    c->props.mode = MO_UNDEFINED;
    c->props.expression = strdup("y=x");
    c->props.clip_min = CT_NONE;
    c->props.clip_max = CT_NONE;
    c->props.muted = 0;
    c->props.extra = table_new();

    int len = strlen(src_name) + 5;
    c->props.query_name = malloc(len);
    snprintf(c->props.query_name, len, "%s%s", src_name, "/got");

    // add new connection to this signal's list
    c->next = rs->connections;
    rs->connections = c;
    c->parent = rs;
    r->n_connections++;

    return c;
}
Exemple #10
0
int main()
{
    /* Create a root directory and point working directory to it */
    Table *table = table_new();
    Inode *root = table_new_inode(table, DIR_T);
    Inode *w_dir = root;

    /* Command interpreter */
    char input[MAX_CMD_LEN]; /* Input buffer */
    
    while (strcmp(input, "quit"))
    {
        printf("> "); /* Prompt */
        gets(input);
        if (!strcmp(input, "new")) {
            printf("Enter filename: ");
            gets(input);
            newfile(table, w_dir, FILE_T, input);
        }
        else if (!strcmp(input, "showall")) {
            table_print_all(table);
        }
        else if (!strcmp(input, "node")) {
            int n = inode_dir_seek(w_dir, "crips");
            printf("%i\n", n);
        }
        else {
            printf("Invalid command.\n");
        }
    }

    /* Clean up */
    table_destroy(table);
    return EXIT_SUCCESS;
}
Exemple #11
0
/*
 *  constructs a default set for configuration variables
 *
 *  conf_preset() cannot be implemented with conf_set() since they differ in handling an omitted
 *  section name. conf_section() cannot affect conf_preset() because the former is not callable
 *  before the latter. Thus, conf_preset() can safely assume that a section name is given properly
 *  whenever necessary. On the other hand, because conf_set() is affected by conf_section(), a
 *  variable name without a section name and a period should be recognized as referring to the
 *  current section, not to the global section.
 *
 *  TODO:
 *    - some adjustment on arguments to table_new() is necessary;
 *    - considering changes to the format of a configuration file as a program to accept it is
 *      upgraded, making it a recoverable error to encounter a non-preset section or variable name
 *      would be useful; this enables an old version of the program to accept a new configuration
 *      file with diagnostics.
 */
int (conf_preset)(const conf_t *tab, int ctrl)
{
    size_t len;
    char *pbuf, *sec, *var;
    const char *hkey;
    table_t *t;
    struct valnode_t *pnode;

    assert(!section);
    assert(tab);

    control = ctrl;
    section = table_new(0, NULL, NULL);
    errcode = CONF_ERR_OK;

    for (; tab->var; tab++) {
        assert(tab->defval);
        assert(tab->type == CONF_TYPE_BOOL || tab->type == CONF_TYPE_INT ||
               tab->type == CONF_TYPE_UINT || tab->type == CONF_TYPE_REAL ||
               tab->type == CONF_TYPE_STR);

        len = strlen(tab->var);
        pbuf = strcpy(MEM_ALLOC(len+1 + strlen(tab->defval)+1), tab->var);
        if (sep(pbuf, &sec, &var) != CONF_ERR_OK) {
            MEM_FREE(pbuf);
            break;    /* sep sets errcode */
        }
        if (!sec)    /* means global section in this case */
            sec = "";    /* lower modifies sec only when necessary */
        hkey = hash_string((control & CONF_OPT_CASE)? sec: lower(sec));
        t = table_get(section, hkey);
        if (!t) {    /* new section */
            t = table_new(0, NULL, NULL);
            table_put(section, hkey, t);
        }
        MEM_NEW(pnode);
        pnode->type = tab->type;
        pnode->freep = pbuf;
        pnode->val = strcpy(pbuf + len+1, tab->defval);
        table_put(t, hash_string((control & CONF_OPT_CASE)? var: lower(var)), pnode);
    }

    preset = 1;

    return errcode;
}
Exemple #12
0
static int load_module(void) {
	int res;

	spots     = table_new(cmpstr, hashmurmur2, kfree, NULL);
	optns     = table_new(cmpstr, hashmurmur2, kfree, vfree);
	expiries  = table_new(cmpstr, hashmurmur2, NULL,  NULL);
	contracts = table_new(cmpstr, hashmurmur2, kfree, vfree);
	load_config();
	if (msgs_init(&impvbaw_msgs, "impvbaw_msgs", mod_info->self) == -1)
		return MODULE_LOAD_FAILURE;
	if (start_msgs(impvbaw_msgs) == -1)
		return MODULE_LOAD_FAILURE;
	if (msgs_hook(impvbaw_msgs, mm_impvbaw_exec, NULL) == -1)
		return MODULE_LOAD_FAILURE;
	if (msgs_hook(&default_msgs, impvbaw_exec, impvbaw_msgs) == -1)
		return MODULE_LOAD_FAILURE;
	res  = register_application(app, impvbaw_exec, desc, fmt, mod_info->self);
	res |= register_application(app2, mm_impvbaw_exec, desc2, fmt2, mod_info->self);
	return res;
}
Exemple #13
0
int random_get_state_wrapper(void)
  {
  int	stateid;	/* State handle. */

  THREAD_LOCK(state_table_lock);
  if (!state_table) state_table=table_new();

  stateid = table_add(state_table, (vpointer) current_state);	/* FIXME: Need to copy state. */
  THREAD_UNLOCK(state_table_lock);

  return stateid;
  }
Exemple #14
0
int timer_new_slang(void)
  {
  chrono_t	*t=s_malloc(sizeof(chrono_t));
  int		t_handle;

  THREAD_LOCK(chrono_table_lock);
  if (chrono_table==NULL) chrono_table=table_new();

  t_handle = table_add(chrono_table, (vpointer) t);
  THREAD_UNLOCK(chrono_table_lock);

  return (int) t_handle;
  }
Exemple #15
0
int main() {
	struct table *shapes;
	int loops, planecount, pointcount, x, y, z;

	/* Get number of bulks to process. */
	scanf("%d", &loops);
	while(loops--) {

		/* allocate the shapes table and create the
		 * initial shape. */
		shapes = table_new(shape_comparator);
		struct shape *newshape = shape_alloc();
		table_add(shapes, newshape);

		/* Get the plane count. */
		scanf("%d", &planecount);
		while(planecount--) {

			/* Create a new plane and add it to the plane table inside
			 * the shape. */
			struct plane *newplane = plane_alloc();
			table_add(newshape->planes, newplane);

			/* Get the point count. */
			scanf("%d", &pointcount);
			while(pointcount--) {

				/* Add point to the shape. */
				scanf("%d %d %d", &x, &y, &z);
				struct point *newpoint = point_alloc(x, y, z);
				if (!table_add(newshape->points, newpoint)) {
					int loc;
					table_find(newshape->points, newpoint, &loc);
					free(newpoint);
					newpoint = table_get(newshape->points, loc);
				}

				/* Add mapping between plane and point. */
				table_add(newshape->ppmaps, ppmap_alloc(newplane, newpoint));
			}

			/* Add the plane to the planes table inside shape. */
			table_add(newshape->planes, newplane);
		}
		resolve_planes(shapes);
		resolve_shapes(shapes);
		coallece_planes(shapes);
	}
}
Exemple #16
0
static int load_module(void) {
	int res;

	spots = table_new(cmpstr, hashmurmur2, kfree, vfree);
	load_config();
	if (msgs_init(&vxo_msgs, "vxo_msgs", mod_info->self) == -1)
		return MODULE_LOAD_FAILURE;
	if (start_msgs(vxo_msgs) == -1)
		return MODULE_LOAD_FAILURE;
	if ((res = msgs_hook_name(inmsg, vxo_exec, vxo_msgs)) < 0) {
		if (res == -2)
			xcb_log(XCB_LOG_WARNING, "Queue '%s' not found", inmsg);
		return MODULE_LOAD_FAILURE;
	}
	return register_application(app, vxo_exec, desc, fmt, mod_info->self);
}
Exemple #17
0
// TODO: optionnal arguments fieldType and subDomain in query string
static command_status_t record_list(COMMAND_ARGS)
{
    domain_t *d;
    Iterator it;
    command_status_t ret;
    domain_record_argument_t *args;

    USED(mainopts);
    args = (domain_record_argument_t *) arg;
    assert(NULL != args->domain);
    if (COMMAND_SUCCESS == (ret = get_domain_records(args->domain, &d, args->nocache, error))) {
        // display
        table_t *t;

        t = table_new(
#ifdef PRINT_OVH_ID
            5, _("id"), TABLE_TYPE_INT,
#else
            4,
#endif /* PRINT_OVH_ID */
            _("subdomain"), TABLE_TYPE_STRING,
            _("type"), TABLE_TYPE_ENUM, domain_record_types,
            _("TTL"), TABLE_TYPE_INT,
            _("target"), TABLE_TYPE_STRING
        );
        hashtable_to_iterator(&it, d->records);
        for (iterator_first(&it); iterator_is_valid(&it); iterator_next(&it)) {
            record_t *r;

            r = iterator_current(&it, NULL);
            if (0 == args->type || r->type == args->type) {
                table_store(t,
#ifdef PRINT_OVH_ID
                    r->id,
#endif /* PRINT_OVH_ID */
                    r->name, r->type, r->ttl, r->target
                );
            }
        }
        iterator_close(&it);
        table_display(t, TABLE_FLAG_NONE);
        table_destroy(t);
    }

    return ret;
}
Exemple #18
0
/* FIXME */
void qc_command(client c) {
	char buf[64];
	dstr rid;
	struct crss *crss;

	snprintf(buf, sizeof buf, "%p,", c);
	rid = dstr_new(buf);
	rid = dstr_cat(rid, c->argv[1]);
	if (rids == NULL)
		rids = table_new(cmpstr, hashmurmur2, kfree, NULL);
	table_lock(rids);
	if ((crss = table_get_value(rids, rid))) {
		crss->cancel = 1;
		xcb_log(XCB_LOG_DEBUG, "Query with rid '%s' got cancelled", c->argv[1]);
	}
	table_unlock(rids);
	add_reply_string(c, "\r\n", 2);
	dstr_free(rid);
}
Exemple #19
0
void ws(char *name, FILE *fp) 
{	
	table_t table ;
	char buf[128];
	char *word;
	int *count;
	void **ar;
	int i;

	table = NULL;
	word = NULL;
	ar = NULL;
	memset(buf, 0, sizeof(buf));
	table = table_new(4096, cmpstring, hashcode);
	
	while(getword(fp, buf, sizeof(buf))) {
		word = (char *) mem_calloc(1, strlen(buf) + 1);
		assert(word);
		strcpy(word, buf);		
		
		count = table_get(table, word);
		if(count) {
			(*count)++;
		}else {
			count = (int *) mem_calloc(1, sizeof(*count));
			assert(count);
			*count = 1;
			table_put(table, word, count);	
		}
	}/*while*/
	
	if(name)
		printf("%s:\n",name);
        printf("table has keys:%d\n", table_length(table));	
	ar = table_to_array(table, NULL);
	qsort(ar, table_length(table), 2 * sizeof(*ar), cmp);
	for(i = 0; ar[i]; i += 2) {
		printf("%d\t%s\n", *(int *)ar[i+1], (char *)ar[i]);
		
	}


}
Exemple #20
0
static int
dict_open(lua_State *L) {
    luaL_checktype(L, 1, LUA_TTABLE);

    Table *dict = table_new();
    size_t len = lua_rawlen(L,1);
    size_t i;
    for(i=1;i<=len;i++) {
        lua_rawgeti(L, 1, i);
        if(!_dict_insert(L, dict)) {
            _dict_close(dict);
            return luaL_error(L, "illegal parameters in table index %d", i);
        }
        lua_pop(L, 1);
    }

    g_dict = dict;
    return 0;
}
Exemple #21
0
void wf(const char *name, FILE *fp) 
{
    table_t table = table_new(0, NULL, NULL);
    char buf[BUFSIZ];

    while (getword(fp, buf, sizeof(buf), first, rest)) {
        const char *word;
        int i, *count;
        for (i=0; buf[i] != '\0'; i++)
            buf[i] = tolower(buf[i]);
        word = atom_string(buf);
        count = table_get(table, word);
        if (count) {
            (*count) ++;
        } else {
            count = (int *)zalloc(sizeof (*count));
            *count = 1;
            table_put(table, word, count);
        }
    }

    if (name) {
        printf("%s:\n", name);
    }
    /* print the words */
    int i;
    void **array = table_to_array(table, NULL);
    qsort(array, table_length(table), 2*sizeof(*array), cmp);
    for (i = 0; array[i]; i+=2) {
        printf("%d\t%s\n", *(int *)array[i+1], (char *)array[i]);
    }
    zfree(array);

    /* destroy the table */
    table_free(&table, vfree);
}
Exemple #22
0
static int
_dict_insert(lua_State *L, Table* dict) {
    if(!lua_istable(L, -1)) {
        return 0;
    }

    size_t len = lua_rawlen(L, -1);
    size_t i;
    uint32_t rune;
    TableNode *node = NULL;
    for(i=1; i<=len; i++) {
        lua_rawgeti(L, -1, i);
        int isnum;
		rune = lua_tounsignedx(L, -1, &isnum);
        lua_pop(L, 1);

        if(!isnum) {
            return 0;
        }

        Table *tmp;
        if(node == NULL) {
            tmp = dict;
        } else {
            if(node->value == NULL) {
                node->value = table_new();
            } 
            tmp = (Table*)node->value;
        }
        node = table_insert(tmp, rune);
    }
    if(node) {
        node->flag = 'o';
    }
    return 1;
}
Exemple #23
0
static int list_images(int argc, char *argv[], void *userdata) {
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
        _cleanup_(table_unrefp) Table *table = NULL;
        int r;

        r = acquire_bus(&bus);
        if (r < 0)
                return r;

        r = sd_bus_call_method(
                        bus,
                        "org.freedesktop.portable1",
                        "/org/freedesktop/portable1",
                        "org.freedesktop.portable1.Manager",
                        "ListImages",
                        &error,
                        &reply,
                        NULL);
        if (r < 0)
                return log_error_errno(r, "Failed to list images: %s", bus_error_message(&error, r));

        table = table_new("name", "type", "ro", "crtime", "mtime", "usage", "state");
        if (!table)
                return log_oom();

        r = sd_bus_message_enter_container(reply, 'a', "(ssbtttso)");
        if (r < 0)
                return bus_log_parse_error(r);

        for (;;) {
                const char *name, *type, *state;
                uint64_t crtime, mtime, usage;
                TableCell *cell;
                bool ro_bool;
                int ro_int;

                r = sd_bus_message_read(reply, "(ssbtttso)", &name, &type, &ro_int, &crtime, &mtime, &usage, &state, NULL);
                if (r < 0)
                        return bus_log_parse_error(r);
                if (r == 0)
                        break;

                r = table_add_many(table,
                                   TABLE_STRING, name,
                                   TABLE_STRING, type);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                ro_bool = ro_int;
                r = table_add_cell(table, &cell, TABLE_BOOLEAN, &ro_bool);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                if (ro_bool) {
                        r = table_set_color(table, cell, ansi_highlight_red());
                        if (r < 0)
                                return log_error_errno(r, "Failed to set table cell color: %m");
                }

                r = table_add_many(table,
                                   TABLE_TIMESTAMP, crtime,
                                   TABLE_TIMESTAMP, mtime,
                                   TABLE_SIZE, usage);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                r = table_add_cell(table, &cell, TABLE_STRING, state);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                if (!streq(state, "detached")) {
                        r = table_set_color(table, cell, ansi_highlight_green());
                        if (r < 0)
                                return log_error_errno(r, "Failed to set table cell color: %m");
                }
        }

        r = sd_bus_message_exit_container(reply);
        if (r < 0)
                return bus_log_parse_error(r);

        if (table_get_rows(table) > 1) {
                r = table_set_sort(table, (size_t) 0, (size_t) -1);
                if (r < 0)
                        return log_error_errno(r, "Failed to sort table: %m");

                table_set_header(table, arg_legend);

                r = table_print(table, NULL);
                if (r < 0)
                        return log_error_errno(r, "Failed to show table: %m");
        }

        if (arg_legend) {
                if (table_get_rows(table) > 1)
                        printf("\n%zu images listed.\n", table_get_rows(table) - 1);
                else
                        printf("No images.\n");
        }

        return 0;
}
Exemple #24
0
int main (int argc, char **argv)
{
  Table *tab;
  int ii, jj;
  Alignment *sol;
  int nsol = 1;
  int done;
  
  if (argc < 3)
    errx (EXIT_FAILURE, "please provide two strings on the command line, for example 'vbr yog'");
  tab = table_new (argv[1], argv[2]);
  
  printf ("input source:      %s\n"
	  "input destination: %s\n",
	  argv[1], argv[2]);
  
  /***************************************************
   * propagate
   */
  
  for (ii = 1; ii <= tab->srclen; ++ii) {
    for (jj = 1; jj <= tab->dstlen; ++jj) {
      int best;
      char * act;
      
      tab->state[ii][jj].v_ins = tab->state[ii][jj-1].v_best + GAP_COST;
      best = tab->state[ii][jj].v_ins;
      
      tab->state[ii][jj].v_del = tab->state[ii-1][jj].v_best + GAP_COST;
      if (best < tab->state[ii][jj].v_del)
	best = tab->state[ii][jj].v_del;
      
      tab->state[ii][jj].v_match
	= tab->state[ii-1][jj-1].v_best
	+ match_cost (tab->src[ii-1], /* use ii-1 because of the extra "gap" at the beginning */
		      tab->dst[jj-1]);
      if (best < tab->state[ii][jj].v_match)
	best = tab->state[ii][jj].v_match;
      
      act = tab->state[ii][jj].act;
      if (best == tab->state[ii][jj].v_match)
	*(act++) = 'm';
      if (best == tab->state[ii][jj].v_del)
	*(act++) = 'd';
      if (best == tab->state[ii][jj].v_ins)
	*(act++) = 'i';
      *(act++) = '\0';
      
      tab->state[ii][jj].v_best = best;
    }
  }
  
  /***************************************************
   * print
   */
  
  printf ("\n    _");
  for (ii = 1; ii <= tab->dstlen; ++ii)
    printf ("    %c", tab->dst[ii-1]);
  printf ("\n\n");
  for (ii = 0; ii <= tab->srclen; ++ii) {
    printf ("%c", ii == 0 ? '_' : tab->src[ii-1]);
    for (jj = 0; jj <= tab->dstlen; ++jj)
      printf (" % 4d", tab->state[ii][jj].v_best);
    printf ("\n ");
    for (jj = 0; jj <= tab->dstlen; ++jj)
      printf (" %4s", tab->state[ii][jj].act);
    printf ("\n\n");
  }
  
  /***************************************************
   * trace back
   */
  
  sol = alignment_new (tab);
  
  for (done = 0; done != 1; /**/) {
    int ncheck;
    done = 1;
    
    /*
      check for branches, but may end up appending duplicates which
      should not be checked this time around... so remember the old
      size in ncheck
    */
    ncheck = nsol;
    for (ii = 0; ii < ncheck; ++ii) {
      
      /*
	skip finished alignments
      */
      if (sol[ii].isrc == 0 && sol[ii].idst == 0)
	continue;
      
      /*
	check whether we have a 2nd and a 3rd action
      */
      for (jj = 1; jj <= 2; ++jj) {
	
	/*
	  no more actions when we hit the '\0' of the action string
	*/
	if (tab->state[sol[ii].isrc][sol[ii].idst].act[jj] == '\0')
	  break;
	
	/*
	  append a duplicate of sol[ii] that uses jj as iact
	*/
	if (NULL == (sol = realloc (sol, (nsol + 1) * sizeof *sol)))
	  err (EXIT_FAILURE, "realloc sol");
	alignment_dup (sol + nsol, sol + ii, jj);
	
	++nsol;
      }
    }
    
    /*
      update all alignment branches
    */
    for (ii = 0; ii < nsol; ++ii) {
      char act;
      
      /*
	skip finished alignments
      */
      if (sol[ii].isrc == 0 && sol[ii].idst == 0)
	continue;
      
      /*
	perform next action in the backtrace
      */
      done = 0;
      act = tab->state[sol[ii].isrc][sol[ii].idst].act[sol[ii].iact];
      if ('m' == act) {
	*(--sol[ii].src) = tab->src[--sol[ii].isrc];
	*(--sol[ii].dst) = tab->dst[--sol[ii].idst];
      }
      else if ('i' == act) {
	*(--sol[ii].src) = '_';
	*(--sol[ii].dst) = tab->dst[--sol[ii].idst];
      }
      else if ('d' == act) {
	*(--sol[ii].src) = tab->src[--sol[ii].isrc];
	*(--sol[ii].dst) = '_';
      }
      else
	errx (EXIT_FAILURE, "BUG: action %d  solution %d  isrc %d  idst %d  iact %d",
	      (int) act, ii, sol[ii].isrc, sol[ii].idst, sol[ii].iact);
      
      /*
	reset iact to zero (only becomes non-zero in the branch detection)
      */
      sol[ii].iact = 0;
    }
  }
  
  /*
    print all optimal alignments
  */
  printf ("backtrace:\n\n");
  for (ii = 0; ii < nsol; ++ii)
    printf ("output source:      %s\n"
	    "output destination: %s\n\n",
	    sol[ii].src, sol[ii].dst);
  
  /***************************************************
   * clean up after ourselves
   */
  
  for (ii = 0; ii < nsol; ++ii) {
    free (sol[ii].srcbuf);
    free (sol[ii].dstbuf);
  }
  free (sol);
  table_delete (tab);
  
  return 0;
}
int main (int argc, char **argv)
{
  Table *tab;
  int ii, jj;
  
  if (argc < 3)
    errx (EXIT_FAILURE, "please provide two strings on the command line");
  tab = table_new (argv[1], argv[2]);
  
  printf ("input source:      %s\n"
	  "input destination: %s\n",
	  argv[1], argv[2]);
  
  /***************************************************
   * propagate
   */
  
  for (ii = 1; ii <= tab->srclen; ++ii) {
    for (jj = 1; jj <= tab->dstlen; ++jj) {
      int best;
      char * act;
      
      tab->state[ii][jj].v_ins = tab->state[ii][jj-1].v_best + GAP_COST;
      best = tab->state[ii][jj].v_ins;
      
      tab->state[ii][jj].v_del = tab->state[ii-1][jj].v_best + GAP_COST;
      if (best < tab->state[ii][jj].v_del)
	best = tab->state[ii][jj].v_del;
      
      tab->state[ii][jj].v_match
	= tab->state[ii-1][jj-1].v_best
	+ match_cost (tab->src[ii-1], /* use ii-1 because of the extra "gap" at the beginning */
		      tab->dst[jj-1]);
      if (best < tab->state[ii][jj].v_match)
	best = tab->state[ii][jj].v_match;
      
      if (best < 0)
	best = 0;
      
      act = tab->state[ii][jj].act;
      if (best == tab->state[ii][jj].v_match)
	*(act++) = 'm';
      if (best == tab->state[ii][jj].v_del)
	*(act++) = 'd';
      if (best == tab->state[ii][jj].v_ins)
	*(act++) = 'i';
      *(act++) = '\0';
      
      tab->state[ii][jj].v_best = best;
    }
  }
  
  /***************************************************
   * print
   */
  
  printf ("\n    _");
  for (ii = 1; ii <= tab->dstlen; ++ii)
    printf ("    %c", tab->dst[ii-1]);
  printf ("\n\n");
  for (ii = 0; ii <= tab->srclen; ++ii) {
    printf ("%c", ii == 0 ? '_' : tab->src[ii-1]);
    for (jj = 0; jj <= tab->dstlen; ++jj)
      printf (" % 4d", tab->state[ii][jj].v_best);
    printf ("\n ");
    for (jj = 0; jj <= tab->dstlen; ++jj)
      printf (" %4s", tab->state[ii][jj].act);
    printf ("\n\n");
  }
  
  /***************************************************
   * trace back is not so easy with Smith-Waterman, will skip it for
   * now
   */
  
  /***************************************************
   * clean up after ourselves
   */
  
  table_delete (tab);
  
  return 0;
}
Exemple #26
0
void rooms_init(void)
{
	rooms = table_new();
}
Exemple #27
0
/**
 * add FITS table to image structure
 */
FITStable *table_read(IMAGE *img, fitsfile *fp){
	int ncols, i;
	long nrows;
	char extname[FLEN_VALUE];
	#define TRYRET(f, ...) do{TRYFITS(f, fp, __VA_ARGS__); if(fitsstatus) goto ret;}while(0)
	TRYRET(fits_get_num_rows, &nrows);
	TRYRET(fits_get_num_cols, &ncols);
	TRYRET(fits_read_key, TSTRING, "EXTNAME", extname, NULL);
	DBG("Table named %s with %ld rows and %d columns", extname, nrows, ncols);
	FITStable *tbl = table_new(img, extname);
	if(!tbl) return NULL;
	for(i = 1; i <= ncols; ++i){
		int typecode;
		long repeat, width;
		FITSFUN(fits_get_coltype, fp, i, &typecode, &repeat, &width);
		if(fitsstatus){
			WARNX(_("Can't read column %d!"), i);
			continue;
		}
		DBG("typecode=%d, repeat=%ld, width=%ld", typecode, repeat, width);
		table_column col = {.repeat = repeat, .width = width, .coltype = typecode};
		void *array = malloc(width*repeat);
		if(!array) ERRX("malloc");
		int anynul;
		int64_t nullval = 0;
		int j;
		for(j = 0; j < repeat; ++j){
			FITSFUN(fits_read_col, fp, typecode, i, j=1, 1, 1, (void*)nullval, array, &anynul);
			if(fitsstatus){
				WARNX(_("Can't read column %d row %d!"), i, j);
				continue;
			}
		}
		DBG("done");
		continue;
		col.contents = array;
		char keyword[FLEN_KEYWORD];
		int stat = 0;
		fits_make_keyn("TTYPE", i, keyword, &stat);
		if(stat){WARNX("???"); stat = 0;}
		fits_read_key(fp, TSTRING, keyword, col.colname, NULL, &stat);
		if(stat){ sprintf(col.colname, "noname"); stat = 0;}
		fits_make_keyn("TUNIT", i, keyword, &stat);
		if(stat){WARNX("???"); stat = 0;}
		fits_read_key(fp, TSTRING, keyword, col.unit, NULL, &stat);
		if(stat) *col.unit = 0;
		DBG("Column, cont[2]=%d, type=%d, w=%ld, r=%ld, nm=%s, u=%s", ((int*)col.contents)[2], col.coltype,
			col.width, col.repeat, col.colname, col.unit);
		//table_addcolumn(tbl, &col);
		FREE(array);
	}
//	DBG("fits_create_tbl nrows=%zd, ncols=%zd, colnms[0]=%s, formats[0]=%s, "
//			"units[0]=%s, name=%s", tbl->nrows, cols, tbl->colnames[0], tbl->formats[0], tbl->units[0], tbl->tabname);

	#undef TRYRET
ret:
	if(fitsstatus){
		tablefree(&tbl);
		--img->tables->amount;
	}
	return tbl;
}
Exemple #28
0
int main(int argc, char **argv) {
	int ncmds, i;
	const char *tmp;
	pgm_error_t *pgm_err = NULL;

	/* FIXME */
	signal(SIGPIPE, SIG_IGN);
	setup_signal_handlers();
	cmds = table_new(cmpstr, hashmurmur2, NULL, NULL);
	ncmds = sizeof commands / sizeof (struct cmd);
	for (i = 0; i < ncmds; ++i) {
		struct cmd *cmd = commands + i;

		table_insert(cmds, cmd->name, cmd);
	}
	if (argc != 2 && argc != 3)
		usage();
	else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
		usage();
	else if (argc == 3 && strcmp(argv[1], "-f"))
		usage();
	if (argc == 2 && daemon(1, 0) == -1)
		fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
	/* FIXME */
	if (init_logger("/var/log/xcb/xcb-dp2.log", __LOG_DEBUG) == -1) {
		fprintf(stderr, "Error initializing logger\n");
		exit(1);
	}
	cfg_path = argc == 2 ? argv[1] : argv[2];
	if ((cfg = config_load(cfg_path)) == NULL)
		exit(1);
	if ((tmp = variable_retrieve(cfg, "general", "log_level"))) {
		if (!strcasecmp(tmp, "info"))
			set_logger_level(__LOG_INFO);
		else if (!strcasecmp(tmp, "notice"))
			set_logger_level(__LOG_NOTICE);
		else if (!strcasecmp(tmp, "warning"))
			set_logger_level(__LOG_WARNING);
	}
	/* FIXME */
	if (addms)
		times = table_new(cmpstr, hashmurmur2, kfree, vfree);
	clients_to_close = dlist_new(NULL, NULL);
	clients = dlist_new(NULL, NULL);
	monitors = dlist_new(NULL, NULL);
	tp = thrpool_new(16, 512, 200, NULL);
	if (!pgm_init(&pgm_err)) {
		xcb_log(XCB_LOG_ERROR, "Error starting PGM engine: %s", pgm_err->message);
		pgm_error_free(pgm_err);
		goto err;
	}
	/* FIXME */
	if (NEW(pgm_send_cfg) == NULL) {
		xcb_log(XCB_LOG_ERROR, "Error allocating memory for PGM cfg");
		goto err;
	}
	pgm_send_cfg->network = NULL;
	pgm_send_cfg->port    = 0;
	init_pgm_send_cfg(pgm_send_cfg);
	if (pgm_send_cfg->network == NULL) {
		xcb_log(XCB_LOG_ERROR, "PGM network can't be NULL");
		goto err;
	}
	if (pgm_send_cfg->port == 0) {
		xcb_log(XCB_LOG_ERROR, "PGM port can't be zero");
		goto err;
	}
	if ((pgm_sender = pgmsock_create(pgm_send_cfg->network, pgm_send_cfg->port, PGMSOCK_SENDER)) == NULL)
		goto err;
	/* FIXME */
	if ((el = create_event_loop(1024 + 1000)) == NULL) {
		xcb_log(XCB_LOG_ERROR, "Error creating event loop");
		goto err;
	}
	create_time_event(el, 1, server_cron, NULL, NULL);
	if ((tmp = variable_retrieve(cfg, "general", "udp_port")) && strcmp(tmp, "")) {
		if ((udpsock = net_udp_server(NULL, atoi(tmp), neterr, sizeof neterr)) == -1) {
			xcb_log(XCB_LOG_ERROR, "Opening port '%s': %s", tmp, neterr);
			goto err;
		}
		if (net_nonblock(udpsock, neterr, sizeof neterr) == -1) {
			xcb_log(XCB_LOG_ERROR, "Setting port '%s' nonblocking: %s", tmp, neterr);
			goto err;
		}
	}
	if ((tmp = variable_retrieve(cfg, "general", "tcp_port")) && strcmp(tmp, ""))
		if ((tcpsock = net_tcp_server(NULL, atoi(tmp), neterr, sizeof neterr)) == -1) {
			xcb_log(XCB_LOG_ERROR, "Opening port '%s': %s", tmp, neterr);
			goto err;
		}
	if (udpsock > 0 && create_file_event(el, udpsock, EVENT_READABLE, read_quote, NULL) == -1) {
		xcb_log(XCB_LOG_ERROR, "Unrecoverable error creating udpsock '%d' file event", udpsock);
		goto err;
	}
	if (tcpsock > 0 && create_file_event(el, tcpsock, EVENT_READABLE, tcp_accept_handler, NULL) == -1) {
		xcb_log(XCB_LOG_ERROR, "Unrecoverable error creating tcpsock '%d' file event", tcpsock);
		goto err;
	}
	xcb_log(XCB_LOG_NOTICE, "Server dispatcher started");
	start_event_loop(el, ALL_EVENTS);
	delete_event_loop(el);
	pgm_shutdown();
	return 0;

err:
	close_logger();
	exit(1);
}
Exemple #29
0
int main() {
    table_t tab = table_new(1024, cmp, dictGenHashFunction);

    table_put(tab, "append", "cmd_append");
    table_put(tab, "bitcount", "cmd_bitcount");
    table_put(tab, "brpop", "cmd_brpop");
    table_put(tab, "brpoplpush", "cmd_brpoplpush");
    table_put(tab, "decr", "cmd_decr");
    table_put(tab, "decrby", "cmd_decrby");
    table_put(tab, "del", "cmd_del");
    table_put(tab, "exists", "cmd_exists");
    table_put(tab, "get", "cmd_get");
    table_put(tab, "getbit", "cmd_getbit");
    table_put(tab, "getrange", "cmd_getrange");
    table_put(tab, "incr", "cmd_incr");
    table_put(tab, "incrby", "cmd_incrby");
    table_put(tab, "keys", "cmd_keys");
    table_put(tab, "lindex", "cmd_lindex");
    table_put(tab, "linsert", "cmd_linsert");
    table_put(tab, "llen", "cmd_llen");
    table_put(tab, "lpop", "cmd_lpop");
    table_put(tab, "lpush", "cmd_lpush");
    table_put(tab, "lpushx", "cmd_lpushx");
    table_put(tab, "lrange", "cmd_lrange");
    table_put(tab, "lrem", "cmd_lrem");
    table_put(tab, "lset", "cmd_lset");
    table_put(tab, "ltrim", "cmd_ltrim");
    table_put(tab, "mget", "cmd_mget");
    table_put(tab, "msetnx", "cmd_msetnx");
    table_put(tab, "randomkey", "cmd_randomkey");
    table_put(tab, "rename", "cmd_rename");
    table_put(tab, "rpop", "cmd_rpop");
    table_put(tab, "rpoplpush", "cmd_rpoplpush");
    table_put(tab, "rpush", "cmd_rpush");
    table_put(tab, "rpushx", "cmd_rpushx");
    table_put(tab, "set", "cmd_set");
    table_put(tab, "setbit", "cmd_setbit");
    table_put(tab, "setrange", "cmd_setrange");
    table_put(tab, "strlen", "cmd_strlen");
    table_put(tab, "type", "cmd_type");

    table_map(tab, apply);
    printf("len = %d\n", table_length(tab));

    char key[32];
    scanf("%s", key);
    printf("%s\n", (char *)table_get(tab, key));

    printf("remove set\n");
    table_remove(tab, "set");

    table_map(tab, apply);
    printf("len = %d\n", table_length(tab));

    scanf("%s", key);
    printf("%s\n", (char *)table_get(tab, key));

    table_free(&tab);

    return 0;
}
Exemple #30
0
IMAGE *process_pipeline(IMAGE *image){
	if(!image){
		/// "Не задано входное изображение"
		ERRX(_("No input image given"));
	}
	if(!farray || !farray_size){
		/// "Не заданы параметры конвейера"
		WARNX(_("No pipeline parameters given"));
	}
	size_t i;
	Filter **far = farray;
	IMAGE *in = copyFITS(image); // copy original image to leave it unchanged
	IMAGE *processed = NULL;
	for(i = 0; i < farray_size; ++i, ++far){
		Filter *f = *far;
		DBG("Got filter #%d: w=%d, h=%d, sx=%g, sy=%g\n", f->FilterType,
			f->w, f->h, f->sx, f->sy);
		printf("try filter %zd\n", i);
		Itmarray oarg = {NULL, 0};
		processed = f->imfunc(in, f, &oarg);
		/// "Ошибка в обработке конвейера"
		if(!processed) ERRX(_("Error on pipeline processing!"));
		// TODO: what should I do with oarg???
		if(oarg.size){
			size_t i, l = oarg.size;
			//if(verbose_level){
				green("got oarg: \n");
				for(i = 0; i < l; ++i){
					printf("%5zd: %g\n", i, oarg.data[i]);
				}
			//}
			char tabname[80];
			snprintf(tabname, 80, "%s_CONVERSION", f->name);
			FITStable *tab = table_new(processed, tabname);
			if(tab){
				table_column col = {
					.width = sizeof(int32_t),
					.repeat = l,
					.coltype = TINT
				};
				int32_t *levls = MALLOC(int32_t, l);
				for(i = 0; i < l; ++i) levls[i] = (int32_t) i;
				col.contents = levls;
				sprintf(col.colname, "level");
				*col.unit = 0;
				table_addcolumn(tab, &col);
				FREE(levls);
				col.contents = oarg.data;
				col.coltype = TDOUBLE;
				col.width = sizeof(double),
				sprintf(col.colname, "value");
				sprintf(col.unit, "ADU");
				table_addcolumn(tab, &col);
				printf("Create table:\n");
				table_print(tab);
			}
			FREE(oarg.data);
		}
		processed->keylist = in->keylist;
		char changes[FLEN_CARD];
		snprintf(changes, FLEN_CARD, "HISTORY modified by routine %s",  f->name);
		list_add_record(&(processed->keylist), changes);
		//list_print(processed->keylist);
		in->keylist = NULL; // prevent deleting global keylist
		imfree(&in);
		in = processed;
	}
	return processed;
}