[pan2/testing: 152/279] modified uuencode to use bytes_per_file- rather than lines_per_file-logic
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/testing: 152/279] modified uuencode to use bytes_per_file- rather than lines_per_file-logic
- Date: Sat, 3 Dec 2011 22:34:57 +0000 (UTC)
commit 4d9f5f571bc90038dea1ec592744298820ee79b1
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date: Tue Jul 5 13:57:21 2011 +0200
modified uuencode to use bytes_per_file- rather than
lines_per_file-logic
pan/data/encode-cache.cc | 2 +-
pan/data/encode-cache.h | 2 +-
pan/gui/post-ui.cc | 24 +-
pan/gui/prefs-ui.cc | 5 +-
pan/icons/icon_pan.png | Bin 4909 -> 4779 bytes
pan/tasks/encoder.cc | 11 +-
pan/tasks/encoder.h | 4 +-
pan/tasks/nzb.cc | 7 -
pan/tasks/task-upload.cc | 36 +-
pan/tasks/task-upload.h | 8 +-
uulib/uudeview.h | 10 +-
uulib/uuencode.c | 3109 ++++++++++++++++++++++++++++++----------------
12 files changed, 2075 insertions(+), 1143 deletions(-)
---
diff --git a/pan/data/encode-cache.cc b/pan/data/encode-cache.cc
index fbcad4e..0d39ddf 100644
--- a/pan/data/encode-cache.cc
+++ b/pan/data/encode-cache.cc
@@ -138,7 +138,7 @@ EncodeCache :: add (const Quark& message_id)
****
***/
-void EncodeCache :: finalize (std::string& message_id)
+void EncodeCache :: finalize (std::string message_id)
{
struct stat sb;
stat (message_id.c_str(), &sb);
diff --git a/pan/data/encode-cache.h b/pan/data/encode-cache.h
index 56a2d27..34091ef 100644
--- a/pan/data/encode-cache.h
+++ b/pan/data/encode-cache.h
@@ -63,7 +63,7 @@ namespace pan
bool contains (const Quark& message_id) const;
void add (const Quark& message_id);
- void finalize (std::string& message_id);
+ void finalize (std::string message_id);
void get_data(std::string& data, const Quark& where);
void reserve (const mid_sequence_t& mids);
void release (const mid_sequence_t& mids);
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index be49ee0..bc40853 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -968,7 +968,6 @@ PostUI :: on_progress_error (Progress&, const StringView& message)
gtk_widget_show (d);
}
-
bool
PostUI :: maybe_post_message (GMimeMessage * message)
{
@@ -1072,7 +1071,7 @@ PostUI :: maybe_post_message (GMimeMessage * message)
_upload_queue.get_all_tasks(tasks);
int cnt(0);
char buf[2048];
- int lpf = _prefs.get_int("upload-option-lpf",4000);
+ int lpf = _prefs.get_int("upload-option-bpf",1024*512);
struct stat sb;
_running_uploads = tasks.size();
@@ -1094,11 +1093,9 @@ PostUI :: maybe_post_message (GMimeMessage * message)
const char* basename = t->_basename.c_str();
TaskUpload::Needed n;
- stat (basename,&sb);
-
- int total = std::max(1, (int) (((long)sb.st_size + (lpf*bpl[t->_encode_mode]-1)) /
- (lpf*bpl[t->_encode_mode])));
+ int total = get_total_parts(t->_filename.c_str(), t);
+ std::string last_mid;
foreach (std::set<int>, t->_wanted, pit)
{
if (custom_mid)
@@ -1106,6 +1103,9 @@ PostUI :: maybe_post_message (GMimeMessage * message)
std::string out;
generate_unique_id(domain, *pit,out);
n.mid = out;
+ n.last_mid = last_mid;
+ // set father mid to first part of upload
+ if (last_mid.empty()) last_mid = out;
}
g_snprintf(buf,sizeof(buf),"%s.%d", basename, *pit);
@@ -2714,8 +2714,8 @@ PostUI :: get_total_parts(const char* file, TaskUpload* it)
{
struct stat sb;
stat (file,&sb);
- int lpf = _prefs.get_int("upload-option-lpf",4000);
- return std::max(1, (int) (((long)sb.st_size + (lpf*bpl[it->_encode_mode]-1)) / (lpf*bpl[it->_encode_mode])));
+ int bpf = _prefs.get_int("upload-option-bpf",1024*512);
+ return std::max(1,(int)std::ceil(sb.st_size / bpf));
}
void
@@ -2772,7 +2772,6 @@ PostUI :: select_parts ()
if (!_upload_ptr) return;
- int lpf = _prefs.get_int("upload-option-lpf",4000);
int new_parts = get_total_parts(_upload_ptr->_filename.c_str(), _upload_ptr);
if (_total_parts != new_parts)
{
@@ -3014,7 +3013,7 @@ PostUI :: prompt_user_for_queueable_files (GtkWindow * parent, const Prefs& pref
// not used for now...
ui.comment1 = _prefs.get_flag("upload-queue-append-subject-enabled",false);
// query lines per file value
- ui.lpf = _prefs.get_int("upload-option-lpf",4000);
+ ui.bpf = _prefs.get_int("upload-option-bpf",1024*512);
GSList * cur = g_slist_nth (tmp_list,0);
for (; cur; cur = cur->next)
@@ -3042,14 +3041,13 @@ PostUI :: prompt_user_for_queueable_files (GtkWindow * parent, const Prefs& pref
struct stat sb;
stat ((const char*)cur->data,&sb);
- int total = std::max(1, (int) (((long)sb.st_size + (ui.lpf*bpl[TaskUpload::YENC]-1)) / (ui.lpf*bpl[TaskUpload::YENC])));
- ui.total = total;
+ ui.total = std::max(1,(int)std::ceil(sb.st_size / (double)_prefs.get_int("upload-option-bpf",1024*512)));
TaskUpload* tmp = new TaskUpload(std::string((const char*)cur->data),
profile.posting_server, _cache,
a, ui, msg,0, TaskUpload::YENC);
- for (int i=1;i<=total; ++i)
+ for (int i=1;i<=ui.total; ++i)
tmp->_wanted.insert(i);
_upload_queue.add_task(tmp);
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index 4cf503f..479f71b 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -628,8 +628,9 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
HIG :: workarea_add_wide_control (t, &row, w);
HIG :: workarea_add_section_title (t, &row, _("Upload Subject Line Appearance"));
HIG :: workarea_add_section_spacer (t, row, 4);
- w = new_spin_button ("upload-option-lpf", 4000, 50000, prefs);
- l = gtk_label_new(_("Default Lines per File (for yEnc Encoder)"));
+ // 256 mb blocks max, 512 kb min
+ w = new_spin_button ("upload-option-bpf", 5000, 1024*1024*256, prefs);
+ l = gtk_label_new(_("Default Bytes per File (for yEnc Encoder)"));
gtk_misc_set_alignment (GTK_MISC(l), 0.0, 0.5);
gtk_label_set_mnemonic_widget(GTK_LABEL(l), w);
HIG::workarea_add_row (t, &row, w, l);
diff --git a/pan/icons/icon_pan.png b/pan/icons/icon_pan.png
index b7cc52a..5d12201 100644
Binary files a/pan/icons/icon_pan.png and b/pan/icons/icon_pan.png differ
diff --git a/pan/tasks/encoder.cc b/pan/tasks/encoder.cc
index f42e349..7ed9772 100644
--- a/pan/tasks/encoder.cc
+++ b/pan/tasks/encoder.cc
@@ -66,7 +66,7 @@ Encoder :: enqueue (TaskUpload * task,
std::string & filename,
std::string & basename,
std::string & subject,
- int lpf,
+ int bpf,
const TaskUpload::EncodeMode enc)
{
@@ -79,7 +79,7 @@ Encoder :: enqueue (TaskUpload * task,
this->needed = &task->_needed;
this->cache = cache;
this->article = article;
- this->lpf = lpf;
+ this->bpf = bpf;
this->subject = subject;
percent = 0;
@@ -121,6 +121,8 @@ Encoder :: do_work()
for (TaskUpload::needed_t::iterator it = needed->begin(); it != needed->end(); ++it, ++cnt)
{
+ g_snprintf(buf,sizeof(buf),"%s.%d",basename.c_str(), cnt);
+
int enc(YENC_ENCODED);
std::ofstream out;
std::string txt;
@@ -131,7 +133,7 @@ Encoder :: do_work()
break;
case TaskUpload::PLAIN:
file :: get_text_file_contents (filename, txt);
- cache->get_filename(cachename, Quark(it->second.message_id));
+ cache->get_filename(cachename, Quark(buf));//it->second.message_id));
out.open(cachename, std::ios::out);
out << txt;
out.close();
@@ -154,7 +156,7 @@ Encoder :: do_work()
continue;
}
- res = UUEncodePartial (fp, NULL, (char*)filename.c_str(), enc , (char*)basename.c_str(), NULL, 0644, cnt, lpf,&crc);
+ res = UUEncodePartial_byFSize (fp, NULL, (char*)filename.c_str(), enc , (char*)basename.c_str(), NULL, 0644, cnt, bpf ,&crc);
if (fp) fclose(fp);
_no_encode:
@@ -167,6 +169,7 @@ _no_encode:
task->_all_bytes += sb.st_size;
tmp->add_part(cnt, StringView(it->second.mid), sb.st_size);
if (res != UURET_CONT) break;
+
}
if (res != UURET_OK && res != UURET_CONT)
diff --git a/pan/tasks/encoder.h b/pan/tasks/encoder.h
index 1b27a14..f7c7a89 100644
--- a/pan/tasks/encoder.h
+++ b/pan/tasks/encoder.h
@@ -66,7 +66,7 @@ namespace pan
std::string & filename,
std::string & basename,
std::string & subject,
- int lpf,
+ int bpf,
const TaskUpload::EncodeMode enc = TaskUpload::YENC);
public:
@@ -85,7 +85,7 @@ namespace pan
TaskUpload * task;
TaskUpload::EncodeMode encode_mode;
std::string basename, filename, subject;
- int lpf;
+ int bpf;
EncodeCache * cache;
TaskUpload::needed_t * needed;
Article * article;
diff --git a/pan/tasks/nzb.cc b/pan/tasks/nzb.cc
index 41a0622..bdc1577 100644
--- a/pan/tasks/nzb.cc
+++ b/pan/tasks/nzb.cc
@@ -254,13 +254,6 @@ NZB :: nzb_to_xml (std::ostream & out,
{
int depth (0);
-// // init rng
-// MTRand rng;
-// rng.seed();
-
- char buf[2048];
- char name[2048];
-
out << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
<< "<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.0//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd\">\n"
<< indent(depth++)
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index 7f4d8bf..c3221f1 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -58,7 +58,7 @@ namespace
{
char buf[4096];
char * freeme = g_path_get_basename(f);
- snprintf (buf, sizeof(buf), _("%s"), freeme);
+ snprintf (buf, sizeof(buf), "%s", freeme);
g_free(freeme);
return buf;
}
@@ -88,17 +88,19 @@ TaskUpload :: TaskUpload (const std::string & filename,
_encoder_has_run (false),
_encode_mode(enc),
_all_bytes(0),
- _lpf(format.lpf),
+ _bpf(format.bpf),
_queue_pos(0),
_msg (msg),
_total_parts(format.total),
- _save_file(format.save_file)
+ _save_file(format.save_file),
+ _references(g_mime_object_get_header ((GMimeObject *)msg, "References"))
{
struct stat sb;
stat(filename.c_str(),&sb);
_bytes = sb.st_size;
_state.set_paused();
+
}
void
@@ -152,6 +154,16 @@ TaskUpload :: update_work (NNTP* checkin_pending)
}
void
+TaskUpload :: add_reference_to_list(std::string s)
+{
+ char buf[4096];
+ g_snprintf(buf,sizeof(buf),"%s <%s>", _references.empty() ? "": _references.c_str() , s.c_str());
+// mut.lock();
+ g_mime_object_set_header ((GMimeObject *)_msg, "References", buf);
+// mut.unlock;
+}
+
+void
TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::string& d)
{
std::stringstream out;
@@ -161,9 +173,17 @@ TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::st
//modify subject
char buf[2048];
- g_snprintf(buf, sizeof(buf), "%s - \"%s\" - (%03d/%03d)", _subject.c_str(), _basename.c_str(), n->partno, _total_parts);
+ g_snprintf(buf, sizeof(buf), "%s - \"%s\" - %s(%03d/%03d)",
+ _subject.c_str(),
+ _basename.c_str(),
+ (_encode_mode==YENC ? " yEnc ":""),
+ n->partno, _total_parts);
g_mime_message_set_subject (msg, buf);
+ ///TODO debug
+// if (!n->last_mid.empty())
+// add_reference_to_list(n->last_mid);
+
//extract body
gboolean unused;
char * body (g_mime_object_to_string ((GMimeObject *) msg));
@@ -300,11 +320,10 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
case TOO_MANY_CONNECTIONS:
// lockout for 120 secs, but try
- _state.set_need_nntp(nntp->_server);
-
+ it->second.reset();
break;
default:
- this->stop();
+ _needed.erase (it);
Log::add_entry_list (tmp, _logfile);
_logfile.clear();
Log :: add_err_va (_("Posting of file %s not successful: Check the log (right-click on list item) !"),
@@ -342,8 +361,7 @@ TaskUpload :: use_encoder (Encoder* encoder)
init_steps(100);
_state.set_working();
-// _encoder->enqueue (this, &_cache, &_article, _filename, _basename, _master_subject, 5000, YENC);
- _encoder->enqueue (this, &_cache, &_article, _filename, _basename, _master_subject, _lpf, _encode_mode);
+ _encoder->enqueue (this, &_cache, &_article, _filename, _basename, _master_subject, _bpf, _encode_mode);
debug ("encoder thread was free, enqueued work");
}
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index 8910b17..2cc8262 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -60,7 +60,7 @@ namespace pan
bool comment1;
std::string save_file;
std::string mid;
- int lpf;
+ int bpf;
int total;
};
@@ -73,7 +73,7 @@ namespace pan
int partno;
NNTP* nntp;
std::string message_id;
- std::string mid; // for rng
+ std::string mid, last_mid; // for rng
std::string cachename;
Xref xref;
bool encoded;
@@ -171,8 +171,9 @@ namespace pan
std::vector<Article*> _upload_list;
Article::mid_sequence_t _mids;
int _queue_pos;
- int _lpf;
+ int _bpf;
needed_t _needed;
+ std::string _references; // original references, not to be touched!
void update_work (NNTP * checkin_pending = 0);
@@ -186,6 +187,7 @@ namespace pan
std::set<int> _wanted;
GMimeMessage * _msg;
void prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::string& d);
+ void add_reference_to_list(std::string s);
};
}
diff --git a/uulib/uudeview.h b/uulib/uudeview.h
index 5943816..c47fcc8 100644
--- a/uulib/uudeview.h
+++ b/uulib/uudeview.h
@@ -172,7 +172,7 @@ typedef struct {
long foffset; /* file offset -- internal use only */
long totsize; /* file total size -- internal use only */
} uuprogress;
-
+
/*
* Externally visible Functions
@@ -191,7 +191,7 @@ int UUEXPORT UUGetOption _ANSI_ARGS_((int, int *, char *, int));
int UUEXPORT UUSetOption _ANSI_ARGS_((int, int, char *));
char * UUEXPORT UUstrerror _ANSI_ARGS_((int));
int UUEXPORT UUSetMsgCallback _ANSI_ARGS_((void *,
- void (*) (void *,
+ void (*) (void *,
char *,
int)));
int UUEXPORT UUSetBusyCallback _ANSI_ARGS_((void *,
@@ -213,7 +213,7 @@ int UUEXPORT UUDecodeToTemp _ANSI_ARGS_((uulist *));
int UUEXPORT UURemoveTemp _ANSI_ARGS_((uulist *));
int UUEXPORT UUDecodeFile _ANSI_ARGS_((uulist *, char *));
int UUEXPORT UUInfoFile _ANSI_ARGS_((uulist *, void *,
- int (*) (void *,
+ int (*) (void *,
char *)));
int UUEXPORT UUSmerge _ANSI_ARGS_((int));
int UUEXPORT UUCleanUp _ANSI_ARGS_((void));
@@ -228,6 +228,10 @@ int UUEXPORT UUEncodePartial _ANSI_ARGS_((FILE *, FILE *,
char *, int,
char *, char *,
int, int, long, unsigned long*));
+int UUEXPORT UUEncodePartial_byFSize _ANSI_ARGS_((FILE *, FILE *,
+ char *, int,
+ char *, char *,
+ int, int, long, unsigned long*));
int UUEXPORT UUEncodeToStream _ANSI_ARGS_((FILE *, FILE *,
char *, int,
char *, int));
diff --git a/uulib/uuencode.c b/uulib/uuencode.c
index 9098206..3235b9e 100644
--- a/uulib/uuencode.c
+++ b/uulib/uuencode.c
@@ -30,6 +30,7 @@
#include <ctype.h>
#include <stdio.h>
#include <time.h>
+#include <math.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
@@ -125,7 +126,8 @@ static unsigned char *eolstring = (unsigned char *) "\012";
* encoding tables
*/
-unsigned char UUEncodeTable[64] = {
+unsigned char UUEncodeTable[64] =
+{
'`', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
@@ -137,7 +139,8 @@ unsigned char UUEncodeTable[64] = {
};
-unsigned char B64EncodeTable[64] = {
+unsigned char B64EncodeTable[64] =
+{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
@@ -148,7 +151,8 @@ unsigned char B64EncodeTable[64] = {
'4', '5', '6', '7', '8', '9', '+', '/'
};
-unsigned char XXEncodeTable[64] = {
+unsigned char XXEncodeTable[64] =
+{
'+', '-', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
@@ -159,7 +163,8 @@ unsigned char XXEncodeTable[64] = {
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
-unsigned char BHEncodeTable[64] = {
+unsigned char BHEncodeTable[64] =
+{
'!', '"', '#', '$', '%', '&', '\'', '(',
')', '*', '+', ',', '-', '0', '1', '2',
'3', '4', '5', '6', '8', '9', '@', 'A',
@@ -170,12 +175,14 @@ unsigned char BHEncodeTable[64] = {
'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r'
};
-unsigned char HexEncodeTable[16] = {
+unsigned char HexEncodeTable[16] =
+{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
-typedef struct {
+typedef struct
+{
char *extension;
char *mimetype;
} mimemap;
@@ -188,24 +195,25 @@ typedef struct {
* them. Everything not on the list gets mapped to application/octet-stream
*/
-static mimemap mimetable[] = {
- { "gif", "image/gif" }, /* Grafics Interchange Format */
- { "jpg", "image/jpeg" }, /* JFIF encoded files */
- { "jpeg", "image/jpeg" },
- { "tif", "image/tiff" }, /* Tag Image File Format */
- { "tiff", "image/tiff" },
- { "cgm", "image/cgm" }, /* Computer Graphics Metafile */
- { "au", "audio/basic" }, /* 8kHz ulaw audio data */
- { "mov", "video/quicktime" }, /* Apple Quicktime */
- { "qt", "video/quicktime" }, /* Also infrequently used */
- { "mpeg", "video/mpeg" }, /* Motion Picture Expert Group */
- { "mpg", "video/mpeg" },
- { "mp2", "video/mpeg" }, /* dito, MPEG-2 encoded files */
- { "mp3", "audio/mpeg" }, /* dito, MPEG-3 encoded files */
- { "ps", "application/postscript" }, /* Postscript Language */
- { "zip", "application/zip" }, /* ZIP archive */
- { "doc", "application/msword"},/* assume Microsoft Word */
- { NULL, NULL }
+static mimemap mimetable[] =
+{
+ { "gif", "image/gif" }, /* Grafics Interchange Format */
+ { "jpg", "image/jpeg" }, /* JFIF encoded files */
+ { "jpeg", "image/jpeg" },
+ { "tif", "image/tiff" }, /* Tag Image File Format */
+ { "tiff", "image/tiff" },
+ { "cgm", "image/cgm" }, /* Computer Graphics Metafile */
+ { "au", "audio/basic" }, /* 8kHz ulaw audio data */
+ { "mov", "video/quicktime" }, /* Apple Quicktime */
+ { "qt", "video/quicktime" }, /* Also infrequently used */
+ { "mpeg", "video/mpeg" }, /* Motion Picture Expert Group */
+ { "mpg", "video/mpeg" },
+ { "mp2", "video/mpeg" }, /* dito, MPEG-2 encoded files */
+ { "mp3", "audio/mpeg" }, /* dito, MPEG-3 encoded files */
+ { "ps", "application/postscript" }, /* Postscript Language */
+ { "zip", "application/zip" }, /* ZIP archive */
+ { "doc", "application/msword"},/* assume Microsoft Word */
+ { NULL, NULL }
};
/*
@@ -223,7 +231,8 @@ static int bpl[8] = { 0, 45, 57, 45, 45, 0, 0, 128 };
* tables
*/
-static unsigned char *etables[5] = {
+static unsigned char *etables[5] =
+{
NULL,
UUEncodeTable,
B64EncodeTable,
@@ -254,179 +263,636 @@ UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc3
if (outfile==NULL || infile==NULL ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUEncodeStream()");
- return UURET_ILLVAL;
- }
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUEncodeStream()");
+ return UURET_ILLVAL;
+ }
/*
* Special handling for plain text and quoted printable. Text is
* read line oriented.
*/
- if (encoding == PT_ENCODED || encoding == QP_ENCODED) {
- while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
- if (_FP_fgets (itemp, 255, infile) == NULL) {
- break;
- }
+ if (encoding == PT_ENCODED || encoding == QP_ENCODED)
+ {
+ while (!feof (infile) && (linperfile <= 0 || line < linperfile))
+ {
+ if (_FP_fgets (itemp, 255, infile) == NULL)
+ {
+ break;
+ }
+
+ itemp[255] = '\0';
+ count = strlen (itemp);
+
+ llen = 0;
+ optr = otemp;
+
+ /*
+ * Busy Callback
+ */
+
+ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+ uustring (S_ENCODE_CANCEL));
+ return UURET_CANCEL;
+ }
+
+ if (encoding == PT_ENCODED)
+ {
+ /*
+ * If there is a line feed, replace by eolstring
+ */
+ if (count > 0 && itemp[count-1] == '\n')
+ {
+ itemp[--count] = '\0';
+ if (fwrite (itemp, 1, count, outfile) != count ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ }
+ else
+ {
+ if (fwrite (itemp, 1, count, outfile) != llen)
+ {
+ return UURET_IOERR;
+ }
+ }
+ }
+ else if (encoding == QP_ENCODED)
+ {
+ for (index=0; index<count; index++)
+ {
+ if (llen == 0 && itemp[index] == '.')
+ {
+ /*
+ * Special rule: encode '.' at the beginning of a line, so
+ * that some mailers aren't confused.
+ */
+ *optr++ = '=';
+ *optr++ = HexEncodeTable[itemp[index] >> 4];
+ *optr++ = HexEncodeTable[itemp[index] & 0x0f];
+ llen += 3;
+ }
+ else if ((itemp[index] >= 33 && itemp[index] <= 60) ||
+ (itemp[index] >= 62 && itemp[index] <= 126) ||
+ itemp[index] == 9 || itemp[index] == 32)
+ {
+ *optr++ = itemp[index];
+ llen++;
+ }
+ else if (itemp[index] == '\n')
+ {
+ /*
+ * If the last character before EOL was a space or tab,
+ * we must encode it. If llen > 74, there's no space to do
+ * that, so generate a soft line break instead.
+ */
+
+ if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32))
+ {
+ *(optr-1) = '=';
+ if (llen <= 74)
+ {
+ *optr++ = HexEncodeTable[itemp[index-1] >> 4];
+ *optr++ = HexEncodeTable[itemp[index-1] & 0x0f];
+ llen += 2;
+ }
+ }
+
+ if (fwrite (otemp, 1, llen, outfile) != llen ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+
+ /*
+ * Fix the soft line break condition from above
+ */
+
+ if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) &&
+ *(optr-1) == '=')
+ {
+ otemp[0] = '=';
+ otemp[1] = HexEncodeTable[itemp[index-1] >> 4];
+ otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f];
+
+ if (fwrite (otemp, 1, 3, outfile) != 3 ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ }
+
+ optr = otemp;
+ llen = 0;
+ }
+ else
+ {
+ *optr++ = '=';
+ *optr++ = HexEncodeTable[itemp[index] >> 4];
+ *optr++ = HexEncodeTable[itemp[index] & 0x0f];
+ llen += 3;
+ }
+
+ /*
+ * Lines must be shorter than 76 characters (not counting CRLF).
+ * If the line grows longer than that, we must include a soft
+ * line break.
+ */
+
+ if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
+ (llen >= 75 ||
+ (!((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
+ (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
+ llen >= 73)))
+ {
+
+ *optr++ = '=';
+ llen++;
+
+ if (fwrite (otemp, 1, llen, outfile) != llen ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+
+ optr = otemp;
+ llen = 0;
+ }
+ }
+ }
+
+ line++;
+ }
+
+ return UURET_OK;
+ }
- itemp[255] = '\0';
- count = strlen (itemp);
+ /*
+ * Special handling for yEnc
+ */
+ if (encoding == YENC_ENCODED)
+ {
llen = 0;
optr = otemp;
+ while (!feof (infile) && (linperfile <= 0 || line < linperfile))
+ {
+ if ((count = fread (itemp, 1, 128, infile)) != 128)
+ {
+ if (count == 0)
+ {
+ break;
+ }
+ else if (ferror (infile))
+ {
+ return UURET_IOERR;
+ }
+ }
+
+ if (pcrc)
+ *pcrc = crc32(*pcrc, itemp, count);
+ if (crc)
+ *crc = crc32(*crc, itemp, count);
+
+ line++;
+
+ /*
+ * Busy Callback
+ */
+
+ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+ uustring (S_ENCODE_CANCEL));
+ return UURET_CANCEL;
+ }
+
+ for (index=0; index<count; index++)
+ {
+ if (llen > 127)
+ {
+ if (fwrite (otemp, 1, llen, outfile) != llen ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ llen = 0;
+ optr = otemp;
+ }
+
+ switch ((char) ((int) itemp[index] + 42))
+ {
+ case '\0':
+ case '\t':
+ case '\n':
+ case '\r':
+ case '=':
+ case '\033':
+ *optr++ = '=';
+ *optr++ = (char) ((int) itemp[index] + 42 + 64);
+ llen += 2;
+ break;
+
+ case '.':
+ if (llen == 0)
+ {
+ *optr++ = '=';
+ *optr++ = (char) ((int) itemp[index] + 42 + 64);
+ llen += 2;
+ }
+ else
+ {
+ *optr++ = (char) ((int) itemp[index] + 42);
+ llen++;
+ }
+ break;
+
+ default:
+ *optr++ = (char) ((int) itemp[index] + 42);
+ llen++;
+ break;
+ }
+ }
+ }
+
+ /*
+ * write last line
+ */
+
+ if (llen)
+ {
+ if (fwrite (otemp, 1, llen, outfile) != llen ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ }
+
+ return UURET_OK;
+ }
+
+ /*
+ * Handling for binary encodings
+ */
+
+ /*
+ * select charset
+ */
+
+ table = etables[encoding];
+
+ if (table==NULL || bpl[encoding]==0)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUEncodeStream()");
+ return UURET_ILLVAL;
+ }
+
+ while (!feof (infile) && (linperfile <= 0 || line < linperfile))
+ {
+ if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding])
+ {
+ if (count == 0)
+ break;
+ else if (ferror (infile))
+ return UURET_IOERR;
+ }
+
+ optr = otemp;
+ llen = 0;
+
/*
* Busy Callback
*/
- if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
- uustring (S_ENCODE_CANCEL));
- return UURET_CANCEL;
- }
+ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+ uustring (S_ENCODE_CANCEL));
+ return UURET_CANCEL;
+ }
- if (encoding == PT_ENCODED) {
- /*
- * If there is a line feed, replace by eolstring
- */
- if (count > 0 && itemp[count-1] == '\n') {
- itemp[--count] = '\0';
- if (fwrite (itemp, 1, count, outfile) != count ||
- fwrite ((char *) eolstring, 1,
- strlen(eolstring), outfile) != strlen (eolstring)) {
- return UURET_IOERR;
- }
- }
- else {
- if (fwrite (itemp, 1, count, outfile) != llen) {
- return UURET_IOERR;
- }
- }
- }
- else if (encoding == QP_ENCODED) {
- for (index=0; index<count; index++) {
- if (llen == 0 && itemp[index] == '.') {
- /*
- * Special rule: encode '.' at the beginning of a line, so
- * that some mailers aren't confused.
- */
- *optr++ = '=';
- *optr++ = HexEncodeTable[itemp[index] >> 4];
- *optr++ = HexEncodeTable[itemp[index] & 0x0f];
- llen += 3;
- }
- else if ((itemp[index] >= 33 && itemp[index] <= 60) ||
- (itemp[index] >= 62 && itemp[index] <= 126) ||
- itemp[index] == 9 || itemp[index] == 32) {
- *optr++ = itemp[index];
- llen++;
- }
- else if (itemp[index] == '\n') {
- /*
- * If the last character before EOL was a space or tab,
- * we must encode it. If llen > 74, there's no space to do
- * that, so generate a soft line break instead.
- */
-
- if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32)) {
- *(optr-1) = '=';
- if (llen <= 74) {
- *optr++ = HexEncodeTable[itemp[index-1] >> 4];
- *optr++ = HexEncodeTable[itemp[index-1] & 0x0f];
- llen += 2;
- }
- }
-
- if (fwrite (otemp, 1, llen, outfile) != llen ||
- fwrite ((char *) eolstring, 1,
- strlen(eolstring), outfile) != strlen (eolstring)) {
- return UURET_IOERR;
- }
-
- /*
- * Fix the soft line break condition from above
- */
-
- if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) &&
- *(optr-1) == '=') {
- otemp[0] = '=';
- otemp[1] = HexEncodeTable[itemp[index-1] >> 4];
- otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f];
-
- if (fwrite (otemp, 1, 3, outfile) != 3 ||
- fwrite ((char *) eolstring, 1,
- strlen(eolstring), outfile) != strlen (eolstring)) {
- return UURET_IOERR;
- }
- }
-
- optr = otemp;
- llen = 0;
- }
- else {
- *optr++ = '=';
- *optr++ = HexEncodeTable[itemp[index] >> 4];
- *optr++ = HexEncodeTable[itemp[index] & 0x0f];
- llen += 3;
- }
-
- /*
- * Lines must be shorter than 76 characters (not counting CRLF).
- * If the line grows longer than that, we must include a soft
- * line break.
- */
-
- if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
- (llen >= 75 ||
- (!((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
- (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
- llen >= 73))) {
-
- *optr++ = '=';
- llen++;
-
- if (fwrite (otemp, 1, llen, outfile) != llen ||
- fwrite ((char *) eolstring, 1,
- strlen(eolstring), outfile) != strlen (eolstring)) {
- return UURET_IOERR;
- }
-
- optr = otemp;
- llen = 0;
- }
- }
- }
+ /*
+ * for UU and XX, encode the number of bytes as first character
+ */
+
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ *optr++ = table[count];
+ llen++;
+ }
+
+ /*
+ * Main encoding
+ */
+
+ for (index=0; index<=count-3; index+=3, llen+=4)
+ {
+ *optr++ = table[itemp[index] >> 2];
+ *optr++ = table[((itemp[index ] & 0x03) << 4)|(itemp[index+1] >> 4)];
+ *optr++ = table[((itemp[index+1] & 0x0f) << 2)|(itemp[index+2] >> 6)];
+ *optr++ = table[ itemp[index+2] & 0x3f];
+ }
+
+ /*
+ * Special handling for incomplete lines
+ */
+
+ if (index != count)
+ {
+ if (encoding == B64ENCODED)
+ {
+ if (count - index == 2)
+ {
+ *optr++ = table[itemp[index] >> 2];
+ *optr++ = table[((itemp[index ] & 0x03) << 4) |
+ ((itemp[index+1] & 0xf0) >> 4)];
+ *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
+ *optr++ = '=';
+ }
+ else if (count - index == 1)
+ {
+ *optr++ = table[ itemp[index] >> 2];
+ *optr++ = table[(itemp[index] & 0x03) << 4];
+ *optr++ = '=';
+ *optr++ = '=';
+ }
+ llen += 4;
+ }
+ else if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ if (count - index == 2)
+ {
+ *optr++ = table[itemp[index] >> 2];
+ *optr++ = table[((itemp[index ] & 0x03) << 4) |
+ ( itemp[index+1] >> 4)];
+ *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
+ *optr++ = table[0];
+ }
+ else if (count - index == 1)
+ {
+ *optr++ = table[ itemp[index] >> 2];
+ *optr++ = table[(itemp[index] & 0x03) << 4];
+ *optr++ = table[0];
+ *optr++ = table[0];
+ }
+ llen += 4;
+ }
+ }
+
+ /*
+ * end of line
+ */
+
+ tptr = eolstring;
+
+ while (*tptr)
+ *optr++ = *tptr++;
+
+ *optr++ = '\0';
+ llen += strlen ((char *) eolstring);
+
+ if (fwrite (otemp, 1, llen, outfile) != llen)
+ return UURET_IOERR;
line++;
}
+ return UURET_OK;
+}
- return UURET_OK;
- }
+static int
+UUEncodeStream_byFSize (FILE *outfile, FILE *infile, int encoding, long bpf, crc32_t *crc, crc32_t *pcrc)
+{
+ unsigned char *itemp = (char *) uuestr_itemp;
+ unsigned char *otemp = (char *) uuestr_otemp;
+ unsigned char *optr, *table, *tptr;
+ int index, count;
+ long offset=0;
+ long line = 0;
+ size_t llen;
+ ///TODO
+ int linperfile = 0;
+
+ if (outfile==NULL || infile==NULL ||
+ (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ return UURET_ILLVAL;
+ }
+
+ /*
+ * Special handling for plain text and quoted printable. Text is
+ * read line oriented.
+ */
+
+ if (encoding == PT_ENCODED || encoding == QP_ENCODED)
+ {
+ while (!feof (infile) && (linperfile <= 0 || line < linperfile))
+ {
+ if (_FP_fgets (itemp, 255, infile) == NULL)
+ {
+ break;
+ }
+
+ itemp[255] = '\0';
+ count = strlen (itemp);
+
+ llen = 0;
+ optr = otemp;
+
+ /*
+ * Busy Callback
+ */
+
+ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+ uustring (S_ENCODE_CANCEL));
+ return UURET_CANCEL;
+ }
+
+ if (encoding == PT_ENCODED)
+ {
+ /*
+ * If there is a line feed, replace by eolstring
+ */
+ if (count > 0 && itemp[count-1] == '\n')
+ {
+ itemp[--count] = '\0';
+ if (fwrite (itemp, 1, count, outfile) != count ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ }
+ else
+ {
+ if (fwrite (itemp, 1, count, outfile) != llen)
+ {
+ return UURET_IOERR;
+ }
+ }
+ }
+ else if (encoding == QP_ENCODED)
+ {
+ for (index=0; index<count; index++)
+ {
+ if (llen == 0 && itemp[index] == '.')
+ {
+ /*
+ * Special rule: encode '.' at the beginning of a line, so
+ * that some mailers aren't confused.
+ */
+ *optr++ = '=';
+ *optr++ = HexEncodeTable[itemp[index] >> 4];
+ *optr++ = HexEncodeTable[itemp[index] & 0x0f];
+ llen += 3;
+ }
+ else if ((itemp[index] >= 33 && itemp[index] <= 60) ||
+ (itemp[index] >= 62 && itemp[index] <= 126) ||
+ itemp[index] == 9 || itemp[index] == 32)
+ {
+ *optr++ = itemp[index];
+ llen++;
+ }
+ else if (itemp[index] == '\n')
+ {
+ /*
+ * If the last character before EOL was a space or tab,
+ * we must encode it. If llen > 74, there's no space to do
+ * that, so generate a soft line break instead.
+ */
+
+ if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32))
+ {
+ *(optr-1) = '=';
+ if (llen <= 74)
+ {
+ *optr++ = HexEncodeTable[itemp[index-1] >> 4];
+ *optr++ = HexEncodeTable[itemp[index-1] & 0x0f];
+ llen += 2;
+ }
+ }
+
+ if (fwrite (otemp, 1, llen, outfile) != llen ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+
+ /*
+ * Fix the soft line break condition from above
+ */
+
+ if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) &&
+ *(optr-1) == '=')
+ {
+ otemp[0] = '=';
+ otemp[1] = HexEncodeTable[itemp[index-1] >> 4];
+ otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f];
+
+ if (fwrite (otemp, 1, 3, outfile) != 3 ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ }
+
+ optr = otemp;
+ llen = 0;
+ }
+ else
+ {
+ *optr++ = '=';
+ *optr++ = HexEncodeTable[itemp[index] >> 4];
+ *optr++ = HexEncodeTable[itemp[index] & 0x0f];
+ llen += 3;
+ }
+
+ /*
+ * Lines must be shorter than 76 characters (not counting CRLF).
+ * If the line grows longer than that, we must include a soft
+ * line break.
+ */
+
+ if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
+ (llen >= 75 ||
+ (!((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
+ (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
+ llen >= 73)))
+ {
+
+ *optr++ = '=';
+ llen++;
+
+ if (fwrite (otemp, 1, llen, outfile) != llen ||
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+
+ optr = otemp;
+ llen = 0;
+ }
+ }
+ }
+
+ line++;
+ }
+
+ return UURET_OK;
+ }
/*
* Special handling for yEnc
*/
- if (encoding == YENC_ENCODED) {
+ if (encoding == YENC_ENCODED)
+ {
llen = 0;
optr = otemp;
-
- while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
- if ((count = fread (itemp, 1, 128, infile)) != 128) {
- if (count == 0) {
- break;
- }
- else if (ferror (infile)) {
- return UURET_IOERR;
- }
+ long rest = bpf;
+ long current = 0;
+
+ while (rest > 0)
+ {
+ current = rest > 128 ? 128 : rest;
+
+ if ((count = fread (itemp, sizeof(unsigned char), current, infile)) != 128)
+ {
+ if (count == 0)
+ {
+ break;
+ }
+ else if (ferror (infile))
+ {
+ return UURET_IOERR;
+ }
}
+ rest -= count;
+
if (pcrc)
- *pcrc = crc32(*pcrc, itemp, count);
+ *pcrc = crc32(*pcrc, itemp, count);
if (crc)
- *crc = crc32(*crc, itemp, count);
+ *crc = crc32(*crc, itemp, count);
line++;
@@ -434,65 +900,74 @@ UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc3
* Busy Callback
*/
- if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
- uustring (S_ENCODE_CANCEL));
- return UURET_CANCEL;
- }
-
- for (index=0; index<count; index++) {
- if (llen > 127) {
- if (fwrite (otemp, 1, llen, outfile) != llen ||
- fwrite ((char *) eolstring, 1,
- strlen(eolstring), outfile) != strlen (eolstring)) {
- return UURET_IOERR;
- }
- llen = 0;
- optr = otemp;
- }
-
- switch ((char) ((int) itemp[index] + 42)) {
- case '\0':
- case '\t':
- case '\n':
- case '\r':
- case '=':
- case '\033':
- *optr++ = '=';
- *optr++ = (char) ((int) itemp[index] + 42 + 64);
- llen += 2;
- break;
-
- case '.':
- if (llen == 0) {
- *optr++ = '=';
- *optr++ = (char) ((int) itemp[index] + 42 + 64);
- llen += 2;
- }
- else {
- *optr++ = (char) ((int) itemp[index] + 42);
- llen++;
- }
- break;
-
- default:
- *optr++ = (char) ((int) itemp[index] + 42);
- llen++;
- break;
- }
- }
+ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+ uustring (S_ENCODE_CANCEL));
+ return UURET_CANCEL;
+ }
+
+ for (index=0; index<count; index++)
+ {
+ if (llen > 127 )
+ {
+ if (fwrite (otemp, sizeof(unsigned char), llen, outfile) != llen ||
+ fwrite ((char *) eolstring, sizeof(unsigned char),
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
+ llen = 0;
+ optr = otemp;
+ }
+
+ switch ((char) ((int) itemp[index] + 42))
+ {
+ case '\0':
+ case '\t':
+ case '\n':
+ case '\r':
+ case '=':
+ case '\033':
+ *optr++ = '=';
+ *optr++ = (char) ((int) itemp[index] + 42 + 64);
+ llen += 2;
+ break;
+
+ case '.':
+ if (llen == 0)
+ {
+ *optr++ = '=';
+ *optr++ = (char) ((int) itemp[index] + 42 + 64);
+ llen += 2;
+ }
+ else
+ {
+ *optr++ = (char) ((int) itemp[index] + 42);
+ llen++;
+ }
+ break;
+
+ default:
+ *optr++ = (char) ((int) itemp[index] + 42);
+ llen++;
+ break;
+ }
+ }
}
/*
* write last line
*/
- if (llen) {
+ if (llen)
+ {
if (fwrite (otemp, 1, llen, outfile) != llen ||
- fwrite ((char *) eolstring, 1,
- strlen(eolstring), outfile) != strlen (eolstring)) {
- return UURET_IOERR;
- }
+ fwrite ((char *) eolstring, 1,
+ strlen(eolstring), outfile) != strlen (eolstring))
+ {
+ return UURET_IOERR;
+ }
}
return UURET_OK;
@@ -508,20 +983,27 @@ UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc3
table = etables[encoding];
- if (table==NULL || bpl[encoding]==0) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUEncodeStream()");
+ if (table==NULL || bpl[encoding]==0)
+ {
return UURET_ILLVAL;
}
- while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
- if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) {
+ long rest = bpf;
+ long current = 0;
+
+ while (!feof (infile) && rest > 0)
+ {
+ current = rest > bpl[encoding] ? bpl[encoding] : rest;
+ if ((count = fread (itemp, 1, current, infile)) != bpl[encoding])
+ {
if (count == 0)
- break;
+ break;
else if (ferror (infile))
- return UURET_IOERR;
+ return UURET_IOERR;
}
+ rest -= count;
+
optr = otemp;
llen = 0;
@@ -529,70 +1011,80 @@ UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc3
* Busy Callback
*/
- if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
- uustring (S_ENCODE_CANCEL));
- return UURET_CANCEL;
- }
+ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+ uustring (S_ENCODE_CANCEL));
+ return UURET_CANCEL;
+ }
/*
* for UU and XX, encode the number of bytes as first character
*/
- if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- *optr++ = table[count];
- llen++;
- }
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ *optr++ = table[count];
+ llen++;
+ }
/*
* Main encoding
*/
- for (index=0; index<=count-3; index+=3, llen+=4) {
- *optr++ = table[itemp[index] >> 2];
- *optr++ = table[((itemp[index ] & 0x03) << 4)|(itemp[index+1] >> 4)];
- *optr++ = table[((itemp[index+1] & 0x0f) << 2)|(itemp[index+2] >> 6)];
- *optr++ = table[ itemp[index+2] & 0x3f];
- }
+ for (index=0; index<=count-3; index+=3, llen+=4)
+ {
+ *optr++ = table[itemp[index] >> 2];
+ *optr++ = table[((itemp[index ] & 0x03) << 4)|(itemp[index+1] >> 4)];
+ *optr++ = table[((itemp[index+1] & 0x0f) << 2)|(itemp[index+2] >> 6)];
+ *optr++ = table[ itemp[index+2] & 0x3f];
+ }
/*
* Special handling for incomplete lines
*/
- if (index != count) {
- if (encoding == B64ENCODED) {
- if (count - index == 2) {
- *optr++ = table[itemp[index] >> 2];
- *optr++ = table[((itemp[index ] & 0x03) << 4) |
- ((itemp[index+1] & 0xf0) >> 4)];
- *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
- *optr++ = '=';
- }
- else if (count - index == 1) {
- *optr++ = table[ itemp[index] >> 2];
- *optr++ = table[(itemp[index] & 0x03) << 4];
- *optr++ = '=';
- *optr++ = '=';
- }
- llen += 4;
- }
- else if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- if (count - index == 2) {
- *optr++ = table[itemp[index] >> 2];
- *optr++ = table[((itemp[index ] & 0x03) << 4) |
- ( itemp[index+1] >> 4)];
- *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
- *optr++ = table[0];
- }
- else if (count - index == 1) {
- *optr++ = table[ itemp[index] >> 2];
- *optr++ = table[(itemp[index] & 0x03) << 4];
- *optr++ = table[0];
- *optr++ = table[0];
- }
- llen += 4;
+ if (index != count)
+ {
+ if (encoding == B64ENCODED)
+ {
+ if (count - index == 2)
+ {
+ *optr++ = table[itemp[index] >> 2];
+ *optr++ = table[((itemp[index ] & 0x03) << 4) |
+ ((itemp[index+1] & 0xf0) >> 4)];
+ *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
+ *optr++ = '=';
+ }
+ else if (count - index == 1)
+ {
+ *optr++ = table[ itemp[index] >> 2];
+ *optr++ = table[(itemp[index] & 0x03) << 4];
+ *optr++ = '=';
+ *optr++ = '=';
+ }
+ llen += 4;
+ }
+ else if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ if (count - index == 2)
+ {
+ *optr++ = table[itemp[index] >> 2];
+ *optr++ = table[((itemp[index ] & 0x03) << 4) |
+ ( itemp[index+1] >> 4)];
+ *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
+ *optr++ = table[0];
+ }
+ else if (count - index == 1)
+ {
+ *optr++ = table[ itemp[index] >> 2];
+ *optr++ = table[(itemp[index] & 0x03) << 4];
+ *optr++ = table[0];
+ *optr++ = table[0];
+ }
+ llen += 4;
+ }
}
- }
/*
* end of line
@@ -620,7 +1112,7 @@ UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc3
int UUEXPORT
UUEncodeMulti (FILE *outfile, FILE *infile, char *infname, int encoding,
- char *outfname, char *mimetype, int filemode)
+ char *outfname, char *mimetype, int filemode)
{
mimemap *miter=mimetable;
struct stat finfo;
@@ -634,41 +1126,48 @@ UUEncodeMulti (FILE *outfile, FILE *infile, char *infname, int encoding,
(infile == NULL && infname==NULL) ||
(outfname==NULL && infname==NULL) ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUEncodeMulti()");
- return UURET_ILLVAL;
- }
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUEncodeMulti()");
+ return UURET_ILLVAL;
+ }
progress.action = 0;
- if (infile==NULL) {
- if (stat (infname, &finfo) == -1) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_STAT_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
- }
- if ((theifile = fopen (infname, "rb")) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_OPEN_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
- }
- themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
- progress.fsize = (long) finfo.st_size;
- }
- else {
- if (fstat (fileno (infile), &finfo) != 0) {
- themode = (filemode)?filemode:0644;
- progress.fsize = -1;
- }
- else {
- themode = (int) finfo.st_mode & 0777;
+ if (infile==NULL)
+ {
+ if (stat (infname, &finfo) == -1)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_STAT_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if ((theifile = fopen (infname, "rb")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
progress.fsize = (long) finfo.st_size;
}
- theifile = infile;
- }
+ else
+ {
+ if (fstat (fileno (infile), &finfo) != 0)
+ {
+ themode = (filemode)?filemode:0644;
+ progress.fsize = -1;
+ }
+ else
+ {
+ themode = (int) finfo.st_mode & 0777;
+ progress.fsize = (long) finfo.st_size;
+ }
+ theifile = infile;
+ }
if (progress.fsize < 0)
progress.fsize = -1;
@@ -687,85 +1186,99 @@ UUEncodeMulti (FILE *outfile, FILE *infile, char *infname, int encoding,
* Application/Octet-Stream
*/
- if (mimetype == NULL) {
- if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) {
- while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
- miter++;
- mimetype = miter->mimetype;
+ if (mimetype == NULL)
+ {
+ if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.')))
+ {
+ while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
+ miter++;
+ mimetype = miter->mimetype;
+ }
}
- }
- if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) {
- mimetype = "text/plain";
- }
+ if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED))
+ {
+ mimetype = "text/plain";
+ }
/*
* print sub-header
*/
- if (encoding != YENC_ENCODED) {
- fprintf (outfile, "Content-Type: %s%s",
- (mimetype)?mimetype:"Application/Octet-Stream",
- eolstring);
- fprintf (outfile, "Content-Transfer-Encoding: %s%s",
- CTE_TYPE(encoding), eolstring);
- fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
- UUFNameFilter ((outfname)?outfname:infname), eolstring);
- fprintf (outfile, "%s", eolstring);
- }
+ if (encoding != YENC_ENCODED)
+ {
+ fprintf (outfile, "Content-Type: %s%s",
+ (mimetype)?mimetype:"Application/Octet-Stream",
+ eolstring);
+ fprintf (outfile, "Content-Transfer-Encoding: %s%s",
+ CTE_TYPE(encoding), eolstring);
+ fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
+ UUFNameFilter ((outfname)?outfname:infname), eolstring);
+ fprintf (outfile, "%s", eolstring);
+ }
- if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- fprintf (outfile, "begin %o %s%s",
- (themode) ? themode : 0644,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- crc = crc32(0L, Z_NULL, 0);
- crcptr = &crc;
- if (progress.fsize == -1) {
- fprintf (outfile, "=ybegin line=128 name=%s%s",
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else {
- fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
- progress.fsize,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ fprintf (outfile, "begin %o %s%s",
+ (themode) ? themode : 0644,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ crc = crc32(0L, Z_NULL, 0);
+ crcptr = &crc;
+ if (progress.fsize == -1)
+ {
+ fprintf (outfile, "=ybegin line=128 name=%s%s",
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
+ progress.fsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
}
- }
- if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) {
- if (res != UURET_CANCEL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_ERR_ENCODING),
- UUFNameFilter ((infname)?infname:outfname),
- (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res));
+ if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK)
+ {
+ if (res != UURET_CANCEL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_ERR_ENCODING),
+ UUFNameFilter ((infname)?infname:outfname),
+ (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res));
+ }
+ progress.action = 0;
+ return res;
}
- progress.action = 0;
- return res;
- }
- if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- fprintf (outfile, "%c%s",
- (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
- eolstring);
- fprintf (outfile, "end%s", eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- if (progress.fsize == -1) {
- fprintf (outfile, "=yend crc32=%08lx%s",
- crc,
- eolstring);
- }
- else {
- fprintf (outfile, "=yend size=%ld crc32=%08lx%s",
- progress.fsize,
- crc,
- eolstring);
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ fprintf (outfile, "%c%s",
+ (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
+ eolstring);
+ fprintf (outfile, "end%s", eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ if (progress.fsize == -1)
+ {
+ fprintf (outfile, "=yend crc32=%08lx%s",
+ crc,
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=yend size=%ld crc32=%08lx%s",
+ progress.fsize,
+ crc,
+ eolstring);
+ }
}
- }
/*
* empty line at end does no harm
@@ -786,9 +1299,9 @@ UUEncodeMulti (FILE *outfile, FILE *infile, char *infname, int encoding,
int UUEXPORT
UUEncodePartial (FILE *outfile, FILE *infile,
- char *infname, int encoding,
- char *outfname, char *mimetype,
- int filemode, int partno, long linperfile, unsigned long* crcptr)
+ char *infname, int encoding,
+ char *outfname, char *mimetype,
+ int filemode, int partno, long linperfile, unsigned long* crcptr)
{
mimemap *miter=mimetable;
static FILE *theifile;
@@ -803,11 +1316,12 @@ UUEncodePartial (FILE *outfile, FILE *infile,
if ((outfname==NULL&&infname==NULL) || partno<=0 ||
(infile == NULL&&infname==NULL) || outfile==NULL ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUEncodePartial()");
- return UURET_ILLVAL;
- }
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+// UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+// uustring (S_PARM_CHECK), "UUEncodePartial()");
+ return UURET_ILLVAL;
+ }
/*
* The first part needs a set of headers
@@ -815,143 +1329,162 @@ UUEncodePartial (FILE *outfile, FILE *infile,
progress.action = 0;
- if (partno == 1) {
- *crcptr = crc32(0L, Z_NULL, 0);
-
- if (infile==NULL) {
- if (stat (infname, &finfo) == -1) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_STAT_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
- }
- if ((theifile = fopen (infname, "rb")) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_OPEN_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
- }
- if (linperfile <= 0)
- numparts = 1;
+ if (partno == 1)
+ {
+ *crcptr = crc32(0L, Z_NULL, 0);
+
+ if (infile==NULL)
+ {
+ if (stat (infname, &finfo) == -1)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_STAT_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if ((theifile = fopen (infname, "rb")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if (linperfile <= 0)
+ numparts = 1;
+ else
+ numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
+ (linperfile*bpl[encoding]));
+
+ themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
+ thesize = (long) finfo.st_size;
+ }
else
- numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
- (linperfile*bpl[encoding]));
-
- themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
- thesize = (long) finfo.st_size;
- }
- else {
- if (fstat (fileno (infile), &finfo) != 0) {
- UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
- uustring (S_STAT_ONE_PART));
- numparts = 1;
- themode = (filemode)?filemode:0644;
- thesize = -1;
- }
- else {
- if (linperfile <= 0)
- numparts = 1;
- else
- numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
- (linperfile*bpl[encoding]));
-
- themode = (int) finfo.st_mode & 0777;
- thesize = (long) finfo.st_size;
- }
- theifile = infile;
- }
-
- _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
-
- progress.totsize = (thesize>=0) ? thesize : -1;
- progress.partno = 1;
- progress.numparts = numparts;
- progress.percent = 0;
- progress.foffset = 0;
+ {
+ if (fstat (fileno (infile), &finfo) != 0)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
+ uustring (S_STAT_ONE_PART));
+ numparts = 1;
+ themode = (filemode)?filemode:0644;
+ thesize = -1;
+ }
+ else
+ {
+ if (linperfile <= 0)
+ numparts = 1;
+ else
+ numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
+ (linperfile*bpl[encoding]));
+
+ themode = (int) finfo.st_mode & 0777;
+ thesize = (long) finfo.st_size;
+ }
+ theifile = infile;
+ }
+
+ _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
+
+ progress.totsize = (thesize>=0) ? thesize : -1;
+ progress.partno = 1;
+ progress.numparts = numparts;
+ progress.percent = 0;
+ progress.foffset = 0;
- /*
- * If not given from outside, select an appropriate Content-Type by
- * looking at the file's extension. If it is unknown, default to
- * Application/Octet-Stream
- */
-
- if (mimetype == NULL) {
- if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) {
- while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
- miter++;
- mimetype = miter->mimetype;
- }
- }
+ /*
+ * If not given from outside, select an appropriate Content-Type by
+ * looking at the file's extension. If it is unknown, default to
+ * Application/Octet-Stream
+ */
- if (mimetype == NULL && (encoding==PT_ENCODED || encoding==QP_ENCODED)) {
- mimetype = "text/plain";
- }
+ if (mimetype == NULL)
+ {
+ if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.')))
+ {
+ while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
+ miter++;
+ mimetype = miter->mimetype;
+ }
+ }
+
+ if (mimetype == NULL && (encoding==PT_ENCODED || encoding==QP_ENCODED))
+ {
+ mimetype = "text/plain";
+ }
- /*
- * print sub-header
- */
+ /*
+ * print sub-header
+ */
- if (encoding != YENC_ENCODED) {
- fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
- fprintf (outfile, "Content-Type: %s%s",
- (mimetype)?mimetype:"Application/Octet-Stream",
- eolstring);
- fprintf (outfile, "Content-Transfer-Encoding: %s%s",
- CTE_TYPE(encoding), eolstring);
- fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
- UUFNameFilter ((outfname)?outfname:infname), eolstring);
- }
+ if (encoding != YENC_ENCODED)
+ {
+ fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
+ fprintf (outfile, "Content-Type: %s%s",
+ (mimetype)?mimetype:"Application/Octet-Stream",
+ eolstring);
+ fprintf (outfile, "Content-Transfer-Encoding: %s%s",
+ CTE_TYPE(encoding), eolstring);
+ fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
+ UUFNameFilter ((outfname)?outfname:infname), eolstring);
+ }
- fprintf (outfile, "%s", eolstring);
+ fprintf (outfile, "%s", eolstring);
- /*
- * for the first part of UU or XX messages, print a begin line
- */
+ /*
+ * for the first part of UU or XX messages, print a begin line
+ */
- if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- fprintf (outfile, "begin %o %s%s",
- (themode) ? themode : ((filemode)?filemode:0644),
- UUFNameFilter ((outfname)?outfname:infname), eolstring);
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ fprintf (outfile, "begin %o %s%s",
+ (themode) ? themode : ((filemode)?filemode:0644),
+ UUFNameFilter ((outfname)?outfname:infname), eolstring);
+ }
}
- }
- if (encoding == YENC_ENCODED) {
- pcrc = crc32(0L, Z_NULL, 0);
- pcrcptr = &pcrc;
- if (numparts != 1) {
- if (progress.totsize == -1) {
- fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
- partno,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else {
- fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
- partno,
- progress.totsize,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
-
- fprintf (outfile, "=ypart begin=%d end=%d%s",
- (partno-1)*linperfile*128+1,
- (partno*linperfile*128) < progress.totsize ?
- (partno*linperfile*128) : progress.totsize,
- eolstring);
- }
- else {
- if (progress.totsize == -1) {
- fprintf (outfile, "=ybegin line=128 name=%s%s",
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else {
- fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
- progress.totsize,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
+ if (encoding == YENC_ENCODED)
+ {
+ pcrc = crc32(0L, Z_NULL, 0);
+ pcrcptr = &pcrc;
+ if (numparts != 1)
+ {
+ if (progress.totsize == -1)
+ {
+ fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
+ partno,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
+ partno,
+ progress.totsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+
+ fprintf (outfile, "=ypart begin=%d end=%d%s",
+ (partno-1)*linperfile*128+1,
+ (partno*linperfile*128) < progress.totsize ?
+ (partno*linperfile*128) : progress.totsize,
+ eolstring);
+ }
+ else
+ {
+ if (progress.totsize == -1)
+ {
+ fprintf (outfile, "=ybegin line=128 name=%s%s",
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
+ progress.totsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ }
}
- }
/*
* update progress information
@@ -973,67 +1506,77 @@ UUEncodePartial (FILE *outfile, FILE *infile,
progress.action = UUACT_ENCODING;
if ((res = UUEncodeStream (outfile, theifile, encoding, linperfile,
- crcptr, pcrcptr)) != UURET_OK) {
- if (infile==NULL) fclose (theifile);
- if (res != UURET_CANCEL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_ERR_ENCODING),
- UUFNameFilter ((outfname)?outfname:infname),
- (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
+ crcptr, pcrcptr)) != UURET_OK)
+ {
+ if (infile==NULL) fclose (theifile);
+ if (res != UURET_CANCEL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_ERR_ENCODING),
+ UUFNameFilter ((outfname)?outfname:infname),
+ (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
+ }
+ progress.action = 0;
+ return res;
}
- progress.action = 0;
- return res;
- }
/*
* print end line
*/
if (feof (theifile) &&
- (encoding == UU_ENCODED || encoding == XX_ENCODED)) {
- fprintf (outfile, "%c%s",
- (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
- eolstring);
- fprintf (outfile, "end%s", eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- if (numparts != 1) {
- fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
- (partno*linperfile*128) < progress.totsize ?
- linperfile*128 : (progress.totsize-(partno-1)*linperfile*128),
- partno,
- pcrc);
- }
- else {
- fprintf (outfile, "=yend size=%d",
- progress.totsize);
+ (encoding == UU_ENCODED || encoding == XX_ENCODED))
+ {
+ fprintf (outfile, "%c%s",
+ (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
+ eolstring);
+ fprintf (outfile, "end%s", eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ if (numparts != 1)
+ {
+ fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
+ (partno*linperfile*128) < progress.totsize ?
+ linperfile*128 : (progress.totsize-(partno-1)*linperfile*128),
+ partno,
+ pcrc);
+ }
+ else
+ {
+ fprintf (outfile, "=yend size=%d",
+ progress.totsize);
+ }
+ if (feof (theifile))
+ fprintf (outfile, " crc32=%08lx", *crcptr);
+ fprintf (outfile, "%s", eolstring);
}
- if (feof (theifile))
- fprintf (outfile, " crc32=%08lx", *crcptr);
- fprintf (outfile, "%s", eolstring);
- }
/*
* empty line at end does no harm
*/
- if (encoding != PT_ENCODED && encoding != QP_ENCODED) {
- fprintf (outfile, "%s", eolstring);
- }
-
- if (infile==NULL) {
- if (res != UURET_OK) {
- progress.action = 0;
- fclose (theifile);
- return res;
+ if (encoding != PT_ENCODED && encoding != QP_ENCODED)
+ {
+ fprintf (outfile, "%s", eolstring);
}
- if (feof (theifile)) {
- progress.action = 0;
- fclose (theifile);
- return UURET_OK;
+
+ if (infile==NULL)
+ {
+ if (res != UURET_OK)
+ {
+ progress.action = 0;
+ fclose (theifile);
+ return res;
+ }
+ if (feof (theifile))
+ {
+ progress.action = 0;
+ fclose (theifile);
+ return UURET_OK;
+ }
+ return UURET_CONT;
}
- return UURET_CONT;
- }
/*
* leave progress.action as-is
@@ -1042,62 +1585,355 @@ UUEncodePartial (FILE *outfile, FILE *infile,
return UURET_OK;
}
-/*
- * send output to a stream, don't do any headers at all
- */
-
int UUEXPORT
-UUEncodeToStream (FILE *outfile, FILE *infile,
- char *infname, int encoding,
- char *outfname, int filemode)
+UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
+ char *infname, int encoding,
+ char *outfname, char *mimetype,
+ int filemode, int partno, long bpf, unsigned long* crcptr)
{
+ mimemap *miter=mimetable;
+ static FILE *theifile;
+ int themode, numparts;
struct stat finfo;
- FILE *theifile;
- int themode;
+ long thesize;
+ char *ptr;
int res;
- crc32_t crc;
- crc32_t *crcptr=NULL;
+ crc32_t pcrc;
+ crc32_t *pcrcptr=NULL;
- if (outfile==NULL ||
- (infile == NULL&&infname==NULL) ||
- (outfname==NULL&&infname==NULL) ||
+ if ((outfname==NULL&&infname==NULL) || partno<=0 ||
+ (infile == NULL&&infname==NULL) || outfile==NULL ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUEncodeToStream()");
- return UURET_ILLVAL;
- }
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ return UURET_ILLVAL;
+ }
+
+ /*
+ * The first part needs a set of headers
+ */
progress.action = 0;
- if (infile==NULL) {
- if (stat (infname, &finfo) == -1) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_STAT_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
+ if (partno == 1)
+ {
+ *crcptr = crc32(0L, Z_NULL, 0);
+
+ if (infile==NULL)
+ {
+ if (stat (infname, &finfo) == -1)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_STAT_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if ((theifile = fopen (infname, "rb")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if (bpf <= 0)
+ numparts = 1;
+ else
+ numparts = (int) ((long)ceill(finfo.st_size / bpf));
+
+ themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
+ thesize = (long) finfo.st_size;
+ }
+ else
+ {
+ if (fstat (fileno (infile), &finfo) != 0)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
+ uustring (S_STAT_ONE_PART));
+ numparts = 1;
+ themode = (filemode)?filemode:0644;
+ thesize = -1;
+ }
+ else
+ {
+ themode = (int) finfo.st_mode & 0777;
+ thesize = (long) finfo.st_size;
+
+ if (bpf <= 0)
+ numparts = 1;
+ else
+ numparts = (int) ((long)ceill(thesize / bpf));
+
+
+ }
+ theifile = infile;
+ }
+
+ _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
+
+ progress.totsize = (thesize>=0) ? thesize : -1;
+ progress.partno = 1;
+ progress.numparts = numparts;
+ progress.percent = 0;
+ progress.foffset = 0;
+
+ /*
+ * If not given from outside, select an appropriate Content-Type by
+ * looking at the file's extension. If it is unknown, default to
+ * Application/Octet-Stream
+ */
+
+ if (mimetype == NULL)
+ {
+ if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.')))
+ {
+ while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
+ miter++;
+ mimetype = miter->mimetype;
+ }
+ }
+
+ if (mimetype == NULL && (encoding==PT_ENCODED || encoding==QP_ENCODED))
+ {
+ mimetype = "text/plain";
+ }
+
+ /*
+ * print sub-header
+ */
+
+ if (encoding != YENC_ENCODED)
+ {
+ fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
+ fprintf (outfile, "Content-Type: %s%s",
+ (mimetype)?mimetype:"Application/Octet-Stream",
+ eolstring);
+ fprintf (outfile, "Content-Transfer-Encoding: %s%s",
+ CTE_TYPE(encoding), eolstring);
+ fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
+ UUFNameFilter ((outfname)?outfname:infname), eolstring);
+ }
+
+ fprintf (outfile, "%s", eolstring);
+
+ /*
+ * for the first part of UU or XX messages, print a begin line
+ */
+
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ fprintf (outfile, "begin %o %s%s",
+ (themode) ? themode : ((filemode)?filemode:0644),
+ UUFNameFilter ((outfname)?outfname:infname), eolstring);
+ }
}
- if ((theifile = fopen (infname, "rb")) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_OPEN_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
+ if (encoding == YENC_ENCODED)
+ {
+ pcrc = crc32(0L, Z_NULL, 0);
+ pcrcptr = &pcrc;
+ if (numparts != 1)
+ {
+ if (progress.totsize == -1)
+ {
+ fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
+ partno,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
+ partno,
+ progress.totsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+
+ fprintf (outfile, "=ypart begin=%d end=%d%s",
+ (partno-1)*bpf,
+ (partno*bpf) < progress.totsize ?
+ (partno*bpf) : progress.totsize,
+ eolstring);
+ }
+ else
+ {
+ if (progress.totsize == -1)
+ {
+ fprintf (outfile, "=ybegin line=128 name=%s%s",
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
+ progress.totsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ }
}
- themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
- progress.fsize = (long) finfo.st_size;
+
+ /*
+ * update progress information
+ */
+
+ progress.partno = partno;
+ progress.percent = 0;
+ progress.foffset = ftell (theifile);
+
+ if (progress.totsize <= 0)
+ progress.fsize = -1;
+ else if (bpf <= 0)
+ progress.fsize = progress.totsize;
+ else if (progress.foffset+ bpf > progress.totsize)
+ progress.fsize = progress.totsize - progress.foffset;
+ else
+ progress.fsize = bpf;
+
+ progress.action = UUACT_ENCODING;
+
+ if ((res = UUEncodeStream_byFSize (outfile, theifile, encoding, bpf,
+ crcptr, pcrcptr)) != UURET_OK)
+ {
+ if (infile==NULL) fclose (theifile);
+ if (res != UURET_CANCEL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_ERR_ENCODING),
+ UUFNameFilter ((outfname)?outfname:infname),
+ (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
+ }
+ progress.action = 0;
+ return res;
+ }
+
+ /*
+ * print end line
+ */
+
+ if (feof (theifile) &&
+ (encoding == UU_ENCODED || encoding == XX_ENCODED))
+ {
+ fprintf (outfile, "%c%s",
+ (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
+ eolstring);
+ fprintf (outfile, "end%s", eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ if (numparts != 1)
+ {
+ fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
+ (partno*bpf) < progress.totsize ?
+ bpf : (progress.totsize-(partno-1)*bpf),
+ partno,
+ pcrc);
+ }
+ else
+ {
+ fprintf (outfile, "=yend size=%d",
+ progress.totsize);
+ }
+ if (feof (theifile))
+ fprintf (outfile, " crc32=%08lx", *crcptr);
+ fprintf (outfile, "%s", eolstring);
+ }
+
+ /*
+ * empty line at end does no harm
+ */
+
+ if (encoding != PT_ENCODED && encoding != QP_ENCODED)
+ {
+ fprintf (outfile, "%s", eolstring);
+ }
+
+ if (infile==NULL)
+ {
+ if (res != UURET_OK)
+ {
+ progress.action = 0;
+ fclose (theifile);
+ return res;
+ }
+ if (feof (theifile))
+ {
+ progress.action = 0;
+ fclose (theifile);
+ return UURET_OK;
+ }
+ return UURET_CONT;
}
- else {
- if (fstat (fileno (infile), &finfo) == -1) {
- /* gotta live with it */
- themode = 0644;
- progress.fsize = -1;
+
+ /*
+ * leave progress.action as-is
+ */
+
+ return UURET_OK;
+}
+
+/*
+ * send output to a stream, don't do any headers at all
+ */
+
+int UUEXPORT
+UUEncodeToStream (FILE *outfile, FILE *infile,
+ char *infname, int encoding,
+ char *outfname, int filemode)
+{
+ struct stat finfo;
+ FILE *theifile;
+ int themode;
+ int res;
+ crc32_t crc;
+ crc32_t *crcptr=NULL;
+
+ if (outfile==NULL ||
+ (infile == NULL&&infname==NULL) ||
+ (outfname==NULL&&infname==NULL) ||
+ (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUEncodeToStream()");
+ return UURET_ILLVAL;
}
- else {
+
+ progress.action = 0;
+
+ if (infile==NULL)
+ {
+ if (stat (infname, &finfo) == -1)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_STAT_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if ((theifile = fopen (infname, "rb")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
progress.fsize = (long) finfo.st_size;
}
- theifile = infile;
- }
+ else
+ {
+ if (fstat (fileno (infile), &finfo) == -1)
+ {
+ /* gotta live with it */
+ themode = 0644;
+ progress.fsize = -1;
+ }
+ else
+ {
+ themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
+ progress.fsize = (long) finfo.st_size;
+ }
+ theifile = infile;
+ }
if (progress.fsize < 0)
progress.fsize = -1;
@@ -1110,58 +1946,68 @@ UUEncodeToStream (FILE *outfile, FILE *infile,
progress.foffset = 0;
progress.action = UUACT_ENCODING;
- if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- fprintf (outfile, "begin %o %s%s",
- (themode) ? themode : 0644,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- crc = crc32(0L, Z_NULL, 0);
- crcptr = &crc;
- if (progress.fsize == -1) {
- fprintf (outfile, "=ybegin line=128 name=%s%s",
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else {
- fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
- progress.fsize,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ fprintf (outfile, "begin %o %s%s",
+ (themode) ? themode : 0644,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ crc = crc32(0L, Z_NULL, 0);
+ crcptr = &crc;
+ if (progress.fsize == -1)
+ {
+ fprintf (outfile, "=ybegin line=128 name=%s%s",
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
+ progress.fsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
}
- }
- if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) {
- if (res != UURET_CANCEL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_ERR_ENCODING),
- UUFNameFilter ((infname)?infname:outfname),
- (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
+ if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK)
+ {
+ if (res != UURET_CANCEL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_ERR_ENCODING),
+ UUFNameFilter ((infname)?infname:outfname),
+ (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
+ }
+ progress.action = 0;
+ return res;
}
- progress.action = 0;
- return res;
- }
- if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
- fprintf (outfile, "%c%s",
- (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
- eolstring);
- fprintf (outfile, "end%s", eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- if (progress.fsize == -1) {
- fprintf (outfile, "=yend crc32=%08lx%s",
- crc,
- eolstring);
- }
- else {
- fprintf (outfile, "=yend size=%ld crc32=%08lx%s",
- progress.fsize,
- crc,
- eolstring);
+ if (encoding == UU_ENCODED || encoding == XX_ENCODED)
+ {
+ fprintf (outfile, "%c%s",
+ (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
+ eolstring);
+ fprintf (outfile, "end%s", eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ if (progress.fsize == -1)
+ {
+ fprintf (outfile, "=yend crc32=%08lx%s",
+ crc,
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=yend size=%ld crc32=%08lx%s",
+ progress.fsize,
+ crc,
+ eolstring);
+ }
}
- }
/*
* empty line at end does no harm
@@ -1181,7 +2027,7 @@ UUEncodeToStream (FILE *outfile, FILE *infile,
int UUEXPORT
UUEncodeToFile (FILE *infile, char *infname, int encoding,
- char *outfname, char *diskname, long linperfile)
+ char *outfname, char *diskname, long linperfile)
{
int part, numparts, len, filemode, res;
char *oname=NULL, *optr, *ptr;
@@ -1193,52 +2039,60 @@ UUEncodeToFile (FILE *infile, char *infname, int encoding,
if ((diskname==NULL&&infname==NULL) ||
(outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUEncodeToFile()");
- return UURET_ILLVAL;
- }
-
- if (diskname) {
- if ((ptr = strchr (diskname, '/')) == NULL)
- ptr = strchr (diskname, '\\');
- if (ptr) {
- len = strlen (diskname) + ((uuencodeext)?strlen(uuencodeext):3) + 5;
-
- if ((oname = malloc (len)) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_OUT_OF_MEMORY), len);
- return UURET_NOMEM;
- }
- sprintf (oname, "%s", diskname);
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUEncodeToFile()");
+ return UURET_ILLVAL;
}
- else {
- len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname)
- + ((uuencodeext)?strlen(uuencodeext):0) + 5;
- if ((oname = malloc (len)) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_OUT_OF_MEMORY), len);
- return UURET_NOMEM;
- }
- sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname);
+ if (diskname)
+ {
+ if ((ptr = strchr (diskname, '/')) == NULL)
+ ptr = strchr (diskname, '\\');
+ if (ptr)
+ {
+ len = strlen (diskname) + ((uuencodeext)?strlen(uuencodeext):3) + 5;
+
+ if ((oname = malloc (len)) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_OUT_OF_MEMORY), len);
+ return UURET_NOMEM;
+ }
+ sprintf (oname, "%s", diskname);
+ }
+ else
+ {
+ len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname)
+ + ((uuencodeext)?strlen(uuencodeext):0) + 5;
+
+ if ((oname = malloc (len)) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_OUT_OF_MEMORY), len);
+ return UURET_NOMEM;
+ }
+ sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname);
+ }
}
- }
- else {
- len = ((uusavepath) ? strlen (uusavepath) : 0) +
- strlen(UUFNameFilter(infname)) +
- ((uuencodeext)?strlen(uuencodeext):0) + 5;
-
- if ((oname = malloc (len)) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_OUT_OF_MEMORY), len);
- return UURET_NOMEM;
+ else
+ {
+ len = ((uusavepath) ? strlen (uusavepath) : 0) +
+ strlen(UUFNameFilter(infname)) +
+ ((uuencodeext)?strlen(uuencodeext):0) + 5;
+
+ if ((oname = malloc (len)) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_OUT_OF_MEMORY), len);
+ return UURET_NOMEM;
+ }
+ optr = UUFNameFilter (infname);
+ sprintf (oname, "%s%s",
+ (uusavepath)?uusavepath:"",
+ (*optr=='.')?optr+1:optr);
}
- optr = UUFNameFilter (infname);
- sprintf (oname, "%s%s",
- (uusavepath)?uusavepath:"",
- (*optr=='.')?optr+1:optr);
- }
/*
* optr points after the last dot, so that we can print the part number
@@ -1246,235 +2100,263 @@ UUEncodeToFile (FILE *infile, char *infname, int encoding,
*/
optr = _FP_strrchr (oname, '.');
- if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) {
- optr = oname + strlen (oname);
- *optr++ = '.';
- }
- else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') {
- optr = oname + strlen (oname);
- *optr++ = '.';
- }
+ if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL)
+ {
+ optr = oname + strlen (oname);
+ *optr++ = '.';
+ }
+ else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\')
+ {
+ optr = oname + strlen (oname);
+ *optr++ = '.';
+ }
else
optr++;
progress.action = 0;
- if (infile==NULL) {
- if (stat (infname, &finfo) == -1) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_STAT_FILE),
- infname, strerror (uu_errno=errno));
- _FP_free (oname);
- return UURET_IOERR;
- }
- if ((theifile = fopen (infname, "rb")) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_OPEN_FILE),
- infname, strerror (uu_errno=errno));
- _FP_free (oname);
- return UURET_IOERR;
- }
- if (linperfile <= 0)
- numparts = 1;
- else
- numparts = (int) (((long)finfo.st_size + (linperfile*bpl[encoding]-1)) /
- (linperfile*bpl[encoding]));
-
- filemode = (int) finfo.st_mode & 0777;
- progress.totsize = (long) finfo.st_size;
- }
- else {
- if (fstat (fileno (infile), &finfo) == -1) {
- /* gotta live with it */
- filemode = 0644;
- numparts = -1;
- progress.totsize = -1;
- }
- else {
+ if (infile==NULL)
+ {
+ if (stat (infname, &finfo) == -1)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_STAT_FILE),
+ infname, strerror (uu_errno=errno));
+ _FP_free (oname);
+ return UURET_IOERR;
+ }
+ if ((theifile = fopen (infname, "rb")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_FILE),
+ infname, strerror (uu_errno=errno));
+ _FP_free (oname);
+ return UURET_IOERR;
+ }
if (linperfile <= 0)
- numparts = 1;
+ numparts = 1;
else
- numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
- (linperfile*bpl[encoding]));
+ numparts = (int) (((long)finfo.st_size + (linperfile*bpl[encoding]-1)) /
+ (linperfile*bpl[encoding]));
filemode = (int) finfo.st_mode & 0777;
- progress.totsize = -1;
+ progress.totsize = (long) finfo.st_size;
+ }
+ else
+ {
+ if (fstat (fileno (infile), &finfo) == -1)
+ {
+ /* gotta live with it */
+ filemode = 0644;
+ numparts = -1;
+ progress.totsize = -1;
+ }
+ else
+ {
+ if (linperfile <= 0)
+ numparts = 1;
+ else
+ numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
+ (linperfile*bpl[encoding]));
+
+ filemode = (int) finfo.st_mode & 0777;
+ progress.totsize = -1;
+ }
+ theifile = infile;
}
- theifile = infile;
- }
_FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
progress.totsize = (progress.totsize<0) ? -1 : progress.totsize;
progress.numparts = numparts;
- for (part=1; !feof (theifile); part++) {
- /*
- * Attach extension
- */
- if (progress.numparts==1 && progress.totsize!=-1 && uuencodeext!=NULL)
- strcpy (optr, uuencodeext);
- else
- sprintf (optr, "%03d", part);
-
- /*
- * check if target file exists
- */
-
- if (!uu_overwrite) {
- if (stat (oname, &finfo) == 0) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_TARGET_EXISTS), oname);
- if (infile==NULL) fclose (theifile);
- progress.action = 0;
- free (oname);
- return UURET_EXISTS;
- }
- }
-
- /*
- * update progress information
- */
+ for (part=1; !feof (theifile); part++)
+ {
+ /*
+ * Attach extension
+ */
+ if (progress.numparts==1 && progress.totsize!=-1 && uuencodeext!=NULL)
+ strcpy (optr, uuencodeext);
+ else
+ sprintf (optr, "%03d", part);
- progress.action = 0;
- progress.partno = part;
- progress.percent = 0;
- progress.foffset = ftell (theifile);
-
- if (progress.totsize == -1)
- progress.fsize = -1;
- else if (linperfile <= 0)
- progress.fsize = progress.totsize;
- else if (progress.foffset+linperfile*bpl[encoding] > progress.totsize)
- progress.fsize = progress.totsize - progress.foffset;
- else
- progress.fsize = linperfile*bpl[encoding];
+ /*
+ * check if target file exists
+ */
- progress.action = UUACT_ENCODING;
+ if (!uu_overwrite)
+ {
+ if (stat (oname, &finfo) == 0)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_TARGET_EXISTS), oname);
+ if (infile==NULL) fclose (theifile);
+ progress.action = 0;
+ free (oname);
+ return UURET_EXISTS;
+ }
+ }
- if ((outfile = fopen (oname, "w")) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_OPEN_TARGET),
- oname, strerror (uu_errno = errno));
- if (infile==NULL) fclose (theifile);
- progress.action = 0;
- free (oname);
- return UURET_IOERR;
- }
+ /*
+ * update progress information
+ */
- if (encoding != YENC_ENCODED) {
- fprintf (outfile, "%s", eolstring);
- fprintf (outfile, "_=_ %s", eolstring);
- if (numparts == -1)
- fprintf (outfile, "_=_ Part %03d of file %s%s",
- part, UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
+ progress.action = 0;
+ progress.partno = part;
+ progress.percent = 0;
+ progress.foffset = ftell (theifile);
+
+ if (progress.totsize == -1)
+ progress.fsize = -1;
+ else if (linperfile <= 0)
+ progress.fsize = progress.totsize;
+ else if (progress.foffset+linperfile*bpl[encoding] > progress.totsize)
+ progress.fsize = progress.totsize - progress.foffset;
else
- fprintf (outfile, "_=_ Part %03d of %03d of file %s%s",
- part, numparts,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- fprintf (outfile, "_=_ %s", eolstring);
- fprintf (outfile, "%s", eolstring);
- }
+ progress.fsize = linperfile*bpl[encoding];
+
+ progress.action = UUACT_ENCODING;
+
+ if ((outfile = fopen (oname, "w")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_TARGET),
+ oname, strerror (uu_errno = errno));
+ if (infile==NULL) fclose (theifile);
+ progress.action = 0;
+ free (oname);
+ return UURET_IOERR;
+ }
+
+ if (encoding != YENC_ENCODED)
+ {
+ fprintf (outfile, "%s", eolstring);
+ fprintf (outfile, "_=_ %s", eolstring);
+ if (numparts == -1)
+ fprintf (outfile, "_=_ Part %03d of file %s%s",
+ part, UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ else
+ fprintf (outfile, "_=_ Part %03d of %03d of file %s%s",
+ part, numparts,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ fprintf (outfile, "_=_ %s", eolstring);
+ fprintf (outfile, "%s", eolstring);
+ }
+
+ if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED))
+ {
+ fprintf (outfile, "begin %o %s%s",
+ (filemode)?filemode : 0644,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ if (!crcptr)
+ {
+ crc = crc32(0L, Z_NULL, 0);
+ crcptr = &crc;
+ }
+ pcrc = crc32(0L, Z_NULL, 0);
+ pcrcptr = &pcrc;
+ if (numparts != 1)
+ {
+ if (progress.totsize == -1)
+ {
+ fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
+ part,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
+ part,
+ progress.totsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+
+ fprintf (outfile, "=ypart begin=%d end=%d%s",
+ (part-1)*linperfile*128+1,
+ (part*linperfile*128) < progress.totsize ?
+ (part*linperfile*128) : progress.totsize,
+ eolstring);
+ }
+ else
+ {
+ if (progress.totsize == -1)
+ {
+ fprintf (outfile, "=ybegin line=128 name=%s%s",
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ else
+ {
+ fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
+ progress.totsize,
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ }
+ }
+ }
+
+ if ((res = UUEncodeStream (outfile, theifile,
+ encoding, linperfile, crcptr, pcrcptr)) != UURET_OK)
+ {
+ if (res != UURET_CANCEL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_ERR_ENCODING),
+ UUFNameFilter ((infname)?infname:outfname),
+ (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
+ }
+ if (infile==NULL) fclose (theifile);
+ progress.action = 0;
+ fclose (outfile);
+ unlink (oname);
+ _FP_free (oname);
+ return res;
+ }
+
+ if (feof (theifile) &&
+ (encoding == UU_ENCODED || encoding == XX_ENCODED))
+ {
+ fprintf (outfile, "%c%s",
+ (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
+ eolstring);
+ fprintf (outfile, "end%s", eolstring);
+ }
+ else if (encoding == YENC_ENCODED)
+ {
+ if (numparts != 1)
+ {
+ fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
+ (part*linperfile*128) < progress.totsize ?
+ linperfile*128 : (progress.totsize-(part-1)*linperfile*128),
+ part,
+ pcrc);
+ }
+ else
+ {
+ fprintf (outfile, "=yend size=%d",
+ progress.totsize);
+ }
+ if (feof (theifile))
+ fprintf (outfile, " crc32=%08lx", crc);
+ fprintf (outfile, "%s", eolstring);
+ }
- if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) {
- fprintf (outfile, "begin %o %s%s",
- (filemode)?filemode : 0644,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- if (!crcptr) {
- crc = crc32(0L, Z_NULL, 0);
- crcptr = &crc;
- }
- pcrc = crc32(0L, Z_NULL, 0);
- pcrcptr = &pcrc;
- if (numparts != 1) {
- if (progress.totsize == -1) {
- fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
- part,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else {
- fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
- part,
- progress.totsize,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
-
- fprintf (outfile, "=ypart begin=%d end=%d%s",
- (part-1)*linperfile*128+1,
- (part*linperfile*128) < progress.totsize ?
- (part*linperfile*128) : progress.totsize,
- eolstring);
- }
- else {
- if (progress.totsize == -1) {
- fprintf (outfile, "=ybegin line=128 name=%s%s",
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- else {
- fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
- progress.totsize,
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- }
- }
- }
-
- if ((res = UUEncodeStream (outfile, theifile,
- encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) {
- if (res != UURET_CANCEL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_ERR_ENCODING),
- UUFNameFilter ((infname)?infname:outfname),
- (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
- }
- if (infile==NULL) fclose (theifile);
- progress.action = 0;
- fclose (outfile);
- unlink (oname);
- _FP_free (oname);
- return res;
- }
+ /*
+ * empty line at end does no harm
+ */
- if (feof (theifile) &&
- (encoding == UU_ENCODED || encoding == XX_ENCODED)) {
- fprintf (outfile, "%c%s",
- (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
- eolstring);
- fprintf (outfile, "end%s", eolstring);
- }
- else if (encoding == YENC_ENCODED) {
- if (numparts != 1) {
- fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
- (part*linperfile*128) < progress.totsize ?
- linperfile*128 : (progress.totsize-(part-1)*linperfile*128),
- part,
- pcrc);
- }
- else {
- fprintf (outfile, "=yend size=%d",
- progress.totsize);
- }
- if (feof (theifile))
- fprintf (outfile, " crc32=%08lx", crc);
fprintf (outfile, "%s", eolstring);
+ fclose (outfile);
}
- /*
- * empty line at end does no harm
- */
-
- fprintf (outfile, "%s", eolstring);
- fclose (outfile);
- }
-
if (infile==NULL) fclose (theifile);
progress.action = 0;
_FP_free (oname);
@@ -1489,26 +2371,26 @@ UUEncodeToFile (FILE *infile, char *infname, int encoding,
int UUEXPORT
UUE_PrepSingle (FILE *outfile, FILE *infile,
- char *infname, int encoding,
- char *outfname, int filemode,
- char *destination, char *from,
- char *subject, int isemail)
+ char *infname, int encoding,
+ char *outfname, int filemode,
+ char *destination, char *from,
+ char *subject, int isemail)
{
return UUE_PrepSingleExt (outfile, infile,
- infname, encoding,
- outfname, filemode,
- destination, from,
- subject, NULL,
- isemail);
+ infname, encoding,
+ outfname, filemode,
+ destination, from,
+ subject, NULL,
+ isemail);
}
int UUEXPORT
UUE_PrepSingleExt (FILE *outfile, FILE *infile,
- char *infname, int encoding,
- char *outfname, int filemode,
- char *destination, char *from,
- char *subject, char *replyto,
- int isemail)
+ char *infname, int encoding,
+ char *outfname, int filemode,
+ char *destination, char *from,
+ char *subject, char *replyto,
+ int isemail)
{
mimemap *miter=mimetable;
char *subline, *oname;
@@ -1517,75 +2399,85 @@ UUE_PrepSingleExt (FILE *outfile, FILE *infile,
if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUE_PrepSingle()");
- return UURET_ILLVAL;
- }
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUE_PrepSingle()");
+ return UURET_ILLVAL;
+ }
oname = UUFNameFilter ((outfname)?outfname:infname);
len = ((subject)?strlen(subject):0) + strlen(oname) + 40;
- if ((ptr = _FP_strrchr (oname, '.'))) {
- while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
- miter++;
- mimetype = miter->mimetype;
- }
+ if ((ptr = _FP_strrchr (oname, '.')))
+ {
+ while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
+ miter++;
+ mimetype = miter->mimetype;
+ }
else
mimetype = NULL;
- if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) {
- mimetype = "text/plain";
- }
+ if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED))
+ {
+ mimetype = "text/plain";
+ }
- if ((subline = (char *) malloc (len)) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_OUT_OF_MEMORY), len);
- return UURET_NOMEM;
- }
+ if ((subline = (char *) malloc (len)) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_OUT_OF_MEMORY), len);
+ return UURET_NOMEM;
+ }
- if (encoding == YENC_ENCODED) {
- if (subject)
- sprintf (subline, "- %s - %s (001/001)", oname, subject);
- else
- sprintf (subline, "- %s - (001/001)", oname);
- }
- else {
- if (subject)
- sprintf (subline, "%s (001/001) - [ %s ]", subject, oname);
- else
- sprintf (subline, "[ %s ] (001/001)", oname);
- }
+ if (encoding == YENC_ENCODED)
+ {
+ if (subject)
+ sprintf (subline, "- %s - %s (001/001)", oname, subject);
+ else
+ sprintf (subline, "- %s - (001/001)", oname);
+ }
+ else
+ {
+ if (subject)
+ sprintf (subline, "%s (001/001) - [ %s ]", subject, oname);
+ else
+ sprintf (subline, "[ %s ] (001/001)", oname);
+ }
- if (from) {
- fprintf (outfile, "From: %s%s", from, eolstring);
- }
- if (destination) {
- fprintf (outfile, "%s: %s%s",
- (isemail)?"To":"Newsgroups",
- destination, eolstring);
- }
+ if (from)
+ {
+ fprintf (outfile, "From: %s%s", from, eolstring);
+ }
+ if (destination)
+ {
+ fprintf (outfile, "%s: %s%s",
+ (isemail)?"To":"Newsgroups",
+ destination, eolstring);
+ }
fprintf (outfile, "Subject: %s%s", subline, eolstring);
- if (replyto) {
- fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
- }
+ if (replyto)
+ {
+ fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
+ }
- if (encoding != YENC_ENCODED) {
- fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
- fprintf (outfile, "Content-Type: %s; name=\"%s\"%s",
- (mimetype)?mimetype:"Application/Octet-Stream",
- UUFNameFilter ((outfname)?outfname:infname),
- eolstring);
- fprintf (outfile, "Content-Transfer-Encoding: %s%s",
- CTE_TYPE(encoding), eolstring);
- }
+ if (encoding != YENC_ENCODED)
+ {
+ fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
+ fprintf (outfile, "Content-Type: %s; name=\"%s\"%s",
+ (mimetype)?mimetype:"Application/Octet-Stream",
+ UUFNameFilter ((outfname)?outfname:infname),
+ eolstring);
+ fprintf (outfile, "Content-Transfer-Encoding: %s%s",
+ CTE_TYPE(encoding), eolstring);
+ }
fprintf (outfile, "%s", eolstring);
res = UUEncodeToStream (outfile, infile, infname, encoding,
- outfname, filemode);
+ outfname, filemode);
_FP_free (subline);
return res;
@@ -1593,29 +2485,29 @@ UUE_PrepSingleExt (FILE *outfile, FILE *infile,
int UUEXPORT
UUE_PrepPartial (FILE *outfile, FILE *infile,
- char *infname, int encoding,
- char *outfname, int filemode,
- int partno, long linperfile, long filesize,
- char *destination, char *from, char *subject,
- int isemail)
+ char *infname, int encoding,
+ char *outfname, int filemode,
+ int partno, long linperfile, long filesize,
+ char *destination, char *from, char *subject,
+ int isemail)
{
return UUE_PrepPartialExt (outfile, infile,
- infname, encoding,
- outfname, filemode,
- partno, linperfile, filesize,
- destination,
- from, subject, NULL,
- isemail);
+ infname, encoding,
+ outfname, filemode,
+ partno, linperfile, filesize,
+ destination,
+ from, subject, NULL,
+ isemail);
}
int UUEXPORT
UUE_PrepPartialExt (FILE *outfile, FILE *infile,
- char *infname, int encoding,
- char *outfname, int filemode,
- int partno, long linperfile, long filesize,
- char *destination,
- char *from, char *subject, char *replyto,
- int isemail)
+ char *infname, int encoding,
+ char *outfname, int filemode,
+ int partno, long linperfile, long filesize,
+ char *destination,
+ char *from, char *subject, char *replyto,
+ int isemail)
{
static int numparts, themode;
static char mimeid[64];
@@ -1629,11 +2521,12 @@ UUE_PrepPartialExt (FILE *outfile, FILE *infile,
if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
- encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_PARM_CHECK), "UUE_PrepPartial()");
- return UURET_ILLVAL;
- }
+ encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED))
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_PARM_CHECK), "UUE_PrepPartial()");
+ return UURET_ILLVAL;
+ }
oname = UUFNameFilter ((outfname)?outfname:infname);
len = ((subject)?strlen(subject):0) + strlen (oname) + 40;
@@ -1642,154 +2535,174 @@ UUE_PrepPartialExt (FILE *outfile, FILE *infile,
* if first part, get information about the file
*/
- if (partno == 1) {
- if (infile==NULL) {
- if (stat (infname, &finfo) == -1) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_STAT_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
- }
- if ((theifile = fopen (infname, "rb")) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_NOT_OPEN_FILE),
- infname, strerror (uu_errno=errno));
- return UURET_IOERR;
- }
- if (linperfile <= 0)
- numparts = 1;
+ if (partno == 1)
+ {
+ if (infile==NULL)
+ {
+ if (stat (infname, &finfo) == -1)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_STAT_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if ((theifile = fopen (infname, "rb")) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_NOT_OPEN_FILE),
+ infname, strerror (uu_errno=errno));
+ return UURET_IOERR;
+ }
+ if (linperfile <= 0)
+ numparts = 1;
+ else
+ numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
+ (linperfile*bpl[encoding]));
+
+ themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
+ thesize = (long) finfo.st_size;
+ }
else
- numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
- (linperfile*bpl[encoding]));
-
- themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
- thesize = (long) finfo.st_size;
- }
- else {
- if (fstat (fileno (infile), &finfo) != 0) {
- if (filesize <= 0) {
- UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
- uustring (S_STAT_ONE_PART));
- numparts = 1;
- themode = (filemode)?filemode:0644;
- thesize = -1;
- }
- else {
- if (linperfile <= 0)
- numparts = 1;
- else
- numparts = (int) ((filesize+(linperfile*bpl[encoding]-1))/
- (linperfile*bpl[encoding]));
-
- themode = (filemode)?filemode:0644;
- thesize = filesize;
- }
- }
- else {
- if (linperfile <= 0)
- numparts = 1;
- else
- numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
- (linperfile*bpl[encoding]));
-
- filemode = (int) finfo.st_mode & 0777;
- thesize = (long) finfo.st_size;
- }
- theifile = infile;
- }
+ {
+ if (fstat (fileno (infile), &finfo) != 0)
+ {
+ if (filesize <= 0)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
+ uustring (S_STAT_ONE_PART));
+ numparts = 1;
+ themode = (filemode)?filemode:0644;
+ thesize = -1;
+ }
+ else
+ {
+ if (linperfile <= 0)
+ numparts = 1;
+ else
+ numparts = (int) ((filesize+(linperfile*bpl[encoding]-1))/
+ (linperfile*bpl[encoding]));
+
+ themode = (filemode)?filemode:0644;
+ thesize = filesize;
+ }
+ }
+ else
+ {
+ if (linperfile <= 0)
+ numparts = 1;
+ else
+ numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/
+ (linperfile*bpl[encoding]));
+
+ filemode = (int) finfo.st_mode & 0777;
+ thesize = (long) finfo.st_size;
+ }
+ theifile = infile;
+ }
- /*
- * if there's one part only, don't use Message/Partial
- */
+ /*
+ * if there's one part only, don't use Message/Partial
+ */
- if (numparts == 1) {
- if (infile==NULL) fclose (theifile);
- return UUE_PrepSingleExt (outfile, infile, infname, encoding,
- outfname, filemode, destination,
- from, subject, replyto, isemail);
- }
+ if (numparts == 1)
+ {
+ if (infile==NULL) fclose (theifile);
+ return UUE_PrepSingleExt (outfile, infile, infname, encoding,
+ outfname, filemode, destination,
+ from, subject, replyto, isemail);
+ }
- /*
- * we also need a unique ID
- */
+ /*
+ * we also need a unique ID
+ */
- sprintf (mimeid, "UUDV-%ld.%ld.%s",
- (long) time(NULL), thesize,
- (strlen(oname)>16)?"oops":oname);
- }
+ sprintf (mimeid, "UUDV-%ld.%ld.%s",
+ (long) time(NULL), thesize,
+ (strlen(oname)>16)?"oops":oname);
+ }
- if ((subline = (char *) malloc (len)) == NULL) {
- UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
- uustring (S_OUT_OF_MEMORY), len);
- if (infile==NULL) fclose (theifile);
- return UURET_NOMEM;
- }
+ if ((subline = (char *) malloc (len)) == NULL)
+ {
+ UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
+ uustring (S_OUT_OF_MEMORY), len);
+ if (infile==NULL) fclose (theifile);
+ return UURET_NOMEM;
+ }
- if (encoding == YENC_ENCODED) {
- if (partno == 1)
- crc = crc32(0L, Z_NULL, 0);
- crcptr = &crc;
- if (subject)
- sprintf (subline, "- %s - %s (%03d/%03d)", oname, subject,
- partno, numparts);
- else
- sprintf (subline, "- %s - (%03d/%03d)", oname,
- partno, numparts);
- }
- else {
- if (subject)
- sprintf (subline, "%s (%03d/%03d) - [ %s ]",
- subject, partno, numparts, oname);
- else
- sprintf (subline, "[ %s ] (%03d/%03d)",
- oname, partno, numparts);
- }
+ if (encoding == YENC_ENCODED)
+ {
+ if (partno == 1)
+ crc = crc32(0L, Z_NULL, 0);
+ crcptr = &crc;
+ if (subject)
+ sprintf (subline, "- %s - %s (%03d/%03d)", oname, subject,
+ partno, numparts);
+ else
+ sprintf (subline, "- %s - (%03d/%03d)", oname,
+ partno, numparts);
+ }
+ else
+ {
+ if (subject)
+ sprintf (subline, "%s (%03d/%03d) - [ %s ]",
+ subject, partno, numparts, oname);
+ else
+ sprintf (subline, "[ %s ] (%03d/%03d)",
+ oname, partno, numparts);
+ }
- if (from) {
- fprintf (outfile, "From: %s%s", from, eolstring);
- }
+ if (from)
+ {
+ fprintf (outfile, "From: %s%s", from, eolstring);
+ }
- if (destination) {
- fprintf (outfile, "%s: %s%s",
- (isemail)?"To":"Newsgroups",
- destination, eolstring);
- }
+ if (destination)
+ {
+ fprintf (outfile, "%s: %s%s",
+ (isemail)?"To":"Newsgroups",
+ destination, eolstring);
+ }
fprintf (outfile, "Subject: %s%s", subline, eolstring);
- if (replyto) {
- fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
- }
+ if (replyto)
+ {
+ fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
+ }
- if (encoding != YENC_ENCODED) {
- fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
- fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s",
- partno, numparts, eolstring);
- fprintf (outfile, "\tid=\"%s\"%s",
- mimeid, eolstring);
- }
+ if (encoding != YENC_ENCODED)
+ {
+ fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
+ fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s",
+ partno, numparts, eolstring);
+ fprintf (outfile, "\tid=\"%s\"%s",
+ mimeid, eolstring);
+ }
fprintf (outfile, "%s", eolstring);
res = UUEncodePartial (outfile, theifile,
- infname, encoding,
- (outfname)?outfname:infname, NULL,
- themode, partno, linperfile, crcptr);
+ infname, encoding,
+ (outfname)?outfname:infname, NULL,
+ themode, partno, linperfile, crcptr);
_FP_free (subline);
- if (infile==NULL) {
- if (res != UURET_OK) {
- fclose (theifile);
- return res;
- }
- if (feof (theifile)) {
- fclose (theifile);
- return UURET_OK;
+ if (infile==NULL)
+ {
+ if (res != UURET_OK)
+ {
+ fclose (theifile);
+ return res;
+ }
+ if (feof (theifile))
+ {
+ fclose (theifile);
+ return UURET_OK;
+ }
+ return UURET_CONT;
}
- return UURET_CONT;
- }
return res;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]