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

📄 debug.c

📁 bonddb 是一个源于PostgreSQL封装包的对象。它是一个由C/C++编写的快速数据提取层应用软件
💻 C
📖 第 1 页 / 共 2 页
字号:
 * Set the output stream, it uses stdio FILE streams.  This is where most * messages are logged to.   */voiddebug_debugstream_set(FILE * stream)	{	if (globaldebuginfo.debug_stream != stdout && globaldebuginfo.debug_stream != stderr	        && globaldebuginfo.debug_stream != NULL)		fclose(globaldebuginfo.debug_stream);	globaldebuginfo.debug_stream = stream;	}/** * debug_errorstream_set: * @stream:  *  * Set the error stream, it uses stdio FILE streams. Everything to the error * streams is also outputted to debug streams. */voiddebug_errorstream_set(FILE * stream)	{	if (globaldebuginfo.error_stream != stdout && globaldebuginfo.error_stream != stderr	        && globaldebuginfo.error_stream != NULL)		fclose(globaldebuginfo.error_stream);	globaldebuginfo.error_stream = stream;	}/** * debug_cleanup: *  * Free up all the streams and depart.  * */voiddebug_cleanup(void)	{	if (debug_stream != stdout && debug_stream != stderr && debug_stream != NULL)		{		fclose(debug_stream);		debug_stream = NULL;		}	/* WRITE ME */	}/** * debug_setcolour: * * Set the current colour for debugging messages. You need to reset the colour * to disable it. */voiddebug_setcolour(gchar * colour)	{	/* Need some fancy stuff here, or maybe not. Could set colours by a number or hex or something more easier than	   those strings and then set like that. */	if (globaldebuginfo.currentcolour != NULL)		mem_free(globaldebuginfo.currentcolour);	globaldebuginfo.currentcolour = mem_strdup(colour);	}voiddebug_usecolour(gboolean use)	{	globaldebuginfo.colour = use;	}/*****************************************************************  Francis: Old functions start from here I left them due to compatability reason. For example, if you use old obsolete APIs, such as debug_getstream(), you will get old FILE pointer's value. ******************************************************************//** * setdebuglinenum: * @d:  *  * Marked as OBSOLETE. */voidsetdebuglinenum(gint d)	{	debug_linenumshow = d;	}/** * setdebuginfo: * @d:  *  * Marked as OBSOLETE. */voidsetdebuginfo(gint d)	{	debug_info = d;	}/** * hidedebuginfo: * @d:  *  * Marked as OBSOLETE. */voidhidedebuginfo()	{	debug_stream = fopen("debugmsg.log", "wt");	}/** * showdebuginfo: * @d:  *  * Marked as OBSOLETE. */voidshowdebuginfo()	{	if (debug_stream != stdout && debug_stream != stderr && debug_stream != NULL)		fclose(debug_stream);	debug_stream = stdout;	}/* talk about emtpy C files */voiddebug_printinfo(gchar * file, gint line, gchar * function, void *ptr)	{	if (debug_linenumshow == 0)		fprintf(debug_stream, " <%s:%d %s();>\n", file, line, function);	else		{		fprintf(debug_stream, " <%s: %s();>\n", file, function);		}	}FILE *debug_getstream(void)	{	return debug_debugstream_get();	}#if GTK_DEBUGNOTEstatic FILE *globalfp = NULL;/* example-start helloworld helloworld.c *//* This is a callback function. The data arguments are ignored * in this example. More on callbacks below. */static void hello(GtkWidget * widget, gpointer data);static void launch_control_panel();static void debug_showwin(gchar * message);static voidhello(GtkWidget * widget, gpointer data)	{	gchar *message;	long filesize;	g_print("Hello World\n");	if (!globalfp)		{		return ;		}	fseek(globalfp, 0L, SEEK_END);	filesize = ftell(globalfp);	rewind(globalfp);	printf("size: %ld\n", filesize);	message = malloc((int)sizeof(gchar) * (filesize + 1));	fread(message, sizeof(gchar), filesize, globalfp);	message[(int)filesize] = '\0';	printf("%s\n", message);	debug_showwin(message);	fclose(globalfp);	unlink("./debug.log");	globalfp = NULL;	}static voidlaunch_control_panel()	{	/* GtkWidget is the storage type for widgets */	GtkWidget *window;	GtkWidget *button;	/* create a new window */	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);	gtk_window_set_title(GTK_WINDOW(window), "Debug Manager");	/* Sets the border width of the window. */	gtk_container_set_border_width(GTK_CONTAINER(window), 10);	/* Creates a new button with the label "Hello World". */	button = gtk_button_new_with_label("Show Next");	gtk_signal_connect_object(GTK_OBJECT(window), "delete_event",	                          GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(window));	gtk_signal_connect_object(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(window));	/* When the button receives the "clicked" signal, it will call the function hello() passing it NULL as its argument.	   The hello() function is defined above. */	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(hello), NULL);	/* This will cause the window to be destroyed by calling gtk_widget_destroy(window) when "clicked".  Again, the	   destroy signal could come from here, or the window manager. */	/*	   gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT	   (window)); */	/* This packs the button into the window (a gtk container). */	gtk_container_add(GTK_CONTAINER(window), button);	/* The final step is to display this newly created widget. */	gtk_widget_show(button);	/* and the window */	gtk_widget_show(window);	return ;	}/* example-end */static voiddebug_showwin(gchar * message)	{	GtkWidget *dialog, *label, *okay_button;	GtkWidget *text, *scrollwin;	gchar *title;	static int counts = 0;	int pos;	/* Create the widgets */	title = g_strdup_printf("Notifier %d", counts++);	dialog = gtk_dialog_new();	gtk_window_set_title(GTK_WINDOW(dialog), title);	gtk_window_set_policy(GTK_WINDOW(dialog), TRUE, TRUE, FALSE);	g_free(title);	// label = gtk_label_new(message);	/* Text Area */	text = gtk_text_new(NULL, NULL);	gtk_widget_ref(text);	gtk_object_set_data_full(GTK_OBJECT(dialog), "text", text, (GtkDestroyNotify) gtk_widget_unref);	gtk_editable_insert_text(GTK_EDITABLE(text), message, strlen(message), &pos);	/* Scrolled Window */	scrollwin = gtk_scrolled_window_new(NULL, NULL);	gtk_widget_ref(scrollwin);	gtk_object_set_data_full(GTK_OBJECT(dialog), "scrollwin", scrollwin, (GtkDestroyNotify) gtk_widget_unref);	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);	/* OK button */	gtk_window_set_modal((GtkWindow *) dialog, TRUE);	okay_button = gtk_button_new_with_label("OK!");	/* Ensure that the dialog box is destroyed when the user clicks ok. */	gtk_signal_connect_object(GTK_OBJECT(okay_button), "clicked",	                          GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer) dialog);	/* Add the label, and show everything we've added to the dialog. */	gtk_container_add(GTK_CONTAINER(scrollwin), text);	gtk_container_add(GTK_CONTAINER(scrollwin), text);	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), scrollwin);	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), okay_button);	gtk_widget_show_all(dialog);	}/** * debugnote: *  * A popup window is shown with the message. *  */voiddebugnote(const char *fmt, ...)	{	va_list ap;	gchar *title;	char message[MSG_BUF_SIZE];	static int notecount = 0;	GtkWidget *dialog, *label, *okay_button;	/* Comment out to enable more than 30 pops, else it will quit */	g_assert(notecount < 30);	va_start(ap, fmt);	vsnprintf(message, MSG_BUF_SIZE, fmt, ap);	va_end(ap);	/* Create the widgets */	dialog = gtk_dialog_new();	title = g_strdup_printf("=== Note %d ===", notecount++);	gtk_window_set_title(GTK_WINDOW(dialog), title);	g_free(title);	gtk_window_set_modal((GtkWindow *) dialog, TRUE);	label = gtk_label_new(message);	okay_button = gtk_button_new_with_label("Okay");	/* Ensure that the dialog box is destroyed when the user clicks ok. */	gtk_signal_connect_object(GTK_OBJECT(okay_button), "clicked",	                          GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer) dialog);	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), okay_button);	/* Add the label, and show everything we've added to the dialog. */	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);	gtk_widget_show_all(dialog);	}/** * debugwin: *  * Display a window containing debugging output. *  */voiddebugwin(const char *fmt, ...)	{	va_list ap;	static int count = 0;	static gboolean launched = FALSE;	if (!globalfp)		{		globalfp = fopen("./debug.log", "w+");		}	fprintf(globalfp, "%3d ", count);	va_start(ap, fmt);	vfprintf(globalfp, fmt, ap);	va_end(ap);	fprintf(globalfp, "\n");	fflush(globalfp);	if (!launched)		{		launched = TRUE;		launch_control_panel();		}	count++;	}#elsevoiddebugnote(const char *fmt, ...)	{}voiddebugwin(const char *fmt, ...)	{}#endifginttest_total(gint pass, gint total)	{	if (pass != total)		{		error_output("TEST FAILED, with %d out of %d\n", pass, total);		return -1;		}	debug_output("TEST PASSED\n");	return 0;	}ginttest_result(gchar * retstr, gchar * shouldbe, gint * pass)	{	if (retstr == NULL)		{		error_output("Test of %s failed due to NULL value, it should be %s\n", retstr,shouldbe);		return -2;		}	if (strcmp(retstr, shouldbe) == 0)		{		(*pass)++;		return 0;		}	error_output("Test result compare of %s and %s failed\n", retstr, shouldbe);	return -1;	}voidtest_annonce(gint testnum, gchar * testdescr)	{	debug_output("TEST STARTING: (%d) %s\n", testnum, testdescr);	}

⌨️ 快捷键说明

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