/* * utils * * Various miscellaneous (and largely non-WIMP) utility routines * * © 1993-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Steel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "stdio.h" #include "string.h" #include "ctype.h" #include "utils.h" #include "os.h" #include "werr.h" #include "wimpt.h" #include "swiv.h" #include "swis.h" #include "buffer.h" /* * int utils_caselessCmp(const char *s1,const char *s2) * * Use * Caseless comparison between string 1 and string 2 * * Parameters * const char *s1 == source string * const char *s2 == target string * * Returns * 0 if the strings are equal, >0 if s1>s2, or <0 if s1=300) return (_swi(Territory_Collate, _inr(0,3)+_return(0), -1,s1,s2,3)); else { char c1; char c2; while (*s1!='\0' || *s2!='\0') { c1=tolower(*(s1++)); c2=tolower(*(s2++)); if (c1!=c2) return (c1-c2); } return (0); } } /* * char *utils_ctermToNterm(char *s) * * Use * Changes a control-terminated string into a null-terminated string. * * Parameters * char *s == the string to change * * Returns * A pointer to the string. */ char *utils_ctermToNterm(char *s) { char *p; for (p=s;*p>31;p++) /* blank loop - all in for statement */; *p=0; return (s); } /* * char *utils_leafname(char *filename) * * Use * Returns the leafname of the file whose full pathname is given in * filename. * * Parameters * char *filename == pointer to full filename string * * Returns * Pointer to character after last '.' of string. */ char *utils_leafname(char *filename) { char *p=filename; while (*filename) { if (*(filename++)=='.') p=filename; } return (p); } /* * os_error *utils_complain(os error *e,char *string) * * Use * If e is an error (i.e. not NULL) then the routine calls werr() with * parameters (string,e->errmess). Ths string must contain a '%s' at some * point. * * Parameters * os_error *e == either NULL or a pointer to a standard system * error structure. * char *string == a string containing one %s, for which the error * message from the structure passed above will be substituted. * * Returns * The error pointer. */ os_error *utils_complain(os_error *e,char *string) { if (e) werr(FALSE,string,e->errmess); return (e); } /* * char *utils_cvtSize(int size) * * Use * Converts a size in bytes into a string suitable to display the size to * a user. It uses OS_ConvertFileSize to do he translation, although this * is not guaranteed for future versions. * * Parameters * int size == the size in bytes * * Returns * A pointer to the result (read-only) */ char *utils_cvtSize(int size) { char *buff=buffer_find(); _swix(XOS_ConvertFileSize,_inr(0,2),size,buff,16); return (buff); }