Beispiel #1
0
int main(int argc, char *argv[])
{
    int ret;
    FILE *fp;
    Instruction start = {
        .instruction = I_NOP,
        .next_instruction = NULL,
        .alt_instruction = NULL
    };
    Variables global_vars;

    if (argc != 2 || (fp = fopen(argv[1], "rb")) == NULL)
    {
		debug("Cannot open file.\n");
        return print_error(INTERNAL_ERROR);
	}

    variables_init(&global_vars);

	debug("calling PARSE\n");
    if ((ret = parse(fp, &start, &global_vars)) == SUCCESS)
    {
		debug("PARSE ok\n\n");

#ifdef DEBUG
		debug("\n========================PRINTING GLOBAL VARIABLES==========================\n");
		variables_print(&global_vars);
		fprintf(stderr, "\n===========================================================================\n\n");
		debug("\n===========================PRINTING INSTRUCTION============================\n");
		debug_print_instruction(&start);
		fprintf(stderr, "\n===========================================================================\n\n");
#endif

		debug("calling INTERPRETER\n");
		if ((ret = interpret(&start, &global_vars)) == SUCCESS)
		{
			debug("INTERPRETER OK\n");
		}
		else
		{
			debug("INTERPRETER: NOT success return code\n");
		}
	}
	else
	{
		debug("PARSER: NOT success return code\n");
	}

    fclose(fp);
    variables_free(&global_vars);
    free_instr();
    cstr_gc_free_all();

	debug("MAIN RETURN CODE is: [ %d ]\n", ret);
    return print_error(ret);
}
// Get the text based on the settings for a especific line
void Cache_GetLineText(struct ClcContact *contact, int type, LPTSTR text, int text_size, TCHAR *variable_text, BOOL xstatus_has_priority, BOOL show_status_if_no_away, BOOL use_name_and_message_for_xstatus, BOOL contact_time_show_only_if_different)
{
	text[0] = '\0';
	switch(type)
	{
	case TEXT_STATUS:
		{
			if (GetStatusName(text, text_size, contact, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus)
			{
				DBVARIANT dbv;

				// Try to get XStatusMsg
				if (!DBGetContactSettingTString(contact->hContact, contact->proto, "XStatusMsg", &dbv)) 
				{
					if (dbv.ptszVal != NULL && dbv.ptszVal[0] != 0)
					{
						TCHAR *tmp = mir_strdupT(text);
						mir_sntprintf(text, text_size, TEXT("%s: %s"), tmp, dbv.pszVal);
						mir_free(tmp);
					}
					DBFreeVariant(&dbv);
				}
			}

			break;
		}
	case TEXT_NICKNAME:
		{
			if (contact->hContact && contact->proto)
			{
				DBVARIANT dbv;
				if (!DBGetContactSettingTString(contact->hContact, contact->proto, "Nick", &dbv)) 
				{
					lstrcpyn(text, dbv.ptszVal, text_size);
					DBFreeVariant(&dbv);
				}
			}
			break;
		}
	case TEXT_STATUS_MESSAGE:
		{
			if (GetStatusMessage(text, text_size, contact, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus)
			{
				DBVARIANT dbv;

				// Try to get XStatusName
				if (!DBGetContactSettingTString(contact->hContact, contact->proto, "XStatusName", &dbv)) 
				{
					if (dbv.pszVal != NULL && dbv.pszVal[0] != 0)
					{
						TCHAR *tmp = mir_strdupT(text);
						mir_sntprintf(text, text_size, TEXT("%s: %s"), dbv.pszVal, tmp);
						mir_free(tmp);
					}
					DBFreeVariant(&dbv);
				}
			}

			break;
		}
	case TEXT_TEXT:
		{
#ifndef UNICODE	
			if (!ServiceExists(MS_VARS_FORMATSTRING))
			{
				lstrcpyn(text, variable_text, text_size);
			}
			else
			{
				char *tmp = variables_parse(variable_text, contact->szText, contact->hContact);
				lstrcpyn(text, tmp, text_size);
				variables_free(tmp);
			}
#else
			lstrcpyn(text, variable_text, text_size);
#endif
			break;
		}
	case TEXT_CONTACT_TIME:
		{
			if (contact->timezone != -1 && (!contact_time_show_only_if_different || contact->timediff != 0))
			{
				// Get contact time
				DBTIMETOSTRINGT dbtts;
				time_t contact_time;

				contact_time = time(NULL) - contact->timediff;
				text[0] = '\0';

				dbtts.szDest = text;
				dbtts.cbDest = 70;
				dbtts.szFormat = TEXT("t");
				CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, contact_time, (LPARAM) & dbtts);
			}

			break;
		}
	}
	if (type==TEXT_STATUS_MESSAGE && show_status_if_no_away && text[0] == '\0')
	{
		//re-request status if no away
		Cache_GetLineText(contact, TEXT_STATUS, text, text_size, variable_text, xstatus_has_priority,0, use_name_and_message_for_xstatus, contact_time_show_only_if_different);		
	}

}
Beispiel #3
0
void Protocol::GetStatusMsg(int aStatus, char *msg, size_t msg_size)
{
	if (!CanGetStatusMsg())
	{
		lstrcpyn(msg, "", msg_size);
		return;
	}

	bool isCurrentStatus = (aStatus == GetStatus());

	if (isCurrentStatus && CanCall(PS_GETMYAWAYMSG))
	{
		char *tmp = (char *) Call(PS_GETMYAWAYMSG);
		lstrcpyn(msg, tmp == NULL ? "" : tmp, msg_size);
	}
	else if (isCurrentStatus && ServiceExists(MS_SA_ISSARUNNING) && CallService(MS_SA_ISSARUNNING, 0, 0)) 
	{
		char *tmp = (char *) CallService(MS_AWAYMSG_GETSTATUSMSG, (WPARAM) ID_STATUS_CURRENT, (LPARAM) name.c_str());

		if (tmp != NULL)
		{
			lstrcpyn(msg, tmp, msg_size);
			mir_free(tmp);
		}
		else lstrcpyn(msg, "", msg_size);
		
	}
	else if (ServiceExists(MS_NAS_GETSTATE))
	{
		NAS_PROTOINFO pi;

		ZeroMemory(&pi, sizeof(pi));
		pi.cbSize = sizeof(NAS_PROTOINFO);
		pi.szProto = (char *) name.c_str();
		pi.status = (isCurrentStatus ? 0 : aStatus);
		pi.szMsg = NULL;

		if (CallService(MS_NAS_GETSTATE, (WPARAM) &pi, 1) == 0)
		{
			if (pi.szMsg == NULL)
			{
				pi.szProto = NULL;

				if (CallService(MS_NAS_GETSTATE, (WPARAM) &pi, 1) == 0)
				{
					if (pi.szMsg != NULL)
					{
						lstrcpyn(msg, pi.szMsg, msg_size);
						mir_free(pi.szMsg);
					}
					else lstrcpyn(msg, "", msg_size);
				}
				else lstrcpyn(msg, "", msg_size);
			}
			else // if (pi.szMsg != NULL)
			{
				lstrcpyn(msg, pi.szMsg, msg_size);
				mir_free(pi.szMsg);
			}
		}
		else lstrcpyn(msg, "", msg_size);

		if (ServiceExists(MS_VARS_FORMATSTRING))
		{
			char *tmp = variables_parse(msg, NULL, NULL);
			lstrcpyn(msg, tmp, msg_size);
			variables_free(tmp);
		}
	}
	// TODO: Remove when removing old NAS services support
	else if (ServiceExists("NewAwaySystem/GetState"))
	{
		NAS_PROTOINFO pi, *pii;

		ZeroMemory(&pi, sizeof(pi));
		pi.cbSize = sizeof(NAS_PROTOINFO);
		pi.szProto = (char *) name.c_str();
		pi.status = (isCurrentStatus ? 0 : aStatus);
		pi.szMsg = NULL;

		pii = π

		if (CallService("NewAwaySystem/GetState", (WPARAM) &pii, 1) == 0)
		{
			if (pi.szMsg == NULL)
			{
				pi.szProto = NULL;

				if (CallService("NewAwaySystem/GetState", (WPARAM) &pii, 1) == 0)
				{
					if (pi.szMsg != NULL)
					{
						lstrcpyn(msg, pi.szMsg, msg_size);
						mir_free(pi.szMsg);
					}
					else lstrcpyn(msg, "", msg_size);
				}
				else lstrcpyn(msg, "", msg_size);
			}
			else // if (pi.szMsg != NULL)
			{
				lstrcpyn(msg, pi.szMsg, msg_size);
				mir_free(pi.szMsg);
			}
		}
		else lstrcpyn(msg, "", msg_size);

		if (ServiceExists(MS_VARS_FORMATSTRING))
		{
			char *tmp = variables_parse(msg, NULL, NULL);
			lstrcpyn(msg, tmp, msg_size);
			variables_free(tmp);
		}
	}
	else if (ServiceExists(MS_AWAYMSG_GETSTATUSMSG))
	{
		char *tmp = (char *) CallService(MS_AWAYMSG_GETSTATUSMSG, (WPARAM)aStatus, 0);

		if (tmp != NULL)
		{
			lstrcpyn(msg, tmp, msg_size);
			mir_free(tmp);
		}
		else lstrcpyn(msg, "", msg_size);
	}
}