hoford@sequoia.upenn.edu (John Hoford) (12/12/90)
This c progam allows you to type hp commands on your unix machine. ------ cut here -------- /* This progams runs on a sun4 os4.1 and should run on most unix boxes. It runs kermit in background and sends the commands you type in to the hp48 by appending them to "remote host". All commands should be upper case. You can place multiple commands on a line ( 10 2 / ). It responds by outputing the stack. You can also type the dir command which runs "remote dir" and done which quits configure your .kermrc to your "line" and "baud" and run progam. please send improvements to hoford@gynko.circ.upenn.edu */ #include<stdio.h> #include<signal.h> #define TRUE 1 int reap_kermit(); char str[80]; char cmd_str[30]; main() { int kin[2]; int pid; int head_len; int i; strcpy(str,"remote host "); head_len = strlen(str); pipe(kin); /* make a pipe */ signal(SIGCHLD,kermit_end); /* when child exits call kermit_end func */ if ((pid = fork()) == -1) { fprintf(stderr,"erro cannot fork\n"); exit(1); } if (pid==0) /* in child child*/ { close(0); dup(kin[0]); execl("/usr/local/bin/kermit",NULL); /*call kermit fprintf(stderr,"could not execl\n"); /* shold not reach hear */ exit(2); } /*-------- in parent---------- */ while(TRUE) /* loop forever */ { gets(cmd_str); /* read cmd line */ if (strcmp("done",cmd_str)) /* if cmd is not done */ { if (strcmp("dir",cmd_str)) /* if cmd is not dir */ { if (strlen(cmd_str) != 0) { cmd_str[strlen(cmd_str)] = '\n'; /* append "\n" */ cmd_str[strlen(cmd_str)+1] = (char) 0; for(i=0;i<strlen(cmd_str);i++) /* remove after \n */ if (cmd_str[i] == '\n') { cmd_str[i+1] = 0; break; } strcpy(&(str[head_len]),cmd_str); /* apend to rem host */ write(kin[1],str,strlen(str)); /* write to stdin of */ /* kermit */ } } else /* if dir run remote dir*/ { write(kin[1],"remote dir\n",strlen("remote dir\n")); } } else /* if done */ { printf("kill kermit \n"); write(kin[1],"bye\n",4); /* shut down hp server */ write(kin[1],"quit\n",5); /* quit kermit */ sleep(2); /* wait awhile */ kill(pid,SIGTERM); /* make shure kill again */ exit(1); /* done */ } } } kermit_end() /* if died print the string that killed */ { printf("kermit died str = %s\n",str); exit(); } -- Steven D. Kugelmass, Ph.D. Director, Computer Science Cardiothoracic Imaging Research Center Department of Radiology