forked from jonas/tig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.c
998 lines (770 loc) · 20.5 KB
/
graph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
/* Copyright (c) 2006-2013 Jonas Fonseca <fonseca@diku.dk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "tig.h"
#include "graph.h"
DEFINE_ALLOCATOR(realloc_graph_columns, struct graph_column, 32)
DEFINE_ALLOCATOR(realloc_graph_symbols, struct graph_symbol, 1)
struct id_color {
char *id;
size_t color;
};
struct id_color *
id_color_new(const char *id, size_t color)
{
struct id_color *node = malloc(sizeof(struct id_color));
node->id = (char *) malloc(strlen(id) + 1);
strcpy(node->id, id);
node->color = color;
return node;
}
static void
id_color_delete(struct id_color *node)
{
free(node->id);
free(node);
}
static int
id_color_eq(const void *entry, const void *element)
{
return strcmp(((const struct id_color *) entry)->id, ((const struct id_color *) element)->id) == 0;
}
static void
key_del(void *key)
{
id_color_delete((struct id_color *) key);
}
static hashval_t
id_color_hash(const void *node)
{
return htab_hash_string(((const struct id_color*) node)->id);
}
static void
colors_add_id(struct colors *colors, const char *id, const size_t color)
{
struct id_color *node = id_color_new(id, color);
void **slot = htab_find_slot(colors->id_map, node, INSERT);
if (slot != NULL && *slot == NULL) {
*slot = node;
colors->count[color]++;
} else {
id_color_delete(node);
}
}
static void
colors_remove_id(struct colors *colors, const char *id)
{
struct id_color *node = id_color_new(id, 0);
void **slot = htab_find_slot(colors->id_map, node, NO_INSERT);
if (slot != NULL && *slot != NULL) {
colors->count[((struct id_color *) *slot)->color]--;
htab_clear_slot(colors->id_map, slot);
}
id_color_delete(node);
}
static size_t
colors_get_color(struct colors *colors, const char *id)
{
struct id_color *key = id_color_new(id, 0);
struct id_color *node = (struct id_color *) htab_find(colors->id_map, key);
id_color_delete(key);
if (node == NULL) {
return (size_t) -1; // Max value of size_t. ID not found.
}
return node->color;
}
static size_t
colors_get_free_color(struct colors *colors)
{
size_t free_color = 0;
size_t lowest = (size_t) -1; // Max value of size_t
int i;
for (i = 0; i < ARRAY_SIZE(colors->count); i++) {
if (colors->count[i] < lowest) {
lowest = colors->count[i];
free_color = i;
}
}
return free_color;
}
static void
colors_init(struct colors *colors)
{
if (colors->id_map == NULL) {
uint size = 500;
colors->id_map = htab_create_alloc(size, id_color_hash, id_color_eq, key_del, calloc, free);
}
}
static size_t
get_color(struct graph *graph, char *new_id)
{
size_t color;
colors_init(&graph->colors);
color = colors_get_color(&graph->colors, new_id);
if (color < (size_t) -1) {
return color;
}
color = colors_get_free_color(&graph->colors);
colors_add_id(&graph->colors, new_id, color);
return color;
}
void
done_graph(struct graph *graph)
{
free(graph->prev_row.columns);
free(graph->row.columns);
free(graph->next_row.columns);
free(graph->parents.columns);
memset(graph, 0, sizeof(*graph));
}
#define graph_column_has_commit(col) ((col)->id[0])
static size_t
graph_find_column_by_id(struct graph_row *row, const char *id)
{
size_t free_column = row->size;
size_t i;
for (i = 0; i < row->size; i++) {
if (!graph_column_has_commit(&row->columns[i]) && free_column == row->size)
free_column = i;
else if (!strcmp(row->columns[i].id, id))
return i;
}
return free_column;
}
static size_t
graph_find_free_column(struct graph_row *row)
{
size_t i;
for (i = 0; i < row->size; i++) {
if (!graph_column_has_commit(&row->columns[i]))
return i;
}
return row->size;
}
static struct graph_column *
graph_insert_column(struct graph *graph, struct graph_row *row, size_t pos, const char *id)
{
struct graph_column *column;
if (!realloc_graph_columns(&row->columns, row->size, 1))
return NULL;
column = &row->columns[pos];
if (pos < row->size) {
memmove(column + 1, column, sizeof(*column) * (row->size - pos));
}
row->size++;
memset(column, 0, sizeof(*column));
string_copy_rev(column->id, id);
column->symbol.boundary = !!graph->is_boundary;
return column;
}
struct graph_column *
graph_add_parent(struct graph *graph, const char *parent)
{
return graph_insert_column(graph, &graph->parents, graph->parents.size, parent);
}
static bool
graph_needs_expansion(struct graph *graph)
{
return graph->position + graph->parents.size > graph->row.size;
}
static bool
graph_expand(struct graph *graph)
{
while (graph_needs_expansion(graph)) {
if (!graph_insert_column(graph, &graph->prev_row, graph->prev_row.size, ""))
return FALSE;
if (!graph_insert_column(graph, &graph->row, graph->row.size, ""))
return FALSE;
if (!graph_insert_column(graph, &graph->next_row, graph->next_row.size, ""))
return FALSE;
}
return TRUE;
}
static bool
graph_needs_collapsing(struct graph *graph)
{
return graph->row.size > 1
&& !graph_column_has_commit(&graph->row.columns[graph->row.size - 1]);
}
static bool
graph_collapse(struct graph *graph)
{
while (graph_needs_collapsing(graph)) {
graph->prev_row.size--;
graph->row.size--;
graph->next_row.size--;
}
return TRUE;
}
static void
graph_canvas_append_symbol(struct graph *graph, struct graph_symbol *symbol)
{
struct graph_canvas *canvas = graph->canvas;
if (realloc_graph_symbols(&canvas->symbols, canvas->size, 1))
canvas->symbols[canvas->size++] = *symbol;
}
static void
graph_row_clear_commit(struct graph_row *row, const char *id)
{
int i;
for (i = 0; i < row->size; i++) {
if (strcmp(row->columns[i].id, id) == 0) {
row->columns[i].id[0] = 0;
}
}
}
static void
graph_insert_parents(struct graph *graph)
{
struct graph_row *prev_row = &graph->prev_row;
struct graph_row *row = &graph->row;
struct graph_row *next_row = &graph->next_row;
struct graph_row *parents = &graph->parents;
int i;
for (i = 0; i < parents->size; i++) {
struct graph_column *new = &parents->columns[i];
if (graph_column_has_commit(new)) {
size_t match = graph_find_free_column(next_row);
if (match == next_row->size && next_row->columns[next_row->size - 1].id) {
graph_insert_column(graph, next_row, next_row->size, new->id);
graph_insert_column(graph, row, row->size, "");
graph_insert_column(graph, prev_row, prev_row->size, "");
} else {
next_row->columns[match] = *new;
}
}
}
}
static bool
commit_is_in_row(const char *id, struct graph_row *row)
{
int i;
for (i = 0; i < row->size; i++) {
if (!graph_column_has_commit(&row->columns[i]))
continue;
if (strcmp(id, row->columns[i].id) == 0)
return true;
}
return false;
}
static void
graph_remove_collapsed_columns(struct graph *graph)
{
struct graph_row *row = &graph->next_row;
int i;
for (i = row->size - 1; i > 0; i--) {
if (i == graph->position)
continue;
if (i == graph->position + 1)
continue;
if (strcmp(row->columns[i].id, graph->id) == 0)
continue;
if (strcmp(row->columns[i].id, row->columns[i - 1].id) != 0)
continue;
if (commit_is_in_row(row->columns[i].id, &graph->parents) && !graph_column_has_commit(&graph->prev_row.columns[i]))
continue;
if (strcmp(row->columns[i - 1].id, graph->prev_row.columns[i - 1].id) != 0 || graph->prev_row.columns[i - 1].symbol.shift_left)
row->columns[i] = row->columns[i + 1];
}
}
static void
graph_fill_empty_columns(struct graph *graph)
{
struct graph_row *row = &graph->next_row;
int i;
for (i = row->size - 2; i >= 0; i--) {
if (!graph_column_has_commit(&row->columns[i])) {
row->columns[i] = row->columns[i + 1];
}
}
}
static void
graph_generate_next_row(struct graph *graph)
{
graph_row_clear_commit(&graph->next_row, graph->id);
graph_insert_parents(graph);
graph_remove_collapsed_columns(graph);
graph_fill_empty_columns(graph);
}
static int
commits_in_row(struct graph_row *row)
{
int count = 0;
int i;
for (i = 0; i < row->size;i++) {
if (graph_column_has_commit(&row->columns[i]))
count++;
}
return count;
}
static void
graph_commit_next_row(struct graph *graph)
{
int i;
for (i = 0; i < graph->row.size; i++) {
graph->prev_row.columns[i] = graph->row.columns[i];
if (i == graph->position && commits_in_row(&graph->parents) > 0)
graph->prev_row.columns[i] = graph->next_row.columns[i];
if (!graph_column_has_commit(&graph->prev_row.columns[i]))
graph->prev_row.columns[i] = graph->next_row.columns[i];
graph->row.columns[i] = graph->next_row.columns[i];
}
graph->prev_position = graph->position;
}
static bool
continued_down(struct graph_row *row, struct graph_row *next_row, int pos)
{
if (strcmp(row->columns[pos].id, next_row->columns[pos].id) != 0)
return false;
if (row->columns[pos].symbol.shift_left)
return false;
return true;
}
static bool
shift_left(struct graph_row *row, struct graph_row *prev_row, int pos)
{
int i;
if (!graph_column_has_commit(&row->columns[pos]))
return false;
for (i = pos - 1; i >= 0; i--) {
if (!graph_column_has_commit(&row->columns[i]))
continue;
if (strcmp(row->columns[i].id, row->columns[pos].id) != 0)
continue;
if (!continued_down(prev_row, row, i))
return true;
break;
}
return false;
}
static bool
new_column(struct graph_row *row, struct graph_row *prev_row, int pos)
{
int i;
if (!graph_column_has_commit(&prev_row->columns[pos]))
return true;
for (i = pos; i < row->size; i++) {
if (strcmp(row->columns[pos].id, prev_row->columns[i].id) == 0)
return false;
}
return true;
}
static bool
continued_right(struct graph_row *row, int pos, int commit_pos)
{
int i, end;
if (pos < commit_pos)
end = commit_pos;
else
end = row->size;
for (i = pos + 1; i < end; i++) {
if (strcmp(row->columns[pos].id, row->columns[i].id) == 0)
return true;
}
return false;
}
static bool
continued_left(struct graph_row *row, int pos, int commit_pos)
{
int i, start;
if (pos < commit_pos)
start = 0;
else
start = commit_pos;
for (i = start; i < pos; i++) {
if (!graph_column_has_commit(&row->columns[i]))
continue;
if (strcmp(row->columns[pos].id, row->columns[i].id) == 0)
return true;
}
return false;
}
static bool
parent_down(struct graph_row *parents, struct graph_row *next_row, int pos)
{
int parent;
for (parent = 0; parent < parents->size; parent++) {
if (!graph_column_has_commit(&parents->columns[parent]))
continue;
if (strcmp(parents->columns[parent].id, next_row->columns[pos].id) == 0)
return true;
}
return false;
}
static bool
parent_right(struct graph_row *parents, struct graph_row *row, struct graph_row *next_row, int pos)
{
int parent, i;
for (parent = 0; parent < parents->size; parent++) {
if (!graph_column_has_commit(&parents->columns[parent]))
continue;
for (i = pos + 1; i < next_row->size; i++) {
if (strcmp(parents->columns[parent].id, next_row->columns[i].id) != 0)
continue;
if (strcmp(parents->columns[parent].id, row->columns[i].id) != 0)
return true;
}
}
return false;
}
static bool
flanked(struct graph_row *row, int pos, int commit_pos, const char *commit_id)
{
int i, start, end;
if (pos < commit_pos) {
start = 0;
end = pos;
} else {
start = pos + 1;
end = row->size;
}
for (i = start; i < end; i++) {
if (strcmp(row->columns[i].id, commit_id) == 0)
return true;
}
return false;
}
static bool
below_commit(int pos, struct graph *graph)
{
if (!pos == graph->prev_position)
return false;
if (!strcmp(graph->row.columns[pos].id, graph->prev_row.columns[pos].id) == 0)
return false;
return true;
}
static void
graph_generate_symbols(struct graph *graph)
{
struct graph_row *prev_row = &graph->prev_row;
struct graph_row *row = &graph->row;
struct graph_row *next_row = &graph->next_row;
struct graph_row *parents = &graph->parents;
int pos;
for (pos = 0; pos < row->size; pos++) {
struct graph_column *column = &row->columns[pos];
struct graph_symbol *symbol = &column->symbol;
char *id = next_row->columns[pos].id;
symbol->commit = (pos == graph->position);
symbol->boundary = (pos == graph->position && next_row->columns[pos].symbol.boundary);
symbol->initial = (commits_in_row(parents) < 1);
symbol->merge = (commits_in_row(parents) > 1);
symbol->continued_down = continued_down(row, next_row, pos);
symbol->continued_up = continued_down(prev_row, row, pos);
symbol->continued_right = continued_right(row, pos, graph->position);
symbol->continued_left = continued_left(row, pos, graph->position);
symbol->continued_up_left = continued_left(prev_row, pos, prev_row->size);
symbol->parent_down = parent_down(parents, next_row, pos);
symbol->parent_right = (pos > graph->position && parent_right(parents, row, next_row, pos));
symbol->below_commit = below_commit(pos, graph);
symbol->flanked = flanked(row, pos, graph->position, graph->id);
symbol->next_right = continued_right(next_row, pos, 0);
symbol->matches_commit = (strcmp(column->id, graph->id) == 0);
symbol->shift_left = shift_left(row, prev_row, pos);
symbol->continue_shift = shift_left(row, prev_row, pos + 1);
symbol->below_shift = prev_row->columns[pos].symbol.shift_left;
symbol->new_column = new_column(row, prev_row, pos);
symbol->empty = (!graph_column_has_commit(&row->columns[pos]));
if (graph_column_has_commit(column)) {
id = column->id;
}
symbol->color = get_color(graph, id);
graph_canvas_append_symbol(graph, symbol);
}
colors_remove_id(&graph->colors, graph->id);
}
bool
graph_render_parents(struct graph *graph)
{
if (!graph_expand(graph))
return FALSE;
graph_generate_next_row(graph);
graph_generate_symbols(graph);
graph_commit_next_row(graph);
graph->parents.size = graph->position = 0;
if (!graph_collapse(graph))
return FALSE;
return TRUE;
}
bool
graph_add_commit(struct graph *graph, struct graph_canvas *canvas,
const char *id, const char *parents, bool is_boundary)
{
graph->position = graph_find_column_by_id(&graph->row, id);
graph->id = id;
graph->canvas = canvas;
graph->is_boundary = is_boundary;
while ((parents = strchr(parents, ' '))) {
parents++;
if (!graph_add_parent(graph, parents))
return FALSE;
graph->has_parents = TRUE;
}
if (graph->parents.size == 0 &&
!graph_add_parent(graph, ""))
return FALSE;
return TRUE;
}
const bool
graph_symbol_forks(struct graph_symbol *symbol)
{
if (!symbol->continued_down)
return false;
if (!symbol->continued_right)
return false;
if (!symbol->continued_up)
return false;
return true;
}
const bool
graph_symbol_cross_over(struct graph_symbol *symbol)
{
if (symbol->empty)
return false;
if (!symbol->continued_down)
return false;
if (!symbol->continued_up && !symbol->new_column && !symbol->below_commit)
return false;
if (symbol->shift_left)
return false;
if (symbol->parent_right && symbol->merge)
return true;
if (symbol->flanked)
return true;
return false;
}
const bool
graph_symbol_turn_left(struct graph_symbol *symbol)
{
if (symbol->matches_commit && symbol->continued_right && !symbol->continued_down)
return false;
if (symbol->continue_shift)
return false;
if (symbol->continued_up || symbol->new_column || symbol->below_commit) {
if (symbol->matches_commit)
return true;
if (symbol->shift_left)
return true;
}
return false;
}
const bool
graph_symbol_turn_down_cross_over(struct graph_symbol *symbol)
{
if (!symbol->continued_down)
return false;
if (!symbol->continued_right)
return false;
if (symbol->flanked)
return true;
if (symbol->merge)
return true;
return false;
}
const bool
graph_symbol_turn_down(struct graph_symbol *symbol)
{
if (!symbol->continued_down)
return false;
if (!symbol->continued_right)
return false;
return true;
}
const bool
graph_symbol_merge(struct graph_symbol *symbol)
{
if (symbol->continued_down)
return false;
if (!symbol->parent_down)
return false;
if (symbol->parent_right)
return false;
return true;
}
const bool
graph_symbol_multi_merge(struct graph_symbol *symbol)
{
if (!symbol->parent_down)
return false;
if (!symbol->parent_right)
return false;
return true;
}
const bool
graph_symbol_vertical_bar(struct graph_symbol *symbol)
{
if (symbol->empty)
return false;
if (symbol->shift_left)
return false;
if (!symbol->continued_down)
return false;
if (symbol->continued_up)
return true;
if (symbol->parent_right)
return false;
if (symbol->flanked)
return false;
if (symbol->continued_right)
return false;
return true;
}
const bool
graph_symbol_horizontal_bar(struct graph_symbol *symbol)
{
if (symbol->shift_left)
return true;
if (symbol->continued_down)
return false;
if (!symbol->parent_right && !symbol->continued_right)
return false;
if ((symbol->continued_up && !symbol->continued_up_left))
return false;
if (!symbol->below_commit)
return true;
return false;
}
const bool
graph_symbol_multi_branch(struct graph_symbol *symbol)
{
if (symbol->continued_down)
return false;
if (!symbol->continued_right)
return false;
if (symbol->below_shift)
return false;
if (symbol->continued_up || symbol->new_column || symbol->below_commit) {
if (symbol->matches_commit)
return true;
if (symbol->shift_left)
return true;
}
return false;
}
const char *
graph_symbol_to_utf8(struct graph_symbol *symbol)
{
if (symbol->commit) {
if (symbol->boundary)
return " ◯";
else if (symbol->initial)
return " ◎";
else if (symbol->merge)
return " ●";
return " ●";
}
if (graph_symbol_cross_over(symbol))
return "─│";
if (graph_symbol_vertical_bar(symbol))
return " │";
if (graph_symbol_turn_left(symbol))
return "─╯";
if (graph_symbol_multi_branch(symbol))
return "─┴";
if (graph_symbol_horizontal_bar(symbol))
return "──";
if (graph_symbol_forks(symbol))
return " ├";
if (graph_symbol_turn_down_cross_over(symbol))
return "─╭";
if (graph_symbol_turn_down(symbol))
return " ╭";
if (graph_symbol_merge(symbol))
return "─╮";
if (graph_symbol_multi_merge(symbol))
return "─┬";
return " ";
}
const chtype *
graph_symbol_to_chtype(struct graph_symbol *symbol)
{
static chtype graphics[2];
if (symbol->commit) {
graphics[0] = ' ';
if (symbol->boundary)
graphics[1] = 'o';
else if (symbol->initial)
graphics[1] = 'I';
else if (symbol->merge)
graphics[1] = 'M';
else
graphics[1] = 'o'; //ACS_DIAMOND; //'*';
return graphics;
} else if (graph_symbol_cross_over(symbol)) {
graphics[0] = ACS_HLINE;
graphics[1] = ACS_VLINE;
} else if (graph_symbol_vertical_bar(symbol)) {
graphics[0] = ' ';
graphics[1] = ACS_VLINE;
} else if (graph_symbol_turn_left(symbol)) {
graphics[0] = ACS_HLINE;
graphics[1] = ACS_LRCORNER;
} else if (graph_symbol_multi_branch(symbol)) {
graphics[0] = ACS_HLINE;
graphics[1] = ACS_BTEE;
} else if (graph_symbol_horizontal_bar(symbol)) {
graphics[0] = graphics[1] = ACS_HLINE;
} else if (graph_symbol_forks(symbol)) {
graphics[0] = ' ';
graphics[1] = ACS_LTEE;
} else if (graph_symbol_turn_down_cross_over(symbol)) {
graphics[0] = ACS_HLINE;
graphics[1] = ACS_ULCORNER;
} else if (graph_symbol_turn_down(symbol)) {
graphics[0] = ' ';
graphics[1] = ACS_ULCORNER;
} else if (graph_symbol_merge(symbol)) {
graphics[0] = ACS_HLINE;
graphics[1] = ACS_URCORNER;
} else if (graph_symbol_multi_merge(symbol)) {
graphics[0] = ACS_HLINE;
graphics[1] = ACS_TTEE;
} else {
graphics[0] = graphics[1] = ' ';
}
return graphics;
}
const char *
graph_symbol_to_ascii(struct graph_symbol *symbol)
{
if (symbol->commit) {
if (symbol->boundary)
return " o";
else if (symbol->initial)
return " I";
else if (symbol->merge)
return " M";
return " *";
}
if (graph_symbol_cross_over(symbol))
return "-|";
if (graph_symbol_vertical_bar(symbol))
return " |";
if (graph_symbol_turn_left(symbol))
return "-'";
if (graph_symbol_multi_branch(symbol))
return "-+";
if (graph_symbol_horizontal_bar(symbol))
return "--";
if (graph_symbol_forks(symbol))
return " +";
if (graph_symbol_turn_down_cross_over(symbol))
return "-.";
if (graph_symbol_turn_down(symbol))
return " .";
if (graph_symbol_merge(symbol))
return "-.";
if (graph_symbol_multi_merge(symbol))
return "-+";
return " ";
}
/* vim: set ts=8 sw=8 noexpandtab: */