예제 #1
0
void walkpages()                  /* process the pages in the DVI-file */
{
    register bool wantpage;

    pagecounter = 0L;
    while ((opcode = skipnops()) != POST) {
        if (opcode != BOP)              /* should be at start of page now    */
            errorexit(nobop);
        else {
            pagecounter++;
            pagenr = sget4();           /* get TeX page number               */
            mseek(DVIfile, 36L, relative); /* skip page header */
            backpointer = sget4();      /* get previous page offset          */
            if (pageswitchon)
                if (sequenceon)
                    wantpage = inlist(pagecounter);
                else
                    wantpage = inlist(pagenr);
            else
                wantpage = TRUE;

            if (wantpage) {
                initpage();
                dopage();
                printpage();
            }
            else {
                skippage();
            }
        }
    }

} /* walkpages */
예제 #2
0
파일: proc.c 프로젝트: dilawar/suckless
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
	DIR* dir;
	struct dirent *entry;
	char buf[p_max_size];
	int length, totallength = 0;
	struct ll_string* files_front = NULL;
	struct ll_string* files_back = NULL;

	dir = opendir(obj->data.s);
	if(dir != NULL) {
		while ((entry = readdir(dir))) {
			if(entry->d_name[0] != '.') {
				snprintf(buf, p_max_size, "%d/%s", strtopid(obj->data.s), entry->d_name);
				length = readlink(buf, buf, p_max_size);
				buf[length] = 0;
				if(inlist(files_front, buf) == 0) {
					files_back = addnode(files_back, buf);
					snprintf(p + totallength, p_max_size - totallength, "%s; " , buf);
					totallength += length + strlen("; ");
				}
				if(files_front == NULL) {
					files_front = files_back;
				}
			}
		}
		closedir(dir);
		freelist(files_front);
		p[totallength - strlen("; ")] = 0;
	} else {
		p[0] = 0;
	}
}
예제 #3
0
파일: advdbs.c 프로젝트: BPaden/garglk
/* hasadjective - check to see if an object has a specified adjective */
int hasadjective(int obj,int adjective)
{
    while (obj) {
	if (inlist(getofield(obj,O_ADJECTIVES),adjective))
	    return (TRUE);
	obj = getofield(obj,O_CLASS);
    }
    return (FALSE);
}
예제 #4
0
파일: advdbs.c 프로젝트: BPaden/garglk
/* hasnoun - check to see if an object has a specified noun */
int hasnoun(int obj,int noun)
{
    while (obj) {
	if (inlist(getofield(obj,O_NOUNS),noun))
	    return (TRUE);
	obj = getofield(obj,O_CLASS);
    }
    return (FALSE);
}
예제 #5
0
void
reorder(struct nlist *st1, struct nlist *st2, int entries)
{
	struct nlist *p;
	int i, n;

	for (p = st1, n = entries; --n >= 0; ++p)
		if (inlist(p) != -1)
			++symfound;
	for (p = st2 + symfound, n = entries; --n >= 0; ++st1) {
		if (excluded(st1))
			continue;
		i = inlist(st1);
		if (i == -1)
			*p++ = *st1;
		else
			st2[i] = *st1;
		++symkept;
	}
}
예제 #6
0
int
addbms(struct boardheader *rec)
{
	int i;
	for (i = 0; i < BMNUM; i++) {
		if (rec->bm[i][0] && !inlist(rec->bm[i])) {
			strcpy(bmlist[count], rec->bm[i]);
			count++;
		}
	}
	return 0;
}
예제 #7
0
파일: autosd.c 프로젝트: rlp1938/autosd
static cfgprm get_config_parameters(const char *relpath)
{
	char **cflines = readcfg(relpath);
	cfgprm prms;
	int cflidx = 0;
	while (cflidx < 3) {
		char *list[4] = {"check_interval", "monitor_level", "quit_level"
							,(char *)NULL };
		cfgdata cd = split_cfg_line(cflines[cflidx]);
		int res = inlist(cd.cfgname, list);
		check_set_config_values(res, &prms, cd);
		cflidx++;
	} // while()
	freelist(cflines);
	return prms;
} // get_config_parameters()
예제 #8
0
void playgame(Node * listhead){
    
    /* value of the user input after parsing*/
    int val;
    char userinput[12];
    /*printing the prompt for the beginning of the game*/
    
    printf("This game has you guess which integers are in the list.\n");
    printf("Enter an integer (followed by the newline)\n");
    printf("or q (followed by the newline) to quit.\n");
    printf("Integer guess: ");
    
    /* getting the user input*/
    if(fgets(userinput,sizeof(userinput), stdin)!=NULL){
        /* if the input doesn't start with the letter q, the program runs*/
        /* quits otherwise */
        
        while(userinput[0] != 'q'){
            /* string to integer*/
            val=atoi(userinput);
            
            /* calling the inlist function to check if the list contains*/
            /* the integer or not*/
            /* printing the required prompt and asking user to enter again*/
            if(inlist(listhead, val) == 1){
                printf("%d is on the list.\n", val);
                printf("Integer guess: ");
                fgets(userinput, sizeof userinput, stdin);
            }
            
            /* if the integer is not present in the list*/
            else{
                printf("%d is not on the list.\n", val);
                printf("Integer guess: ");
                fgets(userinput, sizeof userinput, stdin);
                
            }
            
        }
        
        /* if the user input starts with q, the program is exitted*/
        if(userinput[0]=='q'){
            exit(1);
        }
    }
}
예제 #9
0
void
compute_multab()
{
	int k, m;
	short blk[64];

	for (k = 1; k < 64; ++k) {
		memset((char*)blk, 0, sizeof(blk));
		blk[ROWZAG[k]] = FIX(1);
		v_rdct(blk);
		for (m = 0; m < 64; ++m) {
			if (inlist(multab, nmul, blk[m]))
				continue;
			multab[nmul++] = blk[m];
		}
	}
}
예제 #10
0
void playgame(Node * listhead){
  int str_to_int;
  char str[100];
  int n;

  printf("This game has you guess which integers are in the list.\n");
  printf("Enter an integer or q to quit.\n");
  while((n = strncmp(fgets(str, 100, stdin), "q", 1)) != 0){                                                   \

    str_to_int = atoi(str);
    if (inlist(listhead, str_to_int) == 1){
      printf("%d is in the list\n", str_to_int);
    }
    else {
      printf("%d is not in the list\n", str_to_int);
    }
  }

  printf("Quitting.\n");
}
예제 #11
0
static void
inform(char *cf, int rank)
{
	int fd, j;
	FILE *cfp = NULL;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	PRIV_START;
	fd = safe_open(cf, O_RDONLY|O_NOFOLLOW, 0);
	PRIV_END;
	if (fd < 0 || (cfp = fdopen(fd, "r")) == NULL) {
		if (fd >= 0)
			close(fd);
		return;
	}

	j = 0;
	while (getcfline(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, atoi(cf+3));
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				continue;
			if (j == 0 || strcmp(file, line+1) != 0)
				(void)strlcpy(file, line+1, sizeof(file));
			j++;
			continue;
		case 'N':
			show(line+1, file, j);
			file[0] = '\0';
			j = 0;
		}
	}
	fclose(cfp);
	if (!lflag) {
		blankfill(termwidth - (80 - SIZCOL));
		printf("%lld bytes\n", (long long)totsize);
		totsize = 0;
	}
}
예제 #12
0
파일: g2eye.c 프로젝트: palmerc/lab
void evalopenlineeye(int s,int c){
	int length, points = EOL; 
	     /* length is number of points.  Points are places with two
              * liberties and only friendly neighbors
              */
	int end1,end2;  /* ends are points after last point */
	int v1,v2;      /* v1,v2 will be the vital points */
	int rn,sn,ptr,corner=NOSQUARE;
	addlist(s,&points);
	length = 1;
	end1 = list[nblbp[s]];
	end2 = list[links[nblbp[s]]];
	v1 = end1;
	v2 = end2;
	while(lnbn[end1] <= 2 && lnbf[end1][1-c] == 0){
		if(lnbn[end1] == 1){
			killist(&points);
			return;  /* end not open */
			}
		addlist(end1,&points);
		++length;
		v1 = end1;
		if(edge[end1] == 0)corner = end1;
		if(end1 == end2)break;
		sn = list[nblbp[end1]];
		if(inlist(sn,&points))
			sn = list[links[nblbp[end1]]];
		end1 = sn;
		}
	if(end1 != end2)
  	    while(lnbn[end2] <= 2 && lnbf[end2][1-c] == 0){
		if(lnbn[end2] == 1){
			killist(&points);
			return;  /* end not open */
			}
		addlist(end2,&points);
		++length;
		v2 = end2;
		if(edge[end2] == 0)corner = end2;
		sn = list[nblbp[end2]];
		if(inlist(sn,&points))
			sn = list[links[nblbp[end2]]];
		end2 = sn;
		}

	rn = gtflist(&eyefreelist);
	eyeptr[rn] = points;
	for(ptr = points; ptr != EOL; ptr = links[ptr]){
		eyerec[list[ptr]] = rn;
		}



	if(length == 1 && end1+end2-s-s != 0 && lnbf[end1][c] != 0 &&
	   lnbf[end1][1-c] == 0 && lnbf[end2][c] != 0 && lnbf[end2][1-c] == 0){
		/* corner eye in middle of board */
		eyetype[rn] = OPENLINEEYE;
		eyeval[rn] = 0;
		eyepot[rn] = 8;
		eyemin[rn] = 0;
		sn = end1+end2-s;
		if(ld[sn] == 6)eyepot[rn] = 4;  /* so don't double count two
						   facing each other */
		addlist(sn,&eyevital[rn]);
		addlist(rn,&eyevitrec[sn]);
		return;
		}

	if(length == 2 && (abs(end1-end2) == 1 || abs(end1-end2) == boardsize) &&
	   lnbf[end1][1-c] == 0 && lnbf[end2][1-c] == 0 &&
	   (lnbf[end1][c] != 0 || lnbf[end2][c] != 0)){
		eyetype[rn] = OPENLINEEYE;
		eyeval[rn] = 0;
		eyepot[rn] = 8;
		eyemin[rn] = 0;
		addlist(end1,&eyevital[rn]);
		addlist(rn,&eyevitrec[end1]);
		addlist(end2,&eyevital[rn]);
		addlist(rn,&eyevitrec[end2]);
		return;
		}

	if(length == 3 && end1 == end2){
		eyetype[rn] = OPENLINEEYE;
		eyeval[rn] = 0;
		eyepot[rn] = 8;
		eyemin[rn] = 0;
		addlist(end1,&eyevital[rn]);
		addlist(rn,&eyevitrec[end1]);
		return;
		}

	if(end1 == end2 && length == 4){  /* block 4 eye */
		eyetype[rn] = FOURPTBLOCKEYE;
		eyepot[rn] = 8;
		eyeval[rn] = 8;
		eyemin[rn] = 8;
		return;
		}

	if(!inlist(end1,&points) && lnbf[end1][1-c] == 0){
		++length;
		v1 = end1;
		}
	if(!inlist(end2,&points) && lnbf[end2][1-c] == 0 ){
		++length;
		v2 = end2;
		}
			
	if(length > 8)length = 8;
	eyetype[rn] = OPENLINEEYE;
	eyeval[rn] = evlol[length];
	eyepot[rn] = evlol[length+1];
	eyemin[rn] = evlol[length-1];
	if(eyepot[rn] != eyeval[rn] || length >= 6){
		addlist(v1,&eyevital[rn]);
		addlist(v2,&eyevital[rn]);
		addlist(rn,&eyevitrec[v1]);
		addlist(rn,&eyevitrec[v2]);
		if(corner != NOSQUARE){
			addlist(corner,&eyevital[rn]);
			addlist(rn,&eyevitrec[corner]);
			}
		}
	}
예제 #13
0
void
inform(const struct printer *pp, char *cf)
{
	int copycnt, jnum;
	char	 savedname[MAXPATHLEN+1];
	FILE	*cfp;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	PRIV_START
	if ((cfp = fopen(cf, "r")) == NULL)
		return;
	PRIV_END

	if (rank < 0)
		rank = 0;
	if (pp->remote || garbage || strcmp(cf, current))
		rank++;

	/*
	 * The cf-file may include commands to print more than one datafile
	 * from the user.  For each datafile, the cf-file contains at least
	 * one line which starts with some format-specifier ('a'-'z'), and
	 * a second line ('N'ame) which indicates the original name the user
	 * specified for that file.  There can be multiple format-spec lines
	 * for a single Name-line, if the user requested multiple copies of
	 * that file.  Standard lpr puts the format-spec line(s) before the
	 * Name-line, while lprNG puts the Name-line before the format-spec
	 * line(s).  This section needs to handle the lines in either order.
	 */
	copycnt = 0;
	file[0] = '\0';
	savedname[0] = '\0';
	jnum = calc_jobnum(cf, NULL);
	while (getline(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, jnum);
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				break;
			if (copycnt == 0 || strcmp(file, line+1) != 0) {
				strlcpy(file, line + 1, sizeof(file));
			}
			copycnt++;
			/*
			 * deliberately 'continue' to another getline(), so
			 * all format-spec lines for this datafile are read
			 * in and counted before calling show()
			 */
			continue;
		case 'N':
			strlcpy(savedname, line + 1, sizeof(savedname));
			break;
		}
		if ((file[0] != '\0') && (savedname[0] != '\0')) {
			show(savedname, file, copycnt);
			copycnt = 0;
			file[0] = '\0';
			savedname[0] = '\0';
		}
	}
	fclose(cfp);
	/* check for a file which hasn't been shown yet */
	if (file[0] != '\0') {
		if (savedname[0] == '\0') {
			/* a safeguard in case the N-ame line is missing */
			strlcpy(savedname, file, sizeof(savedname));
		}
		show(savedname, file, copycnt);
	}
	if (!lflag) {
		blankfill(SIZCOL);
		printf("%ld bytes\n", totsize);
		totsize = 0;
	}
}
예제 #14
0
파일: displayq.c 프로젝트: ryo/netbsd-src
void
inform(const char *cf)
{
	int j;
	FILE *cfp;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	seteuid(euid);
	if ((cfp = fopen(cf, "r")) == NULL)
		return;
	seteuid(uid);

	if (rank < 0)
		rank = 0;
	if (remote || garbage || strcmp(cf, current))
		rank++;
	j = 0;
	while (get_line(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, atoi(cf+3));
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				continue;
			if (j == 0 || strcmp(fname, line+1) != 0) {
				(void)strlcpy(fname, line+1, sizeof(fname));
			}
			j++;
			continue;
		case 'N':
			show(line + 1, fname, j);
			fname[0] = '\0';
			j = 0;
		}
	}
	fclose(cfp);
	if (!lflag) {
		blankfill(SIZCOL);
		printf("%ld bytes\n", totsize);
		totsize = 0;
	}
}
예제 #15
0
int
main(int argc, char **argv)
{
	struct nlist *p, *symp;
	FILE *f, *xfile;
	int i;
	char *start, *t, *xfilename;
	int ch, n, o;

	xfilename = NULL;
	while ((ch = getopt(argc, argv, "cmtx:")) != -1)
		switch(ch) {
		case 'c':
			clean = 1;
			break;
		case 'm':
			missing = 1;
			break;
		case 't':
			small = 1;
			break;
		case 'x':
			if (xfilename != NULL)
				usage();
			xfilename = optarg;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 2)
		usage();

	if ((f = fopen(argv[0], "r")) == NULL)
		err(ERREXIT, "%s", argv[0]);

	for (p = order; fgets(asym, sizeof(asym), f) != NULL;) {
		for (t = asym; isspace(*t); ++t);
		if (!*(start = t))
			continue;
		while (*++t);
		if (*--t == '\n')
			*t = '\0';
		p->n_un.n_name = strdup(start);
		++p;
		if (++nsym >= sizeof order / sizeof order[0])
			break;
	}
	(void)fclose(f);

	if (xfilename != NULL) {
		if ((xfile = fopen(xfilename, "r")) == NULL)
			err(ERREXIT, "%s", xfilename);
		for (; fgets(asym, sizeof(asym), xfile) != NULL;) {
			for (t = asym; isspace(*t); ++t);
			if (!*(start = t))
				continue;
			while (*++t);
			if (*--t == '\n')
				*t = '\0';
			exclude[nexclude] = strdup(start);
			if (++nexclude >= sizeof exclude / sizeof exclude[0])
				break;
		}
		(void)fclose(xfile);
	}

	kfile = argv[1];
	if ((f = fopen(kfile, "r")) == NULL)
		err(ERREXIT, "%s", kfile);
	if ((o = open(kfile, O_WRONLY)) < 0)
		err(ERREXIT, "%s", kfile);

	/* read exec header */
	if ((fread(&exec, sizeof(exec), 1, f)) != 1)
		badfmt("no exec header");
	if (N_BADMAG(exec))
		badfmt("bad magic number");
	if (exec.a_syms == 0)
		badfmt("stripped");
	(void)fstat(fileno(f), &stb);
	if (stb.st_size < N_STROFF(exec) + sizeof(off_t))
		badfmt("no string table");

	/* seek to and read the symbol table */
	sa = N_SYMOFF(exec);
	(void)fseek(f, sa, SEEK_SET);
	n = exec.a_syms;
	if (!(symtab = (struct nlist *)malloc(n)))
		err(ERREXIT, NULL);
	if (fread((void *)symtab, 1, n, f) != n)
		badfmt("corrupted symbol table");

	/* read string table size and string table */
	if (fread((void *)&strtabsize, sizeof(int), 1, f) != 1 ||
	    strtabsize <= 0)
		badfmt("corrupted string table");
	strings = malloc(strtabsize);
	if (strings == NULL)
		err(ERREXIT, NULL);
	/*
	 * Subtract four from strtabsize since strtabsize includes itself,
	 * and we've already read it.
	 */
	if (fread(strings, 1, strtabsize - sizeof(int), f) !=
	    strtabsize - sizeof(int))
		badfmt("corrupted string table");

	i = n / sizeof(struct nlist);
	if (!clean) {
		newtab = (struct nlist *)malloc(n);
		if (newtab == NULL)
			err(ERREXIT, NULL);
		memset(newtab, 0, n);

		reorder(symtab, newtab, i);
		free((void *)symtab);
		symtab = newtab;
	} else {
		symkept = i;
	}

	newstrings = malloc(strtabsize);
	if (newstrings == NULL)
		err(ERREXIT, NULL);
	t = newstrings;
	for (symp = symtab; --i >= 0; symp++) {
		if (symp->n_un.n_strx == 0)
			continue;
		if (inlist(symp) < 0) {
			if (small)
				continue;
			if (clean && !savesymb(symp))
				symp->n_type &= ~N_EXT;
		} else if (clean)
			symfound++;
		symp->n_un.n_strx -= sizeof(int);
		(void)strcpy(t, &strings[symp->n_un.n_strx]);
		symp->n_un.n_strx = (t - newstrings) + sizeof(int);
		t += strlen(t) + 1;
	}

	/* update shrunk sizes */
	strtabsize = t - newstrings + sizeof(int);
	n = symkept * sizeof(struct nlist);

	/* fix exec sym size */
	(void)lseek(o, (off_t)0, SEEK_SET);
	exec.a_syms = n;
	if (write(o, (void *)&exec, sizeof(exec)) != sizeof(exec))
		err(ERREXIT, "%s", kfile);

	(void)lseek(o, sa, SEEK_SET);
	if (write(o, (void *)symtab, n) != n)
		err(ERREXIT, "%s", kfile);
	if (write(o, (void *)&strtabsize, sizeof(int)) != sizeof(int))
		err(ERREXIT, "%s", kfile);
	if (write(o, newstrings, strtabsize - sizeof(int)) !=
	    strtabsize - sizeof(int))
		err(ERREXIT, "%s", kfile);

	ftruncate(o, lseek(o, (off_t)0, SEEK_CUR));

	if ((i = nsym - symfound) > 0) {
		(void)printf("symorder: %d symbol%s not found:\n",
		    i, i == 1 ? "" : "s");
		for (i = 0; i < nsym; i++)
			if (order[i].n_value == 0)
				printf("%s\n", order[i].n_un.n_name);
		if (!missing)
			exit(NOTFOUNDEXIT);
	}
	exit(OKEXIT);
}
예제 #16
0
파일: dll.c 프로젝트: m-lohmann/qnial
void
iregisterdllfun(void)
{
  int         i,
              index;
  ResType     argtypes[MAX_ARGS];  /* list of types of arguments */
  bool        vararg[MAX_ARGS];    /* is the argument a variable arg */
  bool        ispointer[MAX_ARGS]; /* is the argument a pointer */
  int         varargcount = 0;     /* number of variable args */
  int         ispointercount = 0;  /* number of pointer args */
  nialptr     z = apop();
  char       *nialname;            /* names used by calldllfun */
  char       *dllname;             /* the real name of the function */
                                   /* in the DLL file */
  char       *library;             /* name of the DLL file */
  ResType     resulttype;          /* the type of the result */
  nialptr     nargtypes;           /* the arg type array */
  int         argcount;
  int         j;
  int         sz;
  nialptr     current;       /* usually hold the current entry in the dlllist */
  int         is_register;

  /* if we have 5 args we are registering a function */

  if ((tally(z) == 5) && (kind(z) == atype))
    is_register = 1;         /* register mode */

  else 
  /* only one arg and it is a char or a phrase, we are deleting the fun */
  if ((kind(z) == chartype) || (kind(z) == phrasetype))
    is_register = 0;         /* delete mode */

  else {                     /* error mode */
    apush(makefault("?Incorrect number of arguments to registerdllfun"));
    freeup(z);
    return;
  }

  if (is_register) {
    /* The Nial level name for the DLL function */
    STRING_CHECK(z, 0)
      nialname = STRING_GET(z, 0);


    /* The internal DLL name for the function */
    STRING_CHECK(z, 1)
      dllname = STRING_GET(z, 1);

    /* The name of the library file */
    STRING_CHECK(z, 2)
      library = STRING_GET(z, 2);

    /* The name of the result type */
    STRING_CHECK(z, 3)
      resulttype = StringToTypeID(STRING_GET(z, 3));

    /* did we find an unrecognized result type? */
    if (resulttype < 0) {
      apush(makefault("?Return type not recognized"));
      freeup(z);
      return;
    }

    if (kind(fetch_array(z, 4)) != atype) {
      apush(makefault("?Argument must be a list of strings or phrases"));
      freeup(z);
      return;
    }

    nargtypes = fetch_array(z, 4);
    argcount = tally(nargtypes);

    /* Check each of the argument type */
    for (j = 0; j < argcount; j++)
      STRING_CHECK_FREEUP(nargtypes, j, z)
      /* create an integer list of argument types from the phrase/string list */
        for (i = 0; i < argcount; i++) {
        char       *tmp;

        tmp = pfirstchar(fetch_array(nargtypes, i));  /* safe: no allocation */
        argtypes[i] = StringToTypeID(tmp);

        /* the ith argument name was not recognized */
        if (argtypes[i] < 0) {
          char        stmp[256];

          wsprintf(stmp, "?Type \"%s\" for argument %d not recognized", tmp, i + 1);
          apush(makefault(stmp));
          freeup(z);
          return;
        }
        /* set the vararg and ispointer flags for this arg */
        vararg[i] = IsVarArg(tmp);
        ispointer[i] = IsPointer(tmp);
        /* keep count of these special args */
        if (vararg[i])
          varargcount++;
        if (ispointer[i])
          ispointercount++;
      }

    /* NEW workspace Version */

    /* If the list does not yet exist, then create a one element list here */
    if (tally(dlllist) == 0) {
      nialptr     tmp = create_new_dll_entry; /* build a empty entry */

      setup_dll_entry(tmp)   /* fill it with empty data */
        apush(tmp);
      isolitary();           /* make it a list */
      decrrefcnt(dlllist);
      freeup(dlllist);
      dlllist = apop();
      incrrefcnt(dlllist);
      index = 0;
    }
    else {
      int         pos;

      /* does the requested name already exist in out list? */
      if ((pos = inlist(nialname)) >= 0) {
        /* yes it's here already, so note its position, and free the old
         * entry */
        index = pos;
        freeEntry(index);
      }
      else {
        /* if we got here, then we need to create a new entry and add it to
         * and existing dlllist */
        nialptr     tmp = create_new_dll_entry;

        setup_dll_entry(tmp)
          decrrefcnt(dlllist);
        append(dlllist, tmp);
        dlllist = apop();
        incrrefcnt(dlllist);
        index = tally(dlllist) - 1; /* this is the location of the new entry */
      }
    }



    /* grab the entry to work on */
    current = fetch_array(dlllist, index);

    /* fill in data */
    set_handle(current, NULL);
    set_nialname(current, nialname);
    set_dllname(current, dllname);
    set_callingconvention(current, (dllname[0] == '_' ? C_CALL : PASCAL_CALL));
    set_library(current, library);
    set_isloaded(current, false);
    set_resulttype(current, resulttype);
    set_argcount(current, argcount);
    set_varargcount(current, varargcount);
    set_ispointercount(current, ispointercount);

    sz = argcount;
    replace_array(current, 10, (sz == 0 ? Null : new_create_array(inttype, 1, 0, &sz)));
    for (j = 0; j < sz; j++)
      set_argtypes(current, j, argtypes[j]);

    replace_array(current, 11, (sz == 0 ? Null : new_create_array(booltype, 1, 0, &sz)));
    for (j = 0; j < sz; j++)
      set_ispointer(current, j, ispointer[j]);

    replace_array(current, 14, (sz == 0 ? Null : new_create_array(booltype, 1, 0, &sz)));
    for (j = 0; j < sz; j++)
      set_vararg(current, j, vararg[j]);
  }
  else { /* delete entry code */
예제 #17
0
/*
 * Transfer the file or directory in target[].
 * rname is the name of the file on the remote host.
 */
int 
sendf (char *rname, int opts)
{
	struct subcmd *sc;
	struct stat stb;
	int sizerr, f, u, len;
	off_t i;
	DIR *d;
	struct dirent *dp;
	char *otp, *cp;
	extern struct subcmd *subcmds;
	char	buf[BUFSIZ];
	static char uname[15], group[15];

	if (debug)
		 printf("sendf(%s, %x)\n", rname, opts);

	if (except(target))
		return;
	if ((opts & FOLLOW ? stat(target, &stb) : lstat(target, &stb)) < 0) {
		advise (target, "Can't stat");
		return;
	}
	if ((u = update(rname, opts, &stb)) == 0) {
		if ((stb.st_mode & S_IFMT) == S_IFREG && stb.st_nlink > 1)
			 savelink(&stb, opts);
		return;
	}

	if (pw == NULL || pw->pw_uid != stb.st_uid)
		if ((pw = getpwuid(stb.st_uid)) == NULL) {
			log(lfp, "%s: no password entry for uid \n", target);
			pw = NULL;
			 sprintf(uname, ":%d", stb.st_uid);
		}
	if (gr == NULL || gr->gr_gid != stb.st_gid)
		if ((gr = getgrgid(stb.st_gid)) == NULL) {
			log(lfp, "%s: no name for group %d\n", target);
			gr = NULL;
			 sprintf(group, ":%d", stb.st_gid);
		}
	if (u == 1) {
#ifdef UW
		if (opts & NOINSTALL) {
			log(lfp, "does not exist, did not install: %s\n", target);
			goto dospecial;
		}
#endif UW
		if (opts & VERIFY) {
			log(lfp, "need to install: %s\n", target);
			goto dospecial;
		}
		log(lfp, "installing: %s\n", target);
		opts &= ~(COMPARE|REMOVE);
	}

	switch (stb.st_mode & S_IFMT) {
	case S_IFDIR:
		if ((d = opendir(target)) == NULL) {
			advise (target, "Can't open directory");
			return;
		}
		if (transfer (stb.st_mode & S_IFMT, opts,
					  stb.st_mode & 07777, (off_t)0, (time_t)0,
					  protoname (), protogroup (),
					  rname, "") < 0) {
			 closedir (d);
			return;
		}

		if (opts & REMOVE)
			 rmchk(opts);

		otp = tp;
		len = tp - target;
		while (dp = readdir(d)) {
			if (!strcmp(dp->d_name, ".") ||
					!strcmp(dp->d_name, ".."))
				continue;
			if (len + 1 + (int)strlen(dp->d_name) >= BUFSIZ - 1) {
				advise (NULLCP, "%s/%s name too long",
						target, dp->d_name);
				continue;
			}
			tp = otp;
			*tp++ = '/';
			cp = dp->d_name;
			while (*tp++ = *cp++)
				;
			tp--;
			sendf(dp->d_name, opts);
		}
		 closedir(d);
		 terminate (S_IFDIR, OK);
		tp = otp;
		*tp = '\0';
		return;

	case S_IFLNK:
		if (u != 1)
			opts |= COMPARE;
		if (stb.st_nlink > 1) {
			struct linkbuf *lp;

			if ((lp = savelink(&stb, opts)) != NULL) {
				if (*lp -> target == 0)
					 strcpy (buf, lp -> pathname);
				else	 sprintf (buf, "%s/%s",
											lp -> target,
											lp -> pathname);
				 transfer ((unsigned short)0, opts,
								 (unsigned short)0, (off_t)0,
								 (time_t)0, "", "",
								 rname, buf);
				return;
			}
		}
		sizerr = (readlink(target, buf, BUFSIZ) != stb.st_size);
		if (debug)
			 printf("readlink = %.*s\n", stb.st_size, buf);
		if (transfer (stb.st_mode & S_IFMT, opts, stb.st_mode & 07777,
					  stb.st_size, stb.st_mtime,
					  protoname (), protogroup (), rname,
					  buf) < 0)
			return;
		goto done;

	case S_IFREG:
		break;

	default:
		advise (NULLCP, "%s: not a file or directory", target);
		return;
	}

	if (u == 2) {
		if (opts & VERIFY) {
			log(lfp, "need to update: %s\n", target);
			goto dospecial;
		}
		log(lfp, "updating: %s\n", target);
	}

	if (stb.st_nlink > 1) {
		struct linkbuf *lp;

		if ((lp = savelink(&stb, opts)) != NULL) {
			if (*lp -> target == 0)
				 strcpy (buf, lp -> pathname);
			else	 sprintf (buf, "%s/%s",
										lp -> target,
										lp -> pathname);
			 transfer ((unsigned short)0, opts,
							 (unsigned short)0, (off_t)0,
							 (time_t)0, "", "",
							 rname, buf);
			return;
		}
	}

	if ((f = open(target, O_RDONLY, 0)) < 0) {
		advise (target, "Can't open file");
		return;
	}
	if ( transfer ((unsigned short)S_IFREG, opts, stb.st_mode & 07777,
				   stb.st_size,
				   stb.st_mtime, protoname (), protogroup (),
				   rname, "") < 0) {
		 close (f);
		return;
	}
	sizerr = 0;
	for (i = 0; i < stb.st_size; i += sizeof tranbuf) {
		int amt = sizeof tranbuf;
		if (i + amt > stb.st_size)
			amt = stb.st_size - i;
		if (sizerr == 0 && read(f, tranbuf, amt) != amt)
			sizerr = 1;
		if (tran_data (tranbuf, amt) == NOTOK)
			break;
	}
	 close(f);
	if (sizerr) {
		advise (NULLCP, "%s: file changed size", target);
		if (terminate (S_IFREG, NOTOK) < 0)
			return;
	} else {
		if (terminate (S_IFREG, OK) < 0)
			return;
	}
done:
	if (opts & COMPARE)
		return;
dospecial:
	for (sc = subcmds; sc != NULL; sc = sc->sc_next) {
		if (sc->sc_type != SPECIAL)
			continue;
#ifdef UW
		if (opts & NOINSTALL)  /* don't do specials associated with
					  non-installation notices */
			continue;
#endif UW
		if (sc->sc_args != NULL && !inlist(sc->sc_args, target))
			continue;
		log(lfp, "special \"%s\"\n", sc->sc_name);
		if (opts & VERIFY)
			continue;
		 sprintf(buf, "FILE=%s;export FILE;%s",
					   target, sc->sc_name);
		 runspecial (buf);

	}
}
예제 #18
0
파일: docmd.c 프로젝트: UNGLinux/Obase
/*
 * Compare the mtime of file to the list of time stamps.
 */
static void
cmptime(char *name, struct subcmd *sbcmds, char **env)
{
	struct subcmd *sc;
	struct stat stb;

	debugmsg(DM_CALL, "cmptime(%s)", name);

	if (except(name))
		return;

	if (nflag) {
		(void) printf("comparing dates: %s\n", name);
		return;
	}

	/*
	 * first time cmptime() is called?
	 */
	if (ptarget == NULL) {
		if (exptilde(target, name, sizeof(target)) == NULL)
			return;
		ptarget = name = target;
		while (*ptarget)
			ptarget++;
	}
	if (access(name, R_OK) < 0 || stat(name, &stb) < 0) {
		error("%s: cannot access file: %s", name, SYSERR);
		return;
	}

	if (S_ISDIR(stb.st_mode)) {
		rcmptime(&stb, sbcmds, env);
		return;
	} else if (!S_ISREG(stb.st_mode)) {
		error("%s: not a plain file", name);
		return;
	}

	if (stb.st_mtime > lastmod) {
		message(MT_INFO, "%s: file is newer", name);
		for (sc = sbcmds; sc != NULL; sc = sc->sc_next) {
			char buf[BUFSIZ];
			if (sc->sc_type != SPECIAL)
				continue;
			if (sc->sc_args != NULL && !inlist(sc->sc_args, name))
				continue;
			(void) snprintf(buf, sizeof(buf), "%s=%s;%s", 
				        E_LOCFILE, name, sc->sc_name);
			message(MT_CHANGE, "special \"%s\"", buf);
			if (*env) {
				size_t len = strlen(*env) + strlen(name) + 2;
				*env = (char *) xrealloc(*env, len);
				(void) strlcat(*env, name, len);
				(void) strlcat(*env, ":", len);
			}
			if (IS_ON(options, DO_VERIFY))
				continue;

			runcommand(buf);
		}
	}
}
예제 #19
0
파일: Ostw.C 프로젝트: zhangzc11/CPTV
int BeginJob( int argc, char** argv )
{
  string inputfile;
  string outputfile;
  string DataSet;
  vector<string> datafiles;

  /* Argument parsing */
  /* ---------------- */
  if( argc != 5 ) {
    Usage();
  } else {
    inputfile = argv[1];
    outputfile = argv[2];
    RunInfoOutput = argv[3];
    DataSet = argv[4];

    string extension = inputfile.substr( inputfile.length()-5, 5 );
    /* A single input file */
    if( extension == ".root" )  {
      //cout<<"A single input file, "<<inputfile<<endl;
      datafiles.push_back(inputfile);
    }
    /* Input file is a list */
    else if( extension == ".list" )  {
      //cout<<"A list of root files, "<<inputfile<<endl;
      /* Grab all the data files in the list */
      ifstream inlist( inputfile.c_str() );
      string line;
      while( getline( inlist, line ) )  {
        datafiles.push_back( line );
      }
    }

    if( DataSet == "Gd" )      AllCut = new Cuts( Cuts::Gd );
    else if ( DataSet == "H" ) AllCut = new Cuts( Cuts::H  );
    else {
      cout<<"Unknown data set "<<endl;
      exit(0);
    }
  }

  /* Load the StreamChain and initializa StreamChain Tree reader */
  /* ----------------------------------------------------------- */
  StreamChain = new TChain("Stream");

  for( unsigned int i =0; i<datafiles.size(); i++ ) {
    StreamChain->Add( datafiles[i].c_str() );
  }
  //cout<<datafiles.size()<<" data files will be processed."<<endl;

  Reader = new StreamReader;
  Reader->Init(StreamChain);

  /* Prepare the output tree */
  aEventTree = new EventTree("Event",outputfile.c_str(),0);

  for( int bin = 1; bin<=timebins; bin++ ) {
    double time = (timeEnd-timeStart)/timebins * (bin-0.5);
    TimeX[bin-1] = time;
    
    for( int Ad = 1; Ad<=4; Ad++ ) {
      CTimeAviPl [Ad-1][bin-1]  = 0;
      CSingleUpPl[Ad-1][bin-1]  = 0;
      CSingleLwPl[Ad-1][bin-1]  = 0;
      CRatePl    [Ad-1][bin-1]  = 0;
      
      CTimeAviAd [Ad-1][bin-1]  = 0;
      CSingleUpAd[Ad-1][bin-1]  = 0;
      CSingleLwAd[Ad-1][bin-1]  = 0;
      CRateAd    [Ad-1][bin-1]  = 0;
      
      CTimeAviSh [Ad-1][bin-1]  = 0;
      CSingleUpSh[Ad-1][bin-1]  = 0;
      CSingleLwSh[Ad-1][bin-1]  = 0;
      CRateSh    [Ad-1][bin-1]  = 0;
      
      CTimeAvi   [Ad-1][bin-1]  = 0;
      CSingleUp  [Ad-1][bin-1]  = 0;
      CSingleLw  [Ad-1][bin-1]  = 0;
      CRate      [Ad-1][bin-1]  = 0;
    }
  }

  return 1;
}
예제 #20
0
파일: GetRateXY.C 프로젝트: yuxip/CellScan
  Int_t GetRateXY( Int_t fillnum = 15419 ,const char* sl = "small" ){
	
	gSystem->Load("../lib/libMyCellMgr.so");
        gROOT->LoadMacro("/home/yuxip/FMS/CellScan/macros/Legal.C");
	Char_t runlist[20];
	sprintf(runlist,"fill%d.list",fillnum);
	fstream inlist(runlist,ios::in);
	if(!inlist){
		cout<<runlist<<" does not exist!!"<<endl;
		return -1;
	}	

	TH2F* 	fcmp;
	TFile* 	fcell	= 0;
	Int_t	n1 	= 0;
	Int_t	n2	= 0;
	
	Char_t outfilename[30];
	if(!strcmp(sl,"large")){
		sprintf(outfilename,"largeRateVsGcor_fill%d_n2.ps",fillnum);
		n1 = 2;
		n2 = 2;         //analysis each nstb separately
	}
	else if(!strcmp(sl,"small")){
		sprintf(outfilename,"smallRateVsGcor_fill%d_n4.ps",fillnum);
		n1 = 4;
		n2 = 4;
	}
	else{
		cout<<"invalid 2nd argument"<<endl;
		return -1;
	}
	TString outfile(outfilename);
	TString headout = outfile + "[";
	TString endout  = outfile + "]";
//	TCanvas* c1 	= new TCanvas("c1","c1",1100,1100);
	TCanvas* c1 	= new TCanvas("c1","c1",700,700);
//	c1->Divide(3,3);
//	c1->Print(headout);
	
	fstream inGcor("FmsCorr_sh.txt",ios::in);
	Int_t	iew;
	Int_t	instb;
	Int_t	ich;
	Float_t	gcorsh;
	
	Int_t	cnt	= 1;
	Int_t	cellcnt	= 0;
	Int_t	rch	= 0;
	Long_t 	runnum 	= 0;
	Char_t	cellname[30];
	Char_t	cellfile[30];
	Char_t  title[20];
	Int_t	bit	= 0;
	UChar_t status	= 0;
	Int_t	rate	= 0;
	Int_t 	Trgth	= 100;
	MyCell*	mcell	= 0;
	Float_t mycor;
	Float_t	gdiff;
//	while(inlist>>runnum){
	
	sprintf(title,"RateVsGcor_fill%d_n2",fillnum);
//	fcmp[cnt-1] = new TH2F(title,title,100,-1,1,100,0,10000);
	fcmp = new TH2F(title,title,100,-1,1,100,0,10000);
	while(inGcor>>iew>>instb>>ich>>gcorsh){
		if(instb==n1&&iew==2)break;
	}
	
	for(Int_t nstb = n1; nstb <= n2; nstb++){
		for(Int_t row0 = 0; row0 < 34; row0++){
			for(Int_t col0 = 0; col0 < 17; col0++){

				if(cellcnt)inGcor>>iew>>instb>>ich>>gcorsh;
				cellcnt++;	
				if(!Legal(2,nstb,row0,col0)){
					continue;
				}
				sprintf(cellname,"Cellr%d_c%d_n%d",row0,col0,nstb);
				cout<<"processing "<<cellname<<endl;
				if(col0==0){
					if(nstb<3){
						rch = 17*row0+col0+1;
					}
					else if(nstb<5){
						rch = 12*row0+col0+1;
					}
					cout<<"debug instb: "<<instb<<" nstb: "<<nstb<<" ich: "<<ich<<" rch: "<<rch<<" gcorsh: "<<gcorsh<<endl;
				}

				sprintf(cellfile,"../cells/Cellr%d_c%d_n%d.root",row0,col0,nstb);
					
				fcell = new TFile(cellfile,"read");
				if(!fcell){
					cout<<cellfile<<" does not exist!!"<<endl;
					return -1;
				}
				mcell = (MyCell*)fcell->Get(cellname);
				if(!mcell){
					cout<<"ERROR reading "<<cellname<<" object"<<endl;
					return -1;
				}
				mycor = mcell->GetGainCor();
				if(col0==0)cout<<"mycor: "<<mycor<<endl;
				gdiff = mycor - gcorsh;
//					status = mcell->GetStatusBit(runnum);
//					bit = (Int_t)(status&0x03); //can not be 0011
				inlist.clear();
				inlist.seekg(0,ios::beg);
				while(inlist>>runnum){
					if(col0==0)cout<<"run :"<<runnum<<endl;
					rate = mcell->GetNth(runnum,Trgth);
					fcmp->Fill(gdiff,rate);
				}
				mcell	= 0;
				status 	= 0;
				bit	= 0;
				gdiff	= 0;
				fcell->Close();
				fcell	= 0;
			}
		}
	}
//	c1->cd(cnt);
	fcmp->Draw("COLZ");
//	if(cnt%9==0){
//		c1->Print(outfile);
//		c1->Clear();
//		c1->Divide(3,3);
//		cnt = 0;
//	}
//		cnt++;
//		cout<<"============================"<<runnum<<" done.."<<endl;
//		cellcnt = 0;
//	}
	c1->Print(outfile);	
//	c1->Print(endout);
		
	return 1;
  }
예제 #21
0
파일: advdbs.c 프로젝트: BPaden/garglk
/* haspreposition - check to see if an action has a specified preposition */
int haspreposition(int act, int preposition)
{
    return (inlist(getafield(act,A_PREPOSITIONS),preposition));
}
예제 #22
0
/* Check if command is in continue list
   and do a "aliasing" if it exists as a job in background */

#undef CNDEBUG			/* For now */
void
continue_jobs(struct wordent *cp)
{
    struct wordent *we;
    struct process *pp, *np;
    Char   *cmd, *continue_list, *continue_args_list;

#ifdef CNDEBUG
    Char   *tag;
    static Char STRcndebug[] =
    {'c', 'n', 'd', 'e', 'b', 'u', 'g', '\0'};
#endif /* CNDEBUG */
    int    in_cont_list, in_cont_arg_list;


#ifdef CNDEBUG
    tag = varval(STRcndebug);
#endif /* CNDEBUG */
    continue_list = varval(STRcontinue);
    continue_args_list = varval(STRcontinue_args);
    if (*continue_list == '\0' && *continue_args_list == '\0')
	return;

    we = cp->next;
    while (*we->word == ';' && we != cp)
	we = we->next;
    while (we != cp) {
#ifdef CNDEBUG
	if (*tag)
	    xprintf(CGETS(22, 11, "parsing command line\n"));
#endif /* CNDEBUG */
	cmd = we->word;
	in_cont_list = inlist(continue_list, cmd);
	in_cont_arg_list = inlist(continue_args_list, cmd);
	if (in_cont_list || in_cont_arg_list) {
#ifdef CNDEBUG
	    if (*tag)
		xprintf(CGETS(22, 12, "in one of the lists\n"));
#endif /* CNDEBUG */
	    np = NULL;
	    for (pp = proclist.p_next; pp; pp = pp->p_next) {
		if (prefix(cmd, pp->p_command)) {
		    if (pp->p_index) {
			np = pp;
			break;
		    }
		}
	    }
	    if (np) {
		insert(we, in_cont_arg_list);
	    }
	}
	for (we = we->next;
	     *we->word != ';' && we != cp;
	     we = we->next)
	    continue;
	if (*we->word == ';')
	    we = we->next;
    }
#ifdef CNDEBUG
    if (*tag) {
	xprintf(CGETS(22, 13, "command line now is:\n"));
	for (we = cp->next; we != cp; we = we->next)
	    xprintf("%S ", we->word);
    }
#endif /* CNDEBUG */
    return;
}
예제 #23
0
파일: file.c 프로젝트: kahrs/cda
Line *
inlist(FILE *fp)
{
	int c,i;
	char *s;
	Point p;
	Line *l=0;
	while (1) {
		c=fgetc(fp);
		switch (c) {
		case '\n':
			break;
		default:
			do
				c = fgetc(fp);
			while (c != '\n');
			break;
		case 'w':
		case 'l':
			l = newline(inpoint(fp),l);
			l->Q = inpoint(fp);
			break;
		case 'b':
			l = newbox(inpoint(fp),l);
			l->Q = inpoint(fp);
			break;
		case 'd':
			l = newdots(inpoint(fp),l);
			l->Q = inpoint(fp);
			break;
		case 'z':
			l = newmacro(inpoint(fp),l);
			l->Q = inpoint(fp);
			break;
		case 's':
			s = instring(fp);
			i = inint(fp);
			p = inpoint(fp);
			if (*s != 0) {
				l = newstring(p,i,l);
				setstring((String *)l,s);
			}
			break;
		case 't':		/* turn a jraw text into two graw strings */
			s = instring(fp);
			i = jtog(inint(fp));
			p = Pt(0,(showgrey ? GRID*2 : GRID));
			l = newstring(p,i,l);
			setstring((String *)l,s);
			s = instring(fp);
			inint(fp);
			p = inpoint(fp);
			if (*s != 0) {		/* gad, what a mess */
				l = newstring(add(p,l->P),i,l);
				setstring((String *)l,s);
				l->next->P = p;
			}
			else			/* watch carefully */
				l->P = p;
			break;
		case 'r':
			l = newref(intern(instring(fp)),l);
			break;
		case 'i':
			s = intern(instring(fp));
			l = newinst(inpoint(fp),s,l);
			break;
		case 'm':
			nest = 1;
			l = newmaster(intern(instring(fp)),l);
			((Master *)l)->dl = inlist(fp);
			break;
		case 'e':
			if (nest == 0)
				dprint("found end of no macro\n");
			nest = 0;
		case -1:
			return l;
		}
	}
}