コード例 #1
0
ファイル: write.c プロジェクト: AhmadTux/DragonFlyBSD
/*
 * wr_fputs - like fputs(), but makes control characters visible and
 *     turns \n into \r\n
 */
static void
wr_fputs(unsigned char *s)
{

#define	PUTC(c)	if (putchar(c) == EOF) err(1, NULL);

	for (; *s != '\0'; ++s) {
		if (*s == '\n') {
			PUTC('\r');
		} else if (((*s & 0x80) && *s < 0xA0) ||
			   /* disable upper controls */
			   (!isprint(*s) && !isspace(*s) &&
			    *s != '\a' && *s != '\b')
			  ) {
			if (*s & 0x80) {
				*s &= ~0x80;
				PUTC('M');
				PUTC('-');
			}
			if (iscntrl(*s)) {
				*s ^= 0x40;
				PUTC('^');
			}
		}
		PUTC(*s);
	}
	return;
#undef PUTC
}
コード例 #2
0
ファイル: HTTPRes.c プロジェクト: BackupTheBerlios/texlive
/*	HTTPMakeResponse
**	----------------
**	Makes a HTTP/1.0-1.1 response header.
*/
PRIVATE int HTTPMakeResponse (HTStream * me, HTRequest * request)
{
    char crlf[3];
    HTRsHd response_mask = HTRequest_rsHd(request);
    *crlf = CR; *(crlf+1) = LF; *(crlf+2) = '\0';

    if (response_mask & HT_S_LOCATION) {		/* @@@ */

    }
    if (response_mask & HT_S_PROXY_AUTH) {		/* @@@ */

    }
    if (response_mask & HT_S_PUBLIC) {			/* @@@ */

    }
    if (response_mask & HT_S_RETRY_AFTER) {		/* @@@ */

    }
    if (response_mask & HT_S_SERVER) {
	PUTS("Server: ");
	PUTS(HTLib_appName());
	PUTC('/');
	PUTS(HTLib_appVersion());
	PUTC(' ');
	PUTS(HTLib_name());
	PUTC('/');
	PUTS(HTLib_version());
	PUTBLOCK(crlf, 2);
    }
    if (response_mask & HT_S_WWW_AUTH) {		/* @@@ */

    }
    HTTRACE(PROT_TRACE, "HTTP........ Generating Response Headers\n");
    return HT_OK;
}
コード例 #3
0
/*
 * Receive a packet.
 */
static int
kgdb_recv(u_char *bp, int maxlen)
{
	u_char *p;
	int c, csum, tmpcsum;
	int len;

	DPRINTF(("kgdb_recv:  "));
	do {
		p = bp;
		csum = len = 0;
		while ((c = GETC()) != KGDB_START)
			DPRINTF(("%c",c));
		DPRINTF(("%c Start ",c));

		while ((c = GETC()) != KGDB_END && len < maxlen) {
			DPRINTF(("%c",c));
			c &= 0x7f;
			csum += c;
			*p++ = c;
			len++;
		}
		csum &= 0xff;
		*p = '\0';
		DPRINTF(("%c End ", c));

		if (len >= maxlen) {
			DPRINTF(("Long- "));
			PUTC(KGDB_BADP);
			continue;
		}
		tmpcsum = csum;

		c = GETC();
		DPRINTF(("%c",c));
		csum -= digit2i(c) * 16;
		c = GETC();
		DPRINTF(("%c",c));
		csum -= digit2i(c);

		if (csum == 0) {
			DPRINTF(("Good+ "));
			PUTC(KGDB_GOODP);
			/* Sequence present? */
			if (bp[2] == ':') {
				DPRINTF(("Seq %c%c ", bp[0], bp[1]));
				PUTC(bp[0]);
				PUTC(bp[1]);
				len -= 3;
				kgdb_copy(bp + 3, bp, len);
			}
			break;
		}
		DPRINTF((" Bad(wanted %x, off by %d)- ", tmpcsum, csum));
		__USE(tmpcsum);
		PUTC(KGDB_BADP);
	} while (1);
	DPRINTF(("kgdb_recv: %s\n", bp));
	return (len);
}
コード例 #4
0
ファイル: leptjson.c プロジェクト: Leungtamir/json-tutorial
static void lept_encode_utf8(lept_context* c, unsigned u) {
    if (u <= 0x7F) 
        PUTC(c, u & 0xFF);
    else if (u <= 0x7FF) {
        PUTC(c, 0xC0 | ((u >> 6) & 0xFF));
        PUTC(c, 0x80 | ( u       & 0x3F));
    }
コード例 #5
0
ファイル: write.c プロジェクト: ajinkya93/OpenBSD
/*
 * wr_fputs - like fputs(), but makes control characters visible and
 *     turns \n into \r\n
 */
void
wr_fputs(char *s)
{

#define	PUTC(c)	if (putchar(c) == EOF) goto err;

	for (; *s != '\0'; ++s) {
		if (*s == '\n') {
			PUTC('\r');
			PUTC('\n');
			continue;
		}
		if (isu8cont(*s))
			continue;
		if (isprint(*s) || isspace(*s) || *s == '\a') {
			PUTC(*s);
		} else {
			PUTC('?');
		}

	}
	return;

err:	err(1, NULL);
#undef PUTC
}
コード例 #6
0
ファイル: mandelbrot.c プロジェクト: z88dk/z88dk
int main (int argc, char **argv)
{
    STATIC int w, h, bit_num;
    STATIC unsigned char byte_acc;
    STATIC int i;
	 STATIC int iter = 50;
    STATIC double x, y;
    STATIC double Zr, Zi, Cr, Ci, Tr, Ti;
    STATIC double limit = 2.0;

#ifdef COMMAND
    w = argc > 1 ? atoi(argv[1]) : 60;
	 h = argc > 2 ? atoi(argv[2]) : w;
#else
    w = h = 60;
#endif

    PRINTF3("P4\n%d %d\n",w,h);

TIMER_START();

    for(y=0;y<h;++y) 
    {
        for(x=0;x<w;++x)
        {
            Zr = Zi = Tr = Ti = 0.0;
            Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0);
        
            for (i=0;i<iter && (Tr+Ti <= limit*limit);++i)
            {
                Zi = 2.0*Zr*Zi + Ci;
                Zr = Tr - Ti + Cr;
                Tr = Zr * Zr;
                Ti = Zi * Zi;
            }
       
            byte_acc <<= 1; 
            if(Tr+Ti <= limit*limit) byte_acc |= 0x01;
                
            ++bit_num; 

            if(bit_num == 8)
            {
                PUTC(byte_acc,stdout);
                byte_acc = 0;
                bit_num = 0;
            }
            else if(x == w-1)
            {
                byte_acc <<= (8-w%8);
                PUTC(byte_acc,stdout);
                byte_acc = 0;
                bit_num = 0;
            }
        }
    }

TIMER_STOP();
}
コード例 #7
0
ファイル: vparse.c プロジェクト: JensErat/cyrus-imapd
static int _parse_entry_multivalue(struct vparse_state *state)
{
    state->entry->multivalue = 1;
    state->entry->v.values = strarray_new();

    NOTESTART();

    while (*state->p) {
        switch (*state->p) {
        /* only one type of quoting */
        case '\\':
            /* seen in the wild - \n split by line wrapping */
            if (state->p[1] == '\r') INC(1);
            if (state->p[1] == '\n') {
                if (state->p[2] != ' ' && state->p[2] != '\t')
                    return PE_BACKQUOTE_EOF;
                INC(2);
            }
            if (!state->p[1])
                return PE_BACKQUOTE_EOF;
            if (state->p[1] == 'n' || state->p[1] == 'N')
                PUTC('\n');
            else
                PUTC(state->p[1]);
            INC(2);
            break;

        case ';':
            strarray_appendm(state->entry->v.values, buf_dup_cstring(&state->buf));
            INC(1);
            break;

        case '\r':
            INC(1);
            break; /* just skip */
        case '\n':
            if (state->p[1] == ' ' || state->p[1] == '\t') {/* wrapped line */
                INC(2);
                break;
            }
            /* otherwise it's the end of the value */
            INC(1);
            goto out;

        default:
            PUTC(*state->p);
            INC(1);
            break;
        }
    }

out:
    /* reaching the end of the file isn't a failure here,
     * it's just another type of end-of-value */
    strarray_appendm(state->entry->v.values, buf_dup_cstring(&state->buf));
    return 0;
}
コード例 #8
0
ファイル: cwriter.c プロジェクト: mbrock/bigloo-llvm
/*---------------------------------------------------------------------*/
obj_t
bgl_write_string( obj_t o, bool_t esc, obj_t op ) {
   if( esc ) PUTC( op, '#' );
   
   PUTC( op, '"' );
   bgl_display_string( o, op );
   PUTC( op, '"' );

   return op;
}
コード例 #9
0
ファイル: fc-cat.c プロジェクト: Nathan22Miles/SileLectionary
static FcBool
cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBool verbose)
{
    FcChar8	    *dir;
    const FcChar8   *base;
    int		    n;
    int		    ndir = 0;
    FcStrList	    *list;

    list = FcStrListCreate (dirs);
    if (!list)
	goto bail2;
    
    while ((dir = FcStrListNext (list)))
    {
	base = file_base_name (base_name, dir);
	if (!write_string (stdout, base))
	    goto bail3;
	if (PUTC (' ', stdout) == EOF)
	    goto bail3;
	if (!write_int (stdout, 0))
	    goto bail3;
        if (PUTC (' ', stdout) == EOF)
	    goto bail3;
	if (!write_string (stdout, FC_FONT_FILE_DIR))
	    goto bail3;
	if (PUTC ('\n', stdout) == EOF)
	    goto bail3;
	ndir++;
    }
    
    for (n = 0; n < set->nfont; n++)
    {
	FcPattern   *font = set->fonts[n];
	FcChar8 *s;

	s = FcPatternFormat (font, (const FcChar8 *) "%{=fccat}\n");
	if (s)
	{
	    printf ("%s", s);
	    FcStrFree (s);
	}
    }
    if (verbose && !set->nfont && !ndir)
	printf ("<empty>\n");

    FcStrListDone (list);

    return FcTrue;

bail3:
    FcStrListDone (list);
bail2:
    return FcFalse;
}
コード例 #10
0
ファイル: 7-3.c プロジェクト: peterlintang/c-language
int doprint(char *fmt, va_list ap)
{
	int ret = 0;
	int code;
	int value = 0;
	char *p = NULL;
	char string[24] = { 0 };

	for (; ; ) {
		while (((code = *fmt) != '\0') && (code != '%')) {
			PUTC(code);
			fmt++;
			ret++;
		}
		if (code == '\0')
			goto out;

		switch (code = *++fmt) {
			case 'd':
				value = va_arg(ap, int);
				p = itoa(string, value, 24);
				break;
			case 'o':
				value = va_arg(ap, int);
				p = otoa(string, value, 24);
				break;
			case 'x':
				value = va_arg(ap, int);
				p = xtoa(string, value, 24);
				break;
			case 's':
				p = va_arg(ap, char *);
				break;
			case 'c':
				value = va_arg(ap, int);
				string[0] = (char )value;
				string[1] = '\0';
				p = string;
				break;
			default:
				p = NULL;
				break;
		}
		while (p && (*p != '\0')) {
			PUTC(*p);
			p++, ret++;
		}
		fmt++;
	}

out:
	return ret;
}
コード例 #11
0
ファイル: slocat.c プロジェクト: apk/bases
void process (struct iop *io) {
	while (1) {
		int c = GETC (io);
		if (c == EOF) break;
		usleep (3000);
		PUTC (io, c);
		FLUSH (io);
	}
	if (io->fd == -1) {
		PUTC (io, '\n');
	}
}
コード例 #12
0
ファイル: fc-cat.c プロジェクト: Nathan22Miles/SileLectionary
static FcBool
write_string (FILE *f, const FcChar8 *string)
{

    if (PUTC ('"', f) == EOF)
	return FcFalse;
    if (!write_chars (f, string))
	return FcFalse;
    if (PUTC ('"', f) == EOF)
	return FcFalse;
    return FcTrue;
}
コード例 #13
0
ファイル: MemBuffer.cpp プロジェクト: Cristo-Conklin/XWRT
void CContainers::writeMemBuffers(int preprocFlag, int PPMDlib_order, int comprLevel, Encoder* PAQ_encoder, unsigned char* zlibBuffer,COutFileStream* outStream)
{
	std::map<std::string,CMemoryBuffer*>::iterator it;

	int fileLen=0;
	int len=0;
	int lenCompr=0;
	int allocated=0;

#ifdef USE_LZMA_LIBRARY
	if (IF_OPTION(OPTION_LZMA))
	{
		Byte **Data;
		size_t* Size;
		int count;
		
		count=(int)memmap.size();
		Size=new size_t[count];
		Data=(unsigned char**) malloc(sizeof(unsigned char*)*count);
		if (Data==NULL)
			OUT_OF_MEMORY();
	
		int i=0;
		for (it=memmap.begin(); it!=memmap.end(); it++)
		{
			CMemoryBuffer* b=it->second;
			fileLen=b->Size();
			
			if (fileLen>0)
			{
				Size[i]=fileLen;
				Data[i]=b->TargetBuf;
				i++;
				
				PUTC((int)it->first.size());
				for (int i=0; i<(int)it->first.size(); i++)
					PUTC(it->first[i]);
				
				PUTC(fileLen>>24);
				PUTC(fileLen>>16);
				PUTC(fileLen>>8);
				PUTC(fileLen);	
			}
		}
		
		PUTC(0);
		
		count=i;
		int last=LZMAlib_GetOutputFilePos(outStream);
		LZMAlib_EncodeSolidMemToFile(Data,Size,count,outStream);
		printStatus(0,LZMAlib_GetOutputFilePos(outStream)-last,true);
	}
コード例 #14
0
ファイル: erl_printf.c プロジェクト: AlainODea/otp
static int
write_f_add_cr(void *vfp, char* buf, size_t len)
{
    size_t i;
    ASSERT(vfp);
    for (i = 0; i < len; i++) {
	if (buf[i] == '\n' && PUTC('\r', (FILE *) vfp) == EOF)
	    return get_error_result();
	if (PUTC(buf[i], (FILE *) vfp) == EOF)
	    return get_error_result();
    }
    return 0;
}
コード例 #15
0
ファイル: inv94.c プロジェクト: apk/bases
void process (struct iop *io) {
	while (1) {
		int d;
		int c = GETC (io);
		if (c == EOF) break;
		if (c >= '!' && c <= '~') {
			c = ('!' + '~') - c;
		}
		PUTC (io, c);
	}
	if (io->fd == -1) {
		PUTC (io, '\n');
	}
}
コード例 #16
0
ファイル: kgdb_stub.c プロジェクト: ajinkya93/OpenBSD
/*
 * Receive a packet.
 */
static int
kgdb_recv(u_char *bp, int maxlen)
{
	u_char *p;
	int c, csum;
	int len;

	do {
		p = bp;
		csum = len = 0;
		while ((c = GETC()) != KGDB_START)
			;

		while ((c = GETC()) != KGDB_END && len < maxlen) {
			c &= 0x7f;
			csum += c;
			*p++ = c;
			len++;
		}
		csum &= 0xff;
		*p = '\0';

		if (len >= maxlen) {
			PUTC(KGDB_BADP);
			continue;
		}

		csum -= digit2i(GETC()) * 16;
		csum -= digit2i(GETC());

		if (csum == 0) {
			PUTC(KGDB_GOODP);
			/* Sequence present? */
			if (bp[2] == ':') {
				PUTC(bp[0]);
				PUTC(bp[1]);
				len -= 3;
				kgdb_copy(bp + 3, bp, len);
			}
			break;
		}
		PUTC(KGDB_BADP);
	} while (1);
#ifdef	DEBUG_KGDB
	printf("kgdb_recv: %s\n", bp);
#endif
	return (len);
}
コード例 #17
0
ファイル: HTWAIS.c プロジェクト: JGunning/Spyglass-mosaic
void showDiags ARGS2(
	HTStream *, 		target,
	diagnosticRecord **, 	d)
{
  long i;

  for (i = 0; d[i] != NULL; i++) {
    if (d[i]->ADDINFO != NULL) {
      PUTS("Diagnostic code is ");
      PUTS(d[i]->DIAG);
      PUTC(' ');
      PUTS(d[i]->ADDINFO);
      PUTC('\n'); ;
    }
  }
}
コード例 #18
0
ファイル: output.cpp プロジェクト: AhmadTux/DragonFlyBSD
simple_output &simple_output::put_raw_char(char c)
{
  col += last_word.flush(fp);
  PUTC(c, fp);
  col++;
  return *this;
}
コード例 #19
0
ファイル: output.cpp プロジェクト: AhmadTux/DragonFlyBSD
simple_output &simple_output::copy_file(FILE *infp)
{
  int c;
  while ((c = getc(infp)) != EOF)
    PUTC(c, fp);
  return *this;
}
コード例 #20
0
ファイル: GridText.c プロジェクト: svagionitis/libwww
/*	Output a line
**	-------------
*/
PRIVATE void display_line (HText * text, HTLine * line)
{
#ifdef CURSES
      int     y, x;

      waddstr(w_text, SPACES(line->offset));
      waddstr(w_text, line->data);
      getyx(w_text, y, x);
      if (y < DISPLAY_LINES-1) {
              wmove(w_text, ++y, 0);
      }
#else
   if (!text->target)
   {
#ifdef CYRILLIC
       /* HWL 18/7/94: applied patch from [email protected] (Anton Tropashko) */
       a_print(SPACES(line->offset),H,stdout); 
       a_print(line->data,H,stdout);
       fputc('\n',stdout);
#else
       OutputData(LineMode_getView(text->pLm), "%s%s\n", SPACES(line->offset), line->data);
#endif
   }
   else {
       PUTS(SPACES(line->offset));
       PUTS(line->data);
       PUTC('\n');
   }
#endif
   
}
コード例 #21
0
ファイル: HTNetTxt.c プロジェクト: BackupTheBerlios/texlive
/*	Converter from CRLF to \n
**	-------------------------
**	The input is assumed to be in local representation with lines
**	delimited by (CR,LF) pairs in the local representation.
**	The conversion to local representation is always done in HTSocket.c
**	The (CR,LF) sequence when found is changed to a '\n' character,
**	the internal C representation of a new line.
*/
PRIVATE int NetToText_put_block (HTStream * me, const char * s, int l)
{
    int status;
    if (!me->start)
	me->start = s;
    else {
	l -= (me->start - s);
	s = me->start;
    }
    while (l-- > 0) {
	if (me->had_cr && *s == LF) {
	    if (s > me->start+1) {
		if ((status = PUTBLOCK(me->start, s - me->start-1)) != HT_OK)
		    return status;
	    }
	    me->start = s+1;
	    if ((status = PUTC('\n')) != HT_OK)
		return status;
	}
	me->had_cr = (*s++ == CR);
    }
    if (me->start < s && (status = PUTBLOCK(me->start, s-me->start)) != HT_OK)
	return status;
    me->start = NULL;			      /* Whole buffer is written :-) */
    return HT_OK;
}
コード例 #22
0
ファイル: HTNetTxt.c プロジェクト: BackupTheBerlios/texlive
/*	Converter from \n to CRLF
**	-------------------------
**	The input is assumed to be in local representation with lines
**	delimited by \n. The \n when found is changed to a CRLF sequence,
**	the network representation of a new line.
**	Conversion: '\r' is stripped and \n => CRLF
*/
PRIVATE int TextToNet_put_block (HTStream * me, const char* b, int len)
{
    int status;
#if 0
    const char *limit = b+len;
#endif    
    if (!me->start)
	me->start = b;
    else {
	len -= (me->start - b);
	b = me->start;
    }
    while (len-- > 0) {
	if (me->had_cr && *b == LF) {
	    if (b > me->start+1) {
		if ((status = PUTBLOCK(me->start, b - me->start-1)) != HT_OK)
		    return status;
	    }
	    me->start = b+1;
	    if ((status = PUTC('\n')) != HT_OK)
		return status;
	}
	me->had_cr = (*b++ == CR);
    }
    if (me->start < b && (status = PUTBLOCK(me->start, b-me->start)) != HT_OK)
	return status;
    me->start = NULL;			      /* Whole buffer is written :-) */
    return HT_OK;
}
コード例 #23
0
ファイル: cwriter.c プロジェクト: mbrock/bigloo-llvm
/*---------------------------------------------------------------------*/
obj_t
bgl_write_utf8string( obj_t o, obj_t op ) {
   PUTS( op, "#u\"" );
   bgl_display_string( o, op );
   PUTC( op, '"' );

   return op;
}
コード例 #24
0
ファイル: iptc.c プロジェクト: Synchro/php-src
/* {{{ php_iptc_put1
 */
static int php_iptc_put1(FILE *fp, int spool, unsigned char c, unsigned char **spoolbuf)
{
	if (spool > 0)
		PUTC(c);

	if (spoolbuf) *(*spoolbuf)++ = c;

  	return c;
}
コード例 #25
0
ファイル: output.cpp プロジェクト: AhmadTux/DragonFlyBSD
simple_output &simple_output::end_line()
{
  flush_last_word();
  if (col != 0) {
    PUTC('\n', fp);
    col = 0;
  }
  return *this;
}
コード例 #26
0
ファイル: nautil.c プロジェクト: stormlovetao/FS2015
void
putstring(FILE *f, char *s)
{
    while (*s != '\0')
    {
        PUTC(*s,f);
        ++s;
    }
}
コード例 #27
0
/*
 * Send a packet.
 */
static void
kgdb_send(const u_char *bp)
{
	const u_char *p;
	u_char csum, c;

	DPRINTF(("kgdb_send: %s\n", bp));
	do {
		p = bp;
		PUTC(KGDB_START);
		for (csum = 0; (c = *p); p++) {
			PUTC(c);
			csum += c;
		}
		PUTC(KGDB_END);
		PUTC(i2digit(csum >> 4));
		PUTC(i2digit(csum));
	} while ((c = GETC() & 0x7f) == KGDB_BADP);
}
コード例 #28
0
ファイル: logrel_io.c プロジェクト: georgyberdyshev/ascend
static
void WriteLogicalRelation(FILE *f,
		          CONST struct logrelation *lr,
			  CONST struct Instance *ref)
{
  switch(LogRelRelop(lr)){
  case e_boolean_eq:
  case e_boolean_neq:
    WriteLogSide(f,lr,1,ref);
    PUTC(' ',f);
    WriteLogOp(f,LogRelRelop(lr));
    PUTC(' ',f);
    WriteLogSide(f,lr,0,ref);
    break;
  default:
    FPRINTF(ASCERR,"Unexpected Relop in WriteLogicalRelation\n");
    break;
  }
}
コード例 #29
0
ファイル: fc-cat.c プロジェクト: Nathan22Miles/SileLectionary
static FcBool
write_chars (FILE *f, const FcChar8 *chars)
{
    FcChar8    c;
    while ((c = *chars++))
    {
	switch (c) {
	case '"':
	case '\\':
	    if (PUTC ('\\', f) == EOF)
		return FcFalse;
	    /* fall through */
	default:
	    if (PUTC (c, f) == EOF)
		return FcFalse;
	}
    }
    return FcTrue;
}
コード例 #30
0
ファイル: kgdb_stub.c プロジェクト: ryo/netbsd-src
/*
 * Send a message.  The host gets one chance to read it.
 */
static void
kgdb_send(u_char type, u_char *bp, int len)
{
    u_char csum;
    u_char *ep = bp + len;

    PUTC(FRAME_START);
    PUTESC(type);

    csum = type;
    while (bp < ep) {
        type = *bp++;
        csum += type;
        PUTESC(type)
    }
    csum = -csum;
    PUTESC(csum)
    PUTC(FRAME_END);
}