How to make sure sscanf reads to the end of the line

I needed to do this for GNOME bug 453678, and it wasn’t very obvious. In the end I thought of a way, and I’ve tested it with gcc on GNU/Linux and HP C on OpenVMS to make sure it wasn’t just a GNU thing. (No, this doesn’t imply that I’m introducing a policy of building Metacity on OpenVMS in future.)

GEIN $ type test.c
#include <stdio.h>
#include <string.h>

void
check(char *string)
{
  int workspace = -1;
  int chars = 0;

  sscanf (string, "Workspace %d%n", &workspace, &chars);

  printf ("Input is [%s], workspace number is %d, fully=%s\n",
      string, workspace, *(string+chars)=='\0'?"Yes":"No");
}

int
main(int argc, char**argv)
{
  check ("Workspace 1 is very nice");
  check ("Workspace 2");
  check ("I like beer");
}

GEIN $ cc test
GEIN $ link test
GEIN $ run test
Input is [Workspace 1 is very nice], workspace number is 1, fully=No
Input is [Workspace 2], workspace number is 2, fully=Yes
Input is [I like beer], workspace number is -1, fully=No
GEIN $ 

OpenVMS testing courtesy of gein.vistech.net .

The benefits of careful checking before you release

This is a screenshot from a web game that my daughter Riordon was playing. It demonstrates well the reason you should check things before release (and you know what they say about leaving three fingers pointing back at yourself):

This did give us the chance to talk about the difference between marked-up and plain text.
[A response on LJ: It’s good to talk to your kids about that, before they learn about it on the streets.]

Everybody has won, and all must have prizes

This blog has been far out at sea all night, as Ted Hughes would never have said. They made a rather cutesified children’s cartoon out of one of his books, over here in the US, and they show it every Christmas on TV. I am still waiting for a similar treatment to be given to The Bell Jar.

Anyway, I have been reminded of Wind in the literal rather than the metaphorical sense for the last few days, and I haven’t had much time to post. And my mother-in-law’s beloved cat died: 1, 2, 3, and the weather has been horrible for days and days. I’ve just wanted to sleep and hide. But Spring will come though a thousand Februaries march against it, and already perhaps the daffodils are pushing through the earth.

Frida Kahlo: I said I’d tell you what I thought about the Frida Kahlo exhibition. I think you should go and see it if you can. I’ve loved Kahlo’s work for a long time, but it isn’t often you get the chance to get up close to so much of her work and see it at close quarters, and there were some periods in her life I’d seen nothing from (I particularly loved some of her later work, like Moses, because I love really complicated artwork). One thing I’d rather have seen– perhaps this is merely a symptom of my being uncultured– is prints of the pieces they hadn’t got the originals of (What the Water Gave Me particularly wasn’t there). Perhaps that’s just what I need to buy the exhibition book for.

As to the actual discussion and commentary the museum provided, while it was certainly very adequate, I noticed a particular bias towards some of the important influences on her work at the expense of others. In particular, they talked a lot about how she wanted to have children and could not, and how later she saw her pets as her children, and the world, and Rivera. But while they discussed how this came out in her work a good deal– and showed how it came out in the paintings in ways I’d never seen before– it was rather at the expense of discussing the influences of her bisexuality and her Communism on her work, which were dealt with rather briefly. By comparison, some other exhibitions have brought out these themes rather more directly.

The museum also had another exhibition of the work of Juan Soriano, which is also worth seeing (especially since it’s apparently the first exhibition of his work in a major museum in the US), but there’s less to see there. (I wouldn’t have noticed so much had it not been for the Kahlo exhibition that, despite the ways Soriano works sexual themes into his work, they mentioned only once that he was gay.)

Shirts: I have received a GNOME t-shirt in the post: thank you to the Foundation. This brings the number of tech shirts I have to four: a Google shirt which I unfortunately left in England when I emigrated, a Summer of Code shirt from last year, a Freshmeat shirt that Eric sent me, and this one. I should post photos of me wearing each of them (though not a photo of the imaginary metacity shirt).

Nargery: I know not all of you read the Metacity blog, but I would like your feedback on this discussion of session management. Would you like the ~/.metacity directory to disappear? Who should ensure that applications’ windows are correctly positioned on restarting: the window manager? the toolkit? the applications themselves? nobody? Let us know!

Link soup:

And we’ll all go riding on a rainbow

I had been feeling vaguely ill and sore-throaty most of the week, and on Friday when I woke up and the back of my nose was painful enough that I couldn’t talk easily, I mailed in to say I was feeling sick. Then I decided I was well enough to come in as long as I stayed away from people and didn’t talk much, so I sent a second mail saying I was coming after all. It wasn’t so bad.

On Saturday, Amy and John came over and we went to the Frida Kahlo exhibition at the Art Museum. I will write about it, but not now, because I am too sleepy.

On Sunday we were going to go to church but woke up too late. Instead, I stayed home and fixed:

Do note that the Metacity blog is often more interesting than mine is. I think there should be a planet which mixes people and projects, but I don’t know what it would be called.

I have a bunch of automated tests for Metacity, many in Python, some in C. I want to put them together so that we can run them and have it report “5 out of 20 failed” or something, the same way Test::More and friends do in perl. Anyone have any recommendations for off-the-shelf ways of doing this before I write my own, which I’m happy to do?

And now a survey meme:
How and when did you learn to swim?

At RAF Henlow at the age of about, eh, seven-ish, with a (civilian) swim team called the Henlow Penguins who also ran lessons for youngsters. They appear not to exist any more.

How and when did you learn to drive?

I tried all my last year of sixth form and all my final year of university, without success.

How and when did you learn to tie your shoelaces?

I was probably eleven. I forget how I actually managed to learn in the end: I think it was one of the most complicated things I’d ever attempted, but it was that or go barefoot since there weren’t velcro trainers in sizes over ten years old. I remember one kid who was congenitally bald offered to tie my shoes in the green room when I had to wear lace-ups on stage, and when someone scoffed and said, “Why can’t you tie your shoes?” he glared at them and said, “Why can’t I grow hair?”

How and when did you learn to cook?

I learned enough to get by as a teenager, and enough to survive when I went away to college. I learned to bake as a child, but that’s not the same thing.

How and when did you learn to type?

Earlier than I can remember, probably at around four or five on a 1930s Remington typewriter that I got second-hand– I think it was because my grandfather didn’t need it any more. I loved that typewriter: its name was TW, and I used it to type out interminable stories. My mother (I assume) would sometimes come in and leave notes in the persona of the typewriter, signed “TW”.

Software we’d like to see, part six million: the Swamp

This arose from an IRC conversation which I was tangentially involved in, and I wanted to write down my thoughts while I ate my lunch. I am not a HCI person, so take it all with a pinch of salt. Also, all this has been said a thousand times before.

So.

1. You know what? I am tired of arguments about filechoosers. Nobody can get the things right and make everyone happy, and I think the reason for that is actually they assume you’re thinking about a small set of separate files where the set members don’t change very often, and which live in a hierarchy. That’s a bit like how programmers think of source code, which is probably why, but it’s not how most people think of documents. (Heck, I think it’s not how programmers think of most documents.) If you look at the documents directory or the desktop of most people, you’ll find a huge flat heap of files. You know we already have tools to deal with this sort of thing, but they only work for certain kinds of file (F-Spot lets you organise your thousands of photos by date and tags rather than by requiring you use hierarchical directories and filenames).

2. Yes, I know about Beagle. I still have to make up names for my documents and put them in a hierarchy.

3. Colin Walters mentioned in the IRC discussion that we could just make “File | Save” write stuff straight out to ~/Documents or whatever and not make people deal with having to slot it into a hierarchy at all. I would love this. Maybe turn it on in gconf or with an environment variable that could be set at login for certain users.

4. The trouble with this very good idea, of course, is that they then have to be able to find it again. So we let them search on metadata (yes, including <buzzword>tags</buzzword>) when they want to re-open the file. (Effectively that’s what they’re doing when they choose a filename like “email from Joe” so they they can find it again.) We have three kinds of metadata, though the difference should not be apparent to the user: there’s information gathered from the file like the height and width of an image (and some files formats can store arbitrary metadata internally), and there’s similar information which can be edited by the user and written back in, and then there’s information which must be stored externally to the actual file.

5. Where we actually store the data and metadata doesn’t matter. Ext2, maybe, with separate GKeyFiles for the metadata. Or maybe in a big SQLite database. I don’t mind, really. Maybe give people the option. Don’t ask users on installation or they’ll run a mile.

6. Using separate files raises the problem that all third-party solutions to the 8+3 character filename limit on MS-DOS had: you would always lose the data if you copied the file away. For this reason I’d rather not reuse an existing ~/Documents-type directory. Maybe call it ~/.swamp or something (I like the idea of a files floating around in the swamp and occasionally bubbling to the surface). Using one big file with tools to copy files in or out saves us that problem, of course.

7. Those of you thinking very fast will say, “If people don’t give a filename when they choose Save, then Save and Save As are the same thing, and that means there is no way to branch development of a document”. You are right, but you said the magic word, “branch”. Once user documents live in a controlled environment, there is no reason not to apply simple version control, which VMS has had since basically forever. Imagine how useful that would be! In fact, why are we requiring users to name files like programmers and not also automatically giving them the programmers’ advantage of putting their files under some distributed VCS?

This is just a thought-experiment, really.

I’ve had a number of people say they can’t comment on my GNOME blog; try clicking the number of comments and seeing whether that works. If it doesn’t, email me (tthurman at gnome). [Update: Might be working better now.]

Let me know when you make other posts about the subject (as I said on IRC, this is long on ranting and short on original content) and I’ll link them here. Or you could just pingback, of course.

planet as message board

alex-weej: I would like metacity and libwnck to share the window menu code. If Compiz is doing it already, hurrah. If you know more, more hurrah.

bkor: I am quite willing to release 2.21.21, but I don’t know what you want in it. There is no 2.21 branch because there are never branches named after odd-numbered versions. I am quite happy to make special branch, though, but from where? And what should go in after the branch? Or do you just want a copy of current trunk, or of the 2.23 branchpoint, with the numbers changed? And if so, why?

Session management and metacity (nargery)

Metacity has a directory ~/.metacity which it uses to store session state. When you log out of GNOME, Metacity stores away a bunch of data about the windows of session-managed applications so that when they start up again it can attempt to restore them. (For example, if you were running Epiphany maximised when you logged out, you probably want it to come up maximised when you log back in.) This is how it’s been done since the early days.

It has been pointed out in GNOME bug 518596 that using ~/.metacity for this purpose is contrary to the freedesktop specifications. This would mean that everyone’s home directory was slightly less cluttered. bkor and others are suggesting making this a Gnome Goal across the whole system.

The question then arises whether session state is a “config” or a “cache” file within the meaning of that specification. Window placement is “non-essential” and to some extent temporary, so perhaps it’s “cache”. On the other hand, it’s not information that can be regenerated with greater effort and is stored to save the trouble, and it is used in configuration, so perhaps it’s “config”. I am writing this post to ask you your opinions on the matter and to lazyweb for prior art.

If we do decide it’s cache, it’s possible we could avoid searching ~/.metacity if the file isn’t in ~/.cache/metacity. That’s good, because that step would stay with us for ever, and I doubt most people keep useful session management files around for more than a few months.

the snow, the rain, and the nasal bleed

Friday began with snow. Lots of snow. Nobody was willing to run the risk of driving me into work, so I stayed home and (as is usually the case if I get the chance to stay home) got a lot of work done.

Other than that, on Friday we went to the diner and ate some food. Then we went to buy Rio some shoes, and on the way we found a scarlet towel that Rio said she liked. The shop person said, “I have a towel like that at home. You’ll never guess what I like to put in it.” I said “What?” and bit my tongue to stop myself saying “Yourself naked?”, since although it seemed the obvious answer it was presumably not what was meant. (The answer was actually kitchen supplies in an entirely red and black kitchen.)

I also wrote a poem in a trochaic form I don’t usually use.

Welcome to the adult world!
Feel a clumsy failing fool.
Living is a tricky game,
Harder than they tell at school.

Every day beyond your means:
Hide it from the public view.
All around must never guess
What it is they’re hiding too.

Conquer bedrooms, conquer boardrooms,
Build your mountain to the sky.
Have a resume to die for:
When you get it, then you die.

Yet the children play in dirt,
Heedless of a pointless star:
“Never ask us what we’ll be:
Know that we already are”.

Conversation at the dinner table on Saturday:
Rio (eating the last of a tub of tin roof ice-cream): My ice-cream is crumby. I mean, I don’t think it’s crummy like it’s no good, it’s crumby like it has peanut crumbs in it.
Marn: But your ice-cream is also cool. I don’t mean like, whoah, it’s awesome, I mean cool like you got it out of the freezer.
Rio: That’s true.
Marn: And your ice-cream is also sweet. I don’t mean like sweet, like, SCHWEEET, I mean sweet like it contains sugar.
Rio: I don’t get it.
Fin: You didn’t grow up in the eighties.

I have also been refactoring Metacity’s parsing of gconf options, and it has been very satisfying to regularise the code. Other Metacity bugs I’m working on: GNOME bug 460018 and GNOME bug 509530. Moreover, I have been playing with launchpad; Gnusto is now known to launchpad and known to ohloh. I may add other such things later.

Conversation at the dinner table on Sunday:
Fin: So we’ll try to alternate beef and chicken.
Me: But we’re having pizza on Wednesday.
Alex: What are pepperonis, anyway? Is that cow meat?
Me: No, I think pig meat.
Alex: Wow, does that mean Jewish people can’t eat pepperoni pizzas?
Rio: I think they have to eat them because they have a rule that says they mustn’t.
Fin: That’s Discordianism, love, not Judaism.
Rio: Oh, yeah, like how they have to eat hot dog buns on a Friday.

Today Rio and I went to Alex’s church. Rio has a bit of a cold and was sniffling through the sermon, and a kindly Mother’s Union-type person (or whatever the RCs have instead) sitting behind us offered her a tissue. Shortly after the acclamation Rio attempted to kneel, slipped off the kneeler and hit her face on the pew in front. She bled copiously all over her clothes and hands. The Mother’s Union woman asked whether she was all right and handed us the whole packet! I asked Rio if she was okay to walk and she nodded, so we scrambled out of the building, down the stairs, past some Girl Scouts who appeared out of nowhere to shout “Girl Scout Cookies!” at us– we shouted “Nosebleed!” back at them. I think they were the boss monster– and we ran back to our house. Fin cleaned Rio up and soaked her clothes and I found her an icepack. She curled up and recuperated by watching every rerun of MythBusters she could find.

Link soup:

You can’t stop the waves, but you can learn to surf

Rio and Alex and I went to St Gabriel’s. The man who had served as the organist and choirmaster there for nineteen years died very suddenly the other week, and the place is still feeling shocked. Mother Donna Jean preached a rather interesting sermon on the parallels between the story of Abraham’s call and the story of Nicodemus. I asked her about other Johannine uses of the metaphor of night to represent the lack of understanding and she joked that I should be preaching next week; I said that was possibly the scariest thing anyone had said for a while. I was a little frustrated that the last hymn was one I didn’t know but the score for Cwm Rhondda was staring at me from the next page. (I am not responsible for that video.)

Later I finished writing a program to compile Metacity Journal entries: in other words, it goes around and finds bug activity, checkins of code and translations, mentions on blogs, and so on, and makes a blog post out of them. Here is the first output. I will be publishing the code, of course, but it will need a bit of tidying.

Later we all went for a walk in the park. Riordon stopped and said “I’ve got something in my shoe”, and when she took it off, balancing on one foot on the towpath, and shook it, out fell a US quarter, a US nickel, and a British 5p. I told her that she must have swept her hearth particularly well, according to the old rhyme. She said that she had actually been cleaning the floor in her room, but that she had been keeping shoes downstairs, and the good folk were hardly going to be able both to see her floor and examine her footwear.

After that we came home and I closed a ton of Metacity bugs.

“When I get a little money I buy books…” I have been wanting for a long time to read three particular books to Rio that I loved as a kid. They are: The Turbulent Term of Tyke Tyler by Gene Kemp, Nothing to be Afraid Of by Jan Mark, and I Like This Poem, which is an anthology edited by Kaye Webb. Amazon in the US doesn’t know TTTOTT, though it has the other two second-hand, which I don’t mind at all and indeed prefer in a lot of ways. Tonight I thought I’d order all three from Amazon in the UK; I was quite pleased to find that most of them were available for prices as low as a penny in some cases until I saw that shipping would be £20 to me in the US and £8 even to my parents in Hertfordshire. I think this must be the result of reasoning in a weak currency, because $20 to ship three books, or $40 overseas, seems rather excessive to me. Is that really what postage costs, and do any of you have advice or even an old copy of TTTOTT that you can send me in return for postage, gratitude, other trinkets, love, bug fixes, sonnets written praising you…? Update: My sister Mandy tells me that the book is called “Tyke Tiler” in the US, for obscure reasons, and it may therefore be findable after all.

Software we’d like to see: I have always been in slight awe of IMAP. It does everything POP3 does, everything SMTP does (and a lot better)[1], everything NNTP does, and it does its own useful things as well. You even could use it, if you were monomaniac enough, for a ton of other things, including as a replacement for FTP, or as an RPC transport. If some Emperor of the Internet was to decree tomorrow that henceforth nobody was to use POP3, even the people who only want what POP3 does could run IMAP and just only allow or only use its “recent” mode. Really, I think there are two things that puzzle me about it:

  • Why anyone is still using POP3, and more so, why they are still using SMTP.
  • Why everything-but-the-wire-protocol of IMAP is still travelling over a custom protocol and not REST. It seems to me as though it would mean we could reuse existing and well-tested code, it would mean you’d get all the existing bonuses of the HTTP protocol like its ubiquity and gateway support and so on, and the IMAP protocol is very REST-like already: it would be a pretty simple one-to-one mapping.

I haven’t seen anyone seriously suggest this, although Google showed me a thought-experiment as a teaching aid. If I was still working for an email provider I would suggest it, but I’m not.

[1] Ryan Lovett has pointed out that IMAP specifically doesn’t allow for sending mail, and he’s right: I misread the RFC and thought I saw something that wasn’t there. I’m sorry. I do think it should be included into a system such as the one I discuss above: something which allowed access to a group of messages/files over HTTP in the style of WebDAV (although possibly simpler), so that you could read and write and sort them into folders, and then also have a way to send them and to search for ones with flags like “recent”, would be a hugely useful grand unified protocol.

Webtoys
I fixed the “partlock” bug in Joule, which annoyed a small number of people a whole lot. Also, I thought you might be interested to see the usage of the cupid script:

The community was quite quiet this year compared to last, I think. I would show you the world map for just the script if I could figure out how to generate it. I can only seem to get Google Analytics to show maps for the whole site.

(Very brief) link soup:

(I apologise for those of you reading this on blogo/tthurman who think it clashes; I’m trying to make it look like marnanel.org and so far I’ve only got as far as playing with the CSS.)

Valentine’s and after

Valentine’s day was actually quite quiet for the most part. Our company gave us a bag of sweets, mostly those little love-heart ones which say things on them like EMAIL ME and YOU’RE THE BEST and CLOSE MY BUG((Not an actual example, sadly. Maybe we could make some GNOME sweets for next year.)), and chocolate hearts with mottos inside. My team lead was told “Be your own Valentine!” which sounds like a polite way of saying something else.

When we got home, Fin had made an amazing meal for all of us, each with our favourite thing to eat. Some of them had tomatoes and things cut into heart shapes. It must have taken ages.

I also discovered a not terribly obvious problem with GMail. I wrote a script which would tell you who had left you Valentine’s messages on LiveJournal, and it worked by turning on email notification, sending each LJ comment received to a GMail account, and every hour having a cronjob which read the account using IMAP, indexed them all in a Postgres database, and then having a cgi which could display search results. That was all very well, but on Valentine’s day itself, something inside GMail decided that the account was being used for IMAP in some kind of inappropriate way, and shut it down wth the error Lockdown in Sector 4! I disabled the cronjob, but it meant that some people didn’t see their valentine messages for another day or so.

On Friday it was pretty quiet again. I wrote a triolet.

Lines Written on the 15th of February

Today’s just a day
That’s not Valentine.
No roses, no wine.
Today’s just a day
I still want to say
I’m glad that you’re mine.
Today’s just a day
That’s not Valentine.

I also spent far too long trying to remember the visibility rules in GNOME bug 509165.

Link soup: