Permalink
Browse files

Parse function now returns a pointer and not a copy for performance.

  • Loading branch information...
1 parent 598f2e7 commit a7875db9f581fb3f57e733bb184265fcb26873c3 @Naouak committed Apr 8, 2012
Showing with 43 additions and 41 deletions.
  1. +6 −6 source/ebu.c
  2. +1 −1 source/ebu.h
  3. +36 −34 source/ebu_shift.c
View
@@ -4,18 +4,18 @@
#include "ebu.h"
-struct EBU parseEBU(FILE* f){
- struct EBU ebu;
+struct EBU* parseEBU(FILE* f){
+ struct EBU* ebu;
- fread(&(ebu.gsi), 1024, 1, f);
+ fread(&(ebu->gsi), 1024, 1, f);
unsigned char TNB[6];
- strncpy(TNB,ebu.gsi.TNB,5);
+ strncpy(TNB,ebu->gsi.TNB,5);
TNB[5] = '\0';
int nTNB = atoi(TNB);
- ebu.tti = (struct EBU_TTI*) malloc(sizeof(struct EBU_TTI) * nTNB);
- fread(ebu.tti, 128, nTNB, f);
+ ebu->tti = (struct EBU_TTI*) malloc(sizeof(struct EBU_TTI) * nTNB);
+ fread(ebu->tti, 128, nTNB, f);
return ebu;
}
View
@@ -60,7 +60,7 @@ struct EBU{
struct EBU_TTI* tti;
};
-struct EBU parseEBU(FILE* f);
+struct EBU* parseEBU(FILE* f);
void saveEBU(FILE* f, const struct EBU* ebu);
struct EBU_TC* charToTC(const unsigned char TC[8]);
void TCToChar(unsigned char tc[8],const struct EBU_TC TC);
View
@@ -28,45 +28,47 @@ int main(int argc, const char* argv[]) {
}
if(input == NULL || output == NULL || nshift == 0){
- if(input == NULL)
- printf("no input set\n");
- if(output == NULL)
- printf("no output set\n");
- if(nshift == 0)
- printf("no shift set\n");
+ if(input == NULL)
+ printf("no input set\n");
+ if(output == NULL)
+ printf("no output set\n");
+ if(nshift == 0)
+ printf("no shift set\n");
printf("Usage: %s -i input.stl -t timeshift([-]HHMMSSFF) output.stl",argv[0]);
return 0;
}
- FILE* source = fopen(input,"r");
- if(source == NULL){
- fclose(source);
- return 1;
- }
- struct EBU ebu = parseEBU(source);
- fclose(source);
+ FILE* source = fopen(input,"r");
+ if(source == NULL){
+ fclose(source);
+ return 1;
+ }
+ struct EBU* ebu = parseEBU(source);
+ fclose(source);
+
+ struct EBU_TC shift;
+ int positive = nshift>0?1:-1;
+ if(positive < 0)
+ nshift *= -1;
+ shift.frames = nshift%100;
+ nshift /= 100;
+ shift.seconds = nshift%100;
+ nshift /= 100;
+ shift.minutes = nshift%100;
+ nshift /= 100;
+ shift.hours = nshift%100;
+
+ shiftTCs(ebu,shift,positive);
+ FILE* dest = fopen(output,"w");
+ if(dest == NULL){
+ fclose(dest);
+ return 2;
+ }
+ saveEBU(dest,ebu);
+ fclose(dest);
- struct EBU_TC shift;
- int positive = nshift>0?1:-1;
- if(positive < 0)
- nshift *= -1;
- shift.frames = nshift%100;
- nshift /= 100;
- shift.seconds = nshift%100;
- nshift /= 100;
- shift.minutes = nshift%100;
- nshift /= 100;
- shift.hours = nshift%100;
-
- shiftTCs(&ebu,shift,positive);
- FILE* dest = fopen(output,"w");
- if(dest == NULL){
- fclose(dest);
- return 2;
- }
- saveEBU(dest,&ebu);
- fclose(dest);
+ free(ebu);
- return 0;
+ return 0;
}

0 comments on commit a7875db

Please sign in to comment.