Index: src/tkt.c ================================================================== --- src/tkt.c +++ src/tkt.c @@ -52,10 +52,19 @@ ** here. */ static int nField = 0; static Blob fieldList; static char **azField = 0; +static char **azValue = 0; +static unsigned char *aChanged = 0; + +/* +** Compare two entries in azField for sorting purposes +*/ +static int nameCmpr(void *a, void *b){ + return strcmp((char*)a, (char*)b); +} /* ** Subscript command: LIST setfields ** ** Parse up the list and populate the nField and azField variables. @@ -70,20 +79,84 @@ zFieldList = SbS_StackValue(p, 0, &nFieldList); blob_appendf(&fieldList, zFieldList, nFieldList); while( blob_token(&fieldList, &field) ){ nField++; } - azField = malloc( sizeof(azField[0])*nField ); - blob_rewind(&fieldList); - i = 0; - while( blob_token(&fieldList, &field) ){ - azField[i] = blob_terminate(&field); + azField = malloc( sizeof(azField[0])*nField*2 + nField ); + if( azField ){ + azValue = &azField[nField]; + aChanged = (unsigned char*)&azValue[nField]; + blob_rewind(&fieldList); + i = 0; + while( blob_token(&fieldList, &field) ){ + azField[i] = blob_terminate(&field); + azValue[i] = 0; + aChanged[i] = 0; + } } + qsort(azField, nField, sizeof(azField[0]), nameCmpr); } SbS_Pop(p, 1); return 0; } + +/* +** Find the text of the field whose name is the Nth element down +** on the Subscript stack. 0 means the top of the stack. +** +** First check for a value for this field as passed in via +** CGI parameter. If not found, then use the value from the +** database. +*/ +static const char *field_value(int N){ + const char *zFName; + int nFName; + char *zName; + int i; + const char *zValue; + + zFName = SbS_StackValue(pInterp, N, &nFName); + if( zField==0 ){ + return 0; + } + zName = mprintf("%.*s", nFName, zFName); + zValue = P(zName); + if( zValue==0 ){ + for(i=0; i