* mdocml: Rudimentary implementation of user-defined strings; no time for
@ 2010-07-03 16:02 schwarze
2010-07-03 16:12 ` Kristaps Dzonsons
2010-07-25 18:58 ` Joerg Sonnenberger
0 siblings, 2 replies; 6+ messages in thread
From: schwarze @ 2010-07-03 16:02 UTC (permalink / raw)
To: source
Log Message:
-----------
Rudimentary implementation of user-defined strings;
no time for more refinement right now.
In particular, fixes terminfo(3) and mdoc.samples(7).
ok kristaps@, who will add the HTML frontend bits
Modified Files:
--------------
mdocml:
regs.h
roff.3
roff.c
term.c
Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.157
retrieving revision 1.158
diff -Lterm.c -Lterm.c -u -p -r1.157 -r1.158
--- term.c
+++ term.c
@@ -30,6 +30,7 @@
#include "mandoc.h"
#include "chars.h"
#include "out.h"
+#include "regs.h"
#include "term.h"
#include "main.h"
@@ -377,6 +378,11 @@ res(struct termp *p, const char *word, s
size_t sz;
rhs = chars_a2res(p->symtab, word, len, &sz);
+ if (NULL == rhs) {
+ rhs = roff_getstrn(word, len);
+ if (rhs)
+ sz = strlen(rhs);
+ }
if (rhs)
encode(p, rhs, sz);
}
Index: roff.3
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.3,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lroff.3 -Lroff.3 -u -p -r1.3 -r1.4
--- roff.3
+++ roff.3
@@ -50,6 +50,15 @@
.Fc
.Ft void
.Fn roff_reset "struct roff *roff"
+.In regs.h
+.Ft "char *"
+.Fn roff_setstr "const char *name" "const char *string"
+.Ft "char *"
+.Fn roff_getstr "const char *name"
+.Ft "char *"
+.Fn roff_getstrn "const char *name" "size_t len"
+.Ft void
+.Fn roff_freestr void
.Sh DESCRIPTION
The
.Nm
@@ -145,6 +154,52 @@ Returns 0 on failure, 1 on success.
Signals that the parse is complete.
Returns 0 on failure, 1 on success.
.El
+.Sh USER-DEFINED STRINGS
+Strings defined by the
+.Xr roff 7
+.Sx \&ds
+instruction are saved using the
+.Fn roff_setstr
+function and retrieved using the
+.Fn roff_getstr
+and
+.Fn roff_getstrn
+functions.
+.Pp
+These functions take the name of the string to be accessed
+as their first argument.
+While
+.Fn roff_getstr
+requires the name to be null-terminated,
+.Fn roff_getstrn
+accepts non-terminated strings, but requires the length of the name
+to be specified.
+.Pp
+The second argument to
+.Fn roff_setstr
+is the new value of the string.
+It will be copied to internal storage, so both pointers to constant
+strings and pointers to volatile storage are acceptable.
+.Pp
+All of these functions return a pointer to the new value of the string
+in internal storage, which should be considered read-only, so use
+.Xr strdup 3
+on it as appropriate.
+The read functions return NULL when a string of the specified name
+is not available or empty, and
+.Fn roff_setstr
+returns NULL when memory allocation fails.
+In the latter case, the string will remain unset.
+.Pp
+The function
+.Fn roff_freestr
+clears all user-defined strings.
+It always succeeds.
+Both
+.Fn roff_reset
+and
+.Fn roff_free
+call it.
.Sh EXAMPLES
See
.Pa main.c
@@ -159,3 +214,15 @@ The
.Nm
library was written by
.An Kristaps Dzonsons Aq kristaps@bsd.lv .
+.Sh BUGS
+The implementation of user-defined strings needs improvement:
+.Bl -dash
+.It
+String values are taken literally and are not interpreted.
+.It
+Parsing of quoted strings is incomplete.
+.It
+The stings are stored internally using a singly linked list,
+which is fine for small numbers of strings,
+but ineffient when handling many strings.
+.El
Index: regs.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/regs.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregs.h -Lregs.h -u -p -r1.3 -r1.4
--- regs.h
+++ regs.h
@@ -41,6 +41,11 @@ struct regset {
struct reg regs[REG__MAX];
};
+char *roff_setstr(const char *, const char *);
+char *roff_getstr(const char *);
+char *roff_getstrn(const char *, size_t);
+void roff_freestr(void);
+
__END_DECLS
#endif /*!REGS_H*/
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -Lroff.c -Lroff.c -u -p -r1.91 -r1.92
--- roff.c
+++ roff.c
@@ -108,6 +108,12 @@ struct roffmac {
struct roffmac *next;
};
+struct roffstr {
+ char *name;
+ char *string;
+ struct roffstr *next;
+} *first_string;
+
static enum rofferr roff_block(ROFF_ARGS);
static enum rofferr roff_block_text(ROFF_ARGS);
static enum rofferr roff_block_sub(ROFF_ARGS);
@@ -116,6 +122,7 @@ static enum rofferr roff_ccond(ROFF_ARG
static enum rofferr roff_cond(ROFF_ARGS);
static enum rofferr roff_cond_text(ROFF_ARGS);
static enum rofferr roff_cond_sub(ROFF_ARGS);
+static enum rofferr roff_ds(ROFF_ARGS);
static enum rofferr roff_line(ROFF_ARGS);
static enum rofferr roff_nr(ROFF_ARGS);
static enum roffrule roff_evalcond(const char *, int *);
@@ -135,7 +142,7 @@ static struct roffmac roffs[ROFF_MAX] =
{ "de", roff_block, roff_block_text, roff_block_sub, 0, NULL },
{ "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL },
{ "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
- { "ds", roff_line, NULL, NULL, 0, NULL },
+ { "ds", roff_ds, NULL, NULL, 0, NULL },
{ "el", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
{ "ie", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
{ "if", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
@@ -268,6 +275,7 @@ roff_free1(struct roff *r)
while (r->last)
roffnode_pop(r);
+ roff_freestr();
}
@@ -879,6 +887,39 @@ roff_cond(ROFF_ARGS)
/* ARGSUSED */
static enum rofferr
+roff_ds(ROFF_ARGS)
+{
+ char *name, *string, *end;
+
+ name = *bufp + pos;
+ if ('\0' == *name)
+ return(ROFF_IGN);
+
+ string = name;
+ while (*string && ' ' != *string)
+ string++;
+ if (*string)
+ *(string++) = NULL;
+ if (*string && '"' == *string)
+ string++;
+ while (*string && ' ' == *string)
+ string++;
+ end = string;
+ while (*end)
+ end++;
+ if (string < end) {
+ end--;
+ if (*end == '"')
+ *end = '\0';
+ }
+
+ roff_setstr(name, string);
+ return(ROFF_IGN);
+}
+
+
+/* ARGSUSED */
+static enum rofferr
roff_nr(ROFF_ARGS)
{
const char *key, *val;
@@ -917,4 +958,76 @@ roff_nr(ROFF_ARGS)
ROFF_DEBUG("roff: ignoring register: %s\n", key);
return(ROFF_IGN);
+}
+
+
+char *
+roff_setstr(const char *name, const char *string)
+{
+ struct roffstr *n;
+ char *namecopy;
+
+ n = first_string;
+ while (n && strcmp(name, n->name))
+ n = n->next;
+ if (n) {
+ free(n->string);
+ } else {
+ if (NULL == (namecopy = strdup(name)))
+ return(NULL);
+ if (NULL == (n = malloc(sizeof(struct roffstr)))) {
+ free(n);
+ return(NULL);
+ }
+ n->name = namecopy;
+ n->next = first_string;
+ first_string = n;
+ }
+ if (string)
+ n->string = strdup(string);
+ else
+ n->string = NULL;
+ return(n->string);
+}
+
+char *
+roff_getstr(const char *name)
+{
+ struct roffstr *n;
+
+ n = first_string;
+ while (n && strcmp(name, n->name))
+ n = n->next;
+ if (n)
+ return(n->string);
+ else
+ return(NULL);
+}
+
+char *
+roff_getstrn(const char *name, size_t len)
+{
+ struct roffstr *n;
+
+ n = first_string;
+ while (n && (strncmp(name, n->name, len) || '\0' != n->name[len]))
+ n = n->next;
+ if (n)
+ return(n->string);
+ else
+ return(NULL);
+}
+
+void
+roff_freestr(void)
+{
+ struct roffstr *n, *nn;
+
+ for (n = first_string; n; n = nn) {
+ free(n->name);
+ free(n->string);
+ nn = n->next;
+ free(n);
+ }
+ first_string = NULL;
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: mdocml: Rudimentary implementation of user-defined strings; no time for
2010-07-03 16:02 mdocml: Rudimentary implementation of user-defined strings; no time for schwarze
@ 2010-07-03 16:12 ` Kristaps Dzonsons
2010-07-03 16:21 ` Ingo Schwarze
2010-07-25 18:58 ` Joerg Sonnenberger
1 sibling, 1 reply; 6+ messages in thread
From: Kristaps Dzonsons @ 2010-07-03 16:12 UTC (permalink / raw)
To: source
[-- Attachment #1: Type: text/plain, Size: 27 bytes --]
Ingo, did you mean this?
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 615 bytes --]
? config.h
? config.log
? foo.1
? foo.1.html
? foo.3
? foo.7
? foo.html
? mandoc
? patch.txt
? relayd.8.html
? ssh.1.html
? regress/output
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.92
diff -u -r1.92 roff.c
--- roff.c 3 Jul 2010 16:02:12 -0000 1.92
+++ roff.c 3 Jul 2010 16:14:39 -0000
@@ -899,7 +899,7 @@
while (*string && ' ' != *string)
string++;
if (*string)
- *(string++) = NULL;
+ *(string++) = '\0';
if (*string && '"' == *string)
string++;
while (*string && ' ' == *string)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: mdocml: Rudimentary implementation of user-defined strings; no time for
2010-07-03 16:12 ` Kristaps Dzonsons
@ 2010-07-03 16:21 ` Ingo Schwarze
2010-07-03 16:27 ` Kristaps Dzonsons
2010-07-15 16:53 ` Joerg Sonnenberger
0 siblings, 2 replies; 6+ messages in thread
From: Ingo Schwarze @ 2010-07-03 16:21 UTC (permalink / raw)
To: source
Hi Kristaps!
Kristaps Dzonsons write on Sat, Jul 03, 2010 at 06:12:41PM +0200:
> Ingo, did you mean this?
> Index: roff.c
> ===================================================================
> RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
> retrieving revision 1.92
> diff -u -r1.92 roff.c
> --- roff.c 3 Jul 2010 16:02:12 -0000 1.92
> +++ roff.c 3 Jul 2010 16:14:39 -0000
> @@ -899,7 +899,7 @@
> while (*string && ' ' != *string)
> string++;
> if (*string)
> - *(string++) = NULL;
> + *(string++) = '\0';
> if (*string && '"' == *string)
> string++;
> while (*string && ' ' == *string)
NO!
I have put NULL on purpose.
NULL, here, is supposed to mean:
This string is not currently defined.
Just like there were no entry for it in the list.
In both cases, roff_getstr() will return NULL, as documented.
I don't think it would be a good idea to have
- not setting a string in the first place and
- unsetting it
behave differently, the former returning NULL,
the latter returning an empty string...
Yours,
Ingo
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: mdocml: Rudimentary implementation of user-defined strings; no time for
2010-07-03 16:21 ` Ingo Schwarze
@ 2010-07-03 16:27 ` Kristaps Dzonsons
2010-07-15 16:53 ` Joerg Sonnenberger
1 sibling, 0 replies; 6+ messages in thread
From: Kristaps Dzonsons @ 2010-07-03 16:27 UTC (permalink / raw)
To: source
> NO!
>
> I have put NULL on purpose.
> NULL, here, is supposed to mean:
>
> This string is not currently defined.
>
> Just like there were no entry for it in the list.
> In both cases, roff_getstr() will return NULL, as documented.
>
> I don't think it would be a good idea to have
> - not setting a string in the first place and
> - unsetting it
> behave differently, the former returning NULL,
> the latter returning an empty string...
Gah, you're right. I didn't spot the ++ in there. Mea culpa!
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: mdocml: Rudimentary implementation of user-defined strings; no time for
2010-07-03 16:21 ` Ingo Schwarze
2010-07-03 16:27 ` Kristaps Dzonsons
@ 2010-07-15 16:53 ` Joerg Sonnenberger
1 sibling, 0 replies; 6+ messages in thread
From: Joerg Sonnenberger @ 2010-07-15 16:53 UTC (permalink / raw)
To: source
On Sat, Jul 03, 2010 at 06:21:06PM +0200, Ingo Schwarze wrote:
> > Ingo, did you mean this?
>
> > Index: roff.c
> > ===================================================================
> > RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
> > retrieving revision 1.92
> > diff -u -r1.92 roff.c
> > --- roff.c 3 Jul 2010 16:02:12 -0000 1.92
> > +++ roff.c 3 Jul 2010 16:14:39 -0000
> > @@ -899,7 +899,7 @@
> > while (*string && ' ' != *string)
> > string++;
> > if (*string)
> > - *(string++) = NULL;
> > + *(string++) = '\0';
> > if (*string && '"' == *string)
> > string++;
> > while (*string && ' ' == *string)
>
> NO!
>
> I have put NULL on purpose.
> NULL, here, is supposed to mean:
>
> This string is not currently defined.
Well, *(string++) is still a char. It is not a pointer and as such it
triggers a GCC warning.
Joerg
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: mdocml: Rudimentary implementation of user-defined strings; no time for
2010-07-03 16:02 mdocml: Rudimentary implementation of user-defined strings; no time for schwarze
2010-07-03 16:12 ` Kristaps Dzonsons
@ 2010-07-25 18:58 ` Joerg Sonnenberger
1 sibling, 0 replies; 6+ messages in thread
From: Joerg Sonnenberger @ 2010-07-25 18:58 UTC (permalink / raw)
To: source
This change still breaks the build with -Werror.
Ingo, can you please fix it?
Joerg
On Sat, Jul 03, 2010 at 12:02:13PM -0400, schwarze@mdocml.bsd.lv wrote:
> Log Message:
> -----------
> Rudimentary implementation of user-defined strings;
> no time for more refinement right now.
> In particular, fixes terminfo(3) and mdoc.samples(7).
> ok kristaps@, who will add the HTML frontend bits
>
> Modified Files:
> --------------
> mdocml:
> regs.h
> roff.3
> roff.c
> term.c
>
> Revision Data
> -------------
> Index: term.c
> ===================================================================
> RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
> retrieving revision 1.157
> retrieving revision 1.158
> diff -Lterm.c -Lterm.c -u -p -r1.157 -r1.158
> --- term.c
> +++ term.c
> @@ -30,6 +30,7 @@
> #include "mandoc.h"
> #include "chars.h"
> #include "out.h"
> +#include "regs.h"
> #include "term.h"
> #include "main.h"
>
> @@ -377,6 +378,11 @@ res(struct termp *p, const char *word, s
> size_t sz;
>
> rhs = chars_a2res(p->symtab, word, len, &sz);
> + if (NULL == rhs) {
> + rhs = roff_getstrn(word, len);
> + if (rhs)
> + sz = strlen(rhs);
> + }
> if (rhs)
> encode(p, rhs, sz);
> }
> Index: roff.3
> ===================================================================
> RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.3,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -Lroff.3 -Lroff.3 -u -p -r1.3 -r1.4
> --- roff.3
> +++ roff.3
> @@ -50,6 +50,15 @@
> .Fc
> .Ft void
> .Fn roff_reset "struct roff *roff"
> +.In regs.h
> +.Ft "char *"
> +.Fn roff_setstr "const char *name" "const char *string"
> +.Ft "char *"
> +.Fn roff_getstr "const char *name"
> +.Ft "char *"
> +.Fn roff_getstrn "const char *name" "size_t len"
> +.Ft void
> +.Fn roff_freestr void
> .Sh DESCRIPTION
> The
> .Nm
> @@ -145,6 +154,52 @@ Returns 0 on failure, 1 on success.
> Signals that the parse is complete.
> Returns 0 on failure, 1 on success.
> .El
> +.Sh USER-DEFINED STRINGS
> +Strings defined by the
> +.Xr roff 7
> +.Sx \&ds
> +instruction are saved using the
> +.Fn roff_setstr
> +function and retrieved using the
> +.Fn roff_getstr
> +and
> +.Fn roff_getstrn
> +functions.
> +.Pp
> +These functions take the name of the string to be accessed
> +as their first argument.
> +While
> +.Fn roff_getstr
> +requires the name to be null-terminated,
> +.Fn roff_getstrn
> +accepts non-terminated strings, but requires the length of the name
> +to be specified.
> +.Pp
> +The second argument to
> +.Fn roff_setstr
> +is the new value of the string.
> +It will be copied to internal storage, so both pointers to constant
> +strings and pointers to volatile storage are acceptable.
> +.Pp
> +All of these functions return a pointer to the new value of the string
> +in internal storage, which should be considered read-only, so use
> +.Xr strdup 3
> +on it as appropriate.
> +The read functions return NULL when a string of the specified name
> +is not available or empty, and
> +.Fn roff_setstr
> +returns NULL when memory allocation fails.
> +In the latter case, the string will remain unset.
> +.Pp
> +The function
> +.Fn roff_freestr
> +clears all user-defined strings.
> +It always succeeds.
> +Both
> +.Fn roff_reset
> +and
> +.Fn roff_free
> +call it.
> .Sh EXAMPLES
> See
> .Pa main.c
> @@ -159,3 +214,15 @@ The
> .Nm
> library was written by
> .An Kristaps Dzonsons Aq kristaps@bsd.lv .
> +.Sh BUGS
> +The implementation of user-defined strings needs improvement:
> +.Bl -dash
> +.It
> +String values are taken literally and are not interpreted.
> +.It
> +Parsing of quoted strings is incomplete.
> +.It
> +The stings are stored internally using a singly linked list,
> +which is fine for small numbers of strings,
> +but ineffient when handling many strings.
> +.El
> Index: regs.h
> ===================================================================
> RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/regs.h,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -Lregs.h -Lregs.h -u -p -r1.3 -r1.4
> --- regs.h
> +++ regs.h
> @@ -41,6 +41,11 @@ struct regset {
> struct reg regs[REG__MAX];
> };
>
> +char *roff_setstr(const char *, const char *);
> +char *roff_getstr(const char *);
> +char *roff_getstrn(const char *, size_t);
> +void roff_freestr(void);
> +
> __END_DECLS
>
> #endif /*!REGS_H*/
> Index: roff.c
> ===================================================================
> RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
> retrieving revision 1.91
> retrieving revision 1.92
> diff -Lroff.c -Lroff.c -u -p -r1.91 -r1.92
> --- roff.c
> +++ roff.c
> @@ -108,6 +108,12 @@ struct roffmac {
> struct roffmac *next;
> };
>
> +struct roffstr {
> + char *name;
> + char *string;
> + struct roffstr *next;
> +} *first_string;
> +
> static enum rofferr roff_block(ROFF_ARGS);
> static enum rofferr roff_block_text(ROFF_ARGS);
> static enum rofferr roff_block_sub(ROFF_ARGS);
> @@ -116,6 +122,7 @@ static enum rofferr roff_ccond(ROFF_ARG
> static enum rofferr roff_cond(ROFF_ARGS);
> static enum rofferr roff_cond_text(ROFF_ARGS);
> static enum rofferr roff_cond_sub(ROFF_ARGS);
> +static enum rofferr roff_ds(ROFF_ARGS);
> static enum rofferr roff_line(ROFF_ARGS);
> static enum rofferr roff_nr(ROFF_ARGS);
> static enum roffrule roff_evalcond(const char *, int *);
> @@ -135,7 +142,7 @@ static struct roffmac roffs[ROFF_MAX] =
> { "de", roff_block, roff_block_text, roff_block_sub, 0, NULL },
> { "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL },
> { "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
> - { "ds", roff_line, NULL, NULL, 0, NULL },
> + { "ds", roff_ds, NULL, NULL, 0, NULL },
> { "el", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
> { "ie", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
> { "if", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
> @@ -268,6 +275,7 @@ roff_free1(struct roff *r)
>
> while (r->last)
> roffnode_pop(r);
> + roff_freestr();
> }
>
>
> @@ -879,6 +887,39 @@ roff_cond(ROFF_ARGS)
>
> /* ARGSUSED */
> static enum rofferr
> +roff_ds(ROFF_ARGS)
> +{
> + char *name, *string, *end;
> +
> + name = *bufp + pos;
> + if ('\0' == *name)
> + return(ROFF_IGN);
> +
> + string = name;
> + while (*string && ' ' != *string)
> + string++;
> + if (*string)
> + *(string++) = NULL;
> + if (*string && '"' == *string)
> + string++;
> + while (*string && ' ' == *string)
> + string++;
> + end = string;
> + while (*end)
> + end++;
> + if (string < end) {
> + end--;
> + if (*end == '"')
> + *end = '\0';
> + }
> +
> + roff_setstr(name, string);
> + return(ROFF_IGN);
> +}
> +
> +
> +/* ARGSUSED */
> +static enum rofferr
> roff_nr(ROFF_ARGS)
> {
> const char *key, *val;
> @@ -917,4 +958,76 @@ roff_nr(ROFF_ARGS)
> ROFF_DEBUG("roff: ignoring register: %s\n", key);
>
> return(ROFF_IGN);
> +}
> +
> +
> +char *
> +roff_setstr(const char *name, const char *string)
> +{
> + struct roffstr *n;
> + char *namecopy;
> +
> + n = first_string;
> + while (n && strcmp(name, n->name))
> + n = n->next;
> + if (n) {
> + free(n->string);
> + } else {
> + if (NULL == (namecopy = strdup(name)))
> + return(NULL);
> + if (NULL == (n = malloc(sizeof(struct roffstr)))) {
> + free(n);
> + return(NULL);
> + }
> + n->name = namecopy;
> + n->next = first_string;
> + first_string = n;
> + }
> + if (string)
> + n->string = strdup(string);
> + else
> + n->string = NULL;
> + return(n->string);
> +}
> +
> +char *
> +roff_getstr(const char *name)
> +{
> + struct roffstr *n;
> +
> + n = first_string;
> + while (n && strcmp(name, n->name))
> + n = n->next;
> + if (n)
> + return(n->string);
> + else
> + return(NULL);
> +}
> +
> +char *
> +roff_getstrn(const char *name, size_t len)
> +{
> + struct roffstr *n;
> +
> + n = first_string;
> + while (n && (strncmp(name, n->name, len) || '\0' != n->name[len]))
> + n = n->next;
> + if (n)
> + return(n->string);
> + else
> + return(NULL);
> +}
> +
> +void
> +roff_freestr(void)
> +{
> + struct roffstr *n, *nn;
> +
> + for (n = first_string; n; n = nn) {
> + free(n->name);
> + free(n->string);
> + nn = n->next;
> + free(n);
> + }
> + first_string = NULL;
> }
> --
> To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-07-25 19:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-03 16:02 mdocml: Rudimentary implementation of user-defined strings; no time for schwarze
2010-07-03 16:12 ` Kristaps Dzonsons
2010-07-03 16:21 ` Ingo Schwarze
2010-07-03 16:27 ` Kristaps Dzonsons
2010-07-15 16:53 ` Joerg Sonnenberger
2010-07-25 18:58 ` Joerg Sonnenberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).