Back to index

texmacs  1.0.7.15
Defines | Functions | Variables
tm_graphviz.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define DATA_BEGIN   ((char) 2)
#define DATA_END   ((char) 5)
#define DATA_ESCAPE   ((char) 27)

Functions

void next_input ()
void read_input ()
char * readfile (FILE *fp)
void run_dotty (char *input, char **output, char **errors)
void build_input ()
int main ()

Variables

static int counter = 0
static int buffer_len = 4096
static char buffer [4096]

Define Documentation

#define DATA_BEGIN   ((char) 2)

Definition at line 21 of file tm_graphviz.c.

#define DATA_END   ((char) 5)

Definition at line 22 of file tm_graphviz.c.

#define DATA_ESCAPE   ((char) 27)

Definition at line 23 of file tm_graphviz.c.


Function Documentation

void build_input ( )

Definition at line 99 of file tm_graphviz.c.

               {
  FILE *foutp = fopen ("dotty.tmp.in", "a");
  fprintf (foutp, "%s", buffer);
  fclose (foutp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( )

Definition at line 106 of file tm_graphviz.c.

        {
  printf ("%cverbatim:", DATA_BEGIN);
  printf ("Welcome to a simple TeXmacs interface to Graphviz/dot\n");
  printf ("(C) 2002 Jorik Blaas and Joris van der Hoeven\n");
  next_input ();
  printf ("%c", DATA_END);
  fflush (stdout);

  while (!feof (stdin)) {
    char * out;
    char * err;

    read_input ();
    if (strcmp (buffer, "quit") == 0) break;

    printf ("%cps:", DATA_BEGIN);
    run_dotty (buffer, &out, &err);
    build_input ();
    printf ("%s", out);
    free (out);
    if (strlen(err)>0)
    {
      printf ("%cverbatim:", DATA_BEGIN);
      printf ("\nErrors: %s\n", err);
    }
    free(err);
    printf ("%c\n", DATA_END);

    next_input ();
    printf ("%c", DATA_END);
    fflush (stdout);
  }
  return 0;
}

Here is the call graph for this function:

void next_input ( )

Definition at line 30 of file tm_graphviz.c.

              {
  counter++;
  printf ("%cchannel:prompt%c", DATA_BEGIN, DATA_END);
  printf ("Graphviz %d] ", counter);
}

Here is the caller graph for this function:

void read_input ( )

Definition at line 37 of file tm_graphviz.c.

              {
  int i;
  for (i=0; i<buffer_len-1; i++) {
    buffer[i]= fgetc (stdin);
    if (buffer[i] == '\n') break;
  }
  buffer[i]='\0';
}

Here is the caller graph for this function:

char* readfile ( FILE *  fp)

Definition at line 62 of file tm_graphviz.c.

                      {
  char * buf = (char*)malloc(1025);
  char *wbuf = buf;
  int buflen=1025;

  while(!feof(fp))
  {
    int br = fread( wbuf, 1, 1024, fp );
    if(br==-1 || br==0)
       break;
    wbuf += br;
    buflen+=1024;
    buf = (char*)realloc( buf, buflen );
  }
  *wbuf='\0';
  return buf;
}

Here is the caller graph for this function:

void run_dotty ( char *  input,
char **  output,
char **  errors 
)

Definition at line 82 of file tm_graphviz.c.

                                                          {
  FILE *wfp, *fp, *efp;

  wfp = fopen("dotty.tmp.dot", "w");
  fprintf(wfp, "%s", input );
  fclose(wfp);

  fp = popen( "dot -Tps dotty.tmp.dot 2>dotty.tmp.err", "r" );
  *output = readfile(fp);
  fclose(fp);

  efp = fopen("dotty.tmp.err","r");
  *errors = readfile(efp);
  fclose(efp); 
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char buffer[4096] [static]

Definition at line 27 of file tm_graphviz.c.

int buffer_len = 4096 [static]

Definition at line 26 of file tm_graphviz.c.

int counter = 0 [static]

Definition at line 25 of file tm_graphviz.c.