Advertisement
Yesideez

vob2srt.c

Jan 2nd, 2019
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. /* $VER: vob2srt.c v0.01 by Zeb (02-Jan-2019)
  2. **
  3. ** Convert VobSub (IDX/SUB) subtitle files to SRT files
  4. **
  5. ** Hopefully the first of many programming exercises of actual useful software
  6. ** to learn how to program in C. I'm using gcc on Linux before anyone asks!
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12.  
  13. //#define debug 1;
  14.  
  15. int strRight(char *src,char *trg, int intOffset);
  16.  
  17. char strSourceFile[64]={0},strTargetFile[64]={0};
  18. char cmd[4];
  19.  
  20. int main(int argc,char *argv[]) {
  21.   int i;
  22.   for (i=1;i<argc;i++) {
  23.     #ifdef debug
  24.     printf("Pass %d: ",i);
  25.     strncpy(cmd,argv[i],4); //Convert arg text to lower case, extract first 4 characters
  26.     #endif
  27.     if (strncmp(cmd,"-src",4)) { //source file specified
  28.       strRight(argv[i],strSourceFile,4);
  29.       #ifdef debug
  30.       printf("Source '%s' copied\n",strSourceFile);
  31.       #endif
  32.     }
  33.     if (strncmp(cmd,"-trg",4)) { //target file specified
  34.       strRight(argv[i],strTargetFile,4);
  35.       #ifdef debug
  36.       printf("Target '%s' copied\n",strTargetFile);
  37.       #endif
  38.     }
  39.   }
  40.   return 0;
  41. }
  42.  
  43. /* Similar to RIGHT$() in BASIC - copy src to trg from offset char until end
  44. **
  45. ** Usage: src: source filename
  46. **        trg: target filename
  47. **        offset: where to start copying from
  48. *****************************************************************************/
  49. int strRight(char *src,char *trg,int intOffset) {
  50.   int i=0;
  51.   #ifdef debug
  52.   int t=0;
  53.   #endif
  54.   if (intOffset<0 || intOffset>strlen(src)) {return 0;} //error - invalid offset
  55.   #ifdef debug
  56.   printf("strRight: src='%s', offset=%d\n",src,intOffset);
  57.   #endif
  58.   while (src[intOffset+i]!='\0') {
  59.     #ifdef debug
  60.     t=intOffset+i;
  61.     printf("Character at position %d is %c\n",t,src[t]);
  62.     #endif
  63.     trg[i]=src[intOffset+i];
  64.     i++;
  65.   }
  66.   return 1;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement