Esempio n. 1
0
void
main(int argc, char *av[])
{
	int i;
	char *f;

	argv = av;
	Binit(&bout, 1, OWRITE);
	ARGBEGIN{
	case 'w':
		wordflag = YES;
		break;
	case '_':
		wordflag = YES;
		underscoreflag = YES;
		break;
	case 'm':
		msflag = YES;
		if(f = ARGF())
			switch(*f)
			{
			case 'm':	mac = MM; break;
			case 's':	mac = MS; break;
			case 'l':	disp = 1; break;
			default:	usage();
			}
		else
			usage();
		break;
	case 'i':
		iflag = YES;
		break;
	default:
		usage();
	}ARGEND
	if(*argv)
		infile = opn(*argv++);
	else{
		infile = malloc(sizeof(Biobuf));
		Binit(infile, 0, OREAD);
	}
	files[0] = infile;
	filesp = &files[0];

	for(i='a'; i<='z' ; ++i)
		chars[i] = LETTER;
	for(i='A'; i<='Z'; ++i)
		chars[i] = LETTER;
	for(i='0'; i<='9'; ++i)
		chars[i] = DIGIT;
	chars['\''] = APOS;
	chars['&'] = APOS;
	chars['\b'] = APOS;
	chars['.'] = PUNCT;
	chars[','] = PUNCT;
	chars[';'] = PUNCT;
	chars['?'] = PUNCT;
	chars[':'] = PUNCT;
	work();
}
Esempio n. 2
0
 OpenSaveBox& onOpenAndSelectFile(std::function<void(const nana::string& file)> opn)
 {
     add_validated([this, opn](/*nana::combox&cb*/)
                 { 
                   if( this->UserSelected() )   
                       opn ( nana::charset ( this->FileName() )) ; 
                   return true;
                 } ); 
     
     return *this;
 }
Esempio n. 3
0
int
eof(void)
{
	if(Bfildes(&(infile->Biobufhdr)) != 0)
		Bterm(&(infile->Biobufhdr));
	if(filesp > files)
		infile = *--filesp;
	else
	if(*argv)
		infile = opn(*argv++);
	else
		exits(0);
	return(C);
}
Esempio n. 4
0
ex_immed()
{
	int i, *ip, j;
	struct item *p;
	struct nlist *n;
	double f;
	char fname[64];						/* Array for filename */
	char *cp, *vfname();

	i = *pcp++;
	switch(i) {

	default:
		error("immed B");

	case SCRIPT:
		if(protofile > 0) close(protofile);
		protofile = 0;
		cp = vfname(fname);
		if(equal(cp, "off")) return;
		if((protofile = open(cp, 1)) > 0){
			lseek(protofile, 0L, 2);	/* append to existing file */
			printf("[appending]\n");
		}
		else {
			/*
			 * create new file
			 */
			protofile = opn(cp, 0644);
			printf("[new file]\n");
		}
		write(protofile, "\t)script on\n", 12);
		return;

	case DEBUG:
		debug = ~debug;
		return;

	case MEMORY:
		memoryCheck();
		return;

	case DIGITS:
		i = topfix();
		if(i < 1 || i > 20) error("digits D");
		printf("was %d\n",thread.digits);
		thread.digits = i;
		return;

	case TRACE:
		funtrace = 1;
		return;

	case UNTRACE:
		funtrace = 0;
		return;

	case WRITE:
		funwrite(0);
		return;

	case DEL:
	case EDITF:
		sp[0] = sp[-1];		/*	duplicate top of stack  */
		sp++;
		funwrite(scr_file);
		funedit(scr_file, i);
		unlink(scr_file);
		return;


	case EDIT:
		funedit(0, i);
		return;

	case FUZZ:
		i = topfix();
		if(i <= 0) {
			thread.fuzz = 0.;
			return;
		}
		f = i;
		thread.fuzz = exp(-f*2.3025851);
		return;

	case ORIGIN:
		printf("was %d\n",thread.iorg);
		thread.iorg = topfix();
		return;

	case WIDTH:
		i = topfix();
		if(i < 1) error("width D");
		printf("was %d\n",thread.width);
		thread.width = i;
		return;

	case READ:
		funread(0);
		return;

	case ERASE:
		p = sp[-1];
		sp--;
		erase(p);
		return;

	case CONTIN:
		i = opn("continue", 0644);
		wssave(i, 0);
		printf(" continue");

	case OFF:
		term(0);

	case VARS:
		for(n=nlist; n->namep; n++) {
			if(n->itemp && n->use == DA && n->namep[0] != 'L') {
				if(column+8 >= thread.width) printf("\n\t");
				printf(n->namep);
				putchar('\t');
			}
		}
		putchar('\n');
		return;

	case FNS:
		for(n=nlist; n->namep; n++) {
			if(n->use == DF || n->use == MF || n->use == NF) {
				if(column+8 >= thread.width) printf("\n\t");
				printf(n->namep);
				putchar('\t');
			}
		}
		putchar('\n');
		return;

	case CODE:
		n = (struct nlist *)sp[-1];
		sp--;
		switch(n->use){
		default:
			error("not a fn");
		case NF:
		case MF:
		case DF:
			if(n->itemp == 0) funcomp(n);
			ip = (int *)n->itemp;
			for(i=0; i <= *ip; i++){
				printf(" [%d] ", i);
				dump(ip[i+1], 0);
			}
			putchar('\n');
		}
		return;

	case RESET:
		while(gsip) ex_ibr0();
		longjmp(reset_env, 0);

	case SICOM:
		tback(1);
		return;

	case CLEAR:
		clear();
		printf("clear ws\n");
		goto warp1;				/* four lines down, or so... */

	case LOAD:
	case PLOAD:
		j = opn(vfname(fname), 0);
		clear();
		if (i == LOAD) wsload(j, 0);
		if (i == PLOAD) wsload(j, 1);
		printf(" %s\n", fname);
		evLlx();				/* possible latent expr evaluation */
warp1:
		/*
		 * this garbage is necessary because clear()
		 * does a brk(&end), and the normal return & cleanup
		 * procedures are guaranteed to fail (miserably).
		 *		--jjb 1/78
		 */
		sp = stack;
		longjmp(reset_env, 0);

	case LIB:
		listdir();
		return;

	case COPY:
		if(gsip) error("si damage -- type ')reset'");
		wsload(opn(vfname(fname),0), 0);
		printf(" copy %s\n", fname);
		return;

	case DROPC:
		cp = vfname(fname);
		if(unlink(cp) == -1) printf("[can't remove %s]\n", cp);
		return;

	case SAVE:
	case PSAVE:
		j = opn(vfname(fname), 0644);
		if (i == SAVE) wssave(j, 0);
		if (i == PSAVE) wssave(j, 1);
		printf(" saved %s\n", fname);
		return;

	case VSAVE:
		i = opn(vfname(fname), 0644);
		vsave(i);
		putchar('\n');
		return;

	case SHELL:
		ex_shell();
		return;

	case LIST:
		ex_list();
		return;

	case PRWS:
		ex_prws();
		return;

	}
}
Esempio n. 5
0
int main()
   {
   int row;         /* row# in the picture */
   int col;         /* column# in the picture */
   int txtindx;     /* index into the text */
   int fntofst;     /* offset into the 12x24 font */
   int picofst;     /* offset into the picture */
   int fntlen;      /* the total length of the font (12*24*94) */
   int txtlen;      /* the total length of the text */
   int pfxlen;      /* the length of the PPM prefix */
   int picrowsz;    /* the number of pixels*3 in a PPM row */
   int piccolsz;    /* the number of rows in the PPM */
   int picsz;       /* the number of pixels*3 in the PPM */
   int hndl;        /* the font file handle */
   char *fnt;       /* pointer for the font */
   char *fntp,*fntq;       /* relative pointers for the font */
   char *p,*q;       /* relative pointers for the text */
   char *txt;        /* pointer for the font */
   char *txtp;       /* relative pointer for the text */
   /* format for the PPM prefix: */
   /* P6 */
   /* white space */
   /* row size in pixels */
   /* white space */
   /* column size in pixels */
   /* white space */
   /* colors depth = 255 */
   /* white space or new line */
   char pfx[64];     /* PPM prefix */
   unsigned char *pic;      /* pointer to the PPM */
   unsigned char *picp;     /* relative pointer for the PPM */
   unsigned char *picq;     /* relative pointer for the PPM */
   /* the erandu random number generator uses the IBM */
   /* RANDU algorithm plus the Bays-Durham shuffle */
   rufmt *ru;               /* erandu structure */
   ru = (rufmt *) eranduinit();    /* initialize the erandu generator */
   /*******************************************/
   /* allocate the font space                 */
   /*******************************************/
   fnt = (char *) malloc(MAXLEN);
   if (fnt == NULL)
      {
      fprintf(stderr,"main: out of memory "
         "allocating fnt\n");
      exit(1);
      } /* out of memory */
   /*******************************************/
   /* allocate the text space                 */
   /*******************************************/
   txt = (char *) malloc(TXTLEN);
   if (txt == NULL)
      {
      fprintf(stderr,"main: out of memory "
         "allocating txt\n");
      exit(1);
      } /* out of memory */
   /*********************************************/
   /* open the font file                        */
   /* read the font into memory                 */
   /* the font is an ASCII font of asterisks    */
   /* the asterisks are translated into pixels  */
   /*********************************************/
   hndl = opn("font.txt");
   fntlen = 0;
   fntp = (char *) fnt;
   fntq = (char *) fnt + MAXLEN;
   while (fntp < fntq)
      {
      int ch;
      ch = gethndl(hndl);
      if (ch == EOF) break;       /* end of file */
      if (ch == '\n') continue;   /* bypass end of line */
      *fntp++ = (char) ch;
      fntlen++;
      } /* for each pixel in font */
   cls(hndl);         /* close the font file */
   /* re-allocate the font space */
   fnt = (char *) realloc(fnt,fntlen);
   /* display the font, for debugging */
   /************ shwfnt(fnt,fntlen); *******************/
   /*********************************************/
   /* read the captcha text from stdin          */
   /* bypass end of line                        */
   /* allow only printable characters           */
   /* ASCII space to '~'                        */
   /*********************************************/
   txtlen = 0;
   p = (char *) txt;
   q = (char *) txt + TXTLEN - 1;
   while (p < q)
      {
      int ch;
      ch = getbyte();
      if (ch == EOF) break;
      if (ch == '\n') break;
      if (ch < ' ' || ch > '~')
         {
	 fprintf(stderr,"main: invalid text\n");
	 fprintf(stderr,"char %02x   char# %d\n",
	    ch, txtlen+1);
	 exit(1);
	 } /* invalid txt char */
      *p++ = (char) ch;
      txtlen++;
      } /* for each char in text */
   *p = '\0';        /* terminate the text string */
   /* allow three pixels between each character */
   /* the font is 12x24 */
   /* txtlen * 15 because of 3 dots in between */
   /* allow variable margin space for rows and columns */
   /* the PPM has a partially random size */
   /* each pixel in the PPM contains three RGB bytes */
   picrowsz = 3 * ((txtlen*15) + 80 + (eranduint(ru,40)));
   piccolsz = 24 + 40 + (eranduint(ru,40));
   picsz = picrowsz * piccolsz;    /* total PPM size */
   /* write the dimensions of the PPM to stderr */
   fprintf(stderr,"txtlen %d picrowsz %d piccolsz %d\n",
      txtlen, picrowsz, piccolsz);
   /*******************************************/
   /* allocate the PPM space                  */
   /*******************************************/
   pic = (unsigned char *) malloc(picsz + 1024);
   if (pic == NULL)
      {
      fprintf(stderr,"main: out of memory "
         "allocating pic\n");
      exit(1);
      } /* out of memory */
   /*******************************************/
   /* write the PPM prefix to stdout          */
   /*******************************************/
   sprintf(pfx,"P6 %d %d 255\n",
      picrowsz/3, piccolsz);
   pfxlen = strlen(pfx);
   putblk((unsigned char *) pfx,pfxlen);
   /*******************************************/
   /* generate the random PPM background      */
   /* in 16 million color RGB pixels          */
   /*******************************************/
   picp = (unsigned char *) pic;
   picq = (unsigned char *) pic + picsz;
   while (picp < picq)
      {
      int i;
      i = erandupwr(ru,8);
      *picp++ = (unsigned char) i;
      } /* for each rgb in pixel */
   /*******************************************/
   /* overlay the random background with      */
   /* partially random colored text           */
   /* the text is darker than the background  */
   /*******************************************/
   txtindx = 0;
   /* loop for each character in text */
   while (txtindx < txtlen)
      {
      int ch;
      txtp = (char *) txt + txtindx;
      ch = *txtp;
      /* space is random background */
      if (ch == ' ')
         {
	 txtindx++;
	 continue;
	 } /* bypass space */
      /* point to the font for the character ch */
      fntofst = (ch - '!') * (12 * 24);
      row = 0;
      /* inner loop for each row in font */
      while (row < 24)
         {
         fntp = (char *) fnt + fntofst + (row*12);
	 col = 0;
         /* inner loop for each column in font */
	 while (col < 12)
	    {
	    /* txtindx*15 to allow 3 dots between characters */
	    /* 20 pixel margin at top of PPM */
            picofst = ((row+20) * picrowsz) + (txtindx*15*3);
	    if (*fntp == '*')
	       {
	       picp = (unsigned char *) pic + picofst + (col*3) + 120;
	       *picp++ = erandupwr(ru,6);     /* 0-63 color depth */
	       *picp++ = erandupwr(ru,6);     /* 0-63 color depth */
	       *picp++ = erandupwr(ru,6);     /* 0-63 color depth */
	       } /* if asterisk in font */
	    col++;
	    fntp++;
	    } /* for each column in row */
	 row++;
	 } /* for each row in font */
      txtindx++;
      } /* for each starting column in text */
   /* write the PPM map to stdout */
   putblk(pic,picsz);
   /* free allocated memory in heap */
   free(fnt);
   free(txt);
   free(pic);
   free(ru->state);
   free(ru);
   return(0);
   } /* main */
Esempio n. 6
0
void
comline(void)
{
	long c1, c2;

	while(C==' ' || c=='\t')
		;
comx:
	if((c1=c) == '\n')
		return;
	c2 = C;
	if(c1=='.' && c2!='.')
		inmacro = NO;
	if(msflag && c1 == '['){
		refer(c2);
		return;
	}
	if(c2 == '\n')
		return;
	if(c1 == '\\' && c2 == '\"')
		SKIP;
	else
	if (filesp==files && c1=='E' && c2=='Q')
			eqn();
	else
	if(filesp==files && c1=='T' && (c2=='S' || c2=='C' || c2=='&')) {
		if(msflag)
			stbl(); 
		else
			tbl();
	}
	else
	if(c1=='T' && c2=='E')
		intable = NO;
	else if (!inmacro &&
			((c1 == 'd' && c2 == 'e') ||
		   	 (c1 == 'i' && c2 == 'g') ||
		   	 (c1 == 'a' && c2 == 'm')))
				macro();
	else
	if(c1=='s' && c2=='o') {
		if(iflag)
			SKIP;
		else {
			getfname();
			if(fname[0]) {
				if(infile = opn(fname))
					*++filesp = infile;
				else infile = *filesp;
			}
		}
	}
	else
	if(c1=='n' && c2=='x')
		if(iflag)
			SKIP;
		else {
			getfname();
			if(fname[0] == '\0')
				exits(0);
			if(Bfildes(&(infile->Biobufhdr)) != 0)
				Bterm(&(infile->Biobufhdr));
			infile = *filesp = opn(fname);
		}
	else
	if(c1 == 't' && c2 == 'm')
		SKIP;
	else
	if(c1=='h' && c2=='w')
		SKIP; 
	else
	if(msflag && c1 == 'T' && c2 == 'L') {
		SKIP_TO_COM;
		goto comx; 
	}
	else
	if(msflag && c1=='N' && c2 == 'R')
		SKIP;
	else
	if(msflag && c1 == 'A' && (c2 == 'U' || c2 == 'I')){
		if(mac==MM)SKIP;
		else {
			SKIP_TO_COM;
			goto comx; 
		}
	} else
	if(msflag && c1=='F' && c2=='S') {
		SKIP_TO_COM;
		goto comx; 
	}
	else
	if(msflag && (c1=='S' || c1=='N') && c2=='H') {
		SKIP_TO_COM;
		goto comx; 
	} else
	if(c1 == 'U' && c2 == 'X') {
		if(wordflag)
			Bprint(&(bout.Biobufhdr), "UNIX\n");
		else
			Bprint(&(bout.Biobufhdr), "UNIX ");
	} else
	if(msflag && c1=='O' && c2=='K') {
		SKIP_TO_COM;
		goto comx; 
	} else
	if(msflag && c1=='N' && c2=='D')
		SKIP;
	else
	if(msflag && mac==MM && c1=='H' && (c2==' '||c2=='U'))
		SKIP;
	else
	if(msflag && mac==MM && c2=='L') {
		if(disp || c1=='R')
			sdis('L', 'E');
		else {
			SKIP;
			Bprint(&(bout.Biobufhdr), " .");
		}
	} else
	if(!msflag && c1=='P' && c2=='S') {
		inpic();
	} else
	if(msflag && (c1=='D' || c1=='N' || c1=='K'|| c1=='P') && c2=='S') { 
		sdis(c1, 'E'); 
	} else
	if(msflag && (c1 == 'K' && c2 == 'F')) { 
		sdis(c1,'E'); 
	} else
	if(msflag && c1=='n' && c2=='f')
		sdis('f','i');
	else
	if(msflag && c1=='c' && c2=='e')
		sce();
	else {
		if(c1=='.' && c2=='.') {
			if(msflag) {
				SKIP;
				return;
			}
			while(C == '.')
				;
		}
		inmacro++;
		if(c1 <= 'Z' && msflag)
			regline(YES,ONE);
		else {
			if(wordflag)
				C;
			regline(YES,TWO);
		}
		inmacro--;
	}
}