diff options
Diffstat (limited to 'converter/ppm/ppmtompeg/specifics.c')
-rw-r--r-- | converter/ppm/ppmtompeg/specifics.c | 198 |
1 files changed, 98 insertions, 100 deletions
diff --git a/converter/ppm/ppmtompeg/specifics.c b/converter/ppm/ppmtompeg/specifics.c index aa3d7b18..acf98116 100644 --- a/converter/ppm/ppmtompeg/specifics.c +++ b/converter/ppm/ppmtompeg/specifics.c @@ -1,13 +1,13 @@ /*===========================================================================* - * specifics.c * - * * - * basic procedures to deal with the specifics file * - * * - * EXPORTED PROCEDURES: * - * Specifics_Init * + * specifics.c * + * * + * basic procedures to deal with the specifics file * + * * + * EXPORTED PROCEDURES: * + * Specifics_Init * * Spec_Lookup * * SpecTypeLookup * - * * + * * *===========================================================================*/ /* @@ -41,6 +41,7 @@ #include "netpbm/mallocvar.h" #include "netpbm/nstring.h" +#include "netpbm/pm_system.h" #include "all.h" #include "mtypes.h" @@ -68,7 +69,7 @@ void Parse_Specifics_File_v2 (FILE *fp); FrameSpecList *MakeFslEntry (void); void AddSlc (FrameSpecList *c,int snum, int qs); Block_Specifics *AddBs (FrameSpecList *c,int bnum, - boolean rel, int qs); + boolean rel, int qs); FrameSpecList *MakeFslEntry (void); #define my_upper(c) (((c>='a') && (c<='z')) ? (c-'a'+'A') : c) #define CvtType(x) ReallyCvt(my_upper(x)) @@ -152,38 +153,37 @@ static char version = -1; void Specifics_Init() { - FILE *specificsFP; + /* 'specificsFile' is a global variable whose value is the name of the + specifics file, given by the parameter file. + */ + + FILE * specificsFP; + const char * preprocessedFileNm; + + pm_message("Specifics file: %s", specificsFile); + + pm_asprintf(&preprocessedFileNm, "%s.cpp", specificsFile); + + pm_system_lp("rm", NULL, NULL, NULL, NULL, "-f", preprocessedFileNm); { const char * command; - pm_asprintf(&command, "rm -f %s.cpp", specificsFile); - system(command); - pm_strfree(command); - } - { - const char * command; - pm_asprintf(&command, "cpp -P %s %s %s.cpp", - specificsDefines, specificsFile, specificsFile); - system(command); + pm_asprintf(&command, "cpp -P %s '%s' -o '%s'", + specificsDefines, specificsFile, preprocessedFileNm); + pm_system(NULL, NULL, NULL, NULL, command); pm_strfree(command); } - strcat(specificsFile, ".cpp"); - if ((specificsFP = fopen(specificsFile, "r")) == NULL) { - fprintf(stderr, "Error with specifics file, cannot open %s\n", - specificsFile); - exit(1); - } - printf("Specifics file: %s\n", specificsFile); + + specificsFP = pm_openr(preprocessedFileNm); + + pm_system_lp("rm", NULL, NULL, NULL, NULL, "-f", preprocessedFileNm); Parse_Specifics_File(specificsFP); - { - const char * command; - pm_asprintf(&command, "rm -f %s.cpp", specificsFile); - system(command); - pm_strfree(command); - } -} + pm_close(specificsFP); + + pm_strfree(preprocessedFileNm); +} @@ -221,24 +221,24 @@ FILE *fp; case 'V': lp += 7; if (1 != sscanf(lp, "%d", &vers)) { - fprintf(stderr," Improper version line in specs file: %s\n", line); + fprintf(stderr," Improper version line in specs file: %s\n", line); } else { - switch (vers) { - case 1: - version = vers; - Parse_Specifics_File_v1(fp); - break; - case 2: - version = vers; - Parse_Specifics_File_v2(fp); - break; - default: - fprintf(stderr, "Improper version line in specs file: %s\n", line); - fprintf(stderr, "\tSpecifics file will be IGNORED.\n"); - specificsOn = FALSE; - return; - break; - }} + switch (vers) { + case 1: + version = vers; + Parse_Specifics_File_v1(fp); + break; + case 2: + version = vers; + Parse_Specifics_File_v2(fp); + break; + default: + fprintf(stderr, "Improper version line in specs file: %s\n", line); + fprintf(stderr, "\tSpecifics file will be IGNORED.\n"); + specificsOn = FALSE; + return; + break; + }} break; default: fprintf(stderr, "Specifics file: What? *%s*\n", line); @@ -247,6 +247,8 @@ FILE *fp; } + + /* Version 1 */ void Parse_Specifics_File_v1(fp) FILE *fp; @@ -271,9 +273,9 @@ FILE *fp; lp += 6; sscanf(lp, "%d %c %d", &fnum, &typ, &qs); if (current->framenum != -1) { - new=MakeFslEntry(); - current->next = new; - current = new; + new=MakeFslEntry(); + current->next = new; + current = new; } current->framenum = fnum; current->frametype = CvtType(typ); @@ -442,7 +444,6 @@ Parse_Specifics_File_v2(FILE * const fP) { - /*================================================================= * * MakeFslEntry @@ -467,8 +468,6 @@ FrameSpecList *MakeFslEntry() - - /*================================================================ * * AddSlc @@ -503,8 +502,6 @@ int snum,qs; - - /*================================================================ * * AddBs @@ -544,9 +541,6 @@ int bnum,qs; - - - /*================================================================ * * SpecLookup @@ -581,8 +575,8 @@ int start_qs; found_it = FALSE; while (tmp != (FrameSpecList *) NULL) { if (tmp->framenum == fn) { - found_it = TRUE; - break; + found_it = TRUE; + break; } else tmp = tmp->next; } if (!found_it) return -1; @@ -591,20 +585,20 @@ int start_qs; if (last->framenum != fn) { /* cache miss! */ /* first check if it is next */ if ((last->next != (FrameSpecList *) NULL) && - (last->next->framenum == fn)) { - last = last->next; + (last->next->framenum == fn)) { + last = last->next; } else { - /* if not next, check from the start. - (this allows people to put frames out of order,even - though the spec doesn't allow it.) */ - tmp = fsl; - found_it = FALSE; - while (tmp != (FrameSpecList *) NULL) { - if (tmp->framenum==fn) {found_it = TRUE; break;} - tmp = tmp->next; - } - if (!found_it) return -1; - last = tmp; + /* if not next, check from the start. + (this allows people to put frames out of order,even + though the spec doesn't allow it.) */ + tmp = fsl; + found_it = FALSE; + while (tmp != (FrameSpecList *) NULL) { + if (tmp->framenum==fn) {found_it = TRUE; break;} + tmp = tmp->next; + } + if (!found_it) return -1; + last = tmp; } } } @@ -634,10 +628,10 @@ int start_qs; for (sptr = last->slc; sptr != (Slice_Specifics *) NULL; sptr = sptr->next) { if (sptr->num == num) { #ifdef BLEAH - printf("QSchange Slice %d.%d to %d\n", fn, num, sptr->qscale); + printf("QSchange Slice %d.%d to %d\n", fn, num, sptr->qscale); #endif - if (sptr->qscale == 0) return -1; - return sptr->qscale; + if (sptr->qscale == 0) return -1; + return sptr->qscale; } } break; @@ -649,30 +643,30 @@ int start_qs; } for (bptr=last->bs; bptr != (Block_Specifics *) NULL; bptr=bptr->next) { if (bptr->num == num) { - int new_one; + int new_one; #ifdef BLEAH - printf("QSchange Block %d.%d to %d\n", fn, num, bptr->qscale); + printf("QSchange Block %d.%d to %d\n", fn, num, bptr->qscale); #endif - *info = bptr->mv; - if (bptr->relative) { - if (bptr->qscale == 0) { - /* Do nothing! */ - new_one = start_qs; - } else { - new_one = start_qs + bptr->qscale + leftovers; - if (new_one < 1) { - leftovers = new_one - 1; - new_one = 1; - } else if (new_one > 31) { - leftovers = new_one - 31; - new_one = 31; - } else leftovers = 0; - }} - else { - new_one = bptr->qscale; - leftovers = 0; - } - return new_one; + *info = bptr->mv; + if (bptr->relative) { + if (bptr->qscale == 0) { + /* Do nothing! */ + new_one = start_qs; + } else { + new_one = start_qs + bptr->qscale + leftovers; + if (new_one < 1) { + leftovers = new_one - 1; + new_one = 1; + } else if (new_one > 31) { + leftovers = new_one - 31; + new_one = 31; + } else leftovers = 0; + }} + else { + new_one = bptr->qscale; + leftovers = 0; + } + return new_one; } } break; @@ -685,6 +679,7 @@ int start_qs; } + /*================================================================ * * SpecTypeLookup @@ -718,3 +713,6 @@ int fn; #endif return tmp->frametype; } + + + |