Exemple #1
0
/*************************************************************************
* This function creates the coarser graph
**************************************************************************/
void CreateCoarseGraphNoMask(CtrlType *ctrl, GraphType *graph, int cnvtxs, idxtype *match, idxtype *perm)
{
  int i, j, k, m, istart, iend, nvtxs, nedges, ncon, cnedges, v, u, dovsize;
  idxtype *xadj, *vwgt, *vsize, *adjncy, *adjwgt, *adjwgtsum, *auxadj;
  idxtype *cmap, *htable;
  idxtype *cxadj, *cvwgt, *cvsize, *cadjncy, *cadjwgt, *cadjwgtsum;
  float *nvwgt, *cnvwgt;
  GraphType *cgraph;

  dovsize = (ctrl->optype == OP_KVMETIS ? 1 : 0);

  IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr));

  nvtxs = graph->nvtxs;
  ncon = graph->ncon;
  xadj = graph->xadj;
  vwgt = graph->vwgt;
  vsize = graph->vsize;
  nvwgt = graph->nvwgt;
  adjncy = graph->adjncy;
  adjwgt = graph->adjwgt;
  adjwgtsum = graph->adjwgtsum;
  cmap = graph->cmap;


  /* Initialize the coarser graph */
  cgraph = SetUpCoarseGraph(graph, cnvtxs, dovsize);
  cxadj = cgraph->xadj;
  cvwgt = cgraph->vwgt;
  cvsize = cgraph->vsize;
  cnvwgt = cgraph->nvwgt;
  cadjwgtsum = cgraph->adjwgtsum;
  cadjncy = cgraph->adjncy;
  cadjwgt = cgraph->adjwgt;


  htable = idxset(cnvtxs, -1, idxwspacemalloc(ctrl, cnvtxs));

  iend = xadj[nvtxs];
  auxadj = ctrl->wspace.auxcore;
  memcpy(auxadj, adjncy, iend*sizeof(idxtype));
  for (i=0; i<iend; i++)
    auxadj[i] = cmap[auxadj[i]];

  cxadj[0] = cnvtxs = cnedges = 0;
  for (i=0; i<nvtxs; i++) {
    v = perm[i];
    if (cmap[v] != cnvtxs)
      continue;

    u = match[v];
    if (ncon == 1)
      cvwgt[cnvtxs] = vwgt[v];
    else
      scopy(ncon, nvwgt+v*ncon, cnvwgt+cnvtxs*ncon);

    if (dovsize)
      cvsize[cnvtxs] = vsize[v];

    cadjwgtsum[cnvtxs] = adjwgtsum[v];
    nedges = 0;

    istart = xadj[v];
    iend = xadj[v+1];
    for (j=istart; j<iend; j++) {
      k = auxadj[j];
      if ((m = htable[k]) == -1) {
        cadjncy[nedges] = k;
        cadjwgt[nedges] = adjwgt[j];
        htable[k] = nedges++;
      }
      else {
        cadjwgt[m] += adjwgt[j];
      }
    }

    if (v != u) {
      if (ncon == 1)
        cvwgt[cnvtxs] += vwgt[u];
      else
        saxpy(ncon, 1.0, nvwgt+u*ncon, 1, cnvwgt+cnvtxs*ncon, 1);

      if (dovsize)
        cvsize[cnvtxs] += vsize[u];

      cadjwgtsum[cnvtxs] += adjwgtsum[u];

      istart = xadj[u];
      iend = xadj[u+1];
      for (j=istart; j<iend; j++) {
        k = auxadj[j];
        if ((m = htable[k]) == -1) {
          cadjncy[nedges] = k;
          cadjwgt[nedges] = adjwgt[j];
          htable[k] = nedges++;
        }
        else {
          cadjwgt[m] += adjwgt[j];
        }
      }

      /* Remove the contracted adjacency weight */
      if ((j = htable[cnvtxs]) != -1) {
        ASSERT(cadjncy[j] == cnvtxs);
        cadjwgtsum[cnvtxs] -= cadjwgt[j];
        cadjncy[j] = cadjncy[--nedges];
        cadjwgt[j] = cadjwgt[nedges];
        htable[cnvtxs] = -1;
      }
    }

    ASSERTP(cadjwgtsum[cnvtxs] == idxsum(nedges, cadjwgt), ("%d %d\n", cadjwgtsum[cnvtxs], idxsum(nedges, cadjwgt)));

    for (j=0; j<nedges; j++)
      htable[cadjncy[j]] = -1;  /* Zero out the htable */

    cnedges += nedges;
    cxadj[++cnvtxs] = cnedges;
    cadjncy += nedges;
    cadjwgt += nedges;
  }

  cgraph->nedges = cnedges;

  ReAdjustMemory(graph, cgraph, dovsize);

  IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr));

  idxwspacefree(ctrl, cnvtxs);
}
Exemple #2
0
local void setparams()
{
    input = getparam("in");
    ncol = nemoinpi(getparam("xcol"),col,MAXCOL);
    if (ncol < 0) error("parsing error col=%s",getparam("col"));
    if (hasvalue("out")) outstr=stropen(getparam("out"),"w");
    else outstr = NULL;

    nsteps = nemoinpd(getparam("bins"),bins,MAXHIST+1) - 1;
    if (nsteps == 0) {
      Qbin = FALSE;
      Qmin = hasvalue("xmin");
      Qmax = hasvalue("xmax");
      nsteps=getiparam("bins");
      if (nsteps > MAXHIST) 
        error("bins=%d too large; MAXHIST=%d",nsteps,MAXHIST);
      if (Qmin) xrange[0] = getdparam("xmin");
      if (Qmax) xrange[1] = getdparam("xmax");
      if (Qmin && Qmax && xrange[0] >= xrange[1]) error("Need xmin < xmax");
    } else if (nsteps > 0) {
      Qbin = TRUE;
      Qmin = TRUE;
      Qmax = TRUE;
      xrange[0] = hasvalue("xmin") ?  getdparam("xmin") : bins[0];
      xrange[1] = hasvalue("xmax") ?  getdparam("xmax") : bins[nsteps];
      warning("new mode: manual bins=%s",getparam("bins"));
    } else
      error("no proper usage for bins=%s",getparam("bins"));
    Qauto = (!Qmin || !Qmax) ;
    Qmad = getbparam("mad");

    maxcount=getiparam("maxcount");
    headline = getparam("headline");
    ylog=getbparam("ylog");
    xlab=getparam("xlab");
    ylab=getparam("ylab");
    Qgauss = getbparam("gauss");
    Qresid = getbparam("residual");
    Qtab = getbparam("tab");
    Qcumul = getbparam("cumul");
    if (Qcumul) {
        Qgauss=Qresid=FALSE;
        ylog=FALSE;
    }
    Qmedian = getbparam("median");
    Qtorben = getbparam("torben");
    if (Qtorben) Qmedian=FALSE;
    Qrobust = getbparam("robust");
    if (ylog && streq(ylab,"N")) ylab = scopy("log(N)");
    Qdual = getbparam("dual");

    nmax = nemo_file_lines(input,getiparam("nmax"));
    if (nmax<1) error("Problem reading from %s",input);

    nxcoord = nemoinpr(getparam("xcoord"),xcoord,MAXCOORD);

    nsigma = getdparam("nsigma");
    mysort = getsort(getparam("sort"));
    scale = getrparam("scale");
    if (scale != 1.0) {
      int n1=strlen(xlab);
      string s2 = getparam("scale");
      int n2=strlen(s2);
      xlab2 = (string) allocate(n1+n2+20);
      sprintf(xlab2,"%s [scale *%s]",xlab,s2);
      xlab = xlab2;
    }
    instr = stropen (input,"r");
}
Exemple #3
0
node* execute(node* jobList, char* largs[], char* rargs[], char* input, char* in, char* out, int pipestatus, int back, int jc, int error){
	int pidl;
	int pidr = 0;
	int pg;
	int status;
	int count = 0;
	int new_outno;
	int new_inno;
	int fd[2];
	char* job;
	node* current;
	node* recentJob;

	//error checking block
	if (error < 0) {
		if (error == -1) {
			write(1, "Error: Invalid I/O Input\n", 26);
			return jobList;
		}

		if (error == -2) {
			write(1, "Error: Invalid Pipe Input\n", 27);
			return jobList;
		}

		if (error == -3) {
			write(1, "Error: Invalid Background Input\n", 33);
			return jobList;
		}

		if (error == -4) {
			write(1, "Error: Invalid fg or bg input\n", 31);
			return jobList;
		}
	}

	//fg
	if (jc == 1) {
		//find a stopped job
		recentJob = findStopped(jobList);
		if (recentJob == NULL) {
			recentJob = jobList; // get the top of the stack
		}

		//this means that there are 0 background jobs
		if (recentJob == NULL) {
			printf("Error: No background jobs\n");
		}

		//send cont signal, give tc to the group
		else {
			if (killpg(recentJob->pgid, SIGCONT) < 0) perror("kill");
			if (tcsetpgrp(STDIN_FILENO, recentJob->pgid) < 0) perror("tcsetpgrp fg");

			//get the pid and pg
			pidl = recentJob->pid;
			pg = recentJob->pgid;
			pipestatus = recentJob->pipe;
			job = malloc(slen(recentJob->command) + 1);
			scopy(recentJob->command, job);

			//if pipe, get the other pid too
			if(pipestatus) {
				jobList = delete(jobList, recentJob->pid);
				recentJob = getg(jobList, pg);
				pidr = recentJob->pid;
			}

			//delete the job off the bg list
			jobList = delete(jobList, recentJob->pid);

			//print job on the shell
			printf("%s\n", job);

			//wait for both processes to finish
			waitpid(pidl, &status, WUNTRACED);
			waitpid(pidr, &status, WUNTRACED);

			// if foreground was stopped, place this job onto the list, notify it was stopped
			if (WIFSTOPPED(status)) {
				printf("\nStopped: %s\n", job);
				jobList = push(jobList, job, pidl, getpgid(pidl), pipestatus, 1);
				if (pipestatus) jobList = push(jobList, job, pidr, getpgid(pidl), pipestatus, 1);
			}

			//free job (i wish)
			free(job);

			//take back control of tc
			if (tcsetpgrp(STDIN_FILENO, getpgid(0)) < 0) perror("tcsetpgrp parent");

			jobList = bgWait(jobList);
		}
		return jobList;
	}

	//bg
	if (jc == 2) {
		// find a stopped job
		recentJob = findStopped(jobList);

		//if there are no stopped jobs, move on
		if (recentJob == NULL) {
			printf("Error: No stopped background jobs\n");
		}

		//otherwise, give signal to that job to continue
		else {
			if (killpg(recentJob->pgid, SIGCONT) < 0) perror("kill");
			pg = recentJob->pgid;
			jobList = changeStopped(jobList, pg);
			printf("Running : %s\n", recentJob->command);
		}

		// poll for background processes
		jobList = bgWait(jobList);

		//return
		return jobList;
	}

	//set up pipe fd's
	if (pipestatus) {
		if (pipe(fd) < 0) perror("Error");
	}

	// fork - twice if there's a pipe
	if ((pidl = fork()) < 0) {
		perror("Error");
	}

	//left command child branch
	if(pidl == 0) {
		//set all signals to default
		signal(SIGTTOU, SIG_DFL);
		signal(SIGTTIN, SIG_DFL);
		signal(SIGTERM, SIG_DFL);
		signal(SIGTSTP, SIG_DFL);
		signal(SIGINT, SIG_DFL);

		// set pgid
		if (setpgid(getpid(), getpid()) < 0) perror("setpgid");

		// give tc if not background (both in child and parent for rc)
		if (!back) {
			if (tcsetpgrp(STDIN_FILENO, getpgid(0)) < 0) perror("tcsetpgrp child");
		}

		//close input + dup2 out to the pipe
		if (pipestatus) {
			if (close(fd[0]) < 0) perror("Error");
			if(dup2(fd[1], 1) < 0) perror("Error");
		}

		// set I/O redirections in child process - stdout
		if (out != NULL && (!pipestatus)) {
			new_outno = open(out, O_WRONLY | O_TRUNC | O_CREAT, 0644); //to do - error check
			if (dup2(new_outno, STDOUT_FILENO) < 0) {
				perror("Error");
				exit(1);
			}
		}

		//stdin
		if (in != NULL) {
			new_inno = open(in, O_RDONLY); //to do - error check
			if (dup2(new_inno, STDIN_FILENO) < 0) {
				perror("Error");
				exit(1);
			}
		}

		// exec
		if (execvp(largs[0], largs) < 0) {
			perror("Error");
			exit(1);
		}
	}

	//PARENT
	else {
		// SECOND PROCESS BRANCH
		if (pipestatus) {
			if((pidr = fork()) < 0) {
				perror("Error");
			}

			// second child branch
			else if(pidr == 0) {

				//set all signals to default
				signal(SIGTTOU, SIG_DFL);
				signal(SIGTTIN, SIG_DFL);
				signal(SIGTERM, SIG_DFL);
				signal(SIGTSTP, SIG_DFL);
				signal(SIGINT, SIG_DFL);

				// set group id if foreground
				if (setpgid(getpid(), pidl) < 0) perror("Error");

				// give tc if not background (both in child and parent for rc)
				if (!back) {
					if (tcsetpgrp(STDIN_FILENO, getpgid(0)) < 0) perror("tcsetpgrp child");
				}

				//close output + dup2 input from pipe
				if (close(fd[1]) < 0) perror("Error");
				if (dup2(fd[0], 0) < 0) perror("Error");

				// set I/O redirections in child process - stdout
				if (out != NULL) {
					new_outno = open(out, O_WRONLY | O_TRUNC | O_CREAT, 0644); //to do - error check
					if (dup2(new_outno, STDOUT_FILENO) < 0) {
						perror("Error");
						exit(1);
					}
				}

				// exec
				if (execvp(rargs[0], rargs) < 0) {
					perror("Error");
					exit(1);
				}
			}
		}

		//PARENT BRANCH:
		//close both pipes in the parent
		if (pipestatus) {
			if (close(fd[0]) < 0) perror("Error");
			if (close(fd[1]) < 0) perror("Error");
		} 

		//set groups
		if (setpgid(pidl, pidl) < 0) perror("setpgid"); 
		if (pipestatus) {
			if (setpgid(pidr, pidl) < 0) perror("setpgid");
		}

		//if background, put job into the list
		if (back) {
			jobList = push(jobList, input, pidl, getpgid(pidl), pipestatus, 0);
			// also put the right side on the list if pipe
			if (pipestatus) jobList = push(jobList, input, pidr, getpgid(pidr), pipestatus, 0);
		}

		//for foreground
		if (!back) {
			//set tcpgrp for child/children
			if (tcsetpgrp(STDIN_FILENO, pidl) < 0) perror("tcsetpgrp child");

			//wait for both child processes to finish if not bg
			waitpid(pidl, &status, WUNTRACED);
			waitpid(pidr, &status, WUNTRACED);

			// if foreground was stopped, place this job onto the list, notify it was stopped
			if (WIFSTOPPED(status)) {
				printf("\nStopped: %s\n", input);
				jobList = push(jobList, input, pidl, getpgid(pidl), pipestatus, 1);
				if (pipestatus) jobList = push(jobList, input, pidr, getpgid(pidl), pipestatus, 1);
			}

			//take back control of tc
			if (tcsetpgrp(STDIN_FILENO, getpgid(0)) < 0) perror("tcsetpgrp parent");
		}

		// wait for background
		jobList = bgWait(jobList);
		return jobList;
	}
	//should never get here but to fend off warnings
	return jobList;
}
Exemple #4
0
STATIC void
expmeta(char *enddir, char *name)
{
	char *p;
	char *q;
	char *start;
	char *endname;
	int metaflag;
	struct stat statb;
	DIR *dirp;
	struct dirent *dp;
	int atend;
	int matchdot;

	metaflag = 0;
	start = name;
	for (p = name ; ; p++) {
		if (*p == '*' || *p == '?')
			metaflag = 1;
		else if (*p == '[') {
			q = p + 1;
			if (*q == '!' || *q == '^')
				q++;
			for (;;) {
				while (*q == CTLQUOTEMARK)
					q++;
				if (*q == CTLESC)
					q++;
				if (*q == '/' || *q == '\0')
					break;
				if (*++q == ']') {
					metaflag = 1;
					break;
				}
			}
		} else if (*p == '!' && p[1] == '!'	&& (p == name || p[-1] == '/')) {
			metaflag = 1;
		} else if (*p == '\0')
			break;
		else if (*p == CTLQUOTEMARK)
			continue;
		else if (*p == CTLESC)
			p++;
		if (*p == '/') {
			if (metaflag)
				break;
			start = p + 1;
		}
	}
	if (metaflag == 0) {	/* we've reached the end of the file name */
		if (enddir != expdir)
			metaflag++;
		for (p = name ; ; p++) {
			if (*p == CTLQUOTEMARK)
				continue;
			if (*p == CTLESC)
				p++;
			*enddir++ = *p;
			if (*p == '\0')
				break;
		}
		if (metaflag == 0 || lstat(expdir, &statb) >= 0)
			addfname(expdir);
		return;
	}
	endname = p;
	if (start != name) {
		p = name;
		while (p < start) {
			while (*p == CTLQUOTEMARK)
				p++;
			if (*p == CTLESC)
				p++;
			*enddir++ = *p++;
		}
	}
	if (enddir == expdir) {
		p = ".";
	} else if (enddir == expdir + 1 && *expdir == '/') {
		p = "/";
	} else {
		p = expdir;
		enddir[-1] = '\0';
	}
	if ((dirp = opendir(p)) == NULL)
		return;
	if (enddir != expdir)
		enddir[-1] = '/';
	if (*endname == 0) {
		atend = 1;
	} else {
		atend = 0;
		*endname++ = '\0';
	}
	matchdot = 0;
	p = start;
	while (*p == CTLQUOTEMARK)
		p++;
	if (*p == CTLESC)
		p++;
	if (*p == '.')
		matchdot++;
	while (! int_pending() && (dp = readdir(dirp)) != NULL) {
		if (dp->d_name[0] == '.' && ! matchdot)
			continue;
		if (patmatch(start, dp->d_name, 0)) {
			if (atend) {
				scopy(dp->d_name, enddir);
				addfname(expdir);
			} else {
				for (p = enddir, q = dp->d_name;
				     (*p++ = *q++) != '\0';)
					continue;
				p[-1] = '/';
				expmeta(p, endname);
			}
		}
	}
	closedir(dirp);
	if (! atend)
		endname[-1] = '/';
}
Exemple #5
0
PUBLIC void maLogRequest(HttpConn *conn)
{
    HttpHost    *host;
    HttpRx      *rx;
    HttpTx      *tx;
    HttpRoute   *route;
    MprBuf      *buf;
    char        keyBuf[80], *timeText, *fmt, *cp, *qualifier, *value, c;
    int         len;

    rx = conn->rx;
    tx = conn->tx;
    route = rx->route;
    host = httpGetConnContext(conn);
    if (host == 0) {
        return;
    }
    fmt = route->logFormat;
    if (fmt == 0) {
        return;
    }
    if (rx->method == 0) {
        return;
    }
    len = BIT_MAX_URI + 256;
    buf = mprCreateBuf(len, len);

    while ((c = *fmt++) != '\0') {
        if (c != '%' || (c = *fmt++) == '%') {
            mprPutCharToBuf(buf, c);
            continue;
        }
        switch (c) {
        case 'a':                           /* Remote IP */
            mprPutStringToBuf(buf, conn->ip);
            break;

        case 'A':                           /* Local IP */
            mprPutStringToBuf(buf, conn->sock->listenSock->ip);
            break;

        case 'b':
            if (tx->bytesWritten == 0) {
                mprPutCharToBuf(buf, '-');
            } else {
                mprPutIntToBuf(buf, tx->bytesWritten);
            } 
            break;

        case 'B':                           /* Bytes written (minus headers) */
            mprPutIntToBuf(buf, (tx->bytesWritten - tx->headerSize));
            break;

        case 'h':                           /* Remote host */
            mprPutStringToBuf(buf, conn->ip);
            break;

        case 'n':                           /* Local host */
            mprPutStringToBuf(buf, rx->parsedUri->host);
            break;

        case 'O':                           /* Bytes written (including headers) */
            mprPutIntToBuf(buf, tx->bytesWritten);
            break;

        case 'r':                           /* First line of request */
            mprPutToBuf(buf, "%s %s %s", rx->method, rx->uri, conn->protocol);
            break;

        case 's':                           /* Response code */
            mprPutIntToBuf(buf, tx->status);
            break;

        case 't':                           /* Time */
            mprPutCharToBuf(buf, '[');
            timeText = mprFormatLocalTime(MPR_DEFAULT_DATE, mprGetTime());
            mprPutStringToBuf(buf, timeText);
            mprPutCharToBuf(buf, ']');
            break;

        case 'u':                           /* Remote username */
            mprPutStringToBuf(buf, conn->username ? conn->username : "******");
            break;

        case '{':                           /* Header line */
            qualifier = fmt;
            if ((cp = strchr(qualifier, '}')) != 0) {
                fmt = &cp[1];
                *cp = '\0';
                c = *fmt++;
                scopy(keyBuf, sizeof(keyBuf), "HTTP_");
                scopy(&keyBuf[5], sizeof(keyBuf) - 5, qualifier);
                switch (c) {
                case 'i':
                    value = (char*) mprLookupKey(rx->headers, supper(keyBuf));
                    mprPutStringToBuf(buf, value ? value : "-");
                    break;
                default:
                    mprPutStringToBuf(buf, qualifier);
                }
                *cp = '}';

            } else {
                mprPutCharToBuf(buf, c);
            }
            break;

        case '>':
            if (*fmt == 's') {
                fmt++;
                mprPutIntToBuf(buf, tx->status);
            }
            break;

        default:
            mprPutCharToBuf(buf, c);
            break;
        }
    }
    mprPutCharToBuf(buf, '\n');
    mprAddNullToBuf(buf);
    mprWriteFile(route->log, mprGetBufStart(buf), mprGetBufLength(buf));
}
Exemple #6
0
void
copy(int prompt, FILE *fin)
{
	FILE *fout, *f;
	char s[200], t[200], s1[200], *r, *tod;
	char nm[100];
	int *p;
	time_t tval;
	int nmatch = 0;

	if (subdir[0] == 0)
		snprintf(subdir, sizeof subdir, "%s/%s", _PATH_LLIB, sname);
	for (;;) {
		if (pgets(s, sizeof s, prompt, fin) == 0) {
			if (fin == stdin) {
				/* fprintf(stderr, "Don't type control-D\n"); */
				/* this didn't work out very well */
				wrapup(1);	/* ian */
				continue;
			} else
				break;
		}
		trim(s);
		/* change the sequence %s to lesson directory */
		/* if needed */
		for (r = s; *r; r++)
			if (*r == '%') {
				snprintf(s1, sizeof s1, s,
				    subdir, subdir, subdir);
				strlcpy(s, s1, sizeof s);
				break;
			}
		r = wordb(s, t);
		p = action(t);
		/* some actions done only once per script */
		if (p && *p == ONCE) {
			if (wrong) {	/* we are on 2nd time */
				scopy(fin, NULL);
				continue;
			}
			strlcpy(s, r, sizeof s);
			r = wordb(s, t);
			p = action(t);
		}
		if (p == 0) {
			if (comfile >= 0) {
				write(comfile, s, strlen(s));
				write(comfile, "\n", 1);
			}
			else {
				signal(SIGINT, SIG_IGN);
				status = mysys(s);
				signal(SIGINT, signal_intrpt);
			}
			if (incopy) {
				fprintf(incopy, "%s\n", s);
				strlcpy(last, s, sizeof last);
			}
			continue;
		}
		switch (*p) {
		case READY:
			if (incopy && r) {
				fprintf(incopy, "%s\n", r);
				strlcpy(last, r, sizeof last);
			}
			return;
		case PRINT:
			if (wrong)
				scopy(fin, NULL);	/* don't repeat msg */
			else if (r)
				list(r);
			else
				scopy(fin, stdout);
			break;
		case NOP:
			break;
		case MATCH:
			if (nmatch > 0)	/* we have already passed */
				scopy(fin, NULL);
			/* did we pass this time? */
			else if ((status = strcmp(r, last)) == 0) {
				nmatch++;
				scopy(fin, stdout);
			} else
				scopy(fin, NULL);
			break;
		case BAD:
			if (strcmp(r, last) == 0)
				scopy(fin, stdout);
			else
				scopy(fin, NULL);
			break;
		case SUCCEED:
			scopy(fin, (status == 0) ? stdout : NULL);
			break;
		case FAIL:
			scopy(fin, (status != 0) ? stdout : NULL);
			break;
		case CREATE:
			fout = fopen(r, "w");
			scopy(fin, fout);
			fclose(fout);
			break;
		case CMP:
			status = cmp(r);	/* contains two file names */
			break;
		case MV:
			snprintf(nm, sizeof nm, "%s/L%s.%s", subdir, todo, r);
			fcopy(r, nm);
			break;
		case USER:
		case NEXT:
			more = 1;
			return;
		case COPYIN:
			incopy = fopen(".copy", "w");
			break;
		case UNCOPIN:
			fclose(incopy);
			incopy = NULL;
			break;
		case COPYOUT:
			maktee();
			break;
		case UNCOPOUT:
			untee();
			break;
		case PIPE:
			comfile = makpipe();
			break;
		case UNPIPE:
			close(comfile);
			wait(0);
			comfile = -1;
			break;
		case YES:
		case NO:
			if (incopy) {
				fprintf(incopy, "%s\n", s);
				strlcpy(last, s, sizeof last);
			}
			return;
		case WHERE:
			printf("You are in lesson %s\n", todo);
			fflush(stdout);
			break;
		case BYE:
			more = 0;
			return;
		case CHDIR:
			printf("cd not allowed\n");
			fflush(stdout);
			break;
		case LEARN:
			printf("You are already in learn.\n");
			fflush(stdout);
			break;
		case LOG:
			if (!logging)
				break;
			if (logfile[0] == 0) {
				snprintf(logfile, sizeof logfile,
				    "%s/log/%s", direct, sname);
			}
			f = fopen((r ? r : logfile), "a");
			if (f == NULL)
				break;
			time(&tval);
			tod = ctime(&tval);
			tod[24] = 0;
			fprintf(f, "%s L%-6s %s %2d %s\n", tod,
			    todo, status? "fail" : "pass", speed, pwline);
			fclose(f);
			break;
		}
	}
	return;
}
Exemple #7
0
void parse_dir_colors()
{
  char buf[1025], **arg, **c, *colors, *s, *cc;
  int i, n;
  struct extensions *e;
  
  if (Hflag) return;
  
  if (getenv("TERM") == NULL) {
    colorize = FALSE;
    return;
  }
  
  s = getenv("TREE_COLORS");
  if (s == NULL) s = getenv("LS_COLORS");
  cc = getenv("CLICOLOR");
  if (getenv("CLICOLOR_FORCE") != NULL) force_color=TRUE;
  if ((s == NULL || strlen(s) == 0) && (force_color || cc != NULL)) s = ":no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.bat=01;32:*.BAT=01;32:*.btm=01;32:*.BTM=01;32:*.cmd=01;32:*.CMD=01;32:*.com=01;32:*.COM=01;32:*.dll=01;32:*.DLL=01;32:*.exe=01;32:*.EXE=01;32:*.arj=01;31:*.bz2=01;31:*.deb=01;31:*.gz=01;31:*.lzh=01;31:*.rpm=01;31:*.tar=01;31:*.taz=01;31:*.tb2=01;31:*.tbz2=01;31:*.tbz=01;31:*.tgz=01;31:*.tz2=01;31:*.z=01;31:*.Z=01;31:*.zip=01;31:*.ZIP=01;31:*.zoo=01;31:*.asf=01;35:*.ASF=01;35:*.avi=01;35:*.AVI=01;35:*.bmp=01;35:*.BMP=01;35:*.flac=01;35:*.FLAC=01;35:*.gif=01;35:*.GIF=01;35:*.jpg=01;35:*.JPG=01;35:*.jpeg=01;35:*.JPEG=01;35:*.m2a=01;35:*.M2a=01;35:*.m2v=01;35:*.M2V=01;35:*.mov=01;35:*.MOV=01;35:*.mp3=01;35:*.MP3=01;35:*.mpeg=01;35:*.MPEG=01;35:*.mpg=01;35:*.MPG=01;35:*.ogg=01;35:*.OGG=01;35:*.ppm=01;35:*.rm=01;35:*.RM=01;35:*.tga=01;35:*.TGA=01;35:*.tif=01;35:*.TIF=01;35:*.wav=01;35:*.WAV=01;35:*.wmv=01;35:*.WMV=01;35:*.xbm=01;35:*.xpm=01;35:";
  
  if (s == NULL || (!force_color && (nocolor || !isatty(1)))) {
    colorize = FALSE;
    return;
  } else {
    colorize = TRUE;
    /* You can uncomment the below line and tree will always try to ANSI-fy the indentation lines */
    /*    ansilines = TRUE; */
  }
  
  colors = scopy(s);
  
  arg = split(colors,":",&n);
  
  for(i=0;arg[i];i++) {
    c = split(arg[i],"=",&n);
    switch(cmd(c[0])) {
      case COL_NORMAL:
	if (c[1]) norm_flgs = scopy(c[1]);
	break;
      case COL_FILE:
	if (c[1]) file_flgs = scopy(c[1]);
	break;
      case COL_DIR:
	if (c[1]) dir_flgs = scopy(c[1]);
	break;
      case COL_LINK:
	if (c[1]) {
	  if (strcasecmp("target",c[1]) == 0) {
	    linktargetcolor = TRUE;
	    link_flgs = "01;36"; /* Should never actually be used */
	  } else link_flgs = scopy(c[1]);
	}
	break;
      case COL_FIFO:
	if (c[1]) fifo_flgs = scopy(c[1]);
	break;
      case COL_DOOR:
	if (c[1]) door_flgs = scopy(c[1]);
	break;
      case COL_BLK:
	if (c[1]) block_flgs = scopy(c[1]);
	break;
      case COL_CHR:
	if (c[1]) char_flgs = scopy(c[1]);
	break;
      case COL_ORPHAN:
	if (c[1]) orphan_flgs = scopy(c[1]);
	break;
      case COL_SOCK:
	if (c[1]) sock_flgs = scopy(c[1]);
	break;
      case COL_SETUID:
	if (c[1]) suid_flgs = scopy(c[1]);
	break;
      case COL_SETGID:
	if (c[1]) sgid_flgs = scopy(c[1]);
	break;
      case COL_STICKY_OTHER_WRITABLE:
	if (c[1]) stickyow_flgs = scopy(c[1]);
	break;
      case COL_OTHER_WRITABLE:
	if (c[1]) otherwr_flgs = scopy(c[1]);
	break;
      case COL_STICKY:
	if (c[1]) sticky_flgs = scopy(c[1]);
	break;
      case COL_EXEC:
	if (c[1]) exec_flgs = scopy(c[1]);
	break;
      case COL_MISSING:
	if (c[1]) missing_flgs = scopy(c[1]);
	break;
      case COL_LEFTCODE:
	if (c[1]) leftcode = scopy(c[1]);
	break;
      case COL_RIGHTCODE:
	if (c[1]) rightcode = scopy(c[1]);
	break;
      case COL_ENDCODE:
	if (c[1]) endcode = scopy(c[1]);
	break;
      case DOT_EXTENSION:
	if (c[1]) {
	  e = xmalloc(sizeof(struct extensions));
	  e->ext = scopy(c[0]+1);
	  e->term_flg = scopy(c[1]);
	  e->nxt = ext;
	  ext = e;
	}
    }
    free(c);
  }
  free(arg);
  
  /* make sure at least norm_flgs is defined.  We're going to assume vt100 support */
  if (!leftcode) leftcode = scopy("\033[");
  if (!rightcode) rightcode = scopy("m");
  if (!norm_flgs) norm_flgs = scopy("00");
  
  if (!endcode) {
    sprintf(buf,"%s%s%s",leftcode,norm_flgs,rightcode);
    endcode = scopy(buf);
  }
  
  free(colors);
  
  /*  if (!termmatch) colorize = FALSE; */
}
Exemple #8
0
/*************************************************************************
* This function creates the coarser graph
**************************************************************************/
void CreateCoarseGraph(CtrlType *ctrl, GraphType *graph, int cnvtxs, idxtype *match, idxtype *perm)
{
  int i, j, jj, k, kk, l, m, istart, iend, nvtxs, nedges, ncon, cnedges, v, u, mask, dovsize;
  idxtype *xadj, *vwgt, *vsize, *adjncy, *adjwgt, *adjwgtsum, *auxadj;
  idxtype *cmap, *htable;
  idxtype *cxadj, *cvwgt, *cvsize, *cadjncy, *cadjwgt, *cadjwgtsum;
  float *nvwgt, *cnvwgt;
  GraphType *cgraph;

  dovsize = (ctrl->optype == OP_KVMETIS ? 1 : 0);

  mask = HTLENGTH;
  if (cnvtxs < 8*mask || graph->nedges/graph->nvtxs > 15) {
    CreateCoarseGraphNoMask(ctrl, graph, cnvtxs, match, perm);
    return;
  }

  IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr));

  nvtxs = graph->nvtxs;
  ncon = graph->ncon;
  xadj = graph->xadj;
  vwgt = graph->vwgt;
  vsize = graph->vsize;
  nvwgt = graph->nvwgt;
  adjncy = graph->adjncy;
  adjwgt = graph->adjwgt;
  adjwgtsum = graph->adjwgtsum;
  cmap = graph->cmap;

  /* Initialize the coarser graph */
  cgraph = SetUpCoarseGraph(graph, cnvtxs, dovsize);
  cxadj = cgraph->xadj;
  cvwgt = cgraph->vwgt;
  cvsize = cgraph->vsize;
  cnvwgt = cgraph->nvwgt;
  cadjwgtsum = cgraph->adjwgtsum;
  cadjncy = cgraph->adjncy;
  cadjwgt = cgraph->adjwgt;


  iend = xadj[nvtxs];
  auxadj = ctrl->wspace.auxcore;
  memcpy(auxadj, adjncy, iend*sizeof(idxtype));
  for (i=0; i<iend; i++)
    auxadj[i] = cmap[auxadj[i]];

  htable = idxset(mask+1, -1, idxwspacemalloc(ctrl, mask+1));

  cxadj[0] = cnvtxs = cnedges = 0;
  for (i=0; i<nvtxs; i++) {
    v = perm[i];
    if (cmap[v] != cnvtxs)
      continue;

    u = match[v];
    if (ncon == 1)
      cvwgt[cnvtxs] = vwgt[v];
    else
      scopy(ncon, nvwgt+v*ncon, cnvwgt+cnvtxs*ncon);

    if (dovsize)
      cvsize[cnvtxs] = vsize[v];

    cadjwgtsum[cnvtxs] = adjwgtsum[v];
    nedges = 0;

    istart = xadj[v];
    iend = xadj[v+1];
    for (j=istart; j<iend; j++) {
      k = auxadj[j];
      kk = k&mask;
      if ((m = htable[kk]) == -1) {
        cadjncy[nedges] = k;
        cadjwgt[nedges] = adjwgt[j];
        htable[kk] = nedges++;
      }
      else if (cadjncy[m] == k) {
        cadjwgt[m] += adjwgt[j];
      }
      else {
        for (jj=0; jj<nedges; jj++) {
          if (cadjncy[jj] == k) {
            cadjwgt[jj] += adjwgt[j];
            break;
          }
        }
        if (jj == nedges) {
          cadjncy[nedges] = k;
          cadjwgt[nedges++] = adjwgt[j];
        }
      }
    }

    if (v != u) {
      if (ncon == 1)
        cvwgt[cnvtxs] += vwgt[u];
      else
        saxpy(ncon, 1.0, nvwgt+u*ncon, 1, cnvwgt+cnvtxs*ncon, 1);

      if (dovsize)
        cvsize[cnvtxs] += vsize[u];

      cadjwgtsum[cnvtxs] += adjwgtsum[u];

      istart = xadj[u];
      iend = xadj[u+1];
      for (j=istart; j<iend; j++) {
        k = auxadj[j];
        kk = k&mask;
        if ((m = htable[kk]) == -1) {
          cadjncy[nedges] = k;
          cadjwgt[nedges] = adjwgt[j];
          htable[kk] = nedges++;
        }
        else if (cadjncy[m] == k) {
          cadjwgt[m] += adjwgt[j];
        }
        else {
          for (jj=0; jj<nedges; jj++) {
            if (cadjncy[jj] == k) {
              cadjwgt[jj] += adjwgt[j];
              break;
            }
          }
          if (jj == nedges) {
            cadjncy[nedges] = k;
            cadjwgt[nedges++] = adjwgt[j];
          }
        }
      }

      /* Remove the contracted adjacency weight */
      jj = htable[cnvtxs&mask];
      if (jj >= 0 && cadjncy[jj] != cnvtxs) {
        for (jj=0; jj<nedges; jj++) {
          if (cadjncy[jj] == cnvtxs)
            break;
        }
      }
      if (jj >= 0 && cadjncy[jj] == cnvtxs) { /* This 2nd check is needed for non-adjacent matchings */
        cadjwgtsum[cnvtxs] -= cadjwgt[jj];
        cadjncy[jj] = cadjncy[--nedges];
        cadjwgt[jj] = cadjwgt[nedges];
      }
    }

    ASSERTP(cadjwgtsum[cnvtxs] == idxsum(nedges, cadjwgt), ("%d %d %d %d %d\n", cnvtxs, cadjwgtsum[cnvtxs], idxsum(nedges, cadjwgt), adjwgtsum[u], adjwgtsum[v]));

    for (j=0; j<nedges; j++)
      htable[cadjncy[j]&mask] = -1;  /* Zero out the htable */
    htable[cnvtxs&mask] = -1;

    cnedges += nedges;
    cxadj[++cnvtxs] = cnedges;
    cadjncy += nedges;
    cadjwgt += nedges;
  }

  cgraph->nedges = cnedges;

  ReAdjustMemory(graph, cgraph, dovsize);

  IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr));

  idxwspacefree(ctrl, mask+1);

}
Exemple #9
0
local void setparams()
{
    input = getparam("in");

    nsteps = nemoinpd(getparam("bins"),bins,MAXHIST+1) - 1;
    if (nsteps == 0) {
      Qbin = FALSE;
      Qmin = hasvalue("xmin");
      Qmax = hasvalue("xmax");
      nsteps=getiparam("bins");
      if (nsteps > MAXHIST) 
        error("bins=%d too large; MAXHIST=%d",nsteps,MAXHIST);
      if (Qmin) xrange[0] = getdparam("xmin");
      if (Qmax) xrange[1] = getdparam("xmax");
      if (Qmin && Qmax && xrange[0] >= xrange[1]) error("Need xmin < xmax");
    } else if (nsteps > 0) {
      Qbin = TRUE;
      Qmin = TRUE;
      Qmax = TRUE;
      xrange[0] = hasvalue("xmin") ?  getdparam("xmin") : bins[0];
      xrange[1] = hasvalue("xmax") ?  getdparam("xmax") : bins[nsteps];
      warning("new mode: manual bins=%s",getparam("bins"));
    } else
      error("no proper usage for bins=%s",getparam("bins"));
    Qauto = (!Qmin || !Qmax) ;

    maxcount=getiparam("maxcount");
    headline = getparam("headline");
    ylog=getbparam("ylog");
    xlab=getparam("xlab");
    ylab=getparam("ylab");
    Qgauss = getbparam("gauss");
    Qresid = getbparam("residual");
    Qtab = getbparam("tab");
    Qcumul = getbparam("cumul");
    if (Qcumul) {
        Qgauss=Qresid=FALSE;
        ylog=FALSE;
    }
    Qint = getbparam("integrate");
    if (Qint && !Qcumul) error("Integrate option in non-cumulative mode makes no sense");
    Qmedian = getbparam("median");
    if (ylog && streq(ylab,"N")) ylab = scopy("log(N)");
    Qdual = getbparam("dual");

    nxcoord = nemoinpr(getparam("xcoord"),xcoord,MAXCOORD);

    nsigma = getdparam("nsigma");
    mysort = getsort(getparam("sort"));
    scale = getrparam("scale");
    Qblank = hasvalue("blankval");
    if (Qblank) blankval = getrparam("blankval");
    if (scale != 1.0) {
      int n1=strlen(xlab);
      string s2 = getparam("scale");
      int n2=strlen(s2);
      xlab2 = (string) allocate(n1+n2+20);
      sprintf(xlab2,"%s [scale *%s]",xlab,s2);
      xlab = xlab2;
    }
    input = getparam("in");
}
Exemple #10
0
static void
showjob(struct output *out, struct job *jp, int mode)
{
	int procno;
	int st;
	struct procstat *ps;
	int col;
	char s[64];

#if JOBS
	if (mode & SHOW_PGID) {
		/* just output process (group) id of pipeline */
		outfmt(out, "%ld\n", (long)jp->ps->pid);
		return;
	}
#endif

	procno = jp->nprocs;
	if (!procno)
		return;

	if (mode & SHOW_PID)
		mode |= SHOW_MULTILINE;

	if ((procno > 1 && !(mode & SHOW_MULTILINE))
	    || (mode & SHOW_SIGNALLED)) {
		/* See if we have more than one status to report */
		ps = jp->ps;
		st = ps->status;
		do {
			int st1 = ps->status;
			if (st1 != st)
				/* yes - need multi-line output */
				mode |= SHOW_MULTILINE;
			if (st1 == -1 || !(mode & SHOW_SIGNALLED) || WIFEXITED(st1))
				continue;
			if (WIFSTOPPED(st1) || ((st1 = WTERMSIG(st1) & 0x7f)
			    && st1 != SIGINT && st1 != SIGPIPE))
				mode |= SHOW_ISSIG;

		} while (ps++, --procno);
		procno = jp->nprocs;
	}

	if (mode & SHOW_SIGNALLED && !(mode & SHOW_ISSIG)) {
		if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE)) {
			TRACE(("showjob: freeing job %d\n", jp - jobtab + 1));
			freejob(jp);
		}
		return;
	}

	for (ps = jp->ps; --procno >= 0; ps++) {	/* for each process */
		if (ps == jp->ps)
			fmtstr(s, 16, "[%ld] %c ",
				(long)(jp - jobtab + 1),
#if JOBS
				jp == jobtab + curjob ? '+' :
				curjob != -1 && jp == jobtab +
					    jobtab[curjob].prev_job ? '-' :
#endif
				' ');
		else
			fmtstr(s, 16, "      " );
		col = strlen(s);
		if (mode & SHOW_PID) {
			fmtstr(s + col, 16, "%ld ", (long)ps->pid);
			     col += strlen(s + col);
		}
		if (ps->status == -1) {
			scopy("Running", s + col);
		} else if (WIFEXITED(ps->status)) {
			st = WEXITSTATUS(ps->status);
			if (st)
				fmtstr(s + col, 16, "Done(%d)", st);
			else
				fmtstr(s + col, 16, "Done");
		} else {
#if JOBS
			if (WIFSTOPPED(ps->status)) 
				st = WSTOPSIG(ps->status);
			else /* WIFSIGNALED(ps->status) */
#endif
				st = WTERMSIG(ps->status);
			st &= 0x7f;
			if (st < NSIG && sys_siglist[st])
				scopyn(sys_siglist[st], s + col, 32);
			else
				fmtstr(s + col, 16, "Signal %d", st);
			if (WCOREDUMP(ps->status)) {
				col += strlen(s + col);
				scopyn(" (core dumped)", s + col,  64 - col);
			}
		}
		col += strlen(s + col);
		outstr(s, out);
		do {
			outc(' ', out);
			col++;
		} while (col < 30);
		outstr(ps->cmd, out);
		if (mode & SHOW_MULTILINE) {
			if (procno > 0) {
				outc(' ', out);
				outc('|', out);
			}
		} else {
			while (--procno >= 0)
				outfmt(out, " | %s", (++ps)->cmd );
		}
		outc('\n', out);
	}
	flushout(out);
	jp->changed = 0;
	if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE))
		freejob(jp);
}