Re: #200264 and xmessage
On 26.04.04 Frank Küster (frank@debian.org) wrote:
> Hilmar Preusse <hille42@web.de> schrieb:
Hi all,
> > The source is attached, builds and runs with libxaw6 and libxaw7.
> > Further the patch for debian/rules.
>
> Thank you. Wouldn't it be better to give it on argument, and let it
> write
>
> "Please install the package\n\"perl-tk\" to use $1."
>
> so that we can reuse it when there's an other program that depends on
> perl-tk? Or even two arguments, the second being the package name?
>
I think we don't need 2 arguments. patch attached, to be applied to
my first posted C file. Is now able to display multi line messages.
example usage:
./texdoctk-warn "please install the package\n\"perl-tk\" to use texdoctk"
kudos to Stefan for implementing > 99% of it.
Hilmar
--
Superstition, idolatry, and hypocrisy have ample wages, but truth goes
a-begging.
-- Martin Luther
http://hilmarpreusse.forum-rheinland.de/
--- texdoctk-warn.c Wed Apr 28 10:58:40 2004
+++ texdoctk-warn-new.c Wed Apr 28 10:56:57 2004
@@ -5,6 +5,8 @@
gcc -o texdoctk-warn -O2 -W -Wall -ansi -pedantic -L/usr/X11R6/lib -lXaw -lXt -lX11 texdoctk-warn.c
*/
#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/StringDefs.h>
@@ -26,14 +28,50 @@
exit(0);
}
+static char *
+normalize_newline(char *str)
+{
+ int i, k;
+ for (i = 0, k = 0; str[i] != '\0'; i++, k++) {
+ if (str[i] == '\\' && str[i + 1] == 'n') {
+ /* escaped `\n': change `\\n' to `\n' */
+ if (i > 1 && str[i - 1] == '\\') {
+ str[k] = str[i + 1];
+ }
+ else {
+ str[k] = '\n';
+ }
+ i++;
+ }
+ else {
+ str[k] = str[i];
+ }
+ }
+ str[k] = '\0';
+ return str;
+}
+
int main(int argc, char *argv[])
{
XtAppContext app_context;
Widget toplevel, paned, text, box, button;
int offset = 6;
XtAccelerators accels;
- /* test for multi-lines */
- const char *msg = "Please install the package\n\"perl-tk\" to use texdoctk.";
+ char *msg = NULL;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s message\n", argv[0]);
+ exit(1);
+ }
+ if ((msg = malloc(strlen(argv[1]) + 1)) == NULL) {
+ fprintf(stderr, "Couldn't allocate space for `%s'!\n", argv[1]);
+ exit(1);
+ }
+
+ strcpy(msg, argv[1]);
+
+ /* replace "\n" in msg (2 chars) by `\n' (one char) */
+ msg = normalize_newline(msg);
toplevel = XtAppInitialize(&app_context, "Info",
NULL, 0,
Reply to: