Browse code

fix bug: when loading a file, was not recognizing correctly if file ended in a newline or not

Dario Rodriguez authored on 09/10/2020 21:50:11
Showing 1 changed files
... ...
@@ -163,7 +163,7 @@ fprintf(stderr,"QUESTION INIT: %s: %s\n",re->question->title,re->question->body)
163 163
                                 /* check if last character of file is '\n', if not, add it */
164 164
                                 if(redata_getused(re->data)==0
165 165
                                   || (redata_line_rawinfo(re->data,redata_getused(re->data)-1,&startpos,&startptr,&len,NULL)!=-1
166
-                                    && len>0 && startptr[len-1]!='\0')) {
166
+                                    && len>0 && startptr[len-1]!='\n')) {
167 167
                                         redata_op_add(re->data,redata_getused(re->data),"\n",1,NULL);
168 168
                                         re->command=COMMAND_WARNING;
169 169
                                         snprintf(re->commandbuf,sizeof(re->commandbuf),"Added missing \\n at end of file");
... ...
@@ -866,7 +866,9 @@ re_rtrim(re_t *re, long curpos, int *trimmed)
866 866
            len>1 && start[len-1]=='\n' && start[len-2]==' ' && curpos==(startpos+len-1)) {
867 867
                 for(n=1;(n+1)<(len-1) && start[len-1-n-1]==' ';n++)
868 868
                         ;
869
+#if 0
869 870
 fprintf(stderr,"Trying to DELETE SPACES del %i bytes\n",n);
871
+#endif
870 872
                 redata_op_del(re->data,curpos-n,n,NULL);
871 873
                 re->cursorpos-=n;
872 874
                 if(trimmed!=NULL)