Crossings Minimization  1.0
dot.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include "dot.h"
#include "defs.h"
Include dependency graph for dot.c:

Go to the source code of this file.

Macros

#define MAX_MSG_LENGTH   512
 
#define MAX_NAME_LENGTH   512
 

Functions

static void error (bool fatal)
 
static int skip_blanks_and_comments (int ch, FILE *in_stream)
 
static char read_identifier (int ch, FILE *in, char *id_buf)
 
void initDot (FILE *in)
 
void getNameFromDotFile (char *buffer)
 
bool nextEdge (FILE *in, char *src_buf, char *dst_buf)
 
void dotPreamble (FILE *out, const char *graph_name, const char *seed_info)
 
void endDot (FILE *out)
 
void outputEdge (FILE *out, const char *src_name, const char *dst_name)
 

Variables

static char error_message [MAX_MSG_LENGTH]
 
static char graph_name [MAX_NAME_LENGTH]
 
static int line_number = 1
 

Macro Definition Documentation

◆ MAX_MSG_LENGTH

#define MAX_MSG_LENGTH   512

Definition at line 38 of file dot.c.

◆ MAX_NAME_LENGTH

#define MAX_NAME_LENGTH   512

Definition at line 39 of file dot.c.

Referenced by initDot().

Function Documentation

◆ dotPreamble()

void dotPreamble ( FILE *  out,
const char *  graph_name,
const char *  initial_comment 
)

Writes the first part of a dot file to the output stream: comments about how the graph was created and seed information

Definition at line 210 of file dot.c.

Referenced by outputEdge(), and writeDot().

◆ endDot()

void endDot ( FILE *  out)

Writes the final '}'

Definition at line 217 of file dot.c.

Referenced by outputEdge(), and writeDot().

◆ error()

static void error ( bool  fatal)
static

Prints the message in 'error_message' with the line number

Parameters
fatalif true, program will exit (fatal error)

Definition at line 51 of file dot.c.

References error_message, and line_number.

Referenced by initDot(), and nextEdge().

◆ getNameFromDotFile()

void getNameFromDotFile ( char *  buffer)

Stores the name of the graph in the given buffer. Assumes the buffer is large enough.

Definition at line 167 of file dot.c.

References graph_name.

Referenced by allocateAdjacencyLists().

◆ initDot()

void initDot ( FILE *  in)

Stores information about the dot file and advances the input to the point where edges can be read. NOTE: information in an initial comment is lost

Todo:
eventually will want to pick up the first comment

Definition at line 144 of file dot.c.

References error(), error_message, graph_name, MAX_NAME_LENGTH, and skip_blanks_and_comments().

Referenced by allocateAdjacencyLists(), createEdges(), and outputEdge().

Here is the call graph for this function:

◆ nextEdge()

bool nextEdge ( FILE *  in,
char *  source_buffer,
char *  destination_buffer 
)

Reads the next edge from the input, storing the names of the vertices in buffers. Assumes the buffers are large enough.

Returns
true if another edge was found.

Definition at line 172 of file dot.c.

References error(), error_message, read_identifier(), and skip_blanks_and_comments().

Referenced by allocateAdjacencyLists(), createEdges(), and outputEdge().

Here is the call graph for this function:

◆ outputEdge()

void outputEdge ( FILE *  out,
const char *  src,
const char *  dst 
)

Writes the edge (src, dst) to the output

Definition at line 222 of file dot.c.

References dotPreamble(), endDot(), initDot(), main(), nextEdge(), and outputEdge().

Referenced by outputEdge(), and writeDot().

Here is the call graph for this function:

◆ read_identifier()

static char read_identifier ( int  ch,
FILE *  in,
char *  id_buf 
)
static

Reads an identifier from the input stream into the buffer

Parameters
chthe beginning of the identifier
Returns
the character after the identifier

Definition at line 131 of file dot.c.

Referenced by nextEdge().

◆ skip_blanks_and_comments()

static int skip_blanks_and_comments ( int  ch,
FILE *  in_stream 
)
static

Skips blanks and comments in the input stream using a finite-state machine. Also updates the line number when appropriate.

Parameters
chthe starting character for the sequence, as provided by the client
Returns
the character that ends the sequence of blanks and comments, to be used by the client

Definition at line 65 of file dot.c.

References line_number, and state.

Referenced by initDot(), and nextEdge().

Variable Documentation

◆ error_message

char error_message[MAX_MSG_LENGTH]
static

Definition at line 41 of file dot.c.

Referenced by error(), initDot(), and nextEdge().

◆ graph_name

◆ line_number

int line_number = 1
static

Definition at line 43 of file dot.c.

Referenced by error(), and skip_blanks_and_comments().