Logo Search packages:      
Sourcecode: lbt version File versions  Download package

int main ( int  argc,
char **  argv 
)

The main program

Parameters:
argc number of command-line arguments
argv the command-line arguments

State counter

Generic number

a character

separator between acceptance set entries

the state number

Definition at line 71 of file lbt2dot.c.

References parseGate().

{
  /** State counter */
  unsigned i;
  /** Generic number */
  unsigned num;
  /** a character */
  int ch;

  if (2 != fscanf (stdin, "%u%u", &i, &num)) {
  parseError:
    fputs ("error in automaton\n", stderr);
  semanticError:
    return 1;
  }

  fputs ("digraph g {\n", stdout);

  while (i--) {
    /** separator between acceptance set entries */
    const char* separator = "\\n";
    /** the state number */
    unsigned state;
    /* read the state number and "initial state" flag */
    if (2 != fscanf (stdin, "%u%u", &state, &num) || num > 1)
      goto parseError;
    fprintf (stdout, "%u", state);
    fputs ("[", stdout);
    if (num) /* initial state */
      fputs ("style=filled,", stdout);
    fprintf (stdout, "label=\"%u", state);

    /* acceptance sets that the state belongs to */
    for (;;) {
      while (isspace (ch = fgetc (stdin)));
      if (ch == '-') {
      if (1 != fscanf (stdin, "%u", &num) || 1 != num) {
        fputs ("unexpected data after '-'\n", stderr);
        goto semanticError;
      }
      break;
      }
      ungetc (ch, stdin);
      if (!isdigit (ch) || 1 != fscanf (stdin, "%u", &num))
      goto parseError;
      fprintf (stdout, "%s%u", separator, num);
      separator = ",";
    }

    fputs ("\"];\n", stdout);

    /* transitions */
    for (;;) {
      while (isspace (ch = fgetc (stdin)));
      if (ch == '-') {
      if (1 != fscanf (stdin, "%u", &num) || 1 != num) {
        fputs ("unexpected data after '-'\n", stderr);
        goto semanticError;
      }
      break;
      }
      ungetc (ch, stdin);
      if (!isdigit (ch) || 1 != fscanf (stdin, "%u", &num))
      goto parseError;
      fprintf (stdout, "%u->%u[label=\"", state, num);
      if (parseGate ())
      goto parseError;
      fputs ("\"];\n", stdout);
    }
  }

  fputs ("}\n", stdout);

  while (isspace (ch = fgetc (stdin)));

  if (ch != EOF) {
    fputs ("extraneous non-whitespace data at end of input\n", stderr);
    goto semanticError;
  }

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index