#!/bin/bash
# postmarkmark installer
###SHELLPACK preamble postmark-install 1.51.orig
WEB_LOCATION=http://ftp.de.debian.org/debian/pool/main/p/postmark
MIRROR_LOCATION="$WEBROOT/postmark/"

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

# Unconditionally fetch the tar to find out the real version number
TARFILE=postmark_${VERSION}.tar.gz
sources_fetch $WEB_LOCATION/$TARFILE $MIRROR_LOCATION/$TARFILE $SHELLPACK_SOURCES/$TARFILE

# Building from scratch, uncompress the tar
cd $SHELLPACK_SOURCES
tar xf $TARFILE
if [ $? -ne 0 ]; then
	error "$P: tar xf postmark_${VERSION}.tar.gz failed"
	popd > /dev/null
	exit $SHELLPACK_ERROR
fi

echo "--- postmark-1.51.orig/postmark-1.51.c
+++ postmark-1.51/postmark-1.51.c
@@ -71,6 +71,12 @@
 #define GETWD(x) getwd(x)
 #define MKDIR(x) mkdir(x,0700)
 #define SEPARATOR \"/\"
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #endif
 
 #define MAX_LINE 255
@@ -280,7 +286,7 @@
    int weight=1;
    char *split;
 
-   if (split=strrchr(params,' '))
+   if( (split=strrchr(params,' ')) )
       {
       *split='\0';
       if ((weight=atoi(split+1))<=0)
@@ -299,7 +305,7 @@
 {
    file_system *new_file_system;
 
-   if (new_file_system=(file_system *)calloc(1,sizeof(file_system)))
+   if( (new_file_system=(file_system *)calloc(1,sizeof(file_system))) )
       {
       strcpy(new_file_system->system.name,params);
       new_file_system->system.size=weight;
@@ -528,30 +534,30 @@
    t_elapsed=diff_time(t_end_time,t_start_time);
 
    fprintf(fp,\"Time:\n\");
-   fprintf(fp,\"\t%d seconds total\n\",elapsed);
-   fprintf(fp,\"\t%d seconds of transactions (%d per second)\n\",t_elapsed,
-      transactions/t_elapsed);
+   fprintf(fp,\"\t%d seconds total\n\", (int)elapsed);
+   fprintf(fp,\"\t%d seconds of transactions (%d per second)\n\", (int)t_elapsed,
+      (int)(transactions/t_elapsed));
 
    fprintf(fp,\"\nFiles:\n\");
    fprintf(fp,\"\t%d created (%d per second)\n\",files_created,
-      files_created/elapsed);
+      (int)(files_created/elapsed));
 
    interval=diff_time(t_start_time,start_time);
    fprintf(fp,\"\t\tCreation alone: %d files (%d per second)\n\",simultaneous,
       simultaneous/interval);
    fprintf(fp,\"\t\tMixed with transactions: %d files (%d per second)\n\",
-      files_created-simultaneous,(files_created-simultaneous)/t_elapsed);
-   fprintf(fp,\"\t%d read (%d per second)\n\",files_read,files_read/t_elapsed);
+      files_created-simultaneous, (int)((files_created-simultaneous)/t_elapsed));
+   fprintf(fp,\"\t%d read (%d per second)\n\",files_read, (int)(files_read/t_elapsed));
    fprintf(fp,\"\t%d appended (%d per second)\n\",files_appended,
-      files_appended/t_elapsed);
+       (int)(files_appended/t_elapsed));
    fprintf(fp,\"\t%d deleted (%d per second)\n\",files_created,
-      files_created/elapsed);
+       (int)(files_created/elapsed));
    
    interval=diff_time(end_time,t_end_time);
    fprintf(fp,\"\t\tDeletion alone: %d files (%d per second)\n\",deleted,
       deleted/interval);
    fprintf(fp,\"\t\tMixed with transactions: %d files (%d per second)\n\",
-      files_deleted-deleted,(files_deleted-deleted)/t_elapsed);
+      files_deleted-deleted,(int)((files_deleted-deleted)/t_elapsed));
 
    fprintf(fp,\"\nData:\n\");
    fprintf(fp,\"\t%s read \",scalef(bytes_read));
@@ -572,7 +578,7 @@
    t_elapsed=diff_time(t_end_time,t_start_time);
    interval=diff_time(t_start_time,start_time);
 
-   fprintf(fp,\"%d %d %.2f \", elapsed, t_elapsed, 
+   fprintf(fp,\"%d %d %.2f \", (int)elapsed, (int)t_elapsed, 
       (float)transactions/t_elapsed);
    fprintf(fp, \"%.2f %.2f %.2f \", (float)files_created/elapsed, 
       (float)simultaneous/interval,
@@ -661,7 +667,7 @@
 
    if (subdirectories>1)
       {
-      sprintf(conversion,\"s%d%s\",RND(subdirectories),SEPARATOR);
+      sprintf(conversion,\"s%d%s\",(int)(RND(subdirectories)),SEPARATOR);
       strcat(dest,conversion);
       }
 
@@ -1044,6 +1050,8 @@
    return(1); /* return 1 unless exit requested, then return 0 */
 }
 
+int read_config_file(char *filename, char *buffer, int ignore);
+
 /* CLI callback for 'load' - read configuration file */
 int cli_load(param)
 char *param;
@@ -1149,7 +1157,7 @@
 
    printf(\"%s\",PROMPT);                 /* print prompt */
    fflush(stdout);                      /* force prompt to print */
-   if (result=fgets(buffer,size,stdin)) /* read line safely */
+   if( (result=fgets(buffer,size,stdin)) ) /* read line safely */
       {
       buffer[strlen(buffer)-1]='\0';    /* delete final CR */
       if (!strcmp(buffer,\"?\"))           /* translate aliases */
@@ -1199,7 +1207,7 @@
    int result=1; /* default exit value - proceed with UI */
    FILE *fp;
 
-   if (fp=fopen(filename,\"r\")) /* open config file */
+   if( (fp=fopen(filename,\"r\")) ) /* open config file */
       {
       printf(\"Reading configuration from file '%s'\n\",filename);
       while (fgets(buffer,MAX_LINE,fp) && result) /* read lines until 'quit' */
@@ -1219,7 +1227,7 @@
 }
 
 /* main function - reads config files then enters get line/parse line loop */
-main(argc,argv)
+int main(argc,argv)
 int argc;
 char *argv[];
 {
@@ -1229,6 +1237,7 @@
    if (read_config_file((argc==2)?argv[1]:\".pmrc\",buffer,1))
       while (cli_read_line(buffer,MAX_LINE) && cli_parse_line(buffer))
          ;
+   return 0;
 }
 
 /*" | patch -p0 || exit -1

# Rename directory to something we expect.
DST_DIR=`tar tf $TARFILE | head -n 1 | awk -F / '{print $1}'`
mv $DST_DIR postmark-${VERSION}-installed
pushd postmark-${VERSION}-installed > /dev/null || die Failed to rename tar

# Build
gcc ${MMTESTS_BUILD_CFLAGS:--O2} -Wall postmark-1.51.c -o postmark
if [ $? -ne 0 ]; then
	error "$P: build failed"
	popd > /dev/null
	exit $SHELLPACK_ERROR
fi

echo postmark installed successfully
