├── ChangeLog ├── doc ├── Makefile.am └── adplay.1 ├── adplay.spec ├── Makefile.am ├── TODO ├── adplug.desktop ├── .gitignore ├── AUTHORS ├── src ├── Makefile.am ├── null.h ├── esound.h ├── ao.h ├── diskraw.h ├── qsa.h ├── disk.h ├── oss.h ├── alsa.h ├── defines.h ├── sdl_driver.h ├── esound.cc ├── oss.cc ├── output.h ├── ao.cc ├── output.cc ├── players.h ├── sdl.cc ├── disk.cc ├── qsa.cc ├── alsa.cc ├── getopt1.c ├── getopt.h ├── adplay.cc └── getopt.c ├── RELEASE ├── README ├── NEWS ├── m4 ├── ao.m4 ├── alsa.m4 ├── sdl.m4 ├── esd.m4 ├── sdl2.m4 └── pkg.m4 ├── adplay.qpg ├── configure.ac └── COPYING /ChangeLog: -------------------------------------------------------------------------------- 1 | See https://github.com/adplug/adplay-unix/commits/master 2 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | man_MANS = adplay.1 2 | 3 | EXTRA_DIST = $(man_MANS) 4 | -------------------------------------------------------------------------------- /adplay.spec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adplug/adplay-unix/HEAD/adplay.spec -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src doc 2 | 3 | EXTRA_DIST = adplay.spec adplay.qpg 4 | 5 | AUTOMAKE_OPTIONS = dist-bzip2 6 | 7 | ACLOCAL_AMFLAGS=-I m4 8 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | AdPlay/UNIX To Do List: 2 | ----------------------- 3 | - Remove warning about Ken's synth not working in surround mode once it has 4 | been fixed in AdPlug. 5 | -------------------------------------------------------------------------------- /adplug.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=adplug 3 | Comment=adlib sound player 4 | Exec=adplug %f 5 | Icon=adplug 6 | Terminal=true 7 | Type=Application 8 | Categories=AudioVideo;AudioVideoEditing 9 | Keywords=music;playing; 10 | MimeTypes=audio/a2m;audio/adl;audio/amd;audio/cff;audio/cmf;audio/d00;audio/dtm;audio/hsc;audio/hsp;audio/laa;audio/lds;audio/rad;audio/raw;audio/sa2;audio/sng;audio/xad;audio/xms;audio/xsm; 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | aclocal.m4 2 | config.cache 3 | config.guess 4 | config.log 5 | config.status 6 | config.sub 7 | configure 8 | depcomp 9 | install-sh 10 | Makefile 11 | Makefile.in 12 | missing 13 | mkinstalldirs 14 | INSTALL 15 | autom4te.cache 16 | libtool 17 | ltmain.sh 18 | *.o 19 | stamp-h1 20 | .deps 21 | compile 22 | m4/libtool.m4 23 | m4/ltoptions.m4 24 | m4/ltsugar.m4 25 | m4/ltversion.m4 26 | m4/lt~obsolete.m4 27 | src/adplay 28 | src/config.h* 29 | src/.libs/ 30 | *.exe 31 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Main Development: 2 | ----------------- 3 | Simon Peter 4 | 5 | Additional Credits: 6 | ------------------- 7 | Goetz Waschk : 8 | - Mandrake Linux packages 9 | - Red Hat RPM spec file 10 | 11 | Mike Gorchak : 12 | - QNX Sound Architecture (QSA) output driver 13 | - Simple Directmedia Layer (SDL) output driver 14 | - QNX packages 15 | - QNX qpg file 16 | 17 | Michael Guntsche : 18 | - libao output driver 19 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = adplay 2 | 3 | adplay_SOURCES = adplay.cc output.cc output.h players.h defines.h 4 | 5 | EXTRA_adplay_SOURCES = oss.cc oss.h null.h disk.cc disk.h esound.cc esound.h \ 6 | qsa.cc qsa.h sdl.cc sdl_driver.h alsa.cc alsa.h ao.cc ao.h getopt.c \ 7 | getopt1.c getopt.h diskraw.h 8 | 9 | adplay_LDADD = $(drivers) $(adplug_LIBS) @ESD_LIBS@ @QSA_LIBS@ @SDL_LIBS@ \ 10 | @ALSA_LIBS@ @AO_LIBS@ $(GETOPT_SOURCES) 11 | adplay_DEPENDENCIES = $(drivers) $(GETOPT_SOURCES) 12 | 13 | adplug_data_dir = $(sharedstatedir)/adplug 14 | 15 | AM_CPPFLAGS = $(adplug_CFLAGS) @ESD_CFLAGS@ @SDL_CFLAGS@ @ALSA_CFLAGS@ \ 16 | -DADPLUG_DATA_DIR=\"$(adplug_data_dir)\" 17 | -------------------------------------------------------------------------------- /RELEASE: -------------------------------------------------------------------------------- 1 | Release procedure 2 | ----------------- 3 | 4 | Before release: 5 | 6 | * Ensure version numbers are correct in configure.ac, adplay.qpg, doc/adplay.1. 7 | They should already be set to the version number of the next release, but 8 | may need altering e.g. if an unplanned bugfix release is made. 9 | 10 | * Update file list in adplug.qpg 11 | 12 | * Update NEWS with changes since last release 13 | 14 | * Create new tag: `git tag v1.2.3` and `git push origin v1.2.3` 15 | 16 | * Run 'make dist' to create tarballs and upload to github 17 | 18 | After release: 19 | 20 | * Update version numbers as above to match the "next" release. This means the 21 | git code will always compile as the version number of the next release. 22 | -------------------------------------------------------------------------------- /src/null.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_NULL 21 | #define H_NULL 22 | 23 | #include 24 | #include "output.h" 25 | 26 | class NullOutput: public Player 27 | { 28 | public: 29 | virtual void frame() 30 | { } 31 | 32 | virtual Copl *get_opl() 33 | { return &opl; } 34 | 35 | private: 36 | CSilentopl opl; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/esound.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_ESOUND 21 | #define H_ESOUND 22 | 23 | #include "output.h" 24 | 25 | class EsoundPlayer: public EmuPlayer 26 | { 27 | public: 28 | EsoundPlayer(Copl *nopl, unsigned char bits, int channels, int freq, 29 | const char *url = 0); 30 | virtual ~EsoundPlayer(); 31 | 32 | protected: 33 | virtual void output(const void *buf, unsigned long size); 34 | 35 | private: 36 | int socket; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/ao.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003, 2024 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_AO_ 21 | #define H_AO_ 22 | 23 | #include 24 | 25 | #include "output.h" 26 | 27 | class AOPlayer: public EmuPlayer 28 | { 29 | public: 30 | AOPlayer(Copl *nopl, const char *device, unsigned char bits, int channels, 31 | int freq, unsigned long bufsize); 32 | virtual ~AOPlayer(); 33 | 34 | protected: 35 | virtual void output(const void *buf, unsigned long size); 36 | 37 | private: 38 | ao_device *aodevice; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/diskraw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_DISKRAW 21 | #define H_DISKRAW 22 | 23 | #include "output.h" 24 | 25 | /* pairs up to AdPlay CDiskopl */ 26 | class DiskRawWriter: public Player 27 | { 28 | public: 29 | DiskRawWriter(CDiskopl *nopl) 30 | :opl(nopl) 31 | { } 32 | 33 | virtual void frame() { 34 | playing = p->update(); 35 | opl->update(p); 36 | } 37 | 38 | virtual Copl *get_opl() 39 | { return opl; } 40 | 41 | private: 42 | CDiskopl *opl; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/qsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_QSA 21 | #define H_QSA 22 | 23 | #include "output.h" 24 | 25 | #include 26 | 27 | #define QSA_FRAG_SIZE 4096 28 | 29 | class QSAPlayer: public EmuPlayer 30 | { 31 | public: 32 | QSAPlayer(unsigned char bits, int channels, int freq); 33 | virtual ~QSAPlayer(); 34 | 35 | protected: 36 | virtual void output(const void *buf, unsigned long size); 37 | 38 | private: 39 | snd_pcm_t* audio_handle; // audio device handle 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/disk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_DISK 21 | #define H_DISK 22 | 23 | #include 24 | 25 | #include "output.h" 26 | 27 | class DiskWriter: public EmuPlayer 28 | { 29 | public: 30 | DiskWriter(Copl *nopl, const char *filename, unsigned char nbits, 31 | unsigned char nchannels, unsigned long nfreq); 32 | virtual ~DiskWriter(); 33 | 34 | protected: 35 | virtual void output(const void *buf, unsigned long size); 36 | 37 | private: 38 | binostream *f; 39 | unsigned long samplesize; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/oss.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_OSS 21 | #define H_OSS 22 | 23 | #include "output.h" 24 | 25 | class OSSPlayer: public EmuPlayer 26 | { 27 | public: 28 | OSSPlayer(Copl *nopl, const char *device, unsigned char bits, int channels, 29 | int freq, unsigned long bufsize); 30 | virtual ~OSSPlayer(); 31 | 32 | protected: 33 | virtual void output(const void *buf, unsigned long size); 34 | 35 | private: 36 | int audio_fd; // audio device file 37 | unsigned long size; // audio buffer size in bytes 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/alsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_ALSA 21 | #define H_ALSA 22 | 23 | #define ALSA_PCM_NEW_HW_PARAMS_API 24 | 25 | #include 26 | 27 | #include "output.h" 28 | 29 | class ALSAPlayer: public EmuPlayer 30 | { 31 | public: 32 | ALSAPlayer(Copl *nopl, const char *device, unsigned char bits, int channels, 33 | int freq, unsigned long bufsize); 34 | virtual ~ALSAPlayer(); 35 | 36 | protected: 37 | virtual void output(const void *buf, unsigned long size); 38 | 39 | private: 40 | snd_pcm_t *pcm_handle; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_DEFINES 21 | #define H_DEFINES 22 | 23 | #include "config.h" 24 | 25 | /***** Defines *****/ 26 | 27 | // AdPlay/UNIX version string 28 | #define ADPLAY_VERSION "AdPlay/UNIX " VERSION 29 | 30 | // Message urgency levels 31 | #define MSG_PANIC 0 // Unmaskable 32 | #define MSG_ERROR 1 33 | #define MSG_WARN 2 34 | #define MSG_NOTE 3 35 | #define MSG_DEBUG 4 36 | 37 | #ifndef MIN 38 | # define MIN(a,b) (((a) < (b)) ? (a) : (b)) 39 | #endif 40 | #ifndef MAX 41 | # define MAX(a,b) (((a) > (b)) ? (a) : (b)) 42 | #endif 43 | 44 | /***** Global functions *****/ 45 | 46 | void message(int level, const char *fmt, ...); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/sdl_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_SDL 21 | #define H_SDL 22 | 23 | #define SDL_MAIN_HANDLED 1 24 | 25 | #include 26 | 27 | #include "output.h" 28 | 29 | class SDLPlayer: public Player 30 | { 31 | private: 32 | Copl *opl; 33 | SDL_AudioSpec spec; 34 | 35 | static void callback(void *, Uint8 *, int); 36 | unsigned char getsampsize() 37 | { return spec.channels * (spec.format == AUDIO_U8 ? 1 : 2); } 38 | 39 | public: 40 | SDLPlayer(Copl *nopl, unsigned char bits, int channels, int freq, 41 | unsigned long bufsize); 42 | virtual ~SDLPlayer(); 43 | 44 | virtual void frame(); 45 | virtual Copl *get_opl() { return opl; } 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | AdPlay/UNIX - UNIX console-based OPL2 audio player 2 | Copyright (C) 2001 - 2025 Simon Peter 3 | 4 | Description 5 | ----------- 6 | AdPlay/UNIX is AdPlug's UNIX console-based frontend. AdPlug is a free, 7 | universal OPL2 audio playback library. AdPlay/UNIX supports the full range 8 | of AdPlug's file format playback features. Despite this, at the moment, only 9 | emulated OPL2 output is supported by AdPlay/UNIX, but this on a wide range 10 | of output devices. 11 | 12 | Prerequisites 13 | ------------- 14 | The following libraries are needed in order to compile this program: 15 | 16 | Library Version 17 | ------- ------- 18 | AdPlug >= 1.4, or >= 2.2 for full feature support 19 | 20 | git 21 | --- 22 | If you checked out from git, first run: 23 | 24 | autoreconf --install 25 | 26 | to generate the build cruft and get the configure script. You need recent 27 | versions of autoconf, automake and libtool to do this. If autoreconf fails 28 | for any reason or you are hacking on the build system, you can run each step 29 | manually instead of using autoreconf: 30 | 31 | libtoolize -c -f --install 32 | aclocal -I m4 33 | autoheader 34 | automake -a -c 35 | autoconf 36 | 37 | Usage 38 | ----- 39 | Start AdPlay/UNIX with at least one file to be played as parameter. 40 | Additional commandline parameters are explained by typing: 41 | 42 | adplay --help 43 | 44 | Or by reading the man page. A more detailed doc will follow when i get the 45 | time to write one. Any help is greatly appreciated! 46 | 47 | - Simon Peter 48 | -------------------------------------------------------------------------------- /src/esound.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "defines.h" 25 | #include "esound.h" 26 | 27 | EsoundPlayer::EsoundPlayer(Copl *nopl, unsigned char bits, int channels, 28 | int freq, const char *url) 29 | : EmuPlayer(nopl, bits, channels, freq, ESD_BUF_SIZE) 30 | { 31 | socket = esd_play_stream((bits == 16 ? ESD_BITS16 : ESD_BITS8) | 32 | (channels == 2 ? ESD_STEREO : ESD_MONO) | 33 | ESD_STREAM | ESD_PLAY, freq, url, ADPLAY_VERSION); 34 | 35 | // on error, just exit here. esd_play_stream() does perror() already... 36 | if(socket < 0) exit(EXIT_FAILURE); 37 | } 38 | 39 | EsoundPlayer::~EsoundPlayer() 40 | { 41 | close(socket); 42 | } 43 | 44 | void EsoundPlayer::output(const void *buf, unsigned long size) 45 | { 46 | write(socket, buf, size); 47 | } 48 | -------------------------------------------------------------------------------- /src/oss.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "oss.h" 29 | 30 | #define DEFAULT_DEVICE "/dev/dsp" // Default output device file 31 | 32 | OSSPlayer::OSSPlayer(Copl *nopl, const char *device, unsigned char bits, 33 | int channels, int freq, unsigned long bufsize) 34 | : EmuPlayer(nopl, bits, channels, freq, bufsize) 35 | { 36 | int format = (bits == 16 ? AFMT_S16_LE : AFMT_S8); 37 | 38 | // Set to default if no device given 39 | if(!device) device = DEFAULT_DEVICE; 40 | 41 | // open OSS audio device 42 | if((audio_fd = open(device, O_WRONLY, 0)) == -1) { 43 | perror(device); 44 | exit(EXIT_FAILURE); 45 | } 46 | 47 | ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format); 48 | ioctl(audio_fd, SOUND_PCM_WRITE_CHANNELS, &channels); 49 | ioctl(audio_fd, SNDCTL_DSP_SPEED, &freq); 50 | } 51 | 52 | OSSPlayer::~OSSPlayer() 53 | { 54 | close(audio_fd); 55 | } 56 | 57 | void OSSPlayer::output(const void *buf, unsigned long size) 58 | { 59 | write(audio_fd, buf, size); 60 | } 61 | -------------------------------------------------------------------------------- /src/output.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef H_OUTPUT 21 | #define H_OUTPUT 22 | 23 | #include 24 | 25 | class Player 26 | { 27 | public: 28 | CPlayer *p; 29 | bool playing; 30 | 31 | Player(); 32 | virtual ~Player(); 33 | 34 | virtual void frame() = 0; 35 | virtual Copl *get_opl() = 0; 36 | virtual void reset() {}; 37 | }; 38 | 39 | class EmuPlayer: public Player 40 | { 41 | private: 42 | Copl *opl; 43 | char *audiobuf; 44 | unsigned long buf_size, freq; 45 | unsigned char bits, channels; 46 | 47 | public: 48 | EmuPlayer(Copl *nopl, unsigned char nbits, unsigned char nchannels, 49 | unsigned long nfreq, unsigned long nbufsize); 50 | virtual ~EmuPlayer(); 51 | 52 | virtual void setbufsize(unsigned long nbufsize); 53 | virtual void frame(); 54 | virtual Copl *get_opl() { return opl; } 55 | virtual void reset(); 56 | 57 | protected: 58 | virtual void output(const void *buf, unsigned long size) = 0; 59 | // The output buffer is always of the size requested through the constructor. 60 | // This time, size is measured in bytes, not samples! 61 | 62 | unsigned char getsampsize() { return (channels * (bits / 8)); } 63 | 64 | private: 65 | static long minicnt; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | This is a brief overview of user-visible changes in adplay. 2 | 3 | Changes for version 1.10: 4 | ------------------------- 5 | - None yet 6 | 7 | Changes for version 1.9: 8 | ------------------------ 9 | - Tie in with AdPlug 2.4 10 | - SDL2 compilation support 11 | - Fix a subsong playback corner case 12 | - RAW file writer 13 | 14 | Changes for version 1.8.1: 15 | -------------------------- 16 | - Tie in with AdPlug 2.3.2 17 | - Add surround effect support for NukedOPL 18 | 19 | Changes for version 1.8: 20 | ------------------------ 21 | - Tie in with AdPlug 2.3 release 22 | - Support for NukedOPL emulator 23 | - Various bug fixes 24 | 25 | Changes for version 1.7: 26 | ------------------------ 27 | - Changed default subsong to default subsong of file. 28 | - ALSA playback works better with recent ALSA releases 29 | - Surround/harmonic synth is now default (use --mono for old behaviour) 30 | 31 | Changes for version 1.6: 32 | ------------------------ 33 | - Added the following output mechanisms: 34 | - libao: libao driver 35 | 36 | Changes for version 1.5: 37 | ------------------------ 38 | - Made compatible with AdPlug 2.0. 39 | 40 | Changes for version 1.4: 41 | ------------------------ 42 | - Added the following output mechanisms: 43 | - alsa: Advanced Linux Sound Architecture (ALSA) driver 44 | 45 | Changes for version 1.3: 46 | ------------------------ 47 | - Disk writer now writes proper files on big endian machines. 48 | - AdPlug Database support. 49 | - Added verbosity level options. 50 | - Added the following output mechanisms: 51 | - esound: EsounD (ESD) driver 52 | - qsa: QNX Sound Architecture (QSA) driver 53 | - sdl: Simple Directmedia Layer (SDL) driver 54 | 55 | Changes for version 1.2: 56 | ------------------------ 57 | - Updated man page. 58 | - Many build fixes. 59 | - Modularized output system. 60 | - Added the following output mechanisms: 61 | - oss: Open Sound System (OSS) driver 62 | - null: Null (silent) output 63 | - disk: Disk writer 64 | 65 | Changes for version 1.1: 66 | ------------------------ 67 | - Rewrote using GNU autotools. 68 | - Wrote man page. 69 | - FreeBSD fixes. 70 | -------------------------------------------------------------------------------- /src/ao.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003, 2024 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "ao.h" 29 | 30 | AOPlayer::AOPlayer(Copl *nopl, const char *device, unsigned char bits, 31 | int channels, int freq, unsigned long bufsize) 32 | : EmuPlayer(nopl, bits, channels, freq, bufsize) 33 | { 34 | ao_sample_format format = {0}; 35 | int default_driver; 36 | 37 | ao_initialize(); 38 | 39 | default_driver = ao_default_driver_id(); 40 | 41 | format.bits = bits; 42 | format.channels = channels; 43 | format.rate = freq; 44 | format.byte_format = AO_FMT_NATIVE; 45 | 46 | aodevice = ao_open_live(default_driver, &format, NULL); 47 | } 48 | 49 | AOPlayer::~AOPlayer() 50 | { 51 | // We're skipping this here, even though we should call ao_close() 52 | // on exit. Unfortunately, the pulseaudio backend in ao has a race 53 | // condition where it fails if we call ao_close() while ao_play() is 54 | // running. This happens easily due to adplay's use of SIGINT to 55 | // exit and ao uses multiple threads for playback. 56 | 57 | // if(aodevice != NULL) { 58 | // ao_close(aodevice); 59 | // } 60 | 61 | // ao_shutdown(); 62 | } 63 | 64 | void AOPlayer::output(const void *buf, unsigned long size) 65 | { 66 | ao_play(aodevice, (char *)buf, (uint_32)size); 67 | } 68 | -------------------------------------------------------------------------------- /src/output.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "output.h" 25 | #include "defines.h" 26 | 27 | /***** Player *****/ 28 | 29 | Player::Player() 30 | : p(0), playing(false) 31 | { 32 | } 33 | 34 | Player::~Player() 35 | { 36 | if(p) delete p; 37 | } 38 | 39 | /***** EmuPlayer *****/ 40 | 41 | long EmuPlayer::minicnt = 0; 42 | 43 | EmuPlayer::EmuPlayer(Copl *nopl, unsigned char nbits, unsigned char nchannels, 44 | unsigned long nfreq, unsigned long nbufsize) 45 | : opl(nopl), buf_size(nbufsize), freq(nfreq), bits(nbits), channels(nchannels) 46 | { 47 | audiobuf = new char [buf_size * getsampsize()]; 48 | } 49 | 50 | EmuPlayer::~EmuPlayer() 51 | { 52 | delete [] audiobuf; 53 | } 54 | 55 | // Some output plugins (ALSA) need to change the buffer size mid-init 56 | void EmuPlayer::setbufsize(unsigned long nbufsize) 57 | { 58 | delete [] audiobuf; 59 | buf_size = nbufsize; 60 | audiobuf = new char [buf_size * getsampsize()]; 61 | } 62 | 63 | void EmuPlayer::frame() 64 | { 65 | long i, towrite = buf_size; 66 | char *pos = audiobuf; 67 | 68 | // Prepare audiobuf with emulator output 69 | while(towrite > 0) { 70 | while(minicnt < 0) { 71 | minicnt += freq; 72 | playing = p->update(); 73 | } 74 | i = MIN(towrite, (long)(minicnt / p->getrefresh() + 4) & ~3); 75 | opl->update((short *)pos, i); 76 | pos += i * getsampsize(); towrite -= i; 77 | i = (long)(p->getrefresh() * i); 78 | minicnt -= MAX(1, i); 79 | } 80 | 81 | // call output driver 82 | output(audiobuf, buf_size * getsampsize()); 83 | } 84 | 85 | void EmuPlayer::reset() 86 | { 87 | minicnt = 0; 88 | } 89 | -------------------------------------------------------------------------------- /src/players.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2006 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | /* 21 | * players.h - This header conditionally includes AdPlay's output drivers 22 | * and sets a reasonable default. 23 | */ 24 | 25 | #ifndef H_PLAYERS 26 | #define H_PLAYERS 27 | 28 | #include "config.h" 29 | 30 | // Enumerate ALL outputs (regardless of availability) 31 | enum Outputs {none, null, ao, oss, disk, esound, qsa, sdl, alsa, raw}; 32 | 33 | #define DEFAULT_DRIVER none 34 | 35 | // Null (silent) output 36 | #ifdef DRIVER_NULL 37 | #include "null.h" 38 | #undef DEFAULT_DRIVER 39 | #define DEFAULT_DRIVER null 40 | #endif 41 | 42 | // RAW driver 43 | #ifdef DRIVER_RAW 44 | #include "diskraw.h" 45 | #undef DEFAULT_DRIVER 46 | #define DEFAULT_DRIVER raw 47 | #endif 48 | 49 | // Disk writer 50 | #ifdef DRIVER_DISK 51 | #include "disk.h" 52 | #undef DEFAULT_DRIVER 53 | #define DEFAULT_DRIVER disk 54 | #endif 55 | 56 | // EsounD driver 57 | #ifdef DRIVER_ESOUND 58 | #include "esound.h" 59 | #undef DEFAULT_DRIVER 60 | #define DEFAULT_DRIVER esound 61 | #endif 62 | 63 | // SDL driver 64 | #ifdef DRIVER_SDL 65 | #include "sdl_driver.h" 66 | #undef DEFAULT_DRIVER 67 | #define DEFAULT_DRIVER sdl 68 | #endif 69 | 70 | // AO driver 71 | #ifdef DRIVER_AO 72 | #include "ao.h" 73 | #undef DEFAULT_DRIVER 74 | #define DEFAULT_DRIVER ao 75 | #endif 76 | 77 | // OSS driver 78 | #ifdef DRIVER_OSS 79 | #include "oss.h" 80 | #undef DEFAULT_DRIVER 81 | #define DEFAULT_DRIVER oss 82 | #endif 83 | 84 | // ALSA driver 85 | #ifdef DRIVER_ALSA 86 | #include "alsa.h" 87 | #undef DEFAULT_DRIVER 88 | #define DEFAULT_DRIVER alsa 89 | #endif 90 | 91 | // QSA driver 92 | #ifdef DRIVER_QSA 93 | #include "qsa.h" 94 | #undef DEFAULT_DRIVER 95 | #define DEFAULT_DRIVER qsa 96 | #endif 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/sdl.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "sdl_driver.h" 25 | #include "defines.h" 26 | 27 | SDLPlayer::SDLPlayer(Copl *nopl, unsigned char bits, int channels, int freq, 28 | unsigned long bufsize) 29 | : opl(nopl) 30 | { 31 | memset(&spec, 0x00, sizeof(SDL_AudioSpec)); 32 | 33 | if(SDL_Init(SDL_INIT_AUDIO) < 0) { 34 | message(MSG_ERROR, "unable to initialize SDL -- %s", SDL_GetError()); 35 | exit(EXIT_FAILURE); 36 | } 37 | 38 | spec.freq = freq; 39 | if(bits == 16) spec.format = AUDIO_S16SYS; else spec.format = AUDIO_U8; 40 | spec.channels = channels; 41 | spec.samples = bufsize; 42 | spec.callback = SDLPlayer::callback; 43 | spec.userdata = this; 44 | 45 | if(SDL_OpenAudio(&spec, NULL) < 0) { 46 | message(MSG_ERROR, "unable to open audio -- %s", SDL_GetError()); 47 | exit(EXIT_FAILURE); 48 | } 49 | 50 | message(MSG_DEBUG, "got audio buffer size -- %d", spec.size); 51 | } 52 | 53 | SDLPlayer::~SDLPlayer() 54 | { 55 | if(!SDL_WasInit(SDL_INIT_AUDIO)) return; 56 | 57 | SDL_CloseAudio(); 58 | SDL_Quit(); 59 | } 60 | 61 | void SDLPlayer::frame() 62 | { 63 | SDL_PauseAudio(0); 64 | SDL_Delay(1000 * spec.freq / (spec.size / getsampsize())); 65 | } 66 | 67 | void SDLPlayer::callback(void *userdata, Uint8 *audiobuf, int len) 68 | { 69 | SDLPlayer *self = (SDLPlayer *)userdata; 70 | static long minicnt = 0; 71 | long i, towrite = len / self->getsampsize(); 72 | char *pos = (char *)audiobuf; 73 | 74 | // Prepare audiobuf with emulator output 75 | while(towrite > 0) { 76 | while(minicnt < 0) { 77 | minicnt += self->spec.freq; 78 | self->playing = self->p->update(); 79 | } 80 | i = MIN(towrite, (long)(minicnt / self->p->getrefresh() + 4) & ~3); 81 | self->opl->update((short *)pos, i); 82 | pos += i * self->getsampsize(); towrite -= i; 83 | minicnt -= (long)(self->p->getrefresh() * i); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/disk.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2003 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "defines.h" 28 | #include "disk.h" 29 | 30 | #define BUFSIZE 512 31 | 32 | DiskWriter::DiskWriter(Copl *nopl, const char *filename, unsigned char nbits, 33 | unsigned char nchannels, unsigned long nfreq) 34 | : EmuPlayer(nopl, nbits, nchannels, nfreq, BUFSIZE), f(0), samplesize(0) 35 | { 36 | if(!filename) { 37 | message(MSG_ERROR, "no output filename specified"); 38 | exit(EXIT_FAILURE); 39 | } 40 | 41 | // If filename is '-', output to stdout 42 | if(strcmp(filename, "-")) 43 | f = new binofstream(filename); 44 | else 45 | f = new binowstream(&std::cout); // not very good to mix cout with stdout 46 | 47 | if(!f || f->error()) { 48 | message(MSG_ERROR, "cannot open file for output -- %s", filename); 49 | if(f) delete f; 50 | exit(EXIT_FAILURE); 51 | } 52 | 53 | f->setFlag(binio::BigEndian, false); 54 | 55 | // Write Microsoft RIFF WAVE header 56 | f->writeString("RIFF", 4); f->writeInt(36, 4); f->writeString("WAVEfmt ", 8); 57 | f->writeInt(16, 4); f->writeInt(1, 2); f->writeInt(nchannels, 2); 58 | f->writeInt(nfreq, 4); f->writeInt(nfreq * getsampsize(), 4); 59 | f->writeInt(getsampsize(), 2); f->writeInt(nbits, 2); 60 | f->writeString("data", 4); f->writeInt(0, 4); 61 | } 62 | 63 | DiskWriter::~DiskWriter() 64 | { 65 | if(!f) return; 66 | 67 | if(samplesize % 2) { // Wave data must end on an even byte boundary 68 | f->writeInt(0, 1); 69 | samplesize++; 70 | } 71 | 72 | // Write file sizes 73 | f->seek(40); f->writeInt(samplesize, 4); 74 | samplesize += 36; // make absolute filesize (add header size) 75 | f->seek(4); f->writeInt(samplesize, 4); 76 | 77 | // end disk writing 78 | delete f; 79 | } 80 | 81 | void DiskWriter::output(const void *buf, unsigned long size) 82 | { 83 | char *b = (char *)buf; 84 | unsigned long i, ssize = getsampsize(); 85 | 86 | for(i = 0; i < size; i += ssize) 87 | switch(ssize) { 88 | case 1: f->writeInt(*(b + i), 1); break; 89 | case 2: f->writeInt(*(short *)(b + i), 2); break; 90 | case 4: f->writeInt(*(long *)(b + i), 4); break; 91 | } 92 | 93 | samplesize += size; 94 | } 95 | -------------------------------------------------------------------------------- /src/qsa.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001, 2002 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include "qsa.h" 21 | 22 | #include 23 | 24 | QSAPlayer::QSAPlayer(unsigned char bits, int channels, int freq) 25 | : EmuPlayer(bits, channels, freq, QSA_FRAG_SIZE) 26 | { 27 | int rval; 28 | snd_pcm_channel_params_t cparams; 29 | audio_handle=NULL; 30 | 31 | rval = snd_pcm_open_preferred(&audio_handle, NULL, NULL, SND_PCM_OPEN_PLAYBACK); 32 | if (rval < 0) 33 | { 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | memset(&cparams, 0, sizeof(snd_pcm_channel_params_t)); 38 | 39 | cparams.channel = SND_PCM_CHANNEL_PLAYBACK; 40 | cparams.mode = SND_PCM_MODE_BLOCK; 41 | cparams.start_mode = SND_PCM_START_FULL; 42 | cparams.stop_mode = SND_PCM_STOP_STOP; 43 | if (bits==16) 44 | { 45 | cparams.format.format = SND_PCM_SFMT_S16_LE; 46 | } 47 | else 48 | { 49 | cparams.format.format = SND_PCM_SFMT_U8; 50 | } 51 | cparams.format.interleave = 1; 52 | cparams.format.rate = freq; 53 | cparams.format.voices = channels; 54 | cparams.buf.block.frag_size = QSA_FRAG_SIZE; 55 | cparams.buf.block.frags_min = 4; 56 | cparams.buf.block.frags_max = 8; 57 | 58 | rval = snd_pcm_plugin_params(audio_handle, &cparams); 59 | if (rval < 0) 60 | { 61 | exit(EXIT_FAILURE); 62 | } 63 | 64 | rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK); 65 | if (rval < 0) 66 | { 67 | exit(EXIT_FAILURE); 68 | } 69 | } 70 | 71 | QSAPlayer::~QSAPlayer() 72 | { 73 | int rval; 74 | 75 | if (audio_handle != NULL) 76 | { 77 | rval = snd_pcm_plugin_flush(audio_handle, SND_PCM_CHANNEL_PLAYBACK); 78 | rval = snd_pcm_close(audio_handle); 79 | audio_handle = NULL; 80 | } 81 | } 82 | 83 | void QSAPlayer::output(const void *buf, unsigned long size) 84 | { 85 | int rval; 86 | unsigned long written; 87 | unsigned long towrite; 88 | snd_pcm_channel_status_t cstatus; 89 | 90 | towrite=size; 91 | 92 | do { 93 | written = snd_pcm_plugin_write(audio_handle, buf, towrite); 94 | 95 | if (written != towrite) 96 | { 97 | if((errno == EINVAL) || (errno == EIO)) 98 | { 99 | memset(&cstatus, 0, sizeof(cstatus)); 100 | if (snd_pcm_plugin_status(audio_handle, &cstatus) < 0 ) 101 | { 102 | return; 103 | } 104 | if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || 105 | (cstatus.status == SND_PCM_STATUS_READY)) 106 | { 107 | if (snd_pcm_plugin_prepare (audio_handle, SND_PCM_CHANNEL_PLAYBACK) < 0 ) 108 | { 109 | return; 110 | } 111 | } 112 | continue; 113 | } 114 | } 115 | else 116 | { 117 | break; 118 | } 119 | } while (1); 120 | } 121 | -------------------------------------------------------------------------------- /m4/ao.m4: -------------------------------------------------------------------------------- 1 | # ao.m4 2 | # Configure paths for libao 3 | # Jack Moffitt 10-21-2000 4 | # Shamelessly stolen from Owen Taylor and Manish Singh 5 | # AdPlay/Unix updated some usage of deprecated macros 6 | 7 | dnl XIPH_PATH_AO([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) 8 | dnl Test for libao, and define AO_CFLAGS and AO_LIBS 9 | dnl 10 | AC_DEFUN([XIPH_PATH_AO], 11 | [dnl 12 | dnl Get the cflags and libraries 13 | dnl 14 | AC_ARG_WITH(ao,[ --with-ao=PFX Prefix where libao is installed (optional)], ao_prefix="$withval", ao_prefix="") 15 | AC_ARG_WITH(ao-libraries,[ --with-ao-libraries=DIR Directory where libao library is installed (optional)], ao_libraries="$withval", ao_libraries="") 16 | AC_ARG_WITH(ao-includes,[ --with-ao-includes=DIR Directory where libao header files are installed (optional)], ao_includes="$withval", ao_includes="") 17 | AC_ARG_ENABLE(aotest, [ --disable-aotest Do not try to compile and run a test ao program],, enable_aotest=yes) 18 | if test "x$ao_libraries" != "x" ; then 19 | AO_LIBS="-L$ao_libraries" 20 | elif test "x$ao_prefix" != "x"; then 21 | AO_LIBS="-L$ao_prefix/lib" 22 | elif test "x$prefix" != "xNONE"; then 23 | AO_LIBS="-L$prefix/lib" 24 | fi 25 | if test "x$ao_includes" != "x" ; then 26 | AO_CFLAGS="-I$ao_includes" 27 | elif test "x$ao_prefix" != "x"; then 28 | AO_CFLAGS="-I$ao_prefix/include" 29 | elif test "x$prefix" != "xNONE"; then 30 | AO_CFLAGS="-I$prefix/include" 31 | fi 32 | # see where dl* and friends live 33 | AC_CHECK_FUNCS(dlopen, [AO_DL_LIBS=""], [ 34 | AC_CHECK_LIB(dl, dlopen, [AO_DL_LIBS="-ldl"], [ 35 | AC_MSG_WARN([could not find dlopen() needed by libao sound drivers 36 | your system may not be supported.]) 37 | ]) 38 | ]) 39 | AO_LIBS="$AO_LIBS -lao $AO_DL_LIBS" 40 | AC_MSG_CHECKING(for ao) 41 | no_ao="" 42 | if test "x$enable_aotest" = "xyes" ; then 43 | ac_save_CFLAGS="$CFLAGS" 44 | ac_save_LIBS="$LIBS" 45 | CFLAGS="$CFLAGS $AO_CFLAGS" 46 | LIBS="$LIBS $AO_LIBS" 47 | dnl 48 | dnl Now check if the installed ao is sufficiently new. 49 | dnl 50 | rm -f conf.aotest 51 | AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 52 | #include 53 | #include 54 | #include 55 | #include 56 | ]],[[ 57 | system("touch conf.aotest"); 58 | return 0; 59 | ]])],, no_ao=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) 60 | CFLAGS="$ac_save_CFLAGS" 61 | LIBS="$ac_save_LIBS" 62 | fi 63 | if test "x$no_ao" = "x" ; then 64 | AC_MSG_RESULT(yes) 65 | ifelse([$1], , :, [$1]) 66 | else 67 | AC_MSG_RESULT(no) 68 | if test -f conf.aotest ; then 69 | : 70 | else 71 | echo "*** Could not run ao test program, checking why..." 72 | CFLAGS="$CFLAGS $AO_CFLAGS" 73 | LIBS="$LIBS $AO_LIBS" 74 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 75 | #include 76 | #include 77 | ]],[[ return 0; ]])], 78 | [ echo "*** The test program compiled, but did not run. This usually means" 79 | echo "*** that the run-time linker is not finding ao or finding the wrong" 80 | echo "*** version of ao. If it is not finding ao, you'll need to set your" 81 | echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 82 | echo "*** to the installed location Also, make sure you have run ldconfig if that" 83 | echo "*** is required on your system" 84 | echo "***" 85 | echo "*** If you have an old version installed, it is best to remove it, although" 86 | echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], 87 | [ echo "*** The test program failed to compile or link. See the file config.log for the" 88 | echo "*** exact error that occured. This usually means ao was incorrectly installed" 89 | echo "*** or that you have moved ao since it was installed." ]) 90 | CFLAGS="$ac_save_CFLAGS" 91 | LIBS="$ac_save_LIBS" 92 | fi 93 | AO_CFLAGS="" 94 | AO_LIBS="" 95 | ifelse([$2], , :, [$2]) 96 | fi 97 | AC_SUBST(AO_CFLAGS) 98 | AC_SUBST(AO_LIBS) 99 | rm -f conf.aotest 100 | ]) 101 | -------------------------------------------------------------------------------- /src/alsa.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2004 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include "defines.h" 21 | #include "alsa.h" 22 | 23 | #define DEFAULT_DEVICE "default" // Default ALSA output device 24 | 25 | ALSAPlayer::ALSAPlayer(Copl *nopl, const char *device, unsigned char bits, 26 | int channels, int freq, unsigned long bufsize) 27 | : EmuPlayer(nopl, bits, channels, freq, bufsize) 28 | { 29 | snd_pcm_hw_params_t *hwparams; 30 | unsigned int nfreq = freq; 31 | unsigned long nbufsize; 32 | 33 | if(!device) device = DEFAULT_DEVICE; 34 | 35 | snd_pcm_hw_params_malloc(&hwparams); 36 | 37 | // Try to open audio device 38 | if(snd_pcm_open(&pcm_handle, device, SND_PCM_STREAM_PLAYBACK, 0) < 0) { 39 | message(MSG_ERROR, "error opening PCM device -- %s", device); 40 | exit(EXIT_FAILURE); 41 | } 42 | 43 | // Init hwparams with full configuration space 44 | if(snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { 45 | message(MSG_ERROR, "cannot configure this PCM device -- %s", device); 46 | exit(EXIT_FAILURE); 47 | } 48 | 49 | // Set access type 50 | if(snd_pcm_hw_params_set_access(pcm_handle, hwparams, 51 | SND_PCM_ACCESS_RW_INTERLEAVED) < 0) { 52 | message(MSG_ERROR, "error setting access type"); 53 | exit(EXIT_FAILURE); 54 | } 55 | 56 | // Set sample format 57 | if (snd_pcm_hw_params_set_format(pcm_handle, hwparams, bits == 16 ? 58 | SND_PCM_FORMAT_S16 : SND_PCM_FORMAT_U8) < 0) { 59 | message(MSG_ERROR, "error setting format"); 60 | exit(EXIT_FAILURE); 61 | } 62 | 63 | // Set sample rate (nearest possible) 64 | if(snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &nfreq, 0) < 0) { 65 | message(MSG_ERROR, "error setting sample rate"); 66 | exit(EXIT_FAILURE); 67 | } 68 | 69 | if(nfreq != (unsigned int)freq) 70 | message(MSG_NOTE, "%d Hz sample rate not supported by your hardware, using " 71 | "%d Hz instead", freq, nfreq); 72 | 73 | // Set number of channels 74 | if(snd_pcm_hw_params_set_channels(pcm_handle, hwparams, channels) < 0) { 75 | message(MSG_ERROR, "error setting channels"); 76 | exit(EXIT_FAILURE); 77 | } 78 | 79 | // Set number of periods 80 | if(snd_pcm_hw_params_set_periods(pcm_handle, hwparams, 4, 0) < 0) { 81 | message(MSG_ERROR, "error setting periods"); 82 | exit(EXIT_FAILURE); 83 | } 84 | 85 | // Set the preferred buffer size (in samples) 86 | if(snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, 4*bufsize / getsampsize()) < 0) { 87 | if (snd_pcm_hw_params_get_buffer_size(hwparams, &nbufsize) < 0) { 88 | message(MSG_ERROR, "error setting and getting buffer size"); 89 | exit(EXIT_FAILURE); 90 | } 91 | setbufsize(nbufsize); 92 | message(MSG_NOTE, "couldn't set buffersize to %ld, using default of %ld instead", bufsize, nbufsize); 93 | } 94 | 95 | // Apply HW parameter settings to PCM device and prepare device 96 | if(snd_pcm_hw_params(pcm_handle, hwparams) < 0) { 97 | message(MSG_ERROR, "error setting HW params"); 98 | exit(EXIT_FAILURE); 99 | } 100 | 101 | snd_pcm_hw_params_free(hwparams); 102 | } 103 | 104 | ALSAPlayer::~ALSAPlayer() 105 | { 106 | // stop playback immediately 107 | snd_pcm_drop(pcm_handle); 108 | snd_pcm_close(pcm_handle); 109 | } 110 | 111 | void ALSAPlayer::output(const void *buf, unsigned long size) 112 | { 113 | if(snd_pcm_writei(pcm_handle, buf, size / getsampsize()) < 0) 114 | snd_pcm_prepare(pcm_handle); 115 | } 116 | -------------------------------------------------------------------------------- /adplay.qpg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | QNX.ORG.RU Community 17 | 18 | 19 | QNX.ORG.RU Team 20 | Mike Gorchak 21 | mike@malva.ua 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | Application 40 | adplay 41 | 1 42 | http://qnx.org.ru/repository 43 | 1.01 44 | 45 | 46 | adplay 47 | adplay 48 | dn.tlp@gmx.net 49 | Public 50 | public 51 | http://adplug.github.io 52 | 53 | dn.tlp@gmx.net 54 | Simon Peter 55 | http://adplug.github.io 56 | 57 | dn.tlp@gmx.net 58 | 59 | 60 | AdPlay/UNIX is AdPlug's UNIX console-based frontend. AdPlug is a free, universal OPL2 audio playback library. AdPlay/UNIX supports the full range of AdPlug's file format playback features. 61 | AdPlay/UNIX is AdPlug's UNIX console-based frontend. AdPlug is a free, universal OPL2 audio playback library. AdPlay/UNIX supports the full range of AdPlug's file format playback features. Despite this, at the moment, only emulated OPL2 output is supported by AdPlay/UNIX, but this on a wide range of output devices. 62 | http://adplug.github.io 63 | 64 | 65 | 66 | 1.10 67 | Medium 68 | Stable 69 | 70 | 71 | 1 72 | 73 | GNU General Public License 74 | 75 | 76 | Multimedia/Music and Audio/Audio Media Players 77 | FM, Tracker, Music, Adlib, OPL2, Player 78 | 79 | 80 | Console 81 | User 82 | 83 | repdata://LicenseUrl/COPYING 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/getopt1.c: -------------------------------------------------------------------------------- 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. 2 | Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 3 | Free Software Foundation, Inc. 4 | This file is part of the GNU C Library. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "getopt.h" 26 | 27 | #if !defined __STDC__ || !__STDC__ 28 | /* This is a separate conditional since some stdc systems 29 | reject `defined (const)'. */ 30 | #ifndef const 31 | #define const 32 | #endif 33 | #endif 34 | 35 | #include 36 | 37 | /* Comment out all this code if we are using the GNU C Library, and are not 38 | actually compiling the library itself. This code is part of the GNU C 39 | Library, but also included in many other GNU distributions. Compiling 40 | and linking in this code is a waste when using the GNU C library 41 | (especially if it is a shared library). Rather than having every GNU 42 | program understand `configure --with-gnu-libc' and omit the object files, 43 | it is simpler to just do this in the source for each such file. */ 44 | 45 | #define GETOPT_INTERFACE_VERSION 2 46 | #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 47 | #include 48 | #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION 49 | #define ELIDE_CODE 50 | #endif 51 | #endif 52 | 53 | #ifndef ELIDE_CODE 54 | 55 | 56 | /* This needs to come after some library #include 57 | to get __GNU_LIBRARY__ defined. */ 58 | #ifdef __GNU_LIBRARY__ 59 | #include 60 | #endif 61 | 62 | #ifndef NULL 63 | #define NULL 0 64 | #endif 65 | 66 | int 67 | getopt_long (argc, argv, options, long_options, opt_index) 68 | int argc; 69 | char *const *argv; 70 | const char *options; 71 | const struct option *long_options; 72 | int *opt_index; 73 | { 74 | return _getopt_internal (argc, argv, options, long_options, opt_index, 0); 75 | } 76 | 77 | /* Like getopt_long, but '-' as well as '--' can indicate a long option. 78 | If an option that starts with '-' (not '--') doesn't match a long option, 79 | but does match a short option, it is parsed as a short option 80 | instead. */ 81 | 82 | int 83 | getopt_long_only (argc, argv, options, long_options, opt_index) 84 | int argc; 85 | char *const *argv; 86 | const char *options; 87 | const struct option *long_options; 88 | int *opt_index; 89 | { 90 | return _getopt_internal (argc, argv, options, long_options, opt_index, 1); 91 | } 92 | 93 | 94 | #endif /* Not ELIDE_CODE. */ 95 | 96 | #ifdef TEST 97 | 98 | #include 99 | 100 | int 101 | main (argc, argv) 102 | int argc; 103 | char **argv; 104 | { 105 | int c; 106 | int digit_optind = 0; 107 | 108 | while (1) 109 | { 110 | int this_option_optind = optind ? optind : 1; 111 | int option_index = 0; 112 | static struct option long_options[] = 113 | { 114 | {"add", 1, 0, 0}, 115 | {"append", 0, 0, 0}, 116 | {"delete", 1, 0, 0}, 117 | {"verbose", 0, 0, 0}, 118 | {"create", 0, 0, 0}, 119 | {"file", 1, 0, 0}, 120 | {0, 0, 0, 0} 121 | }; 122 | 123 | c = getopt_long (argc, argv, "abc:d:0123456789", 124 | long_options, &option_index); 125 | if (c == -1) 126 | break; 127 | 128 | switch (c) 129 | { 130 | case 0: 131 | printf ("option %s", long_options[option_index].name); 132 | if (optarg) 133 | printf (" with arg %s", optarg); 134 | printf ("\n"); 135 | break; 136 | 137 | case '0': 138 | case '1': 139 | case '2': 140 | case '3': 141 | case '4': 142 | case '5': 143 | case '6': 144 | case '7': 145 | case '8': 146 | case '9': 147 | if (digit_optind != 0 && digit_optind != this_option_optind) 148 | printf ("digits occur in two different argv-elements.\n"); 149 | digit_optind = this_option_optind; 150 | printf ("option %c\n", c); 151 | break; 152 | 153 | case 'a': 154 | printf ("option a\n"); 155 | break; 156 | 157 | case 'b': 158 | printf ("option b\n"); 159 | break; 160 | 161 | case 'c': 162 | printf ("option c with value `%s'\n", optarg); 163 | break; 164 | 165 | case 'd': 166 | printf ("option d with value `%s'\n", optarg); 167 | break; 168 | 169 | case '?': 170 | break; 171 | 172 | default: 173 | printf ("?? getopt returned character code 0%o ??\n", c); 174 | } 175 | } 176 | 177 | if (optind < argc) 178 | { 179 | printf ("non-option ARGV-elements: "); 180 | while (optind < argc) 181 | printf ("%s ", argv[optind++]); 182 | printf ("\n"); 183 | } 184 | 185 | exit (0); 186 | } 187 | 188 | #endif /* TEST */ 189 | -------------------------------------------------------------------------------- /src/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public License as 7 | published by the Free Software Foundation; either version 2 of the 8 | License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with the GNU C Library; see the file COPYING.LIB. If not, 17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. */ 19 | 20 | #ifndef _GETOPT_H 21 | 22 | #ifndef __need_getopt 23 | # define _GETOPT_H 1 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | // in mingw, __argc and __argv are special 31 | #undef __argc 32 | #undef __argv 33 | 34 | /* For communication from `getopt' to the caller. 35 | When `getopt' finds an option that takes an argument, 36 | the argument value is returned here. 37 | Also, when `ordering' is RETURN_IN_ORDER, 38 | each non-option ARGV-element is returned here. */ 39 | 40 | extern char *optarg; 41 | 42 | /* Index in ARGV of the next element to be scanned. 43 | This is used for communication to and from the caller 44 | and for communication between successive calls to `getopt'. 45 | 46 | On entry to `getopt', zero means this is the first call; initialize. 47 | 48 | When `getopt' returns -1, this is the index of the first of the 49 | non-option elements that the caller should itself scan. 50 | 51 | Otherwise, `optind' communicates from one call to the next 52 | how much of ARGV has been scanned so far. */ 53 | 54 | extern int optind; 55 | 56 | /* Callers store zero here to inhibit the error message `getopt' prints 57 | for unrecognized options. */ 58 | 59 | extern int opterr; 60 | 61 | /* Set to an option character which was unrecognized. */ 62 | 63 | extern int optopt; 64 | 65 | #ifndef __need_getopt 66 | /* Describe the long-named options requested by the application. 67 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 68 | of `struct option' terminated by an element containing a name which is 69 | zero. 70 | 71 | The field `has_arg' is: 72 | no_argument (or 0) if the option does not take an argument, 73 | required_argument (or 1) if the option requires an argument, 74 | optional_argument (or 2) if the option takes an optional argument. 75 | 76 | If the field `flag' is not NULL, it points to a variable that is set 77 | to the value given in the field `val' when the option is found, but 78 | left unchanged if the option is not found. 79 | 80 | To have a long-named option do something other than set an `int' to 81 | a compiled-in constant, such as set a value from `optarg', set the 82 | option's `flag' field to zero and its `val' field to a nonzero 83 | value (the equivalent single-letter option character, if there is 84 | one). For long options that have a zero `flag' field, `getopt' 85 | returns the contents of the `val' field. */ 86 | 87 | struct option 88 | { 89 | # if defined __STDC__ && __STDC__ 90 | const char *name; 91 | # else 92 | char *name; 93 | # endif 94 | /* has_arg can't be an enum because some compilers complain about 95 | type mismatches in all the code that assumes it is an int. */ 96 | int has_arg; 97 | int *flag; 98 | int val; 99 | }; 100 | 101 | /* Names for the values of the `has_arg' field of `struct option'. */ 102 | 103 | # define no_argument 0 104 | # define required_argument 1 105 | # define optional_argument 2 106 | #endif /* need getopt */ 107 | 108 | 109 | /* Get definitions and prototypes for functions to process the 110 | arguments in ARGV (ARGC of them, minus the program name) for 111 | options given in OPTS. 112 | 113 | Return the option character from OPTS just read. Return -1 when 114 | there are no more options. For unrecognized options, or options 115 | missing arguments, `optopt' is set to the option letter, and '?' is 116 | returned. 117 | 118 | The OPTS string is a list of characters which are recognized option 119 | letters, optionally followed by colons, specifying that that letter 120 | takes an argument, to be placed in `optarg'. 121 | 122 | If a letter in OPTS is followed by two colons, its argument is 123 | optional. This behavior is specific to the GNU `getopt'. 124 | 125 | The argument `--' causes premature termination of argument 126 | scanning, explicitly telling `getopt' that there are no more 127 | options. 128 | 129 | If OPTS begins with `--', then non-option arguments are treated as 130 | arguments to the option '\0'. This behavior is specific to the GNU 131 | `getopt'. */ 132 | 133 | #if defined __STDC__ && __STDC__ 134 | # ifdef __GNU_LIBRARY__ 135 | /* Many other libraries have conflicting prototypes for getopt, with 136 | differences in the consts, in stdlib.h. To avoid compilation 137 | errors, only prototype getopt for the GNU C library. */ 138 | extern int getopt (int __argc, char *const *__argv, const char *__shortopts); 139 | # else /* not __GNU_LIBRARY__ */ 140 | extern int getopt (); 141 | # endif /* __GNU_LIBRARY__ */ 142 | 143 | # ifndef __need_getopt 144 | extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, 145 | const struct option *__longopts, int *__longind); 146 | extern int getopt_long_only (int __argc, char *const *__argv, 147 | const char *__shortopts, 148 | const struct option *__longopts, int *__longind); 149 | 150 | /* Internal only. Users should not call this directly. */ 151 | extern int _getopt_internal (int __argc, char *const *__argv, 152 | const char *__shortopts, 153 | const struct option *__longopts, int *__longind, 154 | int __long_only); 155 | # endif 156 | #else /* not __STDC__ */ 157 | extern int getopt (); 158 | # ifndef __need_getopt 159 | extern int getopt_long (); 160 | extern int getopt_long_only (); 161 | 162 | extern int _getopt_internal (); 163 | # endif 164 | #endif /* __STDC__ */ 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | /* Make sure we later can get all the definitions and declarations. */ 171 | #undef __need_getopt 172 | 173 | #endif /* getopt.h */ 174 | -------------------------------------------------------------------------------- /m4/alsa.m4: -------------------------------------------------------------------------------- 1 | dnl Configure Paths for Alsa 2 | dnl Some modifications by Richard Boulton 3 | dnl Christopher Lansdown 4 | dnl Jaroslav Kysela 5 | dnl Last modification: $Id: alsa.m4,v 1.24 2004/09/15 18:48:07 tiwai Exp $ 6 | dnl 7 | dnl AM_PATH_ALSA([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 8 | dnl Test for libasound, and define ALSA_CFLAGS, ALSA_LIBS and 9 | dnl ALSA_TOPOLOGY_LIBS as appropriate. 10 | dnl 11 | dnl enables arguments --with-alsa-prefix= 12 | dnl --with-alsa-inc-prefix= 13 | dnl --disable-alsatest 14 | dnl 15 | dnl For backwards compatibility, if ACTION_IF_NOT_FOUND is not specified, 16 | dnl and the alsa libraries are not found, a fatal AC_MSG_ERROR() will result. 17 | dnl 18 | 19 | AC_DEFUN([AM_PATH_ALSA], 20 | [dnl Save the original CFLAGS, LDFLAGS, and LIBS 21 | alsa_save_CFLAGS="$CFLAGS" 22 | alsa_save_LDFLAGS="$LDFLAGS" 23 | alsa_save_LIBS="$LIBS" 24 | alsa_found=yes 25 | alsa_topology_found=no 26 | dnl 27 | dnl Get the cflags and libraries for alsa 28 | dnl 29 | AC_ARG_WITH(alsa-prefix, 30 | AS_HELP_STRING([--with-alsa-prefix=PFX], [Prefix where Alsa library is installed(optional)]), 31 | [alsa_prefix="$withval"], [alsa_prefix=""]) 32 | AC_ARG_WITH(alsa-inc-prefix, 33 | AS_HELP_STRING([--with-alsa-inc-prefix=PFX], [Prefix where include libraries are (optional)]), 34 | [alsa_inc_prefix="$withval"], [alsa_inc_prefix=""]) 35 | AC_ARG_ENABLE(alsa-topology, 36 | AS_HELP_STRING([--enable-alsatopology], [Force to use the Alsa topology library]), 37 | [enable_atopology="$enableval"], 38 | [enable_atopology=no]) 39 | AC_ARG_ENABLE(alsatest, 40 | AS_HELP_STRING([--disable-alsatest], [Do not try to compile and run a test Alsa program]), 41 | [enable_alsatest="$enableval"], 42 | [enable_alsatest=yes]) 43 | dnl Add any special include directories 44 | AC_MSG_CHECKING(for ALSA CFLAGS) 45 | if test "$alsa_inc_prefix" != "" ; then 46 | ALSA_CFLAGS="$ALSA_CFLAGS -I$alsa_inc_prefix" 47 | CFLAGS="$CFLAGS -I$alsa_inc_prefix" 48 | fi 49 | AC_MSG_RESULT($ALSA_CFLAGS) 50 | AC_CHECK_LIB(c, dlopen, LIBDL="", [AC_CHECK_LIB(dl, dlopen, LIBDL="-ldl")]) 51 | dnl add any special lib dirs 52 | AC_MSG_CHECKING(for ALSA LDFLAGS) 53 | if test "$alsa_prefix" != "" ; then 54 | ALSA_LIBS="$ALSA_LIBS -L$alsa_prefix" 55 | LDFLAGS="$LDFLAGS $ALSA_LIBS" 56 | fi 57 | dnl add the alsa library 58 | ALSA_LIBS="$ALSA_LIBS -lasound -lm $LIBDL -lpthread" 59 | LIBS="$ALSA_LIBS $LIBS" 60 | AC_MSG_RESULT($ALSA_LIBS) 61 | dnl Check for a working version of libasound that is of the right version. 62 | if test "x$enable_alsatest" = "xyes"; then 63 | AC_MSG_CHECKING([required libasound headers version]) 64 | min_alsa_version=ifelse([$1], , 0.1.1, $1) 65 | no_alsa="" 66 | alsa_min_major_version=`echo $min_alsa_version | \ 67 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 68 | alsa_min_minor_version=`echo $min_alsa_version | \ 69 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 70 | alsa_min_micro_version=`echo $min_alsa_version | \ 71 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 72 | AC_MSG_RESULT($alsa_min_major_version.$alsa_min_minor_version.$alsa_min_micro_version) 73 | AC_LANG_PUSH([C]) 74 | AC_MSG_CHECKING([for libasound headers version >= $alsa_min_major_version.$alsa_min_minor_version.$alsa_min_micro_version ($min_alsa_version)]) 75 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 76 | #include 77 | #include 78 | ]], [[ 79 | /* ensure backward compatibility */ 80 | #if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR) 81 | #define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR 82 | #endif 83 | #if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR) 84 | #define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR 85 | #endif 86 | #if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR) 87 | #define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR 88 | #endif 89 | # if(SND_LIB_MAJOR > $alsa_min_major_version) 90 | exit(0); 91 | # else 92 | # if(SND_LIB_MAJOR < $alsa_min_major_version) 93 | # error not present 94 | # endif 95 | # if(SND_LIB_MINOR > $alsa_min_minor_version) 96 | exit(0); 97 | # else 98 | # if(SND_LIB_MINOR < $alsa_min_minor_version) 99 | # error not present 100 | # endif 101 | # if(SND_LIB_SUBMINOR < $alsa_min_micro_version) 102 | # error not present 103 | # endif 104 | # endif 105 | # endif 106 | exit(0); 107 | ]])], 108 | [AC_MSG_RESULT(found.)], 109 | [AC_MSG_RESULT(not present.) 110 | ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)]) 111 | alsa_found=no] 112 | ) 113 | AC_LANG_POP([C]) 114 | AC_LANG_PUSH([C]) 115 | AC_MSG_CHECKING([for libatopology (sound headers version > 1.1.9)]) 116 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 117 | #include 118 | #include 119 | #include 120 | ]], [[ 121 | /* ensure backward compatibility */ 122 | #if !defined(SND_LIB_VERSION) 123 | #define SND_LIB_VERSION 0 124 | #endif 125 | #if SND_LIB_VERSION > 0x00010109 126 | exit(0); 127 | #else 128 | # error not present 129 | #endif 130 | exit(0); 131 | ]])], 132 | [AC_MSG_RESULT(yes) 133 | enable_atopology="yes"], 134 | [AC_MSG_RESULT(no)] 135 | ) 136 | AC_LANG_POP([C]) 137 | fi 138 | dnl Now that we know that we have the right version, let's see if we have the library and not just the headers. 139 | if test "x$enable_alsatest" = "xyes"; then 140 | AC_CHECK_LIB([asound], [snd_ctl_open],, 141 | [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)]) 142 | alsa_found=no] 143 | ) 144 | if test "x$enable_atopology" = "xyes"; then 145 | alsa_topology_found=yes 146 | alsa_save_LIBS2="$LIBS" 147 | AC_CHECK_LIB([atopology], [snd_tplg_new],, 148 | [ifelse([$3], , [AC_MSG_ERROR(No linkable libatopology was found.)]) 149 | alsa_topology_found=no, 150 | ] 151 | ) 152 | LIBS="$alsa_save_LIBS2" 153 | fi 154 | else 155 | if test "x$enable_atopology" = "xyes"; then 156 | alsa_topology_found=yes 157 | fi 158 | fi 159 | if test "x$alsa_found" = "xyes" ; then 160 | ifelse([$2], , :, [$2]) 161 | LIBS=`echo $LIBS | sed 's/-lasound//g'` 162 | LIBS=`echo $LIBS | sed 's/ //'` 163 | LIBS="-lasound $LIBS" 164 | fi 165 | if test "x$alsa_found" = "xno" ; then 166 | ifelse([$3], , :, [$3]) 167 | CFLAGS="$alsa_save_CFLAGS" 168 | LDFLAGS="$alsa_save_LDFLAGS" 169 | LIBS="$alsa_save_LIBS" 170 | ALSA_CFLAGS="" 171 | ALSA_LIBS="" 172 | ALSA_TOPOLOGY_LIBS="" 173 | fi 174 | dnl add the alsa topology library; must be at the end 175 | AC_MSG_CHECKING(for ALSA topology LDFLAGS) 176 | if test "x$alsa_topology_found" = "xyes"; then 177 | ALSA_TOPOLOGY_LIBS="$ALSA_TOPOLOGY_LIBS -latopology" 178 | fi 179 | AC_MSG_RESULT($ALSA_TOPOLOGY_LIBS) 180 | dnl That should be it. Now just export out symbols: 181 | AC_SUBST(ALSA_CFLAGS) 182 | AC_SUBST(ALSA_LIBS) 183 | AC_SUBST(ALSA_TOPOLOGY_LIBS) 184 | ]) 185 | -------------------------------------------------------------------------------- /doc/adplay.1: -------------------------------------------------------------------------------- 1 | .\" -*- nroff -*- 2 | .\" adplay is free software; you can redistribute it and/or modify 3 | .\" it under the terms of the GNU General Public License as published by 4 | .\" the Free Software Foundation; either version 2 of the License, or 5 | .\" (at your option) any later version. 6 | .\" 7 | .\" This program is distributed in the hope that it will be useful, 8 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | .\" GNU General Public License for more details. 11 | .\" 12 | .\" You should have received a copy of the GNU General Public License 13 | .\" along with this program; see the file COPYING. If not, write to 14 | .\" the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 15 | .\" 16 | .TH ADPLAY 1 "December 21, 2025" "AdPlay/UNIX 1.10" "User Commands" 17 | .SH NAME 18 | adplay \- AdPlay/UNIX console-based OPL2 audio player 19 | .SH SYNOPSIS 20 | .B adplay 21 | .RI "[OPTION]... FILE..." 22 | .SH DESCRIPTION 23 | AdPlay/UNIX is AdPlug's UNIX console-based frontend. It tries to play 24 | back all given FILEs, using one of many available output mechanisms. 25 | .PP 26 | AdPlay/UNIX plays endlessly, if only one file is given. With multiple files, 27 | it plays them in a sequence and exits after the last file. The same can 28 | also be accomplished with only one file, by using the \fB-o\fP 29 | option. When using the disk writer, \fB-o\fP is implied. 30 | .SH EXIT STATUS 31 | \fBadplay\fP returns 0 on successful operation. 1 is returned 32 | otherwise. 33 | .SH OUTPUT MECHANISMS 34 | .PP 35 | AdPlay/UNIX can play back using many different output mechanisms, 36 | which can be selected with the \fB-O\fP argument. The availability of 37 | a method depends on compile-time settings. Available methods are 38 | printed out after the help text, displayed with \fB--help\fP. 39 | .PP 40 | Next is a brief description of all output mechanisms, following their 41 | abbreviations: 42 | .SS oss -- Open Sound System (OSS) driver 43 | .PP 44 | This output method is available on most Linux and other UNIX systems. 45 | .SS null -- Total silence 46 | .PP 47 | Discards anything sent to it. It can be useful for testing purposes. 48 | .SS disk -- Disk writer 49 | .PP 50 | Writes its output to a file in Microsoft RIFF WAVE format. 51 | .SS esound -- EsounD output 52 | .PP 53 | Creates a socket connection to an EsounD server and streams the audio 54 | to it. 55 | .SS qsa -- QNX Sound Architecture (QSA) driver 56 | .PP 57 | Uses the QNX system's standard output method. 58 | .SS sdl -- Simple Directmedia Layer (SDL) driver 59 | .PP 60 | Uses the SDL library for sound output. The library has a broader 61 | platform support than any of the other output methods. Thus, it could 62 | be useful on some exotic systems. 63 | .SS alsa -- Advanced Linux Sound Architecture (ALSA) driver 64 | .PP 65 | Uses the standard output method on newer Linux systems. 66 | .SS ao -- libao driver 67 | .PP 68 | Libao is a cross-platform audio library with very broad platform 69 | support. Might be useful on systems, where SDL is not available, and 70 | generally to do tricky things. 71 | .SH OPTIONS 72 | .PP 73 | The order of the option commandline parameters is not important, 74 | except for the \fB-d\fP option, which always has to be specified after 75 | an \fB-O\fP option. 76 | .SS "Output selection:" 77 | .TP 78 | .B -O, --output=OUTPUT 79 | Specify output mechanism. Available mechanisms depend on compilation 80 | settings and are printed on \fB--help\fP output. A reasonable default 81 | is automatically selected, based on the availability of the output 82 | mechanisms. 83 | .SS "OSS driver (oss) specific:" 84 | .TP 85 | .B -d --device=FILE 86 | Set sound output device file to FILE. This is \fB/dev/dsp\fP by 87 | default. 88 | .SS "Disk writer (disk) specific:" 89 | .TP 90 | .B -d --device=FILE 91 | Write sound data to FILE. The data is written in Microsoft RIFF WAVE 92 | format (little-endian). You can specify a single '-' to write to 93 | stdout instead. This option has no default and must be specified when 94 | the disk writer is to be used! 95 | .SS "EsounD output (esound) specific:" 96 | .TP 97 | .B -d --device=URL 98 | Connect to "hostname:port" combination in URL. Example: 99 | "myhost.sound.net:1234". The default is "localhost:16001". 100 | .SS "ALSA driver (alsa) specific:" 101 | .TP 102 | .B -d --device=DEVICE 103 | Set sound output device to DEVICE. This is \fBplughw:0,0\fP by default. 104 | .SS "Playback quality:" 105 | .TP 106 | .B -8, --8bit 107 | Use only 8-bit samples for playback. 108 | .TP 109 | .B --16bit 110 | Use only 16-bit samples for playback (default). 111 | .TP 112 | .B -f, --freq=FREQ 113 | Set playback frequency to FREQ, in Hz. This is 44100Hz by default. 114 | .TP 115 | .B --stereo 116 | Use only stereo samples for playback. The sound stream is just doubled, no 117 | further audio processing is done. This option is pretty useless unless you 118 | have very obscure audio hardware that only accepts stereo streams. AdPlug 119 | only generates mono streams because the OPL2 only generates mono sound. 120 | .TP 121 | .B --mono 122 | Use only mono samples for playback (default if AdPlug <= 2.1.) 123 | .TP 124 | .B --surround 125 | Use only stereo samples for playback, but generate them from two mono OPL2 126 | chips. One OPL2 chip is very slightly transposed to produce a pleasant 127 | harmonic/surround sound effect (default if AdPlug >= 2.2.) 128 | .TP 129 | .B -b --buffer=SIZE 130 | Set sound buffer size to SIZE samples. If you notice sound skipping with the 131 | default setting, try a greater buffer size. Note that this is measured in 132 | samples, not bytes! This is 2048 samples by default. Only the OSS, 133 | SDL, ALSA and libao output drivers support this option. 134 | .SS "Informative output:" 135 | .TP 136 | .B -i --instruments 137 | Display instrument names (if available). 138 | .TP 139 | .B -r --realtime 140 | Display realtime playback information, while playing. This will display a 141 | one-line status bar, containing essential playback information. 142 | .TP 143 | .B -m --message 144 | Display the song message (if available). 145 | .SS "Playback:" 146 | .TP 147 | .B -s --subsong=N 148 | Play subsong number N, instead of the default subsong of the 149 | file. Only useful for file formats that support multiple subsongs. 150 | .TP 151 | .B -o --once 152 | Don't loop endlessly. This will exit \fBadplay\fP after the song 153 | ended. This is the default when multiple \fBFILEs\fP are given. 154 | .TP 155 | .B -l --loop=N 156 | Loop N times then stop. Due to technical limitations of the adplug library, 157 | a "loop" is considered to be the time between the start of playback and when 158 | looping first occurs. Accordingly, playback may actually halt at an unexpected 159 | point, especially when combined with \fB-s\fR. This implies \fB-o\fR. 160 | .SS "Miscellaneous:" 161 | .TP 162 | .B -D, --database=FILE 163 | Additionally use database file FILE. This option may be specified 164 | multiple times. Each database file is additionally merged with the 165 | others, creating one large database on the fly. 166 | .TP 167 | .B -q, --quiet 168 | Be more quiet. 169 | .TP 170 | .B -v, --verbose 171 | Be more verbose. 172 | .TP 173 | .B -h, --help 174 | Show summary of options. 175 | .TP 176 | .B -V, --version 177 | Show version of program. 178 | .SH AUTHOR 179 | Simon Peter 180 | -------------------------------------------------------------------------------- /m4/sdl.m4: -------------------------------------------------------------------------------- 1 | # Configure paths for SDL 2 | # Sam Lantinga 9/21/99 3 | # stolen from Manish Singh 4 | # stolen back from Frank Belew 5 | # stolen from Manish Singh 6 | # Shamelessly stolen from Owen Taylor 7 | 8 | # serial 2 9 | 10 | dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 11 | dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS 12 | dnl 13 | AC_DEFUN([AM_PATH_SDL], 14 | [dnl 15 | dnl Get the cflags and libraries from the sdl-config script 16 | dnl 17 | AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], 18 | sdl_prefix="$withval", sdl_prefix="") 19 | AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], 20 | sdl_exec_prefix="$withval", sdl_exec_prefix="") 21 | AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], 22 | , enable_sdltest=yes) 23 | 24 | min_sdl_version=ifelse([$1], ,1.2.0,$1) 25 | 26 | if test "x$sdl_prefix$sdl_exec_prefix" = x ; then 27 | PKG_CHECK_MODULES([SDL], [sdl >= $min_sdl_version], 28 | [sdl_pc=yes], 29 | [sdl_pc=no]) 30 | else 31 | sdl_pc=no 32 | if test x$sdl_exec_prefix != x ; then 33 | sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" 34 | if test x${SDL_CONFIG+set} != xset ; then 35 | SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config 36 | fi 37 | fi 38 | if test x$sdl_prefix != x ; then 39 | sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" 40 | if test x${SDL_CONFIG+set} != xset ; then 41 | SDL_CONFIG=$sdl_prefix/bin/sdl-config 42 | fi 43 | fi 44 | fi 45 | 46 | if test "x$sdl_pc" = xyes ; then 47 | no_sdl="" 48 | SDL_CONFIG="pkg-config sdl" 49 | else 50 | as_save_PATH="$PATH" 51 | if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then 52 | PATH="$prefix/bin:$prefix/usr/bin:$PATH" 53 | fi 54 | AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH]) 55 | PATH="$as_save_PATH" 56 | AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) 57 | no_sdl="" 58 | 59 | if test "$SDL_CONFIG" = "no" ; then 60 | no_sdl=yes 61 | else 62 | SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags` 63 | SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs` 64 | 65 | sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \ 66 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 67 | sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \ 68 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 69 | sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ 70 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 71 | if test "x$enable_sdltest" = "xyes" ; then 72 | ac_save_CFLAGS="$CFLAGS" 73 | ac_save_CXXFLAGS="$CXXFLAGS" 74 | ac_save_LIBS="$LIBS" 75 | CFLAGS="$CFLAGS $SDL_CFLAGS" 76 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 77 | LIBS="$LIBS $SDL_LIBS" 78 | dnl 79 | dnl Now check if the installed SDL is sufficiently new. (Also sanity 80 | dnl checks the results of sdl-config to some extent 81 | dnl 82 | rm -f conf.sdltest 83 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 84 | #include 85 | #include 86 | #include "SDL.h" 87 | 88 | int main (int argc, char *argv[]) 89 | { 90 | int major, minor, micro; 91 | FILE *fp = fopen("conf.sdltest", "w"); 92 | 93 | if (fp) fclose(fp); 94 | 95 | if (sscanf("$min_sdl_version", "%d.%d.%d", &major, &minor, µ) != 3) { 96 | printf("%s, bad version string\n", "$min_sdl_version"); 97 | exit(1); 98 | } 99 | 100 | if (($sdl_major_version > major) || 101 | (($sdl_major_version == major) && ($sdl_minor_version > minor)) || 102 | (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) 103 | { 104 | return 0; 105 | } 106 | else 107 | { 108 | printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); 109 | printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); 110 | printf("*** best to upgrade to the required version.\n"); 111 | printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); 112 | printf("*** to point to the correct copy of sdl-config, and remove the file\n"); 113 | printf("*** config.cache before re-running configure\n"); 114 | return 1; 115 | } 116 | } 117 | 118 | ]])], [], [no_sdl=yes], [echo $ac_n "cross compiling; assumed OK... $ac_c"]) 119 | CFLAGS="$ac_save_CFLAGS" 120 | CXXFLAGS="$ac_save_CXXFLAGS" 121 | LIBS="$ac_save_LIBS" 122 | fi 123 | fi 124 | if test "x$no_sdl" = x ; then 125 | AC_MSG_RESULT(yes) 126 | else 127 | AC_MSG_RESULT(no) 128 | fi 129 | fi 130 | if test "x$no_sdl" = x ; then 131 | ifelse([$2], , :, [$2]) 132 | else 133 | if test "$SDL_CONFIG" = "no" ; then 134 | echo "*** The sdl-config script installed by SDL could not be found" 135 | echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" 136 | echo "*** your path, or set the SDL_CONFIG environment variable to the" 137 | echo "*** full path to sdl-config." 138 | else 139 | if test -f conf.sdltest ; then 140 | : 141 | else 142 | echo "*** Could not run SDL test program, checking why..." 143 | CFLAGS="$CFLAGS $SDL_CFLAGS" 144 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 145 | LIBS="$LIBS $SDL_LIBS" 146 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 147 | #include 148 | #include "SDL.h" 149 | 150 | int main(int argc, char *argv[]) 151 | { return 0; } 152 | #undef main 153 | #define main K_and_R_C_main 154 | ]], [[ return 0; ]])], 155 | [ echo "*** The test program compiled, but did not run. This usually means" 156 | echo "*** that the run-time linker is not finding SDL or finding the wrong" 157 | echo "*** version of SDL. If it is not finding SDL, you'll need to set your" 158 | echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 159 | echo "*** to the installed location Also, make sure you have run ldconfig if that" 160 | echo "*** is required on your system" 161 | echo "***" 162 | echo "*** If you have an old version installed, it is best to remove it, although" 163 | echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], 164 | [ echo "*** The test program failed to compile or link. See the file config.log for the" 165 | echo "*** exact error that occured. This usually means SDL was incorrectly installed" 166 | echo "*** or that you have moved SDL since it was installed. In the latter case, you" 167 | echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ]) 168 | CFLAGS="$ac_save_CFLAGS" 169 | CXXFLAGS="$ac_save_CXXFLAGS" 170 | LIBS="$ac_save_LIBS" 171 | fi 172 | fi 173 | SDL_CFLAGS="" 174 | SDL_LIBS="" 175 | ifelse([$3], , :, [$3]) 176 | fi 177 | AC_SUBST(SDL_CFLAGS) 178 | AC_SUBST(SDL_LIBS) 179 | rm -f conf.sdltest 180 | ]) 181 | -------------------------------------------------------------------------------- /m4/esd.m4: -------------------------------------------------------------------------------- 1 | # Configure paths for ESD 2 | # Manish Singh 98-9-30 3 | # stolen back from Frank Belew 4 | # stolen from Manish Singh 5 | # Shamelessly stolen from Owen Taylor 6 | # AdPlay/Unix updated some usage of deprecated macros 7 | 8 | dnl AM_PATH_ESD([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 9 | dnl Test for ESD, and define ESD_CFLAGS and ESD_LIBS 10 | dnl 11 | AC_DEFUN([AM_PATH_ESD], 12 | [dnl 13 | dnl Get the cflags and libraries from the esd-config script 14 | dnl 15 | AC_ARG_WITH(esd-prefix,[ --with-esd-prefix=PFX Prefix where ESD is installed (optional)], 16 | esd_prefix="$withval", esd_prefix="") 17 | AC_ARG_WITH(esd-exec-prefix,[ --with-esd-exec-prefix=PFX Exec prefix where ESD is installed (optional)], 18 | esd_exec_prefix="$withval", esd_exec_prefix="") 19 | AC_ARG_ENABLE(esdtest, [ --disable-esdtest Do not try to compile and run a test ESD program], 20 | , enable_esdtest=yes) 21 | 22 | if test x$esd_exec_prefix != x ; then 23 | esd_args="$esd_args --exec-prefix=$esd_exec_prefix" 24 | if test x${ESD_CONFIG+set} != xset ; then 25 | ESD_CONFIG=$esd_exec_prefix/bin/esd-config 26 | fi 27 | fi 28 | if test x$esd_prefix != x ; then 29 | esd_args="$esd_args --prefix=$esd_prefix" 30 | if test x${ESD_CONFIG+set} != xset ; then 31 | ESD_CONFIG=$esd_prefix/bin/esd-config 32 | fi 33 | fi 34 | 35 | AC_PATH_PROG(ESD_CONFIG, esd-config, no) 36 | min_esd_version=ifelse([$1], ,0.2.7,$1) 37 | AC_MSG_CHECKING(for ESD - version >= $min_esd_version) 38 | no_esd="" 39 | if test "$ESD_CONFIG" = "no" ; then 40 | no_esd=yes 41 | else 42 | AC_LANG_SAVE 43 | AC_LANG([C]) 44 | ESD_CFLAGS=`$ESD_CONFIG $esdconf_args --cflags` 45 | ESD_LIBS=`$ESD_CONFIG $esdconf_args --libs` 46 | 47 | esd_major_version=`$ESD_CONFIG $esd_args --version | \ 48 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 49 | esd_minor_version=`$ESD_CONFIG $esd_args --version | \ 50 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 51 | esd_micro_version=`$ESD_CONFIG $esd_config_args --version | \ 52 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 53 | if test "x$enable_esdtest" = "xyes" ; then 54 | ac_save_CFLAGS="$CFLAGS" 55 | ac_save_LIBS="$LIBS" 56 | CFLAGS="$CFLAGS $ESD_CFLAGS" 57 | LIBS="$LIBS $ESD_LIBS" 58 | dnl 59 | dnl Now check if the installed ESD is sufficiently new. (Also sanity 60 | dnl checks the results of esd-config to some extent 61 | dnl 62 | rm -f conf.esdtest 63 | AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 64 | #include 65 | #include 66 | #include 67 | #include 68 | ]],[[ 69 | char* 70 | my_strdup (char *str) 71 | { 72 | char *new_str; 73 | 74 | if (str) 75 | { 76 | new_str = malloc ((strlen (str) + 1) * sizeof(char)); 77 | strcpy (new_str, str); 78 | } 79 | else 80 | new_str = NULL; 81 | 82 | return new_str; 83 | } 84 | 85 | int main () 86 | { 87 | int major, minor, micro; 88 | char *tmp_version; 89 | 90 | system ("touch conf.esdtest"); 91 | 92 | /* HP/UX 9 (%@#!) writes to sscanf strings */ 93 | tmp_version = my_strdup("$min_esd_version"); 94 | if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { 95 | printf("%s, bad version string\n", "$min_esd_version"); 96 | exit(1); 97 | } 98 | 99 | if (($esd_major_version > major) || 100 | (($esd_major_version == major) && ($esd_minor_version > minor)) || 101 | (($esd_major_version == major) && ($esd_minor_version == minor) && ($esd_micro_version >= micro))) 102 | { 103 | return 0; 104 | } 105 | else 106 | { 107 | printf("\n*** 'esd-config --version' returned %d.%d.%d, but the minimum version\n", $esd_major_version, $esd_minor_version, $esd_micro_version); 108 | printf("*** of ESD required is %d.%d.%d. If esd-config is correct, then it is\n", major, minor, micro); 109 | printf("*** best to upgrade to the required version.\n"); 110 | printf("*** If esd-config was wrong, set the environment variable ESD_CONFIG\n"); 111 | printf("*** to point to the correct copy of esd-config, and remove the file\n"); 112 | printf("*** config.cache before re-running configure\n"); 113 | return 1; 114 | } 115 | } 116 | 117 | ]])],, no_esd=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) 118 | CFLAGS="$ac_save_CFLAGS" 119 | LIBS="$ac_save_LIBS" 120 | AC_LANG_RESTORE 121 | fi 122 | fi 123 | if test "x$no_esd" = x ; then 124 | AC_MSG_RESULT(yes) 125 | ifelse([$2], , :, [$2]) 126 | else 127 | AC_MSG_RESULT(no) 128 | if test "$ESD_CONFIG" = "no" ; then 129 | echo "*** The esd-config script installed by ESD could not be found" 130 | echo "*** If ESD was installed in PREFIX, make sure PREFIX/bin is in" 131 | echo "*** your path, or set the ESD_CONFIG environment variable to the" 132 | echo "*** full path to esd-config." 133 | else 134 | if test -f conf.esdtest ; then 135 | : 136 | else 137 | echo "*** Could not run ESD test program, checking why..." 138 | CFLAGS="$CFLAGS $ESD_CFLAGS" 139 | LIBS="$LIBS $ESD_LIBS" 140 | AC_LANG_SAVE 141 | AC_LANG([C]) 142 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 143 | #include 144 | #include 145 | ]],[[ return 0; ]])], 146 | [ echo "*** The test program compiled, but did not run. This usually means" 147 | echo "*** that the run-time linker is not finding ESD or finding the wrong" 148 | echo "*** version of ESD. If it is not finding ESD, you'll need to set your" 149 | echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 150 | echo "*** to the installed location Also, make sure you have run ldconfig if that" 151 | echo "*** is required on your system" 152 | echo "***" 153 | echo "*** If you have an old version installed, it is best to remove it, although" 154 | echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], 155 | [ echo "*** The test program failed to compile or link. See the file config.log for the" 156 | echo "*** exact error that occured. This usually means ESD was incorrectly installed" 157 | echo "*** or that you have moved ESD since it was installed. In the latter case, you" 158 | echo "*** may want to edit the esd-config script: $ESD_CONFIG" ]) 159 | CFLAGS="$ac_save_CFLAGS" 160 | LIBS="$ac_save_LIBS" 161 | AC_LANG_RESTORE 162 | fi 163 | fi 164 | ESD_CFLAGS="" 165 | ESD_LIBS="" 166 | ifelse([$3], , :, [$3]) 167 | fi 168 | AC_SUBST(ESD_CFLAGS) 169 | AC_SUBST(ESD_LIBS) 170 | rm -f conf.esdtest 171 | ]) 172 | 173 | dnl AM_ESD_SUPPORTS_MULTIPLE_RECORD([ACTION-IF-SUPPORTS [, ACTION-IF-NOT-SUPPORTS]]) 174 | dnl Test, whether esd supports multiple recording clients (version >=0.2.21) 175 | dnl 176 | AC_DEFUN([AM_ESD_SUPPORTS_MULTIPLE_RECORD], 177 | [dnl 178 | AC_MSG_NOTICE([whether installed esd version supports multiple recording clients]) 179 | ac_save_ESD_CFLAGS="$ESD_CFLAGS" 180 | ac_save_ESD_LIBS="$ESD_LIBS" 181 | AM_PATH_ESD(0.2.21, 182 | ifelse([$1], , [ 183 | AM_CONDITIONAL(ESD_SUPPORTS_MULTIPLE_RECORD, true) 184 | AC_DEFINE(ESD_SUPPORTS_MULTIPLE_RECORD, 1, 185 | [Define if you have esound with support of multiple recording clients.])], 186 | [$1]), 187 | ifelse([$2], , [AM_CONDITIONAL(ESD_SUPPORTS_MULTIPLE_RECORD, false)], [$2]) 188 | if test "x$ac_save_ESD_CFLAGS" != x ; then 189 | ESD_CFLAGS="$ac_save_ESD_CFLAGS" 190 | fi 191 | if test "x$ac_save_ESD_LIBS" != x ; then 192 | ESD_LIBS="$ac_save_ESD_LIBS" 193 | fi 194 | ) 195 | ]) 196 | -------------------------------------------------------------------------------- /m4/sdl2.m4: -------------------------------------------------------------------------------- 1 | # Configure paths for SDL 2 | # Sam Lantinga 9/21/99 3 | # stolen from Manish Singh 4 | # stolen back from Frank Belew 5 | # stolen from Manish Singh 6 | # Shamelessly stolen from Owen Taylor 7 | # 8 | # Changelog: 9 | # * also look for SDL2.framework under Mac OS X 10 | # * removed HP/UX 9 support. 11 | # * updated for newer autoconf. 12 | 13 | # serial 2 14 | 15 | dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 16 | dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS 17 | dnl 18 | AC_DEFUN([AM_PATH_SDL2], 19 | [dnl 20 | dnl Get the cflags and libraries from the sdl2-config script 21 | dnl 22 | AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], 23 | sdl_prefix="$withval", sdl_prefix="") 24 | AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], 25 | sdl_exec_prefix="$withval", sdl_exec_prefix="") 26 | AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], 27 | , enable_sdltest=yes) 28 | AC_ARG_ENABLE(sdlframework, [ --disable-sdlframework Do not search for SDL2.framework], 29 | , search_sdl_framework=yes) 30 | 31 | AC_ARG_VAR(SDL2_FRAMEWORK, [Path to SDL2.framework]) 32 | 33 | min_sdl_version=ifelse([$1], ,2.0.0,$1) 34 | 35 | if test "x$sdl_prefix$sdl_exec_prefix" = x ; then 36 | PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version], 37 | [sdl_pc=yes], 38 | [sdl_pc=no]) 39 | else 40 | sdl_pc=no 41 | if test x$sdl_exec_prefix != x ; then 42 | sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" 43 | if test x${SDL2_CONFIG+set} != xset ; then 44 | SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config 45 | fi 46 | fi 47 | if test x$sdl_prefix != x ; then 48 | sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" 49 | if test x${SDL2_CONFIG+set} != xset ; then 50 | SDL2_CONFIG=$sdl_prefix/bin/sdl2-config 51 | fi 52 | fi 53 | fi 54 | 55 | if test "x$sdl_pc" = xyes ; then 56 | no_sdl="" 57 | SDL2_CONFIG="pkg-config sdl2" 58 | else 59 | as_save_PATH="$PATH" 60 | if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then 61 | PATH="$prefix/bin:$prefix/usr/bin:$PATH" 62 | fi 63 | AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH]) 64 | PATH="$as_save_PATH" 65 | no_sdl="" 66 | 67 | if test "$SDL2_CONFIG" = "no" -a "x$search_sdl_framework" = "xyes"; then 68 | AC_MSG_CHECKING(for SDL2.framework) 69 | if test "x$SDL2_FRAMEWORK" != x; then 70 | sdl_framework=$SDL2_FRAMEWORK 71 | else 72 | for d in / ~/ /System/; do 73 | if test -d "${d}Library/Frameworks/SDL2.framework"; then 74 | sdl_framework="${d}Library/Frameworks/SDL2.framework" 75 | fi 76 | done 77 | fi 78 | 79 | if test x"$sdl_framework" != x && test -d "$sdl_framework"; then 80 | AC_MSG_RESULT($sdl_framework) 81 | sdl_framework_dir=`dirname $sdl_framework` 82 | SDL_CFLAGS="-F$sdl_framework_dir -Wl,-framework,SDL2 -I$sdl_framework/include" 83 | SDL_LIBS="-F$sdl_framework_dir -Wl,-framework,SDL2" 84 | else 85 | no_sdl=yes 86 | fi 87 | fi 88 | 89 | if test "$SDL2_CONFIG" != "no"; then 90 | if test "x$sdl_pc" = "xno"; then 91 | AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) 92 | SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags` 93 | SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs` 94 | fi 95 | 96 | sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \ 97 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 98 | sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \ 99 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 100 | sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \ 101 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 102 | if test "x$enable_sdltest" = "xyes" ; then 103 | ac_save_CFLAGS="$CFLAGS" 104 | ac_save_CXXFLAGS="$CXXFLAGS" 105 | ac_save_LIBS="$LIBS" 106 | CFLAGS="$CFLAGS $SDL_CFLAGS" 107 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 108 | LIBS="$LIBS $SDL_LIBS" 109 | dnl 110 | dnl Now check if the installed SDL is sufficiently new. (Also sanity 111 | dnl checks the results of sdl2-config to some extent 112 | dnl 113 | rm -f conf.sdltest 114 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 115 | #include 116 | #include 117 | #include "SDL.h" 118 | 119 | int main (int argc, char *argv[]) 120 | { 121 | int major, minor, micro; 122 | FILE *fp = fopen("conf.sdltest", "w"); 123 | 124 | if (fp) fclose(fp); 125 | 126 | if (sscanf("$min_sdl_version", "%d.%d.%d", &major, &minor, µ) != 3) { 127 | printf("%s, bad version string\n", "$min_sdl_version"); 128 | exit(1); 129 | } 130 | 131 | if (($sdl_major_version > major) || 132 | (($sdl_major_version == major) && ($sdl_minor_version > minor)) || 133 | (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) 134 | { 135 | return 0; 136 | } 137 | else 138 | { 139 | printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); 140 | printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro); 141 | printf("*** best to upgrade to the required version.\n"); 142 | printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n"); 143 | printf("*** to point to the correct copy of sdl2-config, and remove the file\n"); 144 | printf("*** config.cache before re-running configure\n"); 145 | return 1; 146 | } 147 | } 148 | 149 | ]])], [], [no_sdl=yes], [echo $ac_n "cross compiling; assumed OK... $ac_c"]) 150 | CFLAGS="$ac_save_CFLAGS" 151 | CXXFLAGS="$ac_save_CXXFLAGS" 152 | LIBS="$ac_save_LIBS" 153 | 154 | fi 155 | if test "x$sdl_pc" = "xno"; then 156 | if test "x$no_sdl" = "xyes"; then 157 | AC_MSG_RESULT(no) 158 | else 159 | AC_MSG_RESULT(yes) 160 | fi 161 | fi 162 | fi 163 | fi 164 | if test "x$no_sdl" = x ; then 165 | ifelse([$2], , :, [$2]) 166 | else 167 | if test "$SDL2_CONFIG" = "no" ; then 168 | echo "*** The sdl2-config script installed by SDL could not be found" 169 | echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" 170 | echo "*** your path, or set the SDL2_CONFIG environment variable to the" 171 | echo "*** full path to sdl2-config." 172 | else 173 | if test -f conf.sdltest ; then 174 | : 175 | else 176 | echo "*** Could not run SDL test program, checking why..." 177 | CFLAGS="$CFLAGS $SDL_CFLAGS" 178 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 179 | LIBS="$LIBS $SDL_LIBS" 180 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 181 | #include 182 | #include "SDL.h" 183 | 184 | int main(int argc, char *argv[]) 185 | { return 0; } 186 | #undef main 187 | #define main K_and_R_C_main 188 | ]], [[ return 0; ]])], 189 | [ echo "*** The test program compiled, but did not run. This usually means" 190 | echo "*** that the run-time linker is not finding SDL or finding the wrong" 191 | echo "*** version of SDL. If it is not finding SDL, you'll need to set your" 192 | echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 193 | echo "*** to the installed location Also, make sure you have run ldconfig if that" 194 | echo "*** is required on your system" 195 | echo "***" 196 | echo "*** If you have an old version installed, it is best to remove it, although" 197 | echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], 198 | [ echo "*** The test program failed to compile or link. See the file config.log for the" 199 | echo "*** exact error that occured. This usually means SDL was incorrectly installed" 200 | echo "*** or that you have moved SDL since it was installed. In the latter case, you" 201 | echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ]) 202 | CFLAGS="$ac_save_CFLAGS" 203 | CXXFLAGS="$ac_save_CXXFLAGS" 204 | LIBS="$ac_save_LIBS" 205 | fi 206 | fi 207 | SDL_CFLAGS="" 208 | SDL_LIBS="" 209 | ifelse([$3], , :, [$3]) 210 | fi 211 | AC_SUBST(SDL_CFLAGS) 212 | AC_SUBST(SDL_LIBS) 213 | rm -f conf.sdltest 214 | ]) 215 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # Tell autoconf we're compiling a C++ program using automake and libtool. 2 | AC_INIT([adplay],[1.10]) 3 | AC_CONFIG_SRCDIR(src/adplay.cc) 4 | AC_CONFIG_FILES(Makefile src/Makefile doc/Makefile) 5 | AC_CANONICAL_TARGET 6 | AM_INIT_AUTOMAKE 7 | AC_CONFIG_MACRO_DIRS([m4]) 8 | AC_CONFIG_HEADERS([src/config.h]) 9 | LT_INIT 10 | AC_LANG(C++) 11 | 12 | # Check if we got a sane C/C++ compilation environment. 13 | AC_PROG_INSTALL 14 | AC_PROG_CC 15 | AC_PROG_CXX 16 | AC_PROG_CPP 17 | AC_PROG_CXXCPP 18 | 19 | # Nothing works without these libraries... 20 | AC_CHECK_LIB(stdc++,main,,AC_MSG_ERROR([libstdc++ not installed])) 21 | PKG_CHECK_MODULES([adplug], [adplug >= 2.0],,[ 22 | AC_MSG_WARN([You seem to be using a version of AdPlug prior to 2.0. \ 23 | I will try to do the old-style library search for which i cannot check \ 24 | versions. Please bear in mind that i am requiring at least version 1.4.]) 25 | AC_CHECK_LIB(adplug,main,,AC_MSG_ERROR([*** AdPlug not installed ***]))]) 26 | 27 | # Check if getopt header is installed on this system 28 | AC_CHECK_HEADERS([getopt.h], , 29 | AC_SUBST(GETOPT_SOURCES, [getopt.c getopt1.c getopt.h])) 30 | 31 | # Save compiler flags and set up for compiling test programs 32 | oldlibs="$LIBS" 33 | oldcppflags="$CPPFLAGS" 34 | LIBS="$LDFLAGS $adplug_LIBS" 35 | CPPFLAGS="$CPPFLAGS $adplug_CFLAGS" 36 | 37 | # Check if AdPlug is installed and linked correctly 38 | AC_MSG_CHECKING([whether AdPlug is linked correctly]) 39 | AC_LINK_IFELSE([AC_LANG_PROGRAM([#include 40 | 41 | class Testplayer: public CPlayer 42 | { 43 | public: 44 | Testplayer(): CPlayer(NULL) {} 45 | bool load(const std::string &f, const CFileProvider &fp) { return false; } 46 | bool update() { return false; } 47 | float getrefresh() { return 0; } 48 | std::string gettype() { return std::string(); } 49 | void rewind(int s) {} 50 | }; 51 | 52 | Testplayer p;], [p.getrefresh();])], 53 | AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]); AC_MSG_ERROR([Unable to compile a program using AdPlug. Please check to ensure AdPlug is installed correctly.]) ) 54 | 55 | # Check if AdPlug supports the new getsubsong() method 56 | AC_MSG_CHECKING([whether AdPlug supports the getsubsong() method]) 57 | AC_LINK_IFELSE([AC_LANG_PROGRAM([#include 58 | 59 | class Testplayer: public CPlayer 60 | { 61 | public: 62 | Testplayer(): CPlayer(NULL) {} 63 | bool load(const std::string &f, const CFileProvider &fp) { return false; } 64 | bool update() { return false; } 65 | float getrefresh() { return 0; } 66 | std::string gettype() { return std::string(); } 67 | void rewind(int s) {} 68 | }; 69 | 70 | Testplayer p;], [p.getsubsong();])], 71 | AC_DEFINE(HAVE_ADPLUG_GETSUBSONG,, [Defined if AdPlug supports the getsubsong() method]) 72 | AC_MSG_RESULT([yes]), AC_MSG_RESULT([no])) 73 | 74 | # Check if AdPlug supports the new surround/harmonic synth 75 | AC_MSG_CHECKING([whether AdPlug supports the surround/harmonic synth]) 76 | AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], [CSurroundopl *dummy;])], 77 | AC_DEFINE(HAVE_ADPLUG_SURROUND,, [Defined if AdPlug supports the surround/harmonic synth]) 78 | AC_MSG_RESULT([yes]), AC_MSG_RESULT([no - AdPlug >= 2.2 required])) 79 | 80 | # Check if AdPlug supports NukedOPL 81 | AC_MSG_CHECKING([whether AdPlug supports the NukedOPL synth]) 82 | AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], [CNemuopl *dummy;])], 83 | AC_DEFINE(HAVE_ADPLUG_NUKEDOPL,, [Defined if AdPlug supports the NukedOPL synth]) 84 | AC_MSG_RESULT([yes]), AC_MSG_RESULT([no - AdPlug >= 2.3 required])) 85 | 86 | # Restore flags after compiling test programs 87 | LIBS="$oldlibs" 88 | CPPFLAGS="$oldcppflags" 89 | 90 | ##### Output mechanism checks ##### 91 | # These checks enable or disable certain output mechanisms, 92 | # depending on system facilities and user requests. 93 | 94 | # Define user option arguments 95 | AC_ARG_ENABLE([output-oss],AS_HELP_STRING([--disable-output-oss],[Disable OSS output])) 96 | AC_ARG_ENABLE([output-null],AS_HELP_STRING([--disable-output-null],[Disable null output])) 97 | AC_ARG_ENABLE([output-raw],AS_HELP_STRING([--disable-output-raw],[Disable RAW file writer])) 98 | AC_ARG_ENABLE([output-disk],AS_HELP_STRING([--disable-output-disk],[Disable disk writer])) 99 | AC_ARG_ENABLE([output-esound],AS_HELP_STRING([--disable-output-esound],[Disable EsounD output])) 100 | AC_ARG_ENABLE([output-qsa],AS_HELP_STRING([--disable-output-qsa],[Disable QSA output])) 101 | AC_ARG_ENABLE([output-sdl],AS_HELP_STRING([--disable-output-sdl],[Disable SDL output])) 102 | AC_ARG_ENABLE([output-alsa],AS_HELP_STRING([--disable-output-alsa],[Disable ALSA output])) 103 | AC_ARG_ENABLE([output-ao],AS_HELP_STRING([--disable-output-ao],[Disable AO output])) 104 | # Check if we can compile the enabled drivers: 105 | # OSS driver 106 | if test ${enable_output_oss:=yes} = yes; then 107 | AC_MSG_CHECKING([for OSS headers]) 108 | AC_PREPROC_IFELSE([AC_LANG_SOURCE([[ 109 | #include 110 | #include 111 | #include 112 | ]])],[ 113 | AC_DEFINE(DRIVER_OSS,1,[Build OSS driver]) 114 | drivers=$drivers' oss.$(OBJEXT)' 115 | AC_MSG_RESULT([found]) 116 | ],[ 117 | enable_output_oss=no 118 | AC_MSG_RESULT([not found -- OSS output disabled]) 119 | ]) 120 | fi 121 | 122 | # AO output 123 | if test ${enable_output_ao:=yes} = yes; then 124 | XIPH_PATH_AO(AC_DEFINE(DRIVER_AO,1,[Build AO output]) 125 | drivers=$drivers' ao.${OBJEXT}', 126 | enable_output_ao=no 127 | AC_MSG_RESULT([*** AO (libao) not installed ***])) 128 | fi 129 | 130 | # Null output 131 | if test ${enable_output_null:=yes} = yes; then 132 | AC_DEFINE(DRIVER_NULL,1,[Build null output]) 133 | fi 134 | 135 | # Disk writer 136 | if test ${enable_output_disk:=yes} = yes; then 137 | AC_DEFINE(DRIVER_DISK,1,[Build disk writer]) 138 | drivers=$drivers' disk.$(OBJEXT)' 139 | fi 140 | 141 | # RAW file writer 142 | if test ${enable_output_raw:=yes} = yes; then 143 | AC_DEFINE(DRIVER_RAW,1,[Build disk writer]) 144 | fi 145 | 146 | # EsounD output 147 | if test ${enable_output_esound:=yes} = yes; then 148 | AM_PATH_ESD(0.2.8, 149 | AC_DEFINE(DRIVER_ESOUND,1,[Build EsounD output]) 150 | drivers=$drivers' esound.$(OBJEXT)', 151 | enable_output_esound=no 152 | AC_MSG_RESULT([*** EsounD (libesd) >= 0.2.8 not installed ***])) 153 | fi 154 | 155 | # QSA driver 156 | if test ${enable_output_qsa:=yes} = yes; then 157 | AC_MSG_CHECKING([for QSA headers]) 158 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 159 | #include 160 | #include 161 | ]], [[ 162 | int arg=snd_pcm_open_preferred(NULL, NULL, NULL, 0); 163 | ]])],[ 164 | have_qsa=yes 165 | ],[]) 166 | if test x$have_qsa = xyes; then 167 | AC_DEFINE(DRIVER_QSA,1,[Build QSA driver]) 168 | drivers=$drivers' qsa.$(OBJEXT)' 169 | QSA_LIBS=-lasound 170 | AC_SUBST(QSA_LIBS) 171 | AC_MSG_RESULT([found]) 172 | else 173 | enable_output_qsa=no 174 | QSA_LIBS="" 175 | AC_SUBST(QSA_LIBS) 176 | AC_MSG_RESULT([not found -- QSA output disabled]) 177 | fi 178 | fi 179 | 180 | # SDL output 181 | if test ${enable_output_sdl:=yes} = yes; then 182 | AC_LANG_PUSH(C) 183 | AM_PATH_SDL2(["2.0.0"], 184 | AC_DEFINE(HAVE_SDL_H, 1, [Define to 1 if you have the "SDL.h" header file]) 185 | AC_DEFINE(DRIVER_SDL, 1, [Build SDL2 output]) 186 | drivers=$drivers' sdl.$(OBJEXT)', 187 | try_sdl12=yes 188 | AC_MSG_RESULT([*** SDL libsdl2 >= 2.0.0 not installed ***]) 189 | ) 190 | AC_LANG_POP(C) 191 | 192 | dnl we can not put AM_PATH_SDL directly into the ACTION-IF-NOT-FOUND of AM_PATH_SDL2 193 | dnl due to some m4 macro recursion causing a bad ./configure script to be generated 194 | if test ${try_sdl12:=no} = yes; then 195 | AC_LANG_PUSH(C) 196 | AM_PATH_SDL(["1.2.0"], 197 | AC_DEFINE(HAVE_SDL_H, 1, [Define to 1 if you have the "SDL.h" header file]) 198 | AC_DEFINE(DRIVER_SDL, 1, [Build SDL1.x output]) 199 | drivers=$drivers' sdl.$(OBJEXT)', 200 | enable_output_sdl=no 201 | AC_MSG_RESULT([*** SDL libsdl >= 1.2.0 not installed ***]) 202 | ) 203 | AC_LANG_POP(C) 204 | fi 205 | dnl strip away options that would turn our application from console to a windows GUI application 206 | SDL_CFLAGS=`echo $SDL_CFLAGS |sed -e 's/-Dmain=SDL_main//g'` 207 | SDL_LIBS=`echo $SDL_LIBS | sed -e 's/-mwindows/-mconsole/g' -e 's/-lSDLmain//g' -e 's/-lSDL2main//g'` 208 | fi 209 | 210 | # ALSA output 211 | if test ${enable_output_alsa:=yes} = yes; then 212 | AM_PATH_ALSA(0.9.1, 213 | AC_DEFINE(DRIVER_ALSA,1,[Build ALSA output]) 214 | drivers=$drivers' alsa.${OBJEXT}', 215 | enable_output_alsa=no 216 | AC_MSG_RESULT([*** ALSA (libasound) >= 0.9.1 not installed ***])) 217 | fi 218 | 219 | 220 | 221 | AC_SUBST([drivers]) 222 | 223 | AC_OUTPUT 224 | 225 | # Display user informative configuration output 226 | echo "" 227 | echo "Configuration:" 228 | echo "Install path: ${prefix}" 229 | echo "" 230 | echo "Build output mechanisms:" 231 | echo "OSS output (oss): ${enable_output_oss}" 232 | echo "Null output (null): ${enable_output_null}" 233 | echo "RAW file writer (raw): ${enable_output_raw}" 234 | echo "Disk writer (disk): ${enable_output_disk}" 235 | echo "EsounD output (esound): ${enable_output_esound}" 236 | echo "QSA output (qsa): ${enable_output_qsa}" 237 | echo "SDL output (sdl): ${enable_output_sdl}" 238 | echo "ALSA output (alsa): ${enable_output_alsa}" 239 | echo "Libao output (ao): ${enable_output_ao}" 240 | -------------------------------------------------------------------------------- /m4/pkg.m4: -------------------------------------------------------------------------------- 1 | # pkg.m4 - Macros to locate and use pkg-config. -*- Autoconf -*- 2 | # serial 12 (pkg-config-0.29.2) 3 | 4 | dnl Copyright © 2004 Scott James Remnant . 5 | dnl Copyright © 2012-2015 Dan Nicholson 6 | dnl 7 | dnl This program is free software; you can redistribute it and/or modify 8 | dnl it under the terms of the GNU General Public License as published by 9 | dnl the Free Software Foundation; either version 2 of the License, or 10 | dnl (at your option) any later version. 11 | dnl 12 | dnl This program is distributed in the hope that it will be useful, but 13 | dnl WITHOUT ANY WARRANTY; without even the implied warranty of 14 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | dnl General Public License for more details. 16 | dnl 17 | dnl You should have received a copy of the GNU General Public License 18 | dnl along with this program; if not, write to the Free Software 19 | dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | dnl 02111-1307, USA. 21 | dnl 22 | dnl As a special exception to the GNU General Public License, if you 23 | dnl distribute this file as part of a program that contains a 24 | dnl configuration script generated by Autoconf, you may include it under 25 | dnl the same distribution terms that you use for the rest of that 26 | dnl program. 27 | 28 | dnl PKG_PREREQ(MIN-VERSION) 29 | dnl ----------------------- 30 | dnl Since: 0.29 31 | dnl 32 | dnl Verify that the version of the pkg-config macros are at least 33 | dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's 34 | dnl installed version of pkg-config, this checks the developer's version 35 | dnl of pkg.m4 when generating configure. 36 | dnl 37 | dnl To ensure that this macro is defined, also add: 38 | dnl m4_ifndef([PKG_PREREQ], 39 | dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])]) 40 | dnl 41 | dnl See the "Since" comment for each macro you use to see what version 42 | dnl of the macros you require. 43 | m4_defun([PKG_PREREQ], 44 | [m4_define([PKG_MACROS_VERSION], [0.29.2]) 45 | m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1, 46 | [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])]) 47 | ])dnl PKG_PREREQ 48 | 49 | dnl PKG_PROG_PKG_CONFIG([MIN-VERSION]) 50 | dnl ---------------------------------- 51 | dnl Since: 0.16 52 | dnl 53 | dnl Search for the pkg-config tool and set the PKG_CONFIG variable to 54 | dnl first found in the path. Checks that the version of pkg-config found 55 | dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is 56 | dnl used since that's the first version where most current features of 57 | dnl pkg-config existed. 58 | AC_DEFUN([PKG_PROG_PKG_CONFIG], 59 | [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) 60 | m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) 61 | m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) 62 | AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) 63 | AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) 64 | AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) 65 | if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then 66 | AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) 67 | fi 68 | if test -n "$PKG_CONFIG"; then 69 | _pkg_min_version=m4_default([$1], [0.9.0]) 70 | AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) 71 | if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then 72 | AC_MSG_RESULT([yes]) 73 | else 74 | AC_MSG_RESULT([no]) 75 | PKG_CONFIG="" 76 | fi 77 | fi[]dnl 78 | ])dnl PKG_PROG_PKG_CONFIG 79 | 80 | dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 81 | dnl ------------------------------------------------------------------- 82 | dnl Since: 0.18 83 | dnl 84 | dnl Check to see whether a particular set of modules exists. Similar to 85 | dnl PKG_CHECK_MODULES(), but does not set variables or print errors. 86 | dnl 87 | dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 88 | dnl only at the first occurrence in configure.ac, so if the first place 89 | dnl it's called might be skipped (such as if it is within an "if", you 90 | dnl have to call PKG_CHECK_EXISTS manually 91 | AC_DEFUN([PKG_CHECK_EXISTS], 92 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 93 | if test -n "$PKG_CONFIG" && \ 94 | AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then 95 | m4_default([$2], [:]) 96 | m4_ifvaln([$3], [else 97 | $3])dnl 98 | fi]) 99 | 100 | dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) 101 | dnl --------------------------------------------- 102 | dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting 103 | dnl pkg_failed based on the result. 104 | m4_define([_PKG_CONFIG], 105 | [if test -n "$$1"; then 106 | pkg_cv_[]$1="$$1" 107 | elif test -n "$PKG_CONFIG"; then 108 | PKG_CHECK_EXISTS([$3], 109 | [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` 110 | test "x$?" != "x0" && pkg_failed=yes ], 111 | [pkg_failed=yes]) 112 | else 113 | pkg_failed=untried 114 | fi[]dnl 115 | ])dnl _PKG_CONFIG 116 | 117 | dnl _PKG_SHORT_ERRORS_SUPPORTED 118 | dnl --------------------------- 119 | dnl Internal check to see if pkg-config supports short errors. 120 | AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], 121 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 122 | if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then 123 | _pkg_short_errors_supported=yes 124 | else 125 | _pkg_short_errors_supported=no 126 | fi[]dnl 127 | ])dnl _PKG_SHORT_ERRORS_SUPPORTED 128 | 129 | 130 | dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], 131 | dnl [ACTION-IF-NOT-FOUND]) 132 | dnl -------------------------------------------------------------- 133 | dnl Since: 0.4.0 134 | dnl 135 | dnl Note that if there is a possibility the first call to 136 | dnl PKG_CHECK_MODULES might not happen, you should be sure to include an 137 | dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac 138 | AC_DEFUN([PKG_CHECK_MODULES], 139 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 140 | AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl 141 | AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl 142 | pkg_failed=no 143 | AC_MSG_CHECKING([for $2]) 144 | _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) 145 | _PKG_CONFIG([$1][_LIBS], [libs], [$2]) 146 | m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS 147 | and $1[]_LIBS to avoid the need to call pkg-config. 148 | See the pkg-config man page for more details.]) 149 | if test $pkg_failed = yes; then 150 | AC_MSG_RESULT([no]) 151 | _PKG_SHORT_ERRORS_SUPPORTED 152 | if test $_pkg_short_errors_supported = yes; then 153 | $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` 154 | else 155 | $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` 156 | fi 157 | # Put the nasty error message in config.log where it belongs 158 | echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD 159 | m4_default([$4], [AC_MSG_ERROR( 160 | [Package requirements ($2) were not met: 161 | $$1_PKG_ERRORS 162 | Consider adjusting the PKG_CONFIG_PATH environment variable if you 163 | installed software in a non-standard prefix. 164 | _PKG_TEXT])[]dnl 165 | ]) 166 | elif test $pkg_failed = untried; then 167 | AC_MSG_RESULT([no]) 168 | m4_default([$4], [AC_MSG_FAILURE( 169 | [The pkg-config script could not be found or is too old. Make sure it 170 | is in your PATH or set the PKG_CONFIG environment variable to the full 171 | path to pkg-config. 172 | _PKG_TEXT 173 | To get pkg-config, see .])[]dnl 174 | ]) 175 | else 176 | $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS 177 | $1[]_LIBS=$pkg_cv_[]$1[]_LIBS 178 | AC_MSG_RESULT([yes]) 179 | $3 180 | fi[]dnl 181 | ])dnl PKG_CHECK_MODULES 182 | 183 | 184 | dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], 185 | dnl [ACTION-IF-NOT-FOUND]) 186 | dnl --------------------------------------------------------------------- 187 | dnl Since: 0.29 188 | dnl 189 | dnl Checks for existence of MODULES and gathers its build flags with 190 | dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags 191 | dnl and VARIABLE-PREFIX_LIBS from --libs. 192 | dnl 193 | dnl Note that if there is a possibility the first call to 194 | dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to 195 | dnl include an explicit call to PKG_PROG_PKG_CONFIG in your 196 | dnl configure.ac. 197 | AC_DEFUN([PKG_CHECK_MODULES_STATIC], 198 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 199 | _save_PKG_CONFIG=$PKG_CONFIG 200 | PKG_CONFIG="$PKG_CONFIG --static" 201 | PKG_CHECK_MODULES($@) 202 | PKG_CONFIG=$_save_PKG_CONFIG[]dnl 203 | ])dnl PKG_CHECK_MODULES_STATIC 204 | 205 | 206 | dnl PKG_INSTALLDIR([DIRECTORY]) 207 | dnl ------------------------- 208 | dnl Since: 0.27 209 | dnl 210 | dnl Substitutes the variable pkgconfigdir as the location where a module 211 | dnl should install pkg-config .pc files. By default the directory is 212 | dnl $libdir/pkgconfig, but the default can be changed by passing 213 | dnl DIRECTORY. The user can override through the --with-pkgconfigdir 214 | dnl parameter. 215 | AC_DEFUN([PKG_INSTALLDIR], 216 | [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) 217 | m4_pushdef([pkg_description], 218 | [pkg-config installation directory @<:@]pkg_default[@:>@]) 219 | AC_ARG_WITH([pkgconfigdir], 220 | [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, 221 | [with_pkgconfigdir=]pkg_default) 222 | AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) 223 | m4_popdef([pkg_default]) 224 | m4_popdef([pkg_description]) 225 | ])dnl PKG_INSTALLDIR 226 | 227 | 228 | dnl PKG_NOARCH_INSTALLDIR([DIRECTORY]) 229 | dnl -------------------------------- 230 | dnl Since: 0.27 231 | dnl 232 | dnl Substitutes the variable noarch_pkgconfigdir as the location where a 233 | dnl module should install arch-independent pkg-config .pc files. By 234 | dnl default the directory is $datadir/pkgconfig, but the default can be 235 | dnl changed by passing DIRECTORY. The user can override through the 236 | dnl --with-noarch-pkgconfigdir parameter. 237 | AC_DEFUN([PKG_NOARCH_INSTALLDIR], 238 | [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) 239 | m4_pushdef([pkg_description], 240 | [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) 241 | AC_ARG_WITH([noarch-pkgconfigdir], 242 | [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, 243 | [with_noarch_pkgconfigdir=]pkg_default) 244 | AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) 245 | m4_popdef([pkg_default]) 246 | m4_popdef([pkg_description]) 247 | ])dnl PKG_NOARCH_INSTALLDIR 248 | 249 | 250 | dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, 251 | dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 252 | dnl ------------------------------------------- 253 | dnl Since: 0.28 254 | dnl 255 | dnl Retrieves the value of the pkg-config variable for the given module. 256 | AC_DEFUN([PKG_CHECK_VAR], 257 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 258 | AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl 259 | _PKG_CONFIG([$1], [variable="][$3]["], [$2]) 260 | AS_VAR_COPY([$1], [pkg_cv_][$1]) 261 | AS_VAR_IF([$1], [""], [$5], [$4])dnl 262 | ])dnl PKG_CHECK_VAR 263 | 264 | dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES, 265 | dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND], 266 | dnl [DESCRIPTION], [DEFAULT]) 267 | dnl ------------------------------------------ 268 | dnl 269 | dnl Prepare a "--with-" configure option using the lowercase 270 | dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and 271 | dnl PKG_CHECK_MODULES in a single macro. 272 | AC_DEFUN([PKG_WITH_MODULES], 273 | [ 274 | m4_pushdef([with_arg], m4_tolower([$1])) 275 | m4_pushdef([description], 276 | [m4_default([$5], [build with ]with_arg[ support])]) 277 | m4_pushdef([def_arg], [m4_default([$6], [auto])]) 278 | m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes]) 279 | m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no]) 280 | m4_case(def_arg, 281 | [yes],[m4_pushdef([with_without], [--without-]with_arg)], 282 | [m4_pushdef([with_without],[--with-]with_arg)]) 283 | AC_ARG_WITH(with_arg, 284 | AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),, 285 | [AS_TR_SH([with_]with_arg)=def_arg]) 286 | AS_CASE([$AS_TR_SH([with_]with_arg)], 287 | [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)], 288 | [auto],[PKG_CHECK_MODULES([$1],[$2], 289 | [m4_n([def_action_if_found]) $3], 290 | [m4_n([def_action_if_not_found]) $4])]) 291 | m4_popdef([with_arg]) 292 | m4_popdef([description]) 293 | m4_popdef([def_arg]) 294 | ])dnl PKG_WITH_MODULES 295 | 296 | dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES, 297 | dnl [DESCRIPTION], [DEFAULT]) 298 | dnl ----------------------------------------------- 299 | dnl 300 | dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES 301 | dnl check._[VARIABLE-PREFIX] is exported as make variable. 302 | AC_DEFUN([PKG_HAVE_WITH_MODULES], 303 | [ 304 | PKG_WITH_MODULES([$1],[$2],,,[$3],[$4]) 305 | AM_CONDITIONAL([HAVE_][$1], 306 | [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"]) 307 | ])dnl PKG_HAVE_WITH_MODULES 308 | 309 | dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES, 310 | dnl [DESCRIPTION], [DEFAULT]) 311 | dnl ------------------------------------------------------ 312 | dnl 313 | dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after 314 | dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make 315 | dnl and preprocessor variable. 316 | AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES], 317 | [ 318 | PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4]) 319 | AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"], 320 | [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])]) 321 | ])dnl PKG_HAVE_DEFINE_WITH_MODULES 322 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /src/adplay.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AdPlay/UNIX - OPL2 audio player 3 | * Copyright (C) 2001 - 2017, 2024 Simon Peter 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /* 32 | * Sun systems declare getopt in unistd.h, 33 | * other systems (Linux, Apple) use getopt.h. 34 | */ 35 | #if (defined(__SVR4) && defined(__sun)) 36 | # include 37 | #else 38 | # ifdef HAVE_GETOPT_H 39 | # include 40 | # else 41 | # include "getopt.h" 42 | // ALSA now includes the system-wide getopt under Linux, so stop this 43 | # define _GETOPT_POSIX_H 1 44 | # endif 45 | #endif 46 | 47 | #include "defines.h" 48 | 49 | #ifdef HAVE_ADPLUG_NUKEDOPL 50 | #include 51 | #endif 52 | #ifdef HAVE_ADPLUG_SURROUND 53 | #include 54 | #endif 55 | 56 | #include "output.h" 57 | #include "players.h" 58 | 59 | /***** Defines *****/ 60 | 61 | // Default file name of AdPlug's database file 62 | #define ADPLUGDB_FILE "adplug.db" 63 | 64 | // Default AdPlug user's configuration subdirectory 65 | #define ADPLUG_CONFDIR ".adplug" 66 | 67 | // Default path to AdPlug's system-wide database file 68 | #ifdef ADPLUG_DATA_DIR 69 | # define ADPLUGDB_PATH ADPLUG_DATA_DIR "/" ADPLUGDB_FILE 70 | #else 71 | # define ADPLUGDB_PATH ADPLUGDB_FILE 72 | #endif 73 | 74 | /***** Typedefs *****/ 75 | 76 | typedef enum { 77 | Emu_Satoh, 78 | Emu_Ken, 79 | Emu_Woody, 80 | #ifdef HAVE_ADPLUG_NUKEDOPL 81 | Emu_Nuked, 82 | #endif 83 | } EmuType; 84 | 85 | /***** Global variables *****/ 86 | 87 | static const char *program_name; 88 | static Player *player = 0; // global player object 89 | static CAdPlugDatabase mydb; 90 | static Copl *opl = 0; 91 | 92 | /***** Configuration (and defaults) *****/ 93 | 94 | static struct { 95 | int buf_size, freq, channels, bits, harmonic, message_level; 96 | unsigned int subsong, loops; 97 | const char *device; 98 | char *userdb; 99 | bool endless, showinsts, songinfo, songmessage; 100 | EmuType emutype; 101 | Outputs output; 102 | } cfg = { 103 | 2048, 44100, 104 | #ifdef HAVE_ADPLUG_SURROUND 105 | 2, 16, 1, // Default to surround if available 106 | #else 107 | 1, 16, 0, // Else default to mono (until stereo w/ single OPL is fixed) 108 | #endif 109 | MSG_NOTE, 110 | (unsigned int)-1, 1, 111 | NULL, 112 | NULL, 113 | true, false, false, false, 114 | Emu_Woody, 115 | DEFAULT_DRIVER 116 | }; 117 | 118 | /***** Global functions *****/ 119 | 120 | void message(int level, const char *fmt, ...) 121 | { 122 | va_list argptr; 123 | 124 | if(cfg.message_level < level) return; 125 | 126 | fprintf(stderr, "%s: ", program_name); 127 | va_start(argptr, fmt); 128 | vfprintf(stderr, fmt, argptr); 129 | va_end(argptr); 130 | fprintf(stderr, "\n"); 131 | } 132 | 133 | /***** Local functions *****/ 134 | 135 | static void usage() 136 | /* Print usage information. */ 137 | { 138 | printf("Usage: %s [OPTION]... FILE...\n\n" 139 | "Output selection:\n" 140 | " -e, --emulator=EMULATOR specify emulator to use\n" 141 | " -O, --output=OUTPUT specify output mechanism\n\n" 142 | #ifdef DRIVER_OSS 143 | "OSS driver (oss) specific:\n" 144 | " -d, --device=FILE set sound device file to FILE\n" 145 | " -b, --buffer=SIZE set output buffer size to SIZE\n\n" 146 | #endif 147 | #ifdef DRIVER_DISK 148 | "Disk writer (disk) specific:\n" 149 | " -d, --device=FILE output to FILE ('-' is stdout)\n\n" 150 | #endif 151 | #ifdef DRIVER_ESOUND 152 | "EsounD driver (esound) specific:\n" 153 | " -d, --device=URL URL to EsounD server host (hostname:port)\n\n" 154 | #endif 155 | #ifdef DRIVER_SDL 156 | "SDL driver (sdl) specific:\n" 157 | " -b, --buffer=SIZE set output buffer size to SIZE\n\n" 158 | #endif 159 | #ifdef DRIVER_ALSA 160 | "ALSA driver (alsa) specific:\n" 161 | " -d, --device=DEVICE set sound device to DEVICE\n" 162 | " -b, --buffer=SIZE set output buffer size to SIZE\n\n" 163 | #endif 164 | #ifdef DRIVER_RAW 165 | "RAW file writer (raw) specific:\n" 166 | " -d, --device=FILE output to FILE\n\n" 167 | #endif 168 | "Playback quality:\n" 169 | " -8, --8bit 8-bit sample quality\n" 170 | " --16bit 16-bit sample quality\n" 171 | " -f, --freq=FREQ set sample frequency to FREQ\n" 172 | " --surround stereo/surround stream\n" 173 | " --stereo stereo stream\n" 174 | " --mono mono stream\n\n" 175 | "Informative output:\n" 176 | " -i, --instruments display instrument names\n" 177 | " -r, --realtime display realtime song info\n" 178 | " -m, --message display song message\n\n" 179 | "Playback:\n" 180 | " -s, --subsong=N play subsong number N\n" 181 | " -o, --once play only once, don't loop\n" 182 | " -l, --loop=N loop exactly N times\n\n" 183 | "Generic:\n" 184 | " -D, --database=FILE additionally use database file FILE\n" 185 | " -q, --quiet be more quiet\n" 186 | " -v, --verbose be more verbose\n" 187 | " -h, --help display this help and exit\n" 188 | " -V, --version output version information and exit\n\n", 189 | program_name); 190 | 191 | // Print list of available output mechanisms 192 | printf("Available emulators: satoh ken woody"); 193 | #ifdef HAVE_ADPLUG_NUKEDOPL 194 | printf(" nuked"); 195 | #endif 196 | printf("\n"); 197 | printf("Available output mechanisms:" 198 | #ifdef DRIVER_OSS 199 | " oss" 200 | #endif 201 | #ifdef DRIVER_NULL 202 | " null" 203 | #endif 204 | #ifdef DRIVER_DISK 205 | " disk" 206 | #endif 207 | #ifdef DRIVER_ESOUND 208 | " esound" 209 | #endif 210 | #ifdef DRIVER_QSA 211 | " qsa" 212 | #endif 213 | #ifdef DRIVER_SDL 214 | " sdl" 215 | #endif 216 | #ifdef DRIVER_AO 217 | " ao" 218 | #endif 219 | #ifdef DRIVER_ALSA 220 | " alsa" 221 | #endif 222 | #ifdef DRIVER_RAW 223 | " raw" 224 | #endif 225 | "\n"); 226 | } 227 | 228 | static int decode_switches(int argc, char **argv) 229 | /* 230 | * Set all the option flags according to the switches specified. 231 | * Return the index of the first non-option argument. 232 | */ 233 | { 234 | int c; 235 | struct option const long_options[] = { 236 | {"8bit", no_argument, NULL, '8'}, // 8-bit replay 237 | {"16bit", no_argument, NULL, '1'}, // 16-bit replay 238 | {"freq", required_argument, NULL, 'f'}, // set frequency 239 | {"surround", no_argument, NULL, '4'}, // stereo/harmonic replay 240 | {"stereo", no_argument, NULL, '3'}, // stereo replay 241 | {"mono", no_argument, NULL, '2'}, // mono replay 242 | {"buffer", required_argument, NULL, 'b'}, // buffer size 243 | {"device", required_argument, NULL, 'd'}, // device file 244 | {"instruments", no_argument, NULL, 'i'}, // show instruments 245 | {"realtime", no_argument, NULL, 'r'}, // realtime song info 246 | {"message", no_argument, NULL, 'm'}, // song message 247 | {"subsong", no_argument, NULL, 's'}, // play subsong 248 | {"once", no_argument, NULL, 'o'}, // don't loop 249 | {"loop", required_argument, NULL, 'l'}, // loop count 250 | {"help", no_argument, NULL, 'h'}, // display help 251 | {"version", no_argument, NULL, 'V'}, // version information 252 | {"emulator", required_argument, NULL, 'e'}, // emulator to use 253 | {"output", required_argument, NULL, 'O'}, // output mechanism 254 | {"database", required_argument, NULL, 'D'}, // different database 255 | {"quiet", no_argument, NULL, 'q'}, // be more quiet 256 | {"verbose", no_argument, NULL, 'v'}, // be more verbose 257 | {NULL, 0, NULL, 0} // end of options 258 | }; 259 | 260 | while ((c = getopt_long(argc, argv, "8f:b:d:irms:ol:hVe:O:D:qv", 261 | long_options, (int *)0)) != EOF) { 262 | switch (c) { 263 | case '8': cfg.bits = 8; break; 264 | case '1': cfg.bits = 16; break; 265 | case 'f': cfg.freq = atoi(optarg); break; 266 | case '4': cfg.channels = 2; cfg.harmonic = 1; break; 267 | case '3': cfg.channels = 2; cfg.harmonic = 0; break; 268 | case '2': cfg.channels = 1; cfg.harmonic = 0; break; 269 | case 'b': cfg.buf_size = atoi(optarg); break; 270 | case 'd': cfg.device = optarg; break; 271 | case 'i': cfg.showinsts = true; break; 272 | case 'r': cfg.songinfo = true; break; 273 | case 'm': cfg.songmessage = true; break; 274 | case 's': cfg.subsong = atoi(optarg); break; 275 | case 'o': cfg.endless = false; break; 276 | case 'l': cfg.endless = false; cfg.loops = atoi(optarg); break; 277 | case 'V': puts(ADPLAY_VERSION); exit(EXIT_SUCCESS); 278 | case 'h': usage(); exit(EXIT_SUCCESS); break; 279 | case 'D': 280 | if(!mydb.load(optarg)) 281 | message(MSG_WARN, "could not open database -- %s", optarg); 282 | break; 283 | case 'O': 284 | #ifdef DRIVER_OSS 285 | if(!strcmp(optarg,"oss")) cfg.output = oss; 286 | else 287 | #endif 288 | #ifdef DRIVER_NULL 289 | if(!strcmp(optarg,"null")) cfg.output = null; 290 | else 291 | #endif 292 | #ifdef DRIVER_DISK 293 | if(!strcmp(optarg,"disk")) { 294 | cfg.output = disk; 295 | cfg.endless = false; // endless output is almost never desired here 296 | } 297 | else 298 | #endif 299 | #ifdef DRIVER_ESOUND 300 | if(!strcmp(optarg,"esound")) cfg.output = esound; 301 | else 302 | #endif 303 | #ifdef DRIVER_QSA 304 | if(!strcmp(optarg,"qsa")) cfg.output = qsa; 305 | else 306 | #endif 307 | #ifdef DRIVER_ALSA 308 | if(!strcmp(optarg,"alsa")) cfg.output = alsa; 309 | else 310 | #endif 311 | #ifdef DRIVER_SDL 312 | if(!strcmp(optarg,"sdl")) cfg.output = sdl; 313 | else 314 | #endif 315 | #ifdef DRIVER_AO 316 | if(!strcmp(optarg,"ao")) cfg.output = ao; 317 | else 318 | #endif 319 | #ifdef DRIVER_RAW 320 | if(!strcmp(optarg,"raw")) { 321 | cfg.output = raw; 322 | cfg.endless = false; // endless output is almost never desired here 323 | } 324 | else 325 | #endif 326 | { 327 | message(MSG_ERROR, "unknown output method -- %s", optarg); 328 | exit(EXIT_FAILURE); 329 | } 330 | break; 331 | case 'e': 332 | if(!strcmp(optarg, "satoh")) cfg.emutype = Emu_Satoh; 333 | else if(!strcmp(optarg, "ken")) cfg.emutype = Emu_Ken; 334 | else if(!strcmp(optarg, "woody")) cfg.emutype = Emu_Woody; 335 | #ifdef HAVE_ADPLUG_NUKEDOPL 336 | else if(!strcmp(optarg, "nuked")) cfg.emutype = Emu_Nuked; 337 | #endif 338 | else { 339 | message(MSG_ERROR, "unknown emulator -- %s", optarg); 340 | exit(EXIT_FAILURE); 341 | } 342 | case 'q': if(cfg.message_level) cfg.message_level--; break; 343 | case 'v': cfg.message_level++; break; 344 | } 345 | } 346 | if (!cfg.loops) cfg.loops = 1; 347 | 348 | return optind; 349 | } 350 | 351 | static void play(const char *fn, Player *pl, int subsong = -1) 352 | /* 353 | * Start playback of subsong 'subsong' of file 'fn', using player 354 | * 'player'. If 'subsong' is not given or -1, start playback of 355 | * default subsong of file. 356 | */ 357 | { 358 | unsigned long i; 359 | unsigned long s = 0; 360 | unsigned long ls = 0; 361 | unsigned int loops = 0; 362 | 363 | // initialize output & player 364 | pl->get_opl()->init(); 365 | delete pl->p; 366 | pl->reset(); 367 | pl->p = CAdPlug::factory(fn,pl->get_opl()); 368 | 369 | if(!pl->p) { 370 | message(MSG_WARN, "unknown filetype -- %s", fn); 371 | return; 372 | } 373 | 374 | if(subsong != -1) 375 | pl->p->rewind(subsong); 376 | #ifdef HAVE_ADPLUG_GETSUBSONG 377 | else 378 | subsong = pl->p->getsubsong(); 379 | #endif 380 | 381 | fprintf(stderr, "Playing '%s'...\n" 382 | "Type : %s\n" 383 | "Title : %s\n" 384 | "Author: %s\n\n", fn, pl->p->gettype().c_str(), 385 | pl->p->gettitle().c_str(), pl->p->getauthor().c_str()); 386 | 387 | if(cfg.showinsts) { // display instruments 388 | fprintf(stderr, "Instrument names:\n"); 389 | for(i = 0;i < pl->p->getinstruments(); i++) 390 | fprintf(stderr, "%2lu: %s\n", i, pl->p->getinstrument(i).c_str()); 391 | fprintf(stderr, "\n"); 392 | } 393 | 394 | if(cfg.songmessage) // display song message 395 | fprintf(stderr, "Song message:\n%s\n\n", pl->p->getdesc().c_str()); 396 | 397 | // play loop 398 | do { 399 | if(cfg.songinfo) // display song info 400 | fprintf(stderr, "Subsong: %d/%d, Order: %d/%d, Pattern: %d/%d, Row: %d, " 401 | "Speed: %d, Timer: %.2fHz \r", 402 | subsong, pl->p->getsubsongs()-1, pl->p->getorder(), 403 | pl->p->getorders(), pl->p->getpattern(), pl->p->getpatterns(), 404 | pl->p->getrow(), pl->p->getspeed(), pl->p->getrefresh()); 405 | 406 | pl->frame(); 407 | ++s; 408 | 409 | if (!pl->playing) { 410 | if (!ls) ls = s; 411 | if (s == ls) { 412 | ++loops; 413 | s = 0; 414 | } 415 | } 416 | } while(cfg.endless || loops < cfg.loops); 417 | } 418 | 419 | static void shutdown(void) 420 | /* General deinitialization handler. */ 421 | { 422 | if(player) delete player; 423 | if(opl) delete opl; 424 | } 425 | 426 | static void sighandler(int signal) 427 | /* Handles all kinds of signals. */ 428 | { 429 | switch(signal) { 430 | case SIGINT: 431 | // Try to properly reposition terminal cursor, if Ctrl+C is used to exit. 432 | printf("\n\n"); 433 | case SIGTERM: 434 | exit(EXIT_SUCCESS); 435 | } 436 | } 437 | 438 | /***** Main program *****/ 439 | 440 | int main(int argc, char **argv) 441 | { 442 | int optind, i; 443 | const char *homedir; 444 | char *userdb = NULL; 445 | 446 | // init 447 | program_name = argv[0]; 448 | atexit(shutdown); 449 | signal(SIGINT, sighandler); signal(SIGTERM, sighandler); 450 | 451 | // Try user's home directory first, before trying the default location. 452 | homedir = getenv("HOME"); 453 | if(homedir) { 454 | userdb = (char *)malloc(strlen(homedir) + strlen(ADPLUG_CONFDIR) + 455 | strlen(ADPLUGDB_FILE) + 3); 456 | strcpy(userdb, homedir); strcat(userdb, "/" ADPLUG_CONFDIR "/"); 457 | strcat(userdb, ADPLUGDB_FILE); 458 | } 459 | 460 | // parse commandline 461 | optind = decode_switches(argc,argv); 462 | if(optind == argc) { // no filename given 463 | fprintf(stderr, "%s: need at least one file for playback\n", program_name); 464 | fprintf(stderr, "Try '%s --help' for more information.\n", program_name); 465 | if(userdb) free(userdb); 466 | exit(EXIT_FAILURE); 467 | } 468 | if(argc - optind > 1) cfg.endless = false; // more than 1 file given 469 | 470 | // init emulator 471 | switch(cfg.emutype) { 472 | case Emu_Satoh: 473 | if (cfg.harmonic) { 474 | #ifdef HAVE_ADPLUG_SURROUND 475 | COPLprops a, b; 476 | a.use16bit = b.use16bit = cfg.bits == 16; 477 | a.stereo = b.stereo = false; 478 | a.opl = new CEmuopl(cfg.freq, a.use16bit, a.stereo); 479 | b.opl = new CEmuopl(cfg.freq, b.use16bit, b.stereo); 480 | opl = new CSurroundopl(&a, &b, cfg.bits == 16); 481 | // CSurroundopl now owns a.opl and b.opl and will free upon destruction 482 | #else 483 | fprintf(stderr, "Surround requires AdPlug v2.2 or newer. Use --mono " 484 | "or upgrade and recompile AdPlay.\n"); 485 | if(userdb) free(userdb); 486 | exit(EXIT_FAILURE); 487 | #endif 488 | } else { 489 | opl = new CEmuopl(cfg.freq, cfg.bits == 16, cfg.channels == 2); 490 | } 491 | break; 492 | case Emu_Ken: 493 | if (cfg.harmonic) { 494 | #ifdef HAVE_ADPLUG_SURROUND 495 | #ifndef CKEMUOPL_MULTIINSTANCE 496 | fprintf(stderr, "%s: Sorry, Ken's emulator only supports one instance " 497 | "so does not work properly in surround mode in old versions of " 498 | "the adplug library.\n", program_name); 499 | #endif 500 | COPLprops a, b; 501 | a.use16bit = b.use16bit = cfg.bits == 16; 502 | a.stereo = b.stereo = false; 503 | a.opl = new CKemuopl(cfg.freq, a.use16bit, a.stereo); 504 | b.opl = new CKemuopl(cfg.freq, b.use16bit, b.stereo); 505 | opl = new CSurroundopl(&a, &b, cfg.bits == 16); 506 | // CSurroundopl now owns a and b and will free upon destruction 507 | #else 508 | fprintf(stderr, "Surround requires AdPlug v2.2 or newer. Use --mono " 509 | "or upgrade and recompile AdPlay.\n"); 510 | if(userdb) free(userdb); 511 | exit(EXIT_FAILURE); 512 | #endif 513 | } else { 514 | opl = new CKemuopl(cfg.freq, cfg.bits == 16, cfg.channels == 2); 515 | } 516 | break; 517 | case Emu_Woody: 518 | if (cfg.harmonic) { 519 | #ifdef HAVE_ADPLUG_SURROUND 520 | COPLprops a, b; 521 | a.use16bit = b.use16bit = cfg.bits == 16; 522 | a.stereo = b.stereo = false; 523 | a.opl = new CWemuopl(cfg.freq, a.use16bit, a.stereo); 524 | b.opl = new CWemuopl(cfg.freq, b.use16bit, b.stereo); 525 | opl = new CSurroundopl(&a, &b, cfg.bits == 16); 526 | // CSurroundopl now owns a and b and will free upon destruction 527 | #else 528 | fprintf(stderr, "Surround requires AdPlug v2.2 or newer. Use --mono " 529 | "or upgrade and recompile AdPlay.\n"); 530 | if(userdb) free(userdb); 531 | exit(EXIT_FAILURE); 532 | #endif 533 | } else { 534 | opl = new CWemuopl(cfg.freq, cfg.bits == 16, cfg.channels == 2); 535 | } 536 | break; 537 | #ifdef HAVE_ADPLUG_NUKEDOPL 538 | case Emu_Nuked: 539 | if (cfg.harmonic) { 540 | COPLprops a, b; 541 | a.use16bit = b.use16bit = true; // Nuked only supports 16-bit 542 | a.stereo = b.stereo = true; // Nuked only supports stereo 543 | a.opl = new CNemuopl(cfg.freq); 544 | b.opl = new CNemuopl(cfg.freq); 545 | opl = new CSurroundopl(&a, &b, cfg.bits == 16); // SurroundOPL can convert to 8-bit though 546 | // CSurroundopl now owns a and b and will free upon destruction 547 | } else { 548 | if(cfg.bits != 16 || cfg.channels != 2) { 549 | fprintf(stderr, "Sorry, Nuked OPL3 emulator only works in stereo 16 bits. " 550 | "Use --stereo and --16bit options.\n"); 551 | if(userdb) free(userdb); 552 | exit(EXIT_FAILURE); 553 | } else { 554 | opl = new CNemuopl(cfg.freq); 555 | } 556 | } 557 | break; 558 | #endif 559 | } 560 | 561 | // init player 562 | switch(cfg.output) { 563 | case none: 564 | message(MSG_PANIC, "no output methods compiled in"); 565 | exit(EXIT_FAILURE); 566 | #ifdef DRIVER_OSS 567 | case oss: 568 | player = new OSSPlayer(opl, cfg.device, cfg.bits, cfg.channels, cfg.freq, 569 | cfg.buf_size); 570 | break; 571 | #endif 572 | #ifdef DRIVER_NULL 573 | case null: 574 | player = new NullOutput(); 575 | break; 576 | #endif 577 | #ifdef DRIVER_DISK 578 | case disk: 579 | player = new DiskWriter(opl, cfg.device, cfg.bits, cfg.channels, cfg.freq); 580 | break; 581 | #endif 582 | #ifdef DRIVER_ESOUND 583 | case esound: 584 | player = new EsoundPlayer(opl, cfg.bits, cfg.channels, cfg.freq, 585 | cfg.device); 586 | break; 587 | #endif 588 | #ifdef DRIVER_QSA 589 | case qsa: 590 | player = new QSAPlayer(opl, cfg.bits, cfg.channels, cfg.freq); 591 | break; 592 | #endif 593 | #ifdef DRIVER_AO 594 | case ao: 595 | player = new AOPlayer(opl, cfg.device, cfg.bits, cfg.channels, cfg.freq, cfg.buf_size); 596 | break; 597 | #endif 598 | #ifdef DRIVER_SDL 599 | case sdl: 600 | player = new SDLPlayer(opl, cfg.bits, cfg.channels, cfg.freq, cfg.buf_size); 601 | break; 602 | #endif 603 | #ifdef DRIVER_ALSA 604 | case alsa: 605 | player = new ALSAPlayer(opl, cfg.device, cfg.bits, cfg.channels, cfg.freq, 606 | cfg.buf_size); 607 | break; 608 | #endif 609 | #ifdef DRIVER_RAW 610 | case raw: 611 | player = new DiskRawWriter(new CDiskopl(cfg.device)); 612 | break; 613 | #endif 614 | default: 615 | message(MSG_ERROR, "output method not available"); 616 | exit(EXIT_FAILURE); 617 | } 618 | 619 | // load database 620 | if(userdb) { mydb.load(userdb); free(userdb); } 621 | mydb.load(ADPLUGDB_PATH); 622 | CAdPlug::set_database(&mydb); 623 | 624 | // play all files from commandline 625 | for(i=optind;i. 25 | Ditto for AIX 3.2 and . */ 26 | #ifndef _NO_PROTO 27 | # define _NO_PROTO 28 | #endif 29 | 30 | #ifdef HAVE_CONFIG_H 31 | # include 32 | #endif 33 | 34 | #if !defined __STDC__ || !__STDC__ 35 | /* This is a separate conditional since some stdc systems 36 | reject `defined (const)'. */ 37 | # ifndef const 38 | # define const 39 | # endif 40 | #endif 41 | 42 | #include 43 | 44 | /* Comment out all this code if we are using the GNU C Library, and are not 45 | actually compiling the library itself. This code is part of the GNU C 46 | Library, but also included in many other GNU distributions. Compiling 47 | and linking in this code is a waste when using the GNU C library 48 | (especially if it is a shared library). Rather than having every GNU 49 | program understand `configure --with-gnu-libc' and omit the object files, 50 | it is simpler to just do this in the source for each such file. */ 51 | 52 | #define GETOPT_INTERFACE_VERSION 2 53 | #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 54 | # include 55 | # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION 56 | # define ELIDE_CODE 57 | # endif 58 | #endif 59 | 60 | #ifndef ELIDE_CODE 61 | 62 | 63 | /* This needs to come after some library #include 64 | to get __GNU_LIBRARY__ defined. */ 65 | #ifdef __GNU_LIBRARY__ 66 | /* Don't include stdlib.h for non-GNU C libraries because some of them 67 | contain conflicting prototypes for getopt. */ 68 | # include 69 | # include 70 | #endif /* GNU C library. */ 71 | 72 | #ifdef VMS 73 | # include 74 | # if HAVE_STRING_H - 0 75 | # include 76 | # endif 77 | #endif 78 | 79 | #ifndef _ 80 | /* This is for other GNU distributions with internationalized messages. 81 | When compiling libc, the _ macro is predefined. */ 82 | # ifdef HAVE_LIBINTL_H 83 | # include 84 | # define _(msgid) gettext (msgid) 85 | # else 86 | # define _(msgid) (msgid) 87 | # endif 88 | #endif 89 | 90 | /* This version of `getopt' appears to the caller like standard Unix `getopt' 91 | but it behaves differently for the user, since it allows the user 92 | to intersperse the options with the other arguments. 93 | 94 | As `getopt' works, it permutes the elements of ARGV so that, 95 | when it is done, all the options precede everything else. Thus 96 | all application programs are extended to handle flexible argument order. 97 | 98 | Setting the environment variable POSIXLY_CORRECT disables permutation. 99 | Then the behavior is completely standard. 100 | 101 | GNU application programs can use a third alternative mode in which 102 | they can distinguish the relative order of options and other arguments. */ 103 | 104 | #include "getopt.h" 105 | 106 | /* For communication from `getopt' to the caller. 107 | When `getopt' finds an option that takes an argument, 108 | the argument value is returned here. 109 | Also, when `ordering' is RETURN_IN_ORDER, 110 | each non-option ARGV-element is returned here. */ 111 | 112 | char *optarg; 113 | 114 | /* Index in ARGV of the next element to be scanned. 115 | This is used for communication to and from the caller 116 | and for communication between successive calls to `getopt'. 117 | 118 | On entry to `getopt', zero means this is the first call; initialize. 119 | 120 | When `getopt' returns -1, this is the index of the first of the 121 | non-option elements that the caller should itself scan. 122 | 123 | Otherwise, `optind' communicates from one call to the next 124 | how much of ARGV has been scanned so far. */ 125 | 126 | /* 1003.2 says this must be 1 before any call. */ 127 | int optind = 1; 128 | 129 | /* Formerly, initialization of getopt depended on optind==0, which 130 | causes problems with re-calling getopt as programs generally don't 131 | know that. */ 132 | 133 | int __getopt_initialized; 134 | 135 | /* The next char to be scanned in the option-element 136 | in which the last option character we returned was found. 137 | This allows us to pick up the scan where we left off. 138 | 139 | If this is zero, or a null string, it means resume the scan 140 | by advancing to the next ARGV-element. */ 141 | 142 | static char *nextchar; 143 | 144 | /* Callers store zero here to inhibit the error message 145 | for unrecognized options. */ 146 | 147 | int opterr = 1; 148 | 149 | /* Set to an option character which was unrecognized. 150 | This must be initialized on some systems to avoid linking in the 151 | system's own getopt implementation. */ 152 | 153 | int optopt = '?'; 154 | 155 | /* Describe how to deal with options that follow non-option ARGV-elements. 156 | 157 | If the caller did not specify anything, 158 | the default is REQUIRE_ORDER if the environment variable 159 | POSIXLY_CORRECT is defined, PERMUTE otherwise. 160 | 161 | REQUIRE_ORDER means don't recognize them as options; 162 | stop option processing when the first non-option is seen. 163 | This is what Unix does. 164 | This mode of operation is selected by either setting the environment 165 | variable POSIXLY_CORRECT, or using `+' as the first character 166 | of the list of option characters. 167 | 168 | PERMUTE is the default. We permute the contents of ARGV as we scan, 169 | so that eventually all the non-options are at the end. This allows options 170 | to be given in any order, even with programs that were not written to 171 | expect this. 172 | 173 | RETURN_IN_ORDER is an option available to programs that were written 174 | to expect options and other ARGV-elements in any order and that care about 175 | the ordering of the two. We describe each non-option ARGV-element 176 | as if it were the argument of an option with character code 1. 177 | Using `-' as the first character of the list of option characters 178 | selects this mode of operation. 179 | 180 | The special argument `--' forces an end of option-scanning regardless 181 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only 182 | `--' can cause `getopt' to return -1 with `optind' != ARGC. */ 183 | 184 | static enum 185 | { 186 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER 187 | } ordering; 188 | 189 | /* Value of POSIXLY_CORRECT environment variable. */ 190 | static char *posixly_correct; 191 | 192 | #ifdef __GNU_LIBRARY__ 193 | /* We want to avoid inclusion of string.h with non-GNU libraries 194 | because there are many ways it can cause trouble. 195 | On some systems, it contains special magic macros that don't work 196 | in GCC. */ 197 | # include 198 | # define my_index strchr 199 | #else 200 | 201 | # if HAVE_STRING_H 202 | # include 203 | # else 204 | # include 205 | # endif 206 | 207 | /* Avoid depending on library functions or files 208 | whose names are inconsistent. */ 209 | 210 | #ifndef getenv 211 | extern char *getenv (); 212 | #endif 213 | 214 | static char * 215 | my_index (str, chr) 216 | const char *str; 217 | int chr; 218 | { 219 | while (*str) 220 | { 221 | if (*str == chr) 222 | return (char *) str; 223 | str++; 224 | } 225 | return 0; 226 | } 227 | 228 | /* If using GCC, we can safely declare strlen this way. 229 | If not using GCC, it is ok not to declare it. */ 230 | #ifdef __GNUC__ 231 | /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. 232 | That was relevant to code that was here before. */ 233 | # if (!defined __STDC__ || !__STDC__) && !defined strlen 234 | /* gcc with -traditional declares the built-in strlen to return int, 235 | and has done so at least since version 2.4.5. -- rms. */ 236 | extern int strlen (const char *); 237 | # endif /* not __STDC__ */ 238 | #endif /* __GNUC__ */ 239 | 240 | #endif /* not __GNU_LIBRARY__ */ 241 | 242 | /* Handle permutation of arguments. */ 243 | 244 | /* Describe the part of ARGV that contains non-options that have 245 | been skipped. `first_nonopt' is the index in ARGV of the first of them; 246 | `last_nonopt' is the index after the last of them. */ 247 | 248 | static int first_nonopt; 249 | static int last_nonopt; 250 | 251 | #ifdef _LIBC 252 | /* Bash 2.0 gives us an environment variable containing flags 253 | indicating ARGV elements that should not be considered arguments. */ 254 | 255 | /* Defined in getopt_init.c */ 256 | extern char *__getopt_nonoption_flags; 257 | 258 | static int nonoption_flags_max_len; 259 | static int nonoption_flags_len; 260 | 261 | static int original_argc; 262 | static char *const *original_argv; 263 | 264 | /* Make sure the environment variable bash 2.0 puts in the environment 265 | is valid for the getopt call we must make sure that the ARGV passed 266 | to getopt is that one passed to the process. */ 267 | static void 268 | __attribute__ ((unused)) 269 | store_args_and_env (int argc, char *const *argv) 270 | { 271 | /* XXX This is no good solution. We should rather copy the args so 272 | that we can compare them later. But we must not use malloc(3). */ 273 | original_argc = argc; 274 | original_argv = argv; 275 | } 276 | # ifdef text_set_element 277 | text_set_element (__libc_subinit, store_args_and_env); 278 | # endif /* text_set_element */ 279 | 280 | # define SWAP_FLAGS(ch1, ch2) \ 281 | if (nonoption_flags_len > 0) \ 282 | { \ 283 | char __tmp = __getopt_nonoption_flags[ch1]; \ 284 | __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ 285 | __getopt_nonoption_flags[ch2] = __tmp; \ 286 | } 287 | #else /* !_LIBC */ 288 | # define SWAP_FLAGS(ch1, ch2) 289 | #endif /* _LIBC */ 290 | 291 | /* Exchange two adjacent subsequences of ARGV. 292 | One subsequence is elements [first_nonopt,last_nonopt) 293 | which contains all the non-options that have been skipped so far. 294 | The other is elements [last_nonopt,optind), which contains all 295 | the options processed since those non-options were skipped. 296 | 297 | `first_nonopt' and `last_nonopt' are relocated so that they describe 298 | the new indices of the non-options in ARGV after they are moved. */ 299 | 300 | #if defined __STDC__ && __STDC__ 301 | static void exchange (char **); 302 | #endif 303 | 304 | static void 305 | exchange (argv) 306 | char **argv; 307 | { 308 | int bottom = first_nonopt; 309 | int middle = last_nonopt; 310 | int top = optind; 311 | char *tem; 312 | 313 | /* Exchange the shorter segment with the far end of the longer segment. 314 | That puts the shorter segment into the right place. 315 | It leaves the longer segment in the right place overall, 316 | but it consists of two parts that need to be swapped next. */ 317 | 318 | #ifdef _LIBC 319 | /* First make sure the handling of the `__getopt_nonoption_flags' 320 | string can work normally. Our top argument must be in the range 321 | of the string. */ 322 | if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) 323 | { 324 | /* We must extend the array. The user plays games with us and 325 | presents new arguments. */ 326 | char *new_str = malloc (top + 1); 327 | if (new_str == NULL) 328 | nonoption_flags_len = nonoption_flags_max_len = 0; 329 | else 330 | { 331 | memset (__mempcpy (new_str, __getopt_nonoption_flags, 332 | nonoption_flags_max_len), 333 | '\0', top + 1 - nonoption_flags_max_len); 334 | nonoption_flags_max_len = top + 1; 335 | __getopt_nonoption_flags = new_str; 336 | } 337 | } 338 | #endif 339 | 340 | while (top > middle && middle > bottom) 341 | { 342 | if (top - middle > middle - bottom) 343 | { 344 | /* Bottom segment is the short one. */ 345 | int len = middle - bottom; 346 | register int i; 347 | 348 | /* Swap it with the top part of the top segment. */ 349 | for (i = 0; i < len; i++) 350 | { 351 | tem = argv[bottom + i]; 352 | argv[bottom + i] = argv[top - (middle - bottom) + i]; 353 | argv[top - (middle - bottom) + i] = tem; 354 | SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); 355 | } 356 | /* Exclude the moved bottom segment from further swapping. */ 357 | top -= len; 358 | } 359 | else 360 | { 361 | /* Top segment is the short one. */ 362 | int len = top - middle; 363 | register int i; 364 | 365 | /* Swap it with the bottom part of the bottom segment. */ 366 | for (i = 0; i < len; i++) 367 | { 368 | tem = argv[bottom + i]; 369 | argv[bottom + i] = argv[middle + i]; 370 | argv[middle + i] = tem; 371 | SWAP_FLAGS (bottom + i, middle + i); 372 | } 373 | /* Exclude the moved top segment from further swapping. */ 374 | bottom += len; 375 | } 376 | } 377 | 378 | /* Update records for the slots the non-options now occupy. */ 379 | 380 | first_nonopt += (optind - last_nonopt); 381 | last_nonopt = optind; 382 | } 383 | 384 | /* Initialize the internal data when the first call is made. */ 385 | 386 | #if defined __STDC__ && __STDC__ 387 | static const char *_getopt_initialize (int, char *const *, const char *); 388 | #endif 389 | static const char * 390 | _getopt_initialize (argc, argv, optstring) 391 | int argc; 392 | char *const *argv; 393 | const char *optstring; 394 | { 395 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 396 | is the program name); the sequence of previously skipped 397 | non-option ARGV-elements is empty. */ 398 | 399 | first_nonopt = last_nonopt = optind; 400 | 401 | nextchar = NULL; 402 | 403 | posixly_correct = getenv ("POSIXLY_CORRECT"); 404 | 405 | /* Determine how to handle the ordering of options and nonoptions. */ 406 | 407 | if (optstring[0] == '-') 408 | { 409 | ordering = RETURN_IN_ORDER; 410 | ++optstring; 411 | } 412 | else if (optstring[0] == '+') 413 | { 414 | ordering = REQUIRE_ORDER; 415 | ++optstring; 416 | } 417 | else if (posixly_correct != NULL) 418 | ordering = REQUIRE_ORDER; 419 | else 420 | ordering = PERMUTE; 421 | 422 | #ifdef _LIBC 423 | if (posixly_correct == NULL 424 | && argc == original_argc && argv == original_argv) 425 | { 426 | if (nonoption_flags_max_len == 0) 427 | { 428 | if (__getopt_nonoption_flags == NULL 429 | || __getopt_nonoption_flags[0] == '\0') 430 | nonoption_flags_max_len = -1; 431 | else 432 | { 433 | const char *orig_str = __getopt_nonoption_flags; 434 | int len = nonoption_flags_max_len = strlen (orig_str); 435 | if (nonoption_flags_max_len < argc) 436 | nonoption_flags_max_len = argc; 437 | __getopt_nonoption_flags = 438 | (char *) malloc (nonoption_flags_max_len); 439 | if (__getopt_nonoption_flags == NULL) 440 | nonoption_flags_max_len = -1; 441 | else 442 | memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), 443 | '\0', nonoption_flags_max_len - len); 444 | } 445 | } 446 | nonoption_flags_len = nonoption_flags_max_len; 447 | } 448 | else 449 | nonoption_flags_len = 0; 450 | #endif 451 | 452 | return optstring; 453 | } 454 | 455 | /* Scan elements of ARGV (whose length is ARGC) for option characters 456 | given in OPTSTRING. 457 | 458 | If an element of ARGV starts with '-', and is not exactly "-" or "--", 459 | then it is an option element. The characters of this element 460 | (aside from the initial '-') are option characters. If `getopt' 461 | is called repeatedly, it returns successively each of the option characters 462 | from each of the option elements. 463 | 464 | If `getopt' finds another option character, it returns that character, 465 | updating `optind' and `nextchar' so that the next call to `getopt' can 466 | resume the scan with the following option character or ARGV-element. 467 | 468 | If there are no more option characters, `getopt' returns -1. 469 | Then `optind' is the index in ARGV of the first ARGV-element 470 | that is not an option. (The ARGV-elements have been permuted 471 | so that those that are not options now come last.) 472 | 473 | OPTSTRING is a string containing the legitimate option characters. 474 | If an option character is seen that is not listed in OPTSTRING, 475 | return '?' after printing an error message. If you set `opterr' to 476 | zero, the error message is suppressed but we still return '?'. 477 | 478 | If a char in OPTSTRING is followed by a colon, that means it wants an arg, 479 | so the following text in the same ARGV-element, or the text of the following 480 | ARGV-element, is returned in `optarg'. Two colons mean an option that 481 | wants an optional arg; if there is text in the current ARGV-element, 482 | it is returned in `optarg', otherwise `optarg' is set to zero. 483 | 484 | If OPTSTRING starts with `-' or `+', it requests different methods of 485 | handling the non-option ARGV-elements. 486 | See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. 487 | 488 | Long-named options begin with `--' instead of `-'. 489 | Their names may be abbreviated as long as the abbreviation is unique 490 | or is an exact match for some defined option. If they have an 491 | argument, it follows the option name in the same ARGV-element, separated 492 | from the option name by a `=', or else the in next ARGV-element. 493 | When `getopt' finds a long-named option, it returns 0 if that option's 494 | `flag' field is nonzero, the value of the option's `val' field 495 | if the `flag' field is zero. 496 | 497 | The elements of ARGV aren't really const, because we permute them. 498 | But we pretend they're const in the prototype to be compatible 499 | with other systems. 500 | 501 | LONGOPTS is a vector of `struct option' terminated by an 502 | element containing a name which is zero. 503 | 504 | LONGIND returns the index in LONGOPT of the long-named option found. 505 | It is only valid when a long-named option has been found by the most 506 | recent call. 507 | 508 | If LONG_ONLY is nonzero, '-' as well as '--' can introduce 509 | long-named options. */ 510 | 511 | int 512 | _getopt_internal (argc, argv, optstring, longopts, longind, long_only) 513 | int argc; 514 | char *const *argv; 515 | const char *optstring; 516 | const struct option *longopts; 517 | int *longind; 518 | int long_only; 519 | { 520 | int print_errors = opterr; 521 | if (optstring[0] == ':') 522 | print_errors = 0; 523 | 524 | optarg = NULL; 525 | 526 | if (optind == 0 || !__getopt_initialized) 527 | { 528 | if (optind == 0) 529 | optind = 1; /* Don't scan ARGV[0], the program name. */ 530 | optstring = _getopt_initialize (argc, argv, optstring); 531 | __getopt_initialized = 1; 532 | } 533 | 534 | /* Test whether ARGV[optind] points to a non-option argument. 535 | Either it does not have option syntax, or there is an environment flag 536 | from the shell indicating it is not an option. The later information 537 | is only used when the used in the GNU libc. */ 538 | #ifdef _LIBC 539 | # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ 540 | || (optind < nonoption_flags_len \ 541 | && __getopt_nonoption_flags[optind] == '1')) 542 | #else 543 | # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') 544 | #endif 545 | 546 | if (nextchar == NULL || *nextchar == '\0') 547 | { 548 | /* Advance to the next ARGV-element. */ 549 | 550 | /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been 551 | moved back by the user (who may also have changed the arguments). */ 552 | if (last_nonopt > optind) 553 | last_nonopt = optind; 554 | if (first_nonopt > optind) 555 | first_nonopt = optind; 556 | 557 | if (ordering == PERMUTE) 558 | { 559 | /* If we have just processed some options following some non-options, 560 | exchange them so that the options come first. */ 561 | 562 | if (first_nonopt != last_nonopt && last_nonopt != optind) 563 | exchange ((char **) argv); 564 | else if (last_nonopt != optind) 565 | first_nonopt = optind; 566 | 567 | /* Skip any additional non-options 568 | and extend the range of non-options previously skipped. */ 569 | 570 | while (optind < argc && NONOPTION_P) 571 | optind++; 572 | last_nonopt = optind; 573 | } 574 | 575 | /* The special ARGV-element `--' means premature end of options. 576 | Skip it like a null option, 577 | then exchange with previous non-options as if it were an option, 578 | then skip everything else like a non-option. */ 579 | 580 | if (optind != argc && !strcmp (argv[optind], "--")) 581 | { 582 | optind++; 583 | 584 | if (first_nonopt != last_nonopt && last_nonopt != optind) 585 | exchange ((char **) argv); 586 | else if (first_nonopt == last_nonopt) 587 | first_nonopt = optind; 588 | last_nonopt = argc; 589 | 590 | optind = argc; 591 | } 592 | 593 | /* If we have done all the ARGV-elements, stop the scan 594 | and back over any non-options that we skipped and permuted. */ 595 | 596 | if (optind == argc) 597 | { 598 | /* Set the next-arg-index to point at the non-options 599 | that we previously skipped, so the caller will digest them. */ 600 | if (first_nonopt != last_nonopt) 601 | optind = first_nonopt; 602 | return -1; 603 | } 604 | 605 | /* If we have come to a non-option and did not permute it, 606 | either stop the scan or describe it to the caller and pass it by. */ 607 | 608 | if (NONOPTION_P) 609 | { 610 | if (ordering == REQUIRE_ORDER) 611 | return -1; 612 | optarg = argv[optind++]; 613 | return 1; 614 | } 615 | 616 | /* We have found another option-ARGV-element. 617 | Skip the initial punctuation. */ 618 | 619 | nextchar = (argv[optind] + 1 620 | + (longopts != NULL && argv[optind][1] == '-')); 621 | } 622 | 623 | /* Decode the current option-ARGV-element. */ 624 | 625 | /* Check whether the ARGV-element is a long option. 626 | 627 | If long_only and the ARGV-element has the form "-f", where f is 628 | a valid short option, don't consider it an abbreviated form of 629 | a long option that starts with f. Otherwise there would be no 630 | way to give the -f short option. 631 | 632 | On the other hand, if there's a long option "fubar" and 633 | the ARGV-element is "-fu", do consider that an abbreviation of 634 | the long option, just like "--fu", and not "-f" with arg "u". 635 | 636 | This distinction seems to be the most useful approach. */ 637 | 638 | if (longopts != NULL 639 | && (argv[optind][1] == '-' 640 | || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) 641 | { 642 | char *nameend; 643 | const struct option *p; 644 | const struct option *pfound = NULL; 645 | int exact = 0; 646 | int ambig = 0; 647 | int indfound = -1; 648 | int option_index; 649 | 650 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++) 651 | /* Do nothing. */ ; 652 | 653 | /* Test all long options for either exact match 654 | or abbreviated matches. */ 655 | for (p = longopts, option_index = 0; p->name; p++, option_index++) 656 | if (!strncmp (p->name, nextchar, nameend - nextchar)) 657 | { 658 | if ((unsigned int) (nameend - nextchar) 659 | == (unsigned int) strlen (p->name)) 660 | { 661 | /* Exact match found. */ 662 | pfound = p; 663 | indfound = option_index; 664 | exact = 1; 665 | break; 666 | } 667 | else if (pfound == NULL) 668 | { 669 | /* First nonexact match found. */ 670 | pfound = p; 671 | indfound = option_index; 672 | } 673 | else 674 | /* Second or later nonexact match found. */ 675 | ambig = 1; 676 | } 677 | 678 | if (ambig && !exact) 679 | { 680 | if (print_errors) 681 | fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 682 | argv[0], argv[optind]); 683 | nextchar += strlen (nextchar); 684 | optind++; 685 | optopt = 0; 686 | return '?'; 687 | } 688 | 689 | if (pfound != NULL) 690 | { 691 | option_index = indfound; 692 | optind++; 693 | if (*nameend) 694 | { 695 | /* Don't test has_arg with >, because some C compilers don't 696 | allow it to be used on enums. */ 697 | if (pfound->has_arg) 698 | optarg = nameend + 1; 699 | else 700 | { 701 | if (print_errors) 702 | { 703 | if (argv[optind - 1][1] == '-') 704 | /* --option */ 705 | fprintf (stderr, 706 | _("%s: option `--%s' doesn't allow an argument\n"), 707 | argv[0], pfound->name); 708 | else 709 | /* +option or -option */ 710 | fprintf (stderr, 711 | _("%s: option `%c%s' doesn't allow an argument\n"), 712 | argv[0], argv[optind - 1][0], pfound->name); 713 | } 714 | 715 | nextchar += strlen (nextchar); 716 | 717 | optopt = pfound->val; 718 | return '?'; 719 | } 720 | } 721 | else if (pfound->has_arg == 1) 722 | { 723 | if (optind < argc) 724 | optarg = argv[optind++]; 725 | else 726 | { 727 | if (print_errors) 728 | fprintf (stderr, 729 | _("%s: option `%s' requires an argument\n"), 730 | argv[0], argv[optind - 1]); 731 | nextchar += strlen (nextchar); 732 | optopt = pfound->val; 733 | return optstring[0] == ':' ? ':' : '?'; 734 | } 735 | } 736 | nextchar += strlen (nextchar); 737 | if (longind != NULL) 738 | *longind = option_index; 739 | if (pfound->flag) 740 | { 741 | *(pfound->flag) = pfound->val; 742 | return 0; 743 | } 744 | return pfound->val; 745 | } 746 | 747 | /* Can't find it as a long option. If this is not getopt_long_only, 748 | or the option starts with '--' or is not a valid short 749 | option, then it's an error. 750 | Otherwise interpret it as a short option. */ 751 | if (!long_only || argv[optind][1] == '-' 752 | || my_index (optstring, *nextchar) == NULL) 753 | { 754 | if (print_errors) 755 | { 756 | if (argv[optind][1] == '-') 757 | /* --option */ 758 | fprintf (stderr, _("%s: unrecognized option `--%s'\n"), 759 | argv[0], nextchar); 760 | else 761 | /* +option or -option */ 762 | fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), 763 | argv[0], argv[optind][0], nextchar); 764 | } 765 | nextchar = (char *) ""; 766 | optind++; 767 | optopt = 0; 768 | return '?'; 769 | } 770 | } 771 | 772 | /* Look at and handle the next short option-character. */ 773 | 774 | { 775 | char c = *nextchar++; 776 | char *temp = my_index (optstring, c); 777 | 778 | /* Increment `optind' when we start to process its last character. */ 779 | if (*nextchar == '\0') 780 | ++optind; 781 | 782 | if (temp == NULL || c == ':') 783 | { 784 | if (print_errors) 785 | { 786 | if (posixly_correct) 787 | /* 1003.2 specifies the format of this message. */ 788 | fprintf (stderr, _("%s: illegal option -- %c\n"), 789 | argv[0], c); 790 | else 791 | fprintf (stderr, _("%s: invalid option -- %c\n"), 792 | argv[0], c); 793 | } 794 | optopt = c; 795 | return '?'; 796 | } 797 | /* Convenience. Treat POSIX -W foo same as long option --foo */ 798 | if (temp[0] == 'W' && temp[1] == ';') 799 | { 800 | char *nameend; 801 | const struct option *p; 802 | const struct option *pfound = NULL; 803 | int exact = 0; 804 | int ambig = 0; 805 | int indfound = 0; 806 | int option_index; 807 | 808 | /* This is an option that requires an argument. */ 809 | if (*nextchar != '\0') 810 | { 811 | optarg = nextchar; 812 | /* If we end this ARGV-element by taking the rest as an arg, 813 | we must advance to the next element now. */ 814 | optind++; 815 | } 816 | else if (optind == argc) 817 | { 818 | if (print_errors) 819 | { 820 | /* 1003.2 specifies the format of this message. */ 821 | fprintf (stderr, _("%s: option requires an argument -- %c\n"), 822 | argv[0], c); 823 | } 824 | optopt = c; 825 | if (optstring[0] == ':') 826 | c = ':'; 827 | else 828 | c = '?'; 829 | return c; 830 | } 831 | else 832 | /* We already incremented `optind' once; 833 | increment it again when taking next ARGV-elt as argument. */ 834 | optarg = argv[optind++]; 835 | 836 | /* optarg is now the argument, see if it's in the 837 | table of longopts. */ 838 | 839 | for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) 840 | /* Do nothing. */ ; 841 | 842 | /* Test all long options for either exact match 843 | or abbreviated matches. */ 844 | for (p = longopts, option_index = 0; p->name; p++, option_index++) 845 | if (!strncmp (p->name, nextchar, nameend - nextchar)) 846 | { 847 | if ((unsigned int) (nameend - nextchar) == strlen (p->name)) 848 | { 849 | /* Exact match found. */ 850 | pfound = p; 851 | indfound = option_index; 852 | exact = 1; 853 | break; 854 | } 855 | else if (pfound == NULL) 856 | { 857 | /* First nonexact match found. */ 858 | pfound = p; 859 | indfound = option_index; 860 | } 861 | else 862 | /* Second or later nonexact match found. */ 863 | ambig = 1; 864 | } 865 | if (ambig && !exact) 866 | { 867 | if (print_errors) 868 | fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 869 | argv[0], argv[optind]); 870 | nextchar += strlen (nextchar); 871 | optind++; 872 | return '?'; 873 | } 874 | if (pfound != NULL) 875 | { 876 | option_index = indfound; 877 | if (*nameend) 878 | { 879 | /* Don't test has_arg with >, because some C compilers don't 880 | allow it to be used on enums. */ 881 | if (pfound->has_arg) 882 | optarg = nameend + 1; 883 | else 884 | { 885 | if (print_errors) 886 | fprintf (stderr, _("\ 887 | %s: option `-W %s' doesn't allow an argument\n"), 888 | argv[0], pfound->name); 889 | 890 | nextchar += strlen (nextchar); 891 | return '?'; 892 | } 893 | } 894 | else if (pfound->has_arg == 1) 895 | { 896 | if (optind < argc) 897 | optarg = argv[optind++]; 898 | else 899 | { 900 | if (print_errors) 901 | fprintf (stderr, 902 | _("%s: option `%s' requires an argument\n"), 903 | argv[0], argv[optind - 1]); 904 | nextchar += strlen (nextchar); 905 | return optstring[0] == ':' ? ':' : '?'; 906 | } 907 | } 908 | nextchar += strlen (nextchar); 909 | if (longind != NULL) 910 | *longind = option_index; 911 | if (pfound->flag) 912 | { 913 | *(pfound->flag) = pfound->val; 914 | return 0; 915 | } 916 | return pfound->val; 917 | } 918 | nextchar = NULL; 919 | return 'W'; /* Let the application handle it. */ 920 | } 921 | if (temp[1] == ':') 922 | { 923 | if (temp[2] == ':') 924 | { 925 | /* This is an option that accepts an argument optionally. */ 926 | if (*nextchar != '\0') 927 | { 928 | optarg = nextchar; 929 | optind++; 930 | } 931 | else 932 | optarg = NULL; 933 | nextchar = NULL; 934 | } 935 | else 936 | { 937 | /* This is an option that requires an argument. */ 938 | if (*nextchar != '\0') 939 | { 940 | optarg = nextchar; 941 | /* If we end this ARGV-element by taking the rest as an arg, 942 | we must advance to the next element now. */ 943 | optind++; 944 | } 945 | else if (optind == argc) 946 | { 947 | if (print_errors) 948 | { 949 | /* 1003.2 specifies the format of this message. */ 950 | fprintf (stderr, 951 | _("%s: option requires an argument -- %c\n"), 952 | argv[0], c); 953 | } 954 | optopt = c; 955 | if (optstring[0] == ':') 956 | c = ':'; 957 | else 958 | c = '?'; 959 | } 960 | else 961 | /* We already incremented `optind' once; 962 | increment it again when taking next ARGV-elt as argument. */ 963 | optarg = argv[optind++]; 964 | nextchar = NULL; 965 | } 966 | } 967 | return c; 968 | } 969 | } 970 | 971 | int 972 | getopt (argc, argv, optstring) 973 | int argc; 974 | char *const *argv; 975 | const char *optstring; 976 | { 977 | return _getopt_internal (argc, argv, optstring, 978 | (const struct option *) 0, 979 | (int *) 0, 980 | 0); 981 | } 982 | 983 | #endif /* Not ELIDE_CODE. */ 984 | 985 | #ifdef TEST 986 | 987 | /* Compile with -DTEST to make an executable for use in testing 988 | the above definition of `getopt'. */ 989 | 990 | int 991 | main (argc, argv) 992 | int argc; 993 | char **argv; 994 | { 995 | int c; 996 | int digit_optind = 0; 997 | 998 | while (1) 999 | { 1000 | int this_option_optind = optind ? optind : 1; 1001 | 1002 | c = getopt (argc, argv, "abc:d:0123456789"); 1003 | if (c == -1) 1004 | break; 1005 | 1006 | switch (c) 1007 | { 1008 | case '0': 1009 | case '1': 1010 | case '2': 1011 | case '3': 1012 | case '4': 1013 | case '5': 1014 | case '6': 1015 | case '7': 1016 | case '8': 1017 | case '9': 1018 | if (digit_optind != 0 && digit_optind != this_option_optind) 1019 | printf ("digits occur in two different argv-elements.\n"); 1020 | digit_optind = this_option_optind; 1021 | printf ("option %c\n", c); 1022 | break; 1023 | 1024 | case 'a': 1025 | printf ("option a\n"); 1026 | break; 1027 | 1028 | case 'b': 1029 | printf ("option b\n"); 1030 | break; 1031 | 1032 | case 'c': 1033 | printf ("option c with value `%s'\n", optarg); 1034 | break; 1035 | 1036 | case '?': 1037 | break; 1038 | 1039 | default: 1040 | printf ("?? getopt returned character code 0%o ??\n", c); 1041 | } 1042 | } 1043 | 1044 | if (optind < argc) 1045 | { 1046 | printf ("non-option ARGV-elements: "); 1047 | while (optind < argc) 1048 | printf ("%s ", argv[optind++]); 1049 | printf ("\n"); 1050 | } 1051 | 1052 | exit (0); 1053 | } 1054 | 1055 | #endif /* TEST */ 1056 | --------------------------------------------------------------------------------