<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

CS 476/576
Systems Programming
Fall 2008
Midterm Exam
Time 2 & 1/2 hours
Open Book & Notes

 

 

 

 Name:

 Unix Login:

 

Each Question is 20 points.

 

 


Question 1:

The standard UNIX command host converts a host IP address t o host domain name,

For example:

% host 128.82.4.118

118.4.82.128.in-addr.arpa domain name pointer deneb.cs.odu.edu.

Write a shell script Qhost that have the following description:

Qhost   <IP address>

The output of this command is the host name.

For example:

% Qhost  128.82.4.118

deneb

Ansewer:


 

Question 2:

 

The standard UNIX command  who produces a line for each login window,

For example:

% who

aamr     pts/8        Oct  2 15:56 (h160202.s160.odu.edu)

cs476    pts/9        Oct  4 22:19 (antares.cs.odu.edu)

djordan  pts/15       Oct  4 20:56 (c-71-63-63-218.hsd1.va.comcast.net)

cs476    pts/16       Oct  4 22:18 (antares.cs.odu.edu)

Write a shell script called Qwho that have the following description:

Qwho 

The output of this command is a no-duplicate sorted list of users followed by the number of users.

For example:

% Qwho

aamr

cs476

djordan

3

Ansewer:


Question 3:

 

Write a curses program called Qcurses that displays the string name “WAHAB” diagonally as:

 

% Qcurses

 

                    W

                        A

                           H

                              A

                                 B

 

Ansewer:


Question 4:

 

The following program is a listing of the xlines program presented in class.

Modify the program, call it  Qxlib  such that the program draws a dot  at the first  pointer click

After that  it draws a line segment between each pointer click  and the preceeding pointer click.

 

main(argc,argv)
int argc;
char **argv;
{

  Display *display;
  Window root, window;
  long fgcolor, bgcolor;
  int screen, pointx, pointy ;
  int FirstPt = TRUE;
  long eventmask = ButtonPressMask|ExposureMask|KeyPressMask;
  XEvent event;
  XGCValues gcval;
  GC draw;
  Colormap cmap;
  XColor color, ignore;
  char *colorname = "blue";

 

 

 

  if (!(display = XOpenDisplay(argv[1]))) {
    perror("XOpenDisplay");
    exit(1);
  }

  root = RootWindow(display,screen = DefaultScreen(display));
  fgcolor = BlackPixel(display,screen);
  bgcolor = WhitePixel(display,screen);

  window = XCreateSimpleWindow(display,root,0,0,400,400,2,fgcolor,bgcolor);

  cmap = DefaultColormap (display, screen);
  XAllocNamedColor(display, cmap, colorname, &color, &ignore);
  fgcolor = color.pixel;
  gcval.foreground = fgcolor;
  gcval.background = bgcolor;
  draw = XCreateGC(display,window,GCForeground|GCBackground,&gcval);

  XSelectInput(display,window,eventmask);
  XMapWindow(display,window);


  for (;;) {
   

    XWindowEvent(display,window,eventmask,&event);
   

    switch (event.type) {
  

    case Expose:
      XClearWindow(display,window);
      break;
  

    case ButtonPress:
      if (FirstPt) {
        FirstPt=FALSE;
        pointx = event.xbutton.x;
        pointy = event.xbutton.y;
        XDrawPoint (display,window,draw, pointx, pointy);
        break;
      }
      else {
        FirstPt=TRUE;
        XDrawLine (display,window,draw, pointx,pointy,
            event.xbutton.x, event.xbutton.y);
        break;
      }
   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   

 

    case KeyPress:
      exit(0);
    default:
      fprintf(stderr,"Unexpected event: %d\n",event.type);
    }
  }
}


 

Question 5:

 

The following program creates a  motif interface with a ingle button, the Quit button.

Modify the program, call it Qmotif, to add two more buttons labeled Qcurses and Qxlib

to execute the commands of  Questions 3 and 4.

 

void quitCallback ( Widget w, XtPointer clientData, XtPointer callData );

 

 

void main ( int argc, char **argv )
{
            Widget shell, commands,  quit;

 

      XtAppContext app;

            shell = XtAppInitialize ( &app, "Xecute", NULL, 0, &argc, argv, NULL, NULL, 0 );


      commands =  XtVaCreateManagedWidget ( "commands",  xmRowColumnWidgetClass,  shell,  XmNnumColumns, 3, XmNorientation, XmHORIZONTAL,  NULL );


     quit = XtVaCreateManagedWidget ( "Quit", xmPushButtonWidgetClass, commands, NULL, 0 );

 

 

 

 

   XtAddCallback ( quit, XmNactivateCallback, quitCallback, NULL);

 

 

 

 

      XtRealizeWidget ( shell );
            XtAppMainLoop ( app );
}

void quitCallback ( Widget w, XtPointer clientData, XtPointer callData )
{
            exit ( 0 );
}