00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "Misc.h"
00011 #include <stdlib.h>
00012 #include <string.h>
00013
00014 int strip(char *dest, char c, int mode) {
00015 int x,y,l, retval=0;
00016
00017 if (mode>2) mode=2;
00018 if (mode<0) mode=0;
00019
00020 if (mode)
00021 {
00022 for (x=0; dest[strlen(dest)-1] == c; x++)
00023 dest[strlen(dest)-1] = 0;
00024 if (mode != 2) return(x);
00025 else retval = x;
00026 }
00027
00028
00029 if (!mode || mode==2)
00030 {
00031 l = strlen(dest);
00032 for (x=0 ;dest[0]==c; x++)
00033 for(y=0; y<l; y++)
00034 dest[y] = dest[y+1];
00035 }
00036 retval += x;
00037 return(retval);
00038 }
00039
00040
00041 int crstrip(char *dest)
00042 {
00043 int x=0;
00044
00045 while ( (dest[strlen(dest)-1] == 13) || (dest[strlen(dest)-1] == 10) )
00046 {
00047 dest[strlen(dest)-1] = 0;
00048 x++;
00049 }
00050 return(x);
00051 }
00052
00053
00054 int allocCpy(char **dest, char *src) {
00055 if (!(*dest = (char *)malloc(strlen(src)+1)))
00056 return(-1);
00057 strcpy(*dest, src);
00058 return(0);
00059 }
00060
00061
00062
00063 int getCmdIndex(const char **cmds, const char *myCmd) {
00064 for (int i = 0; cmds[i][0]; i++)
00065 if (!strcasecmp(myCmd, cmds[i]))
00066 return(i);
00067
00068 return -1;
00069 }
00070