summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2756.c
blob: 5426385cc5189e7ad8d49a6c41d685dc785db2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
143
144
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
    bug 2756
    A non-connected live-range not caught by the live-range splitter resulted
    in an invalid register allocation and an assertion failure in code generation.
*/

#include <testfwk.h>

#pragma disable_warning 84
#pragma disable_warning 85

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __SDCC

struct _bstdio_file {int i;};
typedef struct _bstdio_file FILE;

int bfprintf(FILE *_bstream, const char *__fmt, ...)
{
	return 0;
}

int bprintf(const char *_bfmt, ...)
{
	return 0;
}

FILE *__fopen(const char *_bpath, int _bfd, FILE * _bstream, const char *_bmode)
{
	return 0;
}

#define fopen(__file, __mode)	      __fopen((__file), -1, (FILE*)0, (__mode))

char *bgetenv(char *__name)
{
	return "env";
}

char *bfgets(char *_bs, size_t _bsize, FILE *_bstream)
{
	return 0;
}

FILE bstderr[1];

void err(int _beval, const char *_bfmt, ...)
{
}

void errx(int _beval, const char *_bfmt, ...)
{
}

#if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
char *argv0;
int all = 0;
int wday;
int advance;
char CurLine[64];
char *CurLinep;
#endif

enum {NONE, DAY, WEEK, MONTH} mflag;

#define	CALFILE	"/.calendar"

int pnmatch(const char *s, const char *p, int unanch)
{
	return 0;
}

void usage(void)
{
}

int findmon1(void)
{
	return 0;
}

int findmon2(void)
{
	return 0;
}

int findmon3(void)
{
	return 0;
}

int findday(void)
{
	return 0;
}

int findyear(void)
{
	return 0;
}

int current(int opt)
{
	return 0;
}

int date(int day, int month, int year)
{
	return 0;
}

void doall(void)
{
}

int m(int argc, char *argv[])
{
#if !(defined (__SDCC_mcs51) && defined (__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
#if !(defined (__SDCC_mcs51) && (defined (__SDCC_MODEL_LARGE) || defined (__SDCC_MODEL_HUGE))) // build failure
	int arg = 1;
	char *cp;
	char *thisline;
	char *matchstr;
	char *filename[10];
	FILE *fp[10];
	int matchdate;
	int foundfiles;
	int nfiles;
	int thismonth, thisday, thisyear;
	int thisdate;
	char *atsign;

	argv0 = argv[0];
	mflag = NONE; 				/* Default to no match */

	for (arg = 1; arg < argc; arg++)  { 	/* Read option string */
		cp = argv[arg];
	sw:	switch (*cp) {
			case '-':
				cp++;
				goto sw;
			case 'a':
				all = 1;
				break;
			case 'f':
				filename[arg-1] = ++cp;
				nfiles++;
				continue;
			case 'd':
				matchstr = ++cp;
				mflag = DAY;
				continue;
			case 'w':
				matchstr = ++cp;
				mflag = WEEK;
				continue;
			case 'm':
				matchstr = ++cp;
				mflag = MONTH;
				continue;
			default:
				bfprintf(bstderr, "%s: unrecognized option '%c'\n", argv0, *cp);
				usage();
		}
	}
	if (all)
		doall();

	/*
	 * Open files.
	 */
	if (nfiles)  {
		for (arg = 0; arg < nfiles; arg++ )  {
			if ((fp[arg] = fopen(filename[arg], "r")) == NULL)
				bfprintf(bstderr, "cannot open file %s\n", filename[arg]);
			else
				foundfiles++;
		}
		if (!foundfiles)
			err(1, "cannot open any files specified");
	} else {
		char *hp;

		nfiles = 1;
		if ((hp = bgetenv("HOME")) == NULL)
			errx(1, "can't find my way back HOME");
		filename[0] = malloc(strlen(hp) + strlen(CALFILE) + 1);
		if (filename[0] == NULL)
			errx(1, "out of memory");
		strcpy(filename[0], hp);
		strcat(filename[0], CALFILE);
		if ((fp[0] = fopen(filename[0], "r")) == NULL)
			err(1, "cannot open file $HOME/.calendar");
	}
	/*
	 * Find match condition from options or current date
	 */
	switch (mflag)  {
		case NONE:
			matchdate = current(0);
			break;
		case DAY:
		case WEEK:
			if (*matchstr == '\0') 
				matchdate = current(0);
			else {
				strncpy(CurLine, matchstr, sizeof(CurLine));
				CurLinep = &CurLine[0];
				if ((thismonth = findmon1()) == -1) 
					errx(1, "invalid month in match date");
				if ((thisday = findday()) == -1)  
					errx(1, "invalid day in match date");
				if ((thisyear = findyear()) == -1)  
					thisyear = current(1);
				matchdate = date(thisday, thismonth, thisyear);
			}
			break;
		case MONTH:
			if (*matchstr == '\0')
				matchdate = current(2);
			else  {
				strncpy(CurLine, matchstr, sizeof(CurLine));
				CurLinep = &CurLine[0];
				if ((matchdate = findmon2()) == -1)
					errx(1, "invalid month in match date");
			}
			break;
	}
	/*
	 * Read the calendar files, print matched lines.
	 */
	for (arg = 0; arg < nfiles; arg++) {
		if (fp[arg] == NULL)
			continue;
		while ((thisline = bfgets(CurLine,sizeof(CurLine),fp[arg]))!=NULL) {
			CurLinep = &CurLine[0];
			advance = 0;
			if ((atsign = strchr(CurLinep, '@')) != NULL)
				advance = atoi(atsign + 1);
			if ((thismonth = findmon3()) == -1)
				thismonth = 0;
			if ((thisday = findday()) == -1)
				thisday = 0;
			if ((thisyear = findyear()) == -1)
				thisyear = current(1);
			thisdate = date(thisday, thismonth, thisyear);
			if (thisdate >= matchdate &&
			    thisdate <= matchdate + advance)
				bprintf("%s", thisline);
			else switch (mflag)  {
				case NONE:
					if (wday == 6)
						if (thisdate == matchdate ||
						  thisdate == matchdate + 1 ||
						  thisdate == matchdate + 2 ||
						  thisdate == matchdate + 3)
							bprintf("%s", thisline);
					if (wday == 7)
						if (thisdate == matchdate ||
						  thisdate == matchdate + 1 ||
						  thisdate == matchdate + 2)
							bprintf("%s", thisline);
					if (0 <= wday && wday < 6)
						if (thisdate == matchdate ||
						   thisdate == matchdate + 1)
							bprintf("%s", thisline);
					break;
				case DAY:
					if (thisdate == matchdate)
						bprintf("%s", thisline);
					break;
				case WEEK:
					if (matchdate <= thisdate &&
						    thisdate <= matchdate+7)
						bprintf("%s", thisline);
					break;
				case MONTH:
					if (thismonth == matchdate)
						bprintf("%s", thisline);
					break;
			}
			thisline = NULL;
		}
	}
#endif
#endif
	return 0;
}

#endif // __SDCC

void testBug(void)
{
}