summaryrefslogtreecommitdiff
path: root/libgui/src/tclwinpath.c
blob: ce75ab0dd7f7fbafa719a3bbfa324bd8fe32fe75 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* tclwinpath.c -- Tcl routines to convert paths under cygwin32.
   Copyright (C) 1997 Cygnus Solutions.
   Written by Ian Lance Taylor <ian@cygnus.com>.

   This file contains Tcl interface routines to do path translation
   when using cygwin32.  */

#ifdef __CYGWIN32__

#include <windows.h>

#include <tcl.h>

#include "guitcl.h"
#include "subcommand.h"

/* The path conversion routines are not declared anywhere that I know
   of.  */

extern void cygwin32_conv_to_win32_path (const char *, char *);
extern void cygwin32_conv_to_full_win32_path (const char *, char *);
extern void cygwin32_conv_to_posix_path (const char *, char *);
extern void cygwin32_conv_to_full_posix_path (const char *, char *);
extern int cygwin32_posix_path_list_p (const char *);
extern int cygwin32_win32_to_posix_path_list_buf_size (const char *);
extern int cygwin32_posix_to_win32_path_list_buf_size (const char *);
extern void cygwin32_win32_to_posix_path_list (char *, char *);
extern void cygwin32_posix_to_win32_path_list (char *, char *);
extern void cygwin32_split_path (const char *, char *, char *);

/* This file declares a Tcl command with subcommands.

   Each of the following subcommands returns a string based on the
   PATH argument.  If PATH is already in the desired form, these
   commands just return it unchanged.

   ide_cygwin_path to_win32 PATH
       Return PATH converted to a win32 pathname.

   ide_cygwin_path to_full_win32 PATH
       Return PATH converted to an absolute win32 pathname.

   ide_cygwin_path to_posix PATH
       Return PATH converted to a POSIX pathname.

   ide_cygwin_path to_full_posix PATH
       Return PATH converted to an absolute POSIX pathname.

   The following subcommand returns a boolean value.

   ide_cygwin_path posix_path_list_p PATHLIST
       Return whether PATHLIST is a POSIX style path list.

   The following subcommands return strings.

   ide_cygwin_path posix_to_win32_path_list PATHLIST
       Return PATHLIST converted from POSIX style to win32 style.

   ide_cygwin_path win32_to_posix_path_list PATHLIST
       Return PATHLIST converted from win32 style to POSIX style.

   */

/* Handle ide_cygwin_path to_win32.  */

static int
path_to_win32 (ClientData cd, Tcl_Interp *interp, int argc, char **argv)
{
  char buf[MAX_PATH];

  cygwin32_conv_to_win32_path (argv[2], buf);
  Tcl_SetResult (interp, buf, TCL_VOLATILE);
  return TCL_OK;
}

/* Handle ide_cygwin_path to_full_win32.  */

static int
path_to_full_win32 (ClientData cd, Tcl_Interp *interp, int argc, char **argv)
{
  char buf[MAX_PATH];

  cygwin32_conv_to_full_win32_path (argv[2], buf);
  Tcl_SetResult (interp, buf, TCL_VOLATILE);
  return TCL_OK;
}

/* Handle ide_cygwin_path to_posix.  */

static int
path_to_posix (ClientData cd, Tcl_Interp *interp, int argc, char **argv)
{
  char buf[MAX_PATH];

  cygwin32_conv_to_posix_path (argv[2], buf);
  Tcl_SetResult (interp, buf, TCL_VOLATILE);
  return TCL_OK;
}

/* Handle ide_cygwin_path to_full_posix.  */

static int
path_to_full_posix (ClientData cd, Tcl_Interp *interp, int argc, char **argv)
{
  char buf[MAX_PATH];

  cygwin32_conv_to_full_posix_path (argv[2], buf);
  Tcl_SetResult (interp, buf, TCL_VOLATILE);
  return TCL_OK;
}

/* Handle ide_cygwin_path posix_path_list_p.  */

static int
path_posix_path_list_p (ClientData cd, Tcl_Interp *interp, int argc,
			char **argv)
{
  int ret;

  ret = cygwin32_posix_path_list_p (argv[2]);
  Tcl_ResetResult (interp);
  Tcl_SetBooleanObj (Tcl_GetObjResult (interp), ret);
  return TCL_OK;
}

/* Handle ide_cygwin_path posix_to_win32_path_list.  */

static int
path_posix_to_win32_path_list (ClientData cd, Tcl_Interp *interp, int argc,
			       char **argv)
{
  int size;
  char *buf;

  size = cygwin32_posix_to_win32_path_list_buf_size (argv[2]);
  buf = ckalloc (size);
  cygwin32_posix_to_win32_path_list (argv[2], buf);
  Tcl_SetResult (interp, buf, TCL_DYNAMIC);
  return TCL_OK;
}

/* Handle ide_cygwin_path win32_to_posix_path_list.  */

static int
path_win32_to_posix_path_list (ClientData cd, Tcl_Interp *interp, int argc,
			       char **argv)
{
  int size;
  char *buf;

  size = cygwin32_win32_to_posix_path_list_buf_size (argv[2]);
  buf = ckalloc (size);
  cygwin32_win32_to_posix_path_list (argv[2], buf);
  Tcl_SetResult (interp, buf, TCL_DYNAMIC);
  return TCL_OK;
}

/* The subcommand table.  */

static const struct ide_subcommand_table path_commands[] =
{
  { "to_win32",		path_to_win32,		3, 3 },
  { "to_full_win32",	path_to_full_win32,	3, 3 },
  { "to_posix",		path_to_posix,		3, 3 },
  { "to_full_posix",	path_to_full_posix,	3, 3 },
  { "posix_path_list_p", path_posix_path_list_p, 3, 3 },
  { "posix_to_win32_path_list", path_posix_to_win32_path_list, 3, 3 },
  { "win32_to_posix_path_list", path_win32_to_posix_path_list, 3, 3 },
  { NULL, NULL, 0, 0}
};

/* Create the ide_cygwin_path command.  */

int
ide_create_cygwin_path_command (Tcl_Interp *interp)
{
  return ide_create_command_with_subcommands (interp, "ide_cygwin_path",
					      path_commands, NULL, NULL);
}

#endif /* __CYGWIN32__ */