Esempio n. 1
0
char*
StringMoveHistory(MemorySlice *history, bool abbrev)
{
  Move move;
  Memory *curr;
  Side side = White;
  StringBuilder builder = NewStringBuilder();
  int fullMoveCount = 1;

  for(curr = history->Vals; curr != history->Curr; curr++) {
    move = curr->Move;

    if(abbrev) {
      AppendString(&builder, "%s ", StringMove(move));
    } else {
      switch(side) {
      case White:
        AppendString(&builder, "%d. %s",
                     fullMoveCount, StringMove(move));
        break;
      case Black:
        AppendString(&builder, " %s\n",
                     StringMove(move));

        fullMoveCount++;

        break;
      }
    }

    side = OPPOSITE(side);
  }

  return builder.Length == 0 ? NULL : BuildString(&builder, true);
}
Esempio n. 2
0
// Test that our search finds example mates in one.
char*
TestMatesInTwo()
{
  char *fen;
  Game game;
  int i, dummyVal;
  Move actual, expected;
  uint64_t dummy = 0;

  StringBuilder builder = NewStringBuilder();

  for(i = 0; i < COUNT; i++) {
    fen = fens[i];
    expected = ParseMove(mates[i]);

    game = ParseFen(fen);
    actual = Search(&game, &dummy, &dummyVal, 3);    

    if(actual != expected) {
      AppendString(&builder, "Search failed mate-in-two for:-\n\n"
                   "%s\n"
                   "Expected move %s, engine selected %s.\n\n",
                   StringChessSet(&game.ChessSet), StringMove(expected), StringMove(actual));
    }
  }

  return builder.Length == 0 ? NULL : BuildString(&builder, true);
}
Esempio n. 3
0
/*****************************************************************************
*
*   PersonIdPrint(pip, buf)
*
*****************************************************************************/
NLM_EXTERN CharPtr PersonIdPrint(PersonIdPtr pip, CharPtr buf)
{
	CharPtr tmp;
	NameStdPtr nsp;

	if (buf == NULL) return NULL;

	tmp = buf;
	*tmp = '?';
	*(tmp + 1) = '\0';

	if (pip == NULL) return buf;

	if (pip->choice == 2)    /* std */
	{
		nsp = (NameStdPtr) (pip->data);
		if (nsp != NULL)
		{
			if (nsp->names [3] != NULL)                 /* full name */
				tmp = StringMove(tmp, nsp->names [3]);
			else if (nsp->names[0] != NULL)             /* make from parts */
			{
				if (nsp->names [1] != NULL && nsp->names [2] != NULL)
				{
					tmp = StringMove(tmp, nsp->names [1]);	/* first */
					*tmp = ' '; tmp++; *tmp='\0';
					tmp = StringMove(tmp, nsp->names [2]);	/* middle */
					*tmp = ' '; tmp++; *tmp='\0';
				}
				else if ((nsp->names [4] != NULL) &&
						(nsp->names [0] != NULL) &&
						(StringLen(nsp->names[4]) < 10))
				{
					tmp = StringMove(tmp, nsp->names [4]);  /* initials */
					*tmp = ' '; tmp++; *tmp='\0';
				}
				else if (nsp->names [1] != NULL)
				{
					tmp = StringMove(tmp, nsp->names [1]);
					*tmp = ' '; tmp++; *tmp='\0';
				}
				tmp = StringMove(tmp, nsp->names [0]);		/* last */
				if (nsp->names[5] != NULL)                  /* suffix */
				{
					*tmp = ' '; tmp++; *tmp='\0';
					tmp = StringMove(tmp, nsp->names[5]);
				}
			}
		}
	}
	else if (pip->choice == 3 || pip->choice == 4) /* ml or str */
		StringMove(tmp, (CharPtr)(pip->data));

	return buf;
}
Esempio n. 4
0
/*****************************************************************************
*
*   CharPtr AsnTypeDumpStack(str, aip)
*   	dump a typestack into str
*       returns a pointer to the '\0' at the end of the str
*
*****************************************************************************/
NLM_EXTERN CharPtr LIBCALL  AsnTypeDumpStack (CharPtr str, AsnIoPtr aip)
{
    Int2 level, isa, lastnochoice;

    lastnochoice = -1;
    *str = '\0';

	for(level = 0; level <= aip->type_indent; level++)
	{
		if (level == aip->type_indent)
		{
			if ((aip->type & ASNIO_OUT) ||
				((aip->type & ASNIO_IN) && (aip->read_id == FALSE)))
				str = StringMove(str, "<");
		}
		if (aip->typestack[level].type == NULL)
			str = StringMove(str, " ");
		else
		{
			isa = AsnFindBaseIsa(aip->typestack[level].type);
            if (aip->typestack[level].type->name != NULL)
                str = StringMove(str, aip->typestack[level].type->name);
            else if ((lastnochoice == SEQOF_TYPE) ||
                        (lastnochoice == SETOF_TYPE))
                str = StringMove(str, "E");
            else
                str = StringMove(str, "?");
            if (isa != CHOICE_TYPE)
                lastnochoice = isa;
		}
        if (level != aip->type_indent)
            str = StringMove(str, ".");
		else
		{
			if ((aip->type & ASNIO_OUT) ||
				((aip->type & ASNIO_IN) && (aip->read_id == FALSE)))
				str = StringMove(str, ">");
		}
	}
	return str;
}
Esempio n. 5
0
static void PrintSequence (BioseqPtr bsp, SeqFeatPtr sfp,
                           FILE *fp, Boolean is_na)

{
  Char        buffer [255];
  Uint1       code;
  Int2        count;
  Uint1       repr;
  Uint1       residue;
  SeqPortPtr  spp;
  CharPtr     title;
  CharPtr     tmp;

  if (bsp != NULL && fp != NULL) {
    if ((Boolean) ISA_na (bsp->mol) == is_na) {
      repr = Bioseq_repr (bsp);
      if (repr == Seq_repr_raw || repr == Seq_repr_const) {
        title = BioseqGetTitle (bsp);
        tmp = StringMove (buffer, ">");
        tmp = SeqIdPrint (bsp->id, tmp, PRINTID_FASTA_LONG);
        tmp = StringMove (tmp, " ");
        StringNCpy (tmp, title, 200);
        fprintf (fp, "%s\n", buffer);
		if (pmon != NULL)
			MonitorStrValue(pmon, buffer);
        if (is_na) {
          code = Seq_code_iupacna;
        } else {
          code = Seq_code_iupacaa;
        }
        if (sfp != NULL) {
          spp = SeqPortNewByLoc (sfp->location, code);
        } else {
          spp = SeqPortNew (bsp, 0, -1, 0, code);
        }
        if (spp != NULL) {
          count = 0;
          while ((residue = SeqPortGetResidue (spp)) != SEQPORT_EOF) {
            if (! IS_residue (residue)) {
              buffer [count] = '\0';
              fprintf (fp, "%s\n", buffer);
              count = 0;
              switch (residue) {
                case SEQPORT_VIRT :
                  fprintf (fp, "[Gap]\n");
                  break;
                case SEQPORT_EOS :
                  fprintf (fp, "[EOS]\n");
                  break;
                default :
                  fprintf (fp, "[Invalid Residue]\n");
                  break;
              }
            } else {
              buffer [count] = residue;
              count++;
              if (count >= CHARSPERLINE) {
                buffer [count] = '\0';
                fprintf (fp, "%s\n", buffer);
                count = 0;
              }
            }
          }
          if (count != 0) {
            buffer [count] = '\0';
            fprintf (fp, "%s\n", buffer);
          }
          SeqPortFree (spp);
        }
      }
    }
  }
}
Esempio n. 6
0
/*****************************************************************************
*
*   FileBuildPath()
*
*****************************************************************************/
NLM_EXTERN Nlm_CharPtr LIBCALL  Nlm_FileBuildPath (Nlm_CharPtr root, Nlm_CharPtr sub_path, Nlm_CharPtr filename)

{
    Nlm_CharPtr tmp;
    Nlm_Boolean dir_start = FALSE;
#ifdef OS_VMS
  Nlm_Boolean had_root = FALSE;
#endif

    if (root == NULL)              /* no place to put it */
        return NULL;

    tmp = root;
    if (*tmp != '\0')                /* if not empty */
    {
#ifndef OS_VMS
        dir_start = TRUE;
#else
        had_root = TRUE;
#endif
        while (*tmp != '\0')
        {
#ifdef OS_VMS
            if (*tmp == '[')
                dir_start = TRUE;
#endif
            tmp++;
        }

        if ((*(tmp - 1) != DIRDELIMCHR) && (dir_start))
        {
            *tmp = DIRDELIMCHR;
            tmp++; *tmp = '\0';
        }
    }

    if (sub_path != NULL)
    {
#ifdef OS_VMS
        if (dir_start)
        {
            *(tmp-1) = '.';
            if (*sub_path == '[')
                sub_path++;
        }
        else if ((had_root) && (*sub_path != '['))
        {
            *tmp = '[';
            tmp++; *tmp = '\0';
        }
#else
        if ((dir_start) && (*sub_path == DIRDELIMCHR))
            sub_path++;
#endif
        tmp = StringMove(tmp, sub_path);
        if (*(tmp-1) != DIRDELIMCHR)
        {
            *tmp = DIRDELIMCHR;
            tmp++; *tmp = '\0';
        }
    }

    if (filename != NULL)
        StringMove(tmp, filename);

    return root;
}
Esempio n. 7
0
static void AddXMLname(AsnTypePtr atp, AsnTypePtr PNTR typestack, Int2 stackptr)
{
	Char buf[80];
	AsnTypePtr atp2;
	Boolean found=FALSE, getparent=TRUE, doitem = FALSE, done = FALSE;
	CharPtr tmp;
	Int2 i, isa;

	if (atp->XMLname == NULL)   /* only do it once */
	{
		tmp = buf; *tmp = '\0';
		if (atp->name == NULL)
		{
			doitem = TRUE;
		}
		else if (IS_UPPER(*(atp->name)))
		{
			getparent = FALSE;
			tmp = StringMove(tmp, atp->name);
		}

		if ((getparent) && (stackptr))
		{
			atp2 = typestack[stackptr - 1];
			isa = AsnFindBaseIsa(atp2);
			if ((doitem) && ((isa == SEQOF_TYPE) || (isa == SETOF_TYPE)))
			{
				atp2 = AsnFindBaseTypeDTD(atp);
				if (atp2 != NULL)
				{
				if (atp2->name == NULL)
				{
					atp2 = typestack[stackptr - 1];
					if (atp->type != NULL)
					{
						if (ISA_BASETYPE(atp->type->isa))
						{
							if (atp2->XMLname != NULL)
							{
								tmp = StringMove(tmp, atp2->XMLname);
								getparent = FALSE;
								found = TRUE;
							}
						}
					}
				}
				else
				{
					if (atp2->XMLname != NULL)
						tmp = StringMove(tmp, atp2->XMLname);
					else if (atp2->name != NULL)
						tmp = StringMove(tmp, atp2->name);
					if (*buf != '\0')
					{
						doitem = FALSE;
						getparent = FALSE;
						done = TRUE;
						found = TRUE;
					}
				}
				}
			}

			atp2 = typestack[stackptr - 1];
			if ((getparent) && (atp2->XMLname != NULL))  /* already nested */
			{
				tmp = StringMove(tmp, atp2->XMLname);
				tmp = StringMove(tmp, "_");
				getparent = FALSE;
				found = TRUE;
			}

			if ((stackptr) && (getparent))
			{
				found = FALSE;

				for (i = (stackptr - 1); (i >= 0) && (! found); i--)
				{
					atp2 = AsnFindBaseTypeDTD(typestack[i]);
					if ((atp2 != NULL) && (atp2->name != NULL) && (IS_UPPER(*(atp2->name))))
					{
						while (i < stackptr)
						{
							atp2 = AsnFindBaseTypeDTD(typestack[i]);
							if (atp2->name == NULL)
								tmp = StringMove(tmp, "E");
							else
								tmp = StringMove(tmp, atp2->name);
							tmp = StringMove(tmp, "_");
							i++;
						}
						found = TRUE;
					}
				}
			}

			if ((! done) && found)
			{
				if (doitem)
					tmp = StringMove(tmp, "_E");
				else
					tmp = StringMove(tmp, atp->name);
			}
		}


		if (*buf != '\0')
		{
			atp->XMLname = StringSave(buf);
		}
	}

	atp2 = AsnFindBaseTypeDTD(atp);
	if ((! atp->imported) && (atp2 != NULL) && (atp2->type != NULL))
	{
		isa = atp2->type->isa;
		if ((isa == SEQ_TYPE) || (isa == SET_TYPE))
		{
			typestack[stackptr] = atp;
			for (atp2 = atp->branch; atp2 != NULL; atp2 = atp2->next)
				AddXMLname(atp2, typestack, (Int2)(stackptr + 1));
		}
		else if ((isa == SEQOF_TYPE) || (isa == SETOF_TYPE))
		{
			typestack[stackptr] = atp;
			for (atp2 = atp->branch; atp2 != NULL; atp2 = atp2->next)
				AddXMLname(atp2, typestack, (Int2)(stackptr + 1));
		}			
		else if (isa == CHOICE_TYPE)
		{
			typestack[stackptr] = atp;
			for (atp2 = atp->branch; atp2 != NULL; atp2 = atp2->next)
				AddXMLname(atp2, typestack, (Int2)(stackptr + 1));
		}
	}

	return;

}
Esempio n. 8
0
NLM_EXTERN Nlm_Boolean LIBCALL StringSubString(char FAR *theString, char FAR *Find, char FAR *Replace, Nlm_Int4 MaxLength)
/* replaces all non-overlapping instances of the string Find in the
   string theString with the string Replace. The strings do not have to be the 
   same size. The new string is truncated at MaxLength characters
   Including the final NULL). If MaxLength is zero, the string's current
   length is presumed to be the maximum.
   It returns TRUE if any strings were replaced, else FALSE.
   */
{
  Nlm_CharPtr FindPtr,ComparePtr,StringPtr,NewString, NewStringPtr;
  Nlm_Int4 SpaceNeeded,Len;
  Nlm_Boolean Replaced = FALSE;

  if (*Find == NULLB)
    return(FALSE);

  Len = Nlm_StringLen(theString);
  SpaceNeeded = MAX( (Nlm_Int4)((Len * Nlm_StringLen(Replace) 
				 * sizeof(Nlm_Char) )
				/ Nlm_StringLen(Find) + 1),Len) + 1;

  NewStringPtr = NewString = (Nlm_CharPtr)
    Nlm_MemGet((size_t)SpaceNeeded, MGET_ERRPOST);

  StringPtr = theString;
  while (*StringPtr != NULLB)
    {
      FindPtr = Find;
      ComparePtr = StringPtr;
      while ( (*FindPtr != NULLB) && (*FindPtr == *ComparePtr) )
	{
	  FindPtr++;
	  ComparePtr++;
	}
      
      /* if we found the entire string, replace it. */
      if (*FindPtr == NULLB)
	{
	  NewStringPtr = StringMove(NewStringPtr,Replace);
	  StringPtr = ComparePtr;
	  Replaced = TRUE;
	}
      else
	/* otherwise, move on to the next character. */
	*NewStringPtr++ = *StringPtr++;
    }
  *NewStringPtr = NULLB;

  if (MaxLength <= 0)
    MaxLength = strlen(theString) + 1;

  /* Truncate the string, if necessary.*/
  if ((Nlm_Int4)strlen(NewString) >= MaxLength - 1)
    {
      NewString[MaxLength-1] = NULLB;
    }
    
  Nlm_StringCpy(theString,NewString);
  Nlm_MemFree(NewString);

  return(Replaced);
}
Esempio n. 9
0
void BioseqRawToRaw(BioseqPtr bsp, Boolean idonly,
              short whichSeq, short *seqnum,
              char **seq, char **seqid, long *seqlen)
{
  SeqPortPtr spp;
  SeqIdPtr bestid;
  Uint1 repr, code, residue;
  CharPtr tmp, title;
  long  outlen, outmax;
  char  localid[256], *sp;

  /* !!! this may be called several times for a single sequence
    because SeqEntryExplore looks for parts and joins them...
    assume seq, seqid, seqlen may contain data (or NULL)
  */
  if (bsp == NULL) return;
  repr = Bioseq_repr(bsp);
  if (!(repr == Seq_repr_raw || repr == Seq_repr_const)) return;

  (*seqnum)++;
  if (!(whichSeq == *seqnum || whichSeq == 0)) return;

  bestid = SeqIdFindBest(bsp->id, (Uint1) 0);
  title = BioseqGetTitle(bsp);
  if (idonly) {
    sprintf(localid, " %d)  ", *seqnum);
    tmp= localid + strlen(localid)-1;
    }
  else {
    strcpy(localid," ");
    tmp= localid;
    }
  tmp = SeqIdPrint(bestid, tmp, PRINTID_FASTA_SHORT);
  tmp = StringMove(tmp, " ");
  StringNCpy(tmp, title, 200);
/* fprintf(stderr,"BioseqRawToRaw: localid='%s'\n",localid); */

          /* < seqid is fixed storage */
  /* strcpy( *seqid, localid);  */
          /* < seqid is variable sized */
  outmax= strlen(localid) + 3;
  if (*seqid==NULL) {
    *seqid= (char*) malloc(outmax);
    if (*seqid==NULL) return;
    strcpy(*seqid, localid);
    }
  else {
    outmax += strlen(*seqid) + 2;
    *seqid= (char*) realloc( *seqid, outmax);
    if (*seqid==NULL) return;
    if (!idonly) strcat(*seqid, "; ");
    strcat(*seqid, localid);
    }

  if (idonly) {
    strcat(*seqid,"\n");
    return;
    }

  if (ISA_na(bsp->mol)) code = Seq_code_iupacna;
  else code = Seq_code_iupacaa;
  spp = SeqPortNew(bsp, 0, -1, 0, code);
  SeqPortSeek(spp, 0, SEEK_SET);

  sp= *seq;
  if (sp==NULL) {  /* this is always true now !? */
    outlen= 0;
    outmax= 500;
    sp= (char*) malloc(outmax);
    }
  else {
    outlen= strlen(sp);
    outmax= outlen + 500;
    sp= (char*) realloc( sp, outmax);
    }
  if (sp==NULL) return;

  while ((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF) {
    if (outlen>=outmax) {
      outmax= outlen + 500;
      sp= (char*) realloc(sp, outmax);
      if (sp==NULL) return;
      }
    sp[outlen++] = residue;
    }
  sp= (char*) realloc(sp, outlen+1);
  if (sp!=NULL) sp[outlen]= '\0';
  *seq= sp;
  *seqlen= outlen;
  SeqPortFree(spp);
  return;
}
Esempio n. 10
0
Int2 Main (void)
{
    Int2 m_argModuleIn=0, f_arg_moduleOut=1, 
	X_argDTDModuleOut=2, T_argTreeDumpOut=3, 
	v_argPrintFileIn = 4, p_argPrintFileOut = 5,
	x_argXMLDataOut=6, d_argBinaryFileIn = 7
	, t_argAsnTypeName = 8, e_argBinaryFileOut = 9
	, o_argHeadFile = 10, l_argLoadFile = 11
	, b_argBufferSize = 12, w_argTokenMax = 13
	/*--- args below here are capitilized and for code generation, only--*/
	/*--  Except for the 'M' arg, which will also affect normal use ---*/
	, G_argGenerateCode = 14, M_argMoreModuleFiles = 15
	, B_argCodeFileName = 16, D_argCodeGenDebugLevel = 17
	, S_argDebugFileName = 18, I_argExtraIncludeName = 19
	, Z_argBitTwiddle = 20, K_argLoadName = 21
	, J_objMgrEntry = 22, L_objMgrLabel = 23, P_argXMLmodulePrefix = 24
	, V_argChoiceStruct = 25;

	AsnIoPtr aip = NULL,
		aipout = NULL,
		xaipout = NULL,
		aipencode = NULL;
	FILE * fp;
	AsnModulePtr amp = NULL,
		currentmod = NULL,
		nextmod, thisamp;
	AsnTypePtr atp;
	Boolean print_each_module = FALSE;
	AsnCodeInfoPtr acip = (AsnCodeInfoPtr)MemNew(sizeof(AsnCodeInfo));
	CharPtr filename = NULL, p, last_comma, objmgrentry = NULL;
	int len;


    /* never abort on error, but show it */
    ErrSetFatalLevel(SEV_MAX);
    ErrSetMessageLevel(SEV_MIN);
    asnargs[P_argXMLmodulePrefix].defaultvalue = (const char *)AsnGetXMLmodulePrefix();

    if (! GetArgs("AsnTool 4", NUMARGS, asnargs))
	return 1;
    ErrClear();

    AsnSetXMLmodulePrefix((CharPtr)(asnargs[P_argXMLmodulePrefix].strvalue));

	/*
	if (! GetArgs("AsnTool 4", NUMARGS, asnargs))
		return 1;
        ErrClear();
    */

    if (! AsnIoSetBufsize(NULL, (Int2)asnargs[b_argBufferSize].intvalue))
        return 1;

    if ((aip = AsnIoOpen(asnargs[m_argModuleIn].strvalue, "r")) == NULL)
	{
	    ErrShow();
	    return 1;
	}

    acip -> loadname = asnargs[m_argModuleIn].strvalue;

    if (asnargs[K_argLoadName].strvalue != NULL) {
	acip -> loadname = asnargs[K_argLoadName].strvalue; /* overrides m_argModuleIn, if set */
    }

    if (asnargs[e_argBinaryFileOut].strvalue != NULL)    /* output a binary value file */
	if ((aipencode = AsnIoOpen(asnargs[e_argBinaryFileOut].strvalue, "wb")) == NULL)
	    {
		ErrShow();
		return 1;
	    }

				/**  parse the module(s)  ***/
	
    if (asnargs[f_arg_moduleOut].strvalue != NULL)
	{
	    if ((aipout = AsnIoOpen(asnargs[f_arg_moduleOut].strvalue, "w")) == NULL)
		{
		    ErrShow();
		    return 1;
		}
	}

    thisamp = NULL;
    while ((nextmod = AsnLexTReadModule(aip)) != NULL )
	{
	    if (thisamp == NULL)
		thisamp = nextmod;

	    if (amp == NULL)
		amp = nextmod;
	    else
		currentmod->next = nextmod;
	    currentmod = nextmod;
	}
    acip ->  last_amp = currentmod; /* last module of main file */
    AsnStoreTree(acip->loadname, thisamp); /* store and link tree */

    /*--- read additional module files that will be used for everything
      but code generation.
      ---*/

    if (asnargs[M_argMoreModuleFiles].strvalue != NULL)
	for (p = asnargs[M_argMoreModuleFiles].strvalue; *p; p = last_comma + 1) {
	    /*--- extract next filename for reading ASN.1 definitions ---*/
	    for (last_comma = p; *last_comma; last_comma++) {
	        if (*last_comma == ',')
		    break;
	    }
	    len = last_comma - p;
	    filename = (char *)MemFree (filename);
	    filename = (char *)MemNew (len + 1);
	    StringNCpy (filename, p, len);
	    filename[len] = '\0';
#ifdef WIN_DUMB
	    printf ("Loading %s \n", filename);
#endif

	    if ((aip = AsnIoOpen(filename, "r")) == NULL)
		{
		    ErrShow();
		    return 1;
		}
	    /*--- read the modules in this current file ---*/
	    thisamp = NULL;
	    while ((nextmod = AsnLexTReadModule(aip)) != NULL )
		{
		    if (thisamp == NULL)
			thisamp = nextmod;
		    if (amp == NULL)
			amp = nextmod;
		    else
			currentmod->next = nextmod;
		    currentmod = nextmod;
		}
	    AsnStoreTree(filename, thisamp); /* store and link tree */
	    if (!*last_comma)
	        break;
	    aip = AsnIoClose(aip);
	}

    aip = AsnIoClose(aip);

    if (amp == NULL)
	{
	    ErrPostEx(SEV_FATAL,0,0, "Unable to continue due to bad ASN.1 module");
	    ErrShow();
	    return 1;
	}


    if (asnargs[f_arg_moduleOut].strvalue != NULL)
	{
	    if ((aipout = AsnIoOpen(asnargs[f_arg_moduleOut].strvalue, "w")) == NULL)
		{
		    ErrShow();
		    return 1;
		}

	    currentmod = amp;
	    do
		{
		    AsnPrintModule(currentmod, aipout);
		    if (currentmod == acip->last_amp)  /* last main module */
			currentmod = NULL;
		    else
			currentmod = currentmod->next;
		} while (currentmod != NULL);

	    aipout = AsnIoClose(aipout);
	}
	
    if (asnargs[X_argDTDModuleOut].strvalue != NULL)
	{
	    Char tbuf[250];
	    CharPtr ptr;

	    if (! StringCmp(asnargs[X_argDTDModuleOut].strvalue, "m"))
		{
		    print_each_module = TRUE;
		}
	    else
		{
		    if ((aipout = AsnIoOpen(asnargs[X_argDTDModuleOut].strvalue, "wx")) == NULL)
			{
			    ErrShow();
			    return 1;
			}
		}

	    currentmod = amp;
	    do
		{
		    if (print_each_module)
			{
			    StringMove(tbuf, currentmod->modulename);
			    for (ptr = tbuf; *ptr != '\0'; ptr++)
				{
				    if (*ptr == '-')
					*ptr = '_';
				}
			    StringMove(ptr, ".dtd");

			    AsnPrintModuleXMLInc(currentmod, tbuf);

			    StringMove(ptr, ".mod");
				
			    aipout = AsnIoOpen(tbuf, "wx");
			}
			

		    AsnPrintModuleXML(currentmod, aipout);

		    if (print_each_module)
			aipout = AsnIoClose(aipout);

		    if (currentmod == acip->last_amp)  /* last main module */
			currentmod = NULL;
		    else
			currentmod = currentmod->next;
		} while (currentmod != NULL);

	    if (! print_each_module)
		aipout = AsnIoClose(aipout);
	}
	
    if (asnargs[T_argTreeDumpOut].strvalue != NULL)
	{
	    if ((fp = FileOpen(asnargs[T_argTreeDumpOut].strvalue, "w")) == NULL)
		{
		    ErrShow();
		    return 1;
		}

	    currentmod = amp;
	    do
		{
		    AsnPrintTreeModule(currentmod, fp);
		    if (currentmod == acip->last_amp)  /* last main module */
			currentmod = NULL;
		    else
			currentmod = currentmod->next;
		} while (currentmod != NULL);

	    FileClose(fp);
	}


    acip -> amp = amp;
	
    /* print a value file */

    if (asnargs[p_argPrintFileOut].strvalue != NULL)
	{
	    if ((aipout = AsnIoOpen(asnargs[p_argPrintFileOut].strvalue, "w")) == NULL)
		{
		    ErrShow();
		    return 1;
		}
	}
    /* print an XML file */

    if (asnargs[x_argXMLDataOut].strvalue != NULL)
	{
	    if ((xaipout = AsnIoOpen(asnargs[x_argXMLDataOut].strvalue, "wx")) == NULL)
		{
		    ErrShow();
		    return 1;
		}
	}

    if (asnargs[v_argPrintFileIn].strvalue != NULL)        /* read a printvalue file */
	{
	    if ((aip = AsnIoOpen(asnargs[v_argPrintFileIn].strvalue, "r")) == NULL)
		{
		    ErrShow();
		    return 1;
		}

	    AsnTxtReadValFile(amp, aip, aipout, aipencode, xaipout);
	    ErrShow();
	}

    aip = AsnIoClose(aip);

    if (asnargs[d_argBinaryFileIn].strvalue != NULL)        /* read a ber file */
	{
	    if ((asnargs[t_argAsnTypeName].strvalue == NULL) || (! TO_UPPER(*asnargs[t_argAsnTypeName].strvalue)))
                {
		    ErrPostEx(SEV_FATAL,0,0, "Must use -t Type to define contents of decode file");
		    ErrShow();
		    return 1;
		}

	    atp = AsnTypeFind(amp, asnargs[t_argAsnTypeName].strvalue);
	    if (atp == NULL)
                {
#ifdef WIN_MSWIN
		    ErrPostEx(SEV_FATAL,0,0, "Couldn't find Type %Fs", asnargs[t_argAsnTypeName].strvalue);
#else
		    ErrPostEx(SEV_FATAL,0,0, "Couldn't find Type %s", asnargs[t_argAsnTypeName].strvalue);
#endif
		    ErrShow();
		    return 1;
		}

	    if ((aip = AsnIoOpen(asnargs[d_argBinaryFileIn].strvalue, "rb")) == NULL)
		{
		    ErrShow();
		    return 1;
		}


	    AsnBinReadValFile(atp, aip, aipout, aipencode, xaipout);
	    ErrShow();
	}

    AsnIoClose(xaipout);
    AsnIoClose(aipout);
    AsnIoClose(aip);
    AsnIoClose(aipencode);

    if (asnargs[o_argHeadFile].strvalue != NULL)         /* produce header file */
	AsnOutput(asnargs[o_argHeadFile].strvalue, amp, FALSE, (Int2)asnargs[w_argTokenMax].intvalue);

    if (asnargs[l_argLoadFile].strvalue != NULL)        /* produce loader file */
        AsnOutput(asnargs[l_argLoadFile].strvalue, amp, TRUE, (Int2)asnargs[w_argTokenMax].intvalue);

    if (asnargs[G_argGenerateCode ].intvalue != 0)
	{
	    acip ->  filename = asnargs[B_argCodeFileName].strvalue;
	    acip ->  do_bit_twiddle = asnargs[Z_argBitTwiddle].intvalue;
	    acip ->  force_choice_struct = asnargs[V_argChoiceStruct].intvalue;
	    acip ->  include_filename = asnargs[I_argExtraIncludeName].strvalue;
	    acip ->  maxDefineLength = asnargs[w_argTokenMax].intvalue;
	    acip -> debug_level = asnargs[D_argCodeGenDebugLevel ].intvalue;
	    acip -> object_manager_entry = asnargs[J_objMgrEntry].strvalue;
	    acip -> object_label = asnargs[L_objMgrLabel].strvalue;
	    if (asnargs[S_argDebugFileName].strvalue != NULL) {
		(acip -> bug_fp) = FileOpen (asnargs[S_argDebugFileName].strvalue, "w");
	    } else {
		(acip -> bug_fp) = FileOpen ("stderr", "w");
	    }
	    AsnCode(acip);
	}
	
	MemFree(acip);
	MemFree(filename);

    return 0;
}
Esempio n. 11
0
Int2 LIBCALLBACK VSMGenericBinAsnOpen ( Pointer data )
{
    Char filename[255];
    AsnIoPtr aip;
    Pointer ptr;
    Uint2 entityID;
    Int2 ct, i, retval = OM_MSG_RET_OK;
    ObjMgrPtr omp;
    ObjMgrTypePtr omtp = NULL;
    OMProcControlPtr ompcp;
    WindoW w;
    GrouP g;
    ButtoN b;
    VSMReadBinStr vrb;
    VSeqMgrPtr vsmp;

    ompcp = (OMProcControlPtr)data;
    vsmp = VSeqMgrGet();
    omp = vsmp->omp;

    filename[0] = '\0';
    if (GetInputFileName(filename, (size_t)254, NULL, NULL))
    {
        vrb.do_it = FALSE;
        vrb.window_done = FALSE;
        vrb.the_type = 0;
        w = ModalWindow (-50, -33, -10, -10, NULL);
        SetWindowExtra(w, &vrb, NULL);
        g = HiddenGroup(w, 0, 2, NULL);
        StaticPrompt(g, "Select ASN.1 type:", 0,0,systemFont,'l');
        vrb.p = PopupList(g, TRUE, NULL);
        i = 0;
        ct = 0;
        omtp = NULL;
        while ((omtp = ObjMgrTypeFindNext(omp, omtp)) != NULL)
        {
            if (omtp->asnname != NULL)
            {
                i++;
                PopupItem(vrb.p, omtp->asnname);
                if (! StringCmp(vsmp->lastASNtype, omtp->asnname))
                    ct = i;
            }
        }
        
        if (! i)
        {
            ErrPostEx(SEV_ERROR,0,0, "No ASN.1 types are registered");
            Remove(w);
            return OM_MSG_RET_ERROR;
        }
        
        if (! ct)
            ct = 1;
        SetValue(vrb.p, ct);
        
        g = HiddenGroup(w, 2, 0, NULL);
        DefaultButton(g, "Accept", AsnBinAcceptProc);
        b = PushButton(g, "Cancel", AsnBinCancelProc);
        
        Show(w);
        Nlm_WaitForCondition (! vrb.window_done);
        ProcessAnEvent();
        
        if (! vrb.do_it)
            return retval;
        
        i = 0;
        omtp = NULL;
        while ((omtp = ObjMgrTypeFindNext(omp, omtp)) != NULL)
        {
            i++;
            if (i == vrb.the_type)
                break;
        }
        
        if (omtp == NULL)
        {
            ErrPostEx(SEV_ERROR,0,0,"Couldn't find vrb.the_type");
            return OM_MSG_RET_ERROR;
        }
        
        StringMove(vsmp->lastASNtype, omtp->asnname);    
        WatchCursor();
        aip = AsnIoOpen(filename, "rb");
        ptr = (*(omtp->asnread))(aip, NULL);
        AsnIoClose(aip);
        if (ptr == NULL)
        {
            ErrPostEx(SEV_ERROR,0,0,"Couldn't read [%s], type [%s]", filename, omtp->asnname);
            retval = OM_MSG_RET_ERROR;
        }
        else
        {
            entityID = ObjMgrRegister(omtp->datatype, ptr);
            ompcp->output_data = ptr;
            ompcp->output_entityID = entityID;
            PromoteToSeqEntry (entityID, omtp->datatype, ptr);

            retval = OM_MSG_RET_DONE;
        }
        ArrowCursor();
    }
    else
        retval = OM_MSG_RET_OK;

    return retval;
}