+ fprintf(out, "\"%s\"", standard_fields[i].key);
+
+ /*
+ Custom fields handling:
+ This loop appends custom fields' id at the end of allcsv_export_fields and shift
+ the CSV_LAST sentinel value each time one is found.
+ CUSTOM_FIELD_START_INDEX is added to these index values so csv_export_common()
+ can later recognize them and call db_fget_byid() instead of the traditional db_fget()
+
+ It only search for defined the [legacy?] "custom" fields.
+ */
+
+ // pointer to the end of the field list
+ int append_field = ITEM_FIELDS;
+ // custom field's trailing number (between 1 and 5)
+ int j;
+ // full custom field name, eg "custom4"
+ char custom_field_key[8];
+ // index used by custom_field_key
+ int field_no;
+ // name of the defined field <field_no> as chosen by the user
+ char *custom_field_name;
+
+ for (j = 1; j <= 5; j++) {
+ snprintf(custom_field_key, 8, "custom%d", j++);
+ if(find_declared_field(custom_field_key)) {
+ find_field_number(custom_field_key, &field_no);
+ get_field_info(field_no, NULL, &custom_field_name, NULL);
+ // append the field to the list
+ allcsv_export_fields[append_field] = field_no + CUSTOM_FIELD_START_INDEX;
+ allcsv_export_fields[++append_field] = CSV_LAST;
+ // print column name
+ fprintf(out, ",\"%s\"", custom_field_name);
+ }
+ }
+ free(custom_field_name);
+ fprintf(out, "\n");