mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Added 'softspace' interface to replace 'needspace' printing hack.
This commit is contained in:
parent
282914b7b0
commit
eb183da74f
1 changed files with 18 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ typedef struct {
|
||||||
FILE *f_fp;
|
FILE *f_fp;
|
||||||
object *f_name;
|
object *f_name;
|
||||||
object *f_mode;
|
object *f_mode;
|
||||||
/* XXX Should move the 'need space' on printing flag here */
|
int f_softspace; /* Flag used by 'print' command */
|
||||||
} fileobject;
|
} fileobject;
|
||||||
|
|
||||||
FILE *
|
FILE *
|
||||||
|
|
@ -70,6 +70,7 @@ newopenfileobject(fp, name, mode)
|
||||||
f->f_fp = NULL;
|
f->f_fp = NULL;
|
||||||
f->f_name = newstringobject(name);
|
f->f_name = newstringobject(name);
|
||||||
f->f_mode = newstringobject(mode);
|
f->f_mode = newstringobject(mode);
|
||||||
|
f->f_softspace = 0;
|
||||||
if (f->f_name == NULL || f->f_mode == NULL) {
|
if (f->f_name == NULL || f->f_mode == NULL) {
|
||||||
DECREF(f);
|
DECREF(f);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -387,6 +388,7 @@ file_write(f, args)
|
||||||
err_badarg();
|
err_badarg();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
f->f_softspace = 0;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
n2 = fwrite(getstringvalue(args), 1, n = getstringsize(args), f->f_fp);
|
n2 = fwrite(getstringvalue(args), 1, n = getstringsize(args), f->f_fp);
|
||||||
if (n2 != n) {
|
if (n2 != n) {
|
||||||
|
|
@ -432,3 +434,18 @@ typeobject Filetype = {
|
||||||
0, /*tp_compare*/
|
0, /*tp_compare*/
|
||||||
file_repr, /*tp_repr*/
|
file_repr, /*tp_repr*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Interface for the 'soft space' between print items. */
|
||||||
|
|
||||||
|
int
|
||||||
|
softspace(f, newflag)
|
||||||
|
object *f;
|
||||||
|
int newflag;
|
||||||
|
{
|
||||||
|
int oldflag = 0;
|
||||||
|
if (f != NULL && is_fileobject(f)) {
|
||||||
|
oldflag = ((fileobject *)f)->f_softspace;
|
||||||
|
((fileobject *)f)->f_softspace = newflag;
|
||||||
|
}
|
||||||
|
return oldflag;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue