Beispiel #1
0
int main(int argc, char *argv[])
{
  int c;
  ATerm bottomOfStack;
  ATerm term;
  char   *inputName = "-";
  char   *outputName = "-";

  while ((c = getopt(argc, argv, myarguments)) != -1) {
    switch (c) {
      case 'i':
	inputName = optarg;
	break;
      case 'o':
	outputName = optarg;
	break;
      case 'V':
	version();
	break;
      case 'h':
	usage();
	return 0;
      default:
	usage();
	return 1;
    }
  }

  ATBinit(argc, argv, &bottomOfStack);

  term = ATreadFromNamedFile(inputName);
  ATwriteToNamedTextFile(term, outputName);

  return 0;
}
Beispiel #2
0
int main(int argc, char **argv)
{
  int c;
  ATerm bottomOfStack;
  PT_ParseTree tree, flatTree;

  /*  Configuration items  */
  char   *input="-";
  char   *output="-";
  ATbool bafmode=ATtrue;
  ATbool verbose=ATfalse;
  ATbool proceed=ATtrue;

  extern char *optarg;
  extern int   optind;

  /*  Commandline mode  */

  while ((c = getopt(argc, argv, myarguments)) != -1) {
    switch (c) {
      case 'b':  bafmode = ATtrue;                       break;
      case 'i':  input=optarg;                           break;
      case 'o':  output=optarg;                          break;
      case 't':  bafmode = ATfalse;                      break;
      case 'v':  verbose = ATtrue;                       break;
      case 'V':  version(); proceed=ATfalse;             break;

      case 'h':
      default:   usage(); proceed=ATfalse;                     break;
    }
  }
  argc -= optind;
  argv += optind;

  ATinit(argc, argv, &bottomOfStack);
  PT_initMEPTApi();
  PT_initAsFix2Api();

  if(proceed) {
    tree = PT_ParseTreeFromTerm(ATreadFromNamedFile(input));
    flatTree = flattenPT(tree);

    if(!flatTree) {
      ATerror("%s: conversion failed.", myname);
    }
    if(bafmode) {
      ATwriteToNamedBinaryFile(PT_ParseTreeToTerm(flatTree), output);
    }
    else {
      ATwriteToNamedTextFile(PT_ParseTreeToTerm(flatTree), output);
    }
  }

  return 0;
}
Beispiel #3
0
int main (int argc, char **argv)
{
  int c; 
  ATerm bottomOfStack;
  PT_ParseTree parsetree;
  ATerm ambiguities;
  ATbool atermformat = ATfalse;
  char   *input_file_name  = "-";
  char   *output_file_name = "-";
  
  while ((c = getopt(argc, argv, myarguments)) != EOF)
    switch (c) {
      case 'a':  atermformat = ATtrue;         break;
      case 'h':  usage();                      exit(0);
      case 'i':  input_file_name  = optarg;    break;
      case 'o':  output_file_name = optarg;    break;
      case 'V':  fprintf(stderr, "%s %s\n", myname, myversion);
                                               exit(0);
      default :  usage();                      exit(1);
  }

  ATinit(argc, argv, &bottomOfStack);    /* Initialize Aterm library */
  PT_initMEPTApi();

  parsetree = PT_ParseTreeFromTerm(ATreadFromNamedFile(input_file_name));

  if(parsetree == NULL) {
    ATerror("%s: could not read term from input file %s\n", 
	    myname, input_file_name);
  }

  ambiguities = PT_reportParseTreeAmbiguities(parsetree);

  if(!atermformat) {
    FILE *fp = NULL;

    if(!strcmp(output_file_name, "") || !strcmp(output_file_name,"-")) {
      fp = stdout;
    } else if(!(fp = fopen(output_file_name, "wb"))) {
      ATerror("%s: could not open %s for output.\n", myname, output_file_name);
      return 1;
    }

    prettyPrint(ambiguities,fp);

    fclose(fp);
  } else {
    ATwriteToNamedTextFile(ambiguities, output_file_name);
  }

  return 0;
}
Beispiel #4
0
int main (int argc, char *argv[])
{
  int c; /* option character */
  ATerm bottomOfStack;
  ATerm tree;
  Graph graph;

  char   *input_file_name  = "-";
  char   *output_file_name = "-";

  ATbool characters = ATfalse;
  ATbool productions = ATfalse;
  ATbool layout = ATfalse;
  ATbool literals = ATtrue;
  ATbool binary = ATtrue;
  ATbool sharing = ATfalse;

#ifndef WITHOUT_TOOLBUS
  ATbool use_toolbus = ATfalse;
  int i;
 
  for (i=1; !use_toolbus && i < argc; i++) {
    use_toolbus = !strcmp(argv[i], "-TB_TOOL_NAME");
  }
 
  if (use_toolbus) {
    int cid;
    ATBinit(argc, argv, &bottomOfStack);
    PT_initMEPTApi();
    initGraphApi();
    cid = ATBconnect(NULL, NULL, -1, graph_converter_handler);
    ATBeventloop();
  }
  else
#endif
  {
    while ((c = getopt(argc, argv, myarguments)) != EOF)
      switch (c) {
        case 'b':  binary = ATtrue;              break;
        case 'c':  characters = ATtrue;          break;
        case 'h':  usage();                      exit(0);
        case 'i':  input_file_name  = optarg;    break;
        case 'l':  layout = ATtrue;              break;
        case 'm':  literals = ATfalse;           break;
        case 'o':  output_file_name = optarg;    break;
        case 'p':  productions = ATtrue;         break;
        case 't':  binary = ATfalse;             break;
        case 's':  sharing = ATtrue;             break;
        case 'V':  fprintf(stderr, "%s %s\n", myname, myversion);
                                                 exit(0);
        default :  usage();                      exit(1);
    }

    ATinit(argc, argv, &bottomOfStack);
    PT_initMEPTApi();
    initGraphApi();

    tree = ATreadFromNamedFile(input_file_name);

    if(tree == NULL) {
      ATerror("%s: could not read term from input file %s\n", 
	      myname, input_file_name);
    }

    graph = PT_printAnyToGraph(tree, characters, productions,
			       layout, literals, sharing);

    if (!strcmp(output_file_name,"-")) {
      if (binary) {
        ATwriteToBinaryFile(GraphToTerm(graph), stdout);
      } 
      else {
        ATwriteToTextFile(GraphToTerm(graph), stdout);
      } 
    }
    else {
      if (binary) {
        ATwriteToNamedBinaryFile(GraphToTerm(graph), output_file_name);
      } 
      else {
        ATwriteToNamedTextFile(GraphToTerm(graph), output_file_name);
      } 
    }
  }

  return 0;
}
Beispiel #5
0
int asc_support_main(ATerm *bottomOfStack, int argc, char *argv[], void (*register_all)(), void (*resolve_all)(), void (*init_all)(), unsigned const char* tableBaf, size_t tableSize, ATbool parseInput, ATBhandler handler) {

  PT_ParseTree pt = NULL;
  PT_Tree asfix;
  PT_Tree trm;
  PT_ParseTree rpt = NULL;
  ATerm reduct;
  const char *outputFilename;
  int numberOfInputs;

  ATinit(argc, argv, bottomOfStack);
  initApis();

  register_all();
  resolve_all();
  init_all();

  initParsetable(tableBaf, tableSize);
  SGLR_initialize();

  OPT_initialize();
  ASC_initializeDefaultOptions();

  /*  Check whether we're a ToolBus process  */
  if (toolbusMode(argc, argv)) {
    ATBinit(argc, argv, bottomOfStack);
    ATBconnect(NULL, NULL, -1, asf_toolbus_handler);
    ATBeventloop();
  }
  else {    
    handleOptions(argc, argv, parseInput);

    numberOfInputs = ASC_getNumberOfParseTrees();
    outputFilename = ASC_getOutputFilename();

    if (!streq(ASC_getPrefixFunction(),"")) {
      pt = applyFunction((const char*) ASC_getPrefixFunction(), 
			 (const char*) ASC_getResultNonTermName(), numberOfInputs, inputs);
    } 
    else {
      if (numberOfInputs == 0) {
	pt = parsetreeFromFile("-", parseInput);
      }
      else if (numberOfInputs == 1) {
	pt = inputs[0];
      }
      else if (numberOfInputs != 1) {
	ATerror("Can only process one argument if no -f and -r option "
		"are supplied.\n"
		"Did a -s argument eat up your -f or -r option?\n");
	return 1;
      }
    }

    if (PT_isValidParseTree(pt)) {
      trm = PT_getParseTreeTop(pt);

      if (ASC_getVerboseFlag()) { ATfprintf(stderr,"Reducing ...\n"); }

      reduct = innermost(trm);

      if (ASC_getVerboseFlag()) { ATfprintf(stderr,"Reducing finished.\n"); }
      if (ASC_getStatsFlag())  { printStats(); }

      if (ASC_getOutputFlag()) {
	asfix = toasfix(reduct);
	rpt = PT_makeParseTreeTop(asfix, 0);

	if (parseInput) {
	  FILE *fp = NULL;

	  if (!strcmp(outputFilename, "-")) {
	    fp = stdout;
	  }
	  else {
	    fp = fopen(outputFilename, "wb");
	  }

	  if (fp != NULL) {
	    PT_yieldParseTreeToFile(rpt, fp, ATfalse);
	  }
	  else {
	    ATerror("asc-main: unable to open %s for writing\n", outputFilename);
	  }
	}
	else {
	  if (ASC_getBafmodeFlag()) {
	    ATwriteToNamedBinaryFile(PT_ParseTreeToTerm(rpt),outputFilename);
	  }
	  else {
	    ATwriteToNamedTextFile(PT_ParseTreeToTerm(rpt),outputFilename);
	  }
	}
      }
    }
  }

  return 0;
}
Beispiel #6
0
int main (int argc, char *argv[])
{
  int c; 
  ATerm bottomOfStack;
  ATerm input = NULL;
  ATerm output = NULL;
  ATbool textual = ATfalse;
  char *input_file_name = "-";
  char *output_file_name = "-";
  int i;
  ATbool use_toolbus = ATfalse;

  ATinit(argc, argv, &bottomOfStack);
  RS_initRStoreApi();
  PRS_initParsedRStoreApi();

  for (i=1; !use_toolbus && i < argc; i++) {
    use_toolbus = !strcmp(argv[i], "-TB_TOOL_NAME");
  }

  if (use_toolbus) {
    int cid;
    ATBinit(argc, argv, &bottomOfStack);

    cid = ATBconnect(NULL, NULL, -1, lower_rstore_handler);
    ATBeventloop();
  }
  else {
    while ((c = getopt(argc, argv, myarguments)) != EOF)
      switch (c) {
	case 'h':  usage();                      exit(0);
	case 'i':  input_file_name  = optarg;    break;
	case 'o':  output_file_name = optarg;    break;
	case 't':  textual = ATtrue; break;
	case 'V':  fprintf(stderr, "%s %s\n", myname, myversion);
		   exit(0);
	default :  usage();                      exit(1);
      }

    input = ATreadFromNamedFile(input_file_name);

    if(input == NULL) {
      ATerror("%s: could not read term from input file %s\n", 
	      myname, input_file_name);
      return 1;
    }

    if (PRS_isValidRStore((PRS_RStoreFromTerm(input)))) {
      output = (ATerm) RS_lowerRStore(PRS_RStoreFromTerm(input));
    }
    else if (PRS_isValidStart(PRS_StartFromTerm(input))) {
      PRS_RStore tmp = PRS_getStartTopRStore(PRS_StartFromTerm(input));
      output = (ATerm) RS_lowerRStore(tmp);
    }

    if(output != NULL) {
      if (textual) {
	ATwriteToNamedTextFile(output, output_file_name);
      }
      else {
	ATwriteToNamedSAFFile(output, output_file_name);
      }
    }
    else {
      ATwarning("%s: something went wrong\n", myname);
      return 1;
    }
  }

  return 0;
}
Beispiel #7
0
int main(int argc, char **argv)
{
  int c;
  ATerm bottomOfStack;
  char   *input="-";
  char   *output="-";
  char   *argument = NULL;
  ATbool minimizeSort = ATfalse;
  ATbool maximizeSort = ATfalse;
  ATerm inputTerm = NULL;
  ATerm outputTerm = NULL;
  PT_ParseTree inputTree = NULL;
  PT_ParseTree outputTree = NULL;

  while ((c = getopt(argc, argv, myarguments)) != -1) {
    switch (c) {
      case 'i':  
	input=optarg;
	break;
      case 'n':
	minimizeSort = ATtrue;
	argument = optarg;
	break;
      case 'N':
	maximizeSort = ATtrue;
	argument = optarg;
	break;
      case 'o':  
	output=optarg;     
	break;
      case 'V':  
	version();
	return 0;
      case 'h':
	usage();
	return 0;
      default:   
	usage();
	return 1;
    }
  }

  ATinit(argc, argv, &bottomOfStack);     
  PT_initMEPTApi();

  inputTerm = ATreadFromNamedFile(input);
  inputTree = PT_ParseTreeFromTerm(inputTerm);

  if (inputTerm != NULL) {
    /* The tool will always execute one filter at a time, such that the user
     * can implement his own scheduling by repeatedly using this tool.
     * Please do not change this behavior.
     */
    if (XOR(minimizeSort, maximizeSort) && argument != NULL) {
      PT_Symbol sort = PT_makeSymbolCf(PT_makeSymbolSort(argument));
      outputTree = minmax(inputTree, sort, minimizeSort);
    }
    else {
      usage();
      return 1;
    }

    if (outputTree != NULL) {
      outputTree = flattenAgain(outputTree);
      outputTerm = PT_ParseTreeToTerm(outputTree);

      ATwriteToNamedTextFile(outputTerm, output);
    }
    else {
      fprintf(stderr, "%s: filtering failed unexpectedly\n", myname);
      return 1;
    }
  }
  else {
    fprintf(stderr,"%s: could not open file %s\n", myname, input);
    return 1;
  }

  return 0;
}
Beispiel #8
0
int asc_support_main(ATerm *bottomOfStack, int argc, char *argv[], 
		     void (*register_all)(), 
		     void (*resolve_all)(),
		     void (*init_all)()
#ifdef TOOLBUS
		     , ATBhandler handler
#endif
		     )
{
  PT_ParseTree pt;
  PT_ParseTree asfix;
  PT_Tree trm;
  ATerm t; 
  ATerm reduct;
#ifdef TOOLBUS
  ATbool toolbus_mode = ATfalse;
#endif
  ATbool produce_output = ATtrue;
  ATbool run_verbose = ATfalse;
  ATbool printstats = ATfalse;
  ATbool bafmode = ATtrue;
  char *inputs[MAX_ARGS] = { "-" };
  int nInputs = 0;
  char *output = "-";
  char *function = "";
  char *result = "";
  int i;

  ATinit(argc, argv, bottomOfStack);
  PT_initMEPTApi();
  ASF_initASFMEApi();
  ASC_initRunTime(INITIAL_TABLE_SIZE);

  register_all();
  resolve_all();
  init_all();

#ifdef TOOLBUS
  /*  Check whether we're a ToolBus process  */

  for(i=1; !toolbus_mode && i<argc; i++) {
    if(!strcmp(argv[i], "-TB_TOOL_NAME")) {
      toolbus_mode = ATtrue;
    }
  }

  if (toolbus_mode) {
     ATBinit(argc, argv, bottomOfStack);
     ATBconnect(NULL, NULL, -1, handler);
     ATBeventloop();
  }
  else {
#endif
  for(i=1; i<argc; i++) {
    if(streq(argv[i], "-v")) {
      run_verbose = ATtrue;
    } 
    else if(streq(argv[i], "-h")) {
      usage(argv[0]);
    } 
    else if(streq(argv[i], "-f")) {
      function = argv[++i];
    }
    else if(streq(argv[i], "-i")) {
      if (nInputs <= MAX_ARGS) {
        inputs[nInputs++] = strdup(argv[++i]);
      }
      else {
	ATerror("%s: Maximum number of %d \'-i\' arguments exceeded.\n", 
		argv[0], MAX_ARGS);
      }
    } 
    else if(streq(argv[i], "-o")) {
      output = argv[++i];
    }
    else if(streq(argv[i], "-r")) {
      result = argv[++i];
    }
    else if(streq(argv[i], "-s")) {
      printstats = ATtrue;
    }
    else if(streq(argv[i], "-t")) {
      bafmode = ATfalse;
    }
    else if(streq(argv[i], "-m")) {
      produce_output = ATfalse;
    }
  }


  if (!streq(function,"")) {
    PT_Args args = PT_makeArgsEmpty();
    
    if (streq(inputs[0],"-")) {
      nInputs++;
    }

    for (--nInputs; nInputs >= 0; nInputs--) {
      PT_ParseTree parseTree = PT_makeParseTreeFromTerm(
                                 ATreadFromNamedFile(inputs[nInputs]));

      if (parseTree == NULL) {
	ATerror("Unable to read in %s\n", inputs[nInputs]);
	exit(1);
      }

      args = PT_makeArgsList(PT_getParseTreeTree(parseTree), args);
    }

    pt = PT_applyFunctionToArgsParseTree(function, result, args);
  } 
  else {
    if (nInputs != 1 && (!streq(inputs[0], "-"))) {
      ATerror("Can only process one argument if no -f and -r option "
	      "are supplied.\n");
      return 1;
    }

    t = ATreadFromNamedFile(inputs[0]);
    pt = PT_makeParseTreeFromTerm(t);
  }

  if (PT_isValidParseTree(pt)) {
    trm = PT_getParseTreeTree(pt);
    
    if(run_verbose) {
      ATfprintf(stderr,"Reducing ...\n");
    }
    
    reduct = innermost(trm);
    
    if(run_verbose) {
      ATfprintf(stderr,"Reducing finished.\n");
    }

    if (printstats) {
      struct rusage usage;
      FILE *file;
      char buf[BUFSIZ];
      int size, resident, shared, trs, lrs, drs, dt;

      sprintf(buf, "/proc/%d/statm", getpid());
      file = fopen(buf, "r");
      if (file) {
	fscanf(file, "%d %d %d %d %d %d %d",
	       &size, &resident, &shared, &trs, &lrs, &drs, &dt);
	/*
	fprintf(stderr, "size     = %d kb\n", size*4);
	fprintf(stderr, "resident = %d kb\n", resident*4);
	fprintf(stderr, "shared   = %d kb\n", shared*4);
	fprintf(stderr, "trs      = %d kb\n", trs*4);
	fprintf(stderr, "lrs      = %d kb\n", lrs*4);
	*/
	fprintf(stderr, "memory used : %d kb\n", drs*4);
	/*fprintf(stderr, "dt       = %d kb\n", dt*4);*/
      } else {
	fprintf(stderr, "could not open %s\n", buf);
	perror("");
      }
      if (getrusage(RUSAGE_SELF, &usage) == -1) {
	perror("rusage");
      } else {
	/*fprintf(stderr, "rusage statistics (see 'man getrusage')\n");*/
	fprintf(stderr, "utime       : %ld.%06d sec.\n",
		(long)usage.ru_utime.tv_sec, (int)usage.ru_utime.tv_usec);
	fprintf(stderr, "stime       : %ld.%06d sec.\n",
		(long)usage.ru_stime.tv_sec, (int)usage.ru_stime.tv_usec);
#if 0
	/* The following rusage stats do not work yet */
	fprintf(stderr, "maxrss   : %ld\n", usage.ru_maxrss);
	fprintf(stderr, "ixrss    : %ld\n", usage.ru_ixrss);
	fprintf(stderr, "idrss    : %ld\n", usage.ru_idrss);
	fprintf(stderr, "isrss    : %ld\n", usage.ru_isrss);
	fprintf(stderr, "minflt   : %ld\n", usage.ru_minflt);
	fprintf(stderr, "majflt   : %ld\n", usage.ru_majflt);
	fprintf(stderr, "nswap    : %ld\n", usage.ru_nswap);
	fprintf(stderr, "\n");
	fprintf(stderr, "inblock  : %ld\n", usage.ru_nswap);
	fprintf(stderr, "oublock  : %ld\n", usage.ru_nswap);
	fprintf(stderr, "msgsnd   : %ld\n", usage.ru_nswap);
	fprintf(stderr, "msgrcv   : %ld\n", usage.ru_nswap);
	fprintf(stderr, "nsignals : %ld\n", usage.ru_nswap);
	fprintf(stderr, "nvcsw    : %ld\n", usage.ru_nswap);
	fprintf(stderr, "nivcsw   : %ld\n", usage.ru_nswap);
#endif
      }
    }
 
    if (produce_output) {
      asfix = toasfix(reduct);
      if (bafmode) {
	ATwriteToNamedBinaryFile(PT_makeTermFromParseTree(asfix),output);
      }
      else {
	ATwriteToNamedTextFile(PT_makeTermFromParseTree(asfix),output);
      }

    }
  }

#ifdef TOOLBUS
  }
#endif

  return 0;
}