Commit 9692f02c authored by Stewart Brodie's avatar Stewart Brodie
Browse files

New zap_gadget_string macro to assist in zapping string into templates.

In addition to the offset into the gadget structure of the pointer to
the string data, this macro takes the offset of the maximum length field
in the same template and ensures that the buffer length stated is at least
long enough to hold the string being zapped into the buffer.  This
parent a5fae552
......@@ -30,6 +30,7 @@
#include "objects.window.h"
#include "mem.h"
#include "objsupport.h"
#include "string32.h"
static _kernel_oserror *extract_gadget_info(char *tm,ComponentID id,void **p,int *l)
{
......@@ -65,6 +66,24 @@ _kernel_oserror *__zap_gadget(char *tm,ComponentID id,int off,int val)
}
_kernel_oserror *__zap_gadget_string(char *tm,ComponentID id,int off,const char* val,int offlen)
{
/* Zaps the string into the gadget template and checks the length against a length field
* in the same template, increasing the value if necessary
*/
int *p,l;
_kernel_oserror *e=__zap_gadget(tm,id,off,(int)val);
if (e) return e;
e=extract_gadget_info(tm,id,(void **) &p,&l);
if(!e) {
int cl=*(p+ off/sizeof(int));
int rl=string_length((char *)val)+1;
if (cl<rl) e=__zap_gadget(tm,id,offlen,rl);
}
return e;
}
int *__read_gadget(char *tm,ComponentID id,int off)
{
int *p,l;
......
......@@ -33,6 +33,7 @@ _kernel_oserror *create_from_template(char *template, ObjectID *handle);
/* zaps gadget attributes, NOTE: use macro form below */
_kernel_oserror *__zap_gadget(char *tm,ComponentID id,int off,int val);
_kernel_oserror *__zap_gadget_string(char *tm,ComponentID id,int off,const char* val,int offlen);
int *__read_gadget(char *tm,ComponentID id,int off);
/* zaps window template, NOTE: use macro form below */
......@@ -48,6 +49,14 @@ _kernel_oserror *delete_gadget(char *tm,ComponentID id);
#define zap_gadget(a,b,c,d,e) __zap_gadget(a,c,sizeof(GadgetHeader) + offsetof(b,d),(int) (e))
/* zap_gadget_string(char *template,typedef GadgetType, ComponentID component, structure member, value, structure member (length)
* This is used to up the max buffer length if the string was too long to fit in the buffer.
* This avoids problems of too small buffer lengths in Res files causing problems.
*/
#define zap_gadget_string(a,b,c,d,e,f) __zap_gadget_string(a,c,sizeof(GadgetHeader) + offsetof(b,d),(e), sizeof(GadgetHeader)+offsetof(b,f))
#define zap_gadget_header(a,c,d,e) __zap_gadget(a,c, offsetof(GadgetHeader,d),(int) (e))
/* zap_window(char *template,WindowTemplate structure member,value) */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment