Esempio n. 1
0
//==============================================================================
static void mungeJuce (const File& juceFolder)
{
    if (! juceFolder.isDirectory())
    {
        std::cout << " The folder supplied must be the root of your Juce directory!\n\n";
        return;
    }

    const File hppTemplate (juceFolder.getChildFile ("amalgamation/juce_amalgamated_template.h"));
    const File cppTemplate (juceFolder.getChildFile ("amalgamation/juce_amalgamated_template.cpp"));

    const File hppTarget (juceFolder.getChildFile ("juce_amalgamated.h"));
    const File cppTarget (juceFolder.getChildFile ("juce_amalgamated.cpp"));

    StringArray alreadyIncludedFiles, includesToIgnore;

    if (! munge (hppTemplate, hppTarget, "*.h", alreadyIncludedFiles, includesToIgnore))
    {
        return;
    }

    findAllFilesIncludedIn (hppTemplate, alreadyIncludedFiles);
    includesToIgnore.add (hppTarget.getFileName());

    munge (cppTemplate, cppTarget, "*.cpp;*.c;*.h;*.mm;*.m", alreadyIncludedFiles, includesToIgnore);
}
void NLOPT_STDCALL nlopt_destroy(nlopt_opt opt)
{
     if (opt) {
	  unsigned i;
	  if (opt->munge_on_destroy) {
	       nlopt_munge munge = opt->munge_on_destroy;
	       munge(opt->f_data);
	       for (i = 0; i < opt->m; ++i)
		    munge(opt->fc[i].f_data);
	       for (i = 0; i < opt->p; ++i)
		    munge(opt->h[i].f_data);
	  }
	  for (i = 0; i < opt->m; ++i)
	       free(opt->fc[i].tol);
	  for (i = 0; i < opt->p; ++i)
	       free(opt->h[i].tol);
	  free(opt->lb); free(opt->ub);
	  free(opt->xtol_abs);
	  free(opt->fc);
	  free(opt->h);
	  nlopt_destroy(opt->local_opt);
	  free(opt->dx);
	  free(opt->work);
	  free(opt);
     }
}
Esempio n. 3
0
int main()
{
  std::vector<int> vi;
  munge(vi);

  std::vector<float> vf;
  munge(vf);

  C<int, bool> c;
  C<float, int> cspec;

}
Esempio n. 4
0
    void test_munge()
    {
        std::string a("foo bar");
        munge(a);
        assert_equal(a, "foo_bar");

        std::string b("/FOO.bar (\"quote\')");
        munge(b);
        assert_equal(b, "_foo.bar_(_quote_)");

        std::string c("");
        munge(c);
        assert_equal(c, "");
    }
Esempio n. 5
0
//==============================================================================
int main (int argc, char* argv[])
{
    std::cout << "\n*** The C++ Amalgamator! Written for Juce - www.rawmaterialsoftware.com\n";

    if (argc == 4)
    {
        const File templateFile (File::getCurrentWorkingDirectory().getChildFile (String (argv[1]).unquoted()));
        const File targetFile (File::getCurrentWorkingDirectory().getChildFile (String (argv[2]).unquoted()));
        const String wildcard (String (argv[3]).unquoted());
        StringArray alreadyIncludedFiles, includesToIgnore;

        munge (templateFile, targetFile, wildcard, alreadyIncludedFiles, includesToIgnore);
    }
    else if (argc == 2)
    {
        const File juceFolder (File::getCurrentWorkingDirectory().getChildFile (String (argv[1]).unquoted()));
        mungeJuce (juceFolder);
    }
    else
    {
        std::cout << " Usage: amalgamator TemplateFile TargetFile \"FileToReplaceWildcard\"\n\n"
                     " amalgamator will run through a C++ file and replace any\n"
                     " #include statements with the contents of the file they refer to.\n"
                     " It'll only do this for files that are within the same parent\n"
                     " directory as the target file, and will ignore include statements\n"
                     " that use '<>' instead of quotes. It'll also only include a file once,\n"
                     " ignoring any repeated instances of it.\n\n"
                     " The wildcard lets you specify what kind of files will be replaced, so\n"
                     " \"*.cpp;*.h\" would replace only includes that reference a .cpp or .h file.\n\n"
                     " Or: just run 'amalgamator YourJuceDirectory' to rebuild the juce files.";
    }

    std::cout << "\n";
    return 0;
}
Esempio n. 6
0
int main(void) {
  pthread_t id;
  pthread_create(&id, NULL, t_fun, NULL);
  munge(&mutex2,&myglobal2); // NOWARN!
  pthread_join (id, NULL);
  return 0;
}
Esempio n. 7
0
int wn_random_ints_fill_buf()
{
  int feedback, ret;

  /* compute output bits */
  switch (out_munge_num)
  {
#include "wnrdo.h"
  }
  wn_random_ints_count = WN_RANDOM_WIDTH - 1;  /* wn_random_ints_buf is 1 less than full */
  ++out_munge_num;
  if (out_munge_num == NUM_OUT_MUNGE_BLOCKS)
  {
    out_munge_num = 0;
  }

  /* compute feedback bits */
  feedback = munge(state_pointer,feedback_munge_pointer);
  increment_feedback_munge_pointer();

  /* stuff feedback bits back into shift register */
  decrement_state_pointer();
  (*state_pointer) ^= feedback;

  return(ret);
}
Esempio n. 8
0
int main(int argc, char *argv[]) {
  
  int x = 10;
  int y = 11;
  deposit1(10);
  deposit2(11);

  transfer(100);

  safeDeposit(&gLock2, 2, 1337);

  condDeposit1(1, 10);

  _spin_lock(&gLock1);
  foo();
  _spin_lock(&gLock2);

  glob2++;
  lockedOnEntry();

  _spin_unlock(&gLock1);


  if(y < x)
    goto label1; 
  x++;
  y++;

  munge(&V1,&gLockV1);
  munge(&V2,&gLockV2);
  munge(&V3,&gLockV3);

  recurses(&V1,&gLockV1);

  multi_recurses1(&gLockV4);

 label0:
  y++;
  return 0;

 label1:
  x++;
  return 1;
  


}
Esempio n. 9
0
int main(int argc, char *argv[]) {
  int i;
  printf("Starting ...");
  for (i=1; i<argc; ++i) {
    printf("\"%s\" => ", argv[i]);
    printf("\"%s\"\n", munge(argv[i]));
  }
}
Esempio n. 10
0
void
deps_add_dep (struct deps *d, const char *t)
{
  t = munge (apply_vpath (d, t));  /* Also makes permanent copy.  */

  if (d->ndeps == d->deps_size)
    {
      d->deps_size = d->deps_size * 2 + 8;
      d->depv = xrealloc (d->depv, d->deps_size * sizeof (const char *));
    }
  d->depv[d->ndeps++] = t;
}
nlopt_result
NLOPT_STDCALL nlopt_remove_equality_constraints(nlopt_opt opt)
{
     unsigned i;
     if (!opt) return NLOPT_INVALID_ARGS;
     if (opt->munge_on_destroy) {
	  nlopt_munge munge = opt->munge_on_destroy;
	  for (i = 0; i < opt->p; ++i)
	       munge(opt->h[i].f_data);
     }
     for (i = 0; i < opt->p; ++i)
	  free(opt->h[i].tol);
     free(opt->h);
     opt->h = NULL;
     opt->p = opt->p_alloc = 0;
     return NLOPT_SUCCESS;
}
Esempio n. 12
0
/* Adds a target T.  We make a copy, so it need not be a permanent
   string.  QUOTE is true if the string should be quoted.  */
void
deps_add_target (struct deps *d, const char *t, int quote)
{
  if (d->ntargets == d->targets_size)
    {
      d->targets_size = d->targets_size * 2 + 4;
      d->targetv = xrealloc (d->targetv,
			     d->targets_size * sizeof (const char *));
    }

  t = apply_vpath (d, t);
  if (quote)
    t = munge (t);  /* Also makes permanent copy.  */
  else
    t = xstrdup (t);

  d->targetv[d->ntargets++] = t;
}
nlopt_opt NLOPT_STDCALL nlopt_copy(const nlopt_opt opt)
{
     nlopt_opt nopt = NULL;
     unsigned i;
     if (opt) {
	  nlopt_munge munge;
	  nopt = (nlopt_opt) malloc(sizeof(struct nlopt_opt_s));
	  *nopt = *opt;
	  nopt->lb = nopt->ub = nopt->xtol_abs = NULL;
	  nopt->fc = nopt->h = NULL;
	  nopt->m_alloc = nopt->p_alloc = 0;
	  nopt->local_opt = NULL;
	  nopt->dx = NULL;
	  nopt->work = NULL;
	  opt->force_stop_child = NULL;

	  munge = nopt->munge_on_copy;
	  if (munge && nopt->f_data)
	       if (!(nopt->f_data = munge(nopt->f_data))) goto oom;

	  if (opt->n > 0) {
	       nopt->lb = (double *) malloc(sizeof(double) * (opt->n));
	       if (!opt->lb) goto oom;
	       nopt->ub = (double *) malloc(sizeof(double) * (opt->n));
	       if (!opt->ub) goto oom;
	       nopt->xtol_abs = (double *) malloc(sizeof(double) * (opt->n));
	       if (!opt->xtol_abs) goto oom;
	       
	       memcpy(nopt->lb, opt->lb, sizeof(double) * (opt->n));
	       memcpy(nopt->ub, opt->ub, sizeof(double) * (opt->n));
	       memcpy(nopt->xtol_abs, opt->xtol_abs, sizeof(double) * (opt->n));
	  }

	  if (opt->m) {
	       nopt->m_alloc = opt->m;
	       nopt->fc = (nlopt_constraint *) malloc(sizeof(nlopt_constraint)
						      * (opt->m));
	       if (!nopt->fc) goto oom;
	       memcpy(nopt->fc, opt->fc, sizeof(nlopt_constraint) * (opt->m));
	       for (i = 0; i < opt->m; ++i) nopt->fc[i].tol = NULL;
	       if (munge)
		    for (i = 0; i < opt->m; ++i)
			 if (nopt->fc[i].f_data &&
			     !(nopt->fc[i].f_data
			       = munge(nopt->fc[i].f_data)))
			      goto oom;
	       for (i = 0; i < opt->m; ++i)
		    if (opt->fc[i].tol) {
			 nopt->fc[i].tol = (double *) malloc(sizeof(double)
							     * nopt->fc[i].m);
			 if (!nopt->fc[i].tol) goto oom;
			 memcpy(nopt->fc[i].tol, opt->fc[i].tol,
				sizeof(double) * nopt->fc[i].m);
		    }
	  }

	  if (opt->p) {
	       nopt->p_alloc = opt->p;
	       nopt->h = (nlopt_constraint *) malloc(sizeof(nlopt_constraint)
						     * (opt->p));
	       if (!nopt->h) goto oom;
	       memcpy(nopt->h, opt->h, sizeof(nlopt_constraint) * (opt->p));
	       for (i = 0; i < opt->p; ++i) nopt->h[i].tol = NULL;
	       if (munge)
		    for (i = 0; i < opt->p; ++i)
			 if (nopt->h[i].f_data &&
			     !(nopt->h[i].f_data
			       = munge(nopt->h[i].f_data)))
			      goto oom;
	       for (i = 0; i < opt->p; ++i)
		    if (opt->h[i].tol) {
			 nopt->h[i].tol = (double *) malloc(sizeof(double)
							     * nopt->h[i].m);
			 if (!nopt->h[i].tol) goto oom;
			 memcpy(nopt->h[i].tol, opt->h[i].tol,
				sizeof(double) * nopt->h[i].m);
		    }
	  }

	  if (opt->local_opt) {
	       nopt->local_opt = nlopt_copy(opt->local_opt);
	       if (!nopt->local_opt) goto oom;
	  }

	  if (opt->dx) {
	       nopt->dx = (double *) malloc(sizeof(double) * (opt->n));
	       if (!nopt->dx) goto oom;
	       memcpy(nopt->dx, opt->dx, sizeof(double) * (opt->n));
	  }
     }
     return nopt;

oom:
     nopt->munge_on_destroy = NULL; // better to leak mem than crash
     nlopt_destroy(nopt);
     return NULL;
}
Esempio n. 14
0
void *t_fun(void *arg) {
  munge(&mutex1, &myglobal1); // NOWARN!
  return NULL;
}
Esempio n. 15
0
/**
   Get description for a specified mimetype.
*/
static char *get_description( const char *mimetype )
{
    char *fn_part;

    char *fn;
    int fd;
    struct stat st;
    char *contents;
    char *start=0, *stop=0, *best_start=0;

    if( !start_re )
    {
        char *lang;
        char buff[BUFF_SIZE];

        lang = get_lang_re();
        if( !lang )
            return 0;

        snprintf( buff, BUFF_SIZE, START_TAG, lang, lang );

        start_re = my_malloc( sizeof(regex_t));
        stop_re = my_malloc( sizeof(regex_t));

        int reg_status;
        if( ( reg_status = regcomp( start_re, buff, REG_EXTENDED ) ) )
        {
            char regerrbuf[BUFF_SIZE];
            regerror(reg_status, start_re, regerrbuf, BUFF_SIZE);
            fprintf( stderr, _( "%s: Could not compile regular expressions %s with error %s\n"), MIMEDB, buff, regerrbuf);
            error=1;

        }
        else if ( ( reg_status = regcomp( stop_re, STOP_TAG, REG_EXTENDED ) ) )
        {
            char regerrbuf[BUFF_SIZE];
            regerror(reg_status, stop_re, regerrbuf, BUFF_SIZE);
            fprintf( stderr, _( "%s: Could not compile regular expressions %s with error %s\n"), MIMEDB, buff, regerrbuf);
            error=1;

        }

        if( error )
        {
            free( start_re );
            free( stop_re );
            start_re = stop_re = 0;

            return 0;
        }
    }

    fn_part = my_malloc( strlen(MIME_DIR) + strlen( mimetype) + strlen(MIME_SUFFIX) + 1 );

    if( !fn_part )
    {
        return 0;
    }

    strcpy( fn_part, MIME_DIR );
    strcat( fn_part, mimetype );
    strcat( fn_part, MIME_SUFFIX );

    fn = get_filename(fn_part); //malloc( strlen(MIME_DIR) +strlen( MIME_SUFFIX)+ strlen( mimetype ) + 1 );
    free(fn_part );

    if( !fn )
    {
        return 0;
    }

    fd = open( fn, O_RDONLY );

//	fprintf( stderr, "%s\n", fn );

    if( fd == -1 )
    {
        perror( "open" );
        error=1;
        return 0;
    }

    if( stat( fn, &st) )
    {
        perror( "stat" );
        error=1;
        return 0;
    }

    contents = my_malloc( st.st_size + 1 );
    if( !contents )
    {
        return 0;
    }

    if( read( fd, contents, st.st_size ) != st.st_size )
    {
        perror( "read" );
        error=1;
        return 0;
    }

    /*
      Don't need to check exit status of close on read-only file descriptors
    */
    close( fd );
    free( fn );

    contents[st.st_size]=0;
    regmatch_t match[1];
    int w = -1;

    start=contents;

    /*
      On multiple matches, use the longest match, should be a pretty
      good heuristic for best match...
    */
    while( !regexec(start_re, start, 1, match, 0) )
    {
        int new_w = match[0].rm_eo - match[0].rm_so;
        start += match[0].rm_eo;

        if( new_w > w )
        {
            /*
               New match is for a longer match then the previous
               match, so we use the new match
            */
            w=new_w;
            best_start = start;
        }
    }

    if( w != -1 )
    {
        start = best_start;
        if( !regexec(stop_re, start, 1, match, 0) )
        {
            /*
              We've found the beginning and the end of a suitable description
            */
            char *res;

            stop = start + match[0].rm_so;
            *stop = '\0';
            res = munge( start );
            free( contents );
            return res;
        }
    }
    free( contents );
    fprintf( stderr, _( "%s: No description for type %s\n"), MIMEDB, mimetype );
    error=1;
    return 0;

}
Esempio n. 16
0
thread t1 () {
    munge (&x, &m1);
    munge (&y, &m2);
    munge (&z, &m2);
}
void OptiXRenderer::saveToPPMFile(char* filename, optix::float4* image, int width, int height) {
	FILE* f;
	/*
	char sbuffer[100];
	sprintf(sbuffer, "photons-%d.ppm", fileid);
	fileid++;
	*/
	// Find highest value
	float magic_number = 0;
	float biggest = 0;
	for(int i=0;i<width*height;i++) {
		if(image[i].x>biggest) biggest = image[i].x;
		if(image[i].y>biggest) biggest = image[i].y;
		if(image[i].z>biggest) biggest = image[i].z;
	}
	printf("Biggest value is %f\n", biggest);
	float biggest_munge = munge(biggest);
	float max_hits = 0;
	for(int i=0;i<width*height;i++) {
		if(image[i].w>max_hits) max_hits = image[i].w;
	}
	printf("Maximum hits is %d\n", max_hits);
	float sum = 0;
	float sumr, sumg, sumb;
	for(int i=0;i<width*height;i++) {
		sum += image[i].x;
		sumr+= image[i].x;
		sum += image[i].y;
		sumg+= image[i].y;
		sum += image[i].z;
		sumb+= image[i].z;
	}
	printf("SUM colour value is %f\n", sum);
	float average = sum/(width*height*3);
	float avgr = sumr/(width*height);
	float avgg = sumg/(width*height);
	float avgb = sumb/(width*height);
	printf("Avg colour value is %f\n", average);
	// BUild file
	f = fopen(filename, "w");
	int maxVal = 65535;
	fprintf(f, "P3\n");
	fprintf(f, "%d %d\n", width, height);
	fprintf(f, "%d\n", maxVal);
	fprintf(f, "\n");
	for(int i=0;i<width;i++){
		for(int j=height-1;j>=0;j--){
			// Get our pixel
			optix::float4 pixel = image[index(i, j, width)];
			// Do some calculation
			float pixel_high = 0.00000000000000001f;
			if(pixel.x>pixel_high) pixel_high = pixel.x;
			if(pixel.y>pixel_high) pixel_high = pixel.y;
			if(pixel.z>pixel_high) pixel_high = pixel.z;
			//float brightness = 3;//(pixel.w/max_hits)*0.5+0.5;
			float pixel_low = 1000000000000000000000000.0f;
			if(pixel.x<pixel_low) pixel_low = pixel.x;
			if(pixel.y<pixel_low) pixel_low = pixel.y;
			if(pixel.z<pixel_low) pixel_low = pixel.z;
			float avg_pixel_brightness = ((pixel.x+pixel.y+pixel.z)/3);
			// Get RGB values
			float r, g, b; // 0.0f-1.0f
			float  h, s, v; // 0.0f-1.0f
			float  h2, s2, v2; // 0.0f-1.0f
			float mod = avg_pixel_brightness/average;
			r = pixel.x/pixel_high;
			g = pixel.y/pixel_high;
			b = pixel.z/pixel_high;
			// I whip my colours back and forth
			rgb2hsv(r, g, b, &h, &s, &v);
			//v = pixel.w/max_hits;
			//r = pixel.x/pixel_high*mod;
			//g = pixel.y/pixel_high*mod;
			//b = pixel.z/pixel_high*mod;
			//rgb2hsv(r, g, b, &h2, &s2, &v2);
			//if(v>1.0f) v = 1.0f;
			const int factor = 2;
			s = pow(pixel_high - pixel_low, factor)/pow(pixel_high, factor);
			v = munge(pixel.w)/munge(max_hits);
			v *= 2.0f;
			if(v>1.0f) v = 1.0f;
			r = g = b = 0;
			hsv2rgb(h, s, v, &r, &g, &b);
			// Write to file
			fprintf(f," %d %d %d \n",
				toColourInt(r, maxVal),
				toColourInt(g, maxVal),
				toColourInt(b, maxVal)
			);
		}
	}
	fclose(f);
}