#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>

#include "common.h"		/* common module */
#include "cmdline.h"		/* command line module */

#define PROGVER "auinfo V0.1.1 22-Nov-2001"
#ifndef DISTVER		/* set in Makefile */
#define DISTVER "<unknown>"
#endif

static char *progName = "<no program name>";
static int  level;
static int  levelUsed;
static int *varArgIdx;

static CmdLinePara paraList[] = {
  {&varArgIdx,NULL,""},
  {NULL,NULL,NULL}
};
static CmdLineSwitch switchList[] = {
  {"h",NULL,NULL,NULL,NULL,"print help"},
  {"d",&level,"%d",NULL,&levelUsed,
   "info level (dflt: 1)"},
  {NULL,NULL,NULL,NULL,NULL,NULL}
};

int main(int argc, char *argv[]) {
  WAVEOUTCAPS waveOutDevCaps;
  /* The WAVEOUTCAPS structure describes
     the capabilities of a waveform-audio
     output device:
   
     typedef struct {
     unsigned short int   wMid;
     unsigned short int   wPid; 
     unsigned int	  vDriverVersion;
     char		  szPname[MAXPNAMELEN]; 
     unsigned int         dwFormats;     
     unsigned short int   wChannels;
     unsigned short int   wReserved1; 
     unsigned int         dwSupport; 
     } WAVEOUTCAPS;  */
 
  WAVEINCAPS waveInDevCaps;
  /* The WAVEINCAPS structure describes 
     the capabilities of a waveform-audio 
     input device:

     typedef struct { 
     WORD      wMid; 
     WORD      wPid; 
     MMVERSION vDriverVersion; 
     CHAR      szPname[MAXPNAMELEN]; 
     DWORD     dwFormats; 
     WORD      wChannels; 
     WORD      wReserved1; 
     }  WAVEINCAPS; */
  int result;
  int i, nDevice;

  /* evaluate command line  */
  CmdLineInit(0);
  result = CmdLineEval(argc,argv,paraList,switchList,1,&progName);
  if (result) {
    if (result==1) {
      fprintf(stderr,"%s: %s\n",progName,PROGVER "   " DISTVER);
      CmdLineHelp(progName,paraList,switchList,stderr);
      exit (1);
    }
    else
      CommonExit(1,"command line error (\"-h\" for help)");
  } 

  fprintf(stderr,"%s: %s\n",progName,PROGVER "   " DISTVER);
 
  /* list input devices */
  fprintf(stdout,"\nAudio input device IDs are:\n\n ID\tName\t\t\tVersion\n");
  nDevice = waveInGetNumDevs();
  for(i=-1 ; i<nDevice; ++i) {
    waveInGetDevCaps( i, &(waveInDevCaps), sizeof(waveInDevCaps));
    fprintf(stdout," %d\t%s\t%d.%d\n", i, waveInDevCaps.szPname,
            HIBYTE(waveInDevCaps.vDriverVersion),
            LOBYTE(waveInDevCaps.vDriverVersion)); 
  }


  /* list output devices */
  fprintf(stdout,"\nAudio output device IDs are:\n\n ID\tName\t\t\tVersion\n");
  nDevice = waveOutGetNumDevs();
  for(i=-1 ; i<nDevice; ++i) {
    waveOutGetDevCaps( i, &(waveOutDevCaps), sizeof(waveOutDevCaps));
    fprintf(stdout," %d\t%s\t%d.%d\n", i, waveOutDevCaps.szPname,
            HIBYTE(waveOutDevCaps.vDriverVersion),
            LOBYTE(waveOutDevCaps.vDriverVersion)); 
  }
  fprintf(stdout,"\n");    
}
