Formatting change to braces around one case of a switch.

Sometimes, within a switch statement, you want to declare local
variables specific to the handler for one particular case. Until now
I've mostly been writing this in the form

    switch (discriminant) {
      case SIMPLE:
        do stuff;
        break;
      case COMPLICATED:
        {
            declare variables;
            do stuff;
        }
        break;
    }

which is ugly because the two pieces of essentially similar code
appear at different indent levels, and also inconvenient because you
have less horizontal space available to write the complicated case
handler in - particuarly undesirable because _complicated_ case
handlers are the ones most likely to need all the space they can get!

After encountering a rather nicer idiom in the LLVM source code, and
after a bit of hackery this morning figuring out how to persuade
Emacs's auto-indent to do what I wanted with it, I've decided to move
to an idiom in which the open brace comes right after the case
statement, and the code within it is indented the same as it would
have been without the brace. Then the whole case handler (including
the break) lives inside those braces, and you get something that looks
more like this:

    switch (discriminant) {
      case SIMPLE:
        do stuff;
        break;
      case COMPLICATED: {
        declare variables;
        do stuff;
        break;
      }
    }

This commit is a big-bang change that reformats all the complicated
case handlers I could find into the new layout. This is particularly
nice in the Pageant main function, in which almost _every_ case
handler had a bundle of variables and was long and complicated. (In
fact that's what motivated me to get round to this.) Some of the
innermost parts of the terminal escape-sequence handling are also
breathing a bit easier now the horizontal pressure on them is
relieved.

(Also, in a few cases, I was able to remove the extra braces
completely, because the only variable local to the case handler was a
loop variable which our new C99 policy allows me to move into the
initialiser clause of its for statement.)

Viewed with whitespace ignored, this is not too disruptive a change.
Downstream patches that conflict with it may need to be reapplied
using --ignore-whitespace or similar.
This commit is contained in:
Simon Tatham 2020-02-16 07:49:52 +00:00
Родитель 2571eabeef
Коммит 8d186c3c93
21 изменённых файлов: 2248 добавлений и 2333 удалений

Просмотреть файл

@ -32,26 +32,25 @@ void backend_socket_log(Seat *seat, LogContext *logctx,
sk_getaddr(addr, addrbuf, lenof(addrbuf));
msg = dupprintf("Connected to %s", addrbuf);
break;
case PLUGLOG_PROXY_MSG:
case PLUGLOG_PROXY_MSG: {
/* Proxy-related log messages have their own identifying
* prefix already, put on by our caller. */
{
int len, log_to_term;
int len, log_to_term;
/* Suffix \r\n temporarily, so we can log to the terminal. */
msg = dupprintf("%s\r\n", error_msg);
len = strlen(msg);
assert(len >= 2);
/* Suffix \r\n temporarily, so we can log to the terminal. */
msg = dupprintf("%s\r\n", error_msg);
len = strlen(msg);
assert(len >= 2);
log_to_term = conf_get_int(conf, CONF_proxy_log_to_term);
if (log_to_term == AUTO)
log_to_term = session_started ? FORCE_OFF : FORCE_ON;
if (log_to_term == FORCE_ON)
seat_stderr(seat, msg, len);
log_to_term = conf_get_int(conf, CONF_proxy_log_to_term);
if (log_to_term == AUTO)
log_to_term = session_started ? FORCE_OFF : FORCE_ON;
if (log_to_term == FORCE_ON)
seat_stderr(seat, msg, len);
msg[len-2] = '\0'; /* remove the \r\n again */
}
msg[len-2] = '\0'; /* remove the \r\n again */
break;
}
default:
msg = NULL; /* shouldn't happen, but placate optimiser */
break;

278
cmdgen.c
Просмотреть файл

@ -211,91 +211,90 @@ int main(int argc, char **argv)
while (p && *++p) {
char c = *p;
switch (c) {
case '-':
case '-': {
/*
* Long option.
*/
{
char *opt, *val;
opt = p++; /* opt will have _one_ leading - */
while (*p && *p != '=')
p++; /* find end of option */
if (*p == '=') {
*p++ = '\0';
val = p;
} else
val = NULL;
char *opt, *val;
opt = p++; /* opt will have _one_ leading - */
while (*p && *p != '=')
p++; /* find end of option */
if (*p == '=') {
*p++ = '\0';
val = p;
} else
val = NULL;
if (!strcmp(opt, "-help")) {
if (val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects no argument\n", opt);
} else {
help();
nogo = true;
}
} else if (!strcmp(opt, "-version")) {
if (val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects no argument\n", opt);
} else {
showversion();
nogo = true;
}
} else if (!strcmp(opt, "-pgpfp")) {
if (val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects no argument\n", opt);
} else {
/* support --pgpfp for consistency */
pgp_fingerprints();
nogo = true;
}
} else if (!strcmp(opt, "-old-passphrase")) {
if (!val && argc > 1)
--argc, val = *++argv;
if (!val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects an argument\n", opt);
} else {
old_passphrase = readpassphrase(val);
if (!old_passphrase)
errs = true;
}
} else if (!strcmp(opt, "-new-passphrase")) {
if (!val && argc > 1)
--argc, val = *++argv;
if (!val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects an argument\n", opt);
} else {
new_passphrase = readpassphrase(val);
if (!new_passphrase)
errs = true;
}
} else if (!strcmp(opt, "-random-device")) {
if (!val && argc > 1)
--argc, val = *++argv;
if (!val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects an argument\n", opt);
} else {
random_device = val;
}
} else {
if (!strcmp(opt, "-help")) {
if (val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects no argument\n", opt);
} else {
help();
nogo = true;
}
} else if (!strcmp(opt, "-version")) {
if (val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects no argument\n", opt);
} else {
showversion();
nogo = true;
}
} else if (!strcmp(opt, "-pgpfp")) {
if (val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects no argument\n", opt);
} else {
/* support --pgpfp for consistency */
pgp_fingerprints();
nogo = true;
}
} else if (!strcmp(opt, "-old-passphrase")) {
if (!val && argc > 1)
--argc, val = *++argv;
if (!val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects an argument\n", opt);
} else {
old_passphrase = readpassphrase(val);
if (!old_passphrase)
errs = true;
fprintf(stderr,
"puttygen: no such option `-%s'\n", opt);
}
}
} else if (!strcmp(opt, "-new-passphrase")) {
if (!val && argc > 1)
--argc, val = *++argv;
if (!val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects an argument\n", opt);
} else {
new_passphrase = readpassphrase(val);
if (!new_passphrase)
errs = true;
}
} else if (!strcmp(opt, "-random-device")) {
if (!val && argc > 1)
--argc, val = *++argv;
if (!val) {
errs = true;
fprintf(stderr, "puttygen: option `-%s'"
" expects an argument\n", opt);
} else {
random_device = val;
}
} else {
errs = true;
fprintf(stderr,
"puttygen: no such option `-%s'\n", opt);
}
p = NULL;
break;
}
case 'h':
case 'V':
case 'P':
@ -941,75 +940,74 @@ int main(int argc, char **argv)
break;
case PUBLIC:
case PUBLICO:
{
FILE *fp;
case PUBLICO: {
FILE *fp;
if (outfile) {
fp = f_open(outfilename, "w", false);
if (!fp) {
fprintf(stderr, "unable to open output file\n");
exit(1);
}
} else {
fp = stdout;
}
if (sshver == 1) {
ssh1_write_pubkey(fp, ssh1key);
} else {
if (!ssh2blob) {
assert(ssh2key);
ssh2blob = strbuf_new();
ssh_key_public_blob(ssh2key->key, BinarySink_UPCAST(ssh2blob));
}
ssh2_write_pubkey(fp, ssh2key ? ssh2key->comment : origcomment,
ssh2blob->s, ssh2blob->len,
(outtype == PUBLIC ?
SSH_KEYTYPE_SSH2_PUBLIC_RFC4716 :
SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH));
}
if (outfile)
fclose(fp);
if (outfile) {
fp = f_open(outfilename, "w", false);
if (!fp) {
fprintf(stderr, "unable to open output file\n");
exit(1);
}
} else {
fp = stdout;
}
break;
case FP:
{
FILE *fp;
char *fingerprint;
if (sshver == 1) {
ssh1_write_pubkey(fp, ssh1key);
} else {
if (!ssh2blob) {
assert(ssh2key);
ssh2blob = strbuf_new();
ssh_key_public_blob(ssh2key->key, BinarySink_UPCAST(ssh2blob));
}
if (sshver == 1) {
assert(ssh1key);
fingerprint = rsa_ssh1_fingerprint(ssh1key);
} else {
if (ssh2key) {
fingerprint = ssh2_fingerprint(ssh2key->key);
} else {
assert(ssh2blob);
fingerprint = ssh2_fingerprint_blob(
ptrlen_from_strbuf(ssh2blob));
}
}
if (outfile) {
fp = f_open(outfilename, "w", false);
if (!fp) {
fprintf(stderr, "unable to open output file\n");
exit(1);
}
} else {
fp = stdout;
}
fprintf(fp, "%s\n", fingerprint);
if (outfile)
fclose(fp);
sfree(fingerprint);
ssh2_write_pubkey(fp, ssh2key ? ssh2key->comment : origcomment,
ssh2blob->s, ssh2blob->len,
(outtype == PUBLIC ?
SSH_KEYTYPE_SSH2_PUBLIC_RFC4716 :
SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH));
}
if (outfile)
fclose(fp);
break;
}
case FP: {
FILE *fp;
char *fingerprint;
if (sshver == 1) {
assert(ssh1key);
fingerprint = rsa_ssh1_fingerprint(ssh1key);
} else {
if (ssh2key) {
fingerprint = ssh2_fingerprint(ssh2key->key);
} else {
assert(ssh2blob);
fingerprint = ssh2_fingerprint_blob(
ptrlen_from_strbuf(ssh2blob));
}
}
if (outfile) {
fp = f_open(outfilename, "w", false);
if (!fp) {
fprintf(stderr, "unable to open output file\n");
exit(1);
}
} else {
fp = stdout;
}
fprintf(fp, "%s\n", fingerprint);
if (outfile)
fclose(fp);
sfree(fingerprint);
break;
}
case OPENSSH_AUTO:
case OPENSSH_NEW:

Просмотреть файл

@ -1235,20 +1235,19 @@ static struct openssh_new_key *load_openssh_new_key(BinarySource *filesrc,
goto error;
}
break;
case ON_K_BCRYPT:
{
BinarySource opts[1];
case ON_K_BCRYPT: {
BinarySource opts[1];
BinarySource_BARE_INIT_PL(opts, str);
ret->kdfopts.bcrypt.salt = get_string(opts);
ret->kdfopts.bcrypt.rounds = get_uint32(opts);
BinarySource_BARE_INIT_PL(opts, str);
ret->kdfopts.bcrypt.salt = get_string(opts);
ret->kdfopts.bcrypt.rounds = get_uint32(opts);
if (get_err(opts)) {
errmsg = "failed to parse bcrypt options string";
goto error;
}
if (get_err(opts)) {
errmsg = "failed to parse bcrypt options string";
goto error;
}
break;
}
}
/*

Просмотреть файл

@ -1281,20 +1281,19 @@ int do_bidi(bidi_char *line, int count)
bover = true;
break;
case PDF:
{
int prevlevel = getPreviousLevel(levels, i);
case PDF: {
int prevlevel = getPreviousLevel(levels, i);
if (prevlevel == -1) {
currentEmbedding = paragraphLevel;
currentOverride = ON;
} else {
currentOverride = currentEmbedding & OMASK;
currentEmbedding = currentEmbedding & ~OMASK;
}
if (prevlevel == -1) {
currentEmbedding = paragraphLevel;
currentOverride = ON;
} else {
currentOverride = currentEmbedding & OMASK;
currentEmbedding = currentEmbedding & ~OMASK;
}
levels[i] = currentEmbedding;
break;
}
/* Whitespace is treated as neutral for now */
case WS:

1153
pageant.c

Разница между файлами не показана из-за своего большого размера Загрузить разницу

93
proxy.c
Просмотреть файл

@ -766,13 +766,12 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
put_uint16(command, p->remote_port);
switch (sk_addrtype(p->remote_addr)) {
case ADDRTYPE_IPV4:
{
char addr[4];
sk_addrcopy(p->remote_addr, addr);
put_data(command, addr, 4);
break;
}
case ADDRTYPE_IPV4: {
char addr[4];
sk_addrcopy(p->remote_addr, addr);
put_data(command, addr, 4);
break;
}
case ADDRTYPE_NAME:
sk_getaddr(p->remote_addr, hostname, lenof(hostname));
put_uint32(command, 1);
@ -1084,19 +1083,18 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
put_byte(command, 4); /* IPv6 */
sk_addrcopy(p->remote_addr, strbuf_append(command, 16));
break;
case ADDRTYPE_NAME:
{
char hostname[512];
put_byte(command, 3); /* domain name */
sk_getaddr(p->remote_addr, hostname, lenof(hostname));
if (!put_pstring(command, hostname)) {
p->error = "Proxy error: SOCKS 5 cannot "
"support host names longer than 255 chars";
strbuf_free(command);
return 1;
}
case ADDRTYPE_NAME: {
char hostname[512];
put_byte(command, 3); /* domain name */
sk_getaddr(p->remote_addr, hostname, lenof(hostname));
if (!put_pstring(command, hostname)) {
p->error = "Proxy error: SOCKS 5 cannot "
"support host names longer than 255 chars";
strbuf_free(command);
return 1;
}
break;
}
}
put_uint16(command, p->remote_port);
@ -1317,41 +1315,40 @@ char *format_telnet_command(SockAddr *addr, int port, Conf *conf)
break;
case 'x':
case 'X':
{
/* escaped hexadecimal value (ie. \xff) */
unsigned char v = 0;
int i = 0;
case 'X': {
/* escaped hexadecimal value (ie. \xff) */
unsigned char v = 0;
int i = 0;
for (;;) {
eo++;
if (fmt[eo] >= '0' && fmt[eo] <= '9')
v += fmt[eo] - '0';
else if (fmt[eo] >= 'a' && fmt[eo] <= 'f')
v += fmt[eo] - 'a' + 10;
else if (fmt[eo] >= 'A' && fmt[eo] <= 'F')
v += fmt[eo] - 'A' + 10;
else {
/* non hex character, so we abort and just
* send the whole thing unescaped (including \x)
*/
put_byte(buf, '\\');
eo = so + 1;
break;
}
for (;;) {
eo++;
if (fmt[eo] >= '0' && fmt[eo] <= '9')
v += fmt[eo] - '0';
else if (fmt[eo] >= 'a' && fmt[eo] <= 'f')
v += fmt[eo] - 'a' + 10;
else if (fmt[eo] >= 'A' && fmt[eo] <= 'F')
v += fmt[eo] - 'A' + 10;
else {
/* non hex character, so we abort and just
* send the whole thing unescaped (including \x)
*/
put_byte(buf, '\\');
eo = so + 1;
break;
}
/* we only extract two hex characters */
if (i == 1) {
put_byte(buf, v);
eo++;
break;
}
/* we only extract two hex characters */
if (i == 1) {
put_byte(buf, v);
eo++;
break;
}
i++;
v <<= 4;
}
i++;
v <<= 4;
}
break;
}
default:
put_data(buf, fmt + so, 2);

Просмотреть файл

@ -492,13 +492,12 @@ static void write_clip_setting(settings_w *sesskey, const char *savekey,
case CLIPUI_EXPLICIT:
write_setting_s(sesskey, savekey, "explicit");
break;
case CLIPUI_CUSTOM:
{
char *sval = dupcat("custom:", conf_get_str(conf, strconfkey));
write_setting_s(sesskey, savekey, sval);
sfree(sval);
}
case CLIPUI_CUSTOM: {
char *sval = dupcat("custom:", conf_get_str(conf, strconfkey));
write_setting_s(sesskey, savekey, sval);
sfree(sval);
break;
}
}
}

Просмотреть файл

@ -262,15 +262,14 @@ bool ssh1_handle_direction_specific_packet(
return true;
case SSH1_SMSG_EXIT_STATUS:
{
int exitcode = get_uint32(pktin);
ppl_logevent("Server sent command exit status %d", exitcode);
ssh_got_exitcode(s->ppl.ssh, exitcode);
case SSH1_SMSG_EXIT_STATUS: {
int exitcode = get_uint32(pktin);
ppl_logevent("Server sent command exit status %d", exitcode);
ssh_got_exitcode(s->ppl.ssh, exitcode);
s->session_terminated = true;
}
s->session_terminated = true;
return true;
}
default:
return false;

Просмотреть файл

@ -115,35 +115,35 @@ bool ssh1_handle_direction_specific_packet(
return true;
case SSH1_CMSG_REQUEST_PTY:
case SSH1_CMSG_REQUEST_PTY: {
if (s->finished_setup)
goto unexpected_setup_packet;
{
ptrlen termtype = get_string(pktin);
unsigned height = get_uint32(pktin);
unsigned width = get_uint32(pktin);
unsigned pixwidth = get_uint32(pktin);
unsigned pixheight = get_uint32(pktin);
struct ssh_ttymodes modes = read_ttymodes_from_packet(
BinarySource_UPCAST(pktin), 1);
if (get_err(pktin)) {
ppl_logevent("Unable to decode pty request packet");
success = false;
} else if (!chan_allocate_pty(
s->mainchan_chan, termtype, width, height,
pixwidth, pixheight, modes)) {
ppl_logevent("Unable to allocate a pty");
success = false;
} else {
success = true;
}
ptrlen termtype = get_string(pktin);
unsigned height = get_uint32(pktin);
unsigned width = get_uint32(pktin);
unsigned pixwidth = get_uint32(pktin);
unsigned pixheight = get_uint32(pktin);
struct ssh_ttymodes modes = read_ttymodes_from_packet(
BinarySource_UPCAST(pktin), 1);
if (get_err(pktin)) {
ppl_logevent("Unable to decode pty request packet");
success = false;
} else if (!chan_allocate_pty(
s->mainchan_chan, termtype, width, height,
pixwidth, pixheight, modes)) {
ppl_logevent("Unable to allocate a pty");
success = false;
} else {
success = true;
}
pktout = ssh_bpp_new_pktout(
s->ppl.bpp, (success ? SSH1_SMSG_SUCCESS : SSH1_SMSG_FAILURE));
pq_push(s->ppl.out_pq, pktout);
return true;
}
case SSH1_CMSG_PORT_FORWARD_REQUEST:
if (s->finished_setup)
@ -166,25 +166,24 @@ bool ssh1_handle_direction_specific_packet(
pq_push(s->ppl.out_pq, pktout);
return true;
case SSH1_CMSG_X11_REQUEST_FORWARDING:
case SSH1_CMSG_X11_REQUEST_FORWARDING: {
if (s->finished_setup)
goto unexpected_setup_packet;
{
ptrlen authproto = get_string(pktin);
ptrlen authdata = get_string(pktin);
unsigned screen_number = 0;
if (s->remote_protoflags & SSH1_PROTOFLAG_SCREEN_NUMBER)
screen_number = get_uint32(pktin);
ptrlen authproto = get_string(pktin);
ptrlen authdata = get_string(pktin);
unsigned screen_number = 0;
if (s->remote_protoflags & SSH1_PROTOFLAG_SCREEN_NUMBER)
screen_number = get_uint32(pktin);
success = chan_enable_x11_forwarding(
s->mainchan_chan, false, authproto, authdata, screen_number);
}
success = chan_enable_x11_forwarding(
s->mainchan_chan, false, authproto, authdata, screen_number);
pktout = ssh_bpp_new_pktout(
s->ppl.bpp, (success ? SSH1_SMSG_SUCCESS : SSH1_SMSG_FAILURE));
pq_push(s->ppl.out_pq, pktout);
return true;
}
case SSH1_CMSG_AGENT_REQUEST_FORWARDING:
if (s->finished_setup)

Просмотреть файл

@ -516,19 +516,18 @@ static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
ssh2_channel_try_eof(c); /* in case we had a pending EOF */
break;
case SSH2_MSG_CHANNEL_OPEN_FAILURE:
case SSH2_MSG_CHANNEL_OPEN_FAILURE: {
assert(c->halfopen);
{
char *err = ssh2_channel_open_failure_error_text(pktin);
chan_open_failed(c->chan, err);
sfree(err);
}
char *err = ssh2_channel_open_failure_error_text(pktin);
chan_open_failed(c->chan, err);
sfree(err);
del234(s->channels, c);
ssh2_channel_free(c);
break;
}
case SSH2_MSG_CHANNEL_DATA:
case SSH2_MSG_CHANNEL_EXTENDED_DATA:

Просмотреть файл

@ -3411,71 +3411,70 @@ static void term_out(Terminal *term)
strbuf_free(buf);
}
break;
case '\007': /* BEL: Bell */
{
struct beeptime *newbeep;
unsigned long ticks;
case '\007': { /* BEL: Bell */
struct beeptime *newbeep;
unsigned long ticks;
ticks = GETTICKCOUNT();
ticks = GETTICKCOUNT();
if (!term->beep_overloaded) {
newbeep = snew(struct beeptime);
newbeep->ticks = ticks;
newbeep->next = NULL;
if (!term->beephead)
term->beephead = newbeep;
else
term->beeptail->next = newbeep;
term->beeptail = newbeep;
term->nbeeps++;
}
/*
* Throw out any beeps that happened more than
* t seconds ago.
*/
while (term->beephead &&
term->beephead->ticks < ticks - term->bellovl_t) {
struct beeptime *tmp = term->beephead;
term->beephead = tmp->next;
sfree(tmp);
if (!term->beephead)
term->beeptail = NULL;
term->nbeeps--;
}
if (term->bellovl && term->beep_overloaded &&
ticks - term->lastbeep >= (unsigned)term->bellovl_s) {
/*
* If we're currently overloaded and the
* last beep was more than s seconds ago,
* leave overload mode.
*/
term->beep_overloaded = false;
} else if (term->bellovl && !term->beep_overloaded &&
term->nbeeps >= term->bellovl_n) {
/*
* Now, if we have n or more beeps
* remaining in the queue, go into overload
* mode.
*/
term->beep_overloaded = true;
}
term->lastbeep = ticks;
/*
* Perform an actual beep if we're not overloaded.
*/
if (!term->bellovl || !term->beep_overloaded) {
win_bell(term->win, term->beep);
if (term->beep == BELL_VISUAL) {
term_schedule_vbell(term, false, 0);
}
}
seen_disp_event(term);
if (!term->beep_overloaded) {
newbeep = snew(struct beeptime);
newbeep->ticks = ticks;
newbeep->next = NULL;
if (!term->beephead)
term->beephead = newbeep;
else
term->beeptail->next = newbeep;
term->beeptail = newbeep;
term->nbeeps++;
}
/*
* Throw out any beeps that happened more than
* t seconds ago.
*/
while (term->beephead &&
term->beephead->ticks < ticks - term->bellovl_t) {
struct beeptime *tmp = term->beephead;
term->beephead = tmp->next;
sfree(tmp);
if (!term->beephead)
term->beeptail = NULL;
term->nbeeps--;
}
if (term->bellovl && term->beep_overloaded &&
ticks - term->lastbeep >= (unsigned)term->bellovl_s) {
/*
* If we're currently overloaded and the
* last beep was more than s seconds ago,
* leave overload mode.
*/
term->beep_overloaded = false;
} else if (term->bellovl && !term->beep_overloaded &&
term->nbeeps >= term->bellovl_n) {
/*
* Now, if we have n or more beeps
* remaining in the queue, go into overload
* mode.
*/
term->beep_overloaded = true;
}
term->lastbeep = ticks;
/*
* Perform an actual beep if we're not overloaded.
*/
if (!term->bellovl || !term->beep_overloaded) {
win_bell(term->win, term->beep);
if (term->beep == BELL_VISUAL) {
term_schedule_vbell(term, false, 0);
}
}
seen_disp_event(term);
break;
}
case '\b': /* BS: Back space */
if (term->curs.x == 0 && (term->curs.y == 0 || !term->wrap))
/* do nothing */ ;
@ -3542,28 +3541,27 @@ static void term_out(Terminal *term)
if (term->logctx)
logtraffic(term->logctx, (unsigned char) c, LGTYP_ASCII);
break;
case '\t': /* HT: Character tabulation */
{
pos old_curs = term->curs;
termline *ldata = scrlineptr(term->curs.y);
case '\t': { /* HT: Character tabulation */
pos old_curs = term->curs;
termline *ldata = scrlineptr(term->curs.y);
do {
term->curs.x++;
} while (term->curs.x < term->cols - 1 &&
!term->tabs[term->curs.x]);
do {
term->curs.x++;
} while (term->curs.x < term->cols - 1 &&
!term->tabs[term->curs.x]);
if ((ldata->lattr & LATTR_MODE) != LATTR_NORM) {
if (term->curs.x >= term->cols / 2)
term->curs.x = term->cols / 2 - 1;
} else {
if (term->curs.x >= term->cols)
term->curs.x = term->cols - 1;
}
check_selection(term, old_curs, term->curs);
if ((ldata->lattr & LATTR_MODE) != LATTR_NORM) {
if (term->curs.x >= term->cols / 2)
term->curs.x = term->cols / 2 - 1;
} else {
if (term->curs.x >= term->cols)
term->curs.x = term->cols - 1;
}
check_selection(term, old_curs, term->curs);
seen_disp_event(term);
break;
}
}
} else
switch (term->termstate) {
@ -3679,62 +3677,60 @@ static void term_out(Terminal *term)
term->tabs[term->curs.x] = true;
break;
case ANSI('8', '#'): /* DECALN: fills screen with Es :-) */
case ANSI('8', '#'): { /* DECALN: fills screen with Es :-) */
compatibility(VT100);
{
termline *ldata;
int i, j;
pos scrtop, scrbot;
termline *ldata;
int i, j;
pos scrtop, scrbot;
for (i = 0; i < term->rows; i++) {
ldata = scrlineptr(i);
check_line_size(term, ldata);
for (j = 0; j < term->cols; j++) {
copy_termchar(ldata, j,
&term->basic_erase_char);
ldata->chars[j].chr = 'E';
}
ldata->lattr = LATTR_NORM;
}
if (term->scroll_on_disp)
term->disptop = 0;
seen_disp_event(term);
scrtop.x = scrtop.y = 0;
scrbot.x = 0;
scrbot.y = term->rows;
check_selection(term, scrtop, scrbot);
for (i = 0; i < term->rows; i++) {
ldata = scrlineptr(i);
check_line_size(term, ldata);
for (j = 0; j < term->cols; j++) {
copy_termchar(ldata, j,
&term->basic_erase_char);
ldata->chars[j].chr = 'E';
}
ldata->lattr = LATTR_NORM;
}
if (term->scroll_on_disp)
term->disptop = 0;
seen_disp_event(term);
scrtop.x = scrtop.y = 0;
scrbot.x = 0;
scrbot.y = term->rows;
check_selection(term, scrtop, scrbot);
break;
}
case ANSI('3', '#'):
case ANSI('4', '#'):
case ANSI('5', '#'):
case ANSI('6', '#'):
case ANSI('6', '#'): {
compatibility(VT100);
{
int nlattr;
termline *ldata;
int nlattr;
termline *ldata;
switch (ANSI(c, term->esc_query)) {
case ANSI('3', '#'): /* DECDHL: 2*height, top */
nlattr = LATTR_TOP;
break;
case ANSI('4', '#'): /* DECDHL: 2*height, bottom */
nlattr = LATTR_BOT;
break;
case ANSI('5', '#'): /* DECSWL: normal */
nlattr = LATTR_NORM;
break;
default: /* case ANSI('6', '#'): DECDWL: 2*width */
nlattr = LATTR_WIDE;
break;
}
ldata = scrlineptr(term->curs.y);
check_line_size(term, ldata);
check_trust_status(term, ldata);
ldata->lattr = nlattr;
switch (ANSI(c, term->esc_query)) {
case ANSI('3', '#'): /* DECDHL: 2*height, top */
nlattr = LATTR_TOP;
break;
case ANSI('4', '#'): /* DECDHL: 2*height, bottom */
nlattr = LATTR_BOT;
break;
case ANSI('5', '#'): /* DECSWL: normal */
nlattr = LATTR_NORM;
break;
default: /* case ANSI('6', '#'): DECDWL: 2*width */
nlattr = LATTR_WIDE;
break;
}
ldata = scrlineptr(term->curs.y);
check_line_size(term, ldata);
check_trust_status(term, ldata);
ldata->lattr = nlattr;
break;
}
/* GZD4: G0 designate 94-set */
case ANSI('A', '('):
compatibility(VT100);
@ -3913,34 +3909,32 @@ static void term_out(Terminal *term)
(term->dec_om ? 2 : 0));
seen_disp_event(term);
break;
case 'J': /* ED: erase screen or parts of it */
{
unsigned int i = def(term->esc_args[0], 0);
if (i == 3) {
/* Erase Saved Lines (xterm)
* This follows Thomas Dickey's xterm. */
if (!term->no_remote_clearscroll)
term_clrsb(term);
} else {
i++;
if (i > 3)
i = 0;
erase_lots(term, false, !!(i & 2), !!(i & 1));
}
case 'J': { /* ED: erase screen or parts of it */
unsigned int i = def(term->esc_args[0], 0);
if (i == 3) {
/* Erase Saved Lines (xterm)
* This follows Thomas Dickey's xterm. */
if (!term->no_remote_clearscroll)
term_clrsb(term);
} else {
i++;
if (i > 3)
i = 0;
erase_lots(term, false, !!(i & 2), !!(i & 1));
}
if (term->scroll_on_disp)
term->disptop = 0;
seen_disp_event(term);
break;
case 'K': /* EL: erase line or parts of it */
{
unsigned int i = def(term->esc_args[0], 0) + 1;
if (i > 3)
i = 0;
erase_lots(term, true, !!(i & 2), !!(i & 1));
}
}
case 'K': { /* EL: erase line or parts of it */
unsigned int i = def(term->esc_args[0], 0) + 1;
if (i > 3)
i = 0;
erase_lots(term, true, !!(i & 2), !!(i & 1));
seen_disp_event(term);
break;
}
case 'L': /* IL: insert lines */
compatibility(VT102);
CLAMP(term->esc_args[0], term->rows);
@ -3994,41 +3988,34 @@ static void term_out(Terminal *term)
case 'h': /* SM: toggle modes to high */
case ANSI_QUE('h'):
compatibility(VT100);
{
int i;
for (i = 0; i < term->esc_nargs; i++)
toggle_mode(term, term->esc_args[i],
term->esc_query, true);
}
for (int i = 0; i < term->esc_nargs; i++)
toggle_mode(term, term->esc_args[i],
term->esc_query, true);
break;
case 'i': /* MC: Media copy */
case ANSI_QUE('i'):
case ANSI_QUE('i'): {
compatibility(VT100);
{
char *printer;
if (term->esc_nargs != 1) break;
if (term->esc_args[0] == 5 &&
(printer = conf_get_str(term->conf,
CONF_printer))[0]) {
term->printing = true;
term->only_printing = !term->esc_query;
term->print_state = 0;
term_print_setup(term, printer);
} else if (term->esc_args[0] == 4 &&
term->printing) {
term_print_finish(term);
}
char *printer;
if (term->esc_nargs != 1) break;
if (term->esc_args[0] == 5 &&
(printer = conf_get_str(term->conf,
CONF_printer))[0]) {
term->printing = true;
term->only_printing = !term->esc_query;
term->print_state = 0;
term_print_setup(term, printer);
} else if (term->esc_args[0] == 4 &&
term->printing) {
term_print_finish(term);
}
break;
}
case 'l': /* RM: toggle modes to low */
case ANSI_QUE('l'):
compatibility(VT100);
{
int i;
for (i = 0; i < term->esc_nargs; i++)
toggle_mode(term, term->esc_args[i],
term->esc_query, false);
}
for (int i = 0; i < term->esc_nargs; i++)
toggle_mode(term, term->esc_args[i],
term->esc_query, false);
break;
case 'g': /* TBC: clear tabs */
compatibility(VT100);
@ -4078,222 +4065,217 @@ static void term_out(Terminal *term)
}
break;
case 'm': /* SGR: set graphics rendition */
{
/*
* A VT100 without the AVO only had one
* attribute, either underline or
* reverse video depending on the
* cursor type, this was selected by
* CSI 7m.
*
* case 2:
* This is sometimes DIM, eg on the
* GIGI and Linux
* case 8:
* This is sometimes INVIS various ANSI.
* case 21:
* This like 22 disables BOLD, DIM and INVIS
*
* The ANSI colours appear on any
* terminal that has colour (obviously)
* but the interaction between sgr0 and
* the colours varies but is usually
* related to the background colour
* erase item. The interaction between
* colour attributes and the mono ones
* is also very implementation
* dependent.
*
* The 39 and 49 attributes are likely
* to be unimplemented.
*/
int i;
for (i = 0; i < term->esc_nargs; i++) {
switch (def(term->esc_args[i], 0)) {
case 0: /* restore defaults */
term->curr_attr = term->default_attr;
term->curr_truecolour =
term->basic_erase_char.truecolour;
break;
case 1: /* enable bold */
compatibility(VT100AVO);
term->curr_attr |= ATTR_BOLD;
break;
case 2: /* enable dim */
compatibility(OTHER);
term->curr_attr |= ATTR_DIM;
break;
case 21: /* (enable double underline) */
compatibility(OTHER);
case 4: /* enable underline */
compatibility(VT100AVO);
term->curr_attr |= ATTR_UNDER;
break;
case 5: /* enable blink */
compatibility(VT100AVO);
term->curr_attr |= ATTR_BLINK;
break;
case 6: /* SCO light bkgrd */
compatibility(SCOANSI);
term->blink_is_real = false;
term->curr_attr |= ATTR_BLINK;
term_schedule_tblink(term);
break;
case 7: /* enable reverse video */
term->curr_attr |= ATTR_REVERSE;
break;
case 10: /* SCO acs off */
compatibility(SCOANSI);
if (term->no_remote_charset) break;
term->sco_acs = 0; break;
case 11: /* SCO acs on */
compatibility(SCOANSI);
if (term->no_remote_charset) break;
term->sco_acs = 1; break;
case 12: /* SCO acs on, |0x80 */
compatibility(SCOANSI);
if (term->no_remote_charset) break;
term->sco_acs = 2; break;
case 22: /* disable bold and dim */
compatibility2(OTHER, VT220);
term->curr_attr &= ~(ATTR_BOLD | ATTR_DIM);
break;
case 24: /* disable underline */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_UNDER;
break;
case 25: /* disable blink */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_BLINK;
break;
case 27: /* disable reverse video */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_REVERSE;
break;
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
/* foreground */
term->curr_truecolour.fg.enabled = false;
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |=
(term->esc_args[i] - 30)<<ATTR_FGSHIFT;
break;
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
/* aixterm-style bright foreground */
term->curr_truecolour.fg.enabled = false;
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |=
((term->esc_args[i] - 90 + 8)
<< ATTR_FGSHIFT);
break;
case 39: /* default-foreground */
term->curr_truecolour.fg.enabled = false;
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |= ATTR_DEFFG;
break;
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
/* background */
term->curr_truecolour.bg.enabled = false;
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |=
(term->esc_args[i] - 40)<<ATTR_BGSHIFT;
break;
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
/* aixterm-style bright background */
term->curr_truecolour.bg.enabled = false;
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |=
((term->esc_args[i] - 100 + 8)
<< ATTR_BGSHIFT);
break;
case 49: /* default-background */
term->curr_truecolour.bg.enabled = false;
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |= ATTR_DEFBG;
break;
/*
* A VT100 without the AVO only had one
* attribute, either underline or reverse
* video depending on the cursor type, this
* was selected by CSI 7m.
*
* case 2:
* This is sometimes DIM, eg on the GIGI and
* Linux
* case 8:
* This is sometimes INVIS various ANSI.
* case 21:
* This like 22 disables BOLD, DIM and INVIS
*
* The ANSI colours appear on any terminal
* that has colour (obviously) but the
* interaction between sgr0 and the colours
* varies but is usually related to the
* background colour erase item. The
* interaction between colour attributes and
* the mono ones is also very implementation
* dependent.
*
* The 39 and 49 attributes are likely to be
* unimplemented.
*/
for (int i = 0; i < term->esc_nargs; i++) {
switch (def(term->esc_args[i], 0)) {
case 0: /* restore defaults */
term->curr_attr = term->default_attr;
term->curr_truecolour =
term->basic_erase_char.truecolour;
break;
case 1: /* enable bold */
compatibility(VT100AVO);
term->curr_attr |= ATTR_BOLD;
break;
case 2: /* enable dim */
compatibility(OTHER);
term->curr_attr |= ATTR_DIM;
break;
case 21: /* (enable double underline) */
compatibility(OTHER);
case 4: /* enable underline */
compatibility(VT100AVO);
term->curr_attr |= ATTR_UNDER;
break;
case 5: /* enable blink */
compatibility(VT100AVO);
term->curr_attr |= ATTR_BLINK;
break;
case 6: /* SCO light bkgrd */
compatibility(SCOANSI);
term->blink_is_real = false;
term->curr_attr |= ATTR_BLINK;
term_schedule_tblink(term);
break;
case 7: /* enable reverse video */
term->curr_attr |= ATTR_REVERSE;
break;
case 10: /* SCO acs off */
compatibility(SCOANSI);
if (term->no_remote_charset) break;
term->sco_acs = 0; break;
case 11: /* SCO acs on */
compatibility(SCOANSI);
if (term->no_remote_charset) break;
term->sco_acs = 1; break;
case 12: /* SCO acs on, |0x80 */
compatibility(SCOANSI);
if (term->no_remote_charset) break;
term->sco_acs = 2; break;
case 22: /* disable bold and dim */
compatibility2(OTHER, VT220);
term->curr_attr &= ~(ATTR_BOLD | ATTR_DIM);
break;
case 24: /* disable underline */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_UNDER;
break;
case 25: /* disable blink */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_BLINK;
break;
case 27: /* disable reverse video */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_REVERSE;
break;
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
/* foreground */
term->curr_truecolour.fg.enabled = false;
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |=
(term->esc_args[i] - 30)<<ATTR_FGSHIFT;
break;
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
/* aixterm-style bright foreground */
term->curr_truecolour.fg.enabled = false;
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |=
((term->esc_args[i] - 90 + 8)
<< ATTR_FGSHIFT);
break;
case 39: /* default-foreground */
term->curr_truecolour.fg.enabled = false;
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |= ATTR_DEFFG;
break;
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
/* background */
term->curr_truecolour.bg.enabled = false;
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |=
(term->esc_args[i] - 40)<<ATTR_BGSHIFT;
break;
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
/* aixterm-style bright background */
term->curr_truecolour.bg.enabled = false;
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |=
((term->esc_args[i] - 100 + 8)
<< ATTR_BGSHIFT);
break;
case 49: /* default-background */
term->curr_truecolour.bg.enabled = false;
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |= ATTR_DEFBG;
break;
/*
* 256-colour and true-colour
* sequences. A 256-colour
* foreground is selected by a
* sequence of 3 arguments in the
* form 38;5;n, where n is in the
* range 0-255. A true-colour RGB
* triple is selected by 5 args of
* the form 38;2;r;g;b. Replacing
* the initial 38 with 48 in both
* cases selects the same colour
* as the background.
*/
case 38:
if (i+2 < term->esc_nargs &&
term->esc_args[i+1] == 5) {
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |=
((term->esc_args[i+2] & 0xFF)
<< ATTR_FGSHIFT);
term->curr_truecolour.fg =
optionalrgb_none;
i += 2;
}
if (i + 4 < term->esc_nargs &&
term->esc_args[i + 1] == 2) {
parse_optionalrgb(
&term->curr_truecolour.fg,
term->esc_args + (i+2));
i += 4;
}
break;
case 48:
if (i+2 < term->esc_nargs &&
term->esc_args[i+1] == 5) {
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |=
((term->esc_args[i+2] & 0xFF)
<< ATTR_BGSHIFT);
term->curr_truecolour.bg =
optionalrgb_none;
i += 2;
}
if (i + 4 < term->esc_nargs &&
term->esc_args[i+1] == 2) {
parse_optionalrgb(
&term->curr_truecolour.bg,
term->esc_args + (i+2));
i += 4;
}
break;
}
}
set_erase_char(term);
/*
* 256-colour and true-colour
* sequences. A 256-colour
* foreground is selected by a
* sequence of 3 arguments in the
* form 38;5;n, where n is in the
* range 0-255. A true-colour RGB
* triple is selected by 5 args of
* the form 38;2;r;g;b. Replacing
* the initial 38 with 48 in both
* cases selects the same colour
* as the background.
*/
case 38:
if (i+2 < term->esc_nargs &&
term->esc_args[i+1] == 5) {
term->curr_attr &= ~ATTR_FGMASK;
term->curr_attr |=
((term->esc_args[i+2] & 0xFF)
<< ATTR_FGSHIFT);
term->curr_truecolour.fg =
optionalrgb_none;
i += 2;
}
if (i + 4 < term->esc_nargs &&
term->esc_args[i + 1] == 2) {
parse_optionalrgb(
&term->curr_truecolour.fg,
term->esc_args + (i+2));
i += 4;
}
break;
case 48:
if (i+2 < term->esc_nargs &&
term->esc_args[i+1] == 5) {
term->curr_attr &= ~ATTR_BGMASK;
term->curr_attr |=
((term->esc_args[i+2] & 0xFF)
<< ATTR_BGSHIFT);
term->curr_truecolour.bg =
optionalrgb_none;
i += 2;
}
if (i + 4 < term->esc_nargs &&
term->esc_args[i+1] == 2) {
parse_optionalrgb(
&term->curr_truecolour.bg,
term->esc_args + (i+2));
i += 4;
}
break;
}
}
set_erase_char(term);
break;
case 's': /* save cursor */
save_cursor(term, true);
@ -4504,31 +4486,30 @@ static void term_out(Terminal *term)
deselect(term);
}
break;
case 'X': /* ECH: write N spaces w/o moving cursor */
case 'X': { /* ECH: write N spaces w/o moving cursor */
/* XXX VTTEST says this is vt220, vt510 manual
* says vt100 */
compatibility(ANSIMIN);
CLAMP(term->esc_args[0], term->cols);
{
int n = def(term->esc_args[0], 1);
pos cursplus;
int p = term->curs.x;
termline *cline = scrlineptr(term->curs.y);
int n = def(term->esc_args[0], 1);
pos cursplus;
int p = term->curs.x;
termline *cline = scrlineptr(term->curs.y);
check_trust_status(term, cline);
if (n > term->cols - term->curs.x)
n = term->cols - term->curs.x;
cursplus = term->curs;
cursplus.x += n;
check_boundary(term, term->curs.x, term->curs.y);
check_boundary(term, term->curs.x+n, term->curs.y);
check_selection(term, term->curs, cursplus);
while (n--)
copy_termchar(cline, p++,
&term->erase_char);
seen_disp_event(term);
}
check_trust_status(term, cline);
if (n > term->cols - term->curs.x)
n = term->cols - term->curs.x;
cursplus = term->curs;
cursplus.x += n;
check_boundary(term, term->curs.x, term->curs.y);
check_boundary(term, term->curs.x+n, term->curs.y);
check_selection(term, term->curs, cursplus);
while (n--)
copy_termchar(cline, p++,
&term->erase_char);
seen_disp_event(term);
break;
}
case 'x': /* DECREQTPARM: report terminal characteristics */
compatibility(VT100);
if (term->ldisc) {
@ -4541,22 +4522,21 @@ static void term_out(Terminal *term)
}
}
break;
case 'Z': /* CBT */
case 'Z': { /* CBT */
compatibility(OTHER);
CLAMP(term->esc_args[0], term->cols);
{
int i = def(term->esc_args[0], 1);
pos old_curs = term->curs;
int i = def(term->esc_args[0], 1);
pos old_curs = term->curs;
for(;i>0 && term->curs.x>0; i--) {
do {
term->curs.x--;
} while (term->curs.x >0 &&
!term->tabs[term->curs.x]);
}
check_selection(term, old_curs, term->curs);
for(;i>0 && term->curs.x>0; i--) {
do {
term->curs.x--;
} while (term->curs.x >0 &&
!term->tabs[term->curs.x]);
}
check_selection(term, old_curs, term->curs);
break;
}
case ANSI('c', '='): /* Hide or Show Cursor */
compatibility(SCOANSI);
switch(term->esc_args[0]) {
@ -4808,32 +4788,31 @@ static void term_out(Terminal *term)
else if (term->osc_strlen < OSC_STR_MAX)
term->osc_string[term->osc_strlen++] = (char)c;
break;
case SEEN_OSC_P:
{
int max = (term->osc_strlen == 0 ? 21 : 15);
int val;
if ((int)c >= '0' && (int)c <= '9')
val = c - '0';
else if ((int)c >= 'A' && (int)c <= 'A' + max - 10)
val = c - 'A' + 10;
else if ((int)c >= 'a' && (int)c <= 'a' + max - 10)
val = c - 'a' + 10;
else {
term->termstate = TOPLEVEL;
break;
}
term->osc_string[term->osc_strlen++] = val;
if (term->osc_strlen >= 7) {
win_palette_set(
term->win, term->osc_string[0],
term->osc_string[1] * 16 + term->osc_string[2],
term->osc_string[3] * 16 + term->osc_string[4],
term->osc_string[5] * 16 + term->osc_string[6]);
term_invalidate(term);
term->termstate = TOPLEVEL;
}
case SEEN_OSC_P: {
int max = (term->osc_strlen == 0 ? 21 : 15);
int val;
if ((int)c >= '0' && (int)c <= '9')
val = c - '0';
else if ((int)c >= 'A' && (int)c <= 'A' + max - 10)
val = c - 'A' + 10;
else if ((int)c >= 'a' && (int)c <= 'a' + max - 10)
val = c - 'a' + 10;
else {
term->termstate = TOPLEVEL;
break;
}
term->osc_string[term->osc_strlen++] = val;
if (term->osc_strlen >= 7) {
win_palette_set(
term->win, term->osc_string[0],
term->osc_string[1] * 16 + term->osc_string[2],
term->osc_string[3] * 16 + term->osc_string[4],
term->osc_string[5] * 16 + term->osc_string[6]);
term_invalidate(term);
term->termstate = TOPLEVEL;
}
break;
}
case SEEN_OSC_W:
switch (c) {
case '0':

Просмотреть файл

@ -422,30 +422,29 @@ static dr_emit_flags_t instrument_instr(
case OP_rol:
case OP_ror:
case OP_rcl:
case OP_rcr:
case OP_rcr: {
/*
* Shift instructions. If they're register-controlled, log the
* shift count.
*/
{
opnd_t shiftcount = instr_get_src(instr, 0);
if (!opnd_is_immed(shiftcount)) {
reg_id_t r0;
drreg_status_t st;
st = drreg_reserve_register(drcontext, bb, instr, NULL, &r0);
DR_ASSERT(st == DRREG_SUCCESS);
opnd_t op_r0 = opnd_create_reg(r0);
instrlist_preinsert(bb, instr, INSTR_CREATE_movzx(
drcontext, op_r0, shiftcount));
instr_format_location(instr, &loc);
dr_insert_clean_call(
drcontext, bb, instr, (void *)log_var_shift, false,
2, op_r0, OPND_CREATE_INTPTR(loc));
st = drreg_unreserve_register(drcontext, bb, instr, r0);
DR_ASSERT(st == DRREG_SUCCESS);
}
opnd_t shiftcount = instr_get_src(instr, 0);
if (!opnd_is_immed(shiftcount)) {
reg_id_t r0;
drreg_status_t st;
st = drreg_reserve_register(drcontext, bb, instr, NULL, &r0);
DR_ASSERT(st == DRREG_SUCCESS);
opnd_t op_r0 = opnd_create_reg(r0);
instrlist_preinsert(bb, instr, INSTR_CREATE_movzx(
drcontext, op_r0, shiftcount));
instr_format_location(instr, &loc);
dr_insert_clean_call(
drcontext, bb, instr, (void *)log_var_shift, false,
2, op_r0, OPND_CREATE_INTPTR(loc));
st = drreg_unreserve_register(drcontext, bb, instr, r0);
DR_ASSERT(st == DRREG_SUCCESS);
}
break;
}
}
return DR_EMIT_DEFAULT;

Просмотреть файл

@ -974,14 +974,11 @@ void dlg_set_focus(union control *ctrl, dlgparam *dp)
* Radio buttons: we find the currently selected button and
* focus it.
*/
{
int i;
for (i = 0; i < ctrl->radio.nbuttons; i++)
if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON(uc->buttons[i]))) {
gtk_widget_grab_focus(uc->buttons[i]);
}
}
for (int i = 0; i < ctrl->radio.nbuttons; i++)
if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON(uc->buttons[i]))) {
gtk_widget_grab_focus(uc->buttons[i]);
}
break;
case CTRL_LISTBOX:
#if !GTK_CHECK_VERSION(2,4,0)
@ -1885,21 +1882,19 @@ GtkWidget *layout_ctrls(
GtkWidget *w = NULL;
switch (ctrl->generic.type) {
case CTRL_COLUMNS:
{
static const int simplecols[1] = { 100 };
columns_set_cols(cols, ctrl->columns.ncols,
(ctrl->columns.percentages ?
ctrl->columns.percentages : simplecols));
}
case CTRL_COLUMNS: {
static const int simplecols[1] = { 100 };
columns_set_cols(cols, ctrl->columns.ncols,
(ctrl->columns.percentages ?
ctrl->columns.percentages : simplecols));
continue; /* no actual control created */
case CTRL_TABDELAY:
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl->tabdelay.ctrl);
if (uc)
columns_taborder_last(cols, uc->toplevel);
}
}
case CTRL_TABDELAY: {
struct uctrl *uc = dlg_find_byctrl(dp, ctrl->tabdelay.ctrl);
if (uc)
columns_taborder_last(cols, uc->toplevel);
continue; /* no actual control created */
}
}
uc = snew(struct uctrl);
@ -1947,223 +1942,220 @@ GtkWidget *layout_ctrls(
ctrl->checkbox.shortcut, SHORTCUT_UCTRL, uc);
left = true;
break;
case CTRL_RADIO:
case CTRL_RADIO: {
/*
* Radio buttons get to go inside their own Columns, no
* matter what.
*/
{
gint i, *percentages;
GSList *group;
gint i, *percentages;
GSList *group;
w = columns_new(0);
if (ctrl->generic.label) {
GtkWidget *label = gtk_label_new(ctrl->generic.label);
columns_add(COLUMNS(w), label, 0, 1);
columns_force_left_align(COLUMNS(w), label);
gtk_widget_show(label);
shortcut_add(scs, label, ctrl->radio.shortcut,
SHORTCUT_UCTRL, uc);
uc->label = label;
}
percentages = g_new(gint, ctrl->radio.ncolumns);
for (i = 0; i < ctrl->radio.ncolumns; i++) {
percentages[i] =
((100 * (i+1) / ctrl->radio.ncolumns) -
100 * i / ctrl->radio.ncolumns);
}
columns_set_cols(COLUMNS(w), ctrl->radio.ncolumns,
percentages);
g_free(percentages);
group = NULL;
w = columns_new(0);
if (ctrl->generic.label) {
GtkWidget *label = gtk_label_new(ctrl->generic.label);
columns_add(COLUMNS(w), label, 0, 1);
columns_force_left_align(COLUMNS(w), label);
gtk_widget_show(label);
shortcut_add(scs, label, ctrl->radio.shortcut,
SHORTCUT_UCTRL, uc);
uc->label = label;
}
percentages = g_new(gint, ctrl->radio.ncolumns);
for (i = 0; i < ctrl->radio.ncolumns; i++) {
percentages[i] =
((100 * (i+1) / ctrl->radio.ncolumns) -
100 * i / ctrl->radio.ncolumns);
}
columns_set_cols(COLUMNS(w), ctrl->radio.ncolumns,
percentages);
g_free(percentages);
group = NULL;
uc->nbuttons = ctrl->radio.nbuttons;
uc->buttons = snewn(uc->nbuttons, GtkWidget *);
uc->nbuttons = ctrl->radio.nbuttons;
uc->buttons = snewn(uc->nbuttons, GtkWidget *);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
GtkWidget *b;
gint colstart;
for (i = 0; i < ctrl->radio.nbuttons; i++) {
GtkWidget *b;
gint colstart;
b = (gtk_radio_button_new_with_label
(group, ctrl->radio.buttons[i]));
uc->buttons[i] = b;
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(b));
colstart = i % ctrl->radio.ncolumns;
columns_add(COLUMNS(w), b, colstart,
(i == ctrl->radio.nbuttons-1 ?
ctrl->radio.ncolumns - colstart : 1));
columns_force_left_align(COLUMNS(w), b);
gtk_widget_show(b);
g_signal_connect(G_OBJECT(b), "toggled",
G_CALLBACK(button_toggled), dp);
g_signal_connect(G_OBJECT(b), "focus_in_event",
G_CALLBACK(widget_focus), dp);
if (ctrl->radio.shortcuts) {
shortcut_add(scs, gtk_bin_get_child(GTK_BIN(b)),
ctrl->radio.shortcuts[i],
SHORTCUT_UCTRL, uc);
}
}
b = (gtk_radio_button_new_with_label
(group, ctrl->radio.buttons[i]));
uc->buttons[i] = b;
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(b));
colstart = i % ctrl->radio.ncolumns;
columns_add(COLUMNS(w), b, colstart,
(i == ctrl->radio.nbuttons-1 ?
ctrl->radio.ncolumns - colstart : 1));
columns_force_left_align(COLUMNS(w), b);
gtk_widget_show(b);
g_signal_connect(G_OBJECT(b), "toggled",
G_CALLBACK(button_toggled), dp);
g_signal_connect(G_OBJECT(b), "focus_in_event",
G_CALLBACK(widget_focus), dp);
if (ctrl->radio.shortcuts) {
shortcut_add(scs, gtk_bin_get_child(GTK_BIN(b)),
ctrl->radio.shortcuts[i],
SHORTCUT_UCTRL, uc);
}
}
break;
case CTRL_EDITBOX:
{
GtkWidget *signalobject;
}
case CTRL_EDITBOX: {
GtkWidget *signalobject;
if (ctrl->editbox.has_list) {
if (ctrl->editbox.has_list) {
#if !GTK_CHECK_VERSION(2,4,0)
/*
* GTK 1 combo box.
*/
w = gtk_combo_new();
gtk_combo_set_value_in_list(GTK_COMBO(w), false, true);
uc->entry = GTK_COMBO(w)->entry;
uc->list = GTK_COMBO(w)->list;
signalobject = uc->entry;
/*
* GTK 1 combo box.
*/
w = gtk_combo_new();
gtk_combo_set_value_in_list(GTK_COMBO(w), false, true);
uc->entry = GTK_COMBO(w)->entry;
uc->list = GTK_COMBO(w)->list;
signalobject = uc->entry;
#else
/*
* GTK 2 combo box.
*/
uc->listmodel = gtk_list_store_new(2, G_TYPE_INT,
G_TYPE_STRING);
w = gtk_combo_box_new_with_model_and_entry
(GTK_TREE_MODEL(uc->listmodel));
g_object_set(G_OBJECT(w), "entry-text-column", 1,
(const char *)NULL);
/* We cannot support password combo boxes. */
assert(!ctrl->editbox.password);
uc->combo = w;
signalobject = uc->combo;
/*
* GTK 2 combo box.
*/
uc->listmodel = gtk_list_store_new(2, G_TYPE_INT,
G_TYPE_STRING);
w = gtk_combo_box_new_with_model_and_entry
(GTK_TREE_MODEL(uc->listmodel));
g_object_set(G_OBJECT(w), "entry-text-column", 1,
(const char *)NULL);
/* We cannot support password combo boxes. */
assert(!ctrl->editbox.password);
uc->combo = w;
signalobject = uc->combo;
#endif
} else {
w = gtk_entry_new();
if (ctrl->editbox.password)
gtk_entry_set_visibility(GTK_ENTRY(w), false);
uc->entry = w;
signalobject = w;
}
uc->entrysig =
g_signal_connect(G_OBJECT(signalobject), "changed",
G_CALLBACK(editbox_changed), dp);
g_signal_connect(G_OBJECT(signalobject), "key_press_event",
G_CALLBACK(editbox_key), dp);
g_signal_connect(G_OBJECT(signalobject), "focus_in_event",
G_CALLBACK(widget_focus), dp);
g_signal_connect(G_OBJECT(signalobject), "focus_out_event",
G_CALLBACK(editbox_lostfocus), dp);
g_signal_connect(G_OBJECT(signalobject), "focus_out_event",
G_CALLBACK(editbox_lostfocus), dp);
} else {
w = gtk_entry_new();
if (ctrl->editbox.password)
gtk_entry_set_visibility(GTK_ENTRY(w), false);
uc->entry = w;
signalobject = w;
}
uc->entrysig =
g_signal_connect(G_OBJECT(signalobject), "changed",
G_CALLBACK(editbox_changed), dp);
g_signal_connect(G_OBJECT(signalobject), "key_press_event",
G_CALLBACK(editbox_key), dp);
g_signal_connect(G_OBJECT(signalobject), "focus_in_event",
G_CALLBACK(widget_focus), dp);
g_signal_connect(G_OBJECT(signalobject), "focus_out_event",
G_CALLBACK(editbox_lostfocus), dp);
g_signal_connect(G_OBJECT(signalobject), "focus_out_event",
G_CALLBACK(editbox_lostfocus), dp);
#if !GTK_CHECK_VERSION(3,0,0)
/*
* Edit boxes, for some strange reason, have a minimum
* width of 150 in GTK 1.2. We don't want this - we'd
* rather the edit boxes acquired their natural width
* from the column layout of the rest of the box.
*/
{
GtkRequisition req;
gtk_widget_size_request(w, &req);
gtk_widget_set_size_request(w, 10, req.height);
}
#else
/*
* In GTK 3, this is still true, but there's a special
* method for GtkEntry in particular to fix it.
*/
if (GTK_IS_ENTRY(w))
gtk_entry_set_width_chars(GTK_ENTRY(w), 1);
#endif
if (ctrl->generic.label) {
GtkWidget *label, *container;
label = gtk_label_new(ctrl->generic.label);
shortcut_add(scs, label, ctrl->editbox.shortcut,
SHORTCUT_FOCUS, uc->entry);
container = columns_new(4);
if (ctrl->editbox.percentwidth == 100) {
columns_add(COLUMNS(container), label, 0, 1);
columns_force_left_align(COLUMNS(container), label);
columns_add(COLUMNS(container), w, 0, 1);
} else {
gint percentages[2];
percentages[1] = ctrl->editbox.percentwidth;
percentages[0] = 100 - ctrl->editbox.percentwidth;
columns_set_cols(COLUMNS(container), 2, percentages);
columns_add(COLUMNS(container), label, 0, 1);
columns_force_left_align(COLUMNS(container), label);
columns_add(COLUMNS(container), w, 1, 1);
columns_force_same_height(COLUMNS(container),
label, w);
}
gtk_widget_show(label);
gtk_widget_show(w);
w = container;
uc->label = label;
}
}
break;
case CTRL_FILESELECT:
case CTRL_FONTSELECT:
/*
* Edit boxes, for some strange reason, have a minimum
* width of 150 in GTK 1.2. We don't want this - we'd
* rather the edit boxes acquired their natural width
* from the column layout of the rest of the box.
*/
{
GtkWidget *ww;
const char *browsebtn =
(ctrl->generic.type == CTRL_FILESELECT ?
"Browse..." : "Change...");
gint percentages[] = { 75, 25 };
w = columns_new(4);
columns_set_cols(COLUMNS(w), 2, percentages);
if (ctrl->generic.label) {
ww = gtk_label_new(ctrl->generic.label);
columns_add(COLUMNS(w), ww, 0, 2);
columns_force_left_align(COLUMNS(w), ww);
gtk_widget_show(ww);
shortcut_add(scs, ww,
(ctrl->generic.type == CTRL_FILESELECT ?
ctrl->fileselect.shortcut :
ctrl->fontselect.shortcut),
SHORTCUT_UCTRL, uc);
uc->label = ww;
}
uc->entry = ww = gtk_entry_new();
#if !GTK_CHECK_VERSION(3,0,0)
{
GtkRequisition req;
gtk_widget_size_request(ww, &req);
gtk_widget_set_size_request(ww, 10, req.height);
}
GtkRequisition req;
gtk_widget_size_request(w, &req);
gtk_widget_set_size_request(w, 10, req.height);
}
#else
gtk_entry_set_width_chars(GTK_ENTRY(ww), 1);
/*
* In GTK 3, this is still true, but there's a special
* method for GtkEntry in particular to fix it.
*/
if (GTK_IS_ENTRY(w))
gtk_entry_set_width_chars(GTK_ENTRY(w), 1);
#endif
columns_add(COLUMNS(w), ww, 0, 1);
gtk_widget_show(ww);
uc->button = ww = gtk_button_new_with_label(browsebtn);
columns_add(COLUMNS(w), ww, 1, 1);
gtk_widget_show(ww);
if (ctrl->generic.label) {
GtkWidget *label, *container;
columns_force_same_height(COLUMNS(w), uc->entry, uc->button);
label = gtk_label_new(ctrl->generic.label);
g_signal_connect(G_OBJECT(uc->entry), "key_press_event",
G_CALLBACK(editbox_key), dp);
uc->entrysig =
g_signal_connect(G_OBJECT(uc->entry), "changed",
G_CALLBACK(editbox_changed), dp);
g_signal_connect(G_OBJECT(uc->entry), "focus_in_event",
G_CALLBACK(widget_focus), dp);
g_signal_connect(G_OBJECT(uc->button), "focus_in_event",
G_CALLBACK(widget_focus), dp);
g_signal_connect(G_OBJECT(ww), "clicked",
G_CALLBACK(filefont_clicked), dp);
shortcut_add(scs, label, ctrl->editbox.shortcut,
SHORTCUT_FOCUS, uc->entry);
container = columns_new(4);
if (ctrl->editbox.percentwidth == 100) {
columns_add(COLUMNS(container), label, 0, 1);
columns_force_left_align(COLUMNS(container), label);
columns_add(COLUMNS(container), w, 0, 1);
} else {
gint percentages[2];
percentages[1] = ctrl->editbox.percentwidth;
percentages[0] = 100 - ctrl->editbox.percentwidth;
columns_set_cols(COLUMNS(container), 2, percentages);
columns_add(COLUMNS(container), label, 0, 1);
columns_force_left_align(COLUMNS(container), label);
columns_add(COLUMNS(container), w, 1, 1);
columns_force_same_height(COLUMNS(container),
label, w);
}
gtk_widget_show(label);
gtk_widget_show(w);
w = container;
uc->label = label;
}
break;
}
case CTRL_FILESELECT:
case CTRL_FONTSELECT: {
GtkWidget *ww;
const char *browsebtn =
(ctrl->generic.type == CTRL_FILESELECT ?
"Browse..." : "Change...");
gint percentages[] = { 75, 25 };
w = columns_new(4);
columns_set_cols(COLUMNS(w), 2, percentages);
if (ctrl->generic.label) {
ww = gtk_label_new(ctrl->generic.label);
columns_add(COLUMNS(w), ww, 0, 2);
columns_force_left_align(COLUMNS(w), ww);
gtk_widget_show(ww);
shortcut_add(scs, ww,
(ctrl->generic.type == CTRL_FILESELECT ?
ctrl->fileselect.shortcut :
ctrl->fontselect.shortcut),
SHORTCUT_UCTRL, uc);
uc->label = ww;
}
uc->entry = ww = gtk_entry_new();
#if !GTK_CHECK_VERSION(3,0,0)
{
GtkRequisition req;
gtk_widget_size_request(ww, &req);
gtk_widget_set_size_request(ww, 10, req.height);
}
#else
gtk_entry_set_width_chars(GTK_ENTRY(ww), 1);
#endif
columns_add(COLUMNS(w), ww, 0, 1);
gtk_widget_show(ww);
uc->button = ww = gtk_button_new_with_label(browsebtn);
columns_add(COLUMNS(w), ww, 1, 1);
gtk_widget_show(ww);
columns_force_same_height(COLUMNS(w), uc->entry, uc->button);
g_signal_connect(G_OBJECT(uc->entry), "key_press_event",
G_CALLBACK(editbox_key), dp);
uc->entrysig =
g_signal_connect(G_OBJECT(uc->entry), "changed",
G_CALLBACK(editbox_changed), dp);
g_signal_connect(G_OBJECT(uc->entry), "focus_in_event",
G_CALLBACK(widget_focus), dp);
g_signal_connect(G_OBJECT(uc->button), "focus_in_event",
G_CALLBACK(widget_focus), dp);
g_signal_connect(G_OBJECT(ww), "clicked",
G_CALLBACK(filefont_clicked), dp);
break;
}
case CTRL_LISTBOX:
#if GTK_CHECK_VERSION(2,0,0)

Просмотреть файл

@ -5044,17 +5044,16 @@ static void gtk_seat_update_specials_menu(Seat *seat)
case SS_SEP:
menuitem = gtk_menu_item_new();
break;
default:
default: {
menuitem = gtk_menu_item_new_with_label(specials[i].name);
{
SessionSpecial *sc = snew(SessionSpecial);
*sc = specials[i]; /* structure copy */
g_object_set_data_full(G_OBJECT(menuitem), "user-data",
sc, free_special_cmd);
}
SessionSpecial *sc = snew(SessionSpecial);
*sc = specials[i]; /* structure copy */
g_object_set_data_full(G_OBJECT(menuitem), "user-data",
sc, free_special_cmd);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(special_menuitem), inst);
break;
}
}
if (menuitem) {
gtk_container_add(GTK_CONTAINER(menu), menuitem);

Просмотреть файл

@ -22,44 +22,43 @@ static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
case WM_ERASEBKGND:
return true;
case WM_PAINT:
{
HBRUSH hbr;
HGDIOBJ holdbr;
RECT cr;
int wtlen;
LPTSTR wt;
HDC hdc;
case WM_PAINT: {
HBRUSH hbr;
HGDIOBJ holdbr;
RECT cr;
int wtlen;
LPTSTR wt;
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
SelectObject(hdc, tip_font);
SelectObject(hdc, GetStockObject(BLACK_PEN));
SelectObject(hdc, tip_font);
SelectObject(hdc, GetStockObject(BLACK_PEN));
hbr = CreateSolidBrush(tip_bg);
holdbr = SelectObject(hdc, hbr);
hbr = CreateSolidBrush(tip_bg);
holdbr = SelectObject(hdc, hbr);
GetClientRect(hWnd, &cr);
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
GetClientRect(hWnd, &cr);
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
wtlen = GetWindowTextLength(hWnd);
wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
GetWindowText(hWnd, wt, wtlen + 1);
wtlen = GetWindowTextLength(hWnd);
wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
GetWindowText(hWnd, wt, wtlen + 1);
SetTextColor(hdc, tip_text);
SetBkColor(hdc, tip_bg);
SetTextColor(hdc, tip_text);
SetBkColor(hdc, tip_bg);
TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
sfree(wt);
sfree(wt);
SelectObject(hdc, holdbr);
DeleteObject(hbr);
SelectObject(hdc, holdbr);
DeleteObject(hbr);
EndPaint(hWnd, &ps);
}
EndPaint(hWnd, &ps);
return 0;
}
case WM_NCHITTEST:
return HTTRANSPARENT;
@ -69,22 +68,21 @@ static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
tip_font = NULL;
break;
case WM_SETTEXT:
{
LPCTSTR str = (LPCTSTR) lParam;
SIZE sz;
HDC hdc = CreateCompatibleDC(NULL);
case WM_SETTEXT: {
LPCTSTR str = (LPCTSTR) lParam;
SIZE sz;
HDC hdc = CreateCompatibleDC(NULL);
SelectObject(hdc, tip_font);
GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
SelectObject(hdc, tip_font);
GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
InvalidateRect(hWnd, NULL, false);
SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
InvalidateRect(hWnd, NULL, false);
DeleteDC(hdc);
}
DeleteDC(hdc);
break;
}
}
return DefWindowProc(hWnd, nMsg, wParam, lParam);

Просмотреть файл

@ -925,20 +925,18 @@ void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
wid = xpos - left;
switch (i) {
case 1:
case 1: {
/* The drag list box. */
r.left = left; r.right = wid;
r.top = cp->ypos; r.bottom = listheight;
{
HWND ctl;
ctl = doctl(cp, r, "LISTBOX",
WS_CHILD | WS_VISIBLE | WS_TABSTOP |
WS_VSCROLL | LBS_HASSTRINGS | LBS_USETABSTOPS,
WS_EX_CLIENTEDGE,
"", listid);
p_MakeDragList(ctl);
}
HWND ctl = doctl(cp, r, "LISTBOX",
WS_CHILD | WS_VISIBLE | WS_TABSTOP |
WS_VSCROLL | LBS_HASSTRINGS | LBS_USETABSTOPS,
WS_EX_CLIENTEDGE,
"", listid);
p_MakeDragList(ctl);
break;
}
case 2:
/* The "Up" and "Down" buttons. */
@ -1496,19 +1494,18 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
* switching on its type.
*/
switch (ctrl->generic.type) {
case CTRL_TEXT:
{
char *wrapped, *escaped;
int lines;
num_ids = 1;
wrapped = staticwrap(&pos, cp->hwnd,
ctrl->generic.label, &lines);
escaped = shortcut_escape(wrapped, NO_SHORTCUT);
statictext(&pos, escaped, lines, base_id);
sfree(escaped);
sfree(wrapped);
}
case CTRL_TEXT: {
char *wrapped, *escaped;
int lines;
num_ids = 1;
wrapped = staticwrap(&pos, cp->hwnd,
ctrl->generic.label, &lines);
escaped = shortcut_escape(wrapped, NO_SHORTCUT);
statictext(&pos, escaped, lines, base_id);
sfree(escaped);
sfree(wrapped);
break;
}
case CTRL_EDITBOX:
num_ids = 2; /* static, edit */
escaped = shortcut_escape(ctrl->editbox.label,
@ -1533,42 +1530,41 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
}
sfree(escaped);
break;
case CTRL_RADIO:
case CTRL_RADIO: {
num_ids = ctrl->radio.nbuttons + 1; /* label as well */
{
struct radio *buttons;
int i;
struct radio *buttons;
int i;
escaped = shortcut_escape(ctrl->radio.label,
ctrl->radio.shortcut);
shortcuts[nshortcuts++] = ctrl->radio.shortcut;
escaped = shortcut_escape(ctrl->radio.label,
ctrl->radio.shortcut);
shortcuts[nshortcuts++] = ctrl->radio.shortcut;
buttons = snewn(ctrl->radio.nbuttons, struct radio);
buttons = snewn(ctrl->radio.nbuttons, struct radio);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
buttons[i].text =
shortcut_escape(ctrl->radio.buttons[i],
(char)(ctrl->radio.shortcuts ?
ctrl->radio.shortcuts[i] :
NO_SHORTCUT));
buttons[i].id = base_id + 1 + i;
if (ctrl->radio.shortcuts) {
assert(nshortcuts < MAX_SHORTCUTS_PER_CTRL);
shortcuts[nshortcuts++] = ctrl->radio.shortcuts[i];
}
}
radioline_common(&pos, escaped, base_id,
ctrl->radio.ncolumns,
buttons, ctrl->radio.nbuttons);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
sfree(buttons[i].text);
}
sfree(buttons);
sfree(escaped);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
buttons[i].text =
shortcut_escape(ctrl->radio.buttons[i],
(char)(ctrl->radio.shortcuts ?
ctrl->radio.shortcuts[i] :
NO_SHORTCUT));
buttons[i].id = base_id + 1 + i;
if (ctrl->radio.shortcuts) {
assert(nshortcuts < MAX_SHORTCUTS_PER_CTRL);
shortcuts[nshortcuts++] = ctrl->radio.shortcuts[i];
}
}
radioline_common(&pos, escaped, base_id,
ctrl->radio.ncolumns,
buttons, ctrl->radio.nbuttons);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
sfree(buttons[i].text);
}
sfree(buttons);
sfree(escaped);
break;
}
case CTRL_CHECKBOX:
num_ids = 1;
escaped = shortcut_escape(ctrl->checkbox.label,

Просмотреть файл

@ -88,17 +88,15 @@ static INT_PTR CALLBACK LogProc(HWND hwnd, UINT msg,
int i;
switch (msg) {
case WM_INITDIALOG:
{
char *str = dupprintf("%s Event Log", appname);
SetWindowText(hwnd, str);
sfree(str);
}
{
static int tabs[4] = { 78, 108 };
SendDlgItemMessage(hwnd, IDN_LIST, LB_SETTABSTOPS, 2,
(LPARAM) tabs);
}
case WM_INITDIALOG: {
char *str = dupprintf("%s Event Log", appname);
SetWindowText(hwnd, str);
sfree(str);
static int tabs[4] = { 78, 108 };
SendDlgItemMessage(hwnd, IDN_LIST, LB_SETTABSTOPS, 2,
(LPARAM) tabs);
for (i = 0; i < ninitial; i++)
SendDlgItemMessage(hwnd, IDN_LIST, LB_ADDSTRING,
0, (LPARAM) events_initial[i]);
@ -106,6 +104,7 @@ static INT_PTR CALLBACK LogProc(HWND hwnd, UINT msg,
SendDlgItemMessage(hwnd, IDN_LIST, LB_ADDSTRING,
0, (LPARAM) events_circular[(circular_first + i) % LOGEVENT_CIRCULAR_MAX]);
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
@ -184,14 +183,13 @@ static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
{
char *str = dupprintf("%s Licence", appname);
SetWindowText(hwnd, str);
sfree(str);
SetDlgItemText(hwnd, IDA_TEXT, LICENCE_TEXT("\r\n\r\n"));
}
case WM_INITDIALOG: {
char *str = dupprintf("%s Licence", appname);
SetWindowText(hwnd, str);
sfree(str);
SetDlgItemText(hwnd, IDA_TEXT, LICENCE_TEXT("\r\n\r\n"));
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
@ -213,21 +211,20 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg,
char *str;
switch (msg) {
case WM_INITDIALOG:
case WM_INITDIALOG: {
str = dupprintf("About %s", appname);
SetWindowText(hwnd, str);
sfree(str);
{
char *buildinfo_text = buildinfo("\r\n");
char *text = dupprintf
("%s\r\n\r\n%s\r\n\r\n%s\r\n\r\n%s",
appname, ver, buildinfo_text,
"\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved.");
sfree(buildinfo_text);
SetDlgItemText(hwnd, IDA_TEXT, text);
sfree(text);
}
char *buildinfo_text = buildinfo("\r\n");
char *text = dupprintf
("%s\r\n\r\n%s\r\n\r\n%s\r\n\r\n%s",
appname, ver, buildinfo_text,
"\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved.");
sfree(buildinfo_text);
SetDlgItemText(hwnd, IDA_TEXT, text);
sfree(text);
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:

Просмотреть файл

@ -2180,20 +2180,19 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
return 0;
case WM_CREATE:
break;
case WM_CLOSE:
{
char *str;
show_mouseptr(true);
str = dupprintf("%s Exit Confirmation", appname);
if (session_closed || !conf_get_bool(conf, CONF_warn_on_close) ||
MessageBox(hwnd,
"Are you sure you want to close this session?",
str, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1)
== IDOK)
DestroyWindow(hwnd);
sfree(str);
}
case WM_CLOSE: {
char *str;
show_mouseptr(true);
str = dupprintf("%s Exit Confirmation", appname);
if (session_closed || !conf_get_bool(conf, CONF_warn_on_close) ||
MessageBox(hwnd,
"Are you sure you want to close this session?",
str, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1)
== IDOK)
DestroyWindow(hwnd);
sfree(str);
return 0;
}
case WM_DESTROY:
show_mouseptr(true);
PostQuitMessage(0);
@ -2216,88 +2215,87 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break;
case IDM_NEWSESS:
case IDM_DUPSESS:
case IDM_SAVEDSESS:
{
char b[2048];
char *cl;
const char *argprefix;
bool inherit_handles;
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE filemap = NULL;
case IDM_SAVEDSESS: {
char b[2048];
char *cl;
const char *argprefix;
bool inherit_handles;
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE filemap = NULL;
if (restricted_acl())
argprefix = "&R";
else
argprefix = "";
if (restricted_acl())
argprefix = "&R";
else
argprefix = "";
if (wParam == IDM_DUPSESS) {
/*
* Allocate a file-mapping memory chunk for the
* config structure.
*/
SECURITY_ATTRIBUTES sa;
strbuf *serbuf;
void *p;
int size;
if (wParam == IDM_DUPSESS) {
/*
* Allocate a file-mapping memory chunk for the
* config structure.
*/
SECURITY_ATTRIBUTES sa;
strbuf *serbuf;
void *p;
int size;
serbuf = strbuf_new();
conf_serialise(BinarySink_UPCAST(serbuf), conf);
size = serbuf->len;
serbuf = strbuf_new();
conf_serialise(BinarySink_UPCAST(serbuf), conf);
size = serbuf->len;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
filemap = CreateFileMapping(INVALID_HANDLE_VALUE,
&sa,
PAGE_READWRITE,
0, size, NULL);
if (filemap && filemap != INVALID_HANDLE_VALUE) {
p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, size);
if (p) {
memcpy(p, serbuf->s, size);
UnmapViewOfFile(p);
}
}
strbuf_free(serbuf);
inherit_handles = true;
cl = dupprintf("putty %s&%p:%u", argprefix,
filemap, (unsigned)size);
} else if (wParam == IDM_SAVEDSESS) {
unsigned int sessno = ((lParam - IDM_SAVED_MIN)
/ MENU_SAVED_STEP) + 1;
if (sessno < (unsigned)sesslist.nsessions) {
const char *session = sesslist.sessions[sessno];
cl = dupprintf("putty %s@%s", argprefix, session);
inherit_handles = false;
} else
break;
} else /* IDM_NEWSESS */ {
cl = dupprintf("putty%s%s",
*argprefix ? " " : "",
argprefix);
inherit_handles = false;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
filemap = CreateFileMapping(INVALID_HANDLE_VALUE,
&sa,
PAGE_READWRITE,
0, size, NULL);
if (filemap && filemap != INVALID_HANDLE_VALUE) {
p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, size);
if (p) {
memcpy(p, serbuf->s, size);
UnmapViewOfFile(p);
}
}
GetModuleFileName(NULL, b, sizeof(b) - 1);
si.cb = sizeof(si);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
CreateProcess(b, cl, NULL, NULL, inherit_handles,
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if (filemap)
CloseHandle(filemap);
sfree(cl);
strbuf_free(serbuf);
inherit_handles = true;
cl = dupprintf("putty %s&%p:%u", argprefix,
filemap, (unsigned)size);
} else if (wParam == IDM_SAVEDSESS) {
unsigned int sessno = ((lParam - IDM_SAVED_MIN)
/ MENU_SAVED_STEP) + 1;
if (sessno < (unsigned)sesslist.nsessions) {
const char *session = sesslist.sessions[sessno];
cl = dupprintf("putty %s@%s", argprefix, session);
inherit_handles = false;
} else
break;
} else /* IDM_NEWSESS */ {
cl = dupprintf("putty%s%s",
*argprefix ? " " : "",
argprefix);
inherit_handles = false;
}
GetModuleFileName(NULL, b, sizeof(b) - 1);
si.cb = sizeof(si);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
CreateProcess(b, cl, NULL, NULL, inherit_handles,
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if (filemap)
CloseHandle(filemap);
sfree(cl);
break;
}
case IDM_RESTART:
if (!backend) {
lp_eventlog(&wgs.logpolicy, "----- Session restarted -----");
@ -2306,193 +2304,192 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
}
break;
case IDM_RECONF:
{
Conf *prev_conf;
int init_lvl = 1;
bool reconfig_result;
case IDM_RECONF: {
Conf *prev_conf;
int init_lvl = 1;
bool reconfig_result;
if (reconfiguring)
break;
else
reconfiguring = true;
if (reconfiguring)
break;
else
reconfiguring = true;
/*
* Copy the current window title into the stored
* previous configuration, so that doing nothing to
* the window title field in the config box doesn't
* reset the title to its startup state.
*/
conf_set_str(conf, CONF_wintitle, window_name);
/*
* Copy the current window title into the stored
* previous configuration, so that doing nothing to
* the window title field in the config box doesn't
* reset the title to its startup state.
*/
conf_set_str(conf, CONF_wintitle, window_name);
prev_conf = conf_copy(conf);
prev_conf = conf_copy(conf);
reconfig_result = do_reconfig(
hwnd, conf, backend ? backend_cfg_info(backend) : 0);
reconfiguring = false;
if (!reconfig_result) {
conf_free(prev_conf);
break;
}
conf_cache_data();
resize_action = conf_get_int(conf, CONF_resize_action);
{
/* Disable full-screen if resizing forbidden */
int i;
for (i = 0; i < lenof(popup_menus); i++)
EnableMenuItem(popup_menus[i].menu, IDM_FULLSCREEN,
MF_BYCOMMAND |
(resize_action == RESIZE_DISABLED
? MF_GRAYED : MF_ENABLED));
/* Gracefully unzoom if necessary */
if (IsZoomed(hwnd) && (resize_action == RESIZE_DISABLED))
ShowWindow(hwnd, SW_RESTORE);
}
/* Pass new config data to the logging module */
log_reconfig(logctx, conf);
sfree(logpal);
/*
* Flush the line discipline's edit buffer in the
* case where local editing has just been disabled.
*/
if (ldisc) {
ldisc_configure(ldisc, conf);
ldisc_echoedit_update(ldisc);
}
if (pal)
DeleteObject(pal);
logpal = NULL;
pal = NULL;
conftopalette();
init_palette();
/* Pass new config data to the terminal */
term_reconfig(term, conf);
setup_clipboards(term, conf);
/* Pass new config data to the back end */
if (backend)
backend_reconfig(backend, conf);
/* Screen size changed ? */
if (conf_get_int(conf, CONF_height) !=
conf_get_int(prev_conf, CONF_height) ||
conf_get_int(conf, CONF_width) !=
conf_get_int(prev_conf, CONF_width) ||
conf_get_int(conf, CONF_savelines) !=
conf_get_int(prev_conf, CONF_savelines) ||
resize_action == RESIZE_FONT ||
(resize_action == RESIZE_EITHER && IsZoomed(hwnd)) ||
resize_action == RESIZE_DISABLED)
term_size(term, conf_get_int(conf, CONF_height),
conf_get_int(conf, CONF_width),
conf_get_int(conf, CONF_savelines));
/* Enable or disable the scroll bar, etc */
{
LONG nflg, flag = GetWindowLongPtr(hwnd, GWL_STYLE);
LONG nexflag, exflag =
GetWindowLongPtr(hwnd, GWL_EXSTYLE);
nexflag = exflag;
if (conf_get_bool(conf, CONF_alwaysontop) !=
conf_get_bool(prev_conf, CONF_alwaysontop)) {
if (conf_get_bool(conf, CONF_alwaysontop)) {
nexflag |= WS_EX_TOPMOST;
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
} else {
nexflag &= ~(WS_EX_TOPMOST);
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
}
}
if (conf_get_bool(conf, CONF_sunken_edge))
nexflag |= WS_EX_CLIENTEDGE;
else
nexflag &= ~(WS_EX_CLIENTEDGE);
nflg = flag;
if (conf_get_bool(conf, is_full_screen() ?
CONF_scrollbar_in_fullscreen :
CONF_scrollbar))
nflg |= WS_VSCROLL;
else
nflg &= ~WS_VSCROLL;
if (resize_action == RESIZE_DISABLED ||
is_full_screen())
nflg &= ~WS_THICKFRAME;
else
nflg |= WS_THICKFRAME;
if (resize_action == RESIZE_DISABLED)
nflg &= ~WS_MAXIMIZEBOX;
else
nflg |= WS_MAXIMIZEBOX;
if (nflg != flag || nexflag != exflag) {
if (nflg != flag)
SetWindowLongPtr(hwnd, GWL_STYLE, nflg);
if (nexflag != exflag)
SetWindowLongPtr(hwnd, GWL_EXSTYLE, nexflag);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOCOPYBITS |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_FRAMECHANGED);
init_lvl = 2;
}
}
/* Oops */
if (resize_action == RESIZE_DISABLED && IsZoomed(hwnd)) {
force_normal(hwnd);
init_lvl = 2;
}
win_set_title(wintw, conf_get_str(conf, CONF_wintitle));
if (IsIconic(hwnd)) {
SetWindowText(hwnd,
conf_get_bool(conf, CONF_win_name_always) ?
window_name : icon_name);
}
{
FontSpec *font = conf_get_fontspec(conf, CONF_font);
FontSpec *prev_font = conf_get_fontspec(prev_conf,
CONF_font);
if (!strcmp(font->name, prev_font->name) ||
!strcmp(conf_get_str(conf, CONF_line_codepage),
conf_get_str(prev_conf, CONF_line_codepage)) ||
font->isbold != prev_font->isbold ||
font->height != prev_font->height ||
font->charset != prev_font->charset ||
conf_get_int(conf, CONF_font_quality) !=
conf_get_int(prev_conf, CONF_font_quality) ||
conf_get_int(conf, CONF_vtmode) !=
conf_get_int(prev_conf, CONF_vtmode) ||
conf_get_int(conf, CONF_bold_style) !=
conf_get_int(prev_conf, CONF_bold_style) ||
resize_action == RESIZE_DISABLED ||
resize_action == RESIZE_EITHER ||
resize_action != conf_get_int(prev_conf,
CONF_resize_action))
init_lvl = 2;
}
InvalidateRect(hwnd, NULL, true);
reset_window(init_lvl);
conf_free(prev_conf);
reconfig_result = do_reconfig(
hwnd, conf, backend ? backend_cfg_info(backend) : 0);
reconfiguring = false;
if (!reconfig_result) {
conf_free(prev_conf);
break;
}
conf_cache_data();
resize_action = conf_get_int(conf, CONF_resize_action);
{
/* Disable full-screen if resizing forbidden */
int i;
for (i = 0; i < lenof(popup_menus); i++)
EnableMenuItem(popup_menus[i].menu, IDM_FULLSCREEN,
MF_BYCOMMAND |
(resize_action == RESIZE_DISABLED
? MF_GRAYED : MF_ENABLED));
/* Gracefully unzoom if necessary */
if (IsZoomed(hwnd) && (resize_action == RESIZE_DISABLED))
ShowWindow(hwnd, SW_RESTORE);
}
/* Pass new config data to the logging module */
log_reconfig(logctx, conf);
sfree(logpal);
/*
* Flush the line discipline's edit buffer in the
* case where local editing has just been disabled.
*/
if (ldisc) {
ldisc_configure(ldisc, conf);
ldisc_echoedit_update(ldisc);
}
if (pal)
DeleteObject(pal);
logpal = NULL;
pal = NULL;
conftopalette();
init_palette();
/* Pass new config data to the terminal */
term_reconfig(term, conf);
setup_clipboards(term, conf);
/* Pass new config data to the back end */
if (backend)
backend_reconfig(backend, conf);
/* Screen size changed ? */
if (conf_get_int(conf, CONF_height) !=
conf_get_int(prev_conf, CONF_height) ||
conf_get_int(conf, CONF_width) !=
conf_get_int(prev_conf, CONF_width) ||
conf_get_int(conf, CONF_savelines) !=
conf_get_int(prev_conf, CONF_savelines) ||
resize_action == RESIZE_FONT ||
(resize_action == RESIZE_EITHER && IsZoomed(hwnd)) ||
resize_action == RESIZE_DISABLED)
term_size(term, conf_get_int(conf, CONF_height),
conf_get_int(conf, CONF_width),
conf_get_int(conf, CONF_savelines));
/* Enable or disable the scroll bar, etc */
{
LONG nflg, flag = GetWindowLongPtr(hwnd, GWL_STYLE);
LONG nexflag, exflag =
GetWindowLongPtr(hwnd, GWL_EXSTYLE);
nexflag = exflag;
if (conf_get_bool(conf, CONF_alwaysontop) !=
conf_get_bool(prev_conf, CONF_alwaysontop)) {
if (conf_get_bool(conf, CONF_alwaysontop)) {
nexflag |= WS_EX_TOPMOST;
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
} else {
nexflag &= ~(WS_EX_TOPMOST);
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
}
}
if (conf_get_bool(conf, CONF_sunken_edge))
nexflag |= WS_EX_CLIENTEDGE;
else
nexflag &= ~(WS_EX_CLIENTEDGE);
nflg = flag;
if (conf_get_bool(conf, is_full_screen() ?
CONF_scrollbar_in_fullscreen :
CONF_scrollbar))
nflg |= WS_VSCROLL;
else
nflg &= ~WS_VSCROLL;
if (resize_action == RESIZE_DISABLED ||
is_full_screen())
nflg &= ~WS_THICKFRAME;
else
nflg |= WS_THICKFRAME;
if (resize_action == RESIZE_DISABLED)
nflg &= ~WS_MAXIMIZEBOX;
else
nflg |= WS_MAXIMIZEBOX;
if (nflg != flag || nexflag != exflag) {
if (nflg != flag)
SetWindowLongPtr(hwnd, GWL_STYLE, nflg);
if (nexflag != exflag)
SetWindowLongPtr(hwnd, GWL_EXSTYLE, nexflag);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOCOPYBITS |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_FRAMECHANGED);
init_lvl = 2;
}
}
/* Oops */
if (resize_action == RESIZE_DISABLED && IsZoomed(hwnd)) {
force_normal(hwnd);
init_lvl = 2;
}
win_set_title(wintw, conf_get_str(conf, CONF_wintitle));
if (IsIconic(hwnd)) {
SetWindowText(hwnd,
conf_get_bool(conf, CONF_win_name_always) ?
window_name : icon_name);
}
{
FontSpec *font = conf_get_fontspec(conf, CONF_font);
FontSpec *prev_font = conf_get_fontspec(prev_conf,
CONF_font);
if (!strcmp(font->name, prev_font->name) ||
!strcmp(conf_get_str(conf, CONF_line_codepage),
conf_get_str(prev_conf, CONF_line_codepage)) ||
font->isbold != prev_font->isbold ||
font->height != prev_font->height ||
font->charset != prev_font->charset ||
conf_get_int(conf, CONF_font_quality) !=
conf_get_int(prev_conf, CONF_font_quality) ||
conf_get_int(conf, CONF_vtmode) !=
conf_get_int(prev_conf, CONF_vtmode) ||
conf_get_int(conf, CONF_bold_style) !=
conf_get_int(prev_conf, CONF_bold_style) ||
resize_action == RESIZE_DISABLED ||
resize_action == RESIZE_EITHER ||
resize_action != conf_get_int(prev_conf,
CONF_resize_action))
init_lvl = 2;
}
InvalidateRect(hwnd, NULL, true);
reset_window(init_lvl);
conf_free(prev_conf);
break;
}
case IDM_COPYALL:
term_copyall(term, clips_system, lenof(clips_system));
break;
@ -2680,21 +2677,19 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
}
}
return 0;
case WM_MOUSEMOVE:
{
/*
* Windows seems to like to occasionally send MOUSEMOVE
* events even if the mouse hasn't moved. Don't unhide
* the mouse pointer in this case.
*/
static WPARAM wp = 0;
static LPARAM lp = 0;
if (wParam != wp || lParam != lp ||
last_mousemove != WM_MOUSEMOVE) {
show_mouseptr(true);
wp = wParam; lp = lParam;
last_mousemove = WM_MOUSEMOVE;
}
case WM_MOUSEMOVE: {
/*
* Windows seems to like to occasionally send MOUSEMOVE
* events even if the mouse hasn't moved. Don't unhide
* the mouse pointer in this case.
*/
static WPARAM wp = 0;
static LPARAM lp = 0;
if (wParam != wp || lParam != lp ||
last_mousemove != WM_MOUSEMOVE) {
show_mouseptr(true);
wp = wParam; lp = lParam;
last_mousemove = WM_MOUSEMOVE;
}
/*
* Add the mouse position and message time to the random
@ -2717,19 +2712,19 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
wParam & MK_CONTROL, is_alt_pressed());
}
return 0;
case WM_NCMOUSEMOVE:
{
static WPARAM wp = 0;
static LPARAM lp = 0;
if (wParam != wp || lParam != lp ||
last_mousemove != WM_NCMOUSEMOVE) {
show_mouseptr(true);
wp = wParam; lp = lParam;
last_mousemove = WM_NCMOUSEMOVE;
}
}
case WM_NCMOUSEMOVE: {
static WPARAM wp = 0;
static LPARAM lp = 0;
if (wParam != wp || lParam != lp ||
last_mousemove != WM_NCMOUSEMOVE) {
show_mouseptr(true);
wp = wParam; lp = lParam;
last_mousemove = WM_NCMOUSEMOVE;
}
noise_ultralight(NOISE_SOURCE_MOUSEPOS, lParam);
break;
}
case WM_IGNORE_CLIP:
ignore_clip = wParam; /* don't panic on DESTROYCLIPBOARD */
break;
@ -2738,122 +2733,120 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
term_lost_clipboard_ownership(term, CLIP_SYSTEM);
ignore_clip = false;
return 0;
case WM_PAINT:
{
PAINTSTRUCT p;
case WM_PAINT: {
PAINTSTRUCT p;
HideCaret(hwnd);
hdc = BeginPaint(hwnd, &p);
if (pal) {
SelectPalette(hdc, pal, true);
RealizePalette(hdc);
}
/*
* We have to be careful about term_paint(). It will
* set a bunch of character cells to INVALID and then
* call do_paint(), which will redraw those cells and
* _then mark them as done_. This may not be accurate:
* when painting in WM_PAINT context we are restricted
* to the rectangle which has just been exposed - so if
* that only covers _part_ of a character cell and the
* rest of it was already visible, that remainder will
* not be redrawn at all. Accordingly, we must not
* paint any character cell in a WM_PAINT context which
* already has a pending update due to terminal output.
* The simplest solution to this - and many, many
* thanks to Hung-Te Lin for working all this out - is
* not to do any actual painting at _all_ if there's a
* pending terminal update: just mark the relevant
* character cells as INVALID and wait for the
* scheduled full update to sort it out.
*
* I have a suspicion this isn't the _right_ solution.
* An alternative approach would be to have terminal.c
* separately track what _should_ be on the terminal
* screen and what _is_ on the terminal screen, and
* have two completely different types of redraw (one
* for full updates, which syncs the former with the
* terminal itself, and one for WM_PAINT which syncs
* the latter with the former); yet another possibility
* would be to have the Windows front end do what the
* GTK one already does, and maintain a bitmap of the
* current terminal appearance so that WM_PAINT becomes
* completely trivial. However, this should do for now.
*/
assert(!wintw_hdc);
wintw_hdc = hdc;
term_paint(term,
(p.rcPaint.left-offset_width)/font_width,
(p.rcPaint.top-offset_height)/font_height,
(p.rcPaint.right-offset_width-1)/font_width,
(p.rcPaint.bottom-offset_height-1)/font_height,
!term->window_update_pending);
wintw_hdc = NULL;
if (p.fErase ||
p.rcPaint.left < offset_width ||
p.rcPaint.top < offset_height ||
p.rcPaint.right >= offset_width + font_width*term->cols ||
p.rcPaint.bottom>= offset_height + font_height*term->rows)
{
HBRUSH fillcolour, oldbrush;
HPEN edge, oldpen;
fillcolour = CreateSolidBrush (
colours[ATTR_DEFBG>>ATTR_BGSHIFT]);
oldbrush = SelectObject(hdc, fillcolour);
edge = CreatePen(PS_SOLID, 0,
colours[ATTR_DEFBG>>ATTR_BGSHIFT]);
oldpen = SelectObject(hdc, edge);
/*
* Jordan Russell reports that this apparently
* ineffectual IntersectClipRect() call masks a
* Windows NT/2K bug causing strange display
* problems when the PuTTY window is taller than
* the primary monitor. It seems harmless enough...
*/
IntersectClipRect(hdc,
p.rcPaint.left, p.rcPaint.top,
p.rcPaint.right, p.rcPaint.bottom);
ExcludeClipRect(hdc,
offset_width, offset_height,
offset_width+font_width*term->cols,
offset_height+font_height*term->rows);
Rectangle(hdc, p.rcPaint.left, p.rcPaint.top,
p.rcPaint.right, p.rcPaint.bottom);
/* SelectClipRgn(hdc, NULL); */
SelectObject(hdc, oldbrush);
DeleteObject(fillcolour);
SelectObject(hdc, oldpen);
DeleteObject(edge);
}
SelectObject(hdc, GetStockObject(SYSTEM_FONT));
SelectObject(hdc, GetStockObject(WHITE_PEN));
EndPaint(hwnd, &p);
ShowCaret(hwnd);
HideCaret(hwnd);
hdc = BeginPaint(hwnd, &p);
if (pal) {
SelectPalette(hdc, pal, true);
RealizePalette(hdc);
}
return 0;
case WM_NETEVENT:
/*
* We have to be careful about term_paint(). It will
* set a bunch of character cells to INVALID and then
* call do_paint(), which will redraw those cells and
* _then mark them as done_. This may not be accurate:
* when painting in WM_PAINT context we are restricted
* to the rectangle which has just been exposed - so if
* that only covers _part_ of a character cell and the
* rest of it was already visible, that remainder will
* not be redrawn at all. Accordingly, we must not
* paint any character cell in a WM_PAINT context which
* already has a pending update due to terminal output.
* The simplest solution to this - and many, many
* thanks to Hung-Te Lin for working all this out - is
* not to do any actual painting at _all_ if there's a
* pending terminal update: just mark the relevant
* character cells as INVALID and wait for the
* scheduled full update to sort it out.
*
* I have a suspicion this isn't the _right_ solution.
* An alternative approach would be to have terminal.c
* separately track what _should_ be on the terminal
* screen and what _is_ on the terminal screen, and
* have two completely different types of redraw (one
* for full updates, which syncs the former with the
* terminal itself, and one for WM_PAINT which syncs
* the latter with the former); yet another possibility
* would be to have the Windows front end do what the
* GTK one already does, and maintain a bitmap of the
* current terminal appearance so that WM_PAINT becomes
* completely trivial. However, this should do for now.
*/
assert(!wintw_hdc);
wintw_hdc = hdc;
term_paint(term,
(p.rcPaint.left-offset_width)/font_width,
(p.rcPaint.top-offset_height)/font_height,
(p.rcPaint.right-offset_width-1)/font_width,
(p.rcPaint.bottom-offset_height-1)/font_height,
!term->window_update_pending);
wintw_hdc = NULL;
if (p.fErase ||
p.rcPaint.left < offset_width ||
p.rcPaint.top < offset_height ||
p.rcPaint.right >= offset_width + font_width*term->cols ||
p.rcPaint.bottom>= offset_height + font_height*term->rows)
{
/*
* To protect against re-entrancy when Windows's recv()
* immediately triggers a new WSAAsyncSelect window
* message, we don't call select_result directly from this
* handler but instead wait until we're back out at the
* top level of the message loop.
*/
struct wm_netevent_params *params =
snew(struct wm_netevent_params);
params->wParam = wParam;
params->lParam = lParam;
queue_toplevel_callback(wm_netevent_callback, params);
HBRUSH fillcolour, oldbrush;
HPEN edge, oldpen;
fillcolour = CreateSolidBrush (
colours[ATTR_DEFBG>>ATTR_BGSHIFT]);
oldbrush = SelectObject(hdc, fillcolour);
edge = CreatePen(PS_SOLID, 0,
colours[ATTR_DEFBG>>ATTR_BGSHIFT]);
oldpen = SelectObject(hdc, edge);
/*
* Jordan Russell reports that this apparently
* ineffectual IntersectClipRect() call masks a
* Windows NT/2K bug causing strange display
* problems when the PuTTY window is taller than
* the primary monitor. It seems harmless enough...
*/
IntersectClipRect(hdc,
p.rcPaint.left, p.rcPaint.top,
p.rcPaint.right, p.rcPaint.bottom);
ExcludeClipRect(hdc,
offset_width, offset_height,
offset_width+font_width*term->cols,
offset_height+font_height*term->rows);
Rectangle(hdc, p.rcPaint.left, p.rcPaint.top,
p.rcPaint.right, p.rcPaint.bottom);
/* SelectClipRgn(hdc, NULL); */
SelectObject(hdc, oldbrush);
DeleteObject(fillcolour);
SelectObject(hdc, oldpen);
DeleteObject(edge);
}
SelectObject(hdc, GetStockObject(SYSTEM_FONT));
SelectObject(hdc, GetStockObject(WHITE_PEN));
EndPaint(hwnd, &p);
ShowCaret(hwnd);
return 0;
}
case WM_NETEVENT: {
/*
* To protect against re-entrancy when Windows's recv()
* immediately triggers a new WSAAsyncSelect window
* message, we don't call select_result directly from this
* handler but instead wait until we're back out at the
* top level of the message loop.
*/
struct wm_netevent_params *params =
snew(struct wm_netevent_params);
params->wParam = wParam;
params->lParam = lParam;
queue_toplevel_callback(wm_netevent_callback, params);
return 0;
}
case WM_SETFOCUS:
term_set_focus(term, true);
CreateCaret(hwnd, caretbm, font_width, font_height);
@ -3137,21 +3130,20 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
term_scroll(term, 0, -term->rows / 2);
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
case SB_THUMBTRACK: {
/*
* Use GetScrollInfo instead of HIWORD(wParam) to get
* 32-bit scroll position.
*/
{
SCROLLINFO si;
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_TRACKPOS;
if (GetScrollInfo(hwnd, SB_VERT, &si) == 0)
si.nTrackPos = HIWORD(wParam);
term_scroll(term, 1, si.nTrackPos);
}
si.cbSize = sizeof(si);
si.fMask = SIF_TRACKPOS;
if (GetScrollInfo(hwnd, SB_VERT, &si) == 0)
si.nTrackPos = HIWORD(wParam);
term_scroll(term, 1, si.nTrackPos);
break;
}
}
break;
case WM_PALETTECHANGED:
@ -3232,61 +3224,59 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
set_input_locale((HKL)lParam);
sys_cursor_update();
break;
case WM_IME_STARTCOMPOSITION:
{
HIMC hImc = ImmGetContext(hwnd);
ImmSetCompositionFont(hImc, &lfont);
ImmReleaseContext(hwnd, hImc);
}
case WM_IME_STARTCOMPOSITION: {
HIMC hImc = ImmGetContext(hwnd);
ImmSetCompositionFont(hImc, &lfont);
ImmReleaseContext(hwnd, hImc);
break;
case WM_IME_COMPOSITION:
{
HIMC hIMC;
int n;
char *buff;
}
case WM_IME_COMPOSITION: {
HIMC hIMC;
int n;
char *buff;
if (osPlatformId == VER_PLATFORM_WIN32_WINDOWS ||
osPlatformId == VER_PLATFORM_WIN32s)
break; /* no Unicode */
if (osPlatformId == VER_PLATFORM_WIN32_WINDOWS ||
osPlatformId == VER_PLATFORM_WIN32s)
break; /* no Unicode */
if ((lParam & GCS_RESULTSTR) == 0) /* Composition unfinished. */
break; /* fall back to DefWindowProc */
if ((lParam & GCS_RESULTSTR) == 0) /* Composition unfinished. */
break; /* fall back to DefWindowProc */
hIMC = ImmGetContext(hwnd);
n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
hIMC = ImmGetContext(hwnd);
n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
if (n > 0) {
int i;
buff = snewn(n, char);
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
/*
* Jaeyoun Chung reports that Korean character
* input doesn't work correctly if we do a single
* term_keyinputw covering the whole of buff. So
* instead we send the characters one by one.
*/
/* don't divide SURROGATE PAIR */
if (ldisc) {
for (i = 0; i < n; i += 2) {
WCHAR hs = *(unsigned short *)(buff+i);
if (IS_HIGH_SURROGATE(hs) && i+2 < n) {
WCHAR ls = *(unsigned short *)(buff+i+2);
if (IS_LOW_SURROGATE(ls)) {
term_keyinputw(
term, (unsigned short *)(buff+i), 2);
i += 2;
continue;
}
}
term_keyinputw(
term, (unsigned short *)(buff+i), 1);
}
if (n > 0) {
int i;
buff = snewn(n, char);
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
/*
* Jaeyoun Chung reports that Korean character
* input doesn't work correctly if we do a single
* term_keyinputw covering the whole of buff. So
* instead we send the characters one by one.
*/
/* don't divide SURROGATE PAIR */
if (ldisc) {
for (i = 0; i < n; i += 2) {
WCHAR hs = *(unsigned short *)(buff+i);
if (IS_HIGH_SURROGATE(hs) && i+2 < n) {
WCHAR ls = *(unsigned short *)(buff+i+2);
if (IS_LOW_SURROGATE(ls)) {
term_keyinputw(
term, (unsigned short *)(buff+i), 2);
i += 2;
continue;
}
free(buff);
}
term_keyinputw(
term, (unsigned short *)(buff+i), 1);
}
ImmReleaseContext(hwnd, hIMC);
return 1;
}
free(buff);
}
ImmReleaseContext(hwnd, hIMC);
return 1;
}
case WM_IME_CHAR:
if (wParam & 0xFF00) {

Просмотреть файл

@ -1624,17 +1624,16 @@ void select_result(WPARAM wParam, LPARAM lParam)
plug_receive(s->plug, 2, buf, ret);
}
break;
case FD_WRITE:
{
int bufsize_before, bufsize_after;
s->writable = true;
bufsize_before = s->sending_oob + bufchain_size(&s->output_data);
try_send(s);
bufsize_after = s->sending_oob + bufchain_size(&s->output_data);
if (bufsize_after < bufsize_before)
plug_sent(s->plug, bufsize_after);
}
case FD_WRITE: {
int bufsize_before, bufsize_after;
s->writable = true;
bufsize_before = s->sending_oob + bufchain_size(&s->output_data);
try_send(s);
bufsize_after = s->sending_oob + bufchain_size(&s->output_data);
if (bufsize_after < bufsize_before)
plug_sent(s->plug, bufsize_after);
break;
}
case FD_CLOSE:
/* Signal a close on the socket. First read any outstanding data. */
do {
@ -1652,42 +1651,42 @@ void select_result(WPARAM wParam, LPARAM lParam)
}
} while (ret > 0);
return;
case FD_ACCEPT:
{
case FD_ACCEPT: {
#ifdef NO_IPV6
struct sockaddr_in isa;
struct sockaddr_in isa;
#else
struct sockaddr_storage isa;
struct sockaddr_storage isa;
#endif
int addrlen = sizeof(isa);
SOCKET t; /* socket of connection */
accept_ctx_t actx;
int addrlen = sizeof(isa);
SOCKET t; /* socket of connection */
accept_ctx_t actx;
memset(&isa, 0, sizeof(isa));
err = 0;
t = p_accept(s->s,(struct sockaddr *)&isa,&addrlen);
if (t == INVALID_SOCKET)
{
err = p_WSAGetLastError();
if (err == WSATRY_AGAIN)
break;
}
memset(&isa, 0, sizeof(isa));
err = 0;
t = p_accept(s->s,(struct sockaddr *)&isa,&addrlen);
if (t == INVALID_SOCKET)
{
err = p_WSAGetLastError();
if (err == WSATRY_AGAIN)
break;
}
actx.p = (void *)t;
actx.p = (void *)t;
#ifndef NO_IPV6
if (isa.ss_family == AF_INET &&
s->localhost_only &&
!ipv4_is_local_addr(((struct sockaddr_in *)&isa)->sin_addr))
if (isa.ss_family == AF_INET &&
s->localhost_only &&
!ipv4_is_local_addr(((struct sockaddr_in *)&isa)->sin_addr))
#else
if (s->localhost_only && !ipv4_is_local_addr(isa.sin_addr))
if (s->localhost_only && !ipv4_is_local_addr(isa.sin_addr))
#endif
{
p_closesocket(t); /* dodgy WinSock let nonlocal through */
} else if (plug_accepting(s->plug, sk_net_accept, actx)) {
p_closesocket(t); /* denied or error */
}
{
p_closesocket(t); /* dodgy WinSock let nonlocal through */
} else if (plug_accepting(s->plug, sk_net_accept, actx)) {
p_closesocket(t); /* denied or error */
}
break;
}
}
}

Просмотреть файл

@ -100,20 +100,19 @@ static void progress_update(void *param, int action, int phase, int iprogress)
case PROGFN_PHASE_EXTENT:
p->phases[phase-1].total = progress;
break;
case PROGFN_READY:
{
unsigned total = 0;
int i;
for (i = 0; i < p->nphases; i++) {
p->phases[i].startpoint = total;
total += p->phases[i].total;
}
p->total = total;
p->divisor = ((p->total + PROGRESSRANGE - 1) / PROGRESSRANGE);
p->range = p->total / p->divisor;
SendMessage(p->progbar, PBM_SETRANGE, 0, MAKELPARAM(0, p->range));
case PROGFN_READY: {
unsigned total = 0;
int i;
for (i = 0; i < p->nphases; i++) {
p->phases[i].startpoint = total;
total += p->phases[i].total;
}
p->total = total;
p->divisor = ((p->total + PROGRESSRANGE - 1) / PROGRESSRANGE);
p->range = p->total / p->divisor;
SendMessage(p->progbar, PBM_SETRANGE, 0, MAKELPARAM(0, p->range));
break;
}
case PROGFN_PROGRESS:
if (p->phases[phase-1].exponential) {
while (p->phases[phase-1].n < progress) {
@ -236,24 +235,23 @@ static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
case WM_INITDIALOG: {
/*
* Centre the window.
*/
{ /* centre the window */
RECT rs, rd;
HWND hw;
RECT rs, rd;
HWND hw;
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
rd.right - rd.left, rd.bottom - rd.top, true);
}
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
rd.right - rd.left, rd.bottom - rd.top, true);
SetDlgItemText(hwnd, 1000, LICENCE_TEXT("\r\n\r\n"));
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
@ -1057,13 +1055,12 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
case IDC_KEYSSH2RSA:
case IDC_KEYSSH2DSA:
case IDC_KEYSSH2ECDSA:
case IDC_KEYSSH2ED25519:
{
state = (struct MainDlgState *)
GetWindowLongPtr(hwnd, GWLP_USERDATA);
ui_set_key_type(hwnd, state, LOWORD(wParam));
}
case IDC_KEYSSH2ED25519: {
state = (struct MainDlgState *)
GetWindowLongPtr(hwnd, GWLP_USERDATA);
ui_set_key_type(hwnd, state, LOWORD(wParam));
break;
}
case IDC_QUIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
@ -1478,61 +1475,60 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
*/
ui_set_state(hwnd, state, 2);
break;
case WM_HELP:
{
int id = ((LPHELPINFO)lParam)->iCtrlId;
const char *topic = NULL;
switch (id) {
case IDC_GENERATING:
case IDC_PROGRESS:
case IDC_GENSTATIC:
case IDC_GENERATE:
topic = WINHELP_CTX_puttygen_generate; break;
case IDC_PKSTATIC:
case IDC_KEYDISPLAY:
topic = WINHELP_CTX_puttygen_pastekey; break;
case IDC_FPSTATIC:
case IDC_FINGERPRINT:
topic = WINHELP_CTX_puttygen_fingerprint; break;
case IDC_COMMENTSTATIC:
case IDC_COMMENTEDIT:
topic = WINHELP_CTX_puttygen_comment; break;
case IDC_PASSPHRASE1STATIC:
case IDC_PASSPHRASE1EDIT:
case IDC_PASSPHRASE2STATIC:
case IDC_PASSPHRASE2EDIT:
topic = WINHELP_CTX_puttygen_passphrase; break;
case IDC_LOADSTATIC:
case IDC_LOAD:
topic = WINHELP_CTX_puttygen_load; break;
case IDC_SAVESTATIC:
case IDC_SAVE:
topic = WINHELP_CTX_puttygen_savepriv; break;
case IDC_SAVEPUB:
topic = WINHELP_CTX_puttygen_savepub; break;
case IDC_TYPESTATIC:
case IDC_KEYSSH1:
case IDC_KEYSSH2RSA:
case IDC_KEYSSH2DSA:
case IDC_KEYSSH2ECDSA:
case IDC_KEYSSH2ED25519:
topic = WINHELP_CTX_puttygen_keytype; break;
case IDC_BITSSTATIC:
case IDC_BITS:
topic = WINHELP_CTX_puttygen_bits; break;
case IDC_IMPORT:
case IDC_EXPORT_OPENSSH_AUTO:
case IDC_EXPORT_OPENSSH_NEW:
case IDC_EXPORT_SSHCOM:
topic = WINHELP_CTX_puttygen_conversions; break;
}
if (topic) {
launch_help(hwnd, topic);
} else {
MessageBeep(0);
}
case WM_HELP: {
int id = ((LPHELPINFO)lParam)->iCtrlId;
const char *topic = NULL;
switch (id) {
case IDC_GENERATING:
case IDC_PROGRESS:
case IDC_GENSTATIC:
case IDC_GENERATE:
topic = WINHELP_CTX_puttygen_generate; break;
case IDC_PKSTATIC:
case IDC_KEYDISPLAY:
topic = WINHELP_CTX_puttygen_pastekey; break;
case IDC_FPSTATIC:
case IDC_FINGERPRINT:
topic = WINHELP_CTX_puttygen_fingerprint; break;
case IDC_COMMENTSTATIC:
case IDC_COMMENTEDIT:
topic = WINHELP_CTX_puttygen_comment; break;
case IDC_PASSPHRASE1STATIC:
case IDC_PASSPHRASE1EDIT:
case IDC_PASSPHRASE2STATIC:
case IDC_PASSPHRASE2EDIT:
topic = WINHELP_CTX_puttygen_passphrase; break;
case IDC_LOADSTATIC:
case IDC_LOAD:
topic = WINHELP_CTX_puttygen_load; break;
case IDC_SAVESTATIC:
case IDC_SAVE:
topic = WINHELP_CTX_puttygen_savepriv; break;
case IDC_SAVEPUB:
topic = WINHELP_CTX_puttygen_savepub; break;
case IDC_TYPESTATIC:
case IDC_KEYSSH1:
case IDC_KEYSSH2RSA:
case IDC_KEYSSH2DSA:
case IDC_KEYSSH2ECDSA:
case IDC_KEYSSH2ED25519:
topic = WINHELP_CTX_puttygen_keytype; break;
case IDC_BITSSTATIC:
case IDC_BITS:
topic = WINHELP_CTX_puttygen_bits; break;
case IDC_IMPORT:
case IDC_EXPORT_OPENSSH_AUTO:
case IDC_EXPORT_OPENSSH_NEW:
case IDC_EXPORT_SSHCOM:
topic = WINHELP_CTX_puttygen_conversions; break;
}
if (topic) {
launch_help(hwnd, topic);
} else {
MessageBeep(0);
}
break;
}
case WM_CLOSE:
state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
sfree(state);

Просмотреть файл

@ -133,18 +133,17 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
{
char *buildinfo_text = buildinfo("\r\n");
char *text = dupprintf
("Pageant\r\n\r\n%s\r\n\r\n%s\r\n\r\n%s",
ver, buildinfo_text,
"\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved.");
sfree(buildinfo_text);
SetDlgItemText(hwnd, 1000, text);
sfree(text);
}
case WM_INITDIALOG: {
char *buildinfo_text = buildinfo("\r\n");
char *text = dupprintf
("Pageant\r\n\r\n%s\r\n\r\n%s\r\n\r\n%s",
ver, buildinfo_text,
"\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved.");
sfree(buildinfo_text);
SetDlgItemText(hwnd, 1000, text);
sfree(text);
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
@ -186,22 +185,20 @@ static INT_PTR CALLBACK PassphraseProc(HWND hwnd, UINT msg,
struct PassphraseProcStruct *p;
switch (msg) {
case WM_INITDIALOG:
case WM_INITDIALOG: {
passphrase_box = hwnd;
/*
* Centre the window.
*/
{ /* centre the window */
RECT rs, rd;
HWND hw;
RECT rs, rd;
HWND hw;
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
rd.right - rd.left, rd.bottom - rd.top, true);
}
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
rd.right - rd.left, rd.bottom - rd.top, true);
SetForegroundWindow(hwnd);
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
@ -214,6 +211,7 @@ static INT_PTR CALLBACK PassphraseProc(HWND hwnd, UINT msg,
*passphrase = dupstr("");
SetDlgItemText(hwnd, 102, *passphrase);
return 0;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
@ -485,41 +483,40 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
ssh2_userkey *skey;
switch (msg) {
case WM_INITDIALOG:
case WM_INITDIALOG: {
/*
* Centre the window.
*/
{ /* centre the window */
RECT rs, rd;
HWND hw;
RECT rs, rd;
HWND hw;
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
rd.right - rd.left, rd.bottom - rd.top, true);
}
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
rd.right - rd.left, rd.bottom - rd.top, true);
if (has_help())
SetWindowLongPtr(hwnd, GWL_EXSTYLE,
GetWindowLongPtr(hwnd, GWL_EXSTYLE) |
WS_EX_CONTEXTHELP);
else {
HWND item = GetDlgItem(hwnd, 103); /* the Help button */
if (item)
DestroyWindow(item);
HWND item = GetDlgItem(hwnd, 103); /* the Help button */
if (item)
DestroyWindow(item);
}
keylist = hwnd;
{
static int tabs[] = { 35, 75, 250 };
SendDlgItemMessage(hwnd, 100, LB_SETTABSTOPS,
sizeof(tabs) / sizeof(*tabs),
(LPARAM) tabs);
static int tabs[] = { 35, 75, 250 };
SendDlgItemMessage(hwnd, 100, LB_SETTABSTOPS,
sizeof(tabs) / sizeof(*tabs),
(LPARAM) tabs);
}
keylist_update();
return 0;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
@ -607,22 +604,21 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
return 0;
}
return 0;
case WM_HELP:
{
int id = ((LPHELPINFO)lParam)->iCtrlId;
const char *topic = NULL;
switch (id) {
case 100: topic = WINHELP_CTX_pageant_keylist; break;
case 101: topic = WINHELP_CTX_pageant_addkey; break;
case 102: topic = WINHELP_CTX_pageant_remkey; break;
}
if (topic) {
launch_help(hwnd, topic);
} else {
MessageBeep(0);
}
case WM_HELP: {
int id = ((LPHELPINFO)lParam)->iCtrlId;
const char *topic = NULL;
switch (id) {
case 100: topic = WINHELP_CTX_pageant_keylist; break;
case 101: topic = WINHELP_CTX_pageant_addkey; break;
case 102: topic = WINHELP_CTX_pageant_remkey; break;
}
if (topic) {
launch_help(hwnd, topic);
} else {
MessageBeep(0);
}
break;
}
case WM_CLOSE:
keylist = NULL;
DestroyWindow(hwnd);
@ -1007,20 +1003,19 @@ static LRESULT CALLBACK TrayWndProc(HWND hwnd, UINT message,
case WM_COMMAND:
case WM_SYSCOMMAND:
switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
case IDM_PUTTY:
{
TCHAR cmdline[10];
cmdline[0] = '\0';
if (restrict_putty_acl)
strcat(cmdline, "&R");
case IDM_PUTTY: {
TCHAR cmdline[10];
cmdline[0] = '\0';
if (restrict_putty_acl)
strcat(cmdline, "&R");
if((INT_PTR)ShellExecute(hwnd, NULL, putty_path, cmdline,
_T(""), SW_SHOW) <= 32) {
MessageBox(NULL, "Unable to execute PuTTY!",
"Error", MB_OK | MB_ICONERROR);
}
if((INT_PTR)ShellExecute(hwnd, NULL, putty_path, cmdline,
_T(""), SW_SHOW) <= 32) {
MessageBox(NULL, "Unable to execute PuTTY!",
"Error", MB_OK | MB_ICONERROR);
}
break;
}
case IDM_CLOSE:
if (passphrase_box)
SendMessage(passphrase_box, WM_CLOSE, 0, 0);
@ -1068,31 +1063,30 @@ static LRESULT CALLBACK TrayWndProc(HWND hwnd, UINT message,
case IDM_HELP:
launch_help(hwnd, WINHELP_CTX_pageant_general);
break;
default:
{
if(wParam >= IDM_SESSIONS_BASE && wParam <= IDM_SESSIONS_MAX) {
MENUITEMINFO mii;
TCHAR buf[MAX_PATH + 1];
TCHAR param[MAX_PATH + 1];
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE;
mii.cch = MAX_PATH;
mii.dwTypeData = buf;
GetMenuItemInfo(session_menu, wParam, false, &mii);
param[0] = '\0';
if (restrict_putty_acl)
strcat(param, "&R");
strcat(param, "@");
strcat(param, mii.dwTypeData);
if((INT_PTR)ShellExecute(hwnd, NULL, putty_path, param,
_T(""), SW_SHOW) <= 32) {
MessageBox(NULL, "Unable to execute PuTTY!", "Error",
MB_OK | MB_ICONERROR);
}
}
default: {
if(wParam >= IDM_SESSIONS_BASE && wParam <= IDM_SESSIONS_MAX) {
MENUITEMINFO mii;
TCHAR buf[MAX_PATH + 1];
TCHAR param[MAX_PATH + 1];
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE;
mii.cch = MAX_PATH;
mii.dwTypeData = buf;
GetMenuItemInfo(session_menu, wParam, false, &mii);
param[0] = '\0';
if (restrict_putty_acl)
strcat(param, "&R");
strcat(param, "@");
strcat(param, mii.dwTypeData);
if((INT_PTR)ShellExecute(hwnd, NULL, putty_path, param,
_T(""), SW_SHOW) <= 32) {
MessageBox(NULL, "Unable to execute PuTTY!", "Error",
MB_OK | MB_ICONERROR);
}
}
break;
}
}
break;
case WM_DESTROY:
@ -1108,27 +1102,26 @@ static LRESULT CALLBACK wm_copydata_WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_COPYDATA:
{
COPYDATASTRUCT *cds;
char *mapname, *err;
case WM_COPYDATA: {
COPYDATASTRUCT *cds;
char *mapname, *err;
cds = (COPYDATASTRUCT *) lParam;
if (cds->dwData != AGENT_COPYDATA_ID)
return 0; /* not our message, mate */
mapname = (char *) cds->lpData;
if (mapname[cds->cbData - 1] != '\0')
return 0; /* failure to be ASCIZ! */
err = answer_filemapping_message(mapname);
if (err) {
cds = (COPYDATASTRUCT *) lParam;
if (cds->dwData != AGENT_COPYDATA_ID)
return 0; /* not our message, mate */
mapname = (char *) cds->lpData;
if (mapname[cds->cbData - 1] != '\0')
return 0; /* failure to be ASCIZ! */
err = answer_filemapping_message(mapname);
if (err) {
#ifdef DEBUG_IPC
debug("IPC failed: %s\n", err);
debug("IPC failed: %s\n", err);
#endif
sfree(err);
return 0;
}
return 1;
sfree(err);
return 0;
}
return 1;
}
}
return DefWindowProc(hwnd, message, wParam, lParam);