/*-------------------------------------------------------------------------*/ static int readfiles (void) /* Read and analyse all files. * If a file can't be read, print a message. * Return 0 if all went well, RETURN_WARN if one of the files could not be * found, RETURN_ERROR if one of the files could not be read properly. */ { int rc; /* Return value */ Node * pNode; /* Node of the file under examination */ int srcRead; /* Number of source files read */ const char * pName; /* Includefile name returned by reader */ rc = 0; srcRead = 0; while (NULL != (pNode = nodes_todo()) ) { int bSystem; /* TRUE if it's a <> include */ if (pNode->flags & NODE_NOTFND) continue; if (!reader_open(pNode->pName)) { rc = readerror(pNode, rc, FALSE); continue; } /* If (can't open pNode->pName) */ if (bVerbose) { printf(" reading %-65s\r", pNode->pName); fflush(stdout); } while (NULL != (pName = reader_get(&bSystem)) ) { int index; /* index into aIncl[] */ Node * pChild; /* Node of included file, NULL if not found */ Node * pChFirst; /* First 'direct' child node */ for (index = -1, pChild = NULL, pChFirst = NULL ; !pChild && index < iInclSize ; index++) { char aName[FILENAME_MAX+1]; char * pCName; /* aName[] cleaned up */ char * pCBase; /* Namepart in *pCName */ /* Don't look for system includes in non-system directories. */ if (index >= 0 && bSplitPath && bSystem && !aIncl[index].bSysPath) continue; aName[FILENAME_MAX] = '\0'; if (index < 0) { /* Special case: look directly for the filename. * If bSplitPath is given, or if the filename is absolute, * use it unchanged. Else, use the path of the including * file as anchor. */ if (bSplitPath || '/' == *pName) strcpy(aName, pName); else { size_t oFilename; oFilename = (unsigned)(pNode->pBase - pNode->pName); strncpy(aName, pNode->pName, oFilename); strcpy(aName+oFilename, pName); } } else { /* Standard case: build the pathname from the include * pathname. */ strcpy(aName, aIncl[index].pPath); strcat(aName, pName); } /* Cleanup the filename and check if it is listed in * the tree */ pCName = util_getpath(aName, &pCBase); if (!pCName) { if (bVerbose) printf("%-78s\r", ""); reader_close(); exit_nomem(" (readfiles: 1. util_getpath)"); } pChild = nodes_findadd(pCName, TRUE); if (pChild->flags & NODE_NEW) { /* New file: check if it exists and set up the * node properly */ struct stat aStat; pChild->pName = pCName; pChild->pBase = pCBase; if (index >= 0) { pChild->pPath = util_getpath(pName, NULL); pChild->iInclude = index; } else if (pNode->iInclude < 0 || pNode->flags & NODE_SOURCE) { pChild->pPath = util_getpath(pCName, NULL); pChild->iInclude = -1; } else { strcpy(aName, pNode->pPath); strcat(aName, pName); pChild->pPath = util_getpath(aName, NULL); pChild->iInclude = pNode->iInclude; } if (!pChild->pPath) { if (bVerbose) printf("%-78s\r", ""); reader_close(); exit_nomem(" (readfiles: 2. util_getpath)"); } pChild->flags = (short)(bSystem ? NODE_SYSTEM : 0); /* It's ok to not find <>-includes - they just don't have * to appear in the output then. */ if (stat(pCName, &aStat)) pChild->flags |= NODE_NOTFND | (bSystem ? NODE_IGNORE : 0); } /* The pChFirst is needed if the include can't be found * so we can keep track from where it is included. */ if (index < 0) pChFirst = pChild; /* Test if the file for pChild exists. */ if (pChild->flags & NODE_NOTFND) { /* Make sure that the file is listed in the warnings * if appropriate. */ if (index >= 0) pChild->flags |= NODE_IGNORE; else if ((pChild->flags & NODE_IGNORE) && !bSystem) pChild->flags ^= NODE_IGNORE; pChild = NULL; } /* For absolute pNames, only index -1 is tried */ if ('/' == *pName) break; } /* for (index = -1..iInclSize) */ assert(pChFirst != NULL); if (pChild ? nodes_depend(pChild, pNode) : nodes_depend(pChFirst, pNode)) { if (bVerbose) printf("%-78s\r", ""); reader_close(); exit_nomem(" (readfiles: nodes_depend)"); } } /* while(get pName from file */ if (bVerbose) printf("%-78s\r", ""); if (!reader_eof() || reader_close()) { perror(aPgmName); printf("%s: Error reading '%s'\n", aPgmName, pNode->pName); rc = RETURN_ERROR; } else if (pNode->flags & NODE_SOURCE) { srcRead++; } } /* while (nodes_todo()) */ if (!srcRead) { printf("%s: No source file read.\n", aPgmName); rc = RETURN_ERROR; } /* Walk tree and print all include files not found */ nodes_initwalk(); while (rc != RETURN_ERROR && NULL != (pNode = nodes_inorder()) ) { if ((pNode->flags & (NODE_NOTFND|NODE_IGNORE)) == NODE_NOTFND) { if (pNode->pUsers) rc = readerror(pNode, rc, TRUE); else pNode->flags |= NODE_IGNORE; } } if (bVerbose) fflush(stdout); return rc; }
static int mad_play_frame(input_object *obj, char *buf) { struct mad_local_data *data; struct mad_pcm *pcm; mad_fixed_t const *left_ch; mad_fixed_t const *right_ch; int16_t *output; int nsamples; int nchannels; if (!obj) return 0; data = (struct mad_local_data *)obj->local_data; if (!data) return 0; if (data->bytes_avail < 3072) { /* alsaplayer_error("Filling buffer = %d,%d", data->bytes_avail, data->map_offset + MAD_BUFSIZE - data->bytes_avail); */ fill_buffer(data, -1); /* data->map_offset + MAD_BUFSIZE - data->bytes_avail); */ mad_stream_buffer(&data->stream, data->mad_map, data->bytes_avail); } else { /* alsaplayer_error("bytes_avail = %d", data->bytes_avail); */ } if (mad_frame_decode(&data->frame, &data->stream) == -1) { if (!MAD_RECOVERABLE(data->stream.error)) { /* alsaplayer_error("MAD error: %s (%d). fatal", error_str(data->stream.error, data->str), data->bytes_avail); */ mad_frame_mute(&data->frame); return 0; } else { if (reader_eof(data->mad_fd)) { return 0; } //alsaplayer_error("MAD error: %s (not fatal)", error_str(data->stream.error, data->str)); memset(buf, 0, obj->frame_size); return 1; } } data->current_frame++; if (data->seekable && data->current_frame < (obj->nr_frames + FRAME_RESERVE)) { data->frames[data->current_frame] = data->map_offset + data->stream.this_frame - data->mad_map; if (data->current_frame > 3 && (data->frames[data->current_frame] - data->frames[data->current_frame-3]) < 6) { return 0; } if (data->highest_frame < data->current_frame) data->highest_frame = data->current_frame; } mad_synth_frame (&data->synth, &data->frame); { pcm = &data->synth.pcm; output = (int16_t *)buf; nsamples = pcm->length; nchannels = pcm->channels; if (nchannels != obj->nr_channels) { alsaplayer_error("ERROR: bad data stream! (channels: %d != %d, frame %d)", nchannels, obj->nr_channels, data->current_frame); mad_frame_mute(&data->frame); memset(buf, 0, obj->frame_size); return 1; } obj->nr_channels = nchannels; if (data->samplerate != data->frame.header.samplerate) { alsaplayer_error("ERROR: bad data stream! (samplerate: %d != %d, frame %d)", data->samplerate, data->frame.header.samplerate, data->current_frame); mad_frame_mute(&data->frame); memset(buf, 0, obj->frame_size); return 1; } data->samplerate = data->frame.header.samplerate; left_ch = pcm->samples[0]; right_ch = pcm->samples[1]; while (nsamples--) { *output++ = my_scale(*(left_ch++)); if (nchannels == 1) { *output++ = my_scale(*(left_ch-1)); } else { /* nchannels == 2 */ *output++ = my_scale(*(right_ch++)); } } } data->bytes_avail = data->stream.bufend - data->stream.next_frame; return 1; }