Some suggested code for substring.c.
Add what looks okay, leave-out what doesn't seem okay.
1) Moved messages to one area - should allow for messages to be re-used. Could possibly add other languages by using #ifdef (hard-coded) or by inserting messages into arrays (load on demand).
2) Used << and >> for CPUs that don't have a divide or multiply (less code, plus faster for some CPUs).
3) Added a possible suggested way of dealing with UTF-8 at lines 42/43/44 by using if (c>=0)
Maybe better to code as if (c>=0 && ascii8bit) where ascii8bit=0 for UTF-8 and !=0 for ISO-885x text.