Exemple #1
0
/**
 * Set status in find results' window
 *
 * @param __res_wnd - window with results
 * @param __format - format of state
 */
static void
set_status (action_find_res_wnd_t *__res_wnd, const wchar_t *__format, ...)
{
  wchar_t buf[1024];

  PACK_ARGS(__format, buf, BUF_LEN (buf));

  w_text_set (__res_wnd->status, buf);
}
Exemple #2
0
static void
set_searching_status (action_find_res_wnd_t *__res_wnd,
                      const wchar_t *__action, const wchar_t *__path)
{
  wchar_t format[1024], path[1024];
  size_t width;

  swprintf (format, BUF_LEN (format), L"%ls: %%ls", __action);

  width = wcswidth (format, wcslen (format));
  fit_dirname (__path,
               __res_wnd->window->position.width - 6 - width, path);

  set_status (__res_wnd, _(format), path);
}
Exemple #3
0
static int parse_file(BlogRef const blog,
                      SLNSessionRef const session,
                      MultipartFormRef const form,
                      SLNSubmissionRef *const outfile,
                      SLNSubmissionRef *const outmeta,
                      str_t **const outname)
{
	assert(form);

	SLNSubmissionRef file = NULL;
	SLNSubmissionRef meta = NULL;
	SLNFileInfo src[1] = {};
	str_t *htmlpath = NULL;
	int rc = 0;

	strarg_t const fields[] = {
		"content-type",
		"content-disposition",
	};
	char content_type[100];
	char content_disposition[1024];
	uv_buf_t values[] = {
		uv_buf_init(BUF_LEN(content_type)),
		uv_buf_init(BUF_LEN(content_disposition)),
	};
	assert(numberof(fields) == numberof(values));
	rc = MultipartFormReadHeadersStatic(form, values, fields, numberof(values));
	if(rc < 0) goto cleanup;

	strarg_t type;
	if(0 == strcmp("form-data; name=\"markdown\"", content_disposition)) {
		type = "text/markdown; charset=utf-8";
	} else {
		type = content_type;
		static strarg_t const f[] = { "filename", "filename*" };
		str_t *v[numberof(f)] = {};
		ContentDispositionParse(content_disposition, NULL, v, f, numberof(f));
		if(v[1]) {
			*outname = v[1]; v[1] = NULL;
		} else {
			*outname = v[0]; v[0] = NULL;
		}
		for(size_t i = 0; i < numberof(v); i++) FREE(&v[i]);
	}

	rc = SLNSubmissionCreate(session, NULL, NULL, &file);
	if(rc < 0) goto cleanup;
	rc = SLNSubmissionSetType(file, type);
	if(rc < 0) goto cleanup;
	for(;;) {
		uv_buf_t buf[1];
		rc = MultipartFormReadData(form, buf);
		if(rc < 0) goto cleanup;
		if(0 == buf->len) break;
		rc = SLNSubmissionWrite(file, (byte_t const *)buf->base, buf->len);
		if(rc < 0) goto cleanup;
	}
	rc = SLNSubmissionEnd(file);
	if(rc < 0) goto cleanup;

	rc = SLNSubmissionGetFileInfo(file, src);
	if(rc < 0) goto cleanup;

	htmlpath = BlogCopyPreviewPath(blog, src->hash);
	if(!htmlpath) rc = UV_ENOMEM;
	if(rc < 0) goto cleanup;

	strarg_t const URI = SLNSubmissionGetPrimaryURI(file);
	(void)BlogConvert(blog, session, htmlpath, &meta, URI, src);
	// We don't actually care about failure here?
	// Even if no preview and no meta-file can be generated, that's fine.

	*outfile = file; file = NULL;
	*outmeta = meta; meta = NULL;

cleanup:
	SLNSubmissionFree(&file);
	SLNSubmissionFree(&meta);
	SLNFileInfoCleanup(src);
	FREE(&htmlpath);

	return rc;
}
Exemple #4
0
/**
 *
 * Initialize Tcl embed library
 *
 * @return TCL_OK if successful, TCL_ERROR otherwise
 */
int
tcllib_init (void)
{
  /* NOTE: Keep order, config.tcl be loaded last */
  static wchar_t *important_files[] = { L"associations.tcl",
                                        L"config.tcl" };
  /* static wchar_t *unimportant_files[] = { L"custom.tcl" }; */
  int i, j, count;
  wchar_t **list;

  interpreter = Tcl_CreateInterp();
  if (interpreter == NULL)
    {
      return TCL_ERROR;
    }

  if (tcllib_init_commands (interpreter) != TCL_OK)
    {
      return TCL_ERROR;
    }

  for  (i = 0; i < sizeof (important_files) / sizeof (important_files[0]); ++i)
    {
      count = get_shared_files (important_files[i], NULL, &list);

      if (count == 0)
        {
          wchar_t msg[1024];
          swprintf (msg, BUF_LEN (msg),
                    _(L"Configuration file \"%ls\" not found"),
                    important_files[i]);
          MESSAGE_ERROR (msg);
          return TCL_ERROR;
        }

      for (j = 0; j < count; ++j)
        {
          if (tcllib_load_file (list[j]) != TCL_OK)
            {
              TCL_RUNTIME_ERROR;

              /* Free memory used by unseen items */
              while (j < count)
                {
                  SAFE_FREE (list[j]);
                  ++j;
                }
              SAFE_FREE (list);

              return TCL_ERROR;
            }
          SAFE_FREE (list[j]);
        }

      SAFE_FREE (list);
    }

  hook_register (L"open-file-hook", _file_associations_hook, 1);

  return TCL_OK;
}
Exemple #5
0
/**
 *
 * File associations hook
 * For details see about hook's on user documentation
 */
int
_file_associations_hook (dynstruct_t *__callData)
{
  extension_action_t *ext;
  wchar_t *executecmd, *filename, *cwd;

  if (dynstruct_get_field_val (__callData, L"filename",
                               (void **) &filename) != DYNST_OK)
    {
      message_box (L"Hook `open-file-hook' error",
                   L"variable `filename' not found", MB_OK|MB_CRITICAL);

      return HOOK_FAILURE;
    }

  filename = escape_string (filename);

  if (_get_file_associations (filename, (void *) &ext) != TCL_OK)
    {
      executecmd = filename;
    }
  else
    {
      if (dynstruct_get_field_val (__callData, L"cwd",
                                   (void **) &cwd) != DYNST_OK)
        {
          message_box (L"Hook `open-file-hook' error",
                       L"variable `cwd' not found", MB_OK|MB_CRITICAL);

          return HOOK_FAILURE;
        }

      if (!ext->opener)
        {
          wchar_t msg[1024];

          swprintf (msg, BUF_LEN (msg),
                    _(L"There is no command specified to open file \"%ls\""),
                    filename);

          MESSAGE_ERROR (msg);
          return HOOK_FAILURE;
        }

      cwd = escape_string (cwd);

      executecmd = prepare_exec_command (ext->opener, filename, cwd);

      SAFE_FREE (filename);
      SAFE_FREE (cwd);
    }

  if (run_shell_command (executecmd) == -1)
    {
      return HOOK_FAILURE;
    }

  SAFE_FREE (executecmd);

  return HOOK_SUCCESS;
}
Exemple #6
0
/**
 * Append entry to list of found items
 *
 * @param __dir - directory where item has been found
 * @param __name - name of item
 * @param __stat - stat information of item
 * @param __res_wnd - window with results
 */
static void
append_result (const wchar_t *__dir, const wchar_t *__name, vfs_stat_t __stat,
               action_find_res_wnd_t *__res_wnd)
{
  wchar_t *string, *dummy;
  size_t len, tmp_len;
  wchar_t buf[128];
  wchar_t suffix;
  w_list_item_t *item;

#ifdef __USE_FILE_OFFSET64
  __u64_t size;
  static wchar_t format[] = L"%lld %c";
#else
  __u32_t size;
  static wchar_t format[] = L"%ld %c";
#endif

  len = __res_wnd->list->position.width - 2;
  string = malloc ((len + 1) * sizeof (wchar_t));
  dummy = malloc ((len + 1) * sizeof (wchar_t));

  /* Append directory for which item belongs to */
  if (!__res_wnd->dir_opened)
    {
      size_t l;

      prepare_row (string, len);
      l = __res_wnd->list->position.width / 4 * 3 - 5;

      fit_dirname (__dir, l, dummy);
      print_cell (string, dummy, 0, len);
      print_cell (string, _(L"<DIR>"), l + 1, len);
      item = w_list_append_item (__res_wnd->list, string, FIND_RES_DIR);

      store_item_value (item, FIND_RES_DIR, __dir, NULL);

      __res_wnd->dir_opened = TRUE;
    }

  prepare_row (string, len);

  /* Name of file */
  fit_dirname (__name, __res_wnd->list->position.width / 2, dummy);
  print_cell (string, dummy, 4, len);

  /* Mode of file */
  umasktowcs (__stat.st_mode, buf);
  print_cell (string, buf, __res_wnd->list->position.width - 10, len);

  /* Modification time */
  format_file_time (buf, BUF_LEN (buf), __stat.st_mtime);
  print_cell (string, buf, __res_wnd->list->position.width - 24, len);

  /* Size of file */
  if (!S_ISDIR (__stat.st_mode))
    {
      size = fsizetohuman (__stat.st_size, &suffix);
      swprintf (buf, BUF_LEN(buf), format, size, suffix);
    }
  else
    {
      wcscpy (buf, _(L"<DIR>"));
    }
  tmp_len = wcslen (buf);
  if (buf[tmp_len - 1] == ' ')
    {
      buf[tmp_len - 1] = 0;
      --tmp_len;
    }
  print_cell (string, buf,
              __res_wnd->list->position.width - 26 - tmp_len, len);

  item = w_list_append_item (__res_wnd->list, string, FIND_RES_ITEM);

  store_item_value (item, FIND_RES_ITEM, __dir, __name);

  free (string);
  free (dummy);
}