There's no way of telling how many colorcells are unallocated.
Your program should work on both monochrome and color screens if possible using something like the following code.
Bool iscolor; Xcolor blue; iscolor = (XDisplayCells(display, screen)>2); foreground = (iscolor && XParsecolor(display,cmap, "blue",&blue) && XAllocColor(display,cmap, &blue)) ? blue.pixel : BlackPixel (display,screen));