JNIEXPORT void JNICALL Java_com_sun_media_sound_MixerSynth_nDestroySynthesizer(JNIEnv* e, jobject thisObj, jlong id) { GM_Song *pSong = (GM_Song *) (INT_PTR) id; TRACE0("Java_com_sun_media_sound_MixerSynth_nDestroySynthesizer.\n"); if (pSong) { GM_KillSongNotes(pSong); pSong->disposeSongDataWhenDone = TRUE; // free our midi pointer GM_FreeSong((void *)e, pSong); } else { ERROR0("pSong is NULL\n"); } TRACE0("Java_com_sun_media_sound_MixerSynth_nDestroySynthesizer completed.\n"); }
extern int anongame_wol_matchlist_destroy(void) { t_anongame_wol_player * player; t_elem * curr; if (anongame_wol_matchlist_head) { LIST_TRAVERSE(anongame_wol_matchlist_head,curr) { if (!(player = (t_anongame_wol_player*)elem_get_data(curr))) { /* should not happen */ ERROR0("wol_matchlist contains NULL item"); continue; } anongame_wol_player_destroy(player,&curr); } if (list_destroy(anongame_wol_matchlist_head)<0) return -1; anongame_wol_matchlist_head = NULL; } return 0; }
JNIEXPORT jlong JNICALL Java_com_sun_media_sound_MidiInDevice_nOpen(JNIEnv* e, jobject thisObj, jint index) { MidiDeviceHandle* deviceHandle = NULL; TRACE1("Java_com_sun_media_sound_MidiInDevice_nOpen: index: %d\n", index); #if USE_PLATFORM_MIDI_IN == TRUE deviceHandle = MIDI_IN_OpenDevice((INT32) index); #endif // if we didn't get a valid handle, throw a MidiUnavailableException // $$kk: 06.24.99: should be getting more information here! if ( !deviceHandle ) { char *msg = "Failed to open the device.\0"; ERROR0("Java_com_sun_media_sound_MidiInDevice_nOpen: Failed to open the device\n"); ThrowJavaMessageException(e, JAVA_MIDI_PACKAGE_NAME"/MidiUnavailableException", msg); } TRACE0("Java_com_sun_media_sound_MidiInDevice_nOpen succeeded\n"); return (jlong) (UINT_PTR) deviceHandle; }
int getDevicePosition(SolPcmInfo* info, int isSource) { audio_info_t audioInfo; audio_prinfo_t* prinfo; int err; if (isSource) { prinfo = &(audioInfo.play); } else { prinfo = &(audioInfo.record); } AUDIO_INITINFO(&audioInfo); err = ioctl(info->fd, AUDIO_GETINFO, &audioInfo); if (err >= 0) { /*TRACE2("---> device paused: %d eof=%d\n", prinfo->pause, prinfo->eof); */ return (int) (prinfo->samples * info->frameSize); } ERROR0("DAUDIO: getDevicePosition: ioctl failed!\n"); return -1; }
extern int apireglist_destroy(void) { t_apiregmember * apiregmember; t_elem * curr; if (apireglist_head) { LIST_TRAVERSE(apireglist_head,curr) { if (!(apiregmember = (t_apiregmember*)elem_get_data(curr))) { ERROR0("channel list contains NULL item"); continue; } apiregmember_destroy(apiregmember,&curr); } if (list_destroy(apireglist_head)<0) return -1; apireglist_head = NULL; } return 0; }
JNIEXPORT jboolean JNICALL Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument(JNIEnv* e, jobject thisObj, jlong id, jint instrumentId) { GM_Song *pSong = (GM_Song *) (INT_PTR) id; OPErr opErr = NOT_SETUP; TRACE0("Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument\n"); if (pSong) { opErr = GM_LoadInstrument(pSong, (XLongResourceID)instrumentId); if (opErr != NO_ERR) { ERROR1("Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument: GM_LoadInstrument returned an error: %d\n", opErr); } } else { ERROR0("Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument: pSong is NULL\n"); } TRACE0("Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument completed\n"); return ( (opErr == NO_ERR) ? TRUE : FALSE ); }
char const * Directory::read() const { const char * result; #ifdef WIN32 switch (status) { default: case -1: /* couldn't rewind */ ERROR0("got status -1"); return 0; case 0: /* freshly opened */ status = 1; if (lFindHandle < 0) return 0; result = fileinfo.name; break; case 1: /* reading */ if (lFindHandle < 0) return 0; if (_findnext(lFindHandle, &fileinfo) < 0) { status = 2; return 0; } else result = fileinfo.name; break; case 2: /* EOF */ return 0; } #else /* POSIX */ struct dirent *dentry = dir ? readdir(dir) : 0; if (!dentry) return 0; result = dentry->d_name; #endif /* WIN32-POSIX */ if (!(strcmp(result, ".") && strcmp(result, ".."))) /* here we presume we don't get an infinite number of "." or ".." ;) */ return read(); return result; }
// returns -1 on error int DAUDIO_Write(void* id, char* data, int byteSize) { AlsaPcmInfo* info = (AlsaPcmInfo*) id; int ret, count; snd_pcm_sframes_t frameSize, writtenFrames; TRACE1("> DAUDIO_Write %d bytes\n", byteSize); /* sanity */ if (byteSize <= 0 || info->frameSize <= 0) { ERROR2(" DAUDIO_Write: byteSize=%d, frameSize=%d!\n", (int) byteSize, (int) info->frameSize); TRACE0("< DAUDIO_Write returning -1\n"); return -1; } count = 2; // maximum number of trials to recover from underrun //frameSize = snd_pcm_bytes_to_frames(info->handle, byteSize); frameSize = (snd_pcm_sframes_t) (byteSize / info->frameSize); do { writtenFrames = snd_pcm_writei(info->handle, (const void*) data, (snd_pcm_uframes_t) frameSize); if (writtenFrames < 0) { ret = xrun_recovery(info, (int) writtenFrames); if (ret <= 0) { TRACE1("DAUDIO_Write: xrun recovery returned %d -> return.\n", ret); return ret; } if (count-- <= 0) { ERROR0("DAUDIO_Write: too many attempts to recover from xrun/suspend\n"); return -1; } } else { break; } } while (TRUE); //ret = snd_pcm_frames_to_bytes(info->handle, writtenFrames); ret = (int) (writtenFrames * info->frameSize); TRACE1("< DAUDIO_Write: returning %d bytes.\n", ret); return ret; }
JNIEXPORT void JNICALL Java_com_sun_media_sound_AbstractPlayer_nAddReceiver(JNIEnv* e, jobject thisObj, jlong id, jlong receiverId) { GM_Song *pSong = (GM_Song *) (INT_PTR) id; GM_Synth *pSynth = NULL; TRACE0("Java_com_sun_media_sound_AbstractPlayer_nAddReceiver.\n"); if (pSong) { // only add it if it's not already in the list while ( (pSynth = GM_GetSongSynth(pSong, pSynth)) != NULL ) { // if it's already in the list, return if (pSynth->deviceHandle == (void *) (INT_PTR) receiverId) { return; } } // $$kk: 07.12.99: change this! #if USE_EXTERNAL_SYNTH == TRUE if (receiverId) { pSynth = PV_CreateExternalSynthForDevice(pSong, (void *)receiverId); } #endif // $$kk: 07.12.99: add it even if it's null 'cause that'll give us the // software synth //if (pSynth) { GM_AddSongSynth(pSong, pSynth); } } else { ERROR0("Java_com_sun_media_sound_AbstractPlayer_nAddReceiver: pSong is NULL\n"); } TRACE0("Java_com_sun_media_sound_AbstractPlayer_nAddReceiver completed.\n"); }
static void _handle_stats_request(connection_t *con, http_parser_t *parser, char *uri) { stats_connection_t *stats; stats_event_inc(NULL, "stats_connections"); if (!connection_check_admin_pass(parser)) { ERROR0("Bad password for stats connection"); connection_close(con); httpp_destroy(parser); return; } stats_event_inc(NULL, "stats"); /* create stats connection and create stats handler thread */ stats = (stats_connection_t *)malloc(sizeof(stats_connection_t)); stats->parser = parser; stats->con = con; thread_create("Stats Connection", stats_connection, (void *)stats, THREAD_DETACHED); }
static int _parse_directory (xmlNodePtr node, void *arg) { ice_config_t *config = arg; struct cfg_tag icecast_tags[] = { { "yp-url", config_get_str, &config->yp_url [config->num_yp_directories]}, { "yp-url-timeout", config_get_int, &config->yp_url_timeout [config->num_yp_directories]}, { "touch-interval", config_get_int, &config->yp_touch_interval [config->num_yp_directories]}, { NULL, NULL, NULL } }; if (config->num_yp_directories >= MAX_YP_DIRECTORIES) { ERROR0("Maximum number of yp directories exceeded!"); return -1; } if (parse_xml_tags (node, icecast_tags)) return -1; config->num_yp_directories++; return 0; }
JNIEXPORT jboolean JNICALL Java_com_sun_media_sound_MixerSynth_nStartSynthesizer(JNIEnv* e, jobject thisObj, jlong id) { OPErr opErr = NO_ERR; GM_Song *pSong = (GM_Song *) (INT_PTR) id; TRACE0("Java_com_sun_media_sound_MixerSynth_nStartSynthesizer.\n"); // $$kk: 03.23.98: hard coding instrument loading here opErr = GM_StartLiveSong(pSong, 1); if (opErr) { ERROR0("FAILED TO START MIDI DIRECT: error on GM_StartLiveSong\n"); // $$kk: 09.17.98: what to do here? return (jboolean)FALSE; } TRACE0("Java_com_sun_media_sound_MixerSynth_nStartSynthesizer.completed\n"); return (jboolean)TRUE; }
int FDWEpollBackend::add(int idx, unsigned rw) { // eventlog(eventlog_level_trace, __FUNCTION__, "called fd: %d rw: %d", fd, rw); struct epoll_event tmpev; std::memset(&tmpev, 0, sizeof(tmpev)); tmpev.events = 0; if (rw & fdwatch_type_read) tmpev.events |= EPOLLIN; if (rw & fdwatch_type_write) tmpev.events |= EPOLLOUT; int op = fdw_rw(fdw_fds + idx) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; tmpev.data.fd = idx; if (epoll_ctl(epfd, op, fdw_fd(fdw_fds + idx), &tmpev)) { ERROR0("got error from epoll_ctl()"); return -1; } return 0; }
INT32 MIDI_Utils_StopDevice(MacMidiDeviceHandle* handle) { OSStatus err = noErr; if (!handle || !handle->h.deviceHandle) { ERROR0("ERROR: MIDI_Utils_StopDevice: handle or native handle is NULL\n"); return MIDI_INVALID_HANDLE; } if (handle->isStarted) { /* set the flag that we don't want to receive messages anymore */ handle->isStarted = FALSE; if (handle->direction == MIDI_IN) { err = MIDIPortDisconnectSource(inPort, (MIDIEndpointRef) (intptr_t) (handle->h.deviceHandle)); } else if (handle->direction == MIDI_OUT) { // Unschedules previously-sent packets. err = MIDIFlushOutput((MIDIEndpointRef) (intptr_t) handle->h.deviceHandle); } MIDI_CHECK_ERROR; } return MIDI_SUCCESS; }
JNIEXPORT void JNICALL Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver(JNIEnv* e, jobject thisObj, jlong id, jlong receiverId) { GM_Song *pSong = (GM_Song *) (INT_PTR) id; GM_Synth *pSynth = NULL; TRACE0("Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver.\n"); if (pSong) { // go through list. while ( (pSynth = GM_GetSongSynth(pSong, pSynth)) != NULL ) { // remove it if it's this one if (pSynth->deviceHandle == (void *) (INT_PTR) receiverId) { GM_RemoveSongSynth(pSong, pSynth); } } } else { ERROR0("Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver: pSong is NULL\n"); } TRACE0("Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver completed.\n"); }
// returns java control static void* CreatePortControl(PortMixer *mixer, PortControlCreator *creator, PortControl::ControlType type, AudioControl **audioControls, int offset, int len) { void *jControl = NULL; PortControl *control = (PortControl *)calloc(1, sizeof(PortControl)); float precision = 0.01; control->type = type; control->controlCount = len; control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *)); memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *)); switch (control->type) { case PortControl::Volume: jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, 0, 1, precision, ""); break; case PortControl::Mute: jControl = creator->newBooleanControl(creator, control, CONTROL_TYPE_MUTE); break; case PortControl::Balance: jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_BALANCE, -1, 1, precision, ""); break; }; if (jControl == NULL) { ERROR0("CreatePortControl: javaControl was not created\n"); free(control->audioControls); free(control); return NULL; } // add the control to mixer control list; control->next = mixer->portControls; mixer->portControls = control; return jControl; }
int DAUDIO_Flush(void* id, int isSource) { DS_Info* info = (DS_Info*) id; //TRACE0("DAUDIO_Flush\n"); if (info->isSource) { info->playBuffer->Stop(); DS_clearBuffer(info, false /* entire buffer */); } else { DWORD captureCursor, readCursor; /* set the read pointer to the current read position */ if (FAILED(info->captureBuffer->GetCurrentPosition(&captureCursor, &readCursor))) { ERROR0("DAUDIO_Flush: ERROR: Failed to get current position."); return false; } DS_clearBuffer(info, false /* entire buffer */); /* SHOULD set to *captureCursor*, * but that would be detected as overflow * in a subsequent GetAvailable() call. */ info->writePos = (int) readCursor; } return true; }
/* a new BOS page has been seen so check which codec it is */ static int process_initial_page (format_plugin_t *plugin, ogg_page *page) { ogg_state_t *ogg_info = plugin->_state; ogg_codec_t *codec; if (ogg_info->bos_completed) { ogg_info->bitrate = 0; ogg_info->codec_sync = NULL; /* need to zap old list of codecs when next group of BOS pages appear */ free_ogg_codecs (ogg_info); } do { codec = initial_vorbis_page (plugin, page); if (codec) break; #ifdef HAVE_THEORA codec = initial_theora_page (plugin, page); if (codec) break; #endif /* any others */ ERROR0 ("Seen BOS page with unknown type"); return -1; } while (0); if (codec) { /* add codec to list */ codec->next = ogg_info->codecs; ogg_info->codecs = codec; } return 0; }
static void _parse_directory(xmlDocPtr doc, xmlNodePtr node, ice_config_t *configuration) { char *tmp; if (configuration->num_yp_directories >= MAX_YP_DIRECTORIES) { ERROR0("Maximum number of yp directories exceeded!"); return; } do { if (node == NULL) break; if (xmlIsBlankNode(node)) continue; if (xmlStrcmp (node->name, XMLSTR("yp-url")) == 0) { if (configuration->yp_url[configuration->num_yp_directories]) xmlFree(configuration->yp_url[configuration->num_yp_directories]); configuration->yp_url[configuration->num_yp_directories] = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("yp-url-timeout")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->yp_url_timeout[configuration->num_yp_directories] = atoi(tmp); if (tmp) xmlFree(tmp); } else if (xmlStrcmp (node->name, XMLSTR("server")) == 0) { _add_server(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("touch-interval")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->yp_touch_interval[configuration->num_yp_directories] = atoi(tmp); if (tmp) xmlFree(tmp); } } while ((node = node->next)); if (configuration->yp_url [configuration->num_yp_directories] == NULL) return; configuration->num_yp_directories++; }
JNIEXPORT void JNICALL Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments(JNIEnv* e, jobject thisObj, jlong id, jobject instruments) { int index = 0; // current index as we iterate through the set of instruments in the bank int nameLength; // variables for vector operations jclass vectorClass; jmethodID addElementMethodID; // variables for java instrument manipulations jclass instrumentClass; jmethodID initMethodID; jobject newInstrumentObject; jstring newName; // variables for the XGetIndexedFileResource call XPTR pData; INT32 instrumentSize; XLongResourceID instrumentId; char instrumentName[BANK_NAME_MAX_SIZE]; //$$kk: what should the size be?? TRACE0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments\n"); // get the vector stuff set up vectorClass = (*e)->GetObjectClass(e, instruments); if (vectorClass == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments: vectorClass is NULL\n"); return; } addElementMethodID = (*e)->GetMethodID(e, vectorClass, "addElement", "(Ljava/lang/Object;)V"); if (addElementMethodID == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments: addElementMethodID is NULL\n"); return; } // get the HeadspaceInstrument class, init method id, etc. instrumentClass = (*e)->FindClass(e, "com/sun/media/sound/HeadspaceInstrument"); if (instrumentClass == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments: instrumentClass is NULL\n"); return; } initMethodID = (*e)->GetMethodID(e, instrumentClass, "<init>", "(Lcom/sun/media/sound/HeadspaceSoundbank;Ljava/lang/String;II)V"); if (initMethodID == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments: initMethodID is NULL\n"); return; } while (TRUE) { // get the next instrument pData = XGetIndexedFileResource((XFILE) (INT_PTR) id, ID_INST, &instrumentId, index, instrumentName, &instrumentSize); if (pData == NULL) { /* done getting instruments */ break; } XPtoCstr(instrumentName); // fix for 4429762: Some instrument names in some soundbanks include bad extra characters // since XPtoCstr() modifies the contents of instrumentName[], we can do so, too! nameLength = 0; while(instrumentName[nameLength]) nameLength++; while(nameLength > 0 && instrumentName[nameLength-1] < 32) { instrumentName[nameLength-1] = 0; nameLength--; } newName = (*e)->NewStringUTF(e, instrumentName); // create a HeadspaceInstrument object newInstrumentObject = (*e)->NewObject(e, instrumentClass, initMethodID, thisObj, (jstring)newName, (jint)instrumentId, (jint)instrumentSize); if (newInstrumentObject == NULL) { ERROR1("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments: Failed to get instantiate HeadspaceInstrument object for instrument id %lu.\n", instrumentId); } else { // add it to the vector (*e)->CallVoidMethod(e, instruments, addElementMethodID, newInstrumentObject); } index++; } TRACE0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments completed\n"); return; }
JNIEXPORT void JNICALL Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples(JNIEnv* e, jobject thisObj, jlong id, jobject samples) { int index = 0; // current index as we iterate through the set of samples in the bank // variables for vector operations jclass vectorClass; jmethodID addElementMethodID; // variables for java sample manipulations jclass sampleClass; jmethodID initMethodID; jobject newSampleObject; jstring newName; // variables for the XGetIndexedFileResource call XPTR pData; INT32 sampleSize; XLongResourceID sampleId; char sampleName[BANK_NAME_MAX_SIZE]; //$$kk: what should the size be?? TRACE0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples\n"); // get the vector stuff set up vectorClass = (*e)->GetObjectClass(e, samples); if (vectorClass == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples: vectorClass is NULL\n"); return; } addElementMethodID = (*e)->GetMethodID(e, vectorClass, "addElement", "(Ljava/lang/Object;)V"); if (addElementMethodID == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples: addElementMethodID is NULL\n"); return; } // get the HeadspaceSample class, init method id, etc. sampleClass = (*e)->FindClass(e, "com/sun/media/sound/HeadspaceSample"); if (sampleClass == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples: sampleClass is NULL\n"); return; } initMethodID = (*e)->GetMethodID(e, sampleClass, "<init>", "(Lcom/sun/media/sound/HeadspaceSoundbank;Ljava/lang/String;III)V"); if (initMethodID == NULL) { ERROR0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples: initMethodID is NULL\n"); return; } while (TRUE) { // get the next instrument pData = XGetIndexedFileResource((XFILE) (INT_PTR) id, ID_INST, &sampleId, index, sampleName, &sampleSize); // look for compressed version first pData = XGetIndexedFileResource((XFILE) (INT_PTR) id, ID_CSND, &sampleId, index, sampleName, &sampleSize); if (pData == NULL) { // look for standard version pData = XGetIndexedFileResource((XFILE) (INT_PTR) id, ID_SND, &sampleId, index, sampleName, &sampleSize); if (pData == NULL) { // look for encrypted version pData = XGetIndexedFileResource((XFILE) (INT_PTR) id, ID_ESND, &sampleId, index, sampleName, &sampleSize); } } if (pData == NULL) { /* done getting instruments */ break; } XPtoCstr(sampleName); newName = (*e)->NewStringUTF(e, sampleName); // create a HeadspaceSample object newSampleObject = (*e)->NewObject(e, sampleClass, initMethodID, thisObj, (jstring)newName, (jint)index, (jint)sampleId, (jint)sampleSize); if (newSampleObject == NULL) { ERROR1("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples: Failed to get instantiate HeadspaceSample object for sample id %lu.\n", sampleId); } else { // add it to the vector (*e)->CallVoidMethod(e, samples, addElementMethodID, newSampleObject); } index++; } TRACE0("Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples completed\n"); return; }
/* pass_on() * Is the work loop of the logger. Selects on the pipe to the to_erl * program erlang. If input arrives from to_erl it is passed on to * erlang. */ static void pass_on(pid_t childpid) { int len; fd_set readfds; fd_set writefds; fd_set* writefds_ptr; struct timeval timeout; time_t last_activity; char buf[BUFSIZ]; char log_alive_buffer[ALIVE_BUFFSIZ+1]; int lognum; int rfd, wfd=0, lfd=0; int maxfd; int ready; int got_some = 0; /* from to_erl */ /* Open the to_erl pipe for reading. * We can't open the writing side because nobody is reading and * we'd either hang or get an error. */ if ((rfd = sf_open(fifo2, O_RDONLY|DONT_BLOCK_PLEASE, 0)) < 0) { ERRNO_ERR1(LOG_ERR,"Could not open FIFO '%s' for reading.", fifo2); exit(1); } #ifdef DEBUG status("run_erl: %s opened for reading\n", fifo2); #endif /* Open the log file */ lognum = find_next_log_num(); lfd = open_log(lognum, O_RDWR|O_APPEND|O_CREAT|O_SYNC); /* Enter the work loop */ while (1) { int exit_status; maxfd = MAX(rfd, mfd); maxfd = MAX(wfd, maxfd); FD_ZERO(&readfds); FD_SET(rfd, &readfds); FD_SET(mfd, &readfds); FD_ZERO(&writefds); if (outbuf_size() == 0) { writefds_ptr = NULL; } else { FD_SET(wfd, &writefds); writefds_ptr = &writefds; } time(&last_activity); timeout.tv_sec = log_alive_minutes*60; /* don't assume old BSD bug */ timeout.tv_usec = 0; ready = select(maxfd + 1, &readfds, writefds_ptr, NULL, &timeout); if (ready < 0) { if (errno == EINTR) { if (waitpid(childpid, &exit_status, WNOHANG) == childpid) { /* * The Erlang emulator has terminated. Give us some more * time to write out any pending data before we terminate too. */ alarm(5); } FD_ZERO(&readfds); FD_ZERO(&writefds); } else { /* Some error occured */ ERRNO_ERR0(LOG_ERR,"Error in select."); exit(1); } } else { time_t now; if (waitpid(childpid, &exit_status, WNOHANG) == childpid) { alarm(5); FD_ZERO(&readfds); FD_ZERO(&writefds); } /* Check how long time we've been inactive */ time(&now); if(!ready || now - last_activity > log_activity_minutes*60) { /* Either a time out: 15 minutes without action, */ /* or something is coming in right now, but it's a long time */ /* since last time, so let's write a time stamp this message */ struct tm *tmptr; if (log_alive_in_gmt) { tmptr = gmtime(&now); } else { tmptr = localtime(&now); } if (!strftime(log_alive_buffer, ALIVE_BUFFSIZ, log_alive_format, tmptr)) { strn_cpy(log_alive_buffer, sizeof(log_alive_buffer), "(could not format time in 256 positions " "with current format string.)"); } log_alive_buffer[ALIVE_BUFFSIZ] = '\0'; sn_printf(buf, sizeof(buf), "\n===== %s%s\n", ready?"":"ALIVE ", log_alive_buffer); write_to_log(&lfd, &lognum, buf, strlen(buf)); } } /* * Write any pending output first. */ if (FD_ISSET(wfd, &writefds)) { int written; char* buf = outbuf_first(); len = outbuf_size(); written = sf_write(wfd, buf, len); if (written < 0 && errno == EAGAIN) { /* * Nothing was written - this is really strange because * select() told us we could write. Ignore. */ } else if (written < 0) { /* * A write error. Assume that to_erl has terminated. */ clear_outbuf(); sf_close(wfd); wfd = 0; } else { /* Delete the written part (or all) from the buffer. */ outbuf_delete(written); } } /* * Read master pty and write to FIFO. */ if (FD_ISSET(mfd, &readfds)) { #ifdef DEBUG status("Pty master read; "); #endif if ((len = sf_read(mfd, buf, BUFSIZ)) <= 0) { sf_close(rfd); if(wfd) sf_close(wfd); sf_close(mfd); unlink(fifo1); unlink(fifo2); if (len < 0) { if(errno == EIO) ERROR0(LOG_ERR,"Erlang closed the connection."); else ERRNO_ERR0(LOG_ERR,"Error in reading from terminal"); exit(1); } exit(0); } write_to_log(&lfd, &lognum, buf, len); /* * Save in the output queue. */ if (wfd) { outbuf_append(buf, len); } } /* * Read from FIFO, write to master pty */ if (FD_ISSET(rfd, &readfds)) { #ifdef DEBUG status("FIFO read; "); #endif if ((len = sf_read(rfd, buf, BUFSIZ)) < 0) { sf_close(rfd); if(wfd) sf_close(wfd); sf_close(mfd); unlink(fifo1); unlink(fifo2); ERRNO_ERR0(LOG_ERR,"Error in reading from FIFO."); exit(1); } if(!len) { /* to_erl closed its end of the pipe */ sf_close(rfd); rfd = sf_open(fifo2, O_RDONLY|DONT_BLOCK_PLEASE, 0); if (rfd < 0) { ERRNO_ERR1(LOG_ERR,"Could not open FIFO '%s' for reading.", fifo2); exit(1); } got_some = 0; /* reset for next session */ } else { if(!wfd) { /* Try to open the write pipe to to_erl. Now that we got some data * from to_erl, to_erl should already be reading this pipe - open * should succeed. But in case of error, we just ignore it. */ if ((wfd = sf_open(fifo1, O_WRONLY|DONT_BLOCK_PLEASE, 0)) < 0) { status("Client expected on FIFO %s, but can't open (len=%d)\n", fifo1, len); sf_close(rfd); rfd = sf_open(fifo2, O_RDONLY|DONT_BLOCK_PLEASE, 0); if (rfd < 0) { ERRNO_ERR1(LOG_ERR,"Could not open FIFO '%s' for reading.", fifo2); exit(1); } wfd = 0; } else { #ifdef DEBUG status("run_erl: %s opened for writing\n", fifo1); #endif } } if (!got_some && wfd && buf[0] == '\014') { char wbuf[30]; int wlen = sn_printf(wbuf,sizeof(wbuf),"[run_erl v%u-%u]\n", RUN_ERL_HI_VER, RUN_ERL_LO_VER); outbuf_append(wbuf,wlen); } got_some = 1; /* Write the message */ #ifdef DEBUG status("Pty master write; "); #endif len = extract_ctrl_seq(buf, len); if(len==1 && buf[0] == '\003') { kill(childpid,SIGINT); } else if (len>0 && write_all(mfd, buf, len) != len) { ERRNO_ERR0(LOG_ERR,"Error in writing to terminal."); sf_close(rfd); if(wfd) sf_close(wfd); sf_close(mfd); exit(1); } } #ifdef DEBUG status("OK\n"); #endif } } } /* pass_on() */
static int open_pty_master(char **ptyslave, int *sfdp) { int mfd; /* Use the posix_openpt if working, as this guarantees creation of the slave device properly. */ #if defined(HAVE_WORKING_POSIX_OPENPT) || (defined(__sun) && defined(__SVR4)) # ifdef HAVE_WORKING_POSIX_OPENPT if ((mfd = posix_openpt(O_RDWR)) >= 0) { # elif defined(__sun) && defined(__SVR4) mfd = sf_open("/dev/ptmx", O_RDWR, 0); if (mfd >= 0) { # endif if ((*ptyslave = ptsname(mfd)) != NULL && grantpt(mfd) == 0 && unlockpt(mfd) == 0) { return mfd; } sf_close(mfd); } /* fallback to openpty if it exist */ #endif #if defined(HAVE_OPENPTY) # ifdef PATH_MAX # define SLAVE_SIZE PATH_MAX # else # define SLAVE_SIZE 1024 # endif { static char slave[SLAVE_SIZE]; # undef SLAVE_SIZE if (openpty(&mfd, sfdp, slave, NULL, NULL) == 0) { *ptyslave = slave; return mfd; } } #elif !defined(HAVE_WORKING_POSIX_OPENPT) /* * The traditional way to find ptys. We only try it if neither * posix_openpt or openpty() are available. */ char *major, *minor; static char majorchars[] = "pqrstuvwxyzabcdePQRSTUVWXYZABCDE"; static char minorchars[] = "0123456789abcdefghijklmnopqrstuv" "wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_+"; /* In the old time the names where /dex/ptyXY where */ /* X is in "pqrs" and Y in "0123456789abcdef" but FreeBSD */ /* and some Linux version has extended this. */ /* This code could probebly be improved alot. For example look at */ /* http://www.xcf.berkeley.edu/~ali/K0D/UNIX/PTY/code/pty.c.html */ /* http://www.xcf.berkeley.edu/~ali/K0D/UNIX/PTY/code/upty.h.html */ { /* New style devpts or devfs /dev/pty/{m,s}{0,1....} */ static char ptyname[] = "/dev/pty/mX"; for (minor = minorchars; *minor; minor++) { ptyname[10] = *minor; if ((mfd = sf_open(ptyname, O_RDWR, 0)) >= 0) { ptyname[9] = 's'; *ptyslave = ptyname; return mfd; } } } { /* Unix98 style /dev/ptym/ptyXY and /dev/pty/ttyXY */ static char ptyname[] = "/dev/ptym/ptyXY"; static char ttyname[] = "/dev/pty/ttyXY"; for (major = majorchars; *major; major++) { ptyname[13] = *major; for (minor = minorchars; *minor; minor++) { ptyname[14] = *minor; if ((mfd = sf_open(ptyname, O_RDWR, 0)) >= 0) { ttyname[12] = *major; ttyname[13] = *minor; *ptyslave = ttyname; return mfd; } } } } { /* Old style /dev/ptyXY */ static char ptyname[] = "/dev/ptyXY"; for (major = majorchars; *major; major++) { ptyname[8] = *major; for (minor = minorchars; *minor; minor++) { ptyname[9] = *minor; if ((mfd = sf_open(ptyname, O_RDWR, 0)) >= 0) { ptyname[5] = 't'; *ptyslave = ptyname; return mfd; } } } } #endif /* !HAVE_OPENPTY */ return -1; } static int open_pty_slave(char *name) { int sfd; struct termios tty_rmode; if ((sfd = sf_open(name, O_RDWR, 0)) < 0) { return -1; } #if defined(__sun) && defined(__SVR4) /* Load the necessary STREAMS modules for Solaris */ if ((ioctl(sfd, I_FIND, "ldterm")) < 0) { ERROR0(LOG_ERR, "Failed to find ldterm STREAMS module"); return -1; } if (ioctl(sfd, I_PUSH, "ptem") < 0) { ERROR0(LOG_ERR, "Failed to push ptem STREAMS module"); return -1; } if (ioctl(sfd, I_PUSH, "ldterm") < 0) { ERROR0(LOG_ERR, "Failed to push ldterm STREAMS module"); return -1; } if (ioctl(sfd, I_PUSH, "ttcompat") < 0) { ERROR0(LOG_ERR, "Failed to push ttcompat STREAMS module"); return -1; } #endif if (getenv("RUN_ERL_DISABLE_FLOWCNTRL")) { if (tcgetattr(sfd, &tty_rmode) < 0) { fprintf(stderr, "Cannot get terminal's current mode\n"); exit(-1); } tty_rmode.c_iflag &= ~IXOFF; if (tcsetattr(sfd, TCSANOW, &tty_rmode) < 0) { fprintf(stderr, "Cannot disable terminal's flow control on input\n"); exit(-1); } tty_rmode.c_iflag &= ~IXON; if (tcsetattr(sfd, TCSANOW, &tty_rmode) < 0) { fprintf(stderr, "Cannot disable terminal's flow control on output\n"); exit(-1); } } #ifdef DEBUG if (tcgetattr(sfd, &tty_rmode) < 0) { fprintf(stderr, "Cannot get terminals current mode\n"); exit(-1); } show_terminal_settings(&tty_rmode); #endif return sfd; }
void* DAUDIO_Open(INT32 mixerIndex, INT32 deviceID, int isSource, int encoding, float sampleRate, int sampleSizeInBits, int frameSize, int channels, int isSigned, int isBigEndian, int bufferSizeInBytes) { snd_pcm_format_mask_t* formatMask; snd_pcm_format_t format; int dir; int ret = 0; AlsaPcmInfo* info = NULL; /* snd_pcm_uframes_t is 64 bit on 64-bit systems */ snd_pcm_uframes_t alsaPeriodSize = 0; snd_pcm_uframes_t alsaBufferSizeInFrames = 0; TRACE0("> DAUDIO_Open\n"); #ifdef USE_TRACE // for using ALSA debug dump methods if (ALSA_OUTPUT == NULL) { snd_output_stdio_attach(&ALSA_OUTPUT, stdout, 0); } #endif info = (AlsaPcmInfo*) malloc(sizeof(AlsaPcmInfo)); if (!info) { ERROR0("Out of memory\n"); return NULL; } memset(info, 0, sizeof(AlsaPcmInfo)); ret = openPCMfromDeviceID(deviceID, &(info->handle), isSource, FALSE /* do open device*/); if (ret == 0) { // set to blocking mode snd_pcm_nonblock(info->handle, 0); ret = snd_pcm_hw_params_malloc(&(info->hwParams)); if (ret != 0) { ERROR1(" snd_pcm_hw_params_malloc returned error %d\n", ret); } else { ret = -1; if (getAlsaFormatFromFormat(&format, frameSize / channels, sampleSizeInBits, isSigned, isBigEndian, encoding)) { if (setHWParams(info, sampleRate, channels, bufferSizeInBytes / frameSize, format)) { info->frameSize = frameSize; #ifdef ALSA_PCM_NEW_HW_PARAMS_API ret = snd_pcm_hw_params_get_period_size(info->hwParams, &alsaPeriodSize, &dir); info->periodSize = (int) alsaPeriodSize; if (ret < 0) { ERROR1("ERROR: snd_pcm_hw_params_get_period: %s\n", snd_strerror(ret)); } snd_pcm_hw_params_get_periods(info->hwParams, &(info->periods), &dir); snd_pcm_hw_params_get_buffer_size(info->hwParams, &alsaBufferSizeInFrames); info->bufferSizeInBytes = (int) alsaBufferSizeInFrames * frameSize; #else info->periodSize = snd_pcm_hw_params_get_period_size(info->hwParams, &dir); info->periods = snd_pcm_hw_params_get_periods(info->hwParams, &dir); info->bufferSizeInBytes = snd_pcm_hw_params_get_buffer_size(info->hwParams) * frameSize; ret = 0; #endif TRACE3(" DAUDIO_Open: period size = %d frames, periods = %d. Buffer size: %d bytes.\n", (int) info->periodSize, info->periods, info->bufferSizeInBytes); } } } if (ret == 0) { // set software parameters ret = snd_pcm_sw_params_malloc(&(info->swParams)); if (ret != 0) { ERROR1("snd_pcm_hw_params_malloc returned error %d\n", ret); } else { if (!setSWParams(info)) { ret = -1; } } } if (ret == 0) { // prepare device ret = snd_pcm_prepare(info->handle); if (ret < 0) { ERROR1("ERROR: snd_pcm_prepare: %s\n", snd_strerror(ret)); } } #ifdef GET_POSITION_METHOD2 if (ret == 0) { ret = snd_pcm_status_malloc(&(info->positionStatus)); if (ret != 0) { ERROR1("ERROR in snd_pcm_status_malloc: %s\n", snd_strerror(ret)); } } #endif } if (ret != 0) { DAUDIO_Close((void*) info, isSource); info = NULL; } else { // set to non-blocking mode snd_pcm_nonblock(info->handle, 1); TRACE1("< DAUDIO_Open: Opened device successfully. Handle=%p\n", (void*) info->handle); } return (void*) info; }
static sock_t wait_for_serversock (void) { #ifdef HAVE_POLL int i, ret; struct pollfd ufds [global.server_sockets + 1]; for(i=0; i < global.server_sockets; i++) { ufds[i].fd = global.serversock[i]; ufds[i].events = POLLIN; ufds[i].revents = 0; } #ifdef HAVE_SIGNALFD ufds[i].revents = 0; if (sigfd >= 0) { ufds[i].fd = sigfd; ufds[i].events = POLLIN; ret = poll(ufds, i+1, 4000); } else ret = poll(ufds, i, 4000); #else ret = poll(ufds, global.server_sockets, 333); #endif if (ret <= 0) return SOCK_ERROR; else { int dst; #ifdef HAVE_SIGNALFD if (ufds[i].revents & POLLIN) { struct signalfd_siginfo fdsi; int ret = read (sigfd, &fdsi, sizeof(struct signalfd_siginfo)); if (ret == sizeof(struct signalfd_siginfo)) { switch (fdsi.ssi_signo) { case SIGINT: case SIGTERM: DEBUG0 ("signalfd received a termination"); global.running = ICE_HALTING; connection_running = 0; break; case SIGHUP: INFO0 ("HUP received, reread scheduled"); global.schedule_config_reread = 1; break; default: WARN1 ("unexpected signal (%d)", fdsi.ssi_signo); } } } if (ufds[i].revents & (POLLNVAL|POLLERR)) { ERROR0 ("signalfd descriptor became invalid, doing thread restart"); slave_restart(); // something odd happened } #endif for(i=0; i < global.server_sockets; i++) { if(ufds[i].revents & POLLIN) return ufds[i].fd; if(ufds[i].revents & (POLLHUP|POLLERR|POLLNVAL)) { if (ufds[i].revents & (POLLHUP|POLLERR)) { sock_close (global.serversock[i]); WARN0("Had to close a listening socket"); } global.serversock[i] = SOCK_ERROR; } } /* remove any closed sockets */ for(i=0, dst=0; i < global.server_sockets; i++) { if (global.serversock[i] == SOCK_ERROR) continue; if (i!=dst) global.serversock[dst] = global.serversock[i]; dst++; } global.server_sockets = dst; return SOCK_ERROR; } #else fd_set rfds; struct timeval tv; int i, ret; sock_t max = SOCK_ERROR; FD_ZERO(&rfds); for(i=0; i < global.server_sockets; i++) { FD_SET(global.serversock[i], &rfds); if (max == SOCK_ERROR || global.serversock[i] > max) max = global.serversock[i]; } tv.tv_sec = 0; tv.tv_usec = 333000; ret = select(max+1, &rfds, NULL, NULL, &tv); if(ret < 0) { return SOCK_ERROR; } else if(ret == 0) { return SOCK_ERROR; } else { for(i=0; i < global.server_sockets; i++) { if(FD_ISSET(global.serversock[i], &rfds)) return global.serversock[i]; } return SOCK_ERROR; /* Should be impossible, stop compiler warnings */ } #endif }
int pass_on(ProgramState *s) { SIGSELECT sigsel[] = {0,FM_READ_PTR_REPLY}; union SIGNAL *sig; char child_read_buff[BUFSIZ], pipe_read_buff[BUFSIZ]; struct aiocb child_read_req, pipe_read_req; int rfd, wfd = 0; FmHandle rfh, child_rfh; int outstanding_writes = 0, got_some = 0, child_done = 0; if ((rfd = sf_open(s->r_pipe, O_RDONLY, 0)) < 0) { ERRNO_ERR1(LOG_ERR,"Could not open FIFO '%s' for reading.\n", s->r_pipe); rfd = 0; return 1; } attach(NULL,s->progpid); /* Open the log file */ erts_run_erl_log_open(); efs_examine_fd(rfd,FLIB_FD_HANDLE,&rfh); efs_examine_fd(s->ifd,FLIB_FD_HANDLE,&child_rfh); READ_AIO(child_read_req,s->ifd,BUFSIZ,child_read_buff); READ_AIO(pipe_read_req,rfd,BUFSIZ,pipe_read_buff); while (1) { time_t now,last_activity; time(&last_activity); sig = receive_w_tmo(erts_run_erl_log_alive_minutes()*60000,sigsel); time(&now); if (sig) { erts_run_erl_log_activity(0,now,last_activity); } else { /* timeout */ erts_run_erl_log_activity(1,now,last_activity); continue; } switch (sig->signo) { case OS_ATTACH_SIG: { if (rfd) { sf_close(rfd); rfd = 0; } free_buf(&sig); child_done = 1; /* Make sure to to let all outstanding write request finish */ if (outstanding_writes) break; if (wfd) sf_close(wfd); return 0; } case FM_WRITE_PTR_REPLY: { if (sig->fm_write_ptr.status == EFS_SUCCESS) { if (sig->fm_write_ptr.actual < sig->fm_write_ptr.requested) { WRITE_AIO(wfd, sig->fm_write_ptr.requested-sig->fm_write_ptr.actual, sig->fm_write_ptr.buffer+sig->fm_write_ptr.actual); } } else { /* Assume to_erl has terminated. */ sf_close(wfd); wfd = 0; } free((char*)sig->fm_write_ptr.buffer); aio_dispatch(sig); if ((--outstanding_writes == 0) && child_done) { if (wfd) sf_close(wfd); return 0; } break; } case FM_READ_PTR_REPLY: { /* Child fd */ if (sig->fm_read_ptr.handle == child_rfh) { /* Child terminated */ if (sig->fm_read_ptr.status != EFS_SUCCESS || sig->fm_read_ptr.actual == 0) { if (rfd) { sf_close(rfd); rfd = 0; } if (sig->fm_read_ptr.status != EFS_SUCCESS) { ERROR0(LOG_ERR,"Erlang closed the connection."); aio_dispatch(sig); return 1; } /* child closed connection gracefully */ aio_dispatch(sig); if (outstanding_writes) { child_done = 1; break; } if (wfd) sf_close(wfd); return 0; } else { erts_run_erl_log_write(sig->fm_read_ptr.buffer, sig->fm_read_ptr.actual); if (wfd) { WRITE_AIO(wfd, sig->fm_read_ptr.actual, sig->fm_read_ptr.buffer); outstanding_writes++; } aio_dispatch(sig); READ_AIO(child_read_req, s->ifd,BUFSIZ, child_read_buff); } /* pipe fd */ } else if (sig->fm_read_ptr.handle == rfh) { if (sig->fm_read_ptr.status != EFS_SUCCESS) { if(rfd) sf_close(rfd); if(wfd) sf_close(wfd); aio_dispatch(sig); ERRNO_ERR0(LOG_ERR,"Error in reading from FIFO."); return 1; } if (sig->fm_read_ptr.actual == 0) { /* to_erl closed its end of the pipe */ aio_dispatch(sig); sf_close(rfd); rfd = sf_open(s->r_pipe,O_RDONLY|DONT_BLOCK_PLEASE, 0); if (rfd < 0) { ERRNO_ERR1(LOG_ERR,"Could not open FIFO '%s' for reading.", s->r_pipe); rfd = 0; } else { READ_AIO(pipe_read_req,rfd,BUFSIZ,pipe_read_buff); } got_some = 0; /* reset for next session */ } else { int len = sig->fm_read_ptr.actual; char *buffer = sig->fm_read_ptr.buffer; if (!wfd) { /* Try to open the write pipe to to_erl. Now that we got some data * from to_erl, to_erl should already be reading this pipe - open * should succeed. But in case of error, we just ignore it. */ if ((wfd = sf_open(s->w_pipe, O_WRONLY|DONT_BLOCK_PLEASE, 0)) < 0) { erts_run_erl_log_status("Client expected on FIFO %s, " "but can't open (len=%d)\n", s->w_pipe, sig->fm_read_ptr.actual); sf_close(rfd); rfd = sf_open(s->r_pipe, O_RDONLY|DONT_BLOCK_PLEASE, 0); if (rfd < 0) { ERRNO_ERR1(LOG_ERR,"Could not open FIFO '%s' for reading.", s->r_pipe); return 1; } wfd = 0; } else { #ifdef DEBUG erts_run_erl_log_status("run_erl: %s opened for writing\n", s->w_pipe); #endif } } if (!got_some && wfd && buffer[0] == '\014') { char wbuf[30]; int wlen = sn_printf(wbuf,sizeof(wbuf),"[run_erl v%u-%u]\n", RUN_ERL_HI_VER, RUN_ERL_LO_VER); /* For some reason this, the first write aio seems to not get an FM_WRITE_PTR_REPLY, so we do not do: outstanding_writes++; */ WRITE_AIO(wfd, wlen, wbuf); } got_some = 1; /* Write the message */ #ifdef DEBUG erts_run_erl_log_status("Pty master write; "); #endif len = erts_run_erl_extract_ctrl_seq(buffer,len, s->ofd); if (len > 0) { int wlen = erts_run_erl_write_all(s->ofd, buffer, len); if (wlen != len) { aio_dispatch(sig); ERRNO_ERR0(LOG_ERR,"Error in writing to terminal."); if(rfd) sf_close(rfd); if(wfd) sf_close(wfd); return 1; } } #ifdef DEBUG erts_run_erl_log_status("OK\n"); #endif aio_dispatch(sig); READ_AIO(pipe_read_req,rfd,BUFSIZ,pipe_read_buff); } } break; } default: { free_buf(&sig); break; } } } }
// for each ALSA device, call iterator. userData is passed to the iterator // returns total number of iterations int iteratePCMDevices(DeviceIteratorPtr iterator, void* userData) { int count = 0; int subdeviceCount; int card, dev, subDev; char devname[16]; int err; snd_ctl_t *handle; snd_pcm_t *pcm; snd_pcm_info_t* pcminfo; snd_ctl_card_info_t *cardinfo, *defcardinfo = NULL; UINT32 deviceID; int doContinue = TRUE; snd_pcm_info_malloc(&pcminfo); snd_ctl_card_info_malloc(&cardinfo); // 1st try "default" device err = snd_pcm_open(&pcm, ALSA_DEFAULT_DEVICE_NAME, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); if (err < 0) { // try with the other direction err = snd_pcm_open(&pcm, ALSA_DEFAULT_DEVICE_NAME, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); } if (err < 0) { ERROR1("ERROR: snd_pcm_open (\"default\"): %s\n", snd_strerror(err)); } else { err = snd_pcm_info(pcm, pcminfo); snd_pcm_close(pcm); if (err < 0) { ERROR1("ERROR: snd_pcm_info (\"default\"): %s\n", snd_strerror(err)); } else { // try to get card info card = snd_pcm_info_get_card(pcminfo); if (card >= 0) { sprintf(devname, ALSA_HARDWARE_CARD, card); if (snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK) >= 0) { if (snd_ctl_card_info(handle, cardinfo) >= 0) { defcardinfo = cardinfo; } snd_ctl_close(handle); } } // call callback function for the device if (iterator != NULL) { doContinue = (*iterator)(ALSA_DEFAULT_DEVICE_ID, pcminfo, defcardinfo, userData); } count++; } } // iterate cards card = -1; while (doContinue) { if (snd_card_next(&card) < 0) { break; } if (card < 0) { break; } sprintf(devname, ALSA_HARDWARE_CARD, card); TRACE1("Opening alsa device \"%s\"...\n", devname); err = snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK); if (err < 0) { ERROR2("ERROR: snd_ctl_open, card=%d: %s\n", card, snd_strerror(err)); } else { err = snd_ctl_card_info(handle, cardinfo); if (err < 0) { ERROR2("ERROR: snd_ctl_card_info, card=%d: %s\n", card, snd_strerror(err)); } else { dev = -1; while (doContinue) { if (snd_ctl_pcm_next_device(handle, &dev) < 0) { ERROR0("snd_ctl_pcm_next_device\n"); } if (dev < 0) { break; } snd_pcm_info_set_device(pcminfo, dev); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); err = snd_ctl_pcm_info(handle, pcminfo); if (err == -ENOENT) { // try with the other direction snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE); err = snd_ctl_pcm_info(handle, pcminfo); } if (err < 0) { if (err != -ENOENT) { ERROR2("ERROR: snd_ctl_pcm_info, card=%d: %s", card, snd_strerror(err)); } } else { subdeviceCount = needEnumerateSubdevices(ALSA_PCM) ? snd_pcm_info_get_subdevices_count(pcminfo) : 1; if (iterator!=NULL) { for (subDev = 0; subDev < subdeviceCount; subDev++) { deviceID = encodeDeviceID(card, dev, subDev); doContinue = (*iterator)(deviceID, pcminfo, cardinfo, userData); count++; if (!doContinue) { break; } } } else { count += subdeviceCount; } } } // of while(doContinue) } snd_ctl_close(handle); } } snd_ctl_card_info_free(cardinfo); snd_pcm_info_free(pcminfo); return count; }
static enumError Generate ( control_t * ctrl ) { ASSERT(ctrl); ASSERT(ctrl->info); FILE * cf = ctrl->cf; FILE * hf = ctrl->hf; ASSERT(cf); ASSERT(hf); FREE(ctrl->opt_allow_grp); FREE(ctrl->opt_allow_cmd); ctrl->opt_allow_grp = ctrl->opt_allow_cmd = 0; const info_t *info; //----- ui header fprintf(cf,text_ui_head); fprintf(hf,text_ui_head); //----- setup guard char guard[100]; snprintf(guard,sizeof(guard),"WIT_UI_%s_h",ctrl->info->c_name); char * ptr; for ( ptr = guard; *ptr; ptr++ ) *ptr = *ptr == '-' ? '_' : toupper((int)*ptr); fprintf(hf,"\n#ifndef %s\n#define %s\n",guard,guard); //----- header ASSERT( ctrl->info->type & T_DEF_TOOL ); ccp tool_name = ctrl->info->c_name; fprintf(cf,"#include <getopt.h>\n"); fprintf(cf,"#include \"ui-%s.h\"\n",tool_name); fprintf(hf,"#include \"lib-std.h\"\n"); fprintf(hf,"#include \"ui.h\"\n"); //----- print enum enumOptions & OptionInfo[] print_section(cf,sep1,"OptionInfo[]"); print_section(hf,sep1,"enum enumOptions"); char * var_ptr = var_buf; char * var_end = var_buf + sizeof(var_buf); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const InfoOption_t OptionInfo[OPT__N_TOTAL+1];\n"); fprintf(cf, "const InfoOption_t OptionInfo[OPT__N_TOTAL+1] =\n" "{\n" " {0,0,0,0,0}, // OPT_NONE,\n" "\n" ); fprintf(hf, "typedef enum enumOptions\n" "{\n" "\tOPT_NONE,\n" "\n" ); ctrl->n_opt = 1; ctrl->n_opt_specific = 0; if ( ctrl->n_cmd ) { fprintf(cf," //----- command specific options -----\n\n"); fprintf(hf,"\t//----- command specific options -----\n\n"); for ( info = ctrl->info; info < ctrl->end; info++ ) if ( info->type & F_OPT_COMMAND ) print_opt(ctrl,info); ctrl->n_opt_specific = ctrl->n_opt; fprintf(cf, " {0,0,0,0,0}, // OPT__N_SPECIFIC == %d\n\n" " //----- global options -----\n\n", ctrl->n_opt_specific ); fprintf(hf, "\n\tOPT__N_SPECIFIC, // == %d \n\n" "\t//----- global options -----\n\n", ctrl->n_opt_specific ); } for ( info = ctrl->info; info < ctrl->end; info++ ) if ( info->type & F_OPT_GLOBAL ) print_opt(ctrl,info); fprintf(cf, " {0,0,0,0,0} // OPT__N_TOTAL == %d\n\n" "};\n" ,ctrl->n_opt ); fprintf(hf, "\n\tOPT__N_TOTAL // == %d\n\n" "} enumOptions;\n" ,ctrl->n_opt ); if (ctrl->n_opt_specific) { noTRACE("opt_allowed = ( %2u + %2u ) * %2u\n", ctrl->n_grp, ctrl->n_cmd, ctrl->n_opt_specific ); if (ctrl->n_grp) ctrl->opt_allow_grp = CALLOC(ctrl->n_grp,ctrl->n_opt_specific); ctrl->opt_allow_cmd = CALLOC(ctrl->n_cmd,ctrl->n_opt_specific); } //----- print alternate option infos bool done = false; const info_t * last_cmd = ctrl->info; ctrl->opt_prefix = "def"; for ( info = ctrl->info; info < ctrl->end; info++ ) { if ( info->type & T_CMD_BEG ) { ctrl->opt_prefix = "cmd"; last_cmd = info; } else if ( info->type & T_GRP_BEG ) { ctrl->opt_prefix = "grp"; last_cmd = info; } else if ( info->type & T_CMD_OPT && info->help && *info->help ) { if (!done) { print_section(cf,sep1,"alternate option infos"); done = true; } const info_t * info0; for ( info0 = ctrl->info; info0 < info; info0++ ) if ( info0->type & T_DEF_OPT && !strcmp(info->c_name,info0->c_name) ) { print_info_opt(ctrl,info,info0,last_cmd->c_name); break; } } } //----- print enum enumOptionsBit if ( ctrl->n_cmd ) { print_section(hf,sep1,"enum enumOptionsBit"); fprintf(hf, "//\t***** only for verification *****\n" "\n" "//typedef enum enumOptionsBit\n" "//{\n" "//\t//----- command specific options -----\n" "//\n" ); for ( info = ctrl->info; info < ctrl->end; info++ ) if ( info->type & F_OPT_COMMAND ) fprintf(hf,"//\tOB_%s%.*s= 1llu << OPT_%s,\n", info->c_name, ( 28 - (int)strlen(info->c_name) ) / 8, tabs, info->c_name ); fprintf(hf,"//\n//\t//----- group & command options -----\n"); for ( info = ctrl->info; info < ctrl->end; ) { ccp cmd_name; u8 * opt_allow = 0; if ( info->type & T_CMD_BEG ) { cmd_name = info->c_name; fprintf(hf,"//\n//\tOB_CMD_%s%.*s=", info->c_name, ( 24 - (int)strlen(info->c_name) ) / 8, tabs ); if (ctrl->opt_allow_cmd) { //PRINT("SELECT ALLOW CMD %u/%s\n",info->index,info->c_name); opt_allow = ctrl->opt_allow_cmd + info->index * ctrl->n_opt_specific; } } else if ( info->type & T_GRP_BEG ) { cmd_name = info->c_name; fprintf(hf,"//\n//\tOB_GRP_%s%.*s=", info->c_name, ( 24 - (int)strlen(info->c_name) ) / 8, tabs ); if (ctrl->opt_allow_grp) { //PRINT("SELECT ALLOW GRP %u/%s\n",info->index,info->c_name); opt_allow = ctrl->opt_allow_grp + info->index * ctrl->n_opt_specific; } } else { info++; continue; } info++; char * dest = iobuf; while ( info < ctrl->end ) { if ( info->type & T_ALL_OPT ) { dest += sprintf(dest,"\n//\t\t\t\t| ~(u64)0"); if (opt_allow) { //PRINT("ALLOW ALL\n"); memset(opt_allow,1,ctrl->n_opt_specific); } } else if ( info->type & T_COPY_CMD ) { dest += sprintf(dest,"\n//\t\t\t\t| OB_CMD_%s",info->c_name); if (opt_allow) { //PRINT("OR CMD %u/%s\n",info->index,info->c_name); DASSERT(ctrl->opt_allow_cmd); u8 * src = ctrl->opt_allow_cmd + info->index * ctrl->n_opt_specific; u8 * dest = opt_allow; int count = ctrl->n_opt_specific; while ( count-- > 0 ) *dest++ |= *src++; } } else if ( info->type & T_COPY_GRP ) { dest += sprintf(dest,"\n//\t\t\t\t| OB_GRP_%s",info->c_name); if ( opt_allow && ctrl->opt_allow_grp ) { //PRINT("OR GRP %u/%s\n",info->index,info->c_name); u8 * src = ctrl->opt_allow_grp + info->index * ctrl->n_opt_specific; u8 * dest = opt_allow; int count = ctrl->n_opt_specific; while ( count-- > 0 ) *dest++ |= *src++; } } else if ( info->type & T_CMD_OPT ) { if (FindStringField(&ctrl->copt,info->c_name)) { dest += sprintf(dest,"\n//\t\t\t\t| OB_%s",info->c_name); if ( opt_allow && info->index ) { //PRINT("ALLOW OPT %u/%s\n",info->index,info->c_name); opt_allow[info->index] = 1; } } else if (!FindStringField(&ctrl->gopt,info->c_name)) ERROR0(ERR_SEMANTIC,"Option not defined: %s %s --%s", tool_name, cmd_name, info->c_name ); } else if ( info->type & (T_CMD_BEG|T_GRP_BEG) ) break; ASSERT( dest < iobuf + sizeof(iobuf) ); info++; } if ( dest == iobuf ) fprintf(hf," 0,\n"); else fprintf(hf,"%s,\n",iobuf+8); } fprintf(hf,"//\n//} enumOptionsBit;\n"); } //----- print enum enumCommands & CommandTab[] print_section(hf,sep1,"enum enumCommands"); fprintf(hf, "typedef enum enumCommands\n" "{\n" "\tCMD__NONE," ); if ( ctrl->n_cmd ) { print_section(cf,sep1,"CommandTab[]"); fputs("\n\n",hf); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const CommandTab_t CommandTab[];\n"); fprintf(cf, "const CommandTab_t CommandTab[] =\n" "{\n" ); for ( info = ctrl->info; info < ctrl->end; info++ ) if ( info->type & T_DEF_CMD ) { fprintf( hf, "\tCMD_%s,\n",info->c_name); ccp ptr = info->namelist; while (*ptr) { ccp n1 = ptr; while ( *ptr && *ptr != '|' ) ptr++; const int l1 = ptr - n1; while ( *ptr == '|' ) ptr++; if (*ptr) { ccp n2 = ptr; while ( *ptr && *ptr != '|' ) ptr++; const int l2 = ptr - n2; fprintf(cf, " { CMD_%s,%.*s\"%.*s\",%.*s\"%.*s\",%.*s0 },\n", info->c_name, (20-(int)strlen(info->c_name))/8, tabs, l1, n1, (20-l1)/8, tabs, l2, n2, (20-l2)/8, tabs ); while ( *ptr == '|' ) ptr++; } else fprintf(cf, " { CMD_%s,%.*s\"%.*s\",%.*s0,\t\t0 },\n", info->c_name, (20-(int)strlen(info->c_name))/8, tabs, l1, n1, (20-l1)/8, tabs ); } } else if ( info->type == T_SEP_CMD ) fprintf(hf,"\n"); fprintf(cf, "\n { CMD__N,0,0,0 }\n" "};\n" ); } fprintf(hf, "\n\tCMD__N // == %u\n\n" "} enumCommands;\n" , ctrl->n_cmd ); //----- print options print_section(cf,sep1,"OptionShort & OptionLong"); char * dest = iobuf; for ( info = ctrl->info; info < ctrl->end; info++ ) if ( info->type & T_DEF_OPT && info->namelist[1] == '|' ) { *dest++ = info->namelist[0]; if ( info->type & F_OPT_OPTPARAM ) *dest++ = ':'; if ( info->type & (F_OPT_OPTPARAM|F_OPT_PARAM) ) *dest++ = ':'; } *dest = 0; fprintf(cf,"const char OptionShort[] = \"%s\";\n\n",iobuf); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const char OptionShort[];\n"); ccp opt_buf[OPT_INDEX_SIZE]; memset(opt_buf,0,sizeof(opt_buf)); int getopt_idx = OPT_LONG_BASE; fprintf(cf,"const struct option OptionLong[] =\n{\n"); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const struct option OptionLong[];\n"); for ( info = ctrl->info; info < ctrl->end; info++ ) if ( info->type & T_DEF_OPT ) { ccp ptr = info->namelist; const int pmode = (info->type & F_OPT_OPTPARAM) ? 2 : (info->type & F_OPT_PARAM) ? 1 : 0; if ( info->namelist[1] == '|' ) { snprintf(iobuf,sizeof(iobuf),"%d, 0, '%c'", pmode, info->namelist[0] ); ptr += 2; opt_buf[(u8)(info->namelist[0])] = info->c_name; } else { snprintf(iobuf,sizeof(iobuf),"%d, 0, GO_%s", pmode, info->c_name ); ASSERT_MSG( getopt_idx < OPT_INDEX_SIZE, "getopt_idx[%x] >= OPT_INDEX_SIZE[%x]\n", getopt_idx, OPT_INDEX_SIZE ); opt_buf[(u8)(getopt_idx++)] = info->c_name; } int indent = 0; while (*ptr) { ccp start = ptr; while ( *ptr && *ptr != '|' ) ptr++; const int len = ptr - start; fprintf(cf,"\t%s{ \"%.*s\",%.*s%s },\n", indent ? " " : "", len, start, (26-len-indent)/8, tabs, iobuf ); if (*ptr) ptr++; indent = 1; } } fprintf(cf,"\n\t{0,0,0,0}\n};\n"); //----- print enumGetOpt print_section(hf,sep1,"enumGetOpt"); fprintf(hf,"typedef enum enumGetOpt\n{"); // add '?' temporary; ASSERT(!opt_buf['?']); opt_buf['?'] = "_ERR"; static const int septab[] = { 0, '0', '9'+1, '?', '?'+1, 'A', 'Z'+1, 'a', 'z'+1, OPT_LONG_BASE, OPT_INDEX_SIZE }; const int * sepptr = septab; int i; for ( i = 0; i < OPT_INDEX_SIZE; i++ ) if ( opt_buf[i] ) { if ( i >= *sepptr ) { fputc('\n',hf); while ( i >= *sepptr ) sepptr++; } if ( i < OPT_LONG_BASE ) fprintf(hf,"\tGO_%s%.*s= '%c',\n", opt_buf[i], (28-(int)strlen(opt_buf[i]))/8, tabs, i ); else if ( i == OPT_LONG_BASE ) fprintf(hf,"\tGO_%s%.*s= 0x%02x,\n", opt_buf[i], (28-(int)strlen(opt_buf[i]))/8, tabs, i ); else fprintf(hf,"\tGO_%s,\n",opt_buf[i]); } fprintf(hf,"\n} enumGetOpt;\n"); opt_buf['?'] = 0; //----- print option index print_section(cf,sep1,"OptionUsed & OptionIndex"); fprintf(cf,"u8 OptionUsed[OPT__N_TOTAL+1] = {0};\n\n"); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern u8 OptionUsed[OPT__N_TOTAL+1];\n"); fprintf(cf,"const u8 OptionIndex[OPT_INDEX_SIZE] = \n{\n"); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const u8 OptionIndex[OPT_INDEX_SIZE];\n"); for ( i = 0; i < OPT_INDEX_SIZE; ) { int start = i; while ( i < OPT_INDEX_SIZE && !opt_buf[i] ) i++; int len = i - start; while ( len > 0 ) { const int now_len = len < 16 ? len : 16 - start % 16; fprintf(cf,"\t/* 0x%02x */\t %.*s\n", start, 2*now_len + now_len/4, "0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0," ); start += now_len; len -= now_len; } while ( i < OPT_INDEX_SIZE && opt_buf[i] ) { fprintf(cf,"\t/* 0x%02x %c */\tOPT_%s,\n", i, i > ' ' && i < 0x7f ? i : ' ', opt_buf[i]); i++; } } fprintf(cf,"};\n"); //----- option allowed if (ctrl->opt_allow_cmd) { print_section(cf,sep1,"opt_allowed_cmd_*"); for ( info = ctrl->info; info < ctrl->end; info++ ) { if ( !( info->type & T_DEF_CMD ) ) continue; fprintf(cf,"static u8 option_allowed_cmd_%s[%u] = // cmd #%u\n{", info->c_name, ctrl->n_opt_specific, info->index ); int i; u8 * ptr = ctrl->opt_allow_cmd + info->index * ctrl->n_opt_specific; for ( i = 0; i < ctrl->n_opt_specific; i++ ) fprintf(cf, "%s%u%s", !(i%30) ? "\n " : !(i%10) ? " " : !(i%5) ? " " : "", ptr[i], i < ctrl->n_opt_specific-1 ? "," : "" ); fprintf(cf,"\n};\n\n"); } } //----- InfoCommand print_links(ctrl); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const InfoCommand_t CommandInfo[CMD__N+1];\n"); //----- InfoUI print_section(cf,sep1,"InfoUI"); var_ptr += snprintf(var_ptr,var_end-var_ptr, "extern const InfoUI_t InfoUI;\n"); fprintf(cf, "const InfoUI_t InfoUI =\n" "{\n" "\t\"%s\",\n" // tool_name "\t%s\n" // n_cmd "\t%s\n" // cmd_tab "\tCommandInfo,\n" // cmd_info "\t%s\n" // n_opt_specific "\tOPT__N_TOTAL,\n" // n_opt_total "\tOptionInfo,\n" // opt_info "\tOptionUsed,\n" // opt_used "\tOptionIndex,\n" // opt_index "\tOptionShort,\n" // opt_short "\tOptionLong\n" // opt_long "};\n", ctrl->info->c_name, ctrl->n_cmd ? "CMD__N," : "0, // n_cmd", ctrl->n_cmd ? "CommandTab," : "0, // cmd_tab", ctrl->n_cmd ? "OPT__N_SPECIFIC," : "0, // n_opt_specific" ); //----- external vars print_section(hf,sep1,"external vars"); fputs(var_buf,hf); //----- terminate print_section(cf,sep1,"END"); print_section(hf,sep1,"END"); fprintf(hf,"#endif // %s\n\n",guard); return ERR_OK; };
Sint parsemaxmatoptions(MMcallinfo *mmcallinfo,int argc, char *argv[]) { OptionDescription options[NUMOFOPTIONS]; // store the options Sint optval; // neg. return val. if error, otherwise option number Uint argnum; // pointer to argv signed long readint; // temporary integer to read value from string char leastlengthtext[128+1]; initoptions(&options[0],(Uint) NUMOFOPTIONS); ADDOPTION(OPTMUM,"-mum", "compute maximal matches that are unique in both sequences"); ADDOPTION(OPTMUMREF,"-mumreference", "compute maximal matches that are unique in the reference-\n" "sequence but not necessarily in the query-sequence (default)"); ADDOPTION(OPTMUMCAND,"-mumcand", "same as -mumreference"); ADDOPTION(OPTMAXMATCH,"-maxmatch", "compute all maximal matches regardless of their uniqueness"); ADDOPTION(OPTMATCHNUCLEOTIDESONLY,"-n", "match only the characters a, c, g, or t\n" "they can be in upper or in lower case"); makeleastlengthtext(&leastlengthtext[0]); ADDOPTION(OPTLEASTLENGTH,"-l",&leastlengthtext[0]); ADDOPTION(OPTCOMPUTEBOTHDIRECTIONS,"-b", "compute forward and reverse complement matches"); ADDOPTION(OPTONLYREVERSECOMPLEMENT,"-r", "only compute reverse complement matches"); ADDOPTION(OPTSHOWSTRING,"-s", "show the matching substrings"); ADDOPTION(OPTSHOWREVERSEPOSITIONS,"-c", "report the query-position of a reverse complement match\n" "relative to the original query sequence"); ADDOPTION(OPTFOURCOLUMN,"-F", "force 4 column output format regardless of the number of\n" "reference sequence inputs"); ADDOPTION(OPTSHOWSEQUENCELENGTHS,"-L", "show the length of the query sequences on the header line"); ADDOPTION(OPTCHUNKS,"-C","number of chunks to split query sequence"); ADDOPTION(OPTPREFIXLENGTH,"-P","length of prefix for Direct Access Table"); ADDOPTION(OPTH,"-h", "show possible options"); ADDOPTION(OPTHELP,"-help", "show possible options"); mmcallinfo->showstring = false; mmcallinfo->reversecomplement = false; mmcallinfo->forward = true; mmcallinfo->showreversepositions = false; mmcallinfo->fourcolumn = false; mmcallinfo->showsequencelengths = false; mmcallinfo->matchnucleotidesonly = false; mmcallinfo->cmum = false; mmcallinfo->cmumcand = false; mmcallinfo->cmaxmatch = false; mmcallinfo->minmatchlength = (Uint) DEFAULTMINUNIQUEMATCHLEN; mmcallinfo->chunks = (Uint) DEFAULTCHUNK; if(argc == 1) { showusage(argv[0],&options[0],(Uint) NUMOFOPTIONS); return 1; } for(argnum = UintConst(1); argnum < (Uint) argc && argv[argnum][0] == '-'; argnum++) { optval = procoption(options,(Uint) NUMOFOPTIONS,argv[argnum]); if(optval < 0) { return -1; } switch(optval) { case OPTSHOWSTRING: mmcallinfo->showstring = true; break; case OPTCOMPUTEBOTHDIRECTIONS: mmcallinfo->reversecomplement = true; break; case OPTSHOWREVERSEPOSITIONS: mmcallinfo->showreversepositions = true; break; case OPTLEASTLENGTH: // additionally check the length parameter argnum++; if(argnum > (Uint) (argc-2)) { ERROR1("missing argument for option %s", options[OPTLEASTLENGTH].optname); return -2; } if(sscanf(argv[argnum],"%ld",&readint) != 1 || readint <= 0) { ERROR2("argument %s for option %s is not a positive integer", argv[argnum],options[OPTLEASTLENGTH].optname); return -3; } mmcallinfo->minmatchlength = (Uint) readint; break; case OPTFOURCOLUMN: mmcallinfo->fourcolumn = true; break; case OPTSHOWSEQUENCELENGTHS: mmcallinfo->showsequencelengths = true; break; case OPTMATCHNUCLEOTIDESONLY: mmcallinfo->matchnucleotidesonly = true; break; case OPTONLYREVERSECOMPLEMENT: mmcallinfo->forward = false; mmcallinfo->reversecomplement = true; break; case OPTMAXMATCH: mmcallinfo->cmaxmatch = true; break; case OPTMUMREF: case OPTMUMCAND: mmcallinfo->cmumcand = true; break; case OPTMUM: mmcallinfo->cmum = true; break; case OPTCHUNKS: argnum++; if(argnum > (Uint) (argc-2)) { ERROR1("missing argument for option %s", options[OPTCHUNKS].optname); return -2; } if(sscanf(argv[argnum],"%ld",&readint) != 1 || readint <= 0) { ERROR2("argument %s for option %s is not a positive integer", argv[argnum],options[OPTCHUNKS].optname); return -3; } mmcallinfo->chunks = (Uint) readint; break; case OPTPREFIXLENGTH: argnum++; if(argnum > (Uint) (argc-2)) { ERROR1("missing argument for option %s", options[OPTPREFIXLENGTH].optname); return -2; } if(sscanf(argv[argnum],"%ld",&readint) != 1 || readint <= 0) { ERROR2("argument %s for option %s is not a positive integer", argv[argnum],options[OPTPREFIXLENGTH].optname); return -3; } mmcallinfo->prefix = (Uint) readint; break; case OPTH: case OPTHELP: showusage(argv[0],&options[0],(Uint) NUMOFOPTIONS); return 1; } } if(argnum > (Uint) (argc-2)) { ERROR0("missing file arguments"); return -4; } if(safestringcopy(&mmcallinfo->program[0],argv[0],PATH_MAX) != 0) { return -5; } if(safestringcopy(&mmcallinfo->subjectfile[0],argv[argnum],PATH_MAX) != 0) { return -6; } for(argnum++, mmcallinfo->numofqueryfiles = 0; argnum < (Uint) argc; mmcallinfo->numofqueryfiles++, argnum++) { if(mmcallinfo->numofqueryfiles >= (Uint) MAXNUMOFQUERYFILES) { ERROR1("too many query files, maximal number is %d", (int) MAXNUMOFQUERYFILES); return -7; } if(safestringcopy(&mmcallinfo->queryfilelist [mmcallinfo->numofqueryfiles][0], argv[argnum],PATH_MAX) != 0) { return -8; } } /* verify that mum options are not interchanged */ OPTIONEXCLUDE(OPTMUM,OPTMUMCAND); OPTIONEXCLUDE(OPTMUM,OPTMUMREF); OPTIONEXCLUDE(OPTMUM,OPTMAXMATCH); OPTIONEXCLUDE(OPTMUMCAND,OPTMAXMATCH); OPTIONEXCLUDE(OPTMUMREF,OPTMAXMATCH); if ( mmcallinfo->cmaxmatch ) { mmcallinfo->cmum = false; mmcallinfo->cmumcand = false; } else if ( mmcallinfo->cmum ) { } else /* default to cmumcand */ { mmcallinfo->cmumcand = true; } /* verify that the options -b and -r are not used at the same time */ OPTIONEXCLUDE(OPTCOMPUTEBOTHDIRECTIONS,OPTONLYREVERSECOMPLEMENT); /* verify that -c is only used in combination with either -b or -r */ OPTIONIMPLYEITHER2(OPTSHOWREVERSEPOSITIONS, OPTCOMPUTEBOTHDIRECTIONS,OPTONLYREVERSECOMPLEMENT); return 0; }
static int get_authenticator (auth_t *auth, config_options_t *options) { if (auth->type == NULL) { WARN0 ("no authentication type defined"); return -1; } do { DEBUG1 ("type is %s", auth->type); if (strcmp (auth->type, "url") == 0) { #ifdef HAVE_AUTH_URL if (auth_get_url_auth (auth, options) < 0) return -1; break; #else ERROR0 ("Auth URL disabled, no libcurl support"); return -1; #endif } if (strcmp (auth->type, "command") == 0) { #ifdef WIN32 ERROR1("Authenticator type: \"%s\" not supported on win32 platform", auth->type); return -1; #else if (auth_get_cmd_auth (auth, options) < 0) return -1; break; #endif } if (strcmp (auth->type, "htpasswd") == 0) { if (auth_get_htpasswd_auth (auth, options) < 0) return -1; break; } ERROR1("Unrecognised authenticator type: \"%s\"", auth->type); return -1; } while (0); while (options) { if (strcmp (options->name, "allow_duplicate_users") == 0) auth->flags |= atoi (options->value) ? AUTH_ALLOW_LISTENER_DUP : 0; else if (strcmp(options->name, "realm") == 0) auth->realm = (char*)xmlStrdup (XMLSTR(options->value)); else if (strcmp(options->name, "drop_existing_listener") == 0) auth->flags |= atoi (options->value) ? AUTH_DEL_EXISTING_LISTENER : 0; else if (strcmp (options->name, "rejected_mount") == 0) auth->rejected_mount = (char*)xmlStrdup (XMLSTR(options->value)); else if (strcmp(options->name, "handlers") == 0) auth->handlers = atoi (options->value); options = options->next; } if (auth->handlers < 1) auth->handlers = 3; if (auth->handlers > 100) auth->handlers = 100; return 0; }