104 tmp.close (); |
104 tmp.close (); |
105 return true; |
105 return true; |
106 } |
106 } |
107 |
107 |
108 // ============================================================================= |
108 // ============================================================================= |
|
109 void writeObjects (std::vector<LDObject*>& objects, FILE* fp) { |
|
110 for (LDObject* obj : objects) { |
|
111 if (obj->getType () == LDObject::Subfile) { |
|
112 vector<LDObject*> objs = static_cast<LDSubfile*> (obj)->inlineContents (true, false); |
|
113 |
|
114 writeObjects (objs, fp); |
|
115 for (LDObject* obj : objs) |
|
116 delete obj; |
|
117 } else if (obj->getType () == LDObject::Radial) { |
|
118 vector<LDObject*> objs = static_cast<LDRadial*> (obj)->decompose (true); |
|
119 |
|
120 writeObjects (objs, fp); |
|
121 for (LDObject* obj : objs) |
|
122 delete obj; |
|
123 } else { |
|
124 str line = fmt ("%s\r\n", obj->getContents ().chars ()); |
|
125 fwrite (line.chars(), 1, ~line, fp); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
109 void writeObjects (std::vector<LDObject*>& objects, str fname) { |
130 void writeObjects (std::vector<LDObject*>& objects, str fname) { |
110 // Write the input file |
131 // Write the input file |
111 FILE* fp = fopen (fname, "w"); |
132 FILE* fp = fopen (fname, "w"); |
112 if (!fp) { |
133 if (!fp) { |
113 critical (fmt ("Couldn't open temporary file %s for writing.\n", fname.chars ())); |
134 critical (fmt ("Couldn't open temporary file %s for writing.\n", fname.chars ())); |
114 return; |
135 return; |
115 } |
136 } |
116 |
137 |
117 for (LDObject* obj : objects) { |
138 writeObjects (objects, fp); |
118 str line = fmt ("%s\r\n", obj->getContents ().chars ()); |
|
119 fwrite (line.chars(), 1, ~line, fp); |
|
120 } |
|
121 |
139 |
122 #ifndef RELEASE |
140 #ifndef RELEASE |
123 ushort idx = rand (); |
141 ushort idx = rand (); |
124 printf ("%s -> debug_%u\n", fname.chars (), idx); |
142 printf ("%s -> debug_%u\n", fname.chars (), idx); |
125 QFile::copy (fname.chars (), fmt ("debug_%u", idx)); |
143 QFile::copy (fname.chars (), fmt ("debug_%u", idx)); |