degesch: add a --format switch
This commit is contained in:
		
							
								
								
									
										2
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								NEWS
									
									
									
									
									
								
							@@ -21,6 +21,8 @@
 | 
				
			|||||||
 * degesch: M-! and M-@ to go to the next buffer in order with
 | 
					 * degesch: M-! and M-@ to go to the next buffer in order with
 | 
				
			||||||
   a highlight or new activity respectively
 | 
					   a highlight or new activity respectively
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 * degesch: added --format for previewing things like MOTD files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 * kike: add support for IRCv3.2 server-time
 | 
					 * kike: add support for IRCv3.2 server-time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 * ZyklonB: plugins now run in a dedicated data directory
 | 
					 * ZyklonB: plugins now run in a dedicated data directory
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								degesch.c
									
									
									
									
									
								
							@@ -12803,6 +12803,21 @@ show_logo (struct app_context *ctx)
 | 
				
			|||||||
		log_global_indent (ctx, "#m", g_logo[i]);
 | 
							log_global_indent (ctx, "#m", g_logo[i]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					format_input_and_die (struct app_context *ctx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char buf[513];
 | 
				
			||||||
 | 
						while (fgets (buf, sizeof buf, stdin))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							struct formatter f;
 | 
				
			||||||
 | 
							formatter_init (&f, ctx, NULL);
 | 
				
			||||||
 | 
							formatter_add (&f, "#m", buf);
 | 
				
			||||||
 | 
							formatter_flush (&f, stdout, false);
 | 
				
			||||||
 | 
							formatter_free (&f);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						exit (EXIT_SUCCESS);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
main (int argc, char *argv[])
 | 
					main (int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -12814,11 +12829,14 @@ main (int argc, char *argv[])
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		{ 'h', "help", NULL, 0, "display this help and exit" },
 | 
							{ 'h', "help", NULL, 0, "display this help and exit" },
 | 
				
			||||||
		{ 'V', "version", NULL, 0, "output version information and exit" },
 | 
							{ 'V', "version", NULL, 0, "output version information and exit" },
 | 
				
			||||||
 | 
							// This is mostly intended for previewing formatted MOTD files
 | 
				
			||||||
 | 
							{ 'f', "format", NULL, OPT_LONG_ONLY, "format IRC text from stdin" },
 | 
				
			||||||
		{ 0, NULL, NULL, 0, NULL }
 | 
							{ 0, NULL, NULL, 0, NULL }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct opt_handler oh;
 | 
						struct opt_handler oh;
 | 
				
			||||||
	opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC client.");
 | 
						opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC client.");
 | 
				
			||||||
 | 
						bool format_mode = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int c;
 | 
						int c;
 | 
				
			||||||
	while ((c = opt_handler_get (&oh)) != -1)
 | 
						while ((c = opt_handler_get (&oh)) != -1)
 | 
				
			||||||
@@ -12830,6 +12848,9 @@ main (int argc, char *argv[])
 | 
				
			|||||||
	case 'V':
 | 
						case 'V':
 | 
				
			||||||
		printf (PROGRAM_NAME " " PROGRAM_VERSION "\n");
 | 
							printf (PROGRAM_NAME " " PROGRAM_VERSION "\n");
 | 
				
			||||||
		exit (EXIT_SUCCESS);
 | 
							exit (EXIT_SUCCESS);
 | 
				
			||||||
 | 
						case 'f':
 | 
				
			||||||
 | 
							format_mode = true;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		print_error ("wrong options");
 | 
							print_error ("wrong options");
 | 
				
			||||||
		opt_handler_usage (&oh, stderr);
 | 
							opt_handler_usage (&oh, stderr);
 | 
				
			||||||
@@ -12855,6 +12876,7 @@ main (int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// The following part is a bit brittle because of interdependencies
 | 
						// The following part is a bit brittle because of interdependencies
 | 
				
			||||||
	init_colors (&ctx);
 | 
						init_colors (&ctx);
 | 
				
			||||||
 | 
						if (format_mode)  format_input_and_die (&ctx);
 | 
				
			||||||
	init_global_buffer (&ctx);
 | 
						init_global_buffer (&ctx);
 | 
				
			||||||
	show_logo (&ctx);
 | 
						show_logo (&ctx);
 | 
				
			||||||
	setup_signal_handlers ();
 | 
						setup_signal_handlers ();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user