- Re-indented the output and latex files.

This commit is contained in:
ccremers 2004-04-23 11:03:07 +00:00
parent 0f4e6a5aba
commit 6efcbdea62
2 changed files with 1111 additions and 983 deletions

View File

@ -23,7 +23,8 @@ extern Term TERM_Function;
/* struct for additional info */ /* struct for additional info */
struct traceinfo { struct traceinfo
{
int match; int match;
int position; int position;
}; };
@ -37,36 +38,38 @@ int *runPerm;
/* code */ /* code */
void latexInit(const System sys, int argc, char **argv) void
latexInit (const System sys, int argc, char **argv)
{ {
int i; int i;
printf("\\documentclass{article}\n"); printf ("\\documentclass{article}\n");
printf("\\usepackage{msc}\n"); printf ("\\usepackage{msc}\n");
printf("%%\n"); printf ("%%\n");
printf("%% LaTeX output generated by %s\n", progname); printf ("%% LaTeX output generated by %s\n", progname);
printf("%% Input:\n"); printf ("%% Input:\n");
/* print command line */ /* print command line */
printf("%% $"); printf ("%% $");
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
printf(" %s", argv[i]); printf (" %s", argv[i]);
printf("\n"); printf ("\n");
printf("%%\n"); printf ("%%\n");
printf("\\begin{document}\n\n"); printf ("\\begin{document}\n\n");
/* comment macro (used for debugging) */ /* comment macro (used for debugging) */
printf("\\newcommand{\\comment}[1]{}\n"); printf ("\\newcommand{\\comment}[1]{}\n");
/* preamble */ /* preamble */
printf("\\input{preamble}\n"); printf ("\\input{preamble}\n");
} }
void latexDone(const System sys) void
latexDone (const System sys)
{ {
printf("\\input{postamble}\n"); printf ("\\input{postamble}\n");
printf("\n\\end{document}\n\n"); printf ("\n\\end{document}\n\n");
} }
void void
@ -87,8 +90,8 @@ latexTermPrint (Term term, Termlist highlight)
#endif #endif
if (realTermLeaf (term)) if (realTermLeaf (term))
{ {
if (inTermlist(highlight, term)) if (inTermlist (highlight, term))
printf("\\mathbf{"); printf ("\\mathbf{");
symbolPrint (term->symb); symbolPrint (term->symb);
if (realTermVariable (term)) if (realTermVariable (term))
printf ("V"); printf ("V");
@ -101,8 +104,8 @@ latexTermPrint (Term term, Termlist highlight)
printf ("\\rightarrow"); printf ("\\rightarrow");
latexTermPrint (term->subst, highlight); latexTermPrint (term->subst, highlight);
} }
if (inTermlist(highlight, term)) if (inTermlist (highlight, term))
printf("}"); printf ("}");
} }
if (realTermTuple (term)) if (realTermTuple (term))
{ {
@ -156,35 +159,37 @@ latexTermlistPrint (Termlist tl, Termlist highlight)
latexTermPrint (tl->term, highlight); latexTermPrint (tl->term, highlight);
tl = tl->next; tl = tl->next;
if (tl != NULL) if (tl != NULL)
printf(", "); printf (", ");
} }
printf ("]"); printf ("]");
} }
void latexTimers(const System sys) void
latexTimers (const System sys)
{ {
void endline(void) { void endline (void)
printf("\\\\ \\hline\n"); {
printf ("\\\\ \\hline\n");
} }
printf("\\begin{tabular}{|r|r|c|r|} \\hline\n"); printf ("\\begin{tabular}{|r|r|c|r|} \\hline\n");
/* display stats, header first */ /* display stats, header first */
printf("Time & States & Attack & st/sec"); printf ("Time & States & Attack & st/sec");
endline(); endline ();
/* print time */ /* print time */
double seconds; double seconds;
seconds = (double) clock() / CLOCKS_PER_SEC; seconds = (double) clock () / CLOCKS_PER_SEC;
printf("$%.3e$ &", seconds); printf ("$%.3e$ &", seconds);
/* states traversed */ /* states traversed */
printf("$"); printf ("$");
statesPrintShort(sys); statesPrintShort (sys);
printf("$ &"); printf ("$ &");
/* flag /* flag
* *
@ -193,13 +198,16 @@ void latexTimers(const System sys)
* NoClaim no claims * NoClaim no claims
*/ */
if (sys->claims == 0) { if (sys->claims == 0)
printf("NoClaim & "); {
} else { printf ("NoClaim & ");
if (sys->failed > 0) }
printf("L:%i & ", attackLength(sys->attack));
else else
printf("None & "); {
if (sys->failed > 0)
printf ("L:%i & ", attackLength (sys->attack));
else
printf ("None & ");
} }
/* /*
@ -211,166 +219,195 @@ void latexTimers(const System sys)
/* states per second */ /* states per second */
if (seconds > 0) { if (seconds > 0)
printf("$%.3e$ ", {
printf ("$%.3e$ ",
(double) (sys->statesLow + (double) (sys->statesLow +
(sys->statesHigh * ULONG_MAX)) / seconds); (sys->statesHigh * ULONG_MAX)) / seconds);
} else {
printf("$\\infty$ ");
} }
endline(); else
{
printf ("$\\infty$ ");
}
endline ();
printf("\\end{tabular}\n\n"); printf ("\\end{tabular}\n\n");
} }
void latexMSCStart() void
latexMSCStart ()
{ {
if (landscape) if (landscape)
printf("\\begin{landscape}\n"); printf ("\\begin{landscape}\n");
printf("\\begin{msc}{attack}\n"); printf ("\\begin{msc}{attack}\n");
} }
void latexMSCEnd() void
latexMSCEnd ()
{ {
printf("\\end{msc}\n"); printf ("\\end{msc}\n");
if (landscape) if (landscape)
printf("\\end{landscape}\n"); printf ("\\end{landscape}\n");
} }
void latexDeclInst(const System sys, int run) void
latexDeclInst (const System sys, int run)
{ {
Term bar = NULL; Term bar = NULL;
bar = agentOfRun(sys, run); bar = agentOfRun (sys, run);
printf("\\declinst{run%d}{$", run); printf ("\\declinst{run%d}{$", run);
termPrint(bar); termPrint (bar);
printf("\\sharp%i$}{$", run); printf ("\\sharp%i$}{$", run);
agentsOfRunPrint(sys, run); agentsOfRunPrint (sys, run);
printf("$}\n"); printf ("$}\n");
} }
void latexEventSpace(int amount) void
latexEventSpace (int amount)
{ {
int i; int i;
//printf("%% number of newlines: %d\n",amount); //printf("%% number of newlines: %d\n",amount);
for (i = 0; i < EVENTSPACE * amount; i++) for (i = 0; i < EVENTSPACE * amount; i++)
printf("\\nextlevel\n"); printf ("\\nextlevel\n");
} }
void latexMessagePrint(struct tracebuf *tb, int from, int to) void
latexMessagePrint (struct tracebuf *tb, int from, int to)
{ {
Term sendTerm = NULL; Term sendTerm = NULL;
Term readTerm = NULL; Term readTerm = NULL;
if (from == -1 && to == -1) { if (from == -1 && to == -1)
{
return; return;
} }
if (from != -1) { if (from != -1)
{
sendTerm = tb->event[from]->message; sendTerm = tb->event[from]->message;
} }
if (to != -1) { if (to != -1)
{
readTerm = tb->event[to]->message; readTerm = tb->event[to]->message;
} }
if (from == -1 && to != -1) { if (from == -1 && to != -1)
printf("\\found{$"); {
termPrint(readTerm); printf ("\\found{$");
printf("$}{}{run%d}\n", tb->run[to]); termPrint (readTerm);
} else if (from != -1 && to == -1) { printf ("$}{}{run%d}\n", tb->run[to]);
printf("\\lost{$"); }
termPrint(sendTerm); else if (from != -1 && to == -1)
printf("$}{}{run%d}\n", tb->run[from]); {
} else if (from != -1 && to != -1) { printf ("\\lost{$");
termPrint (sendTerm);
printf ("$}{}{run%d}\n", tb->run[from]);
}
else if (from != -1 && to != -1)
{
printf("\\mess{$"); printf ("\\mess{$");
termPrint(sendTerm); termPrint (sendTerm);
if (!isTermEqual(sendTerm, readTerm)) { if (!isTermEqual (sendTerm, readTerm))
printf("\\rightarrow"); {
termPrint(readTerm); printf ("\\rightarrow");
termPrint (readTerm);
} }
printf("$}{run%d", tb->run[from]); printf ("$}{run%d", tb->run[from]);
printf("}{run%d}[%d]", tb->run[to], printf ("}{run%d}[%d]", tb->run[to],
EVENTSPACE * (tinfo[to].position - EVENTSPACE * (tinfo[to].position - tinfo[from].position));
tinfo[from].position));
printf("\n"); printf ("\n");
} }
} }
void latexMessagePrintHighlight(struct tracebuf *tb, int from, int to, Termlist highlight) void
latexMessagePrintHighlight (struct tracebuf *tb, int from, int to,
Termlist highlight)
{ {
Term sendTerm = NULL; Term sendTerm = NULL;
Term readTerm = NULL; Term readTerm = NULL;
if (from == -1 && to == -1) { if (from == -1 && to == -1)
{
return; return;
} }
if (from != -1) { if (from != -1)
{
sendTerm = tb->event[from]->message; sendTerm = tb->event[from]->message;
} }
if (to != -1) { if (to != -1)
{
readTerm = tb->event[to]->message; readTerm = tb->event[to]->message;
} }
if (from == -1 && to != -1) { if (from == -1 && to != -1)
printf("\\found{$"); {
latexTermPrint(readTerm, highlight); printf ("\\found{$");
printf("$}{}{run%d}\n", tb->run[to]); latexTermPrint (readTerm, highlight);
} else if (from != -1 && to == -1) { printf ("$}{}{run%d}\n", tb->run[to]);
printf("\\lost{$"); }
latexTermPrint(sendTerm, highlight); else if (from != -1 && to == -1)
printf("$}{}{run%d}\n", tb->run[from]); {
} else if (from != -1 && to != -1) { printf ("\\lost{$");
latexTermPrint (sendTerm, highlight);
printf ("$}{}{run%d}\n", tb->run[from]);
}
else if (from != -1 && to != -1)
{
printf("\\mess{$"); printf ("\\mess{$");
latexTermPrint(sendTerm, highlight); latexTermPrint (sendTerm, highlight);
if (!isTermEqual(sendTerm, readTerm)) { if (!isTermEqual (sendTerm, readTerm))
printf("\\rightarrow"); {
latexTermPrint(readTerm, highlight); printf ("\\rightarrow");
latexTermPrint (readTerm, highlight);
} }
printf("$}{run%d", tb->run[from]); printf ("$}{run%d", tb->run[from]);
printf("}{run%d}[%d]", tb->run[to], printf ("}{run%d}[%d]", tb->run[to],
EVENTSPACE * (tinfo[to].position - EVENTSPACE * (tinfo[to].position - tinfo[from].position));
tinfo[from].position));
printf("\n"); printf ("\n");
} }
} }
void latexLearnComment(struct tracebuf *tb, int index, Termlist tl) void
latexLearnComment (struct tracebuf *tb, int index, Termlist tl)
{ {
printf("\\msccomment[4ex]{$I_%d=I_%d\\oplus ", index + 1, printf ("\\msccomment[4ex]{$I_%d=I_%d\\oplus ", index + 1, index);
index); termlistPrint (tl);
termlistPrint(tl); printf ("$}{envright}\n");
printf("$}{envright}\n");
} }
void latexAction(struct tracebuf *tb, int te) void
latexAction (struct tracebuf *tb, int te)
{ {
printf("\\action{$"); printf ("\\action{$");
termPrint(tb->event[te]->message); termPrint (tb->event[te]->message);
printf("$}{run%d}\n", tb->run[te]); printf ("$}{run%d}\n", tb->run[te]);
//printf("\\nextlevel\n"); //printf("\\nextlevel\n");
} }
void latexClaim(struct tracebuf *tb, int run, Termlist tl) void
latexClaim (struct tracebuf *tb, int run, Termlist tl)
{ {
printf("\\condition{$"); printf ("\\condition{$");
printf("\\neg secret "); printf ("\\neg secret ");
termlistPrint(tl); termlistPrint (tl);
printf("$}{run%d}\n", run); printf ("$}{run%d}\n", run);
} }
int latexCorrespondingSend(struct tracebuf *tb, int rd) int
latexCorrespondingSend (struct tracebuf *tb, int rd)
{ {
int labelMatch = 0; int labelMatch = 0;
@ -385,49 +422,57 @@ int latexCorrespondingSend(struct tracebuf *tb, int rd)
int sendEvent = -1; int sendEvent = -1;
int bestSendEvent = -1; int bestSendEvent = -1;
for (sendEvent = readEvent; sendEvent >= 0; sendEvent--) { for (sendEvent = readEvent; sendEvent >= 0; sendEvent--)
if (tb->event[sendEvent]->type == SEND) { {
if (tb->event[sendEvent]->type == SEND)
{
/* do all the different kind of matchings first */ /* do all the different kind of matchings first */
labelMatch = labelMatch =
isTermEqual(tb->event[sendEvent]->label, isTermEqual (tb->event[sendEvent]->label,
tb->event[readEvent]->label); tb->event[readEvent]->label);
toMatch = toMatch =
isTermEqual(tb->event[sendEvent]->to, isTermEqual (tb->event[sendEvent]->to, tb->event[readEvent]->to);
tb->event[readEvent]->to);
fromMatch = fromMatch =
isTermEqual(tb->event[sendEvent]->from, isTermEqual (tb->event[sendEvent]->from,
tb->event[readEvent]->from); tb->event[readEvent]->from);
tofromMatch = toMatch || fromMatch; tofromMatch = toMatch || fromMatch;
messageMatch = messageMatch =
isTermEqual(tb->event[sendEvent]->message, isTermEqual (tb->event[sendEvent]->message,
tb->event[readEvent]->message); tb->event[readEvent]->message);
/* calculate the score */ /* calculate the score */
nMatches = labelMatch + tofromMatch + messageMatch; nMatches = labelMatch + tofromMatch + messageMatch;
if (nMatches == 3) { if (nMatches == 3)
{
/* bingo! success on all matches */ /* bingo! success on all matches */
//printf("Found perfect match: %d\n", s); //printf("Found perfect match: %d\n", s);
bestSendEvent = sendEvent; bestSendEvent = sendEvent;
break; break;
} }
if (nMatches > maxNMatches) { if (nMatches > maxNMatches)
if (labelMatch && messageMatch) { {
if (labelMatch && messageMatch)
{
/* strongest restriction: message and label should match */ /* strongest restriction: message and label should match */
maxNMatches = nMatches; maxNMatches = nMatches;
bestSendEvent = sendEvent; bestSendEvent = sendEvent;
} else if (messageMatch) { }
else if (messageMatch)
{
/* if label AND message don't match: */ /* if label AND message don't match: */
/* at least message should match */ /* at least message should match */
maxNMatches = nMatches; maxNMatches = nMatches;
bestSendEvent = sendEvent; bestSendEvent = sendEvent;
} else if (labelMatch) { }
else if (labelMatch)
{
/* if message doesn't match */ /* if message doesn't match */
/* the label should matches */ /* the label should matches */
@ -439,15 +484,19 @@ int latexCorrespondingSend(struct tracebuf *tb, int rd)
} }
//bestSendEvent = NULL; //bestSendEvent = NULL;
if (bestSendEvent == -1) { if (bestSendEvent == -1)
{
int u; int u;
for (u = 0; u < rd; u++) { for (u = 0; u < rd; u++)
if (tb->event[u]->type == SEND) { {
if (tb->event[u]->type == SEND)
{
//knowledgePrint(sys->traceKnow[u]); //knowledgePrint(sys->traceKnow[u]);
if (inKnowledge if (inKnowledge
(tb->know[u + 1], tb->event[readEvent]->message)) { (tb->know[u + 1], tb->event[readEvent]->message))
{
bestSendEvent = u; bestSendEvent = u;
break; break;
} }
@ -455,8 +504,9 @@ int latexCorrespondingSend(struct tracebuf *tb, int rd)
} }
} }
if (bestSendEvent == -1) { if (bestSendEvent == -1)
printf("%% Could not find a matching SEND\n"); {
printf ("%% Could not find a matching SEND\n");
} }
return bestSendEvent; return bestSendEvent;
} }
@ -493,11 +543,12 @@ newInKnowledge (const Knowledge know, Term term)
return 0; /* unrecognized term type, weird */ return 0; /* unrecognized term type, weird */
} }
int latexCorrespondingSend2(struct tracebuf *tb, int readEvent) int
latexCorrespondingSend2 (struct tracebuf *tb, int readEvent)
{ {
int u; int u;
for (u = tb->length - 1; u>=0 ; u--) for (u = tb->length - 1; u >= 0; u--)
{ {
if (tb->event[u]->type == SEND) if (tb->event[u]->type == SEND)
{ {
@ -521,23 +572,25 @@ int latexCorrespondingSend2(struct tracebuf *tb, int readEvent)
* Display knowledge in LaTeX format. * Display knowledge in LaTeX format.
*/ */
void knowledgePrintLatex(Knowledge know) void
knowledgePrintLatex (Knowledge know)
{ {
Termlist tl; Termlist tl;
if (know == NULL) if (know == NULL)
{ {
printf("\\emptyset"); printf ("\\emptyset");
} }
else else
{ {
tl = knowledgeSet(know); tl = knowledgeSet (know);
termlistPrint(tl); termlistPrint (tl);
termlistDelete(tl); termlistDelete (tl);
} }
} }
void attackDisplayLatex(System sys) void
attackDisplayLatex (System sys)
{ {
int i; int i;
struct tracebuf *tb; struct tracebuf *tb;
@ -553,78 +606,81 @@ void attackDisplayLatex(System sys)
int bestSend; int bestSend;
tb = sys->attack; tb = sys->attack;
if (tb == NULL) { if (tb == NULL)
printf("Attack pointer empty: nothing to display.\n"); {
exit(1); printf ("Attack pointer empty: nothing to display.\n");
exit (1);
} }
/* set variables */ /* set variables */
varbufSet (sys, tb->variables); varbufSet (sys, tb->variables);
/* Rebuild knowledge. Strange, this ought to be good. /* Rebuild knowledge. Strange, this ought to be good.
* Maybe reconstruct dependencies as well. */ * Maybe reconstruct dependencies as well. */
tracebufRebuildKnow(tb); tracebufRebuildKnow (tb);
/* Make a comment in which the trace is displayed, for debugging etc. */ /* Make a comment in which the trace is displayed, for debugging etc. */
printf("\n\\comment{ TRACE\n\n"); printf ("\n\\comment{ TRACE\n\n");
printf("Length: %i\n",tb->length); printf ("Length: %i\n", tb->length);
printf("Reallength: %i\n",tb->reallength); printf ("Reallength: %i\n", tb->reallength);
printf("\n"); printf ("\n");
i = 0; i = 0;
while (i <= tb->length) while (i <= tb->length)
{ {
printf("Knowledge %i:\n",i); printf ("Knowledge %i:\n", i);
knowledgePrint(tb->know[i]); knowledgePrint (tb->know[i]);
printf(" [Inverses]: "); printf (" [Inverses]: ");
knowledgeInversesPrint(tb->know[i]); knowledgeInversesPrint (tb->know[i]);
printf("\n\n"); printf ("\n\n");
if (i < tb->length) if (i < tb->length)
{ {
printf("Event %i\t[",i); printf ("Event %i\t[", i);
switch (tb->status[i]) switch (tb->status[i])
{ {
case S_UNK: case S_UNK:
printf("?"); printf ("?");
break; break;
case S_RED: case S_RED:
printf("redundant"); printf ("redundant");
break; break;
case S_TOD: case S_TOD:
printf("to do"); printf ("to do");
break; break;
case S_OKE: case S_OKE:
printf("okay"); printf ("okay");
break; break;
default: default:
printf("illegal status code"); printf ("illegal status code");
break; break;
} }
printf("]\t"); printf ("]\t");
termPrint(tb->event[i]->message); termPrint (tb->event[i]->message);
printf("\t#%i",tb->run[i]); printf ("\t#%i", tb->run[i]);
printf("\n"); printf ("\n");
roledefPrint(tb->event[i]); roledefPrint (tb->event[i]);
printf("\n\n"); printf ("\n\n");
} }
i++; i++;
} }
printf("}\n\n"); printf ("}\n\n");
/* display initial knowledge */ /* display initial knowledge */
printf("$I_0 = \\emptyset \\oplus "); printf ("$I_0 = \\emptyset \\oplus ");
knowledgePrintLatex(tb->know[0]); knowledgePrintLatex (tb->know[0]);
printf("$\n\n"); printf ("$\n\n");
tinfo = tinfo =
(struct traceinfo *) memAlloc((tb->length+1) * (struct traceinfo *) memAlloc ((tb->length + 1) *
sizeof(struct traceinfo)); sizeof (struct traceinfo));
width = 1; width = 1;
for (i = 0; i < tb->length; i++) { for (i = 0; i < tb->length; i++)
{
if (tb->run[i] >= width) if (tb->run[i] >= width)
width = tb->run[i] + 1; width = tb->run[i] + 1;
} }
for (i = 0; i < tb->length; i++) { for (i = 0; i < tb->length; i++)
{
tb->link[i] = -1; tb->link[i] = -1;
tinfo[i].match = -1; tinfo[i].match = -1;
tinfo[i].position = i; tinfo[i].position = i;
@ -632,8 +688,9 @@ void attackDisplayLatex(System sys)
tinfo[i].match = -1; tinfo[i].match = -1;
tinfo[i].position = i; tinfo[i].position = i;
runPosition = (int *) memAlloc(width * sizeof(int)); runPosition = (int *) memAlloc (width * sizeof (int));
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
{
runPosition[i] = 0; runPosition[i] = 0;
} }
for (i = tb->length - 1; i >= 0; i--) for (i = tb->length - 1; i >= 0; i--)
@ -642,8 +699,8 @@ void attackDisplayLatex(System sys)
{ {
if (tb->event[i]->type == READ && !tb->event[i]->internal) if (tb->event[i]->type == READ && !tb->event[i]->internal)
{ {
bestSend = latexCorrespondingSend2(tb, i); bestSend = latexCorrespondingSend2 (tb, i);
printf("%% match: %d <-> %d\n",i, bestSend); printf ("%% match: %d <-> %d\n", i, bestSend);
if (bestSend == -1) if (bestSend == -1)
continue; continue;
@ -652,13 +709,15 @@ void attackDisplayLatex(System sys)
} }
if (tb->event[i]->type == CLAIM) if (tb->event[i]->type == CLAIM)
{ {
claimDetails = claimViolationDetails(sys, tb->run[i], tb->event[i], tb->know[i]); claimDetails =
claimViolationDetails (sys, tb->run[i], tb->event[i],
tb->know[i]);
} }
} }
} }
printf("\\comment{ claimDetails :\n"); printf ("\\comment{ claimDetails :\n");
termlistPrint(claimDetails); termlistPrint (claimDetails);
printf("\n}\n"); printf ("\n}\n");
// landscape = (width > 4); // not for the time being // landscape = (width > 4); // not for the time being
@ -673,44 +732,55 @@ void attackDisplayLatex(System sys)
eventSize = 1; eventSize = 1;
currRun = tb->run[i]; currRun = tb->run[i];
switch (tb->event[i]->type) { switch (tb->event[i]->type)
{
case SEND: case SEND:
position++; position++;
tinfo[i].position++; tinfo[i].position++;
break; break;
case READ: case READ:
if (tb->link[i] != -1) { if (tb->link[i] != -1)
if (termDistance(tb->event[i]->message,tb->event[tb->link[i]]->message) < LINKTHRESHOLD) {
if (termDistance
(tb->event[i]->message,
tb->event[tb->link[i]]->message) < LINKTHRESHOLD)
{ {
/* disconnect read-send */ /* disconnect read-send */
tb->link[tb->link[i]] = -1; tb->link[tb->link[i]] = -1;
tb->link[i] = -1; tb->link[i] = -1;
} else { }
if (runPosition[currRun] <= tinfo[tb->link[i]].position && else
currRun != tb->run[tb->link[i]])
{ {
printf("\\comment{\n"); if (runPosition[currRun] <= tinfo[tb->link[i]].position
termPrint(tb->event[i]->message); && currRun != tb->run[tb->link[i]])
printf("\n"); {
termPrint(tb->event[tb->link[i]]->message); printf ("\\comment{\n");
printf("\n"); termPrint (tb->event[i]->message);
printf("%% termDistance: %f\n", printf ("\n");
termDistance(tb->event[i]->message, termPrint (tb->event[tb->link[i]]->message);
tb->event[tb->link[i]]->message)); printf ("\n");
printf("}\n"); printf ("%% termDistance: %f\n",
termDistance (tb->event[i]->message,
tb->event[tb->link[i]]->
message));
printf ("}\n");
tinfo[i].position = tinfo[tb->link[i]].position; tinfo[i].position = tinfo[tb->link[i]].position;
eventSize = 0; eventSize = 0;
} }
} }
} }
if (tb->event[i]->internal) { if (tb->event[i]->internal)
{
eventSize = 0; eventSize = 0;
} }
break; break;
case CLAIM: case CLAIM:
if (claimDetails != NULL && claimDetails != (Termlist) -1) { if (claimDetails != NULL && claimDetails != (Termlist) - 1)
{
eventSize = 2; eventSize = 2;
} else { }
else
{
eventSize = 0; eventSize = 0;
} }
break; break;
@ -724,10 +794,11 @@ void attackDisplayLatex(System sys)
} }
} }
latexMSCStart(); latexMSCStart ();
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
{
if (runPosition[i] > 0) if (runPosition[i] > 0)
latexDeclInst(sys, i); latexDeclInst (sys, i);
} }
//for (j=-1; j<=sys->step; j++) //for (j=-1; j<=sys->step; j++)
@ -737,14 +808,15 @@ void attackDisplayLatex(System sys)
{ {
if (tb->status[i] != S_RED) if (tb->status[i] != S_RED)
{ {
latexEventSpace(tinfo[i].position - position); latexEventSpace (tinfo[i].position - position);
if (tinfo[i].position >= position) if (tinfo[i].position >= position)
{ {
position = tinfo[i].position; position = tinfo[i].position;
} }
switch (tb->event[i]->type) { switch (tb->event[i]->type)
{
case SEND: case SEND:
newtl = knowledgeNew(tb->know[i], tb->know[i + 1]); newtl = knowledgeNew (tb->know[i], tb->know[i + 1]);
highlights = NULL; highlights = NULL;
/* Build a Termlist of terms that from the claimViolationDetails, /* Build a Termlist of terms that from the claimViolationDetails,
that appear in the knowledge */ that appear in the knowledge */
@ -753,36 +825,43 @@ void attackDisplayLatex(System sys)
tl = claimDetails; tl = claimDetails;
while (tl != NULL) while (tl != NULL)
{ {
if (inTermlist(newtl, tl->term)) if (inTermlist (newtl, tl->term))
{ {
highlights = termlistAdd(highlights, tl->term); highlights = termlistAdd (highlights, tl->term);
} }
tl = tl->next; tl = tl->next;
} }
printf("\\msccomment[4ex]{$I_%d=I_%d\\oplus ", cKnowledge + 1, printf ("\\msccomment[4ex]{$I_%d=I_%d\\oplus ",
cKnowledge); cKnowledge + 1, cKnowledge);
cKnowledge++; cKnowledge++;
latexTermlistPrint(newtl, highlights); latexTermlistPrint (newtl, highlights);
printf("$}{envright}\n"); printf ("$}{envright}\n");
} }
if (tb->link[i] != -1 && i < tb->length) { if (tb->link[i] != -1 && i < tb->length)
latexMessagePrintHighlight(tb, i, tb->link[i], highlights); {
} else { latexMessagePrintHighlight (tb, i, tb->link[i], highlights);
latexMessagePrintHighlight(tb, i, -1, highlights); //lost message
} }
termlistDelete(highlights); else
{
latexMessagePrintHighlight (tb, i, -1, highlights); //lost message
}
termlistDelete (highlights);
break; break;
case READ: case READ:
if (tb->event[i]->internal) { if (tb->event[i]->internal)
} else if (tb->link[i] == -1) { {
latexMessagePrint(tb, -1, i); //found message }
else if (tb->link[i] == -1)
{
latexMessagePrint (tb, -1, i); //found message
} }
break; break;
case CLAIM: case CLAIM:
if (claimDetails != NULL && claimDetails != (Termlist) -1) { if (claimDetails != NULL && claimDetails != (Termlist) - 1)
latexClaim(tb, tb->run[i], claimDetails); {
latexClaim (tb, tb->run[i], claimDetails);
} }
break; break;
default: default:
@ -790,8 +869,8 @@ void attackDisplayLatex(System sys)
} }
} }
} }
latexEventSpace(2); latexEventSpace (2);
latexMSCEnd(); latexMSCEnd ();
memFree(runPosition, width * sizeof(int)); memFree (runPosition, width * sizeof (int));
memFree(tinfo, (tb->length+1) * sizeof(struct traceinfo)); memFree (tinfo, (tb->length + 1) * sizeof (struct traceinfo));
} }

View File

@ -12,17 +12,20 @@
#include "latex.h" #include "latex.h"
void linePrint(int i) void
linePrint (int i)
{ {
indent(); indent ();
while (i > 0) { while (i > 0)
printf("--------"); {
printf ("--------");
i--; i--;
} }
printf("\n"); printf ("\n");
} }
int correspondingSend(System sys, int rd) int
correspondingSend (System sys, int rd)
{ {
int labelMatch = 0; int labelMatch = 0;
@ -37,36 +40,40 @@ int correspondingSend(System sys, int rd)
int sendEvent = -1; int sendEvent = -1;
int bestSendEvent = -1; int bestSendEvent = -1;
for (sendEvent = readEvent; sendEvent >= 0; sendEvent--) { for (sendEvent = readEvent; sendEvent >= 0; sendEvent--)
if (sys->traceEvent[sendEvent]->type == SEND) { {
if (sys->traceEvent[sendEvent]->type == SEND)
{
/* do all the different kind of matchings first */ /* do all the different kind of matchings first */
labelMatch = labelMatch =
isTermEqualFn(sys->traceEvent[sendEvent]->label, isTermEqualFn (sys->traceEvent[sendEvent]->label,
sys->traceEvent[readEvent]->label); sys->traceEvent[readEvent]->label);
toMatch = toMatch =
isTermEqualFn(sys->traceEvent[sendEvent]->to, isTermEqualFn (sys->traceEvent[sendEvent]->to,
sys->traceEvent[readEvent]->to); sys->traceEvent[readEvent]->to);
fromMatch = fromMatch =
isTermEqualFn(sys->traceEvent[sendEvent]->from, isTermEqualFn (sys->traceEvent[sendEvent]->from,
sys->traceEvent[readEvent]->from); sys->traceEvent[readEvent]->from);
tofromMatch = toMatch || fromMatch; tofromMatch = toMatch || fromMatch;
messageMatch = messageMatch =
isTermEqualFn(sys->traceEvent[sendEvent]->message, isTermEqualFn (sys->traceEvent[sendEvent]->message,
sys->traceEvent[readEvent]->message); sys->traceEvent[readEvent]->message);
/* calculate the score */ /* calculate the score */
nMatches = labelMatch + tofromMatch + messageMatch; nMatches = labelMatch + tofromMatch + messageMatch;
if (nMatches == 3) { if (nMatches == 3)
{
/* bingo! success on all matches */ /* bingo! success on all matches */
//printf("Found perfect match: %d\n", s); //printf("Found perfect match: %d\n", s);
bestSendEvent = sendEvent; bestSendEvent = sendEvent;
break; break;
} }
if (nMatches > maxNMatches) { if (nMatches > maxNMatches)
{
/* if we found a better candidate than we already had, we'll update */ /* if we found a better candidate than we already had, we'll update */
//printf("Comparing SEND #%d: ",s); //printf("Comparing SEND #%d: ",s);
@ -78,19 +85,24 @@ int correspondingSend(System sys, int rd)
/* however, we first want to be sure that at least some matches are successful */ /* however, we first want to be sure that at least some matches are successful */
if (labelMatch && messageMatch) { if (labelMatch && messageMatch)
{
/* strongest restriction: message and label should match */ /* strongest restriction: message and label should match */
maxNMatches = nMatches; maxNMatches = nMatches;
bestSendEvent = sendEvent; bestSendEvent = sendEvent;
} else if (messageMatch) { }
else if (messageMatch)
{
/* if label AND message don't match: */ /* if label AND message don't match: */
/* at least message should match */ /* at least message should match */
maxNMatches = nMatches; maxNMatches = nMatches;
bestSendEvent = sendEvent; bestSendEvent = sendEvent;
} else if (labelMatch) { }
else if (labelMatch)
{
/* if message doesn't match */ /* if message doesn't match */
/* the label should matches */ /* the label should matches */
@ -103,7 +115,8 @@ int correspondingSend(System sys, int rd)
} }
//bestSendEvent = NULL; //bestSendEvent = NULL;
if (bestSendEvent == -1) { if (bestSendEvent == -1)
{
/*Termlist tl; /*Termlist tl;
Term t; Term t;
@ -133,17 +146,20 @@ int correspondingSend(System sys, int rd)
int u; int u;
for (u = 0; u < rd; u++) { for (u = 0; u < rd; u++)
if (sys->traceEvent[u]->type == SEND) { {
if (sys->traceEvent[u]->type == SEND)
{
//termPrint(readEvent->message); //termPrint(readEvent->message);
//printf("\n"); //printf("\n");
knowledgePrint(sys->traceKnow[u]); knowledgePrint (sys->traceKnow[u]);
//printf("Is received message in knowledge after SEND %d? %d\n", u, inKnowledge(sys->traceKnow[u+1],readEvent->message)); //printf("Is received message in knowledge after SEND %d? %d\n", u, inKnowledge(sys->traceKnow[u+1],readEvent->message));
if (inKnowledge if (inKnowledge
(sys->traceKnow[u + 1], (sys->traceKnow[u + 1],
sys->traceEvent[readEvent]->message)) { sys->traceEvent[readEvent]->message))
{
bestSendEvent = u; bestSendEvent = u;
break; break;
} }
@ -151,22 +167,27 @@ int correspondingSend(System sys, int rd)
} }
} }
if (bestSendEvent == -1) { if (bestSendEvent == -1)
printf("!! Could not find a matching SEND\n"); {
} else { printf ("!! Could not find a matching SEND\n");
}
else
{
//latexMessagePrint(sys, bestSendEvent, readEvent); //latexMessagePrint(sys, bestSendEvent, readEvent);
//printf("Latex: "); //printf("Latex: ");
//termPrint(bestSendEvent->from); //termPrint(bestSendEvent->from);
//printf(" -> "); //printf(" -> ");
if (!isTermEqualFn if (!isTermEqualFn
(sys->traceEvent[bestSendEvent]->to, (sys->traceEvent[bestSendEvent]->to,
sys->traceEvent[readEvent]->to)) { sys->traceEvent[readEvent]->to))
{
//termPrint(bestSendEvent->to); //termPrint(bestSendEvent->to);
//printf(" -> "); //printf(" -> ");
} }
if (!isTermEqualFn if (!isTermEqualFn
(sys->traceEvent[bestSendEvent]->from, (sys->traceEvent[bestSendEvent]->from,
sys->traceEvent[readEvent]->from)) { sys->traceEvent[readEvent]->from))
{
//termPrint(readEvent->from); //termPrint(readEvent->from);
//printf(" -> "); //printf(" -> ");
} }
@ -176,9 +197,11 @@ int correspondingSend(System sys, int rd)
return bestSendEvent; return bestSendEvent;
} }
void tracePrint(System sys) void
tracePrint (System sys)
{ {
if (sys->latex) { if (sys->latex)
{
//latexTracePrint(sys); //latexTracePrint(sys);
return; return;
} }
@ -197,80 +220,89 @@ void tracePrint(System sys)
/* how wide is the trace? */ /* how wide is the trace? */
width = 0; width = 0;
for (i = 0; i <= sys->step; i++) { for (i = 0; i <= sys->step; i++)
{
if (sys->traceRun[i] >= width) if (sys->traceRun[i] >= width)
width = sys->traceRun[i] + 1; width = sys->traceRun[i] + 1;
} }
linePrint(width); linePrint (width);
indent(); indent ();
printf("Dumping trace:\n"); printf ("Dumping trace:\n");
linePrint(width); linePrint (width);
/* first some parameter issues */ /* first some parameter issues */
knowledgePrint(sys->traceKnow[0]); knowledgePrint (sys->traceKnow[0]);
/* also print inverses */ /* also print inverses */
indent(); indent ();
printf("Inverses: "); printf ("Inverses: ");
knowledgeInversesPrint(sys->traceKnow[0]); knowledgeInversesPrint (sys->traceKnow[0]);
printf("\n"); printf ("\n");
/* Trace columns header. First the run identifier and role. On the /* Trace columns header. First the run identifier and role. On the
* second line we have the perceived agents for each partner role. * second line we have the perceived agents for each partner role.
* These are printed in the same order as the role specification in the * These are printed in the same order as the role specification in the
* protocol. */ * protocol. */
linePrint(width); linePrint (width);
indent(); indent ();
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
termPrint(sys->runs[i].role->nameterm); {
printf("#%i\t", i); termPrint (sys->runs[i].role->nameterm);
printf ("#%i\t", i);
} }
printf("\n"); printf ("\n");
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
termPrint(agentOfRun(sys, i)); {
printf("\t"); termPrint (agentOfRun (sys, i));
printf ("\t");
} }
printf("\n"); printf ("\n");
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
agentsOfRunPrint(sys, i); {
printf("\t"); agentsOfRunPrint (sys, i);
printf ("\t");
} }
printf("\n"); printf ("\n");
/* now we print the actual trace */ /* now we print the actual trace */
void sticks(int i) { void sticks (int i)
while (i > 0) { {
printf("|\t"); while (i > 0)
{
printf ("|\t");
i--; i--;
} }
} }
void sticksLine(void) { void sticksLine (void)
sticks(width); {
printf("\n"); sticks (width);
printf ("\n");
} }
linePrint(width); linePrint (width);
lastrid = -1; lastrid = -1;
for (i = 0; i <= sys->step; i++) { for (i = 0; i <= sys->step; i++)
{
/* yields extra newlines between switching of runs */ /* yields extra newlines between switching of runs */
j = sys->traceRun[i]; j = sys->traceRun[i];
if (j != lastrid) { if (j != lastrid)
sticksLine(); {
sticksLine ();
lastrid = j; lastrid = j;
} }
/* print the actual event */ /* print the actual event */
indent(); indent ();
sticks(j); sticks (j);
roledefPrint(sys->traceEvent[i]); roledefPrint (sys->traceEvent[i]);
//if (sys->traceEvent[i]->type == READ && !sys->traceEvent[i]->internal) //if (sys->traceEvent[i]->type == READ && !sys->traceEvent[i]->internal)
//{ //{
@ -282,37 +314,40 @@ void tracePrint(System sys)
//} //}
/* have we learnt anything new? */ /* have we learnt anything new? */
newtl = knowledgeNew(sys->traceKnow[i], sys->traceKnow[i + 1]); newtl = knowledgeNew (sys->traceKnow[i], sys->traceKnow[i + 1]);
if (newtl != NULL) { if (newtl != NULL)
printf("\n"); {
sticksLine(); printf ("\n");
sticks(width); sticksLine ();
printf("/* Intruder learns "); sticks (width);
termlistPrint(newtl); printf ("/* Intruder learns ");
termlistDelete(newtl); termlistPrint (newtl);
printf(" */"); termlistDelete (newtl);
printf (" */");
lastrid = -1; lastrid = -1;
} }
/* new line */ /* new line */
printf("\n"); printf ("\n");
} }
switch (sys->clp) { switch (sys->clp)
{
case 1: case 1:
indent(); indent ();
printf("---[ constraints ]-----\n"); printf ("---[ constraints ]-----\n");
constraintlistPrint(sys->constraints); constraintlistPrint (sys->constraints);
break; break;
default: default:
break; break;
} }
linePrint(width); linePrint (width);
} }
void attackDisplayAscii(System sys) void
attackDisplayAscii (System sys)
{ {
int i, j; int i, j;
int length; int length;
@ -330,19 +365,20 @@ void attackDisplayAscii(System sys)
/* how wide is the trace? */ /* how wide is the trace? */
width = 0; width = 0;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++)
{
if (tb->run[i] >= width) if (tb->run[i] >= width)
width = tb->run[i] + 1; width = tb->run[i] + 1;
} }
linePrint(width); linePrint (width);
indent(); indent ();
printf("Dumping trace:\n"); printf ("Dumping trace:\n");
linePrint(width); linePrint (width);
/* first some parameter issues */ /* first some parameter issues */
knowledgePrint(tb->know[0]); knowledgePrint (tb->know[0]);
printf ("Variables: "); printf ("Variables: ");
termlistPrint (sys->variables); termlistPrint (sys->variables);
printf ("\n"); printf ("\n");
@ -352,56 +388,64 @@ void attackDisplayAscii(System sys)
* These are printed in the same order as the role specification in the * These are printed in the same order as the role specification in the
* protocol. */ * protocol. */
linePrint(width); linePrint (width);
indent(); indent ();
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
termPrint(sys->runs[i].role->nameterm); {
printf("#%i\t", i); termPrint (sys->runs[i].role->nameterm);
printf ("#%i\t", i);
} }
printf("\n"); printf ("\n");
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
termPrint(agentOfRun(sys, i)); {
printf("\t"); termPrint (agentOfRun (sys, i));
printf ("\t");
} }
printf("\n"); printf ("\n");
for (i = 0; i < width; i++) { for (i = 0; i < width; i++)
agentsOfRunPrint(sys, i); {
printf("\t"); agentsOfRunPrint (sys, i);
printf ("\t");
} }
printf("\n"); printf ("\n");
/* now we print the actual trace */ /* now we print the actual trace */
void sticks(int i) { void sticks (int i)
while (i > 0) { {
printf("|\t"); while (i > 0)
{
printf ("|\t");
i--; i--;
} }
} }
void sticksLine(void) { void sticksLine (void)
sticks(width); {
printf("\n"); sticks (width);
printf ("\n");
} }
linePrint(width); linePrint (width);
lastrid = -1; lastrid = -1;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++)
{
/* yields extra newlines between switching of runs */ /* yields extra newlines between switching of runs */
j = tb->run[i]; j = tb->run[i];
if (j != lastrid) { if (j != lastrid)
sticksLine(); {
sticksLine ();
lastrid = j; lastrid = j;
} }
/* print the actual event */ /* print the actual event */
indent(); indent ();
sticks(j); sticks (j);
roledefPrint(tb->event[i]); roledefPrint (tb->event[i]);
//if (sys->traceEvent[i]->type == READ && !sys->traceEvent[i]->internal) //if (sys->traceEvent[i]->type == READ && !sys->traceEvent[i]->internal)
//{ //{
@ -413,31 +457,36 @@ void attackDisplayAscii(System sys)
//} //}
/* have we learnt anything new? */ /* have we learnt anything new? */
newtl = knowledgeNew(tb->know[i], tb->know[i + 1]); newtl = knowledgeNew (tb->know[i], tb->know[i + 1]);
if (newtl != NULL) { if (newtl != NULL)
printf("\n"); {
sticksLine(); printf ("\n");
sticks(width); sticksLine ();
printf("/* Intruder learns "); sticks (width);
termlistPrint(newtl); printf ("/* Intruder learns ");
termlistDelete(newtl); termlistPrint (newtl);
printf(" */"); termlistDelete (newtl);
printf (" */");
lastrid = -1; lastrid = -1;
} }
/* new line */ /* new line */
printf("\n"); printf ("\n");
} }
linePrint(width); linePrint (width);
} }
void attackDisplay(System sys) void
attackDisplay (System sys)
{ {
if (sys->latex) { if (sys->latex)
attackDisplayLatex(sys); {
} else { attackDisplayLatex (sys);
attackDisplayAscii(sys); }
else
{
attackDisplayAscii (sys);
} }
} }