temp.c

Go to the documentation of this file.
00001 /*
00002  one line to give the program's name and an idea of what it does.
00003  Copyright (C) 2007  , 
00004 
00005  This program is free software; you can redistribute it and/or
00006  modify it under the terms of the GNU General Public License
00007  as published by the Free Software Foundation; either version 2
00008  of the License, or (at your option) any later version.
00009 
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  GNU General Public License for more details.
00014 
00015  You should have received a copy of the GNU General Public License
00016  along with this program; if not, write to the Free Software
00017  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 
00019  Filename:  temp.c
00020  
00021  Description:  
00022  
00023  Version:  1.0
00024  Created:  12/16/07 18:37:58 CET
00025  Revision:  none
00026  
00027  Author:   (), 
00028  License:  GPL 2.0
00029 */
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 
00034 void strip_string (char *);
00035 int get_n_token (char *s);
00036 int main (int argc, char **argv) 
00037 {
00038   int n = 0;
00039   printf ("argv[1] = %s (request)\n", argv[1]);
00040   printf ("argv[2] = %s (service)\n", argv[2]);
00041   
00042   n = strcmp (argv[1], argv[2]);
00043   if (n < 0) {
00044     printf ("less \n");
00045     if (!strcmp (argv[1], "/")) {
00046       printf ("object path /\n");
00047     } else {
00048       printf ("\n");
00049     }
00050       strip_string (argv[1]);
00051   } else if (n > 0) {
00052     printf ("greater \n");
00053   } else {
00054     printf ("equal \n");
00055   }
00056 
00057   return 0;
00058 }
00059 
00060 void strip_string (char *s) 
00061 {
00062   int i, n_token;
00063   int n = 0;
00064   char *n_s, *tmp;
00065   char *token;
00066   char **lt;
00067   printf ("S = %s\n", s);
00068   
00069   n = strlen(s) +1;
00070   tmp = (char *) malloc(n);
00071   memset (tmp, 0, n);
00072   memcpy (tmp, s, n);
00073   n_token = get_n_token (s);
00074   lt = (char **) malloc (sizeof (char *[n_token]));
00075   
00076   for (i = 0, token = strtok_r (tmp, "/", &n_s); token;
00077        token = strtok_r (n_s, "/", &n_s), i++) 
00078     lt[i] = token;
00079 
00080   for (i = 0; i < n_token; i++)
00081     printf ("token%d = %s\n", i, lt[i]);
00082   free (tmp);
00083   free (lt);
00084   printf ("S = %s, n = %d\n", s, i);
00085 }
00086 
00087 int get_n_token (char *s) 
00088 {
00089   int i, n;
00090   int l = strlen (s);
00091   printf ("l = %d\n", l);
00092   for (i = 0, n = 0; s[i] != '\0'; i++)
00093     if ((i != (l-1)) && s[i] == '/') n++;
00094   return n;
00095 }

Generated on Thu Apr 10 10:00:18 2008 for EasyDbus-0.2 by  doxygen 1.5.4