Example #1
0
static void
c_columnate(void)
{
    int chcnt, col, cnt, endcol, numcols;
    wchar_t **lp;

    numcols = termwidth / maxlength;
    endcol = maxlength;
    for (chcnt = col = 0, lp = list;; ++lp) {
        wprintf(L"%ls", *lp);
        chcnt += width(*lp);
        if (!--entries)
            break;
        if (++col == numcols) {
            chcnt = col = 0;
            endcol = maxlength;
            putwchar('\n');
        } else {
            while ((cnt = roundup(chcnt + 1, TAB)) <= endcol) {
                (void)putwchar('\t');
                chcnt = cnt;
            }
            endcol += maxlength;
        }
    }
    if (chcnt)
        putwchar('\n');
}
Example #2
0
File: ul.c Project: Romutk/lab3.2n
void iattr(void)
{
	register int i;
#ifdef __GNUC__
	register char *lbuf = __builtin_alloca((maxcol+1)*sizeof(char));
#else
	char lbuf[256];
#endif
	register char *cp = lbuf;

	for (i=0; i<maxcol; i++)
		switch (obuf[i].c_mode) {
		case NORMAL:	*cp++ = ' '; break;
		case ALTSET:	*cp++ = 'g'; break;
		case SUPERSC:	*cp++ = '^'; break;
		case SUBSC:	*cp++ = 'v'; break;
		case UNDERL:	*cp++ = '_'; break;
		case BOLD:	*cp++ = '!'; break;
		default:	*cp++ = 'X'; break;
		}
	for (*cp=' '; *cp==' '; cp--)
		*cp = 0;
	for (cp=lbuf; *cp; cp++)
		putwchar(*cp);
	putwchar('\n');
}
Example #3
0
static inline void
write_wchars(wchar_t buf[], size_t start, size_t end, bool escape,
             bool open_field, bool close_field) {
  size_t j;
  if (escape) {
    if (open_field)
      putwchar(L'"');
    for (j = start; j <= end; ++j) {
      if (buf[IDX(j)] == L'"')
        putwchar(L'"');
      if (putwchar(buf[IDX(j)]) == WEOF) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
    if (close_field)
      putwchar(L'"');
  } else {
    for (j = start; j <= end; ++j) {
      if (putwchar(buf[IDX(j)]) == WEOF) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
  }
}
Example #4
0
void
matchContext(wchar_t *T, regexNode re)
{
    int start, end, currPos;

    int i, n;

    currPos = start = end = 0;
    n = wcslen(T);

    while (currPos < n)
    {
        if (re_match2(re, T, &start, &end))
        {
            putwchar(L' ');
            for (i=start; i<end; i++)
              putwchar(*(T+i));
            //wprintf(L"匹配成功,识别边界为[%d, %d)\n", start, end);
            putwchar(L' ');
            currPos = end;
        }
        else
        {
            putwchar(*(T+currPos));
            currPos++;
            start = end = currPos;
        }

    }
    //wprintf(L"匹配失败\n");

}
Example #5
0
static void
r_columnate(void)
{
    int base, chcnt, cnt, col, endcol, numcols, numrows, row;

    numcols = termwidth / maxlength;
    numrows = entries / numcols;
    if (entries % numcols)
        ++numrows;

    for (row = 0; row < numrows; ++row) {
        endcol = maxlength;
        for (base = row, chcnt = col = 0; col < numcols; ++col) {
            wprintf(L"%ls", list[base]);
            chcnt += width(list[base]);
            if ((base += numrows) >= entries)
                break;
            while ((cnt = roundup(chcnt + 1, TAB)) <= endcol) {
                (void)putwchar('\t');
                chcnt = cnt;
            }
            endcol += maxlength;
        }
        putwchar('\n');
    }
}
Example #6
0
void print_grid(FILE *out, const grid_t *grid) {
  for (int row = 0; row < grid->height; row++) {
    for (int col = 0; col < grid->width; col++) {
      putwchar(get_pipe_wchar(grid->grid[GRID_INDEX(grid, row, col)]));
    }
    putwchar(L'\n');
  }
}
Example #7
0
File: ansicon.c Project: kmkkmk/app
// Display a file.
void display( LPCTSTR name, BOOL title )
{
  HANDLE file;
  int	 c;
  LARGE_INTEGER size, offset;

  // Handle the pipe differently.
  if (*name == '-' && name[1] == '\0')
  {
    if (title)
      putwchar( '\n' );
    while ((c = getchar()) != EOF)
      putchar( c );
    return;
  }

  file = CreateFile( name, GENERIC_READ, FILE_SHARE_READ, NULL,
		     OPEN_EXISTING, 0, NULL );
  if (file == INVALID_HANDLE_VALUE)
  {
    print_error( name, title );
    return;
  }

  GetFileSizeEx( file, &size );
  if (size.QuadPart != 0)
  {
    HANDLE map = CreateFileMapping( file, NULL, PAGE_READONLY, 0, 0, NULL );
    if (map)
    {
      if (title)
	putwchar( '\n' );
      offset.QuadPart = 0;
      do
      {
	DWORD len = (size.QuadPart > 65536) ? 65536 : size.LowPart;
	LPVOID mem = MapViewOfFile( map, FILE_MAP_READ, offset.HighPart,
				    offset.LowPart, len );
	if (mem)
	{
	  fwrite( mem, 1, len, stdout );
	  UnmapViewOfFile( mem );
	}
	else
	{
	  print_error( name, title );
	  break;
	}
	offset.QuadPart += len;
	size.QuadPart -= len;
      } while (size.QuadPart);
      CloseHandle( map );
    }
    else
      print_error( name, title );
  }
  CloseHandle( file );
}
Example #8
0
/*
 * @implemented
 */
int _putws(const wchar_t *s)
{
    wint_t c;
    
    while ((c = *s++)) {
        putwchar(c);
    }
    return putwchar(L'\n');
}
Example #9
0
/* Output spaces or tabs for leading indentation.
 */
static void
output_indent(size_t n_spaces) {
  if (output_tab_width) {
    while (n_spaces >= output_tab_width) {
      putwchar('\t');
      n_spaces -= output_tab_width;
    }
  }
  while (n_spaces-- > 0) putwchar(' ');
}
Example #10
0
File: rev.c Project: Hooman3/minix
int
main(int argc, char *argv[])
{
	const char *filename;
	wchar_t *p, *t;
	FILE *fp;
	size_t len;
	int ch, rval;

	setlocale(LC_ALL, "");
	setprogname(argv[0]);

	while ((ch = getopt(argc, argv, "")) != -1)
		switch(ch) {
		case '?':
		default:
			usage();
		}

	argc -= optind;
	argv += optind;

	fp = stdin;
	filename = "stdin";
	rval = 0;
	do {
		if (*argv) {
			if ((fp = fopen(*argv, "r")) == NULL) {
				warn("%s", *argv);
				rval = 1;
				++argv;
				continue;
			}
			filename = *argv++;
		}
		while ((p = fgetwln(fp, &len)) != NULL) {
			if (p[len - 1] == L'\n')
				--len;
			t = p + len - 1;
			for (t = p + len - 1; t >= p; --t)
				putwchar(*t);
			putwchar(L'\n');
		}
		if (ferror(fp)) {
			warn("%s", filename);
			rval = 1;
		}
		(void)fclose(fp);
	} while(*argv);
	exit(rval);
}
Example #11
0
/* Output an ASCII character as a wide character */
static int put1wc(int c)
{
	if (putwchar(c) == WEOF)
		return EOF;
	else
		return c;
}
Example #12
0
void pflush(int ol)
{
	register int i;
	register wchar_t *cp;
	char lastomit;
	int l;

	l = ol;
	lastomit = 0;
	if (l > 266)
		l = 266;
	else
		l |= 1;
	for (i = first | 1; i < l; i++) {
		move(i, i - 1);
		move(i, i + 1);
	}
	for (i = first; i < l; i++) {
		cp = page[i];
		if (printall == 0 && lastomit == 0 && *cp == 0) {
			lastomit = 1;
			continue;
		}
		lastomit = 0;
		fputws(cp, stdout);
		putwchar('\n');
	}
	bcopy(page[ol], page, (267 - ol) * 132 * sizeof(wchar_t));
	bzero(page[267- ol], ol * 132 * sizeof(wchar_t));
	outline -= ol;
	outcol = 0;
	first = 1;
}
Example #13
0
File: fmt.c Project: tomtor/freebsd
/* Process a stream, but just center its lines rather than trying to
 * format them neatly.
 */
static void
center_stream(FILE *stream, const char *name)
{
    wchar_t *line, *p;
    size_t length;
    size_t width;
    int cwidth;

    while ((line = get_line(stream, &length)) != NULL) {
        size_t l = length;

        while (l > 0 && iswspace(*line)) {
            ++line;
            --l;
        }
        length = l;
        for (p = line, width = 0; p < &line[length]; p++)
            width += (cwidth = wcwidth(*p)) > 0 ? cwidth : 1;
        l = width;
        while (l < goal_length) {
            putwchar(' ');
            l += 2;
        }
        wprintf(L"%.*ls\n", (int)length, line);
    }
    if (ferror(stream)) {
        warn("%s", name);
        ++n_errors;
    }
}
Example #14
0
int main ()
{
  wchar_t wc;
  for (wc = 'A' ; wc <= 'Z' ; ++wc) putwchar (wc);

  return 0;
}
Example #15
0
File: ul.c Project: Romutk/lab3.2n
static int put1wc(int c) /* Output an ASCII character as a wide character */
{
  if (putwchar(c) == WEOF)
    return EOF;
  else
    return c;
}
Example #16
0
/* ARGSUSED */
static void
locale_advance(struct termp *p, size_t len)
{
	size_t	 	i;

	for (i = 0; i < len; i++)
		putwchar(L' ');
}
Example #17
0
INLINE void WriteChar(Int32 const &c) {
#ifdef __linux
    printf("%lc", c);
    fflush(stdout);                     // 令 Linux 终端立即输出 而不是等 \n
#else
	putwchar(c);
#endif
}
void CWE252_Unchecked_Return_Value__wchar_t_putchar_04_bad()
{
    if(STATIC_CONST_TRUE)
    {
        /* FLAW: Do not check the return value */
        putwchar((wchar_t)L'A');
    }
}
static void good1()
{
    /* FIX: check for the correct return value */
    if (putwchar((wchar_t)L'A') == WEOF)
    {
        printLine("putwchar failed!");
    }
}
void CWE253_Incorrect_Check_of_Function_Return_Value__wchar_t_putchar_01_bad()
{
    /* FLAW: putwchar() might fail, in which case the return value will be WEOF (-1), but
     * we are checking to see if the return value is 0 */
    if (putwchar((wchar_t)L'A') == 0)
    {
        printLine("putwchar failed!");
    }
}
void CWE252_Unchecked_Return_Value__wchar_t_putchar_16_bad()
{
    while(1)
    {
        /* FLAW: Do not check the return value */
        putwchar((wchar_t)L'A');
        break;
    }
}
/* good2() reverses the bodies in the if statement */
static void good2()
{
    if(STATIC_CONST_TRUE)
    {
        /* FIX: check the return value */
        if (putwchar((wchar_t)L'A') == WEOF)
        {
            printLine("putwchar failed!");
        }
    }
}
/* good2() reverses the bodies in the if statement */
static void good2()
{
    if(GLOBAL_CONST_TRUE)
    {
        /* FIX: check for the correct return value */
        if (putwchar((wchar_t)L'A') == WEOF)
        {
            printLine("putwchar failed!");
        }
    }
}
Example #24
0
static void
pflush(int ol)
{
	static int first;
	int i;
	wchar_t *cp;
	char lastomit;
	int l, w;

	l = ol;
	lastomit = 0;
	if (l > 266)
		l = 266;
	else
		l |= 1;
	for (i = first | 1; i < l; i++) {
		move(i, i - 1);
		move(i, i + 1);
	}
	for (i = first; i < l; i++) {
		cp = page[i];
		if (printall == 0 && lastomit == 0 && *cp == 0) {
			lastomit = 1;
			continue;
		}
		lastomit = 0;
		while (*cp != L'\0') {
			if ((w = wcwidth(*cp)) > 0) {
				putwchar(*cp);
				cp += w;
			} else
				cp++;
		}
		putwchar(L'\n');
	}
	wmemcpy(page[0], page[ol], (267 - ol) * 132);
	wmemset(page[267- ol], L'\0', ol * 132);
	outline -= ol;
	outcol = 0;
	first = 1;
}
/* good1() uses the GoodSinkBody in the while loop */
static void good1()
{
    while(1)
    {
        /* FIX: check the return value */
        if (putwchar((wchar_t)L'A') == WEOF)
        {
            printLine("putwchar failed!");
        }
        break;
    }
}
Example #26
0
File: ul.c Project: Romutk/lab3.2n
void
outc(wint_t c, int width) {
	int i;

	putwchar(c);
	if (must_use_uc && (curmode&UNDERL)) {
		for (i=0; i<width; i++)
			PRINT(CURS_LEFT);
		for (i=0; i<width; i++)
			PRINT(UNDER_CHAR);
	}
}
Example #27
0
static int
sequential(char **argv)
{
	FILE *fp;
	int cnt, failed, needdelim;
	wint_t ch;
	char *p;

	failed = 0;
	for (; (p = *argv); ++argv) {
		if (p[0] == '-' && !p[1])
			fp = stdin;
		else if (!(fp = fopen(p, "r"))) {
			warn("%s", p);
			failed = 1;
			continue;
		}
		cnt = needdelim = 0;
		while ((ch = getwc(fp)) != WEOF) {
			if (needdelim) {
				needdelim = 0;
				if (delim[cnt] != '\0')
					putwchar(delim[cnt]);
				if (++cnt == delimcnt)
					cnt = 0;
			}
			if (ch != '\n')
				putwchar(ch);
			else
				needdelim = 1;
		}
		if (needdelim)
			putwchar('\n');
		if (fp != stdin)
			(void)fclose(fp);
	}

	return (failed != 0);
}
Example #28
0
void pflush(int ol)
{
    register int i;
    register wchar_t *cp;
    char lastomit;
    int l, w;

    l = ol;
    lastomit = 0;
    if (l > 266)
        l = 266;
    else
        l |= 1;
    for (i = first | 1; i < l; i++) {
        move(i, i - 1);
        move(i, i + 1);
    }
    for (i = first; i < l; i++) {
        cp = page[i];
        if (printall == 0 && lastomit == 0 && *cp == 0) {
            lastomit = 1;
            continue;
        }
        lastomit = 0;
        while (*cp) {
            if ((w = wcwidth(*cp)) > 0) {
                putwchar(*cp);
                cp += w;
            } else
                cp++;
        }
        putwchar('\n');
    }
    memmove(page, page[ol], (267 - ol) * 132 * sizeof(wchar_t));
    memset(page[267 - ol], '\0', ol * 132 * sizeof(wchar_t));
    outline -= ol;
    outcol = 0;
    first = 1;
}
Example #29
0
static void
iattr(void)
{
	int i;
	wchar_t lbuf[256];
	wchar_t *cp = lbuf;

	for (i=0; i<maxcol; i++)
		switch (obuf[i].c_mode) {
		case NORMAL:	*cp++ = ' '; break;
		case ALTSET:	*cp++ = 'g'; break;
		case SUPERSC:	*cp++ = '^'; break;
		case SUBSC:	*cp++ = 'v'; break;
		case UNDERL:	*cp++ = '_'; break;
		case BOLD:	*cp++ = '!'; break;
		default:	*cp++ = 'X'; break;
		}
	for (*cp=' '; *cp==' '; cp--)
		*cp = 0;
	for (cp=lbuf; *cp; cp++)
		putwchar(*cp);
	putwchar('\n');
}
Example #30
0
void prtaawapap2(aaw_c *aawc, aaw_c *aawc2) /* print aaw As Pure As Possible */
{
    int i, ii, j, k, ppi=0;
    for(i=1;i<aawc->numl;++i) {
        ii=1+i/2;
        /* order fo tabs and space will be messed up sure, but usually it will be one or the other. */
        for(j=5;j<aawc->aaw[i]->al;++j) {
            for(k=0;k<aawc->aaw[i]->aw[j]->lp1-1; k++)
                putwchar(aawc->aaw[i]->aw[j]->w[k]);
            if(j==aawc->aaw[i]->al-1)
                putwchar('\n');
            else
                putwchar(' ');
        }
        for(j=3;j<aawc2->aaw[ii]->al;++j) {
            for(k=0;k<aawc2->aaw[ii]->aw[j]->lp1-1; k++)
                putwchar(aawc2->aaw[ii]->aw[j]->w[k]);
            if(j==aawc2->aaw[ii]->al-1)
                printf("\n\n"); 
            else
                putwchar(' ');
        }
    }
}