Refactoring!

This commit is contained in:
Ianos Gnatiuc
2006-05-13 16:15:35 +00:00
parent 48908d77d9
commit 40cd10db65
89 changed files with 7944 additions and 28800 deletions

View File

@@ -1,31 +0,0 @@
#ifndef __crc32_h
#define __crc32_h
/* crc32.h */
/* wrapper for gall library */
typedef unsigned long crc32_t;
#define Z_NULL 0
#define byte(a) ((unsigned char)(a))
extern crc32_t __crc32_table[256];
static crc32_t updCrc32(unsigned char ch, crc32_t crc)
{
return (crc32_t)(__crc32_table[byte(crc) ^ byte(ch)] ^ (crc >> 8));
}
static crc32_t crc32(crc32_t crc, const unsigned char *buf, unsigned int len)
{
if (buf == Z_NULL) return 0L;
crc = crc ^ 0xffffffffL;
while (len--)
{
crc = updCrc32(*buf++, crc);
}
return crc ^ 0xffffffffL;
}
#endif /* __crc32_h */

View File

@@ -1,514 +0,0 @@
/*
* fptools.c, some helper functions for getcgi.c and uu(en|de)view
*
* Distributed under the terms of the GNU General Public License.
* Use and be happy.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef SYSTEM_WINDLL
#include <windows.h>
#endif
#ifdef SYSTEM_OS2
#include <os2.h>
#endif
/*
* This file provides replacements for some handy functions that aren't
* available on all systems, like most of the <string.h> functions. They
* should behave exactly as their counterparts. There are also extensions
* that aren't portable at all (like strirstr etc.).
* The proper behaviour in a configure script is as follows:
* AC_CHECK_FUNC(strrchr,AC_DEFINE(strrchr,_FP_strrchr))
* This way, the (probably less efficient) replacements will only be used
* where it is not provided by the default libraries. Be aware that this
* does not work with replacements that just shadow wrong behaviour (like
* _FP_free) or provide extended functionality (_FP_gets).
* The above is not used in the uuenview/uudeview configuration script,
* since both only use the replacement functions in non-performance-cri-
* tical sections (except for _FP_tempnam and _FP_strerror, where some
* functionality of the original would be lost).
*/
#include <stdio.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <gdefs.h>
#include <gctype.h>
#include <fptools.h>
#if 0
#ifdef SYSTEM_WINDLL
BOOL _export WINAPI
DllEntryPoint (HINSTANCE hInstance, DWORD seginfo,
LPVOID lpCmdLine)
{
/* Don't do anything, so just return true */
return TRUE;
}
#endif
#endif
char * fptools_id = "$Id$";
/*
* some versions of free can't handle a NULL pointer properly
* (ANSI says, free ignores a NULL pointer, but some machines
* prefer to SIGSEGV on it)
*/
void TOOLEXPORT
_FP_free (void *ptr)
{
if (ptr) free (ptr);
}
/*
* This is non-standard, so I'm defining my own
*/
char * TOOLEXPORT
_FP_strdup (char *string)
{
char *result;
if (string == NULL)
return NULL;
if ((result = (char *) malloc (strlen (string) + 1)) == NULL)
return NULL;
strcpy (result, string);
return result;
}
/*
* limited-length string copy. this function behaves differently from
* the original in that the dest string is always terminated with a
* NULL character.
*/
char * TOOLEXPORT
_FP_strncpy (char *dest, char *src, int length)
{
char *odest=dest;
if (src == NULL || dest == NULL || length-- <= 0)
return dest;
while (length-- && *src)
*dest++ = *src++;
*dest++ = '\0';
return odest;
}
/*
* duplicate a memory area
*/
void * TOOLEXPORT
_FP_memdup (void *ptr, int len)
{
void *result;
if (ptr == NULL)
return NULL;
if ((result = malloc (len)) == NULL)
return NULL;
memcpy (result, ptr, len);
return result;
}
/*
* case-insensitive compare
*/
int TOOLEXPORT
_FP_stricmp (char *str1, char *str2)
{
if (str1==NULL || str2==NULL)
return -1;
while (*str1) {
if (g_tolower(*str1) != g_tolower(*str2))
break;
str1++;
str2++;
}
return (g_tolower (*str1) - g_tolower (*str2));
}
int TOOLEXPORT
_FP_strnicmp (char *str1, char *str2, int count)
{
if (str1==NULL || str2==NULL)
return -1;
while (*str1 && count) {
if (g_tolower(*str1) != g_tolower(*str2))
break;
str1++;
str2++;
count--;
}
return count ? (g_tolower (*str1) - g_tolower (*str2)) : 0;
}
/*
* autoconf says this function might be a compatibility problem
*/
char * TOOLEXPORT
_FP_strstr (char *str1, char *str2)
{
char *ptr1, *ptr2;
if (str1==NULL)
return NULL;
if (str2==NULL)
return str1;
while (*(ptr1=str1)) {
for (ptr2=str2;
*ptr1 && *ptr2 && *ptr1==*ptr2;
ptr1++, ptr2++)
/* empty loop */ ;
if (*ptr2 == '\0')
return str1;
str1++;
}
return NULL;
}
char * TOOLEXPORT
_FP_strpbrk (char *str, char *accept)
{
char *ptr;
if (str == NULL)
return NULL;
if (accept == NULL || *accept == '\0')
return str;
for (; *str; str++)
for (ptr=accept; *ptr; ptr++)
if (*str == *ptr)
return str;
return NULL;
}
/*
* autoconf also complains about this one
*/
char * TOOLEXPORT
_FP_strtok (char *str1, char *str2)
{
static char *optr;
char *ptr;
if (str2 == NULL)
return NULL;
if (str1) {
optr = str1;
}
else {
if (*optr == '\0')
return NULL;
}
while (*optr && strchr (str2, *optr)) /* look for beginning of token */
optr++;
if (*optr == '\0') /* no token found */
return NULL;
ptr = optr;
while (*optr && strchr (str2, *optr) == NULL) /* look for end of token */
optr++;
if (*optr) {
*optr++ = '\0';
}
return ptr;
}
/*
* case insensitive strstr.
*/
char * TOOLEXPORT
_FP_stristr (char *str1, char *str2)
{
char *ptr1, *ptr2;
if (str1==NULL)
return NULL;
if (str2==NULL)
return str1;
while (*(ptr1=str1)) {
for (ptr2=str2;
*ptr1 && *ptr2 && g_tolower(*ptr1)==g_tolower(*ptr2);
ptr1++, ptr2++)
/* empty loop */ ;
if (*ptr2 == '\0')
return str1;
str1++;
}
return NULL;
}
/*
* Nice fake of the real (non-standard) one
*/
char * TOOLEXPORT
_FP_strrstr (char *ptr, char *str)
{
char *found=NULL, *new, *iter=ptr;
if (ptr==NULL || str==NULL)
return NULL;
if (*str == '\0')
return ptr;
while ((new = _FP_strstr (iter, str)) != NULL) {
found = new;
iter = new + 1;
}
return found;
}
char * TOOLEXPORT
_FP_strirstr (char *ptr, char *str)
{
char *found=NULL, *iter=ptr, *new;
if (ptr==NULL || str==NULL)
return NULL;
if (*str == '\0')
return ptr;
while ((new = _FP_stristr (iter, str)) != NULL) {
found = new;
iter = new + 1;
}
return found;
}
/*
* convert whole string to case
*/
char * TOOLEXPORT
_FP_stoupper (char *input)
{
char *iter = input;
if (input == NULL)
return NULL;
while (*iter) {
*iter = g_toupper (*iter);
iter++;
}
return input;
}
char * TOOLEXPORT
_FP_stolower (char *input)
{
char *iter = input;
if (input == NULL)
return NULL;
while (*iter) {
*iter = g_tolower (*iter);
iter++;
}
return input;
}
/*
* string matching with wildcards
*/
int TOOLEXPORT
_FP_strmatch (char *string, char *pattern)
{
char *p1 = string, *p2 = pattern;
if (pattern==NULL || string==NULL)
return 0;
while (*p1 && *p2) {
if (*p2 == '?') {
p1++; p2++;
}
else if (*p2 == '*') {
if (*++p2 == '\0')
return 1;
while (*p1 && *p1 != *p2)
p1++;
}
else if (*p1 == *p2) {
p1++; p2++;
}
else
return 0;
}
if (*p1 || *p2)
return 0;
return 1;
}
char * TOOLEXPORT
_FP_strrchr (char *string, int tc)
{
char *ptr;
if (string == NULL)
return NULL;
ptr = string + strlen (string) - 1;
while (ptr != string && *ptr != tc)
ptr--;
if (*ptr == tc)
return ptr;
return NULL;
}
/*
* strip directory information from a filename. Works only on DOS and
* Unix systems so far ...
*/
char * TOOLEXPORT
_FP_cutdir (char *filename)
{
char *ptr;
if (filename == NULL)
return NULL;
if ((ptr = _FP_strrchr (filename, '/')) != NULL)
ptr++;
else if ((ptr = _FP_strrchr (filename, '\\')) != NULL)
ptr++;
else
ptr = filename;
return ptr;
}
/*
* My own fgets function. It handles all kinds of line terminators
* properly: LF (Unix), CRLF (DOS) and CR (Mac). In all cases, the
* terminator is replaced by a single LF
*/
char * TOOLEXPORT
_FP_fgets (char *buf, int n, FILE *stream)
{
char *obp = buf;
int c;
if (feof (stream))
return NULL;
while (--n) {
if ((c = fgetc (stream)) == EOF) {
if (ferror (stream))
return NULL;
else {
if (obp == buf)
return NULL;
*buf = '\0';
return obp;
}
}
if (c == '\015') { /* CR */
/*
* Peek next character. If it's no LF, push it back.
* ungetc(EOF, stream) is handled correctly according
* to the manual page
*/
if ((c = fgetc (stream)) != '\012')
if (!feof (stream))
ungetc (c, stream);
*buf++ = '\012';
*buf = '\0';
return obp;
}
else if (c == '\012') { /* LF */
*buf++ = '\012';
*buf = '\0';
return obp;
}
/*
* just another standard character
*/
*buf++ = c;
}
/*
* n-1 characters already transferred
*/
*buf = '\0';
return obp;
}
#if 0
/*
* A replacement strerror function that just returns the error code
*/
char * TOOLEXPORT
_FP_strerror (int errcode)
{
static char number[8];
sprintf (number, "%03d", errcode);
return number;
}
/*
* tempnam is not ANSI, but tmpnam is. Ignore the prefix here.
*/
char * TOOLEXPORT
_FP_tempnam (char *dir, char *pfx)
{
return _FP_strdup (tmpnam (NULL));
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,168 +0,0 @@
/*
* This file is part of uudeview, the simple and friendly multi-part multi-
* file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may
* be contacted at fp@fpx.de
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* Strings used in the library for easier translation etc.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef SYSTEM_WINDLL
#include <windows.h>
#endif
#ifdef SYSTEM_OS2
#include <os2.h>
#endif
#include <stdio.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <uudeview.h>
#include <uuint.h>
#include <uustring.h>
char * uustring_id = "$Id$";
typedef struct {
int code;
char * msg;
} stringmap;
/*
* Map of messages. This table is not exported, the messages must
* be retrieved via the below uustring() function.
*/
static stringmap messages[] = {
/* I/O related errors/messages. Last parameter is strerror() */
{ S_NOT_OPEN_SOURCE, "Could not open source file %s: %s" },
{ S_NOT_OPEN_TARGET, "Could not open target file %s for writing: %s" },
{ S_NOT_OPEN_FILE, "Could not open file %s: %s" },
{ S_NOT_STAT_FILE, "Could not stat file %s: %s" },
{ S_SOURCE_READ_ERR, "Read error on source file: %s" },
{ S_READ_ERROR, "Error reading from %s: %s" },
{ S_IO_ERR_TARGET, "I/O error on target file %s: %s" },
{ S_WR_ERR_TARGET, "Write error on target file %s: %s" },
{ S_WR_ERR_TEMP, "Write error on temp file: %s" },
{ S_TMP_NOT_REMOVED, "Could not remove temp file %s: %s (ignored)" },
/* some other problems */
{ S_OUT_OF_MEMORY, "Out of memory allocating %d bytes" },
{ S_TARGET_EXISTS, "Target file %s exists and overwriting is not allowed" },
{ S_NOT_RENAME, "Could not change name of %s to %s" },
{ S_ERR_ENCODING, "Error while encoding %s: %s" },
{ S_STAT_ONE_PART, "Could not stat input, encoding to one part only" },
{ S_PARM_CHECK, "Parameter check failed in %s" },
{ S_SHORT_BINHEX, "BinHex encoded file %s ended prematurely (%ld bytes left)" },
{ S_DECODE_CANCEL, "Decode operation canceled" },
{ S_ENCODE_CANCEL, "Encode operation canceled" },
{ S_SCAN_CANCEL, "Scanning canceled" },
{ S_SIZE_MISMATCH, "%s: Decoded size (%ld) does not match expected size (%ld)" },
{ S_PSIZE_MISMATCH, "%s part %d: Decoded size (%ld) does not match expected size (%ld)" },
{ S_CRC_MISMATCH, "CRC32 mismatch in %s. Decoded file probably corrupt." },
{ S_PCRC_MISMATCH, "PCRC32 mismatch in %s part %d. Decoded file probably corrupt." },
/* informational messages */
{ S_LOADED_PART, "Loaded from %s: '%s' (%s): %s part %d %s %s %s" },
{ S_NO_DATA_FOUND, "No encoded data found in %s" },
{ S_NO_BIN_FILE, "Oops, could not find decoded file?" },
{ S_STRIPPED_SETUID, "Stripped setuid/setgid bits from target file %s mode %d" },
{ S_DATA_SUSPICIOUS, "Data looks suspicious. Decoded file might be corrupt." },
{ S_NO_TEMP_NAME, "Could not get name for temporary file" },
{ S_BINHEX_SIZES, "BinHex file: data/resource fork sizes %ld/%ld" },
{ S_BINHEX_BOTH, "BinHex file: both forks non-empty, decoding data fork" },
{ S_SMERGE_MERGED, "Parts of '%s' merged with parts of '%s' (%d)" },
/* MIME-related messages */
{ S_MIME_NO_BOUNDARY, "Multipart message without boundary ignored" },
{ S_MIME_B_NOT_FOUND, "Boundary expected on Multipart message but found EOF" },
{ S_MIME_MULTI_DEPTH, "Multipart message nested too deep" },
{ S_MIME_PART_MULTI, "Handling partial multipart message as plain text" },
{ 0, "" }
};
/*
* description of the return values UURET_*
*/
char *uuretcodes[] = {
"OK",
"File I/O Error",
"Not Enough Memory",
"Illegal Value",
"No Data found",
"Unexpected End of File",
"Unsupported function",
"File exists",
"Continue -- no error", /* only to be seen internally */
"Operation Canceled"
};
/*
* Names of encoding types
*/
char *codenames[8] = {
"", "UUdata", "Base64", "XXdata", "Binhex", "Text", "Text", "yEnc"
};
/*
* Message types
*/
char *msgnames[6] = {
"", "Note: ", "Warning: ", "ERROR: ", "FATAL ERROR: ", "PANIC: "
};
/*
* Retrieve one of the messages. We never return NULL
* but instead escape to "oops".
*/
char *
uustring (int codeno)
{
static char * faileddef = "oops";
stringmap *ptr = messages;
while (ptr->code) {
if (ptr->code == codeno)
return ptr->msg;
ptr++;
}
UUMessage (uustring_id, __LINE__, UUMSG_ERROR,
"Could not retrieve string no %d",
codeno);
return faileddef;
}

View File

@@ -1,481 +0,0 @@
/*
* This file is part of uudeview, the simple and friendly multi-part multi-
* file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may
* be contacted at fp@fpx.de
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* certain utilitarian functions that didn't fit anywhere else
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef SYSTEM_WINDLL
#include <windows.h>
#endif
#ifdef SYSTEM_OS2
#include <os2.h>
#endif
#include <stdio.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <uudeview.h>
#include <uuint.h>
#include <fptools.h>
#include <uustring.h>
char * uuutil_id = "$Id$";
/*
* Parts with different known extensions will not be merged by SPMS.
* if first character is '@', it is synonymous to the previous one.
*/
static char *knownexts[] = {
"mpg", "@mpeg", "avi", "mov",
"gif", "jpg", "@jpeg", "tif",
"voc", "wav", "@wave", "au",
"zip", "arj", "tar",
NULL
};
/*
* forward declarations of local functions
*/
static int UUSMPKnownExt _ANSI_ARGS_((char *filename));
static uulist * UU_smparts_r _ANSI_ARGS_((uulist *, int));
/*
* mallocable areas
*/
char *uuutil_bhwtmp;
/*
* free some memory
**/
void
UUkillfread (fileread *data)
{
if (data != NULL) {
_FP_free (data->subject);
_FP_free (data->filename);
_FP_free (data->origin);
_FP_free (data->mimeid);
_FP_free (data->mimetype);
_FP_free (data->sfname);
_FP_free (data);
}
}
void
UUkillfile (uufile *data)
{
uufile *next;
while (data) {
_FP_free (data->filename);
_FP_free (data->subfname);
_FP_free (data->mimeid);
_FP_free (data->mimetype);
UUkillfread (data->data);
next = data->NEXT;
_FP_free (data);
data = next;
}
}
void
UUkilllist (uulist *data)
{
uulist *next;
while (data) {
if (data->binfile != NULL)
if (unlink (data->binfile))
UUMessage (uuutil_id, __LINE__, UUMSG_WARNING,
uustring (S_TMP_NOT_REMOVED),
data->binfile, strerror (errno));
_FP_free (data->filename);
_FP_free (data->subfname);
_FP_free (data->mimeid);
_FP_free (data->mimetype);
_FP_free (data->binfile);
UUkillfile (data->thisfile);
_FP_free (data->haveparts);
_FP_free (data->misparts);
next = data->NEXT;
_FP_free (data);
data = next;
}
}
/*
* this kill function is an exception in that it doesn't kill data itself
*/
void
UUkillheaders (headers *data)
{
if (data != NULL) {
_FP_free (data->from);
_FP_free (data->subject);
_FP_free (data->rcpt);
_FP_free (data->date);
_FP_free (data->mimevers);
_FP_free (data->ctype);
_FP_free (data->ctenc);
_FP_free (data->fname);
_FP_free (data->boundary);
_FP_free (data->mimeid);
memset (data, 0, sizeof (headers));
}
}
/*
* checks for various well-known extensions. if two parts have different
* known extensions, we won't merge them.
*/
static int
UUSMPKnownExt (char *filename)
{
char **eiter = knownexts, *ptr=_FP_strrchr(filename, '.');
int count=0, where=0;
if (ptr == NULL)
return -1;
ptr++;
while (*eiter) {
if (_FP_stricmp (ptr, (**eiter=='@')?*eiter+1:*eiter) == 0)
return where;
else
eiter++;
if (*eiter == NULL)
break;
if (**eiter=='@')
count++;
else
where = ++count;
}
return -1;
}
/*
* de-compress a binhex RLE stream
* the data read from in is uncompressed, and at most maxcount bytes
* (or octets, as they say) are copied to out. Because an uncompression
* might not be completed because of this maximum number of bytes. There-
* for, the leftover character and repetition count is saved. If a marker
* has been read but not the repetition count, *rpc is set to -256.
*
* the function returns the number of bytes eaten from in. If opc is not
* NULL, the total number of characters stored in out is saved there
*
* with repetition counts, remember that we've already transferred *one*
* occurence
*/
int
UUbhdecomp (char *in, char *out, char *last, int *rpc,
size_t inc, size_t max, size_t *opc)
{
size_t count, used=0, dummy;
char marker = '\220' /* '\x90' */;
if (opc == NULL)
opc = &dummy;
else
*opc = 0;
if (*rpc == -256) {
if (inc == 0)
return 0;
*rpc = (int) (unsigned char) *in++; used++;
if (*rpc == 0) {
*last = *out++ = marker;
max--; *opc+=1;
}
else
*rpc-=1;
}
if (*rpc) {
count = (max > (size_t) *rpc) ? (size_t) *rpc : max;
memset (out, *last, count);
out += count;
*opc += count;
max -= count;
*rpc -= count;
}
while (used < inc && max) {
if (*in == marker) {
used++; in++;
if (used == inc) {
*rpc = -256;
return used;
}
*rpc = (int) (unsigned char) *in++; used++;
if (*rpc == 0) {
*last = *out++ = marker;
max--; *opc+=1;
continue;
}
else
*rpc -= 1;
count = (max > (size_t) *rpc) ? (size_t) *rpc : max;
memset (out, *last, count);
out += count;
*opc += count;
max -= count;
*rpc -= count;
}
else {
*last = *out++ = *in++;
used++; *opc+=1; max--;
}
}
return used;
}
/*
* write to binhex file
*/
size_t
UUbhwrite (char *ptr, size_t sel, size_t nel, FILE *file)
{
char *tmpstring=uuutil_bhwtmp;
static int rpc = 0;
static char lc;
int count, tc=0;
size_t opc;
if (ptr == NULL) { /* init */
rpc = 0;
return 0;
}
while (nel || (rpc != 0 && rpc != -256)) {
count = UUbhdecomp (ptr, tmpstring, &lc, &rpc,
nel, 256, &opc);
if (fwrite (tmpstring, 1, opc, file) != opc)
return 0;
if (ferror (file))
return 0;
nel -= count;
ptr += count;
tc += count;
}
return tc;
}
static uulist *
UU_smparts_r (uulist *addit, int pass)
{
uulist *iter = UUGlobalFileList;
uufile *fiter, *dest, *temp;
int count, flag, a, b;
while (iter) {
if ((iter->state & UUFILE_OK) || iter->uudet == 0) {
iter = iter->NEXT;
continue;
}
if (iter == addit) {
iter = iter->NEXT;
continue;
}
if ((iter->begin && addit->begin) || (iter->end && addit->end) ||
(iter->uudet != addit->uudet)) {
iter = iter->NEXT;
continue;
}
if ((a = UUSMPKnownExt (addit->subfname)) != -1 &&
(b = UUSMPKnownExt (iter->subfname)) != -1)
if (a != b) {
iter = iter->NEXT;
continue;
}
flag = count = 0;
fiter = iter->thisfile;
temp = addit->thisfile;
dest = NULL;
while (temp) {
if (!(temp->data->uudet)) {
temp = temp->NEXT;
continue;
}
while (fiter && fiter->partno < temp->partno) {
dest = fiter;
fiter = fiter->NEXT;
}
if (fiter && fiter->partno == temp->partno) {
flag = 0;
break;
}
else {
flag = 1;
count += ((dest) ? temp->partno - dest->partno - 1 : 0) +
((fiter) ? fiter->partno - temp->partno - 1 : 0);
}
temp = temp->NEXT;
}
if (flag == 0 ||
(pass == 0 && count > 0) ||
(pass == 1 && count > 5)) {
iter = iter->NEXT;
continue;
}
dest = iter->thisfile;
fiter = addit->thisfile;
if (iter->filename == NULL && addit->filename != NULL)
iter->filename = _FP_strdup (addit->filename);
if (addit->begin) iter->begin = 1;
if (addit->end) iter->end = 1;
if (addit->mode != 0 && iter->mode == 0)
iter->mode = addit->mode;
while (fiter) {
flag = 0;
if (fiter->partno == iter->thisfile->partno ||
(dest->NEXT != NULL && fiter->partno == dest->NEXT->partno)) {
temp = fiter->NEXT;
fiter->NEXT = NULL;
UUkillfile (fiter);
addit->thisfile= temp;
fiter = temp;
continue;
}
if (fiter->partno < iter->thisfile->partno) {
temp = fiter->NEXT;
fiter->NEXT = iter->thisfile;
iter->thisfile = fiter;
dest = fiter;
addit->thisfile= temp;
fiter = temp;
}
else if (dest->NEXT == NULL || fiter->partno < dest->NEXT->partno) {
temp = fiter->NEXT;
fiter->NEXT = dest->NEXT;
dest->NEXT = fiter;
addit->thisfile= temp;
fiter = temp;
}
else {
dest = dest->NEXT;
}
}
break;
}
return iter;
}
int UUEXPORT
UUSmerge (int pass)
{
uulist *iter = UUGlobalFileList, *last=NULL, *res, *temp;
int flag = 0;
while (iter) {
if ((iter->state & UUFILE_OK) || iter->uudet == 0) {
last = iter;
iter = iter->NEXT;
continue;
}
if ((res = UU_smparts_r (iter, pass)) != NULL) {
UUMessage (uuutil_id, __LINE__, UUMSG_MESSAGE,
uustring (S_SMERGE_MERGED),
(iter->subfname) ? iter->subfname : "",
(res->subfname) ? res->subfname : "", pass);
temp = iter->NEXT;
iter->NEXT = NULL;
UUkilllist (iter);
flag++;
if (last == NULL) {
UUGlobalFileList = temp;
iter = temp;
}
else {
last->NEXT = temp;
iter = temp;
}
continue;
}
last = iter;
iter = iter->NEXT;
}
/*
* check again
*/
UUCheckGlobalList ();
return flag;
}