/**************************************************************** Uebungen zur Vorlesung "Graphische Datenverarbeitung" Sommersemester 1996 Programm: xdatum.c Autor: Christian Boehm ****************************************************************/ # include # include # include # include # include # include /* Globale Variablen */ XtAppContext kontext; /* Applikations-Umgebung */ Widget LabelWidget ; /* Zur Ausgabe des Datums */ static char * fallbackRessourcen [] = { "*titel.labelString: Datum67890", "*exit.labelString: EXIT", NULL } ; /* Callback-Prozeduren */ void TimerCallb (XtPointer dummy1, XtIntervalId * dummy2) { FILE * pipe ; char str [80] ; XmString compoundstring ; int hor, min, sec, timerval ; /* Das Datum wird durch Shell-ufruf ermittelt */ pipe = popen ("date +%d.%m.%Y.%H.%M.%S", "r") ; fscanf (pipe, "%10s.%d.%d.%d", str, &hor, &min, &sec) ; pclose (pipe) ; str [10]='\0' ; /* Stunden, Minuten und Sekunden zur Ermittlung des Zeitintervalls bis Mitternacht */ timerval = 24*3600-(hor*60+min)*60+sec ; /* printf ("%d %d %d %d \n", hor, min, sec, timerval) ; */ compoundstring = XmStringCreateLocalized (str) ; XtVaSetValues (LabelWidget, XmNlabelString, compoundstring, NULL) ; XmStringFree (compoundstring) ; XtAppAddTimeOut (kontext, 1000 * timerval, TimerCallb, (XtPointer)NULL) ; } void exitCB (Widget w, XtPointer p1, XtPointer p2) { exit (0) ; } void InitWidgetBaum (Widget applShell) { Widget box, exitBt ; box = XtCreateManagedWidget ("box", xmRowColumnWidgetClass, applShell, (Arg*)NULL, 0); LabelWidget = XtCreateManagedWidget ("titel", xmLabelWidgetClass, box, (Arg*)NULL, 0); exitBt = XtCreateManagedWidget ("exit", xmPushButtonWidgetClass, box, (Arg*)NULL, 0); XtAddCallback (exitBt, XmNactivateCallback, exitCB, (XtPointer)NULL); TimerCallb ((XtPointer) 0, (XtIntervalId *) 0) ; } main (int argc, char ** argv) { Widget applShell; /* Applikations-Shell */ applShell = XtAppInitialize (&kontext, "XDatum", (XrmOptionDescRec*)NULL, 0, &argc, argv, fallbackRessourcen, (Arg*)NULL, 0); InitWidgetBaum (applShell); XtRealizeWidget (applShell); /* Hauptschleife zur Ereignisbehandlung: */ XtAppMainLoop (kontext); }