Exemple #1
0
// MW-2005-06-04: Relaxed syntax slightly - allowed 'and' and 'or' for connectors
Parse_errors MCAnswer::parse_notify(MCScriptPoint& sp)
{
	Parse_errors t_error = PE_UNDEFINED;
	
	if (sp . parseexp(False, True, &notify . prompt) != PS_NORMAL)
		t_error = PE_ANSWER_BADRESPONSE;
	
	if (t_error == PE_UNDEFINED && sp . skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
	{
		notify . buttons = NULL;
		notify . button_count = 0;

		do
		{
			MCU_realloc((char **)&notify . buttons, notify . button_count, notify . button_count + 1, sizeof(MCExpression *));
			if (sp . parseexp(True, True, &notify . buttons[notify . button_count]) != PS_NORMAL)
				t_error = PE_ANSWER_BADRESPONSE;
			else
				notify . button_count += 1;
		}
		while(t_error == PE_UNDEFINED && (sp . skip_token(SP_FACTOR, TT_BINOP, O_OR) == PS_NORMAL || sp . skip_token(SP_FACTOR, TT_BINOP, O_AND) == PS_NORMAL));
	}
	
	return t_error;
}
Exemple #2
0
void MCOldFonttablenode::registersize(uint2 size, uint2 *&sizes, uint2 &nsizes)
{
	uint2 i;
	for (i = 0 ; i < nsizes ; i++)
		if (sizes[i] == size)
			return;
	MCU_realloc((char **)&sizes, nsizes, nsizes + 1, sizeof(uint2));
	sizes[nsizes++] = size;
}
Exemple #3
0
Parse_errors MCAnswer::parse_file(MCScriptPoint& sp)
{
	Parse_errors t_error = PE_UNDEFINED;

	file . prompt = NULL;
	file . initial = NULL;
	file . filter = NULL;
	file . type_count = 0;
	file . types = NULL;

	if (sp . parseexp(False, True, &file . prompt) != PS_NORMAL)
		t_error = PE_ANSWER_BADRESPONSE;
	
	if (t_error == PE_UNDEFINED && sp . skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
	{
		if (sp . skip_token(SP_COMMAND, TT_STATEMENT, S_FILTER) == PS_NORMAL || sp . skip_token(SP_COMMAND, TT_STATEMENT, S_TYPE) == PS_NORMAL)
			sp . backup(), sp . backup();
		else if (sp . parseexp(False, True, &file . initial) != PS_NORMAL)
			t_error = PE_ANSWER_BADRESPONSE;
	}
		
	if (t_error == PE_UNDEFINED && sp . skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
	{
		if (sp . skip_token(SP_COMMAND, TT_STATEMENT, S_FILTER) == PS_NORMAL)
		{
			if (sp . parseexp(False, True, &file . filter) != PS_NORMAL)
				t_error = PE_ANSWER_BADRESPONSE;
		}
		else if (sp . skip_token(SP_COMMAND, TT_STATEMENT, S_TYPE) == PS_NORMAL)
		{
			do
			{
				MCU_realloc((char **)&file . types, file . type_count, file . type_count + 1, sizeof(MCExpression *));
				if (sp . parseexp(True, True, &file . types[file . type_count]) != PS_NORMAL)
					t_error = PE_ANSWER_BADRESPONSE;
				else
					file . type_count += 1;
			}
			while(!t_error && sp . skip_token(SP_FACTOR, TT_BINOP, O_OR) == PS_NORMAL &&
						(sp . skip_token(SP_COMMAND, TT_STATEMENT, S_TYPE) == PS_NORMAL || sp . skip_token(SP_ASK, TT_UNDEFINED, AT_TYPES) == PS_NORMAL));
		}
		else
			t_error = PE_ANSWER_BADRESPONSE;
	}
	else if (t_error == PE_UNDEFINED && sp . skip_token(SP_FACTOR, TT_OF) == PS_NORMAL)
	{
		if (sp . skip_token(SP_COMMAND, TT_STATEMENT, S_TYPE) != PS_NORMAL ||
				sp . parseexp(False, True, &file . filter) != PS_NORMAL)
			t_error = PE_ANSWER_BADRESPONSE;
	}
		
	return t_error;
}
Exemple #4
0
int CALLBACK MyFontFamProc(ENUMLOGFONTA FAR* lpelf,
                           NEWTEXTMETRICA FAR* lpntm,
                           int FontType, LPARAM lParam)
{
	switch (lParam)
	{
	case FQ_NAMES:
		epptr->concatcstring(lpelf->elfLogFont.lfFaceName, EC_RETURN, nfonts++ == 0);
		break;
	case FQ_SIZES:
		if (!(FontType & TRUETYPE_FONTTYPE))
		{ //if not true-type font
			uint2 size = uint2((((lpelf->elfLogFont.lfHeight * 72)
			               / SCREEN_WIDTH_FOR_FONT_USE) * 8 / 7));
			uint2 i;
			for (i = 0; i < nfonts; i++)
				if (sizes[i] == size)
					return True; //return to callback function again
			MCU_realloc((char **)&sizes, nfonts, nfonts + 1, sizeof(uint2));
			sizes[nfonts] = size;
			epptr->concatuint(size, EC_RETURN, nfonts++ == 0);
			break;
		}
		else
		{ //if true-type font, size is always 0.
			epptr->concatuint(0, EC_RETURN, nfonts++ == 0);
			return False; //stop right here. no more callback function
		}
	case FQ_STYLES:
		{
			if (!(FontType & TRUETYPE_FONTTYPE))
			{ //not true-type font
				epptr->setstaticcstring("plain\nbold\nitalic\nbold-italic");
				return False;  //stop right here, do not continue looping through callback
			}
			char *style = (char *)lpelf->elfStyle;
			if (strequal(style, "Regular"))
				epptr->concatcstring("plain", EC_RETURN, nfonts++ == 0);
			else if (strequal(style, "Bold Italic"))
				epptr->concatcstring("bold-italic", EC_RETURN, nfonts++ == 0);
			else
				epptr->concatcstring((char*)lpelf->elfStyle, EC_RETURN, nfonts++ == 0);
			break;
		}
	default:
		break;
	}
	return True;
}
Exemple #5
0
Exec_stat MCExternalV0::Handle(MCObject *p_context, Handler_type p_type, uint32_t p_index, MCParameter *p_parameters)
{
	char t_type;
	if (p_type == HT_FUNCTION)
		t_type = XFUNCTION[0];
	else
		t_type = XCOMMAND[0];

	_Xternal *t_handler;
	t_handler = &m_table[p_index];
	if (t_handler -> type[0] != t_type)
		return ES_NOT_HANDLED;

		char *retval;
		Bool Xpass, Xerr;
		int nargs = 0;
		char **args = NULL;
		MCExecPoint ep(p_context, NULL, NULL);

		while (p_parameters != NULL)
		{
			// MW-2013-06-20: [[ Bug 10961 ]] Make sure we evaluate the parameter as an
			//   argument. This takes the value from the variable (by-ref), or built-in
			//   value (by-value).
			if (p_parameters->eval_argument(ep) != ES_NORMAL)
				return ES_ERROR;
			MCU_realloc((char **)&args, nargs, nargs + 1, sizeof(char *));
			args[nargs++] = ep.getsvalue().clone();
			p_parameters = p_parameters -> getnext();
		}

		(t_handler -> call)(args, nargs, &retval, &Xpass, &Xerr);

		// MW-2011-03-02: [[ Bug ]] Memory leak as we aren't freeing any error string that
		//   is returned.
		if (Xerr)
		{
			MCeerror -> add(EE_EXTERNAL_EXCEPTION, 0, 0, retval == NULL ? "" : retval);
			m_free(retval);
		}
		else if (retval == NULL)
			MCresult->clear(False);
		else
		{
			ep.setsvalue(retval);
			MCresult->store(ep, False);
			m_free(retval);
		}

		if (args != NULL)
		{
			while (nargs--)
				delete args[nargs];

			delete args;
		}

		if (Xerr)
			return ES_ERROR;
	else if (Xpass)
				return ES_PASS;

				return ES_NORMAL;
	}
Exemple #6
0
void MCEPS::setextents()
{
	tx = 0;
	ty = 0;
	ex = 612;
	ey = 792;

	uint4 offset;
	uint1 *bptr = (uint1 *)postscript;
	if (*bptr == 0xC5)
	{
		MCswapbytes = !MCswapbytes;
		uint4 *uint4ptr = (uint4 *)postscript;
		uint4 offset = swap_uint4(&uint4ptr[1]);
		size = swap_uint4(&uint4ptr[2]);
		MCswapbytes = !MCswapbytes;
		char *newps = new char[size];
		memcpy(newps, &postscript[offset], size);
		delete postscript;
		postscript = newps;
	}
	if (MCU_offset("\n%%BeginPreview:", postscript, offset))
	{
		uint4 eoffset;
		if (MCU_offset("\n%%EndPreview", postscript, eoffset))
		{
			eoffset += 13;
			memmove(&postscript[offset], &postscript[eoffset], size - eoffset);
			size -= eoffset - offset;
		}
	}
	if (MCU_offset("\n%%BoundingBox:", postscript, offset))
	{
		if (strnequal(&postscript[offset + 16], "(atend)", 7))
		{
			uint4 newoffset;
			MCU_offset("\n%%BoundingBox:", &postscript[offset + 24], newoffset);
			offset += newoffset + 24;
		}
		real8 llx, lly, urx, ury;
		const char *sptr = &postscript[offset + 14];
		
		// MW-2005-04-26: Remove 'const' to get it compiling using GCC 4.0 on MacOS X
		char *newptr;
		llx = strtod(sptr, &newptr);
		if (newptr != sptr)
		{
			sptr = newptr;
			lly = strtod(sptr, &newptr);
			if (newptr != sptr)
			{
				sptr = newptr;
				urx = strtod(sptr, &newptr);
				if (newptr != sptr)
				{
					sptr = newptr;
					ury = strtod(sptr, &newptr);
					if (newptr != sptr)
					{
						tx = (int2)llx;
						ty = (int2)lly;
						ex = (uint2)(urx - llx);
						ey = (uint2)(ury - lly);
					}
				}
			}
		}
	}
	offset = 0;
	uint4 newoffset = 0;
	pagecount = 0;
	while (MCU_offset("\n%%Page:", &postscript[offset], newoffset))
	{
		MCU_realloc((char **)&pageIndex, pagecount, pagecount + 1, sizeof(uint4));
		offset += newoffset + 1;
		pageIndex[pagecount] = offset;
		pagecount++;
	}
}
Exemple #7
0
Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
{
	Exec_errors t_error = EE_UNDEFINED;

	Meta::cstring_value t_prompt, t_initial, t_filter;
	Meta::cstring_value *t_types = NULL;
	char **t_type_strings = NULL;
	uint4 t_type_count = 0;
	
	
	
	t_error = Meta::evaluate(ep,
								file . prompt, t_prompt, EE_ANSWER_BADQUESTION,
								file . initial, t_initial, EE_ANSWER_BADRESPONSE,
								file . filter, t_filter, EE_ANSWER_BADRESPONSE);
	
	MCresult -> clear(False);

	if (!t_error && file . type_count > 0)
	{
		t_types = new Meta::cstring_value[file . type_count];
		for(uint4 t_type_index = 0; t_type_index < file . type_count && !t_error; ++t_type_index)
		{
			t_error = Meta::evaluate(ep, file . types[t_type_index], t_types[t_type_index], EE_ANSWER_BADRESPONSE);
			if (!t_error)
				for(char *t_type_string = strtok(*t_types[t_type_index], "\n"); t_type_string != NULL; t_type_string = strtok(NULL, "\n"))
				{
					MCU_realloc((char **)&t_type_strings, t_type_count, t_type_count + 1, sizeof(char *));
					t_type_strings[t_type_count++] = t_type_string;
				}
		}
	}

	// Now we have checked all parameters, we check for access.
	if (!t_error && !MCSecureModeCanAccessDisk())
		t_error = EE_DISK_NOPERM;

	if (!t_error)
	{
		if (MCsystemFS && MCscreen -> hasfeature ( PLATFORM_FEATURE_OS_FILE_DIALOGS ) )
		{
			unsigned int t_options = 0;
			if (sheet)
				t_options |= MCA_OPTION_SHEET;
			if (mode == AT_FILES)
				t_options |= MCA_OPTION_PLURAL;

			if (t_types != NULL)
				MCA_file_with_types(ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial, t_options);
			else
				MCA_file(ep, p_title, t_prompt, t_filter, t_initial, t_options);
		}
		else
		{
			MCExecPoint ep2(ep);
			ep2 . clear();
			for(uint4 t_type = 0; t_type < t_type_count; ++t_type)
				ep2 . concatcstring(t_type_strings[t_type], EC_RETURN, t_type == 0);
			t_error = exec_custom(ep, MCfsnamestring, mode == AT_FILE ? "file" : "files", 5, p_title, *t_prompt, *t_filter, *t_initial, ep2 . getsvalue() . getstring());
		}
		
		if (ep . getsvalue() == MCnullmcstring && t_types == NULL)
			MCresult -> sets(MCcancelstring);
	}

	delete[] t_types;
	delete t_type_strings;

	return t_error;
}
Exemple #8
0
Parse_stat MCSwitch::parse(MCScriptPoint &sp)
{
	Symbol_type type;
	const LT *te;

	initpoint(sp);
	if (sp.next(type) == PS_NORMAL)
	{
		sp.backup();
		if (sp.parseexp(False, True, &cond) != PS_NORMAL)
		{
			MCperror->add
			(PE_SWITCH_BADCONDITION, sp);
			return PS_ERROR;
		}
	}
	else
		if (sp.skip_eol() != PS_NORMAL)
		{
			MCperror->add
			(PE_SWITCH_WANTEDENDSWITCH, sp);
			return PS_ERROR;
		}
	uint2 snum = 0;
	MCStatement *curstatement = NULL;
	MCStatement *newstatement = NULL;
	while (True)
	{
		switch (sp.next(type))
		{
		case PS_NORMAL:
			if (type == ST_DATA)
				newstatement = new MCEcho;
			else if (sp.lookup(SP_COMMAND, te) != PS_NORMAL)
			{
				if (type == ST_ID)
					newstatement = new MCComref(sp.gettoken_nameref());
				else
				{
					MCperror->add
					(PE_SWITCH_NOTCOMMAND, sp);
					return PS_ERROR;
				}
			}
			else
			{
				switch (te->type)
				{
				case TT_STATEMENT:
					newstatement = MCN_new_statement(te->which);
					break;
				case TT_CASE:
					MCU_realloc((char **)&cases, ncases, ncases + 1,
					            sizeof(MCExpression *));
					if (sp.parseexp(False, True, &cases[ncases]) != PS_NORMAL)
					{
						MCperror->add
						(PE_SWITCH_BADCASECONDITION, sp);
						return PS_ERROR;
					}
					MCU_realloc((char **)&caseoffsets, ncases, ncases + 1,
					            sizeof(uint2));
					caseoffsets[ncases++] = snum;
					continue;
				case TT_DEFAULT:
					defaultcase = snum;
					continue;
				case TT_END:
					if (sp.skip_token(SP_COMMAND, TT_STATEMENT, S_SWITCH) != PS_NORMAL)
					{
						MCperror->add
						(PE_SWITCH_WANTEDENDSWITCH, sp);
						return PS_ERROR;
					}
					return PS_NORMAL;
				default: /* token type */
					MCperror->add
					(PE_SWITCH_BADCASECONDITION, sp);
					return PS_ERROR;
				}
			}
			break;
		case PS_EOL:
			if (sp.skip_eol() != PS_NORMAL)
			{
				MCperror->add
				(PE_SWITCH_WANTEDENDSWITCH, sp);
				return PS_ERROR;
			}
			continue;
		case PS_EOF:
			return PS_NORMAL;
		default:
			MCperror->add
			(PE_SWITCH_BADTYPE, sp);
			return PS_ERROR;
		}
		if (newstatement->parse(sp) != PS_NORMAL)
		{
			MCperror->add
			(PE_SWITCH_BADSTATEMENT, sp);
			delete newstatement;
			return PS_ERROR;
		}
		if (statements == NULL)
			statements = curstatement = newstatement;
		else
		{
			curstatement->setnext(newstatement);
			curstatement = newstatement;
		}
		snum++;
	}
	return PS_NORMAL;
}