summaryrefslogtreecommitdiff
path: root/setup_native
diff options
context:
space:
mode:
authorEilidh McAdam <eilidh@lanedo.com>2012-07-02 18:53:12 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2012-07-18 11:00:08 +0200
commit9167f0a1a89ee2567449e4bd8bd21b02d8316be1 (patch)
treef237f75281486afc4b928dd454b23da3e0affa3c /setup_native
parent2921203806ce262696ae2c10c19ad456bcaac375 (diff)
Initial makecab implementation to parse .ddf files.
Currently, makecab does not output .cab files. A subset of the ddf format is interpreted. Change-Id: Iae11aefb4759a0eb76f9455b2206b59864086af5 Signed-off-by: Fridrich Štrba <fridrich.strba@bluewin.ch>
Diffstat (limited to 'setup_native')
-rw-r--r--setup_native/source/win32/wintools/makecab/makecab.c373
-rw-r--r--setup_native/source/win32/wintools/makecab/parseddf.c374
-rw-r--r--setup_native/source/win32/wintools/makecab/parseddf.h36
3 files changed, 783 insertions, 0 deletions
diff --git a/setup_native/source/win32/wintools/makecab/makecab.c b/setup_native/source/win32/wintools/makecab/makecab.c
new file mode 100644
index 000000000000..f4579dab2057
--- /dev/null
+++ b/setup_native/source/win32/wintools/makecab/makecab.c
@@ -0,0 +1,373 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/***********************************************************************
+ * msidb.exe
+ *
+ * Needs -mconsole. See ipconfig.c in wine/programs/ipconfig
+ *
+ * Copyright 2012 Eilidh McAdam (eilidh@lanedo.com)
+ *
+ **********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+#include <zlib.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "parseddf.h"
+
+#define _O_RDONLY 0
+#define _O_WRONLY 1
+#define _O_RDWR 2
+#define _O_CREAT 0x0100
+
+#define _A_RDONLY 1
+#define _A_HIDDEN 2
+#define _A_SYSTEM 4
+#define _A_ARCH 0x20
+
+typedef enum CABLOGLEVEL { CABLOG_ERR = 1, CABLOG_WRN, CABLOG_MSG } CABLOGLEVEL;
+typedef enum CABERR { CAB_OK, CABERR_DDF_UNOPENED } CABERR;
+static unsigned int CabVerb = 0;
+static const char * FCI_ERRS[] = {"None", "Error opening source file", "Error reading source file", "Error allocating memory", "Error creating temporary file", "Unknown compression type specified", "Error creating cabinet file", "Compression was manually aborted", "Error compressing data", "Cabinet data size or file count limits exceeded"};
+
+void cabLog(CABLOGLEVEL lvl, char * msg, ...)
+{
+ va_list args;
+ if (CabVerb < lvl) return;
+
+ switch (lvl)
+ {
+ case CABLOG_WRN: printf("[Warning] "); break;
+ case CABLOG_ERR: printf("[Error] "); break;
+ }
+
+ va_start(args, msg);
+ vprintf(msg, args);
+ va_end(args);
+ printf("\n");
+}
+
+void cabLogErr(PERF erf, char * msg)
+{
+ if (!erf)
+ {
+ cabLog(CABLOG_ERR, "%s: An unknown problem occurred");
+ return;
+ }
+
+ if (erf->erfOper >= 0)
+ {
+ if (erf->erfOper < (sizeof(FCI_ERRS)/sizeof(FCI_ERRS[0])))
+ cabLog(CABLOG_ERR, "%s: %s", msg, FCI_ERRS[erf->erfOper]);
+ else
+ cabLog(CABLOG_ERR, "%s: Unknown error", msg);
+ }
+}
+
+void cabLogCCAB(PCCAB cc)
+{
+ cabLog(CABLOG_MSG,
+ "cb %ld\n"
+ "cbFolderThresh %ld\n"
+ "cbReserveCFHeader %d\n"
+ "cbReserveCFFolder %d\n"
+ "cbReserveCFData %d\n"
+ "iCab %d\n"
+ "iDisk %d\n"
+ "setID %d\n"
+ "szDisk %s\n"
+ "szCab %s\n"
+ "szCabPath %s\n",
+ cc->cb, cc->cbFolderThresh, cc->cbReserveCFHeader,
+ cc->cbReserveCFFolder, cc->cbReserveCFData, cc->iCab,
+ cc->iDisk, cc->setID, cc->szDisk, cc->szCab, cc->szCabPath);
+}
+
+FNFCIALLOC (fnMemAlloc) /*(ULONG cb)*/
+{
+ return malloc(cb);
+}
+
+FNFCIFREE (fnMemFree) /*(void HUGE *memory)*/
+{
+ free(memory);
+}
+
+FNFCIOPEN (fnOpen) /*(char *pszFile, int oflag, int pmode, int *err, void *pv)*/
+{
+ FILE * f = NULL;
+ char * mode = "r+";
+ printf("DEBUG: fnOpen file %s\n", pszFile);
+ if (oflag & _O_WRONLY) mode = "w";
+ else if (oflag & _O_RDWR) mode = "r+";
+ else if (oflag & _O_RDONLY) mode = "r";
+
+ if (oflag & _O_CREAT && oflag & _O_RDWR) mode = "w+";
+
+ f = fopen(pszFile, mode);
+ if (f == NULL)
+ {
+ cabLog(CABLOG_ERR, "Could not get handle to file %s", pszFile);
+ *err = -1;
+ }
+
+ return (INT_PTR) f;
+}
+
+FNFCIREAD (fnRead) /*(INT_PTR hf, void FAR *memory, UINT cb, int FAR *err, void FAR *pv)*/
+{
+ FILE * f = (FILE *)hf;
+ size_t r = fread(memory, 1, cb, f);
+ printf("DEBUG: fnRead\n");
+ if (r < cb)
+ {
+ if (feof(f))
+ {
+ cabLog(CABLOG_WRN, "Reached EOF while reading file (%d chars remain of %d requested)", r, cb);
+ return r;
+ }
+ else if (ferror(f))
+ {
+ cabLog(CABLOG_ERR, "Error while reading file");
+ }
+ *err = -1;
+ return -1;
+ }
+ return r;
+}
+
+FNFCIWRITE (fnWrite) /*(INT_PTR hf, void FAR *memory, UINT cb, int FAR *err, void FAR *pv)*/
+{
+ unsigned int c;
+ printf("DEBUG: fnWrite\n");
+ if ( !(hf && (c = fwrite(memory, 1, sizeof(memory), (FILE *)hf))) )
+ {
+ if(c < cb)
+ {
+ *err = -1;
+ return -1;
+ }
+ }
+ return cb;
+}
+
+FNFCICLOSE (fnClose) /*(INT_PTR hf, int FAR *err, void FAR *pv)*/
+{
+ printf("DEBUG: fnClose\n");
+ if ( !(hf && fclose((FILE *)hf) != EOF) )
+ {
+ *err = -1;
+ return -1;
+ }
+ return 0;
+}
+
+FNFCISEEK (fnSeek) /*(INT_PTR hf, long dist, int seektype, int FAR *err, void FAR *pv)*/
+{
+ printf("DEBUG: fnSeek\n");
+ if (fseek((FILE *)hf, dist, seektype) != 0)
+ {
+ *err = -1;
+ return -1;
+ }
+ return 0;
+}
+
+FNFCIDELETE (fnDelete) /*(LPSTR pszFile, int FAR *err, void FAR *pv)*/
+{
+ printf("DEBUG: fnDelete\n");
+ if (remove(pszFile) != 0)
+ {
+ *err = -1;
+ return -1;
+ }
+ return 0;
+}
+
+FNFCIGETTEMPFILE (fnGetTempFile) /*(char *pszTempName[bcount(cbTempName)], int cbTempName[range(>=, MAX_PATH)], void FAR *pv)*/
+{
+ BOOL success = FALSE;
+ CHAR tempPath[L_tmpnam];
+ char * r;
+ printf("DEBUG: fnGetTempFile\n");
+ r = tmpnam(tempPath);
+ if (r != NULL)
+ {
+ success = TRUE;
+ strcpy(pszTempName, tempPath);
+ cbTempName = strlen(pszTempName);
+ }
+ return success;
+}
+
+FNFCIFILEPLACED (fnFilePlaced) /*(PCCAB *pccab, LPSTR pszFile, long cbFile, BOOL fContinuation, void FAR *pv)*/
+{
+ printf("DEBUG: fnFilePlaced\n");
+ if (fContinuation == FALSE)
+ cabLog(CABLOG_MSG, "%s (%d b) has been added to %s", pszFile, cbFile, pccab->szCab);
+
+ return 0;
+}
+
+FNFCIGETNEXTCABINET(fnGetNextCab)/*(PCCAB pccab, ULONG cbPrevCab, void FAR *pv)*/
+{
+ printf("DEBUG: fnGetNextCab\n");
+ return TRUE;
+}
+
+FNFCISTATUS(fnStatus)/*(UINT typeStatus, ULONG cb1, ULONG cb2, void FAR *pv)*/
+{
+ switch (typeStatus)
+ {
+ case statusFile:
+ printf("\rCompressing source file (%d bytes compressed from %d)", cb1, cb2);
+ break;
+ case statusFolder:
+ printf("\rCopying data into cabinet (%d of %d)", cb1, cb2);
+ break;
+ case statusCabinet:
+ printf("\rWriting cabinet file (%d of approx. %d bytes)", cb1, cb2);
+ return cb2;
+ break;
+ }
+
+ return 0;
+}
+
+FNFCIGETOPENINFO(fnGetOpenInfo)/*(LPSTR pszName, USHORT *pdate, USHORT *ptime, USHORT *pattribs, int FAR *err, void FAR *pv)*/
+{
+ /* pdate: dddddmmmmyyyyyyy - d [1-31] m [1-12] y offset from 1980 */
+ /* ptime: sssssmmmmhhhhhhh = s [second/2] m [0-59] h [0-23] */
+ struct stat s;
+ struct tm * time;
+ FILE * f = NULL;
+ if (stat(pszName, &s) != -1)
+ {
+ time = gmtime(&s.st_mtime);
+ *pdate = 0;
+ *ptime = 0;
+
+ /* Note: tm_year is years since 1900 */
+ *pdate = (time->tm_mday << 11) | ((time->tm_mon+1) << 7) | (time->tm_year-80);
+ *ptime = ((time->tm_sec / 2) << 11) | (time->tm_min << 6) | (time->tm_hour);
+ f = (FILE *) fnOpen(pszName, _O_RDONLY, 0, err, pv);
+ }
+
+ if (!f)
+ {
+ cabLog(CABLOG_ERR, "Could not access file information: %s", pszName);
+ return -1;
+ }
+ return (INT_PTR) f;
+}
+
+/*
+MAKECAB [/V[n]] [/D var=value ...] [/L dir] source [destination]
+MAKECAB [/V[n]] [/D var=value ...] /F directive_file [...]
+source - File to compress.
+destination - File name to give compressed file. If omitted, the
+last character of the source file name is replaced
+with an underscore (_) and used as the destination.
+/F directives - A file with MakeCAB directives (may be repeated).
+/D var=value - Defines variable with specified value.
+/L dir - Location to place destination (default is current directory).
+/V[n] - Verbosity level (1..3)
+*/
+void usage(void)
+{
+ printf(
+ "Usage: makecab [/V[n]] /F directive_file\n"
+ "\nOptions:\n"
+ "/F directives - A file with MakeCAB directives.\n"
+ "/V[n] - Verbosity level (1..3)\n");
+}
+
+int main(int argc, char *argv[])
+{
+ int v = 0;
+ char * ddfFile = NULL;
+ CCAB ddfVars;
+ DDFSRCFILE *srcList = NULL;
+ DDFSRCFILE *srcListCurr = NULL;
+ HFCI fci = NULL;
+ ERF erf;
+
+ while (argv[1] && (argv[1][0] == '-' || argv[1][0] == '/'))
+ {
+ switch(tolower(argv[1][1]))
+ {
+ case 'f': /* Directive file specified */
+ argv++; argc--;
+ ddfFile = argv[1];
+ break;
+ case 'v': /* Verbosity [0-3] */
+ switch(argv[1][2])
+ {
+ case '0': v = 0; break;
+ case '1': v = 1; break;
+ case '2': v = 2; break;
+ case '3': v = 3; break;
+ }
+ break;
+ case '?':
+ usage();
+ return 0;
+ }
+ argv++; argc--;
+ }
+ CabVerb = v;
+
+ srcList = srcListCurr;
+ if (ddfFile != NULL)
+ {
+ cabLog(CABLOG_MSG, "=== Parsing directive file \"%s\"===", ddfFile);
+ switch(ParseDdf(ddfFile, &ddfVars, &srcListCurr, v))
+ {
+ case DDFERR_UNREAD: cabLog(CABLOG_ERR, "Could not open directive file."); break;
+ }
+ getcwd(ddfVars.szCabPath, MAX_PATH-1);
+ strcat(ddfVars.szCabPath, "/");
+ }
+
+ if (srcListCurr != NULL)
+ {
+ cabLogCCAB(&ddfVars);
+ fci = FCICreate(&erf, fnFilePlaced, fnMemAlloc, fnMemFree, fnOpen, fnRead,
+ fnWrite, fnClose, fnSeek, fnDelete, fnGetTempFile, &ddfVars, NULL);
+
+ if (fci != NULL)
+ {
+ cabLog(CABLOG_MSG, "=== Adding files to cabinet ===");
+ for (;srcListCurr != NULL; srcListCurr = srcListCurr->next)
+ {
+ cabLog(CABLOG_MSG, "Adding file: %s%s (%s)", ddfVars.szCabPath, srcListCurr->fileName, srcListCurr->cabName);
+ if (!FCIAddFile(fci, srcListCurr->fileName, srcListCurr->cabName, srcListCurr->extract, fnGetNextCab, fnStatus, fnGetOpenInfo, srcListCurr->cmpType))
+ cabLogErr(&erf, "A problem occurred while adding a file");
+ }
+
+ cabLog(CABLOG_MSG, "=== Flushing the cabinet ===");
+ if (!FCIFlushCabinet(fci, FALSE, fnGetNextCab, fnStatus))
+ cabLogErr(&erf, "A problem occurred while flushing the cabinet");
+ FCIDestroy(fci);
+ }
+ else
+ {
+ cabLogErr(&erf, "Could not get FCI context");
+ }
+ }
+
+ cabLog(CABLOG_MSG, "=== Cleaning up resources ===");
+ /* Free list of cab source files */
+ for (srcListCurr = srcList; srcListCurr != NULL; )
+ {
+ struct DDFSRCFILE *const next = srcListCurr->next;
+ free(srcListCurr);
+ srcListCurr = next;
+ }
+ return 0;
+}
diff --git a/setup_native/source/win32/wintools/makecab/parseddf.c b/setup_native/source/win32/wintools/makecab/parseddf.c
new file mode 100644
index 000000000000..6c1aa29f0c69
--- /dev/null
+++ b/setup_native/source/win32/wintools/makecab/parseddf.c
@@ -0,0 +1,374 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#include "parseddf.h"
+#include <sys/stat.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+
+extern int errno;
+static const char * VARS[] = {"cabinetname", "reservepercabinetsize", "maxdisksize", "compressiontype", "compress", "compressionmemory", "cabinet", "diskdirectorytemplate"};
+static const unsigned int VARS_COUNT = 8;
+static int CompMemory = 0;
+static TCOMP CompType = tcompTYPE_MSZIP;
+static unsigned int DdfVerb = 0;
+
+/* Trim leading whitespace from a null terminated string */
+void ltrim(char * str)
+{
+ unsigned int i = 0;
+ while (isspace(str[i]) && str[i] != '\0') i++;
+ if (i > 0) memmove(str, str+i, strlen(str)+1-i);
+}
+
+/* Trim trailing whitespace from a null terminated string */
+void rtrim(char * str)
+{
+ unsigned int i = strlen(str) - 1;
+ while (isspace(str[i]) && i > 0) i--;
+ if (i) i++;
+ str[i] = '\0';
+}
+
+/* Trim trailing and leading whitespace from a null terminated string */
+void trim(char * str)
+{
+ ltrim(str);
+ rtrim(str);
+}
+
+void ddfLogProgress(DDFLOGLEVEL lvl, char * desc, unsigned int progress)
+{
+ if (DdfVerb < lvl) return;
+ if (progress == 0) printf(" %s: %3d%%", desc, progress);
+ else if (progress > 0 && progress < 100) printf("\r %s: %3d%%", desc, progress);
+ else if (progress == 100) printf("\r %s: 100%%\n", desc);
+ fflush(stdout);
+}
+
+void ddfLog(DDFLOGLEVEL lvl, char * msg, ...)
+{
+ va_list args;
+ if (DdfVerb < lvl) return;
+
+ switch (lvl)
+ {
+ case DDFLOG_WRN: printf("[Warning] "); break;
+ case DDFLOG_ERR: printf("[Error] "); break;
+ }
+
+ va_start(args, msg);
+ vprintf(msg, args);
+ va_end(args);
+ printf("\n");
+}
+
+void ddfPrintState(DDFLOGLEVEL lvl, PCCAB ccab, DDFSRCFILE * srcList)
+{
+ static const unsigned int SIZE = 2048;
+ char msg[SIZE];
+ char srcLine[DDF_MAX_CHARS];
+ unsigned int len;
+ DDFSRCFILE * srcListCurr;
+
+ if (ccab)
+ {
+ len = sprintf(msg,
+ "=== Directive file state table ===\n"
+ "CabinetName %s\n"
+ "ReservePerCabinetSize %d\n"
+ "MaxDiskSize %d\n"
+ "Compress %d\n"
+ "CompressionMemory %d\n"
+ "Cabinet %d\n"
+ "DiskDirectoryTemplate %s",
+ ccab->szCab,
+ ccab->cbReserveCFHeader,
+ ccab->iDisk,
+ 1,
+ CompMemory,
+ 1,
+ ccab->szCabPath);
+ }
+ else
+ {
+ msg[0] = '\0';
+ }
+ if (!srcList) printf("DEBUG: No list!\n");
+
+ for (srcListCurr = srcList;
+ srcListCurr != NULL && (len = strlen(msg)) < SIZE;
+ srcListCurr = srcListCurr->next)
+ {
+ sprintf(srcLine, "\nsrc: %s (%s) extract? %d MSZIP? %d LZX? %d",
+ srcListCurr->fileName, srcListCurr->cabName,
+ srcListCurr->extract, (srcListCurr->cmpType == tcompTYPE_MSZIP),
+ (srcListCurr->cmpType != tcompTYPE_MSZIP));
+ strncat(msg, srcLine, SIZE-strlen(srcLine)-1);
+ }
+ if (msg[SIZE-1] != '\0') msg[SIZE-1] = '\0';
+
+ ddfLog(lvl, msg);
+}
+
+/* Moves the next DDF token from the beginning of *line into *token.
+ *
+ * Currently supported token delimiters are:
+ * whitespace (trimmed when not quoted)
+ * ; demarks the start of a comment
+ * " escapes whitespace, quotes and =
+ * = when setting values
+ * \n \r - only if file has endline incompatibility
+ *
+ * returns:
+ * DDF_OK More tokens remain
+ * DDFERR_NO_MORE_TOKENS At the end of the (usable) line.
+ * DDFERR_INVALID_ENDL Token up to this point is stored, endline is chomped.
+ */
+DDFERR nextToken(char * token, char * line)
+{
+ unsigned int i = 0;
+ unsigned int r = DDF_OK;
+ unsigned int offset = 0;
+ int c;
+ BOOL esc = FALSE;
+
+ ltrim(line);
+ if (line[0] == '\0' || line[0] == ';') return DDFERR_NO_MORE_TOKENS;
+ if (line[0] == '=')
+ {
+ memmove(line, line+1, strlen(line));
+ trim(line);
+ }
+
+ for (i = 0; i < DDF_MAX_CHARS-1 && i < strlen(line); i++)
+ {
+ /* Chomp delimiting tokens unless they're escaped */
+ c = line[i];
+ if (c == '\"')
+ {
+ esc = !esc;
+ offset++;
+ /* Compress "" to ", otherwise don't add quote to token*/
+ if (i > 0 && line[i-1] != '\"') continue;
+ }
+ else if (c == '\r' || c == '\n')
+ {
+ r = DDFERR_INVALID_ENDL;
+ break;
+ }
+ else if(!esc)
+ {
+ if (isspace(c) || c == '=') { r = DDF_OK; break; }
+ else if (c == ';') { r = DDFERR_NO_MORE_TOKENS; break; }
+ }
+
+ token[i - offset] = c;
+
+ }
+ token[i - offset] = '\0';
+ memmove(line, line+i, strlen(line)+1-i);
+ return r;
+}
+
+DDFERR setVar(DDFVAR key, PCCAB ccab, char * value)
+{
+ int i = 0;
+ char * cp = NULL;
+
+ ddfLog(DDFLOG_MSG, "Setting variable %s=%s...", VARS[key], value);
+
+ switch (key)
+ {
+ case DDF_CABNAME:
+ strncpy(ccab->szCab, value, 255);
+ break;
+ case DDF_RESERVEPERCAB:
+ i = atoi(value);
+ if (i < 0) i = 0;
+ if (i > DDF_MAX_CABRESERVE) i = DDF_MAX_CABRESERVE;
+ if (i % 4 != 0) i -= (i % 4);
+ ccab->cbReserveCFHeader = i;
+ break;
+ case DDF_MAXDISK:
+ i = atoi(value);
+ ccab->cb = i;
+ break;
+ case DDF_COMPTYPE:
+ if (strcmp(value, "LZX") == 0)
+ {
+/* if (CompMemory) CompType = TCOMPfromLZXWindow(CompMemory);
+ else CompType = tcompTYPE_LZX;*/
+/*TODO: LZX not yet supported in Wine */
+ CompType = tcompTYPE_MSZIP;
+ }
+ else
+ {
+ if (strcmp(value, "MSZIP") != 0)
+ ddfLog(DDFLOG_WRN, "Invalid compression type \"%s\", reverting to MSZIP.", value);
+ CompType = tcompTYPE_MSZIP;
+ }
+ break;
+ case DDF_COMPRESS:
+ break;
+ case DDF_COMPMEM:
+ i = atoi(value);
+ if (i < 15) i = 15;
+ if (i > 21) i = 21;
+ CompMemory = i;
+ if (CompType == tcompTYPE_LZX) CompType = TCOMPfromLZXWindow(CompMemory);
+ break;
+ case DDF_CABINET:
+ break;
+ case DDF_DISKDIRTEMPLATE:
+ while ((cp = strchr(value, '*')) != '\0') *cp = '1';
+ strncpy(ccab->szCabPath, value, 255);
+ break;
+ }
+
+ return DDF_OK;
+}
+
+DDFERR parseCmd(char * line, PCCAB ccab, char * token)
+{
+ unsigned int r, i;
+ char *p;
+ for (p = token ; *p; ++p) *p = tolower(*p);
+
+ /* Set command checks lower case token representing var name
+ against known variables. If found, the next token is used as
+ the value to assign */
+ if (strcmp(token, ".set") == 0)
+ {
+ r = nextToken(token, line);
+ if (r != DDF_OK) return DDFERR_FUNC_FAILED;
+
+ for (p = token ; *p; ++p) *p = tolower(*p);
+ if (isdigit(token[strlen(token)-1])) token[strlen(token)-1] = '\0';
+ for (i = 0; i < (sizeof(VARS)/sizeof(VARS[0])); i++)
+ {
+ if (strcmp(token, VARS[i]) == 0)
+ {
+ r = nextToken(token, line);
+ if (r != DDF_OK) return DDFERR_FUNC_FAILED;
+ setVar(i, ccab, token);
+ break;
+ }
+ }
+ }
+
+ return DDF_OK;
+}
+
+char * getCabName(char * name)
+{
+ char * cName;
+ if ((cName = strrchr(name, '/')) || (cName = strrchr(name, '\\')))
+ cName++;
+ else
+ cName = name;
+ return cName;
+}
+
+DDFERR parseSrc(char * line, DDFSRCFILE ** srcFileList, char * token)
+{
+ unsigned int r;
+ struct stat s;
+ DDFSRCFILE * tmpSrcFile;
+
+ /* Check file exists before allocating DDFSRCFILE */
+ if (stat(token, &s) == -1 && errno == ENOENT)
+ {
+ ddfLog(DDFLOG_WRN, "Could not find file \"%s\"", token);
+ return DDFERR_SRC_SKIPPED;
+ }
+
+ tmpSrcFile = (DDFSRCFILE *) malloc(sizeof(DDFSRCFILE));
+ if (!tmpSrcFile) return DDFERR_FUNC_FAILED;
+ if (!(*srcFileList))
+ {
+ *srcFileList = tmpSrcFile;
+ }
+ else
+ {
+ while ((*srcFileList)->next != NULL) *srcFileList = (*srcFileList)->next;
+ (*srcFileList)->next = tmpSrcFile;
+ }
+
+ strncpy(tmpSrcFile->fileName, token, MAX_PATH);
+ /* Get cabinet file name or construct from src path if unspecified */
+ r = nextToken(token, line);
+ if (r != DDF_OK || token[0] == '/')
+ {
+ strncpy(tmpSrcFile->cabName, getCabName(tmpSrcFile->fileName), DDF_MAX_CABNAME-1);
+ }
+ else
+ {
+ strncpy(tmpSrcFile->cabName, token, DDF_MAX_CABNAME-1);
+ }
+
+ tmpSrcFile->cabName[DDF_MAX_CABNAME-1] = '\0';
+ tmpSrcFile->extract = FALSE;
+ tmpSrcFile->cmpType = CompType;
+ tmpSrcFile->next = NULL;
+
+ return DDF_OK;
+}
+
+DDFERR parseDdfLine(char * line, PCCAB ccab, DDFSRCFILE ** srcList)
+{
+ unsigned int r;
+ char token[DDF_MAX_CHARS];
+
+ if (line[0] == '\0') return DDF_OK;
+
+ ddfLog(DDFLOG_MSG, "Parsing line \"%s\"", line);
+
+ r = nextToken(token,line);
+ if (r == DDF_OK)
+ {
+ if (token[0] == '.')
+ {
+ r = parseCmd(line, ccab, token);
+ if (r != DDF_OK) ddfLog(DDFLOG_ERR, "Invalid command line skipped: %s%s", token, line);
+ }
+ else
+ {
+ r = parseSrc(line, srcList, token);
+
+ if (r == DDFERR_SRC_SKIPPED)
+ ddfLog(DDFLOG_ERR, "Source file command \"%s%s\" couldn't be read - skipped", token, line);
+ else if (r == DDFERR_FUNC_FAILED)
+ ddfLog(DDFLOG_WRN, "Could not parse command correctly, \"%s\" remains", line);
+ }
+ }
+
+ return r;
+}
+
+DDFERR ParseDdf(char* ddfFile, PCCAB ccab, DDFSRCFILE ** srcListH, unsigned int v)
+{
+ char fLine[DDF_MAX_CHARS];
+ FILE *ddf = NULL;
+ unsigned int i = 0;
+ DDFSRCFILE * srcListCurr = NULL;
+
+ ddf = fopen(ddfFile, "r");
+ if (ddf == NULL) return DDFERR_UNREAD;
+
+ DdfVerb = v;
+ for (; i < DDF_MAX_LINES && fgets(fLine, sizeof fLine, ddf); i++)
+ {
+ fLine[strlen(fLine)-1] = '\0';
+ parseDdfLine(fLine, ccab, &srcListCurr);
+ if (srcListCurr && !(*srcListH))
+ {
+ *srcListH = srcListCurr;
+ }
+ }
+
+ ddfPrintState(DDFLOG_MSG, ccab, *srcListH);
+ ccab->cbFolderThresh = ccab->cb;
+ ccab->iDisk = 0;
+
+ return DDF_OK;
+}
diff --git a/setup_native/source/win32/wintools/makecab/parseddf.h b/setup_native/source/win32/wintools/makecab/parseddf.h
new file mode 100644
index 000000000000..6a46541dc297
--- /dev/null
+++ b/setup_native/source/win32/wintools/makecab/parseddf.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#ifndef __PARSEDDF_H__
+#define __PARSEDDF_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <windows.h>
+#include <fci.h>
+
+typedef enum DDFLINETYPE { DDF_NONE, DDF_CMD, DDF_SRC } DDFLINETYPE;
+typedef enum DDFERR { DDF_OK, DDFERR_INVALID_ENDL, DDFERR_NO_MORE_TOKENS, DDFERR_FUNC_FAILED, DDFERR_SRC_SKIPPED, DDFERR_UNREAD } DDFERR;
+typedef enum DDFVAR { DDF_CABNAME, DDF_RESERVEPERCAB, DDF_MAXDISK, DDF_COMPTYPE, DDF_COMPRESS, DDF_COMPMEM, DDF_CABINET, DDF_DISKDIRTEMPLATE } DDFVAR;
+typedef enum DDFLOGLEVEL { DDFLOG_ERR = 1, DDFLOG_WRN, DDFLOG_MSG } DDFLOGLEVEL;
+
+#define DDF_MAX_CHARS 1024
+#define DDF_MAX_LINES 1024
+#define DDF_MAX_CABRESERVE 60000
+#define DDF_MAX_CABNAME 50
+
+typedef struct DDFSRCFILE
+{
+ char fileName[MAX_PATH];
+ char cabName[DDF_MAX_CABNAME];
+ BOOL extract;
+ TCOMP cmpType;
+ struct DDFSRCFILE * next;
+} DDFSRCFILE;
+
+unsigned int ParseDdf(char * ddfFile, PCCAB vars, DDFSRCFILE ** srcListH, unsigned int v);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PARSEDDF_H__ */