libnjb 2.2.7

dumptime.c
#include "common.h"
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;
debug = 0;
while ((opt = getopt(argc, argv, "D:")) != -1) {
switch (opt) {
case 'D':
debug = atoi(optarg);
break;
default:
fprintf(stderr, "usage: dumptime [ -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);
if (time != NULL) {
printf("The time on the jukebox is:\n");
switch(time->weekday) {
case 0:
printf("Sunday ");
break;
case 1:
printf("Monday ");
break;
case 2:
printf("Tuesday ");
break;
case 3:
printf("Wednesday ");
break;
case 4:
printf("Thursday ");
break;
case 5:
printf("Friday ");
break;
case 6:
printf("Saturday ");
}
/* OK this is the way we write dates
* in Sweden, you may change it if you
* don't like it!
*/
printf("%u-%.2u-%.2u ", time->year,
time->month, time->day);
printf("%.2u:%.2u:%.2u\n", time->hours,
time->minutes, time->seconds);
NJB_Destroy_Time(time);
}
if (NJB_Error_Pending(njb)) {
NJB_Error_Dump(njb, stderr);
}
NJB_Release(njb);
NJB_Close(njb);
return 0;
}
NJB_Capture
int NJB_Capture(njb_t *njb)
Definition procedure.c:223
NJB_Close
void NJB_Close(njb_t *njb)
Definition procedure.c:184
NJB_Discover
int NJB_Discover(njb_t *njbs, int limit, int *n)
Definition procedure.c:108
NJB_Release
int NJB_Release(njb_t *njb)
Definition procedure.c:266
NJB_Open
int NJB_Open(njb_t *njb)
Definition procedure.c:130
NJB_Error_Pending
int NJB_Error_Pending(njb_t *njb)
Definition njb_error.c:303
NJB_Set_Debug
void NJB_Set_Debug(int debug_flags)
Definition procedure.c:2819
NJB_Error_Dump
void NJB_Error_Dump(njb_t *njb, FILE *fp)
Definition njb_error.c:418
NJB_Get_Time
njb_time_t * NJB_Get_Time(njb_t *njb)
Definition procedure.c:2079
NJB_Destroy_Time
void NJB_Destroy_Time(njb_time_t *time)
Definition procedure.c:2152
njb_t
struct njb_struct njb_t
Definition libnjb.h:168
njb_time_t
struct njb_time_struct njb_time_t
Definition libnjb.h:175
NJB_MAX_DEVICES
#define NJB_MAX_DEVICES
Definition libnjb.h:60
njb_time_struct::weekday
int16_t weekday
Definition libnjb.h:407
njb_time_struct::hours
int16_t hours
Definition libnjb.h:408
njb_time_struct::minutes
int16_t minutes
Definition libnjb.h:409
njb_time_struct::seconds
int16_t seconds
Definition libnjb.h:410
njb_time_struct::year
int16_t year
Definition libnjb.h:404
njb_time_struct::month
int16_t month
Definition libnjb.h:405
njb_time_struct::day
int16_t day
Definition libnjb.h:406