00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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 }