]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/textviewdlg.cpp
Initial revision
[taylor/freespace2.git] / src / fred2 / textviewdlg.cpp
1 // TextViewDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "fred.h"
6 #include "textviewdlg.h"
7 #include "cfile.h"
8
9 #ifdef _DEBUG
10 #define new DEBUG_NEW
11 #undef THIS_FILE
12 static char THIS_FILE[] = __FILE__;
13 #endif
14
15 /////////////////////////////////////////////////////////////////////////////
16 // text_view_dlg dialog
17
18 text_view_dlg::text_view_dlg(CWnd* pParent /*=NULL*/)
19         : CDialog(text_view_dlg::IDD, pParent)
20 {
21         //{{AFX_DATA_INIT(text_view_dlg)
22         m_edit = _T("");
23         //}}AFX_DATA_INIT
24 }
25
26 void text_view_dlg::DoDataExchange(CDataExchange* pDX)
27 {
28         CDialog::DoDataExchange(pDX);
29         //{{AFX_DATA_MAP(text_view_dlg)
30         DDX_Text(pDX, IDC_EDIT1, m_edit);
31         //}}AFX_DATA_MAP
32 }
33
34 BEGIN_MESSAGE_MAP(text_view_dlg, CDialog)
35         //{{AFX_MSG_MAP(text_view_dlg)
36         ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
37         //}}AFX_MSG_MAP
38 END_MESSAGE_MAP()
39
40 /////////////////////////////////////////////////////////////////////////////
41 // text_view_dlg message handlers
42
43 void text_view_dlg::set(int ship_class)
44 {
45         char line[256], line2[256];
46         int i, j, found = 0, comment = 0;
47         CFILE *fp;
48
49         if (ship_class < 0)
50                 return;
51
52         fp = cfopen("ships.tbl", "r");
53         Assert(fp);
54
55         while (cfgets(line, 255, fp)) {
56                 while (line[strlen(line) - 1] == '\n')
57                         line[strlen(line) - 1] = 0;
58
59                 for (i=j=0; line[i]; i++) {
60                         if (line[i] == '/' && line[i+1] == '/')
61                                 break;
62
63                         if (line[i] == '/' && line[i+1] == '*') {
64                                 comment = 1;
65                                 i++;
66                                 continue;
67                         }
68
69                         if (line[i] == '*' && line[i+1] == '/') {
70                                 comment = 0;
71                                 i++;
72                                 continue;
73                         }
74
75                         if (!comment)
76                                 line2[j++] = line[i];
77                 }
78
79                 line2[j] = 0;
80                 if (!strnicmp(line2, "$Name:", 6)) {
81                         found = 0;
82                         i = 6;
83                         while (line2[i] == ' ' || line2[i] == '\t')
84                                 i++;
85
86                         if (!stricmp(line2 + i, Ship_info[ship_class].name))
87                                 found = 1;
88                 }
89
90                 if (found) {
91                         m_edit += line;
92                         m_edit += "\r\n";
93                 }
94         }
95
96         cfclose(fp);
97 }
98
99 void text_view_dlg::OnSetfocusEdit1() 
100 {
101         ((CEdit *) GetDlgItem(IDC_EDIT1)) -> SetSel(-1, -1);
102 }