/*
 *
 *      Copyright (C) 1991 by the Massachusetts Institute of Technology
 *      Developed by the MIT Student Information Processing Board (SIPB).
 *      For copying information, see the file mit-copyright.h in this release.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <discuss/discuss.h>

extern tfile unix_tfile();
extern tfile mem_tfile();
extern char *malloc(),*calloc();

extern int errno;
extern char *sys_errlist[];
extern int sys_nerr;

int verbose_errors;
int bsize;
char *buffer;

void main(int argc, char *argv[])
{
  char *getenv();
  name_blk meetings;
  mtg_info meeting_info;
  int result,setenv(),cur_meeting;
  int print_trans,search_trans,search_deleted,s_trans();
  int trans_num;
  tfile tf;
  trn_info2 ti;
  
  initialize_dsc_error_table();

  print_trans = 1;
  search_trans = 0;
  verbose_errors = 1;
  search_deleted = 0;

  if (argc != 4) {
    fprintf(stderr, "oops\n");
    exit(1);
  }

  trans_num = atoi(argv[3]);
  cur_meeting = 1;
  meetings.hostname = argv[1];
  meetings.pathname = argv[2];
  meetings.user_id = "";
  meetings.aliases = NULL;
  meetings.status = 0;
  meetings.date_attended = 0;
  meetings.last = 0;

  tf = unix_tfile(1); /*stdout */

  dsc_get_mtg_info(&meetings,&meeting_info,&result);
  if (result != 0) {
    fprintf(stderr,"dsgrep: error getting meeting info for meeting '%s:%s': %s\n",
	    meetings.hostname, meetings.pathname,
	    error_message(result));
  }

  dsc_get_trn_info2(&meetings,trans_num,&ti,&result);
  if (result != 0) {
    if (verbose_errors)
      fprintf(stderr,"dsgrep: error getting transaction info for %s[%d]: %s\n",
	      (char *) (rindex(meetings.pathname,'/')+1), trans_num,
	      error_message(result));
  }
  if (search_deleted || !(ti.flags & TRN_FDELETED)) {
    printf("%s [%d]: %s\n",(char *)
	   (rindex(meetings.pathname,'/')+1), trans_num, ti.subject);
    if (print_trans) {
      dsc_get_trn(&meetings,trans_num,tf,&result);
      if ((result != 0) && verbose_errors)
	fprintf(stderr,"dsgrep: error getting transaction %s[%d]: %s\n",
		(char *) (rindex(meetings.pathname,'/')+1), trans_num,
		error_message(result));
    }
  }
}
