/[hurd]/hurd/libcons/cons-lookup.c
ViewVC logotype

Diff of /hurd/libcons/cons-lookup.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by marcus, Thu Aug 22 19:24:19 2002 UTC revision 1.2 by marcus, Sun Sep 8 21:55:59 2002 UTC
# Line 24  Line 24 
24    
25  #include "cons.h"  #include "cons.h"
26    
27  /* Lookup the virtual console with number ID in the console CONS,  /* Lookup the virtual console entry with number ID in the console
28     acquire a reference for it, and return it in R_VCONS.  If CREATE is     CONS, and return it in R_VCONS_ENTRY.  If CREATE is true, the
29     true, the virtual console will be created if it doesn't exist yet.     virtual console entry will be created if it doesn't exist yet.  If
30     If CREATE is true, and ID 0, the first free virtual console id is     CREATE is true, and ID 0, the first free virtual console id is
31     used.  CONS must be locked.  */     used.  CONS must be locked.  */
32  error_t  error_t
33  cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)  cons_lookup (cons_t cons, int id, int create, vcons_list_t *r_vcons_entry)
34  {  {
35    vcons_t previous_vcons = 0;    vcons_list_t previous_vcons_entry = 0;
36    vcons_t vcons;    vcons_list_t vcons_entry;
37    
38    if (!id && !create)    if (!id && !create)
39      return EINVAL;      return EINVAL;
# Line 42  cons_lookup (cons_t cons, int id, int cr Line 42  cons_lookup (cons_t cons, int id, int cr
42      {      {
43        if (cons->vcons_list && cons->vcons_list->id <= id)        if (cons->vcons_list && cons->vcons_list->id <= id)
44          {          {
45            previous_vcons = cons->vcons_list;            previous_vcons_entry = cons->vcons_list;
46            while (previous_vcons->next && previous_vcons->next->id <= id)            while (previous_vcons_entry->next
47              previous_vcons = previous_vcons->next;                   && previous_vcons_entry->next->id <= id)
48            if (previous_vcons->id == id)              previous_vcons_entry = previous_vcons_entry->next;
49              if (previous_vcons_entry->id == id)
50              {              {
51                /* previous_vcons->refcnt++; */                *r_vcons_entry = previous_vcons_entry;
               *r_vcons = previous_vcons;  
52                return 0;                return 0;
53              }              }
54          }          }
# Line 60  cons_lookup (cons_t cons, int id, int cr Line 60  cons_lookup (cons_t cons, int id, int cr
60        id = 1;        id = 1;
61        if (cons->vcons_list && cons->vcons_list->id == 1)        if (cons->vcons_list && cons->vcons_list->id == 1)
62          {          {
63            previous_vcons = cons->vcons_list;            previous_vcons_entry = cons->vcons_list;
64            while (previous_vcons && previous_vcons->id == id)            while (previous_vcons_entry && previous_vcons_entry->id == id)
65              {              {
66                id++;                id++;
67                previous_vcons = previous_vcons->next;                previous_vcons_entry = previous_vcons_entry->next;
68              }              }
69          }          }
70      }      }
71    
72    vcons = calloc (1, sizeof (struct vcons));    vcons_entry = calloc (1, sizeof (struct vcons_list));
73    if (!vcons)    if (!vcons_entry)
74      {      return ENOMEM;
       mutex_unlock (&vcons->cons->lock);  
       return ENOMEM;  
     }  
   vcons->cons = cons;  
   /* vcons->refcnt = 1; */  
   vcons->id = id;  
   mutex_init (&vcons->lock);  
   vcons->input = -1;  
   vcons->display = MAP_FAILED;  
   vcons->notify = NULL;  
   
 #if 0  
   err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,  
                         cons->foreground, cons->background);  
   if (err)  
     {  
       free (vcons->name);  
       free (vcons);  
       return err;  
     }  
75    
76    err = input_create (&vcons->input, cons->encoding ?: DEFAULT_ENCODING);    vcons_entry->id = id;
77    if (err)    vcons_entry->vcons = NULL;
     {  
       display_destroy (vcons->display);  
       free (vcons->name);  
       free (vcons);  
       return err;  
     }  
 #endif  
   
   cons_vcons_add (vcons);  
78    
79    /* Insert the virtual console into the doubly linked list.  */    /* Insert the virtual console into the doubly linked list.  */
80    if (previous_vcons)    if (previous_vcons_entry)
81      {      {
82        vcons->prev = previous_vcons;        vcons_entry->prev = previous_vcons_entry;
83        if (previous_vcons->next)        if (previous_vcons_entry->next)
84          {          {
85            previous_vcons->next->prev = vcons;            previous_vcons_entry->next->prev = vcons_entry;
86            vcons->next = previous_vcons->next;            vcons_entry->next = previous_vcons_entry->next;
87          }          }
88        else        else
89          cons->vcons_last = vcons;          cons->vcons_last = vcons_entry;
90        previous_vcons->next = vcons;        previous_vcons_entry->next = vcons_entry;
91      }      }
92    else    else
93      {      {
94        if (cons->vcons_list)        if (cons->vcons_list)
95          {          {
96            cons->vcons_list->prev = vcons;            cons->vcons_list->prev = vcons_entry;
97            vcons->next = cons->vcons_list;            vcons_entry->next = cons->vcons_list;
98          }          }
99        else        else
100          cons->vcons_last = vcons;          cons->vcons_last = vcons_entry;
101        cons->vcons_list = vcons;        cons->vcons_list = vcons_entry;
102      }      }
103    *r_vcons = vcons;  
104      cons_vcons_add (cons, vcons_entry);
105      *r_vcons_entry = vcons_entry;
106    return 0;    return 0;
107  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26