home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
files
/
program
/
lynxlib
/
exinput.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-23
|
6KB
|
198 lines
/* This source file is part of the LynxLib miscellaneous library by
Robert Fischer, and is Copyright 1990 by Robert Fischer. It costs no
money, and you may not make money off of it, but you may redistribute
it. It comes with ABSOLUTELY NO WARRANTY. See the file LYNXLIB.DOC
for more details.
To contact the author:
Robert Fischer \\80 Killdeer Rd \\Hamden, CT 06517 USA
(203) 288-9599 fischer-robert@cs.yale.edu */
#include <e_osbind.h>
#include <nobdefs.h>
#include <gemdefs.h>
#include <exinput.h>
/* --------------------------------------------------------- */
/* The box which is displayed above file selector */
char nul[] = 0;
MW_TEDINFO name_tedinfo = {0L, nul, nul, 3, 6, TE_CNTR, 0x1180, 0x0, -1, 5,1};
MW_OBJECT name_box[2] = {
-1, 1, 1, G_BOX, NONE, OUTLINED, 0x21100L, 0,0, 38,2,
0, -1, -1, G_TEXT, LASTOB, NORMAL, &name_tedinfo, 0,0, -1,-1
};
#define BOX_W 640 /* Width of box in 1/16 of characters */
#define BOX_H 24
#define BOX_RAISE 172 /* Amount to raise box from center */
/* --------------------------------------------------------- */
int otos_fsel_exinput(path, name, button, msg)
/* Works like fsel_exinput, but on old versions of TOS */
char *path; /* Path name to display, including *.* */
char *name; /* Name of file selected */
int *button; /* Button selected */
char *msg; /* Message to display above file selector */
{
wh ch_size; /* Width & Height of characters */
xywh center; /* Place that GEM puts centered box */
int dum;
OBJECT *d = name_box; /* Mess with type checking */
/* Get character size */
graf_handle(WH_PTR(ch_size), &dum, &dum);
/* Set up the outside box */
d[0].ob_width = (BOX_W * ch_size.w) >> 4;
d[0].ob_height = (BOX_H * ch_size.h) >> 4;
form_center(d, XYWH_PTR(center));
d[0].ob_y -= (BOX_RAISE * ch_size.h) >> 4;
/* Set up inside string */
d[1].ob_width = d[0].ob_width;
d[1].ob_height = d[0].ob_height;
name_tedinfo.te_ptext = msg;
name_tedinfo.te_txtlen = strlen(msg) + 1;
/* Draw the box and let system take over */
dial_form(d, FMD_START); /* Draw the box */
objc_draw(d, 0, 256, 0, 0, 0, 0);
dum = fsel_input(path, name, button);
dial_form(d, FMD_FINISH); /* Undraw the box */
return dum;
}
/* --------------------------------------------------------- */
#define FSEL_EXINPUT 91 /* AES call number of fsel_exinput() */
#define PATCH_CTRL 1 /* Set to 1 if library hasn't been patched */
extern char ctrl_cnts[115][3];
extern int int_out[];
extern long addr_in[];
extern crys_if();
int fsel_exinput(path, file, button, label)
/* Binding to the new AES call, as found in the Rainbow TOS */
/* developer's release notes, August 7, 1989, page 26 */
int *path, *file;
int *button;
char *label;
{
register int *i;
register long *a;
register char *c;
LONG usp;
unsigned TOS_version;
/* Get TOS version number */
Gosuper(usp);
TOS_version = SYSBASE->version;
Gouser(usp);
/* if old TOS version, just do get_file */
if (TOS_version < 0x0104)
return otos_fsel_exinput(path, file, button, label);
#if PATCH_CTRL
/* Patch ctrl_cnts array with correct control array parameters */
c = &(ctrl_cnts[FSEL_EXINPUT-10][0]);
if ((c[1] != 2)||(c[2] != 3)) {
*(c++) = 0;
*(c++) = 2;
*c = 3;
}
#endif
/* Set up parameter blocks */
i = int_out;
a = addr_in;
*a++ = (long)path;
*a++ = (long)file;
*a = (long)label;
/* Call AES */
crys_if(FSEL_EXINPUT);
/* and return */
*button = i[1];
return(i[0]);
}
/* --------------------------------------------------------- */
BOOLEAN get_file(path, name, msg)
/* Shell to fsel_exinput */
/* This is included to retain compatibility with the old Wunk library. */
/* It is now just a shell to fsel_exinput, to change around the way the */
/* arguments are passed. */
/* Returns TRUE for OK, FALSE for Cancel */
char *path; /* Path name to display, including *.* */
char *name; /* Name of file selected */
char *msg; /* Message to display above file selector */
{
int dum;
fsel_exinput(path, name, &dum, msg);
return (BOOLEAN)dum;
}
/* --------------------------------------------------------- */
BOOLEAN get_folder(idir, message)
char *idir;
char *message;
{
fle_name path, name;
int l;
strcpy(path, idir);
resolve_dname(path, "");
strcat(path, "*.*");
name[0] = NIL;
if (get_file(path, name, message)) {
/* Extract directory part of path name */
l = strlen(path);
for (; path[l] != '\\'; l--);
idir[l+1] = NIL;
for (; l >= 0; l--) idir[l] = path[l];
/* Fill out missing parts */
resolve_dname(idir, "");
return TRUE;
}
return FALSE;
}
/* ---------------------------------------------------------------- */
/* High-level file-selector routines, to avoid pathname hacking */
/* by Robert Fischer January 3, 1991 */
/* ---------------------------------------------------------- */
set_fsel(fname, wild, fsel)
/* Pulls apart fname and sets fsel's components to it */
char *fname;
char *wild;
fsel_rec *fsel;
{
fle_name stringg;
int i;
strcpy(stringg, fname);
resolve_pname(stringg, "");
for (i = strlen(stringg); stringg[i] != '\\'; i--);
stringg[i] = NIL;
strncpy(fsel->path, stringg, MAXPATH);
fsel->path[i] = '\\';
strncpy(fsel->path + i + 1, wild, MAXPATH - i - 1);
strncpy(fsel->name, stringg + i + 1, MAXLEAF);
}
/* ---------------------------------------------------------- */
BOOLEAN do_fsel(message, fname, fsel)
/* Returns TRUE for success */
char *message; /* Plan to read or write? */
char *fname; /* Output path */
fsel_rec *fsel; /* The defaults to use */
{
int i,j;
resolve_pname(fsel->path, "");
fsel_exinput(fsel->path, fsel->name, &i, message);
if (i != 0) {
i = strlen(fsel->path);
for (; i >= 0 && fsel->path[i] != '\\'; i--);
for (j = i; j >= 0; j--) fname[j] = fsel->path[j];
strcpy(fname + i + 1, fsel->name);
return TRUE;
} else return FALSE;
}
/* --------------------------------------------------------------- */