示例#1
0
    void run()
    {
        for (int i = 0; i < itemsToInstall.size(); ++i)
        {
            const ModuleList::Module* m = list.findModuleInfo (itemsToInstall[i]);

            jassert (m != nullptr);
            if (m != nullptr)
            {
                setProgress (i / (double) itemsToInstall.size());

                MemoryBlock downloaded;
                result = download (*m, downloaded);

                if (result.failed())
                    break;

                if (threadShouldExit())
                    break;

                result = unzip (*m, downloaded);

                if (result.failed())
                    break;
            }

            if (threadShouldExit())
                break;
        }
    }
示例#2
0
extern FILE *gz_open(FILE *compressed_file, int *pid)
{
	int unzip_pipe[2];

	if (pipe(unzip_pipe)!=0) {
		error_msg("pipe error");
		return(NULL);
	}
#ifndef __uClinux__
	if ((*pid = fork()) == -1) {
		error_msg("fork failed");
		return(NULL);
	}
	if (*pid==0) {
		/* child process */
		close(unzip_pipe[0]);
		unzip(compressed_file, fdopen(unzip_pipe[1], "w"));
		fflush(NULL);
		fclose(compressed_file);
		close(unzip_pipe[1]);
		exit(EXIT_SUCCESS);
	}
#else
	return NULL;
#endif /* __uClinux__ */
	close(unzip_pipe[1]);
	if (unzip_pipe[0] == -1) {
		error_msg("gzip stream init failed");
	}
	return(fdopen(unzip_pipe[0], "r"));
}
示例#3
0
static void ApplyDownloads(void *param)
{
	HWND hDlg = (HWND)param;

	//////////////////////////////////////////////////////////////////////////////////////
	// if we need to escalate priviledges, launch a atub

	if (!PrepareEscalation()) {
		PostMessage(hDlg, WM_CLOSE, 0, 0);
		return;
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// ok, let's unpack all zips

	AutoHandle pipe(hPipe);
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
	OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
	//create needed folders after escalating priviledges. Folders creates when we actually install updates
	TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];

	mir_sntprintf(tszFileBack, _countof(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);

	mir_sntprintf(tszFileTemp, _countof(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp);

	VARST tszMirandaPath(_T("%miranda_path%"));

	HANDLE nlc = NULL;
	for (int i=0; i < todo.getCount(); ++i) {
		ListView_EnsureVisible(hwndList, i, FALSE);
		if (todo[i].bEnabled) {
			// download update
			ListView_SetItemText(hwndList, i, 1, TranslateT("Downloading..."));

			if (DownloadFile(&todo[i].File, nlc)) {
				ListView_SetItemText(hwndList, i, 1, TranslateT("Succeeded."));
				if (unzip(todo[i].File.tszDiskPath, tszMirandaPath, tszFileBack,false))
					SafeDeleteFile(todo[i].File.tszDiskPath);  // remove .zip after successful update
			}
			else
				ListView_SetItemText(hwndList, i, 1, TranslateT("Failed!"));
		}
		else
			ListView_SetItemText(hwndList, i, 1, TranslateT("Skipped."));
	}
	Netlib_CloseHandle(nlc);

	ShowPopup(TranslateT("Plugin Updater"), TranslateT("Download complete"), POPUP_TYPE_INFO);

	int rc = MessageBox(hDlg, TranslateT("Download complete. Do you want to go to plugins option page?"), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION);
	if (rc == IDYES)
		CallFunctionAsync(OpenPluginOptions, 0);

	PostMessage(hDlg, WM_CLOSE, 0, 0);
}
void spec_uncompress(int in, int out, int lev) {
    level=lev;
    part_nb=0;
    clear_bufs();
    ifd=in;
    ofd=out;
    method = get_method(1);
    unzip(ifd,ofd);
}
示例#5
0
int extract_fastfile(char * infilename, char * outfilename) {
    FILE *fd,
         *fdo  = NULL;

    uint32_t inlen,
             outlen;
    int i,
        files;

    char *file_input,
         *file_output,
         *file_offset;

    setbuf(stdout, NULL);
    setbuf(stderr, NULL);
    file_input  = infilename;
    file_output = outfilename;
    file_offset = "0x15";

    printf("Extracting fastfile: %s\n", file_input);
    fd = fopen(file_input, "rb");
    if(!fd) std_err();

    if(minzip > INSZ) minzip = INSZ;
    if(minzip < 1)    minzip = 1;

    in       = malloc(INSZ);
    out      = malloc(OUTSZ);
    filebuff = malloc(FBUFFSZ);
    if(!in || !out || !filebuff) std_err();

    offset = get_num(file_offset);  // do not skip, needed for buffseek
    buffseek(fd, offset, SEEK_SET);

    z.zalloc = (alloc_func)0;
    z.zfree  = (free_func)0;
    z.opaque = (voidpf)0;
    if(inflateInit2(&z, zipwbits) != Z_OK) zlib_err(Z_INIT_ERROR);

    fdo = save_file(file_output);
    unzip(fd, &fdo, &inlen, &outlen);
    FCLOSE(fdo)

    printf("\n"
        "%u bytes compressed\n"
        "%u bytes extracted\n",
        inlen, outlen);

    FCLOSE(fdo)
    FCLOSE(fd)
    inflateEnd(&z);
    free(in);
    free(out);
    free(filebuff);
    return(0);
}
示例#6
0
    void run() override
    {
        setProgress (-1.0);

        MemoryBlock zipData;
        result = download (zipData);

        if (result.wasOk() && ! threadShouldExit())
            result = unzip (zipData);
    }
示例#7
0
文件: unzip.c 项目: weiang/Homework
int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <filename> \n", argv[0]);
        return EXIT_FAILURE;
    }

    unzip(argv[1]);
    return EXIT_SUCCESS;
}
示例#8
0
文件: winunzip.c 项目: 131/gsview
int main(int argc, char *argv)
{
int i;
	 i = load_unzip("wizunz32.dll", NULL, NULL, NULL);
	 if (i)
		  return 1;
	 i = unzip("c:\\temp\\ut.zip");
	 printf("\nunzip return value is %d\n", i);
	 free_unzip();
	 return i;
}
示例#9
0
文件: setupc.c 项目: 131/gsview
int
unzip_to_dir(char *filename, char *destination)
{
    /* start unzip session */  
    char fullname[256];
    FILE *f;
    int file_exists = 0;
    char cwd[256];
    int len;
    int rc;

    /* prompt for disk to be installed */
    strcpy(fullname, sourcedir);
    strcat(fullname, filename);
    while (!file_exists) {
	gs_addmess("Unzipping ");
	gs_addmess(fullname);
	gs_addmess("\n");
        if ( (f = fopen(fullname, "r")) == (FILE *)NULL ) {
	    char buf[256], mess[256];
	    gs_addmess_update();
	    load_string(IDS_INSERTDISK, mess, sizeof(mess));
	    sprintf(buf, mess, fullname);
	    strcpy(get_string_answer, fullname);
	    if (dialog(IDD_FILE, InputDlgProc) != DID_OK) {
		load_string(IDS_ZIPNOTFOUND, error_message, sizeof(error_message));
		return 1;
	    }
	    strcpy(fullname, get_string_answer);
	}
	else {
	    file_exists = TRUE;
	    fclose(f);
	}
    }

    getcwd(cwd, sizeof(cwd));
    gs_chdir(destination);
    strcpy(unzipprefix, destination);
    len = strlen(unzipprefix);
    if (len && (unzipprefix[len-1] == '\\'))
	unzipprefix[len-1] = '\0';
    rc = unzip(fullname);
    gs_chdir(cwd);

    if (!rc) {
        if (cancelling) {
	    load_string(IDS_UNZIPCANCELLED, error_message, sizeof(error_message));
	    return -1;
	}
    }
    return rc;
}
示例#10
0
static byte *decompress(byte *data, int *len)
{
	unsigned long pos = 0;
	if (data[0] != 0x1f || data[1] != 0x8b)
		return data;
	inf_buf = 0;
	inf_pos = inf_len = 0;
	if (unzip(data, &pos, inflate_callback) < 0)
		return data;
	*len = inf_pos;
	return inf_buf;
}
示例#11
0
文件: unzip.c 项目: coyizumi/cs111
int
main(int argc, char *argv[])
{
	const char *zipfile;
	int nopts;

	if (isatty(STDOUT_FILENO))
		tty = 1;

	if (getenv("UNZIP_DEBUG") != NULL)
		unzip_debug = 1;
	for (int i = 0; i < argc; ++i)
		debug("%s%c", argv[i], (i < argc - 1) ? ' ' : '\n');

	/*
	 * Info-ZIP's unzip(1) expects certain options to come before the
	 * zipfile name, and others to come after - though it does not
	 * enforce this.  For simplicity, we accept *all* options both
	 * before and after the zipfile name.
	 */
	nopts = getopts(argc, argv);

	/* 
	 * When more of the zipinfo mode options are implemented, this
	 * will need to change.
	 */
	if (zipinfo_mode && !Z1_opt) {
		printf("Zipinfo mode needs additional options\n");
		exit(1);
	}

	if (argc <= nopts)
		usage();
	zipfile = argv[nopts++];

	if (strcmp(zipfile, "-") == 0)
		zipfile = NULL; /* STDIN */

	while (nopts < argc && *argv[nopts] != '-')
		add_pattern(&include, argv[nopts++]);

	nopts--; /* fake argv[0] */
	nopts += getopts(argc - nopts, argv + nopts);

	if (n_opt + o_opt + u_opt > 1)
		errorx("-n, -o and -u are contradictory");

	time(&now);

	unzip(zipfile);

	exit(0);
}
示例#12
0
G_MODULE_EXPORT void bu_clicked(GtkObject* widget, gpointer user_data)
{
	int k;
	char * fn_src;
	char * fn_huf;
	char * fn_dst;

	fn_src=gtk_entry_get_text(GTK_ENTRY(t_srcfile));
	fn_huf=gtk_entry_get_text(GTK_ENTRY(t_haffile));
	fn_dst=gtk_entry_get_text(GTK_ENTRY(t_dstfile));

	if ( (k=unzip(fn_src,fn_huf,fn_dst)) < 0 )
		myperror(k);
}
示例#13
0
static struct zfile *zuncompress (struct zfile *z)
{
    char *name = z->name;
    char *ext = strrchr (name, '.');
    uae_u8 header[4];

    if (ext != NULL) {
	ext++;
	if (strcasecmp (ext, "zip") == 0 && zlib_test ())
	     return unzip (z);
	if (strcasecmp (ext, "gz") == 0)
	     return gunzip (z);
	if (strcasecmp (ext, "adz") == 0)
// thinkp	adz-file support
	     return unzip (z);
// thinkp	adz-file support
	if (strcasecmp (ext, "roz") == 0)
	     return gunzip (z);
	if (strcasecmp (ext, "dms") == 0)
	     return dms (z);
	if (strcasecmp (ext, "lha") == 0
	    || strcasecmp (ext, "lzh") == 0)
	    return lha (z);
	memset (header, 0, sizeof (header));
	zfile_fseek (z, 0, SEEK_SET);
	zfile_fread (header, sizeof (header), 1, z);
	zfile_fseek (z, 0, SEEK_SET);
	if (header[0] == 0x1f && header[1] == 0x8b)
	    return gunzip (z);
	if (header[0] == 'P' && header[1] == 'K')
	    return unzip (z);
	if (header[0] == 'D' && header[1] == 'M' && header[2] == 'S' && header[3] == '!')
	    return dms (z);
    }
    return z;
}
示例#14
0
int scorched3d_recv(int sd, u_char *pck, int pcksz, u_char *buff, int buffsz) {
    int     len,
            unzlen;

    read_sock(sd, (u_char *)&len, 4);
    len = ntohl(len);

    read_sock(sd, (u_char *)&unzlen, 4);
    unzlen = ntohl(unzlen);

    read_sock(sd, pck, len - 4);

    if(unzlen > buffsz) return(0);
    len = unzip(pck, pcksz, buff, unzlen);
    return(len);
}
示例#15
0
TreeFile *UnzipCache::getFile(const char* filename, const char* relative)
{
    clc::Buffer fullPath;
    if (relative) {
        fullPath = clc::Path::join(relative, filename);
        filename = fullPath.c_str();
    }
    TreeFile *f = m_root->findFile(filename);
    if (f)
        return f;
    if (unzip(filename, NULL)) {
        // Even if error, may have extracted.
        f = m_root->findFile(filename);
    }
    return f;
}
示例#16
0
QByteArray ArchiveReader::unpack(const QString &path)
{
    QString lPath = path.toLower();
    if (path.endsWith(".mdz") ||
            lPath.endsWith(".s3z") ||
            lPath.endsWith(".xmz") ||
            lPath.endsWith(".itz"))
        return unzip(path);
    else if (lPath.endsWith(".mdgz") ||
             lPath.endsWith(".s3gz") ||
             lPath.endsWith(".xmgz") ||
             lPath.endsWith(".itgz"))
        return gunzip(path);
    else if (lPath.endsWith(".mdbz"))
        return bunzip2(path);

    return QByteArray();
}
示例#17
0
int
main(int argc, char *argv[])
{
	const char *zipfile;
	int nopts;

	if (isatty(STDOUT_FILENO))
		tty = 1;

	if (getenv("UNZIP_DEBUG") != NULL)
		unzip_debug = 1;
	for (int i = 0; i < argc; ++i)
		debug("%s%c", argv[i], (i < argc - 1) ? ' ' : '\n');

	/*
	 * Info-ZIP's unzip(1) expects certain options to come before the
	 * zipfile name, and others to come after - though it does not
	 * enforce this.  For simplicity, we accept *all* options both
	 * before and after the zipfile name.
	 */
	nopts = getopts(argc, argv);

	if (argc <= nopts)
		usage();
	zipfile = argv[nopts++];

	while (nopts < argc && *argv[nopts] != '-')
		add_pattern(&include, argv[nopts++]);

	nopts--; /* fake argv[0] */
	nopts += getopts(argc - nopts, argv + nopts);

	if (n_opt + o_opt + u_opt > 1)
		errorx("-n, -o and -u are contradictory");

	time(&now);

	unzip(zipfile);

	exit(0);
}
static BOOL extract(LPVOID cdata, DWORD csz) {
    HANDLE h;
    WCHAR tempnam[MAX_PATH+1] = {0};
    BOOL ret = true;
    HZIP zipf;
    ZIPENTRYW ze;
    ZRESULT res;
    int nitems;
    HRESULT hr;
    IProgressDialog *pd = NULL;

    hr = CoCreateInstance(CLSID_ProgressDialog, NULL,
            CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pd));

    if (FAILED(hr)) { show_error(L"Failed to create progress dialog"); return false; }
    pd->SetTitle(L"Extracting Calibre Portable");
    pd->SetLine(1, L"Decompressing data...", true, NULL);

    h = temp_file(tempnam);
    if (h == INVALID_HANDLE_VALUE) return false;

    pd->StartProgressDialog(NULL, NULL, PROGDLG_NORMAL | PROGDLG_AUTOTIME | PROGDLG_NOCANCEL, NULL);
    if (!decompress(cdata, csz, h, pd)) { ret = false; goto end; }
    SetFilePointer(h, 0, NULL, FILE_BEGIN);
    zipf = OpenZip(h, 0, ZIP_HANDLE);
    if (zipf == 0) { show_last_error(L"Failed to open zipped portable data"); ret = false; goto end; }

    res = GetZipItem(zipf, -1, &ze);
    if (res != ZR_OK) { show_zip_error(L"Failed to get count of items in portable data", L"", res); ret = false; goto end;}
    nitems = ze.index;

    pd->SetLine(1, L"Copying files...", true, NULL);
    if (!unzip(zipf, nitems, pd)) { ret = false; goto end; }
end:
    pd->StopProgressDialog();
    pd->Release();
    CloseHandle(h);
    DeleteFile(tempnam);
    return ret;
}
示例#19
0
/*                    file name and path , is data */
static inline QMap<QString,QByteArray> unzipstream( const QString file )
{
/*
  #include "qzipreader_p.h"  
*/
      QMap<QString,QByteArray> ooFile;
      QZipReader unzip(file,QIODevice::ReadOnly);
      QList<QZipReader::FileInfo> list = unzip.fileInfoList();
      QZipReader::FileInfo fi;
      if (list.size() > 0 && unzip.exists()) {
                  for (int l = 0; l < list.size(); l++)
                  {
                     fi = list.at(l);
                     if (fi.size > 0) {
                     ooFile.insert(fi.filePath,unzip.fileData(fi.filePath));
                     }
                     qDebug() << "### file  " << fi.filePath << fi.size;
                  }
                  
        unzip.close();    
       }
   return ooFile;
       
     /*  usage 
     QString txtlog;
     QMap<QString,QByteArray>  filist = unzipstream("giallo.odt");
     QMapIterator<QString,QByteArray> i(filist);
         while (i.hasNext()) {
             i.next();
             qDebug() << "### name---------- " << i.key();
             txtlog.append(i.key());
         }   
    QByteArray base = filist["content.xml"];
    if (base.size() > 0) {
        txtlog.append(QString(base));
    }
    */ 
}
示例#20
0
void NewstuffModelPrivate::installMap()
{
    if ( m_unpackProcess ) {
        m_unpackProcess->close();
        delete m_unpackProcess;
        m_unpackProcess = nullptr;
    } else if ( m_currentFile->fileName().endsWith( QLatin1String( "zip" ) ) ) {
        unzip();
    }
    else if ( m_currentFile->fileName().endsWith( QLatin1String( "tar.gz" ) ) && canExecute( "tar" ) ) {
        m_unpackProcess = new QProcess;
        QObject::connect( m_unpackProcess, SIGNAL(finished(int)),
                          m_parent, SLOT(contentsListed(int)) );
        QStringList arguments = QStringList() << "-t" << "-z" << "-f" << m_currentFile->fileName();
        m_unpackProcess->setWorkingDirectory( m_targetDirectory );
        m_unpackProcess->start( "tar", arguments );
    } else {
        if ( !m_currentFile->fileName().endsWith( QLatin1String( "tar.gz" ) ) ) {
            mDebug() << "Can only handle tar.gz files";
        } else {
            mDebug() << "Cannot extract archive: tar executable not found in PATH.";
        }
    }
}
示例#21
0
void CleanerThread::startNext(const QString &inFile, const QString &outFile)
{
    cleaningTime.start();
    scriptOutput.clear();
    outSVG = QString(outFile).replace("svgz", "svg").replace("SVGZ", "SVG");
    currentIn = inFile;
    currentOut = outFile;

    QDir().mkpath(QFileInfo(outFile).absolutePath());
    if (QFileInfo(inFile).suffix().toLower() == "svg") {
        if (inFile != outFile)
            QFile(outSVG).remove();
        QFile().copy(inFile, outSVG);
    } else {
        unzip(inFile);
    }

    QStringList args;
    args.append(outSVG);
    args.append(outSVG);
    args.append(arguments.args);
    proc->start(arguments.cliPath, args);
    proc->waitForFinished();
}
示例#22
0
IZBuffer* RSAZCryptor::decrypt(int key_len, unsigned char* keybuf, int in_len, unsigned char* inbuf)
{
    if(key_len <= 0 || !keybuf)
    {
        if(m_trace_level > 0)
            printf("Warning: Please specify a key for decryption.\n");
        return NULL;
    }

    if(in_len <= 0 || !inbuf)
    {
        return NULL;
    }

    if(m_trace_level > 5)
    {
        printf("Info: length of keybuf %d\n", key_len);
        printf("Info: length of inbuf %d\n", in_len);
    }

    if(m_trace_level > 10)
    {
        printf("Info: key for decryption: \n%s\n", keybuf);
    }

    ZBuffer* dkeybuf = m_keycache->getCachedKey(this, key_len, keybuf);
    if(!dkeybuf)
    {
        return NULL;
    }

    // Base64 decode first
    ZBuffer dbuf;
    int dlen = in_len;
    unsigned char* dptr = inbuf;
    if(m_encoding)
    {
        base64_decode(in_len, (const char*)inbuf, dbuf);
        if(m_trace_level > 5)
            printf("Info: data length after base64 decode: %d\n", dbuf.length());
        dlen = dbuf.length();
        dptr = dbuf.buffer();
    }

    ZBuffer buf;
    aes_decrypt(dkeybuf->buffer(), dkeybuf->length(), dptr, dlen, buf);

    if(m_trace_level > 5)
        printf("Info: data length after aes_decryption: %d\n", buf.length());

    ZBuffer* outbuf = new ZBuffer();
    int ret = unzip(buf.length(), buf.buffer(), *outbuf);
    
    if(ret != Z_OK || outbuf->length() <= 0)
        return NULL;

    if(m_trace_level > 5)
        printf("Info: data length after base64-decode/decryption/unzip: %d\n", outbuf->length());

    if(m_trace_level > 10)
        printf("info: base64-decode/decryption/unzip result:\n%s\n", outbuf->buffer());

    return outbuf;
}
int read_lammps(char *filename, atomic_dat *atom_fill, bool create_H, bool new_format)
{
	cout << "READING LAMMPS IN SPECIFIC FORMAT OF Cu-Nb RELATED... CHECK FOR THIS IF ERRORS ARE OCCURING\n";
	FILE *fptr;
	static bool prev_success = true;
	if(prev_success)
		{
			if(atom != NULL)
			free(atom);

		}
	unzip(filename);
	//printf("opening data file %s ...\n",filename);
	fptr = fopen(filename,"r");
	if(fptr==NULL)
	{
		cout << filename<<"\t:file open failed\n";
		prev_success = false;
		return(1);

	}else
	{
		prev_success = true;
		char str3[80];
		char str32[80];
		char str33[80];

		double time_step,dummy2,dummy3;


		fscanf(fptr,"%s %s",str32,str33);
	 //   cout << str32<<"\t"<<str33<<" 1 \n";
	    fscanf(fptr,"%d",&time_step);
	    fscanf(fptr,"%s %s",str32,str33);
	   // cout << str32<<"\t"<<str33<<" 2 \n";
	    fscanf(fptr,"%s %s",str32,str33);
	   // cout << str32<<"\t"<<str33<<" 3 \n";
	    fscanf(fptr,"%d",&n);
	    fscanf(fptr,"%s %s",str32,str33);
	   // cout << str32<<"\t"<<str33<<" 4 \n";
	    fscanf(fptr,"%s",str32);
	    //cout << str32<<"5 \n";
		if(new_format)
		{
			char str_a[80],str_b[80],str_c[80];
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
			//cout << str_a<<"\t"<<str_c<<" format changed\n";
		}
		xy = 0.0;xz=0.0;yz=0.0;
		if(new_format)
		{

			fscanf(fptr,"%lf %lf %lf",&xlo,&xhi,&xy);
			//cout << xlo <<"\tdfd\t"<<xhi<<"\t"<<xy<<"\n";
			//lx = (xhi - xlo);
			fscanf(fptr,"%lf %lf %lf",&ylo,&yhi,&xz);
			//ly = (yhi - ylo);
//			cout << ylo<<"\t ly " << yhi<<"\t"<<xz<<"\n";;

			double dummy_z;
			fscanf(fptr,"%lf",&zlo);
			//	    zlo = dummy3;
			fscanf(fptr,"%lf",&zhi);
			fscanf(fptr,"%lf",&yz);
	//		cout << yz<<" yz is \n";
			lz = (zhi-zlo);

			xlo = max(xlo,xlo-xy);
			xlo = max(xlo,xlo-xz);

			xhi = min(xhi,xhi-xy);
			xhi = min(xhi,xhi-xz);

			ylo = max(ylo,ylo-yz);
			yhi = min(yhi,yhi-yz);


			lx = xhi-xlo;
			ly = yhi-ylo;

		//	cout << zlo<<"\t z "<< zhi<<"\n";
			fscanf(fptr,"%s %s",str32,str33);
			//cout << str32<<"\t"<<str33<<"\n";
		//	cout << lx<<"\t"<<ly<<"\t"<<lz<<"\n";

			char str_a[80],str_b[80],str_c[80];

			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			/*
			 if((xy*xz)>0)
			 {
			 }else
			 {
			 }
			 */
		}else
		{
			fscanf(fptr,"%lf %lf",&xlo,&xhi);
		//	cout << xlo <<"\tdfd\t"<<xhi<<"\n";
			lx = (xhi - xlo);
		//	cout << xlo<<"\t"<<lx<<"\n";
			fscanf(fptr,"%lf %lf",&ylo,&yhi);
			//	    fscanf(fptr,"%f",&dummy2);
			//	    fscanf(fptr,"%f",&dummy2);
			ly = (yhi - ylo);
		//	cout << ylo<<"\t ly " << yhi<<"\n";;

			double dummy_z;
			fscanf(fptr,"%lf",&zlo);
			//	    zlo = dummy3;
			fscanf(fptr,"%lf",&zhi);
			lz = (zhi-zlo);
			cout << zlo<<"\t z "<< zhi<<"\n";
			fscanf(fptr,"%s %s",str32,str33);
//			cout << str32<<"\t"<<str33<<"\n";
//			cout << lx<<"\t"<<ly<<"\t"<<lz<<"\n";
		}

		if(create_H)
		{
			H[0][0] = lx;H[0][1]=0.0;H[0][2]=0.0;H[1][0]=xy;H[1][1]=ly;H[1][2]=0.0;H[2][0]=xz;H[2][1]=yz;H[2][2]=lz;
			for(int a=0;a<3;a++)
			{
				for(int b=0;b<3;b++)
				{
					Hcry[a][b] = H[a][b];
					cout << Hcry[a][b]<<"\t";
				}
				cout << "\n";
			}
			H_crystal(H,crystal0);
			crystal_H(crystal0,Hcry);
		}

		double Hcry_inv1[3][3];
		M3inv(Hcry,Hcry_inv1);
		M3inv(Hcry,Hcry_inv);

		atom = (struct atomic_dat *) malloc((n+5)*sizeof(struct atomic_dat));

		double rx,ry,rz,vx,vy,vz,fx,fy,fz,sx,sy,sz,ux,uy,uz,ke,pe;
		int tag,type;
		double test1,test2;

		for (int i = 0; i < n; i++)
		{

			//fscanf(fptr,"%d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf",
			//  &tag,&type &rx, &ry, &rz,&vx,&vy,&vz,&fx,&fy,&fz);
			/*
			 fscanf(fptr,"%d %d %lf %lf %lf %lf %lf %lf", &tag, &type, &rx, &ry, &rz,&vx,&vy,&vz);

			 atom[tag-1].rx = rx;
			 atom[tag-1].ry = ry;
			 atom[tag-1].rz = rz;

			 atom[tag-1].type = type;

			 atom[tag-1].vx = vx;
			 atom[tag-1].vy = vy;
			 atom[tag-1].vz = vz;
			 */

			//fscanf(fptr,"%d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &tag, &type, &sx, &sy, &sz,&ux,&uy,&uz,&vx,&vy,&vz,&pe);
			fscanf(fptr,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &test1, &test2, &sx, &sy, &sz,&ux,&uy,&uz,&vx,&vy,&vz,&pe);
			tag = (int) test1;
			type = (int) test2;
// -0.3 for moving in and +0.3 for moving back out
			atom[tag-1].sx = sx;//-0.3;
			atom[tag-1].sy = sy;
			atom[tag-1].sz = sz;


			/*
			 atom[tag-1].rx = sx*(xhi-xlo);
			 atom[tag-1].ry = sy*(yhi-ylo);
			 atom[tag-1].rz = sz*(zhi-zlo);
			 double r[3],s[3];
			 r[0] = atom[tag-1].rx;
			 r[1] = atom[tag-1].ry;
			 r[2] = atom[tag-1].rz;

			 V3mulM3(r,Hcry_inv1,s);

			 atom[tag-1].sx = s[0];
			 atom[tag-1].sy = s[1];
			 atom[tag-1].sz = s[2];
			 if(tag-1==0)
			 {
				 cout << atom[tag-1].rx<<"\t"<<atom[tag-1].ry<<"\t"<<atom[tag-1].rz<<"\t"<<(ux/sx)<<"\t"<<uy/sy<<"\t"<<uz/sz<<" ++++++++\n";
			 }
			 */

			if(atom[tag-1].sx>=1) atom[tag-1].sx=atom[tag-1].sx-1;
			if(atom[tag-1].sx<0) atom[tag-1].sx=1+atom[tag-1].sx;


			if(atom[tag-1].sy>=1) atom[tag-1].sy=atom[tag-1].sy-1;
			if(atom[tag-1].sy<0) atom[tag-1].sy=1+atom[tag-1].sy;

			if(atom[tag-1].sz>=1) atom[tag-1].sz=atom[tag-1].sz-1;
			if(atom[tag-1].sz<0) atom[tag-1].sz=1+atom[tag-1].sz;


			atom[tag-1].pe = pe;
			atom[tag-1].type = type;

			if(atom[tag-1].type==1)
			{
				atom[tag-1].ma = 63.546;
				atom[tag-1].pe = atom[tag-1].pe; //subtract cohesive energy from the energy of the atom
				strncpy(atom[tag-1].elem,"Cu",sizeof(atom[i].elem));

			}else
			{
				if(atom[tag-1].type==2)
				{
					atom[tag-1].ma = 92.90638;
					atom[tag-1].pe = atom[tag-1].pe;
					strncpy(atom[tag-1].elem ,"Nb",sizeof(atom[i].elem));
				}else
				{
					atom[tag-1].ma = 63.546;
					atom[tag-1].pe = atom[tag-1].pe;
					strncpy(atom[tag-1].elem,"Z",sizeof(atom[i].elem));
				}
			}

			atom[tag-1].vx = vx;
			atom[tag-1].vy = vy;
			atom[tag-1].vz = vz;

			atom[tag-1].ux = ux;
			atom[tag-1].uy = uy;
			atom[tag-1].uz = uz;

			atom[tag-1].fx = ux;
			atom[tag-1].fy = uy;
			atom[tag-1].fz = uz;

		}

		fclose(fptr);
		zip(filename);
		/*
			double H_c_inv[3][3];
		 M3inv(Hcry, H_c_inv);

		 for(int i=0;i<n;i++)
		 {
			 double r[3],s[3];
			 r[0]=atom[i].rx;r[1]=atom[i].ry;r[2]=atom[i].rz;
			 V3mulM3(r,H_c_inv,s);
			 atom[i].sx = s[0];atom[i].sy=s[1];atom[i].sz=s[2];
			 if(atom[i].type==1)
			 {
				 atom[i].ma = 63.546;
			 }else
			 {
				 if(atom[i].type==2)
				 {
					 atom[i].ma = 92.90638;
				 }
			 }
		 }
		 */

	}

	//cout << "out of reading lammps\n";
	return(0);
}
int read_lammps_specific(char *filename, atomic_dat *atom_fill, bool create_H, bool new_format, double H_here[3][3])
{
	FILE *fptr;
	static bool prev_success = true;
	if(prev_success)
		{
			if(atom_fill != NULL)
			free(atom_fill);

		}
	unzip(filename);
	//printf("opening data file %s ...\n",filename);
	fptr = fopen(filename,"r");
	if(fptr==NULL)
	{
		cout << filename<<"\t:file open failed\n";
		prev_success = false;
		return(1);

	}else
	{
		prev_success = true;
		char str3[80];
		char str32[80];
		char str33[80];

		double time_step,dummy2,dummy3;


		fscanf(fptr,"%s %s",str32,str33);
	 //   cout << str32<<"\t"<<str33<<" 1 \n";
	    fscanf(fptr,"%d",&time_step);
	    fscanf(fptr,"%s %s",str32,str33);
	   // cout << str32<<"\t"<<str33<<" 2 \n";
	    fscanf(fptr,"%s %s",str32,str33);
	   // cout << str32<<"\t"<<str33<<" 3 \n";
	    fscanf(fptr,"%d",&n);
	    fscanf(fptr,"%s %s",str32,str33);
	   // cout << str32<<"\t"<<str33<<" 4 \n";
	    fscanf(fptr,"%s",str32);
	    //cout << str32<<"5 \n";
		if(new_format)
		{
			char str_a[80],str_b[80],str_c[80];
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
			//cout << str_a<<"\t"<<str_c<<" format changed\n";
		}
		xy = 0.0;xz=0.0;yz=0.0;
		if(new_format)
		{

			fscanf(fptr,"%lf %lf %lf",&xlo,&xhi,&xy);
			//cout << xlo <<"\tdfd\t"<<xhi<<"\t"<<xy<<"\n";
			//lx = (xhi - xlo);
			fscanf(fptr,"%lf %lf %lf",&ylo,&yhi,&xz);
			//ly = (yhi - ylo);
//			cout << ylo<<"\t ly " << yhi<<"\t"<<xz<<"\n";;

			double dummy_z;
			fscanf(fptr,"%lf",&zlo);
			//	    zlo = dummy3;
			fscanf(fptr,"%lf",&zhi);
			fscanf(fptr,"%lf",&yz);
	//		cout << yz<<" yz is \n";
			lz = (zhi-zlo);

			xlo = max(xlo,xlo-xy);
			xlo = max(xlo,xlo-xz);

			xhi = min(xhi,xhi-xy);
			xhi = min(xhi,xhi-xz);

			ylo = max(ylo,ylo-yz);
			yhi = min(yhi,yhi-yz);


			lx = xhi-xlo;
			ly = yhi-ylo;

		//	cout << zlo<<"\t z "<< zhi<<"\n";
			fscanf(fptr,"%s %s",str32,str33);
			//cout << str32<<"\t"<<str33<<"\n";
		//	cout << lx<<"\t"<<ly<<"\t"<<lz<<"\n";

			char str_a[80],str_b[80],str_c[80];

			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			fscanf(fptr,"%s %s %s",str_a,str_b,str_c);
		//	cout << str_a<<"\t"<<str_c<<" format changed\n";
			/*
			 if((xy*xz)>0)
			 {
			 }else
			 {
			 }
			 */
		}else
		{
			fscanf(fptr,"%lf %lf",&xlo,&xhi);
		//	cout << xlo <<"\tdfd\t"<<xhi<<"\n";
			lx = (xhi - xlo);
		//	cout << xlo<<"\t"<<lx<<"\n";
			fscanf(fptr,"%lf %lf",&ylo,&yhi);
			//	    fscanf(fptr,"%f",&dummy2);
			//	    fscanf(fptr,"%f",&dummy2);
			ly = (yhi - ylo);
		//	cout << ylo<<"\t ly " << yhi<<"\n";;

			double dummy_z;
			fscanf(fptr,"%lf",&zlo);
			//	    zlo = dummy3;
			fscanf(fptr,"%lf",&zhi);
			lz = (zhi-zlo);
			cout << zlo<<"\t z "<< zhi<<"\n";
			fscanf(fptr,"%s %s",str32,str33);
//			cout << str32<<"\t"<<str33<<"\n";
//			cout << lx<<"\t"<<ly<<"\t"<<lz<<"\n";
		}

		if(create_H)
		{
			H_here[0][0] = lx;H_here[0][1]=0.0;H_here[0][2]=0.0;
			H_here[1][0]=xy;H_here[1][1]=ly;H_here[1][2]=0.0;H_here[2][0]=xz;H_here[2][1]=yz;H_here[2][2]=lz;

		}

		double H_herecry_inv1[3][3];
		M3inv(H_here,H_herecry_inv1);

		atom_fill = (struct atomic_dat *) malloc((n+3)*sizeof(struct atomic_dat));

		double rx,ry,rz,vx,vy,vz,fx,fy,fz,sx,sy,sz,ux,uy,uz,ke,pe;
		int tag,type;
		double test1,test2;

		for (int i = 0; i < n; i++)
		{


			//fscanf(fptr,"%d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &tag, &type, &sx, &sy, &sz,&ux,&uy,&uz,&vx,&vy,&vz,&pe);
			fscanf(fptr,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &test1, &test2, &sx, &sy, &sz,&ux,&uy,&uz,&vx,&vy,&vz,&pe);
			tag = (int) test1;
			type = (int) test2;
// -0.3 for moving in and +0.3 for moving back out
			atom_fill[tag-1].sx = sx;//+0.3;
			atom_fill[tag-1].sy = sy;
			atom_fill[tag-1].sz = sz;

			if(atom_fill[tag-1].sx>=1) atom_fill[tag-1].sx=atom_fill[tag-1].sx-1;
			if(atom_fill[tag-1].sx<0) atom_fill[tag-1].sx=1+atom_fill[tag-1].sx;


			if(atom_fill[tag-1].sy>=1) atom_fill[tag-1].sy=atom_fill[tag-1].sy-1;
			if(atom_fill[tag-1].sy<0) atom_fill[tag-1].sy=1+atom_fill[tag-1].sy;

			if(atom_fill[tag-1].sz>=1) atom_fill[tag-1].sz=atom_fill[tag-1].sz-1;
			if(atom_fill[tag-1].sz<0) atom_fill[tag-1].sz=1+atom_fill[tag-1].sz;


			atom_fill[tag-1].pe = pe;
			atom_fill[tag-1].type = type;

			if(atom_fill[tag-1].type==1)
			{
				atom_fill[tag-1].ma = 63.546;
				atom_fill[tag-1].pe = atom_fill[tag-1].pe; //subtract cohesive energy from the energy of the atom
			}else
			{
				if(atom_fill[tag-1].type==2)
				{
					atom_fill[tag-1].ma = 92.90638;
					atom_fill[tag-1].pe = atom_fill[tag-1].pe;
				}
			}

			atom_fill[tag-1].vx = vx;
			atom_fill[tag-1].vy = vy;
			atom_fill[tag-1].vz = vz;

			atom_fill[tag-1].ux = ux;
			atom_fill[tag-1].uy = uy;
			atom_fill[tag-1].uz = uz;

			atom_fill[tag-1].fx = ux;
			atom_fill[tag-1].fy = uy;
			atom_fill[tag-1].fz = uz;

		}

		fclose(fptr);
		zip(filename);

	}

	//cout << "out of reading lammps\n";
	return(0);
}
int read_lammps_general(char *filename)
{
	FILE *fptr;
	int num_val;
	ifstream inputfile;
	string tmp_line;

	static bool g_prev_success = true;
	if(g_prev_success)
	{
		if(atom != NULL)
		free(atom);

	}
	unzip(filename);
	cout <<"filename is \t"<<filename<<" in here \n";
	inputfile.open(filename);
	if(!(inputfile.good()))
	{
		cout << filename<<"\t:file open failed\n";
		g_prev_success = false;
		return(1);
	}
	else{
		g_prev_success = true;
		bool read_coords = false;
		int n_counter = -1;
		int id_counter = -1;
		string *ptr_tmp_line1;
		ptr_tmp_line1 = get_next_splits(inputfile, num_val);
		delete[] ptr_tmp_line1;
		ptr_tmp_line1 = get_next_splits(inputfile, num_val);

		delete[] ptr_tmp_line1;
		ptr_tmp_line1 = get_next_splits(inputfile, num_val);
		delete[] ptr_tmp_line1;
		ptr_tmp_line1 = get_next_splits(inputfile, num_val);
		n = atoi(ptr_tmp_line1[0].c_str());
		delete[] ptr_tmp_line1;
		cout << "number of atoms are\t"<<n<<"\n";;
		string *ref_line;
		int iii =0;
		atom = (struct atomic_dat *) malloc((n+5)*sizeof(struct atomic_dat));


		while(!inputfile.eof())
		{
//			cout << "am here at the top\n";
			string *ptr_tmp_line;
//			cout << "going to get values\n";
			ptr_tmp_line = get_next_splits(inputfile, num_val);
//			cout << "got values ..\n";
			if((ptr_tmp_line[0]=="ITEM:")&&(ptr_tmp_line[1]=="BOX")&&(ptr_tmp_line[2]=="BOUNDS"))
			{
				int prev_num_val  = num_val;
				ptr_tmp_line = get_next_splits(inputfile, num_val);
				xlo = atof(ptr_tmp_line[0].c_str()); xhi = atof(ptr_tmp_line[1].c_str()); if(num_val==3) xy = atof(ptr_tmp_line[2].c_str());
				ptr_tmp_line = get_next_splits(inputfile, num_val);
				ylo =atof(ptr_tmp_line[0].c_str()); yhi = atof(ptr_tmp_line[1].c_str()); if(num_val==3) xz = atof(ptr_tmp_line[2].c_str());
				ptr_tmp_line = get_next_splits(inputfile, num_val);
				zlo = atof(ptr_tmp_line[0].c_str()); zhi = atof(ptr_tmp_line[1].c_str()); if(num_val==3) yz = atof(ptr_tmp_line[2].c_str());

				lz = (zhi-zlo);
				xlo = max(xlo,xlo-xy);
				xlo = max(xlo,xlo-xz);
				xhi = min(xhi,xhi-xy);
				xhi = min(xhi,xhi-xz);
				ylo = max(ylo,ylo-yz);
				yhi = min(yhi,yhi-yz);
				lx = xhi-xlo;
				ly = yhi-ylo;
				cout << lx <<"\t"<<ly<<"\t"<<lz<<"\t"<<xy <<"\t"<<xz <<"\t"<<yz<<"\n";

				H[0][0] = lx;H[0][1]=0.0;H[0][2]=0.0;H[1][0]=xy;H[1][1]=ly;H[1][2]=0.0;H[2][0]=xz;H[2][1]=yz;H[2][2]=lz;
				for(int a=0;a<3;a++)
				{
					for(int b=0;b<3;b++)
					{
						Hcry[a][b] = H[a][b];
						cout << "i AM HERE, WHERE ARE YOU? "<< Hcry[a][b]<<"\t";
					}
					cout << "\n";
				}
				H_crystal(H,crystal0);
				crystal_H(crystal0,Hcry);
				//double Hcry_inv1[3][3];
				//M3inv(Hcry,Hcry_inv1);
				M3inv(Hcry,Hcry_inv);

			}
			if((ptr_tmp_line[0]=="ITEM:")&&(ptr_tmp_line[1]=="ATOMS"))
			{
				//ref_line = ptr_tmp_line;

				ref_line = new string[num_val];
				for (int i =0;i<num_val;i++)
				{
					//ref_line[i] = ptr_tmp_line[i];
					ref_line[i].append(ptr_tmp_line[i]);
//					cout << ref_line[i]<<"\n";
//					strncpy(ref_line[i], ptr_tmp_line[i]);
//					istringstream iss2(ptr_tmp_line[i]);
//					cout << iss2 <<"\n";
//					 iss2 >> ref_line[i];
;				}

				int i =0;
				while (id_counter<0) {if(ref_line[i+2]=="id") id_counter = i;};
				read_coords = true;
				delete [] ptr_tmp_line;
				ptr_tmp_line = get_next_splits(inputfile, num_val);
			}

			//cout << "BEFORE READ COORDS ***********************************\n";
			if(read_coords)
			{
				n_counter++;
				//cout << "reading values "<< n_counter<<"\n";
				int tag = atoi(ptr_tmp_line[id_counter].c_str());
				tag = tag-1;

				if(tag >= n)
				{
					cout << "\natom ID is greater than total atoms -- not allowed yet!\n";
					exit(1);

				}

				// for now hard coded as this routine does not take it from input
				atom[tag].molID = 1;

				for (int i =0;i<num_val;i++)
				{
					if(ref_line[i+2]=="xs")
					{
						atom[tag].sx =atof(ptr_tmp_line[i].c_str());
						if(atom[tag].sx>=1) atom[tag].sx = atom[tag].sx-1;
						if(atom[tag].sx<0) atom[tag].sx = atom[tag].sx+1;
					}
					if(ref_line[i+2]=="ys")
					{
						atom[tag].sy =atof(ptr_tmp_line[i].c_str());
						if(atom[tag].sy>=1) atom[tag].sy = atom[tag].sy-1;
						if(atom[tag].sy<0) atom[tag].sy = atom[tag].sy+1;
					}
					if(ref_line[i+2]=="zs")
					{
						atom[tag].sz =atof(ptr_tmp_line[i].c_str());
						if(atom[tag].sz>=1) atom[tag].sz = atom[tag].sz-1;
						if(atom[tag].sz<0) atom[tag].sz = atom[tag].sz+1;
					}

					if(ref_line[i+2]=="vx") {atom[tag].vx =atof(ptr_tmp_line[i].c_str());}
					if(ref_line[i+2]=="vy") {atom[tag].vy =atof(ptr_tmp_line[i].c_str());}
					if(ref_line[i+2]=="vz"){atom[tag].vz =atof(ptr_tmp_line[i].c_str());}

					if(ref_line[i+2]=="type") {atom[tag].type =atoi(ptr_tmp_line[i].c_str());}
					if(ref_line[i+2]=="mass") {atom[tag].ma =atof(ptr_tmp_line[i].c_str());}

					if(ref_line[i+2]=="c_energy") {atom[tag].pe =atof(ptr_tmp_line[i].c_str());}
					if(ref_line[i+2]=="q") {atom[tag].charge =atof(ptr_tmp_line[i].c_str());}
					if(ref_line[i+2]=="element") { strncpy(atom[tag].elem,ptr_tmp_line[i].c_str(),sizeof(atom[tag].elem));}

			}
				if(n_counter>=n-1) read_coords = false;

			}
//			cout << " am here "<< tag2 << " "<<n<<" "<< n_counter<<"\n" ;
			delete [] ptr_tmp_line;
//			cout << "done it\n";

		}
		delete [] ref_line;
	//	cout << "exit reading data\n";
	}

	inputfile.close();
	zip(filename);
	//Adjustments
	// 1. if element is not there, 1 is Cu, 2 is Nb and others are ZZ
	// 2. set the number of types
	for (int i =0;i <n;i++)
	{	//if(i==0) {cout << strcmp(atom[i].elem,"")<<"\n";cout << strcmp("abcd","abcd")<<"\n";cout << strcmp("efgh","abcd")<<"\n";}
		//cout << sizeof(atom[i].elem) <<" "<<i<<"\n";
		if(strcmp(atom[i].elem,"")==0)
		{
			//cout << i<< " hi\n";
			char abcd[80]="";
			if(atom[i].type == 1)
			{
				strcat(abcd,"Mg");
			}else if(atom[i].type == 2)
			{
				strcat(abcd,"O");
			}else
			{
				strcat(abcd,"Z");
			}
			strncpy(atom[i].elem, abcd,sizeof(atom[i].elem));
			//cout << abcd <<" "<<atom[i].elem<<"\n";
			//strncpy(atom[i].elem, element_names[atom[i].type-1].c_str(),sizeof(atom[i].elem));
			//cout << abcd <<" "<<atom[i].elem<<"\n";
			//cout << abcd <<"\n";
		}


		if(n_types< atom[i].type) n_types = atom[i].type;

	}

	cout << "total types of atoms are\t"<< n_types <<"\n";
	//cout << "exiting here\n";

	return(0);
}
int read_xyz_VESTA(const char *filename1)
{
	FILE *fptr;
	int num_val;
	ifstream inputfile;
	char filename[80]="";
	strcat(filename, filename1);
	string tmp_line;
	static bool g_prev_success = true;
	if (g_prev_success)
	{
		if(atom !=NULL)
			free(atom);
	}
	unzip(filename);
	cout << "file to be converted is \t"<< filename <<"\n";
	inputfile.open(filename);
	if(!(inputfile.good()))
	{
		cout << filename << " file open failed\n";
		g_prev_success  = false;
		return(1);
	}else
	{
		g_prev_success = true;
		bool read_coords = false;
		std::string *ptr_tmp_line1;
		ptr_tmp_line1 = get_next_splits(inputfile, num_val);
		n = atoi(ptr_tmp_line1[0].c_str());
		delete [] ptr_tmp_line1;
		ptr_tmp_line1 = get_next_splits(inputfile, num_val);
		double crystal_data[6];
		crystal_data[0] = atof(ptr_tmp_line1[0].c_str());
		crystal_data[1] = atof(ptr_tmp_line1[1].c_str());
		crystal_data[2] = atof(ptr_tmp_line1[2].c_str());
		crystal_data[3] = atof(ptr_tmp_line1[3].c_str())/180*PI;
		crystal_data[4] = atof(ptr_tmp_line1[4].c_str())/180*PI;
		crystal_data[5] = atof(ptr_tmp_line1[5].c_str())/180*PI;

		for(int i=0;i<6; i++)
		{
			crystal0[i] = crystal_data[i];
		}
		crystal_H(crystal0,Hcry);
		for (int i = 0; i < 3; i++)
		{
			for(int j = 0; j < 3; j++)
			{
				cout << Hcry[i][j]<< " ";
			}
			cout <<"\n";
		}
		M3inv(Hcry,Hcry_inv);

		cout << "number of atoms are\t"<< n <<"\n";
		atom = (struct atomic_dat *) malloc((n+5)*sizeof(struct atomic_dat));
	/*	for (int i =0; i <n;i++)
		{
			atom[i].rx = 0.0;
			atom[i].ry = 0.0;
			atom[i].rz = 0.0;
		}*/
		int tag = 0;
		cout << "initalized the structure\n";
		while(!inputfile.eof())
		{
			std::string *ptr_tmp_line;
			ptr_tmp_line = get_next_splits(inputfile, num_val);
			if(num_val>0)
			{
				atom[tag].rx = atof(ptr_tmp_line[1].c_str());
				atom[tag].ry = atof(ptr_tmp_line[2].c_str());
				atom[tag].rz = atof(ptr_tmp_line[3].c_str());
				atom[tag].type = 0;
				atom[tag].molID = 1;
				strncpy(atom[tag].elem, ptr_tmp_line[0].c_str(), sizeof(atom[tag].elem));

				double r[3],s[3];
				r[0]=atom[tag].rx;r[1]=atom[tag].ry;r[2]=atom[tag].rz;
				atom[tag].ux=atom[tag].rx;atom[tag].uy=atom[tag].ry;atom[tag].uz=atom[tag].rz;

				V3mulM3(r,Hcry_inv,s);
				atom[tag].sx = s[0];atom[tag].sy=s[1];atom[tag].sz=s[2];

				if(atom[tag].sx>1.0) atom[tag].sx = atom[tag].sx-1;
				if(atom[tag].sy>1.0) atom[tag].sy = atom[tag].sy-1;
				if(atom[tag].sz>1.0) atom[tag].sz = atom[tag].sz-1;

				if(atom[tag].sx<0.0) atom[tag].sx = 1.0+atom[tag].sx;
				if(atom[tag].sy<0.0) atom[tag].sy = 1.0+atom[tag].sy;
				if(atom[tag].sz<0.0) atom[tag].sz = 1.0+atom[tag].sz;
				tag++;
			}

		}
		cout << "final tag value "<<tag<<"\n";
	}
	inputfile.close();
}
示例#27
0
static rc_t uncompress_f(float dst[], uint32_t dsize, const uint8_t *src, bitsz_t ssize) {
	uint32_t count;
	uint16_t version;
	rc_t rc;
	uint8_t *enc = NULL;
    unsigned actsize;
	
	version = read_uint(&src, &ssize);
	if (!ssize)
		return RC(rcXF, rcFunction, rcExecuting, rcData, rcCorrupt);
	if (version == 0x0100) {
		count = read_uint(&src, &ssize);
		actsize = count * sizeof(float);
		if (dsize < actsize)
			return RC(rcXF, rcFunction, rcExecuting, rcData, rcInsufficient);
		if (!ssize)
			return RC(rcXF, rcFunction, rcExecuting, rcData, rcCorrupt);
        
		read_uint(&src, &ssize);
		if (!ssize)
			return RC(rcXF, rcFunction, rcExecuting, rcData, rcCorrupt);
        rc = 0;
    }
    else {
        size_t esize;
        
        if (version != 0x0101)
            return RC(rcXF, rcFunction, rcExecuting, rcData, rcBadVersion);

        count = read_uint(&src, &ssize);
        actsize = count * sizeof(float);
        if (dsize < actsize)
            return RC(rcXF, rcFunction, rcExecuting, rcData, rcInsufficient);
        if (!ssize)
            return RC(rcXF, rcFunction, rcExecuting, rcData, rcCorrupt);

        esize = read_uint(&src, &ssize);
        if (!ssize)
            return RC(rcXF, rcFunction, rcExecuting, rcData, rcCorrupt);
        
        enc = malloc(esize);
        if (enc == NULL)
            return RC(rcXF, rcFunction, rcExecuting, rcMemory, rcExhausted);

        rc = unzip(enc, esize, &esize, src, ssize);
        src = enc;
    }
    if (rc == 0) {
        float last;
        unsigned i;
        unsigned j;
        
        for (j = i = 0, last = 0.0; i != count; ++i, j += 4) {
            union { float f; uint32_t u; } y;
            
            y.u = (((((src[j + 0] << 8) | src[j + 1]) << 8) | src[j + 2]) << 8) | src[j + 3];
            if ( isnan(y.f) ) {
                j += 4;
                y.u = (((((src[j + 0] << 8) | src[j + 1]) << 8) | src[j + 2]) << 8) | src[j + 3];
                last = 0.0;
            }
            dst[i] = (last += y.f);
        }
    }
    if (enc)
        free(enc);
	return rc;
}
示例#28
0
static void DlgUpdateSilent(void *lParam)
{
	OBJLIST<FILEINFO> &UpdateFiles = *(OBJLIST<FILEINFO> *)lParam;
	if (UpdateFiles.getCount() == 0) {
		delete &UpdateFiles;
		return;
	}

	// 1) If we need to escalate priviledges, launch a stub
	if (!PrepareEscalation()) {
		delete &UpdateFiles;
		return;
	}

	AutoHandle pipe(hPipe);
	//create needed folders after escalating priviledges. Folders creates when we actually install updates
	TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];

	mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);

	mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp);

	// 2) Download all plugins
	HANDLE nlc = NULL;
	// Count all updates that have been enabled
	int count = 0;
	for (int i = 0; i < UpdateFiles.getCount(); i++) {
		if (UpdateFiles[i].bEnabled && !UpdateFiles[i].bDeleteOnly) {
			// download update
			FILEURL *pFileUrl = &UpdateFiles[i].File;
			if (!DownloadFile(pFileUrl, nlc)) {
				// interrupt update as we require all components to be updated
				Netlib_CloseHandle(nlc);
				SkinPlaySound("updatefailed");
				delete &UpdateFiles;
				return;
			}
			count++;
		}

	}
	Netlib_CloseHandle(nlc);

	// All available updates have been disabled
	if (count == 0) {
		delete &UpdateFiles;
		return;
	}

	// 3) Unpack all zips
	VARST tszMirandaPath(_T("%miranda_path%"));
	for (int i = 0; i < UpdateFiles.getCount(); i++) {
		FILEINFO& p = UpdateFiles[i];
		if (p.bEnabled) {
			if (p.bDeleteOnly) {
				// we need only to backup the old file
				TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH];
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
				BackupFile(p.tszNewName, tszBackFile);
			}
			else {
				// if file name differs, we also need to backup the old file here
				// otherwise it would be replaced by unzip
				if (_tcsicmp(p.tszOldName, p.tszNewName)) {
					TCHAR tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH];
					mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
					mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
					BackupFile(tszSrcPath, tszBackFile);
				}
				
				// remove .zip after successful update
				if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, true))
					SafeDeleteFile(p.File.tszDiskPath);
			}
		}
	}
	delete &UpdateFiles;
	SkinPlaySound("updatecompleted");

#if MIRANDA_VER < 0x0A00
	// 4) Change title of clist
	ptrT title = db_get_tsa(NULL, "CList", "TitleText");
	if (!_tcsicmp(title, _T("Miranda IM")))
		db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG"));
#endif

	opts.bForceRedownload = false;
	db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);

	db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5);
	db_set_b(NULL, MODNAME, DB_SETTING_NEED_RESTART, 1);

	// 5) Prepare Restart
	TCHAR tszTitle[100];
	mir_sntprintf(tszTitle, SIZEOF(tszTitle), TranslateT("%d component(s) was updated"), count);		

	if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) {
		ShowPopup(tszTitle,TranslateT("You need to restart your Miranda to apply installed updates."),POPUP_TYPE_MSG);
	} else {
		bool notified = false;

		if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
			MIRANDASYSTRAYNOTIFY err;
			err.szProto = MODULEA;
			err.cbSize = sizeof(err);
			err.dwInfoFlags = NIIF_INTERN_UNICODE | NIIF_INFO;
			err.tszInfoTitle = tszTitle;
			err.tszInfo = TranslateT("You need to restart your Miranda to apply installed updates.");
			err.uTimeout = 30000;

			notified = !CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&err);
		}
			
		if (!notified) {
			// Error, let's try to show MessageBox as last way to inform user about successful update
			TCHAR tszText[200];
			mir_sntprintf(tszText, SIZEOF(tszText), _T("%s\n\n%s"), TranslateT("You need to restart your Miranda to apply installed updates."), TranslateT("Would you like to restart it now?"));

			if (MessageBox(NULL, tszText, tszTitle, MB_ICONINFORMATION | MB_YESNO) == IDYES)
#if MIRANDA_VER >= 0x0A00
				CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0);
#else
				CallFunctionAsync(RestartMe, 0);
#endif
		}
	}
}
示例#29
0
void unzip_if_needed(uint32_t * where_p, uint32_t * size_p)
{
    uint32_t where = *where_p;
    uint32_t size = *size_p;
    uint32_t zbytes;
    uint32_t startrange, endrange;
    uint32_t gzdatasize, gzwhere;
    uint32_t orig_crc, offset;
    uint32_t target = 0;
    int i, okmem;

    /* Is it a gzip image? */
    if (check_zip((void *)where, size, &zbytes, &gzdatasize,
		  &orig_crc, &offset) == 0) {

	if (offset + zbytes > size) {
	    /*
	     * Assertion failure; check_zip is supposed to guarantee this
	     * never happens.
	     */
	    die("internal error: check_zip returned nonsense\n");
	}

	/*
	 * Find a good place to put it: search memory ranges in descending
	 * order until we find one that is legal and fits
	 */
	okmem = 0;
	for (i = nranges - 1; i >= 0; i--) {
	    /*
	     * We can't use > 4G memory (32 bits only.)  Truncate to 2^32-1
	     * so we don't have to deal with funny wraparound issues.
	     */

	    /* Must be memory */
	    if (ranges[i].type != 1)
		continue;

	    /* Range start */
	    if (ranges[i].start >= 0xFFFFFFFF)
		continue;

	    startrange = (uint32_t) ranges[i].start;

	    /* Range end (0 for end means 2^64) */
	    endrange = ((ranges[i + 1].start >= 0xFFFFFFFF ||
			 ranges[i + 1].start == 0)
			? 0xFFFFFFFF : (uint32_t) ranges[i + 1].start);

	    /* Make sure we don't overwrite ourselves */
	    if (startrange < (uint32_t) & _end)
		startrange = (uint32_t) & _end;

	    /* Allow for alignment */
	    startrange =
		(ranges[i].start + (UNZIP_ALIGN - 1)) & ~(UNZIP_ALIGN - 1);

	    /* In case we just killed the whole range... */
	    if (startrange >= endrange)
		continue;

	    /*
	     * Must be large enough... don't rely on gzwhere for this
	     * (wraparound)
	     */
	    if (endrange - startrange < gzdatasize)
		continue;

	    /*
	     * This is where the gz image would be put if we put it in this
	     * range...
	     */
	    gzwhere = (endrange - gzdatasize) & ~(UNZIP_ALIGN - 1);

	    /* Cast to uint64_t just in case we're flush with the top byte */
	    if ((uint64_t) where + size >= gzwhere && where < endrange) {
		/*
		 * Need to move source data to avoid compressed/uncompressed
		 * overlap
		 */
		uint32_t newwhere;

		if (gzwhere - startrange < size)
		    continue;	/* Can't fit both old and new */

		newwhere = (gzwhere - size) & ~(UNZIP_ALIGN - 1);
		printf("Moving compressed data from 0x%08x to 0x%08x\n",
		       where, newwhere);

		memmove((void *)newwhere, (void *)where, size);
		where = newwhere;
	    }

	    target = gzwhere;
	    okmem = 1;
	    break;
	}

	if (!okmem)
	    die("Not enough memory to decompress image (need 0x%08x bytes)\n",
		gzdatasize);

	printf("gzip image: decompressed addr 0x%08x, len 0x%08x: ",
	       target, gzdatasize);

	*size_p = gzdatasize;
	*where_p = (uint32_t) unzip((void *)(where + offset), zbytes,
				    gzdatasize, orig_crc, (void *)target);
    }
}
示例#30
0
static void ApplyUpdates(void *param)
{
	HWND hDlg = (HWND)param;
	OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
	if (todo.getCount() == 0) {
		return;
	}

	// 1) If we need to escalate priviledges, launch a stub
	if (!PrepareEscalation()) {
		PostMessage(hDlg, WM_CLOSE, 0, 0);
		return;
	}

	AutoHandle pipe(hPipe);
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
	//create needed folders after escalating priviledges. Folders creates when we actually install updates
	TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];
	mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);
	mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp); 

	// 2) Download all plugins
	HANDLE nlc = NULL;
	for (int i=0; i < todo.getCount(); i++) {
		ListView_EnsureVisible(hwndList, i, FALSE);
		if (!todo[i].bEnabled) {
			SetStringText(hwndList, i, TranslateT("Skipped."));
		}
		else if (todo[i].bDeleteOnly) {
			SetStringText(hwndList, i, TranslateT("Will be deleted!"));
		}
		else {
			// download update
			SetStringText(hwndList, i, TranslateT("Downloading..."));

			FILEURL *pFileUrl = &todo[i].File;
			if (!DownloadFile(pFileUrl, nlc)) {
				SetStringText(hwndList, i, TranslateT("Failed!"));

				// interrupt update as we require all components to be updated
				Netlib_CloseHandle(nlc);
				PostMessage(hDlg, UM_ERROR, 0, 0);
				SkinPlaySound("updatefailed");
				return;
			}
			SetStringText(hwndList, i, TranslateT("Succeeded."));
		}
	}
	Netlib_CloseHandle(nlc);

	// 3) Unpack all zips
	VARST tszMirandaPath(_T("%miranda_path%"));
	for (int i = 0; i < todo.getCount(); i++) {
		FILEINFO& p = todo[i];
		if (p.bEnabled) {
			if (p.bDeleteOnly) { 
				// we need only to backup the old file
				TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH];
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
				BackupFile(p.tszNewName, tszBackFile);
			}
			else {
				// if file name differs, we also need to backup the old file here
				// otherwise it would be replaced by unzip
				if ( _tcsicmp(p.tszOldName, p.tszNewName)) {
					TCHAR tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH];
					mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
					mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
					BackupFile(tszSrcPath, tszBackFile);
				}

				if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack,true))
					SafeDeleteFile(p.File.tszDiskPath);  // remove .zip after successful update
			}
		}
	}
	SkinPlaySound("updatecompleted");

#if MIRANDA_VER < 0x0A00
	// 4) Change title of clist
	ptrT title = db_get_tsa(NULL, "CList", "TitleText");
	if (!_tcsicmp(title, _T("Miranda IM")))
		db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG"));
#endif

	opts.bForceRedownload = false;
	db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);

	db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5);

	// 5) Prepare Restart
	int rc = MessageBox(hDlg, TranslateT("Update complete. Press Yes to restart Miranda now or No to postpone a restart until the exit."), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION);
	PostMessage(hDlg, WM_CLOSE, 0, 0);
	if (rc == IDYES)
#if MIRANDA_VER >= 0x0A00
		CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0);
#else
		CallFunctionAsync(RestartMe, 0);
#endif
}