董怼怼ミ 2021-04-21 11:24 采纳率: 0%
浏览 19

行程编码压缩数据代码 1 个无法解析的外部命令

#include <stdio.h>
#include <string.h>
#include "dir.h"    /* for fnsplit() */
#include "rle8.h"
#include "StdAfx.h"
int main(int argc, char **argv)
{
    register int cur_char;                /* a character                    */
    register unsigned int i;              /* generic index variable         */
    register unsigned short run_len = 0;  /* length of character run so far */
    int run_char;                         /* which char run is of           */
    unsigned int j;                       /* another index variable         */
    unsigned short seq_len=0;             /* length of non-run sequence     */
    char scratch_space[256];              /* string scratch space           */
    char seq[MAX_LEN];                    /* buffer for uncompressible data */
    char orig_name[MAXFILE+MAXEXT];       /* original filename      */
    char drive[MAXDRIVE],                 /* needed for fnsplit()   */
         dir[MAXDIR],                     /* needed for fnsplit()   */
         filename[MAXFILE],               /* 8 chars, orig name     */
         ext[MAXEXT];                     /* 3 chars, orig ext      */
    char outfile_name[MAXFILE+MAXEXT];    /* output filename        */
    unsigned long  orig_total;              /* total number of unencoded bytes          */
    unsigned long  rle_total;               /* total number of encoded bytes            */
    FILE *infile;                           /* file ptr to input file (uncompressed)    */
    FILE *outfile;                          /* file ptr to output file (compressed)     */
    errno_t err;
    FILE *file;
    char *infile_name;
    fnsplit(argv[1], drive, dir, filename, ext);    /* get filename    */
    strcpy_s(orig_name, filename);
    strcat_s(orig_name, ext);
    strcpy_s(outfile_name, filename);       /* build output filename  */
    strcat_s(outfile_name, ".r8");
    if (argc != 2)
    {
        puts("Usage: RLE8 filename.ext compresses file to filename.r8");
        return 1;
    }
    puts("rle8  by Shaun Case 1991  public domain.");
    infile_name=argv[1];
    if ((err=fopen_s(&file,infile_name, "rb")) == NULL)
    {
        strcpy_s(scratch_space, "Uable to open ");
        strcat_s(scratch_space, infile_name);
        puts(scratch_space);
        return 1;
    }
    if ((err=fopen_s(&file,outfile_name, "wb")) == NULL)
    {
        strcpy_s(scratch_space, "Uable to open ");
        strcat_s(scratch_space, outfile_name);
        puts(scratch_space);
        return 1;
    }
    for (i = 0; i < 13; i++)            /* write original filename */
        fputc(orig_name[i], outfile);
    while (!feof(infile))
    {
        cur_char = fgetc(infile);
        if (feof(infile))
            continue;
        if (seq_len ==0)                /* haven't got a sequence yet   */
        {
            if (run_len == 0)           /* start a new run              */
            {
                run_char = cur_char;
                ++run_len;
                continue;
            }
            if (run_char == cur_char)   /* got another char in the run  */
                if (++run_len == MAX_LEN)
                {
                    fputc((int)MAX_RUN_HEADER, outfile);
                    fputc((int) run_char, outfile);
                    run_len = 0;
                    continue;
                }
                                   /* got a different character     */
                                   /* than the run we were building */
            if (run_len > 2)       /* so write out the run and      */
                                   /* start a new one of the new    */
                                   /* character.                    */
            {
                fputc((int)(RUN | run_len), outfile);
                fputc((int)run_char, outfile);
                run_len = 1;
                run_char   = cur_char;
                continue;
            }
            /* run was only one or two chars, make a seq out of it instead       */
            for (j = 0; j < run_len; j++);    /* copy 1 or 2 char run to seq[]   */
            {
                seq[seq_len] = run_char;
                ++seq_len;
                if (seq_len == MAX_LEN)       /* if seq[] is full, write to disk */
                {
                    fputc((int)MAX_SEQ_HEADER, outfile);
                    for (i = 0; i < seq_len; i++)
                        fputc((int)seq[i], outfile);
                    seq_len = 0;
                }
            }
            run_len = 0;
            seq[seq_len++] = cur_char;
            if (seq_len == MAX_LEN)        /* if seq[] is full, write to disk */
            {
                fputc((int)MAX_SEQ_HEADER, outfile);
                for (i = 0; i < seq_len; i++)
                    fputc((int)seq[i], outfile);
                seq_len = 0;
            }
        }
        else   /* a sequence exists */
        {
            if (run_len != 0)           /* if a run exists */
            {
                if (cur_char == run_char )  /* add to run!  Yay.  */
                {
                    ++run_len;
                    if (run_len == MAX_LEN)  /* if run is full */
                    {
                        /* write sequence that precedes run */
                        fputc((int)(SEQ | seq_len), outfile);
                        for (i = 0; i < seq_len; i++)
                            fputc((int)seq[i], outfile);
                        /* write run                        */
                        fputc((int)(RUN | run_len), outfile);
                        fputc((int)run_char, outfile);
                        /* and start out fresh              */
                        seq_len = run_len = 0;
                    }  /* end write full run with existing sequence */
                    continue;
                }  /* end add to run for sequence exists */
                /* we couldn't add to the run, and a preceding sequence */
                /* exists, so write the sequence and the run, and       */
                /* try starting a new run with the current character.   */
                /* write sequence that precedes run */
                fputc((int)(SEQ | seq_len), outfile);
                for (i = 0; i < seq_len; i++)
                    fputc((int)seq[i], outfile);
                /* write run                        */
                fputc((int)(RUN | run_len), outfile);
                fputc((int)run_char, outfile);
                /* and start a new run w/ cur_char  */
                seq_len = 0;
                run_len = 1;
                run_char = cur_char;
                continue;
            }    /* end can't add to existing run, and preceding seq exists */
            /* no run exists, but a sequences does.  Try to create a run    */
            /* by looking at cur_char and the last char of the sequence.    */
            /* if that fails, add the char to the sequence.                 */
            /* if the sequence is full, write it to disk.  (Slightly non    */
            /* optimal; we could wait one more char.  A small thing to fix  */
            /* if someone gets the urge...                                  */
            if (seq[seq_len - 1] == cur_char)       /* if we can make a run */
            {
                run_char = cur_char;
                run_len = 2;
                --seq_len;
                continue;
            }
            /* couldn't make a run, add char to seq.  Maybe next time       */
            /* around...                                                    */
            seq[seq_len++] = cur_char;
            if (seq_len == MAX_LEN) /* if the sequence is full, write out   */
           {
                fputc((int)MAX_SEQ_HEADER, outfile);
                for (i = 0; i < MAX_LEN; i++)
                    fputc((int)seq[i], outfile);
                seq_len = 0;
            }
        }  /* end branch on sequence exists */
    } /* done with whole file */
    /* there may be stuff left that hasn't been written yet; if so, write it */
    if (seq_len != 0)  /* write sequence that precedes run */
    {
        fputc((int)(SEQ | seq_len), outfile);
        for (i = 0; i < seq_len; i++)
            fputc((int)seq[i], outfile);
    }
    if (run_len != 0)  /* write run */
    {
        fputc((int)(RUN | run_len), outfile);
        fputc((int)run_char, outfile);
    }
    fclose(infile);
    fclose (outfile);
    return 0;
}  /* end main() */

 

  • 写回答

4条回答 默认 最新

  • 关注

    fnsplit函数的头文件是不是没有include。

    评论

报告相同问题?

悬赏问题

  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵