Bury StringBuf inside librpmbuild internals
This commit is contained in:
parent
b2a688ee00
commit
21e0e5cd48
79
build/misc.c
79
build/misc.c
|
@ -5,9 +5,88 @@
|
|||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <rpm/rpmstring.h>
|
||||
#include "build/rpmbuild_misc.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define BUF_CHUNK 1024
|
||||
|
||||
struct StringBufRec {
|
||||
char *buf;
|
||||
char *tail; /* Points to first "free" char */
|
||||
int allocated;
|
||||
int free;
|
||||
};
|
||||
|
||||
StringBuf newStringBuf(void)
|
||||
{
|
||||
StringBuf sb = xmalloc(sizeof(*sb));
|
||||
|
||||
sb->free = sb->allocated = BUF_CHUNK;
|
||||
sb->buf = xcalloc(sb->allocated, sizeof(*sb->buf));
|
||||
sb->buf[0] = '\0';
|
||||
sb->tail = sb->buf;
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
StringBuf freeStringBuf(StringBuf sb)
|
||||
{
|
||||
if (sb) {
|
||||
sb->buf = _free(sb->buf);
|
||||
sb = _free(sb);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
void truncStringBuf(StringBuf sb)
|
||||
{
|
||||
sb->buf[0] = '\0';
|
||||
sb->tail = sb->buf;
|
||||
sb->free = sb->allocated;
|
||||
}
|
||||
|
||||
void stripTrailingBlanksStringBuf(StringBuf sb)
|
||||
{
|
||||
while (sb->free != sb->allocated) {
|
||||
if (! risspace(*(sb->tail - 1)))
|
||||
break;
|
||||
sb->free++;
|
||||
sb->tail--;
|
||||
}
|
||||
sb->tail[0] = '\0';
|
||||
}
|
||||
|
||||
char * getStringBuf(StringBuf sb)
|
||||
{
|
||||
return sb->buf;
|
||||
}
|
||||
|
||||
void appendStringBufAux(StringBuf sb, const char *s, int nl)
|
||||
{
|
||||
int l;
|
||||
|
||||
l = strlen(s);
|
||||
/* If free == l there is no room for NULL terminator! */
|
||||
while ((l + nl + 1) > sb->free) {
|
||||
sb->allocated += BUF_CHUNK;
|
||||
sb->free += BUF_CHUNK;
|
||||
sb->buf = xrealloc(sb->buf, sb->allocated);
|
||||
sb->tail = sb->buf + (sb->allocated - sb->free);
|
||||
}
|
||||
|
||||
/* FIX: shrug */
|
||||
strcpy(sb->tail, s);
|
||||
sb->tail += l;
|
||||
sb->free -= l;
|
||||
if (nl) {
|
||||
sb->tail[0] = '\n';
|
||||
sb->tail[1] = '\0';
|
||||
sb->tail++;
|
||||
sb->free--;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t parseUnsignedNum(const char * line, uint32_t * res)
|
||||
{
|
||||
char * s1 = NULL;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <rpm/rpmbuild.h>
|
||||
#include <rpm/rpmutil.h>
|
||||
#include "build/rpmbuild_misc.h"
|
||||
|
||||
struct TriggerFileEntry {
|
||||
int index;
|
||||
|
|
|
@ -76,6 +76,48 @@ gid_t getGidS(const char * gname);
|
|||
RPM_GNUC_INTERNAL
|
||||
void handleComments(char * s);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
typedef struct StringBufRec *StringBuf;
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
RPM_GNUC_INTERNAL
|
||||
StringBuf newStringBuf(void);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
RPM_GNUC_INTERNAL
|
||||
StringBuf freeStringBuf( StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
RPM_GNUC_INTERNAL
|
||||
void truncStringBuf(StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
RPM_GNUC_INTERNAL
|
||||
char * getStringBuf(StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
RPM_GNUC_INTERNAL
|
||||
void stripTrailingBlanksStringBuf(StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
#define appendStringBuf(sb, s) appendStringBufAux(sb, s, 0)
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
#define appendLineStringBuf(sb, s) appendStringBufAux(sb, s, 1)
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
RPM_GNUC_INTERNAL
|
||||
void appendStringBufAux(StringBuf sb, const char * s, int nl);
|
||||
|
||||
/** \ingroup rpmbuild
|
||||
* Parse an unsigned number.
|
||||
* @param line from spec file
|
||||
|
|
|
@ -10,14 +10,6 @@
|
|||
#include <rpm/rpmstring.h>
|
||||
#include "debug.h"
|
||||
|
||||
#define BUF_CHUNK 1024
|
||||
|
||||
struct StringBufRec {
|
||||
char *buf;
|
||||
char *tail; /* Points to first "free" char */
|
||||
int allocated;
|
||||
int free;
|
||||
};
|
||||
|
||||
char * stripTrailingChar(char * s, char c)
|
||||
{
|
||||
|
@ -27,75 +19,6 @@ char * stripTrailingChar(char * s, char c)
|
|||
return s;
|
||||
}
|
||||
|
||||
StringBuf newStringBuf(void)
|
||||
{
|
||||
StringBuf sb = xmalloc(sizeof(*sb));
|
||||
|
||||
sb->free = sb->allocated = BUF_CHUNK;
|
||||
sb->buf = xcalloc(sb->allocated, sizeof(*sb->buf));
|
||||
sb->buf[0] = '\0';
|
||||
sb->tail = sb->buf;
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
StringBuf freeStringBuf(StringBuf sb)
|
||||
{
|
||||
if (sb) {
|
||||
sb->buf = _free(sb->buf);
|
||||
sb = _free(sb);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
void truncStringBuf(StringBuf sb)
|
||||
{
|
||||
sb->buf[0] = '\0';
|
||||
sb->tail = sb->buf;
|
||||
sb->free = sb->allocated;
|
||||
}
|
||||
|
||||
void stripTrailingBlanksStringBuf(StringBuf sb)
|
||||
{
|
||||
while (sb->free != sb->allocated) {
|
||||
if (! risspace(*(sb->tail - 1)))
|
||||
break;
|
||||
sb->free++;
|
||||
sb->tail--;
|
||||
}
|
||||
sb->tail[0] = '\0';
|
||||
}
|
||||
|
||||
char * getStringBuf(StringBuf sb)
|
||||
{
|
||||
return sb->buf;
|
||||
}
|
||||
|
||||
void appendStringBufAux(StringBuf sb, const char *s, int nl)
|
||||
{
|
||||
int l;
|
||||
|
||||
l = strlen(s);
|
||||
/* If free == l there is no room for NULL terminator! */
|
||||
while ((l + nl + 1) > sb->free) {
|
||||
sb->allocated += BUF_CHUNK;
|
||||
sb->free += BUF_CHUNK;
|
||||
sb->buf = xrealloc(sb->buf, sb->allocated);
|
||||
sb->tail = sb->buf + (sb->allocated - sb->free);
|
||||
}
|
||||
|
||||
/* FIX: shrug */
|
||||
strcpy(sb->tail, s);
|
||||
sb->tail += l;
|
||||
sb->free -= l;
|
||||
if (nl) {
|
||||
sb->tail[0] = '\n';
|
||||
sb->tail[1] = '\0';
|
||||
sb->tail++;
|
||||
sb->free--;
|
||||
}
|
||||
}
|
||||
|
||||
int rstrcasecmp(const char * s1, const char * s2)
|
||||
{
|
||||
const char * p1 = s1;
|
||||
|
|
|
@ -180,42 +180,6 @@ size_t rstrlcpy(char *dest, const char *src, size_t n);
|
|||
*/
|
||||
char * stripTrailingChar(char * s, char c);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
typedef struct StringBufRec *StringBuf;
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
StringBuf newStringBuf(void);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
StringBuf freeStringBuf( StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
void truncStringBuf(StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
char * getStringBuf(StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
void stripTrailingBlanksStringBuf(StringBuf sb);
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
#define appendStringBuf(sb, s) appendStringBufAux(sb, s, 0)
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
#define appendLineStringBuf(sb, s) appendStringBufAux(sb, s, 1)
|
||||
|
||||
/** \ingroup rpmstring
|
||||
*/
|
||||
void appendStringBufAux(StringBuf sb, const char * s, int nl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue