Go: package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

var strByColor = map[Color]string{
	ColorBlack: "black",
	ColorRed:   "red",
}

func (c Color) String() string {
	return strByColor[c]
}

type Node struct {
	ID      int
	X, Y    int
	Color   Color
	NextIDs map[int]struct{}
}

func (n *Node) String() string {
	d, _ := json.Marshal(n)
	return string(d)
}

type Map struct {
	Width, Height int
	Nodes         map[int]*Node
}

func (m *Map) GetByID(id int) *Node {
	return m.Nodes[id]
}

func (m *Map) Get(x, y int) *Node {
	return m.Nodes[m.getID(x, y)]
}

func (m *Map) SetColor(x, y int, c Color) {
	m.Nodes[m.getID(x, y)].Color = c
}

func (m *Map) getID(x, y int) int {
	return x + y*m.Width
}

func (m *Map) init() {
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			id := m.getID(x, y)
			m.Nodes[id] = &Node{ID: id, X: x, Y: y}
		}
	}
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			nextIDs := map[int]struct{}{}
			if x > 1 {
				nextIDs[m.getID(x-1, y)] = struct{}{}
			}
			if x < m.Width {
				nextIDs[m.getID(x+1, y)] = struct{}{}
			}
			if y > 1 {
				nextIDs[m.getID(x, y-1)] = struct{}{}
			}
			if y < m.Height {
				nextIDs[m.getID(x, y+1)] = struct{}{}
			}
			m.Get(x, y).NextIDs = nextIDs
		}
	}
}

func NewMap(w, h int) *Map {
	m := &Map{Width: w, Height: h, Nodes: map[int]*Node{}}
	m.init()
	return m
}

type Searcher struct {
	Map        *Map
	queue      []*Node
	touchedIDs map[int]struct{}
	visitedIDs map[int]struct{}
}

func NewSearcher(m *Map) *Searcher {
	return &Searcher{
		Map:        m,
		queue:      []*Node{},
		touchedIDs: map[int]struct{}{},
		visitedIDs: map[int]struct{}{},
	}
}

func (s *Searcher) Search(start *Node) {
	s.enqueue(start)

	for {
		if len(s.queue) == 0 {
			break
		}
		for nextID := range s.dequeue().NextIDs {
			n := s.Map.GetByID(nextID)
			if n.Color == ColorRed || s.hasTouched(n) {
				continue
			}
			s.enqueue(n)
		}
	}
}

func (s *Searcher) VisitedNodeCount() int {
	return len(s.visitedIDs)
}

func (s *Searcher) hasTouched(n *Node) bool {
	_, ok := s.touchedIDs[n.ID]
	return ok
}

func (s *Searcher) enqueue(n *Node) {
	s.queue = append(s.queue, n)
	s.touchedIDs[n.ID] = struct{}{}
}

func (s *Searcher) dequeue() *Node {
	n := s.queue[0]
	s.queue = s.queue[1:]
	s.visitedIDs[n.ID] = struct{}{}
	return n
}

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		w, _ := strconv.Atoi(chunks[0])
		h, _ := strconv.Atoi(chunks[1])

		m := NewMap(w, h)

		// Set colors
		var start *Node
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					m.SetColor(i+1, y, ColorBlack)
					if c == '@' {
						start = m.Get(i+1, y)
					}
				case '#':
					m.SetColor(i+1, y, ColorRed)
				}
			}
		}

		// Search
		s := NewSearcher(m)
		s.Search(start)
		fmt.Println(s.VisitedNodeCount())
	}
}

C++: #include<iostream>
#include<queue>
using namespace std;
     
const int INF=100000000;
     
char maze[20][20];
int w, h;
int sx, sy;
int cnt;
     
int d[20][20];
     
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
     
     
int bfs(){
  queue< pair<int, int> > que;
     
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) d[i][j]=INF;
     
  que.push(pair<int, int>(sy, sx));
  d[sy][sx]=0;
     
  while(que.size()){
    pair<int, int> p=que.front();
    que.pop();
     
    for(int i=0;i<4;i++){
      int ny=p.first+dy[i], nx=p.second+dx[i];
     
      if(0<=ny&&ny<h&&0<=nx&&nx<w&&maze[ny][nx]!='#'&&d[ny][nx]==INF){
	que.push(pair<int, int>(ny, nx));
	d[ny][nx]=d[p.first][p.second]+1;
	cnt++;
      }
    }
  }
  return cnt+1;
}
     
int main(){
     
  while(cin>>w>>h, w){
  
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>maze[i][j];
	if(maze[i][j]=='@'){
	  sy=i;
	  sx=j;
	}
      }
    }
    cnt=0;
    int res=bfs();
     
    cout<<res<<endl;

  }
     
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;

int h, w = 0;
int ct = 0;
vector<string> map;

void count(int y,int x){
	map[y][x] = 'X';
	if (y != 0){
		if (map[y-1][x] == '.'){
				count(y-1,x);
		}
	}
	if (y != h-1){
		if (map[y+1][x] == '.'){
				count(y+1,x);
		}
	}
	if (x != 0){
		if (map[y][x-1] == '.'){
				count(y,x-1);
		}
	}
	if (x != w-1){
		if (map[y][x+1] == '.'){
				count(y,x+1);
		}
	}
	ct++;
}

int main(){
	int stx, sty;
	while (1){
		cin >> w >> h;
		if (h == 0 && w == 0){
			break;
		}
		for (int i = 0; i < h; i++){
			string tmp;
			cin >> tmp;
			map.push_back(tmp);
			for (int j = 0; j < w; j++){
				if (map[i][j] == '@'){
					sty = i;
					stx = j;
				}
			}
		}
		count(sty,stx);
		cout << ct << endl;
		ct = 0;
		map.clear();
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstdint>
#include <array>

using namespace std;


typedef std::array<uint32_t, 2> Idx;


uint32_t checkAndSetIdx(vector<string>& mp, vector<Idx>& stack, uint32_t i, uint32_t j)
{
    if(i > mp.size()-1 || j > mp.at(0).size()-1)
        return 0;

    if(mp[i][j] == '.'){
        mp[i][j] = 'x';
        stack.push_back(Idx({i, j}));
        return 1;
    }

    return 0;
}


int main()
{
    while(1)
    {
        uint32_t h, w;
        cin >> w >> h;

        if(w == 0 && h == 0)
            break;


        Idx iniPos;

        vector<string> mp;
        for(uint32_t i = 0; i < h; ++i){
            mp.push_back([](){string str; cin >> str; return str;}());

            for(uint32_t j = 0; j < w; ++j){
                if(mp[i][j] == '@'){
                    iniPos = Idx({i, j});
                    mp[i][j] = 'x';
                }
            }
        }


        vector<Idx> stack;
        stack.push_back(iniPos);
        uint32_t cnt = 1;


        while(stack.size() != 0){
            auto nowPos = stack.at(stack.size() - 1);
            stack.pop_back();
            const auto i = nowPos[0],
                       j = nowPos[1];

            cnt += checkAndSetIdx(mp, stack, i+1, j);
            cnt += checkAndSetIdx(mp, stack, i-1, j);
            cnt += checkAndSetIdx(mp, stack, i, j+1);
            cnt += checkAndSetIdx(mp, stack, i, j-1);
        }

        cout << cnt << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int W, H;
bool m[20][20];
bool hou[20][20];

int dfs(int r, int c)
{
	if (r < 0 || c < 0 || r >= H || c >= W) return 0;
	if (hou[r][c] || !m[r][c]) return 0;
	hou[r][c] = true;
	int res = 1;
	int dr[] = {-1, 0, 0, 1};
	int dc[] = { 0,-1, 1, 0};
	rep(i, 4) res += dfs(r+dr[i], c+dc[i]);
	return res;
}

signed main()
{
	cin >> W >> H;
	while (W) {
		int r=0, c=0;
		rep(i, H) rep(j, W) {
			CIN(char, t);
			if (t == '#') m[i][j] = false;
			else {
				m[i][j] = true;
				if (t == '@') {
					r = i;
					c = j;
				}
			}
		}
		cout << dfs(r, c) << endl;
		cin >> W >> H;
		rep(i, 20) rep(j, 20) hou[i][j] = false;
	}
}