473,508 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

waitbar function error. Pls help

25 New Member
Hello,
this waitbar function (similar to the one in matlab) in C++ pops an error. Pls correct the error for me.
Thanks,
prads
Expand|Select|Wrap|Line Numbers
  1. <code>
  2.  
  3. #include <octave/oct.h>
  4. #if defined (HAVE_TERM_H)
  5. #  include <term.h>
  6. #elif defined (HAVE_TERMCAP_H)
  7. #  include <termcap.h>
  8. #endif
  9.  
  10. #define BUF_SIZE    256
  11. #define MAX_LEN        240
  12. #define DEFAULT_LEN    50
  13. #define    BAR_CHAR    '#'
  14. #define SPACING        3
  15.  
  16. static bool no_terminal=false;
  17.  
  18. DEFUN_DLD(waitbar, args, nargout,
  19. "waitbar(...);\n\
  20.  WAITBAR displays a text-based wait bar. This function\n\
  21.  is similar to the Matlab waitbar command, but it is\n\
  22.  a text, rather than graphical function.\n\n\
  23.  A typical usage of WAITBAR in a lengthy computation\n\
  24.  (inside a FOR loop, for example) is as follows:\n\n\
  25.  for i=1:1000\n\
  26.      ## computation\n\
  27.      waitbar(i/1000);\n\
  28.  end\n\n\
  29.  WAITBAR(X,TITLE), where 0 <= X <= 1, sets the position of\n\
  30.  the waitbar to the fractional length X. Values of X exactly\n\
  31.  equal to 0 or 1 clear the waitbar. The optional second\n\
  32.  argument TITLE sets the waitbar caption to TITLE.\n\n\
  33.  If Octave is running in a smart terminal, the width is\n\
  34.  automatically detected, and the title is displayed in the\n\
  35.  waitbar (and truncated if it is too long). Otherwise, the\n\
  36.  title is not displayed and the width is initialized to a\n\
  37.  default of 50 characters, or it can be set to N characters\n\
  38.  with WAITBAR(0,N). If no terminal is detected (such as when\n\
  39.  Octave is run in batch mode and output is redirected), no\n\
  40.  output is generated.\n\n\
  41.  For compatibility with the Matlab version of this function\n\
  42.  (which is graphical rather than text-based), additional\n\
  43.  arguments are ignored, but there are no guarantees of perfect\n\
  44.  compatibility.") 
  45. {
  46.   static char print_buf[BUF_SIZE];
  47.   static int n_chars_old;
  48.   static int pct_int_old;
  49.   static int length;
  50. #if defined(USE_TERM)
  51.   static char term_buffer[1024];
  52.   static char *begin_rv, *end_rv;
  53.   static int brvlen, ervlen, pct_pos;
  54.   static bool smart_term;
  55.   static bool newtitle = false;
  56.   static charMatrix title;
  57.   int j;
  58. #endif
  59.   static char *term;
  60.   static bool init;
  61.  
  62.   double pct;
  63.   int i;
  64.  
  65.   octave_value_list retval;
  66.   retval(0) = Matrix(0,0);
  67.   int nargin = args.length();
  68.   if (nargin < 1) {
  69.     print_usage ();
  70.     return retval;
  71.   }
  72.  
  73.   if(no_terminal)
  74.     return retval;
  75.  
  76.   pct    = args(0).double_value();
  77.   if(pct>1.0)    pct    = 1.0;        // to prevent overflow
  78.  
  79. #if defined(USE_TERM)
  80.   if(nargin==2 && args(1).is_string())
  81.     {
  82.       newtitle = true;
  83.       title = args(1).string_value();
  84.     }
  85.   if(nargin==3)
  86.     {
  87.       newtitle = true;
  88.       title = args(2).string_value();
  89.     }
  90. #endif
  91.  
  92.   if(pct==0.0 || pct==1.0)
  93.     {
  94.       init = true;
  95.       term = getenv("TERM");
  96.       if(!term)
  97.     {
  98.       no_terminal    = true;
  99.       return retval;
  100.     }
  101. #if defined (USE_TERM)
  102.       i = tgetnum("co");
  103.       smart_term = i ? true : false;
  104.       if(nargin==1 || args(1).is_string())
  105.     length = smart_term ? i-1 : DEFAULT_LEN;
  106. #else
  107.       if(nargin==1)
  108.         length = DEFAULT_LEN;
  109. #endif
  110.       else
  111.     if(nargin==2 && !(args(1).is_string()))
  112.     {
  113.       length    = args(1).int_value();
  114.       if(length>MAX_LEN)    length    = MAX_LEN;
  115.       if(length<=0)        length    = DEFAULT_LEN;
  116.     }
  117. #if defined (USE_TERM)
  118.       pct_pos = length/2-2;
  119.       if(smart_term)
  120.     {
  121.       // get terminal strings ("rv"="reverse video")
  122.       char* buf_ptr    = term_buffer;
  123.       begin_rv    = tgetstr("so", &buf_ptr);
  124.       end_rv    = tgetstr("se", &buf_ptr);
  125.       brvlen = 0;    buf_ptr = begin_rv;
  126.       while(buf_ptr[++brvlen]);
  127.       ervlen = 0;    buf_ptr = end_rv;
  128.       while(buf_ptr[++ervlen]);
  129.  
  130.       // initialize print buffer
  131.       for(i=0; i<BUF_SIZE; ++i)
  132.         print_buf[i]    = ' ';
  133.       print_buf[length+brvlen+ervlen+1] = '\r';
  134.       print_buf[length+brvlen+ervlen+2] = '\0';
  135.       for(i=0; i<brvlen; ++i)
  136.         print_buf[i]    = begin_rv[i];
  137.       for(i=0; i<ervlen; ++i)
  138.         print_buf[i+brvlen]    = end_rv[i];
  139.       fputs(print_buf,stdout);
  140.       if(title.length())
  141.         newtitle    = true;
  142.     }
  143.       else
  144.     {
  145. #endif
  146.       for(i=0; i<BUF_SIZE; ++i)
  147.         print_buf[i]    = ' ';
  148.       print_buf[length+8]    = '\r';
  149.       print_buf[length+9]    = '\0';
  150.       fputs(print_buf,stdout);
  151.       print_buf[0]        = '[';
  152.       print_buf[length+1]    = ']';
  153. #if defined (USE_TERM)
  154.     }
  155. #endif
  156.       n_chars_old    = 0;
  157.       fflush(stdout);
  158.       return retval;
  159.     }
  160.   else
  161.     {
  162.       // calculate position
  163.       int n_chars=(int)(pct*length+0.5);
  164.       int pct_int=(int)(pct*100.0+0.5);
  165.  
  166.       // check to see if we got this far without initialization
  167.       if(init==false)
  168.     {
  169.       Fwaitbar(octave_value(0.0),0);
  170.       fputs(print_buf,stdout);
  171.       fflush(stdout);
  172.     }
  173.  
  174.       // check to see of output needs to be updated
  175. #if !defined (USE_TERM)
  176.       if(n_chars!=n_chars_old || pct_int!=pct_int_old)
  177.     {
  178. #else
  179.       if(n_chars!=n_chars_old || pct_int!=pct_int_old || newtitle)
  180.     {
  181.       if(smart_term)
  182.         {
  183.           static char pct_str[5];
  184.           sprintf(pct_str,"%3i%%",pct_int);
  185.  
  186.           // Insert the title
  187.           if(newtitle)
  188.         {
  189.           pct_pos    = length-SPACING*2;
  190.           for(i=SPACING+brvlen; i<pct_pos+brvlen-SPACING;  ++i)
  191.             print_buf[ i>=n_chars_old+brvlen ? i+ervlen : i ] = ' ';
  192.           for(i=SPACING+brvlen, j=0; j<title.length(); ++i, ++j)
  193.             if(i<pct_pos+brvlen-SPACING)
  194.               print_buf[ i>=n_chars_old ? i+ervlen : i ] = title(0,j);
  195.           newtitle    = false;
  196.         }
  197.  
  198.           // Insert the percentage string
  199.           for(i=pct_pos+brvlen, j=0; j<4; ++i, ++j)
  200.         print_buf[ i>=n_chars_old+brvlen ? i+ervlen : i ] = pct_str[j];
  201.  
  202.           // Move print_buf characters
  203.           if(n_chars_old<n_chars)
  204.         for(i=n_chars_old+brvlen; i<n_chars+brvlen; ++i)
  205.           print_buf[i]    = print_buf[i+ervlen];
  206.           else
  207.         for(i=n_chars_old+brvlen-1; i>=n_chars+brvlen; --i)
  208.           print_buf[i+ervlen]    = print_buf[i];
  209.  
  210.           // Insert end of reverse video
  211.           for(i=n_chars+brvlen, j=0; j<ervlen; ++i, ++j)
  212.         print_buf[i]    = end_rv[j];
  213.         }
  214.       else
  215.         {
  216. #endif
  217.           if(n_chars>=n_chars_old)
  218.         for(int i=n_chars_old+1; i<=n_chars; ++i)
  219.           print_buf[i]    = BAR_CHAR;
  220.           else
  221.         for(int i=n_chars+1; i<=n_chars_old; ++i)
  222.           print_buf[i]    = ' ';
  223.           sprintf(&(print_buf[length+3])," %3i%%\r",pct_int);
  224. #if defined (USE_TERM)
  225.         }
  226. #endif
  227.       fputs(print_buf,stdout);
  228.       fflush(stdout);
  229.       n_chars_old    = n_chars;
  230.       pct_int_old    = pct_int;
  231.     }
  232.     }
  233.   return retval;
  234. }
  235.  
Nov 3 '07 #1
4 2150
weaknessforcats
9,208 Recognized Expert Moderator Expert
What's the error? Compile time or run time?

Also, please use code tage when posting.

I have added them for you this time.
Nov 4 '07 #2
prads
25 New Member
It shows the foll errors.....

octave/oct.h: No such file or directory.
39 expected constructor, destructor, or type conversion before '(' token
39 expected `,' or `;' before '(' token

Thanks,
Prads
Nov 4 '07 #3
prads
25 New Member
I am sorry........line 39 in my code corresponds to 18 in the above code. i.e the error is in DEFUN_DLD()
Thanks,
prads
Nov 4 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
DEFUN_DLD() is a function?

Then what does the function prototype look like?

I'm having trouble reading the code between line 19 and 44.
Nov 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4935
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
11
18993
by: John Collyer | last post by:
Hi, In assembly language you can use a lookup table to call functions. 1. Lookup function address in table 2. Call the function Like: CALL FUNCTION
2
9777
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
2
4419
by: Jozef | last post by:
Hello, I'm trying to create a central function that runs a connection to an SQL Server database. The connection etc works, but when I try to call it, I get an error saying "Runtime-Error 91:...
6
9881
by: Peter Rothenbuecher | last post by:
Hello, when I try to compile the following code with g++ -o client client.c #include<sys/socket.h> #include<stdio.h> #include<stdlib.h> #define ADDRESS "mysocket"; #define MAXLEN 200;
10
4968
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
2
5300
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
1
1576
by: prads | last post by:
Hello, I found this waitbar functioning pgm in a forum which does the same work as a matlab waitbar. However this pgm has an error and i cudnot figure it out. Can anyone pls correct it. Thanks,...
4
6277
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.