/*
Copyright (c) 1998-2005, Dirk Krause
All rights reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above 
  opyright notice, this list of conditions and the following
  disclaimer in the documentation and/or other materials
  provided with the distribution.
* Neither the name of the Dirk Krause nor the names of
  contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
*/

#ifndef TRACECC_H_INC
#define TRACECC_H_INC 1

/* includes {{{1 */
#include <stdio.h>
#include <dk.h>
#if DK_HAVE_STDLIB_H
#include <stdlib.h>
#else
#error "no stdlib.h"
#endif
#if DK_HAVE_UNISTD_H
#include <unistd.h>
#endif
#if DK_HAVE_PROCESS_H
#include <process.h>
#endif
#include <dkapp.h>
#include <dklogc.h>
#include <dkmem.h>
#include <dkstr.h>
#include <dkerror.h>
#include <dklic.h>
#include <dksf.h>
#include <dkcp.h>
/* }}}1 */

/* definitions {{{1 */

/* operation modes {{{2 */
#define TRACECC_OPT_DEBUG		    1
#define TRACECC_OPT_DEBST		    2
#define TRACECC_OPT_KEYWORD		    4
#define TRACECC_OPT_CPPCOMMENT		    8
#define TRACECC_OPT_MAKE		   16
#define TRACECC_OPT_LINENO		   32
#define TRACECC_OPT_JAVA2		   64
#define TRACECC_OPT_DATETIME		  128
#define TRACECC_OPT_HELP		16384
#define TRACECC_OPT_VERSION		 8192
#define TRACECC_OPT_CONFIG		 4096
#define TRACECC_OPT_UNCONF		 2048
#define TRACECC_OPT_SHOWCONF		 1024
/* }}}2 */

/* }}}1 */

/* typedefs {{{1 */

/* option set {{{2 */
typedef struct {
  int o;	/* options or-connected */
  int b;	/* comment box width */
  int i;	/* ide style */
} tracecc_opt_t ;
/* }}}2 */

/* tracecc type {{{2 */
typedef struct {
  /*
    initialized during tracecc_open
  */
  dk_app_t *app;	/* application */
  tracecc_opt_t	o;	/* options as specified by setup */
  tracecc_opt_t f;	/* option set changed while processing file */
  char **messages;	/* message texts */
  int error_code;	/* code for last error */
  long mpl;		/* max path length */
  char *out_name_buf;	/* output name buffer, mpl bytes long */
  char *tmp_name_buf;	/* buffer for temporary file name */
  size_t ibl;		/* input buffer length in bytes */
  char *inbuffer;	/* input buffer */
  char *icmdbuf;	/* buffer for interpreter commands */
  size_t icmdsz;	/* size of buffer */
  /*
    set up when a run is started
  */
  int what;		/* 0=no setup yet, 1=directories, 2=files */
  char *dir_ori;	/* directory as specified, fnsep corrected */
  dk_fne_t *fne_ori;	/* directory name expander */
  char *dir_cur;	/* current directory as obtained from expander */
  dk_dir_t *dir_tra;	/* directory traverser */
  char *in_ori;		/* input file name as specified, fnsp cor */
  char *out_ori;	/* output */
  dk_fne_t *fne_in;	/* file name expander for input file */
  dk_fne_t *fne_out;	/* ... output file */
  char *in_real;	/* real input name, not dynamically */
  char *out_real;	/* ... output */
  /*
    set by run_for_real_in_and_real_out
  */
  int   newft;		/* type of new file 1=C, 2=Java */
  char *in_short;
  FILE *infile;
  FILE *outfile;
  /*
    initialized by run_for_opened_files
  */
  FILE *tmpfile;
  unsigned long lineno;
  size_t ibu;
  size_t ibc;
  char   currentchar;
  int    textflags;
  int    indent;
  int    state;
  int    reaction;
  size_t icmdu;		/* bytes used in interpreter command buffer */
  int    cmbll;
  int    cmbmax;
  /*
    messages we already printed
  */
  int    line_too_long_printed;
} tracecc_t;
/* }}}2 */

/* }}}1 */

/* tracecc.c module {{{1 */
#if defined(EXTERN)
#undef EXTERN
#endif
#ifndef TRACECC_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif
#if defined(__cplusplus)
extern "C" {
#endif
/* module functions {{{2 */
/* }}}2 */
#if defined(__cplusplus)
}
#endif
/* }}}1 */

/* traceco.c module {{{1 */
#if defined(EXTERN)
#undef EXTERN
#endif
#ifndef TRACECO_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif
#if defined(__cplusplus)
extern "C" {
#endif
/* module functions {{{2 */
EXTERN tracecc_t *tracecc_open DK_PR((dk_app_t *app));
EXTERN void tracecc_close DK_PR((tracecc_t *ptr));
EXTERN int tracecc_dir DK_PR((tracecc_t *ptr, char *d));
EXTERN int tracecc_files DK_PR((tracecc_t *ptr, char *i, char *o));
EXTERN int tracecc_get_mode DK_PR((tracecc_t *tc));
EXTERN int tracecc_get_boxwidth DK_PR((tracecc_t *tc));
EXTERN void tracecc_set_mode DK_PR((tracecc_t *tc, int mode));
EXTERN void tracecc_set_boxwidth DK_PR((tracecc_t *tc, int bw));
EXTERN void tracecc_save_preferences DK_PR((dk_app_t *app,int mode, int bw, int is));
EXTERN int tracecc_get_idestyle DK_PR((tracecc_t *tc));
EXTERN void tracecc_set_idestyle DK_PR((tracecc_t *tc, int bw));
/* }}}2 */
#if defined(__cplusplus)
}
#endif
/* }}}1 */


#endif

