18 #include <gwenhywfar/debug.h> 19 #include <gwenhywfar/syncio.h> 20 #include <gwenhywfar/process.h> 21 #include <gwenhywfar/directory.h> 22 #include <gwenhywfar/text.h> 30 #include <sys/types.h> 59 GWB_KEYVALUEPAIR_LIST *givenOptionList)
72 if (xmlNewFile==
NULL) {
73 DBG_ERROR(
NULL,
"No valid node found in build file of folder \"%s\"", srcDir);
78 if (xmlProject==
NULL) {
79 DBG_ERROR(
NULL,
"No project node found in build file of folder \"%s\"", srcDir);
95 DBG_ERROR(
NULL,
"Error parsing build tree in folder \"%s\"", srcDir);
184 if (xmlGwbuildNode==
NULL) {
206 if (vCurrent<vRequired) {
207 DBG_ERROR(
NULL,
"Minimum GWENBUILD version required is %x", vRequired);
216 const char *buildDir;
217 const char *initialSourceDir;
237 return xmlGwbuildNode;
245 unsigned int vmajor=0;
246 unsigned int vminor=0;
247 unsigned int vpatchlevel=0;
280 return (
int) ((vmajor<<16)+(vminor<<8)+(vpatchlevel));
291 while(*p && *p!=
'.') {
405 if (sFolder && *sFolder) {
410 DBG_ERROR(
NULL,
"Could not create folder \"%s\" in build tree", sFolder);
413 if (chdir(sFolder)==-1) {
414 DBG_ERROR(
NULL,
"Could not enter folder \"%s\" in build tree (%s)",
415 sFolder, strerror(errno));
445 fprintf(stdout,
"Entering folder \"%s\"\n", sFolder);
447 if (xmlNewFile==
NULL) {
448 DBG_ERROR(
NULL,
"No valid node found in build file of subdir \"%s\"", sFolder);
459 rv=fn(project, newContext, xmlNewFile);
468 GWB_Context_Tree2_AddChild(currentContext, newContext);
469 fprintf(stdout,
"Leaving folder \"%s\"\n", sFolder);
485 if (!(sName && *sName)) {
492 "%s: Please dont use property \"value\", just store the value between <setVar> and </setVar>",
500 if (strcasecmp(sMode,
"replace")==0)
502 else if (strcasecmp(sMode,
"add")==0)
504 else if (strcasecmp(sMode,
"append")==0)
509 if (strcasecmp(sMode,
"replace")==0) {
522 const char *sPattern;
523 const char *sValueInDb;
535 if (!(sName && *sName)) {
541 if (!(sPattern && *sPattern)) {
547 if (!(sValueInDb && *sValueInDb)) {
548 DBG_ERROR(
NULL,
"No value for \"%s\" in db for <ifVarMatches>", sName);
553 rv=fn(project, currentContext, xmlThen?xmlThen:xmlNode);
561 rv=fn(project, currentContext, xmlElse);
577 const char *sPattern;
578 const char *sValueInDb;
590 if (!(sName && *sName)) {
596 if (!(sPattern && *sPattern)) {
602 if (!(sValueInDb && *sValueInDb)) {
603 DBG_ERROR(
NULL,
"No value for \"%s\" in db for <ifVarMatches>", sName);
608 rv=fn(project, currentContext, xmlThen?xmlThen:xmlNode);
616 rv=fn(project, currentContext, xmlElse);
641 return fn(project, currentContext, xmlThen?xmlThen:xmlNode);
645 return fn(project, currentContext, xmlElse);
664 return fn(project, currentContext, xmlThen?xmlThen:xmlNode);
668 return fn(project, currentContext, xmlElse);
678 const char *sPattern;
685 if (!(sName && *sName)) {
691 if (!(sPattern && *sPattern)) {
696 for (i=0; i<100; i++) {
697 const char *sValueInDb;
713 const char *fileName;
714 const char *currentSrcDir;
723 if (!(fileName && *fileName)) {
731 if (currentSrcDir && *currentSrcDir) {
773 DBG_ERROR(
NULL,
"Could not write \"%s\" (%d)", fileName, rv);
782 DBG_ERROR(
NULL,
"Could not set perms for \"%s\" (%d)", fileName, rv);
817 if (lstat(fname, &st) == -1) {
818 DBG_ERROR(
NULL,
"Error on stat(\"%s\"): %d (%s)", fname, errno, strerror(errno));
822 return (
int)((st.st_mode & ~S_IFMT));
829 if (chmod(fname, perms) == -1) {
830 DBG_ERROR(
NULL,
"Error on chmod(\"%s\"): %d (%s)", fname, errno, strerror(errno));
896 while (*p && *p!=
'@')
912 rawName=(
char *) malloc(len+1);
914 memmove(rawName, pStart, len);
922 DBG_WARN(
NULL,
"Warning: Empty value for DB var \"%s\"", rawName);
950 if (strcasecmp(name,
"writeFile")==0)
952 else if (strcasecmp(name,
"setVar")==0)
954 else if (strcasecmp(name,
"ifVarMatches")==0)
956 else if (strcasecmp(name,
"ifNotVarMatches")==0)
958 else if (strcasecmp(name,
"ifVarHasValue")==0)
960 else if (strcasecmp(name,
"ifNotVarHasValue")==0)
986 const char *installPath;
987 const char *fileType;
988 const char *currentFolder;
1004 if (installPath && *installPath)
1008 if (s && *s && (strcasecmp(s,
"true")==0 || strcasecmp(s,
"yes")==0))
1012 if (s && *s && (strcasecmp(s,
"true")==0 || strcasecmp(s,
"yes")==0))
1021 const char *sFileName;
1024 if (sFileName && *sFileName) {
int GWEN_DB_ReplaceVars(GWEN_DB_NODE *db, const char *s, GWEN_BUFFER *dbuf)
void GWB_Context_AddCurrentBuildDir(GWB_CONTEXT *ctx, const char *s)
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
#define GWENHYWFAR_VERSION_MAJOR
struct GWB_CONTEXT GWB_CONTEXT
#define GWEN_DB_FLAGS_OVERWRITE_VARS
void GWEN_DB_Dump(GWEN_DB_NODE *n, int insert)
GWEN_STRINGLIST * GWB_Parser_ReadXmlDataIntoStringList(GWEN_DB_NODE *db, GWEN_XMLNODE *xmlNode)
void GWB_Project_free(GWB_PROJECT *project)
struct GWEN_DB_NODE GWEN_DB_NODE
#define GWEN_XML_FLAGS_DEFAULT
#define GWEN_DIR_SEPARATOR_S
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
const char * GWEN_XMLNode_GetProperty(const GWEN_XMLNODE *n, const char *name, const char *defaultValue)
int(* GWB_PARSER_PARSE_ELEMENT_FN)(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode)
#define GWB_PARSER_FILENAME
void GWB_File_SetInstallPath(GWB_FILE *f, const char *s)
GWENBUILD * GWB_Project_GetGwbuild(const GWB_PROJECT *project)
GWEN_XMLNODE * GWEN_XMLNode_GetFirstData(const GWEN_XMLNODE *n)
GWB_CONTEXT * GWB_Parser_CopyContextForTarget(const GWB_CONTEXT *sourceContext)
GWEN_BUFFER * GWB_Parser_ReadNamedXmlDataIntoBufferAndExpand(GWEN_DB_NODE *db, GWEN_XMLNODE *xmlNode, const char *elem)
GWB_CONTEXT * GWB_Parser_CopyContextForSubdir(const GWB_CONTEXT *sourceContext, const char *folder)
void GWB_File_AddFlags(GWB_FILE *f, uint32_t i)
int GWEN_SyncIo_Helper_ReadFile(const char *fName, GWEN_BUFFER *dbuf)
GWB_PROJECT * GWB_Project_new(GWENBUILD *gwbuild, GWB_CONTEXT *ctx)
GWB_FILE * GWB_File_List2_GetOrCreateFile(GWB_FILE_LIST2 *fileList, const char *folder, const char *fname)
GWENHYWFAR_API int GWEN_XML_ReadFile(GWEN_XMLNODE *n, const char *filepath, uint32_t flags)
void GWB_File_SetFileType(GWB_FILE *f, const char *s)
void GWB_Context_ClearSourceFileList2(GWB_CONTEXT *ctx)
static int _readVersion(const char *s)
struct GWB_PROJECT GWB_PROJECT
#define DBG_WARN(dbg_logger, format, args...)
#define GWENHYWFAR_VERSION_PATCHLEVEL
static int _parseSubdir(GWB_PROJECT *project, GWB_CONTEXT *currentContext, const char *sFolder, GWB_PARSER_PARSE_ELEMENT_FN fn)
GWEN_XMLNODE * GWEN_XMLNode_new(GWEN_XMLNODE_TYPE t, const char *data)
#define GWB_FILE_FLAGS_DIST
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
int GWB_Parser_ParseSubdirs(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode, GWB_PARSER_PARSE_ELEMENT_FN fn)
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
static int _parseIfNotVarHasValue(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *n, GWB_PARSER_PARSE_ELEMENT_FN fn)
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
#define GWB_FILE_FLAGS_INSTALL
static int _parseIfVarMatches(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *n, GWB_PARSER_PARSE_ELEMENT_FN fn)
GWEN_BUFFER * GWB_Parser_ReadXmlDataIntoBufferAndExpand(GWEN_DB_NODE *db, GWEN_XMLNODE *xmlNode)
int GWB_Parser_ParseWellKnownElements(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *n, GWB_PARSER_PARSE_ELEMENT_FN fn)
#define GWEN_ERROR_BAD_DATA
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
GWB_FILE_LIST2 * GWB_Project_GetFileList(const GWB_PROJECT *project)
GWEN_XMLNODE * GWEN_XMLNode_FindFirstTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
GWEN_DB_NODE * GWB_Context_GetVars(const GWB_CONTEXT *ctx)
void GWB_Project_SetGivenOptionList(GWB_PROJECT *project, GWB_KEYVALUEPAIR_LIST *kvpList)
void GWB_File_SetBuilder(GWB_FILE *f, const char *s)
static int _readIntUntilPoint(const char **s)
static int _getFilePermissions(const char *fname)
const char * GWB_Context_GetInitialSourceDir(const GWB_CONTEXT *ctx)
#define DBG_DEBUG(dbg_logger, format, args...)
const char * GWB_Context_GetTopSourceDir(const GWB_CONTEXT *ctx)
void GWB_Context_AddCurrentRelativeDir(GWB_CONTEXT *ctx, const char *s)
int GWEN_DB_DeleteGroup(GWEN_DB_NODE *n, const char *path)
static int _parseIfVarHasValue(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *n, GWB_PARSER_PARSE_ELEMENT_FN fn)
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
#define GWEN_ERROR_GENERIC
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
GWEN_STRINGLIST * GWEN_StringList_fromString(const char *str, const char *delimiters, int checkDouble)
void GWB_Context_SetInitialSourceDir(GWB_CONTEXT *ctx, const char *s)
int GWB_ParseProject(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode)
void GWEN_Buffer_free(GWEN_BUFFER *bf)
int GWEN_DB_DeleteVar(GWEN_DB_NODE *n, const char *path)
void GWEN_XMLNode_free(GWEN_XMLNODE *n)
void GWEN_XMLNode_UnlinkChild(GWEN_XMLNODE *n, GWEN_XMLNODE *child)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
GWB_PROJECT * GWB_Parser_ReadBuildTree(GWENBUILD *gwbuild, GWB_CONTEXT *currentContext, const char *srcDir, GWB_KEYVALUEPAIR_LIST *givenOptionList)
#define DBG_ERROR(dbg_logger, format, args...)
static int _setFilePermissions(const char *fname, int perms)
void GWB_Context_InsertCurrentSourceDir(GWB_CONTEXT *ctx, const char *s)
void GWB_Context_SetCurrentSourceDir(GWB_CONTEXT *ctx, const char *s)
static int _parseSetVar(GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode)
const char * GWEN_XMLNode_GetData(const GWEN_XMLNODE *n)
GWEN_XMLNODE * GWB_Parser_ReadBuildFile(GWENBUILD *gwbuild, const GWB_CONTEXT *currentContext, const char *fileName)
void GWB_Context_AddCurrentSourceDir(GWB_CONTEXT *ctx, const char *s)
static int _parseWriteFile(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode)
int GWEN_Text_ComparePattern(const char *w, const char *p, int sensecase)
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
GWB_CONTEXT * GWB_Context_dup(const GWB_CONTEXT *originalCtx)
void GWB_Context_InsertTopBuildDir(GWB_CONTEXT *ctx, const char *s)
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
static int _varHasValue(GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode)
#define DBG_INFO(dbg_logger, format, args...)
#define GWENHYWFAR_VERSION_MINOR
void GWB_Context_InsertTopSourceDir(GWB_CONTEXT *ctx, const char *s)
GWENHYWFAR_API int GWEN_Directory_GetPath(const char *path, unsigned int flags)
const char * GWB_Context_GetTopBuildDir(const GWB_CONTEXT *ctx)
void GWB_Parser_SetItemValue(GWEN_DB_NODE *db, const char *sId, const char *suffix, const char *value)
int GWB_Parser_ReplaceVarsBetweenAtSigns(const char *s, GWEN_BUFFER *dbuf, GWEN_DB_NODE *db)
static void _appendVarValue(GWEN_DB_NODE *db, const char *name, const char *newValue)
int GWEN_XMLNode_ExpandProperties(const GWEN_XMLNODE *n, GWEN_DB_NODE *dbVars)
const char * GWB_Context_GetCurrentRelativeDir(const GWB_CONTEXT *ctx)
struct GWENBUILD GWENBUILD
void GWB_Context_ClearDefineList(GWB_CONTEXT *ctx)
void GWB_Context_free(GWB_CONTEXT *ctx)
void GWB_Context_AddSourceFile(GWB_CONTEXT *ctx, GWB_FILE *f)
void GWBUILD_AddBuildFilename(GWENBUILD *gwenbuild, const char *s)
struct GWEN__XMLNODE GWEN_XMLNODE
int GWEN_SyncIo_Helper_WriteFile(const char *fName, const uint8_t *ptrSource, uint64_t lenSource)
#define GWB_FILE_FLAGS_GENERATED
void GWB_Context_ClearIncludeList(GWB_CONTEXT *ctx)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
const char * GWB_Context_GetCurrentSourceDir(const GWB_CONTEXT *ctx)
int GWB_Parser_ParseSourcesOrHeaders(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *xmlNode, int alwaysDist, int isSource)
const char * GWB_Context_GetCurrentBuildDir(const GWB_CONTEXT *ctx)
static int _parseIfNotVarMatches(GWB_PROJECT *project, GWB_CONTEXT *currentContext, GWEN_XMLNODE *n, GWB_PARSER_PARSE_ELEMENT_FN fn)
void GWB_Context_SetTopSourceDir(GWB_CONTEXT *ctx, const char *s)