Get rid of mixed tabs and spaces in winutil.c

This commit is contained in:
Kovid Goyal 2018-02-14 02:59:54 +05:30
parent 30a21d5627
commit 1335ca8b54
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -152,51 +152,51 @@ format_last_error() {
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL NULL
); );
return lpMsgBuf; return lpMsgBuf;
} }
static PyObject * static PyObject *
winutil_set_debug(PyObject *self, PyObject *args) { winutil_set_debug(PyObject *self, PyObject *args) {
PyObject *yes; PyObject *yes;
if (!PyArg_ParseTuple(args, "O", &yes)) return NULL; if (!PyArg_ParseTuple(args, "O", &yes)) return NULL;
DEBUG = (BOOL)PyObject_IsTrue(yes); DEBUG = (BOOL)PyObject_IsTrue(yes);
return Py_None; return Py_None;
} }
static int static int
gettmarg(PyObject *args, struct tm *p) gettmarg(PyObject *args, struct tm *p)
{ {
int y; int y;
memset((void *) p, '\0', sizeof(struct tm)); memset((void *) p, '\0', sizeof(struct tm));
if (!PyArg_Parse(args, "(iiiiiiiii)", if (!PyArg_Parse(args, "(iiiiiiiii)",
&y, &y,
&p->tm_mon, &p->tm_mon,
&p->tm_mday, &p->tm_mday,
&p->tm_hour, &p->tm_hour,
&p->tm_min, &p->tm_min,
&p->tm_sec, &p->tm_sec,
&p->tm_wday, &p->tm_wday,
&p->tm_yday, &p->tm_yday,
&p->tm_isdst)) &p->tm_isdst))
return 0; return 0;
if (y < 1900) { if (y < 1900) {
if (69 <= y && y <= 99) if (69 <= y && y <= 99)
y += 1900; y += 1900;
else if (0 <= y && y <= 68) else if (0 <= y && y <= 68)
y += 2000; y += 2000;
else { else {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"year out of range"); "year out of range");
return 0; return 0;
} }
} }
p->tm_year = y - 1900; p->tm_year = y - 1900;
p->tm_mon--; p->tm_mon--;
p->tm_wday = (p->tm_wday + 1) % 7; p->tm_wday = (p->tm_wday + 1) % 7;
p->tm_yday--; p->tm_yday--;
return 1; return 1;
} }
static PyObject * static PyObject *
@ -219,15 +219,15 @@ winutil_prepare_for_restart(PyObject *self, PyObject *args) {
static PyObject * static PyObject *
winutil_get_max_stdio(PyObject *self, PyObject *args) { winutil_get_max_stdio(PyObject *self, PyObject *args) {
return Py_BuildValue("i", _getmaxstdio()); return Py_BuildValue("i", _getmaxstdio());
} }
static PyObject * static PyObject *
winutil_set_max_stdio(PyObject *self, PyObject *args) { winutil_set_max_stdio(PyObject *self, PyObject *args) {
int num = 0; int num = 0;
if (!PyArg_ParseTuple(args, "i", &num)) return NULL; if (!PyArg_ParseTuple(args, "i", &num)) return NULL;
if (_setmaxstdio(num) == -1) return PyErr_SetFromErrno(PyExc_ValueError); if (_setmaxstdio(num) == -1) return PyErr_SetFromErrno(PyExc_ValueError);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
@ -241,11 +241,11 @@ winutil_getenv(PyObject *self, PyObject *args) {
static PyObject* static PyObject*
winutil_move_file(PyObject *self, PyObject *args) { winutil_move_file(PyObject *self, PyObject *args) {
Py_UNICODE *a, *b; Py_UNICODE *a, *b;
unsigned int flags = MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH; unsigned int flags = MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH;
if (!PyArg_ParseTuple(args, "uu|I", &a, &b, &flags)) return NULL; if (!PyArg_ParseTuple(args, "uu|I", &a, &b, &flags)) return NULL;
if (!MoveFileExW(a, b, flags)) { PyErr_SetFromWindowsErr(0); return NULL; } if (!MoveFileExW(a, b, flags)) { PyErr_SetFromWindowsErr(0); return NULL; }
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
@ -298,16 +298,16 @@ winutil_localeconv(PyObject *self) {
static PyObject * static PyObject *
winutil_strftime(PyObject *self, PyObject *args) winutil_strftime(PyObject *self, PyObject *args)
{ {
PyObject *tup = NULL; PyObject *tup = NULL;
struct tm buf; struct tm buf;
const char *_fmt; const char *_fmt;
size_t fmtlen, buflen; size_t fmtlen, buflen;
wchar_t *outbuf = NULL, *fmt = NULL; wchar_t *outbuf = NULL, *fmt = NULL;
size_t i; size_t i;
memset((void *) &buf, '\0', sizeof(buf)); memset((void *) &buf, '\0', sizeof(buf));
if (!PyArg_ParseTuple(args, "s|O:strftime", &_fmt, &tup)) if (!PyArg_ParseTuple(args, "s|O:strftime", &_fmt, &tup))
return NULL; return NULL;
if (mbstowcs_s(&fmtlen, NULL, 0, _fmt, strlen(_fmt)) != 0) { if (mbstowcs_s(&fmtlen, NULL, 0, _fmt, strlen(_fmt)) != 0) {
PyErr_SetString(PyExc_ValueError, "Failed to convert fmt to wchar"); PyErr_SetString(PyExc_ValueError, "Failed to convert fmt to wchar");
@ -320,24 +320,24 @@ winutil_strftime(PyObject *self, PyObject *args)
goto end; goto end;
} }
if (tup == NULL) { if (tup == NULL) {
time_t tt = time(NULL); time_t tt = time(NULL);
if(localtime_s(&buf, &tt) != 0) { if(localtime_s(&buf, &tt) != 0) {
PyErr_SetString(PyExc_ValueError, "Failed to get localtime()"); PyErr_SetString(PyExc_ValueError, "Failed to get localtime()");
goto end; goto end;
} }
} else if (!gettmarg(tup, &buf)) } else if (!gettmarg(tup, &buf))
goto end; goto end;
if (buf.tm_mon == -1) if (buf.tm_mon == -1)
buf.tm_mon = 0; buf.tm_mon = 0;
else if (buf.tm_mon < 0 || buf.tm_mon > 11) { else if (buf.tm_mon < 0 || buf.tm_mon > 11) {
PyErr_SetString(PyExc_ValueError, "month out of range"); PyErr_SetString(PyExc_ValueError, "month out of range");
goto end; goto end;
} }
if (buf.tm_mday == 0) if (buf.tm_mday == 0)
buf.tm_mday = 1; buf.tm_mday = 1;
else if (buf.tm_mday < 0 || buf.tm_mday > 31) { else if (buf.tm_mday < 0 || buf.tm_mday > 31) {
PyErr_SetString(PyExc_ValueError, "day of month out of range"); PyErr_SetString(PyExc_ValueError, "day of month out of range");
goto end; goto end;
} }
@ -359,9 +359,9 @@ winutil_strftime(PyObject *self, PyObject *args)
PyErr_SetString(PyExc_ValueError, "day of week out of range"); PyErr_SetString(PyExc_ValueError, "day of week out of range");
goto end; goto end;
} }
if (buf.tm_yday == -1) if (buf.tm_yday == -1)
buf.tm_yday = 0; buf.tm_yday = 0;
else if (buf.tm_yday < 0 || buf.tm_yday > 365) { else if (buf.tm_yday < 0 || buf.tm_yday > 365) {
PyErr_SetString(PyExc_ValueError, "day of year out of range"); PyErr_SetString(PyExc_ValueError, "day of year out of range");
goto end; goto end;
} }
@ -371,28 +371,28 @@ winutil_strftime(PyObject *self, PyObject *args)
goto end; goto end;
} }
for (i = 5*fmtlen; ; i += i) { for (i = 5*fmtlen; ; i += i) {
outbuf = (wchar_t *)PyMem_Malloc(i*sizeof(wchar_t)); outbuf = (wchar_t *)PyMem_Malloc(i*sizeof(wchar_t));
if (outbuf == NULL) { if (outbuf == NULL) {
PyErr_NoMemory(); goto end; PyErr_NoMemory(); goto end;
} }
buflen = wcsftime(outbuf, i, fmt, &buf); buflen = wcsftime(outbuf, i, fmt, &buf);
if (buflen > 0 || i >= 256 * fmtlen) { if (buflen > 0 || i >= 256 * fmtlen) {
/* If the buffer is 256 times as long as the format, /* If the buffer is 256 times as long as the format,
it's probably not failing for lack of room! it's probably not failing for lack of room!
More likely, the format yields an empty result, More likely, the format yields an empty result,
e.g. an empty format, or %Z when the timezone e.g. an empty format, or %Z when the timezone
is unknown. */ is unknown. */
PyObject *ret; PyObject *ret;
ret = PyUnicode_FromWideChar(outbuf, buflen); ret = PyUnicode_FromWideChar(outbuf, buflen);
PyMem_Free(outbuf); PyMem_Free(fmt); PyMem_Free(outbuf); PyMem_Free(fmt);
return ret; return ret;
} }
PyMem_Free(outbuf); PyMem_Free(outbuf);
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
/* VisualStudio .NET 2005 does this properly */ /* VisualStudio .NET 2005 does this properly */
if (buflen == 0 && errno == EINVAL) { if (buflen == 0 && errno == EINVAL) {
PyErr_SetString(PyExc_ValueError, "Invalid format string"); PyErr_SetString(PyExc_ValueError, "Invalid format string");
goto end; goto end;
} }
#endif #endif
@ -405,23 +405,23 @@ end:
static PyMethodDef WinutilMethods[] = { static PyMethodDef WinutilMethods[] = {
{"special_folder_path", winutil_folder_path, METH_VARARGS, {"special_folder_path", winutil_folder_path, METH_VARARGS,
"special_folder_path(csidl_id) -> path\n\n" "special_folder_path(csidl_id) -> path\n\n"
"Get paths to common system folders. " "Get paths to common system folders. "
"See windows documentation of SHGetFolderPath. " "See windows documentation of SHGetFolderPath. "
"The paths are returned as unicode objects. csidl_id should be one " "The paths are returned as unicode objects. csidl_id should be one "
"of the symbolic constants defined in this module. You can also OR " "of the symbolic constants defined in this module. You can also OR "
"a symbolic constant with CSIDL_FLAG_CREATE to force the operating " "a symbolic constant with CSIDL_FLAG_CREATE to force the operating "
"system to create a folder if it does not exist."}, "system to create a folder if it does not exist."},
{"argv", winutil_argv, METH_VARARGS, {"argv", winutil_argv, METH_VARARGS,
"argv() -> list of command line arguments\n\n" "argv() -> list of command line arguments\n\n"
"Get command line arguments as unicode objects. Note that the " "Get command line arguments as unicode objects. Note that the "
"first argument will be the path to the interpreter, *not* the " "first argument will be the path to the interpreter, *not* the "
"script being run. So to replace sys.argv, you should use " "script being run. So to replace sys.argv, you should use "
"sys.argv[1:] = argv()[1:]."}, "sys.argv[1:] = argv()[1:]."},
{"set_debug", winutil_set_debug, METH_VARARGS, {"set_debug", winutil_set_debug, METH_VARARGS,
"set_debug(bool)\n\nSet debugging mode." "set_debug(bool)\n\nSet debugging mode."
}, },
{"strftime", winutil_strftime, METH_VARARGS, {"strftime", winutil_strftime, METH_VARARGS,
"strftime(format[, tuple]) -> string\n\ "strftime(format[, tuple]) -> string\n\