/* * Translate options related to precompiled headers. */ static void precomp_header_opts( struct XlatStatus *status, OPT_STORAGE *cmdOpts, CmdLine *compCmdLine ) /***************************************************************************/ { char * newpath; status = status; if( cmdOpts->Fp ) { newpath = PathConvert( cmdOpts->Fp_value->data, '"' ); AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-fhq=%s", newpath ); } else { switch( cmdOpts->precomp_headers ) { case OPT_precomp_headers_Yc: /* fall through */ case OPT_precomp_headers_Yu: /* fall through */ case OPT_precomp_headers_YX: AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-fhq" ); break; case OPT_precomp_headers_default: break; default: Zoinks(); } } if( cmdOpts->Yd ) { /* done by default */ } }
/* * Add a file to the list. If its type is TYPE_DEFAULT_FILE, then file_type * will be called to determine the file's type. */ void AddFile( int type, const char *filename ) /********************************************/ { struct ListElem * newElem; struct ListElem * curElem; char * newfilename; /*** Initialize a new ListElem structure ***/ newElem = AllocMem( sizeof(struct ListElem) ); newfilename = PathConvert( filename, '"' ); newElem->filename = newfilename; if( type == TYPE_DEFAULT_FILE ) { newElem->type = file_type( newfilename ); } else { newElem->type = type; } newElem->next = NULL; /*** Add it to the end of the list (to maintain order) ***/ if( fileList == NULL ) { fileList = newElem; } else { curElem = fileList; while( curElem->next != NULL ) curElem = curElem->next; curElem->next = newElem; } }
QPixmap LoadPDF(QString fn, int Page, int w ) { QString tmp, cmd1, cmd2; const QString pdfFile = PathConvert(fn); const QString tmpFile = PathConvert(QDir::homePath()+"/sctodaytmps.png"); const QString qttmpFile = QDir::homePath()+"/sctodaytmps.png"; QPixmap pm; tmp.setNum(Page); int ret = -1; tmp.setNum(Page); QStringList args; args.append("-sDEVICE=png16m"); args.append("-r72"); args.append("-dGraphicsAlphaBits=4"); args.append("-o"); args.append(tmpFile); args.append("-dFirstPage="+tmp); args.append("-dLastPage="+tmp); args.append(pdfFile); ret = callGS(args); ////////qDebug() << "### ret " << ret; if (ret == 0) { QPixmap tmpimage(qttmpFile); QPixmap penna = tmpimage.scaledToWidth(w); tmpimage.detach(); QFile lastaction(qttmpFile); lastaction.remove(); QPainter p; p.begin(&penna); p.setBrush(Qt::NoBrush); p.setPen(QPen(QBrush(Qt::black),2,Qt::SolidLine)); p.drawRect(0, 0, penna.width(), penna.height()); p.end(); return penna; } return pm; }
/* * Scan a filename. No leading whitespace is allowed. Returns a pointer * to newly allocated memory containing the filename string. If filename * contained a quote character, returned string contains quotes. If leading * whitespace is found, returns NULL. */ char *CmdScanFileName( void ) /***************************/ { char * str; char * newstr; str = CmdScanString(); if( str != NULL ) { newstr = PathConvert( str, '"' ); FreeMem( str ); } else { newstr = NULL; } return( newstr ); }
QPixmap LoadPS( QString fn , const QString arguments_append ) { const QString pdfFile = PathConvert(fn); QChar letter('A' + (qrand() % 26)); QDateTime timer1( QDateTime::currentDateTime() ); const QString qttmpFile = _GSCACHE_+QString("%2_%1.png").arg( timer1.toString("yyyy-MM-dd-HH-mm-ss-zzz") ).arg(letter); QFileInfo fitmp(qttmpFile); const int VersionGS = getGSVersion(); QFile lastaction(fitmp.absoluteFilePath()); lastaction.remove(); QPixmap pm; int ret = -1; QStringList args; if (arguments_append.size() > 3) { args.append(arguments_append); } if (VersionGS >=8) { args.append("-sDEVICE=png16m"); args.append("-dGraphicsAlphaBits=4"); args.append("-r72"); args.append("-o"); args.append(fitmp.fileName()); args.append(pdfFile); } else { args.append("-sDEVICE=pnggray"); args.append("-r72x72"); args.append("-sOutputFile="+fitmp.fileName()); args.append("-q"); args.append(pdfFile); } ret = callGS(args); //////////qDebug() << "### ret " << ret << " VersionGS->" << VersionGS; if (ret == 0) { QPixmap tmpimage(fitmp.absoluteFilePath()); lastaction.remove(); return tmpimage; } return pm; }
/* * This function is for options which affect all source files differently. * Given the filename, it updates the given command line appropriately. Any * CmdLine pointer which is NULL is ignored. */ void HandleFileTranslate( const char *filename, CmdLine *compCmdLine, CmdLine *linkCmdLine ) /*******************************************************************/ { char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char fullPath[_MAX_PATH]; char * newpath; linkCmdLine = linkCmdLine; /*** Handle the /P switch ***/ if( status.preprocessToFile ) { if( compCmdLine != NULL ) { _splitpath( filename, drive, dir, fname, NULL ); _makepath( fullPath, NULL, NULL, fname, ".i" ); newpath = PathConvert( fullPath, '"' ); AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-fo=%s", newpath ); } } }
/* * Convert the resource file. */ static int res_convert( const OPT_STORAGE *cmdOpts ) /**************************************************/ { const size_t bufsize = 32768; void * buf; char * infilename; char outfilename[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; FILE * in; FILE * out; long bytes; size_t amount; size_t rc; char * p; /*** Get the name of the .res file to compile ***/ infilename = GetNextFile( NULL, TYPE_RES_FILE, TYPE_INVALID_FILE ); if( infilename == NULL ) return( CVTRES_NOACTION ); infilename = PathConvert( infilename, '\"' ); if( GetNextFile( NULL, TYPE_RES_FILE, TYPE_INVALID_FILE ) != NULL ) { FatalError( "Can only convert one file at a time" ); } /*** Determine the name of the output file ***/ strcpy( outfilename, "" ); if( cmdOpts->o_value != NULL ) { /* /O used */ p = PathConvert( cmdOpts->o_value->data, '\"' ); strcpy( outfilename, p ); FreeMem( p ); } if( cmdOpts->out_value != NULL ) { /* /OUT used (overrides /O) */ p = PathConvert( cmdOpts->out_value->data, '\"' ); strcpy( outfilename, p ); FreeMem( p ); } if( !strcmp( outfilename, "" ) ) { /* based on input filename */ _splitpath( infilename, drive, dir, fname, NULL ); _makepath( outfilename, drive, dir, fname, ".obj" ); } if( cmdOpts->showwopts ) { fprintf( stderr, "copy %s %s\n", infilename, outfilename ); } if( !cmdOpts->noinvoke ) { /*** Prepare to convert (copy) the file ***/ buf = AllocMem( bufsize ); in = fopen( infilename, "rb" ); if( in == NULL ) FatalError( "Cannot open '%s'", infilename ); out = fopen( outfilename, "wb" ); if( out == NULL ) FatalError( "Cannot create '%s'", outfilename ); bytes = filelength( fileno( in ) ); if( bytes == -1L ) FatalError( "Cannot get size of '%s'", infilename ); /*** Convert (copy) the file ***/ while( bytes > 0L ) { amount = ( bytes >= bufsize ) ? bufsize : (size_t)bytes; rc = fread( buf, amount, 1, in ); if( rc == 0 ) FatalError( "Cannot read from '%s'", infilename ); rc = fwrite( buf, amount, 1, out ); if( rc == 0 ) FatalError( "Cannot write to '%s'", outfilename ); bytes -= amount; } fclose( in ); fclose( out ); } return( CVTRES_SUCCESS ); }
/* * Compile any C and C++ files. Returns COMPILE_NOACTION if there was no * file to compile, COMPILE_ERROR if the compiler returned a bad status code * or if the compiler could not be spawned, or else COMPILE_SUCCESS if * everything went smoothly. */ static int compile( const OPT_STORAGE *cmdOpts, CmdLine *compCmdLine ) /********************************************************************/ { CmdLine * cloneCmdLine; char ** args = NULL; char * filename; int fileType; char * compiler = NULL; int rc; int alive = 1; int numCompiled = 0; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; char fullPath[_MAX_PATH]; int count; /*** Process all the source files, in the order they were given ***/ while( alive ) { filename = GetNextFile( &fileType, TYPE_C_FILE, TYPE_CPP_FILE, TYPE_INVALID_FILE ); if( filename == NULL ) break; /*** Prepare to spawn the compiler ***/ cloneCmdLine = CloneCmdLine( compCmdLine ); HandleFileTranslate( filename, cloneCmdLine, NULL ); switch( fileType ) { case TYPE_C_FILE: compiler = C_COMPILER; AppendCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, compiler ); AppendCmdLine( cloneCmdLine, CL_C_FILENAMES_SECTION, filename ); if( !cmdOpts->nowopts ) { AppendCmdLine( cloneCmdLine, CL_C_OPTS_SECTION, "-aa" ); } args = MergeCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, CL_C_MACROS_SECTION, CL_C_OPTS_SECTION, CL_C_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); break; case TYPE_CPP_FILE: compiler = CPP_COMPILER; AppendCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, compiler ); AppendCmdLine( cloneCmdLine, CL_C_FILENAMES_SECTION, filename ); args = MergeCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, CL_C_MACROS_SECTION, CL_C_OPTS_SECTION, CL_C_CPP_OPTS_SECTION, CL_C_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); break; default: Zoinks(); } /*** Spawn the compiler ***/ _splitpath( filename, drive, dir, fname, ext ); fprintf( stderr, "%s%s\n", fname, ext ); /* print name of file we're compiling */ if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, compiler, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", compiler ); } else { return( COMPILE_ERROR ); } } } /*** Add the object file to the linker list, observe -Fo ***/ if( cmdOpts->Fo ) { AddFile( TYPE_OBJ_FILE, PathConvert( cmdOpts->Fo_value->data, '"' ) ); } else { _makepath( fullPath, NULL, NULL, fname, ".obj" ); AddFile( TYPE_OBJ_FILE, fullPath ); } /*** Prepare for the next iteration ***/ DestroyCmdLine( cloneCmdLine ); numCompiled++; } if( numCompiled > 0 ) { return( COMPILE_SUCCESS ); } else { return( COMPILE_NOACTION ); } }
/* * Parse linker options. */ static void linker_opts( struct XlatStatus *status, OPT_STORAGE *cmdOpts, CmdLine *linkCmdLine ) /***********************************************************************/ { OPT_STRING * optStr; char * newpath; if( cmdOpts->F ) { AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/STACK:%s", cmdOpts->F_value->data ); } if( cmdOpts->Fe ) { AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/OUT:%s", cmdOpts->Fe_value->data ); } optStr = cmdOpts->o_value; if( cmdOpts->o_value != NULL ) { newpath = PathConvert( optStr->data, '"' ); AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/OUT:%s", newpath ); } if( cmdOpts->Fm ) { if( cmdOpts->Fm_value != NULL ) { AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/MAP:%s", cmdOpts->Fm_value->data ); } else { AppendCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/MAP" ); } } if( cmdOpts->LD ) { AppendCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/DLL" ); } if( cmdOpts->link ) { optStr = cmdOpts->link_value; while( optStr != NULL ) { AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "%s", optStr->data ); optStr = optStr->next; } } switch( cmdOpts->debug_info ) { case OPT_debug_info_Zd: AppendCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/DEBUG" ); status->debugLevel = 1; break; case OPT_debug_info_Z7: /* fall through */ case OPT_debug_info_Zi: AppendCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/DEBUG" ); status->debugLevel = 2; break; case OPT_debug_info_default: /* do nothing */ break; default: Zoinks(); } }
/* * Translate options related to object files. */ static void object_opts( struct XlatStatus *status, OPT_STORAGE *cmdOpts, CmdLine *compCmdLine ) /***********************************************************************/ { char * newpath; if( cmdOpts->Fo && !status->disable_Fo ) { newpath = PathConvert( cmdOpts->Fo_value->data, '"' ); AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-fo=%s", newpath ); } if( cmdOpts->Gh ) { AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-ep" ); } if( cmdOpts->Gy ) { AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-zm" ); } if( cmdOpts->LD ) { AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-bd" ); if( cmdOpts->threads_linking==OPT_threads_linking_default ) { cmdOpts->threads_linking = OPT_threads_linking_MT; } } switch( cmdOpts->threads_linking ) { case OPT_threads_linking_MD: case OPT_threads_linking_MDd: AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-bm" ); if( !cmdOpts->_10x ) { AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-br" ); } break; case OPT_threads_linking_ML: case OPT_threads_linking_MLd: break; case OPT_threads_linking_MT: case OPT_threads_linking_MTd: AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-bm" ); break; case OPT_threads_linking_default: /* let the compiler use its default */ break; default: Zoinks(); } switch( cmdOpts->debug_info ) { case OPT_debug_info_Z7: AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-hd" ); status->debugLevel = 2; break; case OPT_debug_info_Zd: AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-hd" ); status->debugLevel = 1; break; case OPT_debug_info_Zi: /* unsupported */ case OPT_debug_info_default: /* do nothing */ break; default: Zoinks(); } if( cmdOpts->Zl ) { AppendCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-zl" ); } if( cmdOpts->Zp ) { AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-zp%d", cmdOpts->Zp_value ); } }
/* * Translate options related to the preprocessor. */ static void preprocessor_opts( struct XlatStatus *status, OPT_STORAGE *cmdOpts, CmdLine *compCmdLine ) /*************************************************************************/ { int preserveComments = 0; int includeLines = 1; /* use #line directives */ int preprocess = 0; OPT_STRING * optStr; char * newpath; optStr = cmdOpts->I_value; while( optStr != NULL ) { newpath = PathConvert( optStr->data, '"' ); AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-i=%s", newpath ); optStr = optStr->next; } optStr = cmdOpts->FI_value; while( optStr != NULL ) { newpath = PathConvert( optStr->data, '"' ); AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-fi=%s", newpath ); optStr = optStr->next; } if( cmdOpts->C ) { if( !cmdOpts->E && !cmdOpts->P && !cmdOpts->EP ) { Warning( "/C requires /E, /P, or /EP -- option ignored" ); } else { preserveComments = 1; } } if( cmdOpts->E ) { status->disable_c = 1; status->disable_FA = 1; status->disable_Fa = 1; status->disable_Fm = 1; status->disable_Fo = 1; preprocess = 1; } if( cmdOpts->P ) { status->disable_c = 1; status->disable_FA = 1; status->disable_Fa = 1; status->disable_Fm = 1; status->disable_Fo = 1; preprocess = 1; status->preprocessToFile = 1; } if( cmdOpts->EP ) { status->disable_c = 1; status->disable_FA = 1; status->disable_Fa = 1; status->disable_Fm = 1; status->disable_Fo = 1; preprocess = 1; includeLines = 0; } if( preprocess ) { AppendFmtCmdLine( compCmdLine, CL_C_OPTS_SECTION, "-p%s%s", includeLines ? "l" : "", preserveComments ? "c" : "" ); } }