Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PopovEvgeniy committed Aug 21, 2019
1 parent 04ac341 commit f8b5862
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
12 changes: 7 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Mugen sound extractor by Popov Evgeniy Alekseyevich

Version 2.3.5.1
Version 2.3.6


System requirement
Expand All @@ -17,9 +17,10 @@ This program takes a target file name as command line argument.
Exit codes

0 - Operation successfully complete.
1 - Can't allocate memory.
2 - File operation error.
3 - Invalid format.
1 - Can't open input file.
2 - Can't create output file.
3 - Can't allocate memory.
4 - Invalid format.

License

Expand Down Expand Up @@ -57,4 +58,5 @@ Version history
2.3.1 - Source code was improved. Linux support has been added.
2.3.1.0.1 Documentation was updated.
2.3.2 - 2.3.5 - Small changes.
2.3.5.1 - Makefile was updated.
2.3.5.1 - Makefile was updated.
2.3.6 - Small changes.
73 changes: 40 additions & 33 deletions sndextract.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FILE *create_output_file(const char *name);
void go_offset(FILE *file,const unsigned long int offset);
unsigned long int get_file_size(FILE *file);
void data_dump(FILE *input,FILE *output,const size_t length);
void fast_data_dump(FILE *input,FILE *output,const size_t length);
void write_output_file(FILE *input,const char *name,const size_t length);
char *get_string_memory(const size_t length);
size_t get_extension_position(const char *source);
Expand Down Expand Up @@ -43,28 +44,28 @@ int main(int argc, char *argv[])

void show_intro()
{
puts(" ");
putchar('\n');
puts("SND EXTRACT");
puts("Version 2.3.5");
puts("Mugen sound extractor by Popov Evgeniy Alekseyevich, 2008-2018 year");
puts("Version 2.3.6");
puts("Mugen sound extractor by Popov Evgeniy Alekseyevich, 2008-2019 years");
puts("This program distributed under GNU GENERAL PUBLIC LICENSE");
}

void command_line_help()
{
puts(" ");
putchar('\n');
puts("You must give a target file name as command line argument!");
}

void show_start_message()
{
puts(" ");
putchar('\n');
puts("Extracting a sounds... Please wait");
}

void show_end_message()
{
puts(" ");
putchar('\n');
puts("Work finish");
}

Expand All @@ -80,28 +81,28 @@ void show_progress(const unsigned long int start,const unsigned long int stop)

FILE *open_input_file(const char *name)
{
FILE *file;
file=fopen(name,"rb");
if (file==NULL)
FILE *target;
target=fopen(name,"rb");
if (target==NULL)
{
puts(" ");
puts("File operation error");
exit(2);
putchar('\n');
puts("Can't open input file");
exit(1);
}
return file;
return target;
}

FILE *create_output_file(const char *name)
{
FILE *file;
file=fopen(name,"wb");
if (file==NULL)
FILE *target;
target=fopen(name,"wb");
if (target==NULL)
{
puts(" ");
puts("File operation error");
putchar('\n');
puts("Can't create ouput file");
exit(2);
}
return file;
return target;
}

void go_offset(FILE *file,const unsigned long int offset)
Expand All @@ -120,23 +121,29 @@ unsigned long int get_file_size(FILE *file)

void data_dump(FILE *input,FILE *output,const size_t length)
{
unsigned char single_byte;
unsigned char data;
size_t index;
data=0;
for (index=0;index<length;++index)
{
fread(&data,sizeof(unsigned char),1,input);
fwrite(&data,sizeof(unsigned char),1,input);
}

}

void fast_data_dump(FILE *input,FILE *output,const size_t length)
{
unsigned char *buffer=NULL;
buffer=(unsigned char*)calloc(length,sizeof(unsigned char));
if (buffer==NULL)
{
for(index=0;index<length;++index)
{
fread(&single_byte,1,1,input);
fwrite(&single_byte,1,1,output);
}

data_dump(input,output,length);
}
else
{
fread(buffer,length,1,input);
fwrite(buffer,length,1,output);
fread(buffer,sizeof(unsigned char),length,input);
fwrite(buffer,sizeof(unsigned char),length,output);
free(buffer);
}

Expand All @@ -146,7 +153,7 @@ void write_output_file(FILE *input,const char *name,const size_t length)
{
FILE *output;
output=create_output_file(name);
data_dump(input,output,length);
fast_data_dump(input,output,length);
fclose(output);
}

Expand All @@ -156,9 +163,9 @@ char *get_string_memory(const size_t length)
memory=(char*)calloc(length+1,sizeof(char));
if(memory==NULL)
{
puts(" ");
putchar('\n');
puts("Can't allocate memory");
exit(1);
exit(3);
}
return memory;
}
Expand Down Expand Up @@ -204,9 +211,9 @@ head read_head(FILE *file)
fread(&snd_head,sizeof(head),1,file);
if (strncmp(snd_head.signature,"ElecbyteSnd",12)!=0)
{
puts(" ");
putchar('\n');
puts("Bad signature of a mugen sound pseudo-archive");
exit(3);
exit(4);
}
return snd_head;
}
Expand Down

0 comments on commit f8b5862

Please sign in to comment.