/* libsizzle/sport.h - string port handling
 
  Copyright (C) 1999, 2000 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
 
  This 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, or (at your option)
  any later version.
  
  This software 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 package; see the file COPYING.  If not, write to the
  Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  MA 02111-1307, USA.  */

#ifndef __SIZZLE_SPORT_H__
#define __SIZZLE_SPORT_H__

#if HAVE_CONFIG_H
# include <config.h>
#endif 

#if __SIZZLE_IMPORT__
# define SIZZLE_API __declspec (dllimport)
#elif __SIZZLE_EXPORT__ 
# define SIZZLE_API __declspec (dllexport)
#else
# define SIZZLE_API
#endif

#include "node.h"

/* Type descriminator and accessor macros for string ports.  */
#define sport_p(c)    (port_p(c) && port_ptype(c) == zzz_sport_port_type)
#define sport_val(c)  (((sport_info_t) port_info(c))->buf)
#define sport_len(c)  (((sport_info_t) port_info(c))->len)
#define sport_size(c) (((sport_info_t) port_info(c))->size)
#define sport_pos(c)  (((sport_info_t) port_info(c))->fpos)

/* Info structure for string port data.  */
typedef struct sport_info * sport_info_t;
struct sport_info
{
  char * buf;
  int len;
  int size;
  int fpos;
};

/* The port type identifier for string ports.  */
SIZZLE_API extern zzz_object_t zzz_sport_port_type;

/* Create a string port with an initial capacity of @var{start_len}.  */
SIZZLE_API zzz_scm_t zzz_make_sport (int start_len);

/* Create a string port which will deliver the contents of the
   null-terminated string @var{str} when read.  */
SIZZLE_API zzz_scm_t zzz_make_sport_str (char * str);

/* Create a string port which will deliver the @var{len} characters
   starting at the location @var{str} when read.  */
SIZZLE_API zzz_scm_t zzz_make_sport_str_n (char * str, unsigned len);

/* Like zzz_make_sport_str_n(), but does not copy its argument string.
   You have to make sure that the underlying string does exist as long
   as the created string port object.  The resulting string port may
   not be written to, it is read-only.  */
SIZZLE_API zzz_scm_t zzz_make_sport_str_n_no_copy (char * str, unsigned len);

/* Initialize the string port module.  */
SIZZLE_API result_t zzz_init_sport (void);

#endif /* not __SIZZLE_SPORT_H__ */
