[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Unixen and Dosfish
Alexander Neundorf sent me patch a while ago that had a Unix to DOS and
DOS to Unix conversion option. I like the idea but the implementation
isn't quite to my liking. For one thing converting Unix to DOS followed
by DOS to Unix (without saving/reloading the file) doesn't produce the
same file. You probably would never need this but I'd like it to work.
More importantly I don't particularly like the option being on the File
menu. I'd prefer something more transparent. I'd like to be able to
load a DOS text file, edit, and save as a DOS text file without doing
anything. Currently DOS text files produce and extra blank line for
the return. Perhaps a toggle at the bottom (or elsewhere) of the window
that indicates whether it is a DOS or Unix text file. Or possibly add
the ability to convert on save as. (Don't know what to do about a
partial DOS, partial UNIX text file.)
Anyway here is Alexander's implementation.
Dennis Payne
dulsi@identicalsoftware.com
diff -u we_block.c.orig we_block.c
--- we_block.c.orig Sat Jun 5 12:15:29 1999
+++ we_block.c Wed Jun 16 18:54:53 1999
@@ -712,6 +712,52 @@
return(0);
}
+/************************
+converts textfiles from unix to dos and otherwise
+mode=0: unix to dos
+mode=1: dos to unix
+************************/
+int unix_to_dos(FENSTER *f)
+{
+ convert_unix_dos(f,0);
+ return (0);
+};
+
+int dos_to_unix(FENSTER *f)
+{
+ convert_unix_dos(f,1);
+ return (0);
+};
+
+int convert_unix_dos(FENSTER *f, int mode)
+{
+ BUFFER *b;
+ SCHIRM *screen;
+ int i=0,y=0;
+
+ for(i = f->ed->mxedt; i > 0 && f->ed->f[i]->dtmd <= 'Z'; i--);
+ if(i <= 0) return(0);
+ e_switch_window(f->ed->edt[i], f);
+ f = f->ed->f[f->ed->mxedt];
+ b = f->b;
+ screen = f->s;
+
+ if (mode==0)
+ for(y=0;y<b->mxlines;y++)
+ {
+ if (b->bf[y].s[ b->bf[y].len ]=='\n')
+ {
+ e_ins_nchar(b, screen," ",b->bf[y].len, y, 1);
+ b->bf[y].s[ b->bf[y].len-1]='\r';
+ }
+ } else
+ if (mode==1)
+ for(y=1;y<b->mxlines;y++) e_del_line(y,b,screen);
+ f->save++;
+ e_schirm(f, 1);
+ return(0);
+}
+
/* block: up- or downcase
mode=0 every character downcase
mode=1 every character upcase
diff -u we_menue.c.orig we_menue.c
--- we_menue.c.orig Sat Jun 5 12:37:41 1999
+++ we_menue.c Wed Jun 16 21:08:38 1999
@@ -25,6 +25,8 @@
int e_hp_back(FENSTER *f);
int e_hp_prev(FENSTER *f);
int e_hp_next(FENSTER *f);
+int unix_to_dos(FENSTER *f);
+int dos_to_unix(FENSTER *f);
/* main menu control bar */
int WpeHandleMainmenu(int n, FENSTER *f)
@@ -70,7 +72,7 @@
mainmenu[1].position = -3;
#ifdef UNIX
mainmenu[1].width = 24;
- mainmenu[1].no_of_items = 12;
+ mainmenu[1].no_of_items = 14;
if((mainmenu[1].menuitems = MALLOC(mainmenu[1].no_of_items * sizeof(OPTK))) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, f->fb);
if(f->ed->edopt & 1)
@@ -78,14 +80,14 @@
mainmenu[1].menuitems[0] = WpeFillSubmenuItem("File-Manager F2", 0, 'M', WpeManager);
mainmenu[1].menuitems[1] = WpeFillSubmenuItem("ADd F.-Mng Shift F2", 1, 'D', WpeManagerFirst);
mainmenu[1].menuitems[3] = WpeFillSubmenuItem("Save Alt F2", 0, 'S', e_m_save);
- mainmenu[1].menuitems[11] = WpeFillSubmenuItem("Quit Alt F4", 0, 'Q', e_quit);
+ mainmenu[1].menuitems[13] = WpeFillSubmenuItem("Quit Alt F4", 0, 'Q', e_quit);
}
else
{
mainmenu[1].menuitems[0] = WpeFillSubmenuItem("File-Manager F3", 0, 'M', WpeManager);
mainmenu[1].menuitems[1] = WpeFillSubmenuItem("ADd F.-Mng Ctrl F3", 1, 'D', WpeManagerFirst);
mainmenu[1].menuitems[3] = WpeFillSubmenuItem("Save F2", 0, 'S', e_m_save);
- mainmenu[1].menuitems[11] = WpeFillSubmenuItem("Quit Alt X", 0, 'Q', e_quit);
+ mainmenu[1].menuitems[13] = WpeFillSubmenuItem("Quit Alt X", 0, 'Q', e_quit);
}
mainmenu[1].menuitems[2] = WpeFillSubmenuItem("New", 0, 'N', e_new);
mainmenu[1].menuitems[4] = WpeFillSubmenuItem("Save As", 5, 'A', WpeSaveAsManager);
@@ -95,6 +97,8 @@
mainmenu[1].menuitems[8] = WpeFillSubmenuItem("Find", 0, 'F', WpeFindWindow);
mainmenu[1].menuitems[9] = WpeFillSubmenuItem("Grep", 0, 'G', WpeGrepWindow);
mainmenu[1].menuitems[10] = WpeFillSubmenuItem("Print File", 0, 'P', WpePrintFile);
+ mainmenu[1].menuitems[11] = WpeFillSubmenuItem("Unix to DOS", 0, 'U', unix_to_dos);
+ mainmenu[1].menuitems[12] = WpeFillSubmenuItem("DOS to Unix" , 1, 'O', dos_to_unix);
#endif
mainmenu[2].position = -3;
mainmenu[2].width = 27;