-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgalisting.cpp
More file actions
89 lines (76 loc) · 2.21 KB
/
galisting.cpp
File metadata and controls
89 lines (76 loc) · 2.21 KB
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
#include <QDebug>
#include <qsystemdetection.h>
#include "galisting.h"
#include "goodasm.h"
GAListing::GAListing() {
clearStops();
}
//Called between runs, to clear column measurements.
void GAListing::clearStops(){
/* For now, we don't clear the tab stops. They grow
* when wider spaces are needed, but they never shrink.
*/
//Good for android and iOS
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
label_len=5;
code_len=10;
comment_len=20;
return;
#endif
//Good for unix.
label_len=8;
code_len=32;
comment_len=51;
}
QString GAListing::bitstring(uint8_t b){
QString s="";
for(int i=0; i<8; i++){
s+=(b&(0x80>>i))?"1":"0";
if(i==3)
s+=".";
}
return s;
}
//Returns the working name of the current module without suffixes.
QString GAListing::moduleName(GoodASM *goodasm){
QString fn=goodasm->filename;
QString name="";
for(int i=0; i<fn.length(); i++){
QChar c=fn[i];
if(c.isLetterOrNumber())
name+=c;
else
return name;
}
if(name.length()>0)
return name;
return "nameless";
}
//Formats a source line for printing.
QString GAListing::formatSource(QString label, QString code,
QString comment, QString comment2){
/* Every source line beings with a potential label, then some code
* and finally a comment. This fuction is largely just concatenating
* with padding, but we cannot use QString::arg() because of its
* trouble with format string injection when presented with I/O addresses.
*/
//Simple example with just a comment.
if(label.length()==0 && code.length()==0 && comment2.length()==0)
return comment+"\n";
QString s=label;
if(s.length()>label_len-2) label_len=s.length()+2;
while(s.length()<label_len) s+=" ";
s+=code;
if(comment!=""){
if(s.length()>code_len-2) code_len=s.length()+2;
while(s.length()<code_len) s+=" ";
s+=comment;
if(comment2!=""){
if(s.length()>comment_len-2) comment_len=s.length()+2;
while(s.length()<comment_len) s+=" ";
s+=comment2;
}
}
s+="\n";
return s;
}