Exemple #1
0
/*
 * allocate a paragraph header, link it to the
 * tail of the current document
 */
static Paragraph *
Pp(ParagraphRoot *d, Line *ptr, int typ)
{
    Paragraph *ret = calloc(sizeof *ret, 1);

    ret->text = ptr;
    ret->typ = typ;

    return ATTACH(*d, ret);
}
Exemple #2
0
G_MODULE_EXPORT int gtk_module_init(gint argc, char *argv[])
{
	const char *errptr = 0;
	int offset = 0;

	regexp_phone = pcre_compile("\\+?[0-9\\-\\.\\(\\)\\s]{0,12}\\d{3}[0-9\\-\\.\\(\\)\\s]{0,12}",
			0, &errptr,&offset,NULL);
	if(!regexp_phone) abort();
	regexp_phone_extra = pcre_study(regexp_phone, 0, &errptr);

#define ATTACH(f) \
	g_type_class_ref(f); g_signal_add_emission_hook(g_signal_lookup("populate-popup", f), \
			0, gtkdial_signal_emission_hook, NULL, NULL)
	ATTACH(GTK_TYPE_ENTRY);
	ATTACH(GTK_TYPE_LABEL);
	ATTACH(GTK_TYPE_TEXT_VIEW);
#undef ATTACH
	return TRUE;
}
Exemple #3
0
LRESULT DirectoryListingDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {

	ATTACH(IDC_SEARCH_STRING, ctrlSearch);
	ctrlSearch.SetFocus();
	//ctrlSearch.SetWindowText(Text::toT(searchStr).c_str());
	WinUtil::appendHistory(ctrlSearch, SettingsManager::HISTORY_SEARCH);

	//ctrlSearch.SetSelAll(TRUE);

	ATTACH(IDC_FILETYPES, ctrlFileType);
	ATTACH(IDC_SEARCH_SIZE, ctrlSize);

	ATTACH(IDC_SIZE_MODE, ctrlSizeMode);
	ATTACH(IDC_SIZE_UNIT, ctrlSizeUnit);
	WinUtil::appendSizeCombos(ctrlSizeUnit, ctrlSizeMode);

	::SetWindowText(GetDlgItem(IDCANCEL), CTSTRING(CANCEL));
	::SetWindowText(GetDlgItem(IDC_DL_SEARCH_DESC), CTSTRING(SEARCH_STRING));
	::SetWindowText(GetDlgItem(IDC_DL_TYPE_TEXT), CTSTRING(FILE_TYPE));
	::SetWindowText(GetDlgItem(IDC_SIZE_LABEL), CTSTRING(SIZE));

	::SetWindowText(GetDlgItem(IDC_USE_CUR_DIR), CTSTRING(SEARCH_CUR_DIR));
	if (!dl->supportsASCH() || dl->getHintedUser().user->isNMDC()) {
		::EnableWindow(GetDlgItem(IDC_USE_CUR_DIR),	FALSE);
		::ShowWindow(GetDlgItem(IDC_NO_ASCH_NOTE), SW_SHOW);
		if (dl->getHintedUser().user->isNMDC()) {
			::SetWindowText(GetDlgItem(IDC_NO_ASCH_NOTE), CTSTRING(PARTIAL_SCH_NMDC_NOTE));
		} else {
			::SetWindowText(GetDlgItem(IDC_NO_ASCH_NOTE), CTSTRING(NO_ASCH_NOTE));
		}
	}

	fileTypeStr = SETTING(LAST_FL_FILETYPE);
	ctrlFileType.fillList(fileTypeStr);


	CenterWindow(GetParent());
	SetWindowText(CTSTRING(SEARCH));

	return FALSE;
}
Exemple #4
0
/*
 * top-level compilation; break the document into
 * style, html, and source blocks with footnote links
 * weeded out.
 */
static Paragraph *
compile_document(Line *ptr, MMIOT *f)
{
    ParagraphRoot d = { 0, 0 };
    ANCHOR(Line) source = { 0, 0 };
    Paragraph *p = 0;
    struct kw *tag;
    int eaten, unclosed;

    while ( ptr ) {
	if ( !(f->flags & MKD_NOHTML) && (tag = isopentag(ptr)) ) {
	    /* If we encounter a html/style block, compile and save all
	     * of the cached source BEFORE processing the html/style.
	     */
	    if ( T(source) ) {
		E(source)->next = 0;
		p = Pp(&d, 0, SOURCE);
		p->down = compile(T(source), 1, f);
		T(source) = E(source) = 0;
	    }
	    p = Pp(&d, ptr, strcmp(tag->id, "STYLE") == 0 ? STYLE : HTML);
	    ptr = htmlblock(p, tag, &unclosed);
	    if ( unclosed ) {
		p->typ = SOURCE;
		p->down = compile(p->text, 1, f);
		p->text = 0;
	    }
	}
	else if ( isfootnote(ptr) ) {
	    /* footnotes, like cats, sleep anywhere; pull them
	     * out of the input stream and file them away for
	     * later processing
	     */
	    ptr = consume(addfootnote(ptr, f), &eaten);
	}
	else {
	    /* source; cache it up to wait for eof or the
	     * next html/style block
	     */
	    ATTACH(source,ptr);
	    ptr = ptr->next;
	}
    }
    if ( T(source) ) {
	/* if there's any cached source at EOF, compile
	 * it now.
	 */
	E(source)->next = 0;
	p = Pp(&d, 0, SOURCE);
	p->down = compile(T(source), 1, f);
    }
    return T(d);
}
Exemple #5
0
int PARA_SettingCommit()
{
#define CHECKPOINT(str1,str2,str3,limit) if(!(strlen(str1)+strlen(str2)+strlen(str3)<limit)){PARA_TRACE("para too long");return -1;}
#define ATTACH(srcstr,str) if(str){CHECKPOINT((srcstr),(str),PARA_TAIL, PARA_SIZE);strcat((srcstr),(str));}
	char* pText = NULL;
	char azPara[PARA_SIZE]; // 8k
	memset(azPara, 0, sizeof(azPara));
	// head
	strcat(azPara, PARA_HEAD);
	// commit name
	pText = para_Make(PARA_DEVNAME, s_szDevName);
	ATTACH(azPara, pText);
	// commit model
	pText = para_Make(PARA_DEVMODEL, s_szDevModel);
	ATTACH(azPara, pText);
//	// commit language
//	pText = para_Make(PARA_LANGUAGE, PARA_UmapLanguage(s_enLanguage));
//	ATTACH(azPara, pText);
//	// commit standard
//	pText = para_Make(PARA_STANDARD, PARA_UmapStandard(s_enStandard));
	ATTACH(azPara, pText);
	// tail
	strcat(azPara, PARA_TAIL);
	// compare diff
	if(0 == strcmp(s_azPara, azPara)){
		// the same
		return -1;
	}
	// save
	memcpy(s_azPara, azPara, sizeof(azPara));
	PARA_TRACE("\r\n%s", s_azPara);
	para_Save();
	return 0;
#undef ATTACH
#undef CHECKPOINT
}
Exemple #6
0
LRESULT CommandDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// Translate
	SetWindowText(CTSTRING(USER_CMD_WINDOW));
	
	ATTACH(IDC_RESULT, ctrlResult);
	ATTACH(IDC_NAME, ctrlName);
	ATTACH(IDC_HUB, ctrlHub);
	ATTACH(IDC_SETTINGS_SEPARATOR, ctrlSeparator);
	ATTACH(IDC_SETTINGS_RAW, ctrlRaw);
	ATTACH(IDC_SETTINGS_CHAT, ctrlChat);
	ATTACH(IDC_SETTINGS_PM, ctrlPM);
	ATTACH(IDC_SETTINGS_ONCE, ctrlOnce);
	ATTACH(IDC_SETTINGS_HUB_MENU, ctrlHubMenu);
	ATTACH(IDC_SETTINGS_USER_MENU, ctrlUserMenu);
	ATTACH(IDC_SETTINGS_SEARCH_MENU, ctrlSearchMenu);
	ATTACH(IDC_SETTINGS_FILELIST_MENU, ctrlFilelistMenu);
	ATTACH(IDC_NICK, ctrlNick);
	ATTACH(IDC_COMMAND, ctrlCommand);
	
	WinUtil::translate(*this, texts);
	
	if (type == UserCommand::TYPE_SEPARATOR)
	{
		ctrlSeparator.SetCheck(BST_CHECKED);
	}
	else
	{
		// More difficult, determine type by what it seems to be...
		if ((_tcsncmp(command.c_str(), _T("$To: "), 5) == 0) &&
		        (command.find(_T(" From: %[myNI] $<%[myNI]> ")) != string::npos ||
		         command.find(_T(" From: %[mynick] $<%[mynick]> ")) != string::npos) &&
		        command.find(_T('|')) == command.length() - 1) // if it has | anywhere but the end, it is raw
		{
			string::size_type i = command.find(_T(' '), 5);
			dcassert(i != string::npos);
			const tstring to = command.substr(5, i - 5);
			string::size_type cmd_pos = command.find(_T('>'), 5) + 2;
			const tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length() - cmd_pos - 1)), true));
			ctrlPM.SetCheck(BST_CHECKED);
			ctrlNick.SetWindowText(to.c_str());
			ctrlCommand.SetWindowText(cmd.c_str());
		}
		else if (((_tcsncmp(command.c_str(), _T("<%[mynick]> "), 12) == 0) ||
		          (_tcsncmp(command.c_str(), _T("<%[myNI]> "), 10) == 0)) &&
		         command[command.length() - 1] == '|')
		{
			// Looks like a chat thing...
			string::size_type cmd_pos = command.find(_T('>')) + 2;
			tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length() - cmd_pos - 1)), true));
			ctrlChat.SetCheck(BST_CHECKED);
			ctrlCommand.SetWindowText(cmd.c_str());
		}
		else
		{
			tstring cmd = command;
			ctrlRaw.SetCheck(BST_CHECKED);
			ctrlCommand.SetWindowText(cmd.c_str());
		}
		if (type == UserCommand::TYPE_RAW_ONCE)
		{
			ctrlOnce.SetCheck(BST_CHECKED);
			type = 1;
		}
	}
	
	ctrlHub.SetWindowText(hub.c_str());
	ctrlName.SetWindowText(name.c_str());
	
	if (ctx & UserCommand::CONTEXT_HUB)
		ctrlHubMenu.SetCheck(BST_CHECKED);
	if (ctx & UserCommand::CONTEXT_USER)
		ctrlUserMenu.SetCheck(BST_CHECKED);
	if (ctx & UserCommand::CONTEXT_SEARCH)
		ctrlSearchMenu.SetCheck(BST_CHECKED);
	if (ctx & UserCommand::CONTEXT_FILELIST)
		ctrlFilelistMenu.SetCheck(BST_CHECKED);
		
	updateControls();
	updateCommand();
	ctrlResult.SetWindowText(command.c_str());
	
	ctrlSeparator.SetFocus();
	
	CenterWindow(GetParent());
	return FALSE;
}
LRESULT CommandDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// Translate
	SetWindowText(CTSTRING(USER_CMD_WINDOW));
	SetDlgItemText(IDC_SETTINGS_TYPE, CTSTRING(USER_CMD_TYPE));
	SetDlgItemText(IDC_SETTINGS_SEPARATOR, CTSTRING(SEPARATOR));
	SetDlgItemText(IDC_SETTINGS_RAW, CTSTRING(USER_CMD_RAW));
	SetDlgItemText(IDC_SETTINGS_CHAT, CTSTRING(USER_CMD_CHAT));
	SetDlgItemText(IDC_SETTINGS_PM, CTSTRING(USER_CMD_PM));
	SetDlgItemText(IDC_SETTINGS_CONTEXT, CTSTRING(USER_CMD_CONTEXT));
	SetDlgItemText(IDC_SETTINGS_HUB_MENU, CTSTRING(USER_CMD_HUB_MENU));
	SetDlgItemText(IDC_SETTINGS_USER_MENU, CTSTRING(USER_CMD_USER_MENU));
	SetDlgItemText(IDC_SETTINGS_SEARCH_MENU, CTSTRING(USER_CMD_SEARCH_MENU));
	SetDlgItemText(IDC_SETTINGS_FILELIST_MENU, CTSTRING(USER_CMD_FILELIST_MENU));
	SetDlgItemText(IDC_SETTINGS_PARAMETERS, CTSTRING(USER_CMD_PARAMETERS));
	SetDlgItemText(IDC_SETTINGS_NAME, CTSTRING(HUB_NAME));
	SetDlgItemText(IDC_SETTINGS_COMMAND, CTSTRING(USER_CMD_COMMAND));
	SetDlgItemText(IDC_SETTINGS_HUB, CTSTRING(USER_CMD_HUB));
	SetDlgItemText(IDC_SETTINGS_TO, CTSTRING(USER_CMD_TO));
	SetDlgItemText(IDC_SETTINGS_ONCE, CTSTRING(USER_CMD_ONCE));
	SetDlgItemText(IDC_USER_CMD_PREVIEW, CTSTRING(USER_CMD_PREVIEW));
	SetDlgItemText(IDC_USER_CMD_OPEN_HELP, CTSTRING(SETTINGS_OPEN_USER_CMD_HELP));

#define ATTACH(id, var) var.Attach(GetDlgItem(id))
	ATTACH(IDC_RESULT, ctrlResult);
	ATTACH(IDC_NAME, ctrlName);
	ATTACH(IDC_HUB, ctrlHub);
	ATTACH(IDC_SETTINGS_SEPARATOR, ctrlSeparator);
	ATTACH(IDC_SETTINGS_RAW, ctrlRaw);
	ATTACH(IDC_SETTINGS_CHAT, ctrlChat);
	ATTACH(IDC_SETTINGS_PM, ctrlPM);
	ATTACH(IDC_SETTINGS_ONCE, ctrlOnce);
	ATTACH(IDC_SETTINGS_HUB_MENU, ctrlHubMenu);
	ATTACH(IDC_SETTINGS_USER_MENU, ctrlUserMenu);
	ATTACH(IDC_SETTINGS_SEARCH_MENU, ctrlSearchMenu);
	ATTACH(IDC_SETTINGS_FILELIST_MENU, ctrlFilelistMenu);
	ATTACH(IDC_NICK, ctrlNick);
	ATTACH(IDC_COMMAND, ctrlCommand);

	// launch the help file, instead of having the help in the dialog
	bool openHelp(BOOLSETTING(OPEN_USER_CMD_HELP));
	::CheckDlgButton(m_hWnd, IDC_USER_CMD_OPEN_HELP, openHelp);
	if(openHelp) {
		HtmlHelp(m_hWnd, WinUtil::getHelpFile().c_str(), HH_HELP_CONTEXT, IDD_UCPAGE);
	}

	if(type == UserCommand::TYPE_SEPARATOR) {
		ctrlSeparator.SetCheck(BST_CHECKED);
	} else {
		// More difficult, determine type by what it seems to be...
		if((_tcsncmp(command.c_str(), _T("$To: "), 5) == 0) &&
			(command.find(_T(" From: %[myNI] $<%[myNI]> ")) != string::npos ||
			command.find(_T(" From: %[mynick] $<%[mynick]> ")) != string::npos) &&
			command.find(_T('|')) == command.length() - 1) // if it has | anywhere but the end, it is raw
		{
			string::size_type i = command.find(_T(' '), 5);
			dcassert(i != string::npos);
			tstring to = command.substr(5, i-5);
			string::size_type cmd_pos = command.find(_T('>'), 5) + 2;
			tstring cmd = command.substr(cmd_pos, command.length()-cmd_pos-1);
			ctrlPM.SetCheck(BST_CHECKED);
			ctrlNick.SetWindowText(to.c_str());
			ctrlCommand.SetWindowText(cmd.c_str());
		} else if(((_tcsncmp(command.c_str(), _T("<%[mynick]> "), 12) == 0) ||
			(_tcsncmp(command.c_str(), _T("<%[myNI]> "), 10) == 0)) &&
			command[command.length()-1] == '|')
		{
			// Looks like a chat thing...
			string::size_type cmd_pos = command.find(_T('>')) + 2;
			tstring cmd = command.substr(cmd_pos, command.length()-cmd_pos-1);
			ctrlChat.SetCheck(BST_CHECKED);
			ctrlCommand.SetWindowText(cmd.c_str());
		} else {
			tstring cmd = command;
			ctrlRaw.SetCheck(BST_CHECKED);
			ctrlCommand.SetWindowText(cmd.c_str());
		}
		if(type == UserCommand::TYPE_RAW_ONCE) {
			ctrlOnce.SetCheck(BST_CHECKED);
			type = 1;
		}
	}

	ctrlHub.SetWindowText(hub.c_str());
	ctrlName.SetWindowText(name.c_str());

	if(ctx & UserCommand::CONTEXT_HUB)
		ctrlHubMenu.SetCheck(BST_CHECKED);
	if(ctx & UserCommand::CONTEXT_CHAT)
		ctrlUserMenu.SetCheck(BST_CHECKED);
	if(ctx & UserCommand::CONTEXT_SEARCH)
		ctrlSearchMenu.SetCheck(BST_CHECKED);
	if(ctx & UserCommand::CONTEXT_FILELIST)
		ctrlFilelistMenu.SetCheck(BST_CHECKED);

	updateControls();
	updateCommand();
	ctrlResult.SetWindowText(command.c_str());

	ctrlSeparator.SetFocus();

	CenterWindow(GetParent());
	return FALSE;
}
LRESULT CommandDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// Translate
	SetWindowText(CTSTRING(USER_CMD_WINDOW));

#define ATTACH(id, var) var.Attach(GetDlgItem(id))
	ATTACH(IDC_NAME, ctrlName);
	ATTACH(IDC_HUB, ctrlHub);
	ATTACH(IDC_SETTINGS_SEPARATOR, ctrlSeparator);
	ATTACH(IDC_SETTINGS_RAW, ctrlRaw);
	ATTACH(IDC_SETTINGS_CHAT, ctrlChat);
	ATTACH(IDC_SETTINGS_PM, ctrlPM);
	ATTACH(IDC_SETTINGS_ONCE, ctrlOnce);
	ATTACH(IDC_SETTINGS_HUB_MENU, ctrlHubMenu);
	ATTACH(IDC_SETTINGS_USER_MENU, ctrlUserMenu);
	ATTACH(IDC_SETTINGS_SEARCH_MENU, ctrlSearchMenu);
	ATTACH(IDC_SETTINGS_FILELIST_MENU, ctrlFilelistMenu);
	ATTACH(IDC_NICK, ctrlNick);
	ATTACH(IDC_COMMAND, ctrlCommand);

	WinUtil::translate(*this, texts);
	SetDlgItemText(IDC_COMMAND_DESCRIPTION, CTSTRING(USER_CMD_DESCRIPTION));

	int newType = 0;
	if(type == UserCommand::TYPE_SEPARATOR) {
		ctrlSeparator.SetCheck(BST_CHECKED);
		newType = 0;
	} else {
		ctrlCommand.SetWindowText(Text::toDOS(command).c_str());
		if(type == UserCommand::TYPE_RAW || type == UserCommand::TYPE_RAW_ONCE) {
			ctrlRaw.SetCheck(BST_CHECKED);
			newType = 1;
		} else if(type == UserCommand::TYPE_CHAT || type == UserCommand::TYPE_CHAT_ONCE) {
			if(to.empty()) {
				ctrlChat.SetCheck(BST_CHECKED);
				newType = 2;
			} else {
				ctrlPM.SetCheck(BST_CHECKED);
				ctrlNick.SetWindowText(to.c_str());
				newType = 3;
			}		
		}

		if(type == UserCommand::TYPE_RAW_ONCE || type == UserCommand::TYPE_CHAT_ONCE) {
			ctrlOnce.SetCheck(BST_CHECKED);
		}
	}
	type = newType;

	ctrlHub.SetWindowText(hub.c_str());
	ctrlName.SetWindowText(name.c_str());

	if(ctx & UserCommand::CONTEXT_HUB)
		ctrlHubMenu.SetCheck(BST_CHECKED);
	if(ctx & UserCommand::CONTEXT_USER)
		ctrlUserMenu.SetCheck(BST_CHECKED);
	if(ctx & UserCommand::CONTEXT_SEARCH)
		ctrlSearchMenu.SetCheck(BST_CHECKED);
	if(ctx & UserCommand::CONTEXT_FILELIST)
		ctrlFilelistMenu.SetCheck(BST_CHECKED);
	
	updateControls();
	updateCommand();

	ctrlSeparator.SetFocus();
	
	CenterWindow(GetParent());
	return FALSE;
}
Exemple #9
0
LONG AttachDetours(VOID)
{
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());

    ATTACH(BuildCommDCBA);
    ATTACH(BuildCommDCBAndTimeoutsA);
    ATTACH(BuildCommDCBAndTimeoutsW);
    ATTACH(BuildCommDCBW);
    ATTACH(ClearCommBreak);
    ATTACH(ClearCommError);
    ATTACH(CloseHandle);
    ATTACH(CreateFileA);
    ATTACH(CreateFileW);
    ATTACH(EscapeCommFunction);
    ATTACH(GetCommConfig);
    ATTACH(GetCommMask);
    ATTACH(GetCommModemStatus);
    ATTACH(GetCommProperties);
    ATTACH(GetCommState);
    ATTACH(GetCommTimeouts);
    ATTACH(GetCurrentThreadId);
    ATTACH(GetModuleFileNameW);
    ATTACH(GetOverlappedResult);
    ATTACH(PurgeComm);
    ATTACH(ReadFile);
    ATTACH(SetCommBreak);
    ATTACH(SetCommConfig);
    ATTACH(SetCommMask);
    ATTACH(SetCommState);
    ATTACH(SetCommTimeouts);
    ATTACH(SetupComm);
    ATTACH(TransmitCommChar);
    ATTACH(WaitCommEvent);
    ATTACH(WriteFile);

    return DetourTransactionCommit();
}
Exemple #10
0
int 
main()
{
	struct T root, *p[60], *to_pluck = NULL;
	/* make a root */
	root.i = 0;
	TREE_NODE_CONS(root.tnd);

	/* then add nodes to the tree */
	ATTACH(1, &root.tnd);
	ATTACH(2, &root.tnd);
	ATTACH(3, &root.tnd);
	ATTACH(4, &p[2]->tnd);
	ATTACH(5, &p[2]->tnd);
	ATTACH(6, &p[4]->tnd);
	ATTACH(7, &p[4]->tnd);
	ATTACH(8, &p[4]->tnd);
	ATTACH(9, &p[5]->tnd);
	ATTACH(10, &p[5]->tnd);
	ATTACH(11, &p[5]->tnd);
	ATTACH(12, &p[1]->tnd);
	ATTACH(13, &p[1]->tnd);
	ATTACH(14, &p[12]->tnd);
	ATTACH(15, &p[3]->tnd);
	
	/* print the tree */
	printf("whole tree:\n");
	tree_foreach(&root.tnd, &tree_pre_order_DFS, &pretty_print, 
	             0, NULL);
	
	/* print a sub-tree */
	printf("a subtree:\n");
	tree_foreach(&p[2]->tnd, &tree_pre_order_DFS, &pretty_print, 
	             0, NULL);
	
	/* print a sub-tree */
	printf("a subtree in easy print:\n");
	tree_foreach(&p[2]->tnd, &tree_post_order_DFS, &easy_print, 
	             0, NULL);
	
	/* pluck and plug */
	tree_foreach(&root.tnd, &tree_pre_order_DFS, 
	             &pluck_and_plug, 0, &to_pluck);
	
	/* print the tree again to see the difference */
	printf("after pluck and plug:\n");
	tree_foreach(&root.tnd, &tree_pre_order_DFS, &pretty_print, 
	             0, NULL);

	/* release the tree 
	 * Please note when releasing the tree, you should use
	 * tree_post_order_DFS way to traversal. Plus, here our 
	 * root is not dynamically allocated, so pass 1 to the 4th
	 * parameter to avoid freeing the root.
	 */
	tree_foreach(&root.tnd, &tree_post_order_DFS, &release, 
	             1, NULL);

	exit(0);
}
Exemple #11
0
struct header_segm *
compile_headline (const char *str)
{
  struct header_segm *head = NULL, *tail = NULL;
  char *text;
  int align;
  size_t width;
  
#define ALIGN_STRING (align == ALIGN_UNDEF ? ALIGN_LEFT : ALIGN_RIGHT)
#define ALIGN_NUMBER (align == ALIGN_UNDEF ? ALIGN_RIGHT : ALIGN_LEFT)
#define ATTACH(p)				\
  do						\
    {						\
      if (!head)				\
	head = p;				\
      else					\
	tail->next = p;				\
      tail = p;					\
    }						\
  while (0)
      
  while (*str)
    {
      struct header_segm *seg;
      size_t len;
      char *p = strchr (str, '%');
      if (!p)
	len = strlen (str);
      else
	len = p - str;
      if (len)
	{
	  text = xmalloc (len + 1);
	  memcpy (text, str, len);
	  text[len] = 0;
	  seg = new_header_segment (ALIGN_LEFT, 0, text, hdr_text);
	  ATTACH (seg);
	}
      if (!p)
	break;

      str = ++p;

      if (*str == '-')
	{
	  str++;
	  align = ALIGN_LEFT;
	}
      else if (*str == '+')
	{
	  str++;
	  align = ALIGN_RIGHT;
	}
      else
	align = ALIGN_UNDEF;
      
      if (mu_isdigit (*str))
	width = strtoul (str, (char**)&str, 10);
      else
	width = 0;

      switch (*str++)
	{
	case '%':
	  seg = new_header_segment (ALIGN_LEFT, 0, xstrdup ("%"), hdr_text);
	  break;
	  
	case 'a': /* Message attributes. */
	  seg = new_header_segment (ALIGN_STRING, width, NULL, hdr_attr);
	  break;

	  /* FIXME: %c    The score of the message. */
	  
	case 'd': /* Message date */
	  seg = new_header_segment (ALIGN_STRING, width, NULL, hdr_date);
	  break;
	  
	  /* FIXME: %e    The indenting level in threaded mode. */
	  
	case 'f': /* Message sender */
	  seg = new_header_segment (ALIGN_STRING, width, NULL, hdr_from);
	  break;

	  /* FIXME: %i    The message thread structure. */
	  
	case 'l': /* The number of lines of the message */
	  seg = new_header_segment (ALIGN_NUMBER, width, NULL, hdr_lines);
	  break;
	  
	case 'm': /* Message number */
	  seg = new_header_segment (ALIGN_NUMBER, width, NULL, hdr_number);
	  break;
	  
	case 'o': /* The number of octets (bytes) in the message */
	  seg = new_header_segment (ALIGN_NUMBER, width, NULL, hdr_size);
	  break;
	  
	case 's': /* Message subject (if any) */
	  seg = new_header_segment (ALIGN_STRING, width, NULL, hdr_subject);
	  break;

	case 'S': /* Message subject (if any) in double quotes */
	  seg = new_header_segment (ALIGN_STRING, width, NULL, hdr_q_subject);
	  break;
	  
	  /* FIXME: %t    The position in threaded/sorted order. */
	  
	case '>': /* A `>' for the current message, otherwise ` ' */
	  seg = new_header_segment (ALIGN_STRING, width, xstrdup (">"), hdr_cur);
	  break;
	  
	case '<': /* A `<' for the current message, otherwise ` ' */
	  seg = new_header_segment (ALIGN_STRING, width, xstrdup ("<"), hdr_cur);
	  break;

	default:
	  mu_error (_("unknown escape: %%%c"), str[-1]);
	  len = str - p;
	  text = xmalloc (len);
	  memcpy (text, p, len-1);
	  text[len-1] = 0;
	  seg = new_header_segment (ALIGN_STRING, width, text, hdr_text);
	}
      ATTACH (seg);
    }
  return head;
#undef ALIGN_STRING
#undef ALIGN_NUMBER
#undef ATTACH
}