mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-18 19:41:01 -05:00
Replace integer context2 encoding in conf_editbox_handler.
I was just about to add another ordinary edit box control, and found I couldn't remember what went in the context2 argument to conf_editbox. When I looked it up, I realised it was one of those horrid integer encodings of the form '1 means this, -1 means that, less than -1 means some parametrised property where the parameter is obtained by negating the encoded integer'. Those are always awkward to remember, and worse to extend. So I've replaced the integer context2 used with conf_editbox_handler with a pointer to a small struct type in which the types and parameters have sensible names and are documented. (To avoid annoying const warnings everywhere, this also meant extending the 'intorptr' union to have a const void * branch as well as a 'void *'. Surprised I haven't needed that before. But if I introduce any more of these parameter structures, it'll come in useful again.)
This commit is contained in:
4
dialog.h
4
dialog.h
@ -43,11 +43,12 @@ enum {
|
||||
* included with DEFINE_INTORPTR_FNS defined. This is a total pain,
|
||||
* but such is life.
|
||||
*/
|
||||
typedef union { void *p; int i; } intorptr;
|
||||
typedef union { void *p; const void *cp; int i; } intorptr;
|
||||
|
||||
#ifndef INLINE
|
||||
intorptr I(int i);
|
||||
intorptr P(void *p);
|
||||
intorptr CP(const void *p);
|
||||
#endif
|
||||
|
||||
#if defined DEFINE_INTORPTR_FNS || defined INLINE
|
||||
@ -58,6 +59,7 @@ intorptr P(void *p);
|
||||
#endif
|
||||
PREFIX intorptr I(int i) { intorptr ret; ret.i = i; return ret; }
|
||||
PREFIX intorptr P(void *p) { intorptr ret; ret.p = p; return ret; }
|
||||
PREFIX intorptr CP(const void *p) { intorptr ret; ret.cp = p; return ret; }
|
||||
#undef PREFIX
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user