]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - warp/sm.c
cgram: properly handle input errors
[bsdgames-darwin.git] / warp / sm.c
1 /* Header: sm.c,v 7.0 86/10/08 15:13:35 lwall Exp */
2
3 /* Log: sm.c,v
4 * Revision 7.0 86/10/08 15:13:35 lwall
5 * Split into separate files. Added amoebas and pirates.
6 *
7 */
8
9 #include <stdio.h>
10 #include <ctype.h>
11 #include <stdlib.h>
12 #include "warp-config.h"
13
14 int
15 main(void)
16 {
17 char screen[23][90], buf[10];
18 int y;
19 int x;
20 int tmpy, tmpx;
21
22 for (x=0; x<79; x++)
23 screen[0][x] = ' ';
24 screen[0][79] = '\0';
25
26 fgets(screen[0],90,stdin);
27 if (isdigit(screen[0][0])) {
28 int numstars = atoi(screen[0]);
29
30 for (y=0; y<23; y++) {
31 for (x=0; x<79; x++)
32 screen[y][x] = ' ';
33 screen[y][79] = '\0';
34 }
35
36 for ( ; numstars; numstars--) {
37 scanf("%d %d\n",&tmpy,&tmpx);
38 y = tmpy;
39 x = tmpx;
40 screen[y][x+x] = '*';
41 }
42
43 for (y=0; y<23; y++) {
44 printf("%s\n",screen[y]);
45 }
46 }
47 else {
48 int numstars = 0;
49
50 for (y=1; y<23; y++) {
51 for (x=0; x<79; x++)
52 screen[y][x] = ' ';
53 screen[y][79] = '\0';
54 }
55
56 for (y=1; y<23; y++) {
57 fgets(screen[y],90,stdin);
58 }
59
60 for (y=0; y<23; y++) {
61 for (x=0; x<80; x += 2) {
62 if (screen[y][x] == '*') {
63 numstars++;
64 }
65 else if (screen[y][x] == '\t' || screen[y][x+1] == '\t') {
66 fprintf(stderr,"Cannot have tabs in starmap--please expand.\n");
67 exit(1);
68 }
69 }
70 }
71
72 printf("%d\n",numstars);
73
74 for (y=0; y<23; y++) {
75 for (x=0; x<80; x += 2) {
76 if (screen[y][x] == '*') {
77 printf("%d %d\n",y,x/2);
78 }
79 }
80 }
81 }
82 exit(0);
83 }