forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty_ref.c
More file actions
69 lines (59 loc) · 1.9 KB
/
pretty_ref.c
File metadata and controls
69 lines (59 loc) · 1.9 KB
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
/** \file pretty_ref.c
* split out of exppp.c 9/21/13
*/
#include <express/schema.h>
#include <exppp/exppp.h>
#include "pp.h"
#include "pretty_ref.h"
void REFout( Dictionary refdict, Linked_List reflist, char * type, int level ) {
Dictionary dict;
DictionaryEntry de;
struct Rename * ren;
Linked_List list;
LISTdo( reflist, s, Schema )
raw( "%s FROM %s;\n", type, s->symbol.name );
LISTod
if( !refdict ) {
return;
}
dict = DICTcreate( 10 );
/* sort each list by schema */
/* step 1: for each entry, store it in a schema-specific list */
DICTdo_init( refdict, &de );
while( 0 != ( ren = ( struct Rename * )DICTdo( &de ) ) ) {
Linked_List nameList;
nameList = ( Linked_List )DICTlookup( dict, ren->schema->symbol.name );
if( !nameList ) {
nameList = LISTcreate();
DICTdefine( dict, ren->schema->symbol.name, nameList, NULL, OBJ_UNKNOWN );
}
LISTadd_last( nameList, ren );
}
/* step 2: for each list, print out the renames */
level = 6; /* no special reason, feels good */
indent2 = level + exppp_continuation_indent;
DICTdo_init( dict, &de );
while( 0 != ( list = ( Linked_List )DICTdo( &de ) ) ) {
bool first_time = true;
LISTdo( list, r, struct Rename * ) {
if( first_time ) {
raw( "%s FROM %s\n", type, r->schema->symbol.name );
} else {
/* finish previous line */
raw( ",\n" );
}
if( first_time ) {
raw( "%*s( ", level, "" );
first_time = false;
} else {
raw( "%*s ", level, "" );
}
raw( r->old->name );
if( r->old != r->nnew ) {
wrap( " AS %s", r->nnew->name );
}
} LISTod
raw( " );\n" );
}
HASHdestroy( dict );
}