Bladeren bron

UU-encoding fix

Fixed UU-encoding
Mateusz Bugdalski 13 jaren geleden
bovenliggende
commit
5f5e1228a7
2 gewijzigde bestanden met toevoegingen van 25 en 18 verwijderingen
  1. 15 12
      lpc.c
  2. 10 6
      uucode.c

+ 15 - 12
lpc.c

@@ -122,20 +122,23 @@ void lpc_write_ram(struct lpc_device *dev, const struct sprog_data *d, unsigned
   checksum = 0;
   
   for(i=0; uuencode_line(d, buf, &offset, &checksum); i++) {
-    if((i % 20)==19)
+    lpc_printf("%s\r\n", buf);
+    if((i % 20)==19) {
       lpc_printf("%u\r\n", checksum);
+      
+      if(lpc_getline(reply_buf)) {
+	if(strcmp(reply_buf, "OK\r\n")==0) {
+	  last_offset = offset;
+	  last_i = i;
+	} else {
+	  offset = last_offset;
+	  i = last_i;
+	}
+      } else
+	break;
+    }
+    
     sprog_progress((offset*100)/d->size);
-  
-    if(lpc_getline(reply_buf)) {
-      if(strcmp(reply_buf, "OK\r\n")==0) {
-	last_offset = offset;
-	last_i = i;
-      } else {
-	offset = last_offset;
-	i = last_i;
-      }
-    } else
-      break;
   }
   
   if(offset!=d->size)

+ 10 - 6
uucode.c

@@ -8,6 +8,7 @@ int uuencode_line(const struct sprog_data *d, char *dst, int *offset, int *check
   unsigned char sum;
   char *dstd;
   int b;
+  int n;
   int i;
   
   b = d->size - *offset;
@@ -20,24 +21,25 @@ int uuencode_line(const struct sprog_data *d, char *dst, int *offset, int *check
     *checksum += srcbuf[i];
   }
   
-  for(i=0; i<(b & (4-1)); i++)
+  for(i=0; (b+i)%3; i++)
     srcbuf[b+i] = 0;
   
-  dst[0] = ' ' + b;
+  dst[0] = b;
+  
   dstd = &dst[1];
   
+  n = 0;
   for(i=0; i<b; i+=3) {
     dstd[0] = srcbuf[i]>>2;
     dstd[1] = srcbuf[i]<<4 | srcbuf[i+1]>>4;
     dstd[2] = srcbuf[i+1]<<2 | srcbuf[i+2]>>6;
-    dstd[3] = srcbuf[i];
+    dstd[3] = srcbuf[i+2];
     dstd += 4;
+    n += 4;
   }
   
-  dstd[0] = sum;
-  dstd[1] = 0;
   
-  for(i=0; i<b+2; i++) {
+  for(i=0; i<n+1; i++) {
     dst[i] &= 0x3f;
     if(dst[i])
       dst[i] += ' ';
@@ -45,6 +47,8 @@ int uuencode_line(const struct sprog_data *d, char *dst, int *offset, int *check
       dst[i] = '`';
   }
   
+  dstd[0] = 0;
+  
   if(*offset >= d->size)
     return 0;