File: main.c

package info (click to toggle)
eukleides 0.9.2-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 452 kB
  • ctags: 270
  • sloc: ansic: 1,934; yacc: 796; lex: 499; makefile: 101; sh: 61
file content (121 lines) | stat: -rw-r--r-- 2,763 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 *  Eukleides  version 0.9.2
 *  Copyright (c) Christian Obrecht 2000-2002
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <stdlib.h>

char *buffer;

int filter = 0, lineno = 1, first = 1, inputmode = 1;

extern int yyparse (void);

void usage (int code)
{
    printf
	("Usage is:\n\teukleides [ -v | -h ]\n\teukleides [ -f ] <filename>\n"
	 "Options:\n\t-v\tPrint version number.\n\t-h\tPrint this help.\n"
	 "\t-f\tRun as a filter.\nSee man page for more informations.\n");
    exit (code);
}

void version (void)
{
    printf ("This is eukleides version 0.9.2\n"
	    "Copyright (c) Christian Obrecht 2000-2002\n");
    exit (0);
}

void warning (char *msg)
{
    fprintf (stderr, "Warning at line %i: %s\n", lineno, msg);
}

void yyerror (char *msg)
{
    fprintf (stderr, "Error at line %i: %s\n", lineno, msg);
    exit (1);
}

void parser (char *file_name)
{
    FILE *file;
    int size, number, file_length;

    file = fopen (file_name, "r");
    if (!file) {
	  fprintf (stderr, "Could not open %s\n", file_name);
	  exit (1);
    }

    file_length = 0;
    size = 1024;
    number = 1024;
    buffer = (char *) malloc (size);
    while (number == 1024) {
	  number = fread (buffer + file_length, 1, 1024, file);
	  file_length += number;
	  if (size == file_length) {
		size *= 2;
		buffer = (char *) realloc (buffer, size);
	  }
    }
    fclose (file);

    if (!filter)
	printf ("%% Generated by eukleides 0.9.2\n"
		"\\psset{linecolor=black, linewidth=.5pt, arrowsize=2pt 4}\n");
    yyparse ();
    if (!filter)
	printf ("\\endpspicture\n");
    exit (0);
}

int main (int argc, char **argv)
{
    switch (argc)
      {
      case 1:
	  usage (0);

      case 2:
	  if (argv[1][0] == '-') {
		if (argv[1][1] == 'v')
		    version ();
		else if (argv[1][1] == 'h')
		    usage (0);
		else
		    usage (1);
	  }
	  else
	      parser (argv[1]);

      case 3:
	  if ((argv[1][0] == '-') && (argv[1][1] == 'f')) {
		filter = 1;
		inputmode = 0;
		parser (argv[2]);
	  }
	  else
	      usage (1);
      default:
	  usage (1);
      }
    return 0;
}