コード例 #1
0
void
dounit(void)
{
	char tbuff[100];

	if (todo == 0)
		return;
	wrong = 0;
retry:
	start(todo);
	/* script = lesson */
	snprintf(tbuff, sizeof tbuff, "%s/%s/L%s", _PATH_LLIB, sname, todo);
	scrin = fopen(tbuff, "r");
	if (scrin == NULL) {
		fprintf(stderr, "No script.\n");
		err(1, "%s", tbuff);
		wrapup(1);
	}

	copy(0, scrin);
	if (more == 0)
		return;
	copy(1, stdin);
	if (more == 0)
		return;
	copy(0, scrin);

	if (comfile >= 0)
		close(comfile);
	wait(&didok);
	didok = (status == 0);
	if (!didok) {
		wrong++;
		printf("\nSorry, that's %snot right.  Try again?  ",
		    wrong > 1 ? "still " : "");
		fflush(stdout);
		for (;;) {
			if (fgets(tbuff, sizeof tbuff, stdin) == NULL)
				errx(1, "could not read input");
			trim(tbuff);
			if (tbuff[0] == 'y') {
				printf("Try the problem again.\n");
				fflush(stdout);
				goto retry;
			} else if (strcmp(tbuff, "bye") == 0)
				wrapup(1);
			else if (tbuff[0] == 'n') {
				wrong = 0;
				printf("\nOK.  Lesson %s (%d)\n", todo, speed);
				printf("Skipping to next lesson.\n\n");
				fflush(stdout);
				break;
			} else {
				printf("Please type yes, no or bye:  ");
				fflush(stdout);
			}
		}
	}
	setdid(todo, sequence++);
}
コード例 #2
0
ファイル: sql.cpp プロジェクト: Devba/blockparser
    virtual void startBlock(
        const Block *b,
        uint64_t
    )
    {
        if(0<=cutoffBlock && cutoffBlock<b->height) wrapup();

        uint8_t blockHash[kSHA256ByteSize];
        sha256Twice(blockHash, b->data, 80);

        const uint8_t *p = b->data;
        SKIP(uint32_t, version, p);
        SKIP(uint256_t, prevBlkHash, p);
        SKIP(uint256_t, blkMerkleRoot, p);
        LOAD(uint32_t, blkTime, p);

        // id BIGINT PRIMARY KEY
        // hash BINARY(32)
        // time BIGINT
        fprintf(blockFile, "%" PRIu64 "\t", (blkID = b->height-1));

        writeEscapedBinaryBuffer(blockFile, blockHash, kSHA256ByteSize);
        fputc('\t', blockFile);

        fprintf(blockFile, "%" PRIu64 "\n", (uint64_t)blkTime);
        if(0==(b->height)%500) {
            fprintf(
                stderr,
                "block=%8" PRIu64 " "
                "nbOutputs=%8" PRIu64 "\n",
                b->height,
                outputMap.size()
            );
        }
    }
コード例 #3
0
ファイル: csv.cpp プロジェクト: Devba/blockparser
    virtual void startBlock(
        const Block *b,
        uint64_t chainBase
    )
    {
        if (lastBlock >= 0 && lastBlock < b->height - 1) wrapup();
        if (b->height - 1 == firstBlock) active = 1;

        if (active) {
            uint8_t blockHash[kSHA256ByteSize];
            sha256Twice(blockHash, b->data, 80);

            const uint8_t *p = b->data;

            // Total block size is 81 bytes plus transactions
            blkSize = 81;

            totalBlkFees = 0;
            totalBlkOutput = 0;
            numBlkTxs = 0;

            LOAD(uint32_t, version, p);
            SKIP(uint256_t, prevBlkHash, p);
            LOAD(uint256_t, blkMerkleRoot, p);
            LOAD(uint32_t, blkTime, p);
            LOAD(uint32_t, difficultyBits, p);
            LOAD(uint32_t, nonce, p);

            // ID
            fprintf(blockFile, "%" PRIu64 ",", blkID);

            // Hash
            uint8_t buf[1 + 2*kSHA256ByteSize];
            toHex(buf, blockHash);
            fprintf(blockFile, "\"%s\",", buf);

            // Version
            fprintf(blockFile, "%" PRIu32 ",", version);

            // Timestamp
            time_t blockTime = blkTime;
            char tbuf[23];
            strftime(tbuf, sizeof tbuf, "%FT%TZ", gmtime(&blockTime));

            fprintf(blockFile, "\"%s\",", tbuf);

            // Nonce
            fprintf(blockFile, "%" PRIu32 ",", nonce);

            // Difficulty
            fprintf(blockFile, "%f,", difficulty(difficultyBits));

            // Merkle root
            uint8_t buf2[kSHA256ByteSize];
            uint8_t buf3[1 + 2*kSHA256ByteSize];
            memcpy(buf2, &blkMerkleRoot, kSHA256ByteSize);
            toHex(buf3, buf2);
            fprintf(blockFile, "\"%s\",", buf3);
        }
    }
コード例 #4
0
ファイル: pcap-enet.c プロジェクト: 2014-class/freerouter
void
readloop(int cnt, int if_fd, struct bpf_program *fp, printfunc printit)
{
#ifdef	IBMRTPC
	register struct packet_header *ph;
	register u_char *bp;
	register int inc;
#else	/* !IBMRTPC */
	static struct timeval tv = { 0 };
#endif	/* IBMRTPC */
	register int cc, caplen;
	register struct bpf_insn *fcode = fp->bf_insns;
	union {
		struct packet_header hdr;
		u_char	p[BUFSPACE];
		u_short	s;
	} buf;

	while (1) {
		if ((cc = read(if_fd, (char *)buf.p, sizeof(buf))) < 0)
			efReadError(if_fd, "reader");

#ifdef	IBMRTPC
		/*
		 * Loop through each packet.
		 */
		bp = buf.p;
		while (cc > 0) {
			ph = (struct packet_header *)bp;
			caplen = ph->tap.th_wirelen > snaplen ? snaplen : ph->tap
.th_wirelen ;
			if (bpf_filter(fcode, (char *)ph->packet,
						ph->tap.th_wirelen, caplen)) {
				if (cnt >= 0 && --cnt < 0)
					goto out;
				(*printit)((char *)ph->packet,
					(struct timeval *)ph->tap.th_timestamp,
					ph->tap.th_wirelen, caplen);
			}
			inc = ph->length.PacketOffset;
			cc -= inc;
			bp += inc;
		}
#else	/* !IBMRTPC */
		caplen = cc > snaplen ? snaplen : cc ;
		if (bpf_filter(fcode, buf.hdr.packet, cc, caplen)) {
			if (cnt >= 0 && --cnt < 0)
				goto out;
			(*printit)(buf.hdr.packet, &tv, cc, caplen);
		}
#endif	/* IBMRTPC */
	}
 out:
	wrapup(if_fd);
}
コード例 #5
0
    virtual void startBlock(
        const Block *b,
        uint64_t chainSize
    )
    {
        curBlock = b;

        const uint8_t *p = b->data;
        const uint8_t *sz = -4 + p;
        LOAD(uint32_t, size, sz);
        offset += size;

        double now = usecs();
        static double startTime = 0;
        static double lastStatTime = 0;
        double elapsed = now - lastStatTime;
        bool longEnough = (5*1000*1000<elapsed);
        bool closeEnough = ((chainSize - offset)<80);
        if(unlikely(longEnough || closeEnough)) {

            if(0==startTime) {
                startTime = now;
            }

            double progress = offset/(double)chainSize;
            double elasedSinceStart = 1e-6*(now - startTime);
            double speed = progress / elasedSinceStart;
            info(
                "%8" PRIu64 " blocks, "
                "%8.3f MegaAddrs , "
                "%6.2f%% , "
                "elapsed = %5.2fs , "
                "eta = %5.2fs , "
                ,
                curBlock->height,
                addrMap.size()*1e-6,
                100.0*progress,
                elasedSinceStart,
                (1.0/speed) - elasedSinceStart
            );

            lastStatTime = now;
        }

        SKIP(uint32_t, version, p);
        SKIP(uint256_t, prevBlkHash, p);
        SKIP(uint256_t, blkMerkleRoot, p);
        LOAD(uint32_t, bTime, p);
        blockTime = bTime;

        if(0<=cutoffBlock && cutoffBlock<=curBlock->height) {
            wrapup();
        }
    }
コード例 #6
0
void
setdid(char *lesson, int seq)
{
	struct whichdid *pw;
	for (pw = which; pw < which + nwh; pw++) {
		if (strcmp(pw->w_less, lesson) == SAME) {
			pw->w_seq = seq;
			return;
		}
	}
	pw = which + nwh++;
	if (nwh >= NW) {
		fprintf(stderr, "nwh >= NW\n");
		wrapup(1);
	}
	pw->w_seq = seq;
	pw->w_less = whcp;
	while ((*whcp++ = *lesson++) != 0)
		;
	if (whcp >= whbuff + NWCH) {
		fprintf(stderr, "lesson name too long\n");
		wrapup(1);
	}
}
コード例 #7
0
void
signal_intrpt(int signo __attribute__ ((__unused__)))
{
	char response[20], *p;

	signal(SIGINT, signal_hangup);
	write(2, "\nInterrupt.\nWant to go on?  ", 28);
	p = response;
	*p = 'n';
	while (read(0, p, 1) == 1 && *p != '\n')
		p++;
	if (response[0] != 'y')
		wrapup(1);
	ungetc('\n', stdin);
	signal(SIGINT, signal_intrpt);
}
コード例 #8
0
void
start(char *lesson)
{
	struct direct {
		int inode;
		char name[14];
	};
#if 0
	struct direct dv[ND], *dm, *dp;
	int f, c, n;
#endif
	char where [1024];

#if 0
	/* I'm not sure the point of this loop to unlink files, it may be
	 * some kind of cleanup. I'm sure I don't like unlinking files
	 * like this and, anyway, it would all have to be recoded using
	 * opendir() and readdir(). 	-- Ian
	 */
	f = open(".", O_RDONLY);
	n = read(f, dv, ND*sizeof(*dp));
	n /= sizeof(*dp);
	if (n == ND)
		fprintf(stderr, "lesson too long\n");
	dm = dv + n;
	for (dp = dv; dp < dm; dp++)
		if (dp->inode) {
			n = strlen(dp->name);
			if (dp->name[n - 2] == '.' && dp->name[n - 1] == 'c')
				continue;
			c = dp->name[0];
			if (c >= 'a' && c <= 'z')
				unlink(dp->name);
		}
	close(f);
	if (ask)
		return;
#endif
	snprintf(where, sizeof where, "%s/%s/L%s", _PATH_LLIB, sname, lesson);
	if (access(where, R_OK) == 0)	/* there is a file */
		return;
	fprintf(stderr, "No lesson %s\n", lesson);
	err(1, "%s", where);
	wrapup(1);
}
コード例 #9
0
void updateAccount(int pid_accnt_no,int add_amount)
{
	struct balance_record* curr;

	for(curr=globl_shm_ptr;curr!=globl_shm_end_record; curr++)
	{
		if(curr->client_accnt_no==pid_accnt_no)
		{
			printf("		Adding %d to AccountNo. : %d \n",add_amount, curr->client_accnt_no);
			curr->client_balance += add_amount;
			curr->last_update_timestamp = time(0);
			return;
		}
	}

	printf("Error : Account PID %d Not found @ Master ! \n\n",pid_accnt_no);
	wrapup();
}
コード例 #10
0
int
main(int argc, char *argv[])
{
	speed = 0;
	more = 1;
	pwline = getlogin();
	setbuf(stdout, malloc(BUFSIZ));
	selsub(argc, argv);
	signal(SIGHUP, signal_hangup);
	signal(SIGINT, signal_intrpt);
	while (more) {
		selunit();
		dounit();
		whatnow();
	}
	wrapup(0);
	return (0);
}
コード例 #11
0
ファイル: imake.c プロジェクト: johntfoster/seacas
int main(int argc, char **argv)
{
	FILE	*tmpfd;
	char	makeMacro[ BUFSIZ ];
	char	makefileMacro[ BUFSIZ ];

	program = argv[0];
	init();
	SetOpts(argc, argv);

	Imakefile = FindImakefile(Imakefile);
	CheckImakefileC(ImakefileC);
	if (Makefile)
		tmpMakefile = Makefile;
	else {
		tmpMakefile = Strdup(tmpMakefile);
		(void) mkstemp(tmpMakefile);
	}
	AddMakeArg("-f");
	AddMakeArg( tmpMakefile );
	sprintf(makeMacro, "MAKE=%s", program);
	AddMakeArg( makeMacro );
	sprintf(makefileMacro, "MAKEFILE=%s", Imakefile);
	AddMakeArg( makefileMacro );

	if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL)
		LogFatal("Cannot create temporary file %s.", tmpMakefile);

	cleanedImakefile = CleanCppInput(Imakefile);
	cppit(cleanedImakefile, Template, ImakefileC, tmpfd, tmpMakefile);

	if (show) {
		if (Makefile == NULL)
			showit(tmpfd);
	} else
		makeit();
	wrapup();
	exit(0);
}
コード例 #12
0
ファイル: sql.cpp プロジェクト: brishtiteveja/bitiodine
  virtual void startBlock(
    const Block *b,
    uint64_t
    ) {
    if (lastBlock < b->height) {
      wrapup();
    }

    auto p = b->chunk->getData();
    uint8_t blockHash[kSHA256ByteSize];
    sha256Twice(blockHash, p, 80);

    SKIP(uint32_t,  version,       p);
    SKIP(uint256_t, prevBlkHash,   p);
    SKIP(uint256_t, blkMerkleRoot, p);
    LOAD(uint32_t, blkTime, p);

    blkID = b->height - 1;

    if (blkID >= firstBlock) {
      fprintf(blockFile, "%" PRIu64 "|", blkID);

      writeHexEscapedBinaryBuffer(blockFile, blockHash, kSHA256ByteSize);
      fputc('|', blockFile);
      fprintf(blockFile, "%" PRIu64 "\n", (uint64_t)blkTime);
    }

    if (0 == blkID % 5000) {
      fprintf(
        stderr,
        "block=%8" PRIu64 " "
        "nbOutputs=%9" PRIu64 "\n",
        blkID,
        outputMap.size()
        );
    }
  }
コード例 #13
0
ファイル: selunit.c プロジェクト: YoshikazuNakahara/Unixv7x86
selunit()
{
	char fnam[20], s[50];
	static char dobuff[50];
	char posslev[20][20];
	int diff[20], i, k, m, n, best, alts;
	FILE *f;
	char zb[200];
	static char saved[20];

	while (ask) {
		printf("What lesson? ");
		fflush(stdout);
		gets(dobuff);
		if (strcmp(dobuff, "bye") == 0)
			wrapup(0);
		level = todo = dobuff;
		sprintf(s, "../../%s/L%s", sname, dobuff);
		if (access(s, 04) == 0)
			return;
		printf("no such lesson\n");
	}
	alts = 0;
retry:
	f=scrin;
	if (f==NULL) {
		sprintf(fnam, "../../%s/L%s", sname, level);
		f = fopen(fnam, "r");
		if (f==NULL) {
			fprintf(stderr, "No script for lesson %s.\n", level);
			wrapup(1);
		}
		while (fgets(zb, 200, f)) {
			trim(zb);
			if (strcmp(zb, "#next")==0)
				break;
		}
	}
	if (feof(f)) {
		printf("Congratulations; you have finished this sequence.\n");
		fflush(stdout);
		todo = 0;
		return;
	}
	for(i=0; fgets(s, 50, f); i++) {
		sscanf(s, "%s %d", posslev[i], &diff[i]);
	}
	best = -1;
	/* cycle through lessons from random start */
	/* first try the current place, failing that back up to
	     last place there are untried alternatives (but only one backup) */
	n = grand()%i;
	for(k=0; k<i; k++) {
		m = (n+k)%i;
		if (already(posslev[m],0)) continue;
		if (best<0) best=m;
		/* real alternatives */
		alts++;
		if (abs(diff[m]-speed) < abs(diff[best]-speed))
			best=m;
	}
	if (best < 0 && nsave) {
		nsave--;
		strcpy(level, saved);
		goto retry;
	}
	if (best <0) {
		/* lessons exhausted or missing */
		printf("Sorry, there are no alternative lessons at this stage.\n");
		printf("See someone for help.\n");
		fflush(stdout);
		todo = 0;
		return;
	}
	strcpy (dobuff, posslev[best]);
	if (alts>1) {
		nsave=1;
		strcpy (saved, level);
	}
	todo = dobuff;
	fclose(f);
}
コード例 #14
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;
}
コード例 #15
0
void main(int argc,char* argv[])
{
	signal(SIGKILL,wrapup);
	signal(SIGINT,wrapup);
	signal(SIGTERM,wrapup);
	signal(SIGQUIT,wrapup);

	int num_ATMs,i;

	if(argc!=2)
	{
		printf("Please enter : %s <number_of_ATMs>\n", argv[0]);
		exit(0);
	}
	else
		sscanf(argv[1],"%d",&num_ATMs);

	createLocatorFile();

	semID = semget((key_t)SEMAPHORE_KEY,num_ATMs,IPC_CREAT|0666);
	if(semID==-1) perror("Error in semget !\n");

	mssgQ_ID=msgget((key_t)MASTER_MSSG_Q_KEY,IPC_CREAT|0666);
	if(mssgQ_ID==-1) perror("Error in msgget !\n");

	globl_shmID = shmget((key_t)GLOBAL_SHARED_MEMORY_KEY,MAX_CLIENTS*sizeof(struct balance_record),IPC_CREAT|0666);
	if(globl_shmID==-1) perror("Error in shmget !\n");

	globl_shm_ptr = shmat(globl_shmID,NULL,0);
	globl_shm_end_record = globl_shm_ptr; // initially NO client record

	initializeAllSubSemaphoreValues(num_ATMs);

	for(i=0;i<num_ATMs;i++)
	{
		int index,KEY; // the same KEY will be used for both the ATM - Client Message Queue as well as the shared memory of the ATM process

		int pid = fork();
		if(pid == 0)
			{			
				// ATM (forked child) process
				index = getpid() - getppid();
				KEY = 10*index;

				char buf[10];
				sprintf(buf,"%d",KEY);

				//int retv = execlp("atm.c","./atm",buf,NULL);
				int retv = execlp("./atm","./atm",buf,NULL);	
				if(retv == -1) {perror("Error in execlp ! \n"); exit(1);}
			}
		else
		{
			// master(parent) process
			index = pid - getpid();
			KEY = 10*index;

			appendToLocatorFile(index,KEY,index-1,KEY);
			
		}

		//sleep(1);	// sleep for 1 second before generating another process
	}

	while(1)
	{
		int pid;
		int atm_pid;

		struct mssg buffer;
		struct msqid_ds qstat;

		msgrcv(mssgQ_ID,&buffer,sizeof(buffer),getpid(),0);
		msgctl(mssgQ_ID,IPC_STAT,&qstat);

		printf("Master Process received message %s from ATM%d\n\n",buffer.mtext,qstat.msg_lspid-getpid());

		if(sscanf(buffer.mtext,"CHCK_ACCOUNT %d",&pid)==1)
			checkClientAccount(pid);
		else if(strcmp(buffer.mtext,"GLOBAL_CONSISTENCY_CHECK_REQUEST")==0)
		{
			performGlobalConsistencyCheck();

			buffer.mtype=qstat.msg_lspid;
			strcpy(buffer.mtext,"GLOBAL CONSISTENCY CHECK COMPLETION CONFIRMATION ");
			msgsnd(mssgQ_ID,&buffer,sizeof(buffer),0);

		}
		else printf("Invalid Message !\n\n");

	}

	wrapup();
}
コード例 #16
0
/* xexit - get out of xlisp */
LVAL xexit()
{
    xllastarg();
    wrapup();
}
コード例 #17
0
ファイル: testcase.cpp プロジェクト: vit2000005/happy_trader
//-------------------------------------------------------------
void TestCase::run (void)
{
	// Reset cancel flag
	cancel_m = false;

	// Inform the monitor
	TestMonitor::enterTestSection( name() );

	// Log memory action
	TestMonitor::setAllocationRecording(true);

	// Setup test
	setup();

	// Stop logging memory action
	TestMonitor::setAllocationRecording(false);

	// Run all those test functions
	for( list<TestFunction>::const_iterator test = testFuns_m.begin();
		test != testFuns_m.end(); ++test ) {

		// Inform the monitor
		TestMonitor::enterTestSection( test->name_m, false );

		// Log memory action
		TestMonitor::setAllocationRecording(true);

		// Run the test
		try {
			(*test->testFunction_m)();
		}
		catch( Testframe::Exception &x ) {
			TestMonitor::recordProblem( x.type().c_str(), x.message().c_str(), "n/a", -1 );
		}
		catch( ... ) {
			TestMonitor::recordProblem( "Exception", "n/a", "n/a", -1 );
		}

		// Stop logging memory action
		TestMonitor::setAllocationRecording(false);

		// Inform the monitor
		TestMonitor::leaveTestSection();

		// Cancel?
		if( cancel_m )
			break;
	}

	// Log memory action
	TestMonitor::setAllocationRecording(true);

	// Wrapup test
	wrapup();

	// Stop logging memory action
	TestMonitor::setAllocationRecording(false);

	// Inform the monitor
	TestMonitor::leaveTestSection();
}
コード例 #18
0
void
signal_hangup(int signo __attribute__ ((__unused__)))
{
	wrapup(1);
}
コード例 #19
0
void
selsub(int argc, char *argv[])
{
	char ans1[100], *cp;
	static char ans2[30];
	static char subname[20];

	if (argc > 1 && argv[1][0] == '-') {
		direct = argv[1] + 1;
		argc--;
		argv++;
	}
	chknam(direct);
	if (chdir(direct) != 0) {
		fprintf(stderr, "can't cd to %s\n", direct);
		exit(1);
	}
	sname = argc > 1 ? argv[1] : 0;
	if (argc > 2)
		strlcpy(level = ans2, argv[2], sizeof ans2);
	else
		level = 0;
	if (argc > 3 )
		speed = atoi(argv[3]);
	if (!sname) {
		printf("These are the available courses:\n");
		list("Linfo");
		printf("If you want more information about the courses,\n");
		printf("or if you have never used 'learn' before,\n");
		printf("type 'return'; otherwise type the name of\n");
		printf("the course you want, followed by 'return'.\n");
		fflush(stdout);
		if (fgets(sname = subname, sizeof subname, stdin) == NULL)
			errx(1, "could not read input");
		trim(sname);
		if (sname[0] == '\0') {
			list("Xinfo");
			do {
				printf("\nWhich subject?  ");
				fflush(stdout);
				if (fgets(sname = subname, sizeof subname,
				    stdin) == NULL)
					errx(1, "could not read input");
				trim(sname);
			} while (sname[0] == '\0');
		}
	}
	chknam(sname);
	if (!level) {
		printf("If you were in the middle of this subject\n");
		printf("and want to start where you left off, type\n");
		printf("the last lesson number the computer printed.\n");
		printf("To start at the beginning, just hit return.\n");
		fflush(stdout);
		if (fgets(ans2, sizeof ans2, stdin) == NULL)
			errx(1, "could not read input");
		trim(ans2);
		if (ans2[0] == 0)
			strlcpy(ans2, "0", sizeof ans2);
		for (cp = ans2; *cp; cp++) {
			if (*cp == '(' || *cp == ' ')
				*cp = 0;
		}
		level = ans2;
	}

	/* make new directory for user to play in */
	if ((playdir = mkdtemp(strdup("/tmp/plXXXXXX"))) == NULL ||
	     chdir(playdir) < 0) {
		fprintf(stderr, "Couldn't create playpen directory %s.\n",
		    playdir);
		fprintf(stderr, "Bye.\n");
		exit(1);
	}

	/*
	 * after this point, we have a working directory.
	 * have to call wrapup to clean up
	 */
	snprintf(ans1, sizeof ans1, "%s/%s/Init", direct, sname);
	if (access(ans1, R_OK) == 0) {
		snprintf(ans1, sizeof ans1, "%s/%s/Init %s",
		    direct, sname, level);
		if (system(ans1) != 0) {
			printf("Leaving learn.\n");
			wrapup(1);
		}
	}
	if (level[0] == '-')	/* no lesson names start with - */
		ask = 1;
	start(level);
}
コード例 #20
0
ファイル: eval.c プロジェクト: syntheticpp/cpptex
void tex::main_control()
	{
	if (every_job != null)
		begin_token_list(every_job, EVERY_JOB_TEXT);
	
	big_switch:
	get_x_token();

   reswitch:
	if (tracing_commands > 0)
		show_cur_cmd_chr();
	
	switch(abs(mode) + cur_cmd) {
		hmode(LETTER):
		hmode(OTHER_CHAR):
		hmode(CHAR_GIVEN):
			goto main_loop;
		
		hmode(CHAR_NUM):
			scan_char_num();
		   cur_chr = cur_val;
		   goto main_loop;
		
		hmode(NO_BOUNDARY):
			get_x_token();
		   if (cur_cmd == LETTER || cur_cmd == OTHER_CHAR
				 || cur_cmd == CHAR_GIVEN || cur_cmd == CHAR_NUM) {
				cancel_boundary = TRUE;
				}
			goto reswitch;

		hmode(SPACER):
			if (space_factor == 1000) {
				goto append_normal_space;
				} 
			else {
				app_space();
				}
		   break;
	
	hmode(EX_SPACE):
	mmode(EX_SPACE):
		goto append_normal_space;
	
	any_mode(RELAX):
	vmode(SPACER):
	mmode(SPACER):
	mmode(NO_BOUNDARY):
		break;
	
	any_mode(IGNORE_SPACES):
		get_nbx_token();
		goto reswitch;

	vmode(STOP):
		if (its_all_over())
			return;
		break;

	any_mode(LAST_ITEM):
	any_mode(MAC_PARAM):
	non_math(EQ_NO):
	vmode(VMOVE):
	hmode(HMOVE):
	mmode(HMOVE):
	vmode(VADJUST):
	vmode(ITAL_CORR):
		report_illegal_case();
		break;

	non_math(SUP_MARK):
	non_math(SUB_MARK):
	non_math(MATH_CHAR_NUM):
	non_math(MATH_GIVEN):
	non_math(MATH_COMP):
	non_math(DELIM_NUM):
	non_math(LEFT_RIGHT):
	non_math(ABOVE):
	non_math(RADICAL):
	non_math(MATH_STYLE):
	non_math(MATH_CHOICE):
	non_math(VCENTER):
	non_math(NON_SCRIPT):
	non_math(MKERN):
	non_math(LIMIT_SWITCH):
	non_math(MSKIP):
	non_math(MATH_ACCENT):
	mmode(ENDV):
	mmode(PAR_END):
	mmode(STOP):
	mmode(VSKIP):
	mmode(UN_VBOX):
	mmode(VALIGN):
	mmode(HRULE):
		insert_dollar_sign();
		break;
	
	vmode(HRULE):
	hmode(VRULE):
	mmode(VRULE):
		tail_append(scan_rule_spec());
		if (abs(mode) == VMODE)
			prev_depth = IGNORE_DEPTH;
		else if (abs(mode) == HMODE)
			space_factor = 1000;
		break;
	
	vmode(VSKIP):
	hmode(HSKIP):
	mmode(HSKIP):
	mmode(MSKIP):
		append_glue();
		break;
	
	any_mode(KERN):
	mmode(MKERN):
		append_kern();
		break;
	
	non_math(LEFT_BRACE):
		new_save_level(SIMPLE_GROUP);
		break;

	any_mode(BEGIN_GROUP):
		new_save_level(SEMI_SIMPLE_GROUP);
		break;

	any_mode(END_GROUP):
		if (cur_group == SEMI_SIMPLE_GROUP) {
			unsave();
		} else {
			off_save();
		}
		break;
	
	any_mode(RIGHT_BRACE):
		handle_right_brace();
		break;

	vmode(HMOVE):
	hmode(VMOVE):
	mmode(VMOVE): {
		int	t;

		t = cur_chr;
		scan_normal_dimen();
		if (t == 0) {
			scan_box(cur_val);
		} else {
			scan_box(-cur_val);
		}
		break;
	}
	any_mode(LEADER_SHIP):
		scan_box(LEADER_FLAG + cur_chr - A_LEADERS);
		break;
	
	any_mode(MAKE_BOX):
		begin_box(0);
		break;

	vmode(START_PAR):
		new_graf(cur_chr > 0);
		break;
	
	vmode(LETTER):
	vmode(OTHER_CHAR):
	vmode(CHAR_NUM):
	vmode(CHAR_GIVEN):
	vmode(MATH_SHIFT):
	vmode(UN_HBOX):
	vmode(VRULE):
	vmode(ACCENT):
	vmode(DISCRETIONARY):
	vmode(HSKIP):
	vmode(VALIGN):
	vmode(EX_SPACE):
	vmode(NO_BOUNDARY):
		back_input();
		new_graf(TRUE);
		break;
	
	hmode(START_PAR):
	mmode(START_PAR):
		indent_in_hmode();
		break;
	
	vmode(PAR_END):
		normal_paragraph();
		if (mode > 0)
			build_page();
		break;

	hmode(PAR_END):
		if (align_state < 0)
			off_save();
		end_graf();
		if (mode == VMODE)	
			build_page();
		break;
	
	hmode(STOP):
	hmode(VSKIP):
	hmode(HRULE):
	hmode(UN_VBOX):
	hmode(HALIGN):
		head_for_vmode();
		break;
	
	any_mode(INSERT):
	hmode(VADJUST):
	mmode(VADJUST):
		begin_insert_or_adjust();
		break;
	
	any_mode(MARK):
		make_mark();
		break;
	
	any_mode(BREAK_PENALTY):
		append_penalty();
		break;
	
	any_mode(REMOVE_ITEM):
		delete_last();
		break;
	
	vmode(UN_VBOX):
	hmode(UN_HBOX):
	mmode(UN_HBOX):
		unpackage();
		break;
	
	hmode(ITAL_CORR):
		append_italic_correction();
		break;
	
	mmode(ITAL_CORR):
		tail_append(new_kern(0));
		break;

	hmode(DISCRETIONARY):
	mmode(DISCRETIONARY):
		append_discretionary();
		break;
	
	hmode(ACCENT):
		make_accent();
		break;
	
	any_mode(CAR_RET):
	any_mode(TAB_MARK):
		align_error();
		break;

	any_mode(NO_ALIGN):
		no_align_error();
		break;
	
	any_mode(OMIT):
		omit_error();
		break;

	vmode(HALIGN):
	hmode(VALIGN):
		init_align();
		break;
	
	mmode(HALIGN):
		if (privileged()) {
			if (cur_group == MATH_SHIFT_GROUP) {
				init_align();
			} else {
				off_save();
			}
		}
		break;

	vmode(ENDV):
	hmode(ENDV):
		do_endv();
		break;
	
	any_mode(END_CS_NAME):
		cs_error();
		break;

	hmode(MATH_SHIFT):
		init_math();
		break;
	
	mmode(EQ_NO):
		if (privileged()) {
			if (cur_group == MATH_SHIFT_GROUP) {
				start_eq_no();
			} else {
				off_save();
			}
		}
		break;
	
	mmode(LEFT_BRACE):
		tail_append(new_noad());
		back_input();
		scan_math(nucleus(tail));
		break;

	mmode(LETTER):
	mmode(OTHER_CHAR):
	mmode(CHAR_GIVEN):
		if (cur_chr < 256)
			set_math_char(math_code(cur_chr));
		else set_math_char(cur_chr);
		break;
	
	mmode(CHAR_NUM):
		scan_char_num();
		cur_chr = cur_val;
		if (cur_chr < 256)
			set_math_char(math_code(cur_chr));
		else set_math_char(cur_chr);
		break;
	
	mmode(MATH_CHAR_NUM):
		scan_fifteen_bit_int();
		set_math_char(cur_val);
		break;
	
	mmode(MATH_GIVEN):
		set_math_char(cur_chr);
		break;

	mmode(DELIM_NUM):
		scan_twenty_seven_bit_int();
		set_math_char(cur_val / 010000);
		break;
	
	mmode(MATH_COMP):
		tail_append(new_noad());
		type(tail) = cur_chr;
		scan_math(nucleus(tail));
		break;
	
	mmode(LIMIT_SWITCH):
		math_limit_switch();
		break;

	mmode(RADICAL):
		math_radical();
		break;

	mmode(ACCENT):
	mmode(MATH_ACCENT):
		math_ac();
		break;

	mmode(VCENTER):
		scan_spec(VCENTER_GROUP, FALSE);
		normal_paragraph();
		push_nest();
		mode = -VMODE;
		prev_depth = IGNORE_DEPTH;
		if (every_vbox != null)
			begin_token_list(every_vbox, EVERY_VBOX_TEXT);
		break;
	
	mmode(MATH_STYLE):
		tail_append(new_style(cur_chr));
		break;
	
	mmode(NON_SCRIPT):
		tail_append(new_glue(zero_glue));
		subtype(tail) = COND_MATH_GLUE;
		break;
	
	mmode(MATH_CHOICE):
		append_choices();
		break;

	mmode(SUB_MARK):
	mmode(SUP_MARK):
		sub_sup();
		break;
	
	mmode(ABOVE):
		math_fraction();
		break;
	
	mmode(LEFT_RIGHT):
		math_left_right();
		break;

	mmode(MATH_SHIFT):
		if (cur_group == MATH_SHIFT_GROUP) {
			after_math();
		} else {
			off_save();
		}
		break;

	any_mode(AFTER_ASSIGNMENT):
		get_token();
		after_token = cur_tok;
		break;
	
	any_mode(AFTER_GROUP):
		get_token();
		save_for_after(cur_tok);
		break;

	any_mode(IN_STREAM):
		clopen_stream();
		break;

	any_mode(MESSAGE):
		issue_message();
		break;
	
	any_mode(CASE_SHIFT):
		shift_case();
		break;
	
	any_mode(XRAY):
		show_whatever();
		break;
	
	any_mode(EXTENSION):
		do_extension();
		break;
	
	default:
		prefixed_command();
		break;
	}
	goto big_switch;

#define adjust_space_factor() \
{ \
	main_s = sf_code(cur_chr); \
	if (main_s == 1000) { \
		space_factor = 1000; \
	} else if (main_s < 1000) { \
		if (main_s > 0) { \
			space_factor = main_s; \
		} \
	} else if (space_factor < 1000) { \
		space_factor = 1000; \
	} else { \
		space_factor = main_s; \
	} \
}
		
main_loop:
	adjust_space_factor();
	main_f = cur_font;
	bchar = font_bchar(main_f);
	false_bchar = font_false_bchar(main_f);
	if (mode > 0 && language != clang)
		fix_language();
	fast_new_avail(lig_stack);
	font(lig_stack) = main_f;
	character(lig_stack) = cur_l = cur_chr;
	cur_q = tail;
	if (cancel_boundary) {
		cancel_boundary = FALSE;
		main_k = NON_ADDRESS;
	} else {
		main_k = bchar_label(main_f);
	}
	if (main_k == NON_ADDRESS)
		goto main_loop_move_2;
	cur_r = cur_l;
	cur_l = NON_CHAR;
	goto main_lig_loop_1;

#define pack_lig(RT_HIT) \
{ \
	main_p = new_ligature(main_f, cur_l, link(cur_q)); \
	if (lft_hit) { \
		subtype(main_p) = 2; \
		lft_hit = FALSE; \
	} \
	if (RT_HIT && lig_stack == null) { \
		incr(subtype(main_p)); \
		rt_hit = FALSE; \
	} \
	tail = link(cur_q) = main_p; \
	ligature_present = FALSE; \
}

#define wrapup(RT_HIT) \
{ \
	if (cur_l < NON_CHAR) { \
		if (character(tail) == hyphen_char(main_f) \
		&& link(cur_q) != null) \
			ins_disc = TRUE; \
		if (ligature_present) \
			pack_lig(RT_HIT); \
		if (ins_disc) { \
			ins_disc = FALSE; \
			if (mode > 0) \
				tail_append(new_disc()); \
		} \
	} \
}

main_loop_wrapup:
	wrapup(rt_hit);

main_loop_move:
	if (lig_stack == null)
		goto reswitch;
	cur_q = tail;
	cur_l = cur_r;

main_loop_move_1:
	if (!is_char_node(lig_stack))
		goto main_loop_move_lig;

main_loop_move_2:
	if (cur_chr < font_bc(main_f) || cur_chr > font_ec(main_f)) {
		char_warning(main_f, cur_chr);
		free_avail(lig_stack);
		goto big_switch;
	}
	main_i = char_info(main_f, cur_l);
	if (!char_exists(main_i)) {
		char_warning(main_f, cur_chr);
		free_avail(lig_stack);
		goto big_switch;
	}
	tail_append(lig_stack);

main_loop_lookahead:
	get_next();
	if (cur_cmd == LETTER
	|| cur_cmd == OTHER_CHAR
	|| cur_cmd == CHAR_GIVEN) {
		goto main_loop_lookahead_1;
	}
	x_token();
	if (cur_cmd == LETTER
	|| cur_cmd == OTHER_CHAR
	|| cur_cmd == CHAR_GIVEN) {
		goto main_loop_lookahead_1;
	}
	if (cur_cmd == CHAR_NUM) {
		scan_char_num();
		cur_chr = cur_val;
		goto main_loop_lookahead_1;
	}
	if (cur_cmd == NO_BOUNDARY) {
		bchar = NON_CHAR;
	}
	cur_r = bchar;
	lig_stack = null;
	goto main_lig_loop;

main_loop_lookahead_1:
	adjust_space_factor();
	fast_new_avail(lig_stack);
	font(lig_stack) = main_f;
	character(lig_stack) = cur_r = cur_chr;
	if (cur_r == false_bchar) {
		cur_r = NON_CHAR;
	}

main_lig_loop:
	if (char_tag(main_i) != LIG_TAG) {
		goto main_loop_wrapup;
	}
	main_k = lig_kern_start(main_f, main_i);
	main_j = *main_k;
	if (skip_byte(main_j) <= STOP_FLAG) {
		goto main_lig_loop_2;
	}
	main_k = lig_kern_restart(main_f, main_j);

main_lig_loop_1:
	main_j = *main_k;

main_lig_loop_2:
	if (next_char(main_j) == cur_r
	&& skip_byte(main_j) <= STOP_FLAG) {
		if (op_byte(main_j) >= KERN_FLAG) {
			wrapup(rt_hit);
			tail_append(new_kern(char_kern(main_f, main_j)));
			goto main_loop_move;
		}
		if (cur_l == NON_CHAR) {
			lft_hit = TRUE;
		} else if (lig_stack == null) {
			rt_hit = TRUE;
		}
		if(interrupted) throw std::logic_error("interrupted");
		switch (op_byte(main_j))
		{
		case 1: case 5:
			cur_l = rem_byte(main_j);
			main_i = char_info(main_f, cur_l);
			ligature_present = TRUE;
			break;
			
		case 2: case 6:
			cur_r = rem_byte(main_j);
			if (lig_stack == null) {
				lig_stack = new_lig_item(cur_r);
				bchar = NON_CHAR;
			} else if (is_char_node(lig_stack)) {
				main_p = lig_stack;
				lig_stack = new_lig_item(cur_r);
				lig_ptr(lig_stack) = main_p;
			} else {
				character(lig_stack) = cur_r;
			}
			break;

		case 3:
			cur_r = rem_byte(main_j);
			main_p = lig_stack;
			lig_stack = new_lig_item(cur_r);
			link(lig_stack) = main_p;
			break;

		case 7: case 11:
			wrapup(FALSE);
			cur_q = tail;
			cur_l = rem_byte(main_j);
			main_i = char_info(main_f, cur_l);
			ligature_present = TRUE;
			break;

		default:
			cur_l = rem_byte(main_j);
			ligature_present = TRUE;
			if (lig_stack == null) {
				goto main_loop_wrapup;
			} else {
				goto main_loop_move_1;
			}
			break;
		}
		if (op_byte(main_j) > 4 && op_byte(main_j) != 7)
			goto main_loop_wrapup;
		if (cur_l < NON_CHAR)
			goto main_lig_loop;
		main_k = bchar_label(main_f);
		goto main_lig_loop_1;
	}
	if (skip_byte(main_j) == 0) {
		incr(main_k);
	} else {
		if (skip_byte(main_j) >= STOP_FLAG)
			goto main_loop_wrapup;
		main_k += skip_byte(main_j) + 1;
	}
	goto main_lig_loop_1;

main_loop_move_lig:
	main_p = lig_ptr(lig_stack);
	if (main_p != null) {
		tail_append(main_p);
	}
	main_t = lig_stack;
	lig_stack = link(main_t);
	free_node(main_t, SMALL_NODE_SIZE);
	main_i = char_info(main_f, cur_l);
	ligature_present = TRUE;
	if (lig_stack == null) {
		if (main_p != null) {
			goto main_loop_lookahead;
		} else {
			cur_r = bchar;
		}
	} else {
		cur_r = character(lig_stack);
	}
	goto main_lig_loop;

append_normal_space:
	if (space_skip == zero_glue) {
		main_p = font_glue(cur_font);
		if (main_p == null)
			main_p = find_font_glue(cur_font);
		main_t = new_glue(main_p);
	} else {
		main_t = new_param_glue(SPACE_SKIP_CODE);
	}
	tail_append(main_t);
	goto big_switch;
}
コード例 #21
0
ファイル: maclib.c プロジェクト: jphartmann/CMS-TXTLIB
int
main(int argc, char ** argv)
{
   char * fn;
   int ix;

   if (3 > argc)
      return fprintf(stderr, "Specify library file name and copy file name(s).\n"), 1;
   if (openout(argv[1])) return 16;

   if (getdir(cards * 80)) return 20;

   for (ix = 2; argv[ix]; ix++)
   {
      char * dot;
      char * slash;
      char * name;
      int namelen;
      int ismacro = 1;                /* Assume file is macro        */
      char * s;

      fn = argv[ix];
      f = fopen(fn, "r");
      if (!f) return fprintf(stderr, "Cannot open %s:  %s\n", fn, strerror(errno)), 16;

      slash = strrchr(fn, '/');
      name = slash ? slash + 1 : fn;
      namelen = strlen(name);

      dot = strrchr(name, '.');
      if (dot)
      {
         namelen = dot - name;
         if (!strcmp(dot + 1, "copy")) ismacro = 0;
      }

      s = gline();
      if (!s) continue;
      if (!ismacro && memcmp(s, "*COPY ", 6)) ismacro = 1;   /* Not stacked copy */
      if (ismacro)
      {
         loadname(name, namelen);
         if (doline(line)) return 20;
      }
      else if (newmember(s)) return 20;
      for (;;)
      {
         s = gline();
         if (!s) break;
         if (!ismacro && !memcmp(s, "*COPY ", 6))
         {
            if (eom()) return 20;
            if (newmember(s)) return 20;
            continue;
         }
         if (doline(line)) return 20;
      }
      if (eom()) return 20;
   }
   if (wrapup(dirs, dir)) return 16;
   printf("%s %d files %d members.\n",
      fno, ix - 2, members);
   return 0;
}