Example #1
0
ASF_ASFConditionalEquationList ASF_unionASFConditionalEquationList(ASF_ASFConditionalEquationList cel1,
								   ASF_OptLayout separator,
								   ASF_ASFConditionalEquationList cel2)
{
  if (!ASF_isASFConditionalEquationListEmpty(cel2)) {
    if (!ASF_isASFConditionalEquationListEmpty(cel1)) {
      int len1 = ASF_getASFConditionalEquationListLength(cel1);
      int len2 = ASF_getASFConditionalEquationListLength(cel2);
      ATermIndexedSet iSet = ATindexedSetCreate((len1+len2)*2, 75);
      ASF_ASFConditionalEquation ce;
      ASF_ASFConditionalEquationList newCel = ASF_makeASFConditionalEquationListEmpty();
      int maxIndex = 0, index;

      while (ASF_hasASFConditionalEquationListHead(cel1)) {
        ce = ASF_getASFConditionalEquationListHead(cel1);
        index = ATindexedSetPut(iSet, 
                                ASF_ASFConditionalEquationToTerm(ce),
                                NULL);
        if (index > maxIndex) {
          maxIndex = index;
        }
                                   
        if (ASF_hasASFConditionalEquationListTail(cel1)) {
          cel1 = ASF_getASFConditionalEquationListTail(cel1);
        }
        else {
          break;
        }
      }
      while (ASF_hasASFConditionalEquationListHead(cel2)) {
        ce = ASF_getASFConditionalEquationListHead(cel2);
        index = ATindexedSetPut(iSet, 
                                ASF_ASFConditionalEquationToTerm(ce),
                                NULL);
        if (index > maxIndex) {
          maxIndex = index;
        }
                                   
        if (ASF_hasASFConditionalEquationListTail(cel2)) {
          cel2 = ASF_getASFConditionalEquationListTail(cel2);
        }
        else {
          break;
        }
      }
      
      for (index=0; index <= maxIndex; index++) {
        ce = ASF_ASFConditionalEquationFromTerm(ATindexedSetGetElem(iSet, index));
        newCel = ASF_makeASFConditionalEquationListMany(ce,
							separator, 
							newCel);
      }
      ATindexedSetDestroy(iSet);
      return newCel;
    }
    return cel2;
  } 

  return cel1;
}
Example #2
0
int 
main (int argc, char **argv)
{
  int c; /* option character */
  ATerm bottomOfStack;
  char *inputs[MAX_MODULES] = { "-" };
  int  nInputs = 0;
  char *output = "-";
  ATbool module = ATfalse;
  ATermList list;
  ASF_ASFConditionalEquationList alleqs;
  int i;

  if(argc == 1) { /* no arguments */
    usage();
    exit(1);
  }

  while ((c = getopt(argc, argv, myarguments)) != EOF) {
    switch (c) {
    case 'h':  
      usage();                      
      exit(0);
    case 'm':
      module = ATtrue;
      break;
    case 'o':  
      output = strdup(optarg);    
      break;
    case 'V':  fprintf(stderr, "%s %s\n", myname, myversion);
      exit(0);
    default:
      usage();
      exit(1);
    }
  }

  /* The optind variable indicates where getopt has stopped */
  for(i = optind; i < argc; i++) {
    if (nInputs < MAX_MODULES) {
      inputs[nInputs++] = strdup(argv[i]);  
    } else {
      ATerror("Maximum number of %d modules exceeded.\n", MAX_MODULES);
      exit(1);
    }
  }

  if (nInputs == 0) {
    nInputs = 1;
    inputs[0] = strdup("-");
  }

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

  list = ATempty;
  for (--nInputs; nInputs >= 0; nInputs--) {
    ATerm p = ATreadFromNamedFile(inputs[nInputs]); 

    if (p == NULL) {
      ATwarning("concat-asf: Unable to read anything from %s\n", 
		inputs[nInputs]);
    }
    else {
      list = ATinsert(list, p);
    }
    free(inputs[nInputs]);
  }

  alleqs = ASF_makeASFConditionalEquationListEmpty();

  for(;!ATisEmpty(list); list = ATgetNext(list)) {
    ATerm head = ATgetFirst(list);
    ASF_ASFConditionalEquationList list;

    if (ATgetType(head) == AT_LIST) {
      list = ASF_ASFConditionalEquationListFromTerm(head);
    }
    else {
      ASF_ASFModule module = ASF_getStartTopASFModule(ASF_StartFromTerm(head));
      list = ASF_getASFModuleEquationList(module);
    }

    ATwarning("Adding %d equations\n", ASF_getASFConditionalEquationListLength(list));

    alleqs = ASF_unionASFConditionalEquationList(alleqs, ASF_makeLayoutNewline(), list);

  }

  if (module) {
    ASF_OptLayout l = ASF_makeLayoutNewline();
    ASF_ASFSection sec = ASF_makeASFSectionEquations(l, alleqs);
    ASF_ASFModule mod = ASF_makeASFModuleDefault(ASF_makeASFSectionListSingle(sec));
    /*PT_ParseTree pt = PT_makeValidParseTreeFromTree((PT_Tree) mod);*/

    ATwriteToNamedBinaryFile((ATerm) mod, output);
  } 
  else {
    ATwriteToNamedBinaryFile(ASF_ASFConditionalEquationListToTerm(alleqs),
			     output);
  }
 
  return 0;
}