Rimetto quello che avevo levato
[gapil.git] / sources / getparam.c
diff --git a/sources/getparam.c b/sources/getparam.c
new file mode 100644 (file)
index 0000000..5619c1f
--- /dev/null
@@ -0,0 +1,194 @@
+/* getparam.c
+ * 
+ * Copyright (C) 2002 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/****************************************************************
+ *
+ * Program getparam.c: 
+ * Program to test function fopen
+ *
+ * Author: Simone Piccardi
+ * Jan. 2002
+ *
+ * Usage: getparam -h give all info's
+ *
+ * $Id: getparam.c,v 1.3 2003/05/02 09:55:14 piccardi Exp $
+ *
+ ****************************************************************/
+/* 
+ * Include needed headers
+ */
+#define _GNU_SOURCE
+#include <errno.h>       /* error definitions and routines */ 
+#include <stdlib.h>      /* C standard library */
+#include <unistd.h>      /* unix standard library */
+#include <string.h>      /* string functions */
+#include <limits.h>
+#include <stdio.h>
+
+
+#include <time.h>        /* for CLK_TCK e CLOCKS_PER_SEC */
+
+/* Table of constants for sysconf() */
+char *sc_names[]={"_SC_ARG_MAX",
+                 "_SC_CHILD_MAX",
+                 "_SC_OPEN_MAX",
+                 "_SC_STREAM_MAX",
+                 "_SC_TZNAME_MAX",
+                 "_SC_NGROUPS_MAX",
+                 "_SC_SSIZE_MAX",
+                 "_SC_CLK_TCK",
+                 "_SC_JOB_CONTROL",
+                 "_SC_SAVED_IDS",
+                 "_SC_VERSION"};
+
+int sc_argument[]={_SC_ARG_MAX,
+                  _SC_CHILD_MAX,
+                  _SC_OPEN_MAX,
+                  _SC_STREAM_MAX,
+                  _SC_TZNAME_MAX,
+                  _SC_NGROUPS_MAX,
+                  _SC_SSIZE_MAX,
+                  _SC_CLK_TCK,
+                  _SC_JOB_CONTROL,
+                  _SC_SAVED_IDS,
+                  _SC_VERSION};
+
+/* 
+   Set the defined[] array to true if the macro is defined else set it
+   to false and define the macro to -1 as a marker
+*/
+int defined[]={
+#ifdef  ARG_MAX
+    1,
+#else
+#define ARG_MAX               -1  
+    0,
+#endif
+#ifdef  CHILD_MAX
+    1,
+#else
+#define CHILD_MAX             -1
+    0,
+#endif
+#ifdef  OPEN_MAX
+    1,
+#else
+#define OPEN_MAX              -1 
+    0,
+#endif
+#ifdef  STREAM_MAX
+    1,
+#else
+#define STREAM_MAX            -1
+    0,
+#endif
+#ifdef  NGROUPS_MAX
+    1,
+#else
+#define NGROUPS_MAX           -1
+    0,
+#endif
+#ifdef  TZNAME_MAX
+    1,
+#else
+#define TZNAME_MAX            -1
+    0,
+#endif
+#ifdef  SSIZE_MAX
+    1
+#else
+#define SSIZE_MAX             -1
+    0
+};
+
+
+
+/* values of stadard macros */
+long values[]={ARG_MAX, 
+              CHILD_MAX,
+              OPEN_MAX,
+              STREAM_MAX,
+              TZNAME_MAX,
+              NGROUPS_MAX,
+              SSIZE_MAX,
+              CLOCKS_PER_SEC,
+              _POSIX_JOB_CONTROL,
+              _POSIX_SAVED_IDS,
+              _POSIX_VERSION};
+
+/* Help printing routine */
+void usage(void);
+
+int main(int argc, char *argv[])
+{
+/* 
+ * Variables definition  
+ */
+    int i;
+    /*
+     * Input section: decode command line parameters 
+     * Use getopt function
+     */
+    opterr = 0;         /* don't want writing to stderr */
+    while ( (i = getopt(argc, argv, "h")) != -1) {
+       switch (i) {
+       /* 
+        * Handling options 
+        */ 
+       case 'h':   /* help option */
+           printf("Wrong -h option use\n");
+           usage();
+           return -1;
+           break;
+       case '?':   /* unrecognized options */
+           printf("Unrecognized options -%c\n",optopt);
+           usage();
+       default:    /* should not reached */
+           usage();
+       }
+    }
+    /* ***********************************************************
+     * 
+     *          Options processing completed
+     *
+     *               Main code beginning
+     * 
+     * ***********************************************************/
+    /* There must be 2 remaing parameters */
+    if ( (argc-optind) != 1 )  {
+       printf("From %d arguments, removed %d options\n", argc, optind);
+       usage();
+    }
+    for (i=0; i<=4; i++) {
+       printf("Response for %s is %ld, values is %ld\n", names[i], 
+              sysconf(argument[i]), values[i]);
+    }
+    return 0;
+}
+/*
+ * routine to print usage info and exit
+ */
+void usage(void) {
+    printf("Program testfopen : test fopen for a file  \n");
+    printf("Usage:\n");
+    printf("  testfopen [-h] file mode \n");
+    printf("  -h          print this help\n");
+    
+    exit(1);
+}
+