[Kst] extragear/graphics/kst/src/datasources/dirfile
Adam Treat
treat at kde.org
Fri Oct 6 18:18:43 CEST 2006
SVN commit 593046 by treat:
Add dirfile PHASE functionality to the datasource plugin.
BUG: 134465
M +8 -0 dirfile.cpp
M +93 -1 getdata.c
M +8 -0 getdata_struct.h
--- trunk/extragear/graphics/kst/src/datasources/dirfile/dirfile.cpp #593045:593046
@@ -63,6 +63,10 @@
_fieldList.append(ft->bitEntries[i].field);
}
+ for (int i = 0; i < ft->n_phase; i++) {
+ _fieldList.append(ft->phaseEntries[i].field);
+ }
+
for (int i = 0; i < ft->n_raw; i++) {
_fieldList.append(ft->rawEntries[i].field);
}
@@ -198,6 +202,10 @@
fieldList.append(ft->bitEntries[i].field);
}
+ for (int i = 0; i < ft->n_phase; i++) {
+ fieldList.append(ft->phaseEntries[i].field);
+ }
+
for (int i = 0; i < ft->n_raw; i++) {
fieldList.append(ft->rawEntries[i].field);
}
--- trunk/extragear/graphics/kst/src/datasources/dirfile/getdata.c #593045:593046
@@ -264,6 +264,7 @@
if (F->n_linterp >0) free(F->linterpEntries);
if (F->n_mplex > 0) free(F->mplexEntries);
if (F->n_bit > 0) free(F->bitEntries);
+ if (F->n_phase > 0) free(F->phaseEntries);
}
/***************************************************************************/
@@ -425,6 +426,23 @@
/***************************************************************************/
/* */
+/* ParsePhase: parse PHASE data type entry in formats file */
+/* */
+/***************************************************************************/
+static int ParsePhase(char in_cols[MAX_IN_COLS][MAX_LINE_LENGTH], int n_cols,
+ struct PhaseEntryType *P, const char* format_file, int line)
+{
+ strcpy(P->field, in_cols[0]); /* field */
+ strncpy(P->raw_field, in_cols[2], FIELD_LENGTH); /* field */
+
+ P->shift=atoi(in_cols[3]); /*shift*/
+
+ /*FIXME make sure the shift is within the range of the raw field...*/
+ return SetGetDataError(GD_E_OK, 0, NULL, 0, NULL);
+}
+
+/***************************************************************************/
+/* */
/* Compare functions for sorting the lists (using stdlib qsort) */
/* */
/***************************************************************************/
@@ -458,6 +476,11 @@
((struct BitEntryType *)B)->field));
}
+static int PhaseCmp(const void *A, const void *B) {
+ return (strcmp(((struct PhaseEntryType *)A)->field,
+ ((struct PhaseEntryType *)B)->field));
+}
+
/***************************************************************************/
/* */
/* ParseFormatFile: Perform the actual parsing of the format file. This */
@@ -529,6 +552,13 @@
F->n_bit*sizeof(struct BitEntryType));
error_code = ParseBit(in_cols, n_cols, F->bitEntries+F->n_bit - 1,
format_file, linenum);
+ } else if (strcmp(in_cols[1], "PHASE")==0) {
+ F->n_phase++;
+ F->phaseEntries =
+ realloc(F->phaseEntries,
+ F->n_phase*sizeof(struct PhaseEntryType));
+ error_code = ParsePhase(in_cols, n_cols, F->phaseEntries+F->n_phase - 1,
+ format_file, linenum);
} else if (strcmp(in_cols[0], "FRAMEOFFSET")==0) {
F->frame_offset = atoi(in_cols[1]);
} else if (strcmp(in_cols[0], "INCLUDE")==0) {
@@ -632,7 +662,7 @@
}
strcpy(F->FileDirName, filedir);
- F->n_raw = F->n_lincom = F->n_multiply = F->n_linterp = F->n_mplex = F->n_bit
+ F->n_raw = F->n_lincom = F->n_multiply = F->n_linterp = F->n_mplex = F->n_bit = F->n_phase
= 0;
F->frame_offset = 0;
F->rawEntries = NULL;
@@ -641,6 +671,7 @@
F->linterpEntries = NULL;
F->mplexEntries = NULL;
F->bitEntries = NULL;
+ F->phaseEntries = NULL;
/* Parse the file. This will take care of any necessary inclusions */
i_include = 1;
@@ -696,6 +727,10 @@
qsort(F->bitEntries, F->n_bit, sizeof(struct BitEntryType),
BitCmp);
}
+ if (F->n_phase > 1) {
+ qsort(F->phaseEntries, F->n_phase, sizeof(struct PhaseEntryType),
+ PhaseCmp);
+ }
return(F);
}
@@ -1029,6 +1064,8 @@
struct MultiplyEntryType *M;
struct BitEntryType tB;
struct BitEntryType *B;
+ struct PhaseEntryType tP;
+ struct PhaseEntryType *P;
struct LinterpEntryType tI;
struct LinterpEntryType *I;
int spf;
@@ -1110,6 +1147,21 @@
}
/***************************************/
+ /** Check to see if it is a phase entry **/
+ /* binary search for the field */
+ /* make a PhaseEntry we can compare to */
+ strncpy(tP.field, field_code, FIELD_LENGTH);
+ /** use the stdlib binary search */
+ P = bsearch(&tP, F->phaseEntries, F->n_phase,
+ sizeof(struct PhaseEntryType), PhaseCmp);
+ if (P!=NULL) {
+ recurse_level++;
+ spf = GetSPF(P->raw_field, F, error_code);
+ recurse_level--;
+ return(spf);
+ }
+
+ /***************************************/
/** Check to see if it is a linterp entry **/
/* binary search for the field */
/* make a LinterpEntry we can compare to */
@@ -1663,6 +1715,40 @@
/***************************************************************************/
/* */
+/* Look to see if the field code belongs to phasefield. If so, parse it.*/
+/* */
+/***************************************************************************/
+static int DoIfPhase(struct FormatType *F, const char *field_code,
+ int first_frame, int first_samp,
+ int num_frames, int num_samp,
+ char return_type, void *data_out,
+ int *error_code, int *n_read) {
+ struct PhaseEntryType tP;
+ struct PhaseEntryType *P;
+
+ /******* binary search for the field *******/
+ /* make a PhaseEntry we can compare to */
+ strncpy(tP.field, field_code, FIELD_LENGTH);
+ /** use the stdlib binary search */
+ P = bsearch(&tP, F->phaseEntries, F->n_phase,
+ sizeof(struct PhaseEntryType), PhaseCmp);
+ if (P==NULL) return(0);
+
+ /*****************************************/
+ /** if we got here, we found the field! **/
+ recurse_level++;
+ *n_read = DoField(F, P->raw_field,
+ first_frame, first_samp + P->shift,
+ num_frames, num_samp,
+ return_type, data_out,
+ error_code);
+ recurse_level--;
+
+ return(1);
+}
+
+/***************************************************************************/
+/* */
/* ReadLinterpFile: Read in the linterp data for this field */
/* */
/***************************************************************************/
@@ -1891,6 +1977,12 @@
return_type, data_out,
error_code, &n_read)) {
return(n_read);
+ } else if (DoIfPhase(F, field_code,
+ first_frame, first_samp,
+ num_frames, num_samp,
+ return_type, data_out,
+ error_code, &n_read)) {
+ return(n_read);
} else if (DoIfLinterp(F, field_code,
first_frame, first_samp,
num_frames, num_samp,
--- trunk/extragear/graphics/kst/src/datasources/dirfile/getdata_struct.h #593045:593046
@@ -67,6 +67,12 @@
int numbits;
};
+struct PhaseEntryType {
+ char field[FIELD_LENGTH+1];
+ char raw_field[FIELD_LENGTH+1];
+ int shift;
+};
+
struct FormatType {
char FileDirName[MAX_FILENAME_LENGTH];
int frame_offset;
@@ -83,6 +89,8 @@
int n_mplex;
struct BitEntryType *bitEntries;
int n_bit;
+ struct PhaseEntryType *phaseEntries;
+ int n_phase;
};
#endif
More information about the Kst
mailing list