#include <string.h>
#include <malloc.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <regex.h>
#include "spec.h"
#include "package.h"
static int parseForLang(char *buf, struct FileList *fl);
static int parseForAttr(char *buf, struct FileList *fl);
static int parseForConfig(char *buf, struct FileList *fl);
+static int parseForRegexLang(char *fileName, char **lang);
static int myGlobPatternP(char *pattern);
static int glob_error(const char *foo, int bar);
static void timeCheck(int tc, Header h);
int_16 fileMode;
int fileUid, fileGid;
char *fileUname, *fileGname;
+ char *lang;
strcpy(fileName, cleanFileName(name));
fl->fileList[fl->fileListRecsUsed].uname = fileUname;
fl->fileList[fl->fileListRecsUsed].gname = fileGname;
- fl->fileList[fl->fileListRecsUsed].lang =
- strdup(fl->currentLang ? fl->currentLang : "");
-
+ if (fl->currentLang) {
+ fl->fileList[fl->fileListRecsUsed].lang = strdup(fl->currentLang);
+ } else if (! parseForRegexLang(fileName, &lang)) {
+ fl->fileList[fl->fileListRecsUsed].lang = strdup(lang);
+ } else {
+ fl->fileList[fl->fileListRecsUsed].lang = strdup("");
+ }
+
fl->fileList[fl->fileListRecsUsed].flags = fl->currentFlags;
fl->fileList[fl->fileListRecsUsed].verifyFlags =
fl->currentVerifyFlags;
return 0;
}
+static int parseForRegexLang(char *fileName, char **lang)
+{
+ static int initialized = 0;
+ static int hasRegex = 0;
+ static regex_t compiledPatt;
+ static char buf[BUFSIZ];
+ int x;
+ regmatch_t matches[2];
+ char *patt, *s;
+
+ if (! initialized) {
+ initialized = 1;
+ patt = rpmGetVar(RPMVAR_LANGPATT);
+ if (! patt) {
+ return 1;
+ }
+ if (regcomp(&compiledPatt, patt, REG_EXTENDED)) {
+ return -1;
+ }
+ hasRegex = 1;
+ }
+
+ if (! hasRegex) {
+ return 1;
+ }
+
+ if (! regexec(&compiledPatt, fileName, 2, matches, REG_NOTEOL)) {
+ /* Got match */
+ s = fileName + matches[1].rm_eo - 1;
+ x = matches[1].rm_eo - matches[1].rm_so;
+ buf[x] = '\0';
+ while (x) {
+ buf[--x] = *s--;
+ }
+ *lang = buf;
+ return 0;
+ }
+
+ return 1;
+}
+
static int parseForLang(char *buf, struct FileList *fl)
{
char *p, *start, *end;
#define RPMVAR_BUILDSHELL 39
#define RPMVAR_INSTCHANGELOG 40
#define RPMVAR_BZIP2BIN 41
+#define RPMVAR_LANGPATT 42
-#define RPMVAR_NUM 42 /* number of RPMVAR entries */
+#define RPMVAR_NUM 43 /* number of RPMVAR entries */
char * rpmGetVar(int var);
int rpmGetBooleanVar(int var);
{ "ftpproxy", RPMVAR_FTPPROXY, 0, 0 },
{ "gzipbin", RPMVAR_GZIPBIN, 0, 1 },
{ "instchangelog", RPMVAR_INSTCHANGELOG, 0, 0 },
+ { "langpatt", RPMVAR_LANGPATT, 0, 0 },
{ "messagelevel", RPMVAR_MESSAGELEVEL, 0, 0 },
{ "netsharedpath", RPMVAR_NETSHAREDPATH, 0, 0 },
{ "optflags", RPMVAR_OPTFLAGS, 1, 0 },