libnjb: deltr.c

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

# deltr.c

    00001 #include "common.h"
    00002
    00003 void usage (void);
    00004
    00005 int main (int argc, char **argv)
    00006 {
    00007         njb_t njbs[NJB_MAX_DEVICES], *njb;
    00008         u_int32_t id;
    00009         int n, debug, syntax, opt;
    00010         extern int optind;
    00011         extern char *optarg;
    00012         char *endptr;
    00013
    00014         debug= syntax= 0;
    00015
    00016         while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
    00017                 switch (opt) {
    00018                 case 'D':
    00019                         debug= atoi(optarg);
    00020                         break;
    00021                 default:
    00022                         usage();
    00023                 }
    00024         }
    00025         argc-= optind;
    00026         argv+= optind;
    00027
    00028         if ( argc != 1 ) usage();
    00029
    00030         id= strtoul(argv[0], &endptr, 10);
    00031         if ( endptr[0] != '\0' ) {
    00032                 fprintf(stderr, "invalid track id %s\n", argv[0]);
    00033                 return 1;
    00034         }
    00035
    00036         if ( debug ) NJB_Set_Debug(debug);
    00037
    00038         if ( NJB_Discover(njbs, 0, &n) == -1 ) {
    00039                 fprintf(stderr, "could not locate any jukeboxes\n");
    00040                 return 1;
    00041         }
    00042
    00043         if ( n == 0 ) {
    00044                 fprintf(stderr, "no NJB devices found\n");
    00045                 return 0;
    00046         }
    00047
    00048         njb= njbs;
    00049
    00050         if ( NJB_Open(njb) == -1 ) {
    00051                 NJB_Error_Dump(njb, stderr);
    00052                 return 1;
    00053         }
    00054
    00055         if ( NJB_Capture(njb) == -1 ) {
    00056                 NJB_Error_Dump(njb, stderr);
    00057                 return 1;
    00058         }
    00059
    00060         if ( NJB_Delete_Track(njb, id) == -1 ) {
    00061                 NJB_Error_Dump(njb, stderr);
    00062         }
    00063
    00064         NJB_Release(njb);
    00065
    00066         NJB_Close(njb);
    00067
    00068         return 0;
    00069 }
    00070
    00071 void usage (void)
    00072 {
    00073         fprintf(stderr, "usage: deltr [ -D debuglvl ] <trackid>\n");
    00074         exit(1);
    00075 }