home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
EXAMPLES
/
DEMOSLED.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-09
|
6KB
|
219 lines
/*
demosled.c
C-scape 3.2 Example Program
Copyright (c) 1988, 1990 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
This program demonstrates the use of embedded screens.
Specifically, a screen (sed) is created which contains
a scrolling list (sled) and a text editor (ted) within it.
This program includes mouse support.
The data entered is saved in the ascii file "demosled.dat"
Revision History:
-----------------
6/06/90 jmd changed main to return an int
9/14/90 bkd changed to use exit(0) instead of return(0).
10/05/90 pmcm made notepad and sled prompts os sensitive
10/19/90 pmcm included ostdlib.h for exit(), added return(1)
12/01/90 ted prototyped main, except if Turbo C++.
12/04/90 ted restored "" includes for C-scape headers (not <> includes).
12/07/90 bkd merged changes from ted.
12/28/90 jmd added second field data pointer to ted to enable cut/paste
*/
#include <stdio.h>
#include "cscape.h"
#include "ostdlib.h" /* for exit() */
#include "sled.h"
#include "teddecl.h"
#define DATAFILE "demosled.dat"
#define BUF_LEN 1000
#define NAME_SIZE 11
#define TYPE_SIZE 11
#define WEIGHT_SIZE 4
#define COMMENT_SIZE 40
static char buffer[BUF_LEN];
static char text[BUF_LEN];
static char *notepad_prompt =
# ifdef OAK_DOS
"Press Ctrl-PgUp to leave note pad";
# endif
# ifndef OAK_DOS
# ifdef OAK_VMS
"Press Ctrl-X PgUp (Ctrl-X Prev Screen) to leave note pad";
# else
"Press Ctrl-X PgUp to leave note pad";
# endif
# endif
static char *bobsled_prompt =
# ifdef OAK_DOS
"Tab, Shift-Tab, GreyPlus to insert a fish, GreyMinus to delete";
# endif
# ifndef OAK_DOS
# ifdef OAK_VMS
"Tab, Ctrl-X Tab, Keypad Comma to insert, Keypad Minus to delete";
# else
"Tab, Ctrl-X Tab, Ctrl-X Plus to insert, Ctrl-X Minus to delete";
# endif
# endif
/* Turbo C++ complains if main is prototyped */
#ifndef TCP
int main(void);
#endif
int main(void)
{
menu_type menu, slmenu, tmenu;
sed_type sed, ted, sled;
int row, array_size, weight;
char owners_name[50];
FILE *fp;
/* Initialize the display interface */
disp_Init(def_ModeText, FNULL);
/* Turn on the mouse */
hard_InitMouse();
/* Turn on sed window class mouse support */
sedwin_ClassInit();
/* create the sled */
slmenu = menu_Open();
menu_Printf(slmenu, "Name Type Weight Comment\n");
menu_Printf(slmenu, "@p[0]@f[@[%d,#]]", NULL, &string_funcs, NAME_SIZE);
menu_Printf(slmenu, "@p[11]@f[@[%d,#]]", NULL, &string_funcs, TYPE_SIZE);
menu_Printf(slmenu, "@p[22]@f[@[%d,#]]", NULL, &int_funcs, WEIGHT_SIZE);
menu_Printf(slmenu, "@p[27]@fw33[@[%d,#]]", NULL, &string_funcs, COMMENT_SIZE);
menu_Flush(slmenu);
sled = sled_Open(slmenu, 4, spc_Sled);
sed_SetBorder(sled, bd_sidebar);
sed_SetMouse(sled, sedmou_Click);
/* open data file */
if ((fp = fopen(DATAFILE, "r")) == NULL ) {
array_size = 1;
owners_name[0] = '\0';
text[0] = '\0';
}
if (fp != NULL) {
rewind(fp);
/* read list size and owners name, the '~' is used as a delimiter */
/* see scanf() reference for the meaning of [^\n] */
fscanf(fp, "%d~%[^\n]\n", &array_size, owners_name);
}
/* read array data from file */
for (row = 0; row < array_size; row++) {
if (fp != NULL) {
fscanf(fp, "%[^~]~", buffer);
sled_SetColVar(sled, 0, row, (VOID *)buffer);
fscanf(fp, "%[^~]~", buffer);
sled_SetColVar(sled, 1, row, (VOID *)buffer);
fscanf(fp, "%d~", &weight);
sled_SetColVar(sled, 2, row, (VOID *)&weight);
fscanf(fp, "%[^\n]\n", buffer);
sled_SetColVar(sled, 3, row, (VOID *)buffer);
}
}
/* read the note data from file */
if (fp != NULL) {
fread(text, 1, BUF_LEN, fp);
fclose(fp);
}
/* create the ted notepad */
tmenu = menu_Open();
menu_Printf(tmenu, "@fd2[]", text, &ted_funcs, NULL, NULL);
menu_Flush(tmenu);
ted = sed_Open(tmenu);
sed_SetBorder(ted, bd_mouse);
sed_SetBorderTitle(ted, "General Notes");
sed_SetHeight(ted, 4);
sed_SetWidth(ted, 60);
sed_SetSpecial(ted, spc_EmbedTed);
sed_SetMouse(ted, sedmou_Click);
ted_SetWrapWidth(ted, 56);
ted_SetMaxSize(ted, 400L);
/* create the master sed */
menu = menu_Open();
menu_Printf(menu, "@p[1,2]Owner: @fd[@[30,#]] ", owners_name,
&string_funcs, "Aquarium owner's name");
menu_Printf(menu, "@p[3,2]@fbd[]", NULL, &bob_funcs,
sed_CreateBob(sled, BOB_DEPENDENT), bobsled_prompt);
menu_Printf(menu, "@p[9,1]@fbd[]", NULL, &bob_funcs,
sed_CreateBob(ted, BOB_DEPENDENT), notepad_prompt);
menu_Flush(menu);
sed = sed_Open(menu);
sed_SetPosition(sed, 1, 1);
sed_SetBorder(sed, bd_mouse);
sed_SetBorderTitle(sed, "Aqua-O'Matic");
sed_SetMouse(sed, sedmou_Click);
sed_SetWidth(sed, sed_GetWidth(sed) + 1);
/* the master sed handles painting, controling, and closing sub objects */
sed_Repaint(sed);
sed_Go(sed);
/* We're done, now save data back to file */
/* open data file */
fp = fopen(DATAFILE, "w");
rewind(fp);
array_size = sled_GetColSize(sled);
/* write list size and owners name, the '~' is used as a delimiter */
fprintf(fp, "%d~%s\n", array_size, owners_name);
/* write array data to file, deallocate memory */
for (row = 0; row < array_size; row++) {
fprintf(fp, "%s~%s~%d~%s\n",
(char *)sled_GetColVar(sled, 0, row),
(char *)sled_GetColVar(sled, 1, row),
*(int *)sled_GetColVar(sled, 2, row),
(char *)sled_GetColVar(sled, 3, row)
);
}
/* write the note data to file, -1 so that we don't write the '\0' */
fwrite(text, 1, (SIZE_T) ted_GetSize(ted) - 1, fp);
fclose(fp);
/* deallocate the seds, etc. */
sed_Close(sed);
disp_Close();
exit(0);
return(0);
}