home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CMAGIC.ZIP
/
MAGIC.2
< prev
next >
Wrap
Text File
|
1992-09-06
|
60KB
|
1,524 lines
Continued from MAGIC.TXT
*************************************************************
void getinfile(void) - function
Usage: getinfile()
Description:
This function merely checks the validity of a file for
input (into the program) using the string, "infilename[50]"
as the file name, and opens the file for input. If the file
does not exist, or cannot be opened, then the global char
variable "problem" is set to a number greater than 0. If
successful, problem = 0.
Considerations:
Infile is opened as a binary file, conversions to strings
are handled automatically by Magic. The default for
infilename is "INPUT."
See Also:
getoutfile(), nameinfile(), fileread(), filereadln()
infilename
Example:
#include<magic.h>
void main(){
magic_setup();
nameinfile("testfile.1");
getinfile();
if (problem > 0) printf("Problem with testfile.1");
waitforuser();
}
Performance of example:
Program checks to see if a disk file named "testfile.1" can
be opened for reading. If not, "Problem with testfile.1" is
printed to screen.
*************************************************************
void getoutfile(void) - function
Usage: getoutfile()
Description:
This function merely checks the validity of a file for
output (to disk) using the string, "outfilename[50]" as the
file name, and opens the file for output. If the file cannot
be opened, then the global char variable "problem" is set to
a number greater than 0. If successful, problem = 0.
Considerations:
Outfile is opened as a binary file. Conversions to
strings are handled automatically by Magic file functions.
If file already exists, it is opened for appending. If it
does not exist, it is created. The default for outfilename is
"OUTPUT."
See Also:
getinfile(), nameoutfile(), filewrite(), filewriteln()
outfilename
Example:
#include<magic.h>
void main(){
magic_setup();
nameoutfile("testfile.1");
getoutfile();
if (problem > 0) printf("Problem with testfile.1");
waitforuser();
}
Performance of example:
Program checks to see if a disk file named "testfile.1" can
be opened for writing. If not, "Problem with testfile.1" is
printed to screen.
*************************************************************
char getvmode(void) - function
Usage: x = getvmode()
Description:
This function returns the current video mode as per the
following chart:
if getvmode = 0 then current video = 80 x 25 text
if getvmode = 1 then current video = CGA 640 x 200 2-color
if getvmode = 2 then current video = CGA 320 x 200 4-color
if getvmode = 3 then current video = EGA-lo 640 x 200 16-color
if getvmode = 4 then current video = EGA 640 x 350 16-color
if getvmode = 5 then current video = Hercules Monochrome
if getvmode = 6 then current video = VGA 640 x 480 16-color
if getvmode = 7 then current video = VGA 320 x 200 256-color
Considerations:
This will work whether or not the Borland/Turbo graphics
function "initgraph() was used to initialize the graphics
mode.
See Also:
initgraph(), setgraphmode(), getgraphmode() {Borland}
Example:
#include <magic.h>
void main() {
magic_setup();
.
.
if (getvmode == 2) pile("We are in CGA 4-color mode");
if (getvmode == 0) pile("We are in text mode");
getanykey(-1,-1);
}
Performance of example:
The example shows the user what video mode is in operation if
the current mode is CGA 4-color or text mode.
*************************************************************
void getyn(int x, int y) - function
Usage: getyn(x,y)
Description:
A message pops up on the screen then waits for the user
to press 'Y' or 'N' or click a mouse button. You must write
strings for the array of sent[]s before calling this
procedure. After the user presses a key, all traces of the
pop-up and the sent[]s disappear.
Getyn() requires two integer variables, the first
determines the horizontal position on the screen, and the
second is the vertical coordinate. If either number is
negative, the pop-up message will be centered on the screen
in the corresponding dimension.
Getyn() sets the global unsigned char, to 'Y' or 'N'.
Considerations:
Maximum sent array size: 18. Make sure to add something to
this effect to every message to avoid confusing your users:
"Press [Y] or [N]..." getyn() is not case sensitive. The
user can type upper or lower case [y] or [n]. If the left
mouse button is clicked answer is set to 'Y' and if the right
mouse button is clicked answer = 'N'. The character returned
to "u" is always capitalized.
There is a limit to the maximum size of a getyn() box.
For instance, in VGA-HI graphics mode, the limit is about 20
lines of text with the longest line being about 40 characters
long.
See Also: menu(), pop(), dialog(), getyn(), sent[], u.
Example:
#include <magic.h>
void main () {
magic_setup();
.
.
pile("Exit to Dos? (Y/N)");
getyn(-1,1);
if (u == 'Y') cleanup();
.
.
}
Performance of example:
A box pops up on the screen containing one line and waits
for the user to press a key. Until the key pressed is upper
or lower case 'Y' or 'N', or until the user clicks a mouse
button, the box remains. Then the global char u is set to 'Y'
or 'N.' If answer = 'Y' then the program terminates cleanly.
*************************************************************
void gothic(void) - function
Usage: gothic()
Description:
This function causes outtext() and outtextxy() to generate
text in the "gothic" stroked font.
Considerations:
GOTH.CHR is linked into .EXE file and RAM usage and disk
space requirements increase.
See Also:
triplex(), little(), bold(), sansserif(), script(),
italic(), complex(), simple(), bitmap(), european()
Example:
#include <magic.h>
#include <graphics.h>
void main(){
magic_setup();
bestvideo();
gothic();
outtextxy(0,0,"Gothic font");
waitforuser();
cleanup();
}
Performance of example:
Program writes "Gothic font" on screen using the "gothic"
font.
*************************************************************
void hercvideo(void) - function
Usage: hercvideo()
Description:
This initializes the system in Hercules graphics mode.
Hercules video driver will be automatically compiled into the
.EXE program file, eliminating the need for external HERC.BGI
file. Program will use 719 x 348 resolution, monochrome.
Considerations:
Will not work on CGA or EGA-equipped computers. Graphmode is
initially set to 0 (see Borland manual for more details).
See Also:
bestvideo(), cgalovideo(), cgahivideo(), egahivideo(),
egalovideo(), vgahivideo(), vgalovideo(), textvideo(),
cleanup() {Magic} setgraphmode() {Borland}
Example:
#include <magic.h>
#include <graphics.h>
void main() {
magic_setup();
hercvideo();
rectangle(10,10,709,337);
waitforuser();
cleanup();
}
Performance of example: The system is put in Hercules
graphics mode. A large rectangle is displayed until any key
is pressed. The program then terminates gracefully.
*************************************************************
void hidecursor(void) - function
Usage: hidecursor()
Description:
This makes the text cursor disappear until it is moved to
another screen location. Generally, use it after writing to
the screen when the user is not expected to type input.
Considerations:
For text mode only, has no effect in graphics.
Hidecursor() is called automatically by getanykey(),
getyn(), pop() and menu().
See Also: bigcursor(), littlecursor()
Example:
#include <magic.h>
#include <stdio.h>
void main() {
magic_setup();
printf("There is no cursor at the end of this line.");
hidecursor();
waitforuser();
}
Performance of example:
A line of text appears on the screen, but there is no
cursor at the end of the line.
*************************************************************
char holdingmouse - Global Variable
Usage: This is used internally by Magic.lib. Direct
manipulation is not recommended, but you can test this
variable to see if a mouse pointer is currently being
displayed.
Description:
This variable can be checked to see if a mouse pointer
(arrow) is currently being displayed. When holdingmouse is
greater than 0, a mouse pointer is being handled.
Considerations:
Do not change this variable. Results would be unpredictable.
*************************************************************
void holdon(void) - function
Usage: holdon()
Description:
Holdon() stalls any further action until the user presses
any key or clicks a mouse button. This function is identical
to waitforuser().
Considerations:
See Also:
waitforuser()
Example:
#include <magic.h>
void main() {
magic_setup();
pile("Test");
pop(-1,-1);
holdon();
restore();
}
Performance of example:
A single string appears in a text box. Instead of
quitting immediately, the program waits until holdon() has
been satisfied with a keypress or a mouse click.
*************************************************************
int howlong - Global Variable
Usage: /* example */ x = howlong
Description
Howlong is a global int variable used by Magic to keep
track of the length of the longest string within the global
char array, "sent[]". Use the function, figurehowlong() to
update howlong.
Howlong counts the number of characters in the string if
in text mode, but in a graphics mode, it contains the number
of pixels to display the longest string in the currently
selected graphics mode, font and horizontal font
magnification.
Considerations:
Although you can directly change this variable, in most
cases, you should use it only for testing, and leave the
automatic string handling to the inner workings of the Magic
library.
See Also:
howmany, figurehowlong(), figurehowmany(), clearsents()
Example:
see figurehowlong()
*************************************************************
int howmany - Global Variable
Usage: /* example */ y = howmany
Description
Howmany is a global int variable used by Magic to keep
track of the number of strings containing text within the
char array, "sent[]". Use the function, figurehowlong() to
update howlong.
Considerations:
See figurehowmany() for more details.
See Also:
howlong, figurehowlong(), figurehowmany(), clearsents()
Example:
see figurehowmany()
*************************************************************
file* infile - Global Variable
Usage: /* example */ fopen(infile,"Things.Doc","wt")
Description:
Infile is declared globally as a file pointer. It is most
often used for importing information into your program with
the automatic procedures fileread() and filereadln(). The
default string assigned to infile as the name under which it
is read from disk is "INPUT", but this can be changed with
nameinfile().
Considerations:
You can override the automatic use of infile in Magic with
standard Borland/Turbo C techniques such as fopen() fclose(),
fprintf() and fscanf(). Infile is handled as a binary file.
Conversions to strings are made automatically by the Magic
functions.
See Also:
fileread(), filereadln(), nameinfile(), outfile() {Magic};
Also all file handling functions {Borland manuals}
Example:
#include <magic.h>
void main() {
magic_setup();
nameinfile("TESTFILE.TXT");
filereadln();
.
.
fclose(infile);
nameinfile("TESTFILE.2");
filereadln();
.
.
}
Performance of example:
Nameinfile() is used to cause infile to be called
"TESTFILE.TXT" when referenced on disk. A line of text is
read from it, then infile is closed. Infile is renamed
"TESTFILE.2" and another line of text is read from infile,
but infile is actually a different file on the disk.
*************************************************************
char infilename[50] - Global Variable
Usage: /* example */ strcpy(infilename,"testfile.1")
Description:
Infilename is an array of 50 characters used to hold a
string for identifying INFILE (see above). Standard
string character array procedures may be used to manipulate
infilename. This is the string getinfile(), nameinfile(),
fileread() and filereadln() use to identify infile.
Considerations:
The default for infilename is "INPUT." Normally,
nameinfile() is used to change infilename.
Example:
#include <magic.h>
#include <string.h>
void main() {
.
.
if (strlen(infilename)) < 4)
printf("We have a very short file name");
.
.
}
Performance of example:
If infilename is less than 4 characters long then the
program prints, "We have a very short file name."
*************************************************************
void italic(void) - function
Usage: italic()
Description:
This function causes outtext() and outtextxy() to generate
text in the "italic" stroked font.
Considerations:
TSCR.CHR is linked into .EXE file and RAM usage and disk
space requirements increase. This font will not work with
older versions of Borland compilers.
See Also:
triplex(), little(), gothic(), sansserif(), script(),
bold(), complex(), simple(), bitmap(), european()
Example:
#include <magic.h>
#include <graphics.h>
void main(){
magic_setup();
bestvideo();
italic();
outtextxy(0,0,"Italic font");
waitforuser();
cleanup();
}
Performance of example:
Program writes "Italic font" on screen using the "italic"
font.
*************************************************************
char keydetect - Global Variable
Usage: /* example */ if (keydetect == 2) printf("extended key")
Description:
This global char variable is updated every time the
Magic library checks for mouse action or a keypress. In
addition to updating the global unsigned char variable u,
which will contain the direct results of the key press,
keydetect is updated. If keydetect is 0, a mouse key was
pressed, or no action has occurred. If keydetect is 1 a
normal, alphanumeric key has been pressed. If keydetect is 2
then a function key was pressed.
Considerations:
See poll() for more details.
See Also:
poll(), xreadkey(), u
Example:
see poll();
*************************************************************
char left - Global Variable
Usage: /* example */ if (left) break;
Description:
Left is a global char variable used to record the status
of the left mouse button. If left = 1 then the left mouse
button has been pressed, otherwise left = 0.
Considerations:
The status of left will change with every call to poll(),
waste(), resetmouse() or procedures within Magic which handle
text or pop up boxes.
See Also: poll(), waste(), ResetMouse(), center, right
Example:
#include <magic.h>
void main() {
magic_setup();
waste();
pile("Nothing will change until you click the");
pile("left mouse button");
pop(-1,-1);
do poll; while (!left);
}
Performance of example:
A box containing two lines of text will stay on the screen
until the user clicks the left mouse button. The program
will then terminate.
*************************************************************
void little(void) - function
Usage: little()
Description:
This function causes outtext() and outtextxy() to generate
text in the "little" stroked font.
Considerations:
LITT.CHR is linked into .EXE file and RAM usage and disk
space requirements increase.
See Also:
triplex(), bold(), gothic(), sansserif(), script(),
italic(), complex(), simple(), bitmap(), european()
Example:
#include <magic.h>
#include <graphics.h>
void main(){
magic_setup();
bestvideo();
little();
outtextxy(0,0,"Little font");
waitforuser();
cleanup();
}
Performance of example:
Program writes "Little font" on screen using the "little"
font.
*************************************************************
void littlecursor(void) - function
Usage: littlecursor()
Description:
After a call to littlecursor(), the cursor in text mode will
be a standard underline (DOS default cursor). This is used in
programs after a call to hidecursor() or bigcursor().
Considerations:
Has no effect in graphics modes, but will resume as a
small cursor when returned to text mode.
See Also:
bigcursor(), hidecursor()
Example:
#include <magic.h>
void main(){
magic_setup();
littlecursor();
printf("Little underline cursor at the end of this line!");
}
Performance of Example:
This program will write 'Little underline cursor at the end
of this line', then quit.
*************************************************************
void magic_setup(void) - function
Usage: magic_setup()
Description:
This function should be called once in every program
which uses anything from the Magic library. It initializes
variables and sets up "links" to functions in the Magic
library.
Considerations:
Use of any Magic functions without calling magic_setup()
within the program will have unpredictable results. Do not
call magic_setup() twice in one program.
Example:
#include <magic.h>
void main(){
magic_setup();
.
.
Performance of example:
The above program is prepared for whatever you want to do
with the Magic library.
*************************************************************
void makemouse(void) - function
Usage: This is for internal use of the Magic Library. Do not
use this function independently.
Description:
This actually draws the mouse arrow on the screen.
Considerations:
Has no effect in text mode. Works with or without a
mouse actually being present. Mouse cursor shape can be
easily customized if you have purchased the source code.
*************************************************************
char mainback - Global Variable
Usage: mainback = color;
Description:
Color is represented with an integer from 0 to 15 or a
pre-defined color constant enumerated in CONIO.H or
GRAPHICS.H. Changing the value of mainback will affect the
main screen background color.
Considerations:
Do not use background colors above 7 in text mode. May not
have the expected effect when used with the limited palettes
of 4-color CGA (mode 0,1 or 2), 2-color CGA or Hercules. To
see effect after changing mainback, call xclear().
See Also:
boxback, maintext, boxtext, barback, bartext.
Example:
#include <magic.h>
#include <conio.h>
void main() {
magic_setup();
mainback := GREEN;
xclear();
pile("Do you like this background color?");
getanykey(-1,-1);
}
Performance of example:
The main background color is set to green. A box will appear
on the screen asking a silly question. The main background
will be green. When a key is pressed, the program quits.
*************************************************************
char maintext - Global Variable
Usage: maintext = color;
Description:
Color is represented with an integer from 0 to 15 or a
pre-defined color constant enumerated in CONIO.H or
GRAPHICS.H. Changing the value of maintext will affect the
color of text printed outside of pop-up boxes.
Considerations:
May not have the expected effect when used with the limited
palettes of 4-color CGA (mode 0,1 or 2), 2-color CGA or
Hercules. No Magic functions actually use this variable, but
you can use it yourself with cprintf() and gotoxy() to write
text outside of pop-ups.
See Also:
boxback, mainback, boxtext, barback, bartext.
Example:
#include <magic.h>
#include <conio.h>
void main() {
magic_setup();
xclear();
maintext := YELLOW;
gotoxy(42,7);
cprintf("Do you like this background color?");
waitforuser();
}
Performance of example:
The main background color is cleared to the default color of
blue. A line of text appears in yellow.
*************************************************************
char mc - Global Variable
Usage: /* example */ if (mc == 2){..}
Description:
Mc is a global char variable used to keep track of menu
item selection. See menu() for more details.
*************************************************************
char *mem - Global Variable
Usage: For internal use by the Magic library only. Do not
manipulate directly.
Description: Mem is used to point to the starting address of
the graphics video RAM.
*************************************************************
void menu(int x, int y) - function
Usage: menu(x,y);
Description:
Menu() pops a box on the screen showing lines of text
from the array sent[81][46]. One of the lines is highlighted
and a user can move the highlight to any of the other items
by moving the mouse or pressing the up or down arrow keys.
When the user presses [Enter] or clicks the left mouse
button, or presses any alphanumeric key, the currently
highlighted item number is assigned to the global char
variable mc. Also, the key pressed will be assigned to the
char global variable "u". The pop-up box disappears and the
array of strings (sent[81][46]) is cleared.
Two integer parameters are required, the first indicates
the horizontal position of the upper left corner and the
second is for the vertical position. If either integer is a
negative number, that integer will be ignored and the menu
will be centered on the screen in the corresponding
dimension.
Before calling menu(), a global char variable, "mc" should
be given a value. "Mc" is the current MenuChoice, meaning
the sent[] corresponding to mc is the one highlighted. If
you state: mc = 1 then the first item on the menu will be
highlighted. If you forget to assign mc, a random menu
choice will be highlighted with your first call to menu().
You can then use u or mc to perform operations related to
your user's choice.
Because when menu() is done, the sent[]s are all cleared,
to have the menu return to the screen, sent[]s must be
refilled with your strings and menu() must be called again.
The usual way to use menu() is to put it into a repeat loop
as shown in the example below.
If the left mouse button is clicked u = 13. If the right
mouse button is clicked u = 27. Also, if user presses
[Enter] left = 1, and if [Esc] right = 1.
Considerations:
Maximum sent[]s = 18; Should assign a value to mc of at
least one and less than the maximum sent[] used. Must
reassign text to the sent[]s for subsequent calls to menu().
In text mode, do not use background colors above 7.
There is a limit to the maximum size of a menu() box. For
instance, in VGA-HI graphics mode, the limit is about 20
lines of text with the longest line being about 40 characters
long.
See also: sent[], pop(), getyn(), getanykey()
Example:
#include <magic.h>
#include <string.h>
#include <ctype.h>
void main() {
magic_setup();
mc = 1;
do
strcpy(sent[1],"Do Thing One");
strcpy(sent[2],"Do Thing Two");
strcpy(sent[3],"Do Thing tHree");
strcpy(sent[4],"Do Thing Four");
strcpy(sent[5],"Do Thing fiVe");
strcpy(sent[6],"Do Thing Six");
strcpy(sent[7]," Quit ");
Menu(-1,-1);
if (left) {
switch (mc) {
case 1 : function1(); break;
case 2 : function2(); break;
case 3 : function3(); break;
case 4 : function4(); break;
case 5 : function5(); break;
case 6 : function6(); break;
case 7 : exit(0);
} /* end of switch */
} /* end of "if (left)" */
switch (toupper(u)) {
case 'O' : function1(); break;
case 'T' : function2(); break;
case 'H' : function3(); break;
case 'F' : function4(); break;
case 'V' : function5(); break;
case 'S' : function6(); break;
case 'Q' : exit(0);
}
while (u != 27);
cleanup();
}
Performance of example:
Mc is set to 1 so when the menu pops up, the first item
will be highlighted. Seven sent[]s are given strings. The
menu pops up and the user presses a key or operates the
mouse. Then if u is 13, (because the left mouse button or
[Enter] has been pressed), a switch statement figures out
what to do with the user's menu choice.
If mc is between 1 and 6, one of the functions is called.
Of course, these functions can do anything you wish, based
upon what menu item the user has selected. The last menu
choice (sent[7]) is 'Quit' and will cause this program to
terminate.
U is changed into an uppercase letter so that the
following switch will work whether the user presses a capital
or small letter. This second switch checks to see whether the
user selected a menu item based upon the capitalized letter
hints. You can also use function keys here. The #0 has
already been stripped off, so if you get a ';', for instance,
then the user pressed [F1] and probably wants 'help.' To
determine whether the user pressed [;] or [F1] check the
global variable keydetect. If an alphanumeric key was
pressed keydetect will be 1. If an extended key, it will be
set to 2.
Assuming the user did not select 'Quit' or press [Esc]
(ASCII #27) or the right mouse button, the menu process will
repeat. When the user finally does choose to quit, the
cleanup() function returns to DOS gracefully.
*************************************************************
void menug(void) - function
Usage: menug() is for internal use of the Magic library.
Direct manipulation is not recommended.
Description:
Menug() is called to display the menu on screen when in a
graphics mode.
*************************************************************
char mouseinstalled(void) - function
Usage: /* example */ if (mouseinstalled) printf("Click left...")
Description:
This function returns 1 if a mouse and its driver are
installed, and 0 if not.
See Also: poll(), setmouserows(), setmousecolumns()
Example:
#include <magic.h>
void main() {
magic_setup();
if (!mouseinstalled) pile("Mouse not found");
else pile("A mouse is present");
getanykey(10,10);
}
Performance of Example:
If there is no mouse then mouseinstalled will be return 0 and
'Mouse not found' will pop up. If there is a mouse, then 'A
mouse is present' will appear on the screen. When the user
presses a key, the program ends.
*************************************************************
char musicon - Global Variable
Usage: musicon = 1;
Description:
This global char variable controls whether the sound effects
are allowed to play. The default for musicon is 0 resulting
in no sound effects. When musicon is set to 1, calls to
pink(), twinkle(), soundup(), sounddown(), sorry() and
bugle() will be played.
Considerations:
Some sound effects are automatically built in to pop()
and restore() which are automatically called by menu(),
getanykey(), getyn() and dialog() and will play if musicon is
set to 1. The default for musicon is 1.
See Also: pink(), twinkle(), soundup(), sounddown().
Example:
include <magic.h>
void main() {
magic_setup();
pile("Do you want sound effects? (Y/N)");
getyn(-1,-1);
if (u == 'Y') musicon = 1; else musicon = 0;
twinkle();
}
Performance of Example:
The user will be asked to press 'Y' or 'N' for sound effects.
If the user selects 'Y' then musicon will be 1 and twinkle()
will play. If the user selects 'N' then no sound will be
heard.
*************************************************************
void nameinfile(char *string) - function
Usage: nameinfile(string)
Description:
This procedure automatically closes the present infile if
it is open then renames it to string. From this time until
another call to nameinfile(), the external file associated
with "infile" will carry the name you have given it.
Considerations:
If string is a literal, not a string variable, then it
must be enclosed in quotation marks. String must be DOS-legal
with up to 8 alphanumeric characters, an optional period,
then up to a three character extension. Full drive
designator and pathnames are supported up to 50 characters.
See Also:
filewrite(), filewriteln(), fileread(), filereadln(),
nameoutfile().
Example:
include <magic.h>
include <stdio.h>
void main() {
magic_setup();
nameinfile("TestFile.Txt");
filereadln();
printf("%s",answer);
waitforuser();
}
Performance of example:
"Testfile.txt" is assigned to infile. When filereadln()
is called, it looks to the disk for the file called
"Testfile.txt" and reads one line. This line is displayed on
the screen. The program terminates when the user presses any
key.
*************************************************************
void nameoutfile(char *string) - function
Usage: nameoutfile(string)
Description:
This procedure automatically closes the present outfile if
it is open then renames it to string. From this time until
another call to nameoutfile(), the external file associated
with "outfile" will carry the name you have given it.
Considerations:
If string is a literal, not a string variable, then it
must be enclosed in quotation marks. String must be DOS-legal
with up to 8 alphanumeric characters, an optional period,
then up to a three character extension. Full drive
designator and pathnames are supported up to 76 characters.
See Also:
filewrite(), filewriteln(), fileread(), filereadln(),
nameinfile().
Example:
include <magic.h>
include <stdio.h>
void main() {
magic_setup();
nameoutfile("TestFile.Txt");
filewriteln("This is a test");
}
Performance of example:
"Testfile.txt" is assigned to outfile. When
filewriteln() is called, it looks to the disk for the file
called "Testfile.txt" or creates a "Testfile.txt" and adds
one line.
*************************************************************
file* outfile - Global Variable
Usage: /* example */ fopen(outfile,"Things.Doc","wt")
Description:
Outfile is declared globally as a file pointer. It is most
often used for exporting information from your program with
the automatic procedures filewrite() and filewriteln(). The
default string assigned to outfile as the name under which it
is read from disk is "OUTPUT", but this can be changed with
nameoutfile().
Considerations:
You can override the automatic use of outfile in Magic with
standard Borland/Turbo C techniques such as fopen() fclose(),
fprintf() and fscanf(). Outfile is opened as a binary file.
String conversions are made automatically by the Magic
functions.
See Also:
filewrite(), filewriteln(), nameinfile(), outfile() {Magic};
Also all file handling functions {Borland manuals}
Example:
#include <magic.h>
void main() {
magic_setup();
nameoutfile("TESTFILE.TXT");
filewriteln("test");
fclose(outfile);
nameoutfile("TESTFILE.2");
filewriteln("test-2");
}
Performance of example:
Nameoutfile() is used to cause outfile to be called
"TESTFILE.TXT" when referenced on disk. A line of text is
written to it, then outfile is closed. Outfile is renamed
"TESTFILE.2" and another line of text is written to outfile,
but outfile is actually a different file on the disk.
*************************************************************
char outfilename[50]
Usage: /* example */ strcpy(outfilename,"testfile.1")
Description:
Outfilename is an array of 50 characters used to hold a
string for identifying OUTFILE (see above). Standard string
character array procedures may be used to manipulate
outfilename. This is the string getoutfile(), nameoutfile(),
filewrite() and filewriteln() use to identify outfile.
Considerations:
The default for outfilename is "OUTPUT." Normally,
nameoutfile() is used to change outfilename.
Example:
#include <magic.h>
#include <string.h>
void main() {
.
.
if (strlen(outfilename)) < 4)
printf("We have a very short file name");
.
.
}
Performance of example:
If outfilename is less than 4 characters long then the
program prints, "We have a very short file name."
*************************************************************
void pile(unsigned char string[81]) - function
Usage: pile(string)
Description:
Pile() uses the global char array, "sent[81][46]" and
the global int variable howmany. "Howmany" keeps track of
howmany strings of text from the sent[] array have been
assigned text. The next available sent[] is assigned string,
and howmany is incremented by one.
Consideration:
If starting a new 'pile of sent[]s' call clearsents()
first, to be sure that all the sent[]s contain no text. Usage
of pile() must be consistent. In other words, if you use
strcat() for sent[1] and sent[2], then use pile(), you may be
surprised to find pile will still affect sent[1]. To remedy,
you can always call figurehowmany() before using pile().
There is a limit to the maximum size of pop-up boxes
using sent[]s. For instance, in VGA-HI graphics mode, the
limit is about 20 lines of text with the longest line being
about 40 characters long.
See Also:
pop(), getanykey(), getyn(), dialog(), menu(),
clearsents(), figurehowmany(), howmany
Example:
#include<magic.h>
void main() {
magic_setup();
pile("This is the first line of a test");
pile("This is the second line.");
getanykey(-1,-1);
}
Performance of example:
Two strings of text are assigned to the array sent[].
Then getanykey() displays those two strings.
*************************************************************
void pink(void) - function
Usage: pink()
Description:
Pink() makes a sound typically indicating a key has been
pressed or a small action has occurred.
Considerations:
The global variable musicon must be greater than 0 or
pink() will not make a sound.
See Also:
musicon, twinkle(), soundup(), sounddown(), sorry() {Magic}
sound(), nosound(), delay() {Borland}
Example:
include <magic.h>
include <stdio.h>
void main() {
magic_setup();
do {
musicon = 1;
u = getch();
pink();
printf("%c",u);
}
while ((u != 13) && (u != 27));
}
Performance of example:
Every time a key is pressed, it's character will be shown
on the screen and an audible click will be heard until the
user presses [Enter] or [Esc].
*************************************************************
void pointeroff(void) - function
Usage: pointeroff()
Description:
Turns off the mouse pointer or arrow.
Considerations:
Will work with or without mouse installed. Graphics modes
only.
See Also:
poll(), pointeron(), resetmouse(), pointertoxy()
Example:
#include <magic.h>
void main() {
magic_setup();
bestvideo();
pointeroff();
waste();
do {
poll();
lineto(px,py);
}
while (!left);
waste();
pointeron();
do poll(); while (!left);
cleanup();
}
Performance of example:
The program will switch to a graphics mode and there will
be no mouse pointer. As long as the user moves the mouse, a
trail of lines will appear on the screen. When the user
clicks the left mouse button, the mouse pointer will reappear
and the drawing of lines will cease. When the user presses
any key or mouse button the program will terminate gracefully.
*************************************************************
void pointeron(void) - function
Usage: pointeron()
Description:
Turns on the mouse pointer or arrow.
Considerations:
Will work with or without mouse installed. Graphics modes
only.
See Also:
poll(), pointeroff(), resetmouse(), pointertoxy()
Example:
#include <magic.h>
#include <graphics.h>
void main() {
magic_setup();
bestvideo();
pointeroff();
waste();
do {
poll();
lineto(px,py);
}
while (!left);
waste();
pointeron();
do poll(); while (!left);
cleanup();
}
Performance of example:
The program will switch to a graphics mode and there will
be no mouse pointer. As long as the user moves the mouse, a
trail of lines will appear on the screen. When the user
clicks the left mouse button, the mouse pointer will reappear
and the drawing of lines will cease. When the user presses
any key or mouse button the program will terminate gracefully.
*************************************************************
char pointerstatus - Global Variable
Usage : /* example */
if (!pointerstatus) outtextxy(x,y,"No arrow")
Description:
Pointerstatus is a global char variable used by Magic to
keep track of whether a mouse (or arrow key) pointer is
visible on screen. In most cases, changing this variable is
dangerous, but testing it is ok. When a pointer is visible,
pointerstatus = 1, otherwise it is 0.
Considerations:
Used in graphics modes only.
See Also:
pointeron(), pointeroff(), resetmouse()
*************************************************************
void pointertoxy(void) - function
Usage: pointertoxy()
Description:
Moves the mouse pointer to coordinates designated by the
global int variables px and py.
Considerations:
Whether or not the pointer is visible, the (graphics) CP
(Current Position) will still be moved to px, py.
See Also:
poll(), pointeroff(), pointeron(), resetmouse().
Example:
#include <magic.h>
void main () {
magic_setup();
bestvideo();
px := getmaxx() / 2; py := getmaxy() / 2;
pointeron();
pointertoxy();
waitforuser();
cleanup();
}
Performance of example:
The current position is moved to px and py, which have
been assigned the center of the screen. The pointer will
appear there. The program waits for the user to press a key,
then terminates gracefully.
*************************************************************
void poll(void) - function
usage: poll()
Description:
Poll() is a very versatile function check for user input
whether from an optional mouse, or from keyboard. If any
change has occurred, the global unsigned char variable "u" is
updated.
At the start of poll(), the global unsigned char variable
"u" is set to #126, an uncommon character. the global char
variables, "left", "center" and "right" are set to 0.
If the left mouse button is clicked, left become 1 and u
becomes 13 (emulating the [Enter] key). If the right button
is clicked, right becomes 1 and u becomes 27, (emulating the
[Esc] key. If the mouse has a center button, and if it is
clicked, center becomes 1. With a two-button mouse, center
is always 0.
If the [Enter] key is pressed, left becomes 1. If the
[Esc] key is pressed, right becomes 1.
Additionally, mouse movement updates the global int
variables px and py which are used to represent horizontal
and vertical position on the screen. If a mouse pointer is
visible (pointeron()), then the mouse pointer is moved to the
new px,py position.
Through poll(), the keyboard can also update px, py and
the 'mouse' pointer. Use of the arrow keys, [Home], [Page
Up], [End] and [Page Down] cause a change of one pixel in a
straight or diagonal direction. If [Num Lock] is on, the
number keys cause a corresponding but larger change of px and
py, straight or diagonal of from 8 to 12 pixels.
Considerations:
Poll() automatically calls pointertoxy() to update the
current px,py position. Poll() can display an arrow (mouse
pointer) whether or not a mouse is installed.
See Also:
pointetoxy(), pointeron(), pointeroff(), resetmouse(),
xreadkey()
Example:
#include <magic.h>
void main() {
magic_setup();
pointeron();
do {
poll();
while (!left);
}
Performance of example:
The mouse pointer (text mode) moves around until the user
clicks the left mouse button or presses the [Enter] key.
*************************************************************
void pop(int x, int y) - function
Usage: pop(x,y)
Description:
This is the simplest version of a pop-up text box in the
Magic kit. Magic has a pre-declared array of 80-character
long strings called sent[]. Before a call to pop(), you must
assign text to as many strings as you wish to display. They
must be in order. The first line displayed will be sent[1],
the second line will be sent[2], and so on. If the rest of
the string array is empty, any strings after the last one to
which you have assigned a line of text will be ignored by
pop().
Pop() requires two integers, x and y. X is the horizontal
coordinate and y is the vertical coordinate. These
coordinates mark the position on the screen where the upper
left corner of the pop up box will occur. The whole box is 4
columns wider than the widest sent[] and two rows taller than
the total number of sent[]s which contain text. If you are in
text mode the upper left corner of the screen is 1,1 and the
lower right corner is 80,25. In any of the graphics modes,
the upper left corner is 0,0 and the lowest right varies. in
CGA, 2-color mode (640 x 200), for instance, the lower right
corner is 639,199.
In graphics or text mode, if either x or y are a negative
integer, the box will be automatically centered on the
screen in the corresponding dimension.
When pop() starts, it first saves the current contents of
the screen to memory. pop() will then place its pop-up box on
the screen. There is no wait for user input built in. After
a call to pop(), the program will progress immediately to the
next step. Therefore, a usual step is to call waitforuser(),
or some other program step, so the pop-up box will be seen
before the program continues. Then call restore() to get rid
of the pop-up box and replace the original screen contents.
To clear out the array of strings (sent[81][46]), call
clearsents().
Actual use of pop() may be rare, since pop(),
waitforuser(), clearsents() and restore() are automatically
incorporated in getanykey(), getyn(), dialog(), and menu().
Considerations:
Must not use x or x integers that are beyond the possible
range for the current video mode. (except negative integers,
which will center the pop-up box) It is advisable to call
restore() some time soon after done with pop(). Otherwise 4k
of RAM is occupied with the saved screen in text mode, and up
to around 300k in some graphics modes. There can be up to 10
text screens saved at one time when there is sufficient RAM
space. If an attempt is made to save more screens than
possible, such as calling pop() 11 times in a row, only the
first screen(s) saved will be available for a restore(). If
your program exceeds available RAM space, the IDE will return
an out of memory notice.
In text mode, you cannot use strings longer than 75
characters and no more than 21 strings. In graphics modes,
the maximum size of the sent[] array (string array) varies.
In graphics modes, there is only one layer of saved
screens available.
Text mode, does not support background colors above 7.
There is a limit to the maximum size of a pop() box. For
instance, in VGA-HI graphics mode, the limit is about 20
lines of text with the longest line being about 40 characters
long.
See Also:
restore(), getanykey(), getyn(), dialog(), menu(), sent[],
clearsents(), pile() centerjustify
Example:
#include <magic.h>
#include <string.h>
void main() {
magic_setup();
strcpy(sent[1],"This is a line of text");
strcpy(sent[2],"This is another line");
strcpy(sent[3],"Press any key...");
pop(1,1);
waitforuser();
restore();
waitforuser();
}
Performance of example:
Since there are 3 sent[]s a text box will pop up that is
three lines tall. The first line is the widest, and therefore
the box will be just large enough to neatly contain the
first, widest line. Pop is given the coordinates of 1,1, so
the upper left corner of the pop up box will be in the
extreme upper left corner of the screen. Waitforuser() will
stall the program until the user presses any key or clicks a
mouse button. Restore() restores the screen as it was before
the pop-up box appeared, which is silly in this program,
because it ends after another waitforuser().
*************************************************************
void popg(int x, int y) - function
Usage: This is for internal use by the Magic Library. Direct
use of this function is not recommended.
Description: Called by pop() to pop up a box in graphics
modes.
*************************************************************
int problem - Global Variable
Usage: /* example */ if (problem) exit(0)
Description:
Problem is a global int variable that is usually set to 0
as any graphics or i/o procedure in the Magic unit starts.
Then, if a problem occurs, the procedure will handle the
problem as cleanly as possible and set Problem to a number
greater than 0, (usually 1).
For instance, if filewrite() is asked to write a string to
a write-protected disk, the program will not crash, but will
not write to the disk, and problem becomes 1. You can then
test problem in your program and branch to handle the
'problem.'
Considerations:
Problem must be checked before a call to any other
procedure in the Magic library because the next function may
reset problem for it's own use.
Example:
#include <magic.h>
void main() {
magic_setup();
nameoutfile("testfile.txt");
filewriteln("This is a line of nonsense.");
if (problem) {
pile("Problem writing to disk");
pile("Disk may be full or write-protected");
pile("Press any key to continue..");
getanykey(-1,-1);
}
}
Performance of example:
This program tries to write, "This is a line of nonsense"
to a disk file called "Testfile.txt." If this proves
impossible, then problem is 1 and a three-line notice pops up
on the screen.
*************************************************************
int px - Global Variable
Usage: /* example */ putpixel(px,py,WHITE)
Description:
Px is a global int variable defined in MAGIC.H. The most
common use of px is to designate a horizontal screen
position. Px is automatically used by pointertoxy() and
modified by poll().
*************************************************************
int py - Global Variable
Usage: /* example */ putpixel(px,py,WHITE)
Description:
Py is a global int variable defined in MAGIC.H. The most
common use of py is to designate a vertical screen position.
Py is automatically used by pointertoxy() and modified by
poll().
*************************************************************
void replacemouse(void) - function
Usage: This is used internally by the Magic Unit. Direct
use of this function is not recommended.
Description: This function replaces the mouse pointer
(arrow) with what it had covered when it is moved to a new
location or pointeroff() is called.
*************************************************************
Continued in file MAGIC.3
(This file is split into three parts because some older
versions of Turbo C cannot display files larger than 64k.)