public inbox for linux-8086@vger.kernel.org
 help / color / mirror / Atom feed
From: u-vpoa@aetey.se
To: Jody Bruchon <jody@jodybruchon.com>
Cc: ELKS <linux-8086@vger.kernel.org>
Subject: Re: a compression tool useful with constrained memory
Date: Mon, 27 Apr 2015 23:04:09 +0200	[thread overview]
Message-ID: <20150427210409.GB8197@example.net> (raw)
In-Reply-To: <553CDBC3.4020605@jodybruchon.com>

[-- Attachment #1: Type: text/plain, Size: 77 bytes --]

Hello,

Here comes a patch (removing some unnecessary size limitations).

Rl

[-- Attachment #2: prems.patch20150426-20150427 --]
[-- Type: text/plain, Size: 7118 bytes --]

--- PRES/pres.c.ori	2015-04-27 22:04:01.705132713 +0200
+++ PRES/pres.c	2015-04-27 22:11:45.855097441 +0200
@@ -3,6 +3,14 @@
  *
  * A library (prem/malprem) and a cli frontend to it (pres)
  *
+ * version 0.2015-04-27
+ *         removed undue data stream size limitations,
+ *         now it should work for up to 2GB files,
+ *         bigger streams will be compressed alright but
+ *         the diagnostic messages could become wrong after 2GB
+ * version 0.2015-04-26
+ *         initial public release
+ *
  * Usage: pres [-dcfFqii] [file ...]
  * Flags:
  *      -d:         Decompress instead of compressing
@@ -246,8 +254,8 @@
     exit(exit_stat);
 }
 
-long int enk; /* input data length */
-long int elk; /* compressed length */
+unsigned long int enk; /* input data length */
+unsigned long int elk; /* compressed length */
 
 /*
  * Compressing input to output (one file)
@@ -267,9 +275,10 @@
         exit( 1 );
     }
     enk = elk = 0;
-    for( ;; ){
+    b_n = 0;
+    for( ;; ++b_n ){
+ /* in output we roll over every 2^16 blocks regardless the b_n type size */
         d = enb;
-        b_n = enk / BLON; /* the future block number */
         /* fill the output buffer */
         while( d - enb < BLON && (c=getchar()) != EOF ){
             ++enk;
@@ -311,10 +320,10 @@
     /*
      * tell the result
      */
-    if(wcat_flg == 0 && !quiet) {
-        fprintf( stderr, "Compression: %d%%",
-                enk > 0 ?
-                ( (100 * ( enk - elk )) / enk ) :
+    if(wcat_flg == 0 && !quiet) { long dif = (long)enk-(long)elk;
+        fprintf( stderr, "Compression: %d%%",
+                enk ?
+                (int)((dif>21474836)?(dif/((long)enk/100)):(100*dif/(long)enk)) :
                 0 );
     }
     if(elk > enk)    /* exit(2) if no compression */
@@ -439,12 +448,13 @@
                 continue;
             }
         }
-        oblk = it_blk + 1;
+        oblk = (it_blk + 1)&65535; /* ensure rolling over every 2^16 blocks */
         lon = it_lon;
         if( lon == BLON ){ /* not the last block */
-            if( (i=serch()) == EOF    /* end ??? */
-             || it_blk != oblk )  /* out of order */
-                    continue; /* do not trust this block */
+            if( ((i=serch()) == EOF    /* end ??? */
+                 || it_blk != oblk)    /* out of order */
+                 && !ignore )
+                    continue; /* do not trust the freshly uncompressed block */
         } else { /* looks like the last one */
             if( ignore && (i=serch()) != EOF ){
                 /* not last, look further! */
@@ -457,8 +467,8 @@
                     continue; /* ignoring the "last" block indication */
             }
         }
-        if( (j=oblk-b_blk-1) != 0 ){
-            /* the next block number in order, but here there was a skip */
+        if( (j=oblk-((b_blk+1)&65535)) != 0 ){
+            /* there was a skip */
             if( fseek( stdout, (long)oblk*(long)BLON, 0 ) < 0 )
                 /* can not seek (pipe) */
                 if( j > 0 && j <= 10 ) /* skipped blocks
--- PRES/flparc.c.ori	2015-04-27 22:04:06.568430732 +0200
+++ PRES/flparc.c	2015-04-27 22:14:26.303900666 +0200
@@ -2,6 +2,14 @@
  * FLPARC - recording/reading data on removable data, with compression
  * (c) RL 1990-2015
  *
+ * version 0.2015-04-27
+ *         removed undue data stream size limitations,
+ *         now it should work for up to 2GB,
+ *         bigger streams will be compressed alright but
+ *         the diagnostic messages would become wrong after 2GB
+ * version 0.2015-04-26
+ *         initial public release
+ *
  * $Header: flparc.c,v 1.2 91/01/24 14:11:35 pro Exp $
  * $Log:	flparc.c,v $
  * Revision 1.2  91/01/24  14:11:35  pro
@@ -36,7 +44,7 @@
 int bi = 0;       /* Index in the blocking buffer */
 unsigned int bimaks; /* Size of the blocking buffer */
 long skp = 0;     /* Pointer in the archive file */
-long num = 0;     /* Number of the bytes input for compression */
+unsigned long num = 0;     /* Number of the bytes input for compression */
 int  flp = -1;    /* Number of the filled media */
 int verb = 0;     /* Tell the current compression ratio */
 int ignore = 0;   /* Ignore read errors at decompression */
@@ -295,11 +303,14 @@
 	    " Skriberaro! Bloko %d\n"), skp/B_LON );
 	    exit_stat = 5;
     }
-    if( num > 0 && verb ) fprintf( stderr, ediag(
-	" Compressed: %d%%\n",
-	" Kunpremite: %d%%\n"),
-	(100*(num-((long)flp*dlon*B_LON+skp+bi)))/num );
-/* note this works up to ca 21MB of size reduction (overflow of 100*(long)) */
+    if( num > 0 && verb ){ long dif = (long)num-((long)flp*dlon*B_LON+skp+bi);
+        fprintf( stderr, ediag(
+	    " Compressed: %d%%\n",
+	    " Kunpremite: %d%%\n"),
+	    num ?
+            (int)((dif>21474836)?(dif/((long)num/100)):(100*dif/(long)num)) :
+            0 );
+    }
     skp = 0;
     bi = 0;
 }
@@ -310,12 +321,13 @@
     char c, d;
 
     ++flp;
-    if( premado && verb && flp > 0 ){
+    if( premado && verb && flp > 0 ){ long dif = (long)num-(long)flp*dlon*B_LON;
 	fprintf( stderr, ediag(
-	    " Currently compressed %d%%\n",
-	    " Nuntempa premado %d%%\n"),
- (100*(num-((long)flp*dlon*B_LON)))/num );
-/* note this works up to ca 21MB of size reduction (overflow of 100*(long)) */
+	    " Currently compressed %d%%\n",
+	    " Nuntempa premado %d%%\n"),
+	    num ?
+            (int)((dif>21474836)?(dif/((long)num/100)):(100*dif/(long)num)) :
+            0 );
     }
     fprintf( stderr, ediag(
 	"\
@@ -375,9 +387,10 @@
         exit_stat = 5;
         return;
     }
-    for( ;; ){
+    b_n = 0;
+    for( ;; ++b_n ){
+ /* in output we roll over every 2^16 blocks regardless the b_n type size */
         d = enb;
-        b_n = num / BLON; /* the future block number */
         /* fill the input buffer */
         while( d - enb < BLON && (c=getchar()) != EOF ){
             ++num;
@@ -541,12 +554,13 @@
                 continue;
             }
         }
-        oblk = it_blk + 1;
+        oblk = (it_blk + 1)&65535; /* ensure rolling over every 2^16 blocks */
         lon = it_lon;
         if( lon == BLON ){ /* not the last block */
-            if( (i=serch()) == EOF    /* error */
-             || it_blk != oblk )  /* out of order */
-                    continue; /* don't trust this block */
+            if( ((i=serch()) == EOF    /* error */
+                 || it_blk != oblk )   /* out of order */
+                 && !ignore )
+                    continue; /* do not trust the freshly uncompressed block */
         } else { /* looks like the last block */
             if( ignore ){
                 /* not the last, we may need to look further! */
@@ -566,8 +580,8 @@
                 }
             }
         }
-        if( (j=oblk-b_blk-1) != 0 ){
-            /* the next block number in order, but here there was a skip */
+        if( (j=oblk-((b_blk+1)&65535)) != 0 ){
+            /* there was a skip */
             if( fseek( stdout, (long)oblk*(long)BLON, 0 ) < 0 )
                 /* can not seek (pipe) */
                 if( j > 0 && j <= 10 ) /* skipped blocks

  parent reply	other threads:[~2015-04-27 21:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-26 12:29 a compression tool useful with constrained memory u-vpoa
2015-04-26 12:36 ` Jody Bruchon
2015-04-26 13:11   ` u-vpoa
2015-04-26 16:49     ` Status updates: compression tool, kernel fixes, BCC features, etc Jody Bruchon
2015-04-27 21:04   ` u-vpoa [this message]
2015-04-29 15:10     ` another fix for huge data (Re: a compression tool useful with constrained memory) u-vpoa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150427210409.GB8197@example.net \
    --to=u-vpoa@aetey.se \
    --cc=jody@jodybruchon.com \
    --cc=linux-8086@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox