⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 support.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: support.c,v 1.26 2001/03/21 03:50:55 ttabner Exp $ * * Copyright (C) 1999-2000 Bynari Inc. * Copyright (C) 2001 Project TradeClient * * LGPL * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library * General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "puma.h"#include "ipc.h"static gchar* check_file_exists        (const gchar     *directory,                                        const gchar     *filename);static GtkWidget* create_dummy_pixmap  (GtkWidget       *widget);GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name) {  GtkWidget *parent, *found_widget;  for (;;) {		if (GTK_IS_MENU (widget))			parent = gtk_menu_get_attach_widget (GTK_MENU (widget));		else			parent = widget->parent;		if (parent == NULL)			break;		widget = parent;	}  found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget), widget_name);  if (!found_widget)    g_warning ("Widget not found: %s", widget_name);  return found_widget;}static char *dummy_pixmap_xpm[] = {"1 1 1 1","  c None"," "};static GtkWidget* create_dummy_pixmap (GtkWidget *widget) {  GdkColormap *colormap;  GdkPixmap *gdkpixmap;  GdkBitmap *mask;  GtkWidget *pixmap;  colormap = gtk_widget_get_colormap (widget);  gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,                                                     NULL, dummy_pixmap_xpm);  if (gdkpixmap == NULL)    g_error ("Couldn't create replacement pixmap.");  pixmap = gtk_pixmap_new (gdkpixmap, mask);  gdk_pixmap_unref (gdkpixmap);  gdk_bitmap_unref (mask);  return pixmap;}static GList *pixmaps_directories = NULL;void add_pixmap_directory (const gchar *directory) {  pixmaps_directories = g_list_prepend (pixmaps_directories, g_strdup (directory));}GtkWidget* create_pixmap (GtkWidget *widget, const gchar *filename) {  gchar *found_filename = NULL;  GdkColormap *colormap;  GdkPixmap *gdkpixmap;  GdkBitmap *mask;  GtkWidget *pixmap;  GList *elem;  elem = pixmaps_directories;  while (elem) {		found_filename = check_file_exists ((gchar*)elem->data, filename);		if (found_filename) break;		elem = elem->next;	}  if (!found_filename) {		found_filename = check_file_exists ("../pixmaps", filename);	}  if (!found_filename) {		g_warning ("Couldn't find pixmap file: %s", filename);		return create_dummy_pixmap (widget);	}  colormap = gtk_widget_get_colormap (widget);  gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,                                                   NULL, found_filename);  if (gdkpixmap == NULL) {		g_warning ("Error loading pixmap file: %s", found_filename);		g_free (found_filename);		return create_dummy_pixmap (widget);	}	g_free (found_filename);	pixmap = gtk_pixmap_new (gdkpixmap, mask);	gdk_pixmap_unref (gdkpixmap);	gdk_bitmap_unref (mask);	return pixmap;}GtkWidget* create_pixmap_from_data (GtkWidget *widget, char **data) {	GdkColormap *colormap;  GdkPixmap *gdkpixmap;  GdkBitmap *mask;  GtkWidget *pixmap;  colormap = gtk_widget_get_colormap (widget);  gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,                                                   NULL, data);  if (gdkpixmap == NULL) {		insert_warning (0, "Internal error or stack corruption while creating pixmaps");		return create_dummy_pixmap (widget);	}  	pixmap = gtk_pixmap_new (gdkpixmap, mask);  gdk_pixmap_unref (gdkpixmap);  gdk_bitmap_unref (mask);  return pixmap;}gchar* check_file_exists (const gchar *directory, const gchar *filename) {  gchar *full_filename;  struct stat s;  gint status;  full_filename = (gchar*) g_malloc (strlen (directory) + 1 + strlen (filename) + 1);  strcpy (full_filename, directory);  strcat (full_filename, G_DIR_SEPARATOR_S);  strcat (full_filename, filename);  status = stat (full_filename, &s);  if (status == 0 && S_ISREG (s.st_mode))    return full_filename;  g_free (full_filename);  return NULL;}GtkWidget* create_icon_text_menu_item (char *pixmap, char *name) {	GtkWidget *hbox2, *pixmap1, *label1;  hbox2 = gtk_hbox_new (FALSE, 0);  gtk_widget_set_name (hbox2, "hbox2");  gtk_widget_ref (hbox2);  gtk_widget_show (hbox2);  pixmap1 = create_pixmap (hbox2, pixmap);  gtk_widget_set_name (pixmap1, pixmap);  gtk_widget_ref (pixmap1);  gtk_object_set_data_full (GTK_OBJECT (hbox2), pixmap, pixmap1,                            (GtkDestroyNotify) gtk_widget_unref);  gtk_widget_show (pixmap1);  gtk_box_pack_start (GTK_BOX (hbox2), pixmap1, FALSE, FALSE, 3);  label1 = gtk_label_new (name);  gtk_widget_set_name (label1, name);  gtk_widget_ref (label1);  gtk_object_set_data_full (GTK_OBJECT (hbox2), name, label1,                            (GtkDestroyNotify) gtk_widget_unref);  gtk_widget_show (label1);  gtk_box_pack_start (GTK_BOX (hbox2), label1, FALSE, FALSE, 0);	return hbox2;}void cleanup () {  Folder *fseek=folder_first (), *dseek;  Message *mseek, *mdseek;  PopAccount *pop=first_popaccount (), *dpop;  Llist *mtype=mime_type_first ();  GtkCList *clist=GTK_CLIST (lookup_widget (tm_globs->main_window, "message_clist"));  MimeType *tmpm;  int row;  for (row=0;row<clist->rows;row++) {    free (gtk_clist_get_row_data (clist, row));  }  while (fseek) {    dseek=fseek->next;    mseek=fseek->msglst;    while (mseek) {      mdseek=mseek->next;      message_free (mseek);      mseek=mdseek;    }    free (fseek->name);    if (fseek->parent) free (fseek->parent);    free (fseek);    fseek=dseek;  }  while (mtype) {    tmpm=(MimeType *)mtype->data;    if (tmpm->type) free (tmpm->type);    if (tmpm->handle) free (tmpm->handle);    if (tmpm->ext) free (tmpm->ext);    mtype=mtype->next;  }  mtype=mime_type_first ();  llist_blow_away_and_destroy (mtype);  while (pop) {    /* See if the account is receiving, if so, kill it! */    if( pop -> pid > 0 ) {      printf( "Killing child process (%d) on account #%d that is busy, with 'SIGKILL'.\n", pop -> pid, pop -> id ) ;      kill( pop -> pid, SIGKILL ) ;      if( waitpid( pop -> pid, NULL, 0 ) == pop -> pid ) printf( "System reported child receive process has been killed.\n" ) ;    }    /* See if the account is sending, if so, kill it! */    if( pop -> spid > 0 ) {      printf( "Killing child SMTP processes (%d) that are busy on account #%d with 'SIGKILL'.\n", pop -> spid, pop -> id ) ;      kill( pop -> spid, SIGKILL ) ;      if( waitpid( pop -> spid, NULL, 0 ) == pop -> spid ) printf( "System reported child send process has been killed.\n" ) ;    }    dpop=pop->next;    if (pop) destroy_popaccount (pop->id);    pop=dpop;  }  /* Kill the connection monitor process if needed */  if( tm_globs -> pid != -1 ) {    printf( "Killing child monitor process process (%d) with 'SIGKILL'.\n", tm_globs -> pid ) ;    /* If it's not already dead or dying, kill it! */    kill( tm_globs -> pid, SIGKILL ) ;    if( waitpid( tm_globs -> pid, NULL, 0 ) == tm_globs -> pid ) printf( "System reported monitor child process has been killed.\n" ) ;  }}/* * Notice that this function is somewhat dangerous as it allocates memory and expects * someone else to clean up after it!!!  Bad....very bad...otherwise, we'll leak!!! */char *generate_timestamp () {  time_t t ;  struct tm *ti ;  char *ptr ;  char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" } ;  char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } ;  /* Get the current time and populate our data structure */  t = time( NULL ) ;  ti = gmtime( &t ) ;  /* Allocate memory and fill it out */  ptr = malloc( 30 * sizeof(char) ) ;  if( ptr ) {    sprintf( ptr, "%s, %02d %s %04d %02d:%02d:%02d UTC", 	     days[ti -> tm_wday], ti -> tm_mday, months[ti -> tm_mon],	     1900 + ti -> tm_year,	     ti -> tm_hour, ti -> tm_min, ti -> tm_sec ) ;  }  return ptr ;}char *generate_os_info () {	struct utsname buf;	char *buffer;	uname (&buf);	buffer=(char *)calloc (strlen (buf.sysname)+strlen(buf.release)+2, sizeof(char));	snprintf (buffer, strlen (buf.sysname)+strlen(buf.release)+2, "%s %s", buf.sysname, buf.release);	return buffer;}/* LINKED LIST FUNCTIONS */Llist *llist_append (Llist *begin, void *data) {	Llist *retval, *seek;	if (begin) {		seek=begin;		while (seek->next) { seek=seek->next; }		retval=(Llist *)calloc(1, sizeof(Llist));		seek->next=retval;		retval->prev=seek;		retval->data=data;		return begin;	} else {		begin=(Llist *)calloc(1, sizeof(Llist));		begin->data=data;		return begin;	}	return NULL;}Llist *llist_prepend (Llist *begin, void *data) {	Llist *retval=(Llist *)calloc (1, sizeof(Llist));	if (begin) {		begin->prev=retval;		retval->next=begin;	}	retval->data=data;	return retval;}Llist *llist_seek (Llist *begin, void *data) {	Llist *seek=begin;	while (seek) {		if (seek->data==data) return seek;		seek=seek->next;	}	return NULL;}Llist *llist_seek_by_name (Llist *begin, char *name) {	Llist *seek=begin;	while (seek) {		if (strcmp(seek->name, name)==0) return seek;		seek=seek->next;	}	return NULL;}Llist *llist_remove_by_node (Llist *node) {	Llist *ptemp, *ntemp, *first;	if (node) {		ptemp=node->prev;		ntemp=node->next;		if (ptemp) {			ptemp->next=ntemp;		} else {			if (ntemp) ntemp->prev=ptemp;			if (node->data) free (node->data);			free (node);			return ntemp; 		}		if (ntemp) ntemp->prev=ptemp;		if (node->data) free (node->data);		free (node);		first=ptemp;		while (first->prev) {			first=first->prev;		}		return first;	} else return FALSE;}Llist *llist_detach_by_node (Llist *node) {	Llist *ptemp, *ntemp, *first;	if (node) {		ptemp=node->prev;		ntemp=node->next;		if (ptemp) {			ptemp->next=ntemp;		} else {			if (ntemp) ntemp->prev=NULL;			free (node);			return ntemp; 		}		if (ntemp) ntemp->prev=ptemp;		free (node);		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -