1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

New header file 'defs.h'.

This centralises a few things that multiple header files were
previously defining, and were protecting against each other's
redefinition with ifdefs - small things like structs and typedefs. Now
all those things are in a defs.h which is by definition safe to
include _first_ (out of all the codebase-local headers) and only need
to be defined once.
This commit is contained in:
Simon Tatham 2018-05-24 08:59:01 +01:00
parent 58379aa5ab
commit 12b38ad9e1
7 changed files with 43 additions and 47 deletions

37
defs.h Normal file
View File

@ -0,0 +1,37 @@
/*
* defs.h: initial definitions for PuTTY.
*
* The rule about this header file is that it can't depend on any
* other header file in this code base. This is where we define
* things, as much as we can, that other headers will want to refer
* to, such as opaque structure types and their associated typedefs,
* or macros that are used by other headers.
*/
#ifndef PUTTY_DEFS_H
#define PUTTY_DEFS_H
typedef struct conf_tag Conf;
typedef struct backend_tag Backend;
typedef struct terminal_tag Terminal;
typedef struct Filename Filename;
typedef struct FontSpec FontSpec;
typedef struct bufchain_tag bufchain;
typedef struct strbuf strbuf;
struct RSAKey;
#include <stdint.h>
typedef uint32_t uint32;
/* Do a compile-time type-check of 'to_check' (without evaluating it),
* as a side effect of returning the value 'to_return'. Note that
* although this macro double-*expands* to_return, it always
* *evaluates* exactly one copy of it, so it's side-effect safe. */
#define TYPECHECK(to_check, to_return) \
(sizeof(to_check) ? (to_return) : (to_return))
#endif /* PUTTY_DEFS_H */

10
misc.h
View File

@ -5,6 +5,7 @@
#ifndef PUTTY_MISC_H
#define PUTTY_MISC_H
#include "defs.h"
#include "puttymem.h"
#include <stdio.h> /* for FILE * */
@ -18,9 +19,6 @@
#define TRUE 1
#endif
typedef struct Filename Filename;
typedef struct FontSpec FontSpec;
unsigned long parse_blocksize(const char *bs);
char ctrlparse(char *s, char **next);
@ -38,7 +36,7 @@ char *dupprintf(const char *fmt, ...)
;
char *dupvprintf(const char *fmt, va_list ap);
void burnstr(char *string);
typedef struct strbuf strbuf;
strbuf *strbuf_new(void);
void strbuf_free(strbuf *buf);
char *strbuf_str(strbuf *buf); /* does not free buf */
@ -70,10 +68,6 @@ struct bufchain_tag {
struct bufchain_granule *head, *tail;
int buffersize; /* current amount of buffered data */
};
#ifndef BUFCHAIN_TYPEDEF
typedef struct bufchain_tag bufchain; /* rest of declaration in misc.c */
#define BUFCHAIN_TYPEDEF
#endif
void bufchain_init(bufchain *ch);
void bufchain_clear(bufchain *ch);

View File

@ -13,12 +13,7 @@
#ifndef PUTTY_NETWORK_H
#define PUTTY_NETWORK_H
#ifndef DONE_TYPEDEFS
#define DONE_TYPEDEFS
typedef struct conf_tag Conf;
typedef struct backend_tag Backend;
typedef struct terminal_tag Terminal;
#endif
#include "defs.h"
typedef struct SockAddr_tag *SockAddr;
/* pay attention to levels of indirection */
@ -229,10 +224,6 @@ Socket new_error_socket(const char *errmsg, Plug plug);
void backend_socket_log(void *frontend, int type, SockAddr addr, int port,
const char *error_msg, int error_code, Conf *conf,
int session_started);
#ifndef BUFCHAIN_TYPEDEF
typedef struct bufchain_tag bufchain; /* rest of declaration in misc.c */
#define BUFCHAIN_TYPEDEF
#endif
void log_proxy_stderr(Plug plug, bufchain *buf, const void *vdata, int len);
#endif

10
putty.h
View File

@ -16,13 +16,7 @@
#endif
#endif
#ifndef DONE_TYPEDEFS
#define DONE_TYPEDEFS
typedef struct conf_tag Conf;
typedef struct backend_tag Backend;
typedef struct terminal_tag Terminal;
#endif
#include "defs.h"
#include "puttyps.h"
#include "network.h"
#include "misc.h"
@ -538,8 +532,6 @@ GLOBAL int loaded_session;
*/
GLOBAL char *cmdline_session_name;
struct RSAKey; /* be a little careful of scope */
/*
* Mechanism for getting text strings such as usernames and passwords
* from the front-end.

5
ssh.h
View File

@ -199,11 +199,6 @@ unsigned char *rsa_ssh1_public_blob(struct RSAKey *key, int *len,
int rsa_public_blob_len(void *data, int maxlen);
void freersakey(struct RSAKey *key);
#ifndef PUTTY_UINT32_DEFINED
/* This makes assumptions about the int type. */
typedef unsigned int uint32;
#define PUTTY_UINT32_DEFINED
#endif
typedef uint32 word32;
unsigned long crc32_compute(const void *s, size_t len);

View File

@ -71,9 +71,6 @@ extern Backend pty_backend;
#define BROKEN_PIPE_ERROR_CODE EPIPE /* used in sshshare.c */
typedef uint32_t uint32; /* C99: uint32_t defined in stdint.h */
#define PUTTY_UINT32_DEFINED
/*
* Under GTK, we send MA_CLICK _and_ MA_2CLK, or MA_CLICK _and_
* MA_3CLK, when a button is pressed for the second or third time.

View File

@ -23,6 +23,8 @@
#include <stdint.h>
#endif
#include "defs.h"
#include "tree234.h"
#include "winhelp.h"
@ -132,8 +134,6 @@ struct FontSpec *fontspec_new(const char *name,
*
* (DECL_WINDOWS_FUNCTION works with both these variants.)
*/
#define TYPECHECK(to_check, to_return) \
(sizeof(to_check) ? to_return : to_return)
#define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
typedef rettype (WINAPI *t_##name) params; \
linkage t_##name p_##name
@ -164,13 +164,6 @@ struct FontSpec *fontspec_new(const char *name,
#endif
#endif
#ifndef DONE_TYPEDEFS
#define DONE_TYPEDEFS
typedef struct conf_tag Conf;
typedef struct backend_tag Backend;
typedef struct terminal_tag Terminal;
#endif
#define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
#define PUTTY_REG_PARENT "Software\\SimonTatham"
#define PUTTY_REG_PARENT_CHILD "PuTTY"
@ -198,9 +191,6 @@ typedef struct terminal_tag Terminal;
typedef HDC Context;
typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
#define PUTTY_UINT32_DEFINED
#ifndef NO_GSSAPI
/*
* GSS-API stuff