From 1c0fecc3f5d9ec294096e9c49b9552512e0456cf Mon Sep 17 00:00:00 2001 From: deadwood Date: Mon, 29 Aug 2016 06:49:37 +0000 Subject: [PATCH] compiler/alib: remove duplication of BuildEasyRequest git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@52900 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/alib/buildeasyrequest.c | 153 ++++++++++++---------------------- compiler/alib/easyrequest.c | 172 +++++++++++++-------------------------- compiler/alib/easystruct_util.h | 35 ++++++++ 3 files changed, 144 insertions(+), 216 deletions(-) rewrite compiler/alib/buildeasyrequest.c (70%) rewrite compiler/alib/easyrequest.c (61%) create mode 100644 compiler/alib/easystruct_util.h diff --git a/compiler/alib/buildeasyrequest.c b/compiler/alib/buildeasyrequest.c dissimilarity index 70% index f4eeb59fb1..3e25edde77 100644 --- a/compiler/alib/buildeasyrequest.c +++ b/compiler/alib/buildeasyrequest.c @@ -1,99 +1,54 @@ -/* - Copyright � 1995-2013, The AROS Development Team. All rights reserved. - $Id$ - - Desc: Varargs version of BuildEasyRequestArgs() (intuition.library) - Lang: english -*/ -#include - -/***************************************************************************** - - NAME */ -#define NO_INLINE_STDARG /* turn off inline def */ -#include -#include -#include -#include - - struct Window * BuildEasyRequest ( - -/* SYNOPSIS */ - struct Window * RefWindow, - struct EasyStruct * easyStruct, - ULONG IDCMP, - ...) - -/* FUNCTION - - INPUTS - - RESULT - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - intuition.library/BuildEasyRequestArgs() - - INTERNALS - -*****************************************************************************/ -{ - va_list args; - struct Window * rc; - const char *ptr; - int argcnt = 0; - IPTR *argtable = NULL; - - for (ptr = easyStruct->es_TextFormat; *ptr; ptr++) - { - if (*ptr == '%') - { - if (ptr[1] == '%') - { - ptr++; - continue; - } - - argcnt++; - } - } - - for (ptr = easyStruct->es_GadgetFormat; *ptr; ptr++) - { - if (*ptr == '%') - { - if (ptr[1] == '%') - { - ptr++; - continue; - } - - argcnt++; - } - } - - if (argcnt) - { - va_start (args, IDCMP); - - int i; - - argtable = AllocVec(sizeof(IPTR)*argcnt, MEMF_PUBLIC); - - for (i=0; i < argcnt; i++) - argtable[i] = va_arg(args, IPTR); - - va_end (args); - } - - rc = BuildEasyRequestArgs (RefWindow, easyStruct, IDCMP, (APTR)argtable); - - FreeVec(argtable); - - return rc; -} /* BuildEasyRequest */ +/* + Copyright � 1995-2016, The AROS Development Team. All rights reserved. + $Id$ + + Desc: Varargs version of BuildEasyRequestArgs() (intuition.library) + Lang: english +*/ + +#include +#include "easystruct_util.h" +#include +#include + +/***************************************************************************** + + NAME */ + + struct Window * BuildEasyRequest ( + +/* SYNOPSIS */ + struct Window *RefWindow, + struct EasyStruct *easyStruct, + ULONG IDCMP, + ...) + +/* FUNCTION + + INPUTS + + RESULT + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + + INTERNALS + +*****************************************************************************/ +{ + struct Window * retval; + STRPTR format = CreateFormatStringFromEasyStruct(easyStruct); + + AROS_SLOWSTACKFORMAT_PRE_USING(IDCMP, format); + retval = BuildEasyRequestArgs(RefWindow, easyStruct, IDCMP, AROS_SLOWSTACKFORMAT_ARG(format)); + AROS_SLOWSTACKFORMAT_POST(format); + + FreeFormatString(format); + + return retval; +} /* BuildEasyRequest */ diff --git a/compiler/alib/easyrequest.c b/compiler/alib/easyrequest.c dissimilarity index 61% index 34d2ca771a..e64d037bae 100644 --- a/compiler/alib/easyrequest.c +++ b/compiler/alib/easyrequest.c @@ -1,117 +1,55 @@ -/* - Copyright (C) 1995-2016, The AROS Development Team. All rights reserved. - $Id$ -*/ - -#include -#include "alib_intern.h" -#include -#include -#include - -static STRPTR CreateFormatStringFromEasyStruct(struct EasyStruct *easyStruct) -{ - STRPTR format = NULL; - LONG lentext = 0, lengadget = 0; - - if (easyStruct->es_TextFormat) lentext = STRLEN(easyStruct->es_TextFormat); - if (easyStruct->es_GadgetFormat) lengadget = STRLEN(easyStruct->es_GadgetFormat); - - format = AllocVec(lentext + lengadget + 1, MEMF_PUBLIC); - CopyMem(easyStruct->es_TextFormat, format, lentext); - CopyMem(easyStruct->es_GadgetFormat, format + lentext, lengadget); - format[lentext + lengadget] = '\0'; - - return format; -} - -static void FreeFormatString(STRPTR format) -{ - FreeVec(format); -} - -/***************************************************************************** - - NAME */ - - LONG EasyRequest ( - -/* SYNOPSIS */ - struct Window *window, - struct EasyStruct *easyStruct, - ULONG *IDCMP_ptr, - ...) - -/* FUNCTION - - INPUTS - - RESULT - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - - INTERNALS - -*****************************************************************************/ -{ - LONG retval; - STRPTR format = CreateFormatStringFromEasyStruct(easyStruct); - - AROS_SLOWSTACKFORMAT_PRE_USING(IDCMP_ptr, format); - retval = EasyRequestArgs(window, easyStruct, IDCMP_ptr, AROS_SLOWSTACKFORMAT_ARG(format)); - AROS_SLOWSTACKFORMAT_POST(format); - - FreeFormatString(format); - - return retval; -} /* EasyRequest */ - - - -/**i************************************************************************** - - NAME */ - - struct Window * BuildEasyRequest ( - -/* SYNOPSIS */ - struct Window *RefWindow, - struct EasyStruct *easyStruct, - ULONG IDCMP, - ...) - -/* FUNCTION - - INPUTS - - RESULT - - NOTES - - EXAMPLE - - BUGS - - SEE ALSO - - INTERNALS - -*****************************************************************************/ -{ - struct Window * retval; - STRPTR format = CreateFormatStringFromEasyStruct(easyStruct); - - AROS_SLOWSTACKFORMAT_PRE_USING(IDCMP, format); - retval = BuildEasyRequestArgs(RefWindow, easyStruct, IDCMP, AROS_SLOWSTACKFORMAT_ARG(format)); - AROS_SLOWSTACKFORMAT_POST(format); - - FreeFormatString(format); - - return retval; -} /* BuildEasyRequest */ +/* + Copyright (C) 1995-2016, The AROS Development Team. All rights reserved. + $Id$ + + Desc: Varargs version of EasyRequestArgs() (intuition.library) + Lang: english +*/ + +#include +#include "easystruct_util.h" +#include +#include + +/***************************************************************************** + + NAME */ + + LONG EasyRequest ( + +/* SYNOPSIS */ + struct Window *window, + struct EasyStruct *easyStruct, + ULONG *IDCMP_ptr, + ...) + +/* FUNCTION + + INPUTS + + RESULT + + NOTES + + EXAMPLE + + BUGS + + SEE ALSO + + INTERNALS + +*****************************************************************************/ +{ + LONG retval; + STRPTR format = CreateFormatStringFromEasyStruct(easyStruct); + + AROS_SLOWSTACKFORMAT_PRE_USING(IDCMP_ptr, format); + retval = EasyRequestArgs(window, easyStruct, IDCMP_ptr, AROS_SLOWSTACKFORMAT_ARG(format)); + AROS_SLOWSTACKFORMAT_POST(format); + + FreeFormatString(format); + + return retval; +} /* EasyRequest */ + diff --git a/compiler/alib/easystruct_util.h b/compiler/alib/easystruct_util.h new file mode 100644 index 0000000000..65d3cb66e0 --- /dev/null +++ b/compiler/alib/easystruct_util.h @@ -0,0 +1,35 @@ +#ifndef _EASYSTRUCT_UTIL_H +#define _EASYSTRUCT_UTIL_H + +/* + Copyright © 2016, The AROS Development Team. All rights reserved. + $Id$ +*/ + +#include "alib_intern.h" +#include +#include + +static inline STRPTR CreateFormatStringFromEasyStruct(struct EasyStruct *easyStruct) +{ + STRPTR format = NULL; + LONG lentext = 0, lengadget = 0; + + if (easyStruct->es_TextFormat) lentext = STRLEN(easyStruct->es_TextFormat); + if (easyStruct->es_GadgetFormat) lengadget = STRLEN(easyStruct->es_GadgetFormat); + + format = AllocVec(lentext + lengadget + 1, MEMF_PUBLIC); + CopyMem(easyStruct->es_TextFormat, format, lentext); + CopyMem(easyStruct->es_GadgetFormat, format + lentext, lengadget); + format[lentext + lengadget] = '\0'; + + return format; +} + +static inline void FreeFormatString(STRPTR format) +{ + FreeVec(format); +} + + +#endif /* _EASYSTRUCT_UTIL_H */ -- 2.11.4.GIT