Libav 0.7.1
|
00001 /* 00002 * This file is part of Libav. 00003 * 00004 * Libav is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * Libav is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with Libav; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 /* 00020 * Based on libavutil/base64.c 00021 */ 00022 00023 #include <stdio.h> 00024 00025 int main(void) 00026 { 00027 static const char b64[] = 00028 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 00029 unsigned i_bits = 0; 00030 int i_shift = 0; 00031 int out_len = 0; 00032 int in; 00033 00034 #define putb64() do { \ 00035 putchar(b64[(i_bits << 6 >> i_shift) & 0x3f]); \ 00036 out_len++; \ 00037 i_shift -= 6; \ 00038 } while (0) 00039 00040 while ((in = getchar()) != EOF) { 00041 i_bits = (i_bits << 8) + in; 00042 i_shift += 8; 00043 while (i_shift > 6) 00044 putb64(); 00045 } 00046 while (i_shift > 0) 00047 putb64(); 00048 while (out_len++ & 3) 00049 putchar('='); 00050 putchar('\n'); 00051 00052 return 0; 00053 }