version 1.23, 2015/11/02 20:25:42 |
version 1.24, 2015/12/19 10:21:01 |
|
|
#include <err.h> |
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
#include <limits.h> |
#include <limits.h> |
|
#include <locale.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <wchar.h> |
|
#include <wctype.h> |
|
|
#define MAXLINELEN (8 * 1024) |
#define MAXLINELEN (8 * 1024) |
|
|
|
|
int ch; |
int ch; |
char *prevline, *thisline; |
char *prevline, *thisline; |
|
|
|
setlocale(LC_CTYPE, ""); |
|
|
if (pledge("stdio rpath wpath cpath", NULL) == -1) |
if (pledge("stdio rpath wpath cpath", NULL) == -1) |
err(1, "pledge"); |
err(1, "pledge"); |
|
|
|
|
char * |
char * |
skip(char *str) |
skip(char *str) |
{ |
{ |
|
wchar_t wc; |
int nchars, nfields; |
int nchars, nfields; |
|
int len; |
|
int field_started; |
|
|
for (nfields = numfields; nfields && *str; nfields--) { |
for (nfields = numfields; nfields && *str; nfields--) { |
while (isblank((unsigned char)*str)) |
/* Skip one field, including preceding blanks. */ |
str++; |
for (field_started = 0; *str != '\0'; str += len) { |
while (*str && !isblank((unsigned char)*str)) |
if ((len = mbtowc(&wc, str, MB_CUR_MAX)) == -1) { |
str++; |
(void)mbtowc(NULL, NULL, MB_CUR_MAX); |
|
wc = L'?'; |
|
len = 1; |
|
} |
|
if (iswblank(wc)) { |
|
if (field_started) |
|
break; |
|
} else |
|
field_started = 1; |
|
} |
} |
} |
for (nchars = numchars; nchars-- && *str && *str != '\n'; ++str) |
|
; |
/* Skip some additional characters. */ |
|
for (nchars = numchars; nchars-- && *str != '\0'; str += len) |
|
if ((len = mblen(str, MB_CUR_MAX)) == -1) |
|
len = 1; |
|
|
return (str); |
return (str); |
} |
} |
|
|