Пример #1
0
void decimalfraction2pltext(int type,
                const std::string& n,
                std::string& tequiv,
                std::string& tinflection)
{
    size_t pos = n.find(', ');

    if (pos == std::string::npos) {
        integer2pltext(type, n, tequiv, tinflection);
        return;
    }
    std::string n0, n1, te0, te1, ti0, ti1;
    n0 = n.substr(0, pos);
    n1 = n.substr(pos+1);
    integer2pltext(type, n0, te0, ti0);
    if (equals_one_half(n1)) {
        if (type == BEFORE_NOUN) {
            if (te0 != "#")
                tequiv = te0 + "ipół";
        } else {
            join2(te0, "i pół", ti0, "0 0", tequiv, tinflection);
        }
        return;
    }
    if (type != CARDINAL && type != CARDINAL_G)
        return;
    if (n1.length() <= 3) {
        fractional2pltext(type, n1, te1, ti1);
        join3(te0, "i", te1, ti0, "0", ti1, tequiv, tinflection);
    } else {
        integer2pltext(CARDINAL, n1, te1, ti1);
        int i;
        for (i=0; n1[i]=='0'; i++) {
            prepend(te1, "zero", CARDINAL);
            prepend(ti1, "0", CARDINAL);
        }
        join3(te0, "przecinek", te1, ti0, "0", ti1, tequiv, tinflection);
    }
}
Пример #2
0
Файл: nfs.c Проект: UIKit0/unfs3
SYMLINK3res *nfsproc3_symlink_3_svc(SYMLINK3args * argp,
				    struct svc_req * rqstp)
{
    static SYMLINK3res result;
    char *path;
    pre_op_attr pre;
    post_op_attr post;
    char obj[NFS_MAXPATHLEN];
    int res;
    mode_t new_mode;

    PREP(path, argp->where.dir);
    pre = get_pre_cached();
    result.status =
	join3(cat_name(path, argp->where.name, obj),
	      atomic_attr(argp->symlink.symlink_attributes), exports_rw());

    cluster_create(obj, rqstp, &result.status);

    if (argp->symlink.symlink_attributes.mode.set_it == TRUE)
	new_mode = create_mode(argp->symlink.symlink_attributes);
    else {
	/* default rwxrwxrwx */
	new_mode =
	    S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP |
	    S_IROTH | S_IWOTH | S_IXOTH;
    }

    if (result.status == NFS3_OK) {
	umask(~new_mode);
	res = backend_symlink(argp->symlink.symlink_data, obj);
	umask(0);
	if (res == -1)
	    result.status = symlink_err();
	else {
	    result.SYMLINK3res_u.resok.obj =
		fh_extend_type(argp->where.dir, obj, S_IFLNK);
	    result.SYMLINK3res_u.resok.obj_attributes =
		get_post_cached(rqstp);
	}
    }

    post = get_post_attr(path, argp->where.dir, rqstp);

    /* overlaps with resfail */
    result.SYMLINK3res_u.resok.dir_wcc.before = pre;
    result.SYMLINK3res_u.resok.dir_wcc.after = post;

    return &result;
}
Пример #3
0
void join4(const std::string& te0,
            const std::string& te1,
            const std::string& te2,
            const std::string& te3,
            const std::string& ti0,
            const std::string& ti1,
            const std::string& ti2,
            const std::string& ti3,
            std::string& tequiv,
            std::string& tinflection)
{
    std::string te012, ti012;

    join3(te0, te1, te2, ti0, ti1, ti2, te012, ti012);
    join2(te012, te3, ti012, ti3, tequiv, tinflection);
}
Пример #4
0
Файл: nfs.c Проект: UIKit0/unfs3
MKNOD3res *nfsproc3_mknod_3_svc(MKNOD3args * argp, struct svc_req * rqstp)
{
    static MKNOD3res result;
    char *path;
    pre_op_attr pre;
    post_op_attr post;
    char obj[NFS_MAXPATHLEN];
    int res;
    mode_t new_mode = 0;
    dev_t dev = 0;

    PREP(path, argp->where.dir);
    pre = get_pre_cached();
    result.status =
	join3(cat_name(path, argp->where.name, obj),
	      mknod_args(argp->what, obj, &new_mode, &dev), exports_rw());

    cluster_create(obj, rqstp, &result.status);

    if (result.status == NFS3_OK) {
	if (argp->what.type == NF3CHR || argp->what.type == NF3BLK)
	    res = backend_mknod(obj, new_mode, dev);	/* device */
	else if (argp->what.type == NF3FIFO)
	    res = backend_mkfifo(obj, new_mode);	/* FIFO */
	else
	    res = backend_mksocket(obj, new_mode);	/* socket */

	if (res == -1) {
	    result.status = mknod_err();
	} else {
	    result.MKNOD3res_u.resok.obj =
		fh_extend_type(argp->where.dir, obj,
			       type_to_mode(argp->what.type));
	    result.MKNOD3res_u.resok.obj_attributes = get_post_cached(rqstp);
	}
    }

    post = get_post_attr(path, argp->where.dir, rqstp);

    /* overlaps with resfail */
    result.MKNOD3res_u.resok.dir_wcc.before = pre;
    result.MKNOD3res_u.resok.dir_wcc.after = post;

    return &result;
}
// loadParserScript -----------------------------------------------------------
// Read the file <engine>.prs and save into memory the parser script.
// ----------------------------------------------------------------------------
void loadParserScript(struct engineInformations *e) {
	FILE *f;
	short i=0;
	char buffer[bfsize+1];
	char *filename;
	
	filename = join3("parser/", e->name, ".prs");														// create the <engine>.prs filename
	
	if ((f = fopen(filename,"r"))==NULL) {																	// exit if opening problems occur
		printf("   Error opening '%s'. Exit!",filename); exit(-1); }
	
	while (fgets(buffer, bfsize, f)!=NULL) {
		buffer[strlen(buffer)-1]='\0';																		// replace the final '\n' with a '\0'
		e->parser_cmd[i] = strdup(buffer);																	// put the cmd in the commmand list
		i++;
	}
	
	e->parser_cmd[i] = NULL;																					// set last pointer to NULL

	fclose(f);
	free(filename);
}
Пример #6
0
Файл: nfs.c Проект: UIKit0/unfs3
MKDIR3res *nfsproc3_mkdir_3_svc(MKDIR3args * argp, struct svc_req * rqstp)
{
    static MKDIR3res result;
    char *path;
    pre_op_attr pre;
    post_op_attr post;
    char obj[NFS_MAXPATHLEN];
    int res;

    PREP(path, argp->where.dir);
    pre = get_pre_cached();
    result.status =
	join3(cat_name(path, argp->where.name, obj),
	      atomic_attr(argp->attributes), exports_rw());

    cluster_create(obj, rqstp, &result.status);

    if (result.status == NFS3_OK) {
	res = backend_mkdir(obj, create_mode(argp->attributes));
	if (res == -1)
	    result.status = mkdir_err();
	else {
	    result.MKDIR3res_u.resok.obj =
		fh_extend_type(argp->where.dir, obj, S_IFDIR);
	    result.MKDIR3res_u.resok.obj_attributes = get_post_cached(rqstp);
	}
    }

    post = get_post_attr(path, argp->where.dir, rqstp);

    /* overlaps with resfail */
    result.MKDIR3res_u.resok.dir_wcc.before = pre;
    result.MKDIR3res_u.resok.dir_wcc.after = post;

    return &result;
}
Пример #7
0
void word_count(int m, int r, char *address){
    FILE * fp= NULL;
    char * line = NULL;
    size_t len = 0;
    ssize_t read;
    char* address1 = "/input";
    char* address2 = "/output";
    char **text = malloc(sizeof(char*) * m);
    
    int x = 0;
    for(x=0;x<m;x++){
        char *n = malloc (sizeof(char)*2);
        snprintf(n , 10, "%d", x);
        char *put = join3(address,address1);
        char *input = join3(put,n);
        /*creat the input file address*/
        fp =fopen(input,"r");
        if (fp == NULL)
            exit(EXIT_FAILURE);
        /*open the file*/
        char * result = "";
        while ((read = getline(&line, &len, fp)) != -1) {
            int length = strlen(line);
            line[length-1] = ' ';
            result = join3(result , line);
            /*join all the lines in one file together to one single line*/
        }
        text[x] = result;
        /*store the line in the corresponding line in the **text  */
        fclose(fp);
    }
    
    mymap = (map_t *)malloc(sizeof(map_t ) * r);
    int number=0;
    for(number =0; number <r;number ++)
        mymap[number] = hashmap_new();
    int q =0;    
    queue = (struct buffered_queue *)malloc(sizeof(struct buffered_queue) * r);
    for( q=0; q<r; q++){
       buffered_queue_init(&queue[q],20);
    }
    /*initialize the hashtable and the queue*/
    
    
    int num =0;
    if (m>=r) 
        num =m;
    else
        num = r;
    
   struct ma arg[num];
    int z =0;  
    for( z=0; z<num; z++){
       arg[z].text = (char **)malloc(sizeof(char*) * m);
       arg[z].id = z;
       arg[z].r = r;
       arg[z].m = m;
       arg[z].text  = text;
    }  
   /*the information passed to the thread store in the struct*/
    
    
    pthread_t map[m];
    pthread_t re[r];  
    int a = 0;
    int b =0;
    int c=0;
    int d=0;
    for( a=0; a<m; a++){
        pthread_create(&map[a], NULL, mapper, &arg[a]);
    }
    for( b=0; b<r; b++){
        pthread_create(&re[b], NULL, reducer, &arg[b]);
    }
    for( c=0; c<m; c++){
        pthread_join(map[c], NULL);
    }
    for( d=0; d<r; d++){
        pthread_join(re[d], NULL);
    }
    buffered_queue_destroy(queue);
    /*creat and run the thread */
    
    int t = 0;
    for(t=0;t<r;t++){
        char *z = malloc (sizeof(char)*2);
        snprintf(z , 10, "%d", t);
        char *put = join3(address,address2);
        /*creat the input text address*/
        char *input = join3(put,z);
        fp = fopen (input, "w+");
        /*open the file*/
        int j =0;
        hashmap_map * m;
        m = (hashmap_map *) mymap[t];
        for(j = 0; j< m->table_size; j++){
            if(m->data[j].in_use != 0) {
                char *key = m->data[j].key;
                int data = m->data[j].data;
                fprintf(fp, "%s %d\n", key,data);
                /* copy one hashtable to on corresponding output file*/
            }
        }
        fclose(fp);
    }
    
    return ;
}
Пример #8
0
void num2pltext(int type,
                const std::string& n,
                std::string& tequiv,
                std::string& tinflection,
                std::string& tsyntax)
{
    size_t pos;

    tsyntax = "";
    tequiv = "#";
    tinflection = "";
    if (n.length() == 0)
        return;
    if (n[0] == '-') {
        num2pltext(type, n.substr(1), tequiv, tinflection, tsyntax);
        prepend(tequiv, "minus", CARDINAL);
        prepend(tinflection, "0", CARDINAL);
        return;
    }
    if (n[0] == '+') {
        num2pltext(type, n.substr(1), tequiv, tinflection, tsyntax);
        prepend(tequiv, "plus", CARDINAL);
        prepend(tinflection, "0", CARDINAL);
        return;
    }
    if (n[n.length()-1] == '%') {
        if (type != CARDINAL)
            return;
        num2pltext(type, n.substr(0, n.length()-1), tequiv, tinflection, tsyntax);
        tequiv += " procent";
        tinflection += " 0";
        return;
    }
    pos = n.find('+');
    if (pos != std::string::npos) {
        if (type != CARDINAL)
            return;
        std::string n0 = n.substr(0, pos);
        std::string n1 = n.substr(pos+1);
        std::string te0, te1, ti0, ti1;
        decimalfraction2pltext(type, n0, te0, ti0);
        decimalfraction2pltext(type, n1, te1, ti1);
        join3(te0, "plus", te1, ti0, "0", ti1, tequiv, tinflection);
        return;
    }
    pos = n.find('-');
    if (pos != std::string::npos) {
        if (type != CARDINAL)
            return;
        std::string n0 = n.substr(0, pos);
        std::string n1 = n.substr(pos+1);
        std::string te0, te1, ti0, ti1;
        if (bigger(n0, n1)) {
            decimalfraction2pltext(type, n0, te0, ti0);
            decimalfraction2pltext(type, n1, te1, ti1);
            join3(te0, "minus", te1, ti0, "0", ti1, tequiv, tinflection);
        } else {
            decimalfraction2pltext(CARDINAL_G, n0, te0, ti0);
            decimalfraction2pltext(CARDINAL_G, n1, te1, ti1);
            join4("od", te0, "do", te1, "0", ti0, "0", ti1, tequiv, tinflection);
        }
        return;
    }
    pos = n.find('/');
    if (pos != std::string::npos) {
        if (type != CARDINAL)
            return;
        std::string n0 = n.substr(0, pos);
        std::string n1 = n.substr(pos+1);
        std::string te0, te1, ti0, ti1;
        integer2pltext(CARDINAL_F, n0, te0, ti0);
        switch (select_government(n0)) {
        case JEDEN:
            integer2pltext(ORDINAL_F, n1, te1, ti1);
            break;
        case DWA:
            integer2pltext(ORDINAL_NPL, n1, te1, ti1);
            break;
        case ZERO:
        case PIEC:
            integer2pltext(ORDINAL_GPL, n1, te1, ti1);
            break;
        default:
            return;
        }
        join2(te0, te1, ti0, ti1, tequiv, tinflection);
        tsyntax = "R=4";
        return;
    }
    decimalfraction2pltext(type, n, tequiv, tinflection);
}
Пример #9
0
/**
 * Join a field with strings before and after it
 *
 * @param[in] mp Memory pool
 * @param[in] f Field to join
 * @param[in] iptr Pointer to initial string
 * @param[in] ilen Length of @a iptr
 * @param[in] fptr Pointer to final string
 * @param[in] flen Length of @a fptr
 * @param[in] nul true if NUL byte should be tacked on, false if not
 * @param[out] out Pointer to output block
 * @param[out] olen Length of the output block
 *
 * @returns status code
 */
static ib_status_t join_parts(ib_mpool_t *mp,
                              const ib_field_t *f,
                              const char *iptr,
                              size_t ilen,
                              const char *fptr,
                              size_t flen,
                              bool nul,
                              char **out,
                              size_t *olen)
{
    IB_FTRACE_INIT();
    ib_status_t rc;
    char numbuf[NUM_BUF_LEN+1]; /* Buffer used to convert number to str */
    assert(NUM_BUF_LEN <= 256);

    switch(f->type) {
    case IB_FTYPE_NULSTR:
    {
        /* Field is a NUL-terminated string */
        const char *s;
        rc = ib_field_value(f, ib_ftype_nulstr_out(&s));
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }
        size_t slen = strlen(s);
        rc = join3(mp,
                   iptr, ilen,
                   s, slen,
                   fptr, flen,
                   nul,
                   out, olen);
        break;
    }

    case IB_FTYPE_BYTESTR:
    {
        /* Field is a byte string */
        const ib_bytestr_t *bs;
        rc = ib_field_value(f, ib_ftype_bytestr_out(&bs));
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }
        rc = join3(mp,
                   iptr, ilen,
                   (const char *)ib_bytestr_const_ptr(bs),
                   ib_bytestr_length(bs),
                   fptr, flen,
                   nul,
                   out, olen);
        break;
    }

    case IB_FTYPE_NUM:
    {
        /* Field is a number; convert it to a string */
        ib_num_t n;
        rc = ib_field_value(f, ib_ftype_num_out(&n));
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }
        snprintf(numbuf, NUM_BUF_LEN, "%"PRId64, n);
        rc = join3(mp,
                   iptr, ilen,
                   numbuf, strlen(numbuf),
                   fptr, flen,
                   nul,
                   out, olen);
        break;
    }

    case IB_FTYPE_UNUM:
    {
        /* Field is an unsigned number; convert it to a string */
        ib_unum_t n;
        rc = ib_field_value(f, ib_ftype_unum_out(&n));
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }
        snprintf(numbuf, NUM_BUF_LEN, "%"PRIu64, n);
        rc = join3(mp,
                   iptr, ilen,
                   numbuf, strlen(numbuf),
                   fptr, flen,
                   nul,
                   out, olen);
        break;
    }

    case IB_FTYPE_LIST:
    {
        /* Field is a list: use the first element in the list */
        const ib_list_t *list;
        const ib_list_node_t *node;
        const ib_field_t *element;

        rc = ib_field_value(f, ib_ftype_list_out(&list));
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }

        node = ib_list_first_const(list);
        if (node == NULL) {
            rc = join2(mp, iptr, ilen, fptr, flen, nul, out, olen);
            break;
        }

        element = (const ib_field_t *)ib_list_node_data_const(node);
        rc = join_parts(mp, element, iptr, ilen, fptr, flen, nul, out, olen);
        break;
    }

    default:
        /* Something else: replace with "" */
        rc = join2(mp, iptr, ilen, fptr, flen, nul, out, olen);
        break;
    }

    IB_FTRACE_RET_STATUS(rc);
}