コード例 #1
0
struct machine_desc * __init setup_machine_tags(phys_addr_t __atags_pointer,
						unsigned int machine_nr)
{
	struct tag *tags = (struct tag *)&default_tags;
	struct machine_desc *mdesc = NULL, *p;
	char *from = default_command_line;

	default_tags.mem.start = PHYS_OFFSET;

	/*
	 * locate machine in the list of supported machines.
	 */
	for_each_machine_desc(p)
		if (machine_nr == p->nr) {
			printk("Machine: %s\n", p->name);
			mdesc = p;
			break;
		}

	if (!mdesc) {
		early_print("\nError: unrecognized/unsupported machine ID"
			    " (r1 = 0x%08x).\n\n", machine_nr);
		dump_machine_table(); /* does not return */
	}

	if (__atags_pointer)
		tags = phys_to_virt(__atags_pointer);
	else if (mdesc->atag_offset)
		tags = (void *)(PAGE_OFFSET + mdesc->atag_offset);

#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
	/*
	 * If we have the old style parameters, convert them to
	 * a tag list.
	 */
	if (tags->hdr.tag != ATAG_CORE)
		convert_to_tag_list(tags);
#endif
	if (tags->hdr.tag != ATAG_CORE) {
		early_print("Warning: Neither atags nor dtb found\n");
		tags = (struct tag *)&default_tags;
	}

	if (mdesc->fixup)
		mdesc->fixup(tags, &from, &meminfo);

	if (tags->hdr.tag == ATAG_CORE) {
		if (meminfo.nr_banks != 0)
			squash_mem_tags(tags);
		save_atags(tags);
		parse_tags(tags);
	}

	/* parse_early_param needs a boot_command_line */
	strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);

	return mdesc;
}
コード例 #2
0
ファイル: setup.c プロジェクト: 3sOx/asuswrt-merlin
void __init setup_arch(char **cmdline_p)
{
	struct tag *tags = (struct tag *)&init_tags;
	char *from = default_command_line;

	setup_processor();
	if(machine_arch_type == MACH_TYPE_A5K)
		machine_name = "A5000";
	else if(machine_arch_type == MACH_TYPE_ARCHIMEDES)
		machine_name = "Archimedes";
	else
		machine_name = "UNKNOWN";

	//FIXME - the tag struct is always copied here but this is a block
	// of RAM that is accidentally reserved along with video RAM. perhaps
	// it would be a good idea to explicitly reserve this?

	tags = (struct tag *)0x0207c000;

	/*
	 * If we have the old style parameters, convert them to
	 * a tag list.
	 */
	if (tags->hdr.tag != ATAG_CORE)
		convert_to_tag_list(tags);
	if (tags->hdr.tag != ATAG_CORE)
		tags = (struct tag *)&init_tags;
	if (tags->hdr.tag == ATAG_CORE) {
		if (meminfo.nr_banks != 0)
			squash_mem_tags(tags);
		parse_tags(tags);
	}

	init_mm.start_code = (unsigned long) &_text;
#ifndef CONFIG_XIP_KERNEL
	init_mm.end_code   = (unsigned long) &_etext;
#else
	init_mm.end_code   = (unsigned long) &_endtext;
	init_mm.start_data   = (unsigned long) &_sdata;
#endif
	init_mm.end_data   = (unsigned long) &_edata;
	init_mm.brk	   = (unsigned long) &_end;

	memcpy(boot_command_line, from, COMMAND_LINE_SIZE);
	boot_command_line[COMMAND_LINE_SIZE-1] = '\0';
	parse_cmdline(&meminfo, cmdline_p, from);
	bootmem_init(&meminfo);
	paging_init(&meminfo);
	request_standard_resources(&meminfo);

#ifdef CONFIG_VT
#if defined(CONFIG_DUMMY_CONSOLE)
	conswitchp = &dummy_con;
#endif
#endif
}
コード例 #3
0
ファイル: maps-osm.c プロジェクト: GNOME/gnome-maps
static MapsOSMNode *
parse_node (const xmlNodePtr node, GError **error)
{
  const char *id_string;
  guint64 id;
  const char *changeset_string;
  guint64 changeset;
  const char *version_string;
  guint version;
  const char *lat_string;
  double lat;
  const char *lon_string;
  double lon;
  
  GHashTable *tags;
  GHashTable *attributes;

  MapsOSMNode *result;

  attributes = parse_attributes (node);

  id_string = g_hash_table_lookup (attributes, "id");
  changeset_string = g_hash_table_lookup (attributes, "changeset");
  version_string = g_hash_table_lookup (attributes, "version");
  lat_string = g_hash_table_lookup (attributes, "lat");
  lon_string = g_hash_table_lookup (attributes, "lon");

  if (!id_string || !changeset_string || !version_string
      || !lat_string || !lon_string)
    {
      *error = g_error_new_literal (MAPS_OSM_ERROR, 0,
                                    _("Missing required attributes"));
      g_hash_table_destroy (attributes);
      return NULL;
    }

  id = g_ascii_strtoull (id_string, NULL, 10);
  changeset = g_ascii_strtoull (changeset_string, NULL, 10);
  version = g_ascii_strtoull (version_string, NULL, 10);
  lon = g_ascii_strtod (lon_string, NULL);
  lat = g_ascii_strtod (lat_string, NULL);

  g_hash_table_destroy (attributes);

  result = maps_osm_node_new (id, version, changeset, lon, lat);

  tags = parse_tags (node->children);
  fill_tags (MAPS_OSMOBJECT (result), tags);

  g_hash_table_destroy (tags);

  return result;
}
コード例 #4
0
ファイル: html.c プロジェクト: JamesTFarrington/roswell
LVal atag_list(char* filename) {
  FILE* fp;
  LVal ret=(LVal)NULL;
  cond_printf(1,"open %s\n",filename);
  fp=fopen(filename,"r");
  if(fp!=NULL) {
    LVal tags=parse_tags(fp,(LVal)NULL,0);
    tags=delete_not_tags("a",delete_not_open_tags(tags));
    ret=nreverse(filter_href(tags));
    tagsfree(tags);
    fclose (fp);
  }
  return ret;
}
コード例 #5
0
ファイル: maps-osm.c プロジェクト: GNOME/gnome-maps
static MapsOSMRelation *
parse_relation (const xmlNodePtr relation, GError **error)
{
  GHashTable *attributes;
  GHashTable *tags;
  GList *member_list;

  const char *id_string;
  guint64 id;
  const char *changeset_string;
  guint64 changeset;
  const char *version_string;
  guint version;
  
  MapsOSMRelation *result;

  attributes = parse_attributes (relation);
  id_string = g_hash_table_lookup (attributes, "id");
  changeset_string = g_hash_table_lookup (attributes, "changeset");
  version_string = g_hash_table_lookup (attributes, "version");

  if (!id_string || !changeset_string || !version_string)
    {
      *error = g_error_new_literal (MAPS_OSM_ERROR, 0,
                                    _("Missing required attributes"));
      g_hash_table_destroy (attributes);
      return NULL;
    }

  g_hash_table_destroy (attributes);

  id = g_ascii_strtoull (id_string, NULL, 10);
  changeset = g_ascii_strtoull (changeset_string, NULL, 10);
  version = g_ascii_strtoull (version_string, NULL, 10);

  result = maps_osm_relation_new (id, version, changeset);

  tags = parse_tags (relation->children);
  fill_tags (MAPS_OSMOBJECT (result), tags);
  g_hash_table_destroy (tags);

  member_list = parse_members (relation->children);
  fill_members (result, member_list);
  g_list_free_full (member_list, (GDestroyNotify) g_hash_table_destroy);

  return result;
}
コード例 #6
0
ファイル: maps-osm.c プロジェクト: GNOME/gnome-maps
static MapsOSMWay *
parse_way (const xmlNodePtr way, GError **error)
{
  GHashTable *attributes;
  GHashTable *tags;
  GArray *node_refs;
  MapsOSMWay *result;

  const char *id_string;
  guint64 id;
  const char *changeset_string;
  guint64 changeset;
  const char *version_string;
  guint version;

  attributes = parse_attributes (way);

  id_string = g_hash_table_lookup (attributes, "id");
  changeset_string = g_hash_table_lookup (attributes, "changeset");
  version_string = g_hash_table_lookup (attributes, "version");

  if (!id_string || !changeset_string || !version_string)
    {
      g_warning ("Missing required attributes\n");
      g_hash_table_destroy (attributes);
      return NULL;
    }

  g_hash_table_destroy (attributes);

  id = g_ascii_strtoull (id_string, NULL, 10);
  changeset = g_ascii_strtoull (changeset_string, NULL, 10);
  version = g_ascii_strtoull (version_string, NULL, 10);

  result = maps_osm_way_new (id, version, changeset);

  tags = parse_tags (way->children);
  fill_tags (MAPS_OSMOBJECT (result), tags);
  g_hash_table_destroy (tags);

  node_refs = parse_node_refs (way->children);
  fill_node_ref_list (result, node_refs);
  g_array_free (node_refs, TRUE);

  return result;
}
コード例 #7
0
ファイル: npc.cpp プロジェクト: donhayes/Cataclysm
void npc::say(game *g, std::string line, ...)
{
 va_list ap;
 va_start(ap, line);
 char buff[8192];
 vsprintf(buff, line.c_str(), ap);
 va_end(ap);
 line = buff;
 int junk;
 parse_tags(line, &(g->u), this);
 if (g->u_see(posx, posy, junk)) {
  g->add_msg("%s says, \"%s\"", name.c_str(), line.c_str());
  g->sound(posx, posy, 16, "");
 } else {
  std::string sound = name + " saying, \"" + line + "\"";
  g->sound(posx, posy, 16, sound);
 }
}
コード例 #8
0
ファイル: fill-tags.c プロジェクト: Genomicsplc/bcftools
int init(int argc, char **argv, bcf_hdr_t *in, bcf_hdr_t *out)
{
    memset(&args,0,sizeof(args_t));
    args.in_hdr  = in;
    args.out_hdr = out;

    static struct option loptions[] =
    {
        {"tags",1,0,'t'},
        {0,0,0,0}
    };
    int c;
    while ((c = getopt_long(argc, argv, "?ht:T:l:cd",loptions,NULL)) >= 0)
    {
        switch (c) 
        {
            case 't': args.tags |= parse_tags(&args,optarg); break;
            case 'h':
            case '?':
            default: error("%s", usage()); break;
        }
    }
    if ( optind != argc ) error(usage());
    if ( !args.tags ) args.tags |= SET_AN|SET_AC|SET_NS|SET_AC_Hom|SET_AC_Het|SET_AC_Hemi|SET_AF;
    
    args.gt_id = bcf_hdr_id2int(args.in_hdr,BCF_DT_ID,"GT");
    if ( args.gt_id<0 ) error("Error: GT field is not present\n");

    if ( args.tags&SET_AN ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=AN,Number=1,Type=Integer,Description=\"Total number of alleles in called genotypes\">");
    if ( args.tags&SET_AC ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=AC,Number=A,Type=Integer,Description=\"Allele count in genotypes\">");
    if ( args.tags&SET_NS ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=NS,Number=1,Type=Integer,Description=\"Number of samples with data\">");
    if ( args.tags&SET_AC_Hom ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=AC_Hom,Number=A,Type=Integer,Description=\"Allele counts in homozygous genotypes\">");
    if ( args.tags&SET_AC_Het ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=AC_Het,Number=A,Type=Integer,Description=\"Allele counts in heterozygous genotypes\">");
    if ( args.tags&SET_AC_Hemi ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=AC_Hemi,Number=A,Type=Integer,Description=\"Allele counts in hemizygous genotypes\">");
    if ( args.tags&SET_AF ) bcf_hdr_append(args.out_hdr, "##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele frequency\">");

    return 0;
}
コード例 #9
0
static void add_video_preset_configuration(MSVideoPreset *preset, const char *tags, MSVideoConfiguration *config) {
	MSVideoPresetConfiguration *vpc = ms_new0(MSVideoPresetConfiguration, 1);
	vpc->tags = parse_tags(tags);
	vpc->config = config;
	preset->configs = ms_list_append(preset->configs, vpc);
}
コード例 #10
0
ファイル: html.c プロジェクト: JamesTFarrington/roswell
LVal parse_tags(FILE* fp,LVal before,int mode) {
  LVal current=tagalloc();
  char str[2]={'\0','\0'};
  int c,i=0;
  char* buf=q("");
  switch(mode) {
  case 0: /* wait for '<' */
    ((struct tag*)firstp(current))->type=0;
    while((c=fgetc(fp))!=EOF) {
      if(c=='<') {
        if(strlen(buf)==0) {
          tagfree(current);
          s(buf);
          return parse_tags(fp,before,1);
        }else {
          ((struct Cons*)current)->next=parse_tags(fp,current,1);
          s(buf);
          return current;
        }
      }else
        str[0]=c,buf=s_cat2(buf,q(str));
    }
    break;
  case 1: /* wait for '>' */
    ((struct tag*)firstp(current))->type=0;
    while((c=fgetc(fp))!=EOF) {
      if(i==0) {
        if(c=='/')
          ((struct tag*)firstp(current))->type=2;
        else {
          ((struct tag*)firstp(current))->type=1;
          str[0]=c;
          buf=s_cat2(buf,q(str));
        }
        ++i;
        continue;
      }
      if(c=='>') {
        char *buf2;
        if(((struct tag*)firstp(current))->type==2) {
          int pos=position_char(" \t\r\n",buf);
          if(pos!=-1) {
            buf2=subseq(buf,0,pos);
            s(buf);
            buf=buf2;
            ((struct tag*)firstp(current))->name=q(buf);
          }else {
            ((struct tag*)firstp(current))->name=buf;
            buf=q("");
          }
        }else if(((struct tag*)firstp(current))->type==1) {
          int pos=position_char(" \t\r\n",buf);
          if(pos!=-1) {
            ((struct tag*)firstp(current))->name=subseq(buf,0,pos);
            buf2=subseq(buf,pos,0);
            ((struct tag*)firstp(current))->attr=(struct Cons*)parse_attr(buf2);
            s(buf);
            buf=buf2;
          }else {
            ((struct tag*)firstp(current))->name=buf;
            buf=q("");
          }
        }
        if(strcmp(((struct tag*)firstp(current))->name,"script")==0) {
          ((struct Cons*)current)->next=parse_tags(fp,current,2);
        }else{
          ((struct Cons*)current)->next=parse_tags(fp,current,0);
        }
        s(buf);
        return current;
      }else {
        str[0]=c;
        buf=s_cat2(buf,q(str));
      }
      ++i;
    }
    break;
  case 2: /* wait for '</' */
    ((struct tag*)firstp(current))->type=0;
    while((c=fgetc(fp))!=EOF) {
      if(c=='<') {
        if((c=fgetc(fp))!=EOF && c=='/') {
          ungetc('/',fp);
          if(strlen(buf)==0) {
            tagfree(current);
            s(buf);
            return parse_tags(fp,current,1);
          }else {
            ((struct Cons*)current)->next=parse_tags(fp,current,1);
            s(buf);
            return current;
          }
        }
        ungetc('/',fp);
      }else {
        str[0]=c;
        buf=s_cat2(buf,q(str));
      }
    }
    break;
  }
  s(buf);
  return current;
}
コード例 #11
0
ファイル: sass.c プロジェクト: ikazuhiro/sufary
static int
parse_options(int argc, char **argv)
{
    int digit_args_val = 0;

    while (1) {
        int ch = getopt_long(argc, argv, short_options, long_options, NULL);
        if (ch == EOF) {
            break;
	}
	switch (ch) {
	case 'h':
	    show_usage();
	    exit(EXIT_FAILURE);
	    break;
	case 'i':
	    ignore_case_mode = 1;
	    break;
	case 'r':
	    regex_mode = 1;
	    break;
	case 's':
	    stdin_mode = 1;
	    break;
	case 'A':
	    if (ck_atoi(optarg, &after_context)) {
		fprintf(stderr, "invalid context length argument\n");
		exit(EXIT_FAILURE);
	    }
	    break;
	case 'B':
	    if (ck_atoi(optarg, &before_context)) {
		fprintf(stderr, "invalid context length argument\n");
		exit(EXIT_FAILURE);
	    }
	    break;
	case 'C':
	    if (optarg) {
		if (ck_atoi(optarg, &before_context)) {
		    fprintf(stderr, "invalid context length argument\n");
		    exit(EXIT_FAILURE);
		}
		after_context  = before_context;
	    } else {
		before_context = 2;
		after_context  = 2;
	    }

	    break;
	case 'd':
	    sa_set_debug_mode(1);
	    break;
	case 't':
	    tag_mode = 1;
	    parse_tags(optarg);
	    break;
	case 'a':
	    array_file_mode = 1;
	    strcpy(array_file_name, optarg);
	    break;
	case 'k':
	    keyword_emphasis_mode = 1;
	    break;
	case 'u':
	    uniq_mode = sort_mode = 1;
	    break;
	case 'S':
	    sort_mode = 1;
	    break;
	case 'c':
	    count_only_mode = 1;
	    break;
	case 'v':
            printf("sass of SUFARY %s\n", VERSION);
	    printf("Copyright (C) 1997-1999 YAMASHITA Tatuo All rights reserved.\n");
            exit(EXIT_FAILURE);
	    break;
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	    digit_args_val = 10 * digit_args_val + ch - '0';
	    before_context = digit_args_val;
	    after_context  = digit_args_val;
	    break;
	default:
	    show_mini_usage();
	    exit(EXIT_FAILURE);
	}
    }
    return optind;
}
コード例 #12
0
ファイル: npctalk.cpp プロジェクト: Uvadzucumi/Cataclysm
talk_topic dialogue::opt(talk_topic topic, game *g)
{
    std::string challenge = dynamic_line(topic, g, beta);
    std::vector<talk_response> responses = gen_responses(topic, g, beta);
// Put quotes around challenge (unless it's an action)
    if (challenge[0] != '*' && challenge[0] != '&') {
        std::stringstream tmp;
        tmp << "\"" << challenge << "\"";
    }
// Parse any tags in challenge
    parse_tags(challenge, alpha, beta);
    if (challenge[0] >= 'a' && challenge[0] <= 'z')
        challenge[0] += 'A' - 'a';
// Prepend "My Name: "
    if (challenge[0] == '&') // No name prepended!
        challenge = challenge.substr(1);
    else if (challenge[0] == '*')
        challenge = beta->name + " " + challenge.substr(1);
    else
        challenge = beta->name + ": " + challenge;
    history.push_back(""); // Empty line between lines of dialogue

// Number of lines to highlight
    int hilight_lines = 1;
    size_t split;
    while (challenge.length() > 40) {
        hilight_lines++;
        split = challenge.find_last_of(' ', 40);
        history.push_back(challenge.substr(0, split));
        challenge = challenge.substr(split);
    }
    history.push_back(challenge);

    std::vector<std::string> options;
    std::vector<nc_color>    colors;
    for (int i = 0; i < responses.size(); i++) {
        std::stringstream text;
        text << i + 1 << ": ";
        if (responses[i].trial != TALK_TRIAL_NONE)
            text << "[" << talk_trial_text[responses[i].trial] << " " <<
                 trial_chance(responses[i], alpha, beta) << "%] ";
        text << responses[i].text;
        options.push_back(text.str());
        parse_tags(options.back(), alpha, beta);
        if (responses[i].text[0] == '!')
            colors.push_back(c_red);
        else if (responses[i].text[0] == '*')
            colors.push_back(c_ltred);
        else if (responses[i].text[0] == '&')
            colors.push_back(c_green);
        else
            colors.push_back(c_white);
    }

    for (int i = 2; i < 24; i++) {
        for (int j = 1; j < 79; j++) {
            if (j != 41)
                mvwputch(win, i, j, c_black, ' ');
        }
    }

    int curline = 23, curhist = 1;
    nc_color col;
    while (curhist <= history.size() && curline > 0) {
        if (curhist <= hilight_lines)
            col = c_red;
        else
            col = c_dkgray;
        mvwprintz(win, curline, 1, col, history[history.size() - curhist].c_str());
        curline--;
        curhist++;
    }

    curline = 3;
    for (int i = 0; i < options.size(); i++) {
        while (options[i].size() > 36) {
            split = options[i].find_last_of(' ', 36);
            mvwprintz(win, curline, 42, colors[i], options[i].substr(0, split).c_str());
            options[i] = "  " + options[i].substr(split);
            curline++;
        }
        mvwprintz(win, curline, 42, colors[i], options[i].c_str());
        curline++;
    }
    mvwprintz(win, curline + 2, 42, c_magenta, _("L: Look at"));
    mvwprintz(win, curline + 3, 42, c_magenta, _("S: Size up stats"));

    wrefresh(win);

    int ch;
    bool okay;
    do {
        do {
            ch = getch();
            if (special_talk(ch) == TALK_NONE)
                ch -= '1';
        } while (special_talk(ch) == TALK_NONE && (ch < 0 || ch >= options.size()));
        okay = false;
        if (special_talk(ch) != TALK_NONE)
            okay = true;
        else if (colors[ch] == c_white || colors[ch] == c_green)
            okay = true;
        else if (colors[ch] == c_red && query_yn(_("You may be attacked! Proceed?")))
            okay = true;
        else if (colors[ch] == c_ltred && query_yn(_("You'll be helpless! Proceed?")))
            okay = true;
    } while (!okay);
    history.push_back("");

    if (special_talk(ch) != TALK_NONE)
        return special_talk(ch);

    std::string response_printed = _("You: ") + responses[ch].text;
    while (response_printed.length() > 40) {
        hilight_lines++;
        split = response_printed.find_last_of(' ', 40);
        history.push_back(response_printed.substr(0, split));
        response_printed = response_printed.substr(split);
    }
    history.push_back(response_printed);

    talk_response chosen = responses[ch];
    if (chosen.mission_index != -1)
        beta->chatbin.mission_selected = chosen.mission_index;
    talk_function effect;
    if (chosen.trial == TALK_TRIAL_NONE ||
            rng(0, 99) < trial_chance(chosen, alpha, beta)) {
        if (chosen.trial != TALK_TRIAL_NONE)
            alpha->practice(sk_speech, (100 - trial_chance(chosen, alpha, beta)) / 10);
        (effect.*chosen.effect_success)(g, beta);
        beta->op_of_u += chosen.opinion_success;
        if (beta->turned_hostile()) {
            beta->make_angry();
            done = true;
        }
        return chosen.success;
    } else {
        alpha->practice(sk_speech, (100 - trial_chance(chosen, alpha, beta)) / 7);
        (effect.*chosen.effect_failure)(g, beta);
        beta->op_of_u += chosen.opinion_failure;
        if (beta->turned_hostile()) {
            beta->make_angry();
            done = true;
        }
        return chosen.failure;
    }
    return TALK_NONE; // Shouldn't ever happen
}
コード例 #13
0
void __init setup_arch(char **cmdline_p)
{
	struct tag *tags = (struct tag *)&init_tags;
	struct machine_desc *mdesc;
	char *from = default_command_line;

	ROOT_DEV = MKDEV(0, 255);

	setup_processor();
	mdesc = setup_machine(machine_arch_type);
	machine_name = mdesc->name;

	if (mdesc->soft_reboot)
		reboot_setup("s");

	if (mdesc->param_offset)
		tags = phys_to_virt(mdesc->param_offset);

	/*
	 * Do the machine-specific fixups before we parse the
	 * parameters or tags.
	 */
	if (mdesc->fixup)
		mdesc->fixup(mdesc, (struct param_struct *)tags,
			     &from, &meminfo);

	/*
	 * If we have the old style parameters, convert them to
	 * a tag list.
	 */
	if (tags->hdr.tag != ATAG_CORE)
		convert_to_tag_list(tags);

	if (tags->hdr.tag == ATAG_CORE) {
		if (meminfo.nr_banks != 0)
			squash_mem_tags(tags);
		parse_tags(tags);
	}

	if (meminfo.nr_banks == 0) {
		meminfo.nr_banks      = 1;
		meminfo.bank[0].start = PHYS_OFFSET;
		meminfo.bank[0].size  = MEM_SIZE;
	}

	init_mm.start_code = (unsigned long) &_text;
	init_mm.end_code   = (unsigned long) &_etext;
	init_mm.end_data   = (unsigned long) &_edata;
	init_mm.brk	   = (unsigned long) &_end;

	memcpy(saved_command_line, from, COMMAND_LINE_SIZE);
	saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
	parse_cmdline(&meminfo, cmdline_p, from);
	bootmem_init(&meminfo);
	paging_init(&meminfo, mdesc);
	request_standard_resources(&meminfo, mdesc);

	/*
	 * Set up various architecture-specific pointers
	 */
	init_arch_irq = mdesc->init_irq;

#ifdef CONFIG_VT
#if defined(CONFIG_VGA_CONSOLE)
	conswitchp = &vga_con;
#elif defined(CONFIG_DUMMY_CONSOLE)
	conswitchp = &dummy_con;
#endif
#endif
}
コード例 #14
0
ファイル: bot.c プロジェクト: HackerCow/hackerb0t
void process_line(SOCKET socket, char* msg)
{
    // V3:
    //@color=#0000FF;emotes=;subscriber=0;turbo=0;user_type= :bomb_mask!bomb_mask@bomb_mask.tmi.twitch.tv PRIVMSG #bomb_mask :Yo thanks
    //:[email protected] PRIVMSG #channel :message that was sent

    if(strncmp(msg, "PING", 4) == 0)
    {
        printf("\n\n\n###########PING###########\n\n\n");
        int len = strlen("PONG");
        send_msg(socket, "PONG tmi.twitch.tv", &len);
        return;
    }

    /* see if message contains tags */
    char* tags = strtok(msg, " ");

    array_t tags_arr;
    int r = parse_tags(tags, &tags_arr);
    char* prefix = strtok(NULL, " ");

    char* cmd = strtok(NULL, " ");
    //printf("prefix and cmd read\n");
    //printf("stuff parsed\n");
    if(strcmp(cmd, "PRIVMSG") == 0)
    {

        //printf("private message\n");
        char* username = calloc(32, sizeof(char));
        char* channel = strtok(NULL, " ")+1;
        char* bot_command = strtok(NULL, " ");
        sscanf(bot_command, ":%s", bot_command);
        if(bot_command[0] != '!')
        {
            free(username);
            return;
        }

        array_t params;
        init_array(&params, 1);
        char* temp_tok = NULL;
        while(temp_tok = strtok(NULL, " \r\n"))
        {
            insert_array(&params, temp_tok);
        }
        int res = sscanf(prefix, "%*[^!]!%[^@]@%*", username);

        char* usertype = get_value(&tags_arr, "user_type");
        //printf("usertype: %s\n", usertype);

        for(int i = 0; i < command_count; i++)
        {
            if(strcmp(registered_commands[i]->name, bot_command+1) == 0)
            {
                char* response = NULL;
                hackerbot_command_args args = {username, usertype, channel, NULL, socket};
                if(registered_commands[i]->argcount == 0)
                {
                    response = registered_commands[i]->function(&args);
                }
                else
                {
                    if(params.used < registered_commands[i]->argcount)
                        response = registered_commands[i]->usage;
                    /* 
                        if the user supplies too many arguments, we will just merge all the 
                        "unnecessarry" ones into one string to make the last argument 
                    */
                    else if(params.used > registered_commands[i]->argcount)
                    {
                        /* ...-1 is perfectly fine because we never hit this code path if argcount == 0 */
                        char* merged = strdup(params.array[registered_commands[i]->argcount-1]);
                        int msg_len = 0;
                        for(int j = registered_commands[i]->argcount; j < params.used; j++)
                        {
                            msg_len = strlen(merged);
                            char* temp_buf = calloc(msg_len + 1 + strlen(params.array[j]) + 1, sizeof(char));
                            memcpy(temp_buf, merged, msg_len);
                            memcpy(temp_buf + msg_len, " ", 1);
                            memcpy(temp_buf + msg_len + 1, params.array[j], strlen(params.array[j]) + 1);

                            free(merged);
                            merged = calloc(msg_len + 1 + strlen(params.array[j]) + 1, sizeof(char));
                            memcpy(merged, temp_buf, msg_len + 1 + strlen(params.array[j]) + 1);
                            free(temp_buf);
                        }

                        int used = params.used;
                        for(int j = registered_commands[i]->argcount; j < used; j++)
                            remove_from_array(&params);

                        params.array[registered_commands[i]->argcount-1] = merged;

                        args.params = &params;
                        response = registered_commands[i]->function(&args);
                        free(merged);
                    }
                    else
                    {
                        args.params = &params;
                        response = registered_commands[i]->function(&args);
                    }
                }
                if(!response)
                    response = "There was an error while processing your request BibleThump";

                send_irc_message(socket, response, username, args.channel);
                goto cleanup;
            }
        }

        send_irc_message(socket, "I don't know that command", username, channel);

        cleanup:
        free_array(&tags_arr);
        free_array(&params);
        free(username);
    }
}