/*
** pat_pad.c for  in 
** 
** Made by 
** Login   <vianney@epita.fr>
** 
** Started on  Wed Sep  1 06:42:21 1999 
** Last update Thu Oct 28 20:19:49 1999 
*/
#include <sys/types.h>
#include <sys/socket.h>
#include "pat_pad.h"
#include "pat_ether.h"
#include "pat_32.h"
#include "pat_pat.h"

t_u32				pat_pad_nbytes = 1;
t_pat				*pat_pad_sub_pat = &ether_pat;

char				*pad_itmpl = "\n\
<table _name=pad[%i%] width=100%%%% bgcolor=\"%%padColor%%\">\n\
<tr>\n\
<td align=center width=100%%%%>\n\
 pad of %pat_pad_nbytes% byte(s) to %pat_pad_sub_pat%\n\
</td>\n\
</table>\n\
<br>\n\
";

t_status			pad_format_do(bs,var,i)
t_bridled_str			*bs;
char				*var;
int				i;
{
  int				varlen;
  long				signedvalue;
  t_status			status;

  varlen = strlen(var);
  if (varlen == 0)
    return (str_cat_char(bs->str,bs->max_len,'%'));
  else
    {
      if (!strcmp(var,"i"))
	{
	  return (long_to_str((signed long)i,
			      10,
			      bs->str,
			      bs->max_len));
	}
      if (!strcmp(var,"pat_pad_nbytes"))
	{
	  return (ulong_to_str((unsigned long)pat_pad_nbytes,
			       pat_base,
			       bs->str,
			       bs->max_len));
	}
      if (!strcmp(var,"pat_pad_sub_pat"))
	{
	  return (pat_to_str(pat_pad_sub_pat,
			     bs->str,
			     bs->max_len));
	}
    }
  return (0);
}

t_status			pad_format(i,tmpl_str,str,max_len)
int				i;
char				*tmpl_str;
char				*str;
int				max_len;
{
  return (tmpl_str_to_str(tmpl_str,
			  (t_tmpl_do_proc)pad_format_do,
			  (VOID_PTR)i,
			  str,
			  max_len));
}

int	pad_chan;

PAT_NAME_GENERIC(pad_pat_name,
		 (VOID_PTR)&pad_chan,
		 "pad")

PAT_GET_TMPL_DECL(pad_pat_get_tmpl)
{
  t_hash_elt	*he;
  int		i;
  t_status	status;
	
  if (he = id_get(id,
		  (VOID_PTR)&pad_chan))
    i = (int)(he->value);
  else
    i = 0;
  if ((status = pad_format(i,
			   pad_itmpl,
			   str,
			   max_len)) != 0)
    return (status);
  if ((status = id_override(id,
			    (VOID_PTR)&pad_chan,
			    (VOID_PTR)(++i))) != 0)
    return (status);
  return (0);
}

PAT_OFF_DECL(pad_pat_off)
{
  (*off_return) = pat_pad_nbytes;
  return (0);
}

PAT_SUB_DECL(pad_pat_sub)
{	
  (*pat_return) = pat_pad_sub_pat;
  return (0);
}

t_pat				pad_pat = 
{
  pad_pat_name,			/* t_pat_name_proc		*/
  pad_pat_off,			/* t_pat_off_proc		*/
  pad_pat_sub,			/* t_pat_sub_proc		*/
  NULL,				/* t_pat_sum_proc		*/
  NULL,				/* t_pat_get_field_proc		*/
  NULL,				/* t_pat_set_field_proc		*/
  NULL,				/* t_pat_get_fields_proc	*/
  pad_pat_get_tmpl,		/* t_pat_get_tmpl_proc		*/
  NULL,				/* t_pat_get_tmpl2_proc		*/
  NULL,				/* t_pat_has_opt_proc		*/
  NULL,				/* t_pat_adapt_len_proc		*/
  NULL,				/* t_pat_get_field_pat_proc	*/
  NULL,				/* t_pat_extract_proc		*/
  NULL,				/* t_pat_insert_proc		*/
  NULL,				/* t_pat_get_choices_proc	*/
};
