Hi,

I polished the patch a bit. I found one additional problem; also `-s'
was already in use by both s2disk and s2ram. This let me to decide not
to allow any short options for the `s2ram hacks' in s2both. For s2ram
they are still supported. If however we would start using the usage
function from config.c for s2ram too, they will not show up. This is
maybe a good thing even.

OK to commit?

Index: s2ram.c
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.c,v
retrieving revision 1.51
diff -u -r1.51 s2ram.c
--- s2ram.c     16 Mar 2007 15:03:08 -0000      1.51
+++ s2ram.c     2 Apr 2007 11:29:25 -0000
@@ -25,10 +25,10 @@
 static struct pci_dev vga_dev;
 static struct pci_access *pacc;
 /* Flags set from whitelist */
-static int flags, vbe_mode = -1;
+static int flags = 0, force = 0, vbe_mode = -1;
 char bios_version[1024], sys_vendor[1024], sys_product[1024], 
sys_version[1024];
 
-/* return codes for s2ram_prepare */
+/* return codes for s2ram_is_supported */
 #define S2RAM_OK       0
 #define S2RAM_FAIL     1
 #define S2RAM_NOFB     126
@@ -229,18 +229,21 @@
        return 0;
 }
 
-int s2ram_prepare(void)
+int s2ram_is_supported(void)
 {
-       int ret, id;
+       int ret = 0, id;
 
-       dmi_scan();
-       id = machine_match();
-       ret = s2ram_check(id);
-
-       if (ret)
-               return ret;
+       if (flags && !force) {
+               printf("acpi_sleep, vbe_save, vbe_post, radeontool and pci_save"
+                       " parameter must be used with --force\n\n");
+               return EINVAL;
+       }
 
-       ret = s2ram_hacks();
+       if (!force) {
+               dmi_scan();
+               id = machine_match();
+               ret = s2ram_check(id);
+       } 
 
        return ret;
 }
@@ -299,6 +302,43 @@
        }
 }
 
+void s2ram_add_flag(int opt, const char *opt_arg)
+{
+       /* The characters are the `deprecated' short options. They will not
+        * clash with the new labels untill we reach quirk 65... */
+       switch (opt) {
+               case 1:
+               case 'f':
+                       force = 1;
+                       break;
+               case 2:
+               case 's':
+                       flags |= VBE_SAVE;
+                       break;
+               case 3:
+               case 'p':
+                       flags |= VBE_POST;
+                       break;
+               case 4:
+               case 'm':
+                       flags |= VBE_MODE;
+                       break;
+               case 5:
+               case 'r':
+                       flags |= RADEON_OFF;
+                       break;
+               case 6:
+               case 'v':
+                       flags |= PCI_SAVE;
+                       break;
+               case 7:
+               case 'a':
+                       flags |= (atoi(optarg) & (S3_BIOS | S3_MODE));
+                       break;
+
+       }
+}
+
 #ifndef CONFIG_BOTH
 static void usage(void)
 {
@@ -328,23 +368,17 @@
 
 int main(int argc, char *argv[])
 {
-       int i, id = -1, ret = 0, test_mode = 0, force = 0;
+       int i, id = -1, ret = 0, test_mode = 0;
        int active_console = -1;
        struct option options[] = {
                { "test",       no_argument,            NULL, 'n'},
                { "help",       no_argument,            NULL, 'h'},
-               { "force",      no_argument,            NULL, 'f'},
-               { "vbe_save",   no_argument,            NULL, 's'},
-               { "vbe_post",   no_argument,            NULL, 'p'},
-               { "vbe_mode",   no_argument,            NULL, 'm'},
-               { "radeontool", no_argument,            NULL, 'r'},
                { "identify",   no_argument,            NULL, 'i'},
-               { "acpi_sleep", required_argument,      NULL, 'a'},
-               { "pci_save",   no_argument,            NULL, 'v'},
+               HACKS_LONG_OPTS
                { NULL,         0,                      NULL,  0 }
        };
 
-       while ((i = getopt_long(argc, argv, "nhfspmriva:", options, NULL)) != 
-1) {
+       while ((i = getopt_long(argc, argv, "nhi" "fspmrva:", options, NULL)) 
!= -1) {
                switch (i) {
                case 'h':
                        usage();
@@ -356,48 +390,27 @@
                case 'n':
                        test_mode = 1;
                        break;
-               case 'f':
-                       force = 1;
-                       break;
-               case 's':
-                       flags |= VBE_SAVE;
-                       break;
-               case 'p':
-                       flags |= VBE_POST;
-                       break;
-               case 'm':
-                       flags |= VBE_MODE;
-                       break;
-               case 'r':
-                       flags |= RADEON_OFF;
-                       break;
-               case 'a':
-                       flags |= (atoi(optarg) & (S3_BIOS | S3_MODE));
-                       break;
-               case 'v':
-                       flags |= PCI_SAVE;
+               case '?':
+                       usage();
                        break;
                default:
-                       usage();
+                       s2ram_add_flag(i,optarg);
                        break;
                }
        }
-       if (flags && !force) {
-               printf("acpi_sleep, vbe_save, vbe_post and radeontool parameter 
"
-                      "must be used with --force\n\n");
-               usage();
-       }
+
        if (force && test_mode) {
                printf("force and test mode do not make sense together.\n\n");
                usage();
        }
 
-       if (!force) {
-               dmi_scan();
-               id = machine_match();
-               ret = s2ram_check(id);
+       if (test_mode) {
+               machine_known(id);
+               goto out;
        }
 
+       ret = s2ram_is_supported();
+
        if (ret == S2RAM_UNKNOWN) {
                printf("Machine is unknown.\n");
                identify_machine();
@@ -407,11 +420,6 @@
        if (ret == S2RAM_NOFB)
                printf("This machine can only suspend without framebuffer.\n");
 
-       if (test_mode) {
-               machine_known(id);
-               goto out;
-       }
-
        if (ret)
                goto out;
 
Index: s2ram.h
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.h,v
retrieving revision 1.4
diff -u -r1.4 s2ram.h
--- s2ram.h     28 Mar 2006 13:16:21 -0000      1.4
+++ s2ram.h     2 Apr 2007 11:29:25 -0000
@@ -15,6 +15,18 @@
 /* from s2ram.c */
 int s2ram_check(int id);
 int s2ram_hacks(void);
-int s2ram_prepare(void);
+int s2ram_is_supported(void);
 int s2ram_do(void);
 void s2ram_resume(void);
+void s2ram_add_flag(int opt, const char *arg);
+
+#define HACKS_LONG_OPTS \
+               { "force",      no_argument,            NULL, 1}, \
+               { "vbe_save",   no_argument,            NULL, 2}, \
+               { "vbe_post",   no_argument,            NULL, 3}, \
+               { "vbe_mode",   no_argument,            NULL, 4}, \
+               { "radeontool", no_argument,            NULL, 5}, \
+               { "pci_save",   no_argument,            NULL, 6}, \
+               { "acpi_sleep", required_argument,      NULL, 7},
+
+
Index: suspend.c
===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.73
diff -u -r1.73 suspend.c
--- suspend.c   1 Apr 2007 22:03:29 -0000       1.73
+++ suspend.c   2 Apr 2007 11:29:25 -0000
@@ -1174,6 +1174,9 @@
                { "config",             required_argument,      NULL, 'f'},
                { "image_size",         required_argument,      NULL, 's'},
                { "resume_offset",      required_argument,      NULL, 'o'},
+#ifdef CONFIG_BOTH
+               HACKS_LONG_OPTS
+#endif
                { NULL,                 0,                      NULL,  0 }
        };
        int i, error;
@@ -1182,7 +1185,7 @@
        unsigned long long int off = 0;
        int set_size = 0;
        unsigned long int im_size = 0;
-       const char *optstring="hf:s:o:";
+       const char *optstring = "hf:s:o:";
 
        while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
                switch (i) {
@@ -1200,11 +1203,29 @@
                        off = atoll(optarg);
                        set_off = 1;
                        break;
-               default:
+               case '?':
                        usage("suspend", options, optstring);
                        return -EINVAL;
+#ifdef CONFIG_BOTH
+               default:
+                       s2ram_add_flag(i,optarg);
+                       break;
+#endif
                }
        }
+
+#ifdef CONFIG_BOTH
+       s2ram = s2ram_is_supported();
+       /* s2ram_is_supported returns EINVAL if there was something wrong
+        * with the options that where added with s2ram_add_flag.
+        * On any other error (unsupported) we will just continue with s2disk.
+        */
+       if (s2ram == EINVAL)
+               return EINVAL;
+       
+       s2ram = !s2ram;
+#endif
+
        error = parse("suspend", conf_name, PARAM_NO, parameters);
        if (error) {
                fprintf(stderr, "suspend: Could not parse config file\n");
@@ -1390,8 +1411,9 @@
        splash.progress(5);
 
 #ifdef CONFIG_BOTH
-       /* If s2ram_prepare returns != 0, better not try to suspend to RAM */
-       s2ram = !s2ram_prepare();
+       /* If s2ram_hacks returns != 0, better not try to suspend to RAM */
+       if (s2ram) 
+               s2ram = !s2ram_hacks();
 #endif
 #ifdef CONFIG_ENCRYPT
         if (encrypt && ! use_RSA) {

Attachment: signature.asc
Description: PGP signature

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to