home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / SOUNDUTILS / mm1_tracker.lzh / TRACKER4.6 / split.c < prev    next >
C/C++ Source or Header  |  1994-11-24  |  3KB  |  157 lines

  1. /* split.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5.  
  6. /* $Id: split.c,v 4.4 1994/11/15 16:11:01 espie Exp espie $
  7.  * $Log: split.c,v $
  8.  * Revision 4.4  1994/11/15  16:11:01  espie
  9.  * *** empty log message ***
  10.  *
  11.  *
  12.  * Revision 4.0  1994/01/11  17:56:24  espie
  13.  * Cleaner.
  14.  * run_in_fg() and create_notes_table() not needed !
  15.  * Use new pref scheme.
  16.  */
  17.      
  18.  
  19. #include <stdio.h>
  20. #include <signal.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #ifndef AMIGA
  24. #include <malloc.h>
  25. #endif
  26.      
  27. #include "defs.h"
  28. #include "song.h"
  29. #include "extern.h"
  30.      
  31. #include "getopt.h"
  32.      
  33. ID("$Id: split.c,v 4.4 1994/11/15 16:11:01 espie Exp espie $")
  34.  
  35. /* global variable to catch various types of errors
  36.  * and achieve the desired flow of control
  37.  */
  38. int error;
  39.  
  40. LOCAL struct song *do_scan_song(name, type)
  41. char *name;
  42. int type;
  43.    {
  44.    struct song *song;
  45.    struct exfile *file;
  46.  
  47.    file = open_file(name, "r", getenv("MODPATH"));
  48.    if (!file)
  49.       return NULL;
  50.    song = read_song(file, type); 
  51.    close_file(file);
  52.    return song;
  53.    }
  54.  
  55. #define CHUNK_SIZE 32000
  56.  
  57. LOCAL char *suffix[] =
  58.    {
  59.    "lzh", "lha", "Z", "z", "shn", "zoo", 0
  60.    };
  61.  
  62. LOCAL void truncate(name)
  63. char *name;
  64.    {
  65.    int i;
  66.    int last_point = 0;
  67.  
  68.    for (i = 0; name[i]; i++)
  69.       {
  70.       if (name[i] == '.')
  71.          last_point = i + 1;
  72.       }
  73.    if (last_point)
  74.       {
  75.       for (i = 0; suffix[i]; i++)
  76.       if (strcmp(name + last_point, suffix[i]) == 0)
  77.          {
  78.          name[last_point - 1] = 0;
  79.          return;
  80.          }
  81.       }
  82.    }
  83.  
  84.    
  85.    
  86. void split_module(name, cutpoint)
  87. char *name;
  88. long cutpoint;
  89.    {
  90.    char buffer[300];
  91.    FILE *mod;
  92.    FILE *samp;
  93.    struct exfile *file;
  94.    char *copy_buff;
  95.    int chunk;
  96.  
  97.    file = open_file(name, "r", getenv("MODPATH"));
  98.    truncate(name);
  99.    sprintf(buffer, "%s.mod", name);
  100.    mod = fopen(buffer, "w");
  101.    if (!mod)
  102.       exit(10);
  103.    sprintf(buffer, "%s.samp", name);
  104.    samp = fopen(buffer, "w");
  105.    if (!samp)
  106.       exit(10);
  107.    copy_buff = malloc(CHUNK_SIZE);
  108.    if (!copy_buff)
  109.       exit(10);
  110.    while(cutpoint >= CHUNK_SIZE)
  111.       {
  112.       fread(copy_buff, 1, CHUNK_SIZE, file_handle(file));
  113.       fwrite(copy_buff, 1, CHUNK_SIZE, mod);
  114.       cutpoint -= CHUNK_SIZE;
  115.       }
  116.    if (cutpoint > 0)
  117.       {
  118.       fread(copy_buff, 1, cutpoint, file_handle(file));
  119.       fwrite(copy_buff, 1, cutpoint, mod);
  120.       }
  121.    fclose(mod);
  122.    while ((chunk = fread(copy_buff, 1, CHUNK_SIZE, file_handle(file))) > 0)
  123.       fwrite(copy_buff, 1, chunk, samp);
  124.    fclose(samp);
  125.    close_file(file);
  126.    }
  127.       
  128.    
  129.  
  130.  
  131. int main(argc, argv)
  132. int argc;
  133. char **argv;
  134.    {
  135.    struct song *song;
  136.    int i;
  137.    int default_type;
  138.  
  139.  
  140.    default_type = BOTH;
  141.  
  142.    for (i = 1; i < argc; i++)
  143.       {
  144.       song = do_scan_song(argv[i], NEW);
  145.       if (!song && error != NEXT_SONG)
  146.          song = do_scan_song(argv[i], OLD);
  147.       if (song)
  148.          {
  149.          dump_song(song); 
  150.          split_module(argv[i], song->samples_start);
  151.          release_song(song);
  152.          }
  153.       }
  154.    }
  155.  
  156.  
  157.