Esempio n. 1
0
File: conn.c Progetto: jophxy/samba
/****************************************************************************
  find first available connection slot, starting from a random position.
The randomisation stops problems with the server dieing and clients
thinking the server is still available.
****************************************************************************/
connection_struct *conn_new(void)
{
	connection_struct *conn;
	int i;

	i = bitmap_find(bmap, 1);
	
	if (i == -1) {
		DEBUG(1,("ERROR! Out of connection structures\n"));	       
		return NULL;
	}

	conn = (connection_struct *)malloc(sizeof(*conn));
	if (!conn) return NULL;

	ZERO_STRUCTP(conn);
	conn->cnum = i;

	bitmap_set(bmap, i);

	num_open++;

	string_set(&conn->user,"");
	string_set(&conn->dirpath,"");
	string_set(&conn->connectpath,"");
	string_set(&conn->origpath,"");
	
	DLIST_ADD(Connections, conn);

	return conn;
}
Esempio n. 2
0
File: Synth.cpp Progetto: 5nizza/sdf
void do_grouping(Cudd& cudd,
                 const vector<VecUint>& orders)
{
    L_INF("trying to group vars..");

    if (orders[0].size() < 5)  // window size is too big
        return;

    hmap<uint, vector<SetUint>> groups_by_length;
    groups_by_length[2] = get_group_candidates(orders, 2);
    groups_by_length[3] = get_group_candidates(orders, 3);
    groups_by_length[4] = get_group_candidates(orders, 4);
    groups_by_length[5] = get_group_candidates(orders, 5);

    L_INF("# of group candidates: of size 2 -- " << groups_by_length[2].size());
    for (auto const& g : groups_by_length[2]) {
        L_INF(string_set(g));
    }
    L_INF("# of group candidates: of size 3 -- " << groups_by_length[3].size());
    for (auto const& g : groups_by_length[3]) {
        L_INF(string_set(g));
    }
    L_INF("# of group candidates: of size 4 -- " << groups_by_length[4].size());
    L_INF("# of group candidates: of size 5 -- " << groups_by_length[5].size());

    auto cur_order = orders.back();    // we fix only groups present in the current order (because that is easier to implement)

    for (uint i = 5; i>=2; --i)  // decreasing order!
        if (!groups_by_length[i].empty())
            _do_grouping(cudd, groups_by_length, i, cur_order);
}
Esempio n. 3
0
void port_read_line(port_t *port, string_t *s)
{
    char ch;
    string_set(s, "");
    assert(port_is_input(port));
    if (port_is_input(port))
    {
        for (;;)
        {
            ch = port_read_char(port);
            /* Line break on \r or \n or \r\n and consume the line break character(s) */
            if (ch == '\r')
            {
                ch = port_peek_char(port);
                if (ch == '\n')
                    ch = port_read_char(port);
                break;
            }
            else if (ch == '\n' || ch == EOF)
                break;

            string_nappend(s, &ch, 1);
        }
    }
}
Esempio n. 4
0
int main(int argc,
         char *argv[]) {
  void *a = new(String, "a");
  void *b = new(String, "bbb");
  void *s = new(Set);

  printf("LENGTH A: %lu\n", string_length(a));
  printf("LENGTH B: %lu\n", string_length(b));

  printf("Prev: %s\n", string_get(a));
  string_set(a, "New String");
  printf("New:  %s\n", string_get(a));

  set_add(s, a);
  set_add(s, b);

  printf("CONTAINS A: %u\n", set_contains(s, a));
  printf("CONTAINS B: %u\n", set_contains(s, b));

  printf("DROP B: %p\n", set_drop(s, b));
  printf("DROP B: %p\n", set_drop(s, b));

  printf("ADD B: %p\n", set_add(s, b));

  delete(s);
  delete(a);
  delete(b);

  return 0;
}
Esempio n. 5
0
/* function: transpose_string_array
 *
 * Implementation of transpose(A) for matrix A.
 */
void transpose_string_array(const string_array_t * a, string_array_t* dest)
{
    size_t i;
    size_t j;
    /*  size_t k;*/
    size_t n,m;

    if(a->ndims == 1) {
        copy_string_array_data(*a,dest);
        return;
    }

    assert(a->ndims==2 && dest->ndims==2);

    n = a->dim_size[0];
    m = a->dim_size[1];

    assert(dest->dim_size[0] == m && dest->dim_size[1] == n);

    for(i = 0; i < n; ++i) {
        for(j = 0; j < m; ++j) {
            string_set(dest, (j * n) + i, string_get(*a, (i * m) + j));
        }
    }
}
Esempio n. 6
0
void array_string_array(string_array_t* dest,int n,string_array_t first,...)
{
    int i,j,c;
    va_list ap;

    string_array_t *elts=(string_array_t*)malloc(sizeof(string_array_t) * n);
    assert(elts);
    /* collect all array ptrs to simplify traversal.*/
    va_start(ap,first);
    elts[0] = first;
    for(i = 1; i < n; ++i) {
        elts[i] = va_arg(ap, string_array_t);
    }
    va_end(ap);

    check_base_array_dim_sizes(elts,n);

    for(i = 0, c = 0; i < n; ++i) {
        int m = base_array_nr_of_elements(elts[i]);
        for(j = 0; j < m; ++j) {
            string_set(dest, c, string_get(elts[i], j));
            c++;
        }
    }
    free(elts);
}
Esempio n. 7
0
void matrix_string_scalar(modelica_string a, string_array_t* dest)
{
    dest->ndims = 2;
    dest->dim_size[0] = 1;
    dest->dim_size[1] = 1;
    string_set(dest, 0, a);
}
Esempio n. 8
0
string_t *string_copy(string_t *str)
{
    string_t *res = string_alloc();
    if (str->buf)
        string_set(res, str->buf);
    return res;
}
Esempio n. 9
0
void set_legacy_jre_path(const char *path)
{
	if (!legacy_jre_path)
		legacy_jre_path = string_init(32);
	string_set(legacy_jre_path, is_absolute_path(path) ? path : ij_path(path));
	if (debug)
		error("Using JRE from ImageJ.cfg: %s", legacy_jre_path->buffer);
}
Esempio n. 10
0
/* Zero based index */
void simple_indexed_assign_string_array1(const string_array_t * source,
                                         int i1,
                                         string_array_t* dest)
{
    /* Assert that source has the correct dimension */
    /* Assert that dest has the correct dimension */
    string_set(dest, i1, string_get(*source, i1));
}
Esempio n. 11
0
void put_string_matrix_element(modelica_string value, int r, int c,
                               string_array_t* dest)
{
    /* Assert that dest hast correct dimension */
    /* Assert that r and c are valid indices */
    string_set(dest, (r * dest->dim_size[1]) + c, value);
    /* printf("Index %d\n",r*dest->dim_size[1]+c); */
}
Esempio n. 12
0
void wiki_save(Database* db, char* page_name, char* content)
{
    Wiki* wiki_a = wiki_new();
    wiki_a->content = xalloc(sizeof(char) * strlen(content) + 1);
    string_set(wiki_a->name, page_name);
    strcpy(wiki_a->content, content);
    db_register_wiki(db, wiki_a);
    wiki_free(wiki_a);
}
Esempio n. 13
0
void fill_string_array(string_array_t* dest,modelica_string s)
{
    size_t nr_of_elements;
    size_t i;

    nr_of_elements = base_array_nr_of_elements(*dest);
    for(i = 0; i < nr_of_elements; ++i) {
        string_set(dest, i, s);
    }
}
Esempio n. 14
0
obj_ptr obj_alloc_string(cptr val)
{
    obj_ptr res = gc_alloc();
    res->type = TYPE_STRING;
    res->data.as_string.buf = 0;
    res->data.as_string.len = 0;
    res->data.as_string.size = 0;
    string_set(&res->data.as_string, val);
    return res;
}
Esempio n. 15
0
void simple_indexed_assign_string_array2(const string_array_t * source,
                                         int i1, int i2,
                                         string_array_t* dest)
{
    size_t index;
    /* Assert that source has correct dimension */
    /* Assert that dest has correct dimension */
    index = (i1 * source->dim_size[1]) + i2;
    string_set(dest, index, string_get(*source, index));
}
Esempio n. 16
0
/* function: cat_string_array
 *
 * Concatenates n string arrays along the k:th dimension.
 * k is one based
 */
void cat_string_array(int k, string_array_t* dest, int n,
                    string_array_t* first,...)
{
    va_list ap;
    int i, j, r, c;
    int n_sub = 1, n_super = 1;
    int new_k_dim_size = 0;
    string_array_t **elts = (string_array_t**)malloc(sizeof(string_array_t *) * n);

    assert(elts);
    /* collect all array ptrs to simplify traversal.*/
    va_start(ap, first);
    elts[0] = first;

    for(i = 1; i < n; i++) {
        elts[i] = va_arg(ap,string_array_t*);
    }
    va_end(ap);

    /* check dim sizes of all inputs and dest */
    assert(elts[0]->ndims >= k);
    for(i = 0; i < n; i++) {
        assert(dest->ndims == elts[i]->ndims);
        for(j = 0; j < (k - 1); j++) {
            assert(dest->dim_size[j] == elts[i]->dim_size[j]);
        }
        new_k_dim_size += elts[i]->dim_size[k-1];
        for(j = k; j < elts[0]->ndims; j++) {
            assert(dest->dim_size[j] == elts[i]->dim_size[j]);
        }
    }
    assert(dest->dim_size[k-1] == new_k_dim_size);

    /* calculate size of sub and super structure in 1-dim data representation */
    for(i = 0; i < (k - 1); i++) {
        n_super *= elts[0]->dim_size[i];
    }
    for(i = k; i < elts[0]->ndims; i++) {
        n_sub *= elts[0]->dim_size[i];
    }

    /* concatenation along k-th dimension */
    j = 0;
    for(i = 0; i < n_super; i++) {
        for(c = 0; c < n; c++) {
            int n_sub_k = n_sub * elts[c]->dim_size[k-1];
            for(r = 0; r < n_sub_k; r++) {
                string_set(dest, j,
                            string_get(*elts[c], r + (i * n_sub_k)));
                j++;
            }
        }
    }
    free(elts);
}
Esempio n. 17
0
void index_string_array(const string_array_t * source,
                        const index_spec_t* source_spec,
                        string_array_t* dest)
{
    _index_t* idx_vec1;
    _index_t* idx_vec2;
    _index_t* idx_size;
    int j;
    int i;

    assert(base_array_ok(source));
    assert(base_array_ok(dest));
    assert(index_spec_ok(source_spec));
    assert(index_spec_fit_base_array(source_spec,source));
    for(i = 0, j = 0; i < source->ndims; ++i) {
        if((source_spec->index_type[i] == 'W')
            ||
            (source_spec->index_type[i] == 'A')) {
            ++j;
        }
    }
    assert(j == dest->ndims);

    idx_vec1 = size_alloc(source->ndims);  /*indices in the source array*/
    idx_vec2 = size_alloc(dest->ndims); /* indices in the destination array*/
    idx_size = size_alloc(source_spec->ndims);

    for(i = 0; i < source->ndims; ++i) {
        idx_vec1[i] = 0;
    }
    for(i = 0; i < source_spec->ndims; ++i) {
        if(source_spec->index[i] != NULL) {
            idx_size[i] = imax(source_spec->dim_size[i],1);
        } else {
            idx_size[i] = source->dim_size[i];
        }
    }

    do {
        for(i = 0, j = 0; i < source->ndims; ++i) {
            if((source_spec->index_type[i] == 'W')
                ||
                (source_spec->index_type[i] == 'A')) {
                idx_vec2[j] = idx_vec1[i];
                j++;
            }
        }

        string_set(dest, calc_base_index(dest->ndims, idx_vec2, dest),
                   string_get(*source,
                              calc_base_index_spec(source->ndims, idx_vec1,
                                                   source, source_spec)));

    } while(0 == next_index(source->ndims, idx_vec1, idx_size));
}
Esempio n. 18
0
void vector_string_array(const string_array_t * a, string_array_t* dest)
{
    size_t i, nr_of_elements;

    /* Assert that a has at most one dimension with dim_size>1*/

    nr_of_elements = base_array_nr_of_elements(*a);
    for(i = 0; i < nr_of_elements; ++i) {
        string_set(dest, i, string_get(*a, i));
    }
}
Esempio n. 19
0
void simple_index_string_array2(const string_array_t * source,
                                int i1, int i2,
                                string_array_t* dest)
{
    size_t i;
    size_t nr_of_elements = base_array_nr_of_elements(*dest);
    size_t off = nr_of_elements * ((source->dim_size[1] * i1) + i2);

    for(i = 0 ; i < nr_of_elements ; i++) {
        string_set(dest, i, string_get(*source, off + i));
    }
}
Esempio n. 20
0
void simple_index_string_array1(const string_array_t * source, int i1,
                                string_array_t* dest)
{
    size_t i;
    size_t nr_of_elements = base_array_nr_of_elements(*dest);
    size_t off = nr_of_elements * i1;

    assert(dest->ndims == (source->ndims - 1));

    for(i = 0 ; i < nr_of_elements ; i++) {
        string_set(dest, i, string_get(*source, off + i));
    }
}
Esempio n. 21
0
void matrix_string_array(const string_array_t * a, string_array_t* dest)
{
    size_t i, cnt;
    /* Assert that size(A,i)=1 for 2 <i<=ndims(A)*/
    dest->dim_size[0] = a->dim_size[0];
    dest->dim_size[1] = (a->ndims < 2)? 1 : a->dim_size[1];

    cnt = dest->dim_size[0] * dest->dim_size[1];

    for(i = 0; i < cnt; ++i) {
        string_set(dest, i, string_get(*a, i));
    }
}
Esempio n. 22
0
void copy_string_array_data(const string_array_t source, string_array_t *dest)
{
    size_t i, nr_of_elements;

    assert(base_array_ok(&source));
    assert(base_array_ok(dest));
    assert(base_array_shape_eq(&source, dest));

    nr_of_elements = base_array_nr_of_elements(source);

    for(i = 0; i < nr_of_elements; ++i) {
        string_set(dest, i, string_get(source, i));
    }
}
Esempio n. 23
0
void fill_alloc_string_array(string_array_t* dest, modelica_string value, int ndims, ...)
{
  size_t i;
  size_t elements = 0;
  va_list ap;
  va_start(ap, ndims);
  elements = alloc_base_array(dest, ndims, ap);
  va_end(ap);
  dest->data = string_alloc(elements);

  for(i = 0; i < elements; ++i) {
      string_set(dest, i, value);
  }
}
Esempio n. 24
0
static int open_acl_xattr(vfs_handle_struct *handle,
					const char *fname,
					files_struct *fsp,
					int flags,
					mode_t mode)
{
	uint32_t access_granted = 0;
	struct security_descriptor *pdesc = NULL;
	bool file_existed = true;
	NTSTATUS status = get_nt_acl_xattr_internal(handle,
					NULL,
					fname,
					(OWNER_SECURITY_INFORMATION |
					 GROUP_SECURITY_INFORMATION |
					 DACL_SECURITY_INFORMATION),
					&pdesc);
        if (NT_STATUS_IS_OK(status)) {
		/* See if we can access it. */
		status = smb1_file_se_access_check(pdesc,
					handle->conn->server_info->ptok,
					fsp->access_mask,
					&access_granted);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(10,("open_acl_xattr: file %s open "
				"refused with error %s\n",
				fname,
				nt_errstr(status) ));
			errno = map_errno_from_nt_status(status);
			return -1;
		}
        } else if (NT_STATUS_EQUAL(status,NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
		file_existed = false;
	}

	DEBUG(10,("open_acl_xattr: get_nt_acl_attr_internal for "
		"file %s returned %s\n",
		fname,
		nt_errstr(status) ));

	fsp->fh->fd = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);

	if (!file_existed && fsp->fh->fd != -1) {
		/* File was created. Inherit from parent directory. */
		string_set(&fsp->fsp_name, fname);
		inherit_new_acl(handle, fname, fsp, false);
	}

	return fsp->fh->fd;
}
Esempio n. 25
0
void indexed_assign_string_array(const string_array_t * source,
                                 string_array_t* dest,
                                 const index_spec_t* dest_spec)
{
    _index_t* idx_vec1;
    _index_t* idx_vec2;
    _index_t* idx_size;
    int i,j;

    assert(base_array_ok(source));
    assert(base_array_ok(dest));
    assert(index_spec_ok(dest_spec));
    assert(index_spec_fit_base_array(dest_spec, dest));
    for(i = 0,j = 0; i < dest_spec->ndims; ++i) {
        if(dest_spec->dim_size[i] != 0) {
            ++j;
        }
    }
    assert(j == source->ndims);

    idx_vec1 = size_alloc(dest->ndims);
    idx_vec2 = size_alloc(source->ndims);
    idx_size = size_alloc(dest_spec->ndims);

    for(i = 0; i < dest_spec->ndims; ++i) {
        idx_vec1[i] = 0;

        if(dest_spec->index[i] != NULL) {
            idx_size[i] = imax(dest_spec->dim_size[i],1);
        } else {
            idx_size[i] = dest->dim_size[i];
        }
    }

    do {
        for(i = 0, j = 0; i < dest_spec->ndims; ++i) {
            if(dest_spec->dim_size[i] != 0) {
                idx_vec2[j] = idx_vec1[i];
                ++j;
            }
        }
        string_set(dest, calc_base_index_spec(dest->ndims, idx_vec1,
                                              dest, dest_spec),
                   string_get(*source, calc_base_index(source->ndims,
                                                      idx_vec2, source)));

    } while(0 == next_index(dest_spec->ndims, idx_vec1, idx_size));
}
Esempio n. 26
0
void string_set(string_t *str, cptr val)
{
    if (!val)
        string_set(str, "");
    else if (str->buf == val)
    {
    }
    else
    {
        size_t size = strlen(val) + 1;

        string_grow(str, size);
        memcpy(str->buf, val, size);
        str->len = size - 1;
    }
}
Esempio n. 27
0
void port_read_until(port_t *port, string_t *s, char_predicate_fn f)
{
    char ch;
    string_set(s, "");
    assert(port_is_input(port));
    if (port_is_input(port))
    {
        for (;;)
        {
            ch = port_peek_char(port);

            if (ch == EOF || f(ch))
                break;

            ch = port_read_char(port);
            string_nappend(s, &ch, 1);
        }
    }
}
Esempio n. 28
0
void promote_scalar_string_array(modelica_string s,int n,
                                 string_array_t* dest)
{
    int i;

    /* Assert that dest is of correct dimension */

    /* Alloc size */
    dest->dim_size = size_alloc(n);

    /* Alloc data */
    dest->data = string_alloc(1);

    dest->ndims = n;
    string_set(dest, 0, s);

    for(i = 0; i < n; ++i) {
        dest->dim_size[i] = 1;
    }
}
Esempio n. 29
0
l3obj* make_new_string_obj(const qqchar& s, Tag* owner, const qqchar& varname) {
    FILE* ifp = 0;

    l3obj* obj = 0;
    l3path basenm("make_new_string_obj_");
    basenm.pushq(varname);

    make_new_captag((l3obj*)&basenm ,0,0,  0,&obj,owner,  0,t_str, owner,ifp);
    LIVEO(obj);

    obj->_type = t_str;
    obj->_dtor = &string_dtor;

    // array should start empty.
    assert(obj->_judyL == 0);
    
    if (s.len()) {
        string_set(obj,0,s);
    }
    return obj;
}
Esempio n. 30
0
/**
 * insert temp. state into the compressed array
 */
int new_state(int i, int k) {
    int j,c;

    for (j=first_free_cell; ; j++) {
        if (j>=cells_size-k) {
            if ((cells=realloc(cells,(cells_size+=cells_delta)*sizeof(tcell)))==NULL)
                error("Memory full");
            memset(cells+(cells_size-cells_delta),0,cells_delta*sizeof(tcell));
        }
        if (free_cell(j) && state_fits(i,j,k)) {
            for (c=1; c<=k; c++)
                if (state(i,c)!=0) save_cell(j+c, c, state(i,c));
            save_cell(j, (state(i,0)==0 ? letter_count : 0), string_set(i));
            break;
        }
    }
    if (j-COMPWIN > first_free_cell) first_free_cell = j-COMPWIN;
    for ( ; !free_cell(first_free_cell); first_free_cell++) ;
    if (j+k > last_full_cell) last_full_cell = j+k;
    return(j);
}