coolmessage.c
来自「具有IDE功能的编辑器」· C语言 代码 · 共 208 行
C
208 行
/* coolmessage.c - simple example usage of the coolwidget X API Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU 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 <coolwidget.h>#include "cmdlineopt.h"#include "pool.h"#include "mad.h"/* {{{ command-line options */#ifdef HAVE_DNDextern int option_dnd_version;#endif/* main and first window */Window main_window = 0;/* now window manager border */int option_unmanaged = 0;int option_x = 20;int option_y = 20;/* shell command to run */extern char *option_man_cmdline;/* argv[0] */char *argv_nought = 0;/* font from the library */extern char *init_font;/* server from command line */char *option_display = 0;/* font from the command line */char *option_font = "-*-helvetica-bold-r-*--14-*-*-*-p-*-*-*";static int get_help = 0;static int print_error = 0;static int get_version = 0;/* other things on the command line */static char *command_line_args[] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};void usage (void){ printf (\ _ ("Coolmessage version %s\nUsage:\n" \ "Coolmessage [options] <Message-Header>\n" \ "-d, -display <display> the X server to display on\n" \ "-f, -fn, -font <font-name> default: 8x13bold\n" \ "-e, -error print `error' to stdout if data\n" \ " is not empty.\n" \ "-h, -H, -?, --help print this message to stdout\n" \ "-V, -v, --version print versiom info\n" \ "\n" \ "Coolmessage reads from stdin and displays the result in\n" \ "a scrollable message box from the coolwidgets X Window widget\n" \ "library. If no data is read from stdin then coolmessage\n" \ "does nothing, otherwise (i.e. the data has non-zero length)\n" \ "it displays the input and (if the -error option is set)\n" \ "writes the string `error' to stdout.\n" \ "\n"), \ VERSION);}void version (void){ printf (_ ("Coolmessage version %s\n"), VERSION);}struct prog_options coolmessage_options[] ={ {' ', "", "", ARG_STRINGS, 0, command_line_args, 0},#ifdef HAVE_DND {0, "-dnd-old", "--dnd-old", ARG_CLEAR, 0, 0, &option_dnd_version},#endif {'f', "-fn", "-font", ARG_STRING, &option_font, 0, 0}, {'e', "-error", "", ARG_SET, 0, 0, &print_error}, {'x', "", "", ARG_INT, 0, 0, &option_y}, {'y', "", "", ARG_INT, 0, 0, &option_x}, {'h', "-?", "--help", ARG_SET, 0, 0, &get_help}, {'H', "-help", "--help", ARG_SET, 0, 0, &get_help}, {'V', "-v", "--version", ARG_SET, 0, 0, &get_version}, {0, "", "--unmanaged", ARG_SET, 0, 0, &option_unmanaged}, {'d', "", "-display", ARG_STRING, &option_display, 0, 0}, {0, 0, 0, 0, 0, 0, 0}};/* here we use our own function (which is better than get_opt() or get_opt_long()) */static void process_command_line (int argc, char **argv){ int error; error = get_cmdline_options (argc, argv, coolmessage_options); if (error) { fprintf (stderr, _ ("%s: error processing commandline argument %d\n"), argv[0], error); usage (); exit (1); } if (get_help) usage (); if (get_version) version (); if (get_help || get_version) exit (0);}/* }}} command-line options */void load_trivial_options (void);int main (int argc, char **argv){ POOL *p; CInitData coolmessage_startup; char *header = 0; Window focus; int revert_to; int i; setlocale (LC_CTYPE, ""); setlocale (LC_TIME, ""); setlocale (LC_MESSAGES, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); load_trivial_options (); process_command_line (argc, argv);/* initialise the library */ memset (&coolmessage_startup, 0, sizeof (coolmessage_startup)); coolmessage_startup.name = argv[0]; coolmessage_startup.display = option_display; coolmessage_startup.font = option_font; CInitialise (&coolmessage_startup); if (option_unmanaged) { XGetInputFocus (CDisplay, &focus, &revert_to); CSetOverrideRedirect (); } CDrawMainWindow ("dummy", "dummy"); p = pool_init (); for (;;) { int c; char ch; c = fgetc (stdin); if (c < 0) break; ch = c; pool_write (p, (unsigned char *) &c, 1); } pool_null (p); if (!pool_length (p)) exit (0); if (command_line_args[0]) { int l = 0; i = 0; while (command_line_args[i]) { l += strlen (command_line_args[i]) + 1; i++; } i = 0; header = CMalloc (l + 16); strcpy (header, " "); while (command_line_args[i]) { strcat (header, command_line_args[i]); strcat (header, " "); i++; } } else { header = (char *) strdup (_(" Message ")); } CTextboxMessageDialog (CRoot, option_x, option_y, 80, 25, header, (char *) pool_break (p), 0); if (print_error) printf ("error\n");/* close connection to the X display */ if (option_unmanaged) XSetInputFocus (CDisplay, focus, revert_to, CurrentTime); CShutdown (); exit (1); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?