Esempio n. 1
0
	void I2CFlexel::setTimeAndDate(const DateTime &timeAndDate)
	{
		setTimeAndDate(
			decToBcd(timeAndDate.seconds), decToBcd(timeAndDate.minutes), decToBcd(timeAndDate.hours), decToBcd(timeAndDate.weekDay),
			decToBcd(timeAndDate.day), decToBcd(timeAndDate.month), decToBcd(timeAndDate.year)
		);
	}
Esempio n. 2
0
int checkArgs(ARGUMENTS *args, int argc, char **argv) {
  int i;
  struct tm tm;
  int timeIsSet=0;
  int dateIsSet=0;

  setTimeAndDate(&tm, time(0), 0); /* store as local time */

  i=1;
  while (i<argc){
    if (strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--help")==0) {
      usage(argv[0]);
      return -1;
    }
    else if (strcmp(argv[i],"-V")==0 || strcmp(argv[i],"--version")==0) {
      fprintf(stdout,k_PRG_VERSION_INFO);
      return -1;
    }
    else if (strcmp(argv[i],"-v")==0) {
      args->verbosity++;
      if (args->flags & AQBACKUP_FLAGS_VERBOUS)
	args->flags|=AQBACKUP_FLAGS_VERY_VERBOUS;
      else
	args->flags|=AQBACKUP_FLAGS_VERBOUS;
    }
    else if (strcmp(argv[i],"-r")==0) {
      args->flags|=AQBACKUP_FLAGS_RECURSIVE;
    }
    else if (strcmp(argv[i],"--overwrite")==0) {
      args->flags|=AQBACKUP_FLAGS_OVERWRITE;
    }
    else if (strcmp(argv[i],"--ignore-errors")==0) {
      args->flags|=AQBACKUP_FLAGS_IGNORE_ERRORS;
    }
    else if (strcmp(argv[i],"--local-delete")==0) {
      args->flags|=AQBACKUP_FLAGS_LOCAL_DELETE;
    }
    else if (strcmp(argv[i],"--no-change-rights")==0) {
      args->flags|=AQBACKUP_FLAGS_DONT_CHANGE_RIGHTS;
    }
    else if (strcmp(argv[i],"--no-change-owner")==0) {
      args->flags|=AQBACKUP_FLAGS_DONT_CHANGE_OWNER;
    }
    else if (strcmp(argv[i],"--no-change-times")==0) {
      args->flags|=AQBACKUP_FLAGS_DONT_CHANGE_TIMES;
    }
    else if (strcmp(argv[i],"--deep-first")==0) {
      args->flags|=AQBACKUP_FLAGS_DEEP_FIRST;
    }
    else if (strcmp(argv[i],"--force")==0) {
      args->flags|=AQBACKUP_FLAGS_FORCE;
    }
    else if (strcmp(argv[i],"-C")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->configFile=argv[i];
    }
    else if (strcmp(argv[i],"--date")==0) {
      int year, month, day;

      i++;
      if (i>=argc)
	return 1;
      if (sscanf(argv[i], "%d/%d/%d", &year, &month, &day)!=3) {
	fprintf(stderr,I18N("Bad date string \"%s\"\n"),
		argv[i]);
	return 1;
      }
      tm.tm_year=year;
      tm.tm_mon=month;
      tm.tm_mday=day;
      dateIsSet=1;
      if (!timeIsSet) {
	tm.tm_sec=0;
	tm.tm_min=0;
	tm.tm_hour=0;
      }
    }
    else if (strcmp(argv[i],"--time")==0) {
      int hour, min, sec;

      hour=min=sec=0;
      i++;
      if (i>=argc)
	return 1;
      if (sscanf(argv[i], "%d:%d:%d", &hour, &min, &sec)<2) {
	fprintf(stderr,I18N("Bad time string \"%s\"\n"),
		argv[i]);
	return 1;
      }
      tm.tm_sec=sec;
      tm.tm_min=min;
      tm.tm_hour=hour;
      timeIsSet=1;
    }
    else if (strcmp(argv[i],"--destdir")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->destdir=argv[i];
    }
    else if (strcmp(argv[i],"--type")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->typ=argv[i];
    }
    else if (strcmp(argv[i],"--basedir")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->basedir=argv[i];
    }
    else if (strcmp(argv[i],"--user")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->user=argv[i];
    }
    else if (strcmp(argv[i],"--passwd")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->passwd=argv[i];
    }
    else if (strcmp(argv[i],"--address")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->address=argv[i];
    }
    else if (strcmp(argv[i],"--port")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->port=atoi(argv[i]);
    }
    else if (strcmp(argv[i],"--ziplevel")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->ziplevel=atoi(argv[i]);
    }
    else if (strcmp(argv[i],"--localonly")==0) {
      args->createLocalOnly=1;
    }
    else if (strcmp(argv[i],"--servercfg")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->serverConfigFile=argv[i];
    }
    else if (strcmp(argv[i],"--logfile")==0) {
      i++;
      if (i>=argc)
	return 1;
      args->logFile=argv[i];
    }
    else if (strcmp(argv[i], "--logtype")==0) {
      i++;
      if (i>=argc)
	return 1;
      if (strcmp(argv[i],"stderr")==0)
	args->logType=LoggerTypeConsole;
      else if (strcmp(argv[i],"file")==0)
	args->logType=LoggerTypeFile;
#ifdef HAVE_SYSLOG_H
      else if (strcmp(argv[i],"syslog")==0)
	args->logType=LoggerTypeSyslog;
#endif
      else {
	fprintf(stderr,I18N("Unknown log type \"%s\"\n"),
		argv[i]);
	return 1;
      }
    }
    else if (strcmp(argv[i], "--loglevel")==0) {
      i++;
      if (i>=argc)
	return 1;
      if (strcmp(argv[i], "emergency")==0)
	args->logLevel=LoggerLevelEmergency;
      else if (strcmp(argv[i], "alert")==0)
	args->logLevel=LoggerLevelAlert;
      else if (strcmp(argv[i], "critical")==0)
	args->logLevel=LoggerLevelCritical;
      else if (strcmp(argv[i], "error")==0)
	args->logLevel=LoggerLevelError;
      else if (strcmp(argv[i], "warning")==0)
	args->logLevel=LoggerLevelWarning;
      else if (strcmp(argv[i], "notice")==0)
	args->logLevel=LoggerLevelNotice;
      else if (strcmp(argv[i], "info")==0)
	args->logLevel=LoggerLevelInfo;
      else if (strcmp(argv[i], "debug")==0)
	args->logLevel=LoggerLevelDebug;
      else {
	fprintf(stderr,
		I18N("Unknown log level \"%s\"\n"),
		argv[i]);
	return 1;
      }
    }
    else if (strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0) {
      usage(argv[0]);
      return -1;
    }
    else if (strcmp(argv[i], "-V")==0 || strcmp(argv[i], "--version")==0) {
      fprintf(stdout,k_PRG_VERSION_INFO);
      return -1;
    }
    else {
      if (*argv[i]=='-') {
	fprintf(stderr,
		I18N("Unknown option \"%s\"\n"), argv[i]);
	return 1;
      }
      // otherwise add param
      Arguments_AddParam(args, argv[i]);
    }
    i++;
  } // while

  /* set time */
  if (timeIsSet || dateIsSet) {
    tm.tm_isdst=-1;
    args->timeAndDate=mktime(&tm); /* now this is UTC time */
  }
  else
    args->timeAndDate=0;

  // that's it
  return 0;
}