/* CSV.H - CSV library header

   environ - C programming support functions
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   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 Lesser 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.
  
   Contact Martin Gregorie at martin@gregorie.org

*/

enum quote_modes
{
   NORMAL  = 1,
   ALWAYS  = 2,
   NEVER   = 3,
   MINIMAL = 4
};

enum line_delimiters
{
   CRLF    = 1,
   CR      = 2,
   LF      = 3
};

typedef struct 
{
   FILE *f;
   char *name;
   char *line;
   char *sline;
   char *oline;
   char **field;
   int  sused;
   int  maxline;
   int  maxfield;
   int  maxoline;
   int  outptr;
   int  nfield;
   int  quotemode;
   char sepchar[2];
   char nl[3];
} CSV;

CSV *csvopen(char *name, char *mode);
CSV *csvclose(CSV *f);
int csvgeterr(void);
char *csvgeterrtext(void);
int csvsetsep(CSV *f, int sepchar);
int csvsetquote(CSV *f, int quotemode);
int csvsetnl(CSV *f, int nlcode);
char *csvgetline(CSV *f);
char *csvgetfield(CSV *f, int n);
int csvgetn(CSV *f);
int csvputline(CSV *f);
int csvputstr(CSV *f, char *val);
int csvputint(CSV *f, int val);
int csvputreal(CSV *f, double val);
int csvstrin(CSV *f, char *str);
char *csvstrout(CSV *f);
int csvstrprep(CSV *f);
void csvsetdebug(int d);


