コード例 #1
0
ファイル: a_strex.c プロジェクト: endlessm/shim
static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
                       ASN1_STRING *str)
{
    int outlen, len;
    int type;
    char quotes;
    unsigned char flags;
    quotes = 0;
    /* Keep a copy of escape flags */
    flags = (unsigned char)(lflags & ESC_FLAGS);

    type = str->type;

    outlen = 0;

    if (lflags & ASN1_STRFLGS_SHOW_TYPE) {
        const char *tagname;
        tagname = ASN1_tag2str(type);
        outlen += strlen(tagname);
        if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1))
            return -1;
        outlen++;
    }

    /* Decide what to do with type, either dump content or display it */

    /* Dump everything */
    if (lflags & ASN1_STRFLGS_DUMP_ALL)
        type = -1;
    /* Ignore the string type */
    else if (lflags & ASN1_STRFLGS_IGNORE_TYPE)
        type = 1;
    else {
        /* Else determine width based on type */
        if ((type > 0) && (type < 31))
            type = tag2nbyte[type];
        else
            type = -1;
        if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
            type = 1;
    }

    if (type == -1) {
        len = do_dump(lflags, io_ch, arg, str);
        if (len < 0)
            return -1;
        outlen += len;
        return outlen;
    }

    if (lflags & ASN1_STRFLGS_UTF8_CONVERT) {
        /*
         * Note: if string is UTF8 and we want to convert to UTF8 then we
         * just interpret it as 1 byte per character to avoid converting
         * twice.
         */
        if (!type)
            type = 1;
        else
            type |= BUF_TYPE_CONVUTF8;
    }

    len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
    if (len < 0)
        return -1;
    outlen += len;
    if (quotes)
        outlen += 2;
    if (!arg)
        return outlen;
    if (quotes && !io_ch(arg, "\"", 1))
        return -1;
    if (do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0)
        return -1;
    if (quotes && !io_ch(arg, "\"", 1))
        return -1;
    return outlen;
}
コード例 #2
0
ファイル: program.c プロジェクト: ZhangYanPeng/ACM
int main(){
  int i,j;
  int ac[15];
  char buf[1000];
  int st;
  char c;
  int a,b;
  int num=0;
  int check;
  while(1){
    num++;
    scanf("%d %d %d",&n,&m,&k);
    if(!m&&!n&&!k)
      break;
    if(num>1)
      printf("\n");
    printf("NTA%d:\n",num);
    gets(buf);
    for(i=0;i<n;i++){
      for(j=0;j<k;j++){
	tr[i][j] = createlist();
	gets(buf);
	if(buf[0]){
	  while(1){
	    sscanf(buf,"%d %d",&a,&b);
	    do_buf(buf);
	    tr[i][j]=addlist(tr[i][j],a,b);
	    if(buf[0]){
	      break;
	      return 0;
	    }
	  }
	}
      }
    }

    while(1){
      scanf("%d",&level);
      if(level<0)
	break;
      for(i=0;i<((int)pow(2,level+1)-1);i++){
	while(1){
	  scanf("%c",&c);
	  if('a'<=c && c<='z' || c=='*'){
	    tree[i]=c;
	    break;
	  }
	}
      }
      
      getac(ac,0);
      check=0;
      for(i=0;i<n;i++){
	if(ac[i]){
	  printf("Valid\n");
	  check=1;
	  break;
	}
      }
      if(!check)
	printf("Invalid\n");
    }
    for(i=0;i<n;i++)
      for(j=0;j<k;j++)
	free(tr[i][j]);
  }
  return 0;
}