首页 > 其他分享 >CSE 13S Introduction

CSE 13S Introduction

时间:2024-07-12 11:21:43浏览次数:7  
标签:will CSE xd 13S Introduction program file xxd your

Assignment 3

XXD

CSE 13S, Winter 2024

1   Introduction

In past assignments, you were shown some files that had weird, sometimes invisible differences. One challenge with files like these is finding an appropriate way to make them human readable, as not every character is printable. To make this easier, we can use tools like xxd. xxd on Unix systems is a very complicated program with many options, but in its simplest form, it displays a binary file in its hexadecimal representation. Feel free to play around with the xxd program. In this assignment, will start to build your own version of this program, with all of the basic functionality of xxd.

2   Helpful information

Buffered Reading

This assignment is your first foray into reading files. Many programs use functions such as fread, which is a function that performs buffered reading. This function will block (wait) until all the requested data is ready or until EOF is reached. This behavior is caused by buffering, which loads data into an array(buffer) as its read, and then returns all the requested data at once. In CSE130, you will see why the blocking behavior. can be detrimental to performance, and how creating your own buffer may be advantageous.

Instead of using fopen() and fread() which do the buffering for you, you will be using open() and read().  These functions are "System Calls" that are included in <fnctl .h> and <unistd .h> respectively. A system call, or "Syscall" for short, is a function that engages directly with the operating system, and requests it to read files from the disk.  This  means  that there  are no abstractions to help you!  These functions will return data as soon as it is available, but may not return all the requested data. To remedy this, we can repeatedly request data and load it into our own buffer until we have enough to process. We can then repeat this step until we have processed all of our data.

Another critical difference between fopen() and open() is that while fopen returns a file stream pointer ( FILE*), open() returns a file descriptor, which is just an  int corresponding to the file’s index on your program’s file descriptor table. For more information about these functions, you may consult the man pages.

3   Your task

The output of the xxd program

xxd has a lot of optional arguments, most of which we will not use. Your job will be to replicate the following behaviours:

•  If you supply no arguments, xxd will read in from stdin and print to stdout.

•  If you supply one argument, it is treated as a filename, and xxd will read from that file, if it exists. It will still print to stdout.

The xxd program (and thus, our example program) has a well defined structure for its output.  Here is the output for xxd on a file with the contents 0123456789abcdef\n.

00000000: 3031 3233 3435 3637 3839  6162  6364  6566    0123456789abcdef 00000010: 0a                                                                                       .

In the leftmost column is the index of the first byte. This is in hexadecimal, padded to 8 digits. It is followed by a colon and a space.

In the middle is the hex values of the bytes passed in. They are padded to 2 hex digits and are in groups of two bytes. There are 8 groups (16 bytes) one space between each group, and 2 spaces at the end of the column. If EOF is reached before we print all 8 groups, we print 2 spaces instead of the hex digits.

In the final column is the ASCII representation.  Any  character  between  ASCII  32 and  ASCII  126 (inclusive) is printed. Any character outside of that range is replaced with a . character. If EOF is reached before we print all 16 bytes, we do not print anything else. There is a newline at the end of this column.

If EOF is not reached on any given read, it waits until 16 bytes are entered. You can try this behavior. by using stdin as your input.

Errors

In this assignment, the only way you are required to handle errors is by returning a nonzero error code. The only errors you must handle is if a filename is invalid or more than one argument is supplied. In all other error circumstances, your program must exit cleanly. This includes cleaning up memory before exit.

Workflow

1.  Complete and submit your design.pdf draft by Monday, February 5th.

2. Create a buffered reader that reads 16 bytes at a time.

3.  Create tests for xd. We provide a file, delayinput .sh to help you with this. This script reads each line of a file, provided in an argument with a 1 second delay between lines.

4.  Build your program, naming it xd (to avoid confusion with the existing program xxd).

5. If you have time, make a copy of xd .c called bad_xd .c. You can then modify your makefile to add a target for bad_xd and update your tests to test bad_xd as well.

6.  Update your design and submit your final commit ID by Wednesday February 7th

Submission

These are the files we require from you:

•  Makefile: This should have rules for all, xd, xd .o, clean, and format. We also require the same flags

as usual, namely -Werror -Wall -Wextra -Wconversion -Wdouble-promotion -Wstrict-prototypes - pedantic

• xd .c: This file can contain all your code. You may also choose to make more files if it helps your code be more readable.

•  design.pdf This file should answer the questions given in the template.

• runner .sh This file should run all your tests. You are welcome to use previous iterations of this file as aresource.

•  tests: This folder is where you will write tests.

•  bad_xd .c: OPTIONAL This file should function identically to xd .c.

Do’s and Don’ts

You must do the following:

•  Format all of your C files with the clang-format file we provide.

•  If you choose to write bad_xd, be sure to make sure it functions identically to xd .c.

•  If you choose to write bad_xd, detail how you shortened your program in your design.

•  Output only to stdout

• Read into a buffer of at least size 16. You may not do any of the following:

•  Have a comment with clang-format  off.

•  Use fopen, fread, or any other buffered reader.

• Have memory leaks or errors

•  Use any #defines that would cause your program to have mismatched braces, parenthesis, or quotes.

•  Add anything to your makefile that helps reduce the size of your program

•  Run any external executables

•  Use #include in your bad_xd with any c code that you write

•  Attempt to read less than 16 bytes at a time.

•  Use #define to make anything equal a semicolon or curly braces

•  Any other tricks that don’t let clang-format work as expected.

Extra Credit

You can get extra credit if your program, bad_xd is less than 1000 characters.  For every 15 characters (rounded up) less than 1000, you will get one extra credit point.  For example, there is a known working solution which is 688 characters, which would receive 21 points of extra credit.

4    Revisions

Version 1 Original.

 

标签:will,CSE,xd,13S,Introduction,program,file,xxd,your
From: https://www.cnblogs.com/qq-99515681/p/18297909

相关文章

  • 使用Spring Boot集成Elasticsearch
    使用SpringBoot集成Elasticsearch大家好,我是微赚淘客系统3.0的小编,是个冬天不穿秋裤,天冷也要风度的程序猿!Elasticsearch是一个分布式搜索和分析引擎,特别适用于处理海量数据。本文将详细介绍如何在SpringBoot项目中集成Elasticsearch,包括环境配置、基本CRUD操作和常见问题的解......
  • Python实战Elasticsearch的核心技巧详解
    概要Elasticsearch是一个分布式的搜索引擎,可以用于全文搜索、结构化搜索、分析等多种场景。它基于Lucene构建,提供了强大的搜索功能和数据分析能力。本文将详细介绍如何使用Python实现与Elasticsearch的交互,包括安装、配置、基本操作和实际应用示例。安装和配置安装Elast......
  • 1.Introduction to Spring Web MVC framework
    WebMVCframework文档:22.WebMVCframework(spring.io)概述WebMVC框架(WebModel-View-ControllerFramework)是一种用于构建Web应用程序的软件架构模式。MVC模式将应用程序分为三个主要组件:模型(Model)、视图(View)和控制器(Controller)。这种分离有助于组织代码和简化开发......
  • elasticsearch: 插件安装与删除
    一,安装插件1,查看已安装的插件:[lhdop@blog~]$curl-XGET"localhost:9200/_cat/plugins?v&s=component"namecomponentversion2,从命令行安装smartcn分词插件:[lhdop@blogbin]$./elasticsearch-plugininstallanalysis-smartcnwarning:ignoringJAVA_HOME=/usr/loc......
  • elasticsearch: 安装ik中文分词(es 8.14.2)
    一,测试分词命令:1,查看已安装的插件:[lhdop@blog~]$curl-XGET"localhost:9200/_cat/plugins?v&s=component"namecomponentversion2,standard分词[lhdop@blog~]$curl-XGET"localhost:9200/_analyze?pretty"-H'Content-Type:application/json&......
  • 基于SpringBoot + SpringCloud+ElasticSear的在线教育管理系统设计与实现(MySQL、Mongo
    本项目适合做计算机相关专业的毕业设计,课程设计,技术难度适中、工作量比较充实。完整资源获取点击下载完整资源1、资源项目源码均已通过严格测试验证,保证能够正常运行;2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通;3、本项目比较适合计算......
  • CSE 13S LRC Rules of the Game
    Assignment 1LRCCSE 13S, Winter 20241 IntroductionWe are going to simulate a simplified version of the dice game Left, Right, and Center. This game isentirely a game of chance, with no skill or player decisions (except f......
  • ElasticSearch系列---【在已有索引中添加新的字段】
    1.问题描述消费kafka的数据,写入es,为了查看推送时间和消费时间的时间差值,我们需要在原有的es索引core_pri_flow_202405中添加新字段produce_time和create_time。2.直接使用devtools添加新字段#使用Easy-Es框架,实体类中添加字段@IndexField(value="produce_time",fieldType=Fie......
  • CSE 105 Summer Session
    CSE 105Summer Session 1 2024Homework 1Due date: Sunday July 7 at 11:59pmInstructionsOne member of the group should upload your group submission to Gradescope. During thesubmissionprocess,theywillbepromptedtoaddthenameso......
  • Elasticsearch:Node.js ECS 日志记录 - Pino
    在我的上一篇文章“Beats:使用Filebeat从Python应用程序中提取日志”里,我详述了如何使用Python来生成日志,并使用Filebeat来收集日志到Elasticsearch中。在今天的文章中,我来详细描述如何使用Node.js来生成ECS相兼容的日子。ECS相兼容的日志符合易于Elasticsear......