home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <utils.h>
- #include <fcntl.h>
-
- char **nav, **opts;
- void bye();
-
- main(int ac, char **av)
- {
- int fp, nac, x, optnum;
- char ftb[35], btw[40];
- int byte1, byte2, sps, manual = 0;
- float Ptime;
-
- if (ac < 2 || INQUIRY) {
- fprintf(stderr, "Usage: SoundTime [-s<sps>] <file> [file] ...\n");
- exit(0);
- }
- if (!(nav = (char **)calloc(100, sizeof(char *)))) {
- fprintf(stderr, "No mem for file array.\n");
- exit(0);
- }
- if (!(opts = (char **)calloc(50, sizeof(char *)))) {
- fprintf(stderr, "No mem for option array.\n");
- bye();
- }
-
- nac = match_args(ac, av, nav, 0, opts);
- if (nac == -1) {
- fprintf(stderr, "CRITICAL memory shortage. REBOOT.\n");
- bye();
- }
- if (!nac) {
- fprintf(stderr, "No files specified.\n");
- bye();
- }
-
- if ((optnum = Opt(opts, "s")) != -1) {
- sps = atoi(OPTDATA(opts, optnum));
- manual = 1;
- }
- else
- sps = -1;
- if (!sps) {
- fprintf(stderr, "%s is an invalid sps\n", OPTDATA(opts, optnum));
- bye();
- }
- for (x = 0; x < nac; ++ x) {
- fp = open(nav[x], O_RDONLY);
- if (fp == -1) {
- complain("%s: %s", av[0], nav[x]);
- continue;
- }
- read(fp, ftb, 35);
- if (strncmp(&ftb[0], "FORM", 4) && strncmp(&ftb[8], "8SVX", 4)) {
- fprintf(stderr, "%s: %s: Not an 8SVX sound\n", av[0], nav[x]);
- close(fp);
- continue;
- }
- byte1 = ftb[32];
- byte2 = ftb[33];
- if (sps == -1)
- sps = byte1 * 256 + byte2;
- Ptime = (float)((float)SIZE(fp) / (float)sps);
- sprintf(btw, " (at %d samples per second)", sps);
- printf("%s: Playing time: %.2f seconds%s\n", nav[x], Ptime,
- manual ? btw : "");
- close(fp);
- }
- bye();
- }
- void bye()
- {
- FREE_ARR(nav); FREE_ARR(opts);
- exit(0);
- }
-