about summary refs log tree commit diff stats
path: root/main.c
Commit message (Expand)AuthorAgeFilesLines
* reverted accidental removal of sx, syAnselm R. Garbe2007-02-211-4/+5
* removed some global vars which should be static insteadAnselm R. Garbe2007-02-211-6/+5
* renamed setfont to initfont, getcolor to initcolorAnselm R. Garbe2007-02-201-29/+29
* added draw.c again (except getcolor and setfont which are helpers in main.c)Anselm R. Garbe2007-02-201-128/+0
* separating drawsquare from drawtext, made drawtext externAnselm R. Garbe2007-02-201-49/+63
* using eprint instead of fputsAnselm R. Garbe2007-02-191-6/+3
* introduced Layout structAnselm R. Garbe2007-02-191-6/+6
* removed procevent, more refactoringAnselm R. Garbe2007-02-191-2/+6
* draw.c is useless (belongs to main.c now)Anselm R. Garbe2007-02-191-0/+165
* some more refactoringAnselm R. Garbe2007-02-191-3/+1
* introduced tile.c, some refactoring of functionsAnselm R. Garbe2007-02-191-1/+1
* removed ugly ban(), extended resize() that it only resets the size if necessa...Anselm R. Garbe2007-02-161-1/+2
* made for/if/else constructs more consistent, some code polishingAnselm R. Garbe2007-02-141-6/+5
* pneubeck pointed out an obvious thing, that a second p = stext + strlen(stext...Anselm R. Garbe2007-02-091-1/+1
* fixed order of Bool declarationsAnselm R. Garbe2007-02-081-1/+1
* added TOPBAR option for making the bar appear what the user likesAnselm R. Garbe2007-02-081-3/+3
* making the bar appear at bottomAnselm R. Garbe2007-02-081-2/+2
* replaced getproto with a saner function, now old-school artifacts of WM times...Anselm R. Garbe2007-02-071-18/+0
* handling WM_STATE seems to make DnD in gtk/qt apps working, well let's handle...Anselm R. Garbe2007-01-281-0/+1
* renamed activescreen into selscreen 3.2Anselm R. Garbe2007-01-231-2/+2
* small changesAnselm R. Garbe2007-01-231-2/+2
* applied Sanders all5.patch (thanks for your weekend session, Sander!)Anselm R. Garbe2007-01-221-1/+1
* removed unnecessary bx, by, bw variablesAnselm R. Garbe2007-01-161-5/+2
* implemented new color scheme accordingly to Sanders proposalAnselm R. Garbe2007-01-141-2/+2
* removed mode label stuffAnselm R. Garbe2007-01-141-2/+2
* small fix of initial numlockmask valueAnselm R. Garbe2007-01-111-0/+1
* reorganizedAnselm R. Garbe2007-01-081-2/+1
* implemented nmaster appearance in mode label (using %u)Anselm R. Garbe2007-01-081-2/+3
* experimental version which allows master clients being increased/decreasedAnselm R. Garbe2007-01-051-1/+2
* changed arg's color schemearg@mig292007-01-021-3/+3
* correctionsarg@mig292007-01-021-2/+2
* next version will contain updated copyright noticearg@mig292007-01-021-2/+2
* fixed cleanup, using clients instead of sel 2.8arg@mig292007-01-021-3/+3
* with this patch everything works fine for mearg@mig292006-12-071-0/+2
* improved the memory leak preventionarg@mig292006-12-061-1/+4
* applied Jukka's patch preventing some cornercases and making the EOF error me...arg@mig292006-11-271-1/+2
* applied yet another proposal of Manuelarg@mig292006-11-261-2/+2
* applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line print...arg@mig292006-11-261-6/+8
* applied Jukka's stdinread patcharg@mig292006-11-261-2/+3
* applied Manuels patch (thanks to Manuel!)arg@mig292006-11-251-14/+21
* applied Gottox patchesarg@mig292006-11-211-2/+3
* applied Gottox' windowarea patcharg@mig292006-11-161-1/+6
* code polishing, removed unnecessary newlinesAnselm R. Garbe2006-10-061-21/+9
* removed the stack position stuffAnselm R. Garbe2006-10-051-4/+1
* keep master ratio on resizecol -> arrangeAnselm R. Garbe2006-10-051-3/+3
* added symbols for different modesAnselm R. Garbe2006-09-291-2/+5
* removed useless updatemasterAnselm R. Garbe2006-09-291-1/+1
* added the new dotile as described on mlAnselm R. Garbe2006-09-291-1/+1
* first step to a more flexible dotile() algorithmAnselm R. Garbe2006-09-291-2/+2
* applied Jukkas patcharg@mmvi2006-09-251-3/+3
>if (output_filename.empty()) { print_translate_usage(); cerr << "must provide a filename to write to using '-o'\n"; exit(1); } transform(p); if (trace_contains_errors()) return 1; save_elf(p, output_filename); if (trace_contains_errors()) { unlink(output_filename.c_str()); return 1; } // End subx translate return 0; } :(code) void print_translate_usage() { cerr << "Usage: subx translate file1 file2 ... -o output\n"; } // write out a program to a bare-bones ELF file void save_elf(const program& p, const string& filename) { ofstream out(filename.c_str(), ios::binary); write_elf_header(out, p); for (size_t i = 0; i < p.segments.size(); ++i) write_segment(p.segments.at(i), out); out.close(); } void write_elf_header(ostream& out, const program& p) { char c = '\0'; #define O(X) c = (X); out.write(&c, sizeof(c)) // host is required to be little-endian #define emit(X) out.write(reinterpret_cast<const char*>(&X), sizeof(X)) //// ehdr // e_ident O(0x7f); O(/*E*/0x45); O(/*L*/0x4c); O(/*F*/0x46); O(0x1); // 32-bit format O(0x1); // little-endian O(0x1); O(0x0); for (size_t i = 0; i < 8; ++i) { O(0x0); } // e_type O(0x02); O(0x00); // e_machine O(0x03); O(0x00); // e_version O(0x01); O(0x00); O(0x00); O(0x00); // e_entry int e_entry = p.segments.at(0).start; // convention emit(e_entry); // e_phoff -- immediately after ELF header int e_phoff = 0x34; emit(e_phoff); // e_shoff; unused int dummy32 = 0; emit(dummy32); // e_flags; unused emit(dummy32); // e_ehsize uint16_t e_ehsize = 0x34; emit(e_ehsize); // e_phentsize uint16_t e_phentsize = 0x20; emit(e_phentsize); // e_phnum uint16_t e_phnum = SIZE(p.segments); emit(e_phnum); // e_shentsize uint16_t dummy16 = 0x0; emit(dummy16); // e_shnum emit(dummy16); // e_shstrndx emit(dummy16); uint32_t p_offset = /*size of ehdr*/0x34 + SIZE(p.segments)*0x20/*size of each phdr*/; for (int i = 0; i < SIZE(p.segments); ++i) { //// phdr // p_type uint32_t p_type = 0x1; emit(p_type); // p_offset emit(p_offset); // p_vaddr uint32_t p_start = p.segments.at(i).start; emit(p_start); // p_paddr emit(p_start); // p_filesz uint32_t size = num_words(p.segments.at(i)); assert(p_offset + size < SEGMENT_ALIGNMENT); emit(size); // p_memsz emit(size); // p_flags uint32_t p_flags = (i == 0) ? /*r-x*/0x5 : /*rw-*/0x6; // convention: only first segment is code emit(p_flags); // p_align // "As the system creates or augments a process image, it logically copies // a file's segment to a virtual memory segment. When—and if— the system // physically reads the file depends on the program's execution behavior, // system load, and so on. A process does not require a physical page // unless it references the logical page during execution, and processes // commonly leave many pages unreferenced. Therefore delaying physical // reads frequently obviates them, improving system performance. To obtain // this efficiency in practice, executable and shared object files must // have segment images whose file offsets and virtual addresses are // congruent, modulo the page size." -- http://refspecs.linuxbase.org/elf/elf.pdf (page 95) uint32_t p_align = 0x1000; // default page size on linux emit(p_align); if (p_offset % p_align != p_start % p_align) { raise << "segment starting at 0x" << HEXWORD << p_start << " is improperly aligned; alignment for p_offset " << p_offset << " should be " << (p_offset % p_align) << " but is " << (p_start % p_align) << '\n' << end(); return; } // prepare for next segment p_offset += size; } #undef O #undef emit } void write_segment(const segment& s, ostream& out) { for (int i = 0; i < SIZE(s.lines); ++i) { const vector<word>& w = s.lines.at(i).words; for (int j = 0; j < SIZE(w); ++j) { uint8_t x = hex_byte(w.at(j).data); // we're done with metadata by this point out.write(reinterpret_cast<const char*>(&x), /*sizeof(byte)*/1); } } } uint32_t num_words(const segment& s) { uint32_t sum = 0; for (int i = 0; i < SIZE(s.lines); ++i) sum += SIZE(s.lines.at(i).words); return sum; } :(before "End Includes") using std::ios;