int main( int argc, char * argv[] ) {
  SgProject* project = frontend(argc,argv);

  initAnalysis(project);
  cfgUtils::initCFGUtils(project);
  Dbg::init("propagation test", "./proptest", "index.html");

//  liveDeadAnalysisDebugLevel = 1;
  analysisDebugLevel = 0;

  LiveDeadVarsAnalysis ldva(project);
//       ldva.filter = gfilter; // the defaultFitler can provide the same semantics now
  UnstructuredPassInterDataflow ciipd_ldva(&ldva);
  //     assert (ciipd_ldva.filter == gfilter);
  ciipd_ldva.runAnalysis();



  StringLiteralAnalysis lanalysis(project);
  lanalysis.runAnalysis();
  analysisDebugLevel = 1;
  PointerAliasAnalysisDebugLevel = 1;
  PointerAliasAnalysis pal(&ldva, project, lanalysis.getLiteralMap());
  pal.runAnalysis();
  printf("done\n");


}
Example #2
0
File: main.c Project: annunal/IDSL
int main(int argc, char *argv[]) 
{
  struct sensorGrid readings;
  int fd, wd, idx;
  char fullname[FILENAME_MAX], tmpname[FILENAME_MAX], logCommands[4096];
  char hostname[200];
  int er=gethostname(hostname,sizeof(hostname));
  printf("Hostname=%s\n",hostname);
  readConfiguration(CONFIGFILENAME);
  
  if (argc>=2) 
  {
	if (strcasecmp(argv[1],"retry")==0)
	{   char dateName[32], currDate[32];
		if(argc==3) strcpy(dateName,argv[2]);
		else {
			
			time_t now = (time_t) time(0);
			struct tm *gmtm = (struct tm *) gmtime(&now);
			strftime(dateName, sizeof(dateName), "retry_%Y-%m-%d.txt", gmtm);
			}
		retryToTransmit(dateName);
		return;
	}
  }
  //if(argc != 3 && argc != 4) {
    //fprintf(stderr, "Usage: %s foldername filename [output]\n", argv[0]);
    //return 1;
  //}

  //if(argc == 4) {
  if(Configuration.commandSerial[0]) {
    otp = openSerialPort(Configuration.commandSerial, B9600);
    if(otp) {
      itp = otp;
    } else {
      perror( "Unable to append to output device" );
      otp = stdout;
      itp = stdin;
    }
  } else {
    otp = stdout;
    itp = stdin;
  }

  /* read configuration */
  for(idx = 0; idx < MAX_PROP; idx++) status[idx] = NULL;

  readStatus(status);

  /* set up communication with the siren */
  if (wiringPiSetupGpio () == -1)  
  {  
     perror( "Can't initialise wiringPi" );
     return -2;
  }  


  initSiren(SIREN_PIN);  
  initBigDisplay();
  readings.pressure = 0;
  readings.temperature = 0;
  readings.distance = 0;
  initSensors();  
  initServo(SERVO_PIN, itp);  
  startServo();
  
  sleep(1);  // sleep 1 s to have at least 1 sensor value
  initAnalysis();  
  
  // lcd = lcdInit (2, 16, 4, RS, STRB, 0, 1, 2, 3, 4, 5, 6, 7);

  startSensorsReading(&readings);

	if(Configuration.watchFolder[0] && Configuration.watchFile) {
		sprintf(tmpname, "%s/%s", argv[1], argv[2]);
		realpath(tmpname, fullname);
	}

  /* set up file watcher */
  fd = inotify_init ();
  if (fd < 0) {
        perror ("unable to initialize inotify");
        return -1;
  }

  if( Configuration.watchFolder[0] )
	wd = inotify_add_watch (fd, Configuration.watchFolder, IN_CLOSE_WRITE );
  else
	wd = 0;

  if (wd < 0) {
        perror ("unable to add inotify watch");
        return -2;
  }

  /* loop on file change events and execute commands */
  while( 1 ) {
    char buf[BUF_LEN];
    int len, i = 0, process = 0;
    
    len = read (fd, buf, BUF_LEN);
    if (len < 0) {
            if (errno == EINTR)
                    ;	/* need to reissue system call */
            else
                    perror ("error reading inotify stream");
    } else if (!len)
		; /* BUF_LEN too small? */
    
    while (i < len) {
            struct inotify_event *event;
    
            event = (struct inotify_event *) &buf[i];
    
            // printf ("wd=%d mask=%u cookie=%u len=%u\n",
                    // event->wd, event->mask,
                    // event->cookie, event->len);
    
            if (event->len && strcmp(argv[2], event->name) == 0)
	    	process++;
    
            i += EVENT_SIZE + event->len;
    }

    if(process) { // It doesn't matter how many times the file changed, but it is good for debugging
	char *line = NULL, *ptr, *end, **commandName, *displayLines[MAX_LINES];
	FILE *fp = 0;
	int i, len, chars, cmd, statusDirty = 0, cmdPosition = 0;
	process = 0;

	fp=fopen(fullname, "r");
	if(fp) {
		unlink(fullname);	// the name is removed from the filesystem, the file isn't until it is closed
					// if a new file is created, it accumulates event in the watcher, and we'll cycle again next round

		while ((chars = getline(&line, &len, fp)) != -1) {
			ptr = line;
			while(*ptr != ':') {
				*ptr=toupper(*ptr);
				ptr++;
			}

			for( cmd=0, ptr = *(commandName = commands); ptr; ptr=*(++commandName), cmd++)
				if( !strncmp(ptr, line, strlen(ptr)) )
				{ // the command is present in the list and can be sent to the panel: it double checks the data from php
					switch(cmd)
					{
						case 7:		// SIREN
							ptr = line + 1 + strlen(ptr);   // skip property name and colon
                                                        end = ptr + strlen(ptr);
                                                        while( *--end == 13 || *end == 10) *end = '\0';
							siren(ptr);
							if(cmdPosition + strlen(line) < 3072)
								cmdPosition += sprintf(logCommands + cmdPosition, "%s;", line );
							statusDirty = -1;
						break;
						case 8:		// SPEAKER
						break;
						case 9:		// DELETE
						break;
						case 10:	// RESET
						break;
						case 11:	// PWR
						break;
						case 12:	// TIMEZONE
						break;
						case 13:	// NAME
						break;
						case 14:	// RESTORE
						break;
						case 15:	// TIMETO
						break;
						case 16:	// IPADDR
						break;
						case 17:	// SUBNET
						break;
						case 18:	// GSM
						break;
						case 19:	// GSMRES
						break;
						default:	// set property
							if(status[cmd]) free(status[cmd]);
							ptr = line + 1 + strlen(ptr);	// skip property name and colon
							end = ptr + strlen(ptr);	// end of command to retrieve EOL
							while( *--end == 13 || *end == 10) *end = '\0';
							status[cmd] = strdup(ptr);
							statusDirty = -1;
							fprintf(otp, "%s\r\n", line);
							fflush(otp);
							if(cmdPosition + strlen(line) < 3072)
								cmdPosition += sprintf(logCommands + cmdPosition, "%s;", line );
						break;
					}
					break;
				}
		}

		if(line) free(line);
		fclose(fp);
	    } else {
		perror("Unable to open the update file");
	    }
	    if(statusDirty)
		writeStatus();
	    logCommandAsync(logCommands);
	    for( i = 0; i < MAX_LINES; i++)
		displayLines[i] = status[LINE1 + i];
	    len = 4;
	    while(i && !displayLines[--i]) len--;
	    bigDisplay(len, displayLines);
    }
  }

  return 0;
}