[ETC] saving getopt.c with DOS End-Of-Line instead of Linux EOL
authorstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 13 Nov 2008 01:52:04 +0000 (01:52 +0000)
committerstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 13 Nov 2008 01:52:04 +0000 (01:52 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1757 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

etc/user/getopt.c

index 045f665..a5e3022 100644 (file)
-/*
- * Copyright (c) 2005 Mellanox Technologies.  All rights reserved.
- * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 
- *
- * This software is available to you under the OpenIB.org BSD license
- * below:
- *
- *     Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *      - Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *
- *      - Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "getopt.h"
-
-char *optarg;
-int optind = 1;
-int opterr = 1;
-int optopt = '?';
-
-int getopt(int argc, char **argv, char *opts)
-{
-       char *loc;
-
-       optarg = NULL;
-
-       if (optind == argc) {
-               return EOF;
-       }
-
-       if (argv[optind][0] != '-') {
-               return EOF;
-       }
-
-       if (!strcmp(argv[optind], "--")) {
-               optind++;
-               return EOF;
-       }
-
-       optopt = argv[optind][1];
-
-       loc = strchr(opts, optopt);
-       if (loc == NULL) {
-               return EOF;
-       }
-
-       if (loc[1] != ':') {
-               goto out;
-       }
-
-       if (argv[optind][2] != '\0') {
-               optarg = &argv[optind][2];
-               goto out;
-       }
-
-       if ((optind + 1 == argc) || (argv[optind + 1][0] == '-')) {
-               if (loc[2] != ':') {
-                       return EOF; 
-               }
-       } else {
-               optarg = argv[++optind];
-       }
-
-out:
-       optind++;
-       return optopt;
-}
-
-int getopt_long(int argc, char **argv, char *opts,
-                               struct option *longopts, int *longindex)
-{
-       char arg[256];
-       char *str;
-       int i;
-
-       if (optind == argc) {
-               return EOF;
-       }
-
-       if (argv[optind][0] != '-') {
-               return EOF;
-       }
-
-       if (!strcmp(argv[optind], "--")) {
-               optind++;
-               return EOF;
-       }
-
-       if (argv[optind][1] != '-') {
-               return getopt(argc, argv, opts);
-       }
-
-       strcpy(arg, &argv[optind][2]);
-       str = strtok(arg, "=");
-
-       for (i = 0; longopts[i].name; i++) {
-
-               if (strcmp(str, longopts[i].name)) {
-                       continue;
-               }
-
-               if (longindex != NULL) {
-                       *longindex = i;
-               }
-
-               if (longopts[i].flag != NULL) {
-                       *(longopts[i].flag) = longopts[i].val;
-               }
-
-               switch (longopts[i].has_arg) {
-               case required_argument:
-                       optarg = strtok(NULL, "=");
-                       if (optarg != NULL) {
-                               break;
-                       }
-
-                       if (++optind == argc || argv[optind][0] == '-') {
-                               return '?';
-                       }
-
-                       optarg = argv[optind];
-                       break;
-               case optional_argument:
-                       optarg = strtok(NULL, "=");
-                       if (optarg != NULL) {
-                               break;
-                       }
-
-                       if (optind + 1 == argc || argv[optind + 1][0] == '-') {
-                               break;
-                       }
-
-                       optarg = argv[++optind];
-                       break;
-               default:
-                       break;
-               }
-
-               optind++;
-               if (longopts[i].flag == 0) {
-                       return (longopts[i].val);
-               } else {
-                       return 0;
-               }
-       }
-       return '?';
-}
+/*\r
+ * Copyright (c) 2005 Mellanox Technologies.  All rights reserved.\r
+ * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. \r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "getopt.h"\r
+\r
+char *optarg;\r
+int optind = 1;\r
+int opterr = 1;\r
+int optopt = '?';\r
+\r
+int getopt(int argc, char **argv, char *opts)\r
+{\r
+       char *loc;\r
+\r
+       optarg = NULL;\r
+\r
+       if (optind == argc) {\r
+               return EOF;\r
+       }\r
+\r
+       if (argv[optind][0] != '-') {\r
+               return EOF;\r
+       }\r
+\r
+       if (!strcmp(argv[optind], "--")) {\r
+               optind++;\r
+               return EOF;\r
+       }\r
+\r
+       optopt = argv[optind][1];\r
+\r
+       loc = strchr(opts, optopt);\r
+       if (loc == NULL) {\r
+               return EOF;\r
+       }\r
+\r
+       if (loc[1] != ':') {\r
+               goto out;\r
+       }\r
+\r
+       if (argv[optind][2] != '\0') {\r
+               optarg = &argv[optind][2];\r
+               goto out;\r
+       }\r
+\r
+       if ((optind + 1 == argc) || (argv[optind + 1][0] == '-')) {\r
+               if (loc[2] != ':') {\r
+                       return EOF; \r
+               }\r
+       } else {\r
+               optarg = argv[++optind];\r
+       }\r
+\r
+out:\r
+       optind++;\r
+       return optopt;\r
+}\r
+\r
+int getopt_long(int argc, char **argv, char *opts,\r
+                               struct option *longopts, int *longindex)\r
+{\r
+       char arg[256];\r
+       char *str;\r
+       int i;\r
+\r
+       if (optind == argc) {\r
+               return EOF;\r
+       }\r
+\r
+       if (argv[optind][0] != '-') {\r
+               return EOF;\r
+       }\r
+\r
+       if (!strcmp(argv[optind], "--")) {\r
+               optind++;\r
+               return EOF;\r
+       }\r
+\r
+       if (argv[optind][1] != '-') {\r
+               return getopt(argc, argv, opts);\r
+       }\r
+\r
+       strcpy(arg, &argv[optind][2]);\r
+       str = strtok(arg, "=");\r
+\r
+       for (i = 0; longopts[i].name; i++) {\r
+\r
+               if (strcmp(str, longopts[i].name)) {\r
+                       continue;\r
+               }\r
+\r
+               if (longindex != NULL) {\r
+                       *longindex = i;\r
+               }\r
+\r
+               if (longopts[i].flag != NULL) {\r
+                       *(longopts[i].flag) = longopts[i].val;\r
+               }\r
+\r
+               switch (longopts[i].has_arg) {\r
+               case required_argument:\r
+                       optarg = strtok(NULL, "=");\r
+                       if (optarg != NULL) {\r
+                               break;\r
+                       }\r
+\r
+                       if (++optind == argc || argv[optind][0] == '-') {\r
+                               return '?';\r
+                       }\r
+\r
+                       optarg = argv[optind];\r
+                       break;\r
+               case optional_argument:\r
+                       optarg = strtok(NULL, "=");\r
+                       if (optarg != NULL) {\r
+                               break;\r
+                       }\r
+\r
+                       if (optind + 1 == argc || argv[optind + 1][0] == '-') {\r
+                               break;\r
+                       }\r
+\r
+                       optarg = argv[++optind];\r
+                       break;\r
+               default:\r
+                       break;\r
+               }\r
+\r
+               optind++;\r
+               if (longopts[i].flag == 0) {\r
+                       return (longopts[i].val);\r
+               } else {\r
+                       return 0;\r
+               }\r
+       }\r
+       return '?';\r
+}\r