Ejemplo n.º 1
0
static void
show(timezone_t tz, char *zone, time_t t, bool v)
{
	struct tm *	tmp;
	struct tm *	gmtmp;
	struct tm tm, gmtm;

	(void) printf("%-*s  ", (int) longest, zone);
	if (v) {
		gmtmp = my_gmtime_r(&t, &gmtm);
		if (gmtmp == NULL) {
			printf(tformat(), t);
		} else {
			dumptime(gmtmp);
			(void) printf(" UT");
		}
		(void) printf(" = ");
	}
	tmp = my_localtime_rz(tz, &t, &tm);
	dumptime(tmp);
	if (tmp != NULL) {
		if (*abbr(tmp) != '\0')
			(void) printf(" %s", abbr(tmp));
		if (v) {
			long off = gmtoff(tmp, NULL,  gmtmp);
			(void) printf(" isdst=%d", tmp->tm_isdst);
			if (off != LONG_MIN)
				(void) printf(" gmtoff=%ld", off);
		}
	}
	(void) printf("\n");
	if (tmp != NULL && *abbr(tmp) != '\0')
		abbrok(abbr(tmp), zone);
}
Ejemplo n.º 2
0
static void
show(char *zone, time_t t, int v)
{
	register struct tm *	tmp;

	(void) printf("%-*s  ", (int) longest, zone);
	if (v) {
		tmp = gmtime(&t);
		if (tmp == NULL) {
			(void) printf(tformat(), t);
		} else {
			dumptime(tmp);
			(void) printf(" UTC");
		}
		(void) printf(" = ");
	}
	tmp = my_localtime(&t);
	dumptime(tmp);
	if (tmp != NULL) {
		if (*abbr(tmp) != '\0')
			(void) printf(" %s", abbr(tmp));
		if (v) {
			(void) printf(" isdst=%d", tmp->tm_isdst);
#ifdef TM_GMTOFF
			(void) printf(" gmtoff=%ld", tmp->TM_GMTOFF);
#endif /* defined TM_GMTOFF */
		}
	}
	(void) printf("\n");
	if (tmp != NULL && *abbr(tmp) != '\0')
		abbrok(abbr(tmp), zone);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  njb_t njbs[NJB_MAX_DEVICES], *njb;
  extern char *optarg;
  int opt;
  int n, debug;
  njb_time_t *time;
  char *pnum;
  char num[80];
  
  debug = 0;
  while ((opt = getopt(argc, argv, "D:")) != -1) {
    switch (opt) {
    case 'D':
      debug = atoi(optarg);
      break;
    default:
      fprintf(stderr, "usage: settime [ -D debuglvl ]\n");
      return 1;
    }
  }
  
  if (debug)
    NJB_Set_Debug(debug);

  if (NJB_Discover(njbs, 0, &n) == -1) {
    fprintf(stderr, "could not locate any jukeboxes\n");
    return 1;
  } 
  
  if (n == 0) {
    fprintf(stderr, "no NJB devices found\n");
    return 0;
  }
  
  njb = njbs;
  
  if (NJB_Open(njb) == -1) {
    NJB_Error_Dump(njb,stderr);
    return 1;
  }

  if (NJB_Capture(njb) == -1) {
    NJB_Error_Dump(njb,stderr);
    return 1;
  }
  
  time = NJB_Get_Time(njb);
  
  printf("The time on the jukebox is:\n");
  dumptime(time);
  
  printf("\nNew time (old values preserved if left blank):\n");
  
  if ( (pnum= prompt("Year:", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->year= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  if ( (pnum= prompt("Month (1-12):", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->month= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  if ( (pnum= prompt("Day:", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->day= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  if ( (pnum= prompt("Weekday (0-6):", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->weekday= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  if ( (pnum= prompt("Hours (0-23):", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->hours= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  if ( (pnum= prompt("Minutes (0-59):", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->minutes= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  if ( (pnum= prompt("Seconds (0-59):", num, 80, 0)) == NULL ) return 1;
  if ( strlen(pnum) ) {
    time->seconds= (u_int16_t) strtoul(pnum, 0, 10);
  }
  
  printf("The time on the jukebox is being set to:\n");
  dumptime(time);
  
  if (NJB_Set_Time(njb, time) == -1) {
    NJB_Error_Dump(njb,stderr);
  }
  
  NJB_Destroy_Time(time);
  
  NJB_Release(njb);
  
  NJB_Close(njb);
  return 0;
}