Exemplo n.º 1
0
Int2 LIBCALLBACK VSMGenericTextAsnOpen ( Pointer data )
{
    Char filename[255];
    Pointer ptr = NULL;
    Uint2 entityID, datatype;
    Int2 retval = OM_MSG_RET_ERROR;
    OMProcControlPtr ompcp;

    ompcp = (OMProcControlPtr)data;

    filename[0] = '\0';
    if (GetInputFileName(filename, (size_t)254, NULL, NULL))
    {
        WatchCursor();
        ptr = ObjMgrGenericAsnTextFileRead (filename, &datatype, &entityID);
        ArrowCursor();
        if (ptr == NULL) goto erret;

        ompcp->output_data = ptr;
        ompcp->output_entityID = entityID;
        PromoteToSeqEntry (entityID, datatype, ptr);

        retval = OM_MSG_RET_DONE;
    }
    else
        retval = OM_MSG_RET_OK;

ret:
    return retval;
erret:
    goto ret;
}
Exemplo n.º 2
0
ofstream GetValidWriteFile()
{
	ofstream file;
	bool fileValid = false;
	do
	{
		// get a file name from the user 
		string fileName = GetInputFileName();
		//open the file
		file.open(fileName.c_str());
		//test the state of the stream to verify that the file name is valid
		if (file.bad() || file.fail())
		{
			//close the file, TODO is this needed?
			file.close();
			//Give the user the option to quit or try again
			BadFileNameChoice();
		}
		else
		{
			//if the file is valid and open, set fileValid to true.
			return file;
			fileValid = true;
		}
	} while (!fileValid);
	return file;
}
Exemplo n.º 3
0
static void DOT_OpenBrowse2Proc(ButtoN b)
{
  DOTStartDataPtr sdata=NULL;
  Char   path[PATH_MAX]={""};

  sdata = (DOTStartDataPtr) GetObjectExtra (b);
  
  if (sdata==NULL) return;
  
  if (GetInputFileName (path, sizeof(path), NULL, NULL)){ 
    SetTitle(sdata->id2, path);
  }
}
Exemplo n.º 4
0
static Int2 LIBCALLBACK VSMGenericFastaOpen ( Boolean is_na )
{
    Char filename[255];
    FILE * fp;
    SeqEntryPtr sep;
    
    filename[0] = '\0';
    if (GetInputFileName(filename, (size_t)254, NULL, NULL))
    {
        WatchCursor();
        fp = FileOpen(filename, "r");
        while ((sep = FastaToSeqEntry(fp, is_na)) != NULL)
            ObjMgrRegister(OBJ_SEQENTRY, (Pointer)sep);
        FileClose(fp);
        ArrowCursor();
    }
    
    return OM_MSG_RET_DONE;
}
Exemplo n.º 5
0
static void ReadFileProc (ButtoN b)
{
  XOSPtr  xosp;
  Char    filename[PATH_MAX];

  if ((xosp = (XOSPtr) GetObjectExtra (b)) != NULL)
  {
    if (!GetInputFileName (filename, PATH_MAX, "", "TEXT"))
    {
      ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "Could not read directory");
      ErrShow ();
    }
    else
    {
      MemFree (xosp->filename);
      xosp->filename = StringSave (filename);
      xosp->gi = 0;
    }
  }
  return;
}
Exemplo n.º 6
0
int main() {
    for (int testNumber = 3; testNumber <= 120; ++testNumber) {
        std::cout << testNumber << std::endl;

        const std::string inputFileName = GetInputFileName(testNumber);
        const std::string outputFileName = GetOutputFileName(testNumber);

        std::cout << "  " << inputFileName << " " << outputFileName << std::endl;

        std::string s, t;

        if (testNumber & 1) {
            s = GetRandString();
            t = GetRandString();
        } else {
            t = GetRandString();
            int n = t.length();
            int l = GetRandIntInRange(1, n);
            int r = GetRandIntInRange(1, n);
            if (l > r) {
                std::swap(l, r);
            }
            s = t.substr(l, r - l + 1);
        }

        std::ofstream inputFile(inputFileName);
        inputFile << s << std::endl;
        inputFile << t << std::endl;
        inputFile.close();

        std::ofstream outputFile(outputFileName);
        outputFile << GetOccurrences(s, t) << std::endl;
        outputFile.close();
    }
    return 0;
}
Exemplo n.º 7
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;
}