Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doxygen2man: Add support for @code blocks #417

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doxygen2man/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = doxygen2man.1

bin_PROGRAMS = doxygen2man
noinst_HEADERS = cstring.h

all: $(PROGRAMS) $(MANS)

doxygen2man_SOURCES = doxygen2man.c
doxygen2man_SOURCES = doxygen2man.c cstring.c
doxygen2man_CPPFLAGS = -I$(top_srcdir)/include/
doxygen2man_CFLAGS = $(AM_CFLAGS) $(libxml_CFLAGS)
doxygen2man_LDADD = $(top_builddir)/lib/libqb.la $(libxml_LIBS)
Expand Down
118 changes: 118 additions & 0 deletions doxygen2man/cstring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* A really basic expanding/appendable string type */

#include <stdlib.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <time.h>
#include <assert.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
#include "cstring.h"

#define INITIAL_SIZE 1024
#define INCREMENT 1024
#define CHECKER_WORD 0xbcd6712a

struct cstring_header
{
size_t checker;
size_t allocated;
size_t used;
char the_string[];
};

cstring_t cstring_alloc(void)
{
char *cstring = malloc(INITIAL_SIZE);
if (cstring) {
struct cstring_header *h = (struct cstring_header *)cstring;
h->checker = CHECKER_WORD;
h->allocated = INITIAL_SIZE;
h->used = 0;
h->the_string[0] = '\0';
return cstring;
} else {
return NULL;
}
}

char *cstring_to_chars(cstring_t cstring)
{
struct cstring_header *h = (struct cstring_header *)(char *)cstring;

if (!h) {
return NULL;
}

assert(h->checker == CHECKER_WORD);
return strdup(h->the_string);
}

cstring_t cstring_append_chars(cstring_t cstring, const char *newstring)
{
struct cstring_header *h = (struct cstring_header *)(char *)cstring;
size_t newlen;

if (!h) {
return NULL;
}

assert(h->checker == CHECKER_WORD);
if (!newstring) {
return NULL;
}

newlen = h->used + strlen(newstring)+1 + sizeof(struct cstring_header);
if (newlen > h->allocated) {
size_t new_allocsize = (newlen + 2048) & 0xFFFFFC00;
char *tmp = realloc(cstring, new_allocsize);
if (!tmp) {
return cstring;
}

cstring = tmp;
h = (struct cstring_header *)(char *)cstring;
h->allocated = new_allocsize;
}
strncat(h->the_string, newstring, h->allocated-1);
h->used += strlen(newstring);
return cstring;
}

cstring_t cstring_append_cstring(cstring_t cstring, cstring_t newstring)
{
/* Just check the newstring - cstring_append_chars() will check the target */
struct cstring_header *h = (struct cstring_header *)(char *)newstring;

if (!h) {
return NULL;
}

assert(h->checker == CHECKER_WORD);
return cstring_append_chars(cstring, h->the_string);
}

cstring_t cstring_from_chars(const char* chars)
{
cstring_t new_string = cstring_alloc();
if (!new_string) {
return NULL;
}
return cstring_append_chars(new_string, chars);
}

void cstring_free(cstring_t cstring)
{
struct cstring_header *h = (struct cstring_header *)(char *)cstring;

if (!h) {
return;
}
assert(h->checker == CHECKER_WORD);
free(cstring);
}


14 changes: 14 additions & 0 deletions doxygen2man/cstring.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __CSTRING_H__
#define __CSTRING_H__

typedef void* cstring_t;

cstring_t cstring_alloc(void);
cstring_t cstring_from_chars(const char* chars);
cstring_t cstring_dup(cstring_t string);
char *cstring_to_chars(cstring_t cstring);
cstring_t cstring_append_chars(cstring_t cstring, const char *newstring);
cstring_t cstring_append_cstring(cstring_t cstring, cstring_t newstring);
void cstring_free(cstring_t cstring);

#endif
Loading