home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / mms / str_codes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-04  |  2.9 KB  |  119 lines

  1. /*////////////////////////////////////////////////////////////////////////
  2. Copyright (c) 1992 Electrotechnical Laboratry (ETL)
  3.  
  4. Permission to use, copy, modify, and distribute this material
  5. for any purpose and without fee is hereby granted, provided
  6. that the above copyright notice and this permission notice
  7. appear in all copies, and that the name of ETL not be
  8. used in advertising or publicity pertaining to this
  9. material without the specific, prior written permission
  10. of an authorized representative of ETL.
  11. ETL MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  12. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  13. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  14. /////////////////////////////////////////////////////////////////////////
  15. ontent-Type: program/C; charset=US-ASCII
  16. Program:      codess.h
  17. Author:       Yutaka Sato <ysato@etl.go.jp>
  18. Description:
  19.  
  20.      This program redirects the file I/O of codes.c
  21.      from/to strings on memory.
  22.  
  23. History:
  24.     92.05.18   created
  25. ///////////////////////////////////////////////////////////////////////*/
  26. #include <stdio.h>
  27.  
  28. /*
  29. main(ac,av)
  30.     char *av[];
  31. {    char in[0x10000],out[0x10000];
  32.     int size;
  33.  
  34.     size = fread(in,1,sizeof in,stdin);
  35.     in[size] = 0;
  36.     if( strcmp(av[1],"eb") == 0 )
  37.         str_to64(in,strlen(in),out,sizeof(out));
  38.     if( strcmp(av[1],"ub") == 0 )
  39.         str_from64(in,strlen(in),out,sizeof(out));
  40.     if( strcmp(av[1],"eq") == 0 )
  41.         str_toqp(in,strlen(in),out,sizeof(out));
  42.     if( strcmp(av[1],"uq") == 0 )
  43.         str_fromqp(in,strlen(in),out,sizeof(out));
  44.     fprintf(stderr,"%s",out);
  45. }
  46. */
  47.  
  48. int _to64(), _from64(), _toqp(), _fromqp();
  49. static
  50. str_callfunc(func,in,isize,out,osize,arg3,arg4)
  51.     int (*func)();
  52.     unsigned char *in,*out;
  53. {    int In,Out;
  54.     int rcode;
  55.     int len;
  56.  
  57.     In = str_fopen(in,isize);
  58.     Out = str_fopen(out,osize);
  59. out[0] = 0;
  60.     rcode = (*func)(In,Out,arg3,arg4);
  61.     len = str_ftell(Out);
  62.     out[len] = 0;
  63.     str_fflush(Out);
  64.     str_fclose(In);
  65.     str_fclose(Out);
  66.     return len;
  67. }
  68. str_to64(in,isize,out,osize)
  69.     unsigned char *in,*out;
  70. {    int len;
  71.     len = str_callfunc(_to64,in,isize,out,osize);
  72.     return len;
  73. }
  74. str_from64(in,isize,out,osize)
  75.     unsigned char *in,*out;
  76. {    int len;
  77.  
  78.     return str_callfunc(_from64,in,isize,out,osize,0,NULL);
  79. }
  80. str_toqp(in,isize,out,osize)
  81.     unsigned char *in,*out;
  82. {    int len;
  83.  
  84.     len = str_callfunc(_toqp,in,isize,out,osize);
  85.     if( 2 < len && out[len-2] == '=' && out[len-1] == '\n' ){
  86.         out[len-2] = 0;
  87.         len -= 2;
  88.     }
  89.     return len;
  90. }
  91. str_fromqp(in,isize,out,osize)
  92.     unsigned char *in,*out;
  93. {
  94.     return str_callfunc(_fromqp,in,isize,out,osize,0,NULL);
  95. }
  96.  
  97. #include "str_stdio.h"
  98.  
  99. #define basis_64    _basis_64
  100. #define to64        _to64
  101. #define output64chunk    _output64chunk
  102. #define PendingBoundary    _PendingBoundary
  103. #define from64        _from64
  104. #define toqp        _toqp
  105. #define fromqp        _fromqp
  106. #define    basis_hex    _basis_hex
  107. #define    toqp        _toqp
  108. #define    fromqp        _fromqp
  109. #define    almostputc    _almostputc
  110. #define    nextcharin    _nextcharin
  111.  
  112. /*
  113. #define char64        _char64
  114. #define    hexchar        _hexchar
  115. */
  116.  
  117. #include "codes.c"
  118.  
  119.