int main(int argc, char *argv[]) { extern jmp_buf catch_error; switch (setjmp(catch_error)) { /* set return point for errors */ case 0: /* handling */ initglobals(); /* sequential case (setjmp call) */ initfuncs(data_funs); initfuncs(eval_funs); break; case 1: /* error calling */ return EXIT_FAILURE; case 2: /* correct EOF */ return EXIT_SUCCESS; } for (;;) print(eval(read(nil)), nil); return EXIT_SUCCESS; /* Never reached */ }
main(int argc, char *argv[], char *envp[]) { LONG result; UCHAR buf[60]; /* If no filename arg supplied by user, exit with usage info */ if ( argc < 2 ) { printf("This program writes out a 'dummy' MIDI (sequencer) file.\r\n"); printf("It requires MIDIFILE.DLL to run.\r\n"); printf("Syntax: MFWRITE.EXE filename [0, 1, or 2 (for Format)]\r\n"); exit(1); } printf("Writing %s...\r\n", argv[1]); /* Initialize the pointers to our callback functions (ie, for the MIDIFILE.DLL to call) */ initfuncs(argv[1]); /* NOTE: We can initialize the MThd before the call to MidiWriteFile(), or we can do it in our StartMThd callback. We'll do it now since we don't need to do anything else right before the MThd is written out (ie, and so don't need a StartMThd callback) */ mfs.Format = 0; mfs.NumTracks = 1; if (argc>2) { /* User wants us to write out a particular Format. If not 0, then write 2 MTrk chunks */ if ( (mfs.Format = atoi(argv[2])) ) { mfs.NumTracks = 2; trk_ptrs[0] = &trk1[0]; } } mfs.Division = 96; /* Arbitrarily chose 96 PPQN for my time-stamps */ /* Make it easier for me to specify Tempo and Time Signature events */ mfs.Flags = MIDIBPM|MIDIDENOM; /* Tell MIDIFILE.DLL to write out the file, calling my callback functions */ result = MidiWriteFile(&mfs); /* Print out error message */ MidiGetErr(&mfs, result, &buf[0]); printf(&buf[0]); exit(0); }