00001 #include "common.h"
00002 #include <string.h>
00003
00004 static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
00005 {
00006 char *cp, *bp;
00007
00008 while (1) {
00009 fprintf(stdout, "%s> ", prompt);
00010 if ( fgets(buffer, bufsz, stdin) == NULL ) {
00011 if (ferror(stdin)) {
00012 perror("fgets");
00013 } else {
00014 fprintf(stderr, "EOF on stdin\n");
00015 }
00016 return NULL;
00017 }
00018
00019 cp = strrchr(buffer, '\n');
00020 if ( cp != NULL ) *cp= '\0';
00021
00022 bp = buffer;
00023 while ( bp != cp ) {
00024 if ( *bp != ' ' ) return bp;
00025 bp++;
00026 }
00027
00028 if (! required) return bp;
00029 }
00030 }
00031
00032 int main (int argc, char **argv)
00033 {
00034 njb_t njbs[NJB_MAX_DEVICES], *njb;
00035 int n, opt, debug;
00036 char newowner[80];
00037 char *pown;
00038 char *ownerstring;
00039 extern char *optarg;
00040 char *lang;
00041
00042 debug = 0;
00043 while ( (opt = getopt(argc, argv, "D:")) != -1 ) {
00044 switch (opt) {
00045 case 'D':
00046 debug= atoi(optarg);
00047 break;
00048 default:
00049 fprintf(stderr, "usage: %s [ -D debuglvl ]\n", argv[0]);
00050 return 1;
00051 }
00052 }
00053
00054 if ( debug ) NJB_Set_Debug(debug);
00055
00056
00057
00058
00059
00060
00061
00062 lang = getenv("LANG");
00063 if (lang != NULL) {
00064 if (strlen(lang) > 5) {
00065 if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
00066 NJB_Set_Unicode(NJB_UC_UTF8);
00067 }
00068 }
00069 }
00070
00071 if (NJB_Discover(njbs, 0, &n) == -1) {
00072 fprintf(stderr, "could not locate any jukeboxes\n");
00073 return 1;
00074 }
00075
00076 if ( n == 0 ) {
00077 fprintf(stderr, "No NJB devices found\n");
00078 return 1;
00079 }
00080
00081 njb = njbs;
00082 if ( NJB_Open(njb) == -1 ) {
00083 NJB_Error_Dump(njb,stderr);
00084 return 1;
00085 }
00086
00087 if ( (pown = prompt("New ownerstring", newowner, 80, 1)) == NULL ) return 1;
00088 if ( NJB_Set_Owner_String (njb, newowner) == -1 ) {
00089 NJB_Error_Dump(njb,stderr);
00090 return 1;
00091 }
00092
00093 ownerstring = NJB_Get_Owner_String(njb);
00094 printf("New owner string: %s\n", ownerstring);
00095 free(ownerstring);
00096
00097 NJB_Close(njb);
00098 return 0;
00099 }