Created
October 10, 2023 00:08
-
-
Save suzukiplan/1c76532218175c7c364bcffabd88c785 to your computer and use it in GitHub Desktop.
PMD Extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PMD extractor */ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(int argc,char* argv[]) | |
{ | |
char fn[16]; | |
int ret=-1; | |
FILE* fp=NULL; | |
char* rbuf=NULL; | |
size_t rsize; | |
int i; | |
int j; | |
int n; | |
if(argc<1) { | |
puts("usage: extpmd file"); | |
goto ENDPROC; | |
} | |
fp=fopen(argv[1],"rb"); | |
if(NULL==fp) { | |
puts("Could not open the input file."); | |
goto ENDPROC; | |
} | |
fseek(fp,0,SEEK_END); | |
rsize=(size_t)ftell(fp); | |
fseek(fp,0,SEEK_SET); | |
if(rsize<1) goto ENDPROC; | |
rbuf=(char*)malloc(rsize); | |
if(NULL==rbuf) { | |
puts("No memory."); | |
goto ENDPROC; | |
} | |
fread(rbuf,rsize,1,fp); | |
fclose(fp); | |
fp=NULL; | |
printf("size=%u\n",(unsigned int)rsize); | |
n=0; | |
j=-1; | |
for(i=0;i<rsize;i++) { | |
if(rbuf[i ]==0x00 | |
&& rbuf[i+1]==0x1A | |
&& rbuf[i+2]==0x00) { | |
if(j!=-1) { | |
sprintf(fn,"song%04d.m",n++); | |
puts(fn); | |
fp=fopen(fn,"wb"); | |
fwrite(&rbuf[j],i-j,1,fp); | |
fclose(fp); | |
fp=NULL; | |
} | |
j=i; | |
} | |
} | |
if(j!=-1) { | |
sprintf(fn,"song%04d.m",n++); | |
puts(fn); | |
fp=fopen(fn,"wb"); | |
fwrite(&rbuf[j],i-j,1,fp); | |
fclose(fp); | |
fp=NULL; | |
} | |
ret=0; | |
ENDPROC: | |
if(fp) fclose(fp); | |
if(rbuf) free(rbuf); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment