Esempio n. 1
0
char* getstring(int x, char *lang)
{
	char str[MAX_ITEMS][MAX_WORD_LEN];
	char newstr[MAX_WORD_LEN];

	int index = 0;
	int another_index = 20;
	
	if (strcmp(lang, LANG_ES) == 0) load_words_es(str);
	if (strcmp(lang, LANG_EN) == 0) load_words_en(str);
			
	if (x < 20)
	{
		strcpy(newstr, strtoupper(str[x]));
	}	
	else if ((x == 20) || ((x + 1) % 10 != 0))
	{
		another_index += 10 * ((x / 10) - 2);
		index = x - another_index;
		
		strcpy(newstr, str[another_index - 1]);
	
		if (strcmp(lang, LANG_EN) == 0)
		{
			newstr[strlen(str[another_index - 1])] = '-';
			newstr[strlen(str[another_index - 1]) + 1] = '\0';
		}
		else if (strcmp(lang, LANG_ES) == 0)
		{
			if (another_index == 20)
			{
				newstr[strlen(str[another_index - 1]) - 1] = 'i';
			}
			else
			{
				newstr[strlen(str[another_index - 1])] = ' ';
				newstr[strlen(str[another_index - 1]) + 1] = 'y';
				newstr[strlen(str[another_index - 1]) + 2] = ' ';
				newstr[strlen(str[another_index - 1]) + 3] = '\0';
			}
		}
	
		strcat(newstr, str[index]);
		strtoupper(newstr);
	}
	else if ((x + 1) % 10 == 0)
	{
		strcpy(newstr, strtoupper(str[x]));
	}
	
	return newstr;
}
Esempio n. 2
0
char *strstrncase (char *haystack, char *needle) {
    char *workh, *workn, *found;
    if ((haystack == NULL) || (needle == NULL))
        return NULL;
    strtoupper (workn = (char *) malloc (strlen (needle)), needle);
    strtoupper (workh = (char *) malloc (strlen (haystack)), haystack);
    found = strstr (workh, workn);
    if (found != NULL)
        found = (found - workh) + haystack;
    free(workn);
    free(workh);
    return found;
}
Esempio n. 3
0
void print_field_type(FILE *code_file, char *type)
{
    char *upper;
    if (strchr(type, '[')) {
        upper = strtoupper(get_basic_type(type)); 
        fprintf(code_file, "\t\tTYPE_%s | TYPE_ARRAY,\n", upper);
    }
    else {
        upper = strtoupper(type);
        fprintf(code_file, "\t\tTYPE_%s,\n", upper);
    }
    free(upper);
}
Esempio n. 4
0
void parse_opcodes(char *cmdbuf, uint32_t *debug_cmd, uint32_t *user1_cmd, uint32_t *idcode_cmd)
{
  char *saveptr = NULL;
  char *cmd;
  char *token;
  char *saveptr2;
  int target;
  int opcode;
  
  cmd = strtok_r(cmdbuf, ",", &saveptr);
  while(cmd != NULL)
    {
      // 'cmd' should now have one pair in the form "EXTEST    (1111000000)"
      target = 0;
      token = strtok_r(cmd, " \t(", &saveptr2);
      if(!strcmp(strtoupper(token), "DEBUG")) {
	target = TARGET_DEBUG;
	debug("Found DEBUG opcode: ");
      }
      else if(!strcmp(strtoupper(token), "USER1")) {
	target = TARGET_USER1;
	debug("Found USER1 opcode:");
      }
      else if(!strcmp(strtoupper(token), "IDCODE")) {
	target = TARGET_IDCODE;
	debug("Found IDCODE opcode: ");
      }

      if(target) {  // don't parse opcode number unless necessary
	token = strtok_r(NULL, " \t()", &saveptr2);
	if(token != NULL) {
	  opcode = strtoul(token, NULL, 2); // *** Test for errors
	  debug("0x%X (%s)\n", opcode, token);
	  
	  if(target == TARGET_DEBUG) *debug_cmd = opcode;
	  else if(target == TARGET_USER1) *user1_cmd = opcode;
	  else if(target == TARGET_IDCODE) *idcode_cmd = opcode;
	}
	else {
	  printf("Error:  failed to find opcode value after identifier.\n");
	}
      }

      cmd = strtok_r(NULL,  ",", &saveptr);
    }


}
Esempio n. 5
0
// Find the codepage number for a charset name.
static uint
cs_codepage(string name)
{
  uint cp = CP_ACP;
  char upname[strlen(name) + 1];
  strtoupper(upname, name);
  uint iso;
  if (sscanf(upname, "ISO-8859-%u", &iso) == 1 ||
      sscanf(upname, "ISO8859-%u", &iso) == 1 ||
      sscanf(upname, "ISO8859%u", &iso) == 1) {
    if (iso && iso <= 16 && iso != 12)
      cp = 28590 + iso;
  }
  else if (sscanf(upname, "CP%u", &cp) == 1 ||
           sscanf(upname, "WIN%u", &cp) == 1 ||
           sscanf(upname, "%u", &cp) == 1) {
    // Got a codepage number.
  }
  else {
    // Search the charset table.
    for (uint i = 0; i < lengthof(cs_names); i++) {
      if (!strcasecmp(name, cs_names[i].name)) {
        cp = cs_names[i].cp;
        break;
      }
    }
  }

  return
    cp == CP_ACP ? GetACP() :
    cp == CP_OEMCP ? GetOEMCP() :
    valid_codepage(cp) ? cp : GetACP();
}
Esempio n. 6
0
/* Parse a port:protocol sequence. Returns a positive integer on error.
 */
int parse_port_sequence(char *sequence, opendoor_t *door)
{
	char *num;
	char *protocol;
	char *port;

	door->seqcount = 0;	/* reset seqcount */
	while((num = strsep(&sequence, ","))) {
		if(door->seqcount >= SEQ_MAX) {
			fprintf(stderr, "config: section %s: too many ports in knock sequence\n", door->name);
			logprint("error: section %s: too many ports in knock sequence\n", door->name);
			return(1);
		}
		port = strsep(&num, ":");
		door->sequence[door->seqcount++] = (unsigned short)atoi(port);
		if((protocol = strsep(&num, ":"))){
			protocol = strtoupper(trim(protocol));
			if(!strcmp(protocol, "TCP")){
				door->protocol[door->seqcount-1] = IPPROTO_TCP;
			} else if(!strcmp(protocol, "UDP")) {
				door->protocol[door->seqcount-1] = IPPROTO_UDP;
			} else {
				fprintf(stderr,"config: section %s: unknown protocol in knock sequence\n", door->name);
				logprint("error: section %s: unknown protocol in knock sequence\n", door->name);
				return(1);
			}
		} else {
			door->protocol[door->seqcount-1] = IPPROTO_TCP; /* default protocol */
		}
	}
	return(0);
}
Esempio n. 7
0
void aggregator_element_end(void * parser, const char *wname)
{
	char name[64];

#if BT_SIZEOFWCHAR == 2
	wcstombs( name, (const wchar_t *) wname, 127);
#else
	strcpy( name, wname );
#endif
	strtoupper( name );
	
	if(	!strcmp(name, "IMAGE") ||
		!strcmp(name, "TEXTINPUT") ||
		!strcmp(name, "ITEM") ||
		!strcmp(name, "ENTRY") ||
		!strcmp(name, "CONTENT") ||
		!strcmp(name, "INFO") )
	{
		element = "";
	}
	if(	!strcmp(name, "ID") )
	{
		if (element == "ID")
		{
			element = "";
		}
	}  
}
Esempio n. 8
0
struct dvec *
vec_fromplot(char *word, struct plot *plot)
{
    struct dvec *d;
    char buf[BSIZE_SP], buf2[BSIZE_SP], cc, *s;

    d = findvec(word, plot);
    if (!d) {
        (void) strcpy(buf, word);
        strtolower(buf);
        d = findvec(buf, plot);
    }
    if (!d) {
        (void) strcpy(buf, word);
        strtoupper(buf);
        d = findvec(buf, plot);
    }

    /* scanf("%c(%s)" doesn't do what it should do. ) */
    if (!d && (sscanf(word, "%c(%s", /* ) */ &cc, buf) == 2) &&
        /* ( */ ((s = strrchr(buf, ')')) != NULL) &&
        (s[1] == '\0')) {
        *s = '\0';
        if (prefix("i(", /* ) */ word) || prefix("I(", /* ) */ word)) {
            /* Spice dependency... */
            (void) sprintf(buf2, "%s#branch", buf);
            (void) strcpy(buf, buf2);
        }
        d = findvec(buf, plot);
    }

    return (d);
}
Esempio n. 9
0
static void upper_onwrite(sst_t* self, sst_chunk_t* chunk) {
  char *s;
  sst_chunk_t *chunk_out;

  s = (char*)chunk->data;
  chunk_out = sst_chunk_new(strtoupper(s), free);

  self->emit(self, chunk_out);
  sst_chunk_free(chunk);
}
Esempio n. 10
0
//Volta o status de letra maiúscula da palavra
//O(L)
char* VoltaMaiuscula(char *palavra, int statusMaiuscula) {
    char *string = palavra;
    switch (statusMaiuscula) {
    case (TODASMAIUSCULAS): {
        string = strtoupper(palavra); //O(L)
        palavra = strtoupper(palavra);//O(L)
        break;
    }
    case (PRIMEIRAMAIUSCULA): {
        string[0] = toupper(palavra[0]);
        break;
    }
    case (PRIMEIRAMINUSCULA): {
        //A string já está toda minúscula, devida à implementação da função corrigeTexto()
        break;
    }
    }
    return string;
}
Esempio n. 11
0
static char *
parse_req (char *line, char **method, char **protocol)
{
  char *req = NULL, *request = NULL, *proto = NULL, *dreq = NULL;
  const char *meth;
  ptrdiff_t rlen;

  meth = extract_method (line);

  /* couldn't find a method, so use the whole request line */
  if (meth == NULL) {
    request = xstrdup (line);
  }
  /* method found, attempt to parse request */
  else {
    req = line + strlen (meth);
    if ((proto = strstr (line, " HTTP/1.0")) == NULL &&
        (proto = strstr (line, " HTTP/1.1")) == NULL) {
      return alloc_string ("-");
    }

    req++;
    if ((rlen = proto - req) <= 0)
      return alloc_string ("-");

    request = xmalloc (rlen + 1);
    strncpy (request, req, rlen);
    request[rlen] = 0;

    if (conf.append_method)
      (*method) = strtoupper (xstrdup (meth));

    if (conf.append_protocol)
      (*protocol) = strtoupper (xstrdup (++proto));
  }

  if ((dreq = decode_url (request)) && dreq != '\0') {
    free (request);
    return dreq;
  }

  return request;
}
Esempio n. 12
0
int nodeLabelCompar2(const void *elem1, const void * elem2)

// sort comparison function: alphabetical sort, skipping over first non-alpha characters in string
// and if the string is ALL nonalpha, it gets sorted to end of list

{
NodeLevelMap *n1,*n2;
char s1[256],s2[256],*S1, *S2;
n1=(NodeLevelMap*)elem1; // ugh, first cast the void pointer for the comparator, then deref to get the node
n2=(NodeLevelMap*)elem2;
strcpy(s1,n1->n->label);
strcpy(s2,n2->n->label);
S1=firstalpha(s1);
S2=firstalpha(s2); // move into string until we get to first alphabet char
if (!S1) return 1;
if (!S2) return -1; // if one of the strings has no alpha chars, this will insure it gets sorted last?
strtoupper(S1);
strtoupper(S2);
return strcmp(S1,S2);
}
Esempio n. 13
0
void
check_all (mpq_srcptr q, int base, const char *want)
{
  char  *s;

  check_one (q, base, want);

  s = __gmp_allocate_strdup (want);
  strtoupper (s);
  check_one (q, -base, s);
  (*__gmp_free_func) (s, strlen(s)+1);
}
Esempio n. 14
0
File: step1.c Progetto: AnLingm/gpdb
void
main(char argc, char **argv)
{
	char		str[250];
	int			sw = 0;

	while (fgets(str, 240, stdin))
	{
		if (sw == 0)
			printf("%s", strtoupper(str));
	}

}
Esempio n. 15
0
void initIPCountryTable(int argc, char *argv[])
{
  int i;
  FILE *fin;
  
  if ((Head=malloc(sizeof(IPNode)))==NULL)
    exit(EXIT_FAILURE);
  strcpy(Head->cc, "***");
  Head->b[0]=NULL;
  Head->b[1]=NULL;  
  
  addNode(QUAD2IP(10,0,0,0), 256*256*256, "LOC", 0);
  addNode(QUAD2IP(127,0,0,0), 256*256*256, "LOC", 0);
  addNode(QUAD2IP(172,16,0,0), 16*256*256, "LOC", 0);
  addNode(QUAD2IP(192,168,0,0), 256*256, "LOC", 0);
 
  for (i=0; i<argc-optind; i++) {
    if ((fin=fopen(argv[i+optind], "r"))==NULL)
      continue;

    if (OptVerbose || OptReportConflictingMappings)
      fprintf(stderr, "== Reading File %d: %s\n", i, argv[i+optind]);
    
    while (!feof(fin)) {
      char buff[256];
      char *strtokState, *token, *cc, *ip, *range;

      if (fgets(buff, sizeof(buff), fin)==NULL)
        continue;
      if ((token=strtok_r(buff, "|", &strtokState))==NULL)
        continue;
      if ((cc=strtok_r(NULL, "|", &strtokState))==NULL)
        continue;
      if ((token=strtok_r(NULL, "|", &strtokState))==NULL)
        continue;
      if (strcmp(token, "ipv4"))
        continue;
      if ((ip=strtok_r(NULL, "|", &strtokState))==NULL)
        continue;
      if ((range=strtok_r(NULL, "|", &strtokState))==NULL)
        continue;

      strtoupper(cc);
      if (strcmp(cc, "GB")==0)
        cc="UK";

      addNode(xaton(ip), atoi(range), cc, i);
    }
    fclose(fin);
  }
}
Esempio n. 16
0
int optindex(char *opt)
{
  int n;

  strtoupper(opt);

  n=0;while (opt[n]==' ' && n<strlen(opt)) n++;
  if (opt[n]=='#' || opt[n]==0) return OPT_COMMENT;
  
  for (n=0;n<OPTS_COUNT;n++)
    if (!strcmp(opt,options[n])) return n;

  return -1;
}
Esempio n. 17
0
/* regidx():
 * Return an index into the regnames[] array that matches the
 * incoming register name.
 * If no match is found, print an error message and return -1.
 */
static int
regidx(char *name)
{
    int i;

    strtoupper(name);
    for(i=0; i<REGTOT; i++) {
        if(!strcmp(name,regnames[i])) {
            return(i);
        }
    }
    printf("Bad reg: '%s'\n",name);
    return(-1);
}
Esempio n. 18
0
//============================================================ read track definition line
void Track::trackDef(char *s){
	char bb[100], *st;
	if(trackType==0){
		trackType=BED_TRACK;
		st=getAttr(s,"type",bb);
		if(st!=0){
			strtoupper(st);
			if(strncmp(st,"WIG",3)==0) 	     trackType=WIG_TRACK;
			if(strncmp(st,"BEDGRAPH" ,8)==0) trackType=BED_GRAPH;
			if(strncmp(st,"BROADPEAK",8)==0) trackType=BROAD_PEAK;
		}
	}
	st=getAttr(s,"name", bb);
	if(st!=0) strcpy(trackName,st);
}
Esempio n. 19
0
/** Sets the Text of the current control */
void Button::SetText(const char* string)
{
	free(Text);
	Text = NULL;
	if (string == NULL) {
		hasText = false;
	} else if (string[0] == 0) {
		hasText = false;
	} else {
		Text = strndup( string, 255 );
		if (Flags&IE_GUI_BUTTON_LOWERCASE)
			strtolower( Text );
		else if (Flags&IE_GUI_BUTTON_CAPS)
			strtoupper( Text );
		hasText = true;
	}
	MarkDirty();
}
Esempio n. 20
0
/* prepareSeq: prepares sequence string for analysis by shustring-type programs.
 * Does the following: 1) set all residues to upper case
 *                     2) generate reverse complement
 *                     3) concatenate reverse complement to end of forward strand
 * e.g. if the string of the original seq. is ACCGZ\0, (Z for the border)
 * then the new one which includes the reversed complement seq. looks like this: ACCGZCGGTZ\0
 *
 */
void prepareSeq(Sequence *sequence){
  Sequence *rstrand;
  Int64 i, j;
  char *nuc = "TCAGtcag";
  
  strtoupper(sequence->seq);
  /* take care of reverse strand */
  rstrand = revcomp(sequence); /* reverse and complement a sequence */
  rstrand->headers = (char **)emalloc(sizeof(char *));
  rstrand->headers[0] = (char *)emalloc(sizeof(char));
  rstrand->borders = (Int64 *)emalloc(sizeof(Int64));
	rstrand->freqTab = NULL;
	rstrand->numSeq = 1;
  sequence->seq[sequence->len] = '\0';
  sequence->len += sequence->len; /* new seq. length = 2 x original size */
  sequence->seq = (char *)erealloc(sequence->seq,(size_t)(sequence->len+1)*sizeof(char));
  /* number of borders = 2 x original size */
	sequence->borders = (Int64 *)erealloc(sequence->borders, 2*(size_t)sequence->numSeq * sizeof(Int64));
  /* adjust the border values */
	for(i=1;i<sequence->numSeq;i++){
		/* seq. looks like this: F1 F2 .. Fn Rn .. R2 R1 */
    sequence->borders[2*sequence->numSeq-i-1] = sequence->len - sequence->borders[i-1] - 2;
  }
  sequence->borders[2*sequence->numSeq-1] = sequence->len - 1;
	/* move first border of reverted sequences to the end */
  rstrand->seq++;  /* since the last border of the original seq is the first char of the reversed seq */               
  //strncat(sequence->seq,rstrand->seq,(size_t)sequence->len); ??
	strncat(sequence->seq,rstrand->seq,(size_t)sequence->len / 2);
  rstrand->seq--; /* return the pointer */
  sequence->seq[sequence->len-1] = BORDER;
  sequence->seq[sequence->len] = '\0';
  freeSequence(rstrand);
  sequence->numNuc = 0;
	for(i = 0; i < 8; i++) {
    //sequence->numNuc += sequence->freqTab[(int)nuc[i]];
		for (j = 0; j < sequence->numNuc; j ++) {
			sequence->numNuc += sequence->freqTab[j][(Int64)nuc[i]];
			sequence->freqTab[j][(Int64)nuc[i]] *= 2; /* fwd and rev strand */
		}
	}
  sequence->numNuc *= 2;  
	sequence->numSbjctNuc *= 2;
}
Esempio n. 21
0
static int set_debug(struct cfgdata_t *cfgdata, char *value)
{
	if (!value) {
		/* If no value is specified debugging is enabled */
		cfgdata->debug = 1;
	} else {
		char v[strlen(value)+1];

		strtoupper(value, v);

		if ( (strcmp(v, "ON") == 0) || (strcmp(v, "1") == 0) ) {
			cfgdata->debug = 1;
		} else if ( (strcmp(v, "OFF") == 0) || (strcmp(v, "0") == 0) ) {
			cfgdata->debug = 0;
		} else {
			log_msg(lg, "Unknown value '%s' for DEBUG keyword", value);
			return -1;
		}
	}
	return 0;
}
Esempio n. 22
0
//=====================================================================================
int getTypeByExt(const char *sext){
	char bext[80];
	strtoupper(strcpy(bext,sext));
	if(strcmp(bext,"BED")==0) return BED_TRACK;
	if(strcmp(bext,"WIG")==0) return WIG_TRACK;

	if(strcmp(bext,"BEDGRAPH"	)==0) return BED_GRAPH;
	if(strcmp(bext,"BED_GRAPH"	)==0) return BED_GRAPH;
	if(strcmp(bext,"B_GRAPH"	)==0) return BED_GRAPH;
	if(strcmp(bext,"BGR"		)==0) return BED_GRAPH;

	if(strcmp(bext,"B_PEAK"		)==0) return BROAD_PEAK;
	if(strcmp(bext,"BPEAK"		)==0) return BROAD_PEAK;
	if(strcmp(bext,"BROAD_PEAK"	)==0) return BROAD_PEAK;
	if(strcmp(bext,"BROADPEAK"	)==0) return BROAD_PEAK;

	if(strcmp(bext,"MODEL"	)==0) return MODEL_TRACK;
	if(strcmp(bext,"MOD"	)==0) return MODEL_TRACK;
	if(strcmp(bext,"MDL"	)==0) return MODEL_TRACK;

	return 0;
}
Esempio n. 23
0
Ipc_Status_t
ipc_send_double (
     char               *tag,    /* The node or instance */
     double             value )  /* The data value to send */
{
   int len = 0;
           
   switch (protocol) {
   case IPC_PROTOCOL_V1:
      strcpy (fmt_buffer, " "); /* save room for the length byte */
      strcat (fmt_buffer, tag);
      strcat (fmt_buffer, " ");

      /* If talking to Mentor tools, must force upper case for Mspice 7.0 */
      strtoupper(fmt_buffer);

      len = stuff_binary_v1 (value, 0.0, 1, fmt_buffer, (int) strlen(fmt_buffer));
      break;
   case IPC_PROTOCOL_V2:
      break;
   }
   return ipc_send_line_binary (fmt_buffer, len);
}
Esempio n. 24
0
/* Process specified keyword */
int process_keyword(enum cfg_type_t cfg_type, struct cfgdata_t *cfgdata, char *keyword, char *value)
{
	struct cfg_keyfunc_t *kf;
	char ukey[strlen(keyword) + 1];

	/* For convenience convert keyword to lowercase */
	strtoupper(keyword, ukey);

	/* See if given keyword is known and call appropriate function */
	for (kf = cfg_keyfunc; kf->keyword != NULL; kf++) {
		if (cfg_type != kf->type) continue;
		if (0 == strcmp(ukey, kf->keyword)) {
			if ( (1 == kf->has_value) && (NULL == value) ) {
				log_msg(lg, "+ keyword '%s' should have value", ukey);
				return -1;
			}
			return kf->keyfunc(cfgdata, value);
		}
	}

	/* Coming this far, keyword was not found */
	return -1;
}
Esempio n. 25
0
/*
static void cmd_test(struct s_reader *reader)
{
    def_resp;
    int i;
    uchar drecmd[] = { 0x00, 0x02 };
    char tmp[64];

    for(i = 0; i <= 0xFF; i++)
    {
        if(i == 0x45) continue;
        drecmd[0] = i;
        dre_cmd(drecmd);
        if(cta_res[2] == 0xE2)
        {
            if(cta_res[3] != 0xE3) rdr_log(reader, "cmd %02X error %02X",i ,cta_res[3]);
        }
        else
        {
            rdr_log(reader, "cmd %02X answer %s",i ,cs_hexdump(0, cta_res, cta_res[1]+2, tmp, sizeof(tmp)));
        }
    }

    uchar drecmd[64];

    //memset(drecmd, 0, 64);
    //drecmd[0] = 0x71;
    for(i = 2; i <= 64; i++)
    {
        memset(drecmd, 0, 64);
        drecmd[i-1] = 0x02;
        drecmd[0] = 0x71;

        dre_script(drecmd, i, 0, 0, 0);

        if(cta_res[2] == 0xE2)
        {
            if((cta_res[3] != 0xE2) & (cta_res[3] != 0xED)) rdr_log(reader, "Len %02X error %02X",i ,cta_res[3]);
            if((cta_res[3] & 0xF0) != 0xE0) rdr_log(reader, "Len %02X answer %s",i ,cs_hexdump(0, cta_res, cta_res[1]+2, tmp, sizeof(tmp)));
        }
        else
        {
            rdr_log(reader, "Len %02X answer %s",i ,cs_hexdump(0, cta_res, cta_res[1]+2, tmp, sizeof(tmp)));
        }
    }
}
*/
static int32_t dre_card_init(struct s_reader *reader, ATR *newatr)
{
	get_atr;
	def_resp;
	uchar ua[] = { 0x43, 0x15 };  // get serial number (UA)
	uchar providers[] = { 0x49, 0x15 };   // get providers
	uchar cmd56[] = { 0x56, 0x00 };
	int32_t i;
	char *card;
	char tmp[9];

	if((atr[0] != 0x3b) || (atr[1] != 0x15) || (atr[2] != 0x11) || (atr[3] != 0x12) || (
				((atr[4] != 0x01) || (atr[5] != 0x01)) &&
				((atr[4] != 0xca) || (atr[5] != 0x07)) &&
                ((atr[4] != 0xcb) || (atr[5] != 0x07)) &&
                ((atr[4] != 0xcc) || (atr[5] != 0x07)) &&
                ((atr[4] != 0xcd) || (atr[5] != 0x07))
			))
		{ return ERROR; }

	if(!cs_malloc(&reader->csystem_data, sizeof(struct dre_data)))
		{ return ERROR; }
	struct dre_data *csystem_data = reader->csystem_data;

	csystem_data->provider = atr[6];
	uchar checksum = xor(atr + 1, 6);

	if(checksum != atr[7])
		{ rdr_log(reader, "warning: expected ATR checksum %02x, smartcard reports %02x", checksum, atr[7]); }

	switch(atr[6])
	{
        case 0:

            if(!(dre_cmd(cmd56))) { return ERROR; }
            if((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00)) { return ERROR; }

            switch(cta_res[4])
            {
                case 0x02:
                    card = "Tricolor Centr DRE3";
                    reader->caid = 0x4ae1;
                    break;
                case 0x03:
                    card = "Tricolor Syberia DRE3";
                    reader->caid = 0x4ae1;  
                    break;
                case 0x18:
                case 0x19:
                    card = "Tricolor Centr DRE4";
                    reader->caid = 0x2710;
                    break;
                case 0x1A:
                    card = "Tricolor Syberia DRE4";
                    reader->caid = 0x2710;
                    break;
                default:
                    return ERROR;
            }
            csystem_data->provider = cta_res[4];
            providers[0] = 0x83;
            break;
        case 0x11:
            card = "Tricolor Centr DRE2";
            reader->caid = 0x4ae1;
            break;          //59 type card = MSP (74 type = ATMEL)
        case 0x12:
            card = "Cable TV";
            reader->caid = 0x4ae1;  //TODO not sure about this one
            break;
        case 0x14:
            card = "Tricolor Syberia DRE2";
            reader->caid = 0x4ae1;
            break;          //59 type card
        case 0x15:
            card = "Platforma HD / DW old";
            reader->caid = 0x4ae1;
            break;          //59 type card
        default:
            return ERROR;
	}

	memset(reader->prid, 0x00, 8);

    if(atr[6] > 0)
    {
        reader->prid[0][3] = atr[6];
    }
    else
    {
        reader->prid[0][3] = csystem_data->provider;
    }

	uchar cmd54[] = { 0x54, 0x14 };   // geocode
	cmd54[1] = csystem_data->provider;
	uchar geocode = 0;
	if((dre_cmd(cmd54)))      //error would not be fatal, like on 0x11 cards
		{ geocode = cta_res[3]; }

	providers[1] = csystem_data->provider;
	if(!(dre_cmd(providers)))
		{ return ERROR; }           //fatal error
	if((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
		{ return ERROR; }

	uchar provname[128];
	for(i = 0; ((i < cta_res[2] - 6) && (i < 128)); i++)
	{
		provname[i] = cta_res[6 + i];
		if(provname[i] == 0x00)
			{ break; }
	}

	int32_t major_version = cta_res[3];
	int32_t minor_version = cta_res[4];

	ua[1] = csystem_data->provider;
	dre_cmd(ua);          //error would not be fatal

	int32_t hexlength = cta_res[1] - 2;   //discard first and last byte, last byte is always checksum, first is answer code

    if(reader->force_ua)
    {
        rdr_log(reader, "WARNING!!!! used UA from force_ua %08X", reader->force_ua);
        memcpy(cta_res + 3, &reader->force_ua, 4);
    }

	reader->hexserial[0] = 0;
	reader->hexserial[1] = 0;
	memcpy(reader->hexserial + 2, cta_res + 3, hexlength);

	int32_t low_dre_id, dre_chksum;
	uchar buf[32];

    if(major_version < 0x3)
    {
        low_dre_id = ((cta_res[4] << 16) | (cta_res[5] << 8) | cta_res[6]) - 48608;
        dre_chksum = 0;
        snprintf((char *)buf, sizeof(buf), "%i%i%08i", csystem_data->provider - 16, major_version + 1, low_dre_id);

        for(i = 0; i < 32; i++)
        {
            if(buf[i] == 0x00)
                { break; }
            dre_chksum += buf[i] - 48;
        }

        if(major_version < 2)
        {
            reader->caid = 0x4ae0;
            card = csystem_data->provider == 0x11 ? "Tricolor Centr DRE1" : "Tricolor Syberia DRE1";
        }

        rdr_log(reader, "type: DRE Crypt, caid: %04X, serial: {%s}, dre id: %i%i%i%08i, geocode %i, card: %s v%i.%i",
                reader->caid, cs_hexdump(0, reader->hexserial + 2, 4, tmp, sizeof(tmp)), dre_chksum, csystem_data->provider - 16,
                major_version + 1, low_dre_id, geocode, card, major_version, minor_version);
    }
    else
    {
        low_dre_id = ((cta_res[4] << 16) | (cta_res[5] << 8) | cta_res[6]);
        dre_chksum = 0;
        snprintf((char *)buf, sizeof(buf), "%i%i%08i", csystem_data->provider, major_version, low_dre_id);

        for(i = 0; i < 32; i++)
        {
            if(buf[i] == 0x00)
                { break; }
            dre_chksum += buf[i] - 48;
        }
        rdr_log(reader, "type: DRE Crypt, caid: %04X, serial: {%s}, dre id: %i%03i%i%08i, geocode %i, card: %s v%i.%i",
                reader->caid, cs_hexdump(0, reader->hexserial + 2, 4, tmp, sizeof(tmp)), dre_chksum, csystem_data->provider,
                major_version, low_dre_id, geocode, card, major_version, minor_version);
    }

	rdr_log(reader, "Provider name:%s.", provname);

	memset(reader->sa, 0, sizeof(reader->sa));
	memcpy(reader->sa[0], reader->hexserial + 2, 1);  //copy first byte of unique address also in shared address, because we dont know what it is...

	rdr_log_sensitive(reader, "SA = %02X%02X%02X%02X, UA = {%s}", reader->sa[0][0], reader->sa[0][1], reader->sa[0][2],
					  reader->sa[0][3], cs_hexdump(0, reader->hexserial + 2, 4, tmp, sizeof(tmp)));

	reader->nprov = 1;

//  cmd_test(reader);

    // exec user script, wicardd format
    if(reader->userscript != NULL)
    {
        uint8_t *usercmd = NULL;
        int cmd_len;
        int n;
        char *tempbuf = malloc(2048);
        trim2(reader->userscript);
        FILE *pFile = fopen(reader->userscript, "rt");

        if(pFile != NULL)
        {
            uchar ignoreProvid = 0;
            uchar crypted = 0;
            uchar cryptkey = 0;
            do
            {
                tempbuf[0] = '\0';
                if(usercmd != NULL) free(usercmd);

                if(fgets(tempbuf, 2048, pFile) == NULL) continue;

                if(strlen(tempbuf) < 10) continue;

                trim2(tempbuf);

                ignoreProvid = 0;
                crypted = 0;
                cryptkey = 0;

                if(tempbuf[0] == '8' && tempbuf[1] == '6' && csystem_data->provider == 0x11) ignoreProvid = 1;
                else if(strncmp(tempbuf ,"REG2" ,4) == 0)
                {
                    dre_read_ee(reader, &tempbuf[4] ,csystem_data->provider);
                    continue;
                }
                else if(strncmp(tempbuf ,"CR" ,2) == 0)
                {
                    crypted = 1;
                    cryptkey = ((tempbuf[2] - (tempbuf[2] > 0x39 ? 0x37:0x30)) << 4) + ((tempbuf[3] - (tempbuf[3] > 0x39 ? 0x37:0x30)) & 0xF);
                }
                else if(tempbuf[0] != '5' && tempbuf[1] != '9') continue;

                strtoupper(tempbuf);

                cmd_len = strlen(tempbuf) / 2 - 3 + ignoreProvid - (crypted * 2);
                usercmd = malloc(cmd_len);

                for(i=0,n= 4+(crypted * 4);i<cmd_len;i++,n+=2)
                {
                    usercmd[i] = ((tempbuf[n] - (tempbuf[n] > 0x39 ? 0x37:0x30)) << 4) + ((tempbuf[n+1] - (tempbuf[n+1] > 0x39 ? 0x37:0x30)) & 0xF);
                }

                /*if(usercmd[cmd_len-1] != csystem_data->provider && !ignoreProvid)
                {
                    rdr_log(reader, "Skip script: current provid %02X , script provid %02X", csystem_data->provider, usercmd[cmd_len-1]);
                    continue;
                }
                */
                rdr_log(reader, "User script: %s", tempbuf);

                /*ret =*/ 

                rdr_log(reader, "Script %s", (dre_script(usercmd, cmd_len, ignoreProvid, crypted, cryptkey)) ? "done" : "error");
            }
            while(!feof(pFile));
        }
        else
        {
            rdr_log(reader, "Can't open script file (%s)", reader->userscript);
        }

        //if(usercmd != NULL) free(usercmd);
        if(tempbuf != NULL) free(tempbuf);
    }

    if(csystem_data->provider == 0x11)
    {
        memset(reader->prid[1], 0x00, 8);
        reader->prid[1][3] = 0xFE;
        reader->nprov = 2;
    }

	if(!dre_set_provider_info(reader))
		{ return ERROR; }           //fatal error

	rdr_log(reader, "ready for requests");
	return OK;
}
Esempio n. 26
0
static int dindel_fetch_func(bam1_t *b, void *data)
{
     data_t_dindel *tmp = (data_t_dindel*)data;
     bam1_core_t *c = &b->core;
     int rlen;
     uint8_t *to_delete;

     /* don't change reads failing default mask: BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP */
     if (c->flag & BAM_DEF_MASK) {
          /* fprintf(stderr, "skipping read: %s at pos %d\n", bam1_qname(b), c->pos); */
          bam_write1(tmp->out, b);
          return 0;
     }

     /* get the reference sequence and compute homopolymer array */
     if (tmp->tid != c->tid) {
             /*fprintf(stderr, "fetching reference sequence %s\n",
               tmp->in->header->target_name[c->tid]); */
          char *ref = fai_fetch(tmp->fai, tmp->in->header->target_name[c->tid], &rlen);
          strtoupper(ref);/* safeguard */
          int rlen = strlen(ref);
          tmp->tid = c->tid;
          if (tmp->hpcount) free(tmp->hpcount);
          tmp->hpcount = (int*)malloc(rlen*sizeof(int));
          find_homopolymers(ref, tmp->hpcount, rlen);
          free(ref);
          tmp->rlen = rlen;
          /* fprintf(stderr, "fetched reference sequence\n");*/
     }

     /* parse the cigar string */
     uint32_t *cigar = bam1_cigar(b);
     uint8_t indelq[c->l_qseq+1];
     /* fprintf(stderr, "l_qseq:%d\n", c->l_qseq); */
     int i;
     int x = c->pos; /* coordinate on reference */
     int y = 0; /* coordinate on query */
     for (i = 0; i < c->n_cigar; ++i) {
          int j, oplen = cigar[i]>>4, op = cigar[i]&0xf;
          if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) {
               for (j = 0; j < oplen; j++) {
                       /*fprintf(stderr, "query:%d, ref:%d, count:%d\n", 
                         y, x, tmp->hpcount[x+1]); */
                    /* FIXME clang complains: The left operand of '>' is a garbage value */
                    indelq[y] = (x > tmp->rlen-2) ? DINDELQ[0] : (tmp->hpcount[x+1]>18 ?
                         DINDELQ[0] : DINDELQ[tmp->hpcount[x+1]]);
                    x++; 
                    y++;
               }
          } else if (op == BAM_CHARD_CLIP) { /* do nothing */
          } else if (op == BAM_CDEL) {
               x += oplen;
          } else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) { 
               for (j = 0; j < oplen; j++) {
                       /* fprintf(stderr, "query:%d, ref:%d\n", y, x); */
                    indelq[y] = DINDELQ[0];
                    y++;
               }
          } else {
               LOG_FATAL("unknown op %d for read %s\n", op, bam1_qname(b));/* FIXME skip? seen this somewhere else properly handled */
               exit(1);
          }
     }
     indelq[y] = '\0';

     to_delete = bam_aux_get(b, BI_TAG);
     if (to_delete) {
          bam_aux_del(b, to_delete);
     }
     bam_aux_append(b, BI_TAG, 'Z', c->l_qseq+1, indelq);

     to_delete = bam_aux_get(b, BD_TAG);
     if (to_delete) {
          bam_aux_del(b, to_delete);
     }
     bam_aux_append(b, BD_TAG, 'Z', c->l_qseq+1, indelq);

     bam_write1(tmp->out, b);
     return 0;
}
Esempio n. 27
0
/* Parse a config file
 */
int parseconfig(char *configfile)
{
	FILE *fp = NULL;
	char line[PATH_MAX+1];
	char *ptr = NULL;
	char *key = NULL;
	int linenum = 0;
	char section[256] = "";
	opendoor_t *door = NULL;
	PMList *lp;

	if((fp = fopen(configfile, "r")) == NULL) {
		perror(configfile);
		return(1);
	}

	while(fgets(line, PATH_MAX, fp)) {
		linenum++;
		trim(line);
		if(strlen(line) == 0 || line[0] == '#') {
			continue;
		}
		if(line[0] == '[' && line[strlen(line)-1] == ']') {
			/* new config section */
			ptr = line;
			ptr++;
			strncpy(section, ptr, sizeof(section));
			section[strlen(section)-1] = '\0';
			dprint("config: new section: '%s'\n", section);
			if(!strlen(section)) {
				fprintf(stderr, "config: line %d: bad section name\n", linenum);
				return(1);
			}
			if(strcmp(section, "options")) {
				/* start a new knock/event record */
				door = malloc(sizeof(opendoor_t));
				if(door == NULL) {
					perror("malloc");
					exit(1);
				}
				strncpy(door->name, section, sizeof(door->name)-1);
				door->name[sizeof(door->name)-1] = '\0';
				door->target = 0;
				door->seqcount = 0;
				door->seq_timeout  = SEQ_TIMEOUT; /* default sequence timeout (seconds)  */
				door->start_command = NULL;
				door->cmd_timeout = CMD_TIMEOUT; /* default command timeout (seconds) */
				door->stop_command = NULL;
				door->one_time_sequences_fd = NULL;
				door->pcap_filter_exp = NULL;
				doors = list_add(doors, door);
			}
		} else {
			/* directive */
			if(!strlen(section)) {
				fprintf(stderr, "config: line %d: all directives must belong to a section\n", linenum);
				return(1);
			}
			ptr = line;
			key = strsep(&ptr, "=");
			if(key == NULL) {
				fprintf(stderr, "config: line %d: syntax error\n", linenum);
				return(1);
			}
			trim(key);
			key = strtoupper(key);
			if(ptr == NULL) {
				if(!strcmp(key, "USESYSLOG")) {
					o_usesyslog = 1;
					dprint("config: usesyslog\n");
				} else {
					fprintf(stderr, "config: line %d: syntax error\n", linenum);
					return(1);
				}
			} else {
				trim(ptr);
				if(!strcmp(section, "options")) {
					if(!strcmp(key, "LOGFILE")) {
						strncpy(o_logfile, ptr, PATH_MAX-1);
						o_logfile[PATH_MAX-1] = '\0';
						dprint("config: log file: %s\n", o_logfile);
					} else if(!strcmp(key, "PIDFILE")) {
						strncpy(o_pidfile, ptr, PATH_MAX-1);
						o_pidfile[PATH_MAX-1] = '\0';
						dprint("config: pid file: %s\n", o_pidfile);
					} else if(!strcmp(key, "INTERFACE")) {
						/* set interface only if it has not already been set by the -i switch */
						if(strlen(o_int) == 0) {
							strncpy(o_int, ptr, sizeof(o_int)-1);
							o_int[sizeof(o_int)-1] = '\0';
							dprint("config: interface: %s\n", o_int);
						}
					} else {
						fprintf(stderr, "config: line %d: syntax error\n", linenum);
						return(1);
					}
				} else {
					if(door == NULL) {
						fprintf(stderr, "config: line %d: \"%s\" can only be used within a Door section\n",
								linenum, key);
						return(1);
					}
					if(!strcmp(key, "TARGET")) {
						door->target = malloc(sizeof(char) * (strlen(ptr)+1));
						if(door->target == NULL) {
							perror("malloc");
							exit(1);
						}
						strcpy(door->target, ptr);
						dprint("config: %s: target: %s\n", door->name, door->target);
					} else if(!strcmp(key, "SEQUENCE")) {
						int i;
						i = parse_port_sequence(ptr, door);
						if (i > 0) {
							return(i);
						}
						dprint_sequence(door, "config: %s: sequence: ", door->name);
					} else if(!strcmp(key, "ONE_TIME_SEQUENCES")) {
						if((door->one_time_sequences_fd = fopen(ptr, "r+")) == NULL) {
							perror(ptr);
							return(1);
						}
						dprint("config: %s: one time sequences file: %s\n", door->name, ptr);
						if (get_new_one_time_sequence(door) == 0) {
							dprint_sequence(door, "config: %s: sequence: ", door->name);
						} else {	/* no more sequences left in the one time sequences file */
							dprint("config: no more sequences left in the one time sequences file %s\n", ptr);
							return(1);
						}
					} else if(!strcmp(key, "SEQ_TIMEOUT") || !strcmp(key, "TIMEOUT")) {
						door->seq_timeout = (time_t)atoi(ptr);
						dprint("config: %s: seq_timeout: %d\n", door->name, door->seq_timeout);
					} else if(!strcmp(key, "START_COMMAND") || !strcmp(key, "COMMAND")) {
						door->start_command = malloc(sizeof(char) * (strlen(ptr)+1));
						if(door->start_command == NULL) {
							perror("malloc");
							exit(1);
						}
						strcpy(door->start_command, ptr);
						dprint("config: %s: start_command: %s\n", door->name, door->start_command);
					} else if(!strcmp(key, "CMD_TIMEOUT")) {
						door->cmd_timeout = (time_t)atoi(ptr);
						dprint("config: %s: cmd_timeout: %d\n", door->name, door->cmd_timeout);
					} else if(!strcmp(key, "STOP_COMMAND")) {
						door->stop_command = malloc(sizeof(char) * (strlen(ptr)+1));
						if(door->stop_command == NULL) {
							perror("malloc");
							exit(1);
						}
						strcpy(door->stop_command, ptr);
						dprint("config: %s: stop_command: %s\n", door->name, door->stop_command);
					} else if(!strcmp(key, "TCPFLAGS")) {
						char *flag;
						strtoupper(ptr);
						while((flag = strsep(&ptr, ","))) {
							/* allow just some flags to be specified */
							if(!strcmp(flag,"FIN")) {
								door->flag_fin = SET;
							} else if(!strcmp(flag,"!FIN")) {
								door->flag_fin = NOT_SET;
							} else if(!strcmp(flag, "SYN")) {
								door->flag_syn = SET;
							} else if(!strcmp(flag, "!SYN")) {
								door->flag_syn = NOT_SET;
							} else if(!strcmp(flag, "RST")) {
								door->flag_rst = SET;
							} else if(!strcmp(flag, "!RST")) {
								door->flag_rst = NOT_SET;
							} else if(!strcmp(flag, "PSH")) {
								door->flag_psh = SET;
							} else if(!strcmp(flag, "!PSH")) {
								door->flag_psh = NOT_SET;
							} else if(!strcmp(flag, "ACK")) {
								door->flag_ack = SET;
							} else if(!strcmp(flag, "!ACK")) {
								door->flag_ack = NOT_SET;
							} else if(!strcmp(flag, "URG")) {
								door->flag_urg = SET;
							} else if(!strcmp(flag, "!URG")) {
								door->flag_urg = NOT_SET;
							} else {
								fprintf(stderr, "config: line %d: unrecognized flag \"%s\"\n",
										linenum, flag);
								return(1);
							}
							dprint("config: tcp flag: %s\n", flag);
						}
					} else {
						fprintf(stderr, "config: line %d: syntax error\n", linenum);
						return(1);
					}
				}
				line[0] = '\0';
			}
		}
	}
	fclose(fp);

	/* sanity checks */
	for(lp = doors; lp; lp = lp->next) {
		door = (opendoor_t*)lp->data;
		if(door->seqcount == 0) {
			fprintf(stderr, "error: section '%s' has an empty knock sequence\n", door->name);
			return(1);
		}
	}

	return(0);
}
Esempio n. 28
0
int loadDigitalTable(bool onlyupdate)
{
	MYSQL_RES *result;
	MYSQL_ROW row;
	int state;
	int i,k;
	int idRow;
	MYSQL *conn=mysqlConnect();
	if( conn == NULL ) 
	{
		my_printf("%s\n",mysql_error(conn));
		return (-1);
	}

	if(!onlyupdate)
	{
		if(DIGITALCHANNELS>0)
		{
			my_printf("get_shared_memory_segment: digitalTable\n");
			digitalTable=(struct digitalLine *)get_shared_memory_segment(DIGITALCHANNELS * sizeof(struct digitalLine), &SHMDIGITALID, "/dev/zero");
			if(!digitalTable)
				die("digitalTable - get_shared_memory_segment\n");
		}
		else
			digitalTable=0;
		my_printf("get_shared_memory_segment: id_digital_pioggia\n");
		id_digital_pioggia=(int *)get_shared_memory_segment(sizeof(int), &SHMPIOGGIA, "/dev/zero");
		if(!id_digital_pioggia)
			die("id_digital_pioggia - get_shared_memory_segment\n");
	}

	initializeDigitalTable();
	
	state = mysql_query(conn, "SELECT digital.id_digital,digital.form_label,"
							"digital.description,digital.label,digital.sinottico,"
							"digital.device_num,digital.ch_num,digital.printer,"
							"digital.time_delay_on,digital.time_delay_off,"
							"digital.alarm_value,digital.msg_on,digital.msg_off,"
							"digital.enabled,digital.sms,digital.msg_is_event,on_value, "
							"digital.record_data_time "
						"FROM digital JOIN system ON digital.device_num=system.device_num "
						"WHERE system.removed=0 AND digital.ch_num!=0"
						" ORDER BY digital.device_num, digital.ch_num");
	if( state != 0 )
	{
		my_printf("%s\n",mysql_error(conn));
		return(1);
	}
	result = mysql_store_result(conn);

	*id_digital_pioggia=-1;


	idRow=0;
	while( ( row = mysql_fetch_row(result)) != NULL )
	{
		i=systemNumToId(atoi(row[5]),NUMSYSTEMS);
		if((i!=-1) && (atoi(row[6])<=systems[i].in_ch_d))
		{
			if(!onlyupdate)
				deviceToid[1][i][atoi(row[6]) - 1]=idRow;
			else
				idRow=deviceToid[1][i][atoi(row[6]) - 1];

			digitalTable[idRow].id_digital=atoi(row[0]);
			if(row[1])
				safecpy(digitalTable[idRow].form_label,row[1]);
			else
				safecpy(digitalTable[idRow].form_label,"");
			if(row[2])
				safecpy(digitalTable[idRow].description,row[2]);
			else
				safecpy(digitalTable[idRow].description,"");
			if(row[3])
				safecpy(digitalTable[idRow].label,row[3]);
			else
				safecpy(digitalTable[idRow].label,"");
			if(row[4])
				safecpy(digitalTable[idRow].sinottico,row[4]);
			else
				safecpy(digitalTable[idRow].sinottico,"");
			digitalTable[idRow].device_num=atoi(row[5]);
			digitalTable[idRow].ch_num=atoi(row[6]);

			digitalTable[idRow].printer=atoi(row[7]);

			digitalTable[idRow].time_delay_on=atoi(row[8]);
			digitalTable[idRow].time_delay_off=atoi(row[9]);
			digitalTable[idRow].alarm_value=atoi(row[10]);
			if(row[11])
				safecpy(digitalTable[idRow].msg_on,row[11]);
			else
				safecpy(digitalTable[idRow].msg_on,"");
			if(row[12])
				safecpy(digitalTable[idRow].msg_off,row[12]);
			else
				safecpy(digitalTable[idRow].msg_off,"");
			digitalTable[idRow].enabled=atoi(row[13]);
			digitalTable[idRow].sms=atoi(row[14]);
			digitalTable[idRow].msg_is_event=atoi(row[15]);
			digitalTable[idRow].on_value=atoi(row[16]);
			digitalTable[idRow].record_data_time=(atoi(row[17])!=-1?60*atoi(row[17]):RECORDDATATIME);
			if(strstr(strtoupper(digitalTable[idRow].label),"PIOGGIA"))
				*id_digital_pioggia=idRow;
			idRow++;
		}
	}
	mysql_free_result(result);

	if(!onlyupdate)
	{
		for(i=0;i<NUMSYSTEMS;i++)
			for(k=0;k<systems[i].in_ch_d;k++)
				if(deviceToid[1][i][k]==-1)
				{
					deviceToid[1][i][k]=idRow;
					idRow++;
				}
	
		if(idRow!=DIGITALCHANNELS)
			my_printf("there's a problem with digital channels\n");
	}
	mysql_close(conn);
	return(0);
}
Esempio n. 29
0
bool CommandLine::parse(int argc,char **argv)
{
	std::string _render3d;

	int opt_help = 0;
	int option_index = 0;
	for(;;)
	{
		//libretro-common's optional argument is not supported presently
		static struct option long_options[] =
		{
			//stuff
			{ "help", no_argument, &opt_help, 1 },

			//user settings
			{ "num-cores", required_argument, NULL, OPT_NUMCORES },
			{ "spu-synch", no_argument, &_spu_sync_mode, 1 },
			{ "spu-method", required_argument, NULL, OPT_SPU_METHOD },
			{ "3d-render", required_argument, NULL, OPT_3D_RENDER },
			{ "3d-texture-deposterize-enable", no_argument, &_texture_deposterize, 1 },
			{ "3d-texture-upscale", required_argument, NULL, OPT_3D_TEXTURE_UPSCALE },
			{ "3d-texture-smoothing-enable", no_argument, &_texture_smooth, 1 },
			#ifdef HOST_WINDOWS
				{ "gpu-resolution-multiplier", required_argument, NULL, OPT_GPU_RESOLUTION_MULTIPLIER },
				{ "windowed-fullscreen", no_argument, &windowed_fullscreen, 1 },
			#else
				{ "nojoy", no_argument, &_commandline_linux_nojoy, 1},
			#endif
			{ "disable-sound", no_argument, &disable_sound, 1},
			{ "disable-limiter", no_argument, &disable_limiter, 1},
			{ "rtc-day", required_argument, NULL, OPT_RTC_DAY},
			{ "rtc-hour", required_argument, NULL, OPT_RTC_HOUR},

			//sync settings
			#ifdef HAVE_JIT
				{ "jit-enable", no_argument, &_cpu_mode, 1},
				{ "jit-size", required_argument, NULL, OPT_JIT_SIZE },
			#endif
			{ "rigorous-timing", no_argument, &_rigorous_timing, 1},
			{ "advanced-timing", no_argument, &_advanced_timing, 1},
			{ "gamehacks", no_argument, &_gamehacks, 1},
			{ "spu-advanced", no_argument, &_spu_advanced, 1},
			{ "backupmem-db", no_argument, &autodetect_method, 1},

			//system equipment
			{ "console-type", required_argument, NULL, OPT_CONSOLE_TYPE },
			{ "bios-arm9", required_argument, NULL, OPT_ARM9},
			{ "bios-arm7", required_argument, NULL, OPT_ARM7},
			{ "bios-swi", no_argument, &_bios_swi, 1},
			{ "firmware-path", required_argument, NULL, OPT_FIRMPATH},
			{ "firmware-boot", required_argument, NULL, OPT_FIRMBOOT},
			{ "lang", required_argument, NULL, OPT_LANGUAGE},

			//slot-1 contents
			{ "slot1", required_argument, NULL, OPT_SLOT1},
			{ "preload-rom", no_argument, &_load_to_memory, 1},
			{ "slot1-fat-dir", required_argument, NULL, OPT_SLOT1_FAT_DIR},
			//and other slot-1 option
			{ "slot1-no8000prot", no_argument, &_slot1_no8000prot, 1},

			//slot-2 contents
			{ "cflash-image", required_argument, NULL, OPT_SLOT2_CFLASH_IMAGE},
			{ "cflash-path", required_argument, NULL, OPT_SLOT2_CFLASH_DIR},
			{ "gbaslot-rom", required_argument, NULL, OPT_SLOT2_GBAGAME},

			//commands
			{ "start-paused", no_argument, &start_paused, 1},
			{ "load-slot", required_argument, NULL, OPT_LOAD_SLOT},
			{ "play-movie", required_argument, NULL, OPT_PLAY_MOVIE},
			{ "record-movie", required_argument, NULL, OPT_RECORD_MOVIE},

			//video filters
			{ "scanline-filter-a", required_argument, NULL, OPT_SCANLINES_A},
			{ "scanline-filter-b", required_argument, NULL, OPT_SCANLINES_B},
			{ "scanline-filter-c", required_argument, NULL, OPT_SCANLINES_C},
			{ "scanline-filter-d", required_argument, NULL, OPT_SCANLINES_D},

			//debugging
			#ifdef GDB_STUB
				{ "arm9gdb", required_argument, NULL, OPT_ARM9GDB},
				{ "arm7gdb", required_argument, NULL, OPT_ARM7GDB},
			#endif

			//utilities
			{ "advanscene-import", required_argument, NULL, OPT_ADVANSCENE},
				
			{0,0,0,0}
		};

		int c = getopt_long(argc,argv,"",long_options,&option_index);
		if(c == -1) break;
		if(c == '?') 
			break;

		switch(c)
		{
		case 0: break;

		//user settings
		case OPT_NUMCORES: _num_cores = atoi(optarg); break;
		case OPT_SPU_METHOD: _spu_sync_method = atoi(optarg); break;
		case OPT_3D_RENDER: _render3d = optarg; break;
		case OPT_3D_TEXTURE_UPSCALE: texture_upscale = atoi(optarg); break;
		case OPT_GPU_RESOLUTION_MULTIPLIER: gpu_resolution_multiplier = atoi(optarg); break;

		//RTC settings
		case OPT_RTC_DAY: _rtc_day = atoi(optarg); break;
		case OPT_RTC_HOUR: _rtc_hour = atoi(optarg); break;

		//sync settings
		case OPT_JIT_SIZE: _jit_size = atoi(optarg); break;

		//system equipment
		case OPT_CONSOLE_TYPE: console_type = optarg; break;
		case OPT_ARM9: _bios_arm9 = strdup(optarg); break;
		case OPT_ARM7: _bios_arm7 = strdup(optarg); break;
		case OPT_FIRMPATH: _fw_path = strdup(optarg); break;
		case OPT_FIRMBOOT: _fw_boot = atoi(optarg); break;

		//slot-1 contents
		case OPT_SLOT1: slot1 = strtoupper(optarg); break;
		case OPT_SLOT1_FAT_DIR: slot1_fat_dir = optarg; break;

		//slot-2 contents
		case OPT_SLOT2_CFLASH_IMAGE: cflash_image = optarg; break;
		case OPT_SLOT2_CFLASH_DIR: _cflash_path = optarg; break;
		case OPT_SLOT2_GBAGAME: _gbaslot_rom = optarg; break;

		//commands
		case OPT_LOAD_SLOT: load_slot = atoi(optarg);  break;
		case OPT_PLAY_MOVIE: play_movie_file = optarg; break;
		case OPT_RECORD_MOVIE: record_movie_file = optarg; break;

		//video filters
		case OPT_SCANLINES_A: _scanline_filter_a = atoi(optarg); break;
		case OPT_SCANLINES_B: _scanline_filter_b = atoi(optarg); break;
		case OPT_SCANLINES_C: _scanline_filter_c = atoi(optarg); break;
		case OPT_SCANLINES_D: _scanline_filter_d = atoi(optarg); break;

		//debugging
		case OPT_ARM9GDB: arm9_gdb_port = atoi(optarg); break;
		case OPT_ARM7GDB: arm7_gdb_port = atoi(optarg); break;

		//utilities
		case OPT_ADVANSCENE: CommonSettings.run_advanscene_import = optarg; break;
		case OPT_LANGUAGE: language = atoi(optarg); break;
		}
	} //arg parsing loop

	if(opt_help)
	{
		printf(help_string);
		exit(1);
	}

	if(_load_to_memory != -1) CommonSettings.loadToMemory = (_load_to_memory == 1)?true:false;
	if(_num_cores != -1) CommonSettings.num_cores = _num_cores;
	if(_rigorous_timing) CommonSettings.rigorous_timing = true;
	if(_advanced_timing != -1) CommonSettings.advanced_timing = _advanced_timing==1;
	if(_gamehacks != -1) CommonSettings.gamehacks.en = _gamehacks==1;

#ifdef HAVE_JIT
	if(_cpu_mode != -1) CommonSettings.use_jit = (_cpu_mode==1);
	if(_jit_size != -1) 
	{
		if ((_jit_size < 1) || (_jit_size > 100)) 
			CommonSettings.jit_max_block_size = 100;
		else
			CommonSettings.jit_max_block_size = _jit_size;
	}
#endif

	//process console type
	CommonSettings.DebugConsole = false;
	CommonSettings.ConsoleType = NDS_CONSOLE_TYPE_FAT;
	console_type = strtoupper(console_type);
	if(console_type == "") {}
	else if(console_type == "FAT") CommonSettings.ConsoleType = NDS_CONSOLE_TYPE_FAT;
	else if(console_type == "LITE") CommonSettings.ConsoleType = NDS_CONSOLE_TYPE_LITE;
	else if(console_type == "IQUE") CommonSettings.ConsoleType = NDS_CONSOLE_TYPE_IQUE;
	else if(console_type == "DSI") CommonSettings.ConsoleType = NDS_CONSOLE_TYPE_DSI;
	else if(console_type == "DEBUG")
	{
		CommonSettings.ConsoleType = NDS_CONSOLE_TYPE_FAT;
		CommonSettings.DebugConsole = true;
	}

	//process 3d renderer 
	_render3d = strtoupper(_render3d);
	if(_render3d == "NONE") render3d = COMMANDLINE_RENDER3D_NONE;
	else if(_render3d == "SW") render3d = COMMANDLINE_RENDER3D_SW;
	else if(_render3d == "OLDGL") render3d = COMMANDLINE_RENDER3D_OLDGL;
	else if(_render3d == "AUTOGL") render3d = COMMANDLINE_RENDER3D_AUTOGL;
	else if(_render3d == "GL") render3d = COMMANDLINE_RENDER3D_GL;

	if (_texture_deposterize != -1) CommonSettings.GFX3D_Renderer_TextureDeposterize = (_texture_deposterize == 1);
	if (_texture_smooth != -1) CommonSettings.GFX3D_Renderer_TextureSmoothing = (_texture_smooth == 1);

	if (autodetect_method != -1)
		CommonSettings.autodetectBackupMethod = autodetect_method;

	//TODO NOT MAX PRIORITY! change ARM9BIOS etc to be a std::string
	if(_bios_arm9) { CommonSettings.UseExtBIOS = true; strcpy(CommonSettings.ARM9BIOS,_bios_arm9); }
	if(_bios_arm7) { CommonSettings.UseExtBIOS = true; strcpy(CommonSettings.ARM7BIOS,_bios_arm7); }
	#ifndef HOST_WINDOWS 
		if(_fw_path) { CommonSettings.UseExtFirmware = true; CommonSettings.UseExtFirmwareSettings = true; strcpy(CommonSettings.ExtFirmwarePath,_fw_path); }
	#endif
	if(_fw_boot) CommonSettings.BootFromFirmware = true;
	if(_bios_swi) CommonSettings.SWIFromBIOS = true;
	if(_slot1_no8000prot) CommonSettings.RetailCardProtection8000 = false;
	if(_spu_sync_mode != -1) CommonSettings.SPU_sync_mode = _spu_sync_mode;
	if(_spu_sync_method != -1) CommonSettings.SPU_sync_method = _spu_sync_method;
	if(_spu_advanced) CommonSettings.spu_advanced = true;

	free(_bios_arm9);
	free(_bios_arm7);
	_bios_arm9 = _bios_arm7 = NULL;

	//remaining argument should be an NDS file, and nothing more
	int remain = argc-optind;
	if(remain==1)
		nds_file = argv[optind];
	else if(remain>1) return false;
	
	return true;
}
Esempio n. 30
0
void aggregator_element_start(void * parser, const char *wname, const char **atts)
{
	map <string, string> attributes;
		
	int i = 0;
#if BT_SIZEOFWCHAR == 2
	size_t size_name = 256;
	size_t len;
	char * name = (char *) malloc( size_name + 1 );
	const wchar_t ** a = (const wchar_t **) atts;
	while( a[i] )
	{
		string key, value;
		len = wcslen( (const wchar_t *) a[i] );
		if( len > size_name ) {
			size_name = len;
			free( name );
			name = (char*) malloc( size_name + 1 );
		}
		wcstombs( name, (const wchar_t *) a[i], size_name);
		strtoupper( name );
		key = string( name );
		i++;
		
		len = wcslen( (const wchar_t *) a[i] );
		if( len > size_name ) {
			size_name = len;
			free( name );
			name = (char*) malloc( size_name + 1 );
		}
		wcstombs( name, (const wchar_t *) a[i], size_name);
		value = string( name );
		i ++;
		attributes[ key ] = value;
	}
	len = wcslen( (const wchar_t *) wname );
	if( len > size_name ) {
		size_name = len;
		free( name );
		name = (char*) malloc( size_name + 1 );
	}
	wcstombs( name, (const wchar_t *) wname, size_name);
#else
	int size_name = 0;
	char * name = (char *) wname;
	while( atts[i] )
	{
		string key, value;
		strtoupper( (char *) atts[i] );
		key = string( atts[i] );
		i++;
		value = string( atts[i] );
		i ++;
		attributes[ key ] = value;
	}
#endif
	
	strtoupper( name );

	if( !strcmp(name, "IMAGE" ) ||
		!strcmp(name, "TEXTINPUT" ) ||
		!strcmp(name, "CONTENT" ) ||
		!strcmp(name, "SUMMARY" ) ||
		!strcmp(name, "TAGLINE" ) ||
		!strcmp(name, "SUBTITLE" ) ||
		!strcmp(name, "LOGO" ) ||
		!strcmp(name, "INFO" ) )
	{
		element = string( name );
	}

	if( !strcmp(name, "ID" ) )
	{
		if (element != "ITEM") {
			element = name;
		}
	}

	if( !strcmp(name, "LINK" ) )
	{
		if ( isset(attributes["REL"]) && attributes["REL"] == "alternate") 
		{
			if ( element == "ITEM" ) 
			{
				items[item]["LINK"] = attributes["HREF"];
			}
			else 
			{
				channel["LINK"] = attributes["HREF"];
			}
		}	
	}

	if( !strcmp(name, "ITEM" ) )
	{
		item ++;
		element = name;
	}

	if( !strcmp(name, "ENTRY" ) )
	{
		item ++;
		element = "ITEM";
	}

	tag = name;
	
	if( size_name > 0 ) free( name );
}