/* Copyright (c) 2001 by SoftIntegration, Inc. All Rights Reserved */

#include <stdio.h>
#include <unistd.h>
string_t startupfile, startupfilesrc;
string_t display = "type",
         hello = "hello.c",
         contourLevels_2= "contourLevels_2.ch",
         getSubplot = "getSubplot.ch",
         svd = "svd.ch",
         odesolve_2 = "odesolve_2.ch";
int i;

#ifdef _WIN32_
if(strlen(_home)==3 &&  *(*((char **)&_home)+1)==':')  /* C:\ */
  startupfile = "_chrc";
else 
  startupfile="/_chrc";
startupfilesrc = stradd(getenv("CHHOME"), "/config/_chrc");
#else
if(strlen(_home)==1) /* root / */
  startupfile=".chrc";
else 
  startupfile="/.chrc";
startupfilesrc = stradd(getenv("CHHOME"), "/config/.chrc");
display="more";
hello=stradd("./", hello);
contourLevels_2=stradd("./", contourLevels_2);
getSubplot=stradd("./", getSubplot);
svd=stradd("./", svd);
odesolve_2=stradd("./", odesolve_2);
#endif


fprintf stdout << ENDFILE

You can type the following commands in 
a Ch language environment to see how Ch works 
interactively in command mode.

(1) Type "ch -d" to copy sample startup file $(startupfilesrc) 
to your home directory $_home. Then,
you can customize the Ch language environment 
by modifying file $_home$(startupfile).
Read $(getenv("CHHOME"))/config/README for more information 
about Ch startup configuration files.

(2) Execute Unix or Windows commands

ls

(3) Use Ch as a calculator

2+3*4
sqrt(4)
56*85.5-sin(1.5)

(4) Learn C/C++ features

int i, *p, **p2
i =12
p = &i
*p
p2 = &p
**p2
printf("i = %d\n", i)
printf("i = %x\n", i)
printf("i = %b\n", i)

cout << "Type in a number for i"
cin  >> i
cout << i
i

(5) class/struct

struct cube{int i, j; float f;} c1 = {1,2,3}
c1
sizeof(c1)
struct cube c2
c2 = c1
c2
cube c3
c3
c3.i = 10
c3
2*c3.i
struct cube *cptr
cptr = &c3
cptr->i

(6) Union
union tag {int i; double d;} m
m.i = 10
m
m.d = 10
m
sizeof(m)

(7) Run C programs 
cd $(getenv("CHHOME"))/demos/bin
$(hello)
ls hello.c
$display hello.c


(8) Aliases can be added in $_home$(startupfile)

alias cool "echo Ch is cool!"
alias cool
cool
unalias cool
cool
alias("mydir", "cd $_home")
mydir
pwd
alias


(9) Use Ch as a script

cd $(getenv("CHHOME"))/bin
ls help.ch
$display help.ch

(10) Check commands 

which ls
which help
which int
which public
which which
which  -a ls
which PATH stdio
which -a PATH stdio

(11) Complex numbers 

complex z = complex(3, 4)
z+z
2*z
sin(z)
abs(z)

(12) Array bounds are checked 
to prevent memory corruption

double a[3] = {1, 2, 3}
a[0]
a[1]
a[2]
a[-1]
a[3]

(13) The range of array subscripts can be adjusted

double b[1:3] = {10, 20, 30}
b[1]
b[3]
b[0]

ENDFILE

i=13;

if(strcmp(_Chedition, "Standard")) {
fprintf stdout << ENDFILE
(14) Computational array for matrix and linear algebra
array double d[3][3]={1,1,1, 3,1,2, 10,11,12}
d
d+d
2*d
sin(d)
2*sin(d)

array double l[3][3], u[3][3]
ludecomp(d, l, u)
l
u
l*u
qrdecomp(d, l, u)
l
u
l*u
transpose(d)
d*inverse(d)
inverse(d)*d

(15) Plotting.

array double x[30], y[30]
linspace(x, -3.14, 3.14)
x
y = sin(x)
plotxy(x, y)
plotxy(x, sin(x))
plotxy(x, x)
plotxy(x, x.*x)
plotxy(x, x.*x.*x)
cd $(getenv("CHHOME"))/demos/lib/libch/plot/ref
$contourLevels_2
$getSubplot

(16) Scientific numerical computing.

cd $(getenv("CHHOME"))/demos/lib/libch/numeric
$svd
$odesolve_2

ENDFILE

i=16;
} /* if(strcmp(_Chedition, "Standard"))  */

if(!access(stradd(getenv("CHHOME"), "/toolkit/demos/OpenGL/glut"), R_OK)) {
fprintf stdout << ENDFILE
($(++i)) 3D graphics and animation using OpenGL.
cd $(getenv("CHHOME"))/toolkit/demos/OpenGL/glut
./gears.c
./reflect.c

ENDFILE
}

if(!access(stradd(getenv("CHHOME"), "/toolkit/demos/GTK/gtk/buttons"), R_OK)) {
fprintf stdout << ENDFILE
($(++i)) Graphical user interface using GTK+.
cd $(getenv("CHHOME"))/toolkit/demos/GTK/gtk/buttons
./buttons.c

ENDFILE
}

if(!access(stradd(getenv("CHHOME"), "/toolkit/demos/Windows/poppad"), R_OK)) {
fprintf stdout << ENDFILE
($(++i)) Graphical user interface using Windows API
cd $(getenv("CHHOME"))/toolkit/demos/Windows
DialogboxIndirect.ch
cd $(getenv("CHHOME"))/toolkit/demos/Windows/poppad
poppad.ch
ENDFILE

}

if(!access(stradd(getenv("CHHOME"), "/toolkit/demos/X11/motif/ch10"), R_OK)) {
fprintf stdout << ENDFILE
($(++i)) Graphical user interface using X/Motif
cd $(getenv("CHHOME"))/toolkit/demos/X11/motif/ch10/color_draw.c
./color_draw.c
ENDFILE

}
