Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

Misc.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////
00002 /*! \file Misc.cpp
00003  *  \brief Miscellaneous utility functions (not hardware utilities)
00004  *  \author     $Author: rsharo $
00005  *  \version $Revision: 1.3 $
00006  *  \date    $Date: 2003/11/01 21:00:16 $
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 /* Provides uniform word lookup functionality. */
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; // Return -1 if not found
00069 }
00070 

Generated on Wed Sep 5 12:54:22 2007 for DSACSS Operational Code by  doxygen 1.3.9.1