Ejemplo n.º 1
0
Archivo: w_init.c Proyecto: j13s/devil
/* Draws a button with an image. data is the substructure of
   the button. bm is the pointer to the normal image. abm the pointer to the
   image for the activated button. The color 0 in the images is replaced
   with the correct background color for the button. The button is as large
   as the image plus the edge of the button if the xsize is set to -1.
   If the button is a string button ysize may be set to -1 to get the
   stdsize for stringbuttons. If the buttons is not a string button and
   xsize!=-1 then ysize must be set as well.
   Therefore both images must be of equal size. The position is the position
   of the left upper edge of the button (not the image).
   Returns pointer to button-structure if successful, 0 otherwise. */
struct w_button *w_addimagebutton(struct w_window *w, enum but_types type,
                                  int xpos, int ypos, int xsize, int ysize,
                                  struct ws_bitmap *bm,
                                  struct ws_bitmap *abm, void *data,
                                  int with_bg,
                                  int draw)
{
    struct w_button *b, *nb;
    struct w_description *d1, *d2;


    if (abm == NULL || bm == NULL || abm->xsize != bm->xsize || abm->ysize !=
        bm->ysize) {
        return NULL;
    }

    checkmem( b = MALLOC( sizeof(struct w_button) ) );
    b->xpos = xpos;
    b->ypos = ypos;
    b->w = w;

    if (xsize < 0) {
        b->xsize = bm->xsize + (type == w_b_switch ? 6 : 2);
        b->ysize = bm->ysize + (type == w_b_switch ? 6 : 2);
    }
    else {
        b->xsize = xsize;
        b->ysize = ysize < 0 ? shapes.titlebar_height + 5 : ysize;
    }

    b->type = type;
    b->helptxt = NULL;
    initlist(&b->inscription);
    initlist(&b->a_inscription);
    b->d.d = data;
    checkmem( d1 = MALLOC( sizeof(struct w_description) ) );
    d1->contents.bm = bm;
    d1->type = w_bdt_image;
    d1->image_with_bg = with_bg;
    d1->y = d1->x = type == w_b_switch ? 3 : 1;

    if (type == w_b_string) {
        d1->y = (b->ysize - bm->ysize) / 2;
        b->d.str->d_xsize = bm->xsize + 2;
        b->d.str->offset = 0;
        b->d.str->length = (b->xsize - b->d.str->d_xsize - 10) / ws_pixstrlen(
            "M");
    }

    checkmem( addnode(&b->inscription, -1, d1) );
    checkmem( d2 = MALLOC( sizeof(struct w_description) ) );
    *d2 = *d1;
    d2->contents.bm = abm;
    checkmem( addnode(&b->a_inscription, -1, d2) );
    nb = w_addbutton(b, draw);
    free(b);
    return nb;
}
Ejemplo n.º 2
0
Archivo: w_init.c Proyecto: j13s/devil
/* This routine is called to initialize the Window system. You must therefore
   init the grfx & all variables you need.
   xres,yres and colors are the parameters of the grfx-mode.
   palette are the colors.
   If fontname==NULL, a default font is used.
   Returns zero if not successful.
   If it's not succesful you must remain in Textmode.
   If successful return a 1 */
int w_initwins(int xres, int yres, int colors, const char *fontname) {
    initlist(&notes.windows);
    initlist(&notes.menu);
    notes.print_msg = 1;
    notes.xres = xres;
    notes.yres = yres;
    notes.colors = colors;
    notes.winspace.xp = notes.winspace.yp = 0;
    notes.winspace.xs = xres;
    notes.winspace.ys = yres;
    notes.cur_win = NULL;
    notes.cur_but = NULL;
    notes.titlebar_text = NULL;

    if ( ( errf = fopen("devil.err", "w") ) == NULL ) {
        errf = stdout;
    }

    if ( !ws_initgrfx(xres, yres, colors, fontname) ) {
        return 0;
    }

    ws_setcolor(0, 0, 0, 0);
    notes.colindex[cv_bg] = w_makecolor(0, 0, 0);
    notes.colindex[cv_winfill] = w_makecolor(0, 0, 0);
    notes.colindex[cv_textbg] = w_makecolor(0, 0, 0);
    ws_setcolor(1, 150, 150, 150);
    notes.colindex[cv_winedge] = w_makecolor(150, 150, 150);
    notes.colindex[cv_buttonin] = w_makecolor(150, 150, 150);
    ws_setcolor(2, 255, 255, 255);
    notes.colindex[cv_windrag] = w_makecolor(255, 255, 255);
    ws_setcolor(3, 200, 200, 200);
    notes.colindex[cv_buttonlt] = w_makecolor(200, 200, 200);
    ws_setcolor(4, 100, 100, 100);
    notes.colindex[cv_buttonrb] = w_makecolor(100, 100, 100);
    ws_setcolor(5, 120, 120, 120);
    notes.colindex[cv_buttonpressed] = w_makecolor(120, 120, 120);
    ws_setcolor(6, 130, 130, 130);
    notes.colindex[cv_switchon] = w_makecolor(130, 130, 130);
    ws_setcolor(7, 255, 255, 255);
    notes.colindex[cv_textfg] = w_makecolor(255, 255, 255);
    ws_setcolor(8, 255, 0, 0);
    notes.colindex[cv_buttonmarker] = w_makecolor(255, 0, 0);
    ws_setcolor(9, 200, 150, 50);
    notes.colindex[cv_curwin] = w_makecolor(200, 150, 50);
    ws_setcolor(10, 250, 190, 65);
    notes.colindex[cv_curwinlt] = w_makecolor(250, 190, 65);
    ws_setcolor(11, 160, 120, 40);
    notes.colindex[cv_curwinrb] = w_makecolor(160, 120, 40);
    notes.initialized = 1;
    ws_resetmousecolors();
    return 1;
}
Ejemplo n.º 3
0
void sys_init(void)

{
	int i;
	str_pword pword;

	initlist(&word_list[0]);
	word_list[0].data = 0;
	current_list = (plist) malloc(sizeof(list));

	index_list[0] = (plist) malloc(sizeof(list));
	pword=(str_pword)malloc(sizeof(str_word));
	pword->freq = 0;
	pword->word[0] = 'a' + i;
	pword->word[1] = '\0';
	insert_data(&word_list[0], i + 1,pword);
	index_list[0] = &word_list[0];
	index_list[0] = index_list[0]->next;

	for(i = 1; i < 27;i++){
		index_list[i] = (plist) malloc(sizeof(list));
		pword=(str_pword)malloc(sizeof(str_word));
		pword->freq = 0;
		pword->word[0] = 'a' + i;
		pword->word[1] = '\0';
		insert_data(&word_list[0], i + 1,pword);
		index_list[i] = index_list[i - 1]->next;
		//pword = index_list[i]->data;
		//printf("%d\n", pword->freq);
	}
}
Ejemplo n.º 4
0
Archivo: node.c Proyecto: neotaso/pp
int main(){
  int i;
  list list;
  list = initlist();
  getlist(list);
  printlist(list);
  return 0;
}
Ejemplo n.º 5
0
/*** Overall System Initialization ***/
void initialize(int argc, char ** argv, unsigned * stateptr,listptr *historyptr)
{
	system("clear");

	*stateptr |= DEFAULT;

	signal(SIGCHLD, reapz);

	*historyptr = initlist(HISTORYSIZE);
}
Ejemplo n.º 6
0
int main()
{
	int set[] = {0, 1, 2, 3, 4, 5, 6};

	struct ListNode *list1 = initlist(set, sizeof(set)/sizeof(int));
	printlist(list1);

	struct ListNode *res = swapPairs(list1);
	printlist(res);
}	
Ejemplo n.º 7
0
Archivo: tools.c Proyecto: j13s/devil
void freelist( struct list *l, void (*freeentry)(void *) ) {
    struct node *n;


    for (n = l->head->next; n != NULL; n = n->next) {
        freenode(l, n->prev, freeentry);
    }

    l->size = 0;
    initlist(l);
}
Ejemplo n.º 8
0
struct filenode *newnode(const char *base, const char *name, int curroffset)
{
	struct filenode *node;
	int len;
	char *str;

	node = malloc(sizeof (*node));
	if (!node) {
		fprintf(stderr,"out of memory\n");
		exit(1);
	}

	len = strlen(name);
	str = malloc(len+1);
	if (!str) {
		fprintf(stderr,"out of memory\n");
		exit(1);
	}
	strcpy(str, name);
	node->name = str;

	if (!curroffset) {
		len = 1;
		name = ".";
	}
	if (strlen(base))
		len++;
	str = malloc(strlen(base)+len+1);
	if (!str) {
		fprintf(stderr,"out of memory\n");
		exit(1);
	}
	if (strlen(base)) {
		sprintf(str, "%s/%s", base, name);
	} else {
		strcpy(str, name);
	}

	node->realname = str;
	node->next = node->prev = NULL;
	node->parent = NULL;
	initlist(&node->dirlist, node);

	node->ondev = -1;
	node->onino = -1;
	node->modes = -1;
	node->size = 0;
	node->devnode = 0;
	node->orig_link = NULL;
	node->offset = curroffset;
	node->pad = 0;

	return node;
}
int main()
{
	int sets[] = {0, 0, 0, 1, 4, 4, 6, 7, 7};

	struct ListNode *beforerm = initlist(sets, sizeof(sets)/sizeof(int));
	printf("before remove, list is :\n");
	printlist(beforerm);

	struct ListNode *afterrm = deleteDuplicates(beforerm);
	printf("\nafter remove, list is :\n");
	printlist(afterrm);
}
Ejemplo n.º 10
0
void main() 
{sqlist L; 
int i,j,k,b,n,e,m,a,cur_e,pre_e,next_e,s; 
initlist(L); 
cout<<"初始化后的基值地址:"<<L.elem<<" L.length=:"<<L.length<<" L.listsize=:"<<L.listsize<<endl; 
cout<<"新建一顺序表."<<endl; 
cout<<"当前表是否为空表"<<listempty(L)<<endl; 
cout<<"定义该线性表长度:"<<endl; 
cin>>a; 
cout<<"分别输入线性表的各个元素,按ENTER"<<endl; 
for(k=1;k<=a;k++){ 
cin>>j; 
i=listinsert(L,k,j);} 
for(b=1;b<=a;b++) 
cout<<L.elem[b-1]<<endl; 
listlength(L); 
cout<<"当前表长:"<<L.length<<endl; 
cout<<"输入要取的数的位置n(n<=a)"<<endl; 
cin>>n; 
getelem(L,n,e); 
//cout<<L.elem[n-1]<<endl; 
cout<<e<<endl;
cout<<"与该数相等的的一个数的位序为:"<<locateelem(L,e,compare)<<endl; 
cout<<"输入要取前驱的数的位置m(<=a)"<<endl; 
cin>>m; 
getelem(L,m,cur_e); 
if(priorelem(L,cur_e,pre_e)) 
cout<<"cur_e的前驱为:"<<pre_e<<endl; 
else 
cout<<"该元素没前驱"<<endl; 
nextelem(L,cur_e,next_e); 
if(nextelem(L,cur_e,next_e)) 
cout<<"cur_e的后继为:"<<next_e<<endl; 
else 
cout<<"该元素没后继"<<endl;
cout<<"奇数在前,偶数在后,并输出"<<endl; 

move(L);
for(s=1;s<=a;s++) 
cout<<L.elem[s-1]<<endl; 

cout<<"输入要删元素的位序m(<=a)"<<endl; 
cin>>m; 
listdelete(L,m,e); 
cout<<"被删的元素为:"<<e<<endl; 
cout<<"删除元素后表长为"<<L.length<<endl; 
//listtraverse(L,visit); 

cout<<"置为空表"<<clearlist(L)<<endl; 
cout<<"销毁线性表"<<destroylist(L)<<endl;
}
Ejemplo n.º 11
0
int main()
{
	int set[] = {0, 1, 2, 3, 4, 5, 6};

	struct ListNode *res = NULL;

	int k;
	for(k = 2; k <= 7; k++)
	{
		struct ListNode *list1 = initlist(set, sizeof(set)/sizeof(int));
		res = reverseKGroup(list1, k);
		printlist(res);
	}
}
Ejemplo n.º 12
0
static void aout_initwrite(section *sec)
{
  initlist(&aoutstrlist.l);
  aoutstrlist.hashtab = mycalloc(STRHTABSIZE*sizeof(struct StrTabNode *));
  aoutstrlist.nextoffset = 4;  /* first string is always at offset 4 */
  initlist(&aoutsymlist.l);
  aoutsymlist.hashtab = mycalloc(SYMHTABSIZE*sizeof(struct SymbolNode *));
  aoutsymlist.nextindex = 0;
  initlist(&treloclist);
  initlist(&dreloclist);

  /* find exactly one .text, .data and .bss section for a.out */
  sections[_TEXT] = sections[_DATA] = sections[_BSS] = NULL;
  secsize[_TEXT] = secsize[_DATA] = secsize[_BSS] = 0;

  for (; sec; sec=sec->next) {
    int i;

    /* section size is assumed to be in in (sec->pc - sec->org), otherwise
       we would have to calculate it from the atoms and store it there */
    if ((sec->pc - sec->org) > 0 || (sec->flags & HAS_SYMBOLS)) {
      i = get_sec_type(sec);
      if (!sections[i]) {
        sections[i] = sec;
        secsize[i] = get_sec_size(sec);
        sec->idx = i;  /* section index 0:text, 1:data, 2:bss */
      }
      else
        output_error(7,sec->name);
    }
  }

  secoffs[_TEXT] = 0;
  secoffs[_DATA] = secsize[_TEXT] + balign(secsize[_TEXT],SECT_ALIGN);
  secoffs[_BSS] = secoffs[_DATA] + secsize[_DATA] +
                  balign(secsize[_DATA],SECT_ALIGN);
}
Ejemplo n.º 13
0
int main(void) {
  struct node *list;
  list = initlist();
  while (1) {
    int c = getchar();//入力
    if (c == '\n' || c == EOF) {
      break;
    }
    insert(list, c);
  }
  // printlist(list->next);
  check(list,list,0);
  // putchar('\n');
  return 0;
}
Ejemplo n.º 14
0
int main(){
	init();
	initlist();
	long n=0,c,lukynumber,r,order;
	bool isboy;
	int people;
	while(getpresent(c,lukynumber,isboy)){
		++n;
		frcount[n]=c;
		insert(n);
		r=rank(c)+1;
		r+=lukynumber*(isboy?1:-1);
		if(r<0||r>=account)tell(-1);
		else{
			people=select(r);
			tell(people);
			remove(r);
			if(--frcount[people])insert(people);
		}
	}
	return 0;
}
Ejemplo n.º 15
0
static void init_lists(void)
{
  initlist(&shdrlist);
  initlist(&symlist);
  initlist(&relalist);
  shstrlist.index = strlist.index = 0;
  initlist(&shstrlist.l);
  initlist(&strlist.l);
  symindex = shdrindex = stabidx = 0;
  addString(&shstrlist,emptystr);  /* first string is always "" */
  symtabidx = addString(&shstrlist,".symtab");
  strtabidx = addString(&shstrlist,".strtab");
  shstrtabidx = addString(&shstrlist,".shstrtab");
  addString(&strlist,emptystr);
  if (!no_symbols && first_nlist) {
    initlist(&stabstrlist.l);
    addString(&stabstrlist,emptystr);
  }
}
Ejemplo n.º 16
0
int main(int argc,char *argv[])
{
  struct GlobalVars *gv = &gvars;
  int i,j;
  char *buf;
  struct LibPath *libp;
  struct InputFile *ifn;
  bool stdlib = TRUE;
  int so_version = 0;   /* minum version for shared objects */
  uint16_t flags = 0;   /* input file flags */

  /* initialize and set default values */
  memset(gv,0,sizeof(struct GlobalVars));
  initlist(&gv->libpaths);
  initlist(&gv->rpaths);
  gv->dynamic = TRUE;  /* link with dynamic libraries first */
  gv->interp_path = DEFAULT_INTERP_PATH;
  gv->soname = NULL;
  gv->endianess = -1;  /* endianess is unknown */

  /* initialize targets */
  for (j=0; fff[j]; j++) {
    if (fff[j]->init)
      fff[j]->init(gv);
  }
#ifdef DEFTARGET
  for (j=0; fff[j]; j++) {
    if (!strcmp(fff[j]->tname,DEFTARGET)) {
      gv->dest_format = (uint8_t)j;
      break;
    }
  }
  if (fff[j] == NULL) {
    fprintf(stderr,"Configuration warning: Selected default target "
            "\"%s\" is not included.\nThe current default target "
            "is \"%s\".\n",DEFTARGET,fff[gv->dest_format]->tname);
    printf("\n");
  }
#endif

  initlist(&gv->inputlist);
  initlist(&gv->lnksec);
  gv->dest_name = "a.out";
  gv->maxerrors = DEF_MAXERRORS;
  gv->reloctab_format = RTAB_UNDEF;
  gv->osec_base_name = NULL;

  if (argc<2 || (argc==2 && *argv[1]=='?')) {
    show_usage();
    exit(EXIT_SUCCESS);
  }

  for (i=1; i<argc; i++) {

    if (*argv[i] == '-') {  /* option detected */
      switch (argv[i][1]) {

        case 'b':  
          if (!strcmp(&argv[i][2],"aseoff")) {  /* set base-relative offset */
            long bo;

            sscanf(get_arg(argc,argv,&i),"%li",&bo);
            fff[gv->dest_format]->baseoff = bo;
          }
          else {  /* select target format */
            if (buf = get_option_arg(argc,argv,&i)) {
              /* for compatibility with older vlink versions,
                 elf32amiga is automatically converted into elf32powerup
                 and amigaos into amigahunk */
              if (!strcmp(buf,"elf32amiga"))
                buf = "elf32powerup";
              else if (!strcmp(buf,"amigaos"))
                buf = "amigahunk";
              for (j=0; fff[j]; j++) {
                if (!strcmp(fff[j]->tname,buf))
                  break;
              }
              if (fff[j])
                gv->dest_format = (uint8_t)j;
              else
                error(9,buf);  /* invalid target format */
            }
          }
          break;

        case 'c':
          if (!strncmp(&argv[i][2],"lr-",3))
            flags &= ~(chk_flags(argv[i]));   /* -clr-flags */
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'd':
          if (!argv[i][2] || argv[i][2]=='c' || argv[i][2]=='p')
            gv->alloc_common = TRUE;  /* force alloc. of common syms. */
          else if (argv[i][2] == 'a')
            gv->alloc_addr = TRUE;  /* force alloc. of address syms. */
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'e':
          if (!strcmp(&argv[i][2],"xport-dynamic"))
            gv->dyn_exp_all = TRUE;  /* export all globals as dynamic */
          else  /* defines entry point */
            gv->entry_name = get_option_arg(argc,argv,&i);
          break;

        case 'f':
          if (!strcmp(&argv[i][2],"ixunnamed")) {
            gv->fix_unnamed = TRUE;  /* assign a name to unnamed sections */
          }
          else {  /* set a flavour */
            char *name,**fl;

            if (name = get_option_arg(argc,argv,&i)) {
              if (fl = gv->flavours.flavours) {
                char **tmp = alloc((gv->flavours.n_flavours+1)*sizeof(char *));

                memcpy(tmp,fl,gv->flavours.n_flavours*sizeof(char *));
                free(fl);
                fl = tmp;
              }
              else
                fl = alloc(sizeof(char *));
              fl[gv->flavours.n_flavours++] = name;
              gv->flavours.flavours = fl;
              gv->flavours.flavours_len += strlen(name) + 1;
            }
          }
          break;

        case 'g':
          if (!strcmp(&argv[i][2],"c-empty"))
            gv->gc_sects = GCS_EMPTY;
          else if (!strcmp(&argv[i][2],"c-all"))
            gv->gc_sects = GCS_ALL;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'h':
          if (!strcmp(&argv[i][2],"unkattr")) {
            struct SecAttrOvr *sao;
            char secname[64];
            lword val;

            val = get_assign_arg(argc,argv,&i,secname,64);
            sao = addsecattrovr(gv,secname,SAO_MEMFLAGS);
            sao->memflags = (uint32_t)val;
          }
          else {
            if (argv[i][2] == '\0') {
              show_usage();      /* help text */
              exit(EXIT_SUCCESS);
            }
            else
              error(2,argv[i]);  /* unrecognized option */
          }
          break;

        case 'i':
          if (!strcmp(&argv[i][2],"nterp"))
            gv->interp_path = get_arg(argc,argv,&i);
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'k':
          gv->keep_sect_order = TRUE;
          break;

        case 'l':  /* library specifier */
          if (buf = get_option_arg(argc,argv,&i)) {
            ifn = alloc(sizeof(struct InputFile));
            ifn->name = buf;
            ifn->lib = TRUE;
            ifn->dynamic = gv->dynamic;
            ifn->so_ver = so_version;
            so_version = 0;
            ifn->flags = flags;
            addtail(&gv->inputlist,&ifn->n);
          }
          break;

        case 'm':
          if (!strcmp(&argv[i][2],"inalign")) {
            long a;

            sscanf(get_arg(argc,argv,&i),"%li",&a);
            gv->min_alignment = (uint8_t)a;
          }
          else if (!strcmp(&argv[i][2],"rel"))
            gv->auto_merge = TRUE;
          else if (!strcmp(&argv[i][2],"type"))
            gv->merge_same_type = TRUE;
          else if (!strcmp(&argv[i][2],"ultibase"))
            gv->multibase = TRUE;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'n':
          if (!argv[i][2])
            gv->no_page_align = TRUE;
          else if (!strcmp(&argv[i][2],"ostdlib"))
            stdlib = FALSE;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'o':  /* set output file name */
          if (!strncmp(&argv[i][2],"sec=",4) && argv[i][6]!='\0') {
            /* defines a base name of the sections to output */
            gv->osec_base_name = &argv[i][6];
            gv->output_sections = TRUE;  /* output each section as a file */
          }
          else if (!strcmp(&argv[i][2],"sec"))
            gv->output_sections = TRUE;  /* output each section as a file */
          else
            gv->dest_name = get_option_arg(argc,argv,&i);
          break;

        case 'q':  /* force relocations into final executable */
          gv->keep_relocs = TRUE;
          break;

        case 'r':  /* output is an relocatable object again */
          if (!argv[i][2]) {
            gv->dest_object = TRUE;
          }
          else if (!strcmp(&argv[i][2],"path")) {
            if (buf = get_arg(argc,argv,&i)) {
              libp = alloc(sizeof(struct LibPath));
              libp->path = buf;
              addtail(&gv->rpaths,&libp->n);
            }
          }
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 's':
          switch (argv[i][2]) {
            case '\0':  /* strip all symbols */
              gv->strip_symbols = STRIP_ALL;
              break;
            case 'c':   /* -sc force small code */
              gv->small_code = TRUE;
              break;
            case 'd':   /* -d force small data */
              gv->small_data = TRUE;
              break;
            case 'e':
              if (!strncmp(&argv[i][3],"t-",2))  /* -set-flags */
                flags |= chk_flags(argv[i]);
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            case 'h':   /* -shared */
              if (!strcmp(&argv[i][3],"ared"))
                gv->dest_sharedobj = TRUE;
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            case 'o':   /* -soname <real name> */
              if (!strcmp(&argv[i][3],"name"))
                gv->soname = get_arg(argc,argv,&i);
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            case 't':   /* -static */
              if (!strcmp(&argv[i][3],"atic"))
                gv->dynamic = FALSE;
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            default:
              error(2,argv[i]);  /* unrecognized option */
              break;
          }
          break;

        case 't':  /* trace file accesses */
          if (!strcmp(&argv[i][2],"extbaserel"))
            gv->textbaserel = TRUE;
          else if (!strncmp(&argv[i][2],"os-",3)) {
            /* -tos-options for targets ataritos and aoutmint */
            if (!strcmp(&argv[i][5],"flags")) {
              long fl;

              sscanf(get_arg(argc,argv,&i),"%li",&fl);
              gv->tosflags = fl;
            }
            else if (!strcmp(&argv[i][5],"fastload"))
              gv->tosflags |= 1;
            else if (!strcmp(&argv[i][5],"fastram"))
              gv->tosflags |= 2;
            else if (!strcmp(&argv[i][5],"fastalloc"))
              gv->tosflags |= 4;
            else if (!strcmp(&argv[i][5],"private"))
              gv->tosflags &= ~0x30;
            else if (!strcmp(&argv[i][5],"global"))
              gv->tosflags |= 0x10;
            else if (!strcmp(&argv[i][5],"super"))
              gv->tosflags |= 0x20;
            else if (!strcmp(&argv[i][5],"readable"))
              gv->tosflags |= 0x30;
            else if (!strcmp(&argv[i][5],"textbased"))
              gv->textbasedsyms = 1;
            else
              error(2,argv[i]);  /* unrecognized option */
          }
          else if (!argv[i][2])
            gv->trace_file = stderr;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'u':  /* mark symbol as undefined */
          if (buf = get_option_arg(argc,argv,&i))
            add_symnames(&gv->undef_syms,buf);
          break;

        case 'v':  /* show version and target info */
          show_version();
          printf("Standard library path: "
#ifdef LIBPATH
                 LIBPATH
#endif
                 "\nDefault target: %s\n"
                 "Supported targets:",fff[gv->dest_format]->tname);
          for (j=0; fff[j]; j++)
            printf(" %s",fff[j]->tname);
          printf("\n");
          exit(EXIT_SUCCESS);

        case 'w':  /* suppress warnings */
          gv->dontwarn = TRUE;
          break;

        case 'x':  /* discard all local symbols */
          gv->discard_local = DISLOC_ALL;
          break;

        case 'y':  /* trace all accesses on a specific symbol */
          if (gv->trace_syms == NULL)
            gv->trace_syms = alloc_hashtable(TRSYMHTABSIZE);
          if (buf = get_option_arg(argc,argv,&i)) {
            struct SymNames **chain = 
                            &gv->trace_syms[elf_hash(buf)%TRSYMHTABSIZE];
            while (*chain)
              chain = &(*chain)->next;
            *chain = alloczero(sizeof(struct SymNames));
            (*chain)->name = buf;
          }
          break;

        case 'B':  /* set link mode */
          if (buf = get_option_arg(argc,argv,&i)) {
            if (!strcmp(buf,"static")) {
              gv->dynamic = FALSE;
            }
            else if (!strcmp(buf,"dynamic")) {
              gv->dynamic = TRUE;
            }
            else if (!strcmp(buf,"shareable")) {
              gv->dest_sharedobj = TRUE;
            }
            else if (!strcmp(buf,"forcearchive")) {
              gv->whole_archive = TRUE;
            }
            else if (!strcmp(buf,"symbolic")) {
              ;  /* don't know, what this means... */
            }
            else {
              error(3,buf);  /* unknown link mode */
            }
          }
          break;

        case 'C':  /* select con-/destructor type */
          if (buf = get_option_arg(argc,argv,&i)) {
            if (!strcmp(buf,"gnu")) {
              gv->collect_ctors_type = CCDT_GNU;
            }
            else if (!strcmp(buf,"vbcc")) {
              gv->collect_ctors_type = CCDT_VBCC;
            }
            else if (!strcmp(buf,"vbccelf")) {
              gv->collect_ctors_type = CCDT_VBCC_ELF;
            }
            else if (!strcmp(buf,"sasc")) {
              gv->collect_ctors_type = CCDT_SASC;
            }
            else  /* @@@ print error message */
              gv->collect_ctors_type = CCDT_NONE;
          }
          break;

        case 'E':  /* set endianess */
          switch (argv[i][2]) {
            case 'B':
              gv->endianess = _BIG_ENDIAN_;
              break;
            case 'L':
              gv->endianess = _LITTLE_ENDIAN_;
              break;
            default:
              error(2,argv[i]);  /* unrecognized option */
              break;
          }
          break;

        case 'F':  /* read a file with object file names */
          if (buf = get_option_arg(argc,argv,&i))
            ReadListFile(gv,buf,flags);
          break;

        case 'L':  /* new library search path */
          if (buf = get_option_arg(argc,argv,&i)) {
            libp = alloc(sizeof(struct LibPath));
            libp->path = buf;
            addtail(&gv->libpaths,&libp->n);
          }
          break;

        case 'M':  /* mapping output */
          gv->map_file = stdout;
          break;

        case 'P':  /* protect symbol against stripping */
          if (buf = get_option_arg(argc,argv,&i))
            add_symnames(&gv->prot_syms,buf);
          break;

        case 'R':  /* use short form for relocations */
          if (buf = get_option_arg(argc,argv,&i)) {
            if (!strcmp(buf,"std"))
              gv->reloctab_format = RTAB_STANDARD;
            else if (!strcmp(buf,"add"))
              gv->reloctab_format = RTAB_ADDEND;
            else if (!strcmp(buf,"short"))
              gv->reloctab_format = RTAB_SHORTOFF;
            else
              error(123,buf);  /* unknown reloc table format ignored */
          }
          break;

        case 'S':  /* strip debugger symbols */
          gv->strip_symbols = STRIP_DEBUG;
          break;

        case 'T':  /* read linker script file or set text address */
          if (!strcmp(&argv[i][2],"text")) {
            if (i+1 < argc)
              sscanf(argv[++i],"%lli",&gv->start_addr);
            else
              error(5,'T');  /* option requires argument */
          }
          else if (buf = get_option_arg(argc,argv,&i)) {
            if (gv->ldscript = mapfile(buf))
              gv->scriptname = buf;
            else
              error(8,buf);
          }
          break;

        case 'V':  /* set minimum version for next shared object */
          if (buf = get_option_arg(argc,argv,&i))
            so_version = atoi(buf);
          break;

        case 'X':  /* discard temporary local symbols only */
          gv->discard_local = DISLOC_TMP;
          break;

        case 'Z':  /* keep trailing zero-bytes at end of section */
          gv->keep_trailing_zeros = TRUE;
          break;

        default:
          error(2,argv[i]);  /* unrecognized option */
          break;
      }
    }

    else {  /* normal input file name */
      ifn = alloc(sizeof(struct InputFile));
      ifn->name = argv[i];
      ifn->lib = FALSE;
      ifn->flags = flags;
      addtail(&gv->inputlist,&ifn->n);
    }
  }

  /* add default library search path at the end of the list */
  if (stdlib) {
#ifdef LIBPATH
    libp = alloc(sizeof(struct LibPath));
    libp->path = LIBPATH;  /* default search path */
    addtail(&gv->libpaths,&libp->n);
#endif
  }

  /* allocate flavour path buffer and sort flavours */
  gv->flavours.flavour_dir = alloc(gv->flavours.flavours_len + 1);
  if (gv->flavours.n_flavours > 1) {
    qsort((void *)gv->flavours.flavours, gv->flavours.n_flavours,
          sizeof(char **), flavours_cmp);
  }

  /* link them... */
  linker_init(gv);
  linker_load(gv);     /* load all objects and libraries and their symbols */
  linker_resolve(gv);  /* resolve symbol references */
  linker_relrefs(gv);  /* find all relative references between sections */
  linker_dynprep(gv);  /* prepare for dynamic linking */
  linker_sectrefs(gv); /* find all referenced sections from the start */
  linker_gcsects(gv);  /* section garbage collection (gc_sects) */
  linker_join(gv);     /* join sections with same name and type */
  linker_mapfile(gv);  /* mapfile output */
  linker_copy(gv);     /* copy section contents and fix symbol offsets */
  linker_delunused(gv);/* delete empty/unused sects. without relocs/symbols */
  linker_relocate(gv); /* relocate addresses in joined sections */
  linker_write(gv);    /* write output file in selected target format */
  linker_cleanup(gv);

  cleanup(gv);
  return 0;
}
Ejemplo n.º 17
0
Archivo: w_init.c Proyecto: j13s/devil
/* Draws a standard button with text. data is the substructure of the button.
   Returns pointer to button-structure if successful, 0 otherwise. */
struct w_button *w_addstdbutton(struct w_window *w, enum but_types type,
                                int xpos, int ypos, int xsize, int ysize,
                                const char *txt, void *data,
                                int draw)
{
    struct w_button *b, *nb;
    struct w_description *d;
    int x, y, l;


    if (ysize > 0 && ysize < shapes.titlebar_height && txt != NULL) {
        return NULL;
    }

    checkmem( b = MALLOC( sizeof(struct w_button) ) );
    b->xpos = xpos;
    b->ypos = ypos;
    b->xsize = xsize;
    b->ysize = ysize;
    b->w = w;
    b->type = type;
    b->helptxt = NULL;
    initlist(&b->inscription);
    initlist(&b->a_inscription);
    b->d.d = data;

    switch (type) {
        case w_b_press:
        case w_b_drag:

            if (b->xsize < 0) {
                b->xsize = txt != NULL ? ws_pixstrlen(txt) +
                4 : shapes.closebutton_width;
            }

            if (b->ysize < 0) {
                b->ysize = shapes.titlebar_height;
            }

            break;

        case w_b_switch:
        case w_b_tag:

            if (b->xsize < 0) {
                b->xsize = txt != NULL ? ws_pixstrlen(txt) +
                6 : shapes.closebutton_width;
            }

            if (b->ysize < 0) {
                b->ysize = shapes.titlebar_height + 4;
            }

            break;

        case w_b_choose:
            b->d.ls->d_xsize = txt == NULL ? 2 : ws_pixstrlen(txt) + 4;

            if (b->xsize < 0) {
                for (x = 0; x < b->d.ls->num_options; x++) {
                    if ( b->xsize < ws_pixstrlen(b->d.ls->options[x]) ) {
                        b->xsize = ws_pixstrlen(b->d.ls->options[x]);
                    }
                }

                b->xsize += b->d.ls->d_xsize + 10;
            }

            if (b->ysize < 0) {
                b->ysize = shapes.titlebar_height + 5;
            }

            break;

        case w_b_string:
            b->d.str->d_xsize = txt == NULL ? 2 : ws_pixstrlen(txt) + 4;
            b->d.str->offset = 0;

            if (b->xsize < 0) {
                b->xsize = b->d.str->max_length * ws_pixstrlen("M") +
                b->d.str->d_xsize + 10;
            }

            if (b->ysize < 0) {
                b->ysize = shapes.titlebar_height + 5;
            }

            b->d.str->length =
                (b->xsize - b->d.str->d_xsize - 10) / ws_pixstrlen("M");
            break;

        case w_b_list:

            if (b->xsize < 0) {
                for (x = 0; x < b->d.sls->no_strings; x++) {
                    if ( b->xsize < ws_pixstrlen(b->d.sls->strings[x]) ) {
                        b->xsize = ws_pixstrlen(b->d.sls->strings[x]);
                    }
                }
            }

            if (b->ysize < 0) {
                b->ysize = (shapes.titlebar_height + 2) * 5 + 4;
            }

            break;

        default:
            return NULL;
    }

    if (txt != NULL) {
        switch (type) {
            case w_b_press:
            case w_b_drag:
            case w_b_switch:
            case w_b_tag:

                if (ws_pixstrlen(txt) + 4 <= b->xsize) {
                    x = ( b->xsize - ws_pixstrlen(txt) ) / 2 - 1;
                    l = strlen(txt);
                }
                else {
                    x = 2;
                    l = ws_charstrlen(b->xsize - 4);
                }

                y = (b->ysize - shapes.titlebar_height) / 2;
                break;

            case w_b_choose:

                if (ws_pixstrlen(txt) + 4 <= b->d.ls->d_xsize) {
                    x = ( b->d.ls->d_xsize - ws_pixstrlen(txt) ) / 2;
                    l = strlen(txt);
                }
                else {
                    x = 3;
                    l = ws_charstrlen(b->d.ls->d_xsize - 4);
                }

                y = (b->ysize - shapes.titlebar_height) / 2;
                break;

            case w_b_string:

                if (ws_pixstrlen(txt) + 4 <= b->d.str->d_xsize) {
                    x = ( b->d.str->d_xsize - ws_pixstrlen(txt) ) / 2;
                    l = strlen(txt);
                }
                else {
                    x = 3;
                    l = b->d.str->d_xsize < 4 ? 0 : ws_charstrlen(
                        b->d.str->d_xsize - 4);
                }

                y = (b->ysize - shapes.titlebar_height) / 2;
                break;

            default:
                return NULL;
        }

        if (l > 0) {
            checkmem( d = MALLOC( sizeof(struct w_description) ) );
            checkmem( d->contents.txt = MALLOC(l + 1) );
            strncpy(d->contents.txt, txt, l);
            d->contents.txt[l] = 0;
            d->type = w_bdt_txt;
            d->x = x;
            d->y = y;
            checkmem( addnode(&b->inscription, -1, d) );
            checkmem( addnode(&b->a_inscription, -1, d) );
        }
    }

    nb = w_addbutton(b, draw);
    free(b);
    return nb;
}
Ejemplo n.º 18
0
Archivo: w_init.c Proyecto: j13s/devil
/* Opens a window with the parameters from w (which is not the same pointer
   as the returned value!). The enums are defined in wins.h.
   Open window means to initialize the window structure
   and bring the window on the current screen. If this is not possible,
   the routine returns NULL. If maxxsize<xsize && maxxsize>0 then
   maxxsize=xsize. Same for maxysize. title==NULL is possible.
   If xpos<0 or ypos<0 this position will be centered. */
struct w_window *w_openwindow(struct w_window *w) {
    struct wi_window *wi;
    struct wi_button *b;
    struct w_b_press *wi_p_closebutton;
    struct w_b_drag *wi_d_sizebutton;
    int x;


    my_assert(w != NULL);
    my_assert( !(w->refresh == wr_routine && w->refresh_routine == NULL) );
    my_assert(w->xsize > 0 && w->ysize > 0 && w->xsize <= notes.winspace.xs
             && w->ysize <= notes.winspace.ys);

    if (w->xpos + w->xsize >= notes.winspace.xs) {
        w->xpos = notes.winspace.xs - w->xsize - 1;
    }

    if (w->ypos + w->ysize >= notes.winspace.ys) {
        w->ypos = notes.winspace.ys - w->ysize - 1;
    }

    checkmem( wi = MALLOC( sizeof(struct wi_window) ) );
    wi->w = *w;

    if (wi->w.xpos < 0) {
        wi->w.xpos = (notes.winspace.xs - wi->w.xsize) / 2;
    }

    if (wi->w.ypos < 0) {
        wi->w.ypos = (notes.winspace.ys - wi->w.ysize) / 2;
    }

    wi->w.xpos += notes.winspace.xp;
    wi->w.ypos += notes.winspace.yp;

    if (wi->w.maxxsize < wi->w.xsize && wi->w.maxxsize > 0) {
        wi->w.maxxsize = wi->w.xsize;
    }

    if (wi->w.maxysize < wi->w.ysize && wi->w.maxysize > 0) {
        wi->w.maxysize = wi->w.ysize;
    }

    if (w->title) {
        checkmem( wi->w.title = MALLOC(strlen(w->title) + 1) );
        strcpy( (char *)wi->w.title, w->title );
    }
    else {
        w->title = NULL;
    }

    wi->bg = wi->in = NULL;
    wi->drawn = 0;
    wi->in_refresh = 0;
    initlist(&wi->buttonlist);
    checkmem( wi->n = addheadnode(&notes.windows, -1, wi) );
    wi->w.no = wi->n->no;
    wi->oysize = wi->iysize = wi->w.ysize;
    wi->ixsize = wi->w.xsize;
    wi->ixpos = wi->w.xpos;
    wi->iypos = wi->w.ypos;

    if (wi->w.shrunk) {
        wi->w.ysize = shapes.titlebar_height;
    }

    if ( wi->w.buttons & (wb_close | wb_shrink) ) {
        checkmem( wi_p_closebutton = MALLOC( sizeof(struct w_b_press) ) );
        wi_p_closebutton->l_pressed_routine =
            wi_p_closebutton->r_pressed_routine = NULL;
        wi_p_closebutton->l_routine = wi->w.buttons &
                                      wb_close ? wi_closeroutine : NULL;
        wi_p_closebutton->r_routine = wi->w.buttons &
                                      wb_shrink ? wi_shrinkroutine : NULL;
        checkmem( b = (struct wi_button *)w_addstdbutton(&wi->w, w_b_press,
                                                         w_xscreencoord(&wi->
                                                                        w,
                                                                        wi->w
                                                                        .xpos), w_yscreencoord(&wi->w, wi->w.ypos),
                                                         shapes.
                                                         closebutton_width,
                                                         shapes.
                                                         titlebar_height, NULL, wi_p_closebutton, 0) )
        b->sys_button = 1;
        b->drawn = 1;          /* otherwise it is not drawn */
        b->b.data = (void *)0;
        x = b->b.xsize;
    }
    else {
        x = 0;
    }

    if ( wi->w.buttons & (wb_drag | wb_size) ) {
        checkmem( wi_d_sizebutton = MALLOC( sizeof(struct w_b_drag) ) );
        wi_d_sizebutton->l_pressroutine = wi->w.buttons &
                                          wb_drag ? wi_drag_press : NULL;
        wi_d_sizebutton->l_dragroutine = wi->w.buttons &
                                         wb_drag ? wi_drag_drag : NULL;
        wi_d_sizebutton->l_relroutine = wi->w.buttons &
                                        wb_drag ? wi_drag_rel : NULL;
        wi_d_sizebutton->r_pressroutine = wi->w.buttons &
                                          wb_size ? wi_resize_press : NULL;
        wi_d_sizebutton->r_dragroutine = wi->w.buttons &
                                         wb_size ? wi_resize_size : NULL;
        wi_d_sizebutton->r_relroutine = wi->w.buttons &
                                        wb_size ? wi_resize_rel : NULL;
        checkmem( b = (struct wi_button *)w_addstdbutton(&wi->w, w_b_drag,
                                                         w_xscreencoord(&wi->
                                                                        w,
                                                                        wi->w
                                                                        .xpos) + x, w_yscreencoord(&wi->w, wi->w.ypos),
                                                         wi->w.xsize - x,
                                                         shapes.
                                                         titlebar_height,
                                                         wi->w.title, wi_d_sizebutton, 0) )
        b->sys_button = 1;
        b->drawn = 1;          /* otherwise it is not drawn */
        b->b.data = (void *)1;
    }

    wi_drawwin(wi);
    return &wi->w;
}
Ejemplo n.º 19
0
void init(chess *q) {
	int fdr, i = 0, j = 0, k;
	coin a;
	//pawn, knight, bishop, rook, queen, king
	const int pevals[12][8][8] = {{{0,   0,   0,   0,   0,   0,   0,   0},
		{20,  20,  20,  20,  20,  20,  20,  20},
		{0,   0,   0,   0,   0,   0,   0,   0},
		{0,   0,   0,   40,  40,  0,   0,   0},
		{0,   0,   0,   40,  40,  0,   0,   0},
		{0,   0,   10,  30,  30, -10,  0,  -10},
		{20,  20,  20,  10,  10,  20,  20,  20},
		{0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,  10,  10,   0,   0,   0},
		      {0,   0,  10,  40,  40,  10,   0,   0},
		      {0,   0,  10,  40,  40,  10,   0,   0},
		      {0,   0,  20,   0,   0,  20,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,  40,   0,   0,   0,   0,   0},
		      {0,   0,   0,  40,  40,   0,   0,   0},
		      {0,  20,   0,   0,   0,   0,  20,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {20,  20,  20,  20,  20,  20,  20,  20}, 
		      {0,   0,   0,   0,   0,   0,   0,   0}, 
		      {0,   0,   0,   0,   0,   0,   0,   0}, 
		      {0,   0,   0,   0,   0,   0,   0,   0}, 
		      {0,   0,   0,   0,   0,   0,   0,   0}, 
		      {10,  10,  10,  10,  10,  10,  10,  10},
		      {20,  20,  20,  20,  20,  20,  20,  20}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,  20,  30,  30,   0,   0,   0},
		      {0,   0,   0,  50,  30,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}, 
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,  20,  50,  30,  50,   0, 100,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {20,  20,  20,  20,  20,  20,  20,  20},
		      {0,   0,  10,  30,  30, -10,   0, -10},
		      {0,   0,   0,  40,  40,   0,   0,   0},
		      {0,   0,   0,  40,  40,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {20,  20,  20,  10,  10,  20,  20,  20},
		      {0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,  20,  10,  10,  20,   0,   0},
		      {0,   0,  10,  40,  40,  10,   0,   0},
		      {0,   0,  10,  40,  40,  10,   0,   0},
		      {0,   0,   0,  10,  10,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {0,  20,   0,   0,   0,   0,  20,   0},
		      {0,   0,   0,  40,  40,   0,   0,   0},
		      {0,   0,  40,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,   0,   0,   0,   0,   0,   0,   0},
		      {20,  20,  20,  20,  20,  20,  20,  20},
		      {10,  10,  10,  10,  10,  10,  10,  10},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {20,  20,  20,  20,  20,  20,  20,  20}},
	      {{0,   0,   0,  50,  50,   0,   0,   0},
		      {0,   0,  20,  30,  30,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}},
	      {{0,  20,  50,  30,  50,   0, 100,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0},
		      {0,   0,   0,   0,   0,   0,   0,   0}}};
	for(i = 0; i < 8; i++) {
		q->p[i] = (coin *) malloc (sizeof(coin) * 8);
	}
	fdr = open("coins.txt", O_RDONLY, S_IRWXU);
	if(fdr == -1) {
		printf("Open failed\n");
		exit(1);
	}
	for(i = 0; i < 8; i++) {
		for(j = 0; j < 8; j++) {
			read(fdr, &a.name[0], 1);
			read(fdr, &a.name[1], 1);
			read(fdr, &a.color, sizeof(int));
			read(fdr, &a.status, sizeof(int));
			q->p[i][j] = a;
		}
	}
	q->enable = DISABLE;
	close(fdr);
	q->state = WHITE;
	//printstate(stdscr, q);
	//getch();
	initlist(q);
	initstack(&q->s);
	initstack(&q->r);
	for(i = 0; i < 12; i++) {
		for(j = 0; j < 8; j++) {
			for(k = 0; k < 8; k++) {
				q->pieceeval[i][j][k] = pevals[i][j][k];
			}
		}
	}
}
Ejemplo n.º 20
0
int main(int argc, char* argv[])
{
    int sockfd, clientfd,status,yes=1,fdmax,p,fd,j;
    unsigned int port;
    struct addrinfo hints;
    struct addrinfo *servinfo;
    struct sockaddr_in* clientinfo;  // will point to the results
    fd_set master,read_fd;
    
    memset(&hints, 0, sizeof hints); // make sure the struct is empty
    FD_ZERO(&master);
    FD_ZERO(&read_fd);
    
    if (argc != 4) {
    printf("usage: ./server ip port clientcount\n");
    return 1;
    }
    
    port =atoi(argv[2]);
    printf("IP Entered,%s\n",argv[1]);                                
    servinfo= (struct addrinfo*)calloc(1,sizeof(struct addrinfo));
    InitAddress (argv[1], port, servinfo);
    
    MAX_COUNT = atoi(argv[3]);                               //Max number of clients
    
    // create userlist
    userlist = initlist();
     
    // make a socket:
    if ((sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,servinfo->ai_protocol)) == -1) {
        perror("server: socket");
	exit(0);
    }
    // local addresses are reused
    if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes,sizeof(int)) == -1) {
        perror("setsockopt");
        exit(1);
    }
    // binding to a port
    if (bind(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
        close(sockfd);
        perror("server: bind");
    }
    //listen
    if(listen(sockfd,MAX_COUNT)==-1){          
      close(sockfd);
      perror("server:listen");
    }

    FD_SET(sockfd,&master);
    fdmax = sockfd;
   
    while(1){   
      
      read_fd = master;
      if( select(fdmax+1,&read_fd,NULL,NULL,NULL) == -1){
	  perror("server:select");
	  exit(0);
      }
      for(p=0;p<=fdmax;p++)
      {
	
	if(FD_ISSET(p,&read_fd)){
	  if(p==sockfd){ // New connection
	      int clientfd = handle_new_cnt(p,master,&fdmax);  
	      if(clientfd)
	         FD_SET(clientfd,&master);
	   } else {// received some msg from old connection
	      if(!handle_old_cnt(p,master,fdmax,sockfd))
	      {
		char usrname[17];
		if(searchlist(p,userlist,usrname)) userlist=deletelist(p,userlist);;      //closing the user incase he has quit
		printf("\nNumber of valid users\t:%d\n",list_size(userlist));
		close(p);
		FD_CLR(p,&master);
	      }
	       
	  }
	 } //data handling done
	}//data for particular p over
      }// infinite loop 
    
    
    close(sockfd);
    //printsockaddr((struct sockaddr_in*)servinfo->ai_addr);
    freeaddrinfo(servinfo); // free the linked-list

}
Ejemplo n.º 21
0
int main() {

	//getlist();

	initlist();
	//writeblock(3, 3, 3, "abc");
	//getlist();
	//char*ip = "192.168.1.107";
	char*ip = "59.78.15.46";
	strcpy(dname,"haha");

	send_list(ip);
	//

	bzero(&list_head, sizeof(struct list_entry));
	pthread_t pid;

	int socket_descriptor;
	if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		perror("socket create error");
		exit(1);
	}
	int on;
	on = 1;
	setsockopt(socket_descriptor, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
	int port = 9010;
	struct sockaddr_in sin;
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = INADDR_ANY;
	sin.sin_port = htons(port);
	bzero(&(sin.sin_zero), 8);
	if (bind(socket_descriptor, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
		perror("bind error");
		exit(1);
	}

	if (listen(socket_descriptor, 10) == -1) {
		perror("listen error");
		exit(1);
	}

	struct sockaddr_in pin;
	struct list_entry* ent;

	int temp_socket_descriptor;

	printf("DISK DRIVER START...\n");
	//if (fork() != 0) {
	//send_copy(ip,1234);
	//} else {
	while (1) {
		unsigned int sin_size = sizeof(struct sockaddr_in);
		temp_socket_descriptor = accept(socket_descriptor,
				(struct sockaddr *) &pin, &sin_size);

		if (temp_socket_descriptor == -1) {
			perror("Accept Failed");
			continue;
		}
		//printf("Accept Success\n");
		if ((ent = (struct list_entry*) malloc(sizeof(struct list_entry)))
				== NULL) {
			perror("Malloc Failed");
			close(temp_socket_descriptor);
			continue;
		}
		bzero(ent, sizeof(struct list_entry));
		ent->skt = temp_socket_descriptor;
		if (pthread_create(&pid, NULL, serve, ent)) {
			perror("Create Thread Failed");
			close(temp_socket_descriptor);
			free(ent);
			continue;
		}
		pthread_detach(pid);
		//close(temp_socket_descriptor);
	}
	//}
	return 0;
}
Ejemplo n.º 22
0
Archivo: w_init.c Proyecto: j13s/devil
/* recursive function for reading menu-data. See w_initmenu for details.
   xoffset and yoffset are the starting point of the current menue. */
int wi_readmenu(FILE *mfile, int no, void(**action) (
                    int), int max_anr, int xoffset, int yoffset, int mainline,
                struct list *l,
                int level)
{
    int i, lastpos = 0;
    char buffer[1024], helptxt[1024], *pos;
    struct wi_menu *m;
    struct node *n;


    for (i = 0; i < no; i++) {
        checkmem( m = MALLOC( sizeof(struct wi_menu) ) );

        if (fscanf(mfile, " %i%*[^{]%1023[^}]%*[^{]%1023[^}]%*[^\n]",
                   &m->actionnr,
                   buffer, helptxt) != 3) {
            fprintf(errf, "Can't read menu-data %d/%d/%d.\n", i, no, level);
            return 0;
        }

        if ( ( pos = strchr(buffer, '>') ) == NULL ) {
            fprintf(errf, "Can't find hotkey in %s.\n", buffer);
            return 0;
        }

        checkmem( m->txt =
                     MALLOC( strlen(buffer) + (!mainline && m->actionnr < 0 ?
                                               1 : -1) ) );
        checkmem( m->help = MALLOC( strlen(helptxt) ) );
        *pos = 0;
        strcpy(m->txt, buffer + 1);
        strcat(m->txt, pos + 1);
        strcpy(m->help, helptxt + 1);
        m->hotkey = level == 0 ? toupper( *(pos + 1) ) : *(pos + 1);
        m->hklinex = ws_pixstrlen(buffer + 1);
        *(pos + 2) = 0;
        m->hklinexs = ws_pixstrlen(pos + 1) - 1;
        m->hkliney = shapes.titlebar_height - 3;
        initlist(&m->submenus);
        m->bm = NULL;
        checkmem( addnode(l, -1, m) );
        m->level = level;

        if (mainline) {
            m->x1 = xoffset + lastpos;
            m->y1 = yoffset;
            m->xs = ws_pixstrlen(m->txt) + shapes.titlebar_height / 2;
            m->ys = shapes.titlebar_height;
            lastpos += m->xs;
        }
        else {
            if (m->actionnr < 0) {
                strcat(m->txt, " >");
            }

            m->ys = shapes.titlebar_height;
            m->x1 = xoffset;
            m->y1 = yoffset + i * m->ys + 2 * shapes.width_menuframe;

            if (m->y1 + m->ys > notes.yres) {
                fprintf(errf, "Submenu too large: txt=%s\n", m->txt);
                return 0;
            }

            if (ws_pixstrlen(m->txt) + shapes.titlebar_height / 2 >
                lastpos) {
                lastpos = ws_pixstrlen(m->txt) + shapes.titlebar_height / 2;
            }
        }

        if (m->actionnr >= 0) {
            if (m->actionnr > max_anr) {
                fprintf(errf, "Action number too large: %d > %d\n",
                        m->actionnr,
                        max_anr);
                return 0;
            }

            m->action = action[m->actionnr];
        }
        else {
            if ( !wi_readmenu(mfile, -m->actionnr, action, max_anr,
                              mainline ? m->x1 :
                              m->x1 + ws_pixstrlen(m->txt) + 1,
                              mainline ? m->y1 + shapes.titlebar_height +
                              shapes.width_menuframe + 1 : m->y1, 0,
                              &m->submenus, level + 1) ) {
                fprintf(errf, "Can't read submenu for %d\n", i);
                return 0;
            }

            m->action = NULL;
            m->actionnr = -1;
        }
    }

    if (!mainline) {
        for (n = l->head; n->next != NULL; n = n->next) {
            n->d.w_m->xs = lastpos + 2;
        }
    }

    return 1;
}