1 /************************************************************************************************** 2 $Header: /pub/cvsroot/yencode/src/y.h,v 1.19 2002/03/15 14:48:52 bboy Exp $ 3 4 Copyright (C) 2002 Don Moore <bboy@bboy.net> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at Your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 **************************************************************************************************/ 20 21 #ifndef _Y_H 22 #define _Y_H 23 24 #include <stdio.h> 25 #include <config.h> 26 #include <misc.h> 27 #include <dirent.h> 28 29 #if HAVE_INTTYPES_H 30 # include <inttypes.h> 31 #endif 32 #if HAVE_UNISTD_H 33 # include <unistd.h> 34 #endif 35 #if HAVE_STDARG_H 36 # include <stdarg.h> 37 #endif 38 #ifdef HAVE_GETOPT_H 39 # include <getopt.h> 40 #else 41 # include "getopt.h" 42 #endif 43 #if HAVE_TIME_H 44 # include <time.h> 45 #endif 46 #if HAVE_SYS_TIME_H 47 # include <sys/time.h> 48 #endif 49 50 #include "crc.h" 51 #include "output.h" 52 #include "support.h" 53 #include "file.h" 54 55 56 /* Default file extension */ 57 #ifndef Y_EXT 58 # define Y_EXT "ync" 59 #endif 60 61 /* Default line length */ 62 #ifndef Y_LL 63 # define Y_LL 128 64 #endif 65 66 /* Default system type */ 67 #ifndef SYSTYPE 68 # define SYSTYPE NULL 69 #endif 70 71 /* Do the +42 `encoding' against char `c' */ 72 #define YENCODE(c) ((c + 42) & 255) 73 74 /* Do the -42 `decoding' against char `c' */ 75 #define YDECODE(c) ((c - 42) & 255) 76 77 78 /* Nonzero if we MUST encode char `c' at any position */ 79 #define YMUST_ESCAPE(c) (c == '\0' || c == '\r' || c == '\n' || c == '=') 80 81 /* Nonzero if we MUST encode if this is the first character of a line */ 82 #define YESCAPE_IF_FIRST(c) (c == '\t' || c == '.' || c == ' ') 83 84 /* Nonzero if we MUST encode if this is the last character of a line */ 85 #define YESCAPE_IF_LAST(c) (c == '\t' || c == ' ') 86 87 /* Nonzero if it makes sense to encode this character at least SOMETIMES */ 88 #define YESCAPE_MAKES_SENSE(c) (c == '\0' || c == '\r' || c == '\n' || c == '=' || c == '\t' || c == ' ' || c == '.') 89 90 /* Determines if a character needs to be escaped taking into account the offset within the current line 91 and the maximum line length */ 92 #define YSHOULD_ESCAPE(c,o,l) (YMUST_ESCAPE(c) || (o == 0 && YESCAPE_IF_FIRST(c)) || (o+1 >= l && YESCAPE_IF_LAST(c))) 93 94 95 /* Nonzero if buffer `b' starts with "=y" */ 96 #define YKEYWORD(b) (b[0] == '=' && b[1] == 'y') 97 98 /* Nonzero if buffer `b' starts with "=ybegin" */ 99 #define YKEYWORD_BEGIN(b) (YKEYWORD(b) && b[2] == 'b' && b[3] == 'e' && b[4] == 'g' && b[5] == 'i' && b[6] == 'n') 100 101 /* Nonzero if buffer `b' starts with "=ypart" */ 102 #define YKEYWORD_PART(b) (YKEYWORD(b) && b[2] == 'p' && b[3] == 'a' && b[4] == 'r' && b[5] == 't') 103 104 /* Nonzero if buffer `b' starts with "=yend" */ 105 #define YKEYWORD_END(b) (YKEYWORD(b) && b[2] == 'e' && b[3] == 'n' && b[4] == 'd') 106 107 108 /* Evaluates as the proper escape character for `c' */ 109 #define YESCAPE(c) ((c + 64) & 255) 110 #define YUNESCAPE(c) ((c - 64) & 255) 111 112 113 #endif /* !_Y_H */ 114 115 /* vi:set ts=3: */ 116