Example #1
0
/*
 * `ncolumns' is followed by (alternately) radio button labels and
 * values, until a null in place of a title string is seen.
 */
control *
ctrl_radiobuttons(controlset *s, char *label, int ncolumns,
                  handler_fn handler, void *context, ...)
{
  va_list ap;
  int i;
  control *c = ctrl_new(s, CTRL_RADIO, handler, context);
  c->label = label ? strdup(label) : null;
  c->radio.ncolumns = ncolumns;
 /*
  * Initial pass along variable argument list to count the
  * buttons.
  */
  va_start(ap, context);
  i = 0;
  while (va_arg(ap, string)) {
    va_arg(ap, int);
    i++;
  }
  va_end(ap);
  c->radio.nbuttons = i;
  c->radio.labels = newn(string, c->radio.nbuttons);
  c->radio.vals = newn(int, c->radio.nbuttons);
 /*
  *second pass along variable argument list to actually fill in
  * the structure.
  */
  va_start(ap, context);
  for (i = 0; i < c->radio.nbuttons; i++) {
    c->radio.labels[i] = strdup(va_arg(ap, string));
    c->radio.vals[i] = va_arg(ap, int);
  }
  va_end(ap);
  return c;
}
Example #2
0
static DWORD WINAPI
shell_exec_thread(void *data)
{
  wchar *wpath = data;

#ifdef __CYGWIN__
  /* Need to sync the Windows environment */
  cygwin_internal(CW_SYNC_WINENV);
#endif

  if ((INT_PTR)ShellExecuteW(wnd, 0, wpath, 0, 0, SW_SHOWNORMAL) <= 32) {
    uint error = GetLastError();
    if (error != ERROR_CANCELLED) {
      int msglen = 1024;
      wchar * msg = newn(wchar, msglen);
      FormatMessageW(
        FORMAT_MESSAGE_FROM_SYSTEM | 64,
        0, error, 0, msg, msglen, 0
      );
      wchar sep[] = W("\n");
      msg = renewn(msg, wcslen(msg) + wcslen(sep) + wcslen(wpath) + 1);
      wcscat(msg, sep);
      wcscat(msg, wpath);
      message_box_w(0, msg, null, MB_ICONERROR, null);
    }
  }
  free(wpath);
  return 0;
}
Example #3
0
void
win_save_title(void)
{
  int len = GetWindowTextLengthW(wnd);
  wchar *title = newn(wchar, len + 1);
  GetWindowTextW(wnd, title, len + 1);
  delete(titles[titles_i]);
  titles[titles_i++] = title;
  if (titles_i == lengthof(titles))
    titles_i = 0;
}
Example #4
0
int FILE_rename_file(const char * old_name, const char * new_name)
{
#if IBM
	string oldn(old_name);
	string newn(new_name);
	string_utf16 old16, new16;
	string_utf_8_to_16(oldn, old16);
	string_utf_8_to_16(newn, new16);
	if(!MoveFileW((const wchar_t*)old16.c_str(), (const wchar_t*)new16.c_str())) return GetLastError();
#endif
#if LIN || APL
	if(rename(old_name,new_name)<0)	return errno;
#endif
	return 0;
}
Example #5
0
void
win_open(wstring wpath)
{
  wstring p = wpath;
  while (iswalpha(*p)) p++;
  if (*wpath == '\\' || *p == ':' || wcsncmp(W("www."), wpath, 4) == 0) {
    // Looks like it's a Windows path or URI
    shell_exec(wpath);
  }
  else {
    // Need to convert POSIX path to Windows first
    if (support_wsl) {
#ifdef debug_wsl
      printf("open <%ls>\n", wpath);
#endif
      if (wcsncmp(wpath, W("/mnt/"), 5) == 0) {
        wchar * unwsl = newn(wchar, wcslen(wpath) + 6);
        wcscpy(unwsl, W("/cygdrive"));
        wcscat(unwsl, wpath + 4);
        delete(wpath);
        wpath = unwsl;
      }
      else if (*wpath == '/') {  // prepend %LOCALAPPDATA%\lxss[\rootfs]
        char * appd = getenv("LOCALAPPDATA");
        if (appd) {
          wchar * wappd = cs__mbstowcs(appd);
          appd = path_win_w_to_posix(wappd);
          free(wappd);
          wappd = cs__mbstowcs(appd);
          free(appd);

          bool rootfs_mount = true;
          for (uint i = 0; i < lengthof(lxss_mounts); i++) {
            if (ispathprefixw(lxss_mounts[i].w, wpath)) {
              rootfs_mount = false;
              break;
            }
          }

          wchar * unwsl = newn(wchar, wcslen(wappd) + wcslen(wpath) + 13);
          wcscpy(unwsl, wappd);
          free(wappd);
          wcscat(unwsl, W("/lxss"));
          if (rootfs_mount)
            wcscat(unwsl, W("/rootfs"));
          wcscat(unwsl, wpath);
          delete(wpath);
          wpath = unwsl;
        }
      }
    }
    wstring conv_wpath = child_conv_path(wpath);
#ifdef debug_wsl
    printf("open <%ls> <%ls>\n", wpath, conv_wpath);
#endif
    delete(wpath);
    if (conv_wpath)
      shell_exec(conv_wpath);
    else
      message_box(0, strerror(errno), null, MB_ICONERROR, null);
  }
}