home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
m
/
master12.zip
/
mastering
/
filetimes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-19
|
12KB
|
389 lines
/************************************************************************
* File: filetimes.c
***********************************************************************/
/* information for 'what' */
char ident1[]="@(#)filetimes Version A.00.16 19 August 1992";
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <errno.h>
#include <Xm/MainW.h>
#include <Xm/CascadeB.h>
#include <Xm/RowColumn.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/FileSB.h>
#include <Xm/PushB.h>
#include <Xm/MessageB.h>
typedef struct
{
Widget widget;
} selectData;
void okCB ();
Widget CreateHelp ();
Widget CreateVersion ();
void VersionCB ();
void HelpCB ();
void QuitCB ();
/*-------------------------------------------------------------
** Global Variables
*/
#define MAX_ARGS 20
static XmStringCharSet charset = (XmStringCharSet) XmFONTLIST_DEFAULT_TAG;
/*-------------------------------------------------------------
** HelpCB - callback for help button
*/
void HelpCB (w, client_data, call_data)
Widget w; /* widget id */
XtPointer client_data; /* data from application */
XtPointer call_data; /* data from widget class */
{
Widget message_box; /* message box */
/* Create help window.
*/
message_box = CreateHelp (w);
/* Display help window.
*/
XtManageChild (message_box);
}
/*-------------------------------------------------------------
** CreateHelp - create help window
*/
Widget CreateHelp (parent)
Widget parent; /* parent widget */
{
Widget button;
Widget message_box; /* Message Dialog */
Arg args[MAX_ARGS]; /* arg list */
register int n; /* arg count */
static char message[BUFSIZ]; /* help text */
XmString title_string = NULL;
XmString message_string = NULL;
XmString button_string = NULL;
/* Generate message to display.
*/
sprintf (message, "\
The FileSelectionBox displays files in the current directory. You \n\
select a file by moving the pointer to that file name and clicking mouse \n\
button 1. Then move the pointer to the `ok' button and click mouse \n\
button 1 again. A message box will appear with the last file access time, \n\
the last file modification time, and the last file change time. Note \n\
that writing to a file changes both modification time and change time. \n\
See the man page for stat (2) and ctime (3C) for more information.\0");
message_string = XmStringCreateLtoR (message, charset);
button_string = XmStringCreateLtoR ("Close", charset);
title_string = XmStringCreateLtoR ("filetimes help", charset);
/* Create message box dialog.
*/
n = 0;
XtSetArg (args[n], XmNdialogTitle, title_string); n++;
XtSetArg (args[n], XmNokLabelString, button_string); n++;
XtSetArg (args[n], XmNmessageString, message_string); n++;
message_box = XmCreateMessageDialog (parent, "helpbox", args, n);
button = XmMessageBoxGetChild (message_box, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild (button);
button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (button);
/* Free strings and return message box.
*/
if (title_string) XmStringFree (title_string);
if (message_string) XmStringFree (message_string);
if (button_string) XmStringFree (button_string);
return (message_box);
}
/*-------------------------------------------------------------
** VersionCB - callback for help button
*/
void VersionCB (w, client_data, call_data)
Widget w; /* widget id */
XtPointer client_data; /* data from application */
XtPointer call_data; /* data from widget class */
{
Widget message_box; /* message box */
/* Create message window. */
message_box = CreateVersion (w);
/* Display version window. */
XtManageChild (message_box);
}
/*-------------------------------------------------------------
** CreateVersion - create version window
*/
Widget CreateVersion (parent)
Widget parent; /* parent widget */
{
Widget button;
Widget message_box; /* Message Dialog */
Arg args[MAX_ARGS]; /* arg list */
register int n; /* arg count */
static char message[BUFSIZ]; /* help text */
XmString title_string = NULL;
XmString message_string = NULL;
XmString button_string = NULL;
char text4[50];
strcpy (text4, &ident1[4]);
/* Generate message to display. */
sprintf (message, "This is %s \0",text4);
/* Create the compound strings */
message_string = XmStringCreateLtoR (message, charset);
button_string = XmStringCreateLtoR ("Close", charset);
title_string = XmStringCreateLtoR ("diskuse help", charset);
/* Create message box dialog. */
n = 0;
XtSetArg (args[n], XmNdialogTitle, title_string); n++;
XtSetArg (args[n], XmNokLabelString, button_string); n++;
XtSetArg (args[n], XmNmessageString, message_string); n++;
message_box = XmCreateMessageDialog (parent, "versionbox", args, n);
button = XmMessageBoxGetChild (message_box, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild (button);
button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (button);
/* Free strings and return message box. */
if (title_string) XmStringFree (title_string);
if (message_string) XmStringFree (message_string);
if (button_string) XmStringFree (button_string);
return (message_box);
}
/*-------------------------------------------------------------
** QuitCB - callback for quit button
*/
void QuitCB (w, client_data, call_data)
Widget w; /* widget id */
XtPointer client_data; /* data from application */
XtPointer call_data; /* data from widget class */
{
/* Terminate the application.
*/
exit (0);
}
/************************************************************************
* main
***********************************************************************/
main (argc, argv)
int argc;
char **argv;
{
int n;
Arg args[10];
Widget toplevel, main_window, menu_bar, menu_pane, button, fsbox;
Widget cascade, temp;
XmString str1, label_text;
XtAppContext app_context;
/*
* Initialize the toolkit.
*/
toplevel = XtAppInitialize (&app_context, "Filetimes", NULL, 0, &argc,
argv, NULL, args, 0);
/*
* Create main window.
*/
n = 0;
main_window = XmCreateMainWindow (toplevel, "main1", args, n);
XtManageChild (main_window);
/*
* Create menu bar in main window.
*/
n = 0;
menu_bar = XmCreateMenuBar (main_window, "menu_bar", args, n);
XtManageChild (menu_bar);
/*
* Create "File" pulldown menu.
*/
n = 0;
menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n);
n = 0;
button = XmCreatePushButton (menu_pane, "Exit", args, n);
XtManageChild (button);
XtAddCallback (button, XmNactivateCallback, QuitCB, NULL);
n = 0;
XtSetArg (args[n], XmNsubMenuId, menu_pane); n++;
cascade = XmCreateCascadeButton (menu_bar, "File", args, n);
XtManageChild (cascade);
/*
* Create "Help" pulldown menu.
*/
n = 0;
menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n);
n = 0;
button = XmCreatePushButton (menu_pane, "Help", args, n);
XtManageChild (button);
XtAddCallback (button, XmNactivateCallback, HelpCB, NULL);
n = 0;
button = XmCreatePushButton (menu_pane, "Program Version", args, n);
XtManageChild (button);
XtAddCallback (button, XmNactivateCallback, VersionCB, NULL);
n = 0;
XtSetArg (args[n], XmNsubMenuId, menu_pane); n++;
cascade = XmCreateCascadeButton (menu_bar, "Help", args, n);
XtManageChild (cascade);
n = 0;
XtSetArg (args[n], XmNmenuHelpWidget, cascade); n++;
XtSetValues (menu_bar, args, n);
/*
* Create the file selection box dialog
*/
str1 = XmStringCreateLtoR ("Files", XmFONTLIST_DEFAULT_TAG);
n = 0;
XtSetArg (args[n], XmNlistLabelString, str1); n++;
fsbox = XmCreateFileSelectionBox (main_window, "filesb", args, n);
XtManageChild (fsbox);
XmStringFree (str1);
XtAddCallback (fsbox, XmNokCallback, okCB, NULL);
temp = XmFileSelectionBoxGetChild (fsbox, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild (temp);
temp = XmFileSelectionBoxGetChild (fsbox, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (temp);
/*
* Set main window areas.
*/
XmMainWindowSetAreas (main_window, menu_bar, NULL, NULL, NULL, fsbox);
/*
* Realize the widget hierarchy and enter the main loop.
*/
XtRealizeWidget (toplevel);
XtAppMainLoop (app_context);
}
/************************************************************************
* okCB
***********************************************************************/
void
okCB (w, client_data, call_data)
Widget w;
XtPointer client_data;
XmFileSelectionBoxCallbackStruct *call_data;
{
Arg args[10];
Widget button, message_box;
XmString title_string = NULL;
XmString message_string = NULL;
XmString message_string1 = NULL;
XmString final_message_string = NULL;
XmString button_string = NULL;
XmString access_msg = NULL;
XmString access_time = NULL;
XmString mod_msg = NULL;
XmString mod_time = NULL;
XmString chg_msg = NULL;
XmString chg_time = NULL;
XmString accstring = NULL;
XmString modstring = NULL;
XmString chgstring = NULL;
XmString pathstring = NULL;
XmString carr_ret = NULL;
int n, stat_val;
static XmStringCharSet charset = (XmStringCharSet) XmFONTLIST_DEFAULT_TAG;
char *path;
struct stat bufr;
char *acctimptr, *modtimptr, *chgtimptr;
char *text, *text1, *text2;
Boolean testit, testit1, testit2;
n = 0;
carr_ret = XmStringCreateLtoR ("\012\012", charset);
pathstring = XmStringConcat (call_data->value, carr_ret);
testit = XmStringGetLtoR (call_data->value, charset, &path);
stat_val = stat (path, &bufr);
acctimptr = ctime(&bufr.st_atime);
access_time = XmStringCreateLtoR (acctimptr, charset);
access_msg = XmStringCreateLtoR ("Last access time = ", charset);
accstring = XmStringConcat (access_msg, access_time);
modtimptr = ctime(&bufr.st_mtime);
mod_time = XmStringCreateLtoR (modtimptr, charset);
mod_msg = XmStringCreateLtoR ("Last modification time = ", charset);
modstring = XmStringConcat (mod_msg, mod_time);
chgtimptr = ctime(&bufr.st_ctime);
chg_time = XmStringCreateLtoR (chgtimptr, charset);
chg_msg = XmStringCreateLtoR ("Last change time = ", charset);
chgstring = XmStringConcat (chg_msg, chg_time);
message_string = XmStringConcat (accstring, modstring);
message_string1 = XmStringConcat (message_string, chgstring);
final_message_string = XmStringConcat (pathstring, message_string1);
if (stat_val != 0) /* Error condition from stat */
final_message_string = XmStringCreateLtoR ("Invalid file or directory.", charset);
/* Create compound strings for message box button labels */
button_string = XmStringCreateLtoR ("Close", charset);
title_string = XmStringCreateLtoR ("File Times", charset);
/* Create message box dialog. */
n = 0;
XtSetArg (args[n], XmNmessageString, final_message_string); n++;
XtSetArg (args[n], XmNdialogTitle, title_string); n++;
XtSetArg (args[n], XmNokLabelString, button_string); n++;
message_box = XmCreateMessageDialog (w, "helpbox", args, n);
XtManageChild (message_box);
button = XmMessageBoxGetChild (message_box, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild (button);
button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (button);
}