home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Beijing Paradise BBS Backup
/
PARADISE.ISO
/
software
/
BBSDOORW
/
MUL100.ZIP
/
MAXPLAY.SCR
< prev
next >
Wrap
Text File
|
1993-02-01
|
7KB
|
212 lines
// MAXPLAY.SCR -- Play Maximus-CBCS Tunes -- Version 1.00
//
// Script program for MUL - the Maximus User Language
// MUL is (C) Copyright 1990-93 by CodeLand Australia
//
// USAGE: MUL -pMaxplay or
// MUL -pMaxplay Tunes.Bbs or
// MUL -pMaxplay /Yell1 or
// MUL -pMaxplay Tunes.Bbs /Yell1
char *banner = "MAXPLAY v1.00"; // Script banner
char *desc = "Play Maximus-CBCS TUNES"; // Description
char *abort = "\nKeyboard ABORT\n"; // Keyboard abort
char fname[80]; // Tunes file name
long fp; // Tunes file handle
char tune[40]; // Tune to play
int note; // Note to play
int duration; // Duration for play
int gotnote; // Got note flag
int notedisplay; // Display control flag
int selfound=0; // Selection found flag
int rotor; // Rotor display flag
main (int argc, char *arg1, char *arg2) // Main program
{
char bf[256]; // File read buffer
printf ("\n%s - %s\n",banner,desc); // Announce
getcmdline (argc,arg1,arg2); // Get the command line
openfile (fname); // Open the tunes file
// Display selection
if (*tune) printf ("\nSearching \"%s\" for \"%s\" .. ",fname,tune);
else printf ("\nPlaying file \"%s\"\n",fname);
while (1) { // Main loop
if (!fgets (bf,256,fp)) break; // Abort if end of file
if (strchr (bf,'*')) { // Tune start
if (*tune) { // If tune selected
if (thetune (bf)) { // If this is the tune
++selfound; // Flag tune as found
puts(" \n"); // Cleanup after search
playtune (bf); // Play the tune
keyabort (); // Abort if key hit
break; // And exit
}
showrotor (); // Display search rotor
}
else {
playtune (bf); // Else play the tune
Play (0,1000); // Pause one second between tunes
}
if (keyabort ()) break; // Abort if key hit
if (feof (fp)) break; // Abort if end of file
}
}
fclose (fp); // Close the tunes file
// If selection not found report it
if (*tune && !selfound) {
printf ("\nTune \"%s\" NOT found\n",tune);
}
saybibi (); // Was it good for you too?
}
// openfile - opens a text file for reading
openfile (char *nam)
{
fp=fopen (nam,"r");
if (!fp) {
printf ("\nERROR opening file \"%s\"\n",nam);
saybibi ();
exit ();
}
}
// Check for selected tune match
thetune (char *line)
{
char *p;
p=strchr (line,'*');
p++;
while (isspace (*p)) p++;
if(!strnicmp(p,tune,strlen(tune))) return 1;
return 0;
}
// Check for keyboard abort
keyabort ()
{
if (kbhit ()) { // Abort if key hit
getch (); // Get the character
putch (' '); // Rotor cleanup
puts (abort); // Acknowledge abort
++selfound; // Turn off not found message
return 1; // Exit play loop
}
return 0;
}
// Convert a string to upper case
stringtoupper (char *s)
{
while (*s) { *s=toupper(*s); s++; }
}
// Display the rotor 8-)
showrotor ()
{
if (++rotor>16) rotor=1;
if (rotor==4) puts ("-\b");
else if (rotor==8) puts ("\\\b");
else if (rotor==12) puts ("|\b");
else if (rotor==16) puts ("/\b");
}
// Play the tune
playtune (char *bf)
{
printf ("\n"); // Display blank line
do { // Skip dupe comment lines
printf ("%s",bf); // Display comment line
if (!fgets (bf,256,fp)) return; // Abort if end of file
} while (strchr (bf,'*')); // While a comment line
gotnote=0; // Reset flag for tune start
notedisplay=5; // Reset display control
do { // Play the tune
if (strlen (bf)<2) break; // Check for end of tune
playline (bf); // Play the line
if (kbhit ()) break; // Abort if key hit
} while (fgets (bf,256,fp)); // While lines available
if (notedisplay!=5) printf ("\n"); // End the note display line
}
// Play notes in line buffer
playline (char *p)
{
char *ptr=strtok (p," \t\n\r"); // Get first token
if (!*ptr) return; // Abort if none
do { // Process the line
if (kbhit ()) break; // Abort if key hit
if (!gotnote) { // If waiting for note value
note=atoi (ptr); // Get note value
gotnote++; // Increment flag
}
else { // Else get duration value
duration=atoi (ptr); // Get duration value
gotnote=0; // Reset got note flag
printf ("N:%4d D:%4d ", // Display the note & duration
note,duration);
if (!--notedisplay) { // Decrement display control
notedisplay=5; // Reset the display control flag
printf ("\n"); // Terminate the line
}
Play (note,duration); // Play the note
}
} while (ptr=strtok (0," \t\n\r"));
}
// Get the command line
getcmdline (int argc, char *arg1, char *arg2)
{
// Load command line tunes file and tune selection options
strcpy (fname,"TUNES.BBS"); // Default tunes name
if (argc) {
if (arg1[0] == '/') strcpy (tune,arg1+1);
else strcpy (fname,arg1);
}
if (argc>1) {
if (arg2[0] == '/') strcpy (tune,arg2+1);
else strcpy (fname,arg2);
}
stringtoupper (tune); // Change string to upper case
stringtoupper (fname); // Change string to upper case
}
// Byebye
saybibi ()
{
puts ("\nMaxPlay done!\n");
}
// End of script