Exemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////
// Send my list of files
void sendList( Folder *dir, int sock ) {
  int i;                  // Iterator
  int nbytes;             // Number of bytes
  char buffer[ MAXBUFSIZE ]; // Message to send
  //  FM temp; 

  ls( dir );

  bzero( buffer, MAXBUFSIZE );
  sprintf( buffer, "%i", dir->total );
  printf( "$ Will forward %s files\n", buffer );
  nbytes = write( sock, buffer, MAXBUFSIZE );
  ERROR( nbytes < 0 );

  for ( i = 0; i < dir->total; ++i ){
	bzero( buffer, MAXBUFSIZE );
	memcpy( &buffer, &dir->list[i], sizeof( FM ) );
	nbytes = write( sock, buffer, MAXBUFSIZE );
	ERROR( nbytes < 0 );
  }

  printCatalog( dir );
  
} // sendList( )
Exemplo n.º 2
0
int main ( int argc, char * argv[ ] ) {
  int nbytes;                // Number of bytes
  int sock;                  // This will be our socket
  char buffer[ MAXBUFSIZE ]; // A buffer to buff things
  char cmd[ MAXBUFSIZE ];    // Command to be sent to Server
  char *newline = NULL;      // Get newline
  Folder dir;                // Local list of folder Files
  Repository repo;           // Master file list

  // Make sure name, ip and port are given
  if ( argc < 4 ) {
	printf("USAGE:  <client_name> <server_ip> <server_port>\n");
	exit ( EXIT_FAILURE );
  }

  sprintf( dir.name, "%s", argv[1] );
  ls( &dir );
  
  printf( "$ Welcome '%s'\n", dir.name );
  
  sock = createSocket( inet_addr( argv[2] ), atoi( argv[3] ) );
  connectPlease( &dir, sock );
  //  getMaster( &repo, sock );

  //
  // Enter command loop
  //
  do {
	bzero( cmd, sizeof( cmd ) );
	printf( "> " );
	
	//
	// Grab Command Line
	//
	if ( fgets( cmd, MAXBUFSIZE, stdin ) != NULL ) {
	  newline = strchr( cmd, '\n'); // Find the newline
	  if ( newline != NULL ) *newline = '\0'; // Overwrite
	  
	  switch ( parseCmd ( cmd ) ) 
		{
		case LS:
		  printCatalog ( &dir );
		  break;
		case GET:
		  getMaster( &repo, sock );
		  break;
		case EXIT: 
		  nbytes = write( sock, "EXIT", MAXBUFSIZE );
		  ERROR( nbytes < 0 );
		  break;
		default:
		  nbytes = write( sock, cmd, MAXBUFSIZE );
		  ERROR( nbytes < 0 );
		  bzero( buffer, MAXBUFSIZE );
		  nbytes = read( sock, buffer, MAXBUFSIZE );
		  printf( "$ %s\n", buffer);
		  break;
		}	
	}
  } while ( !isQuit( cmd ) );  

  close( sock );
  
  return EXIT_SUCCESS;
} // main( )
Exemplo n.º 3
0
int main(int argc,char** argv)
{
	if(argc!= 2){
		printf("Wrong arguments!\nSintax: GESTAUTS 'file_path'\n");
	return 1;
   }
   time_t seconds = time(NULL);
 
 int entradas = 0;
	int menor_ano = 2015;
	int maior_ano = 0;
	int autores = 0;
	char *filename = argv[1];
	FILE* fl = fopen(filename,"a+");
	int read;
	char * line = NULL;
	size_t len = 0;
	int ano;
	Indice* indice;
	 int i = 0;
	indice = initInd(indice); 

	/*malloc(28*sizeof(Node));
	for(i;i<28;i++)
		indice[i] = NULL;
		*/
	Catalog * catalog;
	catalog = catInit(catalog);

i=0 ;
	while ((read = getline(&line, &len, fl)) != -1) {
	int nap= 0;
	char** nomes;
	lineParser(line,&autores, &ano,&nap,&nomes); 

    if(ano > maior_ano)
    	maior_ano = ano;

    if(ano < menor_ano)
    	menor_ano = ano;
 
catalog = add(catalog,ano,nomes,nap); 

while(nap>0)
{
 indice = addToInd(indice ,nomes[nap-1]);
nap--;
}
 

    //printf("%s\n", nomes[0]);
    entradas++;
 
    free(nomes);
    len= 0;
}
printf("Ficheiro: %s\n", filename);
printf("Publicaçoes: %d\n",entradas );
printf("Numero total de autores: %d\n",autores );
printf("Intervalo de anos: [%d-%d]\n", menor_ano,maior_ano);



printCatalog(catalog);




//printIndice(indice);
free(line);
fclose(fl);
free(indice);
free(catalog);
time_t seconds2 = time(NULL);
printf("time in seconds :: %ld\n", (seconds2-seconds) );
return 0;
}