void grid()
{
// setbkcolor(LIGHTGREEN);
 setfillstyle(1,LIGHTGREEN);
 floodfill(0,0,15);
 setlinestyle(0,0,3);
 setcolor(RED);
 settextjustify(1,1);
// settextstyle(0,0,1);
 for(int i=0;i<=480;i+=48)
  line(0,i,479,i);
 line(0,479,479,479);
 for(i=0;i<=480;i+=48)
  line(i,0,i,479);
 int k=1;int a=9;
 char h[3];
 setfillstyle(1,LIGHTBLUE);
 floodfill(639,479,RED);
 setcolor(BROWN);
 setlinestyle(0,0,3);
 ladd(110,452,412);
 ladd(350,452,364);
 ladd(206,404,316);
 ladd(398,308,268);
 ladd(110,260,220);
 ladd(254,260,172);
 ladd(206,164,28);
 ladd(350,164,124);
 ladd(62,116,76);
 snake(168, 374, 264, 447);
 snake(360, 278, 312, 399);
 snake(168, 230, 72, 351);
 snake(408,182,312,255);
 snake(120, 86, 168, 303);
 snake(264, 38, 360, 111);
 snake(72, 38, 72,159);
 snake(264, 134, 216, 255);
 setcolor(RED);
 settextstyle(4,0,1);

 while(a>0)
 {
  for(i=0;i<10;i++)
	{
	 sprintf(h,"%d",k++);
	 outtextxy(i*48+24,a*48+24,h);
	}
  a--;
  for(i=9;i>=0;i--)
	{
	 sprintf(h,"%d",k++);
	 outtextxy(i*48+24,a*48+24,h);
	}
  a--;
 }

}
Esempio n. 2
0
/*----------------------------------------------------------------------
|  insert_ln
|
|  insert data, listnode - insert data just before the list item 
|  pointed to by 'ln'.
|
|  This routine is not intended to be called directly by the user
|  because the validity of ln is not checked.  This routine is called
|  by list manipulation routines within this module, in which ln is
|  known to point to a valid list node.
 ----------------------------------------------------------------------*/
static 
int 
insert_ln ( LIST * l, LISTNODE * ln, void * data_ptr )
{
  LISTNODE * lnptr;

  CKLMAGIC(l);

  if (ln==NULL) {
    ladd ( l, data_ptr );
    CKLMAGIC(l);
    return 0;
  }

  lnptr = get_listnode(l);
  if (lnptr == NULL) {
#ifdef BOS
    breakpoint();
#endif
    return -1;
  }

  CKMAGIC(lnptr);

  lnptr->data = data_ptr;

  if (ln==l->top) {
    /*------------------------------
    |  insert before the list head
     ------------------------------*/
    lnptr->next = ln;
    lnptr->prev = NULL;
    ln->prev = lnptr;
    l->top = lnptr;
  }
  else if (ln==NULL) {
    /*-----------------
    |  list was empty
     -----------------*/
    lnptr->next = NULL;
    lnptr->prev = l->bottom;
    l->bottom->next = lnptr;
    l->bottom = lnptr;
  }
  else {
    /*-----------------------------------
    |  insert in the middle of the list
     -----------------------------------*/
    lnptr->next = ln;
    lnptr->prev = ln->prev;
    lnptr->next->prev = lnptr;
    lnptr->prev->next = lnptr;
  }

  l->num++;

  CKLMAGIC(l);

  return 0;
}
Esempio n. 3
0
File: kheader.c Progetto: klopp/knet
int hdr_AddTextHeader( msg_Headers headers, const char * key,
        const char * value )
{
    msg_Header header = hdr_FindHeader( headers->text, key );

    if( !header )
    {
        header = Calloc( sizeof(struct _msg_Header), 1 );
        if( !header ) return 0;
        header->name = Strdup( key );
        if( !header->name )
        {
            Free( header );
            return 0;
        }
        header->values = slcreate();
        if( !header->values )
        {
            del_Header( header );
            return 0;
        }
        if( !sladd( header->values, value ) )
        {
            del_Header( header );
            return 0;
        }
    }

    return ladd( headers->text, header ) != NULL;
}
Esempio n. 4
0
int main(int argc, char* argv[]){

	if(argc > 2) {
		List* la = int2list(atoi(argv[1]));
		List* lb = int2list(atoi(argv[2]));
		List* lc = ladd(la,lb);
/*		
		la->print();
		lb->print();
		lc->print();
*/		
		List* lar = la->reverse();
		List* lbr = lb->reverse();
		List* lcr = laddrev(lar,lbr);
		
		lar->print();
		lbr->print();
		lcr->print();
		
		delete lar;
		delete lbr;
		delete lc;
		delete lcr;
	}


}
Esempio n. 5
0
void OperandStack::lsub(){
	if(size < 4) {
		printf("Error  :op_stack.lsub\n");
		exit(0);
	}
	lneg();
	ladd();
}
Esempio n. 6
0
int main(void) {
	short a[N + 2] = {1999, 4444, 7777, 2222, 9999},
	      b[N + 2] = { 111, 6666, 3333, 8888, 1111},
	      c[N + 2];

	ladd(a, b, c);
	print(c);
	lsub(a, b, c);
	print(c);

	return 0;
}
Esempio n. 7
0
File: slist.c Progetto: klopp/klib
char *sladd( List list, const char *data ) {
    if( list && data ) {
        char *dup = Strdup( data );
        if( dup ) {
            char *rc = ladd( list, dup );
            if( rc ) {
                return rc;
            }
            Free( dup );
        }
    }
    return NULL;
}
Esempio n. 8
0
/*------------------------------------------------------------
|  lcat
|
|  catenate - catenate l2 to l1, return pointer to l1.
 ------------------------------------------------------------*/
LISTID
lcat ( LISTID lid1, LISTID lid2 )
{
  CKLMAGIC(((LIST *)lid1));
  CKLMAGIC(((LIST *)lid2));
  while (lsize(lid2)) {
    ladd ( lid1, lrmv_n(lid2,1) );
  }

  CKLMAGIC(((LIST *)lid1));
  CKLMAGIC(((LIST *)lid2));

  return lid1;
}
int main()
{
	CList *head = new CList;
	head->value = 0;
	head->next = NULL;
	printf("Counting - for every round of a cyclic list remove the k-th element, while not in the list will be only one. Enter the length of the list and number of the last element. Will be calculated the numbers of k before n!. \n\nn = ");
	int n = 0;
	scanf("%i", &n);
	printf("\nlast = ");
	int last = 0;
	scanf("%i", &last);
	
	long nFact = 1;
	for (int i = 1; i <= n; i++)
			nFact = nFact * i;

	List *lhead = new List;
	lhead->next = NULL;
	
	for (int k = 1; k <= nFact; k++)
	{
		fill(head, n);
		CList *tmp = head;
		while (lengh(head) != 1)
		{
			for (int c = 1; c < k; c++)
			{
				tmp = tmp->next;
			}
			del(head, returnNum(head, tmp->next));
		}
		if (tmp->next->value == last)
			ladd(lhead, k, 1000);
		del(head, 1);
	}

	printf("\n\nk = {");
	lprintList(lhead);
	printf("}\n");
	
	removeList(head);
	lremoveList(lhead);
	
	scanf("%*");

	delete lhead;	
	delete head;
	return 0;
}
Esempio n. 10
0
void set_knight(){
	if(lev==max_lev){
		cnt=ladd(cnt,a);
		cnt=ladd(cnt,b);
		cnt=ladd(cnt,c);
		cnt=ladd(cnt,o);
		return;
	}
/*
	printf("lev=%ld :",lev);
	printlnum(a);
	printf(" ");
	printlnum(b);
	printf(" ");
	printlnum(c);
	printf(" ");
	printlnum(o);
	printf(" \n");
*/
	lev++;

	an=a;
	bn=b;
	cn=c;
	on=o;

	a=bn;
	a=ladd(a,bn);
	a=ladd(a,cn);
	a=ladd(a,cn);

	b=an;
	b=ladd(b,on);
	b=ladd(b,on);

	c=an;

	o=bn;

	set_knight();
}
/** Returns map of instances **/
list *parse_object(lwm2m_object *object, char *message, int message_len) {
    list *instances = list_new();

    char *curr = message;
    while (curr < message + message_len) {
        tlv_header instance_header;
        curr = parse_tlv_header(curr, &instance_header);

        lwm2m_instance *instance = (lwm2m_instance *) malloc(sizeof(lwm2m_instance));
        instance->id = instance_header.id;
        instance->resources = parse_instance(object, curr, instance_header.length);

        ladd(instances, instance->id, instance);
        curr = curr + instance_header.length;
    }
    return instances;
}
// TODO in multiple resource map there should be map <ID, lwm2m_resource*>
list *parse_multiple_resource(lwm2m_object *object, int resource_id, char *message, int message_len) {
    list *resources = list_new();
    tlv_header resource_header;

    char *curr = message;
    while (curr < message + message_len) {
        curr = parse_tlv_header(curr, &resource_header);

        lwm2m_resource *resource_instance = create_resource(object, resource_id);
        resource_instance->id = resource_header.id;
        lwm2m_value value = parse_value(curr, resource_header.length, resource_instance->type);
        __set_value(resource_instance, &value, resource_header.length);

        ladd(resources, resource_instance->id, resource_instance);
        curr = curr + resource_header.length;
    }
    return resources;
}
Esempio n. 13
0
/*-----------------------------------------------------------------
|  lins_n
|
|  Insert data before the nth item in the list.
 -----------------------------------------------------------------*/
int 
lins_n ( LISTID lid, void * data_ptr, unsigned int n )
{
  int i;
  LIST * l;
  LISTNODE * ln;

  l = (LIST *)lid;

  CKLMAGIC(l);

  if ((n<1)||(n>(l->num+1))) {
    return -1;
  }

  if (l->num == 0) {
    return ladd ( lid, data_ptr );
  }

  /*----------------------------------
  |  locate the nth item in the list
   ----------------------------------*/
  ln = l->top;
  i = 1;
  while (ln && (i!=n)) {
    CKMAGIC(ln);
    ln = ln->next;
    i++;
  }

  if (!ln) {
    CKLMAGIC(l);
    return -1;
  }

  CKLMAGIC(l);

  /*-----------------------------------------
  |  insert before the nth item in the list
   -----------------------------------------*/
  return insert_ln ( l, ln, data_ptr );
}
Esempio n. 14
0
list *create_example_objects() {
    list *objects = list_new();

    lwm2m_object *example_object = lwm2m_object_new();
    example_object->id = 123;
    example_object->mandatory = false;
    example_object->multiple = true;
    example_object->object_urn = "urn:oma:lwm2m:oma:123";
    example_object->attributes = list_new();
    example_object->resource_def = create_example_resources(123);
    example_object->resource_def_len = 10;

    // Set object's minimum period attribute to 10 sec
    // TODO new way of declaring attributes
//    lwm2m_attribute *pmin_attribute = new_int_attribute("pmin", 10, ATTR_READ | ATTR_WRITE);
//    lwm2m_map_put_string(example_object->attributes, "pmin", pmin_attribute);

    ladd(objects, example_object->id, (void*) example_object);
    return objects;
}
/** Returns map of resources **/
list *parse_instance(lwm2m_object *object, char *message, int message_len) {
    list *resources = list_new();
    tlv_header resource_header;
    
    char *curr = message;
    while (curr < message + message_len) {
        curr = parse_tlv_header(curr, &resource_header);

        lwm2m_resource *resource = create_resource(object, resource_header.id);

        if (resource_header.type == MULTIPLE_RESOURCE_TYPE) {
            resource->instances = parse_multiple_resource(object, resource->id, curr, resource_header.length);
            resource->multiple = true;
        } else {
            lwm2m_value value = parse_value(curr, resource_header.length, resource->type);
            __set_value(resource, &value, resource_header.length);
        }
        ladd(resources, resource->id, resource);
        curr = curr + resource_header.length;
    }
    return resources;    
}
Esempio n. 16
0
/*------------------------------------------------------------
|  laddo
|
|  add list, ordered - add item p to the list, use 'compare'
|  function to place 'p' when the comparison 'p' is less than
|  the next item.  Return 0 if this was a unique entry,
|  else return 1 indicating a duplicate entry, i.e., the
|  compare function returned 0 while inserting the element.
 ------------------------------------------------------------*/
int 
laddo ( LISTID lid, void * p, int (*compare)(const void *p1,const void *p2), 
	LNODEID * firstdup )
{
  LIST * l;
  LISTNODE * ln;
  int dup, cmp;

  l = (LIST *)lid;

  CKLMAGIC(l);

  dup = 0;
  ln = l->top;

  while (ln!=NULL) {
    CKMAGIC(ln);
    cmp = compare(p,ln->data);
    if (cmp == 0) {
      dup = 1;
      if (firstdup)
	*firstdup = ln;
    }
    if (cmp < 0) {
      insert_ln(l,ln,p);
      CKLMAGIC(l);
      return dup;
    }
    else {
      ln = ln->next;
    }
  }

  ladd(l,p);

  CKLMAGIC(l);

  return dup;
}
Esempio n. 17
0
File: kheader.c Progetto: klopp/knet
int hdr_AddMailHeader( msg_Headers headers, const char * key,
        const char * mail )
{
    msg_Header header = hdr_FindHeader( headers->text, key );

    if( !header )
    {
        Pair addr = addr_Create( mail );
        if( !addr ) return 0;

        header = Calloc( sizeof(struct _msg_Header), 1 );
        if( !header ) return 0;
        header->name = Strdup( key );
        if( !header->name )
        {
            pair_Delete( addr );
            Free( header );
            return 0;
        }
        header->values = plcreate();
        if( !header->values )
        {
            pair_Delete( addr );
            del_Header( header );
            return 0;
        }

        if( !pladd( header->values, A_NAME( addr ), A_EMAIL( addr ) ) )
        {
            pair_Delete( addr );
            del_Header( header );
            return 0;
        }
        pair_Delete( addr );
    }

    return ladd( headers->mail, header ) != NULL;
}
Esempio n. 18
0
sdlclock clock_new(int frequency)
{
    sclock *c = malloc(sizeof(sclock));

    c->lkptable = malloc(sizeof(int) * frequency);
    c->frequency = frequency;
    c->index = 0;
    c->ticks = SDL_GetTicks();

    int i;
    for(i=0;i<frequency;i++)
        c->lkptable[i] = ((1000*(i+1)) / frequency) - ((1000*i) / frequency);

#ifdef DEBUG
    int s = 0;
    for(i=0;i<frequency;i++) s += c->lkptable[i];
    assert(s==1000);
#endif

    ladd(_clocks, c);

    return (sdlclock)c;
}
Esempio n. 19
0
/*---------------------------------------------------------------------------
|  laddu
|
|  add list, ordered, unique - add item p to the list, use 'compare'
|  function to place 'p' when the comparison 'p' is less than the next
|  item.  Return 1 if the item was added, 0 if not.
|
 --------------------------------------------------------------------------*/
int 
laddu ( LISTID lid, void * p, int (*compare)(const void *p1,const void *p2) )
{
  LIST * l;
  LISTNODE * ln;
  int cmp;

  l = (LIST *)lid;

  CKLMAGIC(l);

  ln = l->top;

  while (ln!=NULL) {
    CKMAGIC(ln);
    cmp = compare(p,ln->data);
    if (cmp == 0) {
      CKLMAGIC(l);
      return 0;
    }
    if (cmp < 0) {
      insert_ln(l,ln,p);
      CKLMAGIC(l);
      return 1;
    }
    else {
      ln = ln->next;
    }
  }

  ladd(l,p);

  CKLMAGIC(l);

  return 1;
}
Esempio n. 20
0
list_t *create_ir_lookup_table_from_ping(servo_data_t *servo, timer_prescaler_t prescaler)
{

    int maxVoltage = 1023;
    int minVoltage = 130;
    int avg = 5;
    int speed = 50; //50 mm per second
    int delay_for_5_mm = 100;
    oi_set_wheels(0, 0);
    servo_set_position_deg(servo, 90);

    printf0("Put roomba in front of flat surface like a wall. Press 'c' when ready...\r\n");
    while (getChar0() != 'c')
        printf0("Put roomba in front of flat surface like a wall. Press 'c' when ready...\r\n");

    unsigned voltage = ir_read_voltage_avg(avg);
    printf0("start: %u\r\n", voltage);
    while (voltage != maxVoltage)
    {
        printf0("%u\r\n", voltage);
        oi_set_wheels(-speed, -speed);
        _delay_ms(2 * delay_for_5_mm); //1 cm
        oi_set_wheels(0, 0);
        voltage = ir_read_voltage_avg(avg);
    }

    _delay_ms(100);
    unsigned peakVoltage_distance_mm = ping_mm_busy_wait(prescaler);

    while (voltage == maxVoltage)
    {
        printf0("[%u v], %u p_mm \r\n", voltage, peakVoltage_distance_mm);
        oi_set_wheels(-speed, -speed);
        _delay_ms(delay_for_5_mm * 2);
        oi_set_wheels(0, 0);

        _delay_ms(100);
        peakVoltage_distance_mm = ping_mm_busy_wait(prescaler);
        voltage = ir_read_voltage_avg(avg);
    }

    list_t *ret = lalloc();
    ladd(ret, (void *) new_ir_measurement(maxVoltage, peakVoltage_distance_mm));

    unsigned oldMm = peakVoltage_distance_mm;

    while (voltage > minVoltage)
    {

        _delay_ms(100);
        unsigned mm = ping_mm_busy_wait(prescaler);

        printf0("reading [%u v], %u mm   >?     %u oldMm \r\n", voltage, mm, oldMm);
        while (mm <= oldMm)
        {
            printf0("Non increasing ping value: [OLD: %u] [NEW: %u]\r\n", oldMm, mm);

            _delay_ms(100);
            mm = ping_mm_busy_wait(prescaler);
            oi_set_wheels(-speed, -speed);
            _delay_ms(delay_for_5_mm); //5mm
            oi_set_wheels(0, 0);
        }

        printf0(" adding [%u v], %u mm \r\n", voltage, mm);
        ladd(ret, (void *) new_ir_measurement(voltage, mm));
        oi_set_wheels(-speed, -speed);
        _delay_ms(delay_for_5_mm * 2); //1cm
        oi_set_wheels(0, 0);
        voltage = ir_read_voltage_avg(avg);
        oldMm = mm;
    }
    printf0("sorting...\r\n");
    lmergesort(ret, 0, ret->length - 1, (int (*)(const void *, const void *)) compare_ir_measurements);
    printf0("done\r\n");
    return ret;
}
Esempio n. 21
0
list_t *create_jims_ir_sensor_lookup_table()
{
    list_t *lookup_table = lalloc();
    ladd(lookup_table, (void *) new_ir_measurement(118, 360));
    ladd(lookup_table, (void *) new_ir_measurement(146, 300));
    ladd(lookup_table, (void *) new_ir_measurement(169, 245));
    ladd(lookup_table, (void *) new_ir_measurement(199, 215));
    ladd(lookup_table, (void *) new_ir_measurement(215, 195));
    ladd(lookup_table, (void *) new_ir_measurement(224, 175));
    ladd(lookup_table, (void *) new_ir_measurement(245, 165));
    ladd(lookup_table, (void *) new_ir_measurement(250, 155));
    ladd(lookup_table, (void *) new_ir_measurement(265, 145));
    ladd(lookup_table, (void *) new_ir_measurement(279, 135));
    ladd(lookup_table, (void *) new_ir_measurement(303, 125));
    ladd(lookup_table, (void *) new_ir_measurement(327, 115));
    ladd(lookup_table, (void *) new_ir_measurement(370, 105));
    ladd(lookup_table, (void *) new_ir_measurement(394, 95));
    ladd(lookup_table, (void *) new_ir_measurement(409, 85));
    ladd(lookup_table, (void *) new_ir_measurement(457, 75));
    ladd(lookup_table, (void *) new_ir_measurement(522, 65));
    ladd(lookup_table, (void *) new_ir_measurement(562, 55));
    ladd(lookup_table, (void *) new_ir_measurement(696, 45));
    ladd(lookup_table, (void *) new_ir_measurement(912, 35));
    ladd(lookup_table, (void *) new_ir_measurement(1019, 27));
    return lookup_table;
}
Esempio n. 22
0
int main() {
   struct pf_nattrack_hash *pfnth = NULL;
   struct pf_nattrack_list *item, *item2;
   struct pf_nattrack_list *lastlist = NULL, *freelist;
   struct pf_nattrack node, *nodep;
   int i, dev;

   initialize();

   dev = open("/dev/pf", O_RDWR);
   if (dev < 0) {
      printerror("open(/dev/pf)");
      return 1;
   }

   do {
      //printf("\n\n===================================\n");
      //printf("Nova rodada\n");
      //printf("===================================\n");

      freelist = lastlist;
      lastlist = NULL;
      
      struct pfioc_states ps;
      struct pfsync_state *p;
      char *inbuf = NULL, *newinbuf = NULL;
      unsigned int len = 0;
      int i, opts = 0;

      memset(&ps, 0, sizeof(ps));
      for (;;) {
         ps.ps_len = len;
         if (len) {
            newinbuf = realloc(inbuf, len);
            if (newinbuf == NULL) {
               printerror("error realloc - out of memory?");
               goto done;
            }
            ps.ps_buf = inbuf = newinbuf;
         }
         if (ioctl(dev, DIOCGETSTATES, &ps) < 0) {
            printerror("failed to get states from PF device");
            goto done;
         }
         if (ps.ps_len + sizeof(struct pfioc_states) < len)
            break;
         if (len == 0 && ps.ps_len == 0)
            goto done;
         if (len == 0 && ps.ps_len != 0)
            len = ps.ps_len;
         if (ps.ps_len == 0)
            goto done;	/* no states */
         len *= 2;
      }
      p = ps.ps_states;
      for (i = 0; i < ps.ps_len; i += sizeof(*p), p++) {
         if (!convert_state(p, &node)) continue;

         pfnth = &pfnt_hash[hashkey(&node)];

         item = lfind(pfnth->list, &node);

         if (item) {
            //printf("Item found! Deleting from freelist\n");
            item2 = item->ref;
            *(item2->nt) = node;
            ldel(&freelist, item2);
         } else {
            //printf("Not found. Inserting...\n");
            nodep = (struct pf_nattrack *)malloc(sizeof(struct pf_nattrack));
            *nodep = node;
            item = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item->nt = nodep;
            item2 = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item2->nt = nodep;
            ladd(&pfnth->list, item);
            item->ref = item2;
         }
         ladd(&lastlist, item2);
         item2->ref = item;
      }
done:
      free(inbuf);
      free_list(&freelist);

      sleep(PFTM_INTERVAL);
   } while(1);
      /* comentando para trabalhar com o get_states
      while ( scanf("\n%d", &i) != EOF && i != 0) {
         if (!read_input(&node)) continue;

         pfnth = &pfnt_hash[hashkey(&node)];

         item = lfind(pfnth->list, &node);

         if (item) {
            //printf("Item found! Deleting from freelist\n");
            item2 = item->ref;
            ldel(&freelist, item2);
         } else {
            //printf("Not found. Inserting...\n");
            nodep = (struct pf_nattrack *)malloc(sizeof(struct pf_nattrack));
            *nodep = node;
            item = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item->nt = nodep;
            item2 = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item2->nt = nodep;
            ladd(&pfnth->list, item);
            item->ref = item2;
         }
         ladd(&lastlist, item2);
         item2->ref = item;
      }
      //printf("done\n");
      //printf("-> removendo itens da freelist\n");
      free_list(&freelist);
      //printf("-> items armazenados:\n");
      //for(i=0; i <= pf_hashmask; i++) {
      //   for(item=pfnt_hash[i].list; item; item=item->next) {
      //      print_nattrack(item->nt, 0);
      //   }
      //}

      //printf("Nova rodada? (1 = sim) ");
   } while(scanf("\n%d", &i) != EOF && i != 0);
   */ // comentando para get_states

   free_list(&lastlist);
   free(pfnt_hash);

   return 0;
}
Esempio n. 23
0
static void  filler(decayDiagram ar)
{int     nf=0, k, l=1;

   ni = 0; nk = 0; se = 100;

nn:if (nk > 3) ladd(&l);
   {  knot *with1 = &kn[nk];

      with1->pt = abs(ar[l-1]);
      ladd(&l); with1->fr = nf;
      with1->ty = 0; with1->e3 = 0;

ll:   if (ar[l-1] > 0)
      {
         if (tpc == 1 || se != 100) ni++;
         if (se == 100) se = nk;
         with1->ty++;
         if (with1->ty == 2)
         {  with1->e2 = ar[l-1];
            with1->n2 = ni;
            ladd(&l); goto pp;
         }
         with1->e1 = ar[l-1];
         with1->n1 = ni;
         ladd(&l);
         goto ll;
      }
      nf = nk;
      with1->e2 = -(++nk);
      goto nn;
   }

pp:for (k = nk; k >= 0; k--)
   {  knot *with1 = &kn[k];
      if (with1->ty == 0)
         if (ar[l-1] > 0)
         {
            with1->e1 = ar[l-1];
            if (tpc == 1 || se != 100)
               with1->n1 = ++ni;
            if (se == 100) se = k;
            ladd(&l);
            with1->ty = 1;
         }
         else
         {  nf = k;
            with1->ty = -1;
            with1->e1 = -(++nk);
            goto nn;
         }
   }
   for (k = 0; k <= nk; k++)
   {  knot *with1 = &kn[k];
      if (with1->ty < 0) with1->ty = 0;
      if (tpc == 1 || k != se)
         order(&with1->e1,&with1->e2,&with1->n1,&with1->n2);
   }

   kl = elong(0) + 1;
   kt = empt(0);
   kk = kl - 2 - kt;
   if (tpc == 2) kn[se].e1 = prtclbase[kn[se].e1-1].anti;

   se1 = se;
   ks = 0;
   if (kt > 0) triplet(0);
}