Exemple #1
0
inline void exchange_vars(char *lhs, char *rhs, char *err)
{
    /*
     * Variable Exchange Function, swaps the value
     * stored in two variable lhs & rhs. If they
     * don't exist error message is stored in *err,
     * and function is returned.
     * ------------------------------------------------
     * WARNING: Strings *rhs and *lhs are subject to
     * changes, forget them after calling this function.
     */
    rhs++; /* to avoid '>' */
    trims(rhs,' ');
    /* now exchange */
    int32 *value = getint32(rhs);
    if(value!=NULL) {
        /* okay, rhs is valid */
        int32 rvalue = *value;
        value = getint32(lhs);
        if(value!=NULL) {
            /* now swap the values */
            * getint32(rhs) = * value;
            * value = rvalue;
            printf("%s => %s\n",lhs,rhs);
        } else
            sprintf(err,"LHS Variable '%s' does not exist.",lhs);
    } else
        sprintf(err,"RHS Variable '%s' does not exist.",rhs);
}
Exemple #2
0
int32 * lex_int32(const char *str, int32 *value)
{
    /*   Abstract Lexical Analysis Function
     *  ------------------------------------
     *  lex peforms abstract lexical analysis.
     *  It accepts abstract entities, such as
     *  function calls, variable names, e.t.c
     *  for analysis. Assignment operations,
     *  definitions, declarations, constants
     *  (strings, numbers,..) are NOT accepted.
     *
     *  First it analyses a string, and finds
     *  out it's value (if there exists one).
     *  The value should be a int32. If not,
     *  then it will be typecasted to int32.
     *
     *  If *str describes some pointable matter
     *  (eg. variable names), then a pointer to
     *  the variable is returned and the int32
     *  pointed to by *lex is give it's value.
     *
     *  If the *str describes volatile matter
     *  (eg. functions returns), then it is
     *  evaluated & stored in the variable
     *  pointed at by *lex.
     *
     *  Whereas if no value can be found, a
     *  description of the error is written
     *  into *err & the NULL is returned.
     */
    *value = (getint32(str)==NULL) ? 0:*getint32(str);
    return (getint32(str)==NULL) ? NULL : getint32(str);

    return NULL;
}
Exemple #3
0
int32 * newint32(const char *id)
{
    /*  This function creates a new integer
     *  whose name is defined by the string *id,
     *  and returns an integer pointer to it.
    **/
    /*  --- WARNING --- [ CHECK *id VALIDITY BEFORE PASSING ]
     * newint() does not check the validity of variable names,
     * _even_ null variable names, are accepted. The caller
     * should check the validity of the string being passed.
     */
    /* check if a variable with the same name exists */
    if((getint32(id))!=NULL) return NULL;
    struct int32_table_struct * table_ptr;
    /* increment table size by 1 for 1 new variable */
    int32_table_size += 1;
    /* reallocate table structure with new size */
    if((table_ptr = (struct int32_table_struct *)
                    realloc (int32_table, sizeof(struct int32_table_struct)*
                             int32_table_size))==NULL) msg(system_no_mem,3);
    else /* set the variable */
        int32_table = table_ptr;
    /* set the variable name */
    int32_table[int32_table_size-1].ids = clones(id);
    /* initiaze the variable to 0 */
    int32_table[int32_table_size-1].var = 0;
    /* return a pointer to the variable */
    return &int32_table[int32_table_size-1].var;
}
Exemple #4
0
int32 * lex_int32(const char *str, int32 *value)
{
	/*   Abstract Lexical Analysis Function
	 *  ------------------------------------
	 *  lex peforms abstract lexical analysis.
	 *  It accepts abstract entities, such as
	 *  function calls, variable names, e.t.c
	 *  for analysis. Assignment operations,
	 *  definitions, declarations, constants
	 *  (strings, numbers,..) are NOT accepted.
	 *
	 *  First it analyses a string, and finds
	 *  out it's value (if there exists one).
	 *  The value should be a int32. If not,
	 *  then it will be typecasted to int32.
	 *
	 *  If *str describes some pointable matter
	 *  (eg. variable names), then a pointer to
	 *  the variable is returned and the int32
	 *  pointed to by *lex is give it's value.
	 *
	 *  If the *str describes volatile matter
	 *  (eg. functions returns), then it is
	 *  evaluated & stored in the variable
	 *  pointed at by *lex.
	 *
	 *  Whereas if no value can be found, a
	 *  description of the error is written
	 *  into *err & the NULL is returned.
	 */

	// <-------------- NOT COMPLETED ------------------>

	/* junk: , delete this code... */
	*value = (getint32(str)==NULL) ? 0:*getint32(str);
	const char fn_sqrt[] = "sqrt";
	if(!strncmp(str,fn_sqrt,strlen(fn_sqrt))) {
		str +=  strlen(fn_sqrt);
		for(;(*str<='0'||*str>='9')&&str!='\0';str++);
		*value = atoi(str); printf("\n%s -> %ld\n",
		fn_sqrt,*value); *value = (int32) sqrt(*value);
	} return (getint32(str)==NULL) ? NULL : getint32(str);

	// <-------------- NOT COMPLETED ------------------>
}
Exemple #5
0
void Archive::Open(IO::Stream* stream)
{
	m_p->m_stream = stream;

	TRY
	{
		uint32 signature;
		while ((signature = getint32()) == 0x04034b50)
		{
			File* file = new File(this);

			file->m_bytepos = m_p->m_stream->GetPosition();

			uint16 version_needed_to_extract = getshort();//       2 bytes
			uint16 general_purpose_bit_flag = getshort();//        2 bytes
			file->m_compression_method = getshort();//              2 bytes
			uint16 last_mod_file_time = getshort();//              2 bytes
			uint16 last_mod_file_date = getshort();//              2 bytes
			file->m_crc_32 = getint32();//                          4 bytes
			file->m_compressed_size = getint32();//                 4 bytes
			file->m_uncompressed_size = getint32();//               4 bytes
			uint16 file_name_length = getshort();//                2 bytes
			uint16 extra_field_length = getshort();//              2 bytes

			file->m_name = String(string_alloc<char>(file_name_length));
			m_p->m_stream->Read(file->m_name.GetData8(), file_name_length);

			m_p->m_stream->Seek(extra_field_length, IO::STREAM_SEEK_CUR);

			file->m_dataoffset = m_p->m_stream->GetPosition() - file->m_bytepos;
			m_p->m_stream->Seek(file->m_compressed_size, IO::STREAM_SEEK_CUR);

			m_p->m_filesByName[file->m_name] = file;
			m_p->m_files.push_back(file);
		}

		while (signature == 0x02014b50)
		{
			signature = getint32();
		}
	}
	CATCH (Exception* e)
	{
	}
}
Exemple #6
0
void exec(const char *str)
{
	int32 strn = 0;
	/* check validity of equation in number of brackets */
	int32 brackets = 0;
	for(;*str!='\0';str++,strn++) {
		if(*str=='(')
			brackets++;
		else if(*str==')')
			brackets--;
	} if(brackets!=0) {
		strcpy(lisp_error,"Invalid Syntax, incorrect number of parentheses.");
		return; }
	str -= strn;

	char *lhs = allocs(strn);
	char *rhs = allocs(strn);
	/* here the rhs & lhs are obtained */
	{
	char *sptr = NULL;  /* sptr points at const *str */
	for(sptr=lhs;*str!='\0'&&*str!='=';str++)
		*sptr++ = *str;
	*sptr = '\0';
	if(*str=='=') {
		for(sptr=rhs,str++;*str!='\0';str++)
		{ *sptr++ = *str;
		  *sptr = '\0'; }
	} else { *rhs = '\0'; }
	trims(lhs,' ');
	}

	if(*rhs=='\0') { /* <- empty rhs, so no assignment involved. */

		/* check if rhs is a variable */
		int32 *value = NULL;
		value = getint32(lhs);

		if(value==NULL) {
			/* rhs is NOT a variable */
			int32 val=0;
			eval_int32(lhs,&val);
			printf("\n%ld\n",val);
		}
		else printf("%s = %ld\n",lhs,*value);
	} else { /* rhs exists  */
		/* check for [=>] exchange directive */
		if(*rhs=='>')
			exchange_vars(lhs,rhs,lisp_error);
		else { /* variable creation/assignment */
			void asgn(char *rhs, char *lhs);
			asgn(rhs,lhs);
		}
	}
	/* free memeory */
	free(lhs);
	free(rhs);
}
Exemple #7
0
int MIDIFile::parsemidifile(MIDIEvents *me_){
    this->me=me_;

    //read the header
    int chunk=getint32();//MThd
    if (chunk!=0x4d546864) return(-1);
    int size=getint32();
    if (size!=6) return(-1);//header is always 6 bytes long


    int format=getint16();
    printf("format %d\n",format);

    int ntracks=getint16();//this is always 1 if the format is "0"
    printf("ntracks %d\n",ntracks);

    int division=getint16();
    printf("division %d\n",division);
    if (division>=0){//delta time units in each a quater note
//	tick=???;
    } else {//SMPTE (frames/second and ticks/frame)
	printf("ERROR:in MIDIFile.C::parsemidifile() - SMPTE not implemented yet.");
    };    
    
    if (ntracks>=NUM_MIDI_TRACKS) ntracks=NUM_MIDI_TRACKS-1;
    
    for (int n=0;n<ntracks;n++){
	if (parsetrack(n)<0) {
	    clearmidifile();
	    return(-1);
	};
    };

    printf("\n\nCURRENT File position is = 0x%x\n",midifilek);
    printf("\nMIDI file succesfully parsed.\n");
//    printf("\n0x%x\n",getbyte());

    this->me=NULL;
    return(0);
};
Exemple #8
0
int wrap_getint32(const char *s, int32_t *valp)
{
    struct protstream *prot;
    char *b;
    int c;

    b = xstrdup(s);	/* work around bug in prot_ungetc */
    prot = prot_readmap(b, strlen(b));
    *valp = CANARY;
    c = getint32(prot, valp);
    free(b);
    prot_free(prot);

    return c;
}
Exemple #9
0
void asgn(char *rhs, char *lhs)
{
    /*
     * Variable Assignment Function;
     * perfroms a variable assignment
     * on var with names rhs & lhs, then
     * does the appropriate post-evaluation
     * operations and if errored, then gives
     * a description about the error in *err.
     * ------------------------------------------------
     * WARNING: Strings *rhs and *lhs are subject to
     * changes, forget them after calling this function.
     */

    int32 *value = NULL;
    int32 rvalue = 0;

    /* to find assignment operator */
    char esymbol=0;
    rvalue=strlen(lhs)-1;
    lhs += rvalue;

    /* now find the assignment operator */
    if(*lhs=='*'||*lhs=='/'||
            *lhs=='+'||*lhs=='-'||
            *lhs=='%'||*lhs=='^'||
            *lhs=='~'||*lhs==':'||
            *lhs=='<'||*lhs=='>'||
            *lhs=='|'||*lhs=='&'||
            *lhs=='!'||*lhs=='=') {
        esymbol = *lhs;
        *lhs = '\0';
    } /* set lhs ptr to origin */
    lhs -= rvalue;
    /* evaluate rhs */
    eval_int32(rhs,&rvalue);
    value = newint32(lhs);
    /* if variable elready exists, get it. */
    if(value==NULL)
        value = getint32(lhs);
    /* set the value */
    if(value!=NULL)
        mov_int32(value,&rvalue,esymbol);
    else  /* getint32() hasn't worked properly */
        strcpy(lisp_error,"Fatal Data Transfer Error.");
    printf("%s = %ld\n",lhs,*value);
}
Exemple #10
0
void proxy_copy(const char *tag, char *sequence, char *name, int myrights,
                int usinguid, struct backend *s)
{
    char mytag[128];
    struct d {
        char *idate;
        char *flags;
        unsigned int seqno, uid;
        struct d *next;
    } *head, *p, *q;
    int c;

    /* find out what the flags & internaldate for this message are */
    proxy_gentag(mytag, sizeof(mytag));
    prot_printf(backend_current->out,
                "%s %s %s (Flags Internaldate)\r\n",
                tag, usinguid ? "Uid Fetch" : "Fetch", sequence);
    head = (struct d *) xmalloc(sizeof(struct d));
    head->flags = NULL; head->idate = NULL;
    head->seqno = head->uid = 0;
    head->next = NULL;
    p = head;
    /* read all the responses into the linked list */
    for (/* each FETCH response */;;) {
        unsigned int seqno = 0, uidno = 0;
        char *flags = NULL, *idate = NULL;

        /* read a line */
        c = prot_getc(backend_current->in);
        if (c != '*') break;
        c = prot_getc(backend_current->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        /* check for OK/NO/BAD/BYE response */
        if (!isdigit(c = prot_getc(backend_current->in))) {
            prot_printf(imapd_out, "* %c", c);
            pipe_to_end_of_response(backend_current, 0);
            continue;
        }

        /* read seqno */
        prot_ungetc(c, backend_current->in);
        c = getuint32(backend_current->in, &seqno);
        if (seqno == 0 || c != ' ') {
            /* we suck and won't handle this case */
            c = EOF; break;
        }
        c = chomp(backend_current->in, "fetch (");
        if (c == EOF) {
            c = chomp(backend_current->in, "exists\r");
            if (c == '\n') { /* got EXISTS response */
                prot_printf(imapd_out, "* %d EXISTS\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) {
            /* XXX  the "exists" check above will eat "ex" */
            c = chomp(backend_current->in, "punge\r");
            if (c == '\n') { /* got EXPUNGE response */
                prot_printf(imapd_out, "* %d EXPUNGE\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) {
            c = chomp(backend_current->in, "recent\r");
            if (c == '\n') { /* got RECENT response */
                prot_printf(imapd_out, "* %d RECENT\r\n", seqno);
                continue;
            }
        }
        /* huh, don't get this response */
        if (c == EOF) break;
        for (/* each fetch item */;;) {
            /* looking at the first character in an item */
            switch (c) {
            case 'f': case 'F': /* flags? */
                c = chomp(backend_current->in, "lags");
                if (c != ' ') { c = EOF; }
                else c = prot_getc(backend_current->in);
                if (c != '(') { c = EOF; }
                else {
                    flags = grab(backend_current->in, ')');
                    c = prot_getc(backend_current->in);
                }
                break;
            case 'i': case 'I': /* internaldate? */
                c = chomp(backend_current->in, "nternaldate");
                if (c != ' ') { c = EOF; }
                else c = prot_getc(backend_current->in);
                if (c != '"') { c = EOF; }
                else {
                    idate = grab(backend_current->in, '"');
                    c = prot_getc(backend_current->in);
                }
                break;
            case 'u': case 'U': /* uid */
                c = chomp(backend_current->in, "id");
                if (c != ' ') { c = EOF; }
                else c = getuint32(backend_current->in, &uidno);
                break;
            default: /* hmm, don't like the smell of it */
                c = EOF;
                break;
            }
            /* looking at either SP seperating items or a RPAREN */
            if (c == ' ') { c = prot_getc(backend_current->in); }
            else if (c == ')') break;
            else { c = EOF; break; }
        }
        /* if c == EOF we have either a protocol error or a situation
           we can't handle, and we should die. */
        if (c == ')') c = prot_getc(backend_current->in);
        if (c == '\r') c = prot_getc(backend_current->in);
        if (c != '\n') {
            c = EOF;
            free(flags);
            free(idate);
            break;
        }

        /* if we're missing something, we should echo */
        if (!flags || !idate) {
            char sep = '(';
            prot_printf(imapd_out, "* %d FETCH ", seqno);
            if (uidno) {
                prot_printf(imapd_out, "%cUID %d", sep, uidno);
                sep = ' ';
            }
            if (flags) {
                prot_printf(imapd_out, "%cFLAGS %s", sep, flags);
                sep = ' ';
            }
            if (idate) {
                prot_printf(imapd_out, "%cINTERNALDATE %s", sep, flags);
                sep = ' ';
            }
            prot_printf(imapd_out, ")\r\n");
            if (flags) free(flags);
            if (idate) free(idate);
            continue;
        }

        /* add to p->next */
        p->next = xmalloc(sizeof(struct d));
        p = p->next;
        p->idate = idate;
        p->flags = editflags(flags);
        p->uid = uidno;
        p->seqno = seqno;
        p->next = NULL;
    }
    if (c != EOF) {
        prot_ungetc(c, backend_current->in);

        /* we should be looking at the tag now */
        pipe_until_tag(backend_current, tag, 0);
    }
    if (c == EOF) {
        /* uh oh, we're not happy */
        fatal("Lost connection to selected backend", EC_UNAVAILABLE);
    }

    /* start the append */
    prot_printf(s->out, "%s Append {" SIZE_T_FMT "+}\r\n%s",
                tag, strlen(name), name);
    prot_printf(backend_current->out, "%s %s %s (Rfc822.peek)\r\n",
                mytag, usinguid ? "Uid Fetch" : "Fetch", sequence);
    for (/* each FETCH response */;;) {
        unsigned int seqno = 0, uidno = 0;

        /* read a line */
        c = prot_getc(backend_current->in);
        if (c != '*') break;
        c = prot_getc(backend_current->in);
        if (c != ' ') { /* protocol error */ c = EOF; break; }

        /* check for OK/NO/BAD/BYE response */
        if (!isdigit(c = prot_getc(backend_current->in))) {
            prot_printf(imapd_out, "* %c", c);
            pipe_to_end_of_response(backend_current, 0);
            continue;
        }

        /* read seqno */
        prot_ungetc(c, backend_current->in);
        c = getuint32(backend_current->in, &seqno);
        if (seqno == 0 || c != ' ') {
            /* we suck and won't handle this case */
            c = EOF; break;
        }
        c = chomp(backend_current->in, "fetch (");
        if (c == EOF) { /* not a fetch response */
            c = chomp(backend_current->in, "exists\r");
            if (c == '\n') { /* got EXISTS response */
                prot_printf(imapd_out, "* %d EXISTS\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) { /* not an exists response */
            /* XXX  the "exists" check above will eat "ex" */
            c = chomp(backend_current->in, "punge\r");
            if (c == '\n') { /* got EXPUNGE response */
                prot_printf(imapd_out, "* %d EXPUNGE\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) { /* not an exists response */
            c = chomp(backend_current->in, "recent\r");
            if (c == '\n') { /* got RECENT response */
                prot_printf(imapd_out, "* %d RECENT\r\n", seqno);
                continue;
            }
        }
        if (c == EOF) {
            /* huh, don't get this response */
            break;
        }
        /* find seqno in the list */
        p = head;
        while (p->next && seqno != p->next->seqno) p = p->next;
        if (!p->next) break;
        q = p->next;
        p->next = q->next;
        for (/* each fetch item */;;) {
            int sz = 0;

            switch (c) {
            case 'u': case 'U':
                c = chomp(backend_current->in, "id");
                if (c != ' ') { c = EOF; }
                else c = getuint32(backend_current->in, &uidno);
                break;

            case 'r': case 'R':
                c = chomp(backend_current->in, "fc822");
                if (c == ' ') c = prot_getc(backend_current->in);
                if (c != '{') {
                    /* NIL? */
                    eatline(backend_current->in, c);
                    c = EOF;
                }
                else c = getint32(backend_current->in, &sz);
                if (c == '}') c = prot_getc(backend_current->in);
                if (c == '\r') c = prot_getc(backend_current->in);
                if (c != '\n') c = EOF;

                if (c != EOF) {
                    /* append p to s->out */
                    prot_printf(s->out, " (%s) \"%s\" {%d+}\r\n",
                                q->flags, q->idate, sz);
                    while (sz) {
                        char buf[2048];
                        int j = (sz > (int) sizeof(buf) ?
                                 (int) sizeof(buf) : sz);

                        j = prot_read(backend_current->in, buf, j);
                        if(!j) break;
                        prot_write(s->out, buf, j);
                        sz -= j;
                    }
                    c = prot_getc(backend_current->in);
                }

                break; /* end of case */
            default:
                c = EOF;
                break;
            }
            /* looking at either SP seperating items or a RPAREN */
            if (c == ' ') { c = prot_getc(backend_current->in); }
            else if (c == ')') break;
            else { c = EOF; break; }
        }

        /* if c == EOF we have either a protocol error or a situation
           we can't handle, and we should die. */
        if (c == ')') c = prot_getc(backend_current->in);
        if (c == '\r') c = prot_getc(backend_current->in);
        if (c != '\n') { c = EOF; break; }

        /* free q */
        free(q->idate);
        free(q->flags);
        free(q);
    }
    if (c != EOF) {
        char *appenduid, *b;
        int res;

        /* pushback the first character of the tag we're looking at */
        prot_ungetc(c, backend_current->in);

        /* nothing should be left in the linked list */
        assert(head->next == NULL);

        /* ok, finish the append; we need the UIDVALIDITY and UIDs
           to return as part of our COPYUID response code */
        prot_printf(s->out, "\r\n");

        /* should be looking at 'mytag' on 'backend_current',
           'tag' on 's' */
        pipe_until_tag(backend_current, mytag, 0);
        res = pipe_until_tag(s, tag, 0);

        if (res == PROXY_OK) {
            if (myrights & ACL_READ) {
                appenduid = strchr(s->last_result.s, '[');
                /* skip over APPENDUID */
                if (appenduid) {
                    appenduid += strlen("[appenduid ");
                    b = strchr(appenduid, ']');
                    if (b) *b = '\0';
                    prot_printf(imapd_out, "%s OK [COPYUID %s] %s\r\n", tag,
                                appenduid, error_message(IMAP_OK_COMPLETED));
                }
                else
                    prot_printf(imapd_out, "%s OK %s\r\n", tag, s->last_result.s);
            }
            else {
                prot_printf(imapd_out, "%s OK %s\r\n", tag,
                            error_message(IMAP_OK_COMPLETED));
            }
        } else {
            prot_printf(imapd_out, "%s %s", tag, s->last_result.s);
        }
    } else {
        /* abort the append */
        prot_printf(s->out, " {0+}\r\n\r\n");
        pipe_until_tag(backend_current, mytag, 0);
        pipe_until_tag(s, tag, 0);

        /* report failure */
        prot_printf(imapd_out, "%s NO inter-server COPY failed\r\n", tag);
    }

    /* free dynamic memory */
    while (head) {
        p = head;
        head = head->next;
        if (p->idate) free(p->idate);
        if (p->flags) free(p->flags);
        free(p);
    }
}
Exemple #11
0
void vals_int32(const char *str, int32 * const value)
{
    /*     Elementry Evaluator (int32)
     *   ==============================
     *  This function evaluates, the int32
     *    value of an exprssion element.
     *  Operations ~,!,!! and factorial are carried
     *  out here. Function calls are made and
     *  values of variables are retrieved too.
     *  ---------------------------------------
     *   Note: *str sould be trimmed of spaces
     *   before being passed here.
     */
    *value = 0;

    /* Out the 4 operations (!,!!,~,fact),
     * only 3 operations ~,! and !! appear
     * on L.H.S. of str, where ! and !! can
     * never coincide, but ~ can coincide with
     * the other two. These operations can be
     * permuted in the following ways:
     * ----------------------
     *  nothing    -> 0
     *  !  only    -> 1
     *  !! only    -> 2
     *  ~  only    -> 3
     *  ~ and !    -> 4
     *  ~ and !!   -> 5
     * - - - - - - - - - - - -
     * in case factorial needs
     * to be found then add 10:
     * - - - - - - - - - - - -
     *  nothing    -> 10
     *  !  only    -> 11
     *  !! only    -> 12
     *  ~  only    -> 13
     *  ~ and !    -> 14
     *  ~ and !!   -> 15
     * ----------------------
     * The number is kept in ops.
     */
    uchar ops = 0;

    /* now find ops */
    if(*str=='~'||*str=='!') {
        if(*str++=='~') {
            ops += 3;
            if(*str++=='!') {
                ops++;
                if(*str=='!')
                {
                    ops++;
                    str++;
                }
            } else str--;
        } else { /* (*str=='!') */
            ops++;
            if(*str++=='!') ops++;
            else str--;
        }
    }
    if(str[strlen(str)-1]=='!')
        ops += 10;
    printf("lex: %s -> %d\n",str,ops);

    /* extract the value */
    if(!strncmp(str,"0x",2))
        sscanf(str,"%lx",value);
    else if((*str>='0'&&*str<='9')||
            (*str=='-'&&str[1]>='0'&&str[1]<='9'))
        *value = atol(str);
    else {
        /* get the value */
        //*value = (getint32(str)==NULL) ? 0:*getint32(str);
        lex_int32(str, value);
        /* now operate on the value */
        if(ops==1||ops==2||ops==4||ops==5||
                ops==11||ops==12||ops==14||ops==15) {
            /* nullify variable */
            int32 *tmp;
            tmp = getint32(str);
            if(tmp!=NULL)
                *tmp = 0;
        }
        else if(ops==2||ops==5||
                ops==12||ops==15) {
            /* destroy variable */
        }
    }
    /* find factorial & complement if needed */
    if(ops>=10) {
        *value = factorial(*value);
        ops -= 10;
    }
    if(ops>=3)
        *value = ~*value;
}
Exemple #12
0
int MIDIFile::parsetrack(int ntrack){
    printf("\n--==*Reading track %d **==--\n",ntrack);

    int chunk=getint32();//MTrk
    if (chunk!=0x4d54726b) return(-1);

    int size=getint32();
    printf("size = %d\n",size);

    int oldmidifilek=midifilek;

    unsigned char lastmsg=0;
    unsigned int dt=0;
    
    while(!midieof){
	unsigned int msgdeltatime=getvarint32();
	
///	printf("MSGDELTATIME = %d\n",msgdeltatime);
	
//	dt+=msgdeltatime;

	int msg=peekbyte();
///	printf("raw msg=0x%x     ",msg);
	if (msg<0x80) {
	    msg=lastmsg;
	} else {
	    lastmsg=msg;
	    getbyte();
	};  
///	printf("msg=0x%x\n",msg);

//	dt+=msgdeltatime;
	add_dt(ntrack, msgdeltatime);
	
	unsigned int mtype,mlength;
	/*
	switch(msg)
	{
	    case 0x80 ... 0x8f: //note on off
		    parsenoteoff(ntrack,msg & 0x0f,dt);
		    dt=0;
			break;
	    case 0x90 ... 0x9f: //note on (or note off)
		    parsenoteon(ntrack,msg & 0x0f,dt);
		    dt=0;
			break;
	    case 0xa0 ... 0xaf: //aftertouch - ignored
		    skipnbytes(2);
			break;
	    case 0xb0 ... 0xbf: //control change
		    parsecontrolchange(ntrack,msg & 0x0f,dt);
		    dt=0;
			break;
	    case 0xc0 ... 0xcf: //program change - ignored
		    skipnbytes(1);
			break;
	    case 0xd0 ... 0xdf: //channel pressure - ignored
		    skipnbytes(1);
			break;
	    case 0xe0 ... 0xef: //channel mode messages
		    skipnbytes(2);
			break;
	    case 0xf0: //sysex - ignored
			while (getbyte()!=0xf7)
			{
				if (midieof) break;
			};
			break;
	    case 0xf7: //sysex (another type) - ignored
			skipnbytes(getvarint32());
			break;
	    case 0xff: //meta-event
			mtype=getbyte();
			mlength=getbyte();
			parsemetaevent(mtype,mlength);
  			break;
	    default:
			getbyte();
			printf("UNKNOWN message! 0x%x\n",msg);
			return(-1);
  			break;
	};
	*/
	switch(msg & 0x0f)
	{
	    case 0x80: //note on off
		    parsenoteoff(ntrack,msg & 0x0f,dt);
		    dt=0;
			break;
	    case 0x90: //note on (or note off)
		    parsenoteon(ntrack,msg & 0x0f,dt);
		    dt=0;
			break;
	    case 0xa0: //aftertouch - ignored
		    skipnbytes(2);
			break;
	    case 0xb0: //control change
		    parsecontrolchange(ntrack,msg & 0x0f,dt);
		    dt=0;
			break;
	    case 0xc0: //program change - ignored
		    skipnbytes(1);
			break;
	    case 0xd0: //channel pressure - ignored
		    skipnbytes(1);
			break;
	    case 0xe0: //channel mode messages
		    skipnbytes(2);
			break;
	    case 0xf0: //sysex - ignored
			while (getbyte()!=0xf7)
			{
				if (midieof) break;
			};
			break;
	    case 0xf7: //sysex (another type) - ignored
			skipnbytes(getvarint32());
			break;
	    case 0xff: //meta-event
			mtype=getbyte();
			mlength=getbyte();
			parsemetaevent(mtype,mlength);
  			break;
	    default:
			getbyte();
			printf("UNKNOWN message! 0x%x\n",msg);
			return(-1);
  			break;
	};


	
	if (midieof) return(-1);

	if ((midifilek-oldmidifilek)==size) break;
	    else if((midifilek-oldmidifilek)>size) return(-1);
//    if (size!=6) return(-1);//header is always 6 bytes long
    };

    printf("End Track\n\n");

    return(0);
};