Beispiel #1
0
/* Given a working directory and an arbitrary pathname, resolve them into
 * an absolute pathname. Memory is allocated for the result, which
 * the caller must free
 */
char *
pathname(
char *cd,       /* Current working directory */
char *path)     /* Pathname argument */
{
	register char *buf;

	if(cd == NULL || path == NULL)
		return NULL;

	/* Strip any leading white space on args */
	while(*cd == ' ' || *cd == '\t')
		cd++;
	while(*path == ' ' || *path == '\t')
		path++;

	/* Allocate and initialize output buffer; user must free */
	buf = (char *) mallocw((unsigned)strlen(cd) + strlen(path) + 10);        /* fudge factor */
	buf[0] = '\0';

	/* Interpret path relative to cd only if it doesn't begin with "/" */
	if(path[0] != '/')
		crunch(buf,cd);

	crunch(buf,path);

	/* Special case: null final path means the root directory */
	if(buf[0] == '\0'){
		buf[0] = '/';
		buf[1] = '\0';
	}
	return buf;
}
Beispiel #2
0
int
sc_main( int argc, char* argv[] )
{
    sc_signed x(31);
    sc_signed y(9);
    sc_signed z(31);
    int9 v;

    y = -256;
    v.q = -256;
    assert(y == v.q);
    cout << y << '\t' << v.q << endl;
    for (int i = 0; i < 1000; ++i) {
        y++;
        v.q++;
        fix_int9(v);
        cout << y << '\t' << v.q << endl;
        assert(y == v.q);
    }
    for (int i = 0; i < 1000; ++i) {
        y--;
        v.q--;
        fix_int9(v);
        cout << y << '\t' << v.q << endl;
        assert(y == v.q);
    }
    for (int i = 0; i < 1000; ++i) {
        ++y;
        ++v.q;
        fix_int9(v);
        cout << y << '\t' << v.q << endl;
        assert(y == v.q);
    }
    for (int i = 0; i < 1000; ++i) {
        --y;
        --v.q;
        fix_int9(v);
        cout << y << '\t' << v.q << endl;
        assert(y == v.q);
    }

    z = 129023;
    int31 v31;
    v31.q = 129023;
    crunch(z, v31, 491, 12089);

    x = -129023;
    v31.q = -129023;
    crunch(x, v31, 109, -426);

    x = -1;
    v31.q = -1;
    crunch(x, v31, 30941, -1188);
    
    return 0;
}
Beispiel #3
0
void StatusItem::GeneratePopUp(BPoint point, BRect openrect)
{
	BString str(value);
	str.Append(" ");
	BString url;
	URLCrunch crunch(str.String(), str.Length());
	BPopUpMenu* menu = new BPopUpMenu("URLs");
	BMessage msg(M_LOAD_URL);
	BMessage* allocmsg(NULL);
	BMenuItem* item(NULL);

	while (crunch.Crunch(&url) != B_ERROR) {
		allocmsg = new BMessage(msg);
		allocmsg->AddString("url", url.String());
		item = new BMenuItem(url.String(), allocmsg);
		menu->AddItem(item);
		allocmsg = NULL;
	}

	if (menu->CountItems() > 0) {
		menu->SetTargetForItems(be_app);
		menu->SetAsyncAutoDestruct(true);
		menu->Go(point, true, true, openrect, true);
	} else {
		delete menu;
	}
}
DWORD WINAPI calcDelta(LPVOID params)
{
	while(now < n)
	{
		int i = now++;
		for(int j = i+1; j < n; ++j)
		{
			double* p = ori[i];
			double* q = ori[j];
			double dl = p[0] - q[0];
			double da = p[1] - q[1];
			double db = p[2] - q[2];
			// color difference
			double dc = crunch(sqrt(da * da + db * db));
			double vtheta = cos(theta) * da + sin(theta) * db;
			double tmp;
			if(abs(dl) > dc)
				tmp = dl;
			else
				tmp = dc * (vtheta>0?1:-1);
			delta[i] += tmp;
			delta[j] -= tmp;
		}
	}
	return 0;
}
Beispiel #5
0
void
sc_simcontext::initial_crunch( bool no_crunch )
{
    if ( no_crunch || m_runnable->is_empty() )
    {
        return;
    }
    m_runnable->toggle();

    // run the delta cycle loop

    crunch();
    if ( m_error )
    {
        return;
    }
    if ( m_something_to_trace )
    {
        trace_cycle( false );
    }
    // check for call(s) to sc_stop
    if ( m_forced_stop )
    {
        do_sc_stop_action();
    }
}
Beispiel #6
0
void complete(int n) {
  position p;            
  if (n <= saved) {
    printf("Already computed\n");
    return;
    }
  p.s = 0;
  fill_pos(&p,0);

  save();
  load(saved);
  size = eg.ai[n][n] * eg.bits / 8;
  printf("Allocating memory for %d stones...",n);
  fflush(stdout);
  eg.d = realloc(eg.d,size);
  memset(eg.d+eg.size, 255, size - eg.size);
  printf("done\n");
  eg.n = n;
  eg.size = size;

  int i;

  void handle_position(position *p) {
    int k = eg_index(i, p);
    if (eg_getd(k) == maxval)
      crunch(i, k, p); 
    }
Beispiel #7
0
int crunch(int n, size_t l, position *p) {
  int i,s,v,r,e,cn;
  size_t k;
  position t;
  v = 1;
  p->a[LPIT] = p->a[PITS] = 0;
  for (i=0;i<PITS;i++)
    if (bin(*p,i)) {
      t = *p;    
      s = p->s;
      e = move(&t,i); 
      r = a_bin(t,s,PITS);
      if (t.w < 0) {
        cn = n - t.a[PITS] - t.a[LPIT];
        k = eg_index(cn,&t);
        s = eg_getd(k);
        if (s == maxval) {
          s = crunch(cn,k,&t);
          r = e ? r + s : n - s;
          }
        else
          r = e ? r + s + 1 : n - s - 1;
        }
      if (v < r)
        v = r;
      }
  eg_setd(l,v-1);
  crunched++;
  return v;
  }
Beispiel #8
0
 /// Do the same action as read(n), and call crunch() function
 /// when the buffer's capacity gets less than the wr_lwm() value.
 /// @param n is the number of bytes to read.
 /// @returns -1 if there is not enough data in the buffer
 ///         to read \a n bytes.
 int read_and_crunch(int n) {
     if (UNLIKELY(read(n) == NULL))
         return -1;
     if (capacity() < m_wr_lwm)
         crunch();
     BOOST_ASSERT(m_rd_ptr <= m_wr_ptr);
     return n;
 }
Beispiel #9
0
/* parallism aware crunch routine */
void slow_crunch() {
  int i;
  c_res c;

  if (!cj->n) {  // toplevel job 
    if (cj->js[0] == JOB_FREE) {
      i = 0; 
      c.p = cj->s.p;
      c.da = cj->s.da;
      P_PUSH();
      crunch(&c,cj->d,cj->a);
      P_POP();
      cj->s.r = c.r; 
      cj->s.rd = c.rd;
      strcpy(cj->s.m,c.m);
      cj->status = JOB_DONE;
      }
    else
      cj->status = JOB_BLOCKED; 
    }
  else if (cj->js[0] == JOB_TAKEN)
    cj->status = JOB_BLOCKED;
  else {
    for (i=0;i<cj->n;i++)
      if (cj->js[i] == JOB_FREE) {
        c.o = cj->o[i];
        c.p = cj->s.p;
        c.k = move(&c.p,c.o);
        ha_lookup(ha,&c.da,&c.p);
        P_PUSH();
        crunch(&c,cj->d-1,c.k ? cj->a : -cj->a-1);
        P_POP();
        slow_absorb(cj,&c);         
        if (cj->status == JOB_DONE)
          break;
        }
    for (i=0;i<cj->n;i++)
      if (cj->js[i] != JOB_DONE)
        break;
    cj->status = (i < cj->n) ? JOB_BLOCKED : JOB_DONE;
    }
  }
Beispiel #10
0
double doComp(int compIters, double* a, double* b)
{
     double c;
     int i;

     set(a);
     set(b);
     c = 0.0;

     for ( i = 0; i < compIters; i++ )
          c += crunch(a, b, c);

     return c;
}
inline
void
sc_simcontext::cycle( const sc_time& t)
{
    sc_time next_event_time;

    m_in_simulator_control = true;
    m_runnable->toggle();
    crunch(); 
    trace_cycle( /* delta cycle? */ false );
    m_curr_time += t;
    next_event_time = next_time();
    if ( next_event_time != SC_ZERO_TIME && next_event_time <= m_curr_time) {
        SC_REPORT_WARNING(SC_ID_CYCLE_MISSES_EVENTS_, "");
    }
    m_in_simulator_control = false;
}
Beispiel #12
0
static unsigned char get_char_lsb(const char c)
{
	return crunch(c) & 0x07;
}
Beispiel #13
0
_NIL_TYPE_ _mem_reclaim_(const _UNS_TYPE_ mrg)
 { sweep();
   update();
   crunch();
   if ((_mem_FREE_ + mrg) > _mem_TOP_)
     _error_(_MEM_ERROR_); }
Beispiel #14
0
int
main(int argc, char **argv)
{
    long size[NUMFILES];
    long totsize;
    char buf[20], name[40];
    byte *inbuf, *ptr;
    byte *outbuf;
    long outsize;
    int i, fd;
    DTA *dt;
    int compress, noheader;
    int interactive = 1;

    dt = (DTA *)Fgetdta();

    compress = 0;
    noheader = 0;

    printf("\nSuperglue v1.0\n");
    while (argc > 1) {
        ptr = (byte *)argv[1];
        argv++;
        --argc;
        if (*ptr == '-') {
            ptr++;
            switch (*ptr) {
            case 'c':
                compress = 1;
                i = atoi(ptr+1);
                if (i) gl_matchsize = i;
                break;
            case 'n':
                noheader = 1;
                break;
            default:
                printf("usage: superglu [-n][-c#] [extension]\n");
                break;
            }
        } else {
            interactive = 0;
            break;
        }
    }

    puts(compress ? "COMPRESSING resources" : "storing resources" );
    if (interactive) {
        printf("\nPlease enter the 3 letter country abbreviation, or\n");
        printf("type 'exit' to quit\n");
    }

    do {
        totsize = HEADERSIZE;
        if (interactive) {
            printf("> ");
            fflush(stdout);
            gets(buf);
            if (strlen(buf) > 3) break;
        } else {
            strcpy(buf, *argv);
        }

        /* first, find the sizes of the pieces */
        for (i = 0; i < NUMFILES; i++) {
            sprintf(name, fname[i], buf);
            if (Fsfirst(name, 0) != 0) {
                printf("%s: not found\n", name);
                goto top;
            }
            size[i] = dt->dta_size;
            /* we round all file sizes up to the next even number when we
             * read them into memory, so everything will be on a word boundary
             */
            totsize += ROUND(size[i]);
        }


        ptr = inbuf = (byte *)Malloc( totsize );
        if (!inbuf) {
            printf("not enough memory: couldn't allocate %ld bytes\n",
                   totsize);
            goto top;
        }

        ptr += HEADERSIZE;

        /* now, go read the files */
        for (i = 0; i < NUMFILES; i++) {
            sprintf(name, fname[i], buf);
            fd = Fopen(name, 0);
            if (fd < 0) {
                printf("couldn't open %s\n", name);
                Mfree(inbuf);
                goto top;
            }
            puts(name);
            if (Fread(fd, size[i], ptr) != size[i]) {
                printf("Error during read\n");
                Mfree(inbuf);
                Fclose(fd);
                goto top;
            }
            Fclose(fd);
            ptr += ROUND(size[i]);
            /* fill in the size in the header */
            ((long *)inbuf)[i] = ROUND(size[i]);
        }

        /* OK, now write the result */
        sprintf(name, "glue.%s", buf);
        fd = Fcreate(name, 0);
        if (fd < 0) {
            printf("couldn't create %s\n", name);
            Mfree(inbuf);
            goto top;
        }

        if (compress) {
            outbuf = (byte *)Malloc( totsize * 2 );
            if (!outbuf) {
                printf("NO MEMORY FOR COMPRESSION!!\n");
                printf("storing resource instead\n");
                compress = 0;
            }
        }
        if (compress) {
            magic[0] = 0xab;
            magic[1] = 0x08;
            outsize = crunch(inbuf, totsize, outbuf);
        } else {
            outbuf = inbuf;
            outsize = totsize;
            magic[0] = magic[1] = 0;
        }
        printf("Writing %s...\n", name);

        /* first, the file header */
        if (!noheader) {
            Fwrite(fd, 2L, magic);
            Fwrite(fd, 4L, &totsize);
            Fwrite(fd, 4L, &outsize);
        }

        /* now write the data */
        if (Fwrite(fd, outsize, outbuf) != outsize) {
            printf("write error!\n");
        }

        Fclose(fd);
        Mfree(inbuf);
        if (compress) Mfree(outbuf);
top:
        ;
    } while (interactive);

    return 0;
}
/**
______________________________________________________
//  Remove frames , the frame are given as seen by GUI
//  We remove from start to end -1
// [start,end[
//______________________________________________________
*/
uint8_t ADM_Composer::removeFrames (uint32_t start, uint32_t end)
{

  uint32_t
    seg1,
    seg2,
    rel1,
    rel2;
  uint8_t
    lastone =
    0;

  if (end == _total_frames - 1)
    lastone = 1;

  // sanity check
  if (start > end)
    return 0;
  //if((1+start)==end) return 0;

  // convert frame to block, relative frame
  if (!convFrame2Seg (start, &seg1, &rel1) ||
      !convFrame2Seg (end, &seg2, &rel2))
    {
      assert (0);
    }
  // if seg1 != seg2 we can just modify seg1 and seg2
  if (seg1 != seg2)
    {
      // remove end of seg1

      removeFrom (rel1, seg1, 1);
      //  delete in between seg
      for (uint32_t seg = seg1 + 1; seg < (seg2); seg++)
	_segments[seg]._nb_frames = 0;
      // remove beginning of seg2
      removeTo (rel2, seg2, lastone);
    }
  else
    {
      // it is in the same segment, split it...
      // complete seg ?
      if ((rel1 == _segments[seg1]._start_frame)
	  && (rel2 ==
	      (_segments[seg1]._start_frame +
	       _segments[seg1]._nb_frames - 1)))
	{
	  _segments[seg1]._nb_frames = 0;
	}
      else
	{
	  // split in between.... duh !
	  duplicateSegment (seg1);
	  //
	  removeFrom (rel1, seg1, 1);
	  removeTo (rel2, seg1 + 1, lastone);
	}
    }

  // Crunch
  crunch ();
  sanityCheck ();
  // Compute total nb of frame
  _total_frames = computeTotalFrames ();
  printf ("\n %lu frames ", _total_frames);
  return 1;

}
static
void level(const char *appl, int argc, char *argv[])
{
    char flags_arr[32];
    int forward_mode = 0;
    int literal_sequences_used = 0;
    int max_safety = 0;
    int c;
    int infilec;
    char **infilev;

    struct crunch_options options[1] = { CRUNCH_OPTIONS_DEFAULT };
    struct common_flags flags[1] = {{NULL, DEFAULT_OUTFILE}};

    struct membuf in[1];
    struct membuf out[1];

    flags->options = options;

    LOG(LOG_DUMP, ("flagind %d\n", flagind));
    sprintf(flags_arr, "f%s", CRUNCH_FLAGS);
    while ((c = getflag(argc, argv, flags_arr)) != -1)
    {
        LOG(LOG_DUMP, (" flagind %d flagopt '%c'\n", flagind, c));
        switch (c)
        {
        case 'f':
            forward_mode = 1;
            break;
        default:
            handle_crunch_flags(c, flagarg, print_level_usage, appl, flags);
        }
    }

    membuf_init(in);
    membuf_init(out);

    infilev = argv + flagind;
    infilec = argc - flagind;

    if (infilec == 0)
    {
        LOG(LOG_ERROR, ("Error: no input files to process.\n"));
        print_level_usage(appl, LOG_NORMAL, DEFAULT_OUTFILE);
        exit(1);
    }

    /* append the files instead of merging them */
    for(c = 0; c < infilec; ++c)
    {
        struct crunch_info info[1];
        int in_load;
        int in_len;
        int out_pos;
        out_pos = membuf_memlen(out);

        in_load = do_load(infilev[c], in);
        in_len = membuf_memlen(in);

        if(forward_mode)
        {
            /* append the starting address of decrunching */
            membuf_append_char(out, in_load >> 8);
            membuf_append_char(out, in_load & 255);

            crunch(in, out, options, info);
        }
        else
        {
            crunch_backwards(in, out, options, info);

            /* append the starting address of decrunching */
            membuf_append_char(out, (in_load + in_len) & 255);
            membuf_append_char(out, (in_load + in_len) >> 8);

            /* reverse the just appended segment of the out buffer */
            reverse_buffer((char*)membuf_get(out) + out_pos,
                           membuf_memlen(out) - out_pos);
        }

        if(info->literal_sequences_used)
        {
            literal_sequences_used = 1;
        }
        if(info->needed_safety_offset > max_safety)
        {
            max_safety = info->needed_safety_offset;
        }
    }
Beispiel #17
0
void
sc_simcontext::simulate( const sc_time& duration )
{
    initialize( true );

    if (sim_status() != SC_SIM_OK)
    {
        return;
    }

    sc_time non_overflow_time =
        sc_time(~sc_dt::UINT64_ZERO, false) - m_curr_time;
    if ( duration > non_overflow_time )
    {
        SC_REPORT_ERROR(SC_ID_SIMULATION_TIME_OVERFLOW_, "");
        return;
    }
    else if ( duration < SC_ZERO_TIME )
    {
        SC_REPORT_ERROR(SC_ID_NEGATIVE_SIMULATION_TIME_,"");
    }
    m_in_simulator_control = true;

    sc_time until_t = m_curr_time + duration;

    m_until_event->cancel();  // to be on the safe side
    m_until_event->notify_internal( duration );

    sc_time t;

    // IF DURATION WAS ZERO WE ONLY CRUNCH:
    //
    // We duplicate the code so that we don't add the overhead of the
    // check to each loop in the do below.
    if ( duration == SC_ZERO_TIME )
    {
        m_runnable->toggle();
        crunch( true );
        if ( m_error ) return;
        if ( m_something_to_trace ) trace_cycle( /* delta cycle? */ false );
        if ( m_forced_stop )
            do_sc_stop_action();
        return;
    }


    // NON-ZERO DURATION: EXECUTE UP TO THAT TIME:
    do
    {
        m_runnable->toggle();

        crunch();
        if ( m_error )
        {
            m_in_simulator_control = false;
            return;
        }
        if ( m_something_to_trace )
        {
            trace_cycle( false );
        }
        // check for call(s) to sc_stop
        if ( m_forced_stop )
        {
            do_sc_stop_action();
            return;
        }

        do
        {
            t = next_time();

            // PROCESS TIMED NOTIFICATIONS

            do
            {
                sc_event_timed* et = m_timed_events->extract_top();
                sc_event* e = et->event();
                delete et;
                if ( e != 0 )
                {
                    e->trigger();
                }
            }
            while ( m_timed_events->size() &&
                    m_timed_events->top()->notify_time() == t );

        }
        while ( m_runnable->is_empty() && t != until_t );
        if ( t > m_curr_time ) m_curr_time = t;

    }
    while ( t != until_t );
    m_in_simulator_control = false;
}