c-client callbacks

* This is mostly for personal copy-paste reasons

Those who take the time to develop applications using UW-IMAP (or Panda IMAP) know that there are a number of callbacks that need to be defined. What follows is the simplest (do nothing) version of them.

#include "c-client.h"

void
mm_flags(MAILSTREAM *stream,unsigned long number) {
}

void
mm_status(MAILSTREAM *stream,char *mailbox,MAILSTATUS *status) {
}

void
mm_searched(MAILSTREAM *stream,unsigned long number) {
}

void
mm_exists(MAILSTREAM *stream,unsigned long number) {
}

void
mm_expunged(MAILSTREAM *stream,unsigned long number) {
}

void
mm_list(MAILSTREAM *stream,int delimiter,char *name,long attributes) {
}

void
mm_lsub(MAILSTREAM *stream,int delimiter,char *name,long attributes) {
}

void
mm_notify(MAILSTREAM *stream,char *string,long errflg) {
}

void
mm_log(char *string,long errflg) {
}


void
mm_dlog(char *string) {
}

void
mm_login(NETMBX *mb,char *user,char *pwd,long trial) {
}

void
mm_critical(MAILSTREAM *stream) {
}

void
mm_nocritical(MAILSTREAM *stream) {
}

long
mm_diskerror(MAILSTREAM *stream,long errcode,long serious) {
}

void
mm_fatal(char *string) {
}

on lisp and pseudocode

Remember that it is written in “The Roots of Lisp” that:

If you want a language for describing algorithms, you might want something more abstract, and that was one of McCarthy’s aims in defining Lisp.

It was only after Steve Russell programmed eval (in machine code) that Lisp became a tool for the keyboard rather than a tool for pen and paper.

decreasoner on OpenBSD

decreasoner is a Discrete Event Calculus reasoner written by Erik T. Mueller (author of “Commonsense Reasoning“). This is how I build it on OpenBSD 4.7:

  • tar zxf ply-3.3.tar.gz
  • tar zxf decreasoner.tar.gz
  • cd decreasoner/software/relsat-dist/
  • tar zxf ../../../relsat_2.02.tar
  • gmake -f Makefile.linux
  • cp ./relsat ../../solvers/
  • cd ../..
  • cp ../ply-3.3/ply/lex.py .
  • cp ../ply-3.3/ply/yacc.py .
  • decreasoner.py executes sort -g. Unfortunatelly, OpenBSD’s sort does not support a -g switch and you have to change it to -n. See also a discussion of sort -g vs sort -n.
  • ./make.sh

Someday I think I may contribute a script that may (semi)automate the above…

C interpreters

I spotted today on Hacker News an article about PicoC, a small C interpreter. This triggered my memory in a journey back in 1994 when I had asked over at comp.compilers whether any C interpreter existed. It was then that I learned about ICI, a cool C-like scripting language that deserves more attention, the Quincy C interpreter which evolved to an IDE, and Smac, the C-like
interpreter that comes embedded with the XCoral editor.

Then there are also CINT which is part of an even more interesting project, and of course Ch.

But the coolest interpreter that I’ve seen, is written by Diomidis Spinellis:

#include "/dev/tty"

It changed the rules for the IOCCC.

loop

for (i = 0; i < strlen(string); i++) {
  :
}

This is a C version of a loop that I recently bumped into while copy-pasting some code. In the above loop strlen(string) is called strlen(string) times instead of just once (unless the length of string changes while in the loop):

int len;
:
len = strlen(string);
for (i = 0; i < len; i++) {
  :
}

Unless the compiler detects this and optimizes the loop, this is very bad practice. Yes, most of the compilers do detect this, but this does not mean that the programmer must rely on the compiler's optimizations. What if it does not get optimized in the end?

This is not a rant about wasted CPU cycles. It is mostly a rant about laziness in our thinking.

The Slow Loop

Greenspun’s Tenth Rule and variations

For those who have not heard Greenspun’s Tenth Rule, it states that:

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

By the way, Greenspun‘s rules 1 to 9 do not exist.

Seven months ago, during a discussion about Prolog, I asked Ozan S. Yigit to reformulate Greenspun’s tenth rule for Prolog. Oz replied:

Any sufficiently complicated modern program contains a buggy, informal implementation of prolog that casual observers confuse with lisp.

Just hours earlier I was basically a listener in a discussion that involved NoSQL. While clearly I am not a NoSQL advocate, I am no hater either, but what I heard lead me to the following reformulation of Greenspun’s rule, this time involving the relational model:

Those who blindly adopt #NoSQL will discover a variation of Greenspun’s tenth rule

I am sure that many other variations exist. In fact the Wikipedia page on Greenspun’s Tenth Rule contains a Prolog variation similar to Ozan’s and an Erlang version. So if you know of (or can make up) any other, please post it here (or somewhere).

Stateful protocols

Mark Crispin writes:

“In particular, doing things with mailboxes in the hundreds of MB in that format takes a while. The authors of Outlook and Thunderbird are victims of a computer science course mindset which, starting in the 1980s, taught their pupils that all protocols are (or should be) stateless. Thus, they believe that IMAP is like HTTP; that when a server fails to respond immediately, that means that the correct remedial action is to disconnect and try again, or just disconnect and assume that everything happened anyway.”

[via imap-uw]

system error 1326

Note to self: When CreateProcessWithLogonW returns a 1326 system error (login error basicaly), you can always spawn Sysinternals’ PsExec.

While RunAs accepts the Administrator’s password from the terminal input by design, PsExec accepts it from a command line switch, which means that the source for the password can be the terminal, a file (encrypted symmetrically or not), a window application, etc. Way more flexible, but potentially insecure, especially if the administrator password is stored somewhere in the filesystem unencrypted.