summaryrefslogtreecommitdiffstats
path: root/source3/aparser/parser.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-05-16 11:55:06 +0000
committerAndrew Tridgell <tridge@samba.org>2000-05-16 11:55:06 +0000
commitf3a3a05ade784ff6906e5c8b132c9440a8db44e5 (patch)
tree35f1cfbb0a880a592487450c5a9b8d37cfe302b9 /source3/aparser/parser.c
parent466338b165a19149e7a938bf4302c95dcab82beb (diff)
downloadsamba-f3a3a05ade784ff6906e5c8b132c9440a8db44e5.tar.gz
samba-f3a3a05ade784ff6906e5c8b132c9440a8db44e5.tar.xz
samba-f3a3a05ade784ff6906e5c8b132c9440a8db44e5.zip
another awk parser update
we can now handle arrays of structures, pointers to structures, pointers in unions etc (This used to be commit 1df80cd1e8475b6b2fe7b80b6c9089692ab7691b)
Diffstat (limited to 'source3/aparser/parser.c')
-rw-r--r--source3/aparser/parser.c118
1 files changed, 71 insertions, 47 deletions
diff --git a/source3/aparser/parser.c b/source3/aparser/parser.c
index 76e7d917122..d55a5eb7d34 100644
--- a/source3/aparser/parser.c
+++ b/source3/aparser/parser.c
@@ -125,23 +125,6 @@ char *prs_mem_get(prs_struct *ps, uint32 extra_size)
return &ps->data_p[ps->data_offset];
}
-
-/*******************************************************************
- Stream a uint32.
- ********************************************************************/
-
-BOOL prs_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, BOOL scalars)
-{
- char *q = prs_mem_get(ps, sizeof(uint32));
- if (q == NULL)
- return False;
-
- DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data32)
- ps->data_offset += sizeof(uint32);
-
- return True;
-}
-
/*******************************************************************
Initialise a parse structure - malloc the data if requested.
********************************************************************/
@@ -264,61 +247,102 @@ void dump_data(int level,char *buf1,int len)
}
}
+
/*******************************************************************
- Stream a pointer
+ do IO on a uint32.
********************************************************************/
-BOOL prs_pointer(char *desc, prs_struct *ps, int depth, void **p, BOOL scalars)
+BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned flags)
{
- uint32 v = (*p) ? 1 : 0;
- if (!prs_uint32(desc, ps, depth, &v, True)) return False;
- *p = (void *) (v ? 1 : 0);
+ char *q;
+
+ if (!(flags & PARSE_SCALARS)) return True;
+
+ q = prs_mem_get(ps, sizeof(uint32));
+ if (q == NULL) return False;
+
+ DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data32)
+ ps->data_offset += sizeof(uint32);
+
return True;
}
-/******************************************************************
- Stream an array of uint16s. Length is number of uint16s.
+/*******************************************************************
+ do IO on a uint16.
********************************************************************/
-
-BOOL prs_uint16s(BOOL charmode, char *name, prs_struct *ps, int depth, uint16 *data16s, int len)
+BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned flags)
{
- char *q = prs_mem_get(ps, len * sizeof(uint16));
- if (q == NULL)
- return False;
+ char *q;
- DBG_RW_PSVAL(charmode, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data16s, len)
- ps->data_offset += (len * sizeof(uint16));
+ if (!(flags & PARSE_SCALARS)) return True;
+
+ q = prs_mem_get(ps, sizeof(uint16));
+ if (q == NULL) return False;
+
+ DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16)
+ ps->data_offset += sizeof(uint16);
return True;
}
-/******************************************************************
- Stream an array of uint32s. Length is number of uint32s.
+/*******************************************************************
+ do IO on a uint8.
********************************************************************/
-
-BOOL prs_uint32s(BOOL charmode, char *name, prs_struct *ps, int depth, uint32 *data32s, int len)
+BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flags)
{
- char *q = prs_mem_get(ps, len * sizeof(uint32));
- if (q == NULL)
- return False;
+ char *q;
+
+ if (!(flags & PARSE_SCALARS)) return True;
+
+ q = prs_mem_get(ps, sizeof(uint8));
+ if (q == NULL) return False;
- DBG_RW_PIVAL(charmode, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data32s, len)
- ps->data_offset += (len * sizeof(uint32));
+ DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data8)
+ ps->data_offset += sizeof(uint8);
return True;
}
/*******************************************************************
- Stream a uint16.
+ do IO on a pointer
********************************************************************/
+BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags)
+{
+ uint32 v;
+
+ if (!(flags & PARSE_SCALARS)) return True;
-BOOL prs_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, BOOL scalars)
+ v = (*p) ? 1 : 0;
+ if (!io_uint32(desc, ps, depth, &v, flags)) return False;
+ *p = (void *) (v ? 1 : 0);
+ return True;
+}
+
+/******************************************************************
+ do IO on a unicode array
+ ********************************************************************/
+BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len, unsigned flags)
{
- char *q = prs_mem_get(ps, sizeof(uint16));
- if (q == NULL)
- return False;
+ char *q;
- DBG_RW_SVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16)
- ps->data_offset += sizeof(uint16);
+ if (!(flags & PARSE_SCALARS)) return True;
+
+ q = prs_mem_get(ps, len * sizeof(uint16));
+ if (q == NULL) return False;
+
+ DBG_RW_PSVAL(True, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data16s, len)
+ ps->data_offset += (len * sizeof(uint16));
return True;
}
+
+
+/******************************************************************
+allocate some memory for a parse structure
+ ********************************************************************/
+BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size)
+{
+ (*ptr) = (void *)malloc(size);
+ if (*ptr) return True;
+ return False;
+}
+