Пример #1
0
static void setup_environment_clean(char ***envp, strlist *keep_env, strlist *set_env) {
  size_t n, i;
  const char *key, *val;
  char *nkey, *pos;
  strlist_node *s;

  n = strlist_count(keep_env) + strlist_count(set_env);
  if( (*envp = (char **)malloc((n+1)*sizeof(char*))) == NULL )
    errExit("malloc");

  i = 0;

  for(s = strlist_first(set_env); s != NULL; s = strlist_next(s)) {
    val = strlist_val(s);
    if( (nkey = strdup(val)) == NULL )
      errExit("strdup");
    pos = index(nkey, '=');
    if(pos != NULL && pos != nkey) {
      *pos = '\0';
      strlist_remove(keep_env, nkey);
      *pos = '=';
      (*envp)[i++] = nkey;
    }
    else
      free(nkey);
  }

  for(s = strlist_first(keep_env); s != NULL; s = strlist_next(s)) {
    key = strlist_val(s);
    val = getenv(key);
    if( val != NULL) {
      if( ((*envp)[i] = (char*)malloc((strlen(key) + strlen(val) + 2)*sizeof(char))) == NULL )
        errExit("malloc");
      sprintf((*envp)[i++], "%s=%s", key, val);
    }
  }

  (*envp)[i] = NULL;
}
Пример #2
0
struct DATA *
database_init_frompgn (FILE *finp, strlist_t *sl, const char *synfile_name, bool_t quiet)
{

	struct DATA *pDAB = NULL;
	FILE *fpgn;
	bool_t ok = FALSE;
	const char *pgn;

	ok = NULL != (pDAB = structdata_init ());

	if (NULL != synfile_name) // not provided
		syn_preload (quiet, synfile_name, pDAB); 

	strlist_rwnd(sl);

	pgn = strlist_next(sl);
	while (ok && pgn) {
		if (!quiet)	printf ("\nFile: %s\n",pgn);
		if (NULL != (fpgn = fopen (pgn, "r"))) {
			ok = fpgnscan (fpgn, quiet, pDAB);
			fclose(fpgn);
		} else {
			ok = FALSE;
		}
		if (ok) pgn = strlist_next(sl);
	}

	if (ok && finp) {
		//if (!quiet)	printf ("\nFile: %s\n","standard input");
		ok = fpgnscan (finp, quiet, pDAB);
	}

	return ok? pDAB: NULL;

	#if 0
	hashstat();
	#endif
}
Пример #3
0
static void setup_environment_noclean(strlist *set_env) {
  strlist_node *s;
  const char *v;
  char *key, *pos;

  for(s = strlist_first(set_env); s != NULL; s = strlist_next(s)) {
    v = strlist_val(s);
    pos = index(v, '=');
    if(pos != NULL && pos != v) {
      if( (key = strndup(v, pos - v)) == NULL )
        errExit("strndup");
      setenv(key, pos + 1, 1);
      free(key);
    }
  }
}
Пример #4
0
bool codegen_merge_runtime_bitcode(compile_t* c)
{
  strlist_t* search = package_paths();
  char path[FILENAME_MAX];
  LLVMModuleRef runtime = NULL;

  for(strlist_t* p = search; p != NULL && runtime == NULL; p = strlist_next(p))
  {
    path_cat(strlist_data(p), "libponyrt.bc", path);
    runtime = LLVMParseIRFileInContext(c->context, path);
  }

  errors_t* errors = c->opt->check.errors;

  if(runtime == NULL)
  {
    errorf(errors, NULL, "couldn't find libponyrt.bc");
    return false;
  }

  if(c->opt->verbosity >= VERBOSITY_MINIMAL)
    fprintf(stderr, "Merging runtime\n");

#if PONY_LLVM >= 308
  // runtime is freed by the function.
  if(LLVMLinkModules2(c->module, runtime))
  {
    errorf(errors, NULL, "libponyrt.bc contains errors");
    return false;
  }
#else
  if(LLVMLinkModules(c->module, runtime, LLVMLinkerDestroySource /* unused */,
    NULL))
  {
    errorf(errors, NULL, "libponyrt.bc contains errors");
    LLVMDisposeModule(runtime);
    return false;
  }
#endif

  return true;
}
Пример #5
0
// Attempt to find the specified package directory in our search path
// @return The resulting directory path, which should not be deleted and is
// valid indefinitely. NULL is directory cannot be found.
static const char* find_path(ast_t* from, const char* path)
{
  // First check for an absolute path
  if(is_path_absolute(path))
    return try_path(NULL, path);

  const char* result;

  if((from == NULL) || (ast_id(from) == TK_PROGRAM))
  {
    // Try a path relative to the current working directory
    result = try_path(NULL, path);

    if(result != NULL)
      return result;
  }
  else
  {
    // Try a path relative to the importing package
    from = ast_nearest(from, TK_PACKAGE);
    package_t* pkg = (package_t*)ast_data(from);
    result = try_path(pkg->path, path);

    if(result != NULL)
      return result;
  }

  // Try the search paths
  for(strlist_t* p = search; p != NULL; p = strlist_next(p))
  {
    result = try_path(strlist_data(p), path);

    if(result != NULL)
      return result;
  }

  errorf(path, "couldn't locate this path");
  return NULL;
}
Пример #6
0
void _cwt_size_min_textblk(CwtTextBlkPtr tb, CWT_SIZE *sz)
{
	JQ_ASSERT(tb);
	sz->width = sz->height = 0;

	if( tb->lines->count > 0 ) {
		StringListIterator it;

		JQ_ASSERT(tb->style);

		strlist_begin(tb->lines, &it);

		while( strlist_has_more(&it) ) {
			const CWT_CHAR* text = strlist_next(&it);
			CWT_SIZE text_sz;

			_cwt_text_size(&tb->style->font, text, &text_sz);
			sz->height += tb->style->line_height/100 * text_sz.height;
			sz->width = JQ_MAX(sz->width, text_sz.width);
		}
	}
}
Пример #7
0
void program_lib_build_args(ast_t* program, const char* path_preamble,
  const char* global_preamble, const char* global_postamble,
  const char* lib_premable, const char* lib_postamble)
{
  assert(program != NULL);
  assert(ast_id(program) == TK_PROGRAM);
  assert(global_preamble != NULL);
  assert(global_postamble != NULL);
  assert(lib_premable != NULL);
  assert(lib_postamble != NULL);

  program_t* data = (program_t*)ast_data(program);
  assert(data != NULL);
  assert(data->lib_args == NULL); // Not yet built args

  // Start with an arbitrary amount of space
  data->lib_args_alloced = 256;
  data->lib_args = (char*)malloc(data->lib_args_alloced);
  data->lib_args[0] = '\0';
  data->lib_args_size = 0;

  // Library paths defined in the source code.
  for(strlist_t* p = data->libpaths; p != NULL; p = strlist_next(p))
  {
    const char* libpath = strlist_data(p);
    append_to_args(data, path_preamble);
    append_to_args(data, libpath);
    append_to_args(data, " ");
  }

  // Library paths from the command line and environment variable.
  for(strlist_t* p = package_paths(); p != NULL; p = strlist_next(p))
  {
    const char* libpath = quoted_locator(NULL, strlist_data(p));

    if(libpath == NULL)
      continue;

    append_to_args(data, path_preamble);
    append_to_args(data, libpath);
    append_to_args(data, " ");
  }

  // Library names.
  append_to_args(data, global_preamble);

  for(strlist_t* p = data->libs; p != NULL; p = strlist_next(p))
  {
    const char* lib = strlist_data(p);
    bool amble = !is_path_absolute(lib);

    if(amble)
      append_to_args(data, lib_premable);

    append_to_args(data, lib);

    if(amble)
      append_to_args(data, lib_postamble);

    append_to_args(data, " ");
  }

  append_to_args(data, global_postamble);
}
Пример #8
0
// Attempt to find the specified package directory in our search path
// @return The resulting directory path, which should not be deleted and is
// valid indefinitely. NULL is directory cannot be found.
static const char* find_path(ast_t* from, const char* path,
  bool* out_is_relative)
{
  if(out_is_relative != NULL)
    *out_is_relative = false;

  // First check for an absolute path
  if(is_path_absolute(path))
    return try_path(NULL, path);

  // Get the base directory
  const char* base;

  if((from == NULL) || (ast_id(from) == TK_PROGRAM))
  {
    base = NULL;
  } else {
    from = ast_nearest(from, TK_PACKAGE);
    package_t* pkg = (package_t*)ast_data(from);
    base = pkg->path;
  }

  // Try a path relative to the base
  const char* result = try_path(base, path);

  if(result != NULL)
  {
    if(out_is_relative != NULL)
      *out_is_relative = true;

    return result;
  }

  // If it's a relative path, don't try elsewhere
  if(!is_path_relative(path))
  {
    // Check ../pony_packages and further up the tree
    if(base != NULL)
    {
      result = try_package_path(base, path);

      if(result != NULL)
        return result;

      // Check ../pony_packages from the compiler target
      if((from != NULL) && (ast_id(from) == TK_PACKAGE))
      {
        ast_t* target = ast_child(ast_parent(from));
        package_t* pkg = (package_t*)ast_data(target);
        base = pkg->path;

        result = try_package_path(base, path);

        if(result != NULL)
          return result;
      }
    }

    // Try the search paths
    for(strlist_t* p = search; p != NULL; p = strlist_next(p))
    {
      result = try_path(strlist_data(p), path);

      if(result != NULL)
        return result;
    }
  }

  errorf(path, "couldn't locate this path");
  return NULL;
}
Пример #9
0
/* TODO необходимо доработать алгоритм с возможностью расположения по вертикали
 * блока текста с произвольным количество строк.
 * В настоящий момент правильно располагается по вертикали только блок,
 * состящий из одной строки.
 * */
void _cwt_render_textblk(CwtTextBlkPtr tb, CWT_SIZE *sz)
{
	JQ_ASSERT(tb);

	if( tb->lines->count == 1 ) {
		CWT_RECT bounds;
		CWT_CHAR *text;

		bounds.left = 0;
		bounds.top = 0;
		bounds.width = sz->width;
		bounds.height = sz->height;

		text = strlist_at(tb->lines, 0);
		if( text ) {
			_cwt_outtext_box(text
				, &bounds
				, &tb->style->font
				, tb->style->align
				, tb->style->color
				, tb->style->bgcolor);
		}
	} else if( tb->lines->count > 0 ) {
		StringListIterator it;
		int top;

		JQ_ASSERT(tb->style);

		tb->bottom_overflow = FALSE;

		if( !tb->upwards ) {
			strlist_begin_from(tb->lines, tb->top_line, &it);
			top = 0;
		} else {
			strlist_rbegin(tb->lines, &it);
			top = sz->height;
			tb->bottom_overflow = FALSE;
		}

		while( strlist_has_more(&it) ) {
			const CWT_CHAR* text;
			StringListElemPtr node = strlist_node(&it);
			CWT_RECT line_rect;
			int text_height;
			int line_height;

			text = strlist_next(&it);

			text_height = _cwt_text_height(&tb->style->font, text);
			line_height = (tb->style->line_height * text_height)/100 ;

			if( !tb->upwards ) {
				if( top + text_height > sz->height ) {
					tb->bottom_overflow = TRUE;
					break;
				}
			} else {
				if( top - text_height < 0 ) {
					break;
				}
				top -= line_height;
				tb->top_line = node;
			}

			line_rect.top    = top;
			line_rect.left   = 0;
			line_rect.width  = sz->width;
			line_rect.height = line_height;

			_cwt_outtext_box(text
				, &line_rect
				, &tb->style->font
				, (tb->style->align & 0x0F) | CWT_VALIGN_CENTER
				, tb->style->color
				, tb->style->bgcolor);

			if( !tb->upwards )
				top += line_height;
		}
	}

	tb->upwards = FALSE;
}