File: mglview.cpp

package info (click to toggle)
mathgl 1.9-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 17,496 kB
  • ctags: 3,647
  • sloc: cpp: 36,386; sh: 10,198; ansic: 1,093; makefile: 325; pascal: 52; python: 35
file content (83 lines) | stat: -rw-r--r-- 3,125 bytes parent folder | download | duplicates (2)
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
/***************************************************************************
 * mglview.cpp is part of Math Graphic Library
 * Copyright (C) 2007 Alexey Balakin <balakin@appl.sci-nnov.ru>            *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include "mgl/mgl_fltk.h"
#include "mgl/mgl_parse.h"
//-----------------------------------------------------------------------------
char fname[256];
mglParse p(true);
char str[8192];
char buf[2048];
//-----------------------------------------------------------------------------
int show(mglGraph *gr, void *)
{
	FILE *fp = fopen(fname,"rb");
	p.Execute(gr, fp, true);
	fclose(fp);
	return 0;
}
//-----------------------------------------------------------------------------
int main(int narg, char **arg)
{
	mglGraphFLTK gr;

	if(narg==1)
	{
		printf("mglview show MGL script in FLTK window.\n");
		printf("Current version is 1.%g\n",MGL_VERSION);
		printf("Usage:\tmglview scriptfile [parameter(s)]\n");
		printf("\tParameters have format \"-Nval\".\n");
		printf("\tHere N=0,1...9 is parameter ID and val is its value.\n");
		printf("\tOption -Lval set locale to val.\n");
	}
	else
	{
		FILE *fp = fopen(arg[1],"rb");
		if(fp==0)	printf("Couldn't open file %s\n",arg[1]);
		else
		{
			register long i,j;
			for(i=2;i<narg;i++)	// add arguments for the script
			{
				if(arg[i][0]=='-' && arg[i][1]>='0' && arg[i][1]<='9')
				{	p.AddParam(arg[i][1]-'0',arg[i]+2);	arg[i][0]=0;	}
				if(arg[i][0]=='-' && arg[i][1]=='L')
				{	setlocale(LC_CTYPE, arg[i]+2);		arg[i][0]=0;	}
			}
			strncpy(fname,arg[1],256);
			fclose(fp);
			arg[1][0] = 0;
			for(i=narg-1;i>=0;i--)
			{
				if(arg[i][0]==0)
				{
					for(j=i;j<narg-1;j++)	arg[j] = arg[j+1];
					narg--;
				}
			}
			gr.Window(narg,arg,show,fname);
			return mglFlRun();
		}
	}
	return 0;
}
//-----------------------------------------------------------------------------