Ejemplo n.º 1
0
// Usage: ./client <fileIn> <fileOut> <fileOut2> <heapSize> <rowCount> <rowLength>
int main (int argc, char* argv[]) {

	char* nameFileIn = argv[1];
	char* nameFileOut = argv[2];
	char* nameFileOut2 = argv[3];
	char** page;
	FILE* fpI,* fpO;
	int nr;
	heap_t* heap;
	strArray_t* save;

	int D = atoi(argv[4]), N = atoi(argv[5]), M = atoi(argv[6]);

	printf("input file: %s\noutput file: %s\noutput file 2: %s\n",
			nameFileIn, nameFileOut, nameFileOut2);
	printf("D: %d - N: %d - M: %d\n", D, N, M);

	heap = heapCreate(D);

	save = strArrayInit(heap, 0); /* inizializza a vuoto */

	page = (char**)heapAlloc(heap, N * sizeof(char*));
	fpI = fopen(nameFileIn, "r");
	fpO = fopen(nameFileOut, "w");
	if (page == NULL || fpI == NULL || fpO == NULL) {
		printf("Errore in allocazione memoria o apertura file\n");
		exit(1);
	}

	while ((nr = leggiPagina(heap, page, fpI, N)) > 0) {
		ordinaPagina(page, nr);
		scriviPagina(page, fpO, nr);
		filtraeLiberaPagina(heap, page, nr, save, M);
	} 
	
	fclose(fpI);
	fclose(fpO);
	heapFree(heap, page);

	fpO = fopen(nameFileOut2, "w");
	if (fpO == NULL) {
		printf("Errore in apertura file\n");
		exit(1);
	}

	strArraySort(save);
	strArrayPrint(save, fpO);
	fclose(fpO);

	strArrayFree(heap, save);

	heapDestroy(heap);

	return 0;

}
Ejemplo n.º 2
0
int main (int argc, char *argv[])
{
  char *nameFileIn = argv[1];
  char *nameFileOut = argv[2];
  char *nameFileOut2 = argv[3];
  char **page;
  FILE *fpI, *fpO;
  int i, nr;
  strArray_t *save = strArrayInit(0); /* inizializza a vuoto */

  int D=atoi(argv[4]), N=atoi(argv[5]), M=atoi(argv[6]);

  printf("input file: %s - output file: %s\n", nameFileIn, nameFileOut);
  printf("input file: %s - output file: %s output file 2\n", 
         nameFileIn, nameFileOut, nameFileOut2);
  printf("D: %d - N: %d - M: %d\n", D, N, M);

  page = (char **) malloc (N * sizeof(char *));
  fpI = fopen (nameFileIn, "r");
  fpO = fopen (nameFileOut, "w");
  if (page==NULL || fpI==NULL || fpO==NULL) {
    printf("errore in allocazione memoria o apertura file\n");
    exit (1);
  }

  while ((nr = leggiPagina(page,fpI,N)) > 0) {
    ordinaPagina(page,nr);
    scriviPagina(page,fpO,nr);
    filtraeLiberaPagina(page,nr,save,M);
  } 
  
  fclose(fpI);
  fclose(fpO);
  free(page);

  fpO = fopen (nameFileOut2, "w");
  if (fpO==NULL) {
    printf("errore in apertura file\n");
    exit (1);
  }

  strArraySort(save);
  strArrayPrint(save,fpO);
  fclose(fpO);

  strArrayFree(save);
}
Ejemplo n.º 3
0
  int sFlowList(void *magic, char *line)
  {
    EVMod *mod = (EVMod *)magic;
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    // expect lines of form <var> : <val>
    int varlen = strcspn(line, ":");
    if(varlen >= strlen(line)) {
      myLog(LOG_ERR, "expected <var> : <val>, but got <%s>", line);
      return NO;
    }
    line[varlen] = '\0';
    char *var = stripQuotes(line, SFVS_QUOTES);
    char *val = stripQuotes(line + varlen + 1, SFVS_QUOTES);
    myDebug(1, "sFlowList> %s=%s", var, val);
    if(strcmp(var, "_uuid") == 0) {
      switch(mdata->state) {
      case SFVSSTATE_SYNC_SEARCH:
	myDebug(1, "found sflow uuid %s", val);
	setStr(&mdata->sflowUUID, val);
	setState(mod, SFVSSTATE_SYNC_FOUND);
	break;
      case SFVSSTATE_SYNC_FOUND:
      case SFVSSTATE_SYNC_DESTROY:
	setState(mod, SFVSSTATE_SYNC_DESTROY);
	myDebug(1, "found extra sflow uuid %s", val);
	strArrayAdd(mdata->extras, val);
	break;
      default:
	myLog(LOG_ERR, "sFlowList: unexpected state %s", SFVSStateNames[mdata->state]);
	setState(mod, SFVSSTATE_END);
	return NO;
      }
    }
    else if (mdata->state == SFVSSTATE_SYNC_FOUND) {
      // we have adopted an existing sFlow object.  This is the one
      // we will keep. All others will be destroyed. Here we check in
      // case any of the individual parameters need to be changed too.
      if(strcmp(var, "agent") == 0) {
	char quoted[SFVS_MAX_LINELEN];
	snprintf(quoted, SFVS_MAX_LINELEN, "\"%s\"", val);
	if(strcmp(quoted, mdata->config.agent_dev) != 0) {
	  addSFlowSetting(mod, "agent", mdata->config.agent_dev);
	}
      }
      else if(strcmp(var, "header") == 0) {
	uint32_t n = strtol(val, NULL, 0);
	if(n != mdata->config.header_bytes) {
	  addSFlowSetting_int(mod, "header", mdata->config.header_bytes);
	}
      }
      else if(strcmp(var, "polling") == 0) {
	uint32_t n = strtol(val, NULL, 0);
	if(n != mdata->config.polling_secs) {
	  addSFlowSetting_int(mod, "polling", mdata->config.polling_secs);
	}
      }
      else if(strcmp(var, "sampling") == 0) {
	uint32_t n = strtol(val, NULL, 0);
	if(n != mdata->config.sampling_n) {
	  addSFlowSetting_int(mod, "sampling", mdata->config.sampling_n);
	}
      }
      else if(strcmp(var, "targets") == 0) {
	// the spaces between elements in the array are a nuisance, because they
	// could go away someday and break any scheme that relies on a simple
	// string-compare. So parse it into comma-separated tokens.
	// single-threaded, so we can just use strtok(3)
	UTStringArray *array = strArrayNew();
	val = stripQuotes(val, "[]");
	char *delim = ", ";
	for(char *tok = strtok(val, delim); tok != NULL; tok=strtok(NULL, delim)) {
	  strArrayAdd(array, stripQuotes(tok, SFVS_QUOTES));
	}
	strArraySort(array);
	if(!strArrayEqual(array, mdata->config.targets)) {
	  addSFlowSetting(mod, "targets", mdata->config.targetStr);
	}
	strArrayFree(array);
      }
    }
    return YES;
  }