static void make_vinf(void) { if(flag_12) writeF("static "); writeF("char * varName_ext[%d]={\"P(cms)\"",nvars+nfunc+1); scanvars(3); writeF("};\n"); }
int main(int argc, char *argv[]) { struct kinfo_proc *kp, **kinfo; struct varent *vent; struct winsize ws; struct passwd *pwd; dev_t ttydev; pid_t pid; uid_t uid; int all, ch, flag, i, fmt, lineno, nentries; int prtheader, showthreads, wflag, kflag, what, Uflag, xflg; char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX]; if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0) termwidth = 79; else termwidth = ws.ws_col - 1; if (argc > 1) argv[1] = kludge_oldps_options(argv[1]); all = fmt = prtheader = showthreads = wflag = kflag = Uflag = xflg = 0; pid = -1; uid = 0; ttydev = NODEV; memf = nlistf = swapf = NULL; while ((ch = getopt(argc, argv, "acCegHhjkLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) switch (ch) { case 'a': all = 1; break; case 'c': commandonly = 1; break; case 'e': /* XXX set ufmt */ needenv = 1; break; case 'C': rawcpu = 1; break; case 'g': break; /* no-op */ case 'H': showthreads = 1; break; case 'h': prtheader = ws.ws_row > 5 ? ws.ws_row : 22; break; case 'j': parsefmt(jfmt); fmt = 1; jfmt[0] = '\0'; break; case 'k': kflag++; break; case 'L': showkey(); exit(0); case 'l': parsefmt(lfmt); fmt = 1; lfmt[0] = '\0'; break; case 'M': memf = optarg; break; case 'm': sortby = SORTMEM; break; case 'N': nlistf = optarg; break; case 'O': parsefmt(o1); parsefmt(optarg); parsefmt(o2); o1[0] = o2[0] = '\0'; fmt = 1; break; case 'o': parsefmt(optarg); fmt = 1; break; case 'p': pid = atol(optarg); xflg = 1; break; case 'r': sortby = SORTCPU; break; case 'S': sumrusage = 1; break; case 'T': if ((optarg = ttyname(STDIN_FILENO)) == NULL) errx(1, "stdin: not a terminal"); /* FALLTHROUGH */ case 't': { struct stat sb; char *ttypath, pathbuf[MAXPATHLEN]; if (strcmp(optarg, "co") == 0) ttypath = _PATH_CONSOLE; else if (*optarg != '/') (void)snprintf(ttypath = pathbuf, sizeof(pathbuf), "%s%s", _PATH_TTY, optarg); else ttypath = optarg; if (stat(ttypath, &sb) == -1) err(1, "%s", ttypath); if (!S_ISCHR(sb.st_mode)) errx(1, "%s: not a terminal", ttypath); ttydev = sb.st_rdev; break; } case 'U': pwd = getpwnam(optarg); if (pwd == NULL) errx(1, "%s: no such user", optarg); uid = pwd->pw_uid; endpwent(); Uflag = xflg = 1; break; case 'u': parsefmt(ufmt); sortby = SORTCPU; fmt = 1; ufmt[0] = '\0'; break; case 'v': parsefmt(vfmt); sortby = SORTMEM; fmt = 1; vfmt[0] = '\0'; break; case 'W': swapf = optarg; break; case 'w': if (wflag) termwidth = UNLIMITED; else if (termwidth < 131) termwidth = 131; wflag++; break; case 'x': xflg = 1; break; default: usage(); } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { nlistf = *argv; if (*++argv) { memf = *argv; if (*++argv) swapf = *argv; } } #endif if (nlistf == NULL && memf == NULL && swapf == NULL) { kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); kvm_sysctl_only = 1; } else { kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf); } if (kd == NULL) errx(1, "%s", errbuf); if (!fmt) { if (showthreads) parsefmt(tfmt); else parsefmt(dfmt); } /* XXX - should be cleaner */ if (!all && ttydev == NODEV && pid == -1 && !Uflag) { uid = getuid(); Uflag = 1; } /* * scan requested variables, noting what structures are needed, * and adjusting header widths as appropriate. */ scanvars(); if (neednlist && !nlistread) (void) donlist(); /* * get proc list */ if (Uflag) { what = KERN_PROC_UID; flag = uid; } else if (ttydev != NODEV) { what = KERN_PROC_TTY; flag = ttydev; } else if (pid != -1) { what = KERN_PROC_PID; flag = pid; } else if (kflag) { what = KERN_PROC_KTHREAD; flag = 0; } else { what = KERN_PROC_ALL; flag = 0; } if (showthreads) what |= KERN_PROC_SHOW_THREADS; /* * select procs */ kp = kvm_getprocs(kd, what, flag, sizeof(*kp), &nentries); if (kp == NULL) errx(1, "%s", kvm_geterr(kd)); /* * print header */ printheader(); if (nentries == 0) exit(1); /* * sort proc list, we convert from an array of structs to an array * of pointers to make the sort cheaper. */ if ((kinfo = calloc(sizeof(*kinfo), nentries)) == NULL) err(1, "failed to allocate memory for proc pointers"); for (i = 0; i < nentries; i++) kinfo[i] = &kp[i]; qsort(kinfo, nentries, sizeof(*kinfo), pscomp); /* * for each proc, call each variable output function. */ for (i = lineno = 0; i < nentries; i++) { if (showthreads == 0 && (kinfo[i]->p_flag & P_THREAD) != 0) continue; if (xflg == 0 && ((int)kinfo[i]->p_tdev == NODEV || (kinfo[i]->p_flag & P_CONTROLT ) == 0)) continue; if (showthreads && kinfo[i]->p_tid == -1) continue; for (vent = vhead; vent; vent = vent->next) { (vent->var->oproc)(kinfo[i], vent); if (vent->next != NULL) (void)putchar(' '); } (void)putchar('\n'); if (prtheader && lineno++ == prtheader - 4) { (void)putchar('\n'); printheader(); lineno = 0; } } exit(eval); }
static int c_prog_int(int for12) { int breaker; int i; long dfirst; if(nin+nout<=4) sumDiag=1; else sumDiag=0; flag_12=for12; memerror=zeroHeep; mark_(&heapbeg); if(for12) initvararray(0,'c',2 ); else initvararray(0,'c',3); /* ======= Initialisation parth ======= */ firstVar=nmodelvar; if(!strcmp( modelvars[firstVar].varname,strongconst)) firstVar--; prepareprocinform(); calc_nvars_nfunc(); /* ======= End of Initialisation ====== */ if(!flag_12) { outFileOpen("%sresults%cservice.c",pathtouser,f_slash); labl(); writeF("#include<math.h>\n"); writeF("#include\"num_out.h\"\n"); writeF("#include\"num_in.h\"\n"); writeF("double BWrange_ext=2.7;\n"); writeF("int twidth_ext=0;\n"); writeF("int gtwidth_ext=0;\n"); writeF("int gswidth_ext=0;\n"); writeF(" double va_ext[%d] ={0",nvars+nfunc+1); scanvars(2); writeF("};\n"); } else writeF(" static double va_ext[%d];\n",nvars+nfunc+1); geninf("nin_ext",nin); geninf("nout_ext",nout); geninf("nprc_ext",subproc_sq); make_pinf(); geninf("nvar_ext",nvars); geninf("nfunc_ext",nfunc); make_vinf(); if(!flag_12) { make_den_info(); writeF("\nCalcHEP_interface interface_ext={ %d, %d, varName_ext,va_ext," "%d, %d, %d, &pinf_ext, &pinfAux_ext, polarized_ext, &calcFunc_ext, &BWrange_ext,&twidth_ext," ">width_ext,&gswidth_ext, &sqme_ext,&den_info_ext,&build_cb_ext, &cb_pow_ext," "&cb_nc_ext, &cb_chains_ext, &cb_coeff_ext, &destroy_cb_ext};\n", nvars, nfunc, nin,nout,subproc_sq); writeF("\nCalcHEP_interface * PtrInterface_ext=&interface_ext;\n"); outFileClose(); outFileOpen("%sresults%csqme.c",pathtouser,f_slash); labl(); writeF("#include<stdio.h>\n"); writeF("#include\"num_out.h\"\n"); writeF("#include\"num_in.h\"\n"); } writeF("static int calcall[%d];\n",subproc_sq+1); if(!flag_12) { writeF("static int particles[%d]={0",1+nin+nout); for(i=0;i<nin+nout;i++) writeF(",0"); writeF("};\n"); } if(flag_12) writeF("static DNN "); else writeF("extern DNN "); for(i=1;i<subproc_sq;i++) writeF("S%d_ext,",i); writeF("S%d_ext;\n",subproc_sq); writeF("static DNN * darr[%d]={",subproc_sq); for(i=1;i<subproc_sq;i++) writeF("&S%d_ext,",i); writeF("&S%d_ext};\n",subproc_sq); fseek(catalog,0,SEEK_END); ndiagrtot = ftell(catalog)/sizeof(catrec); writesubroutineinit(); if(!flag_12) { make_infbasis(); writeF("#include\"sqme.inc\"\n"); outFileClose(); } diagrcount = 0; inftmp = inf; init_stat(); for (nsub = 1,dfirst=1; nsub <= subproc_sq; nsub++) { int colors[MAXINOUT]; if (inftmp->tot != 0) /* this subprocess IN archive */ { for(i=0;i<nin+nout;i++) { int l; locateinbase(inftmp->p_name[i], &l); colors[i]=prtclbase[l-1].cdim; } for(i=0;i<nin; i++) if(colors[i]==3) colors[i]=-3; else if(colors[i]==-3) colors[i]=3; if(noCChain) for(i=0;i<nin+nout; i++) colors[i]=1; infCbases(nin+nout,colors,&nC,&cBasisPower,&cChains); if(cBasisPower) { cCoefN=malloc(cBasisPower*sizeof(long)); cCoefD=malloc(cBasisPower*sizeof(long)); } writesubprocess(nsub,dfirst,inftmp->tot, &breaker); dfirst+=inftmp->tot; if (breaker) goto exi; if(cBasisPower) { if(cChains){free(cChains); cChains=NULL;} free(cCoefN); free(cCoefD); } } else writesubprocess(nsub,dfirst,0, NULL); inftmp = inftmp->next; } exi: clearstatistic(); release_(&heapbeg); return !breaker; }