Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ XtInputCall(3) — OSF1 1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

XtAppAddInput(1)

 

Name

XtInputCallbackProc — prototype procedure called to handle file, pipe, or socket input. 

Synopsis

typedef void (∗XtInputCallbackProc)(XtPointer, int ∗, XtInputId ∗);

XtPointer client_data;
int ∗source;
XtInputId ∗id;

Arguments

client_data
Specifies the client data that was registered for this procedure in XtAppAddInput. 

sourceSpecifies the source file descriptor generating the event. 

idSpecifies the ID returned from the corresponding XtAppAddInput call. 

Description

An XtInputCallbackProc is registered by calling XtAppAddInput.  id is the return value from the procedure that registered it. 

An XtInputCallbackProc is called when there is activity in file source.  A procedure of this type is called to handle the type of file activity (input, output) it was registered for.  Note that because the code for reading and writing files varies between operating systems, this code is inherently non-portable. 

Examples

The example below shows an XtInputCallbackProc named get_file_input together with the application used to register it. 

/∗ header files ∗/
  .
  .
  .
/∗ ARGSUSED ∗/
get_file_input(client_data, fid, id)
XtPointer client_data;  /∗ unused ∗/
int ∗fid;
XtInputId ∗id;
{
    char buf[BUFSIZ];
    int nbytes;
    int i;
     if ((nbytes = read(∗fid, buf, BUFSIZ)) == -1)
        perror("get_file_input");
     if (nbytes)
        for (i = 0; i < nbytes; i++)
            putchar(buf[i]);
}
 main(argc, argv)
int argc;
char ∗∗argv;
{
    XtAppContext app_context;
    Widget topLevel, goodbye;
    FILE ∗fid;
    String filename;
     topLevel = XtVaAppInitialize(
        &app_context,       /∗ Application context ∗/
        "XFileInput",       /∗ Application class ∗/
        NULL, 0,            /∗ command line option list ∗/
        &argc, argv,        /∗ command line args ∗/
        NULL,               /∗ for missing app-defaults file ∗/
        NULL);              /∗ terminate varargs list ∗/
     if (argv[1] == NULL) {
        fprintf(stderr,
            "xfileinput: filename must be specified on command line.\n");
        exit(1);
    }
     filename = argv[1];
      .
      .
      .
    /∗ open file, pipe, or socket ∗/
    if ((fid = fopen(filename, "r")) == NULL)
        fprintf(stderr, "xfileinput: couldn’t open input file.\n");
     /∗ register function to handle that input ∗/
    XtAppAddInput(app_context, fileno(fid), XtInputReadMask,
            get_file_input, NULL);
     XtRealizeWidget(topLevel);
    XtAppMainLoop(app_context);
}

See Also

XtAppAddInput(1)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026