Permalink
Browse files

Add newlines

  • Loading branch information...
1 parent 4cb99b6 commit 15dd7f8bae6027b04e97b44e4812f6aa7b89da39 @dj3vande dj3vande committed with Mar 30, 2010
Showing with 16 additions and 11 deletions.
  1. +16 −11 rpnr.l
View
27 rpnr.l
@@ -69,10 +69,10 @@ void do_assignment(void) {
char *arg, *obj;
get_stackitems(&arg, &obj);
- obj = xrealloc(obj, (strlen(obj)+strlen("=()")+strlen(arg)+1)*sizeof(*obj));
- strcat(obj, "=(");
+ obj = xrealloc(obj, (strlen(obj)+strlen("=(\n\n)")+strlen(arg)+1)*sizeof(*obj));
+ strcat(obj, "=(\n");
strcat(obj, arg);
- strcat(obj, ")");
+ strcat(obj, "\n)");
push(obj);
}
@@ -86,29 +86,34 @@ void do_lambda(void) {
obj[0] = '|';
}
obj[strlen(obj)-1] = '|';
- obj = xrealloc(obj, (strlen(obj)+strlen("lambda{ }")+strlen(arg)+1)*sizeof(*obj));
- memmove(obj+strlen("lambda{")-(obj[0] == ':'), obj, (strlen(obj)+1)*sizeof(*obj));
- strcpy(obj, "lambda");
- obj[6] = '{';
+ obj = xrealloc(obj, (strlen(obj)+strlen("lambda{\n \n}")+strlen(arg)+1)*sizeof(*obj));
+ memmove(obj+strlen("lambda{\n")-(obj[0] == ':'), obj, (strlen(obj)+1)*sizeof(*obj));
+
+ /*Prepend (the '\n' overwrites the '\0' strcpy adds)*/
+ strcpy(obj, "lambda{");
+ obj[7] = '\n';
+
+ /*Append these*/
strcat(obj, " ");
strcat(obj, arg);
- strcat(obj, "}");
+ strcat(obj, "\n}");
push(obj);
+ /*Help brace-matching editors: }*/
}
/* Process a "message" by popping top two elements and pushing the result */
void do_message(const char *message) {
char *arg, *obj;
get_stackitems(&arg, &obj);
- obj = xrealloc(obj, (strlen(obj)+strlen("().magic_send(,())")+strlen(":''")+strlen(message)+strlen(arg)+1)*sizeof(*obj));
+ obj = xrealloc(obj, (strlen(obj)+strlen("().\nmagic_send(,\n())")+strlen(":''")+strlen(message)+strlen(arg)+1)*sizeof(*obj));
memmove(obj+1, obj, (strlen(obj)+1)*sizeof(*obj));
obj[0] = '(';
- strcat(obj, ").magic_send(");
+ strcat(obj, ").\nmagic_send(");
if(message[0] != ':') strcat(obj, ":'");
strcat(obj, message);
if(message[0] != ':') strcat(obj, "'");
- strcat(obj, ",(");
+ strcat(obj, ",\n(");
strcat(obj, arg);
strcat(obj, "))");
free(arg);

0 comments on commit 15dd7f8

Please sign in to comment.