/*
   File:        dscli.h
   Author:      Andrew W. Moore
   Created:     Mon Jun  2 19:58:44 EDT 1997
   Description: Utilities on datsets

   Copyright 1997, Carnegie Mellon University
*/

#ifndef dscli_H
#define dscli_H

#include "dsut.h"
#include "command.h"
#include "join.h"

/************************ INPUTS AND OUTPUTS *************************/
void print_ins_and_out(datset *ds,ivec *in_attnums,int out_attnum,int max_atts_printed);

/* This function reads the string array to see if it can process it as
   one of the following commands:

inputs <attnames>
inputs all
ignore <attnames>
add <attnames>
output <attname>

  and it updates *in_attnums and/or out_attnum accordingly (maybe reallocating
  in_attnums.

  Note that if something is declared an output it is automatically removed from inputs.

  Note that "inputs all" sets the inputs to be all attributes EXCEPT the current output

  Note that if there's an illegal attname, this prints a message and does nothing.

  On exit returns TRUE if it changed something.

  Makes sure that in_attnums is sorted in ascending order.
  */   
bool command_line_changes_inputs_or_output(datset *ds,string_array *sa,ivec **in_attnums,
                                           int *out_attnum,bool realvalued_out_ok);


#define value_from_arg(ds,attnum,s) ds_value_from_string(ds,attnum,s)

#define DISP_NONE 0
#define DISP_REPORT 1
#define DISP_RULES 2

typedef struct dsenv
{
  datset *ds;
  ivec *row_to_marked;
  int num_marked;
  bool ds_changed;
  bool acted;
} dsenv;

string_array *mk_datset_attnames(datset *ds,bool,bool);
string_array *mk_datset_attvals(datset *ds,int attnum);

bool check_attnum(datset *ds,char *s);

bool attnums_ok_from(datset *ds,command *c,int arg);
bool attnums_ok(datset *ds,command *c);
bool attnum_ok(datset *ds,command *c,int arg);
/* Declared but not defined - sir 9/6/2000
querynode *mk_querynode_from_command(datset *ds,command *c,int arg); */

dsenv *mk_dsenv_incfree_datset(datset *ds);
datset *mk_datset_free_dsenv(dsenv *de);


void ds_cli_edit(datset **r_ds,int argc,char *argv[]);

void edit_main(int argc,char *argv[]);

void unmark_all(dsenv *de);


void mark_record(dsenv *de, int row);

/* Returns an ivec of listing the rows that are currently marked.
   i.e. [0, 2, 6, 10, ...] */
ivec *mk_ivec_marked_rows(dsenv *de);

void dset_main(int argc,char *argv[], const char *filename);

/* Put this function at the end of and generic_cli function
   you write if there's any chance that any of the commands
   might change the datset. See the end of dsenv_command(...)
   in dscli.c for an example. */
void unmark_all_if_ds_changed(dsenv *de);

#endif
