utility

Implementing the “more” Unix utility command

非 Y 不嫁゛ 提交于 2019-12-12 12:22:12
问题 i am trying to implement the more command. I want to learn that how can I understand if there is a pipe. For example, if I type from the shell cat file1 file2 | more how can I handle that inside the implementation of more? And is the implementation of more available as open source? Actually i could not succeed from reading stdin.I've managed doing more file.txt but not cat file | more.. i think i should first read from user and put a buffer than print the buffer. my code contains: if(argc ==

General purpose utility or library for compiling/decompiling binary data files?

穿精又带淫゛_ 提交于 2019-12-12 09:56:51
问题 I have various binary file formats which I need to dump to some kind of text format, edit and then recompile (possibly to a slightly different version of the binary format). Of course I could write a bunch of utility code in C/C++ to do this kind of thing, and maybe leverage a library for the text side of things (XML or JSON or whatever), but this is a task pattern that keeps cropping up in my work and it seems to me that there probably ought to exist already some kind of general purpose tool

List::Util - reduce - length - encoding - question

99封情书 提交于 2019-12-11 03:36:03
问题 Why do I get a wrong result with the first reduce example? test.txt __BE bb bbbbbbbbbbbbbbb aaaaaa test.pl #!/usr/bin/env perl use warnings; use 5.012; use open ':encoding(UTF-8)'; use List::Util qw(reduce); use Encode; my( @list, $longest, $len ); open my $fh, '<', 'test.txt' or die $!; while( my $line = readline( $fh ) ) { chomp $line; push @list, split( /\s+/, $line ); } close $fh; $longest = reduce{ length($a) > length($b) ? $a : $b } @list; $len = length $longest; say $longest; # aaaaaa

String replace utility conversion from Python to F# [closed]

对着背影说爱祢 提交于 2019-12-11 00:44:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I have a simple python utility code that modifies the string line by line. The code is as follows. import re res = "" with open(

For C++ Vector3 utility class implementations, is array faster than struct and class?

强颜欢笑 提交于 2019-12-10 14:26:43
问题 just out of curiosity, I implemented vector3 utilities in 3 ways: array (with a typedef), class and struct This is the array implementation: typedef float newVector3[3]; namespace vec3{ void add(const newVector3& first, const newVector3& second, newVector3& out_newVector3); void subtract(const newVector3& first, const newVector3& second, newVector3& out_newVector3); void dot(const newVector3& first, const newVector3& second, float& out_result); void cross(const newVector3& first, const

Utility Classes in Java Programming

北慕城南 提交于 2019-12-09 13:58:03
问题 I am new to Java and I referred regarding my question on the Net but not quite Satisfied. I want to know what the "Utility Class" in Java is? Can anybody please tell me with an Example. Thanks, david 回答1: It's usually a class which only has static methods (possibly with a private constructor and marked abstract/final to prevent instantiation/subclassing). It only exists to make other classes easier to use - for example, providing a bunch of static methods to work with String values,

How would I create a hex dump utility in C++?

◇◆丶佛笑我妖孽 提交于 2019-12-08 23:37:36
问题 Basically, I need to write a hex dump utility using C++. It'll look something like this (Part of a Word document's hex dump using Visual Studio) I want to prompt the user for a file name, and then display the hexadecimal values as well as the translated ASCII characters. I'm still new at working with binary files, so if you could keep it simple, that would be much appreciated. 回答1: I don't normally do this for your kind of question.... But it doesn't take much to knock something like this up,

Is there a way to detect portably that a standard header is included using macros?

邮差的信 提交于 2019-12-06 22:55:00
问题 I want to make an equivalent to boost::swap and in my environment, standard headers can, or cannot be included. Depending on project licencing and other stuff. I'd like to make portions of the code protected by guard detectors: Let's consider one compilation unit. project specific, afore-written potential includes: #include <algorithm> // (or <utility> for C++11 projects) later in project code included from my swap utility header: namespace MyCompany { template<class T1, class T2> void swap

Is there a way to detect portably that a standard header is included using macros?

两盒软妹~` 提交于 2019-12-05 03:51:00
I want to make an equivalent to boost::swap and in my environment, standard headers can, or cannot be included. Depending on project licencing and other stuff. I'd like to make portions of the code protected by guard detectors: Let's consider one compilation unit. project specific, afore-written potential includes: #include <algorithm> // (or <utility> for C++11 projects) later in project code included from my swap utility header: namespace MyCompany { template<class T1, class T2> void swap(T1& left, T2& right) { #ifdef _ALGORITHM_ // you get the idea. std::swap(left, right); #else // fallback

Why shouldn't I have a single monolithic utility library?

拟墨画扇 提交于 2019-12-05 00:49:55
问题 We've got a few common libraries (C# but I guess this isn't platform- or language-specific), let's call them A, B, and C. Library A has references to B and C, library B has a reference to a 3rd-party DLL, and library C stands alone. The idea behind three separate projects was that each library had distinct functionality, but library A has over time become a more or less "catch-all" common library that most every client app references. Only a few apps reference B and/or C without A as well. We