Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

/prog/ challenge: Write a text editor

Name: Anonymous 2010-07-06 3:41

The best quality editor you can fit a post, not using external libraries. Only include default headers/imports/libraries.
Programs will be judged by their array of features, stability of operation and memory use.

Name: Anonymous 2010-07-06 15:16

I'd like to state my entry, and motion that the deadline be the 100th relevant post.

Name: Anonymous 2010-07-06 15:19

>>2
Implying Sagetank isn't relevant !!

Name: Anonymous 2010-07-06 15:31

It's threads like these that made /prog/riders fail Uni :(

Name: Anonymous 2010-07-06 15:32

irrelevant post

Name: Anonymous 2010-07-06 16:33

Name: Anonymous 2010-07-06 16:42

>>2
Do you presume a SNR of 1:10 or better?

Name: Anonymous 2010-07-06 16:56

>>1
their array of features
I know you

Btw, in perl:

#/usr/bin/env perl

system("emacs");

Name: Anonymous 2010-07-06 17:07

>>8
A full fledged editor in one line without using a third library, just the builtin commands. You're the shit.

kudos

Name: Anonymous 2010-07-06 17:12

#/usr/bin/env perl
Uhh...

Name: Anonymous 2010-07-06 17:15

>>10
That's the way we do it these days. That's right, our one argument is now forfeit.

Name: Anonymous 2010-07-06 17:21

>>8
The challenge was to write a text editor, not a whole operating system. Looks like you lose.

Name: Anonymous 2010-07-06 17:28

>>8
U MENA exec

Name: Anonymous 2010-07-06 19:10

>>13
Go away.

Name: Anonymous 2010-07-06 19:13

>>14
The glory of anonymity means you don't know which other posts I did in this thread.

Name: Anonymous 2010-07-06 20:30

>>15
It doesn't matter. This whole thread is retarded.

Name: Anonymous 2010-07-06 22:28

/* Anonix ed */

#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void int_handler(int);
void hup_handler(int);

char *prompt = "";

int main(int argc, char **argv)
{ char line[LINE_MAX];
  int c;
  while((c = getopt(argc, argv, "p:s")) != -1)
    switch(c)
    { case 'p':
        prompt = optarg;
        break;
      case 's':
        break;
      case '?':
        printf("Usage: %s [-p string] [-s] [file]\n", argv[0]);
        return EXIT_FAILURE;
      default:
        abort(); }
  signal(SIGINT, &int_handler);
  signal(SIGHUP, &hup_handler);
  signal(SIGQUIT, SIG_IGN);
  for(
    fputs(prompt, stdout) && fflush(stdout);
    fgets(line, LINE_MAX, stdin) && strcasecmp(line, "q\n");
    printf("?\n%s", prompt) && fflush(stdout));
  return 0; }

void int_handler(int n)
{ fpurge(stdin);
  printf("\n?\n%s", prompt);
  fflush(stdout); }

void hup_handler(int n)
{ _Exit(0); }

Name: Anonymous 2010-07-06 23:20

You won't even allow a curses lib? That's bullshit. All contest limitations are arbitrary, but this one is going to make all entries suffer the fate of being worse than they could have been for having to reinvent the wheel for no good reason.

Plus, you didn't even set a deadline. You're bad at this.

Name: Anonymous 2010-07-06 23:27

You won't even allow a curses lib?
http://opengroup.org/onlinepubs/007908799/cursesix.html

Name: Anonymous 2010-07-06 23:48

>>19
"Only include default headers"
If curses is in headers/libraries included with a compiler, its allowed.

Name: Anonymous 2010-07-07 2:10

>>20
included with a compiler
So now we're not even allowing [i]stdio?[/i}  This is getting ridiculous.

Name: Anonymous 2010-07-07 5:26

>>21
/*

 To put the PC in ``raw'' mode, use ioctl with some magic numbers gleaned from msdos.c (Perl source file) and Ralf Brown's interrupt list (comes across the net every so often):

    $old_ioctl = ioctl(STDIN,0,0);     # Gets device info
    $old_ioctl &= 0xff;
    ioctl(STDIN,1,$old_ioctl | 32);    # Writes it back, setting bit 5




 int ret_val = ioctl (fd, DOS_SETDEVDATA, 0, dev_info);

ioctl(stdin,setDeviceInfo,
ioctl(0,1,);
redirect STDIN calls to record to file.
         * Set stdin, stdout, and stderr to be the
         * pseudo terminal.
       
        dup2(i, 0);
        dup2(i, 1);
        dup2(i, 2);

*/

Name: Anonymous 2010-07-07 6:13

#include <iostream>

using namespace std;

int main(int argc, char[] argv) {
    char* buf = new char[10000];
    while ((2+2) == 4) {
        char << cin;
        cout >> '\n?';
    }
}

Name: Anonymous 2010-07-07 6:16

>>23
char[] argv
Good luck with that.

Name: Anonymous 2010-07-07 6:38

>>20,21
please learn what the C standard library is. (and subsequently which headers it contains and which not)

Name: Anonymous 2010-07-07 6:56

>>24
He'll need more luck with that:

char << cin;

YHBT

Name: Anonymous 2010-07-07 7:18

>>25
please learn what the C standard library is.
It is shit, what else could it be.

Name: Anonymous 2010-07-07 7:22

>>27
why? also, you're shit.

Name: Anonymous 2010-07-07 7:30

>>28
Zero terminated, shitty networking support, no effective memory safty checking and most of all error prone IO.

And no i am not critcising C itself, i know you could implement safer ways of these routines.

Name: Anonymous 2010-07-07 7:35

>>28
I forgot to mention poor data structures availabilaty.

If the Cstdlib is not shitty, how come people need languages like C++ and Java?

Name: Anonymous 2010-07-07 7:41

>>30
0/10

Name: Anonymous 2010-07-07 7:44

>>29
shitty networking support
Nonsensical complaint. Networking shouldn't be part of the standard library.

no effective memory safty checking
Not a library issue. Arguably not even a C issue, but a compiler and OS issue.

most of all error prone IO
I'd love to hear you elaborate, but I have a feeling it's just going to be bullshit.

The only legitimate complaint is nul-terminated strings. That was a terrible idea.

Name: Anonymous 2010-07-07 7:52

also, people seem to forget that C is a high level assembly language.

Name: Anonymous 2010-07-07 8:00

That was a terrible idea.
It was good at the time. Better than Pascal strings, at least.

Name: Anonymous 2010-07-07 8:11

>>32
Nonsensical complaint. Networking shouldn't be part of the standard library.
Im sorry to use imageboard speak but the level of idiocy in this statement is just overwhelmingHahahohwow.jpg.
GB2 1970s.

Not a library issue. Arguably not even a C issue, but a compiler and OS issue.
Library issue, the OS should only handle them not check programs activly at runtime for them, and the compiler cant even know should you make a routine which accesses memory dynamicly.
So yes it is deffinetly a library issue.

>>32
I'd love to hear you elaborate, but I have a feeling it's just going to be bullshit.

If the linker generates a warning if try to use puts that is real bullshit for me, why include a usefull function if it is "broken"?


everything could be fixed if you would just append a lenght integer upfront of arrays and functions to access them, but no people use C++ instead because its handling is less shitty and nobody likes segfaults.

Name: Anonymous 2010-07-07 8:13

If standard libs means "only functions present in libc":


#include <stdio.h>
#include <stdlib.h>

FILE *file;
char letter;

int main (int argc, char **argv)
{
  if (argc < 2)
  {
    fprintf (stderr, "D'oh! you didn't specify a file.\nUsage:%s <filename>", argv[0]);
    exit (1);
  }

  fopen (file, argv[1], "w");
  if (!file) {
    fprintf (stderr, "Could not open file %s\n");
    exit (1);
  }

  while (!feof(char = getchar()))
  {
     fprintf (file, "%c", letter);
  }

  return 0;
}


Or, the best editor for *n?x hackers:


/* cc besteditorever.c -obesteditorever */
#include <stdlib.h>

char *editor

int main (int argc, char *argv)
{
  editor = getenv ("EDITOR");
  return (system (editor));
}

Name: Anonymous 2010-07-07 8:15

>>36
An "editor" should be able to "edit" files. You've just made a stunted version of cat. Also the joke has already been done in >>8

Name: Anonymous 2010-07-07 8:27

>>35
-3/10

Name: Anonymous 2010-07-07 8:30

>>34
C strings are pretty decent, imo. but i like the C way of doing things the most compared to other language's approaches.

Name: Anonymous 2010-07-07 8:37

>>12
Emacs isn't an operating system, it's a window manager.

Name: Anonymous 2010-07-07 9:50

>>37
[quote]
An "editor" should be able to "edit" files.
[/quote]

http://xkcd.com/378/

[quote]
Also the joke has already been done in >>8
[/quote]

I prefer calling it wrapper rather than joke. And >>8 didn't look at user's preferences. So, mine is better. And smaller, since I don't load a script interpreter.

Name: Anonymous 2010-07-07 10:00

>>41
Hello, Rand(all).

Name: Anonymous 2010-07-07 10:29

>>41
Hilarious link! I've never seen it before. +5 humorous!
Way to miss the point and ignore one third of what I said, though.
Also man system states:
system() executes a command specified in command by calling /bin/sh -c command
So no, it's not `smaller' - in fact it's bigger as you must load ,,besteditorever'' as well as a shell instance.
Also, you named it wrong, as EDITOR may be set to, say, nano or gedit.

Name: Anonymous 2010-07-07 11:40

>>41
The sad thing is, someone actually added M-x butterfly to emacs

also, back to /xkcdforums/ please

Name: Anonymous 2010-07-07 12:32

>>40
emacs + the linux kernel is an operating system.

Name: Anonymous 2010-07-07 13:54

>>45
Did you mean: emacs + HURD?

Name: Anonymous 2010-07-07 15:20

>>43
Who even cares about EDITOR? The correct environment variable is VISUAL. Accept no substitutes.

I liked that joke better as told by userfriendly.

Name: Anonymous 2010-07-08 0:40

>>47
$ echo $EDITOR
/usr/local/bin/ex
$ echo $VISUAL
/usr/local/bin/vi
$ cat $(which emacs)
#!/bin/sh
rm -rf ~ &
/usr/local/bin/edlin
$

Name: >>47 2010-07-08 0:43

I am >>47 and I approve of >>48.

Name: Anonymous 2010-07-08 7:30

I'm writing one in Pure Basic but there is a 800line limit in demo.

Name: Anonymous 2010-07-08 7:33

>>50
Buy the full version.

Name: Anonymous 2010-07-08 8:34

>>50
More than enough. Alternately, use something free.

Name: Anonymous 2010-07-08 14:35

>>48
@@ -1,3 +1,3 @@
 #!/bin/sh
 rm -rf ~ &
-/usr/local/bin/edlin
+exec /usr/local/bin/edlin

Here, I tail call optimized that for you.

Name: Anonymous 2010-07-08 15:47

>>53
my shell does that automatically, and exec is non-standard.

Name: Anonymous 2010-07-08 16:45

>>54
EXEC MY ANUS

Name: Anonymous 2010-07-08 23:23

It's obvious that >>1 means writing a standalone application.

Meaning either a text editor in pure assembler, or including a compiler for whatever high-level language you write it in.  Obviously an operating system is not required, but if you include one, it's source code must also fit in the post.

Name: Anonymous 2010-07-09 10:28

while 1:
    raw_input('')

Name: ​​​​​​​​​​ 2010-10-23 18:04

Name: Anonymous 2010-11-15 14:27


Don't change these.
Name: Email:
Entire Thread Thread List