Beispiel #1
0
main (int argc, char *argv[])
{
  FILE *test;
  int filetype;
  DB *dbtest;
  int i, startrec, maxrec;
  extern SGML_Doclist *PRS_first_doc;
  struct rlimit limits;
  config_file_info *cf;
  char *crflags, *opflags;
#ifdef WIN32
  crflags = "w+b";
  opflags = "r+b";
#else
  crflags = "w+";
  opflags = "r+";
#endif


  LOGFILE = stderr;

  if (argc < 3) {
    printf ("usage: %s configfilename file <startrec> <maxrec>\n", argv[0]);
    exit (0);
  }

  /* Crank up the number of permitted open files --- just in case */
  getrlimit(RLIMIT_NOFILE, &limits);

#ifdef DEBUGIND
  printf("curr fileno %d  max fileno %d\n",  limits.rlim_cur, limits.rlim_max);
#endif

  if (limits.rlim_cur < limits.rlim_max) {
    limits.rlim_cur = limits.rlim_max;
    setrlimit(RLIMIT_NOFILE, &limits);
  }

#ifdef DEBUGIND
  getrlimit(RLIMIT_NOFILE, &limits);
  printf("curr fileno %d  max fileno %d\n",  limits.rlim_cur, limits.rlim_max);
#endif


  /* the following reads and parses the config info from its file */
  cf_info_base = cf_initialize(argv[1], crflags, opflags);

  if (cf_info_base == NULL) {
    printf("could not initialize configfile %s\n",argv[1]);
    exit(1);
  }

  /* prints the interesting bits of the config info structure */
  /*  cf_print_info (cf_info_base); */

  /* initialize or create all files */
  cf_createall();
  

  if (argc >= 4) 
    startrec = atoi(argv[3]);
  else
    startrec = 1;

  if (argc == 5)
    maxrec = atoi(argv[4]);
  else
    maxrec = cf_getnumdocs(argv[2]);
  
  printf("file: %s startrec: %d maxrec: %d\n", 
	 argv[2], startrec, maxrec);
      
  for (i = startrec; i <= maxrec; i++) {
    printf ("processing record %d\n",i);
    in_kwadd(argv[2],i);

  }
  
  
  /* free any un-freed documents  and the doclist structures */
  /* free all the doc_list memory */
  if (PRS_first_doc)
    free_doc_list(PRS_first_doc);
  
  PRS_first_doc = NULL;

#ifdef NEEDTOTRYWITHOUT
  /* create the cluster files */
  if ((filetype = cf_getfiletype(argv[2])) == FILE_TYPE_SGMLFILE
      || filetype == FILE_TYPE_XML
      || filetype == FILE_TYPE_XML_NODTD
      || filetype == FILE_TYPE_XML_DATASTORE
      || filetype == FILE_TYPE_MARCFILE
      || filetype == FILE_TYPE_SGML_DATASTORE
      || filetype == FILE_TYPE_MARC_DATASTORE) { 
    /* only main SGML files are processed here */
    in_clusmerg(argv[2]);
  }
#endif
  /* free all the DTDs */
  free_all_dtds();
  
  cf_closeall();

}
Beispiel #2
0
/*
 * history test
 */
int main(int argc, char *argv[])
{
    char *c_flag=NULL;
    char *S_flag=NULL, *L_flag=NULL;
    int i, c;
    char *m;
    time_t t = 0;

    /* Init configuration */
    cf_initialize();

    while ((c = getopt(argc, argv, "t:vc:S:L:")) != EOF)
	switch (c) {
	case 't':
	    t = atol(optarg);
	    break;
	    
	/***** Common options *****/
	case 'v':
	    verbose++;
	    break;
	case 'c':
	    c_flag = optarg;
	    break;
	case 'S':
	    S_flag = optarg;
	    break;
	case 'L':
	    L_flag = optarg;
	    break;
	default:
	    exit(EX_USAGE);
	    break;
	}

    /*
     * Read config file
     */
    if(L_flag)				/* Must set libexecdir beforehand */
	cf_s_libexecdir(L_flag);
    cf_read_config_file(c_flag ? c_flag : DEFAULT_CONFIG_MAIN);

    /*
     * Process config options
     */
    if(L_flag)
	cf_s_libexecdir(L_flag);
    if(S_flag)
	cf_s_spooldir(S_flag);

    cf_debug();


    hi_init_history();

    if(optind < argc) 
    {
	for(i=optind; i<argc; i++)
	{
	    m = argv[i];
	    if(hi_test(m))
	    {
		debug(1, "dupe: %s", m);
	    }
	    else
	    {
		if(t)
		{
		    debug(2, "new: %s (time=%ld)", m, t);
		    hi_write_t(t, 0, m);
		}
		else
		{
		    debug(2, "new: %s (time=now)", m);
		    hi_write(0, m);
		}
	    }
	}
    }
    else 
    {
	while( fgets(buffer, sizeof(buffer), stdin) )
	{
	    strip_crlf(buffer);
	    m = buffer;
	    if(hi_test(m))
	    {
		debug(1, "dupe: %s", m);
	    }
	    else
	    {
		if(t)
		{
		    debug(2, "new: %s (time=%ld)", m, t);
		    hi_write_t(t, 0, m);
		}
		else
		{
		    debug(2, "new: %s (time=now)", m);
		    hi_write(0, m);
		}
	    }
	}
	
    }
    
    
    hi_close();
    
    exit(0);
}
main (int argc, char *argv[])
{
  int filetype;
  int i, nargs, startrec, maxrec;
  extern SGML_Doclist *PRS_first_doc;
#ifndef WIN32
  struct rlimit limits;
#endif
  config_file_info *cf;
  int return_code;
  int batch_flag = 0;
  time_t startime;
  char *temp_file_dir = NULL;
  char *sort_args = NULL;
  char *log_file_name = NULL;
  char *dbms_password = NULL;
#ifndef NO_RUSAGE
  struct rusage ru;
#endif
  char *crflags, *opflags;
#ifdef WIN32
  crflags = "w+b";
  opflags = "r+b";
#else
  crflags = "w+";
  opflags = "r+";
#endif

  if (argc < 2) {
    printf ("usage: %s <-b -T tmpdir -S \"sort flags\" -L logfilename -p database_passwrd> configfilename <startrec> <maxrec>\n", argv[0]);
    exit (0);
  }

  /* call scram() if user hits DELETE/BREAK and on seg or bus error */
#ifndef WIN32
  signal(SIGINT, scram);
  signal(SIGBUS, scram);
  signal(SIGSEGV, scram);
  signal(SIGTERM, scram);
  signal(SIGKILL, scram);
  signal(SIGHUP, scram);
#ifndef HP
  signal(SIGXCPU, scram2);
  signal(SIGXFSZ, scram2);
#endif
#endif


#ifndef WIN32
  /* Crank up the number of permitted open files --- just in case */
  getrlimit(RLIMIT_NOFILE, &limits);

  if (limits.rlim_cur < limits.rlim_max) {
    limits.rlim_cur = limits.rlim_max - 1;
    setrlimit(RLIMIT_NOFILE, &limits);
  }

#ifdef DEBUGIND
  getrlimit(RLIMIT_NOFILE, &limits);
  printf("curr fileno %d  max fileno %d\n",  limits.rlim_cur, limits.rlim_max);
#endif
#endif

  /* set the starting time */
  time(&startime);
  
  nargs = argc;

  while (nargs > 0) {
    if (argv[1][0] == '-' && argv[1][1] == 'b') { /* use batch processing */
      batch_flag = 1;
      nargs--;
      argc--;
      argv += 1;
    }
      /* the -T option is only technically available within -b and 
	 gives the temp directory */
    else if (argv[1][0] == '-' && argv[1][1] == 'T') {
      temp_file_dir = argv[2];
      nargs -= 2;
      argc -= 2;
      argv += 2;
    }
    else if (argv[1][0] == '-' && argv[1][1] == 'S') {
      sort_args = argv[2];
      nargs -= 2;
      argc -= 2;
      argv += 2;
    }
    else if (argv[1][0] == '-' && argv[1][1] == 'L') {
      log_file_name = argv[2];
      nargs -= 2;
      argc -= 2;
      argv += 2;
    }
    else if (argv[1][0] == '-' && argv[1][1] == 'p') {
      dbms_password = argv[2];
      nargs -= 2;
      argc -= 2;
      argv += 2;
    }
    else if (argv[1][0] == '-') {
      printf ("usage: %s <-b -T tmpdir -L logfilename> configfilename <startrec> <maxrec>\n", argv[0]);
      exit (0);
    }
    else
      nargs-- ;
  }

  if (log_file_name)
    LOGFILE = fopen(log_file_name,"a+"); /* open the logfile to append */
  else
    LOGFILE = fopen("INDEX_LOGFILE","a+"); /* open the logfile to append */

  /* the following reads and parses the config info from its file */
  cf_info_base = cf_initialize(argv[1], crflags, opflags);

  if (cf_info_base == NULL) {
    printf("could not initialize configfile %s\n",argv[1]);
    exit(1);
  }

  /* prints the interesting bits of the config info structure */
  /*  cf_print_info (cf_info_base); */

  /* initialize or create all files */
  if (cf_createall() != 0) {
    printf("Error in file creation -- see log file\n");
    exit(-1);
  }

  if (argc >= 3) {
    startrec = atoi(argv[2]);
    last_rec_proc = startrec - 1;
  }
  else
    startrec = 1;

  for (cf = cf_info_base; cf ; cf = cf->next_file_info) {

    if (argc == 4)
      maxrec = atoi(argv[3]);
    else {
      maxrec = -1; /* this will be changed to the max in each file */
    }
    if ((filetype = cf->file_type) == FILE_TYPE_SGMLFILE
	|| filetype == FILE_TYPE_XML
	|| filetype == FILE_TYPE_XML_NODTD
	|| filetype == FILE_TYPE_XML_DATASTORE
	|| filetype == FILE_TYPE_MARCFILE
	|| filetype == FILE_TYPE_SGML_DATASTORE
	|| filetype == FILE_TYPE_MARC_DATASTORE) { 
      /* only main SGML files are processed here                        */
      /* BUT if the MARCFILE type is on, it means SGML using USMARC DTD */
      if (filetype > 99 && cf->file_db == NULL) {
	cf_open_datastore(cf);
      }
      if (maxrec == -1) maxrec = cf_getnumdocs(cf->file_name);
      
      fprintf(LOGFILE,
	      "\nRun Date: %s \nfile: %s (%s) startrec: %d maxrec: %d\n",
	      ctime(&startime), cf->file_name, cf->nickname, 
	      startrec, maxrec);
      fflush(LOGFILE);

      for (i = startrec; i <= maxrec; i++) {

	if (i % 500 == 0) {
#ifndef NO_RUSAGE
	  getrusage(RUSAGE_SELF, &ru);
	  fprintf (LOGFILE,"processing record %d -- Memory %d: I/O In %d Out %d\n",
		   i,ru.ru_maxrss, ru.ru_inblock,ru.ru_oublock);	
#else
	  fprintf (LOGFILE,"processing record %d\n", i);
#endif
	  fflush(LOGFILE);
	}

	return_code = in_kwadd(cf->file_name,i, batch_flag, 
			       temp_file_dir);

	if (i != last_rec_proc +1) {

	  fprintf(LOGFILE,
		  "EXITING: Serious error from in_kwadd: i(%d) != last record(%d) %d\n",
		  i, last_rec_proc, return_code);
	  fflush(LOGFILE);
	  exit(return_code);
	}
	last_rec_proc = i;

	if (return_code <= 0) {/* some sort of error occurred */
	  if (return_code == -1 || return_code == -3) {
	    fprintf(LOGFILE,
		    "EXITING: Serious error from in_kwadd: return code %d\n",
		    return_code);
	    fflush(LOGFILE);
	    exit(return_code);
	  }
	  else if (return_code == -2) {
	    /* bad sgml record -- ignor it -- it is already logged */
	    fflush(LOGFILE);
	    }
	  else {
	    fprintf(LOGFILE,
		    "EXITING: unknown error: kwadd return code %d record %d\n",
		    return_code, last_rec_proc);
	    fflush(LOGFILE);
	    exit(return_code);
	  }
	}
	/* free any un-freed documents  and the doclist structures */
	/* free all the doc_list memory */
	if (PRS_first_doc) {
	  free_doc_list(PRS_first_doc);
	  PRS_first_doc = NULL;
	}
      } /* end of main for loop */

      if (batch_flag) {
	/* the processing has created temporary files that need to be */
	/* merged and the information stored in the proper indexes    */
	in_batch_load(cf, temp_file_dir, sort_args);
      }
      /* Make sure everything is on disk */
      in_sync_indexes(cf);
  
      fprintf(LOGFILE,"Last record processed %d\n", last_rec_proc); 

    }
    else if (filetype == FILE_TYPE_VIRTUALDB) {
      fprintf(LOGFILE,"Virtual Databases may not be indexed directly...\n"); 
      fprintf(LOGFILE,"Index each database making up the virtual db separately\n"); 
      
    }
    else if (filetype == FILE_TYPE_DBMS) {

      fprintf(LOGFILE,
	      "\nRun Date: %s \nfile: %s (%s) startrec 0 maxrec: determined for each index...\n",
	      ctime(&startime), cf->file_name, cf->nickname);
      fprintf(LOGFILE,"Indexing from DBMS connection...\n"); 
      fflush(LOGFILE);

      return_code = in_dbms (cf->file_name,batch_flag, temp_file_dir, 
			     dbms_password);
      if (return_code >= 0 && batch_flag) {
	/* the processing has created temporary files that need to be */
	/* merged and the information stored in the proper indexes    */
	in_batch_load(cf, temp_file_dir, sort_args);
      }
      /* Make sure everything is on disk */
      if (return_code >= 0)
	in_sync_indexes(cf);      
    }
  }

  /* free all the DTDs */
  free_all_dtds();

  cf_closeall();

  close_grid_data();

  time(&startime);

  fprintf(LOGFILE,"Last record processed %d at time: %s -- ", 
	  last_rec_proc, ctime(&startime)); 

#ifndef NO_RUSAGE
  getrusage(RUSAGE_SELF, &ru);
  fprintf (LOGFILE,"Memory %d: I/O In %d Out %d\n",
		   ru.ru_maxrss, ru.ru_inblock,ru.ru_oublock);	
#endif
  fclose(LOGFILE);
  return (0);
}
Beispiel #4
0
int main(int argc, char **argv)
{
    int c, n;
    int b_flag=FALSE;
    int n_flag=FALSE;
    char *f_flag=NULL;
    char *m_flag=NULL;
    char cmd[MAXPATH];
    char *args[MAXARGS];
    
    int option_index;
    static struct option long_options[] =
    {
	{ "news-batch",   0, 0, 'b'},	/* Process news batch */
	{ "news-mode",    0, 0, 'n'},	/* Set news mode */
	{ "batch-file",   1, 0, 'f'},	/* Read batch file for list of articles */
	{ "maxmsg",       1, 0, 'm'},	/* New output packet after N msgs */

	{ "help",         0, 0, 'h'},	/* Help */
	{ 0,              0, 0, 0  }
    };

#ifdef SIGPIPE
    /* ignore SIGPIPE */
    signal(SIGPIPE, SIG_IGN);
#endif

    log_program(PROGRAM);

    /* init configuration */
    cf_initialize();
    cf_read_config_file(CONFIG);

    while ((c = getopt_long(argc, argv, "bnf:m:h",
			    long_options, &option_index     )) != EOF)
	switch (c) {
	/***** ftnmail options *****/
	case 'b':
	    b_flag = TRUE;
	    break;
	case 'n':
	    n_flag = TRUE;
	    break;
	case 'f':
	    f_flag = optarg;
	    break;
	case 'm':
	    m_flag = optarg;
	    break;
	    
	/***** common options *****/
	case 'h':
	    usage();
	    exit(0);
	    break;
	default:
	    short_usage();
	    exit(EX_USAGE);
	    break;
	}

    /* complete path of rfc2ftn */
    BUF_COPY3(cmd, cf_p_libexecdir(), "/", RFC2FTN);

    /* build args[] */
    n = 0;
    args[n++] = RFC2FTN;
    if(b_flag)
    {
	args[n++] = "-b";
    }
    if(n_flag)
    {
	args[n++] = "-n";
    }
    if(f_flag)
    {
	args[n++] = "-f";
	args[n++] = f_flag;
    }
    if(m_flag)
    {
	args[n++] = "-m";
	args[n++] = m_flag;
    }

    args[n++] = NULL;

#if 0
    /* debug */
    printf("cmd=%s\n", cmd);
    for(n=0; args[n]; n++)
	printf("args[%d]=%s\n", n, args[n]);
    exit(0);
#endif

    /* exec */
    if( execv(cmd, args) == ERROR )
	fglog("$can't exec %s", cmd);
	
    /* Only reached if error */
    exit(1);

    /**NOT REACHED**/
    return 1;
}
Beispiel #5
0
int main(int argc, char **argv)
{
    int c;
    char *c_flag=NULL;
    
    int option_index;
    static struct option long_options[] =
    {
	{ "no-newline",   0, 0, 'l'},	/* No newline */
	{ "no-output",    0, 0, 'n'},	/* No output */
	{ "test-only",    0, 0, 't'},	/* No output */

	{ "verbose",      0, 0, 'v'},	/* More verbose */
	{ "help",         0, 0, 'h'},	/* Help */
	{ "config",       1, 0, 'c'},	/* Config file */
	{ 0,              0, 0, 0  }
    };

    /* Init configuration */
    cf_initialize();


    while ((c = getopt_long(argc, argv, "lntvhc:",
			    long_options, &option_index     )) != EOF)
	switch (c) {
	/***** ftnconfig options *****/
        case 'l':
	    l_flag = TRUE;
            break;
        case 'n':
	    n_flag = TRUE;
            break;
        case 't':
	    t_flag = TRUE;
	    n_flag = TRUE;
            break;
	    
	/***** Common options *****/
	case 'v':
	    verbose++;
	    break;
	case 'h':
	    usage();
	    exit(0);
	    break;
	case 'c':
	    c_flag = optarg;
	    break;
	default:
	    short_usage();
	    exit(EX_USAGE);
	    break;
	}

    /*
     * Read config file
     */
    cf_read_config_file(c_flag ? c_flag : CONFIG);

    cf_debug();

    if(optind != argc-1) 
    {
	    short_usage();
	    exit(EX_USAGE);
    }
    
    exit( do_para(argv[optind]) ? 0 : 1 );
    }