Beispiel #1
0
void
set_mouse_coord (struct mouse_coord *m)
{
  if (m->c.x < 0 || m->c.x >= ORIGINAL_WIDTH
      || m->c.y < 0 || m->c.y >= ORIGINAL_HEIGHT)
    return;

  int x, y;

  mr_restore_origin (&m->mr);

  if (! m->c.room) {
    al_set_mouse_xy (display, m->sx, m->sy);
    return;
  }

  if (! mr_coord (m->c.room, -1, &x, &y)) {
    mr_center_room (m->c.room);
    x = mr.x;
    y = mr.y;
  }

  struct mouse_coord m0;
  get_mouse_coord (&m0);
  if (m0.x >= 0 && m0.y >= 0 &&
      mr.cell[m0.x][m0.y].room == m->c.room) {
    x = m0.x;
    y = m0.y;
  }

  int tw, th;
  mr_get_resolution (&tw, &th);

  int w = al_get_display_width (display);
  int h = al_get_display_height (display);

  int mx = ((ORIGINAL_WIDTH * x + m->c.x + 1) * w) / tw;
  int my = ((ROOM_HEIGHT * y + m->c.y + 1) * h) / th;

  mx = min_int (mx, w - 1);
  my = min_int (my, h - 1);

  int flags = screen_flags | potion_flags;

  if (flags & ALLEGRO_FLIP_HORIZONTAL)
    mx = (w - 1) - mx;

  if (flags & ALLEGRO_FLIP_VERTICAL)
    my = (h - 1) - my;

  if (! al_set_mouse_xy (display, mx, my))
    error (0, 0, "%s (%p): cannot set mouse xy coordinates (%i,%i)",
           __func__, m, mx, my);

  do {
    al_get_mouse_state (&mouse_state);
  } while (mouse_state.x != mx || mouse_state.y != my);

  mr.select_cycles = SELECT_CYCLES;
}
Beispiel #2
0
void
draw_princess_room_stars (ALLEGRO_BITMAP *bitmap, enum vm vm)
{
  int i, min_x = INT_MAX, min_y = INT_MAX,
    max_x = INT_MIN, max_y = INT_MIN;

  static struct star s[6] = {
    {20,97,0}, {16,104,1}, {23,110,0},
    {17,116,1}, {24,120,2}, {18,128,2}};

  static struct stars_bitmap sb = {.b = NULL};

  if (! sb.b) {
    for (i = 0; i < 6; i++) {
      min_x = min_int (min_x, s[i].x);
      min_y = min_int (min_y, s[i].y);
      max_x = max_int (max_x, s[i].x);
      max_y = max_int (max_y, s[i].y);
    }

    sb.b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1);
    clear_bitmap (sb.b, TRANSPARENT_COLOR);
    sb.c.x = min_x;
    sb.c.y = min_y;

    redraw_stars_bitmap (&s[0], &sb, 6, vm);
  }

  if (vm != last_vm) {
    redraw_stars_bitmap (&s[0], &sb, 6, vm);
    last_vm = vm;
  }

  draw_stars (bitmap, s, &sb, 6, vm);
}
/*
** Bottom-up mergesort with no apparent array copy. To avoid apparent
** copy, we use an auxiliary array aux. Original array and aux array
** take turns to be the resultant array of two-way merge. So the copy
** is virtually completed in the process of merge_ab. However we still
** use an apparent copy loop in the end, but it would't take up too
** much cost.
*/
void merge_sort(item_t *array,int left,int right)
{
	int n=right-left+1;
	int i,m,flag;
	item_t *aux;

	if(right-left+1<=1){
		return;
	}

	aux=malloc(n*sizeof(*aux));

	flag=1;
	for(m=1;m<=right-left;m*=2){
		for(i=left;i<=right-m;i+=2*m){
			if(flag==1){
				merge_ab(aux+i-left,array+i,m,array+i+m,min_int(m,right-m-i+1));
			}else{
				merge_ab(array+i,aux+i-left,m,aux+i+m-left,min_int(m,right-m-i+1));
			}
		}

		flag=(flag==0)?1:0;
	}

	if(flag==0){
		for(i=left;i<=right;i++){
			array[i]=aux[i-left];
		}
	}

	free(aux);
}
Beispiel #4
0
bool
intersection_rectangle (int x0, int y0, int w0, int h0,
                        int x1, int y1, int w1, int h1,
                        int *xrp, int *yrp, int *wrp, int *hrp)
{
  if (w0 <= 0 || h0 <= 0 || w1 <= 0 || h1 <= 0) {
    *xrp = 0;
    *yrp = 0;
    *wrp = 0;
    *hrp = 0;
    return false;
  }

  int xr = max_int (x0, x1);
  int yr = max_int (y0, y1);

  int x0b = x0 + w0 - 1;
  int y0b = y0 + h0 - 1;
  int x1b = x1 + w1 - 1;
  int y1b = y1 + h1 - 1;

  int xrb = min_int (x0b, x1b);
  int yrb = min_int (y0b, y1b);

  int wr = xrb - xr + 1;
  int hr = yrb - yr + 1;

  *xrp = xr;
  *yrp = yr;
  *wrp = wr > 0 ? wr : 0;
  *hrp = hr > 0 ? hr : 0;

  return wr > 0 && hr > 0;
}
Beispiel #5
0
/*
 * Receive a chunk, and write it to stdout or stderr.
 */
static int receive_from_server(int socket, char* stream_identifier, int size)
{
    // select output stream
    int output_fd;
    if (strcmp(stream_identifier, "out") == 0) {
        output_fd = fileno(stdout);
    }
    else if (strcmp(stream_identifier, "err") == 0) {
        output_fd = fileno(stderr);
    }
    else {
        fprintf(stderr, "ERROR: unrecognizable stream identifier: %s\n", stream_identifier);
        exit(1);
    }

    // copy to stream
    char read_buf[BUFFER_SIZE];
    int remained_size = size;
    int ret;
    while (min_int(remained_size, BUFFER_SIZE) > 0 && (ret = recv(socket, read_buf, min_int(remained_size, BUFFER_SIZE), 0)) > 0) {
        write(output_fd, read_buf, ret);
        remained_size -= ret;
#ifdef DEBUG
        fprintf(stderr, "DEBUG: read and write from server: %d (remained: %d)\n", ret, min_int(remained_size, BUFFER_SIZE));
#endif
    }
    return 0;
}
Beispiel #6
0
struct pos *
pos2room (struct pos *p, int room, struct pos *pv)
{
  *pv = *p;
  /* npos (pv, pv); */

  if (pv->room == room) return pv;

  struct pos pb, pa, pl, pr;

  pb = pa = pl = pr = *pv;

  int mpb, mpa, mpr, mpl;
  mpb = mpa = mpr = mpl = INT_MAX;

  int ra, rb, rl, rr;

  ra = roomd (pv->l, room, ABOVE);
  rb = roomd (pv->l, room, BELOW);
  rl = roomd (pv->l, room, LEFT);
  rr = roomd (pv->l, room, RIGHT);

  if (rb == pv->room) {
    pb.floor += FLOORS;
    pb.room = room;
    mpb = pos_mod (&pb, p);
  }

  if (ra == pv->room) {
    pa.floor -= FLOORS;
    pa.room = room;
    mpa = pos_mod (&pa, p);
  }

  if (rr == pv->room) {
    pr.place += PLACES;
    pr.room = room;
    mpr = pos_mod (&pr, p);
  }

  if (rl == pv->room) {
    pl.place -= PLACES;
    pl.room = room;
    mpl = pos_mod (&pl, p);
  }

  int lm = mpb;
  lm = min_int (lm, mpa);
  lm = min_int (lm, mpr);
  lm = min_int (lm, mpl);

  if (lm == mpb) *pv = pb;
  else if (lm == mpa) *pv = pa;
  else if (lm == mpr) *pv = pr;
  else if (lm == mpl) *pv = pl;

  return pv;
}
static void Padding_pack(Widget *this_)
{
	Padding * const instance = (Padding *)this_;
	Vector2i const desired_content_size = instance->content->desired_size;
	instance->content->absolute_position = this_->absolute_position;
	Vector2i_add_xy(&instance->content->absolute_position, instance->amount, instance->amount);
	instance->content->actual_size.x = max_int(min_int(desired_content_size.x, instance->base.actual_size.x) - (2 * instance->amount), 0);
	instance->content->actual_size.y = max_int(min_int(desired_content_size.y, instance->base.actual_size.y) - (2 * instance->amount), 0);
	Widget_pack(instance->content);
}
Beispiel #8
0
void
draw_princess_room_stars (ALLEGRO_BITMAP *bitmap, enum vm vm)
{
  int i, min_x = INT_MAX, min_y = INT_MAX,
    max_x = INT_MIN, max_y = INT_MIN;

  static struct star s[6] = {
    {20,97,0}, {16,104,1}, {23,110,0},
    {17,116,1}, {24,120,2}, {18,128,2}};

  static struct stars stars = {.b = NULL, .s = s, .count = 6};

  if (! stars.b) {
    for (i = 0; i < 6; i++) {
      min_x = min_int (min_x, stars.s[i].x);
      min_y = min_int (min_y, stars.s[i].y);
      max_x = max_int (max_x, stars.s[i].x);
      max_y = max_int (max_y, stars.s[i].y);
    }

    stars.b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1);
    clear_bitmap (stars.b, TRANSPARENT_COLOR);
    stars.c.x = min_x;
    stars.c.y = min_y;

    redraw_stars_bitmap (&stars, vm);
  }

  if (vm != mr.last.vm) redraw_stars_bitmap (&stars, vm);

  draw_stars (bitmap, &stars, vm);
}

void
draw_balcony_stars (ALLEGRO_BITMAP *bitmap, struct pos *p, enum vm vm)
{
  if (con (p)->bg != BALCONY) return;
  struct pos np; npos (p, &np);

  if (! np.room) return;

  struct stars *stars = &mr.cell[mr.dx][mr.dy].stars[np.floor][np.place];

  if (vm != mr.last.vm) redraw_stars_bitmap (stars, vm);

  draw_stars (bitmap, stars, vm);
}

static struct star *
star_coord (struct pos *p, int i, struct star *s)
{
  s->x = PLACE_WIDTH * p->place + 16 + prandom_pos_uniq (p, 2 * i, 1, 28);
  s->y = PLACE_HEIGHT * p->floor - 3 + prandom_pos_uniq (p, 2 * i + 1, 1, 21);
  return s;
}
Beispiel #9
0
/* if we return BIG_TIMEOUT, nothing to wait for */
interval_t
reliable_send_timeout (const struct reliable *rel)
{
  struct gc_arena gc = gc_new ();
  interval_t ret = BIG_TIMEOUT;
  int i;
  const time_t local_now = now;

  for (i = 0; i < rel->size; ++i)
    {
      const struct reliable_entry *e = &rel->array[i];
      if (e->active)
	{
	  if (e->next_try <= local_now)
	    {
	      ret = 0;
	      break;
	    }
	  else
	    {
	      ret = min_int (ret, e->next_try - local_now);
	    }
	}
    }

  dmsg (D_REL_DEBUG, "ACK reliable_send_timeout %d %s",
       (int) ret,
       reliable_print_ids (rel, &gc));

  gc_free (&gc);
  return ret;
}
Beispiel #10
0
void qr_decomp(double* a, int rows, int cols, int ldim)
{
    double rho, s, c, tau, alpha;
    int i, k, j;
    for (k = 0; k < min_int(rows, cols); k++) {
        for (i = k + 1; i < rows; i++) {
            if (get_entry(a, ldim, i, k) == 0) {
                rho = 1.0;
                c = 1.0;
                s = 0.0;
            } else if (fabs(get_entry(a, ldim, k, k)) >= fabs(get_entry(a, ldim, i, k))) {
                tau = get_entry(a, ldim, i, k) / get_entry(a, ldim, k, k);
                rho = tau / (sqrt(tau*tau + 1.0));
                s = rho;
                c = sqrt(1.0 - (s*s));
            } else {
                tau = get_entry(a, ldim, k, k) / get_entry(a, ldim, i, k);
                rho = sqrt(tau*tau + 1.0) / tau;
                c = 1.0 / rho;
                s = sqrt(1.0 - (c*c));
            }
            set_entry(a, ldim, k, k, c*get_entry(a, ldim, k, k) + s*get_entry(a, ldim, i, k));
            set_entry(a, ldim, i, k, rho);

            for (j = k + 1; j < cols; j++) {
                alpha = get_entry(a, ldim, k, j);
                set_entry(a, ldim, k, j, c*alpha + s * get_entry(a, ldim, i, j));
                set_entry(a, ldim, i, j, -s*alpha + c* get_entry(a, ldim, i, j));
            }
        }
    }
}
int
rand_bytes (uint8_t *output, int len)
{
  static int gather_delay = 0;
  ctr_drbg_context *rng_ctx = rand_ctx_get();

  while (len > 0)
    {
      const size_t blen = min_int (len, CTR_DRBG_MAX_REQUEST);
      if (0 != ctr_drbg_random(rng_ctx, output, blen))
	return 0;

      output += blen;
      len -= blen;

      if (gather_delay++ >= FOX_ENTROPY_GATHER_FREQUENCY)
        {
          entropy_context *e_ctx = rng_ctx->p_entropy;
          ASSERT(e_ctx != NULL);
          if (0 != entropy_gather(e_ctx))
            return 0;

          gather_delay = 0;
        }
    }

  return 1;
}
Beispiel #12
0
void qr_transform(double* qr, int m, int n, int ldim, double* b){
  int k, i, min;
  double c, s, rho, alpha;
  
  min = min_int(m,n);
  
  for(k=0;k<min;k++){
    for(i=k+1;i<m;i++){
      rho = get_entry(qr,ldim,i,k);
      
      if(rho==1.0){
        c = 1.0; s = 0.0;
      }
      else if(fabs(rho)<1.0){
        s = rho; c = sqrt(1.0 - s*s);
      }
      else{
        c = 1.0/rho; s = sqrt(1.0 - c*c);
      }
      
      alpha = b[k];
      b[k]  = c*alpha + s*b[i];
      b[i]  = -1.0*s*alpha + c*b[i];
    }
  }
}
Beispiel #13
0
void read_string( const char* szFileName, const char* szVarName, char*   pVariable)
{
    char* szValue = NULL;       /* string containg the read variable value */

    if( szVarName  == 0 )  ERROR("null pointer given as variable name" );
    if( szFileName == 0 )  ERROR("null pointer given as filename" );
    if( pVariable  == 0 )  ERROR("null pointer given as variable" );

    if( szVarName[0] == '*' )
        szValue = find_string( szFileName, szVarName +1 );
    else
        szValue = find_string( szFileName, szVarName );

    if( sscanf( szValue, "%s", pVariable) == 0)
        READ_ERROR("wrong format", szVarName, szFileName,0);

    int rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    if(!rank)
        printf( "File: %s\t\t%s%s= %s\n", szFileName,
                                      szVarName,
                                      &("               "[min_int( (int)strlen(szVarName), 15)]),
                                      pVariable );
}
void
prng_bytes (uint8_t *output, int len)
{
  static size_t processed = 0;

  if (nonce_md)
    {
      const int md_size = md_kt_size (nonce_md);
      while (len > 0)
	{
	  unsigned int outlen = 0;
	  const int blen = min_int (len, md_size);
	  md_full(nonce_md, nonce_data, md_size + nonce_secret_len, nonce_data);
	  memcpy (output, nonce_data, blen);
	  output += blen;
	  len -= blen;

	  /* Ensure that random data is reset regularly */
	  processed += blen;
	  if(processed > PRNG_NONCE_RESET_BYTES) {
	    prng_reset_nonce();
	    processed = 0;
	  }
	}
    }
  else
    rand_bytes (output, len);
}
Beispiel #15
0
void qr_transform(double* qr, int m, int n, int ldim, double* b)
{
   double rho, c, s, alpha;
   int k, i;
   for (k = 0; k < min_int(m, n); k++)
   {
      for (i = k + 1; i < m; i++)
      {
         rho = get_entry(qr, ldim, i, k);
         if (rho == 1)
         {
            c = 1;
            s = 0;
         }
         else if (fabs(rho)<1)
         {
            s = rho;
            c = sqrt(1 - (s*s));
         }
         else
         {
            c = 1 / rho;
            s = sqrt(1 - c*c);
         }

         alpha = b[k];
         b[k] = c*alpha + s*b[i];
         b[i] = -s*alpha + c*b[i];
      }
   }
}
Beispiel #16
0
bool
union_rectangle (int x0, int y0, int w0, int h0,
                 int x1, int y1, int w1, int h1,
                 int *xrp, int *yrp, int *wrp, int *hrp)
{
  if ((w0 <= 0 || h0 <= 0) && (w1 > 0 && h1 > 0)) {
    *xrp = x1;
    *yrp = y1;
    *wrp = w1;
    *hrp = h1;
    return true;
  } else if ((w1 <= 0 || h1 <= 0) && (w0 > 0 && h0 > 0)) {
    *xrp = x0;
    *yrp = y0;
    *wrp = w0;
    *hrp = h0;
    return true;
  } else if ((w0 <= 0 || h0 <= 0) && (w1 <= 0 && h1 <= 0)) {
    *xrp = 0;
    *yrp = 0;
    *wrp = 0;
    *hrp = 0;
    return false;
  }

  int xr = min_int (x0, x1);
  int yr = min_int (y0, y1);

  int x0b = x0 + w0 - 1;
  int y0b = y0 + h0 - 1;
  int x1b = x1 + w1 - 1;
  int y1b = y1 + h1 - 1;

  int xrb = max_int (x0b, x1b);
  int yrb = max_int (y0b, y1b);

  int wr = xrb - xr + 1;
  int hr = yrb - yr + 1;

  *xrp = xr;
  *yrp = yr;
  *wrp = wr > 0 ? wr : 0;
  *hrp = hr > 0 ? hr : 0;

  return wr > 0 && hr > 0;
}
Beispiel #17
0
static void VS_CC
proc_16bit(uint8_t *buff, int bstride, int width, int height, int stride,
           uint8_t *d, const uint8_t *s, edge_t *eh, uint16_t plane_max)
{
    const uint16_t *srcp = (uint16_t *)s;
    uint16_t *dstp = (uint16_t *)d;
    stride /= 2;
    bstride /= 2;

    uint16_t *p0 = (uint16_t *)buff + 8;
    uint16_t *p1 = p0 + bstride;
    uint16_t *p2 = p1 + bstride;
    uint16_t *orig = p0, *end = p2;

    line_copy16(p0, srcp + stride, width, 1);
    line_copy16(p1, srcp, width, 1);

    int th_min = min_int(eh->min, plane_max);
    int th_max = min_int(eh->max, plane_max);

    for (int y = 0; y < height; y++) {
        srcp += stride * (y < height - 1 ? 1 : -1);
        line_copy16(p2, srcp, width, 1);
        for (int x = 0; x < width; x++) {
            int gx = -p0[x - 1] + p0[x + 1] - 2 * p1[x - 1] + 2 * p1[x + 1]
                     - p2[x - 1] + p2[x + 1];
            int gy = -p0[x - 1] - 2 * p0[x] - p0[x + 1] + p2[x - 1] + 2 * p2[x]
                     + p2[x + 1];
            int g = (int)(sqrtf(gx * gx + gy * gy) + 0.5f);
            g = g >> eh->rshift;
            if (g >= th_max) {
                g = plane_max;
            }
            if (g <= th_min) {
                g = 0;
            }
            dstp[x] = g;
        }
        dstp += stride;
        p0 = p1;
        p1 = p2;
        p2 = (p2 == end) ? orig : p2 + bstride;
    }
}
Beispiel #18
0
int main() {
  int a = 5;
  int b = 6;
  int c = min_int(a,b);

  float f1 = 3.1;
  float f2 = 9.5;
  float d = min_float(f1, f2);

}
Beispiel #19
0
int
room_dist (struct level *lv, int r0, int r1, int max)
{
  struct room_dist room[ROOMS];

  /* begin optimization block */
  if (r0 == r1) return 0;

  if (roomd (lv, r0, LEFT) == r1
      || roomd (lv, r0, RIGHT) == r1
      || roomd (lv, r0, BELOW) == r1
      || roomd (lv, r0, ABOVE) == r1)
    return 1;
  /* end optimization block */

  int i;
  for (i = 0; i < ROOMS; i++) {
    room[i].dist = INT_MAX;
    room[i].visited = false;
  }

  room[r0].dist = 0;
  int dmax = 0;

  int u;
  while ((u = min_room_dist (room, &dmax)) != -1
         && dmax <= max) {
    if (u == r1) break;
    room[u].visited = true;

    int l = roomd (lv, u, LEFT);
    int r = roomd (lv, u, RIGHT);
    int b = roomd (lv, u, BELOW);
    int a = roomd (lv, u, ABOVE);

    room[l].dist = min_int (room[l].dist, room[u].dist + 1);
    room[r].dist = min_int (room[r].dist, room[u].dist + 1);
    room[b].dist = min_int (room[b].dist, room[u].dist + 1);
    room[a].dist = min_int (room[a].dist, room[u].dist + 1);
  }

  return room[r1].dist;
}
Beispiel #20
0
void
summa_dump (const char* tag, int m, int n, const double* A_local, MPI_Comm comm2d)
{
  int P_row, P_col;
  summa_getProcSize (comm2d, &P_row, &P_col);
  int rank = mpih_getRank (comm2d);
  int rank_row, rank_col;
  summa_getProcCoords (comm2d, &rank_row, &rank_col);

  int m_local = mm1d_getBlockLength (m, P_row, rank_row);
  int n_local = mm1d_getBlockLength (n, P_col, rank_col);
  int i0 = mm1d_getBlockStart (m, P_row, rank_row);
  int j0 = mm1d_getBlockStart (n, P_col, rank_col);

  for (int r_row = 0; r_row < P_row; ++r_row) {
    for (int r_col = 0; r_col < P_col; ++r_col) {
      MPI_Barrier (comm2d); /* Serialize output */
      if (r_row == rank_row && r_col == rank_col) {
	fflush (stderr);
	mpih_debugmsg (comm2d, "(p%d,p%d)>> Mat:%s -- %d x %d; j \\in [%d,%d]\n",
		       rank_row, rank_col, tag, m_local, n_local,
		       j0, j0+n_local-1);

	/* Maximum no. of rows/columns to print */
	const int MAX_ROWS = 4;
	const int MAX_COLS = 4;

	for (int di = 0; di < min_int (m_local, MAX_ROWS); ++di) {
	  fprintf (stderr, "   Row %d:", i0+di);
	  for (int dj = 0; dj < min_int (n_local, MAX_COLS); ++dj) {
	    fprintf (stderr, " %g", A_local[di + dj*m_local]);
	  } /* dj */
	  if (n_local > MAX_COLS) fprintf (stderr, " ... (omitted)");
	  fprintf (stderr, "\n");
	} /* di */
	if (m_local > MAX_ROWS) fprintf (stderr, "   ... (rows omitted) ...\n");
      } /* (r_row, r_col) == (rank_row, rank_col) */
    } /* r_col */
  } /* r_row */
}
Beispiel #21
0
static
void
dumpParticles__ (const char* tag, int n, particle_t* particles)
{
  const int max_print = 10;
  fprintf (stderr, "=== %s: %d particles ===\n", tag, n);
  for (int i = 0; i < min_int (n, max_print); ++i) {
    fprintf (stderr, "  [%d] (%g, %g); v = (%g, %g)\n", i
	     , particles[i].x, particles[i].y
	     , particles[i].vx, particles[i].vy);
  }
  if (n > max_print) fprintf (stderr, "     ... (omitted) ...\n");
}
Beispiel #22
0
// haystack is \0 (space if leading upper) (lowercase string), ends with two \0
// needles are a NULL terminated list of lowercase strings, with a leading space if upper
int text_search(char* haystack, char** needles, int exact, int* results)
{
    // information about the needles
    int n = count_pointers(needles);
    int uppers[n];        // is this needle uppercase prefix
    int lengths[n];       // length of this needle
    char* strings[n];     // actual text of this needle

    for (int i = 0; i < n; i++)
    {
        uppers[i] = needles[i][0] == ' ';
        strings[i] = uppers[i] ? &needles[i][1] : needles[i];
        lengths[i] = strlen(strings[i]);
    }

    int index = 0;          // Number of \n's I've already seen in haystack
    int found = 0;          // Number I've written to results

    for (index = 0; ; index++)
    {
        int upper = haystack[0] == ' ';
        if (upper) haystack++;
        int length = strlen(haystack);
        if (length == 0) break;
        char* string = haystack;
        haystack = &haystack[length+1];

        int score = 4;
        for (int i = 0; i < n; i++)
        {
            char* pos = strstr(string, strings[i]); // length, strings[i], lengths[i]);
            if (pos == NULL)
            {
                score = -1;
                break;
            }
            else if (pos == string)
            {
                int complete = lengths[i] == length;
                int cased = uppers[i] == upper;
                score = min_int(score, (!complete ? 2 : 0) + (!cased ? 1 : 0));
            }
        }
        if (score >= 0 && (!exact || score == 0))
            results[found++] = (score << 24) | index;
    }
    qsort(results, found, sizeof(int), compare_int);
    for (int i = 0; i < found; i++)
        results[i] = results[i] & 0xffffff;
    return found;
}
Beispiel #23
0
static void
compute_stars_position (int last_room, int room)
{
  struct pos p;
  p.room = room;

  int i, min_x = INT_MAX, min_y = INT_MAX,
    max_x = INT_MIN, max_y = INT_MIN;

  for (p.floor = FLOORS; p.floor >= -1; p.floor--)
    for (p.place = -1; p.place < PLACES; p.place++) {
      struct stars_bitmap *sb =
        &stars_bitmap[p.floor + 1][p.place + 1];
      if (sb->b) {
        al_destroy_bitmap (sb->b);
        sb->b = NULL;
      }
      if (con (&p)->bg != BALCONY) continue;

      for (i = 0; i < STARS; i++) {
        struct star *s = &star[p.floor + 1][p.place + 1][i];
        star_coord (&p, i, s);
        min_x = min_int (min_x, s->x);
        min_y = min_int (min_y, s->y);
        max_x = max_int (max_x, s->x);
        max_y = max_int (max_y, s->y);
        s->color = next_color (s->color);
      }

      sb->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1);
      clear_bitmap (sb->b, TRANSPARENT_COLOR);
      sb->c.room = room;
      sb->c.x = min_x;
      sb->c.y = min_y;

      redraw_stars_bitmap (star[p.floor + 1][p.place + 1], sb, STARS, vm);
    }
}
Beispiel #24
0
void
generate_stars_for_pos (struct pos *p)
{
  struct pos np; npos (p, &np);
  int x, y;
  if (! mr_coord (np.room, -1, &x, &y)) return;

  struct stars *stars = &mr.cell[x][y].stars[np.floor][np.place];
  destroy_bitmap (stars->b);
  stars->b = NULL;
  if (stars->s) al_free (stars->s);
  stars->s = NULL;
  stars->count = 0;

  if (con (&np)->bg != BALCONY) return;

  stars->count = 3 + prandom_pos (&np, 5);
  stars->s = xcalloc (stars->count, sizeof (* stars->s));

  int i, min_x = INT_MAX, min_y = INT_MAX,
    max_x = INT_MIN, max_y = INT_MIN;

  for (i = 0; i < stars->count; i++) {
    struct star *s = &stars->s[i];
    star_coord (&np, i, s);
    min_x = min_int (min_x, s->x);
    min_y = min_int (min_y, s->y);
    max_x = max_int (max_x, s->x);
    max_y = max_int (max_y, s->y);
    s->color = next_color (s->color);
  }

  stars->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1);
  clear_bitmap (stars->b, TRANSPARENT_COLOR);
  new_coord (&stars->c, np.l, np.room, min_x, min_y);

  redraw_stars_bitmap (stars, vm);
}
Beispiel #25
0
smt_astt 
smt_convt::overflow_neg(const expr2tc &expr)
{
  // If in integer mode, this is completely pointless. Return false.
  if (int_encoding)
    return mk_smt_bool(false);

  // Single failure mode: MIN_INT can't be neg'd
  const overflow_neg2t &neg = to_overflow_neg2t(expr);
  unsigned int width = neg.operand->type->get_width();

  constant_int2tc min_int(neg.operand->type, BigInt(1 << (width - 1)));
  equality2tc val(neg.operand, min_int);
  return convert_ast(val);
}
Beispiel #26
0
int
rand_bytes (uint8_t *output, int len)
{
  ctr_drbg_context *rng_ctx = rand_ctx_get();

  while (len > 0)
    {
      const size_t blen = min_int (len, CTR_DRBG_MAX_REQUEST);
      if (0 != ctr_drbg_random(rng_ctx, output, blen))
	return 0;

      output += blen;
      len -= blen;
    }

  return 1;
}
Beispiel #27
0
int main(void){
  
  int i, j, rows, cols;
  double *a, *qr;
  time_t t;
  time(&t);
  srand(t);
  
  /* Matrixdimension festlegen (rows = Zeilen, cols = Spalten) */
  rows = 3;
  cols = 3;
  
  /* Speicher anfordern */
  a = (double*) malloc(rows*cols*sizeof(double));
  qr = (double*) malloc(rows*cols*sizeof(double));
  
  /* Matrix a erzeugen mit (double) Eintraegen zwischen 0 und 10 */
  for(i=0;i<rows;i++)
    for(j=0;j<cols;j++){
      set_entry(a,rows,i,j,(rand() % 200)/20.0);
      set_entry(qr,rows,i,j,get_entry(a,rows,i,j));
    }
  
  /* rows und cols ausgeben */
  printf("\nrows = %d, cols = %d\n",rows,cols);
  
  /* Minimum von rows und cols ausgeben */
  printf("Minimum = %d\n",min_int(rows,cols));
  
  /* Matrix a ausgeben */
  printf("\na:\n");
  print_matrix(qr,rows,cols);
  
  /* qr-Zerlegung */
  qr_decomp(qr,rows,cols,rows);
  
  /* qr-Zerlegung ausgeben */
  printf("\nqr:\n");
  print_matrix(qr,rows,cols);
    
  /* Speicher freigeben */
  free(a);
  free(qr);
  
  return 0;
}
Beispiel #28
0
struct multi_tcp *
multi_tcp_init(int maxevents, int *maxclients)
{
    struct multi_tcp *mtcp;
    const int extra_events = BASE_N_EVENTS;

    ASSERT(maxevents >= 1);
    ASSERT(maxclients);

    ALLOC_OBJ_CLEAR(mtcp, struct multi_tcp);
    mtcp->maxevents = maxevents + extra_events;
    mtcp->es = event_set_init(&mtcp->maxevents, 0);
    wait_signal(mtcp->es, MTCP_SIG);
    ALLOC_ARRAY(mtcp->esr, struct event_set_return, mtcp->maxevents);
    *maxclients = max_int(min_int(mtcp->maxevents - extra_events, *maxclients), 1);
    msg(D_MULTI_LOW, "MULTI: TCP INIT maxclients=%d maxevents=%d", *maxclients, mtcp->maxevents);
    return mtcp;
}
Beispiel #29
0
void read_double( const char* szFileName, const char* szVarName, double* pVariable)
{
    char* szValue = NULL;	/* String mit dem eingelesenen Variablenwert */

    if( szVarName  == 0 )  ERROR("null pointer given as varable name" );
    if( szFileName == 0 )  ERROR("null pointer given as filename" );
    if( pVariable  == 0 )  ERROR("null pointer given as variable" );

    if( szVarName[0] == '*' )
	szValue = find_string( szFileName, szVarName +1 );
    else
	szValue = find_string( szFileName, szVarName );
    
    if( sscanf( szValue, "%lf", pVariable) == 0)
	READ_ERROR("wrong format", szVarName, szFileName, 0);

    printf( "File: %s\t\t%s%s= %f\n", szFileName, 
	                              szVarName,
	                              &("               "[min_int( strlen(szVarName), 15)]), 
	                              *pVariable );
}
Beispiel #30
0
void read_int( const char* szFileName, const char* szVarName, int* pVariable)
{
    char* szValue = NULL;	/* string containing the read variable value */

    if( szVarName  == 0 )  ERROR("null pointer given as varable name" );
    if( szFileName == 0 )  ERROR("null pointer given as filename" );
    if( pVariable  == 0 )  ERROR("null pointer given as variable" );

    if( szVarName[0] == '*' )
	szValue = find_string( szFileName, szVarName +1 );
    else
	szValue = find_string( szFileName, szVarName );
    
    if( sscanf( szValue, "%d", pVariable) == 0)
	READ_ERROR("wrong format", szVarName, szFileName, 0);

    printf( "File: %s\t\t%s%s= %d\n", szFileName, 
	                              szVarName,
	                              &("               "[min_int( strlen(szVarName), 15)]), 
	                              *pVariable );
}