mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-25 13:07:32 +02:00
b2/: move variable-length strings to vstring.[ch], for sharing
This commit is contained in:
parent
8e6357f4fa
commit
4e39ca2e31
@ -14,7 +14,7 @@ SHELL = /bin/bash
|
||||
CFLAGS = -g -Wall $(shell pkg-config --cflags glib-2.0)
|
||||
SLOPPY = -Wno-unused -Wno-implicit-function-declaration
|
||||
OBJS = boom.o chr.o comp.o db.o dump.o eval.o param.o subex.o subst.o util.o \
|
||||
lex.yy.o y.tab.o
|
||||
vstring.o lex.yy.o y.tab.o
|
||||
LDLIBS = -lfl $(shell pkg-config --libs glib-2.0)
|
||||
|
||||
YACC = bison -y
|
||||
|
28
b2/subex.c
28
b2/subex.c
@ -17,6 +17,7 @@
|
||||
#include <regex.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "vstring.h"
|
||||
#include "lang.h"
|
||||
#include "subst.h"
|
||||
#include "subex.h"
|
||||
@ -31,33 +32,6 @@ static const char *fn = NULL, *f[FIELDS];
|
||||
static struct subst jump_end;
|
||||
|
||||
|
||||
static void append_n(char **res, int *res_len, const char *s, int len)
|
||||
{
|
||||
if (!len)
|
||||
return;
|
||||
*res = realloc(*res, *res_len+len+1);
|
||||
if (!*res)
|
||||
abort();
|
||||
memcpy(*res+*res_len, s, len);
|
||||
*res_len += len;
|
||||
(*res)[*res_len] = 0;
|
||||
}
|
||||
|
||||
|
||||
static void append(char **res, int *res_len, const char *s)
|
||||
{
|
||||
append_n(res, res_len, s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
static void append_char(char **res, int *res_len, char c)
|
||||
{
|
||||
append_n(res, res_len, &c, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* TODO: decide what to do with units
|
||||
*/
|
||||
|
37
b2/vstring.c
Normal file
37
b2/vstring.c
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* vstring.c - Variable-length strings
|
||||
*
|
||||
* Copyright 2012 by Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vstring.h"
|
||||
|
||||
|
||||
void append_n(char **res, int *res_len, const char *s, int len)
|
||||
{
|
||||
if (!len)
|
||||
return;
|
||||
if (!*res)
|
||||
*res_len = 0;
|
||||
*res = realloc(*res, *res_len+len+1);
|
||||
if (!*res)
|
||||
abort();
|
||||
memcpy(*res+*res_len, s, len);
|
||||
*res_len += len;
|
||||
(*res)[*res_len] = 0;
|
||||
}
|
||||
|
||||
|
||||
void append(char **res, int *res_len, const char *s)
|
||||
{
|
||||
append_n(res, res_len, s, strlen(s));
|
||||
}
|
25
b2/vstring.h
Normal file
25
b2/vstring.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* vstring.h - Variable-length strings
|
||||
*
|
||||
* Copyright 2012 by Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef VSTRING_H
|
||||
#define VSTRING_H
|
||||
|
||||
|
||||
void append_n(char **res, int *res_len, const char *s, int len);
|
||||
void append(char **res, int *res_len, const char *s);
|
||||
|
||||
|
||||
static inline void append_char(char **res, int *res_len, char c)
|
||||
{
|
||||
append_n(res, res_len, &c, 1);
|
||||
}
|
||||
|
||||
#endif /* !VSTRING_H */
|
Loading…
Reference in New Issue
Block a user