FS2_Open
Open source remastering of the Freespace 2 engine
textviewdlg.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 // TextViewDlg.cpp : implementation file
11 //
12 
13 #include "stdafx.h"
14 #include "FRED.h"
15 #include "TextViewDlg.h"
16 #include "cfile/cfile.h"
17 
18 #ifdef _DEBUG
19 #undef THIS_FILE
20 static char THIS_FILE[] = __FILE__;
21 #endif
22 
24 // text_view_dlg dialog
25 
26 text_view_dlg::text_view_dlg(CWnd* pParent /*=NULL*/)
27  : CDialog(text_view_dlg::IDD, pParent)
28 {
29  //{{AFX_DATA_INIT(text_view_dlg)
30  m_edit = _T("");
31  //}}AFX_DATA_INIT
32 }
33 
34 void text_view_dlg::DoDataExchange(CDataExchange* pDX)
35 {
36  CDialog::DoDataExchange(pDX);
37  //{{AFX_DATA_MAP(text_view_dlg)
38  DDX_Text(pDX, IDC_EDIT1, m_edit);
39  //}}AFX_DATA_MAP
40 }
41 
42 BEGIN_MESSAGE_MAP(text_view_dlg, CDialog)
43  //{{AFX_MSG_MAP(text_view_dlg)
44  ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
45  //}}AFX_MSG_MAP
46 END_MESSAGE_MAP()
47 
49 // text_view_dlg message handlers
50 
51 void text_view_dlg::set(int ship_class)
52 {
53  char line[256], line2[256], file_text[82];
54  int i, j, n, found = 0, comment = 0, num_files = 0;
55  SCP_vector<SCP_string> tbl_file_names;
56  CFILE *fp;
57 
58  if (ship_class < 0)
59  return;
60 
61  fp = cfopen("ships.tbl", "r");
62  Assert(fp);
63 
64 
65  while (cfgets(line, 255, fp)) {
66  while (line[strlen(line) - 1] == '\n')
67  line[strlen(line) - 1] = 0;
68 
69  for (i=j=0; line[i]; i++) {
70  if (line[i] == '/' && line[i+1] == '/')
71  break;
72 
73  if (line[i] == '/' && line[i+1] == '*') {
74  comment = 1;
75  i++;
76  continue;
77  }
78 
79  if (line[i] == '*' && line[i+1] == '/') {
80  comment = 0;
81  i++;
82  continue;
83  }
84 
85  if (!comment)
86  line2[j++] = line[i];
87  }
88 
89  line2[j] = 0;
90  if (!strnicmp(line2, "$Name:", 6)) {
92  found = 0;
93  i = 6;
94 
95  while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
96  i++;
97 
98  if (!stricmp(line2 + i, Ship_info[ship_class].name)) {
99  m_edit += "-- ships.tbl -------------------------------\r\n";
100  found = 1;
101  }
102  }
103 
104  if (found) {
105  m_edit += line;
106  m_edit += "\r\n";
107  }
108  }
109 
110  cfclose(fp);
111 
112 
113  // done with ships.tbl, so now check all modular ship tables...
114  num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-shp.tbm"), CF_SORT_REVERSE);
115 
116  for (n = 0; n < num_files; n++){
117  tbl_file_names[n] += ".tbm";
118 
119  fp = cfopen(tbl_file_names[n].c_str(), "r");
120  Assert(fp);
121 
122  memset( line, 0, sizeof(line) );
123  memset( line2, 0, sizeof(line2) );
124  found = 0;
125  comment = 0;
126 
127  while (cfgets(line, 255, fp)) {
128  while (line[strlen(line) - 1] == '\n')
129  line[strlen(line) - 1] = 0;
130 
131  for (i=j=0; line[i]; i++) {
132  if (line[i] == '/' && line[i+1] == '/')
133  break;
134 
135  if (line[i] == '/' && line[i+1] == '*') {
136  comment = 1;
137  i++;
138  continue;
139  }
140 
141  if (line[i] == '*' && line[i+1] == '/') {
142  comment = 0;
143  i++;
144  continue;
145  }
146 
147  if (!comment)
148  line2[j++] = line[i];
149  }
150 
151  line2[j] = 0;
152  if (!strnicmp(line2, "$Name:", 6)) {
154  found = 0;
155  i = 6;
156 
157  while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
158  i++;
159 
160  if (!stricmp(line2 + i, Ship_info[ship_class].name)) {
161  memset( file_text, 0, sizeof(file_text) );
162  snprintf(file_text, sizeof(file_text)-1, "-- %s -------------------------------\r\n", tbl_file_names[n].c_str());
163  m_edit += file_text;
164  found = 1;
165  }
166  }
167 
168  if (found) {
169  m_edit += line;
170  m_edit += "\r\n";
171  }
172  }
173 
174  cfclose(fp);
175  }
176 }
177 
179 {
180  ((CEdit *) GetDlgItem(IDC_EDIT1)) -> SetSel(-1, -1);
181 }
int i
Definition: multi_pxo.cpp:466
void drop_trailing_white_space(char *str)
Definition: parselo.cpp:93
Assert(pm!=NULL)
Definition: cfile.h:28
#define CF_SORT_REVERSE
Definition: cfile.h:95
#define cfopen(...)
Definition: cfile.h:134
char * cfgets(char *buf, int n, CFILE *cfile)
Definition: cfile.cpp:1571
#define strnicmp(s1, s2, n)
Definition: config.h:272
#define CF_TYPE_TABLES
Definition: cfile.h:50
cfbp fp
Definition: cfile.cpp:1065
GLclampd n
Definition: Glext.h:7286
#define NOX(s)
Definition: pstypes.h:473
GLuint const GLchar * name
Definition: Glext.h:5608
virtual void DoDataExchange(CDataExchange *pDX)
Definition: textviewdlg.cpp:34
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
#define IDC_EDIT1
Definition: resource.h:763
afx_msg void OnSetfocusEdit1()
int cfclose(CFILE *cfile)
Definition: cfile.cpp:895
CString m_edit
Definition: textviewdlg.h:27
int cf_get_file_list(SCP_vector< SCP_string > &list, int pathtype, const char *filter, int sort=CF_SORT_NONE, SCP_vector< file_list_info > *info=NULL)
#define stricmp(s1, s2)
Definition: config.h:271
text_view_dlg(CWnd *pParent=NULL)
Definition: textviewdlg.cpp:26