⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uue.cpp

📁 非常好用的五子棋游戏源码
💻 CPP
字号:
// Created:10-23-98
// By Jeff Connelly

// UUEncoding and UUDecoding (UU -> Unix to Unix)

// Converts a binary file to a plain text file that can be transfered over
// a network or sent though e-mail.

// Note: There are some problems with UUE, mainly that the translation to
//       EBCDIC from ASCII.  The characters in different character
//       sets are different, use XXE instead.

// Based on the source code ORIGSRC\UUENCODE.C that says:
/*
 * Copyright (c) 1983 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the University of California, Berkeley.  The name of the
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/*
 * Modified 12 April 1990 by Mark Adler for use on MSDOS systems with
 * Microsoft C and Turbo C.  Standard input problem fixed 29 April 1990
 * as per suggestion by Steve Harrold.
 *
 * Modifed 13 February 1991 by Greg Roelofs for use on VMS systems.
 * Compile and link normally (but note that the shared-image link option
 * produces a binary only 6 blocks long, as opposed to the 152-block one
 * produced by an ordinary link).  To set up the VMS symbol to run the
 * program ("run uuencode filename1 filename2 filename3" won't work), do:
 *              uuencode :== "$disk:[directory]uuencode.exe"
 * and don't forget the leading "$" or it still won't work.  The syntax
 * differs slightly from the Unix and MS-DOS versions since VMS has such
 * an awkward approach to redirection; run the program with no arguments
 * for the usage (or see USAGE below).  The output file is in VMS "stream-
 * LF" format but should be readable by MAIL, ftp, or anything else.
 */

#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"
 

// For compatability with Turbo C
#ifdef __MSDOS__
#define MSDOS  1
#endif

#ifdef VMS
#   include <types.h>
#   include <stat.h>
#else
#   ifndef MSDOS
//#       include <pwd.h>
#   endif
#   include <sys/types.h>
#   include <sys/stat.h>
#endif

#if MSDOS
#   include <io.h>
#   include <fcntl.h>
#endif

// UUEncode a character
#define ENC(c) ((c) ? ((c) & 077) + ' ' : '`')

// Output a group of 3 bytes, pointed to by 'p'
static void outenc(register char* p)
{
    register int c1, c2, c3, c4;

    c1 = *p >> 2;
    c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
    c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
    c4 = p[2] & 077;
    write_byte(ENC(c1));
    write_byte(ENC(c2));
    write_byte(ENC(c3));
    write_byte(ENC(c4));
}

// Encode a binary file to a plain text UUEncoded file
void EXPORT uu_encode()
{
    char buf[80];
    register int i, n;

    while (true)
    {
        // Read a 1 to 45 character line
        for (n = 0; n < 45; ++n)
        {
            if (end_of_data())
                break;
            buf[n] = read_byte();   
        }
        write_byte(ENC(n));

        for (i = 0; i < n; i += 3)
            outenc (&buf[i]);

        write_byte('\n');
        if (n <= 0)
            break;
    }
}

// Single-char decode
#define DEC(c) (((c) - ' ') & 077)    // 077 (octal) = 0x3F (hex)

// Output a group of 3 bytes (4 input characters).  The input characters
// are pointed to by 'p', 'n' indicates to tell us not to output all of them
// at the end of the stream.
static void outdec(char* p, int n)
{
    int c1, c2, c3;

    c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
    c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
    c3 = DEC(p[2]) << 6 | DEC(p[3]);
    if (n >= 1)
        write_byte(c1);
    if (n >= 2)
        write_byte(c2);
    if (n >= 3)
        write_byte(c3);
}

// Decode a UUEncoded file
void EXPORT uu_decode()
{
    char buf[80];
    char* bp;
    int n, i, expected;

    while (true)
    {
        // Read a 1 to 45 character line
        for (i = 0; i < sizeof(buf) && !end_of_data(); ++i)
        {
            buf[i] = read_byte();
            if (buf[i] == '\n')
            {
                buf[i] = 0;
                break;
            }
        }
        n = DEC(buf[0]);
        if ((n <= 0) || (buf[0] == '\n'))
            break;

        // Calculate expected number of characters and pad if needed
        expected = ((n + 2) / 3) << 2;
        for (i = strlen(buf) - 1; i <= expected; ++i)
            buf[i] = ' ';

        bp = &buf[1];
        while (n > 0)
        {
            outdec(bp, n);
            bp += 4;
            n -= 3;
        }
    }
}







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -