college/Summer-2024/CS-3424/Quizzes/Quiz-4/Assignment.typ

124 lines
3.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#set text(font: "FreeSans")
#set page(margin: 1cm)
#show link: item => [
#text(blue)[#item]
]
#show raw: set text(font: "Fira Code")
#show raw.where(block: false): item => {
box(inset: (x: 1pt))[#box(
stroke: luma(40%) + .1pt,
fill: luma(97%),
outset: (y: 3pt, x: 1pt),
radius: 2pt,
)[#item]]
}
#show raw.where(block: true): item => {
set par(leading: .5em, justify: false)
align(center)[
#block(
outset: 0pt,
stroke: luma(40%) + .5pt,
fill: luma(97%),
radius: 3pt,
)[
#align(left)[#rect(
radius: (
top-left: 3pt,
bottom-right: 3pt,
),
inset: .3em,
stroke: (
bottom: luma(40%) + .5pt,
right: luma(40%) + .5pt,
),
fill: blue.transparentize(95%),
)[#text(fill: blue)[#item.lang]]]
#v(-1em)
#box(inset: 4pt)[#item]
]]
}
#let answer(ans) = {
set text(size: .95em, style: "italic", fill: rgb(64, 90, 95))
block(
inset: 4pt,
stroke: blue + .5pt,
fill: rgb(0, 149, 255, 5%),
radius: 3pt,
)[#for child in ans.fields().children {
if child.func() == raw {
text(fill: black)[#child]
} else {
child
}
}
]
}
#align(center)[#text(size: 1.3em)[= CS 3424 Quiz - Week 5]]
#align(center)[
#("Price Hiller", "zfp106", "Quiz 4", "CS 3424").join(" ⋄ ")
#v(-.5em)
#text(size: 0.8em)[#block(
inset: 4pt,
radius: 1pt,
stroke: luma(40%) + .2pt,
width: 40%,
fill: luma(97%),
)[#par(leading: .4em)[If you are interested in viewing the source code of this document, you can do so
by clicking
#link(
"https://git.orion-technologies.io/Price/college/src/branch/Development/Summer-2024/CS-3424/Quizzes/Quiz-4/Assignment.typ",
"here.",
)]]]
#v(-.5em)
#line(length: 100%, stroke: (dash: "densely-dotted"))
#v(-.5em)
]
1. Create a ```bash sed``` script which makes all comments consistent. Comment lines will begin with either "\//" or "\#" and may have leading spaces or tabs. Replace these instances with "\//" followed by a space and the rest of the original line (the comment itself). Also remove any lines beginning with "%". Include the command to run the script for a file named `file1.php` (contents below) and print output to `file1Clean.php`.
#align(center)[
```php
// file1.php
// Week 4
// Quiz
<?php
# print something
echo “hello world”;
# close php tag
?>
% this isnt a correct comment
```
]
#answer[
I made two assumptions about the desired output:
1. The assignment wants the leading spaces or tabs removed from the comment line
2. The assignment wants lines that have a comment symbol and no spaces after the symbol to also be supported
The script below assumes it will be run via `sed -f <sed-script-here> file1.php`.
```sed
s/^\s*\(#\|\/\/\)\s*\(.*\)$/\/\/ \2/g
/^%/d
w file1Clean.php
```
// #figure(
// image("assets/script-in-action.png", height: 40%),
// caption: [],
// ) <fig-script-in-action>
#figure(
box(clip: true, radius: 4pt)[#image(
"assets/script-in-action.png",
height: 40%,
fit: "contain",
alt: "",
)],
caption: [
Image of the provided ```bash sed``` script being ran and showing the output it wrote to `file1Clean.php`. Notice that the second ```bash cat``` invocation returns an error showing that `file1Clean.php` doesn't exist just yet. The ```bash sed``` invocation afterwards creates `file1Clean.php`.
],
)
]