📄 unravel.c
字号:
/********************************************************************* ** Unravel control panel ** ** Jim Lyle 9 June 1994 ** *********************************************************************/# include <stdio.h># include <errno.h># include <X11/Intrinsic.h># include <X11/StringDefs.h># include <X11/Shell.h># include <X11/Xaw/Form.h># include <X11/Xaw/Command.h># include <X11/Xaw/Label.h># include <X11/Xaw/SimpleMenu.h># include <X11/Xaw/SmeBSB.h># include <X11/Xaw/SmeLine.h># include <X11/Xaw/MenuButton.h># include <X11/Xaw/AsciiText.h># include <sys/types.h># include <dirent.h># include <sys/stat.h># include <sys/time.h># define WAIT 500# include "config.h"# define XtNlinkOnly "linkOnly" static char sccsid[] = "@(#)unravel.c 1.8 7/26/96";static int link_only = 0;typedef struct { Widget top,src,ana,not,out,prog,dup,link; Widget text; char *dir_buff;} label_rec,*label_ptr;Widget help_label;button_help (w,mess,e,ok) Widget w; char *mess; XEvent *e; Boolean *ok;{ XtVaSetValues (help_label, XtNlabel, (XtArgVal) mess, NULL);}set_button_help (w,mess) Widget w; char *mess;{ static char buff[] = "Description of object under mouse pointer is displayed here"; XtAddEventHandler (w,EnterWindowMask,False,button_help,mess); XtAddEventHandler (w,LeaveWindowMask,False,button_help,buff);}int compare(a,b) struct dirent **a,**b;{ if (strcmp((*a)->d_name,(*b)->d_name) > 0) return 1; return 0;}int myscandir (dir_name,list,select,compare) char *dir_name; struct dirent ***list; int (*select)(); int (*compare)();{ DIR *dir; struct dirent *entry; typedef struct l_struct ll_node,*ll; struct l_struct { ll next; struct dirent *e; }; int i,n_match = 0; ll new_ll; struct dirent *new_de; ll nodes,node_list = NULL; dir = opendir (dir_name); if (!dir){ fprintf (stderr,"directory open failed for %s\n", dir_name); exit(1); } for (entry = readdir(dir) ; entry != NULL ; entry = readdir(dir)){ if (select(entry)){ new_ll = (ll) malloc(sizeof (ll_node)); new_ll->next = node_list; node_list = new_ll; new_ll->e = (struct dirent *) malloc ( sizeof(struct dirent)+strlen(entry->d_name)+3); strcpy (new_ll->e->d_name,entry->d_name); n_match++; } } *list = (struct dirent **) malloc ( (n_match + 1)*sizeof(struct dirent *)); nodes = node_list; for (i = 0; i < n_match; i++){ (*list)[i] = nodes->e; nodes = nodes -> next; } qsort (*list,n_match,sizeof(struct dirent *),compare); return n_match;}int file_selector (entry) struct dirent *entry;{ int ix; ix = strlen (entry->d_name) - 2; if (ix > 0) if ((entry->d_name[ix] == '.') && (entry->d_name[ix+1] == 'c')){ return 1; } return 0;}int scan_dir(f) struct dirent ***f;{ struct dirent **files; int count; int i; count = myscandir (".",&files,file_selector,compare); files[count] = NULL; *f = files; return count;}count_lif(n,f,n_ana,n_not,n_out) int n,*n_ana,*n_not,*n_out; char **f;{ int nk = 0,k = 0,out = 0; struct stat status_c,status_lif,status_t; int c,lif,t; char buff[2000]; int s,i; for (i = 0; i < n; i++){ c = stat (f[i],&status_c); s = strlen(f[i]); strcpy (buff,f[i]); buff[s-1] = '\0'; strcat (buff,"LIF"); lif = stat (buff,&status_lif); strcpy (buff,f[i]); buff[s-1] = 'T'; t = stat (buff,&status_t); if ((lif == 0) && (t == 0)){ if ((status_c.st_mtime > status_t.st_mtime) || (status_c.st_mtime > status_lif.st_mtime)) out++; else k++; } else nk++; } *n_ana = k; *n_not = nk; *n_out = out;}count_system(n_prog,n_dup,n_link) int *n_prog,*n_dup,*n_link;{ int n = 0,k,j,s,k_ok,link_ok; int dup = 0; FILE *sys; char buff[2000],name[2000]; int ambig_state = 0; struct stat status_k,status_link; n = 0; *n_link = 0; sys = fopen ("SYSTEM","r"); if (sys){ while (fgets (buff,2000,sys)){ if (buff[0] == 'M'){ ambig_state = 0; k = sscanf(buff,"MAIN %s %d",name,&k); if (k == 2){ n++; strcpy (buff,name); s = strlen(name); buff[s-1] = '\0'; strcat (buff,"LINK"); link_ok = stat (buff,&status_link); buff[s-1] = '\0'; strcat (buff,"K"); k_ok = stat (buff,&status_k); if ((k_ok == 0) && (link_ok == 0)) (*n_link)++; } } else if (buff[0] == 'A'){ ambig_state = 1; } else if (buff[0] == 'F'){ ambig_state = 0; } else if (buff[0] == 'L'){ ambig_state = 0; } else if (ambig_state) dup++; } fclose(sys); } *n_prog = n; *n_dup = dup;}update (w,n,mess) Widget w; int n; char *mess;{ char buff[2000]; sprintf (buff,mess,n); XtVaSetValues (w,XtNlabel,buff,NULL);}update_src_info(label) label_ptr label;{ char **file_names = NULL; struct dirent **files; int n_files,i,n_analyzed,n_prog; int n_not,n_out,n_dup,n_link; Widget src,ana,not,out,prog,dup,link; src = label -> src; ana = label -> ana; not = label -> not; out = label -> out; prog = label -> prog; dup = label -> dup; link = label -> link; n_files = scan_dir(&files); file_names = (char **) malloc ((n_files + 1)*sizeof (char *)); for (i = 0; files[i] ; i++){ file_names[i] = files[i]->d_name; } file_names[n_files] = NULL; count_lif(n_files,file_names,&n_analyzed,&n_not,&n_out); count_system(&n_prog,&n_dup,&n_link); update (ana,n_analyzed,n_analyzed == 1?"%3d file analyzed & up to date": "%3d files analyzed & up to date"); update (src,n_files,n_files == 1?"%3d source file": "%3d source files"); update (not,n_not,n_not == 1?"%3d source file not analyzed": "%3d source files not analyzed"); update (out,n_out,n_out == 1?"%3d file analyzed & out of date": "%3d files analyzed & out of date"); update (link,n_link,n_link == 1?"%3d main program file linked": "%3d main program files linked"); update (prog,n_prog,n_prog == 1?"%3d main program file analyzed": "%3d main program files analyzed"); update (dup,n_dup,n_dup == 1?"%3d duplicate procedure found": "%3d duplicate procedures found");}ana_done (w,labels,e,ok) Widget w; XEvent *e; label_ptr labels; Boolean *ok;{ update_src_info(labels);}push_analysis(w,labels,w_data) Widget w; label_ptr labels; XtPointer w_data;{ char buff[2000]; static int set = 0; if (!set) { set = 1; XtAddEventHandler (w, NoEventMask,True,ana_done,labels); } sprintf (buff,"PATH=%s:$PATH ; analyzer %d &",HOME,XtWindow(w)); system (buff); update_src_info(labels);}push_review(w,hist,w_data) Widget w; int hist; XtPointer w_data;{ char buff[2000]; static char *title[] = { "Result of Last Analysis", "Last Slices Requested", "Log of Current Unravel Session", "Unravel Log of this Directory" }, *file_name[] = { "HISTORY-A", "HISTORY-S", "HISTORY", "HISTORY.LOG" }; sprintf (buff,"%s/helpu %s -geom +10+10 -title \"%s\" %s &", HOME,"-xrm \"*Command.label: History Review Done\"", title[hist],file_name[hist]); system(buff);}push_slice(w,u_data,w_data) Widget w; XtPointer u_data; XtPointer w_data;{ char buff[2000]; sprintf (buff,"%s/select %s >HISTORY-S 2>&1 &",HOME, link_only?"-noslice":""); system (buff);}push_dir(w,labels,w_data) Widget w; XtPointer w_data; label_ptr labels;{ char buff[2000]; int status; XawTextPosition from,to; XawTextBlock block; status = chdir (labels->dir_buff); if (status){ strcpy (buff,(char *)getcwd(NULL,1000)); block.firstPos = 0; block.length = strlen (buff); block.ptr = buff; block.format = FMT8BIT; from = 0; to = strlen (labels->dir_buff); /* XawTextReplace (labels->text,from,to,&block); XawTextSetInsertionPoint (labels->text,block.length); */ } else { update_src_info(labels); sprintf (buff, "echo -n \"Unravel change directory: %s \" >> HISTORY", labels->dir_buff); system(buff); system("date >> HISTORY"); }}push_help(w,u_data,w_data) Widget w; XtPointer u_data; XtPointer w_data;{ char buff[2000]; sprintf (buff,"%s/helpu -geom +10+10 %s/unravel.help %s &",HOME,HOME, "-title \"Unravel Main Help\" "); system (buff);}done(w,u_data,w_data) Widget w; XtPointer u_data; XtPointer w_data;{ system ("/bin/cat HISTORY >> HISTORY.LOG; /bin/rm -f HISTORY *ERR"); exit (0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -