/* * Copyright (C) 2000 Dizzy * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "common/setup_before.h" #include #ifdef HAVE_STDDEF_H # include #else # ifndef NULL # define NULL ((void *)0) # endif #endif #ifdef STDC_HEADERS # include #else # ifdef HAVE_MALLOC_H # include # endif #endif #ifdef HAVE_STRING_H # include #else # ifdef HAVE_STRINGS_H # include # endif #endif #include "compat/strcasecmp.h" #include #include #include "compat/strerror.h" #include "message.h" #include "connection.h" #include "common/util.h" #include "common/eventlog.h" #include "common/xalloc.h" #include "helpfile.h" #include "common/setup_after.h" #include "account_wrap.h" #include "command_groups.h" static FILE* hfd=NULL; /* helpfile descriptor */ static int list_commands(t_connection *); static int describe_command(t_connection *, char const *); extern int helpfile_init(char const *filename) { if (!filename) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL filename"); return -1; } if (!(hfd = fopen(filename,"r"))) { eventlog(eventlog_level_error,__FUNCTION__,"could not open help file \"%s\" for reading (fopen: %s)",filename,pstrerror(errno)); return -1; } return 0; } extern int helpfile_unload(void) { if (hfd!=NULL) { if (fclose(hfd)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not close help file after reading (fclose: %s)",pstrerror(errno)); hfd = NULL; } return 0; } extern int handle_help_command(t_connection * c, char const * text) { unsigned int i,j; char comm[MAX_COMMAND_LEN]; if (hfd == NULL) { /* an error ocured opening readonly the help file, helpfile_unload was called, or helpfile_init hasn't been called */ message_send_text(c,message_type_error,c,"Oops ! There is a problem with the help file. Please contact the administrator of the server."); return 0; } rewind(hfd); for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */ for (; text[i]==' '; i++); if (text[i]=='/') /* skip / in front of command (if present) */ i++; for (j=0; text[i]!=' ' && text[i]!='\0'; i++) /* get comm */ if (j