uifctest.c 5.31 KB
Newer Older
1
2
3
4
/* uedit.c */

/* Synchronet for *nix user editor */

5
/* $Id: uifctest.c,v 1.9 2020/08/16 20:37:08 rswindell Exp $ */
6
7
8
9
10

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
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
 *																			*
 * 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.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

38
#include <signal.h>
39
#include <stdio.h>
40
/* #include "curs_fix.h" */
deuce's avatar
deuce committed
41
#include "filepick.h"
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "uifc.h"

/********************/
/* Global Variables */
/********************/
uifcapi_t uifc; /* User Interface (UIFC) Library API */
char YesStr[]="Yes";
char NoStr[]="No";
char *ok[2]={"OK",""};

int main(int argc, char** argv)  {
	char**	opt;
	char**	mopt;
	int		main_dflt=0;
	int		main_bar=0;
	char	revision[16];
	char	str[256],ctrl_dir[41],*p;
	char	title[256];
	int		i,j;
	int		done;
	int		last;
	int		edtuser=0;
	char	longtitle[1024];
deuce's avatar
deuce committed
65
	struct file_pick fper;
66
67
68
69
70
71
	/******************/
	/* Ini file stuff */
	/******************/
	char	ini_file[MAX_PATH+1];
	FILE*				fp;

72
	sscanf("$Revision: 1.9 $", "%*s %s", revision);
73

74
    printf("\nSynchronet UIFC Test Suite Copyright "
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        "Rob Swindell\n");

    memset(&uifc,0,sizeof(uifc));

	uifc.esc_delay=500;

	for(i=1;i<argc;i++) {
        if(argv[i][0]=='-')
            switch(toupper(argv[i][1])) {
                case 'C':
        			uifc.mode|=UIFC_COLOR;
                    break;
                case 'L':
                    uifc.scrn_len=atoi(argv[i]+2);
                    break;
                case 'E':
                    uifc.esc_delay=atoi(argv[i]+2);
                    break;
				case 'I':
					/* Set up ex-ascii codes */
					uifc.mode|=UIFC_IBM;
					break;
                default:
                    printf("\nusage: %s [ctrl_dir] [options]"
                        "\n\noptions:\n\n"
                        "-c  =  force color mode\n"
                        "-e# =  set escape delay to #msec\n"
						"-i  =  force IBM charset\n"
                        "-l# =  set screen lines to #\n"
						,argv[0]
                        );
        			exit(0);
		}
		if(atoi(argv[i]))
			edtuser=atoi(argv[i]);
    }

#ifdef __unix__
	signal(SIGPIPE, SIG_IGN);
#endif

	uifc.size=sizeof(uifc);
#ifdef USE_CURSES
	i=uifcinic(&uifc);  /* curses */
#else
	i=uifcini32(&uifc);  /* curses */
#endif
	if(i!=0) {
		printf("uifc library init returned error %d\n",i);
		exit(1);
	}

	opt=(char **)malloc(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		opt[i]=(char *)malloc(MAX_OPLN);

	mopt=(char **)malloc(sizeof(char *)*MAX_OPTS);
	for(i=0;i<MAX_OPTS;i++)
		mopt[i]=(char *)malloc(MAX_OPLN);

	sprintf(title,"Synchronet Test Suite");
	if(uifc.scrn(title)) {
		printf(" USCRN (len=%d) failed!\n",uifc.scrn_len+1);
		return(1);
	}

	strcpy(mopt[0],"Long Title");
	strcpy(mopt[1],"String Input");
143
144
	strcpy(mopt[2],"File picker");
	mopt[3][0]=0;
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

	uifc.helpbuf=	"`Test Suite:`\n"
					"\nToDo: Add Help";

	while(1) {
		j=uifc.list(WIN_L2R|WIN_ESC|WIN_ACT|WIN_DYN|WIN_ORG,0,5,70,&main_dflt,&main_bar
			,title,mopt);

		if(j <= -2)
			continue;

		if(j==-1) {
			uifc.bail();
			return(0);
		}

		if(j==0) {
			/* Long Title */
			strcpy(longtitle,"This is a long title...");
			for(p=strchr(longtitle,0);p<longtitle+sizeof(longtitle)-1;p++)
				*p='.';
			*p=0;
			done=0;
			uifc.list(WIN_ORG|WIN_MID|WIN_ACT,0,0,0,&i,0,longtitle,ok);
		}
		if(j==1) {
			/* String input */
			strcpy(longtitle,"This is a test if string input... enter/edit this field");
173
			uifc.input(WIN_MID|WIN_NOBRDR,0,0,"Input",longtitle,sizeof(longtitle),K_EDIT);
174
			uifc.showbuf(WIN_MID, 0, 0, uifc.scrn_width-4, uifc.scrn_len-4, "Result:", longtitle, NULL, NULL);
175
		}
176
177
		if(j==2) {
			/* File picker */
deuce's avatar
deuce committed
178
179
180
181
182
183
184
			if(filepick(&uifc, "Bob", &fper, NULL, NULL, UIFC_FP_ALLOWENTRY)!=-1) {
				if(fper.files==1) {
					sprintf(str,"File selected: %-.200s",fper.selected[0]);
					uifc.msg(str);
				}
				filepick_free(&fper);
			}
185
		}
186
187
	}
}