Add getScaledInt(char*) routine to faciliate switch argument scaling ease 
(-b32K or -l 1G).
Valid for switches -n, -l, -A, -O, -b

Signed-off-by: stan smith (stan.smith@intelcom)

--- tests/wsd/user/ttcp/ttcp.c  Mon Nov 15 12:57:28 2010
+++ tests/wsd/user/ttcp/ttcp.c  Mon Oct 24 14:02:17 2011
@@ -141,6 +141,38 @@
 double time_elapsed();
 char *outfmt();
 
+/*
+ * input a scaled (K, M or G) integer. Suitable for use with getopt.
+ *
+ * inputs:
+ *     *s      C string representing an interger value with optional Scale 
char.
+ *             'xK' imples x * 1024, 'xM' implies x*1024*1024,'xG' implies 
x*1024*1024*1024
+ *
+ * output:
+ *     binary integer representation.
+ */
+
+static int
+getScaledInt(char *s)
+{
+       int     val;
+       char *e;
+
+       val = strtol(s,&e,0);
+       if (e == NULL || *e =='\0')
+               return val;
+
+       if (*e == 'k' || *e == 'K')
+               val *= 1024;
+       else if (*e == 'm' || *e == 'M')
+               val *= 1024*1024;
+       else if (*e == 'g' || *e == 'G')
+               val *= 1024*1024*1024;
+
+       return val;
+}
+
+
 int __cdecl main(int argc, char **argv)
 {
        SYSTEMTIME time0, time1;
@@ -663,10 +695,10 @@
        #endif
                        break;
                case 'n':
-                       nbuf = atoi(optarg);
+                       nbuf = getScaledInt(optarg);
                        break;
                case 'l':
-                       buflen = atoi(optarg);
+                       buflen = getScaledInt(optarg);
                        break;
                case 'p':
                        port = (short)atoi(optarg);
@@ -675,14 +707,14 @@
                        udp = 1;
                        break;
                case 'A':
-                       bufalign = atoi(optarg);
+                       bufalign = getScaledInt(optarg);
                        break;
                case 'O':
-                       bufoffset = atoi(optarg);
+                       bufoffset = getScaledInt(optarg);
                        break;
                case 'b':
        #if defined(SO_SNDBUF) || defined(SO_RCVBUF)
-                       sockbufsize = atoi(optarg);
+                       sockbufsize = getScaledInt(optarg);
        #else
                        fprintf(stderr, 
        "ttcp: -b option ignored: SO_SNDBUF/SO_RCVBUF socket options not 
supported\n");

_______________________________________________
ofw mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw

Reply via email to