1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-13 09:07:33 -05:00

Whitespace rationalisation of entire code base.

The number of people has been steadily increasing who read our source
code with an editor that thinks tab stops are 4 spaces apart, as
opposed to the traditional tty-derived 8 that the PuTTY code expects.

So I've been wondering for ages about just fixing it, and switching to
a spaces-only policy throughout the code. And I recently found out
about 'git blame -w', which should make this change not too disruptive
for the purposes of source-control archaeology; so perhaps now is the
time.

While I'm at it, I've also taken the opportunity to remove all the
trailing spaces from source lines (on the basis that git dislikes
them, and is the only thing that seems to have a strong opinion one
way or the other).
    
Apologies to anyone downstream of this code who has complicated patch
sets to rebase past this change. I don't intend it to be needed again.
This commit is contained in:
Simon Tatham
2019-09-08 20:29:00 +01:00
parent b60230dbb8
commit 5d718ef64b
210 changed files with 30897 additions and 30897 deletions

View File

@ -46,35 +46,35 @@ static void make_session_filename(const char *in, strbuf *out)
* opt-in for safe characters rather than opt-out for
* specific unsafe ones...
*/
if (*in!='+' && *in!='-' && *in!='.' && *in!='@' && *in!='_' &&
if (*in!='+' && *in!='-' && *in!='.' && *in!='@' && *in!='_' &&
!(*in >= '0' && *in <= '9') &&
!(*in >= 'A' && *in <= 'Z') &&
!(*in >= 'a' && *in <= 'z')) {
put_byte(out, '%');
put_byte(out, hex[((unsigned char) *in) >> 4]);
put_byte(out, hex[((unsigned char) *in) & 15]);
} else
put_byte(out, *in);
in++;
put_byte(out, '%');
put_byte(out, hex[((unsigned char) *in) >> 4]);
put_byte(out, hex[((unsigned char) *in) & 15]);
} else
put_byte(out, *in);
in++;
}
}
static void decode_session_filename(const char *in, strbuf *out)
{
while (*in) {
if (*in == '%' && in[1] && in[2]) {
int i, j;
if (*in == '%' && in[1] && in[2]) {
int i, j;
i = in[1] - '0';
i -= (i > 9 ? 7 : 0);
j = in[2] - '0';
j -= (j > 9 ? 7 : 0);
i = in[1] - '0';
i -= (i > 9 ? 7 : 0);
j = in[2] - '0';
j -= (j > 9 ? 7 : 0);
put_byte(out, (i << 4) + j);
in += 3;
} else {
put_byte(out, *in++);
}
put_byte(out, (i << 4) + j);
in += 3;
} else {
put_byte(out, *in++);
}
}
}
@ -87,15 +87,15 @@ static char *make_filename(int index, const char *subname)
* specific subparts of it, by means of environment variables.
*/
if (index == INDEX_DIR) {
struct passwd *pwd;
struct passwd *pwd;
char *xdg_dir, *old_dir, *old_dir2, *old_dir3, *home, *pwd_home;
env = getenv("PUTTYDIR");
if (env)
return dupstr(env);
env = getenv("PUTTYDIR");
if (env)
return dupstr(env);
home = getenv("HOME");
pwd = getpwuid(getuid());
pwd = getpwuid(getuid());
if (pwd && pwd->pw_dir) {
pwd_home = pwd->pw_dir;
} else {
@ -162,45 +162,45 @@ static char *make_filename(int index, const char *subname)
return ret;
}
if (index == INDEX_SESSIONDIR) {
env = getenv("PUTTYSESSIONS");
if (env)
return dupstr(env);
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/sessions", tmp);
sfree(tmp);
return ret;
env = getenv("PUTTYSESSIONS");
if (env)
return dupstr(env);
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/sessions", tmp);
sfree(tmp);
return ret;
}
if (index == INDEX_SESSION) {
strbuf *sb = strbuf_new();
tmp = make_filename(INDEX_SESSIONDIR, NULL);
strbuf_catf(sb, "%s/", tmp);
sfree(tmp);
tmp = make_filename(INDEX_SESSIONDIR, NULL);
strbuf_catf(sb, "%s/", tmp);
sfree(tmp);
make_session_filename(subname, sb);
return strbuf_to_str(sb);
}
if (index == INDEX_HOSTKEYS) {
env = getenv("PUTTYSSHHOSTKEYS");
if (env)
return dupstr(env);
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/sshhostkeys", tmp);
sfree(tmp);
return ret;
env = getenv("PUTTYSSHHOSTKEYS");
if (env)
return dupstr(env);
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/sshhostkeys", tmp);
sfree(tmp);
return ret;
}
if (index == INDEX_HOSTKEYS_TMP) {
tmp = make_filename(INDEX_HOSTKEYS, NULL);
ret = dupprintf("%s.tmp", tmp);
sfree(tmp);
return ret;
tmp = make_filename(INDEX_HOSTKEYS, NULL);
ret = dupprintf("%s.tmp", tmp);
sfree(tmp);
return ret;
}
if (index == INDEX_RANDSEED) {
env = getenv("PUTTYRANDOMSEED");
if (env)
return dupstr(env);
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/randomseed", tmp);
sfree(tmp);
return ret;
env = getenv("PUTTYRANDOMSEED");
if (env)
return dupstr(env);
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/randomseed", tmp);
sfree(tmp);
return ret;
}
tmp = make_filename(INDEX_DIR, NULL);
ret = dupprintf("%s/ERROR", tmp);
@ -246,8 +246,8 @@ settings_w *open_settings_w(const char *sessionname, char **errmsg)
if (!fp) {
*errmsg = dupprintf("Unable to save session: open(\"%s\") "
"returned '%s'", filename, strerror(errno));
sfree(filename);
return NULL; /* can't open */
sfree(filename);
return NULL; /* can't open */
}
sfree(filename);
@ -309,30 +309,30 @@ void provide_xrm_string(const char *string, const char *progname)
p = q = strchr(string, ':');
if (!q) {
fprintf(stderr, "%s: expected a colon in resource string"
" \"%s\"\n", progname, string);
return;
fprintf(stderr, "%s: expected a colon in resource string"
" \"%s\"\n", progname, string);
return;
}
q++;
while (p > string && p[-1] != '.' && p[-1] != '*')
p--;
p--;
xrms = snew(struct skeyval);
key = snewn(q-p, char);
memcpy(key, p, q-p);
key[q-p-1] = '\0';
xrms->key = key;
while (*q && isspace((unsigned char)*q))
q++;
q++;
xrms->value = dupstr(q);
if (!xrmtree)
xrmtree = newtree234(keycmp);
xrmtree = newtree234(keycmp);
ret = add234(xrmtree, xrms);
if (ret) {
/* Override an existing string. */
del234(xrmtree, ret);
add234(xrmtree, xrms);
/* Override an existing string. */
del234(xrmtree, ret);
add234(xrmtree, xrms);
}
}
@ -341,9 +341,9 @@ static const char *get_setting(const char *key)
struct skeyval tmp, *ret;
tmp.key = key;
if (xrmtree) {
ret = find234(xrmtree, &tmp, NULL);
if (ret)
return ret->value;
ret = find234(xrmtree, &tmp, NULL);
if (ret)
return ret->value;
}
return x_get_default(key);
}
@ -368,7 +368,7 @@ settings_r *open_settings_r(const char *sessionname)
fp = fopen(filename, "r");
sfree(filename);
if (!fp)
return NULL; /* can't open */
return NULL; /* can't open */
toret = snew(settings_r);
toret->t = newtree234(keycmp);
@ -411,9 +411,9 @@ char *read_setting_s(settings_r *handle, const char *key)
val = get_setting(key);
if (!val)
return NULL;
return NULL;
else
return dupstr(val);
return dupstr(val);
}
int read_setting_i(settings_r *handle, const char *key, int defvalue)
@ -430,9 +430,9 @@ int read_setting_i(settings_r *handle, const char *key, int defvalue)
val = get_setting(key);
if (!val)
return defvalue;
return defvalue;
else
return atoi(val);
return atoi(val);
}
FontSpec *read_setting_fontspec(settings_r *handle, const char *name)
@ -441,7 +441,7 @@ FontSpec *read_setting_fontspec(settings_r *handle, const char *name)
* In GTK1-only PuTTY, we used to store font names simply as a
* valid X font description string (logical or alias), under a
* bare key such as "Font".
*
*
* In GTK2 PuTTY, we have a prefix system where "client:"
* indicates a Pango font and "server:" an X one; existing
* configuration needs to be reinterpreted as having the
@ -454,9 +454,9 @@ FontSpec *read_setting_fontspec(settings_r *handle, const char *name)
if ((tmp = read_setting_s(handle, suffname)) != NULL) {
FontSpec *fs = fontspec_new(tmp);
sfree(suffname);
sfree(tmp);
return fs; /* got new-style name */
sfree(suffname);
sfree(tmp);
return fs; /* got new-style name */
}
sfree(suffname);
@ -465,12 +465,12 @@ FontSpec *read_setting_fontspec(settings_r *handle, const char *name)
if (tmp && *tmp) {
char *tmp2 = dupcat("server:", tmp, NULL);
FontSpec *fs = fontspec_new(tmp2);
sfree(tmp2);
sfree(tmp);
return fs;
sfree(tmp2);
sfree(tmp);
return fs;
} else {
sfree(tmp);
return NULL;
sfree(tmp);
return NULL;
}
}
Filename *read_setting_filename(settings_r *handle, const char *name)
@ -478,10 +478,10 @@ Filename *read_setting_filename(settings_r *handle, const char *name)
char *tmp = read_setting_s(handle, name);
if (tmp) {
Filename *ret = filename_from_str(tmp);
sfree(tmp);
return ret;
sfree(tmp);
return ret;
} else
return NULL;
return NULL;
}
void write_setting_fontspec(settings_w *handle, const char *name, FontSpec *fs)
@ -565,13 +565,13 @@ bool enum_settings_next(settings_e *handle, strbuf *out)
while ( (de = readdir(handle->dp)) != NULL ) {
fullpath->len = baselen;
put_datapl(fullpath, ptrlen_from_asciz(de->d_name));
put_datapl(fullpath, ptrlen_from_asciz(de->d_name));
if (stat(fullpath->s, &st) < 0 || !S_ISREG(st.st_mode))
continue; /* try another one */
decode_session_filename(de->d_name, out);
strbuf_free(fullpath);
strbuf_free(fullpath);
return true;
}
@ -588,15 +588,15 @@ void enum_settings_finish(settings_e *handle)
/*
* Lines in the host keys file are of the form
*
*
* type@port:hostname keydata
*
*
* e.g.
*
*
* rsa@22:foovax.example.org 0x23,0x293487364395345345....2343
*/
int verify_host_key(const char *hostname, int port,
const char *keytype, const char *key)
const char *keytype, const char *key)
{
FILE *fp;
char *filename;
@ -607,57 +607,57 @@ int verify_host_key(const char *hostname, int port,
fp = fopen(filename, "r");
sfree(filename);
if (!fp)
return 1; /* key does not exist */
return 1; /* key does not exist */
ret = 1;
while ( (line = fgetline(fp)) ) {
int i;
char *p = line;
char porttext[20];
int i;
char *p = line;
char porttext[20];
line[strcspn(line, "\n")] = '\0'; /* strip trailing newline */
line[strcspn(line, "\n")] = '\0'; /* strip trailing newline */
i = strlen(keytype);
if (strncmp(p, keytype, i))
goto done;
p += i;
i = strlen(keytype);
if (strncmp(p, keytype, i))
goto done;
p += i;
if (*p != '@')
goto done;
p++;
if (*p != '@')
goto done;
p++;
sprintf(porttext, "%d", port);
i = strlen(porttext);
if (strncmp(p, porttext, i))
goto done;
p += i;
sprintf(porttext, "%d", port);
i = strlen(porttext);
if (strncmp(p, porttext, i))
goto done;
p += i;
if (*p != ':')
goto done;
p++;
if (*p != ':')
goto done;
p++;
i = strlen(hostname);
if (strncmp(p, hostname, i))
goto done;
p += i;
i = strlen(hostname);
if (strncmp(p, hostname, i))
goto done;
p += i;
if (*p != ' ')
goto done;
p++;
if (*p != ' ')
goto done;
p++;
/*
* Found the key. Now just work out whether it's the right
* one or not.
*/
if (!strcmp(p, key))
ret = 0; /* key matched OK */
else
ret = 2; /* key mismatch */
/*
* Found the key. Now just work out whether it's the right
* one or not.
*/
if (!strcmp(p, key))
ret = 0; /* key matched OK */
else
ret = 2; /* key mismatch */
done:
sfree(line);
if (ret != 1)
break;
done:
sfree(line);
if (ret != 1)
break;
}
fclose(fp);
@ -675,7 +675,7 @@ bool have_ssh_host_key(const char *hostname, int port,
}
void store_host_key(const char *hostname, int port,
const char *keytype, const char *key)
const char *keytype, const char *key)
{
FILE *rfp, *wfp;
char *newtext, *line;
@ -698,7 +698,7 @@ void store_host_key(const char *hostname, int port,
sfree(tmpfilename);
return;
}
sfree(dir);
sfree(dir);
wfp = fopen(tmpfilename, "w");
}
@ -754,11 +754,11 @@ void read_random_seed(noise_consumer_t consumer)
fd = open(fname, O_RDONLY);
sfree(fname);
if (fd >= 0) {
char buf[512];
int ret;
while ( (ret = read(fd, buf, sizeof(buf))) > 0)
consumer(buf, ret);
close(fd);
char buf[512];
int ret;
while ( (ret = read(fd, buf, sizeof(buf))) > 0)
consumer(buf, ret);
close(fd);
}
}
@ -783,7 +783,7 @@ void write_random_seed(void *data, int len)
}
char *dir, *errmsg;
dir = make_filename(INDEX_DIR, NULL);
dir = make_filename(INDEX_DIR, NULL);
if ((errmsg = make_dir_path(dir, 0700)) != NULL) {
nonfatal("Unable to write random seed: %s", errmsg);
sfree(errmsg);
@ -791,9 +791,9 @@ void write_random_seed(void *data, int len)
sfree(dir);
return;
}
sfree(dir);
sfree(dir);
fd = open(fname, O_CREAT | O_WRONLY, 0600);
fd = open(fname, O_CREAT | O_WRONLY, 0600);
if (fd < 0) {
nonfatal("Unable to write random seed: open(\"%s\") "
"returned '%s'", fname, strerror(errno));
@ -803,14 +803,14 @@ void write_random_seed(void *data, int len)
}
while (len > 0) {
int ret = write(fd, data, len);
if (ret < 0) {
int ret = write(fd, data, len);
if (ret < 0) {
nonfatal("Unable to write random seed: write "
"returned '%s'", strerror(errno));
break;
}
len -= ret;
data = (char *)data + len;
len -= ret;
data = (char *)data + len;
}
close(fd);