// >= 0 liczba odczytanych znakow // -1 EOF // -2 GOC_ERROR int goc_isReadArray(GOC_IStream *is, unsigned char *pBuffer, unsigned int nBuffer) { int cnt = 0; if ( is == NULL ) { GOC_ERROR("NULL Input Stream"); return -2; } if ( pBuffer == NULL ) { GOC_ERROR("NULL array"); return -2; } if ( is->readChar == NULL ) { GOC_ERROR("readChar function not implemented"); return -2; } while ( nBuffer-- ) { int c = is->readChar(is); if ( c < 0 ) break; *pBuffer = (unsigned char)c; pBuffer++; cnt++; } if ( cnt > 0 ) return cnt; else return -1; }
int main(int argc, char **argv) { if ( argc == 2 ) { const char *filename = argv[1]; xmlDoc *doc = NULL; xmlNode *root = NULL; // zaladowanie pliku if ( !filename ) { GOC_ERROR("Podano wartosn NULL"); return -1; } if ( !goc_isFileExists(filename) ) { GOC_BERROR("Plik [%s] nie istnieje", filename); return -1; } doc = xmlReadFile( filename, NULL, 0 ); if ( !doc ) { GOC_BERROR("Nieudane parsowanie pliku [%s]", filename); return -1; } root = xmlDocGetRootElement( doc ); if ( !root ) { GOC_ERROR("Nieudane pozyskanie galezi root"); return -1; } { StKlasa* k = fobDeserialize( (fobElement*)root ); fobSerialize( (fobElement*)k, stdout ); } } else { StKlasa* k = fobAlloc(cn_Klasa); k->name = goc_stringCopy(k->name, "Nazwa"); k->plist = goc_tableAdd(k->plist, &k->nlist, sizeof(char*)); k->plist[k->nlist-1] = goc_stringCopy(NULL, "alfa"); k->plist = goc_tableAdd(k->plist, &k->nlist, sizeof(char*)); k->plist[k->nlist-1] = goc_stringCopy(NULL, "beta"); fobSerialize( (fobElement*)k, stdout ); } return 0; }
int goc_isSeek(GOC_IStream *is, long offset, int whence) { if ( is == NULL ) { GOC_ERROR("NULL Input Stream"); return -2; } if ( is->seek == NULL ) { GOC_ERROR("reset function not implemented"); return -2; } return is->seek(is, offset, whence); }
int goc_isSetPos(GOC_IStream *is, long pos) { if ( is == NULL ) { GOC_ERROR("NULL Input Stream"); return -2; } if ( is->seek == NULL ) { GOC_ERROR("reset function not implemented"); return -2; } return is->seek(is, pos, SEEK_SET); }
// >=0 available bytes // -2 GOC_ERROR int goc_isAvailable(GOC_IStream *is) { if ( is == NULL ) { GOC_ERROR("NULL Input Stream"); return -2; } if ( is->available == NULL ) { GOC_ERROR("available function not implemented"); return -2; } return is->available(is); }
// >=0 odczytany znak // -1 EOF // -2 GOC_ERROR int goc_isReadChar(GOC_IStream *is) { if ( is == NULL ) { GOC_ERROR("NULL Input Stream"); return -2; } if ( is->readChar == NULL ) { GOC_ERROR("readChar function not implemented"); return -2; } return is->readChar(is); }
// == 0 OK // -2 GOC_ERROR int goc_isClose(GOC_IStream *is) { if ( is == NULL ) { GOC_ERROR("NULL Input Stream"); return -2; } if ( is->close == NULL ) { GOC_ERROR("close function not implemented"); return -2; } return is->close(is); }
// zajmij pamiêæ i przypisz domy¶lne warto¶ci Parameters* allocParameters() { Parameters* p = (Parameters*)malloc(sizeof(Parameters)); memset(p, 0, sizeof(Parameters)); if ( !p ) GOC_ERROR("Cannot allocate Parameters"); p->tempo = 60; p->pBeat = malloc(4*sizeof(Beat)); p->nBeat = 4; memset(p->pBeat, 0, p->nBeat*sizeof(Beat)); p->pBeat[BEAT_BASE].power = 0.75; p->pBeat[BEAT_BASE].freq = 880.00; p->pBeat[BEAT_ACCENT].power = 0.75; p->pBeat[BEAT_ACCENT].freq = 880.00; p->pBeat[BEAT_INTER].power = 0.75; p->pBeat[BEAT_INTER].freq = 880.00; p->pBeat[BEAT_QUIET].power = 0; p->pBeat[BEAT_QUIET].freq = 0.00; // p->freq = 880.0; // p->power = 0.75; p->tdur = 0.01; p->pdur = 3; p->measure = 4; p->inter = 0; p->flags = 0; p->tacts = 1; return p; }
// zwraca 1, gdy ok, 0 gdy koniec int playOneFrame() { size_t size; if (decoderRead(playBuf, &size) != DECODER_CODE_OK) { GOC_ERROR("Bad decoder read"); closeAudioFile(); return 0; } if ( size == 0 ) { closeAudioFile(); return 0; } if (playerPlay(playBuf, size) != PLAYER_CODE_OK) { GOC_ERROR("Error play"); closeAudioFile(); return 0; } return 1; }
char *goc_isReadLine(GOC_IStream *is) { int c; char buf[128]; char *tmp = NULL; int i; if ( is == NULL ) { GOC_ERROR("NULL input stream"); return NULL; } if ( is->readChar == NULL ) { GOC_ERROR("readChar function not implemented"); return NULL; } i = 0; memset(buf, 0, 128); while ( (c = is->readChar(is)) >= 0 ) { // linux end line if ( c == 0x0A ) break; buf[i++] = (char)c; if ( i == 127 ) { i = 0; tmp = goc_stringAdd(tmp, buf); memset(buf, 0, 128); } } if (( tmp == NULL ) && ( buf[0] == 0 ) && ( c < 0 )) return NULL; tmp = goc_stringAdd(tmp, buf); return tmp; }
int main(int argc, char **argv) { GOC_IStream *is = NULL; GOC_OStream *os = NULL; int c; // unsigned char *pBuff; // unsigned int nBuff; char *line; if ( argc < 2 ) { GOC_ERROR("No input file name"); return -1; } os = goc_memOStreamOpen(); GOC_INFO("--- GOC_FileIStream test"); is = goc_fileIStreamOpen(argv[1]); // nBuff = goc_isAvailable(is); // pBuff = malloc(nBuff); GOC_BINFO("Available: %d\n", goc_isAvailable(is)); // nBuff = 0; while ( (c = goc_isReadChar(is)) > 0 ) { goc_osWriteByte(os, (unsigned char)c); // pBuff[nBuff++] = c; putchar(c); } goc_isClose(is); GOC_INFO("--- GOC_MemIStream test\n"); is = goc_memIStreamAttach(goc_memOStreamGet(os), goc_memOStreamSize(os)); // nBuff = goc_isAvailable(is); GOC_BINFO("Available: %d\n", goc_isAvailable(is)); while ( (c = goc_isReadChar(is)) > 0 ) putchar(c); goc_isClose(is); GOC_INFO("--- GOC_FileIStream readLine test"); is = goc_fileIStreamOpen(argv[1]); while ( (line = goc_isReadLine(is)) ) { printf("%s\n", line); } goc_isClose(is); return 0; }
//--- FUNCTIONS --- static enum MixerCode alsaMixerCardClose(struct MixerSystem* system) { AlsaMixerCard* card = (AlsaMixerCard*)system->active; if ( !card ) { return MIXER_CODE_NO_ACTIVE_CARD; } if ( card->sndmixer ) { if ( snd_mixer_close( card->sndmixer ) < 0 ) { GOC_ERROR("Cannot close active mixer"); } card->sndmixer = NULL; card->mixerElement = goc_arrayFree( card->mixerElement ); } system->active = NULL; return MIXER_CODE_OK; }
int argBeatPower(char** argv, int pos, int argc, Parameters* p) { int bpos; float power; if ( argc <= pos + 2 ) { GOC_ERROR("Wrong arguments use"); return -1; } sscanf(argv[pos+1], "%d", &bpos); sscanf(argv[pos+2], "%f", &power); p->pBeat[bpos].power = power; return 3; }
int argBeatFreq(char** argv, int pos, int argc, Parameters* p) { int bpos; float freq; if ( argc <= pos + 2 ) { GOC_ERROR("Wrong arguments use"); return -1; } sscanf(argv[pos+1], "%d", &bpos); sscanf(argv[pos+2], "%f", &freq); p->pBeat[bpos].freq = freq; return 3; }