Ejemplo n.º 1
0
/*
 * Initialize read line code
 */
void ReadLineInit ()
{
    int i;
    for (i = 0; i <= RL_HISTORY_LINES; i++)
        rl_history[i] = NULL;
    rl_columns = rl_getcolumns ();
    s_init (&rl_ucs,      "", 128);
    s_init (&rl_ucscol,   "", 128);
    s_init (&rl_ucsbytes, "", 128);
    s_init (&rl_input,    "", 128);
    s_init (&rl_display,  "", 128);
    rl_colpos = rl_ucspos = rl_bytepos = 0;
    ReadLineTtySet ();
    atexit (ReadLineTtyUnset);
#if defined(SIGTSTP) && defined(SIGCONT)
    signal (SIGTSTP, &tty_stop_handler);
    signal (SIGCONT, &tty_cont_handler);
#endif
#ifndef __amigaos__
    signal (SIGINT, &tty_int_handler);
#else
    signal (SIGINT, SIG_IGN);
#endif
    ReadLinePromptReset ();
    ConvTo ("", ENC_UCS2BE);
}
Ejemplo n.º 2
0
/*
 * Add current line to history
 * ALSO FINISHES LINE PROCESSING
 */
static void rl_historyadd ()
{
    int i, j;

    rl_linecompress (&rl_temp, 0, -1);
    if (rl_tab_state >= 0 && rl_temp.txt[0])
    {
        for (j = 1; j <= RL_HISTORY_LINES; j++)
            if (!rl_history[j] || !strcmp (rl_temp.txt, rl_history[j]))
                break;
        if (j > RL_HISTORY_LINES)
            j = RL_HISTORY_LINES;
        s_free (rl_history[j]);
        s_free (rl_history[0]);
        rl_history[0] = strdup (rl_temp.txt);
        for (i = j; i > 0; i--)
            rl_history[i] = rl_history[i - 1];
        rl_history[0] = NULL;
    }
    s_init (&rl_ucs, "", 0);
    s_init (&rl_ucscol, "", 0);
    s_init (&rl_ucsbytes, "", 0);
    s_init (&rl_display, "", 0);
    rl_colpos = rl_ucspos = rl_bytepos = 0;
    rl_inputdone = 1;
    rl_history_pos = 0;
}
Ejemplo n.º 3
0
/*
 * Really handle signals
 */
void ReadLineHandleSig (void)
{
    UBYTE sig;
    
    while ((sig = (rl_signal & 30)))
    {
        rl_signal &= 1;
        if (sig & 2)
        {
            s_init (&rl_operate, "", 0);
            rl_key_end ();
            printf ("%s %s^C%s\n", rl_operate.txt, COLERROR, COLNONE);
            rl_print ("\r");
            rl_prompt_stat = 0;
            rl_historyadd ();
            rl_tab_state = 0;
            s_init (&rl_input, "", 0);
            CmdUserInterrupt ();
            ReadLinePromptReset ();
            ReadLinePrompt ();
        }
#if defined(SIGTSTP) && defined(SIGCONT)
        if (sig & 4)
        {
            ReadLineTtySet ();
            rl_print ("\r");
            ReadLinePrompt ();
        }
        if (sig & 8)
        {
            int gpos;

            s_init (&rl_operate, "", 0);
            gpos = rl_colpos;
            rl_key_end ();
            rl_colpos = gpos;
            printf ("%s", rl_operate.txt);
            printf (" %s^Z%s", COLERROR, COLNONE);
            ReadLineTtyUnset ();
            signal (SIGTSTP, SIG_DFL);
            raise (SIGTSTP);
        }
#endif
#if defined(SIGWINCH)
        if (sig & 16)
        {
            if (rl_columns != rl_getcolumns ())
            {
                ReadLinePromptHide ();
                rl_columns = rl_getcolumns ();
            }
        }
#endif
    }
}
Ejemplo n.º 4
0
Archivo: slists.c Proyecto: BIRD/bird
int main(void)
{
  slist a, b;
  snode *x, *y;
  siterator i, j;

  s_init_list(&a);
  s_init_list(&b);
  x = xmalloc(sizeof(*x));
  s_add_tail(&a, x);
  x = xmalloc(sizeof(*x));
  s_add_tail(&a, x);
  x = xmalloc(sizeof(*x));
  s_add_tail(&a, x);
  dump("1", &a);

  s_init(&i, &a);
  s_init(&j, &a);
  dump("2", &a);

  x = s_get(&i);
  printf("Got %p\n", x);
  dump("3", &a);

  s_put(&i, x->next);
  dump("4", &a);

  y = s_get(&j);
  while (y)
    {
      s_put(&j, y);
      dump("5*", &a);
      y = s_get(&j)->next;
    }

  dump("5 done", &a);

  s_rem_node(a.head->next);
  dump("6 (deletion)", &a);

  s_put(&i, s_get(&i)->next);
  dump("6 (relink)", &a);

  x = xmalloc(sizeof(*x));
  s_add_tail(&b, x);
  dump("7 (second list)", &b);

  s_add_tail_list(&b, &a);
  dump("8 (after merge)", &b);

  return 0;
}
Ejemplo n.º 5
0
static void
s_ctors(void) {
  s_init();

  lagopus_msg_debug(10, "datastore object \"%s\" initialzied.\n",
                    MY_COMMAND_NAME);
}
Ejemplo n.º 6
0
/*
 * Expand given UTF8 string into (and replace) editing line
 */
static void rl_lineexpand (const char *hist)
{
    str_s str = { NULL, 0, 0 };
    int off;

    s_init (&rl_ucs, "", 0);
    s_init (&rl_ucscol, "", 0);
    s_init (&rl_ucsbytes, "", 0);
    s_init (&rl_display, "", 0);
    rl_colpos = rl_ucspos = rl_bytepos = 0;
    
    str.txt = (char *) hist;
    str.len = strlen (str.txt);
    for (off = 0; off < str.len; )
        rl_insert (ConvGetUTF8 (&str, &off));
}
Ejemplo n.º 7
0
static p_search_result setup_searcher_16_test( char * query_string, char * db_file, size_t hit_count ) {
    set_max_compute_capability( COMPUTE_ON_SSE2 );

    mat_init_constant_scoring( 1, -1 );
    init_symbol_translation( NUCLEOTIDE, FORWARD_STRAND, 3, 3 );

    p_query query = query_read_from_string( query_string );

    s_init( NEEDLEMAN_WUNSCH, BIT_WIDTH_16, query );

    ssa_db_init( concat( "./tests/testdata/", db_file ) );

    gapO = -1;
    gapE = -1;

    adp_init( hit_count );

    p_search_result res = s_search( &hit_count );

    minheap_sort( res->heap );

    query_free( query );

    return res;
}
Ejemplo n.º 8
0
    }END_TEST

static void test_searcher_overflow_to_64bit( int search_type ) {
    init_constant_scores( 127, -1 );
    init_symbol_translation( AMINOACID, FORWARD_STRAND, 3, 3 );
    p_query query = query_read_from_file( "./tests/testdata/NP_009305.1.fas" );

    s_init( search_type, BIT_WIDTH_8, query );

    ssa_db_init( "./tests/testdata/NP_009305.1.fas" );

    gapO = -1;
    gapE = -1;

    size_t hit_count = 1;
    adp_init( hit_count );

    p_search_result res = s_search( &hit_count );

    minheap_sort( res->heap );

    query_free( query );

    ck_assert_int_eq( hit_count, res->heap->count );

    ck_assert_int_eq( 1, res->overflow_8_bit_count );
    ck_assert_int_eq( 1, res->overflow_16_bit_count );

    int result[2] = { 67818, 0 };

    test_result( res, result, 2 );
}
Ejemplo n.º 9
0
    }END_TEST

static p_search_result setup_BLOSUM62_test( int bit_width, int search_type, size_t hit_count ) {
    init_symbol_translation( AMINOACID, FORWARD_STRAND, 3, 3 );
    mat_init_buildin( BLOSUM62 );

    p_query query = query_read_from_string(
            "HPEVYILIIPGFGIISHVVSTYSKKPVFGEISMVYAMASIGLLGFLVWSHHMYIVGLDADTRAYFTSATMIIAIPTGIKI" );

    s_init( search_type, bit_width, query );

    ssa_db_init( concat( "./tests/testdata/", "short_AA.fas" ) );

    gapO = -1;
    gapE = -1;

    adp_init( hit_count );

    p_search_result res = s_search( &hit_count );

    minheap_sort( res->heap );

    query_free( query );

    ck_assert_int_eq( hit_count, res->heap->count );

    return res;
}
Ejemplo n.º 10
0
Archivo: util_io.c Proyecto: tadu/climm
/*
 * Read a complete line from a fd.
 *
 * Returned string may not be free()d.
 */
strc_t UtilIOReadline (FILE *fd)
{
    static str_s str;
    char *p;
    
    s_init (&str, "", 256);
    while (1)
    {
        str.txt[str.max - 2] = 0;
        if (!fgets (str.txt + str.len, str.max - str.len, fd))
        {
            str.txt[str.len] = '\0';
            if (!str.len)
                return NULL;
            break;
        }
        str.txt[str.max - 1] = '\0';
        str.len = strlen (str.txt);
        if (!str.txt[str.max - 2])
            break;
        s_blow (&str, 128);
    }
    if ((p = strpbrk (str.txt, "\r\n")))
    {
        *p = 0;
        str.len = strlen (str.txt);
    }
    return &str;
}
Ejemplo n.º 11
0
/*
 * Export options into a string.
 */
const char *OptString (const Opt *opts)
{
    static str_s str;
    int i, flag;
    val_t val = 0;
    
    s_init (&str, "", 100);
    
    for (i = 0; OptList[i].name; i++)
        if (OptGetVal (opts, flag = OptList[i].flag, &val))
        {
            if (flag & COF_BOOL)
            {
                if (!*str.txt)
                    s_cat (&str, "options");
                s_catf (&str, " %s %s", OptList[i].name, val ? "on" : "off");
            }
            else
            {
                if (*str.txt)
                    s_catc (&str, '\n');
                if (flag & COF_NUMERIC)
                    s_catf (&str, "options %s %lu", OptList[i].name, UD2UL (val));
                else if (flag & COF_COLOR)
                    s_catf (&str, "options %s %s", OptList[i].name, s_quote (OptS2C (strtable[val])));
                else
                    s_catf (&str, "options %s %s", OptList[i].name, s_quote (strtable[val]));
            }
        }
    if (*str.txt)
        s_catc (&str, '\n');

    return str.txt;
}
Ejemplo n.º 12
0
Archivo: nterm.c Proyecto: rforge/muste
void muste_nterm(int argc, char *argv[])
  {
  int i;
/*
  if (argc==1)
      {
      Rprintf("This program can be used as a SURVO 84C module only.");
      return;
      }
*/      
  s_init(argv[1]);

  i=init_sequence();
  if (i<0) { s_end(argv[1]); return; }
  i=init_regressors();
  if (i<0) return;

  i=linear_regression(seq_n,10);
  if (i<0) return;

  data_close(&data);

  edwrite(nterm_output_buffer,nterm_output_line,1);

  s_end(argv[1]);
}
Ejemplo n.º 13
0
/* Write the file (if necessary) and page headers. */
private void
ps_image_write_headers(FILE *f, gx_device_printer *pdev,
		       const char *const setup[],
		       gx_device_pswrite_common_t *pdpc)
{
    if (gdev_prn_file_is_new(pdev)) {
	gs_rect bbox;

	bbox.p.x = 0;
	bbox.p.y = 0;
	bbox.q.x = pdev->width / pdev->HWResolution[0] * 72.0;
	bbox.q.y = pdev->height / pdev->HWResolution[1] * 72.0;
	psw_begin_file_header(f, (gx_device *)pdev, &bbox, pdpc, false);
	psw_print_lines(f, setup);
	psw_end_file_header(f);
    }
    {
	byte buf[100];		/* arbitrary */
	stream s;

	s_init(&s, pdev->memory);
	swrite_file(&s, f, buf, sizeof(buf));
	psw_write_page_header(&s, (gx_device *)pdev, pdpc, true, pdev->PageCount + 1, 10);
	sflush(&s);
    }
}
Ejemplo n.º 14
0
Archivo: pol.c Proyecto: rforge/muste
void muste_pol(int argc,char *argv[])
        {
// RS REM        int i;
        char *t;

// RS ADD Variable init
mtx=0;
n_row_comments=0;
roots_eps=EPS;
roots_max_iter=MAX_ITER;

        s_init(argv[1]);
        if (g<2) { sur_print("\nIncomplete POL operation!"); WAIT; return; } // RS ADD
        strcpy(xx,word[1]);
        
        p=strchr(xx,'=');
        if (p==NULL)
            {
            sur_print("\n= missing in POL operation!");
            WAIT; return;
            }
        *p++=EOS;
        if (g>2)
            {
            if (strncmp(p,"LAG(",4)==0)
                { op_lag(p); return; } // 16.8.2006
            }

        q=strchr(p,'*');
        if (q!=NULL) { op_mult(); return; }
        q=strchr(p,'/');
        if (q!=NULL) { op_div(); return; }
        q=strchr(p,'+');
        if (q!=NULL) { op_add(); return; }
        q=strchr(p,'-');
        if (q!=NULL) { op_sub(); return; }

        q=strchr(p,'(');

        if (q!=NULL)
            {
            *q++=EOS;
            t=strchr(q,')');
            if (t==NULL)
                {
                sur_print("\n) is missing!");
                WAIT; return;
                }
            *t=EOS;
            muste_strupr(p);
            if (strncmp(p,"PROD",4)==0) { op_product(); return; }
            if (strncmp(p,"ROOT",4)==0) { op_roots(); return; }
            if (strncmp(p,"DER",3)==0) { op_der(); return; }

            op_value();  /* POL V=P(X) */
            }

        }
Ejemplo n.º 15
0
Archivo: linco.c Proyecto: rforge/muste
void muste_linco(char *argv)
        {
        int i;

// RS 5.5.2014 Variable init 
// SURVO_DATA d;
A=NULL;
rlab=NULL;
clab=NULL;
rdim=cdim=lr=lc=type=0;
expr[0]=EOS;
matname[0]=EOS;
pros=0;
var=NULL;
y=NULL;
outvar=NULL;
lag=NULL;
act=0;

  //    if (argc==1) return;
        s_init(argv);

        if (g<3)
            {
            sur_print("\nUsage: LINCO <SURVO_data>,<matrix_of_coefficients>");
            WAIT; return;
            }
        i=data_open2(word[1],&d,1,0,0); if (i<0) return;
                                /* tilaa uusille muuttujille */
        i=spec_init(r1+r-1); if (i<0) return;

        pros=0;

        act='A'; i=spfind("ACT");
        if (i>=0) act=*spb[i];

        i=conditions(&d); if (i<0) return;  /* permitted only once */
        i=matparam(); if (i<0) return;
        i=matrix_load(matname,&A,&rdim,&cdim,&rlab,&clab,&lr,&lc,&type,expr);
        if (i<0) return;

        i=varaa_tilat(); if (i<0) return;
        i=find_variables();
        if (i<0)
            {
            if (etu==2)
                {
                sprintf(tut_info,"___@%d@LINCO@Error in LINCO@",-i);
                s_end(argv[1]); return;
                }
            return;
            }
        linear_combinations();
        data_close(&d);
        s_end(argv);
        }
Ejemplo n.º 16
0
/*
 * Sets the prompt
 */
void ReadLinePromptSet (const char *prompt)
{
    rl_prompt_time = time (NULL);
    s_init (&rl_prompt, COLSERVER, 0);
    s_cat  (&rl_prompt, ConvTo (prompt, ENC(enc_loc))->txt);
    s_cat  (&rl_prompt, COLNONE);
    s_catc (&rl_prompt, ' ');
    if (rl_prompt_stat != 0)
        rl_prompt_stat = 2;
}
Ejemplo n.º 17
0
Archivo: xall.c Proyecto: rforge/muste
void muste_xall(char *argv)
{
    int i;

    s_init(argv);
    i=spec_init(r1+r-1); if (i<0) return;
    i=check_parameters(); if (i<0) return;
    xall();
    s_end(argv);
    return;
}
Ejemplo n.º 18
0
/*
 * Shows the prompt
 */
void ReadLinePrompt ()
{
    int gpos = rl_colpos;

    if (rl_prompt_stat == 1)
        return;
#if DEBUG_RL
    fprintf (stderr, "killoper: %s\n", s_qquote (rl_operate.txt));
#endif
    s_init (&rl_operate, "", 0);
    if (rl_prompt_stat == 2)
        rl_goto (0);
    if (rl_prompt_stat == 2)
    {
        s_catc (&rl_operate, '\r');
#ifdef ANSI_TERM
        s_cat (&rl_operate, ANSI_CLEAR);
#endif
        rl_prompt_stat = 0;
    }
#if DEBUG_RL
    fprintf (stderr, "oper(rm): %s\n", s_qquote (rl_operate.txt));
#endif
    printf ("%s", rl_operate.txt);
    if (rl_prompt_stat == 0)
    {
        rl_print ("\r");
        rl_print (rl_prompt.txt);
        rl_prompt_len = rl_pos ();
        rl_prompt_stat = 1;
        rl_colpos = 0;
    }
    s_init (&rl_operate, "", 0);
    rl_recheck (TRUE);
    rl_goto (gpos);
    printf ("%s", rl_operate.txt);
}
Ejemplo n.º 19
0
/* Initialize the file table */
static int
zfile_init(i_ctx_t *i_ctx_p)
{
    /* Create and initialize an invalid (closed) stream. */
    /* Initialize the stream for the sake of the GC, */
    /* and so it can act as an empty input stream. */

    stream *const s = &invalid_file_stream;

    s_init(s, NULL);
    sread_string(s, NULL, 0);
    s->next = s->prev = 0;
    s_init_no_id(s);
    return 0;
}
Ejemplo n.º 20
0
int main(int argc, const char * argv[]) {
    
    // 头插法
    SLIST singleLinkList0 = s_init();
    for (int i = 0; i < 5; i++) {
        s_add(singleLinkList0, 0, i);
    }
    s_print(singleLinkList0);
    
    // 尾插法
    SLIST singleLinkList = s_init();
    SNODE* endNode = singleLinkList;
    for (int i = 0; i < 5; i++) {
        SNODE* node = (SNODE*)malloc(sizeof(SNODE));
        node->data = i;
        endNode->next = node;
        endNode = node;
        singleLinkList->data++;
    }
    
    s_print(singleLinkList);
    
    s_add(singleLinkList, 3, 5);
    s_print(singleLinkList);
    
    printf("%d\n", s_get(singleLinkList, 3));
    s_print(singleLinkList);
    
    s_delete(singleLinkList, 1);
    s_print(singleLinkList);
    
    s_clear(singleLinkList);
    s_print(singleLinkList);
    
    return 0;
}
Ejemplo n.º 21
0
/*
 * Hides the prompt
 */
void ReadLinePromptHide ()
{
    int pos = rl_colpos;
    ReadLineHandleSig ();
    if (rl_prompt_stat == 0)
        return;
    s_init (&rl_operate, "", 0);
    rl_goto (0);
    s_catc (&rl_operate, '\r');
#ifdef ANSI_TERM
    s_cat (&rl_operate, ANSI_CLEAR);
#endif
    printf ("%s", rl_operate.txt);
    rl_prompt_stat = 0;
    rl_colpos = pos;
    rl_print ("\r");
}
Ejemplo n.º 22
0
AA_API void
aa_sdl_bind_event( SDL_EventType event_type,
                   aa_sdl_handler_function handler,
                   void *cx )
{
    s_lock();
    s_init();

    struct handler *h = AA_NEW(struct handler);
    h->cx = cx;
    h->event_type = event_type;
    h->handler = handler;

    handler_vector_push(&s_event_vector, h);


    s_unlock();
}
Ejemplo n.º 23
0
AA_API void
aa_sdl_bind_key( SDL_Keycode key,
                 aa_sdl_handler_function handler,
                 void *cx )
{
    s_lock();
    s_init();

    struct handler *h = AA_NEW(struct handler);
    h->cx = cx;
    h->key = key;
    h->handler = handler;

    handler_vector_push(&s_key_vector, h);


    s_unlock();

}
Ejemplo n.º 24
0
/*
 * Compresses part of the current edited line into an UTF8 string
 */
static void rl_linecompress (str_t line, UDWORD from, UDWORD to)
{
    UDWORD i;
    wint_tt ucs;
    
    if (to == (UDWORD)-1)
        to = rl_ucscol.len;
    s_init (line, "", 0);
    for (i = from; i < to; i++)
    {
        ucs = rl_ucs_at (&rl_ucs, i);
#if DEBUG_RL
        fprintf (stderr, "ucs %x\n", ucs);
#endif
        if (ucs != WEOF)
            s_cat (line, ConvUTF8 (ucs));
    }
#if DEBUG_RL
    fprintf (stderr, "compress %s\n", s_qquote (line->txt));
#endif
}
Ejemplo n.º 25
0
int main()
{
    serial_init(115200);
    puts("Test noyau");
    puts("Noyau preemptif");

    s_init();
    //Init file FIFO
    field.deb=0;
    field.fin=0;
    int i=0;
    for (i=0; i<MAX_TACHES; i++)
        field.file[i]=0;

    mySem = s_cree(1);
    mySem2 = s_cree(0);
    start(tacheInit);

    while(1);

    return(0);
}
Ejemplo n.º 26
0
//--------------------------------------------------------------------------
static bool idaapi init_debugger(const char *hostname, int port_num, const char *password)
{
  if ( !s_open_remote(hostname, port_num, password) )
    return false;

  int code = s_init((debug & IDA_DEBUG_DEBUGGER) != 0);
  if ( code <= 0 )   // (network) error
  {
    s_close_remote();
    return false;
  }
  debugger.process_get_info = (code & 1) ? process_get_info : NULL;
  debugger.detach_process   = (code & 2) ? s_detach_process : NULL;
  debugger_inited = true;
#if DEBUGGER_ID == DEBUGGER_ID_ARM_WINCE_USER
  slot = BADADDR;
  netnode n;
  n.create("$ wince rstub");
  enable_hwbpts(n.altval(0));
#endif
  return true;
}
Ejemplo n.º 27
0
/* Open the printer, writing the stream header. */
static int
ljet5_open(gx_device * pdev)
{
    int code = gdev_prn_open(pdev);

    if (code < 0)
	return code;
    code = gdev_prn_open_printer(pdev, true);
    if (code < 0)
	return code;
    {
	gx_device_printer *const ppdev = (gx_device_printer *)pdev;
	stream fs;
	stream *const s = &fs;
	byte buf[50];		/* arbitrary */

	s_init(s, pdev->memory);
	swrite_file(s, ppdev->file, buf, sizeof(buf));
	px_write_file_header(s, pdev);
	sflush(s);		/* don't close */
    }
    return 0;
}
Ejemplo n.º 28
0
static p_search_result setup_searcher_test( int bit_width, int search_type, char * query_string, char * db_file,
        size_t hit_count, int symtype, int strands ) {
    init_symbol_translation( symtype, strands, 3, 3 );
    mat_init_constant_scoring( 1, -1 );
    p_query query = query_read_from_string( query_string );

    s_init( search_type, bit_width, query );

    ssa_db_init( concat( "./tests/testdata/", db_file ) );

    gapO = -1;
    gapE = -1;

    adp_init( hit_count );

    p_search_result res = s_search( &hit_count );

    minheap_sort( res->heap );

    query_free( query );

    return res;
}
Ejemplo n.º 29
0
/*
 * Determine width and correct display for given (UTF8) string
 */
strc_t ReadLineAnalyzeWidth (const char *text, UWORD *width)
{
    static str_s str = { NULL, 0, 0 };
    wchar_tt ucs;
    UWORD twidth, swidth = 0;
    const char *dis;
    int off = 0;
    str_s in;
    
    in.txt = (char *)text;
    in.len = strlen (text);
    in.max = 0;
    s_init (&str, "", 100);
    
    for (off = 0; off < in.len; )
    {
        ucs = ConvGetUTF8 (&in, &off);
        rl_analyze_ucs (ucs, &dis, &twidth);
        swidth += twidth & 0xff;
        s_cat (&str, twidth & 0x100 ? ConvUTF8 (ucs) : dis);
    }
    *width = swidth;
    return &str;
}
Ejemplo n.º 30
0
void muste_cluster(char *argv)
        {
        int i,k;
        double a;
        char ch;

//      if (argc==1) return;
        s_init(argv);

        if (g<2)
            {
            sur_print("\nUsage: CLUSTER <SURVO_data>,<output_line>");
            WAIT; return;
            }
        tulosrivi=0;
        if (g>2)
            {
            tulosrivi=edline2(word[2],1,1);
            if (tulosrivi==0) return;
            }

        strcpy(aineisto,word[1]);
        i=data_open(aineisto,&d); if (i<0) return;
        i=sp_init(r1+r-1); if (i<0) return;
        i=mask(&d); if (i<0) return;
        scales(&d);
        i=conditions(&d); if (i<0) return;

        gvar=activated(&d,'G');
        if (gvar<0)
            {
            sur_print("\nNo grouping variable (activated by 'G') given!");
            WAIT; return;
            }

        ivar=-1; ivar=activated(&d,'I');

        i=spfind("TRIALS");
        if (i>=0) maxiter=atoi(spb[i]);

        i=rand_init(); if (i<0) return;   /* 30.4.1994 */

        i=spfind("TEMPFILE");
        if (i>=0) strcpy(tempfile,spb[i]);
        else { strcpy(tempfile,etmpd); strcat(tempfile,"SURVO.CLU"); }

        i=spfind("PRIND");
        if (i>=0 && atoi(spb[i])>0) prind=1;

        data_load(&d,1L,gvar,&a);
        i=data_save(&d,1L,gvar,a);
        if (i<0) return;

        gvar2=(int *)muste_malloc(d.m_act*sizeof(int));
        if (gvar2==NULL) { not_enough_memory(); return; }

        k=0; n_saved=0; m=0;
        for (i=0; i<d.m_act; ++i)
            {
            ch=d.vartype[d.v[i]][1];
            if (ch=='G')
                {
                ++k;
                gvar2[n_saved]=d.v[i];    /* gvar=gvar2[0] */
                ++n_saved; continue;
                }
            if (ch=='I') { ++k; continue; }
            d.v[m++]=d.v[i];
            }
/*
printf("\nivar=%d gvar=%d m=%d\n",ivar,gvar,m); getch();
for (i=0; i<m; ++i) Rprintf(" %d",d.v[i]); getch();
printf("\n"); for (i=0; i<n_saved; ++i) Rprintf(" %d",gvar2[i]); getch();
*/

        i=spfind("GROUPS");
        if (i<0) ng=2; else ng=atoi(spb[i]);
        if (ng<2) ng=2;
        ng2=ng+2;
        mn=m; if (mn<ng) mn=ng;

        first_line=r+1; if (r+n_saved>r3) first_line=1;
        n_show=n_saved; if (n_show>r3) n_show=r3;

        i=varaa_tilat(); if (i<0) return;

        i=lue_havainnot(); if (i<0) return;
        hav_muistissa=havainnot_muistiin();
        ortogonalisoi();
        if (ivar_init) alustava_luokittelu();
        LOCATE(first_line,1);
        SCROLL_UP(first_line,r3+1,r3);
        sur_print("\nCluster analysis: Iteration 1:");
        while (sur_kbhit()) sur_getch();
        it=0;
        while (1)
            {
            while (1)
                {
                if (it) init_gr();
                i=init_tilat();
                if (i>=0) break;
                if (maxiter==1) return;
                }
            iteroi();
            ++it;
            if (maxiter>1) vertaa_muihin();
            if (it==maxiter) break;
            LOCATE(first_line,1);
            sprintf(sbuf,"\nIteration %d (Cluster analysis)",it);
            sur_print(sbuf);
            for (i=0; i<n_show; ++i)
               {
               if (freq[i]==0) break;
               sprintf(sbuf,"\n%d %g %d        ",i+1,lambda2[i],freq[i]); sur_print(sbuf);
               }
            if (sur_kbhit())
                {
                i=sur_getch(); if (i=='.') break;
                }
            }
        tulosta();

        data_close(&d);
        sur_delete(tempfile);
        s_end(argv);
        }