150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
-
+
-
+
|
** ticket configuration. tbldef will hold the ticket table
** definition. sql will hold text to initialize and define
** the tktfield table and to insert template text into the
** config table
*/
blob_appendf(&tbldef,
"DROP TABLE IF EXISTS ticket;\n"
"CREATE TABLE ticket(\n"
"CREATE TABLE repository.ticket(\n"
" tktid INTEGER PRIMARY KEY,\n"
" tktuuid TEXT UNIQUE,\n"
" starttime DATETIME,\n"
" lastmod DATETIME"
);
blob_appendf(&sql,
"DROP TABLE IF EXISTS tktfield;\n"
"CREATE TABLE tktfield(\n"
"CREATE TABLE repository.tktfield(\n"
" fidx INTEGER PRIMARY KEY,\n"
" name TEXT UNIQUE,\n"
" type TEXT,\n"
" width INTEGER,\n"
" arg\n"
");\n"
);
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
blob_reset(&err);
return rc;
}
/*
** COMMAND: test-tktconfig-parse
*/
void test_tktconfig_cmd(void){
void test_tktconfig_parse_cmd(void){
Blob config, err;
if( g.argc!=3 ){
usage("FILENAME");
}
blob_read_from_file(&config, g.argv[2]);
blob_zero(&err);
ticket_config_parse(&config, 1, &err);
if( blob_size(&err) ){
blob_write_to_file(&err, "-");
}
}
/*
** COMMAND: test-tktconfig-import
*/
void test_tktconfig_import_cmd(void){
Blob config, err;
db_must_be_within_tree();
if( g.argc!=3 ){
usage("FILENAME");
}
blob_read_from_file(&config, g.argv[2]);
blob_zero(&err);
db_begin_transaction();
ticket_config_parse(&config, 0, &err);
db_end_transaction(0);
if( blob_size(&err) ){
blob_write_to_file(&err, "-");
}
}
/*
** Load the default ticket configuration.
|
559
560
561
562
563
564
565
|
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
blob_zero(&errmsg);
ticket_config_parse(&config, 0, &errmsg);
if( blob_size(&errmsg) ){
fossil_fatal("%b", &errmsg);
}
db_end_transaction(0);
}
/*
** Return the length of a string without its trailing whitespace.
*/
static int non_whitespace_length(const char *z){
int n = strlen(z);
while( n>0 && isspace(z[n-1]) ){ n--; }
return n;
}
/*
** Fill the given Blob with text that describes the current
** ticket configuration. This is the inverse of ticket_config_parse()
*/
void ticket_config_render(Blob *pOut){
char *zDelim;
char *zContent;
Stmt q;
int n;
blob_appendf(pOut, "ticket-configuration\n");
zDelim = db_text(0, "SELECT '--end-of-text--' || hex(random(20))");
blob_appendf(pOut, "###################################################\n");
db_prepare(&q, "SELECT name, type, width, arg FROM tktfield");
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
const char *zType = db_column_text(&q, 1);
int width = db_column_int(&q, 2);
const char *zArg = db_column_text(&q, 3);
blob_appendf(pOut, "field %s %s %d %s\n", zName, zType, width, zArg);
}
db_finalize(&q);
blob_appendf(pOut, "###################################################\n");
blob_appendf(pOut, "template new %s\n", zDelim);
zContent = db_get("tkt-new-template", 0);
if( zContent ){
n = non_whitespace_length(zContent);
blob_appendf(pOut, "%.*s\n", n, zContent);
free(zContent);
}
blob_appendf(pOut, "%s\n", zDelim);
blob_appendf(pOut, "###################################################\n");
blob_appendf(pOut, "template edit %s\n", zDelim);
zContent = db_get("tkt-edit-template", 0);
if( zContent ){
n = non_whitespace_length(zContent);
blob_appendf(pOut, "%.*s\n", n, zContent);
free(zContent);
}
blob_appendf(pOut, "%s\n", zDelim);
blob_appendf(pOut, "###################################################\n");
blob_appendf(pOut, "template view %s\n", zDelim);
zContent = db_get("tkt-view-template", 0);
if( zContent ){
n = non_whitespace_length(zContent);
blob_appendf(pOut, "%.*s\n", n, zContent);
free(zContent);
}
blob_appendf(pOut, "%s\n", zDelim);
blob_appendf(pOut, "###################################################\n");
blob_appendf(pOut, "description %s\n", zDelim);
zContent = db_get("tkt-desc", 0);
if( zContent ){
n = non_whitespace_length(zContent);
blob_appendf(pOut, "%.*s\n", n, zContent);
free(zContent);
}
blob_appendf(pOut, "%s\n", zDelim);
}
/*
** COMMAND: test-tktconfig-export
** Write the current ticket configuration out to a file.
*/
void tktconfig_render_cmd(void){
Blob config;
db_must_be_within_tree();
if( g.argc!=3 ){
usage("FILENAME");
}
blob_zero(&config);
ticket_config_render(&config);
blob_write_to_file(&config, g.argv[2]);
blob_reset(&config);
}
|