File: fix_length.patch

package info (click to toggle)
gmod 3.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,352 kB
  • ctags: 809
  • sloc: cpp: 7,772; makefile: 77
file content (203 lines) | stat: -rw-r--r-- 5,226 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
Here's a context-diff patch for gmod 2.0.1 which adds in the -C option.
It checks (uncompressed) songs to see if their length matches what gmod
read in.  If the file is longer (has garbage tacked onto the end), the
program moves the song to <filename>.old, then strips off the garbage.
The -C option is really only useful for cleaning up stuff that you've
ripped.

--Alexander Mohr

--begin included file--
*** gmod.c	Sat Apr  8 07:17:43 1995
--- ../ngmod/gmod.c	Sun Apr 23 12:02:19 1995
***************
*** 104,113 ****
    struct song_info song_char;
  #ifdef USE_X
    struct options_info options =
!   {255, 0, 1, 1, 0, 0, 0, 255, 0, 0, 100, 0};
  #else
    struct options_info options =
!   {255, 0, 0, 1, 1, 0, 0, 0, 255, 0, 0, 100, 0};
  #endif
    struct options_info saved_opt;
  #ifndef USE_X
--- 104,113 ----
    struct song_info song_char;
  #ifdef USE_X
    struct options_info options =
!   {255, 0, 1, 1, 0, 0, 0, 255, 0, 0, 100, 0, 0};
  #else
    struct options_info options =
!   {255, 0, 0, 1, 1, 0, 0, 0, 255, 0, 0, 100, 0, 0};
  #endif
    struct options_info saved_opt;
  #ifndef USE_X
*** load_mod.c	Sat Apr  8 07:17:43 1995
--- ../ngmod/load_mod.c	Sun Apr 23 12:41:47 1995
***************
*** 570,584 ****
    else
      ret_val = load_mod_module (mod_fd, name, song_char, options, header);
  
    if (compressed == MY_FALSE)
!     fclose (mod_fd);
    else
      {
        free (command);
        free (fixedname);		/* added by Peter Federighi */
        pclose (mod_fd);
      }
! 
    if (!ret_val)
      free_patterns (0);
    else
--- 572,658 ----
    else
      ret_val = load_mod_module (mod_fd, name, song_char, options, header);
  
+ 
    if (compressed == MY_FALSE)
!     {
!       if ( feof( mod_fd ) )
! 	{
! 	  fprintf( stderr, "Error: EOF Encountered.\n" );
! 	  fclose( mod_fd );
! 	}
!       else if ( options.check_only )  /* Added by Alexander Mohr */
! 	{
! 	  int true_length;
! 	  int is_eof;
! 	  
! 	  true_length = ftell( mod_fd );
! 	  fgetc( mod_fd );
! 	  is_eof = feof( mod_fd );
! 	  fprintf( stdout, "%s   Length: %7d\n",
! 		  is_eof ? "Check Passed" : "Check FAILED",
! 		  true_length );
! 	  fclose (mod_fd);
! 	  if ( !is_eof )
! 	    {
! 	      char tmp_name[400];
! 	      printf( "Attempting to fix %s...\n", name );
! 	      sprintf( tmp_name, "%s.old", name );
! 	      if ( link( name, tmp_name ) != 0 )
! 		{
! 		  printf( "Unable to link %s to %s.\n", name, tmp_name );
! 		}
! 	      else if ( unlink( name ) != 0 )
! 		{
! 		  printf( "Unable to unlink %s.\n", name );
! 		}
! 	      else
! 		{
! 		  unsigned char *storage;
! 		  storage = (unsigned char *)malloc( true_length * sizeof( unsigned char ) );
! 		  if ((mod_fd = fopen (tmp_name, "rb")) == NULL)
! 		    {
! 		      printf( "Unable to open %s.\n", tmp_name );
! 		    }
! 		  else if ( fread( storage, sizeof( unsigned char ), true_length, mod_fd )
! 			   != true_length )
! 		    {
! 		      printf( "Unable to read %d from %s.\n", true_length, tmp_name );
! 		    }
! 		  else
! 		    {
! 		      fclose( mod_fd );
! 		      if ((mod_fd = fopen (name, "wb")) == NULL)
! 			{
! 			  printf( "Unable to open %s for writing.\n", name );
! 			}
! 		      else if ( fwrite( storage, sizeof( unsigned char ), true_length, mod_fd )
! 			       != true_length )
! 			{
! 			  printf( "Unable to write %d to %s.\n", true_length, name );
! 			}
! 		      else
! 			{
! 			  fclose( mod_fd );
! 			  printf( "%s successfully fixed.\n", name );
! 			}
! 		    }
! 		  free( storage );
! 		}
! 	    }
! 	  ret_val = 0;
! 	}
!       else
! 	{
! 	  fclose (mod_fd);
! 	}
!     }
    else
      {
        free (command);
        free (fixedname);		/* added by Peter Federighi */
        pclose (mod_fd);
      }
!   
    if (!ret_val)
      free_patterns (0);
    else
*** parse.c	Sat Apr  8 07:17:44 1995
--- ../ngmod/parse.c	Sun Apr 23 11:59:16 1995
***************
*** 26,34 ****
    int option, num_err = 0;
  
  #ifdef USE_X
!   while ((option = getopt (argc, argv, "chP:rRv:")) != -1)
  #else
!   while ((option = getopt (argc, argv, "bcehlm:pP:qrRsv:xz5")) != -1)
  #endif
      switch (option)
        {
--- 26,34 ----
    int option, num_err = 0;
  
  #ifdef USE_X
!   while ((option = getopt (argc, argv, "cChP:rRv:")) != -1)
  #else
!   while ((option = getopt (argc, argv, "bcCehlm:pP:qrRsv:xz5")) != -1)
  #endif
      switch (option)
        {
***************
*** 42,47 ****
--- 42,48 ----
  	printf ("     -b     DISABLE BPM tempos\n");
  #endif
  	printf ("     -c     DISABLE compression of modules in memory\n");
+ 	printf ("     -C     Check and fix mod length (doesn't play songs)\n");
  #ifndef USE_X
  	printf ("     -e     Show empty samples (for messages)\n");
  #endif
***************
*** 74,79 ****
--- 75,83 ----
  	break;
        case 'c':
  	options->compress = 0;
+ 	break;
+       case 'C':
+ 	options->check_only = 1;
  	break;
        case 'e':
  	options->show_empty_samples = 1;
*** structs.h	Sat Apr  8 07:17:44 1995
--- ../ngmod/structs.h	Sun Apr 23 12:02:23 1995
***************
*** 121,126 ****
--- 121,127 ----
    unsigned char randomize;
    signed char pan_factor;
    unsigned char use_50hz;
+   unsigned char check_only;
  };
  
  struct sample_info
--end--