summaryrefslogtreecommitdiff
path: root/games/sms_sdl/patches/fix_option_parsing.diff
blob: ee91ec487df537a8593e49616023bd40dc233c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
diff -x tags -Naur sms_sdl-0.9.4a-r7.1/sdl/main.c sms_sdl-0.9.4a-r7.1.patched/sdl/main.c
--- sms_sdl-0.9.4a-r7.1/sdl/main.c	2009-10-11 21:49:18.000000000 -0400
+++ sms_sdl-0.9.4a-r7.1.patched/sdl/main.c	2009-10-12 01:41:24.000000000 -0400
@@ -42,17 +42,20 @@
 
 static int parse_args(int argc, char **argv)
 {
-  int i;
+  int i, name_set = 0;
 
   /* default virtual console emulation settings */
   cfg.fm = 0;
   cfg.japan = 0;
 
   cfg.filter = -1;
-  strcpy(cfg.game_name, argv[1]);
 
-  for(i = 2; i < argc; ++i) {
-    if(strcasecmp(argv[i], "--fm") == 0)
+  for(i = 1; i < argc; ++i) {
+    if(!name_set && argv[i][0] != '-') {
+       strcpy(cfg.game_name, argv[i]);
+       name_set++;
+    }
+    else if(strcasecmp(argv[i], "--fm") == 0)
       cfg.fm = 1;
     else if(strcasecmp(argv[i], "--japan") == 0)
       cfg.japan = 1;
@@ -86,6 +89,11 @@
     else 
       printf("WARNING: unknown option '%s'.\n", argv[i]);
   }
+  if(!name_set) {
+	  printf("ERROR: no ROM filename given\n");
+	  return 0;
+  }
+
   return 1;
 }
 
@@ -112,13 +120,13 @@
     printf(" --filter <mode>\t render using a filter: ");
     for(i = 0; i < sizeof(filters) / sizeof(filters[0]) - 1; ++i)
       printf("%s,", filters[i].name);
-    printf("%s.", filters[i].name);
+    printf("%s.\n", filters[i].name);
     return 1;
   }
 
   memset(&cfg, 0, sizeof(cfg));
   if(!parse_args(argc, argv))
-	  return 0;
+	  return 1;
 
   if(sdlsms_init(&cfg)) {
     sdlsms_emulate();
diff -x tags -Naur sms_sdl-0.9.4a-r7.1/sdl/saves.c sms_sdl-0.9.4a-r7.1.patched/sdl/saves.c
--- sms_sdl-0.9.4a-r7.1/sdl/saves.c	2003-07-16 23:20:24.000000000 -0400
+++ sms_sdl-0.9.4a-r7.1.patched/sdl/saves.c	2009-10-11 22:04:10.000000000 -0400
@@ -88,6 +88,11 @@
   unzCloseCurrentFile(zf);
   unzClose(zf);
 
+  /* 20091011 bkw: avoid segfaulting if filename contains no dot */
+  if(!strrchr(romfile, '.')) {
+	  printf("Invalid filename '%s' (no extension), giving up\n", romfile);
+	  return 0;
+  }
   if(strcasecmp(strrchr(romfile, '.'), ".gg") == 0)
     cart.type = TYPE_GG;
   else
@@ -126,6 +131,11 @@
 
   fclose(fd);
 
+  /* 20091011 bkw: avoid segfaulting if filename contains no dot */
+  if(!strrchr(filename, '.')) {
+	  printf("Invalid filename '%s' (no extension), giving up\n", filename);
+	  return 0;
+  }
   /* Figure out game image type */
   if(strcasecmp(strrchr(filename, '.'), ".gg") == 0)
     cart.type = TYPE_GG;