@@ -107,6 +107,45 @@ zsvsheet_status my_test_command_handler(zsvsheet_proc_context_t ctx) {
107
107
}
108
108
return zsvsheet_status_ok ;
109
109
}
110
+
111
+ struct transformation_context {
112
+ size_t col_count ;
113
+ size_t row_count ;
114
+ };
115
+
116
+ // Similar to a regular ZSV row handler used in ext_parse_all
117
+ void my_transformation_row_handler (void * ctx ) {
118
+ zsvsheet_transformation trn = ctx ;
119
+ struct transformation_context * priv = zsv_cb .ext_sheet_transformation_user_context (trn );
120
+ zsv_parser parser = zsv_cb .ext_sheet_transformation_parser (trn );
121
+ zsv_csv_writer writer = zsv_cb .ext_sheet_transformation_writer (trn );
122
+
123
+ size_t j = zsv_cb .cell_count (parser );
124
+ for (size_t i = 0 ; i < j ; i ++ ) {
125
+ struct zsv_cell c = zsv_cb .get_cell (parser , i );
126
+ zsv_writer_cell (writer , i == 0 , c .str , c .len , c .quoted );
127
+ }
128
+
129
+ priv -> col_count += j ;
130
+
131
+ if (!priv -> row_count )
132
+ zsv_writer_cell_s (writer , 0 , (const unsigned char * )"Column count" , 0 );
133
+ else
134
+ zsv_writer_cell_zu (writer , 0 , priv -> col_count );
135
+
136
+ priv -> row_count ++ ;
137
+ }
138
+
139
+ zsvsheet_status my_transformation_command_handler (zsvsheet_proc_context_t ctx ) {
140
+ struct transformation_context my_ctx = {
141
+ .col_count = 0 ,
142
+ .row_count = 0 ,
143
+ };
144
+
145
+ // TODO: This probably should happen in another worker thread and while that is happening the status should display
146
+ // that some work is in progress. The extension author will maybe want to have control over the status message.
147
+ return zsv_cb .ext_sheet_push_transformation (ctx , & my_ctx , my_transformation_row_handler );
148
+ }
110
149
#endif
111
150
112
151
/**
@@ -141,6 +180,11 @@ enum zsv_ext_status zsv_ext_init(struct zsv_ext_callbacks *cb, zsv_execution_con
141
180
if (proc_id < 0 )
142
181
return zsv_ext_status_error ;
143
182
zsv_cb .ext_sheet_register_proc_key_binding ('t' , proc_id );
183
+
184
+ proc_id = zsv_cb .ext_sheet_register_proc ("my-transformation" , "my transformation" , my_transformation_command_handler );
185
+ if (proc_id < 0 )
186
+ return zsv_ext_status_error ;
187
+ zsv_cb .ext_sheet_register_proc_key_binding ('T' , proc_id );
144
188
#endif
145
189
return zsv_ext_status_ok ;
146
190
}
0 commit comments