]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/textviewdlg.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / fred2 / textviewdlg.cpp
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
6  * the source.
7  */
8
9 // TextViewDlg.cpp : implementation file
10 //
11
12 #include "stdafx.h"
13 #include "fred.h"
14 #include "textviewdlg.h"
15 #include "cfile.h"
16
17 #ifdef _DEBUG
18 #define new DEBUG_NEW
19 #undef THIS_FILE
20 static char THIS_FILE[] = __FILE__;
21 #endif
22
23 /////////////////////////////////////////////////////////////////////////////
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
48 /////////////////////////////////////////////////////////////////////////////
49 // text_view_dlg message handlers
50
51 void text_view_dlg::set(int ship_class)
52 {
53         char line[256], line2[256];
54         int i, j, found = 0, comment = 0;
55         CFILE *fp;
56
57         if (ship_class < 0)
58                 return;
59
60         fp = cfopen("ships.tbl", "r");
61         SDL_assert(fp);
62
63         while (cfgets(line, 255, fp)) {
64                 while (line[strlen(line) - 1] == '\n')
65                         line[strlen(line) - 1] = 0;
66
67                 for (i=j=0; line[i]; i++) {
68                         if (line[i] == '/' && line[i+1] == '/')
69                                 break;
70
71                         if (line[i] == '/' && line[i+1] == '*') {
72                                 comment = 1;
73                                 i++;
74                                 continue;
75                         }
76
77                         if (line[i] == '*' && line[i+1] == '/') {
78                                 comment = 0;
79                                 i++;
80                                 continue;
81                         }
82
83                         if (!comment)
84                                 line2[j++] = line[i];
85                 }
86
87                 line2[j] = 0;
88                 if (!strnicmp(line2, "$Name:", 6)) {
89                         found = 0;
90                         i = 6;
91                         while (line2[i] == ' ' || line2[i] == '\t')
92                                 i++;
93
94                         if (!stricmp(line2 + i, Ship_info[ship_class].name))
95                                 found = 1;
96                 }
97
98                 if (found) {
99                         m_edit += line;
100                         m_edit += "\r\n";
101                 }
102         }
103
104         cfclose(fp);
105 }
106
107 void text_view_dlg::OnSetfocusEdit1() 
108 {
109         ((CEdit *) GetDlgItem(IDC_EDIT1)) -> SetSel(-1, -1);
110 }
111