Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

string.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001 James Hess
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the authors nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00044 #define __string_cc__
00045 #include "services.h"
00046 #include "./string.h"
00047 
00048 
00055 const char* get_reply(reply_type reply)
00056 {
00057     static char buf[256];
00058 
00059     if (reply < 0 || reply >= MAX_REPLY_STRING_NUM) {
00060         sprintf(buf, "NO REPLY FOR ERROR %d -- please report this.", reply);
00061         return buf;
00062     }
00063 
00064     return reply_table[reply].string;
00065 }
00066 
00075 void reply(const char *cService, UserList *nTo, int replyNum, ...)
00076 {
00077     static char buf[(IRCBUF*2)+10];
00078         va_list ap;
00079     int sz;
00080 
00081     if (replyNum < 0 || replyNum >= MAX_REPLY_STRING_NUM) {
00082         sprintf(buf, "NO REPLY FOR ERROR %d -- please report this.\r\n", replyNum);
00083 
00084         net_write(server, buf, strlen(buf));
00085         return;
00086     }
00087 
00088     sz = sprintf(buf, ":%s NOTICE %s :", cService, nTo->nick);
00089 
00090     va_start(ap, replyNum);
00091     sz += vsnprintf(buf + sz, sizeof(buf), reply_table[replyNum].string, ap);
00092     va_end(ap);
00093 
00094     buf[sz] = '\r';
00095     buf[sz+1] = '\n';
00096     buf[sz+2] = '\0';
00097     sz += 2;
00098 
00099     net_write(server, buf, sz);
00100 }

Generated at Sat Oct 25 20:56:09 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.