Exemplo n.º 1
0
static ERL_NIF_TERM
ex_mvprintw(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    unsigned int x, y;
    ErlNifBinary string;

    if (argc != 3)
        return enif_make_badarg(env);

    if (! enif_get_uint(env, argv[0], &y))
        return enif_make_badarg(env);

    if (! enif_get_uint(env, argv[1], &x))
        return enif_make_badarg(env);

    if (! enif_inspect_binary(env, argv[2], &string))
        return enif_make_badarg(env);

    char *str = alloc_and_copy_to_cstring(&string);

    int code  = mvprintw(y, x, str);
    free_cstring(str);

    return done(env, code);
}
Exemplo n.º 2
0
void set_footwrap(char_t *wrap) {
  if( wrap ) {
    if( p_cstring(&footwrap) != std_footwrap ) { 
      free_cstring(&footwrap); 
    }
    strdup_cstring(&footwrap, wrap);
  }
}
Exemplo n.º 3
0
void set_headwrap(char_t *wrap) {
  if( wrap ) {
    if( p_cstring(&headwrap) != std_headwrap ) { 
      free_cstring(&headwrap); 
    }
    strdup_cstring(&headwrap, wrap);
  }
}
Exemplo n.º 4
0
void set_root_tag(const char_t *root) {
  if( root ) {
    if( p_cstring(&root_tag) != std_root_tag ) { 
      free_cstring(&root_tag); 
    }
    strdup_cstring(&root_tag, root);

    if( p_cstring(&open_root) != std_open_root ) { 
      free_cstring(&open_root); 
    }
    create_cstring(&open_root, "", 3 + strlen(root));
    vstrcat_cstring(&open_root, "<", root, ">", NULLPTR);

    if( p_cstring(&close_root) != std_close_root ) {
      free_cstring(&close_root); 
    }
    create_cstring(&close_root, "", 4 + strlen(root));
    vstrcat_cstring(&close_root, "</", root, ">", NULLPTR);
  }
}
Exemplo n.º 5
0
/* make a temporary file name (template for mkstemp) that user must free */
char *make_template_tempfile(const char *basename) {
  const char *t;
  cstring_t cs;
  
  t = getenv("TMPDIR");
  t = t ? t : getenv("TMP");
  t = t ? t : "/tmp";
  create_cstring(&cs, t, PATH_MAX);
  t = vstrcat_cstring(&cs, "/", basename, ".XXXXXX", NULLPTR);
  
  /* if we return a string, we must not free cs */
  return ( t < begin_cstring(&cs) + PATH_MAX ) ?
    p_cstring(&cs) : (free_cstring(&cs), NULL);
}
Exemplo n.º 6
0
static ERL_NIF_TERM
ex_printw(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary string;

    if (argc != 1 || ! enif_inspect_binary(env, argv[0], &string))
        return enif_make_badarg(env);

    char *str = alloc_and_copy_to_cstring(&string);
    int code  = printw(str);
    free_cstring(str);

    return done(env, code);
}
Exemplo n.º 7
0
static int test_filepathstatic(void)
{
   filepath_static_t fpath;
   const char*       F;
   cstring_t         workpath   = cstring_INIT;
   directory_t*      workdir    = 0;
   char              fullpath[sys_path_MAXSIZE];

   // prepare
   TEST(0 == new_directory(&workdir, "", 0));
   TEST(0 == path_directory(workdir, &(wbuffer_t) wbuffer_INIT_CSTRING(&workpath)));
   adaptsize_cstring(&workpath);

   // TEST init_filepathstatic: workdir == 0 && filename == 0
   memset(&fpath, 255, sizeof(fpath));
   init_filepathstatic(&fpath, 0, 0);
   TEST(0 == fpath.workdir[0]);
   TEST(0 != fpath.filename);
   TEST(0 == fpath.filename[0]);

   // TEST init_filepathstatic: workdir == 0
   memset(&fpath, 255, sizeof(fpath));
   F = "test-filename";
   init_filepathstatic(&fpath, 0, F);
   TEST(0 == fpath.workdir[0]);
   TEST(F == fpath.filename);

   // TEST init_filepathstatic: filename == 0
   memset(&fpath, 255, sizeof(fpath));
   init_filepathstatic(&fpath, workdir, 0);
   TEST('/' == fpath.workdir[size_cstring(&workpath)]);
   TEST(0 == fpath.workdir[size_cstring(&workpath)+1]);
   TEST(0 == memcmp(fpath.workdir, str_cstring(&workpath), size_cstring(&workpath)));
   TEST(0 != fpath.filename);
   TEST(0 == fpath.filename[0]);

   // TEST init_filepathstatic: filename[0] != '/'
   memset(&fpath, 255, sizeof(fpath));
   F = "test-filename";
   init_filepathstatic(&fpath, workdir, F);
   TEST('/' == fpath.workdir[size_cstring(&workpath)]);
   TEST(0 == fpath.workdir[size_cstring(&workpath)+1]);
   TEST(0 == memcmp(fpath.workdir, str_cstring(&workpath), size_cstring(&workpath)));
   TEST(F == fpath.filename);

   // TEST init_filepathstatic: absolute filename (filename[0] == '/')
   memset(&fpath, 255, sizeof(fpath));
   F = "/tmp/test-filename";
   init_filepathstatic(&fpath, workdir, F);
   TEST(0 == fpath.workdir[0]);
   TEST(F == fpath.filename);

   // TEST init_filepathstatic: ERROR
   init_testerrortimer(&s_filepathstatic_errtimer, 1, ENOENT);
   F = "test-filename";
   init_filepathstatic(&fpath, workdir, F);
   TEST(0 == strcmp("???ERR/", fpath.workdir));
   TEST(F == fpath.filename);

   // TEST STRPARAM_filepathstatic
   F = "test-filename";
   init_filepathstatic(&fpath, workdir, F);
   memset(fullpath, 255, sizeof(fullpath));
   snprintf(fullpath, sizeof(fullpath), "%s%s", STRPARAM_filepathstatic(&fpath));
   TEST(0 == strncmp(fullpath, str_cstring(&workpath), size_cstring(&workpath)));
   TEST('/' == fullpath[size_cstring(&workpath)]);
   TEST(0 == strcmp(fullpath + size_cstring(&workpath) + 1, F));

   // unprepare
   TEST(0 == free_cstring(&workpath));
   TEST(0 == delete_directory(&workdir));

   return 0;
ONERR:
   free_cstring(&workpath);
   delete_directory(&workdir);
   return EINVAL;
}