Not a bad little exercise. Program seems to work fine (only did a few tests), but according to your README, some URLs get garbled. Can you give some examples? As far as my advice, it's mostly suggestions and style stuff:
Code:
typedef char *String;
My personal preference is to not mask pointerness with a typedef, especially for something trivial like this. Just use char *. Any halfway decent programmer will understand you mean it as a string. Besides, you don't always want to allocate memory via malloc for a string (see below).
Code:
s = (String)malloc(SSIZE * sizeof(char));
Don't cast malloc.
Code:
String ping_call(String);/* converts hostname to IP address with ping */
String dig_call(String);/* converts hostname to IP address with dig +short */
String lookformore(String);/* after HREF, look for ICON_URI and SHORTCUTURL */
Don't place protocols inside functions. It's bad style and makes code hard to read. Put them at the top of the file if they're only used in that .c file (in which case they should be static functions), or put them in a header file if they are to be used outside that .c file.
Code:
/* hopefully this switch statement will save useless overhead in calling good_URI_scheme */
This is probably pre-optimization, which is the root of all evil. You're trading a function call for some comparisons and jumps, the difference in number of CPU cycles is negligible. It probably doesn't speed anything up by a measurable amount and it makes your code harder to read and maintain. This certainly isn't your bottleneck either (which is where you should focus your optimization efforts if you need it). Your bottleneck would most likely be the popen/ping/dig calls. Everything else is plenty fast.
Code:
int good_URI_scheme(String s)
{
if ( strlen(s) < 6 )
return(0);
if ( strncmp(s, "http://", 7) == 0 )
return(1);
else if ( strncmp(s, "https://", 8) == 0 )
return(2);
else if ( strncmp(s, "ftp://", 6) == 0 )
return(3);
else
return(0);/* unlisted URI scheme */
}
The strlen only saves you time in the off chance somebody has a bookmark entry with less than 6 chars. For every other case, it costs you extra cycles (if you're that concerned with speed). Let the strncmp calls handle it. Also, if there is (or will be) significance to the return value of good_URI_scheme, you should avoid returning magic numbers like 1, 2 and 3. Instead, return a symbolic constant, like URI_SCHEME_HTTP (you can declare a const int or #define it).
More magic juju. Avoid cryptic statements like this and replace these with appropriate constants like PING_RESULT_LEN and DIG_RESULT_LEN.
Code:
String t = (String)malloc((SSIZE + 21) * sizeof(char));
If you're going to have fixed-length strings, just use a char t[PING_RESULT_LEN+1]; so you don't have to worry about malloc failing or remembering to free the memory when you're done.