基础版本的jmake是将所有当前文件夹下的C/C++文件生成单文件编译命令,并且jmake命令不可加选项。

现在做的改进是能在输入命令jmake时加上一些选项了,‘-’开头的选项加入到每个编译单文件的生成命令中去,其他的选项则是指定要编译的源文件。当然,如果没有指定源文件,就把所有.c,.cc,.cpp文件都分别编译。

代码如下:

/*
 * author: huanglianjing
 *
 * this is a program to compile all single c/c++ file of current directory
 *
 * usage: jmake <files> <-options>
 * if no files assigned, all files in directory will be searched
 * any option will be added to every instruction
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>

][], option[][];
int filenum, optionnum;

];

int file_in_argv(char *filename)//whether filename in argv
{
    int i;
    ; i<filenum; ++i) {
        ) ;
    }
    ;
}

void suffix(char *filename)//get filetype, return empty string if not has
{
    int len = strlen(filename);
    int pos;
    ; pos>=; --pos) {
        if (filename[pos] == '.') break;
    }
     || pos == len-) suf[] = ;
    else {
        int i;
        ; i<len--pos; ++i) suf[i] = filename[pos++i];
        suf[len--pos] = ;
    }
}

int main(int argc, char *argv[])
{
    struct dirent *entry;
    struct stat statbuf;

    int i;
    filenum = optionnum = ;
    ; i<argc; ++i) {
        ] == '-') {//option
            strcpy(option[optionnum++],argv[i]);
        }
        else {//file
            strcpy(file[filenum++],argv[i]);
        }
    }

    DIR *dp = opendir(".");
    ;
    while ((entry=readdir(dp)) != NULL) {
        lstat(entry->d_name,&statbuf);
        if (!S_ISDIR(statbuf.st_mode)) {
            ], ename[], instruction[];
            strcpy(fname,entry->d_name);
            strcpy(ename,entry->d_name);
             || file_in_argv(fname)) ;//consider this file
            else continue;//not consider this file
            int len = strlen(fname);
            suffix(fname);
            ) {//.c
                ename[len-] = '\0';
                sprintf(instruction,"gcc %s -o %s",fname,ename);
                ; i<optionnum; ++i) {
                    strcat(instruction," ");
                    strcat(instruction,option[i]);
                }
                ++insnum;
                printf("%s\n",instruction);
                system(instruction);
            }
            ) {//.cc
                ename[len-] = '\0';
                sprintf(instruction,"g++ %s -o %s",fname,ename);
                ; i<optionnum; ++i) {
                    strcat(instruction," ");
                    strcat(instruction,option[i]);
                }
                ++insnum;
                printf("%s\n",instruction);
                system(instruction);
            }
            ) {//.cpp
                ename[len-] = '\0';
                sprintf(instruction,"g++ %s -o %s",fname,ename);
                ; i<optionnum; ++i) {
                    strcat(instruction," ");
                    strcat(instruction,option[i]);
                }
                ++insnum;
                printf("%s\n",instruction);
                system(instruction);
            }
        }
    }
    ) puts("no file compiled");

    closedir(dp);
    exit();
}

jmake 编译当前目录c/c++单文件 指定文件 可加选项的更多相关文章

  1. jmake 编译当前目录所有c/c++单文件

    在一个目录下写一些单文件的c或者c++文件时,每次敲出命令如g++ a.cpp -o a感觉比较麻烦. 所以就模仿makefile的功能,实现了扫描当前目录,并将所有c文件.cc文件.cpp文件直接调 ...

  2. Nginx下载文件指定文件名称

    配置 location ^~/TEMP/ { alias/share/files/; if ($request_uri ~* ^.*\/(.*)\.(txt|doc|pdf|rar|gz|zip|do ...

  3. scala 读取文件加下的指定文件

    1,获取指定类型文件 def getFile(file:File): Array[File] ={ val files = file.listFiles().filter(! _.isDirector ...

  4. python实现在目录中查找指定文件的方法

    python实现在目录中查找指定文件的方法 本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from ...

  5. dos 下删除文件、文件夹

    删除文件 /p 删除每一个文件之前提示确认/f 强制删除只读文件 /s 从当前目录及所有子目录删除指定文件/q 安静模式.删除全局通配符时,不要求确认/a 根据属性选择要删除的文件 指定下列文件属性中 ...

  6. php清理当前目录下的指定文件和空目录(源码),建议服务器端执行

    <?php /** * @desc 解析当前目录并递归删除目录下的指定文件 * @author mengdj<mengdj@outlook.com> 2014.10.02 1530 ...

  7. 如何解决Visual Studio2010 编译时提示系统找不到指定文件问题

    前一段时间,开始使用vs2010编写程序,可是在编译的时候总是报错,提示系统找不到指定文件,导致无法正常运行程序,花了好久时间终于找到原因解决,是因为常规的输出目录 要与链接的常规的输出文件要相对应. ...

  8. [问题解决]gradle编译失败系统找不到指定的文件

    [问题解决]gradle编译失败系统找不到指定的文件 问题描述 Error:C:\Users\diql.gradle\caches\2.14.1\scripts-remapped\settings_9 ...

  9. bat 读取当前目录指定文件信息并拼接

    bat 读取指定文件的信息并拼接成指定格式

随机推荐

  1. Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout,TableLayout引起页面崩溃

    在使用TableLayout的时候,运行引用程序直接Crash. FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 9703 java. ...

  2. MSSQL 获取数据库字段类型

    SELECT col.name AS 列名, typ.name as 数据类型, col.max_length AS 占用字节数, col.precision AS 数字长度, col.scale A ...

  3. Oracle之PLSQL总结

    基本数据类型变量 1. 基本数据类型     Number 数字型     Int 整数型     Pls_integer 整数型,产生溢出时出现错误 Binary_integer 整数型,表示带符号 ...

  4. stream~filestream

    http://blog.csdn.net/feliciafay/article/details/6157356 http://blog.csdn.net/feliciafay/article/deta ...

  5. View, Activity, Window

    View, Activity, Window 2010-03-02 10:42:56|  分类: android|举报|字号 订阅     对于屏幕显示而言,整个是window,这个window里显示 ...

  6. windows下开发PHP扩展(无需Cygwin)

    第一步:准备 1.php源码包和windows下的二进制包,以及安装Visual C++,并把Microsoft Visual Studio/Common/MSDev98/Bin的绝对路径添加到win ...

  7. Android Studido下的应用性能优化总结--布局优化

    前言:一个应用的成功=产品设计*性能 ,再此我们不讨论一个应用的设计,那交给我们可爱又可恨的产品经理和UI设计师来决定!所以这里分步骤讨论如何提升一个应用的性能,这里先探讨布局优化问题. 布局优化 避 ...

  8. poj 1664 放苹果_整数拆分

    题意:略 用手机敲的代码真是泪流满面,终于过了 #include<iostream> using namespace std; int dp[110][110]; void solve() ...

  9. smb相关资料

    smb相关资料 看资料就上维基 https://en.wikipedia.org/wiki/Server_Message_Block#Implementation http://www.bing.co ...

  10. 各种浏览器兼容篡位的css样式写法

    谷歌浏览器的识别 @media screen and (-webkit-min-device-pixel-ratio:0) { height:10px; } IE6特制识别的 *HTML .Searc ...