File: filedlgs.c

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (101 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// *** merge with lspedit code

#include "xlisp.h"
#include <commdlg.h>
#include <dir.h>

#define FILTERSIZE 255
static char szFilter[FILTERSIZE + 2];
static char szDfltFilter[] = "Lisp Files(*.LSP)|*.lsp|All Files(*.*)|*.*";
static char szDirName[256];

LVAL xsopenfiledialog()
{
  int i, n;
  OPENFILENAME ofn;
  BOOL changedir;
  LVAL usrfilter;

  changedir = moreargs() ? ! null(xlgetarg()) : TRUE;
  if (moreargs()) {
    usrfilter = xlgastring();
    if (getslength(usrfilter) > FILTERSIZE)
      xlbadtype(usrfilter);
    strcpy(szFilter, getstring(usrfilter));
  }
  else
    strcpy(szFilter, szDfltFilter);

  n = strlen(szFilter);
  for (i = 0; i < n; i++)
    if (szFilter[i] == '|')
      szFilter[i] = '\0';
  szFilter[n] = '\0';
  szFilter[n + 1] = '\0';

  if (! getcwd(szDirName, sizeof(szDirName)))
    return NIL;
  buf[0] = '\0';

  memset(&ofn, 0, sizeof(OPENFILENAME));
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.lpstrFilter = szFilter;
  ofn.nFilterIndex = 1;
  ofn.lpstrFile = buf;
  ofn.nMaxFile = STRMAX;
  ofn.lpstrInitialDir = szDirName;
  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  if (! changedir) ofn.Flags |= OFN_NOCHANGEDIR;

  if (GetOpenFileName(&ofn))
    return cvstring(buf);
  else
    return NIL;
}

LVAL xssetfiledialog()
{
  int i, n;
  OPENFILENAME ofn;
  BOOL changedir;
  LVAL usrfilter;
  char *title;

  title = getstring(xlgastring());
  changedir = moreargs() ? ! null(xlgetarg()) : TRUE;
  if (moreargs()) {
    usrfilter = xlgastring();
    if (getslength(usrfilter) > FILTERSIZE)
      xlbadtype(usrfilter);
    strcpy(szFilter, getstring(usrfilter));
  }
  else
    strcpy(szFilter, szDfltFilter);

  n = strlen(szFilter);
  for (i = 0; i < n; i++)
    if (szFilter[i] == '|')
      szFilter[i] = '\0';
  szFilter[n] = '\0';
  szFilter[n + 1] = '\0';

  if (! getcwd(szDirName, sizeof(szDirName)))
    return NIL;
  buf[0] = '\0';

  memset(&ofn, 0, sizeof(OPENFILENAME));
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.lpstrFilter = szFilter;
  ofn.nFilterIndex = 1;
  ofn.lpstrFile = buf;
  ofn.nMaxFile = STRMAX;
  ofn.lpstrInitialDir = szDirName;
  ofn.Flags = OFN_OVERWRITEPROMPT;
  if (! changedir) ofn.Flags |= OFN_NOCHANGEDIR;
  ofn.lpstrTitle = title;

  if (GetSaveFileName(&ofn))
    return cvstring(buf);
  else
    return NIL;
}