// Not ideal - convert list to array, sort it, convert to list again
Item * Sort(Item *MI)
{
    Item *i, **a; int n;
    n=0; dolist(i, MI) n++;
    a = (Item**)m_alloc(n*sizeof(Item*));
    n=0; dolist(i, MI) a[n]=i, n++;
    qsort(a, n, sizeof(Item*), (int(*)(const void*,const void*))cmp_fn);
    for (i=NULL;n;) a[--n]->next=i, i=a[n];
    m_free(a);
    return i;
}
Example #2
0
MenuItem * MenuItem::Sort(int(__cdecl *cmp_fn)(MenuItem**,MenuItem**))
{
	MenuItem *item; int n = 0;
	dolist(item, this) n++;  // get size
	if (n < 2) return this;
	MenuItem **a = (MenuItem**)m_alloc(n * sizeof item); // make array
	n = 0; dolist(item, this) a[n] = item, n++; // store pointers
	qsort(a, n, sizeof *a, (int(__cdecl *)(const void*,const void*))cmp_fn);
	do a[--n]->next = item, item = a[n]; while (n); // make list
	m_free(a); // free array
	return item;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//module_shutdown
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int module_shutdown()
{
	listnode *ln, *ln2;

	//Destroy contained controls
	dolist (ln2, globalmodule.controllist_parentsonly)
	control_destroy((control *) ln2->value, false, false);
	dolist (ln, modulelist)
	{
		module *m = (module *) ln->value;
		if (m->enabled)
			dolist (ln2, m->controllist_parentsonly)
			control_destroy((control *) ln2->value, false, false);
	}
Example #4
0
/*
 * mreadvar - send a read variables request for multiple associations
 */
static void
mreadvar(
	struct parse *pcmd,
	FILE *fp
	)
{
	int i;
	int from;
	int to;
	struct varlist tmplist[MAXLIST];
	struct varlist *pvars;

	/* HMS: uval? */
	if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval,
				&from, &to))
		return;

	if (pcmd->nargs >= 3) {
		memset(tmplist, 0, sizeof(tmplist));
		doaddvlist(tmplist, pcmd->argval[2].string);
		pvars = tmplist;
	} else {
		pvars = g_varlist;
	}

	for (i = from; i <= to; i++) {
		if (i != from)
			fprintf(fp, "\n");
		if (!dolist(pvars, (int)assoc_cache[i].assid,
			    CTL_OP_READVAR, TYPE_PEER, fp))
			break;
	}
	doclearvlist(tmplist);
	return;
}
Example #5
0
/*
 * readvar - send a read variables request with the specified variables
 */
static void
readvar(
	struct parse *pcmd,
	FILE *fp
	)
{
	associd_t	associd;
	int		type;
	struct varlist	tmplist[MAXLIST];


	/* HMS: uval? */
	if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0)
		associd = 0;
	else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
		return;

	memset(tmplist, 0, sizeof(tmplist));
	if (pcmd->nargs >= 2)
		doaddvlist(tmplist, pcmd->argval[1].string);

	type = (0 == associd)
		   ? TYPE_SYS
		   : TYPE_PEER;
	dolist(tmplist, associd, CTL_OP_READVAR, type, fp);

	doclearvlist(tmplist);
}
Example #6
0
void free_nls(void)
{
	struct nls *t;
	dolist (t, pNLS) free_str(&t->translation);
	freeall(&pNLS);
	nls_loaded = false;
}
Example #7
0
void ShowExplorer(void)
{
    struct hwnd_list *p;
    dolist (p, basebarlist)
        ShowWindow(p->hwnd, SW_SHOW);
    freeall(&basebarlist);
}
Example #8
0
//================================================
struct pidl_node *copy_pidl_list(const struct pidl_node *old_pidl_list)
{
	const struct pidl_node *p;
	struct pidl_node *new_pidl_list = NULL;
	dolist (p, old_pidl_list)
		append_node(&new_pidl_list, new_node(duplicateIDlist(p->v)));
	return new_pidl_list;
}
Example #9
0
//===========================================================================
void PluginManager_Exit()
{
    reverse_list(&bbplugins);
    struct plugins *q;
    dolist(q, bbplugins) q->enabled = false;
    load_all_plugins();
    freeall(&bbplugins);
}
Example #10
0
//================================================
void SpecialFolder::UpdateFolder(void)
{
	// ---------------------------------------
	// remember the active item as text

	MenuItem *ActiveItem = m_pActiveItem;
	TCHAR *active_item_text = NULL;

	m_pLastChild = m_pChild;
	if (m_pLastChild) ActiveItem = m_pLastChild->m_pParentItem;
	if (ActiveItem) active_item_text = new_str(ActiveItem->m_pszTitle);

	// delete_old items
	DeleteMenuItems();

	// load the folder contents
	MenuItem *Items = NULL; int r = 0;

	struct pidl_node *p;
	dolist (p, m_pidl_list)
		r |= MenuMaker_LoadFolder(&Items, p->v, m_pszExtra);

	if (Items) add_folder_contents(Items, NULL != m_pidl_list->next);
	else if (r) MakeMenuNOP(this, NLS0(_T("No Files")));
	else MakeMenuNOP(this, NLS0(_T("Invalid Path")));

	// ---------------------------------------
	// search by text the previously active item

	if (active_item_text)
	{
		dolist (ActiveItem, m_pMenuItems)
			if (0 == _tcscmp(active_item_text, ActiveItem->m_pszTitle))
				break;

		free_str(&active_item_text);
	}

	// ---------------------------------------
	// possibly reconnect to an open child-folder

	if (m_pLastChild)
	{
		if (ActiveItem)
		{
			m_pLastChild->incref();
			ActiveItem->LinkSubmenu(m_pLastChild);
			m_pLastChild->LinkToParentItem(ActiveItem);
		}
		else
		{
			m_pLastChild->Hide(); // lost child
		}
		m_pLastChild = NULL;
	}

	if (ActiveItem) ActiveItem->Active(2);
}
Example #11
0
//===========================================================================
void MessageManager_Exit(void)
{
    // Well, if all plugins behave correctly and unregister their messages,
    // there should be nothing left to do here
    struct MsgMap *mm;
    dolist (mm, msgs)
        freeall(&mm->winmap);
    freeall(&msgs);
}
Example #12
0
File: aoi.c Project: lhw/wargame
int
handlecommand(int c, char *buf)
{
	char *msg = "unknown command\n";
	switch(whatcmd(buf)) {
	case CMD_LIST:
		dolist(c);
		break;
	case CMD_VIEW:
		doview(c, buf);
		break;
	case CMD_HELP:
		dohelp(c, buf);
		break;
	case CMD_NONE:
		send(c, msg, strlen(msg), 0);
		break;
	}
}
Example #13
0
/*
 * clocklist - send a clock variables request with the variables on the list
 */
static void
clocklist(
	struct parse *pcmd,
	FILE *fp
	)
{
	associd_t associd;

	/* HMS: uval? */
	if (pcmd->nargs == 0) {
		associd = 0;
	} else {
		if (pcmd->argval[0].uval == 0)
			associd = 0;
		else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
			return;
	}

	dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
}
Example #14
0
/*
 * clockvar - send a clock variables request with the specified variables
 */
static void
clockvar(
	struct parse *pcmd,
	FILE *fp
	)
{
	associd_t associd;
	struct varlist tmplist[MAXLIST];

	/* HMS: uval? */
	if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0)
		associd = 0;
	else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
		return;

	memset(tmplist, 0, sizeof(tmplist));
	if (pcmd->nargs >= 2)
		doaddvlist(tmplist, pcmd->argval[1].string);

	dolist(tmplist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);

	doclearvlist(tmplist);
}
Example #15
0
/*
 * readlist - send a read variables request with the variables on the list
 */
static void
readlist(
	struct parse *pcmd,
	FILE *fp
	)
{
	associd_t	associd;
	int		type;

	if (pcmd->nargs == 0) {
		associd = 0;
	} else {
	  /* HMS: I think we want the u_int32 target here, not the u_long */
		if (pcmd->argval[0].uval == 0)
			associd = 0;
		else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
			return;
	}

	type = (0 == associd)
		   ? TYPE_SYS
		   : TYPE_PEER;
	dolist(g_varlist, associd, CTL_OP_READVAR, type, fp);
}
Example #16
0
/*
 * mreadlist - send a read variables request for multiple associations
 */
static void
mreadlist(
	struct parse *pcmd,
	FILE *fp
	)
{
	int i;
	int from;
	int to;

	/* HMS: uval? */
	if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval,
				&from, &to))
		return;

	for (i = from; i <= to; i++) {
		if (i != from)
			(void) fprintf(fp, "\n");
		if (!dolist(g_varlist, (int)assoc_cache[i].assid,
				CTL_OP_READVAR, TYPE_PEER, fp))
			return;
	}
	return;
}
Example #17
0
static int unlist2 (struct arcdir *adp, const TCHAR *src, int all)
{
	struct zvolume *zv;
	struct zdirectory *h;
	int i;
	TCHAR p[MAX_DPATH];
	TCHAR fn[MAX_DPATH];
	struct arcdir *ad;

	zv = zfile_fopen_archive_root (src, ZFD_ALL);
	if (zv == NULL) {
		geterror();
		_tprintf (_T("Couldn't open archive '%s'\n"), src);
		return 0;
	}
	h = zfile_opendir_archive (src);
	if (!h) {
		_tcscpy (p, src);
		_tcscat (p, _T(".DIR"));
		h = zfile_opendir_archive (src);
		if (!h) {
			geterror();
			_tprintf (_T("Couldn't open directory '%s'\n"), src);
			return 0;
		}
	}

	while (zfile_readdir_archive (h, fn)) {
		struct mystat st; 
		int isdir;
		int flags;
		TCHAR *comment;
		struct zfile *zf;
		uae_u32 crc32 = 0;
		int iscrc = 0;
		int nextdir = -1;

		_tcscpy (p, src);
		_tcscat (p, sep);
		_tcscat (p, fn);
		if (!zfile_stat_archive (p, &st)) {
			st.size = -1;
			st.mtime.tv_sec = st.mtime.tv_usec = 0;
		}
		isdir = 0;
		flags = 0;
		comment = 0;
		zfile_fill_file_attrs_archive (p, &isdir, &flags, &comment);
		flags ^= 15;
		if (!isdir) {
			if (0 && st.size >= 2 * 1024 * 1024) {
				iscrc = -1;
			} else if (st.size > 0) {
				zf = zfile_open_archive (p, 0);
				if (zf) {
					crc32 = zfile_crc32 (zf);
					iscrc = 1;
				}
			}
		}

		ad = &adp[entries++];
		ad->isdir = isdir;
		ad->comment = comment;
		ad->flags = flags;
		ad->name = my_strdup (fn);
		ad->size = st.size;
		ad->dt = st.mtime.tv_sec;
		ad->parent = parentid;
		ad->crc32 = crc32;
		ad->iscrc = iscrc;

		if (isdir && all) {
			int oldparent = parentid;
			parentid = ad - adp;
			nextdir = parentid + 1;
			unlist2 (adp, p, all);
			parentid = oldparent;
		}

		ad->nextlevel = nextdir;

		if (entries >= maxentries)
			break;
	}
	if (parentid >= 0)
		return 1;

	filelist = xmalloc (struct arcdir*, entries);
	for (i = 0; i < entries; i++) {
		filelist[i] = &adp[i];
	}

	// bubblesort is the winner!
	for (i = 0; i < entries; i++) {
		int j;
		for (j = i + 1; j < entries; j++) {
			int diff = _tcsicmp (filelist[i]->name, filelist[j]->name);
			if (diff > 0) {
				struct arcdir *tmp;
				tmp = filelist[i];
				filelist[i] = filelist[j];
				filelist[j] = tmp;
			}
		}
	}

	dolist (filelist, adp, entries, -1, 0);
	zfile_closedir_archive (h);
	zfile_fclose_archive (zv);
	return 1;
}
Example #18
0
static void dolist (struct arcdir **filelist, struct arcdir *adp, int entries, int parent, int level)
{
	int ii, i;

	for (ii = 0; ii < 2; ii++) {
		for (i = 0; i < entries; i++) {
			struct arcdir *ad = filelist[i];
			int j;
			TCHAR protflags[9];
			TCHAR dates[32];
			TCHAR crcs[16];
			int flags;
			struct tm *dt;

			if (ad->parent != parent)
				continue;

			if ((ii == 0 && ad->isdir) || (ii == 1 && !ad->isdir)) {

				flags = ad->flags;

				if (flags >= 0) {
					for (j = 0; j < 8; j++) {
						protflags[j] = '-';
						if (flags & (1 << (7 - j)))
							protflags[j] = prots[j];
					}
					protflags[j] = 0;
				} else {
					_tcscpy (protflags, _T("--------"));
				}

				if (ad->dt > 0) {
					dt = _gmtime64 (&ad->dt);
					_tcsftime (dates, sizeof (dates) / sizeof (TCHAR), _T("%Y/%m/%d %H:%M:%S"), dt);
				} else {
					_tcscpy (dates, _T("-------------------"));
				}

				for (j = 0; j < level; j++)
					_tprintf (_T(" "));
				if (ad->iscrc > 0)
					_stprintf (crcs, _T("%08X"), ad->crc32);
				else if (ad->iscrc < 0)
					_tcscpy (crcs, _T("????????"));
				else
					_tcscpy (crcs, _T("--------"));
				if (ad->isdir > 0)
					_tprintf (_T("     [DIR] %s %s          %s\n"), protflags, dates, ad->name);
				else if (ad->isdir < 0)
					_tprintf (_T("    [VDIR] %s %s          %s\n"), protflags, dates, ad->name);
				else
					_tprintf (_T("%10I64d %s %s %s %s\n"), ad->size, protflags, dates, crcs, ad->name);
				if (ad->comment)
					_tprintf (_T(" \"%s\"\n"), ad->comment);
				if (ad->nextlevel >= 0) {
					level++;
					dolist (filelist, adp, entries, ad - adp, level);
					level--;
				}

			}
		}
	}
}
Example #19
0
static void dochatcommand(char *cmd)
{
	char *para;

	strtok(cmd, " \n");
	if ((para = strtok(NULL, "\n")) == NULL)
		para = cmd + strlen(cmd);

	if (*cmd == 'h')
	{
		printchatline(_msg_chat_41);
		printchatline("  /leave                  - Â÷¶}¥»ÀW¹D            [/le]");
		if (curuser.userlevel >= PERM_CLOAK)
			printchatline("  /cloak                  - Áô¨­                  [/cl]");
		printchatline(_msg_chat_43);
		return;
	}
	else if (!strcmp(cmd, "who") || !strcmp(cmd, "w"))
	{
		dowho(para, ac);
		return;
	}
	else if (!strcmp(cmd, "ws") || !strcmp(cmd, "whoall"))
	{
		dowhoall(ac);
		return;
	}
	else if (!strcmp(cmd, "list") || !strcmp(cmd, "l"))
	{
		dolist(ac);
		return;
	}
	else if (!strcmp(cmd, "leave") || !strcmp(cmd, "le"))
	{
		net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	}
	else if (!strcmp(cmd, "nopasswd") || !strcmp(cmd, "nps"))
	{
		net_printf(ac, "PASSWD\t%s\r\n", NOPASSWORD);
	}
	else if (!strcmp(cmd, "nick") || !strcmp(cmd, "n"))
	{

		fixchatid(para);

		net_printf(ac, "NICKNAME\t%s\r\n", para);
		net_gets(ac, genbuf, sizeof(genbuf));
		if (!strncmp(genbuf, "-ERR", 4))
			printchatline(genbuf + 5);
		else
		{
			xstrncpy(uinfo.chatid, para, sizeof(uinfo.chatid));
			update_ulist(cutmp, &uinfo);

			/* set prompt */
			strcpy(prompt, uinfo.chatid);
			strcat(prompt, ":           ");
			prompt[SAYWORD_POINT] = '\0';
		}
		return;
	}
	else if (!strcmp(cmd, "me"))
	{
		if (*para)
		{
			sprintf(genbuf, "*** %s ***", para);
			net_printf(ac, "SPEAK\t%s\r\n", genbuf);
			printchatline(genbuf);
		}
		else
			printchatline(_msg_chat_45);
		return;
	}
	else if (!strcmp(cmd, "pager") || !strcmp(cmd, "p"))
	{
#if 1
		add_io(0, 0);
#endif
		toggle_pager();
		printchatline(pagerstring(&uinfo));
#if 1
		add_io(ac, 0);
#endif
		return;
	}
	else if (!strcmp(cmd, "cloak") || !strcmp(cmd, "cl"))
	{
		if (HAS_PERM(PERM_CLOAK))
		{
			net_printf(ac, "CLOAK\r\n");
			net_gets(ac, genbuf, sizeof(genbuf));
			if (!strncmp(genbuf, "-ERR", 4))
				printchatline(genbuf + 5);
			else
			{
				uinfo.invisible = (uinfo.invisible) ? FALSE : TRUE;
				update_ulist(cutmp, &uinfo);
				if (!uinfo.invisible)
					printchatline("*** Cloak has been deactivated");
				else
					printchatline("*** Cloak has been activated");
			}
		}
		else
			printchatline("*** ERROR: unknown special chat command");
		return;
	}
	else if (!strcmp(cmd, "clear") || !strcmp(cmd, "c"))
	{
		clear();
		move(ECHATWIN, 0);
		outs("________________________________________________________________________________");
		chat_line = 0;	/* reset */
		printchatline(_msg_chat_46);
		return;
	}
	else if (!strcmp(cmd, "ignore") || !strcmp(cmd, "i"))
	{
		if (*para)
		{
			if (strlen(para) >= IDLEN)
				para[IDLEN - 1] = '\0';
			if (!cmp_wlist(iglist, para, strcmp))
			{
				sprintf(genbuf, _msg_chat_37, para);
				printchatline(genbuf);
				add_wlist(&iglist, para, malloc_str);
			}
		}
		return;
	}
	else if (!strcmp(cmd, "unignore") || !strcmp(cmd, "ui"))
	{
		if (*para)
		{
			if (strlen(para) >= IDLEN)
				para[IDLEN - 1] = '\0';
			if (cmp_wlist(iglist, para, strcmp))
			{
				sprintf(genbuf, _msg_chat_36, para);
				printchatline(genbuf);
				cmpd_wlist(&iglist, para, strcmp, free);
			}
		}
		return;
	}
	else if (!strcmp(cmd, "j") || !strcmp(cmd, "join"))
	{
		char *para2;

		para = strtok(para, " \n");
		if (!para)
			return;

		para2 = strtok(NULL, " \n");
		if (!para2)
			net_printf(ac, "JOIN\t%s\t%s\r\n", para, NOPASSWORD);
		else
			net_printf(ac, "JOIN\t%s\t%s\r\n", para, para2);
	}
	else if (!strcmp(cmd, "m") || !strcmp(cmd, "msg"))
	{
		char *para2;

		para = strtok(para, " \n");
		para2 = strtok(NULL, "");
		if (!para || !para2)
			return;

		net_printf(ac, "MSG\t%s\t%s\r\n", para, para2);
	}
	else if (!strcmp(cmd, "t") || !strcmp(cmd, "topic"))
	{
		net_printf(ac, "TOPIC\t%s\r\n", para);
	}
	else if (!strcmp(cmd, "ps") || !strcmp(cmd, "passwd"))
	{
		net_printf(ac, "PASSWD\t%s\r\n", para);
	}
	else
	{
		printchatline("*** ERROR: unknown special chat command");
		return;
	}

	net_gets(ac, genbuf, sizeof(genbuf));
	if (!strncmp(genbuf, "-ERR", 4))
	{
		genbuf[strlen(genbuf) - 1] = '\0';
		printchatline(genbuf + 5);
	}
}
Example #20
0
//================================================
void delete_pidl_list (struct pidl_node **ppList)
{
	struct pidl_node *p;
	dolist (p, *ppList) m_free(p->v);
	freeall(ppList);
}