Example #1
0
/* create a nonterminal given only names */
struct Production *newPackratNonterminal(unsigned char *name, unsigned char ***sub)
{
    struct Production *ret = getProduction(name);
    struct Buffer_Production_p pors;
    struct Buffer_Production pthens;
    struct Production *pr;
    int ors, thens;

    ret->parser = packratNonterminal;

    /* now fill in the sub-productions */
    INIT_BUFFER(pors);
    for (ors = 0; sub[ors]; ors++) {
        INIT_BUFFER(pthens);
        for (thens = 0; sub[ors][thens]; thens++) {
            pr = getProduction(sub[ors][thens]);
            WRITE_BUFFER(pthens, &pr, 1);
        }
        pr = NULL;
        WRITE_BUFFER(pthens, &pr, 1);

        WRITE_BUFFER(pors, &pthens.buf, 1);
    }
    pr = NULL;
    WRITE_BUFFER(pors, (struct Production ***) &pr, 1);

    ret->arg = pors.buf;

    return ret;
}
static int ReadTRexShort(struct synaptics_ts_data *ts)
{
	int ret = 0;
	unsigned char TRX_Short[7] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00};

	int MaxArrayLength = RxChNum * TxChNum * 2;
	int i, j = 0;
	int mask = 0x01;
	int value;	// Hardcode for Waikiki Test and it support up to 54 Tx
	int result = TOUCH_SUCCESS;
	u8 buf[40] = {0};
	u8 cap_data[MaxArrayLength];

	ret = Touch_I2C_Read(ts->client, REPORT_DATA_REG, cap_data, MaxArrayLength);

	WRITE_BUFFER(f54_wlog_buf, "TRex Short Test\n");

	for (i = 0; i < 7; i++) {
		int short_num = 0;

		value = cap_data[i];
		cap_data[i] = 0;

		for (j = 0; j < 8; j++) {
			if((value & mask) == 1) {
				cap_data[i] = cap_data[i] + (unsigned char)pow_func(2, (7 - j));
				short_num += sprintf(buf+short_num, "%d ", (i * 8 + (7 - j)));
			}

			value >>= 1;
		}

		WRITE_BUFFER(f54_wlog_buf, "TRex-TRex Short Test Data = %#x", cap_data[i]);

		if (short_num) {
			WRITE_BUFFER(f54_wlog_buf, " (Short TRx Number: ");
			WRITE_BUFFER(f54_wlog_buf, buf);
			WRITE_BUFFER(f54_wlog_buf, ")\n");
		}

		WRITE_BUFFER(f54_wlog_buf, "\n");
	}

	for(i = 0; i < 7; i++) {
		if(cap_data[i] != TRX_Short[i]) {
			result = TOUCH_FAIL;
			break;
		}
	}

	if (result == TOUCH_SUCCESS)
		WRITE_BUFFER(f54_wlog_buf, "\nTRex-TRex Short Test passed.\n\n");
	else
		WRITE_BUFFER(f54_wlog_buf, "\nTRex-TRex Short Test failed.\n\n");

	write_log(NULL, f54_wlog_buf);

	return result;
}
Example #3
0
// flatten_item: Serialize a single kssl_item. The offset is updated
// as bytes are written. If offset pointer is NULL this function
// starts at offset 0. Returns KSSL_ERROR_NONE if successful.
kssl_error_code flatten_item(BYTE tag,         // The kssl_item's tag (see
                             // kssl.h)
                             BYTE *payload,    // Buffer containing the item's
                             // payload
                             WORD payload_len, // Length of data from payload
                             // to copy
                             BYTE *bytes,      // Buffer into which item is
                             // serialized
                             int *offset) {    // (optional) offset into bytes
    // to write from
    int local_offset = 0;

    if (bytes == NULL) {
        return KSSL_ERROR_INTERNAL;
    }

    if (offset != NULL) {
        local_offset = *offset;
    }

    WRITE_BYTE(bytes, local_offset, tag);
    WRITE_WORD(bytes, local_offset, payload_len);
    if (payload_len > 0) {
        WRITE_BUFFER(bytes, local_offset, payload, payload_len);
    }

    if (offset != NULL) {
        *offset = local_offset;
    }

    return KSSL_ERROR_NONE;
}
Example #4
0
File: ide.c Project: Aishou/lxdream
void ide_write_data_pio( uint16_t val ) {
    if( idereg.state == IDE_STATE_CMD_WRITE ) {
        WRITE_BUFFER(val);
        idereg.data_offset+=2;
        if( idereg.data_offset >= idereg.data_length ) {
            idereg.state = IDE_STATE_BUSY;
            idereg.status = (idereg.status & ~IDE_STATUS_DRQ) | IDE_STATUS_BSY;
            idereg.data_offset = -1;
            ide_packet_command(data_buffer);
        }
    } else if( idereg.state == IDE_STATE_PIO_WRITE ) {
        WRITE_BUFFER(val);
        idereg.data_offset +=2;
        if( idereg.data_offset >= idereg.data_length ) {
            idereg.state = IDE_STATE_IDLE;
            idereg.status &= ~IDE_STATUS_DRQ;
            idereg.data_offset = -1;
            idereg.count = 3; /* complete */
            ide_raise_interrupt();
            ide_write_buffer( data_buffer, idereg.data_length );
        }
    }
}
Example #5
0
static void unparseJSONStr(struct Buffer_char *buf, const char *str)
{
    size_t i;
    for (i = 0; str[i]; i++) {
        char c = str[i];
        switch (c) {
            case '"':
            case '\\':
                WRITE_ONE_BUFFER(*buf, '\\');
                WRITE_ONE_BUFFER(*buf, c);
                break;

            case '\b':
                WRITE_BUFFER(*buf, "\\b", 2);
                break;

            case '\f':
                WRITE_BUFFER(*buf, "\\f", 2);
                break;

            case '\n':
                WRITE_BUFFER(*buf, "\\n", 2);
                break;

            case '\r':
                WRITE_BUFFER(*buf, "\\r", 2);
                break;

            case '\t':
                WRITE_BUFFER(*buf, "\\t", 2);
                break;

            default:
                WRITE_ONE_BUFFER(*buf, c);
        }
    }
}
Example #6
0
//
// unicode to utf8
//
EFI_STATUS UnicodeToUtf8(CHAR16 CONST* unicodeBuffer, UINTN unicodeCharCount, UINT8* utf8Buffer, UINTN utf8BufferLength)
{
	UINT32 j																= 0;
	utf8Buffer[utf8BufferLength - 1]										= 0;
    UINT32 i = 0;

	for(i = 0; i < unicodeCharCount; i ++)
	{
		CHAR16 unicodeChar													= unicodeBuffer[i];
		if(unicodeChar < 0x0080)
		{
			WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, unicodeChar, UINT8);
		}
		else if(unicodeChar < 0x0800)
		{
			WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >>  6) & 0x0f) | 0xc0, UINT8);
			WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >>  0) & 0x3f) | 0x80, UINT8);
		}
		else
		{
Example #7
0
static void unparseJSONPrime(struct Buffer_char *buf, Node *node)
{
    size_t i;
    const char *tmp;

    WRITE_ONE_BUFFER(*buf, '{');

    if (node->tok) {
        Token *tok = node->tok;
        WRITE_BUFFER(*buf, "\"tok\":{\"type\":\"", 15);

        tmp = tokenName(tok->type);
        unparseJSONStr(buf, tmp);

        WRITE_ONE_BUFFER(*buf, '"');

        if (tok->pre) {
            WRITE_BUFFER(*buf, ",\"pre\":\"", 8);
            unparseJSONStr(buf, tok->pre);
            WRITE_ONE_BUFFER(*buf, '"');
        }

        if (tok->tok) {
            WRITE_BUFFER(*buf, ",\"tok\":\"", 8);
            unparseJSONStr(buf, tok->tok);
            WRITE_ONE_BUFFER(*buf, '"');
        }

        WRITE_BUFFER(*buf, "},", 2);
    }

    WRITE_BUFFER(*buf, "\"type\":\"", 8);
    tmp = nodeName(node->type);
    unparseJSONStr(buf, tmp);

    WRITE_BUFFER(*buf, "\",\"children\":[", 14);

    for (i = 0; node->children[i]; i++) {
        if (i != 0) WRITE_ONE_BUFFER(*buf, ',');
        unparseJSONPrime(buf, node->children[i]);
    }

    WRITE_BUFFER(*buf, "]}", 2);
}
Example #8
0
/* validate a path as OK */
void validatePath(char **path)
{
    struct Buffer_char pathok;
    struct stat sbuf;
    char *rpath;

    if (!*path) return;

    /* first make sure it's absolute */
    if (**path != '/') {
        *path = NULL;
        return;
    }

    /* then get its real path (don't worry about deallocation, there aren't
     * many of these) */
    *path = realpath(*path, NULL);
    if (*path == NULL) return;

    /* then check the ok file */
    INIT_BUFFER(pathok);
    WRITE_BUFFER(pathok, *path, strlen(*path));
    WRITE_STR_BUFFER(pathok, OKFILE);
    WRITE_STR_BUFFER(pathok, "\0");
    if (stat(pathok.buf, &sbuf) < 0) {
        /* file not found or otherwise very bad, kill it */
        *path = NULL;
        FREE_BUFFER(pathok);
        return;
    }
    FREE_BUFFER(pathok);
    if (sbuf.st_uid != geteuid()) {
        /* wrong owner */
        *path = NULL;
        return;
    }

    /* it's valid */
}
static int ReadHighResistance(struct synaptics_ts_data *ts)
{
	int MaxArrayLength = RxChNum * TxChNum * 2;
	int HighResistanceLowerLimit[3] = {-1000, -1000, -400};
	int HighResistanceUpperLimit[3] = {450, 450, 200};
	int maxRxpF, maxTxpF, minpF;
	int i = 0;
	int result = LGTC_SUCCESS;
	u8 cap_data[MaxArrayLength];
	short maxRx, maxTx, min;

	touch_i2c_read(ts->client, REPORT_DATA_REG, MaxArrayLength, cap_data);

	maxRx = ((short)cap_data[0] | (short)cap_data[1] << 8);
	maxTx = ((short)cap_data[2] | (short)cap_data[3] << 8);
	min = ((short)cap_data[4] | (short)cap_data[5] << 8);

	maxRxpF = maxRx;
	maxTxpF = maxTx;
	minpF = min;

	WRITE_BUFFER(f54_wlog_buf, "High Resistance Test\n");
	WRITE_BUFFER(f54_wlog_buf, "Max Rx Offset(pF) = %d\n", maxRxpF);
	WRITE_BUFFER(f54_wlog_buf, "Max Tx Offset(pF) = %d\n", maxTxpF);
	WRITE_BUFFER(f54_wlog_buf, "Min(pF) = %d\n", minpF);
	WRITE_BUFFER(f54_wlog_buf, "\n=====================================================\n");
	WRITE_BUFFER(f54_wlog_buf, "\tHigh Resistance Test\n");
	WRITE_BUFFER(f54_wlog_buf, "=====================================================\n");
	WRITE_BUFFER(f54_wlog_buf, " Parameters: ");
	WRITE_BUFFER(f54_wlog_buf, "%5d %5d %5d ", maxRxpF, maxTxpF, minpF);
	WRITE_BUFFER(f54_wlog_buf, "\n\n Limits(+) : ");

	for(i = 0; i < 3; i++)
		WRITE_BUFFER(f54_wlog_buf, "%5d ", HighResistanceUpperLimit[i]);

	WRITE_BUFFER(f54_wlog_buf, "\n Limits(-) : ");

	for(i = 0; i < 3; i++)
		WRITE_BUFFER(f54_wlog_buf, "%5d ", HighResistanceLowerLimit[i]);

	WRITE_BUFFER(f54_wlog_buf, "\n-----------------------------------------------------\n");

	if (maxRxpF > HighResistanceUpperLimit[0] || maxRxpF < HighResistanceLowerLimit[0])
		result = LGTC_FAIL;
	if (maxTxpF > HighResistanceUpperLimit[1] || maxTxpF < HighResistanceLowerLimit[1])
		result = LGTC_FAIL;
	if (minpF > HighResistanceUpperLimit[2] || minpF < HighResistanceLowerLimit[2])
		result = LGTC_FAIL;

	if (result == LGTC_FAIL)
		WRITE_BUFFER(f54_wlog_buf, "HighResistance Test failed.\n\n");
	else
		WRITE_BUFFER(f54_wlog_buf, "HighResistance Test passed.\n\n");

	write_log(NULL, f54_wlog_buf);

	return result;
}
Example #10
0
int main(int argc, char **argv)
{
    struct Buffer_charp rpaths;
    struct Buffer_char options;
    char *wpath = NULL, *arg;
    char *envpaths;
    int i, j, argi, tmpi;
    unsigned long mountflags = 0;
    int allowclear = 0, clear = 0, userwpath = 1;

    INIT_BUFFER(rpaths);
    WRITE_ONE_BUFFER(rpaths, NULL); /* filled in by forced dir later */

    /* get all the paths out of the environment */
    envpaths = getenv(PATHENV);
    if (envpaths && envpaths[0]) {
        char *saveptr;
        arg = strtok_r(envpaths, ":", &saveptr);
        while (arg) {
            WRITE_ONE_BUFFER(rpaths, arg);
            arg = strtok_r(NULL, ":", &saveptr);
        }
    }

    /* get all the paths out of the args */
    for (argi = 1; argi < argc; argi++) {
        arg = argv[argi];
        if (arg[0] == '-') {
            if (!strcmp(arg, "-w") && argi < argc - 1) {
                argi++;
                wpath = argv[argi];

            } else if (!strcmp(arg, "-r")) {
                /* reset current paths (ignore environment) */
                rpaths.bufused = 1;
                allowclear = 1;

            } else if (!strcmp(arg, "--") && argi < argc - 1) {
                argi++;
                break;

            } else {
                fprintf(stderr, "Unrecognized option %s\n", arg);
            }

        } else {
            WRITE_ONE_BUFFER(rpaths, arg);

        }
    }
    if (argi >= argc) {
        if (getuid() != geteuid()) {
            fprintf(stderr, "Only root may remount an existing view\n");
            return 1;
        }
        mountflags |= MS_REMOUNT;
    }

    /* validate all our paths */
    for (i = 1; i < rpaths.bufused; i++) {
        validatePath(&rpaths.buf[i]);
    }
    validatePath(&wpath);
    rpaths.buf[0] = FORCEDIR;
    if (!wpath) {
        wpath = DEFAULTWRITEDIR;
        userwpath = 0;
    }

    /* make sure there are no duplicates */
    for (i = 1; i < rpaths.bufused; i++) {
        if (!rpaths.buf[i]) continue;
        if (!strcmp(rpaths.buf[i], wpath)) {
            rpaths.buf[i] = NULL;
            continue;
        }
        for (j = 0; j < i; j++) {
            if (rpaths.buf[j] &&
                !strcmp(rpaths.buf[i], rpaths.buf[j])) {
                rpaths.buf[i] = NULL;
                break;
            }
        }
    }

    /* are we trying to clear /usr? */
    if (rpaths.bufused == 1) {
        /* no options = unmount all */
        if (!allowclear) {
            fprintf(stderr, "To explicitly clear all /usr mounts, -r must be specified\n");
            return 1;
        }
        clear = 1;
    }

    /* perform the mount */
    if (!(mountflags & MS_REMOUNT))
        SF(tmpi, unshare, -1, (CLONE_NEWNS));
    if (clear) {
        do {
            tmpi = umount("/usr");
        } while (tmpi == 0);
        if (errno != EINVAL)
            perror("/usr");
    } else {
        /* first mount */
        INIT_BUFFER(options);
        WRITE_STR_BUFFER(options, "br:");
        WRITE_BUFFER(options, wpath, strlen(wpath) + 1);
        tmpi = mount("none", BASE, "aufs", mountflags, options.buf);
        if (tmpi == -1 && (mountflags & MS_REMOUNT)) {
            /* OK, we tried to remount, maybe it just wasn't mounted though */
            mountflags &= ~(MS_REMOUNT);
            tmpi = mount("none", BASE, "aufs", mountflags, options.buf);
        }

        /* remaining mounts */
        for (i = 0; tmpi != -1 && i < rpaths.bufused; i++) {
            if (!rpaths.buf[i]) continue;
            options.bufused = 0;
            WRITE_STR_BUFFER(options, "append:");
            WRITE_BUFFER(options, rpaths.buf[i], strlen(rpaths.buf[i]));
            if (!userwpath)
                WRITE_STR_BUFFER(options, "=rw");
            WRITE_STR_BUFFER(options, "\0");
            tmpi = mount("none", BASE, "aufs", mountflags|MS_REMOUNT, options.buf);
        }

        if (tmpi == -1) {
            perror("mount");
            return 1;
        }
    }

    /* drop privs */
    SF(tmpi, setuid, -1, (getuid()));
    SF(tmpi, setgid, -1, (getgid()));

    /* free our mount options */
    FREE_BUFFER(options);

    /* add it to the environment */
    INIT_BUFFER(options);
    for (i = 0; i < rpaths.bufused; i++) {
        arg = rpaths.buf[i];
        if (arg) {
            if (options.bufused) WRITE_STR_BUFFER(options, ":");
            WRITE_BUFFER(options, arg, strlen(arg));
        }
    }
    WRITE_STR_BUFFER(options, "\0");
    SF(tmpi, setenv, -1, (PATHENV, options.buf, 1));
    FREE_BUFFER(options);

    if (userwpath) {
        SF(tmpi, setenv, -1, (WRITEENV, wpath, 1));
    } else {
        SF(tmpi, unsetenv, -1, (WRITEENV));
    }

    /* then run it */
    if (argi < argc) {
        execvp(argv[argi], argv + argi);
        fprintf(stderr, "[usrview] ");
        perror(argv[argi]);

        return 1;

    } else {
        return 0;

    }
}
Example #11
0
File: ast.c Project: GregorR/plof3
/* turn this PSL into a PSL AST */
struct PSLAstNode *pslToAst(unsigned char *psl, size_t psllen)
{
    size_t psli, si, curtemp;
    struct Buffer_PSLAstNode astout, aststack;
    struct PSLAstNode *cur;

    INIT_BUFFER(astout);
    INIT_BUFFER(aststack);
    curtemp = 1;

    /* make the arg */
    cur = allocPSLAstNode(pslast_arg, NULL, 0, 0, NULL);
    WRITE_BUFFER(aststack, &cur, 1);

    for (psli = 0; psli < psllen; psli++) {
        int arity = 0, pushes = 0;
        unsigned short cmd = psl[psli];
        unsigned char *data = NULL;
        size_t datasz = 0;

        /* maybe it has raw data */
        if (cmd >= psl_marker) {
            psli++;
            psli += pslBignumToInt(psl + psli, &datasz);

            /* make sure this doesn't go off the edge */
            if (psli + datasz <= psllen) {
                data = psl + psli;
                psli += datasz - 1;
            }
        }

        /* now get our arity info */
        switch (cmd) {
#define FOREACH(cmd)
#define LEAKY_PUSH(x)
#define ARITY(x) arity = x;
#define PUSHES(x) pushes = x;
#define LEAKA
#define LEAKB
#define LEAKC
#define LEAKP
#define LEAKALL
#include "psl-optim.c"
#undef FOREACH
#undef LEAKY_PUSH
#undef ARITY
#undef PUSHES
#undef LEAKA
#undef LEAKB
#undef LEAKC
#undef LEAKP
#undef LEAKALL

        default:
            arity = 0;
            pushes = 0;
        }

        /* if this has data, but the data is actually code, need to put that in place */
        if (cmd == psl_code || cmd == psl_immediate) {
            cur = pslToAst(data, datasz);
            data = NULL;
            datasz = 0;
            WRITE_BUFFER(aststack, &cur, 1);
            arity++;
        }

        /* if we need to flatten the stack (we're duplicating or removing stack elements), do so */
        if ((cmd >= psl_push0 && cmd <= psl_push7) || pushes != 1) {
            struct Buffer_PSLAstNode naststack;
            INIT_BUFFER(naststack);

            for (si = 0; si < aststack.bufused; si++) {
                if (aststack.buf[si]->cmd == pslast_gettemp) {
                    /* just copy it */
                    WRITE_BUFFER(naststack, aststack.buf + si, 1);

                } else {
                    cur = allocPSLAstNode(pslast_settemp, NULL, 0,
                                          1, aststack.buf + si);
                    cur->temp0 = curtemp;
                    WRITE_BUFFER(astout, &cur, 1);

                    cur = allocPSLAstNode(pslast_gettemp, NULL, 0,
                                          0, NULL);
                    cur->temp0 = curtemp;
                    WRITE_BUFFER(naststack, &cur, 1);

                    curtemp++;
                }
            }

            /* now replace aststack with the new one */
            aststack = naststack;
        }

        /* replace pushes by gettemps */
        if (cmd >= psl_push0 && cmd <= psl_push7) {
            int depth = cmd - psl_push0;
            if (aststack.bufused < depth + 1) {
                cur = allocPSLAstNode(psl_null, NULL, 0, 0, NULL);
            } else {
                cur = BUFFER_END(aststack)[-depth-1];
            }

            WRITE_BUFFER(aststack, &cur, 1);

            /* just perform pops */
        } else if (cmd == psl_pop) {
            if (aststack.bufused > 0)
                aststack.bufused--;

            /* resolve is weird */
        } else {
            /* figure out the mixed arity of an array */
            if (cmd == psl_array) {
                arity = 1;
                if (aststack.bufused > 0 && BUFFER_TOP(aststack)->cmd == psl_integer) {
                    /* OK, good, there's an integer. If it makes sense, get the value */
                    cur = BUFFER_TOP(aststack);
                    if (cur->children[0]->cmd == psl_raw) {
                        /* hooplah! Get the int val*/
                        struct PlofRawData *rd;
                        ptrdiff_t val;
                        cur = cur->children[0];
                        rd = newPlofRawDataNonAtomic(cur->datasz);
                        memcpy(rd->data, cur->data, cur->datasz);

                        val = parseRawInt(rd);

                        /* and extend the arity */
                        if (val > 0) arity += val;
                    }
                }
            }

            /* make sure we have all the children */
            while (aststack.bufused < arity) {
                /* need to put nulls at the start */
                while (BUFFER_SPACE(aststack) < 1) EXPAND_BUFFER(aststack);
                memmove(aststack.buf + 1, aststack.buf, aststack.bufused * sizeof(struct PSLAstNode *));
                aststack.buf[0] = allocPSLAstNode(psl_null, NULL, 0, 0, NULL);
                aststack.bufused++;
            }

            /* and create the current one */
            cur = allocPSLAstNode(cmd, data, datasz, arity, BUFFER_END(aststack) - arity);
            aststack.bufused -= arity;

            /* handle resolve's weird push */
            if (cmd == psl_resolve) {
                struct PSLAstNode *tmp;
                tmp = allocPSLAstNode(pslast_gettemp, NULL, 0, 0, NULL);
                tmp->temp0 = curtemp;
                WRITE_BUFFER(aststack, &tmp, 1);

                tmp = allocPSLAstNode(pslast_gettemp, NULL, 0, 0, NULL);
                tmp->temp0 = curtemp + 1;
                WRITE_BUFFER(aststack, &tmp, 1);

                cur->temp0 = curtemp;
                cur->temp1 = curtemp + 1;

                curtemp += 2;
            }

            /* put it either on the stack or in our instruction list */
            if (pushes == 1) {
                WRITE_BUFFER(aststack, &cur, 1);
            } else {
                WRITE_BUFFER(astout, &cur, 1);
            }

            /* FIXME: array, resolve special */
        }
    }

    WRITE_BUFFER(astout, aststack.buf, aststack.bufused);
    return allocPSLAstNode(pslast_seq, NULL, 0, astout.bufused, astout.buf);
}
Example #12
0
void saveMeshes( const CalCoreModel* calCoreModel,
                 const MeshesVector& meshes,
                 const std::string&  fn )
    throw (std::runtime_error)
{
    FILE* f = fopen( fn.c_str(), "wb" );

    if ( f == NULL )
    {
        throw std::runtime_error( "Can't create " + fn );
    }

    FileCloser closeOnExit( f );
//    FileBuffer setReadBufferOfSize( f, 1*1024*1024 );

    WRITE_I32( HW_MODEL_FILE_VERSION );

    // -- Write meshes --
    WRITE_I32( meshes.size() );

    for ( size_t i = 0; i < meshes.size(); i++ )
    {
        MeshData* m = meshes[i].get();

        // -- Write name --
        const std::string& name = m->name;
        WRITE_I32( name.size() );
        WRITE_( m->name, name.data(), name.size() );

        // -- Write material --
        int coreMaterialThreadId = getCoreMaterialThreadId(
            const_cast< CalCoreModel* >( calCoreModel ), m->coreMaterial );
        if ( coreMaterialThreadId < 0 )
        {
            fclose( f );
            throw std::runtime_error( "Can't get coreMaterialThreadId (mesh.pCoreMaterial not found in coreModel?" );            
        }
        WRITE_I32( coreMaterialThreadId );

        // -- Read bone parameters --
        WRITE_I32( m->rigid );
        WRITE_I32( m->rigidBoneId );
        WRITE_I32( m->maxBonesInfluence );

        // -- Read bonesIndices --
        WRITE_I32( m->bonesIndices.size() );
        for ( size_t bi = 0; bi < m->bonesIndices.size(); bi++ )
        {
            WRITE_I32( m->bonesIndices[ bi ] );
        }

        // -- Write boundingBox --
        assert( sizeof ( m->boundingBox ) == 6 * 4 ); // must be 6 floats
        WRITE_STRUCT( m->boundingBox );
    }

#define WRITE_BUFFER( _bufferType, _buffer )    \
    if ( m->_buffer.valid() )                   \
    {                                           \
        WRITE_I32( i );                         \
        WRITE_I32( _bufferType );               \
        WRITE_I32( m->_buffer->size() );        \
        WRITE( m->_buffer )                     \
    }

    // -- Write resident mesh buffers --
    for ( size_t i = 0; i < meshes.size(); i++ )
    {
        MeshData* m = meshes[i].get();

        WRITE_I32( i );
        switch ( m->indexBuffer->getType() )
        {
            case osg::PrimitiveSet::DrawElementsUBytePrimitiveType:
                WRITE_I32( BT_INDEX + ET_UBYTE );
                break;

            case osg::PrimitiveSet::DrawElementsUShortPrimitiveType:
                WRITE_I32( BT_INDEX + ET_USHORT );
                break;

            case osg::PrimitiveSet::DrawElementsUIntPrimitiveType:
                WRITE_I32( BT_INDEX + ET_UINT );
                break;

            default:
                throw std::runtime_error( "unsupported indexBuffer type?" );

        }
        WRITE_I32( m->getIndicesCount() );
        WRITE( m->indexBuffer );
        
        WRITE_BUFFER( BT_VERTEX, vertexBuffer );
        WRITE_BUFFER( BT_WEIGHT, weightBuffer );
        WRITE_BUFFER( BT_MATRIX_INDEX, matrixIndexBuffer );
    }

    // -- Write mesh buffers that will be freed after display list created --
    for ( size_t i = 0; i < meshes.size(); i++ )
    {
        MeshData* m = meshes[i].get();

        WRITE_BUFFER ( BT_NORMAL, normalBuffer );
        WRITE_BUFFER ( BT_TEX_COORD, texCoordBuffer );
        WRITE_BUFFER ( BT_TANGENT_AND_HANDEDNESS, tangentAndHandednessBuffer );
    }

#undef WRITE_BUFFER
}
Example #13
0
int main(int argc, char **argv)
{
    FILE *fh;
    struct Buffer_psl file;
    char *filenm = NULL, *arg;
    struct Buffer_psl psl;
    int i, dot;
    struct PSLAstNode *ast;

    GC_INIT();

    dot = 0;
    for (i = 1; i < argc; i++) {
        arg = argv[i];
        if (arg[0] == '-') {
            if (!strcmp(arg, "-d")) {
                dot = 1;
            } else {
                usage();
                return 1;
            }
        } else {
            filenm = arg;
        }
    }

    if (filenm == NULL) {
        usage();
        return 1;
    }

    /* load in the file */
    INIT_BUFFER(file);

    /* find the file */
    fh = fopen(filenm, "rb");
    if (fh == NULL) {
        perror(filenm);
        return 1;
    }

    /* read it */
    READ_FILE_BUFFER(file, fh);
    WRITE_BUFFER(file, "\0", 1);
    file.bufused--;
    fclose(fh);

    /* FIXME: bounds checking */

    /* check what type of file it is */
    psl = readPSLFile(file.bufused, file.buf);

    ast = pslToAst(psl.buf, psl.bufused);
    if (!dot) {
        dumpPSLAst(stdout, ast, 0);
    } else {
        printf("digraph {\nnodesep=0;\nranksep=0;\n");
        dumpPSLAstDot(stdout, ast);
        printf("}\n");
    }
    return 0;
}
Example #14
0
static GstFlowReturn
gst_tta_dec_chain (GstPad * pad, GstBuffer * in)
{
  GstTtaDec *ttadec;
  GstBuffer *outbuf, *buf = GST_BUFFER (in);
  guchar *data, *p;
  decoder *dec;
  unsigned long outsize;
  unsigned long size;
  guint32 frame_samples;
  long res;
  long *prev;

  ttadec = GST_TTA_DEC (GST_OBJECT_PARENT (pad));

  data = GST_BUFFER_DATA (buf);
  size = GST_BUFFER_SIZE (buf);

  ttadec->tta_buf.bit_count = 0;
  ttadec->tta_buf.bit_cache = 0;
  ttadec->tta_buf.bitpos = ttadec->tta_buf.buffer_end;
  ttadec->tta_buf.offset = 0;
  decoder_init (ttadec->tta, ttadec->channels, ttadec->bytes);

  if (GST_BUFFER_DURATION_IS_VALID (buf)) {
    frame_samples =
        ceil ((gdouble) (GST_BUFFER_DURATION (buf) * ttadec->samplerate) /
        (gdouble) GST_SECOND);
  } else {
    frame_samples = ttadec->samplerate * FRAME_TIME;
  }
  outsize = ttadec->channels * frame_samples * ttadec->bytes;

  dec = ttadec->tta;
  p = ttadec->decdata;
  prev = ttadec->cache;
  for (res = 0;
      p < ttadec->decdata + frame_samples * ttadec->channels * ttadec->bytes;) {
    unsigned long unary, binary, depth, k;
    long value, temp_value;
    fltst *fst = &dec->fst;
    adapt *rice = &dec->rice;
    long *last = &dec->last;

    // decode Rice unsigned
    get_unary (&ttadec->tta_buf, data, size, &unary);

    switch (unary) {
      case 0:
        depth = 0;
        k = rice->k0;
        break;
      default:
        depth = 1;
        k = rice->k1;
        unary--;
    }

    if (k) {
      get_binary (&ttadec->tta_buf, data, size, &binary, k);
      value = (unary << k) + binary;
    } else
      value = unary;

    switch (depth) {
      case 1:
        rice->sum1 += value - (rice->sum1 >> 4);
        if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1])
          rice->k1--;
        else if (rice->sum1 > shift_16[rice->k1 + 1])
          rice->k1++;
        value += bit_shift[rice->k0];
      default:
        rice->sum0 += value - (rice->sum0 >> 4);
        if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0])
          rice->k0--;
        else if (rice->sum0 > shift_16[rice->k0 + 1])
          rice->k0++;
    }

    /* this only uses a temporary variable to silence a gcc warning */
    temp_value = DEC (value);
    value = temp_value;

    // decompress stage 1: adaptive hybrid filter
    hybrid_filter (fst, &value);

    // decompress stage 2: fixed order 1 prediction
    switch (ttadec->bytes) {
      case 1:
        value += PREDICTOR1 (*last, 4);
        break;                  // bps 8
      case 2:
        value += PREDICTOR1 (*last, 5);
        break;                  // bps 16
      case 3:
        value += PREDICTOR1 (*last, 5);
        break;                  // bps 24
      case 4:
        value += *last;
        break;                  // bps 32
    }
    *last = value;

    if (dec < ttadec->tta + ttadec->channels - 1) {
      *prev++ = value;
      dec++;
    } else {
      *prev = value;
      if (ttadec->channels > 1) {
        long *r = prev - 1;

        for (*prev += *r / 2; r >= ttadec->cache; r--)
          *r = *(r + 1) - *r;
        for (r = ttadec->cache; r < prev; r++)
          WRITE_BUFFER (r, ttadec->bytes, p);
      }
      WRITE_BUFFER (prev, ttadec->bytes, p);
      prev = ttadec->cache;
      res++;
      dec = ttadec->tta;
    }
  }

  outbuf = gst_buffer_new_and_alloc (outsize);
  memcpy (GST_BUFFER_DATA (outbuf), ttadec->decdata, outsize);
  GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
  GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
  gst_buffer_set_caps (outbuf, GST_PAD_CAPS (ttadec->srcpad));
  return gst_pad_push (ttadec->srcpad, outbuf);
}
// Construct data with Report Type #20 data
static int ReadRawData(struct synaptics_ts_data *ts)
{
	int MaxArrayLength = RxChNum * TxChNum * 2;
	int i,j,k = 0;
	int result = LGTC_SUCCESS;
	u8 cap_data[MaxArrayLength];

	touch_i2c_read(ts->client, REPORT_DATA_REG, MaxArrayLength, cap_data);

	WRITE_BUFFER(f54_wlog_buf, "Full Raw Capacitance Test\n");
	WRITE_BUFFER(f54_wlog_buf, "\nInfo: Tx = %d Rx = %d \n", TxChNum, RxChNum);
	WRITE_BUFFER(f54_wlog_buf, "Image Data : \n");
	WRITE_BUFFER(f54_wlog_buf, "==========================================================================================================\n         :");

	for (i = 0; i < RxChNum; i++)
		WRITE_BUFFER(f54_wlog_buf, "%5d ", i);

	WRITE_BUFFER(f54_wlog_buf, "\n----------------------------------------------------------------------------------------------------------\n");

	for (i = 0; i < TxChNum; i++) {
		WRITE_BUFFER(f54_wlog_buf, "   %5d : ", i);
		for (j = 0; j < RxChNum; j++) {
			full_raw_data[i][j] = ((short)cap_data[k] | (short)cap_data[k+1] << 8);

			WRITE_BUFFER(f54_wlog_buf, "%5d ", full_raw_data[i][j]);
			k = k + 2;
		}
		WRITE_BUFFER(f54_wlog_buf, "\n");
	}
	WRITE_BUFFER(f54_wlog_buf, "------------------------------------------------------------------------------------------------------------\n");

	//Compare 2D area
	for (j = 0; j < RxChNum; j++) {
		for (i = 0; i < TxChNum; i++) {
			if ((full_raw_data[i][j] < LowerImageLimit[i][j]) || (full_raw_data[i][j] > UpperImageLimit[i][j])) {
				WRITE_BUFFER(f54_wlog_buf, "FAIL, %d,%d,%d\n", LowerImageLimit[i][j], UpperImageLimit[i][j], full_raw_data[i][j]);
				result = LGTC_FAIL;
				break;
			}
		}
	}

	if (result == LGTC_SUCCESS)
		WRITE_BUFFER(f54_wlog_buf, "\nFull Raw Capacitance Image Test passed.\n\n");
	else
		WRITE_BUFFER(f54_wlog_buf, "\nFull Raw Capacitance Image Test failed.\n\n");

	write_log(NULL, f54_wlog_buf);

	return result;
}
Example #16
0
void OnException(int signo)
{
    if (signo == SIGCHLD)
        return;


#define WRITE_STRING_LEN(STR, LEN) \
    do { \
        write(STDERR_FILENO, (STR), (LEN)); \
        if (fd) \
            write(fd, (STR), (LEN)); \
    } while(0)

#define WRITE_STRING(STR) \
    WRITE_STRING_LEN(STR, (sizeof(STR) - sizeof(STR[0])))

#define WRITE_BUFFER(BUFFER) \
    WRITE_STRING_LEN((BUFFER).buffer, (BUFFER).offset)

    MinimalBuffer buffer;

    int fd = 0;

    if (crashlog && (signo == SIGSEGV || signo == SIGABRT || signo == SIGKILL))
        fd = open(crashlog, O_WRONLY | O_CREAT | O_TRUNC, 0644);

    /* print signal info */
    BufferReset(&buffer);
    BufferAppendUInt64(&buffer, signo, 10);
    WRITE_STRING("=========================\n");
    WRITE_STRING("FCITX " VERSION " -- Get Signal No.: ");
    WRITE_BUFFER(buffer);
    WRITE_STRING("\n");

    /* print time info */
    time_t t = time(NULL);
    BufferReset(&buffer);
    BufferAppendUInt64(&buffer, t, 10);
    WRITE_STRING("Date: try \"date -d @");
    WRITE_BUFFER(buffer);
    WRITE_STRING("\" if you are using GNU date ***\n");

    /* print process info */
    BufferReset(&buffer);
    BufferAppendUInt64(&buffer, getpid(), 10);
    WRITE_STRING("ProcessID: ");
    WRITE_BUFFER(buffer);
    WRITE_STRING("\n");

#if defined(ENABLE_BACKTRACE)
#define BACKTRACE_SIZE 32
    void *array[BACKTRACE_SIZE] = {NULL, };

    int size = backtrace(array, BACKTRACE_SIZE);
    backtrace_symbols_fd(array, size, STDERR_FILENO);
    if (fd)
        backtrace_symbols_fd(array, size, fd);
#endif

    if (fd)
        close(fd);

    switch (signo) {
    case SIGKILL:
        break;
    case SIGABRT:
    case SIGSEGV:
    case SIGBUS:
    case SIGILL:
    case SIGFPE:
        exit(1);
        break;

    default:
        {
            if (!instance || !instance->initialized) {
                exit(1);
                break;
            }

            uint8_t sig = 0;
            if (signo < 0xff)
                sig = (uint8_t)(signo & 0xff);
            write(selfpipe[1], &sig, 1);
            signal(signo, OnException);
        }
        break;
    }
}
Example #17
0
static void unparsePrime(struct Buffer_char *buf,
                         struct Buffer_charp *filenames,
                         size_t *lastFile,
                         Node *node)
{
    size_t i;

    if (node->tok) {
        Token *tok = node->tok;

        if (tok->f != *lastFile) {
            /* first get out any comments that come before the final newline */
            char *fnl;
            fnl = tok->pre ? strrchr(tok->pre, '\n') : NULL;
            if (fnl)
                WRITE_BUFFER(*buf, tok->pre, fnl - tok->pre);

            /* we're in a different file, write a #line directive */
            if ((tok->f != (size_t) -1) && filenames) {
                char *lnum;
                SF(lnum, malloc, NULL, (4*sizeof(int) + 1));
                sprintf(lnum, "%d", (int) tok->l);

                WRITE_BUFFER(*buf, "\n#line ", 7);
                WRITE_BUFFER(*buf, lnum, strlen(lnum));
                free(lnum);
                WRITE_BUFFER(*buf, " \"", 2);
                if (tok->f < filenames->bufused) {
                    WRITE_BUFFER(*buf, filenames->buf[tok->f], strlen(filenames->buf[tok->f]));
                } else {
                    WRITE_BUFFER(*buf, "???", 3);
                }
                WRITE_BUFFER(*buf, "\"\n", 2);
            } else if (fnl) {
                WRITE_ONE_BUFFER(*buf, '\n');
            }

            *lastFile = tok->f;

            /* now write out the remainder of the comment */
            if (fnl) {
                WRITE_BUFFER(*buf, fnl + 1, strlen(fnl + 1));
            } else if (tok->pre) {
                WRITE_BUFFER(*buf, tok->pre, strlen(tok->pre));
            }

        } else if (tok->pre) {
            WRITE_BUFFER(*buf, tok->pre, strlen(tok->pre));
        }

        if (tok->tok)
            WRITE_BUFFER(*buf, tok->tok, strlen(tok->tok));
    }

    for (i = 0; node->children[i]; i++) {
        unparsePrime(buf, filenames, lastFile, node->children[i]);
    }
}