1 /* GNU Talkfilters 2 Copyright (C) 1998-2003 Free Software Foundation, Inc. 3 4 This file is part of GNU Talkfilters 5 6 GNU Talkfilters is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2, or (at 9 your option) any later version. 10 11 This software is distributed in the hope that it will be amusing, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this software; see the file COPYING. If not, write to the 18 Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef __gtf_common_h 22 #define __gtf_common_h 23 24 #include <stdlib.h> 25 #include <stdio.h> 26 #include <ctype.h> 27 28 #if (defined WIN32) && !(defined __MINGW32__) 29 #define fileno _fileno 30 #define strcasecmp stricmp 31 #endif 32 33 #include "config.h" 34 35 typedef struct 36 { 37 char *buf; 38 size_t bufsz; 39 char *pos; 40 size_t left; 41 char overflow; 42 } gtf_databuf_t; 43 44 /* We NEVER want to read from stdin when called thru the library API, but flex 45 * insists on doing so anyway, so redefine YY_INPUT to always return EOF 46 * immediately. 47 */ 48 49 #ifdef LIBRARY_MODE 50 #define YY_INPUT(buffer,result,max_size) YY_NULL 51 #endif 52 53 54 #define HELP_OPTION 0 55 #define VERSION_OPTION 1 56 57 extern void gtf_parse_args_basic(int argc, char **argv, const char *help, 58 const char *version); 59 60 #define gtf_parse_args() \ 61 gtf_parse_args_basic(argc, argv, GTF_HELP, GTF_VERSION) 62 63 extern void gtf_strbuf_init(gtf_databuf_t *sbuf, char *buf, size_t bufsz); 64 65 extern int gtf_strbuf_vprintf(gtf_databuf_t *buf, const char *fmt, ...); 66 67 extern int gtf_strbuf_puts(gtf_databuf_t *buf, const char *s); 68 69 extern int gtf_strbuf_putc(gtf_databuf_t *buf, char c); 70 71 #ifdef LIBRARY_MODE 72 #define gtf_printf(...) \ 73 gtf_strbuf_vprintf(buf, __VA_ARGS__) 74 #define gtf_putc(S) \ 75 gtf_strbuf_putc(buf, (S)) 76 #define gtf_puts(S) \ 77 gtf_strbuf_puts(buf, (S)) 78 #else /* LIBRARY_MODE */ 79 #define gtf_printf printf 80 #define gtf_putc putchar 81 #define gtf_puts(S) \ 82 fputs((S), stdout) 83 #endif /* LIBRARY_MODE */ 84 85 #define gtf_unput_last() \ 86 unput(*(yytext + yyleng - 1)) 87 88 #define gtf_match_case(X, Y) \ 89 isupper(X) ? toupper(Y) : tolower(Y) 90 91 #define gtf_puts_case(T) \ 92 gtf_printf("%c%s", gtf_match_case(*yytext, *(T)), (T) + 1) 93 94 #define gtf_echo() \ 95 gtf_puts(yytext) 96 97 #define gtf_reset() \ 98 { yyrestart(NULL); BEGIN(0); } 99 100 extern void gtf_random_seed(void); 101 102 #define gtf_random(R) \ 103 (int)(rand() % (R)) 104 105 #define GTF_HELP \ 106 "Usage: %s [OPTIONS]\n\n\ 107 Options:\n\ 108 --help display this help information and exit\n\ 109 --version output version information and exit\n\n\ 110 This program is a filter; it reads data from standard input, processes it,\n\ 111 and writes the results to standard output.\n" 112 113 #define GTF_VERSION "GNU Talk Filters v" VERSION 114 115 #endif /* __gtf_common_h */ 116