libnjb: getowner.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# getowner.c

    00001 #include "common.h"
    00002 #include <string.h>
    00003
    00004 int main (int argc, char **argv)
    00005 {
    00006         njb_t njbs[NJB_MAX_DEVICES], *njb;
    00007         int n, opt, debug;
    00008         char *ownerstring;
    00009         extern char *optarg;
    00010         char *lang;
    00011
    00012         debug= 0;
    00013         while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
    00014                 switch (opt) {
    00015                 case 'D':
    00016                         debug= atoi(optarg);
    00017                         break;
    00018                 default:
    00019                         fprintf(stderr, "usage: getowner [ -D debuglvl ]\n");
    00020                         return 1;
    00021                 }
    00022         }
    00023
    00024         if ( debug ) NJB_Set_Debug(debug);
    00025
    00026         /*
    00027          * Check environment variables $LANG and $LC_CTYPE
    00028          * to see if we want to support UTF-8 unicode
    00029          * $LANG = "xx_XX.UTF-8" or $LC_CTYPE = "?"
    00030          * trigger unicode support.
    00031          */
    00032         lang = getenv("LANG");
    00033         if (lang != NULL) {
    00034           if (strlen(lang) > 5) {
    00035             if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
    00036                NJB_Set_Unicode(NJB_UC_UTF8);
    00037             }
    00038           }
    00039         }
    00040
    00041         if (NJB_Discover(njbs, 0, &n) == -1) {
    00042           fprintf(stderr, "could not locate any jukeboxes\n");
    00043           return 1;
    00044         }
    00045
    00046         if ( n == 0 ) {
    00047                 fprintf(stderr, "No NJB devices found\n");
    00048                 return 1;
    00049         }
    00050
    00051         njb = njbs;
    00052         if ( NJB_Open(njb) == -1 ) {
    00053                 NJB_Error_Dump(njb, stderr);
    00054                 return 1;
    00055         }
    00056
    00057         ownerstring = NJB_Get_Owner_String (njb);
    00058         if (ownerstring != NULL) {
    00059           printf("Owner string: %s\n", ownerstring);
    00060           free(ownerstring);
    00061         } else {
    00062           fprintf(stderr, "could not retrieve owner string\n");
    00063           NJB_Error_Dump(njb, stderr);
    00064         }
    00065
    00066         NJB_Close(njb);
    00067         return 0;
    00068 }
    00069