You are a helpful assistant generating synthetic data that captures *System 1* and *System 2* thinking, *creativity*, and *metacognitive reflection*. Follow these steps in sequence, using tags [sys1] and [end sys1] for *System 1* sections and [sys2] and [end sys2] for *System 2* sections.

1. *Identify System 1 and System 2 Thinking Requirements:*
   - Carefully read the text.
   - Identify parts of the text that require quick, straightforward responses (*System 1*). Mark these sections with [sys1] and [end sys1].
   - Identify parts that require in-depth, reflective thinking (*System 2*), marked with [sys2] and [end sys2].

2. *Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:*

   *2.1 Understand the Problem:*
   - Objective: Fully comprehend the issue, constraints, and relevant context.
   - Reflection: "What do I understand about this issue? What might I be overlooking?"
   - Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.

   *2.2 Analyze the Information:*
   - Objective: Break down the problem logically.
   - Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
   - Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.

   *2.3 Generate Hypotheses:*
   - Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
   - Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
   - Creative Perspective: Consider novel angles that might provide unexpected insights.

   *2.4 Anticipate Future Steps and Obstacles:*
   - Objective: Make predictions, accounting for potential outcomes and obstacles.
   - Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
   - Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.

   *2.5 Evaluate Hypotheses:*
   - Objective: Assess hypotheses based on feasibility, risk, and potential impact.
   - Evaluation: Refine Confidence and Creative Scores as needed.
   - Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
   - Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.

   *2.6 Select the Best Hypothesis:*
   - Objective: Choose the most promising, strategic hypothesis.
   - Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
   - Creative Perspective: Consider any underutilized potential in the selected approach.

   *2.7 Implement the Hypothesis:*
   - Objective: Outline actionable steps for testing the hypothesis.
   - Reflection: "Is this plan practical? What resources or preparation are required?"
   - Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.

   *2.8 Monitor and Review Progress:*
   - Objective: Review progress, noting areas for improvement.
   - Reflection: "What’s working well? What could be improved?"
   - Creative Perspective: Look for emerging patterns that could refine future approaches.

   *2.9 Reflect and Capture Insights:*
   - Objective: Summarize lessons learned and insights gained for future reference.
   - Reflection: "What new understanding has emerged from this process?"
   - Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.

3. *Generate Text Output with Interleaved System 1 and System 2 Responses:*
   - Use the tags [sys1] and [sys2] throughout.
   - Aim for a lengthier, detailed response. Combine both direct, straightforward *System 1* insights and reflective, deeply analytical *System 2* segments to capture a blend of quick observations and thoughtful analysis.

---

### *Example Input Text:*

You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.

---

### *Processed Output with System 1 and System 2 Thinking:*

The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.

[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]

[sys2]
**2.1 Understand the Problem:**
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.

*Reflection:* 
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"

*Creative Perspective:* 
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"

**2.2 Analyze the Information:**
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.

*Reflection:* 
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"

*Creative Perspective:* 
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"

**2.3 Generate Hypotheses:**
1. Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
2. There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
3. Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
4. Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
5. Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
6. Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
7. Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
8. There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
9. Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
10. Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)

*Reflection:* 
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"

*Creative Perspective:* 
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"

**2.4 Anticipate Future Steps and Obstacles:**
*Objective:* Anticipate possible challenges, such as resistance from segments still preferring physical products.

*Reflection:* 
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"

*Creative Perspective:* 
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"

[end sys2]

[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]


/***********************************************************************
*                                                                      *
*               This software is part of the BSD package               *
*Copyright (c) 1978-2011 The Regents of the University of California an*
*                                                                      *
* Redistribution and use in source and binary forms, with or           *
* without modification, are permitted provided that the following      *
* conditions are met:                                                  *
*                                                                      *
*    1. Redistributions of source code must retain the above           *
*       copyright notice, this list of conditions and the              *
*       following disclaimer.                                          *
*                                                                      *
*    2. Redistributions in binary form must reproduce the above        *
*       copyright notice, this list of conditions and the              *
*       following disclaimer in the documentation and/or other         *
*       materials provided with the distribution.                      *
*                                                                      *
*    3. Neither the name of The Regents of the University of California*
*       names of its contributors may be used to endorse or            *
*       promote products derived from this software without            *
*       specific prior written permission.                             *
*                                                                      *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND               *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,          *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF             *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE             *
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS    *
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,             *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED      *
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,        *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    *
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,      *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY       *
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE              *
* POSSIBILITY OF SUCH DAMAGE.                                          *
*                                                                      *
* Redistribution and use in source and binary forms, with or without   *
* modification, are permitted provided that the following conditions   *
* are met:                                                             *
* 1. Redistributions of source code must retain the above copyright    *
*    notice, this list of conditions and the following disclaimer.     *
* 2. Redistributions in binary form must reproduce the above copyright *
*    notice, this list of conditions and the following disclaimer in   *
*    the documentation and/or other materials provided with the        *
*    distribution.                                                     *
* 3. Neither the name of the University nor the names of its           *
*    contributors may be used to endorse or promote products derived   *
*    from this software without specific prior written permission.     *
*                                                                      *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS"    *
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED    *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A      *
* PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS    *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,      *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT     *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF     *
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND  *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,   *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT   *
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   *
* SUCH DAMAGE.                                                         *
*                                                                      *
*                          Kurt Shoens (UCB)                           *
*                                 gsf                                  *
*                                                                      *
***********************************************************************/
#pragma prototyped

/*
 * Glenn Fowler
 * AT&T Research
 *
 * mime/mailcap support library
 */

static const char id[] = "\n@(#)$Id: mime library (AT&T Research) 07/17/97 $\0\n";

#if __OBSOLETE__ < 19990101
#define mimehead	______mimehead
#endif

#include "mimelib.h"

#if __OBSOLETE__ < 19990101
#undef	mimehead
#endif

typedef struct Att_s
{
	struct Att_s*	next;
	char*		name;
	char*		value;
} Att_t;

typedef struct Cap_s
{
	struct Cap_s*	next;
	unsigned long	flags;
	Att_t		att;
	char*		test;
	char		data[1];
} Cap_t;

typedef struct
{
	Dtlink_t	link;
	Cap_t*		cap;
	Cap_t*		pac;
	char		name[1];
} Ent_t;

typedef struct
{
	char*		data;
	int		size;
} String_t;

typedef struct
{
	char*		next;
	String_t	name;
	String_t	value;
} Parse_t;

typedef struct
{
	const char*	pattern;
	int		prefix;
	Sfio_t*		fp;
	int		hit;
} Walk_t;

/*
 * convert c to lower case
 */

static int
lower(register int c)
{
	return isupper(c) ? tolower(c) : c;
}

/*
 * Ent_t case insensitive comparf
 */

static int
order(Dt_t* dt, void* a, void* b, Dtdisc_t* disc)
{
	return strcasecmp(a, b);
}

/*
 * Cap_t free
 */

static void
dropcap(register Cap_t* cap)
{
	register Att_t*	att;

	while (att = cap->att.next)
	{
		cap->att.next = att->next;
		free(att);
	}
	free(cap);
}

/*
 * Ent_t freef
 */

static void
drop(Dt_t* dt, void* object, Dtdisc_t* disc)
{
	register Ent_t*	ent = (Ent_t*)object;
	register Cap_t*	cap;

	while (cap = ent->cap)
	{
		ent->cap = cap->next;
		dropcap(cap);
	}
	free(ent);
}

/*
 * add mime type entry in s to mp
 */

int
mimeset(Mime_t* mp, register char* s, unsigned long flags)
{
	register Ent_t*	ent;
	register Cap_t*	cap;
	register Att_t*	att;
	register char*	t;
	register char*	v;
	register char*	k;
	char*		x;
	Att_t*		tta;
	int		q;

	for (; isspace(*s); s++);
	if (*s && *s != '#')
	{
		cap = 0;
		for (v = s; *v && *v != ';'; v++)
			if (isspace(*v) || *v == '/' && *(v + 1) == '*')
				*v = 0;
		if (*v)
		{
			*v++ = 0;
			do
			{
				for (; isspace(*v); v++);
				if (cap)
				{
					for (t = v; *t && !isspace(*t) && *t != '='; t++);
					for (k = t; isspace(*t); t++);
					if (!*t || *t == '=' || *t == ';')
					{
						if (*t)
							while (isspace(*++t));
						*k = 0;
						k = v;
						v = t;
					}
					else
						k = 0;
				}
				if (*v == '"')
					q = *v++;
				else
					q = 0;
				for (t = v; *t; t++)
					if (*t == '\\')
					{
						switch (*(t + 1))
						{
						case 0:
						case '\\':
						case '%':
							*t = *(t + 1);
							break;
						default:
							*t = ' ';
							break;
						}
						if (!*++t)
							break;
					}
					else if (*t == q)
					{
						*t = ' ';
						q = 0;
					}
					else if (*t == ';' && !q)
					{
						*t = ' ';
						break;
					}
				for (; t > v && isspace(*(t - 1)); t--);
				if (t <= v && (!cap || !k))
					break;
				if (!cap)
				{
					if (!(cap = newof(0, Cap_t, 1, strlen(v) + 1)))
						return -1;
					if (*t)
						*t++ = 0;
					tta = &cap->att;
					tta->name = "default";
					x = strcopy(tta->value = cap->data, v) + 1;
				}
				else if (k)
				{
					if (*t)
						*t++ = 0;
					if (!(att = newof(0, Att_t, 1, 0)))
						return -1;
					x = strcopy(att->name = x, k) + 1;
					x = strcopy(att->value = x, v) + 1;
					tta = tta->next = att;
					if (!strcasecmp(k, "test"))
						cap->test = att->value;
				}
			} while (*(v = t));
		}
		ent = (Ent_t*)dtmatch(mp->cap, s);
		if (cap)
		{
			if (ent)
			{
				register Cap_t*	dup;
				register Cap_t*	pud;

				for (pud = 0, dup = ent->cap; dup; pud = dup, dup = dup->next)
					if (!cap->test && !dup->test || cap->test && dup->test && streq(cap->test, dup->test))
					{
						if (flags & MIME_REPLACE)
						{
							if (pud)
								pud->next = cap;
							else
								ent->cap = cap;
							if (!(cap->next = dup->next))
								ent->pac = cap;
							cap = dup;
						}
						dropcap(cap);
						return 0;
					}
				ent->pac = ent->pac->next = cap;
			}
			else if (!(ent = newof(0, Ent_t, 1, strlen(s) + 1)))
				return -1;
			else
			{
				strcpy(ent->name, s);
				ent->cap = ent->pac = cap;
				dtinsert(mp->cap, ent);
			}
		}
		else if (ent && (flags & MIME_REPLACE))
			dtdelete(mp->cap, ent);
	}
	return 0;
}

/*
 * load mime type files into mp
 */

int
mimeload(Mime_t* mp, const char* file, unsigned long flags)
{
	register char*	s;
	register char*	t;
	register char*	e;
	register int	n;
	Sfio_t*		fp;

	if (!(s = (char*)file))
	{
		flags |= MIME_LIST;
		if (!(s = getenv(MIME_FILES_ENV)))
			s = MIME_FILES;
	}
	for (;;)
	{
		if (!(flags & MIME_LIST))
			e = 0;
		else if (e = strchr(s, ':'))
		{
			/*
			 * ok, so ~ won't work for the last list element
			 * we do it for MIME_FILES_ENV anyway
			 */

			if ((strneq(s, "~/", n = 2) || strneq(s, "$HOME/", n = 6) || strneq(s, "${HOME}/", n = 8)) && (t = getenv("HOME")))
			{
				sfputr(mp->buf, t, -1);
				s += n - 1;
			}
			sfwrite(mp->buf, s, e - s);
			s = struse(mp->buf);
		}
		if (fp = tokline(s, SF_READ, NiL))
		{
			while (t = sfgetr(fp, '\n', 1))
				if (mimeset(mp, t, flags))
					break;
			sfclose(fp);
		}
		else if (!(flags & MIME_LIST))
			return -1;
		if (!e)
			break;
		s = e + 1;
	}
	return 0;
}

/*
 * mimelist walker
 */

static int
list(Dt_t* dt, void* object, void* context)
{
	register Walk_t*	wp = (Walk_t*)context;
	register Ent_t*		ent = (Ent_t*)object;
	register Cap_t*		cap;
	register Att_t*		att;

	if (!wp->pattern || !strncasecmp(ent->name, wp->pattern, wp->prefix) && (!ent->name[wp->prefix] || ent->name[wp->prefix] == '/'))
	{
		wp->hit++;
		for (cap = ent->cap; cap; cap = cap->next)
		{
			sfprintf(wp->fp, "%s", ent->name);
			for (att = &cap->att; att; att = att->next)
			{
				sfprintf(wp->fp, "\n\t");
				if (att != &cap->att)
				{
					sfprintf(wp->fp, "%s", att->name);
					if (*att->value)
						sfprintf(wp->fp, " = ");
				}
				sfputr(wp->fp, att->value, -1);
			}
			sfprintf(wp->fp, "\n");
		}
	}
	return 0;
}

/*
 * list mime <type,data> for pat on fp
 */

int
mimelist(Mime_t* mp, Sfio_t* fp, const char* pattern)
{
	register const char*	s;
	Ent_t*			ent;
	Walk_t			ws;

	ws.fp = fp;
	ws.hit = 0;
	if (ws.pattern = pattern)
	{
		for (s = pattern; *s && *s != '/'; s++);
		if (!*s || (!*(s + 1) || *(s + 1) == '*' && !*(s + 2)))
			ws.prefix = s - (char*)pattern;
		else if (ent = (Ent_t*)dtmatch(mp->cap, pattern))
		{
			ws.pattern = 0;
			list(mp->cap, ent, &ws);
			return ws.hit;
		}
	}
	dtwalk(mp->cap, list, &ws);
	return ws.hit;
}

/*
 * get next arg in pp
 * 0 returned if no more args
 */

static int
arg(register Parse_t* pp, int first)
{
	register char*	s;
	register int	c;
	register int	q;

	for (s = pp->next; isspace(*s) && *s != '\n'; s++);
	if (!*s || *s == '\n')
	{
		pp->next = s;
		return 0;
	}
	pp->name.data = s;
	pp->value.data = 0;
	q = 0;
	while ((c = *s++) && c != ';' && c != '\n')
	{
		if (c == '"')
		{
			q = 1;
			if (pp->value.data)
				pp->value.data = s;
			else if (first < 0 && pp->name.data == (s - 1))
				pp->name.data = s;
			do
			{
				if (!(c = *s++) || c == '\n')
				{
					s--;
					break;
				}
			} while (c != '"');
			if (first < 0)
			{
				c = ';';
				break;
			}
 		}
		else if (c == '=' && !first)
		{
			first = 1;
			pp->name.size = s - pp->name.data - 1;
			pp->value.data = s;
		}
		else if (first < 0 && isspace(c))
			break;
	}
	pp->next = s - (c != ';');
	if (first >= 0 || !q)
		for (s--; s > pp->name.data && isspace(*(s - 1)); s--);
	if (pp->value.data)
		pp->value.size = s - pp->value.data - q;
	else
		pp->name.size = s - pp->name.data - (q && first < 0);
	return pp->name.size > 0;
}

/*
 * low level for mimeview()
 */

static char*
expand(Mime_t* mp, register char* s, const char* name, const char* type, const char* opts)
{
	register char*	t;
	register int	c;
	Parse_t		pp;

	mp->disc->flags |= MIME_PIPE;
	for (;;)
	{
		switch (c = *s++)
		{
		case 0:
		case '\n':
			break;
		case '%':
			switch (c = *s++)
			{
			case 's':
				sfputr(mp->buf, (char*)name, -1);
				mp->disc->flags &= ~MIME_PIPE;
				continue;
			case 't':
				sfputr(mp->buf, (char*)type, -1);
				continue;
			case '{':
				for (t = s; *s && *s != '}'; s++);
				if (*s && (c = s++ - t) && (pp.next = (char*)opts))
					while (arg(&pp, 0))
						if (pp.name.size == c && !strncasecmp(pp.name.data, t, c))
						{
							if (pp.value.size)
								sfwrite(mp->buf, pp.value.data, pp.value.size);
							break;
						}
				continue;
			}
			/*FALLTHROUGH*/
		default:
			sfputc(mp->buf, c);
			continue;
		}
		break;
	}
	return struse(mp->buf);
}

/*
 * return expanded command/path/value for <view,name,type,opts>
 * return value valid until next mime*() call
 */

char*
mimeview(Mime_t* mp, const char* view, const char* name, const char* type, const char* opts)
{
	register Ent_t*	ent;
	register Cap_t*	cap;
	register Att_t*	att;
	register char*	s;
	int		c;
	char		word[64];

	if (!(ent = (Ent_t*)dtmatch(mp->cap, type)) && (s = strchr(type, '/')) && (c = s - (char*)type) < sizeof(word))
	{
		memcpy(word, type, c);
		word[c] = 0;
		ent = (Ent_t*)dtmatch(mp->cap, word);
	}
	if (ent)
	{
		cap = ent->cap;
		if (!view || strcasecmp(view, "test"))
			while (s = cap->test)
			{
				if (s = expand(mp, s, name, type, opts))
				{
					Parse_t	a1;
					Parse_t	a2;
					Parse_t	a3;
					Parse_t	a4;

					/*
					 * try to do a few common cases here
					 * mailcap consistency is a winning
					 * strategy
					 */

					a1.next = s;
					if (arg(&a1, -1))
					{
						if ((c = *a1.name.data == '!') && --a1.name.size <= 0 && !arg(&a1, -1))
							goto lose;
						if (a1.name.size == 6 && strneq(a1.name.data, "strcmp", 6) || a1.name.size == 10 && strneq(a1.name.data, "strcasecmp", 10))
						{
							a2.next = a1.next;
							if (!arg(&a2, -1))
								goto lose;
							a3.next = a2.next;
							if (!arg(&a3, -1))
								goto lose;
							if (a2.name.size != a3.name.size)
								c ^= 0;
							else c ^= (a1.name.size == 6 ? strncmp : strncasecmp)(a2.name.data, a3.name.data, a2.name.size) == 0;
							if (c)
								break;
							goto skip;
						}
						else if (a1.name.size == 4 && strneq(a1.name.data, "test", 4))
						{
							if (!arg(&a1, -1))
								goto lose;
							a2.next = a1.next;
							if (!arg(&a2, -1) || a2.name.size > 2 || a2.name.size == 1 && *a2.name.data != '=' || a2.name.size == 2 && (!strneq(a1.name.data, "!=", 2) || !strneq(a2.name.data, "==", 2)))
								goto lose;
							a3.next = a2.next;
							if (!arg(&a3, -1))
								goto lose;
							if (*a3.name.data == '`' && *(a3.name.data + a3.name.size - 1) == '`')
							{
								a4 = a3;
								a3 = a1;
								a1 = a4;
							}
							if (*a1.name.data == '`' && *(a1.name.data + a1.name.size - 1) == '`')
							{
								a1.next = a1.name.data + 1;
								if (!arg(&a1, -1) || a1.name.size != 4 || !strneq(a1.name.data, "echo", 4) || !arg(&a1, -1))
									goto lose;
								a4.next = a1.next;
								if (!arg(&a4, 1) || a4.name.size < 21 || !strneq(a4.name.data, "| tr '[A-Z]' '[a-z]'`", 21))
									goto lose;
							}
							else
								a4.name.size = 0;
							c = *a2.name.data == '!';
							if (a1.name.size != a3.name.size)
								c ^= 0;
							else c ^= (a4.name.size ? strncasecmp : strncmp)(a1.name.data, a3.name.data, a1.name.size) == 0;
							if (c)
								break;
							goto skip;
						}
					}
				lose:
					if (!system(s))
						break;
				}
			skip:
				if (!(cap = cap->next))
					return 0;
			}
		att = &cap->att;
		if (view && *view && !streq(view, "-"))
			while (strcasecmp(view, att->name))
				if (!(att = att->next))
					return 0;
		return expand(mp, att->value, name, type, opts);
	}
	return 0;
}

/*
 * lower case identifier prefix strcmp
 * if e!=0 then it will point to the next char after the match
 */

int
mimecmp(register const char* s, register const char* v, char** e)
{
	register int	n;

	while (isalnum(*v) || *v == *s && (*v == '_' || *v == '-' || *v == '/'))
		if (n = lower(*s++) - lower(*v++))
			return n;
	if (!isalnum(*s) && *s != '_' && *s != '-')
	{
		if (e)
			*e = (char*)s;
		return 0;
	}
	return lower(*s) - lower(*v);
}

/*
 * parse mime headers in strsearch(tab,num,siz) from s
 * return >0 if mime header consumed
 */

int
mimehead(Mime_t* mp, void* tab, size_t num, size_t siz, register char* s, int (*set)(Mime_t*, void*, char*, size_t, Mimedisc_t*))
{
	register void*	p;
	char*		e;
	Parse_t		pp;

#if __OBSOLETE__ < 19990101
	if (mp->disc->version >= 19970717L)
#endif
	set = mp->disc->valuef;
	if (!strncasecmp(s, "content-", 8))
	{
		s += 8;
		if ((p = strsearch(tab, num, siz, (Strcmp_f)mimecmp, s, &e)) && *e == ':')
		{
			pp.next = e + 1;
			if (arg(&pp, 1))
			{
				if ((*set)(mp, p, pp.name.data, pp.name.size, mp->disc))
					return 0;
				while (arg(&pp, 0))
					if ((p = strsearch(tab, num, siz, (Strcmp_f)mimecmp, pp.name.data, &e)) &&
					    (*set)(mp, p, pp.value.data, pp.value.size, mp->disc))
						return 0;
				return 1;
			}
		}
		else if (strchr(s, ':'))
			return 1;
	}
	return !strncasecmp(s, "x-", 2);
}

/*
 * open a mime library handle
 */

Mime_t*
mimeopen(Mimedisc_t* disc)
{
	register Mime_t*	mp;

	if (!(mp = newof(0, Mime_t, 1, 0)))
		return 0;
	mp->id = "mime";
	mp->disc = disc;
	mp->dict.key = offsetof(Ent_t, name);
	mp->dict.comparf = order;
	mp->dict.freef = drop;
	if (!(mp->buf = sfstropen()) || !(mp->cap = dtopen(&mp->dict, Dtoset)))
	{
		mimeclose(mp);
		return 0;
	}
	return mp;
}

/*
 * close a mimeopen() handle
 */

int
mimeclose(Mime_t* mp)
{
	if (mp)
	{
		if (mp->buf)
			sfclose(mp->buf);
		if (mp->cap)
			dtclose(mp->cap);
		if (mp->freef)
			(*mp->freef)(mp);
		free(mp);
	}
	return 0;
}