"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/ComGlyph/attrdialog.c" (9 Oct 2020, 6472 Bytes) of package /linux/misc/ivtools-ivtools-2.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "attrdialog.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright 1995-1997 Vectaport Inc.
    3  *
    4  * Permission to use, copy, modify, distribute, and sell this software and
    5  * its documentation for any purpose is hereby granted without fee, provided
    6  * that the above copyright notice appear in all copies and that both that
    7  * copyright notice and this permission notice appear in supporting
    8  * documentation, and that the names of the copyright holders not be used in
    9  * advertising or publicity pertaining to distribution of the software
   10  * without specific, written prior permission.  The copyright holders make
   11  * no representations about the suitability of this software for any purpose.
   12  * It is provided "as is" without express or implied warranty.
   13  *
   14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
   15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
   16  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
   17  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
   18  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
   19  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
   20  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   21  * 
   22  */
   23 
   24 #include <ComGlyph/attrdialog.h>
   25 #include <Attribute/attrlist.h>
   26 
   27 #include <ComTerp/comvalue.h>
   28 #include <ComTerp/ctrlfunc.h>
   29 #include <ComTerp/numfunc.h>
   30 #include <ComTerp/comterpserv.h>
   31 #include <ComTerp/strmfunc.h>
   32 
   33 #include <IVGlyph/strchooser.h>
   34 #include <IVGlyph/textedit.h>
   35 #include <IVGlyph/textform.h>
   36 #include <IVGlyph/textwindow.h>
   37 #include <IVGlyph/textview.h>
   38 
   39 #include <IV-look/kit.h>
   40 #include <IV-look/mf_kit.h>
   41 
   42 #include <InterViews/action.h>
   43 #include <InterViews/event.h>
   44 #include <InterViews/layout.h>
   45 #include <InterViews/style.h>
   46 #include <InterViews/session.h>
   47 #include <InterViews/target.h>
   48 
   49 #include <iostream.h>
   50 #include <stdio.h>
   51 #include <string.h>
   52 #include <strstream>
   53 
   54 /*****************************************************************************/
   55 
   56 implementActionCallback(AttrDialogImpl)
   57 
   58 AttrDialog* AttrDialog::instance_ = nil;
   59 
   60 AttrDialog::AttrDialog(boolean session, int argc, char** argv, boolean init) 
   61 : TerpDialog(session, argc, argv, false)
   62 {
   63     if (init) _init(nil, session, argc, argv);
   64 }
   65 
   66 AttrDialog::AttrDialog(ComTerpServ* comterp, boolean session, int argc, char** argv, boolean init) 
   67 : TerpDialog(session, argc, argv, false)
   68 {
   69     if (init) _init(comterp, session, argc, argv);
   70 }
   71 
   72 void AttrDialog::_init(ComTerpServ* comterp, boolean session, int argc, char** argv) 
   73 {
   74     impl_ = new AttrDialogImpl();
   75     AttrDialogImpl& cdi = *(AttrDialogImpl*)impl_;
   76     cdi.kit_ = WidgetKit::instance();
   77     cdi.initterp(comterp);
   78     focus(cdi.init(this, WidgetKit::instance()->style(), session, argc, argv));
   79 }
   80 
   81 
   82 AttrDialog::~AttrDialog() {
   83 }
   84 
   85 AttrDialog& AttrDialog::instance() {
   86     if (!instance_) {
   87         Style* style;
   88     style = new Style(Session::instance()->style());
   89     style->attribute("subcaption", "Evaluate Attribute Expressions");
   90     style->attribute("open", "AttrExpr");
   91     instance_ = new AttrDialog();
   92     Resource::ref(instance_);
   93     }
   94     return *instance_;
   95 }
   96 
   97 void AttrDialog::instance(AttrDialog* instance) {
   98     if (instance_)
   99         Unref(instance_);
  100     Resource::ref(instance);
  101     instance_ = instance;
  102 }
  103 
  104 void AttrDialog::next_expr(const char* expr) {
  105     delete (((AttrDialogImpl*)impl_)->next_expr_);
  106     ((AttrDialogImpl*)impl_)->next_expr_ = strdup(expr);
  107     delete (((AttrDialogImpl*)impl_)->next_code_);
  108     ((AttrDialogImpl*)impl_)->next_code_ = 
  109         comterpserv()->gen_code(expr, ((AttrDialogImpl*)impl_)->next_len_);
  110 }
  111 
  112 void AttrDialog::true_expr(const char* expr) {
  113     delete (((AttrDialogImpl*)impl_)->true_expr_);
  114     ((AttrDialogImpl*)impl_)->true_expr_ = strdup(expr);
  115     delete (((AttrDialogImpl*)impl_)->true_code_);
  116     ((AttrDialogImpl*)impl_)->true_code_ = 
  117         comterpserv()->gen_code(expr, ((AttrDialogImpl*)impl_)->true_len_);
  118 }
  119 
  120 void AttrDialog::false_expr(const char* expr) {
  121     delete (((AttrDialogImpl*)impl_)->false_expr_);
  122     ((AttrDialogImpl*)impl_)->false_expr_ = strdup(expr);
  123     delete (((AttrDialogImpl*)impl_)->false_code_);
  124     ((AttrDialogImpl*)impl_)->false_code_ = 
  125         comterpserv()->gen_code(expr, ((AttrDialogImpl*)impl_)->false_len_);
  126 }
  127 
  128 void AttrDialog::done_expr(const char* expr) {
  129     delete (((AttrDialogImpl*)impl_)->done_expr_);
  130     ((AttrDialogImpl*)impl_)->done_expr_ = strdup(expr);
  131     delete (((AttrDialogImpl*)impl_)->done_code_);
  132     ((AttrDialogImpl*)impl_)->done_code_ = 
  133         comterpserv()->gen_code(expr, ((AttrDialogImpl*)impl_)->done_len_);
  134 }
  135 
  136 
  137 
  138 /*****************************************************************************/
  139 
  140 AttrDialogImpl::AttrDialogImpl() { 
  141     next_code_ = nil;
  142     true_code_ = nil;
  143     false_code_ = nil;
  144     next_expr_ = nil;
  145     true_expr_ = nil;
  146     false_expr_ = nil;
  147     next_len_ = 0;
  148     true_len_ = 0;
  149     false_len_ = 0;
  150     return; 
  151 }
  152 
  153 InputHandler* AttrDialogImpl::init(TerpDialog* d, Style* s, boolean session, int argc, char** argv) {
  154   InputHandler* ih = TerpDialogImpl::init(d, s, session, argc, argv);
  155   _eval_button->action(new ActionCallback(AttrDialogImpl)(this, &AttrDialogImpl::eval));
  156   return ih;
  157 }
  158 
  159 void AttrDialogImpl::eval() {
  160     char exprbuf[BUFSIZ];
  161     const char* expr = expredit_->text();
  162     if (expr[strlen(expr)-1] != '\n') 
  163         sprintf(exprbuf, "%s\n", expr);
  164     else
  165         sprintf(exprbuf, "%s", expr);
  166 
  167     
  168     int exprlen;
  169     postfix_token* exprcode = terpserv_->gen_code(exprbuf, exprlen);
  170 
  171     ComValue retval = ComValue::nullval();
  172 
  173     do {
  174 
  175         retval = terpserv_->run(exprcode, exprlen);
  176     
  177         const char* errmsg = terpserv_->errmsg();
  178 
  179         if (*errmsg) {
  180 
  181             result_->textvalue("");
  182             err_->textvalue(errmsg);
  183             return;
  184 
  185         } else {
  186 
  187         const int bufsiz = BUFSIZ;
  188         char buf[bufsiz];
  189         std::strstream outstr(buf, bufsiz);
  190         outstr << retval;
  191         outstr.put('\0');
  192             result_->textvalue(buf);
  193             err_->textvalue("");
  194 
  195         if (true_code_ && false_code_)
  196           retval = retval.boolean_val() ? 
  197             terpserv_->run(true_code_, true_len_) :
  198           terpserv_->run(false_code_, false_len_);
  199         
  200         }
  201     
  202         resultview_->update(result_);
  203         errview_->update(err_);
  204 
  205     
  206         if (next_code_) 
  207       retval = terpserv_->run(next_code_, next_len_);
  208 
  209     } while (retval.boolean_val());
  210     
  211     if (done_code_) 
  212       retval = terpserv_->run(done_code_, done_len_);
  213 }