comparison lib-src/mmencode.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 11054d720c21
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
16 #define NEWLINE_CHAR '\n' 16 #define NEWLINE_CHAR '\n'
17 #include <stdlib.h> 17 #include <stdlib.h>
18 #include <stdio.h> 18 #include <stdio.h>
19 #include <ctype.h> 19 #include <ctype.h>
20 #include <string.h> 20 #include <string.h>
21 #include <errno.h>
22 21
23 static void 22 static void
24 output64chunk(int c1, int c2, int c3, int pads, FILE *outfile); 23 output64chunk(int c1, int c2, int c3, int pads, FILE *outfile);
25 24
26 static signed char basis_64[] = 25 static signed char basis_64[] =
51 50
52 /* the following gets a character, but fakes it properly into two chars if there's a newline character */ 51 /* the following gets a character, but fakes it properly into two chars if there's a newline character */
53 static int InNewline=0; 52 static int InNewline=0;
54 53
55 static int 54 static int
56 nextcharin (FILE *infile, int PortableNewlines) 55 nextcharin(infile, PortableNewlines)
56 FILE *infile;
57 int PortableNewlines;
57 { 58 {
58 int c; 59 int c;
59 60
60 #ifndef NEWLINE_CHAR 61 #ifndef NEWLINE_CHAR
61 return(getc(infile)); 62 return(getc(infile));
383 if (!*++s) break; 384 if (!*++s) break;
384 c2 = hexchar(*s); 385 c2 = hexchar(*s);
385 putc(c1<<4 | c2, outfile); 386 putc(c1<<4 | c2, outfile);
386 } 387 }
387 } else { 388 } else {
388 #ifdef WIN32_NATIVE 389 #ifdef MSDOS
389 if (*s == '\n') 390 if (*s == '\n')
390 putc('\r', outfile); /* insert CR for binary-mode write */ 391 putc('\r', outfile); /* insert CR for binary-mode write */
391 #endif 392 #endif
392 putc(*s, outfile); 393 putc(*s, outfile);
393 } 394 }
440 of an authorized representative of Bellcore. BELLCORE 441 of an authorized representative of Bellcore. BELLCORE
441 MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 442 MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
442 OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS", 443 OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
443 WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. 444 WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
444 */ 445 */
445 #ifdef WIN32_NATIVE 446 #ifdef MSDOS
446 #include <io.h>
447 #include <fcntl.h> 447 #include <fcntl.h>
448 #endif 448 #endif
449 449
450 #define BASE64 1 450 #define BASE64 1
451 #define QP 2 /* quoted-printable */ 451 #define QP 2 /* quoted-printable */
486 fprintf(stderr, 486 fprintf(stderr,
487 "Usage: mmencode [-u] [-q] [-b] [-p] [-o outputfile] [file name]\n"); 487 "Usage: mmencode [-u] [-q] [-b] [-p] [-o outputfile] [file name]\n");
488 exit(-1); 488 exit(-1);
489 } 489 }
490 } else { 490 } else {
491 #ifdef WIN32_NATIVE 491 #ifdef MSDOS
492 if (encode) 492 if (encode)
493 fp = fopen(argv[i], "rb"); 493 fp = fopen(argv[i], "rb");
494 else 494 else
495 { 495 {
496 fp = fopen(argv[i], "rt"); 496 fp = fopen(argv[i], "rt");
497 setmode(fileno(fpo), O_BINARY); 497 setmode(fileno(fpo), O_BINARY);
498 } /* else */ 498 } /* else */
499 #else 499 #else
500 fp = fopen(argv[i], "r"); 500 fp = fopen(argv[i], "r");
501 #endif /* WIN32_NATIVE */ 501 #endif /* MSDOS */
502 if (!fp) { 502 if (!fp) {
503 perror(argv[i]); 503 perror(argv[i]);
504 exit(-1); 504 exit(-1);
505 } 505 }
506 } 506 }
507 } 507 }
508 #ifdef WIN32_NATIVE 508 #ifdef MSDOS
509 if (fp == stdin) setmode(fileno(fp), O_BINARY); 509 if (fp == stdin) setmode(fileno(fp), O_BINARY);
510 #endif /* WIN32_NATIVE */ 510 #endif /* MSDOS */
511 if (which == BASE64) { 511 if (which == BASE64) {
512 if (encode) { 512 if (encode) {
513 to64(fp, fpo, portablenewlines); 513 to64(fp, fpo, portablenewlines);
514 } else { 514 } else {
515 from64(fp,fpo, (char **) NULL, (int *) 0, portablenewlines); 515 from64(fp,fpo, (char **) NULL, (int *) 0, portablenewlines);