slang-users mailing list

[2000 Date Index] [2000 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

S-Lang Error: Duplicate Definition: ...


Hi there!

This might look like a real stupid question...
But honestly I'm stuck with no ideas where to go frome here...

For some reason I can not get my C program that uses some slang
functions to execute properly.
It compiled cleanly without errors and warnings.

but when I run the program it exists normally with the following error,
when the input() function 
is called the second time 

S-Lang Error: Duplicate Definition: Type Name Array_Type already exists


#include <stdio.h>
#include <ctype.h>
#include <slang.h>
#include <stdlib.h>


#define CR 0x0d                    //carriage return (enter key)
#define DOT 0x2e               //for floating points
#define LF 0x0a                //Line feed
#define BACKSPACE 0x08         //Backspace
#define DEL 0x7f               //DELETE
#define SAVE 0x53              //S for Save
#define HELP 0x48              //H for Help
#define ESC 0x1b               //ESC same as QUIT
#define QUIT 0x51              //Q for Quit
#define CANCEL 0x43            //Terminate the appliction on ^C
#define _NULL 0                    //Empty character
#define TRUE 1
#define FALSE 0
#define LENGTH 10                  //size of the string



int input(char *string, int length);
int my_getkey(void);

int main()
{

        char string[LENGTH];
        int value_int;
        float value_float;


        printf("Enter the text:\n");



      /*this works all pretty well until we call the function the second
time  further down*/

        if(input(string,LENGTH))

                /*convert string to a mathematical value*/
                        value_float = atof(string);
                
                        
                else
                
                    /*convert string to a mathematical value*/
                        value_int = atoi(string);       
                

                        
      
/*****************************************************************************/
      
/*                                                                          
*/
       /* when I call the input() function a second time I get the
error:           */
       /* S-Lang Error: Duplicate definition: Type name Array_Type
already exists   */
      
/*                                                                          
*/
      
/*****************************************************************************/
                        
        printf("Again. Enter the text:\n");             
                
        if(input(string,LENGTH))

                /*convert string to a mathematical value*/
                        value_float = atof(string);
                        
                        
                else
                
                    /*convert string to a mathematical value*/
                        value_int = atoi(string);       
                                
        return 0;
}

int input(char *string, int length)
{


        int flag_float = FALSE;
        int done = FALSE;
        int index = 0;
        unsigned char ch;


       
/*****************************************************************/
        /*                                                              
*/
        /*    General initialisations for the slang library functions   
*/
        /*                                                              
*/
       
/*****************************************************************/

                if ((-1 == SLang_init_slang ())    /* basic interpreter
functions */
                || (-1 == SLang_init_slmath ()) /* sin, cos, etc... */
                || (-1 == SLang_init_slunix ()) /* unix system calls */
                || (-1 == SLang_init_slfile ())) /* file I/O */
              exit (0);


         SLtt_get_terminfo();

            if (-1 == SLang_init_tty (3, 0, 1))
               {
                 fprintf (stdout, "Unable to initialize the
terminal.\n");
                 exit (1);

               }

                SLang_set_abort_signal (NULL);

                
                
                if (-1 ==  SLsmg_init_smg()) {

                 fprintf (stdout, "Unable to initialize
SLsmg_init_smg.\n\
                                   Cannot allocate space\n");
                 exit (1);
               }


        string[0] = _NULL;      //initialize the buffer

                


                do {
                            ch = my_getkey();

                        /*check to see whether the buffer is full*/
                        if (index == (length-1)) {
                                switch (ch) {
                                        
                                       .........
                                       evalueate user input if the
buffer is full
                                       .........
                                       .........




                                        } //end switch
                        }  //end if

                /*process the keyboard input*/

                switch(ch) {
                        
                   
                   evalueate user input
                   ...............
                   ...............


                       
/******************************************************/
                        /*     we accept digits and punctuation
marks         */
                       
/******************************************************/

                        default:
                            if (ch == DOT && flag_float == FALSE){
                              flag_float = TRUE;
                                  putchar(ch);
                              string[index] = ch;
                              index++;
                              }

                             else if (isdigit(ch)) {
                                putchar(ch);
                                string[index] = ch;
                                index++;
                                }
                             else
                               putchar('\a');
                                break;
                        }  //end switch
                } while (!done);   //end do-while


                
                /* reset the terminal */
                 
                SLsmg_reset_smg ();
                SLang_reset_tty();



            return(flag_float);  //flag indicates if we received a float
or integer from user

} //end

/*get the key*/
int my_getkey(void)
{
        unsigned char key;

            /* setbuf to unbuffered*/
        setbuf(stdout, 0);      
                
                key = SLang_getkey();
                if (SLang_Error == USER_BREAK)
                  {
                     fputs ("\nBye\n", stdout);
                     key = 'C';
                  }



        
           else         
                fflush(stdout);  /*display the keys immediatly*/
        
            /*also allow lowercase input*/
            if(key == 's' || key == 'q' || key == 'h')
            key = toupper(key);
        
            return((int)key);
}       

can anybody give me a hint what I'm doing wrong here?
Thank's and sorry for the messy code (as u can c I'm a real newbie 8-)
Joachim!


[2000 date index] [2000 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]