#!/bin/sh
# IRCfs - IRC FileServ for *nix.
# Copyright (C) 2002  Nick 'Zaf' Clifford <zaf@nrc.co.nz>
# For licensing details, refer to the LICENSE file in the source 
# code directory.

cat > servfunc.h << __EOF__
/* This file is automatically generated by servfunc.h.sh */
/* IRCfs - IRC FileServ for *nix.
 * Copyright (C) 2002  Nick 'Zaf' Clifford <zaf@nrc.co.nz>
 * For licensing details, refer to the LICENSE file in the source 
 * code directory.
 */
#ifndef __include_servfunc_h__
#define __include_servfunc_h__

__EOF__

sed -n 's/^[^#].*COMMAND(.*)[ \t]*\([a-zA-Z0-9_]*\).*$/int \1 (struct server *s, const char *command, int argc, char *argv[], void *appdata);/p' \
	< servfunc.c >> servfunc.h
sed -n 's/^[^#].*CODE(.*)[ \t]*\([a-zA-Z0-9_]*\).*$/int \1 (struct server *s, int code, int argc, char *argv[], void *appdata);/p' \
	< servfunc.c >> servfunc.h


cat >> servfunc.h << __EOF__
#endif
__EOF__

cat > servreg.c << __EOF__
/* This file is automatically generated by servfunc.h.sh */
/* IRCfs - IRC FileServ for *nix.
 * Copyright (C) 2002  Nick 'Zaf' Clifford <zaf@nrc.co.nz>
 * For licensing details, refer to the LICENSE file in the source 
 * code directory.
 */
#include "server.h"
#include "servfunc.h"

int server_reg_internal(struct server *s)
{
__EOF__
sed -n 's/^[^#].*COMMAND(\(.*\))[ \t]*\([a-zA-Z0-9_]*\).*$/server_set_command_handler(s,\1,0,NULL,\2,NULL);/p' \
	< servfunc.c >> servreg.c
sed -n 's/^[^#].*CODE(\(.*\))[ \t]*\([a-zA-Z0-9_]*\).*$/server_set_code_handler(s,\1,0,NULL,\2,NULL);/p' \
	< servfunc.c >> servreg.c

cat >> servreg.c << __EOF__
	return 0;
}
__EOF__
