On Friday, 3 August 2007 01:18, Alon Bar-Lev wrote:
>
> 1. Move main() out of s2ram.c into s2ram-main.c, this will enable s2ram.o to
> be included
> in both s2ram and s2both without recompilation.
>
> 2. Split whitelist.c into whitelist.h/whitelist.c as including .c is none
> standard/unsupported.
These changes have to be looked at by Pavel and Stefan.
Greetings,
Rafael
> ---
>
> diff -urNp suspend.org/s2ram.c suspend-0.6_beta1/s2ram.c
> --- suspend.org/s2ram.c 2007-06-17 23:51:30.000000000 +0300
> +++ suspend-0.6_beta1/s2ram.c 2007-08-02 17:36:49.000000000 +0300
> @@ -42,82 +43,3 @@ int s2ram_generic_do(void)
> return ret;
> }
>
> -#ifndef CONFIG_BOTH
> -int main(int argc, char *argv[])
> -{
> - int i, ret = 0;
> - int active_console = -1;
> - struct option options[] = {
> - {
> - "help\0\tthis text.",
> - no_argument, NULL, 'h'
> - },
> - {
> - "test\0\ttest if the machine is in the database.",
> - no_argument, NULL, 'n'
> - },
> - {
> - "identify\0prints a string that identifies the machine.",
> - no_argument, NULL, 'i'
> - },
> - HACKS_LONG_OPTS
> - { NULL, 0, NULL, 0 }
> - };
> - const char *optstring = "hni" "fspmrva:";
> -
> - while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
> - switch (i) {
> - case 'h':
> - usage("s2ram", options, optstring);
> - exit(0);
> - case 'i':
> - identify_machine();
> - exit(0);
> - case 'n':
> - ret = machine_known();
> - exit(ret);
> - case '?':
> - usage("s2ram", options, optstring);
> - exit(1);
> - break;
> - default:
> - s2ram_add_flag(i,optarg);
> - break;
> - }
> - }
> -
> - ret = s2ram_is_supported();
> -
> - if (ret == S2RAM_UNKNOWN) {
> - printf("Machine is unknown.\n");
> - identify_machine();
> - goto out;
> - }
> -
> - if (ret == S2RAM_NOFB)
> - printf("This machine can only suspend without framebuffer.\n");
> -
> - if (ret)
> - goto out;
> -
> - /* switch to console 1 first, since we might be in X */
> - active_console = fgconsole();
> - printf("Switching from vt%d to vt1\n", active_console);
> - chvt(1);
> -
> - ret = s2ram_hacks();
> - if (ret)
> - goto out;
> - ret = s2ram_do();
> - s2ram_resume();
> -
> - out:
> - /* if we switched consoles before suspend, switch back */
> - if (active_console > 0) {
> - printf("switching back to vt%d\n", active_console);
> - chvt(active_console);
> - }
> -
> - return ret;
> -}
> -#endif
> iff -urNp suspend.org/s2ram-main.c suspend-0.6_beta1/s2ram-main.c
> --- suspend.org/s2ram-main.c 1970-01-01 02:00:00.000000000 +0200
> +++ suspend-0.6_beta1/s2ram-main.c 2007-08-02 17:36:35.000000000 +0300
> @@ -0,0 +1,97 @@
> +/*
> + * Suspend-to-RAM
> + *
> + * Copyright 2006 Pavel Machek <[EMAIL PROTECTED]>
> + * Distribute under GPLv2.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <getopt.h>
> +#include <errno.h>
> +#include <string.h>
> +
> +#ifndef S2RAM
> +#define S2RAM
> +#endif
> +#include "vt.h"
> +#include "s2ram.h"
> +#include "configparser.h"
> +
> +int main(int argc, char *argv[])
> +{
> + int i, ret = 0;
> + int active_console = -1;
> + struct option options[] = {
> + {
> + "help\0\tthis text.",
> + no_argument, NULL, 'h'
> + },
> + {
> + "test\0\ttest if the machine is in the database.",
> + no_argument, NULL, 'n'
> + },
> + {
> + "identify\0prints a string that identifies the machine.",
> + no_argument, NULL, 'i'
> + },
> + HACKS_LONG_OPTS
> + { NULL, 0, NULL, 0 }
> + };
> + const char *optstring = "hni" "fspmrva:";
> +
> + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
> + switch (i) {
> + case 'h':
> + usage("s2ram", options, optstring);
> + exit(0);
> + case 'i':
> + identify_machine();
> + exit(0);
> + case 'n':
> + ret = machine_known();
> + exit(ret);
> + case '?':
> + usage("s2ram", options, optstring);
> + exit(1);
> + break;
> + default:
> + s2ram_add_flag(i,optarg);
> + break;
> + }
> + }
> +
> + ret = s2ram_is_supported();
> +
> + if (ret == S2RAM_UNKNOWN) {
> + printf("Machine is unknown.\n");
> + identify_machine();
> + goto out;
> + }
> +
> + if (ret == S2RAM_NOFB)
> + printf("This machine can only suspend without framebuffer.\n");
> +
> + if (ret)
> + goto out;
> +
> + /* switch to console 1 first, since we might be in X */
> + active_console = fgconsole();
> + printf("Switching from vt%d to vt1\n", active_console);
> + chvt(1);
> +
> + ret = s2ram_hacks();
> + if (ret)
> + goto out;
> + ret = s2ram_do();
> + s2ram_resume();
> +
> + out:
> + /* if we switched consoles before suspend, switch back */
> + if (active_console > 0) {
> + printf("switching back to vt%d\n", active_console);
> + chvt(active_console);
> + }
> +
> + return ret;
> +}
> diff -urNp suspend.org/s2ram-x86.c suspend-0.6_beta1/s2ram-x86.c
> --- suspend.org/s2ram-x86.c 2007-08-03 00:33:20.000000000 +0300
> +++ suspend-0.6_beta1/s2ram-x86.c 2007-08-02 23:50:33.000000000 +0300
> @@ -16,7 +17,8 @@
> #include "vbetool/vbetool.h"
> #include "vt.h"
> #include "s2ram.h"
> #include "configparser.h"
> +#include "whitelist.h"
>
> /* From dmidecode.c */
> void dmi_scan(void);
> @@ -36,19 +39,6 @@ char bios_version[1024], sys_vendor[1024
> #define S2RAM_NOFB 126
> #define S2RAM_UNKNOWN 127
>
> -/* flags for the whitelist */
> -#define S3_BIOS 0x01 /* machine needs acpi_sleep=s3_bios */
> -#define S3_MODE 0x02 /* machine needs acpi_sleep=s3_mode */
> -#define VBE_SAVE 0x04 /* machine needs "vbetool save / restore" */
> -#define VBE_POST 0x08 /* machine needs "vbetool post" */
> -#define RADEON_OFF 0x10 /* machine needs "radeontool light off" */
> -#define UNSURE 0x20 /* unverified entries from acpi-support 0.59 */
> -#define NOFB 0x40 /* must not use a frame buffer */
> -#define VBE_MODE 0x80 /* machine needs "vbetool vbemode get / set" */
> -#define PCI_SAVE 0x100 /* we need to save the VGA PCI registers */
> -
> -#include "whitelist.c"
> -
> void identify_machine(void)
> {
> if (!dmi_scanned) {
> diff -urNp suspend.org/whitelist.c suspend-0.6_beta1/whitelist.c
> --- suspend.org/whitelist.c 2007-08-03 00:33:21.000000000 +0300
> +++ suspend-0.6_beta1/whitelist.c 2007-08-02 23:53:08.000000000 +0300
> @@ -3,14 +3,8 @@
> * and all the workarounds
> */
>
> -struct machine_entry
> -{
> - const char *sys_vendor;
> - const char *sys_product;
> - const char *sys_version;
> - const char *bios_version;
> - unsigned int flags;
> -};
> +#include <stdlib.h>
> +#include "whitelist.h"
>
> struct machine_entry whitelist[] = {
> { "IBM", "", "ThinkPad X32", "",
> RADEON_OFF|S3_BIOS|S3_MODE },
> diff -urNp suspend.org/whitelist.h suspend-0.6_beta1/whitelist.h
> --- suspend.org/whitelist.h 1970-01-01 02:00:00.000000000 +0200
> +++ suspend-0.6_beta1/whitelist.h 2007-08-02 23:50:04.000000000 +0300
> @@ -0,0 +1,26 @@
> +/* whitelist.h
> + * whitelist of machines that are known to work somehow
> + * and all the workarounds
> + */
> +
> +/* flags for the whitelist */
> +#define S3_BIOS 0x01 /* machine needs acpi_sleep=s3_bios */
> +#define S3_MODE 0x02 /* machine needs acpi_sleep=s3_mode */
> +#define VBE_SAVE 0x04 /* machine needs "vbetool save / restore" */
> +#define VBE_POST 0x08 /* machine needs "vbetool post" */
> +#define RADEON_OFF 0x10 /* machine needs "radeontool light off" */
> +#define UNSURE 0x20 /* unverified entries from acpi-support 0.59 */
> +#define NOFB 0x40 /* must not use a frame buffer */
> +#define VBE_MODE 0x80 /* machine needs "vbetool vbemode get / set" */
> +#define PCI_SAVE 0x100 /* we need to save the VGA PCI registers */
> +
> +struct machine_entry
> +{
> + const char *sys_vendor;
> + const char *sys_product;
> + const char *sys_version;
> + const char *bios_version;
> + unsigned int flags;
> +};
> +
> +extern struct machine_entry whitelist[];
> --- suspend.org/Makefile 2007-07-29 21:30:27.000000000 +0300
> +++ suspend-0.6_beta1/Makefile 2007-08-03 01:14:35.000000000 +0300
> @@ -16,8 +16,8 @@ LD_FLAGS=-L/usr/local/lib
>
> S2RAM_LD_FLAGS = $(LD_FLAGS)
> SWSUSP_LD_FLAGS = $(LD_FLAGS)
> ifeq ($(ARCH), x86)
> -S2RAM_OBJ += s2ram-x86.o dmidecode.o radeontool.o vbetool/vbetool.o
> +S2RAM_OBJ += s2ram-x86.o whitelist.o dmidecode.o radeontool.o
> vbetool/vbetool.o
> S2RAM_LD_FLAGS += -lx86 -lpci -lz
> else ifeq ($(ARCH), ppc)
> S2RAM_OBJ += s2ram-ppc.o
> @@ -84,7 +84,7 @@ clean:
> rm -f $(BINARIES) suspend-keygen suspend.keys *.o vbetool/*.o
>
> #### Rules for objects
> -s2ram-x86.o: %.o : %.c %.h whitelist.c
> +s2ram-x86.o: %.o : %.c %.h
> $(CC) $(CC_FLAGS) -c $< -o $@
>
> s2ram-both.o: s2ram.c s2ram.h
> @@ -105,7 +105,7 @@ dmidecode.o radeontool.o : %.o: %.c
> s2disk: $(SWSUSP_OBJ) suspend.c
> $(CC) -g $(CC_FLAGS) $^ -o $@ $(SWSUSP_LD_FLAGS)
>
> -s2ram: $(S2RAM_OBJ) s2ram.c
> +s2ram: $(S2RAM_OBJ) s2ram.c s2ram-main.c
> $(CC) -g $(CC_FLAGS) -include s2ram-$(ARCH).h $^ -o $@ $(S2RAM_LD_FLAGS)
>
> s2both: $(SWSUSP_OBJ) $(S2RAM_OBJ) s2ram-both.o suspend.c
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Suspend-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/suspend-devel
>
>
--
"Premature optimization is the root of all evil." - Donald Knuth
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Suspend-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel