File: messbox.cpp

package info (click to toggle)
sludge 2.2.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,852 kB
  • sloc: cpp: 32,432; sh: 1,237; makefile: 634; xml: 284
file content (159 lines) | stat: -rw-r--r-- 3,363 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 *  MessBox.cpp
 *  Sludge Dev Kit
 *
 *  Created by Rikard Peterson on 2009-07-15.
 *  Copyright 2009 Hungry Software and contributors. All rights reserved.
 *
 */

#include <stdio.h>
#include <string.h>

#include "messbox.h"
#include "errorlinktofile.h"
#include "moreio.h"
#include "helpers.h"
#include "splitter.hpp"
#include "compilerinfo.h"


extern stringArray * allSourceStrings;
extern stringArray * allFileHandles;

const char * errorTypeStrings[ERRORTYPE_NUM] =
{
	"WARNING: ",
	"ERROR: ",
	"SYSTEM ERROR: ",
	"INTERNAL ERROR: "
};


errorLinkToFile * errorList = NULL;
int numErrors = 0;

void clearComments () {
	while (errorLinkToFile * item = errorList) {
		errorList = errorList->next;
		delete item->overview;
		if (item->filename) delete item->filename;
		delete item->fullText;
		delete item;
	}
	numErrors = 0;
}


void addCommentWithLine (int errorType, const char * comment, const char * filename, unsigned int lineNumber) {

	errorLinkToFile * newLink = new errorLinkToFile;
	if (! newLink) return;

	if (filename && filename[0] == '\0')
		filename = NULL;

	char * s = copyString(comment);
	char * s2, *s3;

	// Extract real strings...
	while (s2 = strstr(s, "_string")) {
		unsigned long i = 0;
		int ac = 0;

		s3 = s2 + 7;
		int looping = true;
		while (s3[ac] && looping) {
			if (s3[ac] >= '0' && s3[ac] <= '9') {
				i = (i * 10) + s3[ac] - '0';
				if (i >= 65535) {
					looping = false;
				}
			} else {
				looping = false;
			}
			if (looping) ac ++;
		}
		s3+=ac;
		s2[1] = 0;
		s2[0] = '"';
		s2 = s;
		s = joinStrings(s, returnElement (allSourceStrings, i), "\"", s3);
		delete s2;
	}

	// Extract resource file names ...
	while (s2 = strstr(s, "_file")) {
		unsigned long i = 0;
		int ac = 0;

		s3 = s2 + 7;
		int looping = true;
		while (s3[ac] && looping) {
			if (s3[ac] >= '0' && s3[ac] <= '9') {
				i = (i * 10) + s3[ac] - '0';
				if (i >= 65535) {
					looping = false;
				}
			} else {
				looping = false;
			}
			if (looping) ac ++;
		}
		s3+=ac;
		s2[1] = 0;
		s2[0] = '\'';
		s2 = s;
		s = joinStrings(s, returnElement (allFileHandles, i), "'", s3);
		delete s2;
	}

	newLink->errorType = errorType;
	newLink->overview = copyString (s);
	newLink->filename = filename ? copyString (filename) : NULL;
	newLink->lineNumber = lineNumber;
	newLink->next = errorList;
	errorList = newLink;

	char * filenameWline;
	if (filename) {
		if (lineNumber) {
			filenameWline = new char[strlen(filename)+15];
			sprintf(filenameWline, "%s: line %d", filename, lineNumber);
		} else {
			filenameWline = copyString(filename);
		}
	} else {
		filenameWline = copyString ("");
	}
	char * after = filename ? joinStrings (" (in ", filenameWline, ")") : copyString ("");
	newLink->fullText = joinStrings (errorTypeStrings[errorType], s, after);

	delete after;
	delete filenameWline;

	numErrors ++;

	compilerCommentsUpdated();
}

bool addComment (int errorType, const char * txt1, const char * txt2, const char * filename, unsigned int lineNumber) {
	if (txt2)
	{
		char * a = joinStrings (txt1, ": ", txt2);
		if (a)
		{
			addCommentWithLine (errorType, a, filename, lineNumber);
			delete a;
		}
	}
	else
	{
		addCommentWithLine (errorType, txt1, filename, lineNumber);
	}
	return false;
}

void addComment (int errorType, const char *txt1, const char * filename) {
	addCommentWithLine (errorType, txt1, filename, 0);
}