Ejemplo n.º 1
0
void fun_jmp_true ()
{
    register INT16 offs = getint16 (infile);

    if (istrue())
        fseek(infile, (INT32) offs, SEEK_CUR);
}
Ejemplo n.º 2
0
void fun_jmp ()
{
    INT16
        offs;

    offs = getint16 (infile);
    dumpint ( (UNS16) offs);
    printf ("jmp [%s]\n",
            hexstring ((size_t)(ftell(infile) + offs), 4));
}
Ejemplo n.º 3
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);
};
Ejemplo n.º 4
0
void Linker::read_atom(FILE* f, FILE* pFtarg)
{
   aBYTE buf[2];
   aINT16 temp, gatom;


   if (0 == fread(buf, 2, 1, f))
      aborteof(aS("read atom"));
   temp = getint16(buf);
   gatom = map_atom(temp);
   //fwrite(&gatom, 2, 1, pFtarg);
   write_int16(gatom, pFtarg);
}
Ejemplo n.º 5
0
Archivo: img.c Proyecto: rlk/scmtiff
static int getchan(const img *p, int i, int j, int k, float *f)
{
    const size_t s = ((size_t) p->w * i + j) * ((size_t) p->c) + k;

    if (p->b == 32)
    {
        return normf(p, getfloat(p, (const float *) p->p + s), f);
    }
    else if (p->b == 16)
    {
        if (p->g)
            return norms16(p,  getint16(p, (const int16_t  *) p->p + s), f);
        else
            return normu16(p, getuint16(p, (const uint16_t *) p->p + s), f);
    }
    else if (p->b ==  8)
    {
        if (p->g)
            return norms8(p, ((const  int8_t *) p->p)[s], f);
        else
            return normu8(p, ((const uint8_t *) p->p)[s], f);
    }
    return 0;
}
Ejemplo n.º 6
0
static int int2__recv (lua_State *L) {
  newint2(L, getint16(luaL_checkstring(L, 1)));
  return 1;
}
Ejemplo n.º 7
0
int Linker::read_code(FILE* f, FILE* pFtarg, long init_pos, int length, 
							 aBYTE* buf)
{
  aBYTE op;
  int   x;
#ifdef BUG_LINK
  int   i;
#endif
  
  while( init_pos < length)
    {
#ifdef BUG_LINK
      fprintf(lout, "\nstart length %d init_pos %d ", length, init_pos);
#endif
      if (0 == fread(buf, CODESIZE, 1, f))
        aborteof(aS("code"));
      ucFWRITE(buf, CODESIZE, 1, pFtarg);
      init_pos += CODESIZE;
      op = *buf;
#ifdef BUG_LINK
      fprintf(lout, "\nop %d, %s: ", (int) op, lops[op]);
#endif
      switch(op)
        {    
        case Ono_op:                           // no args 
        case Ofail:
        case Oproceed:
        case Odealloc:
        case Ocut:
        case Ocut64:
        case Otrust_me_else:
        case Ou_var_getlist:
        case Ounify_nil:
          break;
          
        case Ounify_y_var:                     // Xi or Yi 
        case Ounify_y_val:
        case Ounify_unsafe:
        case Oget_nil:
        case Oget_list:
        case Oput_nil:
        case Oput_list:
        case Ounify_x_var:
        case Ounify_x_val:
          if (0 == fread(buf, 2, 1, f))
            aborteof(aS("unify x val"));
          ucFWRITE(buf, 2, 1, pFtarg);
          init_pos += 2;
          break;
          
        case Oget_y_var:                       // Xi and Yi or Xj 
        case Oget_y_val:
        case Oput_y_var:
        case Oput_y_val:
        case Oput_unsafe:
        case Oget_x_var:
        case Oget_x_val:
        case Oput_x_var:
        case Oput_x_val:
          if (0 == fread(buf, 2, 2, f))
            aborteof(aS("put x val"));
          ucFWRITE(buf, 2, 2, pFtarg);
          init_pos += 4;
          break;
          
        case Ounify_void:                      // short int 
        case Oalloc:
        case Ocutd:
        case Oretry_me_else:
        case Oretry:
        case Otrust:
        case Ogoto:
        case Otrust_me_2_else:
        case Olabel:
          if (0 == fread(buf, 2, 1, f))
            aborteof(aS("label"));
          ucFWRITE(buf, 2, 1, pFtarg);
          init_pos += 2;
#ifdef BUG_LINK
          fprintf(lout, "%d", (int) getint16(buf));
#endif
          break;
          
        case Otry_me_else:
        case Otry_me_or_else:
        case Otry:                             // 2 short ints 
          if (0 == fread(buf, 2, 2, f))
            aborteof(aS("try"));
          ucFWRITE(buf, 2, 2, pFtarg);
          init_pos += 4;
#ifdef BUG_LINK
          fprintf(lout, "%d, %d", 
                  (int) getint16(buf), (int) getint16(buf+2));
#endif
          break;
          
        case Oget_con:                         // Constant, Xi 
        case Oput_con:
          read_const(f, pFtarg, &init_pos);
          if (0 == fread(buf, 2, 1, f))
            aborteof(aS("put con"));
          ucFWRITE(buf, 2, 1, pFtarg);
          init_pos += 2;
          break;
          
        case Oexec:
        case Oescape:
        case Ocall:                          
        case Omod_call:
        case Omod_exec:
        case Oget_struc:              // functor, arity, (Xi or short or null)
        case Oput_struc:
          read_atom(f, pFtarg);                // functor 
          init_pos += 2;
          if (op == Ocall || op == Oexec || op == Omod_call || op == Omod_exec)      // new style call/exec 
            {
              //if (0 == fread(buf, 2, 1, f)) 
              //  aborteof(aS("put struc"));
              //ucFWRITE(buf, 2, 1, pFtarg);
             // shouldn't this be a read atom, not just a buf??
             read_atom(f, pFtarg);
              init_pos += 2;
            }       
          
          if (0 == fread(buf, 2, 1, f))
            aborteof(aS("put struc 2"));
          ucFWRITE(buf, 2, 1, pFtarg);
          init_pos += 2;
#ifdef BUG_LINK
          fprintf(lout, "  arity = %d", (int) getint16(buf));
#endif
                                             // now figure third (optional arg 
          if (op == Oget_struc || 
              op == Oput_struc)                // Xi 
            {
              if (0 == fread(buf, 2, 1, f))
                aborteof(aS("put struc 3"));
              ucFWRITE(buf, 2, 1, pFtarg);
              init_pos += 2;
#ifdef BUG_LINK
          fprintf(lout, "  xi(get/put_struc) = %d", (int) getint16(buf));
#endif
            }
          else if (op == Ocall || op == Omod_call)                // short 
            {
              if (0 == fread(buf, 2, 1, f))
                aborteof(aS("put struc 4"));
              ucFWRITE(buf, 2, 1, pFtarg);
              init_pos += 2;
#ifdef BUG_LINK
          fprintf(lout, "  short(call/mod_call) = %d", (int) getint16(buf));
#endif
            }
                                              // else no 3rd arg 
          break;
          
        case Ounify_con:
          read_const(f, pFtarg, &init_pos);
          break;
          
          
        case Oswitch_on_term:
          if (0 == fread(buf, 2, 3, f))        // lab1, lab2, lab3 
            aborteof(aS("switch on term"));
          init_pos += 6;
          ucFWRITE(buf, 2, 3, pFtarg);
#ifdef BUG_LINK
          for (i=0; i<3; i++) 
            fprintf(lout, " %d ",(int) getint16(buf + 2 * i));
#endif
          break;
          
        case Oswitch_on_cons:           // short size, (size x |CELL|LABEL|) 
          if (0 == fread(buf, 2, 1, f))
            aborteof(aS("switch on cons"));
          ucFWRITE(buf, 2, 1, pFtarg);
          x = getint16(buf);
          init_pos += 2;
          while(x--)
            {       
              read_const(f, pFtarg, &init_pos); // get const 
              if (0 == fread(buf, 2, 1, f))     // branch label 
                aborteof(aS("switch on cons 2"));

#ifdef BUG_LINK

              fprintf(lout, " branch[%d] ", (int) getint16(buf));
#endif
              ucFWRITE(buf, 2, 1, pFtarg);
              init_pos += 2;
            }
          break;
          
        case Oswitch_on_struc:    // short size, (size x |NAME|ARITY|LABEL|) 
          if (0 == fread(buf, 2, 1, f))
            aborteof(aS("switch on struc"));
          ucFWRITE(buf, 2, 1, pFtarg);
          x = getint16(buf);
          init_pos += 2;
          while(x--)
            {       
              read_atom(f, pFtarg);
              if (0 == fread(buf, 2, 1, f)) // arity 
                aborteof(aS("switch on struc 2"));
              ucFWRITE(buf, 2, 1, pFtarg);
              
              if (0 == fread(buf, 2, 1, f))    // label 
                aborteof(aS("switch on struc 2"));

#ifdef BUG_LINK
              fprintf(lout, " branch[%d] ", (int) getint16(buf));

#endif
              ucFWRITE(buf, 2, 1, pFtarg);
              init_pos += 2 + 2 + 2;
            }
          break;
          
        default:
          abort_linker(aS("Error: Bad opcode in CodeStream %d"), op);
        }
#ifdef BUG_LINK
      fprintf(lout, "\nend length %d init_pos %d ", length, init_pos);
#endif
    }
  return(1);
}
Ejemplo n.º 8
0
/**
 * @fn      Datum reorg_swap(PG_FUNCTION_ARGS)
 * @brief   Swapping relfilenode of tables and relation ids of toast tables
 *          and toast indexes.
 *
 * reorg_swap(oid, relname)
 *
 * TODO: remove useless CommandCounterIncrement().
 *
 * @param	oid		Oid of table of target.
 * @retval			None.
 */
Datum
reorg_swap(PG_FUNCTION_ARGS)
{
	Oid				oid = PG_GETARG_OID(0);
	const char	   *relname = get_quoted_relname(oid);
	const char	   *nspname = get_quoted_nspname(oid);
	Oid 			argtypes[1] = { OIDOID };
	bool	 		nulls[1] = { 0 };
	Datum	 		values[1];
	SPITupleTable  *tuptable;
	TupleDesc		desc;
	HeapTuple		tuple;
	uint32			records;
	uint32			i;

	Oid				reltoastrelid1;
	Oid				reltoastidxid1;
	Oid				oid2;
	Oid				reltoastrelid2;
	Oid				reltoastidxid2;
	Oid				owner1;
	Oid				owner2;
	int16			natts1;
	int16			natts2;

	/* authority check */
	must_be_superuser("reorg_swap");

	/* connect to SPI manager */
	reorg_init();

	/* swap relfilenode and dependencies for tables. */
	values[0] = ObjectIdGetDatum(oid);
	execute_with_args(SPI_OK_SELECT,
		"SELECT X.reltoastrelid, TX.reltoastidxid, X.relowner,"
		"       Y.oid, Y.reltoastrelid, TY.reltoastidxid, Y.relowner,"
		"       X.relnatts, Y.relnatts"
		"  FROM pg_catalog.pg_class X LEFT JOIN pg_catalog.pg_class TX"
		"         ON X.reltoastrelid = TX.oid,"
		"       pg_catalog.pg_class Y LEFT JOIN pg_catalog.pg_class TY"
		"         ON Y.reltoastrelid = TY.oid"
		" WHERE X.oid = $1"
		"   AND Y.oid = ('reorg.table_' || X.oid)::regclass",
		1, argtypes, values, nulls);

	tuptable = SPI_tuptable;
	desc = tuptable->tupdesc;
	records = SPI_processed;

	if (records == 0)
		elog(ERROR, "reorg_swap : no swap target");

	tuple = tuptable->vals[0];

	reltoastrelid1 = getoid(tuple, desc, 1);
	reltoastidxid1 = getoid(tuple, desc, 2);
	owner1 = getoid(tuple, desc, 3);
	oid2 = getoid(tuple, desc, 4);
	reltoastrelid2 = getoid(tuple, desc, 5);
	reltoastidxid2 = getoid(tuple, desc, 6);
	owner2 = getoid(tuple, desc, 7);
	natts1 = getint16(tuple, desc, 8);
	natts2 = getint16(tuple, desc, 9);;

	/* change owner of new relation to original owner */
	if (owner1 != owner2)
	{
		ATExecChangeOwner(oid2, owner1, true, AccessExclusiveLock);
		CommandCounterIncrement();
	}

	/* swap tables. */
	swap_heap_or_index_files(oid, oid2);
	CommandCounterIncrement();

	/* swap indexes. */
	values[0] = ObjectIdGetDatum(oid);
	execute_with_args(SPI_OK_SELECT,
		"SELECT X.oid, Y.oid"
		"  FROM pg_catalog.pg_index I,"
		"       pg_catalog.pg_class X,"
		"       pg_catalog.pg_class Y"
		" WHERE I.indrelid = $1"
		"   AND I.indexrelid = X.oid"
		"   AND Y.oid = ('reorg.index_' || X.oid)::regclass",
		1, argtypes, values, nulls);

	tuptable = SPI_tuptable;
	desc = tuptable->tupdesc;
	records = SPI_processed;

	for (i = 0; i < records; i++)
	{
		Oid		idx1, idx2;

		tuple = tuptable->vals[i];
		idx1 = getoid(tuple, desc, 1);
		idx2 = getoid(tuple, desc, 2);
		swap_heap_or_index_files(idx1, idx2);

		CommandCounterIncrement();
	}

	/* swap names for toast tables and toast indexes */
	if (reltoastrelid1 == InvalidOid)
	{
		if (reltoastidxid1 != InvalidOid ||
			reltoastrelid2 != InvalidOid ||
			reltoastidxid2 != InvalidOid)
			elog(ERROR, "reorg_swap : unexpected toast relations (T1=%u, I1=%u, T2=%u, I2=%u",
				reltoastrelid1, reltoastidxid1, reltoastrelid2, reltoastidxid2);
		/* do nothing */
	}
	else if (reltoastrelid2 == InvalidOid)
	{
		char	name[NAMEDATALEN];

		if (reltoastidxid1 == InvalidOid ||
			reltoastidxid2 != InvalidOid)
			elog(ERROR, "reorg_swap : unexpected toast relations (T1=%u, I1=%u, T2=%u, I2=%u",
				reltoastrelid1, reltoastidxid1, reltoastrelid2, reltoastidxid2);

		/* rename X to Y */
		snprintf(name, NAMEDATALEN, "pg_toast_%u", oid2);
		RENAME_REL(reltoastrelid1, name);
		snprintf(name, NAMEDATALEN, "pg_toast_%u_index", oid2);
		RENAME_REL(reltoastidxid1, name);
		CommandCounterIncrement();
	}
	else if (reltoastrelid1 != InvalidOid)
	{
		char	name[NAMEDATALEN];
		int		pid = getpid();

		/* rename X to TEMP */
		snprintf(name, NAMEDATALEN, "pg_toast_pid%d", pid);
		RENAME_REL(reltoastrelid1, name);
		snprintf(name, NAMEDATALEN, "pg_toast_pid%d_index", pid);
		RENAME_REL(reltoastidxid1, name);
		CommandCounterIncrement();

		/* rename Y to X */
		snprintf(name, NAMEDATALEN, "pg_toast_%u", oid);
		RENAME_REL(reltoastrelid2, name);
		snprintf(name, NAMEDATALEN, "pg_toast_%u_index", oid);
		RENAME_REL(reltoastidxid2, name);
		CommandCounterIncrement();

		/* rename TEMP to Y */
		snprintf(name, NAMEDATALEN, "pg_toast_%u", oid2);
		RENAME_REL(reltoastrelid1, name);
		snprintf(name, NAMEDATALEN, "pg_toast_%u_index", oid2);
		RENAME_REL(reltoastidxid1, name);
		CommandCounterIncrement();
	}

	/* drop reorg trigger */
	execute_with_format(
		SPI_OK_UTILITY,
		"DROP TRIGGER IF EXISTS z_reorg_trigger ON %s.%s CASCADE",
		nspname, relname);

	/* Note, this trigger will not exist if working against 9.0 or earlier,
	 * but that's what IF EXISTS is for.
	 */
	execute_with_format(
	    SPI_OK_UTILITY,
	    "DROP TRIGGER IF EXISTS z_reorg_forbid_truncate ON %s.%s CASCADE",
	    nspname, relname);

	SPI_finish();

	PG_RETURN_VOID();
}