⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sds_list.c

📁 这是一个Linux下的集成开发环境
💻 C
📖 第 1 页 / 共 2 页
字号:
      else      {        char string[128];        sprintf(string,"Bank %s exhausted", list->name);        sds_push_error(SDS_NO_SUCH_OBJ, SDS_WARNING, string);      }    }  }  else  {    node = sds_new_node();    if (!sds_add_node(list, node))      sds_push_error(SDS_NO_SUCH_LIST, SDS_WARNING, "Failed to add node");    node->datatype = datatype;    node->sds = sds;    node->object = object;    node->datasize = dsize;    node->align = align;    node->nelems = multiplicity;    node->data = data;  }  return node;}/******************************************************************void sds_remove_data(node)******************************************************************/voidsds_remove_data(node)struct node_control *node;{  if (node == NULL || node->marked_for_delete)  {    sds_push_error(SDS_NO_SUCH_OBJ, SDS_WARNING, "Removing non-existant node");    return;  }  node->marked_for_delete = 1;}/******************************************************************     INTERNALint sds_add_node(list, node)******************************************************************/intsds_add_node(list, node)struct list_control *list;struct node_control *node;{  if (node == NULL)  {    sds_push_error(SDS_NO_SUCH_OBJ, SDS_WARNING, "Adding null node");    return 1;  }  node->up = list;  if (list->head == NULL)  {    list->head = node;    list->tail = node;    node->next = NULL;    node->prev = NULL;  }  else  {    list->tail->next = node;    node->prev = list->tail;    list->tail = node;  }  if (list->is_homogeneous)  {    node->sds = list->sds;    node->object = list->object;    node->datatype = list->datatype;  }  list->nnodes++;  list->current = node;  return 1;}/******************************************************************     INTERNALstruct node_control * sds_new_node(void)******************************************************************/struct node_control *sds_new_node(VOIDDEF){  struct node_control *node =        (struct node_control *)malloc(sizeof(struct node_control));  sds_init_node(node);  node->node_was_malloced = 1;  return node;}/******************************************************************int    INTERNALlong sds_delete_node(node)******************************************************************/intsds_delete_node(node)struct node_control *node;{  struct list_control *list;  if (node == NULL)  {    sds_push_error(SDS_NO_SUCH_OBJ, SDS_WARNING, "node already deleted");    return 0;  }  list = node->up;  if (list->is_deleted)  {    sds_push_error(SDS_NO_SUCH_LIST, SDS_ERROR, "List index deleted");    return 0;  }  if (node->prev != NULL)  {    if (list->current == node)      list->current = node->prev;    if (node->next != NULL) /* prev and next exist */    {      node->next->prev = node->prev;      node->prev->next = node->next;    }    else /* prev, but no next */    {      list->tail = node->prev;       node->prev->next = NULL;    }  }  else /* no prev */  {    list->head = node->next;    if (node->next != NULL) /* next, but no prev */      node->next->prev = NULL;    else /* no next or prev */      list->tail = NULL;    if (list->current == node)      list->current = list->head;  }  if (node->data_was_malloced)    free((char *)node->data);  if (node->node_was_malloced)    free((char *)node);  list->nnodes--;  return 1;}/******************************************************************     INTERNALvoid sds_bank_compress(list_index)******************************************************************/voidsds_bank_compress(list_index)int list_index;{  sds_listcon *slc = sds_listc();  struct node_control *node = slc->lc[list_index - 1].head;  struct node_control *scan;  while (node != NULL)  {    if (node->marked_for_delete && !node->data_was_malloced)    {      void *banknow = node->data;      long size;      scan = node;      while((scan = scan->next) != NULL)      {        unsigned char align = 0;        if (scan->next != NULL)          align = scan->next->align;        banknow = (void *)((long)banknow + align_delta((off_t)banknow, align));        size = scan->datasize * scan->nelems;        memcpy(banknow, scan->data, (int)size);        scan->data = banknow;        banknow = (void *)((long)banknow + size);      }      slc->lc[list_index - 1].bankused =            (long)banknow - (long)slc->lc[list_index - 1].databank;      scan = node;      sds_delete_node(node);      node = scan->next;    }    else      node = node->next;  }}/******************************************************************     INTERNALvoidsds_init_node(node)******************************************************************/voidsds_init_node(node)struct node_control *node;{  node->next = NULL;  node->prev =  NULL;  node->up = NULL;  node->down = NULL;  node->data = NULL;  node->datasize =   node->sds =   node->object = 0;  node->name = NULL;  node->marked_for_delete =  node->node_was_malloced = 0;  node->data_was_malloced = 0;}/******************************************************************long sds_make_as_list(name, id,sds,object)******************************************************************/intsds_make_as_list(name, id,sds,object)char *name;int id;sds_handle sds,object;{  int list_index;  struct list_control *list;  sds_code mult,code,count,dsize;  void *data;  list_index = sds_new_list(name,id);  if ((list = goodlist(list_index)) == NULL)    return 0;  if ((code = sds_obind2code(sds,object)) == 0)  {    char string[128];    sprintf(string,"Object %ld from sds %ld does not exist", (long)object,(long)sds);    sds_push_error(sds, SDS_WARNING, string);    return 0;  }  mult = sds_array_size(sds,object);  data = sds_obind2ptr(sds,object);  dsize = sds_psize(code);  for (count = 0;count < mult; count++)  {    sds_new_data(list_index,1,code,sds,object,data);    if (sds_get_object_type(sds,object) == SDS_VARIABLE_LENGTH)      data = sds_estart(sds)[object];     else      data = (void *)((long)data + dsize);  }  list->is_homogeneous = 1;  list->sds = sds;  list->object = object;  return list_index;}/******************************************************************int sds_allnodes(void)******************************************************************/int sds_allnodes(VOIDDEF){  int i;  sds_listcon *slc = sds_listc();  int total_nodes = 0;  for (i=0;i<slc->lastlist;i++)    total_nodes += slc->lc[i].nnodes;  return total_nodes;}/******************************************************************int sds_concat_list()******************************************************************/intsds_concat_list(sds,nodes,lists, nindex, lindex, l)sds_handle sds;struct node_control *nodes;struct list_control *lists;long *nindex, *lindex, l;{  sds_listcon *slc = sds_listc();  struct list_control *list = &lists[*lindex];  if (!slc->lc[l].done_output)  {    if (!slc->lc[l].is_deleted)    {      memcpy((char *)list,(char *)&slc->lc[l],sizeof(struct list_control));      sds_concat_nodes(sds,nodes,lists, nindex, lindex);      if (list->name != NULL)        list->name = (char *)sds_add_to_heap(sds,slc->lc[l].name, (char)0);      (*lindex)++;      slc->lc[l].done_output = 1;      return *lindex - 1;    }  }  else  {    long i = 0;    while (&lists[i] != &slc->lc[l])      i++;    return i + 1;  }  return 0;}/******************************************************************void sds_save_lists(filename)******************************************************************/voidsds_save_lists(filename)char *filename;{  long i;  sds_listcon *slc = sds_listc();  sds_handle sds, sdsinfo;  sds_code typecode;  long nindex = 0, lindex = 0;  sds_record_handle *rh;  struct stat databuf;  struct sds_control_p *scp;  struct node_control *nodes;  struct list_control *lists;   int total_nodes = sds_allnodes();  sds = sds_new("tree");  lists = (struct list_control *)            sds_malloc(slc->lastlist * sizeof(struct list_control));  nodes = (struct node_control *)            sds_malloc(total_nodes * sizeof(struct node_control));  clean_lists();  for (i=0;i<slc->lastlist;i++)    sds_concat_list(sds,nodes,lists,&nindex, &lindex, i);  clean_lists();  typecode = sds_define_structure(sds,nodec_tl,nodec_names);  sds_declare_structure(sds,nodes,"Nodes", total_nodes, typecode);  typecode = sds_define_structure(sds,listc_tl,listc_names);  sds_declare_structure(sds,lists,"Lists", lindex, typecode);  for (sdsinfo=1;sdsinfo<=sds_max();sdsinfo++)  {    char name[128];    int mdate;    int size;    short index;    scp = sds_control(sdsinfo);    if (scp && scp->load_name && sdsinfo != sds)    {      stat(scp->load_name , &databuf);      mdate = databuf.st_mtime;      size = databuf.st_size;      index = sdsinfo;      strcpy(name,"SDS:");      strcat(name ,sds_obind2name(sdsinfo,0));      rh = sds_begin_record(name);      sds_record_entry(rh, SDS_SHORT, 1, &index, "index");      sds_record_entry(rh, SDS_STRING, strlen(scp->load_name) + 1,                                                     scp->load_name, "name");      sds_record_entry(rh, SDS_INT, 1, &scp->source, "type");      sds_record_entry(rh, SDS_UNIX_TIME, 1, &mdate, "mod_date");      sds_record_entry(rh, SDS_LONG, 1, &size, "size");      sds_end_and_declare(rh,sds);    }  }  sds_ass(sds,filename, SDS_FILE);  sds_destroy(sds);  free(lists);  free(nodes);}  /******************************************************************void sds_concat_nodes(sds, nodes,list, nindex, lindex)******************************************************************/voidsds_concat_nodes(sds,nodes,lists, nindex, lindex)sds_handle sds;struct node_control *nodes;struct list_control *lists;long *nindex, *lindex;{  struct list_control *list = &lists[*lindex];  struct node_control *n = list->head;  sds_listcon *slc = sds_listc();  list->head = (void *)*nindex; /*looks odd but for internalised pointer */  while (n != NULL)  {    memcpy((char *)&nodes[*nindex], (void *)n, sizeof(struct node_control));    if (n->name != NULL)      nodes[*nindex].name = (void *)sds_add_to_heap(sds,n->name, (char)0);    if (n->prev != NULL)      nodes[*nindex -1].next = (void *)*nindex;    if (n->next != NULL)      nodes[*nindex].next = (void *)(*nindex + 1);    else      list->tail = (void *)*nindex;    if (n->down!= NULL)    {      long li;      for (li = 0;li < slc->lastlist; li++)        if (&lists[li] == n->down)        {          nodes[*nindex].down =               (void *)sds_concat_list(sds,nodes,lists,nindex,lindex,li);          break;        }    }    (*nindex)++;    n = n->next;  }}sds_code sds_get_size(sds, elemtype)sds_code elemtype;sds_handle sds;{  if (elemtype < (long)NTYPES) /* It's a primitive */     return sds_psize(elemtype);  else  {    struct type_list *tl = sds_tlist(sds);    tl = &tl[(elemtype & ~SDS_INDLIST) + 1];    return (tl->nelems);  }}struct node_control *sds_get_current(list)struct list_control *list;{  return list->current;}/******************************************************************struct node_control * sds_add()******************************************************************/struct node_control *sds_add(list, name, data, id, size, type)struct list_control *list;char *name;void *data;int id;int size;int type;{  struct node_control *node = NULL;  char align;  align = sds_psize(type);  node = sds_new_node();  if (!sds_add_node(list, node))    sds_push_error(SDS_NO_SUCH_LIST, SDS_WARNING, "Failed to add node");  node->datatype = type;  node->sds = 0;  node->object = id;  node->datasize = size;  node->align = align;  node->nelems = 1;  node->data = data;  node->name = name;  return node;}struct node_control *sds_next(list,prev)struct list_control *list;struct node_control *prev;{  struct node_control *n;  if (list->is_deleted == 1)    return 0;  if (!prev)		sds_gobefore(list,0);  if (list->current == 0)	{		list->current = list->head;		return 0;	}  if (prev && list->current->prev != prev)    sds_gobefore(list,prev);	n = list->current;  list->current = list->current->next;  return n;}intsds_gobefore(list,node)struct list_control *list;struct node_control *node;{	if (node == 0)		list->current = node = list->head;  if (list->current == node)    return 1;  list->current = list->head;  if (node != 0)  {    while(list->current != node)		{      list->current = list->current->next;			if (!list->current)				return 0;		}  }	return 1;}voidsds_no_lists() { listsleft = 0; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -