home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / casette-lbl / input_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-31  |  3.5 KB  |  163 lines

  1. /*
  2.  * Copyright (C) 1987, Thomas H. Smith -- San Francisco, California
  3.  *   Program 'Cassette':
  4.  *    Permission is granted to any individual or institution
  5.  *    to use, copy, modify, or redistribute this software so long as it
  6.  *    is not sold for profit and provided this copyright notice is retained.
  7.  *
  8.  *   PostScript is a registered trademark of Adobe Systems, Inc.
  9.  */
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #include "cassette.h"
  13.  
  14. static char buffer[BUFSIZ];
  15. static char *bufferlist[BUFSIZ];
  16. char *create_string(), *strip_white();
  17.  
  18.  
  19. char *
  20. input_title(fd)
  21. FILE *fd;
  22. {
  23.     buffer[0] = '\0';
  24.     (void) fgets(buffer, BUFSIZ, fd);
  25.     /* nuke trailing newline */
  26.     buffer[strlen(buffer) - 1] = '\0';
  27.     escape_parens(buffer);
  28.     return(create_string(strip_white(buffer)));
  29. }
  30.  
  31.  
  32. char *
  33. input_artist(fd)
  34. FILE *fd;
  35. {
  36.     buffer[0] = '\0';
  37.     (void) fgets(buffer, BUFSIZ, fd);
  38.     /* nuke trailing newline */
  39.     buffer[strlen(buffer) - 1] = '\0';
  40.     escape_parens(buffer);
  41.     return(create_string(strip_white(buffer)));
  42. }
  43.  
  44.  
  45. char *
  46. input_noise_reduction(fd, noise_type)
  47. FILE *fd;
  48. int *noise_type;
  49. {
  50.     char *noise;
  51.  
  52.     buffer[0] = '\0';
  53.     (void) fgets(buffer, BUFSIZ, fd);
  54.     /* nuke trailing newline */
  55.     buffer[strlen(buffer) - 1] = '\0';
  56.     escape_parens(buffer);
  57.     noise = create_string(strip_white(buffer));
  58.  
  59.     /* see if this is a common noise reduction type */
  60.     if (noise[0] == '\0') {
  61.     *noise_type = NONE;
  62.     } else if ((strncmp(noise, "dolby", 5) == 0) ||
  63.                 (strncmp(noise, "Dolby", 5) == 0)) {
  64.     if ((noise[strlen(noise)-1] == 'c') || (noise[strlen(noise)-1] == 'C'))
  65.         *noise_type = DOLBY_C;
  66.     else
  67.         *noise_type = DOLBY_B;
  68.     } else if ((strcmp(noise, "dbx") == 0) || (strcmp(noise, "DBX") == 0)) {
  69.     *noise_type = DBX;
  70.     } else {
  71.     *noise_type = OTHER;
  72.     }
  73.  
  74.     return(noise);
  75. }
  76.  
  77.  
  78. char **
  79. input_songs(fd)
  80. FILE *fd;
  81. {
  82.     register int index;
  83.     char **returnlist;
  84.     extern char *malloc();
  85.  
  86.     buffer[0] = '\0';
  87.     for (index = 0; index < BUFSIZ; index++) {
  88.     if (fgets(buffer, BUFSIZ, fd) == NULL)
  89.         break;
  90.     /* nuke trailing newline */
  91.     buffer[strlen(buffer) - 1] = '\0';
  92.     if (EMPTYSTRING(buffer))
  93.         break;
  94.     escape_parens(buffer);
  95.     bufferlist[index] = create_string(strip_white(buffer));
  96.     }
  97.  
  98.     returnlist = (char **) malloc((unsigned) index * sizeof(char *) + 1);
  99.     bcopy((char *) bufferlist, (char *) returnlist, index * sizeof(char *));
  100.     returnlist[index] = (char *) NULL;
  101.     return(returnlist);
  102. }
  103.  
  104.  
  105. free_song_list(songs)
  106. char **songs;
  107. {
  108.     register int index;
  109.  
  110.     for (index = 0; songs[index] != NULL; index++)
  111.     (void) free(songs[index]);
  112.     free((char *) songs);
  113. }
  114.  
  115.  
  116. static
  117. escape_parens(srcbuffer)
  118. char *srcbuffer;
  119. {
  120.     register char *src, *dest;
  121.     char destbuffer[BUFSIZ];
  122.     extern char *strcpy();
  123.  
  124.     for (src = srcbuffer, dest = destbuffer;
  125.                 (dest < &(destbuffer[BUFSIZ-1])) && (*src != '\0');
  126.                 src++, dest++) {
  127.     if ((*src == '(') || (*src == ')'))
  128.         *dest++ = '\\';
  129.     *dest = *src;
  130.     }
  131.     *dest = '\0';
  132.     (void) strcpy(srcbuffer, destbuffer);
  133. }
  134.  
  135.  
  136. static char *
  137. strip_white(string)
  138. char *string;
  139. {
  140.     register char *begin, *end;
  141.  
  142.     for (begin = string; isspace(*begin) && (*begin != '\0'); begin++) ;
  143.     for (end = &(begin[strlen(string) - 1]);
  144.                 isspace(*end) && (end != begin); end--) ;
  145.     if (end != begin)
  146.     *++end = '\0';
  147.  
  148.     return(begin);
  149. }
  150.  
  151.  
  152. static char *
  153. create_string(str)
  154. char *str;
  155. {
  156.     char *newstring;
  157.     extern char *malloc(), *strcpy();
  158.  
  159.     newstring = malloc((unsigned) strlen(str) + 1);
  160.     (void) strcpy(newstring, str);
  161.     return(newstring);
  162. }
  163.