Back to index

php5  5.3.10
Defines | Enumerations | Functions | Variables
mbfilter_uuencode.c File Reference
#include "mbfilter.h"
#include "mbfilter_uuencode.h"

Go to the source code of this file.

Defines

#define CK(statement)   do { if ((statement) < 0) return (-1); } while (0)
#define UUDEC(c)   (char)(((c)-' ')&077)

Enumerations

enum  {
  uudec_state_ground = 0, uudec_state_inbegin, uudec_state_until_newline, uudec_state_size,
  uudec_state_a, uudec_state_b, uudec_state_c, uudec_state_d,
  uudec_state_skip_newline
}

Functions

int mbfl_filt_conv_uudec (int c, mbfl_convert_filter *filter)

Variables

const mbfl_encoding mbfl_encoding_uuencode
static const char * uuenc_begin_text = "begin "

Define Documentation

#define CK (   statement)    do { if ((statement) < 0) return (-1); } while (0)

Definition at line 55 of file mbfilter_uuencode.c.

#define UUDEC (   c)    (char)(((c)-' ')&077)

Definition at line 58 of file mbfilter_uuencode.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
uudec_state_ground 
uudec_state_inbegin 
uudec_state_until_newline 
uudec_state_size 
uudec_state_a 
uudec_state_b 
uudec_state_c 
uudec_state_d 
uudec_state_skip_newline 

Definition at line 60 of file mbfilter_uuencode.c.


Function Documentation

int mbfl_filt_conv_uudec ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 65 of file mbfilter_uuencode.c.

{
       int n;
       
       switch(filter->status)      {
              case uudec_state_ground:
                     /* looking for "begin 0666 filename\n" line */
                     if (filter->cache == 0 && c == 'b')
                     {
                            filter->status = uudec_state_inbegin;
                            filter->cache = 1; /* move to 'e' */
                     }
                     else if (c == '\n')
                            filter->cache = 0;
                     else
                            filter->cache++;
                     break;
              case uudec_state_inbegin:
                     if (uuenc_begin_text[filter->cache++] != c)      {
                            /* doesn't match pattern */
                            filter->status = uudec_state_ground;
                            break;
                     }
                     if (filter->cache == 5)
                     {
                            /* thats good enough - wait for a newline */
                            filter->status = uudec_state_until_newline;
                            filter->cache = 0;
                     }
                     break;
              case uudec_state_until_newline:
                     if (c == '\n')
                            filter->status = uudec_state_size;
                     break;
              case uudec_state_size:
                     /* get "size" byte */
                     n = UUDEC(c);
                     filter->cache = n << 24;
                     filter->status = uudec_state_a;
                     break;
              case uudec_state_a:
                     /* get "a" byte */
                     n = UUDEC(c);
                     filter->cache |= (n << 16);
                     filter->status = uudec_state_b;
                     break;
              case uudec_state_b:
                     /* get "b" byte */
                     n = UUDEC(c);
                     filter->cache |= (n << 8);
                     filter->status = uudec_state_c;
                     break;
              case uudec_state_c:
                     /* get "c" byte */
                     n = UUDEC(c);
                     filter->cache |= n;
                     filter->status = uudec_state_d;
                     break;
              case uudec_state_d:
                     /* get "d" byte */
                     {
                            int A, B, C, D = UUDEC(c);
                            A = (filter->cache >> 16) & 0xff;
                            B = (filter->cache >> 8) & 0xff;
                            C = (filter->cache) & 0xff;
                            n = (filter->cache >> 24) & 0xff;
                            if (n-- > 0)
                                   CK((*filter->output_function)( (A << 2) | (B >> 4), filter->data));
                            if (n-- > 0)
                                   CK((*filter->output_function)( (B << 4) | (C >> 2), filter->data));
                            if (n-- > 0)
                                   CK((*filter->output_function)( (C << 6) | D, filter->data));
                            filter->cache = n << 24;

                            if (n == 0)
                                   filter->status = uudec_state_skip_newline;       /* skip next byte (newline) */
                            else
                                   filter->status = uudec_state_a; /* go back to fetch "A" byte */
                     }
                     break;
              case uudec_state_skip_newline:
                     /* skip newline */
                     filter->status = uudec_state_size;
       }
       return c;
}

Variable Documentation

Initial value:
 {
       mbfl_no_encoding_uuencode,
       "UUENCODE",
       "x-uuencode",
       NULL,
       NULL,
       MBFL_ENCTYPE_SBCS
}

Definition at line 37 of file mbfilter_uuencode.c.

const char* uuenc_begin_text = "begin " [static]

Definition at line 59 of file mbfilter_uuencode.c.