From: ian Date: Sun, 20 Mar 2005 18:51:09 +0000 (+0000) Subject: redactgraph prints and documents forforsafety X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=be5d45692742159b802057bb9a74a1dd19810ffc;p=trains.git redactgraph prints and documents forforsafety --- diff --git a/layout/redactgraph.c b/layout/redactgraph.c index 70953b4..dcd5bd7 100644 --- a/layout/redactgraph.c +++ b/layout/redactgraph.c @@ -1,4 +1,26 @@ /* + * output format from printforforsafety is lines like this: + * segment . . [/] + * #... (comment) + * (blank) + * end (at end of file, mandatory) + * syntactic restrictions: + * is alphanumeric and starts with a letter + * is precisely the digit 0 or the digit 1 + * is alphanumeric (and comes from the layout) + * is [...]* + * where is alphabetic and is and + * are in decimal and have no unnecessary leading 0's + * semantic restrictions (not enforced by redactgraph but ought to + * be impossible for layout designer to violate): + * Each [/] appears exactly once. + * appears either once without / or always with. + * Each side of each node appears either + * - once as the 0th or 1th end of a + * - one or more times as the same end of /'s with + * the same + * - not at all (indicates a terminus) + * Refer to safety.h for info regarding . */ /* for debugging, runes like * ./ours.redactgraph consistency movfeatsplitedges consistency movfeatrmstubs consistency movfeatsplitnodes consistency trivpairnodes consistency trivnullnodes consistency printforneato | neato -Tps >u.ps @@ -244,7 +266,7 @@ static void node_surely_orphaned(Node *node) { LIST_UNLINK(all_nodes, node); } -/*---------- operations ----------*/ +/*---------- operations - heavyweight graph redaction ----------*/ /* We combine the individual moveable features in each segment into * a single `feature' with the cross-product of all of the @@ -504,6 +526,8 @@ static void movfeatsplitnodes(void) { } } +/*---------- operations - trivial graph redaction etc. ----------*/ + static void trivpairnodes(void) { /* Eliminate near-trivial nodes - in this case, ones which have only * two edges, which come in on opposite sides, have the same @@ -621,6 +645,8 @@ static void consistency(void) { check("command-line request"); } +/*---------- operations - output ----------*/ + static void printforneato(void) { Node *node; EdgeEnd *edgeend; @@ -656,6 +682,47 @@ static void printforneato(void) { output("}\n"); } +static void printforforsafety(void) { + Node *node; + Edge *edge; + EdgeEnd *edgeend; + int side, end, weight, i; + Segment *segment; + MovFeat *movfeat; + + FOR_ALL_NODES(node) { + FOR_EDGES(edge, node,side,edgeend) { + output("segment "); + FOR_BOTH(end) { + output("n%s.%d ", + edge->ends[end].node->node->pname, + edge->ends[end].node->side); + } + segment= edge->subseg->segment; + output(segment->segname); + if (segment->n_movfeats>1) { + if (!segment->starfeature) { + fprintf(stderr,"printforforsafety before movfeatsplitedges!\n"); + exit(8); + } + output("/"); + weight= 1; + FOR_SEGMENT_MOVFEATS(i,movfeat, segment) { + if (!movfeat->movfeat) continue; + output("%s%d", movfeat->movfeat, + (edge->movpos / weight) % movfeat->n_positions); + weight *= movfeat->n_positions; + } + output("*%d", edge->movpos); + } + output("\n"); + } + } + output("end\n"); +} + +/*---------- main program ----------*/ + typedef struct { const char *name; void (*fn)(void); @@ -664,6 +731,7 @@ typedef struct { static const OpInfo opinfos[]= { #define OI(x) { #x, x }, OI(printforneato) + OI(printforforsafety) OI(consistency) OI(movfeatsplitedges) OI(movfeatrmstubs)