Files correlati : Ricompilazione Demo : [ ] Commento : Modifiche di marco git-svn-id: svn://10.65.10.50/trunk@8858 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			132 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			132 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/*
 | 
						|
  CVS2SQL
 | 
						|
  Programma interfacciabile a CVS tramite loginfo, per registrare i commit su di un database POSTGRES.
 | 
						|
  L'applicazione dovra' essere eseguita sul server nel quale risiede il repository (Etabeta)
 | 
						|
  Le informazioni da registrare sulla tabella COMMITS, vengono reperite in 3 modi:
 | 
						|
   - dallo stdin per quanto riguarda il log file vero e proprio: [Release] [Descrizione] [Errori] [Files]
 | 
						|
   - variabile d'ambiente per l'autore ($USER)
 | 
						|
   - linea di comando per quanto riguarda il nome del modulo.
 | 
						|
 | 
						|
  Sarebbe bello farlo in C++ ma su etabeta gcc e' installato male e non funziona.
 | 
						|
  Altrettanto bello sarebbe potere usare  cvs2sql presente nelle libwww: http://dev.w3.org/cvsweb/libwww/Library/cvs2sql
 | 
						|
  Ma per fare cosi' e' necessario scaricarle e compilarle. E per compilare un programmino del cavolo non voglio includere nel
 | 
						|
  repository tutta quella roba.
 | 
						|
 */
 | 
						|
 | 
						|
#include <libpq-fe.h>
 | 
						|
#include <string.h>
 | 
						|
 | 
						|
 | 
						|
#define POSTGRES_HOST  "mccoy"
 | 
						|
#define POSTGRES_PORT  ""
 | 
						|
#define POSTGRES_DB    "eurocampo"
 | 
						|
#define DEFAULT_USER   "Aga Informatica"
 | 
						|
#define BUFSIZE    16384
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void cvs2sql(char* modulo)
 | 
						|
{
 | 
						|
  FILE *fin=stdin;
 | 
						|
  int status;
 | 
						|
  char autore[20];
 | 
						|
  char release[20];
 | 
						|
  char buffer[BUFSIZE];
 | 
						|
  char files[BUFSIZE/4];
 | 
						|
  char descrizione[BUFSIZE/4];
 | 
						|
  char errori [BUFSIZE/4];
 | 
						|
  char committed_files[BUFSIZE/2];
 | 
						|
  char *p1, *p2, *p3;
 | 
						|
  PGconn* pgc;
 | 
						|
 | 
						|
  
 | 
						|
  /* Sistema l'autore della modifica, prendendolo dalla variabile d'ambiente*/
 | 
						|
  strcpy(autore,getenv("USER"));
 | 
						|
  if (strlen(autore) == 0)
 | 
						|
    strcpy(autore, "Aga Informatica");
 | 
						|
 | 
						|
  /* Legge dallo stdin il log file, 16 KB sono abbastanza per un log...*/
 | 
						|
  status = fread(buffer, 1, BUFSIZE, fin);
 | 
						|
  if (status < 0)
 | 
						|
    {
 | 
						|
      printf("Can't read from stdin\n");
 | 
						|
      return;
 | 
						|
    }
 | 
						|
  /* Legge le informazioni sui files modificati, aggiunti, cancellati */
 | 
						|
  strcpy(committed_files, "");
 | 
						|
  p1 = strstr(buffer, " Files:");
 | 
						|
  if (p1 != NULL)
 | 
						|
    {
 | 
						|
      int l;
 | 
						|
      p2 = strrchr(p1, '\n');
 | 
						|
      p2++;
 | 
						|
      p1 = strstr(p2, "Log Message:");
 | 
						|
      *p1 = '\0';
 | 
						|
      l = (int) (p2 - p1);
 | 
						|
      strncpy(committed_files, p2, l);
 | 
						|
      p1 += 13;
 | 
						|
    }
 | 
						|
  /* Legge il paragrafo di release */
 | 
						|
  p2 = strstr(p1 ? p1 : buffer,"[Release]");
 | 
						|
  if (p2 != NULL)
 | 
						|
    {
 | 
						|
      p2++;
 | 
						|
      p1 = strchr(p2, '\n');
 | 
						|
      *p1 = '\0';
 | 
						|
      strcpy(release, p2);
 | 
						|
      p1++;
 | 
						|
    }
 | 
						|
  p2 = strstr(p1 ? p1 : buffer, "[Files]");
 | 
						|
  if (p2 != NULL)
 | 
						|
    {
 | 
						|
      p2 += 7;
 | 
						|
      strncpy(files, p2, );
 | 
						|
    }
 | 
						|
  p2 = strstr(p1 ? p1 : buffer, "[Descrizione]");
 | 
						|
  if (p2 != NULL)
 | 
						|
    {
 | 
						|
    }
 | 
						|
  p2 = strstr(p1 ? p1 : buffer, "[Errori]");
 | 
						|
  if (p2 != NULL)
 | 
						|
    {
 | 
						|
    }
 | 
						|
 | 
						|
  /* Apre la connessione sul database, inizia una transazione, bloccando la tabella dei progressivi per gestire la concorrenza */
 | 
						|
  pgc = PQsetdb(POSTGRES_HOST, POSTGRES_PORT, NULL, NULL, POSTGRES_DB);
 | 
						|
  if (PQstatus(pgc)==CONNECTION_OK)
 | 
						|
    {
 | 
						|
    }
 | 
						|
  else 
 | 
						|
    printf("FATAL ERROR: Can't open database %s: %s\n", POSTGRES_DB, PQerrorMessage(pgc));
 | 
						|
  PQfinish(pgc);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int main(int argc, char* argv[])
 | 
						|
{
 | 
						|
  if (argc == 2)
 | 
						|
    cvs2sql(argv[1]);
 | 
						|
  else 
 | 
						|
    printf("Usage: cvs2sql <module>\nWarning: $USER environment variable must also be set \nand a log file must be written on stdin.\n");
 | 
						|
  exit(0);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |