MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / fsh_main

Function fsh_main

tools/fshtool.c:1796–1952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1794}
1795
1796int fsh_main(int argc,char **argv)
1797{
1798 FILE *f;
1799 char *outfn,*p;
1800 unsigned char *tmpbuf;
1801 int i,j,choice;
1802
1803 printf("===========================================================================\n");
1804 printf("FSHTOOL version 1.22 - (c) Denis Auroux 2002 - auroux@math.polytechnique.fr\n");
1805 printf("===========================================================================\n");
1806 sanity_check();
1807 if (argc==1) {
1808 usage();
1809 abandon_ship();
1810 }
1811
1812 /* try to open the given file and determine its type from the first few bytes */
1813 f=fopen(argv[1],"rb");
1814 if (f==NULL) {
1815 printf("Input file %s not found.\n",argv[1]);
1816 abandon_ship();
1817 }
1818
1819 fseek(f,0,SEEK_END);
1820 inlen=ftell(f);
1821 rewind(f);
1822 if (inlen<4) { printf("Truncated file ?\n"); abandon_ship(); }
1823 inbuf=malloc(inlen+2048); /* safety margin */
1824 if (inbuf==NULL) { printf("Insufficient memory.\n"); abandon_ship(); }
1825 if (fread(inbuf,1,inlen,f)!=(size_t)inlen)
1826 { printf("File read error.\n"); abandon_ship(); }
1827 fclose(f);
1828
1829 iscompr=0;
1830 if (((inbuf[0]&0xfe)==0x10)&&(inbuf[1]==0xfb)) {
1831 /* this is a compressed QFS file */
1832 iscompr=1;
1833 printf("Uncompressing QFS file (%d bytes) to memory...\n",inlen);
1834 tmpbuf=uncompress_data(inbuf,&inlen);
1835 free(inbuf);
1836 inbuf=tmpbuf;
1837 }
1838
1839 if (!strncmp(inbuf,"SHPI",4)) {
1840 /* this is a FSH file */
1841 printf("FSH data (%d bytes).\n",inlen);
1842
1843 /* find a target directory name */
1844 if (argv[2]!=NULL)
1845 outfn=strdup(argv[2]);
1846 else {
1847 outfn=strdup(argv[1]);
1848 i=strlen(outfn)-4;
1849 if (outfn[i]!='.') {
1850 printf("Don't know how to derive a directory name from '%s'\n",outfn);
1851 printf("Please specify a second command-line argument.\n");
1852 abandon_ship();
1853 }

Callers 1

ExtractQFSFunction · 0.85

Calls 7

sanity_checkFunction · 0.85
usageFunction · 0.85
abandon_shipFunction · 0.85
uncompress_dataFunction · 0.85
fsh_to_bmpFunction · 0.85
bmp_to_fshFunction · 0.85
compress_dataFunction · 0.85

Tested by

no test coverage detected