[openbeos] Terminal - first patch

Hello everyone,

I finally found some time today to do a bit of the work I already 
promised some time ago.
I'm sending a first patch which makes it possible to load the R5 config 
files via the command line (Option -p) and I hope someone will check it 
in ;) The settings-code is a bit of a mess currently but I'll hopefully 
have 
time to clean that up soon.

cya,
Daniel Furrer


? patch
Index: Coding.h
===================================================================
RCS file: /cvsroot/open-beos/current/src/apps/terminal/MYOB/Coding.h,v
retrieving revision 1.1
diff -r1.1 Coding.h
36a37
>   M_UTF8,       /* UTF-8 */
53c54
<   M_EUC_KR,
---
>   M_EUC_KR
62d62
<   M_UTF8        /* UTF-8 */
65a66
>   0,
95a97
>   {"UTF-8", "UTF8", 'U', M_UTF8},
111d112
<   {"UTF-8", "UTF8", 'U', M_UTF8},
Index: PrefHandler.cpp
===================================================================
RCS file: /cvsroot/open-beos/current/src/apps/terminal/MYOB/PrefHandler.cpp,v
retrieving revision 1.1
diff -r1.1 PrefHandler.cpp
40a41
> #include "Coding.h"
41a43,82
> #include "TermConst.h"
> 
> /*
>  * Startup preference settings.
>    */
> const prefDefaults  termDefaults[] ={
>   { PREF_COLS,                        "80" },
>   { PREF_ROWS,                        "25" },
> 
>   { PREF_HALF_FONT_FAMILY,    "Courier10 BT" },
>   { PREF_HALF_FONT_SIZE,      "12" },
>   { PREF_FULL_FONT_FAMILY,    "Haru Tohaba" },
>   { PREF_FULL_FONT_SIZE,      "12" },
> 
>   { PREF_TEXT_FORE_COLOR,     "  0,   0,   0" },
>   { PREF_TEXT_BACK_COLOR,     "255, 255, 255" },
>   { PREF_SELECT_FORE_COLOR,   "255, 255, 255" },
>   { PREF_SELECT_BACK_COLOR,   "  0,   0,   0" },
>   { PREF_CURSOR_FORE_COLOR,   "255, 255, 255" },
>   { PREF_CURSOR_BACK_COLOR,   "  0,   0,   0" },
> 
>   { PREF_IM_FORE_COLOR,               "  0,   0,   0" },
>   { PREF_IM_BACK_COLOR,               "152, 203, 255" },
>   { PREF_IM_SELECT_COLOR,     "255, 152, 152" },
> 
>   { PREF_SHELL,                       "/bin/sh -login" },
>   { PREF_HISTORY_SIZE,                "500" },
> 
>   { PREF_TEXT_ENCODING,               "UTF-8" },
> 
>   { PREF_SELECT_MBUTTON,      "Button 1"},
>   { PREF_PASTE_MBUTTON,               "Button 2"},
>   { PREF_SUBMENU_MBUTTON,     "Button 3"},
>   { PREF_MOUSE_IMAGE,         "Hand cursor"},
>   { PREF_DRAGN_COPY,          "0"},
> 
>   { PREF_GUI_LANGUAGE,                "English"},
>   { PREF_IM_AWARE,            "0"},
>   { NULL, NULL},
> };
49a91
>   OpenText(TERM_PREF, termDefaults);
158,159c200
<   buf = mPrefContainer.FindString(key);
<   if (buf == NULL)
---
>   if (mPrefContainer.FindString(key, &buf) != B_OK)
161a203
>   //printf("%x GET %s: %s\n", this, key, buf);
163d204
<   
234a276
>   //printf("%x SET %s: %s\n", this, key, data);
265a308,310
>   // Future: It would be nice if we could simply use a flatened BMessage to
>   // save the settings. (Who cares about compatibility in this case anyway?)
> 
267,268c312,341
<   mPrefContainer.MakeEmpty();
<   return mPrefContainer.Unflatten(&file);
---
>   //mPrefContainer.MakeEmpty();
>   //mPrefContainer.Unflatten(&file);
>   off_t size;
>   if (file.GetSize(&size) != B_OK || size != sizeof(struct termprefs))
>     return B_ERROR;
> 
>   struct termprefs prefs;
>   file.Read(&prefs, size);
>   if (prefs.magic != TP_MAGIC || prefs.version != TP_VERSION)
>     return B_ERROR;
> 
>   //Valid settings file!
>   setInt32(PREF_COLS, prefs.cols);
>   setInt32(PREF_ROWS, prefs.rows);
>   setInt32(PREF_HALF_FONT_SIZE, prefs.font_size);
>   setInt32(PREF_FULL_FONT_SIZE, prefs.font_size);
>   char *font_family = strtok(prefs.font, "/");
>   char *font_style = strtok(NULL, "");
>   setString(PREF_FULL_FONT_FAMILY, font_family);
>   setString(PREF_FULL_FONT_STYLE, font_style);
>   setString(PREF_HALF_FONT_FAMILY, font_family);
>   setString(PREF_HALF_FONT_STYLE, font_style);
>   setRGB(PREF_TEXT_BACK_COLOR, prefs.bg);
>   setRGB(PREF_TEXT_FORE_COLOR, prefs.fg);
>   setRGB(PREF_CURSOR_BACK_COLOR, prefs.curbg);
>   setRGB(PREF_CURSOR_FORE_COLOR, prefs.curfg);
>   setRGB(PREF_SELECT_BACK_COLOR, prefs.selbg);
>   setRGB(PREF_SELECT_FORE_COLOR, prefs.selfg);
>   setString(PREF_TEXT_ENCODING, encoding_table[prefs.encoding].name);
>   return B_OK;
Index: PrefHandler.h
===================================================================
RCS file: /cvsroot/open-beos/current/src/apps/terminal/MYOB/PrefHandler.h,v
retrieving revision 1.1
diff -r1.1 PrefHandler.h
37a38,63
> #define TP_MAGIC 0xf1f2f3f4
> #define TP_VERSION 0x02
> #define TP_FONT_NAME_SZ 128
> 
> struct termprefs {
>         uint32 magic;
>         uint32 version;
>         float x;
>         float y;
>         uint32 cols;
>         uint32 rows;
>         uint32 tab_width;
>         uint32 font_size;
>         char font[TP_FONT_NAME_SZ]; // "Family/Style"
>         uint32 cursor_blink_rate; // blinktime in µs = 1000000
>         uint32 refresh_rate; // ??? = 0
>         rgb_color bg;
>         rgb_color fg;
>         rgb_color curbg;
>         rgb_color curfg;
>         rgb_color selbg;
>         rgb_color selfg;
>         char encoding; // index in the menu (0 = UTF-8)
>         char unknown[3];
> };
> 
Index: TermApp.cpp
===================================================================
RCS file: /cvsroot/open-beos/current/src/apps/terminal/MYOB/TermApp.cpp,v
retrieving revision 1.1
diff -r1.1 TermApp.cpp
92c92
<   gTermPref = new PrefHandler ();
---
>   gTermPref = new PrefHandler();
105,143c105
< /*
<  * Startup preference settings.
<    */
< const prefDefaults  termDefaults[] ={
<   { PREF_COLS,                        "80" },
<   { PREF_ROWS,                        "25" },
< 
<   { PREF_HALF_FONT_FAMILY,    "Courier10 BT" },
<   { PREF_HALF_FONT_SIZE,      "12" },
<   { PREF_FULL_FONT_FAMILY,    "Haru Tohaba" },
<   { PREF_FULL_FONT_SIZE,      "12" },
< 
<   { PREF_TEXT_FORE_COLOR,     "  0,   0,   0" },
<   { PREF_TEXT_BACK_COLOR,     "255, 255, 255" },
<   { PREF_SELECT_FORE_COLOR,   "255, 255, 255" },
<   { PREF_SELECT_BACK_COLOR,   "  0,   0,   0" },
<   { PREF_CURSOR_FORE_COLOR,   "255, 255, 255" },
<   { PREF_CURSOR_BACK_COLOR,   "  0,   0,   0" },
< 
<   { PREF_IM_FORE_COLOR,               "  0,   0,   0" },
<   { PREF_IM_BACK_COLOR,               "152, 203, 255" },
<   { PREF_IM_SELECT_COLOR,     "255, 152, 152" },
< 
<   { PREF_SHELL,                       "/bin/sh -login" },
<   { PREF_HISTORY_SIZE,                "500" },
< 
<   { PREF_TEXT_ENCODING,               "UTF-8" },
< 
<   { PREF_SELECT_MBUTTON,      "Button 1"},
<   { PREF_PASTE_MBUTTON,               "Button 2"},
<   { PREF_SUBMENU_MBUTTON,     "Button 3"},
<   { PREF_MOUSE_IMAGE,         "Hand cursor"},
<   { PREF_DRAGN_COPY,          "0"},
< 
<   { PREF_GUI_LANGUAGE,                "English"},
<   { PREF_IM_AWARE,            "0"},
<   { NULL, NULL},
< };
<  
---
> 
158,162d119
<   // gTermPref is not empty when App opened by pref file
<   if (gTermPref->IsEmpty()){
<     gTermPref->OpenText(TERM_PREF, termDefaults);
<   }
<   
181,185d137
<   if (geometry_requested) {
<     gTermPref->setInt32 (PREF_ROWS, fRows);
<     gTermPref->setInt32 (PREF_COLS, fCols);
<   }
< 
229c181
<     this->RunNewTerm ();
---
>     this->RunNewTerm();
306c258
<       gTermPref->OpenText(value);
---
>       gTermPref->Open(value);
328,329c280,282
<       fCols = width;
<       fRows = height;
---
>       gTermPref->setInt32 (PREF_COLS, width);
>       gTermPref->setInt32 (PREF_ROWS, height);
> 
357,365c310,314
<       if (text_to_rgb (value, &color, buffer)) {
<         if (gTermPref->IsEmpty()){
<           gTermPref->OpenText(TERM_PREF, termDefaults);
<         }
<         gTermPref->setRGB (standard_args[i].prefname, color);
<       }
<       else {
<         fprintf (stderr, "%s: invalid color string -- %s\n", argv[0], value);
<       }
---
>         if (text_to_rgb (value, &color, buffer)) {
>             gTermPref->setRGB (standard_args[i].prefname, color);
>           } else {
>             fprintf (stderr, "%s: invalid color string -- %s\n", argv[0], 
> value);
>         }
Index: TermWindow.cpp
===================================================================
RCS file: /cvsroot/open-beos/current/src/apps/terminal/MYOB/TermWindow.cpp,v
retrieving revision 1.1
diff -r1.1 TermWindow.cpp
65c65
< // Gloval Preference Handler
---
> // Global Preference Handler

Other related posts: