zoukankan      html  css  js  c++  java
  • MyOd

    MyOd

    代码

    "head.h"

    #ifndef HEAD_H_
    #define HEAD_H_
    
    #include <stdio.h>
    #include <unistd.h>
    #include <string.h>
    #include <errno.h>
    #include <stdbool.h>
    
    long Mtx(FILE *fp, bool recovery);
    long Mtc(FILE *fp, bool flag);
    
    #endif
    

    "mian.c"

    #include "head.h"
    
    int main(int argc, char *argv[])
    {
    
        const char *filename;
        if(argc == 3)
        {
            filename = argv[2];
        }
        else if(argc == 4)
        {
            filename = argv[3];
        }
        else
        {
            fprintf(stderr, "the argument is less.
    	eg:%s [option] <file>
    ",argv[0]);
            return 1;
        }
    
        FILE *fp = fopen(filename, "rt+");
        if (!fp)
        {
            fprintf(stderr, "open file %s was failed:%s
    ", argv[1], strerror(errno));
            return 1;
        }
        long current_pos = 0;
        while (!feof(fp))
        {
            printf("%08o ", (unsigned int)current_pos);
            if(argc == 4)
            {
                if(strcmp(argv[1], "-tx") == 0)
                {
                    Mtx(fp,true);
                    current_pos = Mtc(fp,true);
                }
            }
            else if (argc == 3 && (strcmp(argv[1], "-tx") == 0))
            {
                current_pos = Mtx(fp, false);
            }
            else if (argc == 3 && (strcmp(argv[1], "-tc") == 0))
            {
                current_pos = Mtc(fp,false);
            }
    
        }
        printf("
    %08o 
    ", (unsigned int)current_pos);
        fclose(fp);
        return 0;
    }
    
    

    "tx.c"

    #include "head.h"
    
    long Mtx(FILE *fp, bool recovery)
    {
        long ptr = ftell(fp);
        char buffer[5] = {0};
        char c;
        for (int i = 1; (c = fgetc(fp)) != EOF || i % 4 != 0; i++)
        {
            buffer[(i - 1) % 4] = c;
            if (i % 4 == 0 )
            {
                printf("        %02x%02x%02x%02x ", buffer[3], buffer[2], buffer[1], buffer[0]);
            }
            if (i % 16 == 0)
            {
                printf("
    ");
                break;
            }
        }
        if (recovery)
        {
            fseek(fp, ptr, SEEK_SET);
        }
        return ftell(fp);
    }
    

    "tc.c"

    #include "head.h"
    
    long Mtc(FILE *fp, bool flag)
    {
        char c;
        int i;
        if(flag)
        {
            printf("            ");
        }
        long ptr = ftell(fp);
        fseek(fp, 0L, SEEK_END);
        long end = ftell(fp) - ptr;
         fseek(fp, ptr, SEEK_SET);
         if(end < 16)
         {
             printf("
                ");
         }
        for (i = 1; (c = fgetc(fp)) != EOF; i++)
        {
    
            if (c == '
    ')
            {
                printf("\n");
                printf("   ");
            }
            else
            {
                putchar(c);
                printf("   ");
            }
            if (i % 16 == 0)
            {
                printf("
    ");
                break;
            }
        }
        return ftell(fp);
    }
    

    库制作

    动态库制作:

    makefile:

    MyodD: src/main.c libdynamic.so  
    	gcc -Iinclude src/main.c -Llib -ldynamic -o $@
    	export LD_LIBRARY_PATH=./lib
    libdynamic.so: tx.o tc.o 
    	gcc -shared -o lib/libdynamic.so bin/dynamic/*.o
    
    tx.o: src/tx.c include/head.h
    	gcc -Iinclude -c -fPIC $< -o bin/dynamic/$@
    
    tc.o: src/tc.c include/head.h
    	gcc -Iinclude -c -fPIC $< -o bin/dynamic/$@
    

    过程截图:

    静态库制作:

    makefile:

    MyodS: src/main.c libstatic.a  
    	gcc -Iinclude -static src/main.c -Llib -lstatic -o $@
    
    libstatic.a: tx.o tc.o 
    	ar rcvs -o  lib/$@ bin/static/*.o
    
    tx.o: src/tx.c include/head.h
    	gcc -Iinclude -c $< -o bin/static/$@
    
    tc.o: src/tc.c include/head.h
    	gcc -Iinclude -c $< -o bin/static/$@
    

    过程截图:

    运行结果

  • 相关阅读:
    发送ajax步骤
    web app开发技巧总结
    移动端常见问题及解决方案
    【转】Session Cookie Token的区别
    call、apply、bind的区别
    【转】rem自适应布局
    ThinkPHP系统内置单字母函数函数
    thinkphp buildsql和fetchsql的区别
    thinkphp 3.2.3重写 pdo链接
    thinkphp pdo 重写问题
  • 原文地址:https://www.cnblogs.com/WANGYUHAN/p/15339554.html
Copyright © 2011-2022 走看看