util.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*+-------------------------------------------------------------------------
  2. util.c
  3. wht@wht.net
  4. --------------------------------------------------------------------------*/
  5. /*+:EDITS:*/
  6. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  7. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  8. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  9. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  10. /*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  11. /*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  12. /*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  13. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  14. /*+-------------------------------------------------------------------------
  15. all touuper/tolower not created equally, so this works!
  16. --------------------------------------------------------------------------*/
  17. char
  18. to_upper(ch)
  19. register int ch;
  20. {
  21. return (((ch >= 'a') && (ch <= 'z')) ? ch - 0x20 : ch);
  22. } /* end of to_upper() */
  23. char
  24. to_lower(ch)
  25. register int ch;
  26. {
  27. return (((ch >= 'A') && (ch <= 'Z')) ? ch + 0x20 : ch);
  28. } /* end of to_lower() */
  29. /*+-----------------------------------------------------------------------
  30. pad_zstr_to_len(zstr,len)
  31. pads with spaces to specified length, unless already longer than
  32. len in which case the string is truncated to 'len' characters.
  33. ------------------------------------------------------------------------*/
  34. void
  35. pad_zstr_to_len(zstr, len)
  36. char *zstr;
  37. int len;
  38. {
  39. register int izstr;
  40. izstr = strlen(zstr);
  41. if (izstr >= len)
  42. zstr[len] = 0;
  43. else
  44. {
  45. while (izstr < len)
  46. zstr[izstr++] = 0x20;
  47. zstr[izstr] = 0;
  48. }
  49. } /* end of pad_zstr_to_len */