Пример #1
0
int
libnet_insert_ipo(struct ipoption *opt, u_char opt_len, u_char *buf)
{
    struct libnet_ip_hdr *ip_hdr;
    u_char *p;
    u_short s, j;
    u_char i;

    if (!buf)
    {
        return (-1);
    }

    ip_hdr = (struct libnet_ip_hdr *)(buf);
    s = UNFIX(ip_hdr->ip_len);

    if ((s + opt_len) > IP_MAXPACKET)
    {
        /*
         *  Nope.  Too big.
         */
#if (__DEBUG)
        libnet_error(LIBNET_ERR_WARNING,
                     "insert_ipo: options list would result in too large of a packet\n");
#endif
        return (-1);
    }

    /*
     *  Do we have more then just an IP header?
     */
    if (s > LIBNET_IP_H)
    {
        /*
         *  Move over whatever's in the way.
         */
        memmove((u_char *)ip_hdr + LIBNET_IP_H + opt_len, (u_char *)ip_hdr
                + LIBNET_IP_H, opt_len);
    }

    /*
     *  Copy over option list.  We rely on the programmer having been
     *  smart enough to allocate enough heap memory here.  Uh oh.
     */
    p = (u_char *)ip_hdr + LIBNET_IP_H;
    memcpy(p, opt->ipopt_list, opt_len);

    /*
     *  Count up number of 32-bit words in options list, padding if
     *  neccessary.
     */
    for (i = 0, j = 0; i < opt_len; i++) (i % 4) ? j : j++;

    ip_hdr->ip_hl   += j;
    ip_hdr->ip_len  = FIX(opt_len + s);

    return (1);
}
Пример #2
0
static ptr eval(ptr x) {
  if (Spairp(x)) {
    switch (Schar_value(Scar(x))) {
      case '+': return S_add(First(x), Second(x));
      case '-': return S_sub(First(x), Second(x));
      case '*': return S_mul(First(x), Second(x));
      case '/': return S_div(First(x), Second(x));
      case 'q': return S_trunc(First(x), Second(x));
      case 'r': return S_rem(First(x), Second(x));
      case 'g': return S_gcd(First(x), Second(x));
      case '=': {
        ptr x1 = First(x), x2 = Second(x);
        if (Sfixnump(x1) && Sfixnump(x2))
          return Sboolean(x1 == x2);
        else if (Sbignump(x1) && Sbignump(x2))
          return Sboolean(S_big_eq(x1, x2));
        else return Sfalse;
      }
      case '<': {
        ptr x1 = First(x), x2 = Second(x);
        if (Sfixnump(x1))
          if (Sfixnump(x2))
            return Sboolean(x1 < x2);
          else
            return Sboolean(!BIGSIGN(x2));
        else
          if (Sfixnump(x2))
            return Sboolean(BIGSIGN(x1));
          else
            return Sboolean(S_big_lt(x1, x2));
      }
      case 'f': return Sflonum(S_floatify(First(x)));
      case 'c':
        S_gc(get_thread_context(), UNFIX(First(x)),UNFIX(Second(x)));
        return Svoid;
      case 'd': return S_decode_float(Sflonum_value(First(x)));
      default:
        S_prin1(x);
        putchar('\n');
        printf("unrecognized operator, returning zero\n");
        return FIX(0);
    }
  } else
    return x;
}
Пример #3
0
ptr S_mktime(ptr dtvec) {
  time_t tx;
  struct tm tmx;
  long orig_tzoff = (long)UNFIX(INITVECTIT(dtvec, dtvec_tzoff));

  tmx.tm_sec = (int)Sinteger_value(Svector_ref(dtvec, dtvec_sec));
  tmx.tm_min = (int)Sinteger_value(Svector_ref(dtvec, dtvec_min));
  tmx.tm_hour = (int)Sinteger_value(Svector_ref(dtvec, dtvec_hour));
  tmx.tm_mday = (int)Sinteger_value(Svector_ref(dtvec, dtvec_mday));
  tmx.tm_mon = (int)Sinteger_value(Svector_ref(dtvec, dtvec_mon)) - 1;
  tmx.tm_year = (int)Sinteger_value(Svector_ref(dtvec, dtvec_year));

  tmx.tm_isdst = 0;
  if ((tx = mktime(&tmx)) == (time_t)-1) return Sfalse;
  if (tmx.tm_isdst == 1) { /* guessed wrong */
    tmx.tm_sec = (int)Sinteger_value(Svector_ref(dtvec, dtvec_sec));
    tmx.tm_min = (int)Sinteger_value(Svector_ref(dtvec, dtvec_min));
    tmx.tm_hour = (int)Sinteger_value(Svector_ref(dtvec, dtvec_hour));
    tmx.tm_mday = (int)Sinteger_value(Svector_ref(dtvec, dtvec_mday));
    tmx.tm_mon = (int)Sinteger_value(Svector_ref(dtvec, dtvec_mon)) - 1;
    tmx.tm_year = (int)Sinteger_value(Svector_ref(dtvec, dtvec_year));
    tmx.tm_isdst = 1;
    if ((tx = mktime(&tmx)) == (time_t)-1) return Sfalse;
  }

 /* mktime may have normalized some values, set wday and yday */
  INITVECTIT(dtvec, dtvec_sec) = Sinteger(tmx.tm_sec);
  INITVECTIT(dtvec, dtvec_min) = Sinteger(tmx.tm_min);
  INITVECTIT(dtvec, dtvec_hour) = Sinteger(tmx.tm_hour);
  INITVECTIT(dtvec, dtvec_mday) = Sinteger(tmx.tm_mday);
  INITVECTIT(dtvec, dtvec_mon) = Sinteger(tmx.tm_mon + 1);
  INITVECTIT(dtvec, dtvec_year) = Sinteger(tmx.tm_year);
  INITVECTIT(dtvec, dtvec_wday) = Sinteger(tmx.tm_wday);
  INITVECTIT(dtvec, dtvec_yday) = Sinteger(tmx.tm_yday);
#ifdef WIN32
  {
    TIME_ZONE_INFORMATION tz;
    DWORD rc = GetTimeZoneInformation(&tz);
    long tzoff;

    switch (rc) {
      case TIME_ZONE_ID_UNKNOWN:
      case TIME_ZONE_ID_STANDARD:
        tzoff = tz.Bias * -60;
        break;
      case TIME_ZONE_ID_DAYLIGHT:
        tzoff = (tz.Bias + tz.DaylightBias) * -60;
        break;
    }
    if (tzoff != orig_tzoff) tx = (time_t) difftime(tx, (time_t)(orig_tzoff - tzoff));
  }
#else
  if (tmx.tm_gmtoff != orig_tzoff) tx = difftime(tx, (time_t)(orig_tzoff - tmx.tm_gmtoff));
#endif
  return Scons(S_integer_time_t(tx), Svector_ref(dtvec, dtvec_nsec));
}
Пример #4
0
void cleanFormula()					//wordt nog alleen in de pre-processor gebruikt!!!
{
        int i;

        for( i = 1; i <= nrofvars; i++ )
            if( timeAssignments[ i ] < VARMAX )
            {	UNFIX( i ); }

        currentTimeStamp = 0;
}
Пример #5
0
int
libnet_write_ip(int sock, u_char *buf, int len)
{
    int c;
    struct sockaddr_in sin;
    struct libnet_ip_hdr  *ip_hdr;

    ip_hdr = (struct libnet_ip_hdr *)buf;

#if (LIBNET_BSD_BYTE_SWAP)
    /*
     *  For link access, we don't need to worry about the inconsistencies of
     *  certain BSD kernels.  However, raw socket nuances abound.  Certain
     *  BSD implmentations require the ip_len and ip_off fields to be in host
     *  byte order.  It's MUCH easier to change it here than inside the bpf
     *  writing routine.
     */
    ip_hdr->ip_len = FIX(ip_hdr->ip_len);
    ip_hdr->ip_off = FIX(ip_hdr->ip_off);
#endif

    memset(&sin, 0, sizeof(struct sockaddr_in));
    sin.sin_family  = AF_INET;
    sin.sin_addr.s_addr = ip_hdr->ip_dst.s_addr;

    c = sendto(sock, buf, len, 0, (struct sockaddr *)&sin,
        sizeof(struct sockaddr));

#if (LIBNET_BSD_BYTE_SWAP)
    ip_hdr->ip_len = UNFIX(ip_hdr->ip_len);
    ip_hdr->ip_off = UNFIX(ip_hdr->ip_off);
#endif
             
    if (c != len)
    {
#if (__DEBUG)
        libnet_error(LIBNET_ERR_WARNING, "write_ip: %d bytes written (%s)\n",
                c, strerror(errno));
#endif
    }
    return (c);
}
Пример #6
0
void MainDead( int *local_fixstackp )
{
	int nrval;
	mainDead++;

        while( end_fixstackp > local_fixstackp )
        {
	    nrval = *(--end_fixstackp);
	    UNFIX( nrval ); 
	}
	rstackp = end_fixstackp;
}
Пример #7
0
void S_resize_oblist(void) {
  bucket **new_oblist, *b, *oldb, **pb, *bnext;
  iptr *new_oblist_length_pointer, new_oblist_length, i, idx;
  ptr sym;
  IGEN g;

  new_oblist_length_pointer = S_G.oblist_length_pointer;

  if (S_G.oblist_count < S_G.oblist_length) {
    while (new_oblist_length_pointer != &oblist_lengths[0] && *(new_oblist_length_pointer - 1) >= S_G.oblist_count) {
      new_oblist_length_pointer -= 1;
    }
  } else if (S_G.oblist_count > S_G.oblist_length) {
    while (*(new_oblist_length_pointer + 1) != 0 && *(new_oblist_length_pointer + 1) <= S_G.oblist_count) {
      new_oblist_length_pointer += 1;
    }
  }

  if (new_oblist_length_pointer == S_G.oblist_length_pointer) return;

  new_oblist_length = *new_oblist_length_pointer;
  new_oblist = S_getmem(new_oblist_length * sizeof(bucket *), 1);

  for (i = 0; i < S_G.oblist_length; i += 1) {
    for (b = S_G.oblist[i]; b != NULL; b = bnext) {
      bnext = b->next;
      sym = b->sym;
      idx = UNFIX(SYMHASH(sym)) % new_oblist_length;
      g = GENERATION(sym);

      for (pb = &new_oblist[idx]; (oldb = *pb) != NULL && SegmentGeneration(addr_get_segment(oldb)) < g; pb = &oldb->next);
      b->next = oldb;
      *pb = b;
    }
  }

  S_freemem(S_G.oblist, S_G.oblist_length * sizeof(bucket *));
  S_G.bytesof[static_generation][countof_oblist] += (new_oblist_length - S_G.oblist_length) * sizeof(bucket *);

  S_G.oblist_length_pointer = new_oblist_length_pointer;
  S_G.oblist_length = new_oblist_length;
  S_G.oblist = new_oblist;
}
Пример #8
0
void restore_implication_arrays( const int nrval )
{
	int i, *bImp;
#ifdef GLOBAL_AUTARKY
	int lit1, lit2;
#endif
#ifdef EQ
	int ceqsubst, var;
	while( !( *( substackp - 1 ) == STACK_BLOCK ) )
	{
	    POP( sub, var );
	    ceqsubst = Veq[ NR(var) ][ Veq[ NR(var) ][ 0 ]++ ];
	    CeqValues[ ceqsubst ] *= SGN(var);
	    CeqSizes[ ceqsubst ]++; 
        }
        substackp--;
#ifdef GLOBAL_AUTARKY
	for( i = 1; i < Veq[NR(nrval)][0]; i++ )
	{
	    int j;
	    ceqsubst = Veq[NR(nrval)][i];
	    for( j = 0; j < CeqSizes[ceqsubst]; j++ )
	   	TernaryImpReduction[ Ceq[ceqsubst][j] ]--;
	}
#endif
#endif
//	printf("UNFIXING %i\n", nrval );

	if( kSAT_flag )
	{
	  int clause_index, *clauseSet;
	  clauseSet = clause_set[ nrval ];
	  while( *clauseSet != LAST_CLAUSE )
	  {
	    clause_index = *(clauseSet++);
	    clause_length[ clause_index ] -= SAT_INCREASE;

	    if( clause_length[ clause_index ] < SAT_INCREASE - 2 )
	    {
		restore_big_occurences( clause_index, nrval );
#ifdef GLOBAL_AUTARKY
		clause_SAT_flag[ clause_index ] = 0;
		if( clause_reduction[ clause_index ] > 0 )
		{
                    int *literals = clause_list[ clause_index ];
                    while( *literals != LAST_LITERAL )
			TernaryImpReduction[ *(literals++) ]++;
		}
#endif
	    }
	  }
#ifdef GLOBAL_AUTARKY
	  for( i = 0; i < btb_size[ nrval ]; ++i )
	  {
	    // decrease literal reduction
            int *literals = clause_list[ big_to_binary[ nrval ][ i ] ], flag = 0;
            while( *literals != LAST_LITERAL )
            {
		if( timeAssignments[ *(literals++) ] == NARY_MAX )
		{
		    if( flag == 1 ) { flag = 0; break; }
		    flag = 1;
		}
            }

	    if( flag == 1 )
	    {
		clause_SAT_flag[ big_to_binary[ nrval ][ i ] ] = 0;
		literals = clause_list[ big_to_binary[ nrval ][ i ] ];
            	while( *literals != LAST_LITERAL )
	            TernaryImpReduction[ *(literals++) ]++;
	    }
	  }
#endif
          clauseSet = clause_set[ -nrval ];
	  while( *clauseSet != LAST_CLAUSE )
          {
            clause_index = *(clauseSet++);
	    if( clause_length[ clause_index ] == SAT_INCREASE )
	    {
		restore_big_occurences( clause_index, -nrval );
		clause_length[ clause_index ] = 2;
#ifdef GLOBAL_AUTARKY
                int *literals = clause_list[ clause_index ];
                while( *literals != LAST_LITERAL )
                {
                    int lit = *(literals)++;
                    if( timeAssignments[ lit ] < NARY_MAX )
			btb_size[ lit ]--;
		}
#endif
	    }

#ifdef GLOBAL_AUTARKY
            clause_reduction[ clause_index ]--;

	    // if clause is restored to original length
	    if( clause_reduction[ clause_index ] == 0 )
	    {
		// decreasee literal reduction array
                int *literals = clause_list[ clause_index ];
                while( *literals != LAST_LITERAL )
		    TernaryImpReduction[ *(literals++) ]--;
		
		clause_red_depth[ clause_index ] = nrofvars;
	    }
#endif
#ifdef HIDIFF
	    HiAddLiteral( clause_index, nrval );
#endif
            clause_length[ clause_index ]++;
          }
	}

	/* restore all literals that were removed due to fixing of nrval */
	if( kSAT_flag == 0 )
	{
	    int *tImp = TernaryImp[ -nrval ];
	    for( i = TernaryImpSize[ -nrval ] = tmpTernaryImpSize[ -nrval ]; i--; )
	    {
	    	TernaryImpSize[ *(tImp++) ]++;
	    	TernaryImpSize[ *(tImp++) ]++;
	    }
#ifdef GLOBAL_AUTARKY
	    tImp = TernaryImp[ -nrval ];
            for( i = tmpTernaryImpSize[ -nrval ]; i--; )
	    {
	    	TernaryImpReduction[ *(tImp++) ]--;
	    	TernaryImpReduction[ *(tImp++) ]--;
	    }
#endif
	/* restore all clauses that were removed due to fixing of nrval */
	    tImp = TernaryImp[ nrval ];
	    for( i = TernaryImpSize[ nrval ] = tmpTernaryImpSize[ nrval ]; i--; )
	    {
	    	TernaryImpSize[ *(tImp++) ]++;
	    	TernaryImpSize[ *(tImp++) ]++;
	    }
#ifdef GLOBAL_AUTARKY
	    tImp = TernaryImp[ nrval ] + 2 * TernaryImpSize[ nrval ];
	    for( i = TernaryImpLast[ nrval ] - TernaryImpSize[ nrval ]; i--; )
	    {
		lit1 = *(tImp++);
		lit2 = *(tImp++);

	    	if( IS_REDUCED_TIMP( lit1, lit2 ) )
                    TernaryImpReduction[ lit1 ]++;
		else if( IS_REDUCED_TIMP( lit2, lit1 ) )
                    TernaryImpReduction[ lit2 ]++;
            }
#endif
	}

        bImp = BIMP_START(-nrval);
        for( i = BIMP_ELEMENTS; --i; )
            bImp_satisfied[ -(*(bImp++)) ]--;

	freevars++;
	
	UNFIX( nrval ); 
}
Пример #9
0
static void idiot_checks() {
  IBOOL oops = 0;

  if (bytes_per_segment < S_pagesize) {
    fprintf(stderr, "bytes_per_segment (%x) < S_pagesize (%lx)\n",
              bytes_per_segment, (long)S_pagesize);
    oops = 1;
  }
  if (sizeof(iptr) != sizeof(ptr)) {
    fprintf(stderr, "sizeof(iptr) [%ld] != sizeof(ptr) [%ld]\n",
              (long)sizeof(iptr), (long)sizeof(ptr));
    oops = 1;
  }
  if (sizeof(uptr) != sizeof(ptr)) {
    fprintf(stderr, "sizeof(uptr) [%ld] != sizeof(ptr) [%ld]\n",
              (long)sizeof(uptr), (long)sizeof(ptr));
    oops = 1;
  }
  if (sizeof(ptr) * 8 != ptr_bits) {
    fprintf(stderr, "sizeof(ptr) * 8 [%ld] != ptr_bits [%d]\n",
              (long)sizeof(ptr), ptr_bits);
    oops = 1;
  }
  if (sizeof(int) * 8 != int_bits) {
    fprintf(stderr, "sizeof(int) * 8 [%ld] != int_bits [%d]\n",
              (long)sizeof(int), int_bits);
    oops = 1;
  }
  if (sizeof(short) * 8 != short_bits) {
    fprintf(stderr, "sizeof(short) * 8 [%ld] != short_bits [%d]\n",
              (long)sizeof(short), short_bits);
    oops = 1;
  }
  if (sizeof(long) * 8 != long_bits) {
    fprintf(stderr, "sizeof(long) * 8 [%ld] != long_bits [%d]\n",
              (long)sizeof(long), long_bits);
    oops = 1;
  }
#ifndef WIN32
  if (sizeof(long long) * 8 != long_long_bits) {
    fprintf(stderr, "sizeof(long long) * 8 [%ld] != long_long_bits [%d]\n",
              (long)sizeof(long long), long_long_bits);
    oops = 1;
  }
#endif
  if (sizeof(wchar_t) * 8 != wchar_bits) {
    fprintf(stderr, "sizeof(wchar_t) * 8 [%ld] != wchar_bits [%d]\n",
              (long)sizeof(wchar_t), wchar_bits);
    oops = 1;
  }
  if (sizeof(size_t) * 8 != size_t_bits) {
    fprintf(stderr, "sizeof(size_t) * 8 [%ld] != size_t_bits [%d]\n",
              (long)sizeof(size_t), size_t_bits);
    oops = 1;
  }
#ifndef WIN32
  if (sizeof(ssize_t) * 8 != size_t_bits) {
    fprintf(stderr, "sizeof(ssize_t) * 8 [%ld] != size_t_bits [%d]\n",
              (long)sizeof(ssize_t), size_t_bits);
    oops = 1;
  }
#endif
  if (sizeof(ptrdiff_t) * 8 != ptrdiff_t_bits) {
    fprintf(stderr, "sizeof(ptrdiff_t) * 8 [%ld] != ptrdiff_t_bits [%d]\n",
              (long)sizeof(ptrdiff_t), ptrdiff_t_bits);
    oops = 1;
  }
  if (sizeof(time_t) * 8 != time_t_bits) {
    fprintf(stderr, "sizeof(time_t) * 8 [%ld] != time_t_bits [%d]\n",
              (long)sizeof(time_t), time_t_bits);
    oops = 1;
  }
  if (sizeof(bigit) * 8 != bigit_bits) {
    fprintf(stderr, "sizeof(bigit) * 8 [%ld] != bigit_bits [%d]\n",
              (long)sizeof(bigit), bigit_bits);
    oops = 1;
  }
  if (sizeof(bigitbigit) != 2 * sizeof(bigit)) {
    fprintf(stderr, "sizeof(bigitbigit) [%ld] != sizeof(bigit) [%ld] * 2\n",
              (long)sizeof(bigitbigit), (long)sizeof(bigit));
    oops = 1;
  }
  if (sizeof(char) != 1) {
    fprintf(stderr, "sizeof(char) [%ld] != 1\n", (long)sizeof(char));
    oops = 1;
  }
  if (sizeof(I8) != 1) {
    fprintf(stderr, "sizeof(I8) [%ld] != 1\n", (long)sizeof(I8));
    oops = 1;
  }
  if (sizeof(U8) != 1) {
    fprintf(stderr, "sizeof(U8) [%ld] != 1\n", (long)sizeof(U8));
    oops = 1;
  }
  if (sizeof(I16) != 2) {
    fprintf(stderr, "sizeof(I16) [%ld] != 2\n", (long)sizeof(I16));
    oops = 1;
  }
  if (sizeof(U16) != 2) {
    fprintf(stderr, "sizeof(U16) [%ld] != 2\n", (long)sizeof(U16));
    oops = 1;
  }
  if (sizeof(I32) != 4) {
    fprintf(stderr, "sizeof(I32) [%ld] != 4\n", (long)sizeof(I32));
    oops = 1;
  }
  if (sizeof(U32) != 4) {
    fprintf(stderr, "sizeof(U32) [%ld] != 4\n", (long)sizeof(U32));
    oops = 1;
  }
  if (sizeof(I64) != 8) {
    fprintf(stderr, "sizeof(I64) [%ld] != 8\n", (long)sizeof(I64));
    oops = 1;
  }
  if (sizeof(U64) != 8) {
    fprintf(stderr, "sizeof(U64) [%ld] != 8\n", (long)sizeof(U64));
    oops = 1;
  }
  if (sizeof(string_char) != string_char_bytes) {
    fprintf(stderr, "sizeof(string_char) [%ld] != string_char_bytes [%d]\n", (long)sizeof(string_char), string_char_bytes);
    oops = 1;
  }
  if (UNFIX(fixtest) != -1) {
    fprintf(stderr, "UNFIX operation failed\n");
    oops = 1;
  }
  if (strlen(VERSION)+1 > HEAP_VERSION_LENGTH) {
    fprintf(stderr, "insufficient space for version in heap header\n");
    oops = 1;
  }
  if (strlen(MACHINE_TYPE)+1 > HEAP_MACHID_LENGTH) {
    fprintf(stderr, "insufficient space for machine id in heap header\n");
    oops = 1;
  }
#define big 0
#define little 1
  if (native_endianness == big) {
    uptr x[1];
    *x = 1;
    if (*(char *)x != 0) {
      fprintf(stderr, "endianness claimed to be big, appears to be little\n");
      oops = 1;
    }
  } else {
    uptr x[1];
    *x = 1;
    if (*(char *)x == 0) {
      fprintf(stderr, "endianness claimed to be little, appears to be big\n");
      oops = 1;
    }
  }

  if (sizeof(bucket_pointer_list) != sizeof(bucket_list)) {
    /* gc repurposes bucket_lists for bucket_pointer lists, so they'd better have the same size */
    fprintf(stderr, "bucket_pointer_list and bucket_list have different sizes\n");
    oops = 1;
  }

  if ((cards_per_segment & (sizeof(iptr) - 1)) != 0) {
    /* gc sometimes processes dirty bytes sizeof(iptr) bytes at a time */
    fprintf(stderr, "cards_per_segment is not a multiple of sizeof(iptr)\n");
    oops = 1;
  }
  if (((uptr)(&((seginfo *)0)->dirty_bytes[0]) & (sizeof(iptr) - 1)) != 0) {
    /* gc sometimes processes dirty bytes sizeof(iptr) bytes at a time */
    fprintf(stderr, "dirty_bytes[0] is not iptr-aligned wrt to seginfo struct\n");
    oops = 1;
  }
  if (!Sfixnump(type_vector | ~mask_vector)) {
    /* gc counts on vector type/length looking like a fixnum, so it can put vectors in space_impure */
    fprintf(stderr, "vector type/length field does not look like a fixnum\n");
    oops = 1;
  }

  if (oops) S_abnormal_exit();
}
Пример #10
0
static void print1(ptr x, int d) {
  if (TAG(x, mask_fixnum) == tag_fixnum) {
    printf("%ld", (long)UNFIX(x));
  } else if (TAG(x, mask_pair) == tag_pair) {
    int len = 0;
    ptr y;
    
    if (d > MAXDEPTH) {
      printf("(...)");
      return;
    }
    printf("(");
    print1(CAR(x), d+1);
    y = CDR(x);
    while (TAG(y, mask_pair) == tag_pair && (len < MAXLENGTH-1)) {
      printf(" ");
      print1(CAR(y), d+1);
      y = CDR(y);
      len++;
    }
    if (y != _nil)
      if (len == MAXLENGTH-1)
        printf(" ...");
      else {
        printf(" . ");
        print1(y, d+1);
      }
    printf(")");
  } else if (TAG(x, mask_vector) == tag_vector) {
    long i, n;
    ptr *p;
    if (d > MAXDEPTH) {
      printf("#(...)");
      return;
    }
    printf("#(");
    n = UNFIX(VECTORLENGTH(x));
    p = VECTORDATA(x);
    i = n > MAXLENGTH ? MAXLENGTH : n;
    if (i != 0) {
      print1(*p, d+1);
      while (--i) {
        printf(" ");
        print1(*++p, d+1);
      }
    }
    if (n > MAXLENGTH) printf(" ..."); 
    printf(")");
  } else if (TAG(x, mask_procedure) == tag_procedure) {
    printf("#<procedure>");
  } else if (x == _false) {
    printf("#f");
  } else if (x == _true) {
    printf("#t");
  } else if (x == _nil) {
    printf("()");
  } else if (x == _void) {
    printf("#<void>");
  } else {
    fprintf(stderr, "print (runtime.c): invalid ptr #x%x\n", (unsigned int) x);
    exit(1);
  }
}
Пример #11
0
int
libnet_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t size)
{
    int c;
    struct sockaddr_in sin;
    struct libnet_ipv4_hdr *ip_hdr;

    if (l == NULL)
    { 
        return (-1);
    } 

    ip_hdr = (struct libnet_ipv4_hdr *)packet;

#if (LIBNET_BSD_BYTE_SWAP)
    /*
     *  For link access, we don't need to worry about the inconsistencies of
     *  certain BSD kernels.  However, raw socket nuances abound.  Certain
     *  BSD implmentations require the ip_len and ip_off fields to be in host
     *  byte order.
     */
    ip_hdr->ip_len = FIX(ip_hdr->ip_len);
    ip_hdr->ip_off = FIX(ip_hdr->ip_off);
#endif /* LIBNET_BSD_BYTE_SWAP */

    memset(&sin, 0, sizeof(sin));
    sin.sin_family  = AF_INET;
    sin.sin_addr.s_addr = ip_hdr->ip_dst.s_addr;
#if (__WIN32__)
    /* set port for TCP */
    /*
     *  XXX - should first check to see if there's a pblock for a TCP
     *  header, if not we can use a dummy value for the port.
     */
    if (ip_hdr->ip_p == 6)
    {
        struct libnet_tcp_hdr *tcph_p =
                (struct libnet_tcp_hdr *)(packet + (ip_hdr->ip_hl << 2));
        sin.sin_port = tcph_p->th_dport;
    }
    /* set port for UDP */
    /*
     *  XXX - should first check to see if there's a pblock for a UDP
     *  header, if not we can use a dummy value for the port.
     */
    else if (ip_hdr->ip_p == 17)
    {
        struct libnet_udp_hdr *udph_p =
                (struct libnet_udp_hdr *)(packet + (ip_hdr->ip_hl << 2));
       sin.sin_port = udph_p->uh_dport;
    }
#endif /* __WIN32__ */

    c = sendto(l->fd, packet, size, 0, (struct sockaddr *)&sin,
            sizeof(struct sockaddr));

#if (LIBNET_BSD_BYTE_SWAP)
    ip_hdr->ip_len = UNFIX(ip_hdr->ip_len);
    ip_hdr->ip_off = UNFIX(ip_hdr->ip_off);
#endif /* LIBNET_BSD_BYTE_SWAP */

    if (c != size)
    {
#if !(__WIN32__)
        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                "%s(): %d bytes written (%s)\n", __func__, c,
                strerror(errno));
#else /* __WIN32__ */
        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                "%s(): %d bytes written (%d)\n", __func__, c,
                WSAGetLastError());
#endif /* !__WIN32__ */
    }
    return (c);
}
Пример #12
0
void gl_grop_handler(struct groprender *r, struct gropnode *n) {
  struct glbitmap *glb;
  GLfloat vector[4];

  switch (n->type) {

  case PG_GROP_GL_BINDTEXTURE:
    if (!iserror(rdhandle((void**)&glb,PG_TYPE_BITMAP,-1,n->param[0])) && glb)
      gl_bind_texture(glb);
    break;

  case PG_GROP_GL_ENABLE:
    glEnable(n->param[0]);
    break;

  case PG_GROP_GL_DISABLE:
    glDisable(n->param[0]);
    break;

  case PG_GROP_GL_DEPTHFUNC:
    glDepthFunc(n->param[0]);
    break;

  case PG_GROP_GL_SHADEMODEL:
    glShadeModel(n->param[0]);
    break;

  case PG_GROP_GL_MATRIXMODE:
    glMatrixMode(n->param[0]);
    break;

  case PG_GROP_GL_LOADIDENTITY:
    glLoadIdentity();
    break;

  case PG_GROP_GL_PUSHMATRIX:
    glPushMatrix();
    break;

  case PG_GROP_GL_POPMATRIX:
    glPopMatrix();
    break;

  case PG_GROP_GL_TRANSLATEF:
    glTranslatef(UNFIX(n->param[0]),
		 UNFIX(n->param[1]),
		 UNFIX(n->param[2]));
    break;

  case PG_GROP_GL_ROTATEF:
    glRotatef(UNFIX16(n->r.x,n->r.y),
	      UNFIX(n->param[0]),
	      UNFIX(n->param[1]),
	      UNFIX(n->param[2]));
    break;

  case PG_GROP_GL_SCALEF:
    glScalef(UNFIX(n->param[0]),
	     UNFIX(n->param[1]),
	     UNFIX(n->param[2]));
    break;

  case PG_GROP_GL_BEGIN: 
    glBegin(n->param[0]);
    break;

  case PG_GROP_GL_TEXCOORD2F:
    glTexCoord2f(UNFIX(n->param[0]),
		 UNFIX(n->param[1]));
    break;

  case PG_GROP_GL_VERTEX3F:
    glVertex3f(UNFIX(n->param[0]),
	       UNFIX(n->param[1]),
	       UNFIX(n->param[2]));
    break;

  case PG_GROP_GL_END:
    glEnd();
    break;

  case PG_GROP_GL_HINT:
    glHint(n->param[0],n->param[1]);
    break;

  case PG_GROP_GL_NORMAL3F:
    glNormal3f(UNFIX(n->param[0]),
	       UNFIX(n->param[1]),
	       UNFIX(n->param[2]));    
    break;

  case PG_GROP_GL_LIGHTFV:
    vector[0] = UNFIX(n->param[0]);
    vector[1] = UNFIX(n->param[1]);
    vector[2] = UNFIX(n->param[2]);
    vector[3] = UNFIX16(n->r.w,n->r.h);
    glLightfv(n->r.x,n->r.y,(const GLfloat *)&vector);
    break;

  case PG_GROP_GL_MATERIALFV:
    vector[0] = UNFIX(n->param[0]);
    vector[1] = UNFIX(n->param[1]);
    vector[2] = UNFIX(n->param[2]);
    vector[3] = UNFIX16(n->r.w,n->r.h);
    glMaterialfv(n->r.x,n->r.y,(const GLfloat *)&vector);
    break;

  case PG_GROP_GL_TEXGENFV:
    vector[0] = UNFIX(n->param[0]);
    vector[1] = UNFIX(n->param[1]);
    vector[2] = UNFIX(n->param[2]);
    vector[3] = UNFIX16(n->r.w,n->r.h);
    glTexGenfv(n->r.x,n->r.y,(const GLfloat *)&vector);
    break;

  case PG_GROP_GL_TEXGENI:
    glTexGeni(n->param[0], n->param[1], n->param[2]);
    break;

  case PG_GROP_GL_MATERIALI:
    glMateriali(n->param[0], n->param[1], n->param[2]);
    break;

  case PG_GROP_GL_MATRIX_PIXELCOORD:
    gl_matrix_pixelcoord();
    break;

  case PG_GROP_GL_COLOR:
    gl_color(n->param[0]);
    break;

  case PG_GROP_GL_BLENDFUNC:
    glBlendFunc(n->param[0],n->param[1]);
    break;

  case PG_GROP_GL_FEEDBACK:
    gl_feedback(n->r.x, n->r.y, n->r.w, n->r.h,
		r->lgop, n->param[0], n->param[1],
		(n->param[2]>>16) & 0xFFFF, (n->param[2] & 0xFFFF));
    break;

  case PG_GROP_GL_TEXPARAMETERI:
    glTexParameteri(n->param[0],n->param[1],n->param[2]);
    break;

  }
}
Пример #13
0
void mode_7 (M7_TiledMap tmap, M7_Parameters *params)
{

    // current screen position
	int screen_x, screen_y;

    // the distance and horizontal scale of the line we are drawing
	fix distance, horizontal_scale;

    // masks to make sure we don't read pixels outside the tile
	const int mask = 0x7;

    // step for points in space between two pixels on a horizontal line
	fix line_dx, line_dy;

    // current space position
	fix space_x, space_y;

	int sx, sy;

	const int map_width = tmap.width <<3;
	const int map_height = tmap.height<<3;

	char value;
	char* tile;

	// Trig optimisation
	const fix ca = fcos(params->camera_angle), sa = fsin(params->camera_angle);

	// horizon calculation
	int horiz;
	const fix cpa = fcos(params->camera_pitch), spa = fsin(params->camera_pitch);
	if (cpa != 0) {
		fix h = fmul(spa, FIX(64)) - params->camera_z;
		horiz = UNFIX(fdiv(h, cpa));
	}
	else    // looking straight down (w.y > 0) means horizon at -inf scanline
    horiz= spa > 0 ? INT_MIN : INT_MAX;

	params->horizon = horiz;

	for (screen_y = 0; screen_y < 64; screen_y++)
	{

		if(!(screen_y + horiz)) continue;
    // first calculate the distance of the line we are drawing
		distance = (fmul (params->camera_z, params->scale_y) /
		(screen_y + horiz));

		if(distance < 0)
			continue;

    // then calculate the horizontal scale, or the distance between
    // space points on this horizontal line
		horizontal_scale = fdiv (distance, params->scale_x);

    // calculate the dx and dy of points in space when we step
    // through all points on this line
		line_dx = fmul (-sa, horizontal_scale);
		line_dy = fmul (ca, horizontal_scale);

    // calculate the starting position
		space_x = params->camera_x + fmul (distance, ca) - 64 * line_dx;
		space_y = params->camera_y + fmul (distance, sa) - 64 * line_dy;

    // go through all points in this screen line
		for (screen_x = 0; screen_x < 128; screen_x++)
		{
			sx = UNFIX(space_x);
			sy = UNFIX(space_y);
			if(sx >= 0 && sy >= 0 && sx < map_width && sy < map_height) {
        // get a pixel from the tile and put it on the screen
				tile = tmap.tiles + ((tmap.map[((sy>>3)&255)*tmap.width + tmap.width - 1 - ((sx>>3)&255)])<<3);
				value = (tile[sy&mask] & (1<<(sx&mask))) != 0;
			}
			else
				value = ML_CHECKER;
			ML_pixel(screen_x, screen_y, value);

            // advance to the next position in space
			space_x += line_dx;
			space_y += line_dy;
		}