Exemplo n.º 1
0
/*
 * Checks if the PID in path is still valid by sending signal 0 (does not do
 * anything). kill() will return ESRCH if the process does not exist and 0 or
 * EPERM (depending on the uid) if it exists.
 *
 * If multiple files match the glob pattern, all of them will be checked until
 * the first running process is found.
 *
 */
bool process_runs(const char *path) {
    static char pidbuf[16];
    static glob_t globbuf;
    memset(pidbuf, 0, sizeof(pidbuf));

    if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) != 0)
        die("glob() failed\n");
    if (globbuf.gl_pathc == 0) {
        /* No glob matches, the specified path does not contain a wildcard. */
        globfree(&globbuf);
        if (!slurp(path, pidbuf, sizeof(pidbuf)))
            return false;
        return (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM);
    }
    for (size_t i = 0; i < globbuf.gl_pathc; i++) {
        if (!slurp(globbuf.gl_pathv[i], pidbuf, sizeof(pidbuf))) {
            globfree(&globbuf);
            return false;
        }
        if (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM) {
            globfree(&globbuf);
            return true;
        }
    }
    globfree(&globbuf);

    return false;
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
#if 0
  char *maze, *commands;
  if(2 == argc) {
    commands = argv[1];
    maze = slurp(stdin);
  } else if(3 == argc) {
    commands = argv[1];
    maze = slurp(fopen(argv[2], "r"));
  } else {
    dumphelp();
  }
  assert(maze && commands);
  printf("Commands: '''%s''', Maze: '''%s'''\n", commands, maze);
#endif

  FILE *output = fopen("solved.gif", "wb");
  assert(output);

  /*TODO get len/width from maze */
  int width = 500;
  int height= 500;
  struct colour table[4] =
  { {0xDD, 0xFF, 0xFF},
    {0xFF, 0x00, 0x00},
    {0x00, 0x00, 0xFF},
    {0x00, 0x00, 0x00}
  };

  const int GREY = 0;
  const int RED = 1;
  const int BLUE = 2;
  const int BLACK = 3;

  char *imagedata = malloc(height*width);
  memset(imagedata, GREY, height*width);

  struct image image = {
    4,
    table,
    /*height, width,*/
    500, 100,
    imagedata,
  };

  render(argc == 2? argv[1]: "HI GUYS", BLACK, 10, 5, &image);
  render(argc == 2? argv[1]: "HI GUYS", RED, 20, 5, &image);
  render(argc == 2? argv[1]: "HI GUYS", BLUE, 30, 5, &image);
  unsigned char* outbuffer = malloc(image.width * image.height + 100); //dumb
  int outlen = encodeGIF(&image, outbuffer, output);
  fclose(output);
  free(outbuffer);
//  free(imagedata);
  return 0;
}
Exemplo n.º 3
0
int
main(int argc, char **argv)
{
	int rc;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <dump>\n", argv[0]);
		return TEST_ERR;
	}

	rc = set_default_params();
	if (rc != TEST_OK) {
		perror("Cannot set default params");
		return rc;
	}

	rc = parse_params_file(&params, stdin);
	if (rc != TEST_OK)
		return rc;

	rc = setup_arch();
	if (rc != TEST_OK)
		return rc;

	if (vmcoreinfo_file) {
		vmcoreinfo.blob = slurp(vmcoreinfo_file);
		if (vmcoreinfo.blob == NULL)
			return TEST_ERR;
	}

	if (note_file) {
		notes.blob = slurp(note_file);
		if (notes.blob == NULL)
			return TEST_ERR;
	}

	if (eraseinfo_file) {
		eraseinfo.blob = slurp(eraseinfo_file);
		if (eraseinfo.blob == NULL)
			return TEST_ERR;
	}

	rc = create_file(argv[1]);
	if (rc != TEST_OK)
		return rc;

	return TEST_OK;
}
Exemplo n.º 4
0
int
main()
{
  char* cfgtext = slurp("silo.cfg");
  char* err = calloc(2048, sizeof(char));
  json_settings settings = { 0 };
  json_value* js = json_parse_ex(&settings, cfgtext, strlen(cfgtext), err);
  free(cfgtext);
  if(js == NULL) {
    ERR(silo, "Parse error: %s", err);
    free(err);
    return 1;
  }
  TRACE(silo, "type: %d", js->type);
  TRACE(silo, "none (%d), obj (%d), array (%d), integer (%d), double (%d), "
        "string (%d), bool (%d), null (%d)", json_none, json_object,
        json_array, json_integer, json_double, json_string, json_boolean,
        json_null);

  size_t ndims;
  size_t* dimens = js_dimensions(js, &ndims);

  printf("dtype: %d\n", (int)js_datatype(js));
  double** mycoords = js_coord_arrays(js, dimens, ndims);
  assert(mycoords);

  for(size_t i=0; i < ndims; ++i) { free(mycoords[i]); }
  free(mycoords);
  free(dimens);
  free(err);
  json_value_free(js);
  return 0;
}
Exemplo n.º 5
0
int
main(int argc, char **argv)
{
    if (argc != 3) die(": requires args: acism_file text_file");

    plan_tests(2);

    FILE *pfp = fopen(argv[1], "r");
    if (!pfp) die(": unable to open %s:", argv[1]);

    MEMREF text = bufref(slurp(argv[2]));
    if (nilref(text)) die(": unable to load %s:", argv[2]);

    ACISM *psp = acism_mmap(pfp);
    ok(psp, "acism_mmap returned");
    fclose(pfp);
    double t0 = tick();
    ok(!acism_scan(psp, text, on_match, NULL),
        "mmap-ed acism object works");

    fprintf(stderr, "# nmatches: %d %.4f secs\n", nmatches, tick() - t0);
    acism_dump(psp, PS_STATS, stderr, NULL);
    acism_destroy(psp);

    return exit_status();
}
Exemplo n.º 6
0
int main() {
	slurp();
	blow_path();
	drop_crumbs(&matrix[0][0]);
	draw_path();
	printf("Best sum = %ld\n", matrix[0][0].best_sum);
	return 0;
}
Exemplo n.º 7
0
Arquivo: original.c Projeto: jvia/os
// define your mutexes and semaphores here 
void *my_thread(void *input) { 
  char aname = *(char *)input; // name of aardvark, for debugging
  while (chow_time()) { 
    // Should only eat if there enough ants and not too many aardvarks
    slurp(aname, lrand48() % ANTHILLS);
  }
  return NULL; 
} 
Exemplo n.º 8
0
void load(const std::string& file, environment_t* target)
{
  if ( global_opts.verbose )
    fprintf(stderr, "Loading file %s\n", file.c_str());

  program_t *p = parse(slurp(open_file(file)), target);
  eval(cons(symbol("begin"), p->root), p->globals);
}
Exemplo n.º 9
0
int main(int argc, char **argv) {
    Home home = slurp(argv[1]);

    Debug() << home << std::endl;
    std::cout << std::fixed << std::setprecision(2) << home.findsophie() << std::endl;

    return 0;
}
Exemplo n.º 10
0
void handle_keyboard_input() {
	int key, result;
	char customkey[8] = { 0 }, * marked = NULL;

	fflush(stderr);
	if((key = fgetc(stdin)) == -1)
		return;

	if(key == 27) {
		int ch;
		while((ch = fgetc(stdin)) != -1 && !strchr("ABCDEFGHMPQRSZojmk~", ch));
		return;
	}

	snprintf(customkey, sizeof(customkey), "key0x%02X", key & 0xFF);
	if(haskey(& rc, customkey))
		run(meta(value(& rc, customkey), M_SHELLESC, & track));

	switch(key) {
		case 'l':
			puts(rate("L") ? "Loved." : "Sorry, failed.");
			break;

		case 'U':
			puts(rate("U") ? "Unloved." : "Sorry, failed.");
			break;

		case 'B':
			puts(rate("B") ? "Banned." : "Sorry, failed.");
			fflush(stdout);
			enable(INTERRUPTED);
			kill(playfork, SIGUSR1);
			break;

		case 'n':
			rate("S");
			break;

		case 'q':
			if(haskey(& rc, "delay-change")) {
				delayquit = !delayquit;
				if(delayquit)
					fputs("Going to quit soon.\n", stderr);
				else
					fputs("Delayed quit cancelled.\n", stderr);
			}
			break;

		case 'Q':
			quit();

		case 'i':
			if(playfork) {
				const char * path = rcpath("i-template");
				if(path && !access(path, R_OK)) {
					char ** template = slurp(path);
					if(template != NULL) {
Exemplo n.º 11
0
static bool file_read_number(const char *path, float *out) {
    static char contentbuf[64];
    if (!out)
        die("out == NULL\n");
    if (!slurp(path, contentbuf, sizeof(contentbuf)))
        return false;
    *out = strtof(contentbuf, NULL);
    return true;
}
Exemplo n.º 12
0
GestureScript GestureDetector::load_file(string filename)
{
    string code = slurp(filename);

    RKGestureContext* context = ((State*)internal_state)->gesture_context;
    rkgs_load(context,filename.c_str(),code.c_str());

    GestureScript script;
    return script;
}
Exemplo n.º 13
0
char *slurp_file (char *filename)
{
  char *result;
  FILE *f = fopen(filename, "r");
  if (!f) return empty_string();

  result = slurp(f);
  fclose(f);
  return result;
}
Exemplo n.º 14
0
char *slurp_command (char *command)
{
  char *result;
  FILE *p = popen(command, "r");
  if (!p) return empty_string();

  result = slurp(p);
  pclose(p);
  return result;
}
Exemplo n.º 15
0
void file_buffer_t::reload_from_disk()
{
    adobe::file_slurp<char> slurp(path_m);

    contents_m.assign(slurp.begin(), slurp.end());

    set_line_endings_impl(le_m, true);

    set_dirty(false);
}
Exemplo n.º 16
0
void load_config(const char *dir)
{
  load_flags(dir);

  switch(slurp("key",&key,512)) {
    case -1:
      strerr_die4sys(111,FATAL,ERR_READ,dir,"/key: ");
    case 0:
      strerr_die4x(100,FATAL,dir,"/key",ERR_NOEXIST);
  }

  /* There are problems with using getconf_line to fetch the ezmlmrc
   * pointer, since the alt location for "ezmlmrc" turns out to be the
   * whole ezmlmrc file itself. */
  switch (slurp("ezmlmrc",&ezmlmrc,64)) {
  case -1:
    strerr_die4sys(111,FATAL,ERR_READ,dir,"/ezmlmrc: ");
  case 0:
    ezmlmrc.len = 0;
  }
  ezmlmrc.len = byte_chr(ezmlmrc.s,ezmlmrc.len,'\n');

  getconf_line(&outhost,"outhost",1,dir);
  getconf_line(&outlocal,"outlocal",1,dir);
  if (!stralloc_copy(&local,&outlocal)) die_nomem();

  getconf_line(&listid,"listid",0,dir);
  if (getconf_line(&charset,"charset",0,dir)) {
    if (charset.len >= 2 && charset.s[charset.len - 2] == ':') {
      if (charset.s[charset.len - 1] == 'B' ||
		 charset.s[charset.len - 1] == 'Q') {
        flagcd = charset.s[charset.len - 1];
        charset.s[charset.len - 2] = '\0';
      }
    }
  } else
    if (!stralloc_copys(&charset,TXT_DEF_CHARSET)) die_nomem();
  if (!stralloc_0(&charset)) die_nomem();

  // FIXME: need to handle escapes in mailinglist
  getconf_line(&mailinglist,"mailinglist",1,dir);
}
Exemplo n.º 17
0
Arquivo: gz.c Projeto: Tolchi/misc
int main( int argc, char *argv[]) {
  if (argc < 2) usage(argv[0]);
  int rc;
  size_t flen;
  char *file = argv[1];
  char *data = slurp(file, &flen);

  /* minimal required initialization of z_stream prior to deflateInit2 */
  z_stream zs = {.next_in = data, .zalloc=Z_NULL, .zfree=Z_NULL, .opaque=NULL};
#define want_gzip 16
#define def_windowbits (15 + want_gzip)
#define def_memlevel 8
  rc = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, def_windowbits,
               def_memlevel, Z_DEFAULT_STRATEGY);
  if (rc != Z_OK) {
    fprintf(stderr, "deflateInit failed: %s\n", zs.msg);
    exit(-1);
  }

  /* calculate the max space needed to deflate this buffer in a single pass */
  size_t gzmax = deflateBound(&zs, flen);
  char *out = malloc(gzmax);
  if (out == NULL) {
    fprintf(stderr, "could not allocate %u bytes for compressed file\n",
      (unsigned)gzmax);
    exit(-1);
  }

  /* initialize the remaining parts of z_stream prior to actual deflate */
  zs.avail_in = flen;
  zs.next_out = out;
  zs.avail_out = gzmax;

  /* deflate it in one fell swoop */
  rc = deflate(&zs, Z_FINISH);
  if (rc != Z_STREAM_END) {
    fprintf(stderr,"single-pass deflate failed: ");
    if (rc == Z_OK) fprintf(stderr,"additional passes needed\n");
    else if (rc == Z_STREAM_ERROR) fprintf(stderr,"stream error\n");
    else if (rc == Z_BUF_ERROR) fprintf(stderr,"buffer unavailable\n");
    else fprintf(stderr,"unknown error\n");
    exit(-1);
  }
  rc = deflateEnd(&zs);
  if (rc != Z_OK) fprintf(stderr,"deflateEnd error: %s\n", zs.msg);
  fprintf(stderr,"Original size: %u\n", (unsigned)flen);
  fprintf(stderr,"Deflated size: %u\n", (unsigned)zs.total_out);
  if (write(STDOUT_FILENO, out, zs.total_out) != zs.total_out) {
    fprintf(stderr,"error: partial write\n");
    exit(-1);
  }
  return 0;
}
Exemplo n.º 18
0
static void load_config(void)
{
  load_flags();

  key.len = 0;
  switch(slurp("key",&key,512)) {
    case -1:
      strerr_die2sys(111,FATAL,MSG1(ERR_READ,"key"));
    case 0:
      strerr_die4x(100,FATAL,listdir,"/key",MSG(ERR_NOEXIST));
  }

  /* There are problems with using getconf_line to fetch the ezmlmrc
   * pointer, since the alt location for "ezmlmrc" turns out to be the
   * whole ezmlmrc file itself. */
  switch (slurp("ezmlmrc",&ezmlmrc,64)) {
  case -1:
    strerr_die2sys(111,FATAL,MSG1(ERR_READ,"ezmlmrc"));
  case 0:
    ezmlmrc.len = 0;
  }
  ezmlmrc.len = byte_chr(ezmlmrc.s,ezmlmrc.len,'\n');

  getconf_line(&outhost,"outhost",1);
  getconf_line(&outlocal,"outlocal",1);
  if (!stralloc_copy(&local,&outlocal)) die_nomem();

  getconf_line(&listid,"listid",0);
  if (getconf_line(&charset,"charset",0)) {
    if (charset.len >= 2 && charset.s[charset.len - 2] == ':') {
      if (charset.s[charset.len - 1] == 'B' ||
		 charset.s[charset.len - 1] == 'Q') {
        flagcd = charset.s[charset.len - 1];
        charset.s[charset.len - 2] = '\0';
      }
    }
  } else
    if (!stralloc_copys(&charset,TXT_DEF_CHARSET)) die_nomem();
  if (!stralloc_0(&charset)) die_nomem();
}
Exemplo n.º 19
0
 bool render (std::string& output)
 {
     std::string src;
     if (! slurp (src))
         return false;
     mustache::layout_type layout;
     layout.bind ("recents", RECENTS, mustache::FOR);
     layout.bind ("body",    BODY,    mustache::STRING);
     if (! layout.assemble (src))
         return false;
     layout.expand (*this, output);
     return true;
 }
Exemplo n.º 20
0
/*
 * Read, parse and evaluate SCHEME SOURCE FILE in target environment.
 */
static void import(environment_t *target, const std::string& filename)
{
  if ( global_opts.verbose )
    fprintf(stderr, "Loading file %s\n", filename.c_str());

  program_t *p = parse(slurp(open_file(filename)), target);
  library_t *lib = define_library(p->root, filename.c_str());
  merge(target, lib->exports);
  lib->exports->outer = target;

  // TODO: Double-check that request library name matches library name
  //       in file.
}
Exemplo n.º 21
0
	Effects effectAllFromFile(const filesys::path& file) {

		filesys::path ending[3] = { "material_fx", "scene_fx", "fxh" };

		uint32 effecttype = 0;
		if (std::equal(ending[0].rbegin(), ending[0].rend(), file.rbegin())) {
			effecttype = EffectType::MATERIAL_FX;
		}
		else if (std::equal(ending[1].rbegin(), ending[1].rend(), file.rbegin())) {
			effecttype = EffectType::SCENE_FX;
		}
		else if (std::equal(ending[2].rbegin(), ending[2].rend(), file.rbegin())) {
			effecttype = EffectType::FXHeader;
		}
		else {
			//< this file will not contain an effect -> but we do not print an error, because the underlying filesystem-iterator can't decide so 
			//< this function will be called for each file in the directory
			return Effects();
		}

		Effects eff;
		//Read in source
		IFileStream stream(file.c_str(), std::ios::in);
		if (!stream.is_open()) {
			LOG_ERROR(General, "Cant open file for reading (%s).", file.c_str());
			return eff;
		}
		String source = slurp(stream);

		uint32 bufferSize = sizeof(EffectSpec) + (source.size() + 1) * sizeof(String::value_type);

		union {
			Byte* eff_buffer;
			EffectSpec* effect;
			UIntOfPtrSize location;
		};
		eff_buffer = new Byte[bufferSize];
		std::memset(eff_buffer, 0, bufferSize);
		effect->__effectSourceLocation = location + sizeof(EffectSpec);
		effect->effectType = effecttype;

		effect->uuid = generateUUID();
		filesys::path name = filesys::stem(file) + filesys::extension(file);
		std::strncpy(effect->name, name.c_str(), EffectSpec::MaxEffectName);
		std::strncpy(effect->effectSource, source.c_str(), source.length());

		//LOG_INFO(General, "Source-length: %d Bytes", std::strlen(effect->effectSource));

		eff.push_back(effect);
		return eff;
	}
Exemplo n.º 22
0
static void copy_buffered_output(struct tag_pgrp *running)
{
	char *tag_output;

	tag_output = slurp(running->output);
	if (tag_output) {
		printf("%s", tag_output);
		/* make sure the output ends with a newline */
		if (tag_output[strlen(tag_output) - 1] != '\n')
			printf("\n");
		fflush(stdout);
		free(tag_output);
	}
}
Exemplo n.º 23
0
int openreadclose (char const *fn, stralloc *sa, unsigned int bufsize)
{
  int fd = open_readb(fn) ;
  if (fd == -1) return (errno == ENOENT) ? 0 : -1 ;
  if (!slurp(sa, fd))
  {
    register int e = errno ;
    fd_close(fd) ;
    errno = e ;
    return -1 ;
  }
  fd_close(fd) ;
  (void)bufsize ;
  return 0 ;
}
Exemplo n.º 24
0
int
main(int argc, char **argv)
{
	struct magic_set *ms;
	const char *result;
	char *desired;
	size_t desired_len;
	int i;
	FILE *fp;

	ms = magic_open(MAGIC_NONE);
	if (ms == NULL) {
		(void)fprintf(stderr, "ERROR opening MAGIC_NONE: out of memory\n");
		return 10;
	}
	if (magic_load(ms, NULL) == -1) {
		(void)fprintf(stderr, "ERROR loading with NULL file: %s\n", magic_error(ms));
		return 11;
	}

	if (argc > 1) {
		if (argc != 3) {
			(void)fprintf(stderr, "Usage: test TEST-FILE RESULT\n");
		} else {
			if ((result = magic_file(ms, argv[1])) == NULL) {
				(void)fprintf(stderr, "ERROR loading file %s: %s\n", argv[1], magic_error(ms));
				return 12;
			} else {
				fp = fopen(argv[2], "r");
				if (fp == NULL) {
					(void)fprintf(stderr, "ERROR opening `%s': ", argv[2]);
					perror(NULL);
					return 13;
				}
				desired = slurp(fp, &desired_len);
				fclose(fp);
				(void)printf("%s: %s\n", argv[1], result);
                                if (strcmp(result, desired) != 0) {
					(void)fprintf(stderr, "Error: result was\n%s\nexpected:\n%s\n", result, desired);
					return 1;
                                }
			}
		}
	}

	magic_close(ms);
	return 0;
}
Exemplo n.º 25
0
static cons_t* include(cons_t* p, environment_t* e, const char* basedir)
{
  cons_t *code = list();
  /*
   * TODO: Paths should be relative (or under) the directory
   *       that the library file is in.
   */
  for ( ; !nullp(p); p = cdr(p) ) {
    assert_type(STRING, car(p));

    std::string file = format("%s/%s", basedir, car(p)->string);

    program_t *p = parse(slurp(open_file(file)), e);
    code = append(code, p->root);
  }

  return code;
}
Exemplo n.º 26
0
turbine_code
turbine_run_interp(MPI_Comm comm, const char* script_file,
                   int argc, const char** argv, char* output,
                   Tcl_Interp* interp)
{
  // Read the user script
  char* script = slurp(script_file);
 
  if (script == NULL)
  {
    printf("turbine_run(): Could not load script: %s\n", script_file);
    return TURBINE_ERROR_INVALID;
  }

  int rc =  turbine_run_string(comm, script, argc, argv, output, interp);
  free(script);
  return rc;
}
Exemplo n.º 27
0
void interface(int interactive) {
	if(interactive) {
		int key, result;
		char customkey[8] = { 0 }, * marked = NULL;
		
		canon(0);
		fflush(stderr);
		if((key = fetchkey(1000000)) == -1)
			return;

		if(key == 27) {
			int ch;
			while((ch = fetchkey(100000)) != -1 && !strchr("ABCDEFGHMPQRSZojmk~", ch));
			return;
		}

		switch(key) {
			case 'l':
				puts(rate("L") ? "Loved." : "Sorry, failed.");
				break;

			case 'U':
				puts(rate("U") ? "Unloved." : "Sorry, failed.");
				break;

			case 'B':
				puts(rate("B") ? "Banned." : "Sorry, failed.");
				kill(playfork, SIGUSR1);
				break;

			case 'n':
				rate("S");
				break;

			case 'Q':
				unlink(rcpath("session"));
				exit(EXIT_SUCCESS);

			case 'i':
				if(playfork) {
					const char * path = rcpath("i-template");
					if(path && !access(path, R_OK)) {
						char ** template = slurp(path);
						if(template != NULL) {
Exemplo n.º 28
0
static void execute(const char *fn,const char *def)
     /* Load and execute a qmail command file. */
{
  stralloc file = {0,0,0};
  int code;
  if (def != 0)
    env_put2("DEFAULT",def);
  else
    env_unset("DEFAULT");
  if (slurp(fn,&file,256) != 1)
    strerr_die6sys(111,FATAL,ERR_READ_INPUT,basedir.s,"/",fn,": ");
  code = execute_file(fn,&file);
  substdio_puts(subfderr,"did 0+");
  substdio_put(subfderr,strnum,fmt_ulong(strnum,did_forward));
  substdio_puts(subfderr,"+");
  substdio_put(subfderr,strnum,fmt_ulong(strnum,did_program));
  substdio_putsflush(subfderr,"\n");
  _exit(code);
}
Exemplo n.º 29
0
cons_t* proc_load(cons_t *args, environment_t *env)
{
  assert_length(args, 1, 2);
  assert_type(STRING, car(args));

  cons_t *filename = car(args);
  cons_t *env_spec = cadr(args);

  if ( !nullp(env_spec) ) {
    assert_type(ENVIRONMENT, env_spec);
    env = env_spec->environment;
  } else {
    /*
     * We are supposed to use (interaction-environment) here, but we'll
     * cheeat and use the topmost environment for now.
     */
    env = env->outermost();
  }

  // first try filename without include path
  std::string file = filename->string;

  // no cigar? try include path
  if ( !file_exists(file) )
    file = format("%s/%s", global_opts.include_path, filename->string);

  if ( !file_exists(file) ) {
    raise(runtime_exception(format(
      "Could not find file '%s' in any search paths", filename->string)));
  }

  // Set current filename, in case we need it for error reporting.
  const char* prev = global_opts.current_filename;
  global_opts.current_filename = file.c_str();

  // Parse and evaluate file.
  program_t *p = parse(slurp(open_file(file)), env);
  eval(cons(symbol("begin"), p->root), p->globals);

  // Restore filename.
  global_opts.current_filename = prev;
  return unspecified();
}
Exemplo n.º 30
0
/// Return the contents of a given filename in the ../shaders/ directory.
const std::string GetShaderSourceFromFile(const char* filename, const std::string path)
{
    std::cout << "<<file>> ";

    std::string shaderName = filename;
    std::string fullShaderName = path + shaderName; ///@todo Check parent paths

    std::ifstream file;
    file.open(fullShaderName.c_str(), std::ios::in);
    if (!file.is_open())
    {
        std::cerr << "No file " << filename << std::endl;
        return "";
    }

    std::string fileContents = slurp(file);
    file.close();

    return fileContents;
}