Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* $VER: vob2srt.c v0.01 by Zeb (02-Jan-2019)
- **
- ** Convert VobSub (IDX/SUB) subtitle files to SRT files
- **
- ** Hopefully the first of many programming exercises of actual useful software
- ** to learn how to program in C. I'm using gcc on Linux before anyone asks!
- *****************************************************************************/
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- //#define debug 1;
- int strRight(char *src,char *trg, int intOffset);
- char strSourceFile[64]={0},strTargetFile[64]={0};
- char cmd[4];
- int main(int argc,char *argv[]) {
- int i;
- for (i=1;i<argc;i++) {
- #ifdef debug
- printf("Pass %d: ",i);
- strncpy(cmd,argv[i],4); //Convert arg text to lower case, extract first 4 characters
- #endif
- if (strncmp(cmd,"-src",4)) { //source file specified
- strRight(argv[i],strSourceFile,4);
- #ifdef debug
- printf("Source '%s' copied\n",strSourceFile);
- #endif
- }
- if (strncmp(cmd,"-trg",4)) { //target file specified
- strRight(argv[i],strTargetFile,4);
- #ifdef debug
- printf("Target '%s' copied\n",strTargetFile);
- #endif
- }
- }
- return 0;
- }
- /* Similar to RIGHT$() in BASIC - copy src to trg from offset char until end
- **
- ** Usage: src: source filename
- ** trg: target filename
- ** offset: where to start copying from
- *****************************************************************************/
- int strRight(char *src,char *trg,int intOffset) {
- int i=0;
- #ifdef debug
- int t=0;
- #endif
- if (intOffset<0 || intOffset>strlen(src)) {return 0;} //error - invalid offset
- #ifdef debug
- printf("strRight: src='%s', offset=%d\n",src,intOffset);
- #endif
- while (src[intOffset+i]!='\0') {
- #ifdef debug
- t=intOffset+i;
- printf("Character at position %d is %c\n",t,src[t]);
- #endif
- trg[i]=src[intOffset+i];
- i++;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement