Repository navigation
Expand file tree
/
Copy pathwindiv.c
More file actions
179 lines (159 loc) · 3.64 KB
/
Copy pathwindiv.c
File metadata and controls
179 lines (159 loc) · 3.64 KB
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
/*
* windiv.c Some extra window routines for minicom, that
* I did not want to fold into window.c
*
* This file is part of the minicom communications package,
* Copyright 1991-1995 Miquel van Smoorenburg.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* hgk+jl 02.98 File selection window (no longer used this way..)
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <dirent.h>
#include <sys/stat.h>
#include "port.h"
#include "minicom.h"
#include "intl.h"
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
/*
* Popup a window and put a text in it.
*/
static WIN *vmc_tell(const char *fmt, va_list va)
{
WIN *w;
char buf[128];
if (stdwin == NULL)
return NULL;
vsnprintf(buf, sizeof(buf), fmt, va);
w = mc_wopen((COLS / 2) - 2 - mbslen(buf) / 2, 8,
(COLS / 2) + 2 + mbslen(buf) / 2, 10,
BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);
mc_wcursor(w, CNONE);
mc_wlocate(w, 2, 1);
mc_wputs(w, buf);
mc_wredraw(w, 1);
return w;
}
WIN *mc_tell(const char *s, ...)
{
WIN *w;
va_list ap;
va_start(ap, s);
w = vmc_tell(s, ap);
va_end(ap);
return w;
}
/*
* Show an error message.
*/
void werror(const char *s, ...)
{
WIN *tellwin;
va_list ap;
va_start(ap, s);
tellwin = vmc_tell(s, ap);
va_end(ap);
sleep(2);
mc_wclose(tellwin, 1);
}
/*
* Vertical "mc_wselect" function.
*/
int ask(const char *what, const char **s)
{
int num = 0;
int cur = 0, ocur = 0;
int f, c;
WIN *w;
unsigned int size, offs;
for (f = 0; s[f]; f++)
num++;
size = 5 * num;
offs = 0;
if (mbslen(what) > 2 * size + 4) {
size = mbslen(what) / 2 + 2;
offs = size - 5*num;
}
w = mc_wopen((COLS / 2) - size , 8, (COLS / 2) + 1 + size, 9,
BSINGLE, stdattr, mfcolor, mbcolor, 0, 0, 1);
dirflush = 0;
mc_wcursor(w, CNONE);
mc_wlocate(w, 1 + size - (mbslen(what) / 2), 0);
mc_wputs(w, what);
for (f = 1; f < num; f++) {
mc_wlocate(w, 2 + offs + 10*f, 1);
mc_wputs(w, _(s[f]));
}
mc_wredraw(w, 1);
while (1) {
mc_wlocate(w, 2 + offs + 10 * cur, 1);
if (!useattr)
mc_wprintf(w, ">%s", _(s[cur]) + 1);
else {
mc_wsetattr(w, XA_REVERSE | stdattr);
mc_wputs(w, _(s[cur]));
}
ocur = cur;
mc_wflush();
switch (c = wxgetch()) {
case ' ':
case 27:
case 3:
dirflush = 1;
mc_wclose(w, 1);
return -1;
case '\r':
case '\n':
dirflush = 1;
mc_wclose(w, 1);
return cur;
case K_LT:
case 'h':
cur--;
if (cur < 0)
cur = num - 1;
break;
default:
cur = (cur + 1) % num;
break;
}
mc_wlocate(w, 2 + offs + 10 * ocur, 1);
mc_wsetattr(w, stdattr);
if (!useattr)
mc_wputs(w, " ");
else
mc_wputs(w, _(s[ocur]));
}
}
/*
* Popup a window and ask for input.
*/
char *input(char *s, char *buf)
{
WIN *w;
w = mc_wopen((COLS / 2) - 20, 11, (COLS / 2) + 20, 12,
BDOUBLE, stdattr, mfcolor, mbcolor, 1, 0, 1);
mc_wputs(w, s);
mc_wlocate(w, 0, 1);
mc_wprintf(w, "> %-38.38s", buf);
mc_wlocate(w, 2, 1);
if (mc_wgets(w, buf, 38, 128) < 0)
buf = NULL;
mc_wclose(w, 1);
return buf;
}