static int abcScan(abcScanner *as,abcHandler handler) { if (as) { while (as->state != S_EOF) { abcNextToken(as); switch(abcToken(as)) { case T_FIELD: case T_INFIELD: case T_NONE: break; default: if (handler) { if (handler(as) > 0) m_eof(as); } else { printf("%s\t\t", abcTokenName(as->token)); printf("[%s]\n", as->tokstr); } } } abcClose(as); return 0; } return 1; }
int main(int argc, char *argv[]) { abcScanner *scn; abcToken tok; chs_t abctext = NULL; int k; abctext = chsRead(abctext,stdin,'w'); if (abctext && *abctext) { scn = abcNewScanner(str,abctext); printf("<<\n%s\n>>\n",scn->abc); while ((tok = abcNextToken(scn)) != T_EOF) { printf("%04d %04X %04X ",abcLineNumber(scn), abcCurState(scn), abcToken(scn)); switch (tok) { case T_NOTE: printf("NOTE: "); printf("%c", abcNotePitch(scn)); printf("%.*s", abcNoteSharps(scn), "####"); printf("%.*s", abcNoteFlats(scn), "bbbb"); k = abcNoteDuration(scn); printf(" %d/%d",abcNumerator(k),abcDenominator(k)); printf(" oct: %d",abcNoteOctave(scn)); printf(" MIDI: %d",abcNoteMidi(scn)); printf(" cents: %d",abcNoteCents(scn)); printf("\n"); break; case T_INFIELD: case T_FIELD: switch (*abcTokenStart(scn,1)) { case 'K' : printf("KEY:"); printf(" %.*s", abcKeyTonicLen(scn), abcKeyTonicStart(scn)); printf(" %c", abcKeyMode(scn)); printf(" |%s|", abcKeyAccidentals(scn)); printf(" t=%d", abcKeyTranspose(scn)); printf("\n"); break; default: printf("%.*s", abcTokenLen(scn,0),abcTokenStart(scn,0)); if (tok == T_INFIELD) printf("\n"); } break; default: printf("%.*s\n", abcTokenLen(scn,0),abcTokenStart(scn,0)); } } scn = abcFreeScanner(scn); } return(0); }
int main(int argc, char *argv[]) { FILE *f; int init_state; abcToken tok; chs_t abctext = NULL; if (argc < 2) { /* reading from stdin; assume it's all music */ init_state = S_TUNE; f = stdin; } else { /* reading from file; header may exist */ init_state = S_NONE; f = fopen(argv[1],"rb"); if (!f) { fprintf(stderr,"Unable to open input file\n"); exit(1); } } chsRead(abctext, f, 'w'); if (f != stdin) fclose(f); if (abctext && *abctext) { scn = abcScannerNew(str, abctext); abcStateSet(scn, init_state); while ((tok = abcNextToken(scn)) != T_EOF) { parse(tok); } scn = abcScannerFree(scn); } chsFree(abctext); return 0; }