00001 #include "common.h"
00002
00003 int main(int argc, char **argv)
00004 {
00005 njb_t njbs[NJB_MAX_DEVICES], *njb;
00006 extern char *optarg;
00007 int opt;
00008 int n, debug;
00009 njb_time_t *time;
00010
00011 debug = 0;
00012 while ((opt = getopt(argc, argv, "D:")) != -1) {
00013 switch (opt) {
00014 case 'D':
00015 debug = atoi(optarg);
00016 break;
00017 default:
00018 fprintf(stderr, "usage: dumptime [ -D debuglvl ]\n");
00019 return 1;
00020 }
00021 }
00022
00023 if (debug)
00024 NJB_Set_Debug(debug);
00025
00026 if (NJB_Discover(njbs, 0, &n) == -1) {
00027 fprintf(stderr, "could not locate any jukeboxes\n");
00028 return 1;
00029 }
00030
00031 if (n == 0) {
00032 fprintf(stderr, "no NJB devices found\n");
00033 return 0;
00034 }
00035
00036 njb = njbs;
00037
00038 if (NJB_Open(njb) == -1) {
00039 NJB_Error_Dump(njb, stderr);
00040 return 1;
00041 }
00042
00043 if (NJB_Capture(njb) == -1) {
00044 NJB_Error_Dump(njb, stderr);
00045 return 1;
00046 }
00047
00048 time = NJB_Get_Time(njb);
00049
00050 if (time != NULL) {
00051 printf("The time on the jukebox is:\n");
00052 switch(time->weekday) {
00053 case 0:
00054 printf("Sunday ");
00055 break;
00056 case 1:
00057 printf("Monday ");
00058 break;
00059 case 2:
00060 printf("Tuesday ");
00061 break;
00062 case 3:
00063 printf("Wednesday ");
00064 break;
00065 case 4:
00066 printf("Thursday ");
00067 break;
00068 case 5:
00069 printf("Friday ");
00070 break;
00071 case 6:
00072 printf("Saturday ");
00073 }
00074
00075
00076
00077
00078 printf("%u-%.2u-%.2u ", time->year,
00079 time->month, time->day);
00080 printf("%.2u:%.2u:%.2u\n", time->hours,
00081 time->minutes, time->seconds);
00082 NJB_Destroy_Time(time);
00083 }
00084
00085 if (NJB_Error_Pending(njb)) {
00086 NJB_Error_Dump(njb, stderr);
00087 }
00088
00089 NJB_Release(njb);
00090
00091 NJB_Close(njb);
00092 return 0;
00093 }