📄 analyzer.c
字号:
/********************************************************************* ** Unravel control panel for analyzer ** ** Jim Lyle 10 June 1994 ** *********************************************************************/# include <stdio.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/AsciiText.h># include <X11/Xaw/List.h># include <X11/Xaw/Viewport.h># include <X11/Xaw/SimpleMenu.h># include <X11/Xaw/SmeBSB.h># include <X11/Xaw/SmeLine.h># include <X11/Xaw/MenuButton.h># include <sys/types.h># include <dirent.h># include <sys/stat.h># include <sys/time.h># define WAIT 500# include "config.h" static char sccsid[] = "@(#)analyzer.c 1.5 8/16/95";/*# define XtNrunningFG "runningFG"# define XtNrunningBG "runningBG" static XrmOptionDescRec opt[] = { {"-runningfg", "*runningFG", XrmoptionSepArg,NULL}, {"-runningbg", "*runningBG", XrmoptionSepArg,NULL}}; static XtResource res[] = { {XtNrunningFG,XtCForeground, XtRPixel, sizeof(Pixel), XtOffsetOf(struct app_resources,fg),XtRString,"red"}, {XtNrunningBG,XtCForeground, XtRPixel, sizeof(Pixel), XtOffsetOf(struct app_resources,bg),XtRString,"yellow"}}; top = XtAppInitialize (&ac,"Xtform",opt,XtNumber(opt),&np,p,fall,NULL,0); XtGetApplicationResources (top,&a_res,res,XtNumber(res),NULL,0); struct dirent { char d_name[1000]; };*/# define XtNrunningFG "runningFG"# define XtNrunningBG "runningBG"Widget help_label;int unravel_win_id = 0;typedef struct name_struct name_rec,*name_ptr;struct name_struct { char **use,**skip,**pick; struct dirent **files; Widget keep,ignore;};typedef struct nf_struct nf_rec,*nf_ptr;struct nf_struct { XtAppContext ac; name_ptr n; Widget s,r,h; int at; int of; int errs; int running; char current[500]; char *flags; char *pflags; FILE *history; Pixel run_fg,run_bg,save_fg,save_bg;};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;}static int select_c_file(entry) struct dirent *entry;{ int len; if (!entry) return 0; len = strlen(entry->d_name); if (len < 2) return 0; if ((entry->d_name[len-2] != '.') || (entry->d_name[len-1] != 'c')) return 0; return 1;}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); /* *(new_ll->e) = *entry; */ 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 scan_dir(f) struct dirent ***f;{ struct dirent **files; int count; int alphasort(); int i; count = myscandir (".",&files,select_c_file,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) int *n_prog,*n_dup;{ int n = 0,k,j; int dup = 0; FILE *sys; char buff[2000],name[2000]; int ambig_state = 0; n = 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++; } 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;}notify_unravel (w) Widget w;{ XClientMessageEvent e; Status status = 13; strcpy (e.data.b,"done"); e.display = XtDisplay(w); e.window = unravel_win_id; e.type = ClientMessage; e.format = 8; e.message_type = (Atom) 1; if (unravel_win_id){ status = XSendEvent (e.display,e.window,True,0L,&e); XFlush(e.display); }}do_final_analysis (nf,tt) nf_ptr nf; XtIntervalId *tt;{ char buff[2000]; sprintf (buff,"%s ; %s ;%s/map >> HISTORY-A 2>&1", "echo \" \" >>HISTORY-A","echo running map >> HISTORY-A", HOME); system(buff); if (nf->errs) sprintf (buff, "Analysis complete, %d file%s not ANSI C", nf->errs, nf->errs == 1?"":"s"); else sprintf (buff,"Analysis complete"); XtVaSetValues (nf->s, XtNlabel, buff, XtNforeground,nf->save_fg, XtNbackground,nf->save_bg, NULL); nf->running = 0; notify_unravel (nf->s); if(nf->r)XtVaSetValues (nf->r, XtNlabel, (XtArgVal) "Analyze Selected Files", NULL); return;}do_analysis (nf,tt) nf_ptr nf; XtIntervalId *tt;{ char buff[2000],file[1000],mess[3000]; int i,k,cpp_status,parse_status,status,c_status,t_status; int n,result; int len; struct stat cpp_stat,parse_stat,c_stat,t_stat; XawTextPosition insert; XawTextBlock chunk; Widget src; time_t start,finish,elapsed; int rate; if (nf->running == 0){ XtVaSetValues (nf->s, XtNlabel, "Analysis stopped", NULL); XtVaSetValues (nf->r, XtNsensitive,True, NULL); return; } chunk.firstPos = 0; chunk.format = FMT8BIT; chunk.ptr = mess; i = nf->at; n = nf->of; strcpy (file,nf->n->use[i]); c_status = stat (file,&c_stat); len = strlen(file); if (len > 1) file[len-2] = '\0'; status = unlink ("CPP.ERR"); status = unlink ("PARSE.ERR"); sprintf (buff, "PATH=%s; %s -E %s %s.c 2>CPP.ERR | %s %s -o %s.LIF", HOME, CC, nf->flags, file, "parser 2>PARSE.ERR", nf->pflags, file); start = time(NULL); system (buff); /* printf ("analyze: %s\n",buff); */ finish = time(NULL); elapsed = finish - start; if (elapsed <= 0) elapsed = 1; cpp_status = stat ("CPP.ERR",&cpp_stat); parse_status = stat ("PARSE.ERR",&parse_stat); if (/* cpp_stat.st_size || */ parse_stat.st_size){ /* compile error */ sprintf (mess, "%s is not ANSI C (compile errors)", nf->n->use[i]); nf->errs++; } else { /* no errors */ sprintf (buff,"wc %s.c >>%s.T",file,file); system(buff); sprintf (buff,"%s/tsummary %s.c >>HISTORY-A", HOME,file); system(buff); sprintf (buff, "PATH=%s:$PATH ; export PATH ; vprep %s.c",HOME,file); system(buff); if (finish-start)rate = c_stat.st_size / (elapsed); else rate = c_stat.st_size; sprintf (mess, "%s (%d chars) analysis complete %d secs %d chars/sec", nf->n->use[i], c_stat.st_size,elapsed,rate); } sprintf (buff,"echo \"%s\" >> HISTORY-A ; %s", mess,"cat *.ERR >>HISTORY-A"); system(buff); i++; nf -> at = i; if ( i < n ){ XtAppAddTimeOut (nf->ac,WAIT,do_analysis,nf); if (nf->errs) sprintf (buff, "Analyzing %s (%d of %d) %d file%s not ANSI C", nf->n->use[i],i+1,n,nf->errs,nf->errs == 1?"":"s"); else sprintf (buff,"Analyzing %s (%d of %d) ", nf->n->use[i],i+1,n); XtVaSetValues (nf->s, XtNlabel, buff, NULL); return; } XtVaSetValues (nf->s, XtNlabel, "Scanning for main programs . . .", NULL); XFlush(XtDisplay(nf->s)); XtAppAddTimeOut (nf->ac,WAIT,do_final_analysis,nf); return;}run_a (w,nf,c) Widget w; nf_ptr nf; XtPointer c;{ char buff[2000],file[1000]; int i,k,cpp_status,parse_status,status,c_status,t_status; int n; struct stat cpp_stat,parse_stat,c_stat,t_stat; if (nf->running){ nf->running = 0; XtVaSetValues (w, XtNlabel, (XtArgVal) "Analyze Selected Files", XtNsensitive,False, NULL); return; } n = 0; while(nf->n->use[n])n++; i = 0; nf->at = 0; nf->of = n; nf->errs = 0; if (n > 0){ XtVaSetValues (w, XtNlabel, (XtArgVal) "Stop Analysis", NULL); sprintf (buff,"Analyzing %s (%d of %d)",nf->n->use[i],i+1,n); XtVaGetValues (nf->s, XtNforeground,&(nf->save_fg), XtNbackground,&(nf->save_bg), NULL); XtVaSetValues (nf->s, XtNlabel, buff, XtNforeground,nf->run_fg, XtNbackground,nf->run_bg, NULL); nf->running = 1; nf->r = w; sprintf (buff,"echo CPP Flags: %s >> HISTORY-A",nf->flags); system(buff); sprintf (buff,"echo parser Flags: %s >> HISTORY-A",nf->pflags); system(buff); XtAppAddTimeOut (nf->ac,WAIT,do_analysis,nf); }}push_help(w,u_data,w_data) Widget w; XtPointer u_data; XtPointer w_data;{ char buff[2000]; sprintf (buff, "%s/helpu -geom +20+20 %s %s/analyzer.help &",HOME, "-title \"Analyzer Help\" ",HOME); system (buff);}done(w,u_data,w_data) Widget w; XtPointer u_data; XtPointer w_data;{ notify_unravel (w); system ("cat HISTORY-A >> HISTORY"); exit (0);}move_list (ix,from,to) char *from[],*to[]; int ix;{ char *moving; int k; moving = from[ix]; k = ix; while (from[k]){ from[k] = from[k+1]; k++; } k = 0; while (to[k]) k++; to[k] = moving; to[k+1] = NULL;}/*plist (w,nf,list) Widget w; nf_ptr nf; XawListReturnStruct *list;{ strcpy (nf->current,list->string);}*/alist (w,names,list) Widget w; name_ptr names; XawListReturnStruct *list;{ int k; XawListUnhighlight(w); move_list (list->list_index,names->use,names->skip); XawListChange(names->keep,names->use,0,0,True); XawListChange(names->ignore,names->skip,0,0,True);}/*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;}*/line_cat (line,file) char *line,*file;{ int line_len,file_len; char buff[2000]; line_len = strlen(line); file_len = strlen(file); if (line_len + file_len > 60){ sprintf (buff,"echo %s >>HISTORY-A",line); system (buff); strcpy (line,file); strcat (line," "); } else { strcat (line,file); strcat (line," "); }}clear_files (w,names,w_data) Widget w; name_ptr names; XtPointer w_data;{ char buff[2000],file[2000],line[1000]; int len,i,status,line_len; system ("echo clearing files >>HISTORY-A"); status = unlink("SYSTEM"); line_len = 0; if (!status) strcpy (line,"SYSTEM "); else line[0] = '\0'; for (i = 0; names->use[i] ; i++){ strcpy (file,names->use[i]); len = strlen(file); if (len > 2){ file[len-1] = 'K'; status = unlink (file); if (!status) line_cat(line,file); file[len-1] = 'Y'; status = unlink (file); if (!status) line_cat(line,file); file[len-1] = 'T'; status = unlink (file); if (!status) line_cat(line,file); file[len-1] = 'H'; status = unlink (file); if (!status) line_cat(line,file); file[len-1] = '\0'; strcat (file,"LIF"); status = unlink (file); if (!status) line_cat(line,file); file[len-1] = '\0'; strcat (file,"LINK"); status = unlink (file); if (!status) line_cat(line,file); } } sprintf (buff,"echo %s >>HISTORY-A",line); system(buff); sprintf (buff,"%s ; %s ;%s/map >> HISTORY-A 2>&1", "echo \" \" >>HISTORY-A","echo running map >> HISTORY-A", HOME); system(buff); notify_unravel (w);}analyze_skipped (w,names,list) Widget w; name_ptr names; XtPointer list;{ struct stat status_c,status_lif,status_t; int c,lif,t; int i,len; int n_skip = 0,n_use = 0; char file[2000],*src; for (i = 0; names->files[i] ; i++){ src = names->files[i]->d_name; strcpy (file,src); len = strlen(src); file[len-1] = 'T'; t = stat (file,&status_t); file[len-1] = '\0'; strcat (file,"LIF"); lif = stat (file,&status_lif); c = stat (src,&status_c); if (c == 0) if ((lif == 0) && (t == 0)){ if ((status_c.st_mtime > status_t.st_mtime) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -