Skip to content

i've whote an "ugly" implementation of a pipe-friendly mode #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#endif
#include <assert.h>

#include <stdbool.h>
extern bool quiet;
#include "hwcap.h"

/**
Expand Down Expand Up @@ -142,7 +144,7 @@ struct flag_info flags[] = {
*
* Returns exit status (0 on success, non-zero on failure).
*/
int print_flags()
int print_flags( bool quiet )
{
unsigned long hwcap, hwcap2, subarch = 0;
char* uname_m;
Expand Down Expand Up @@ -180,7 +182,10 @@ int print_flags()
return 1;
}

fputs("CPU_FLAGS_ARM:", stdout);
if (!quiet)
{
fputs("CPU_FLAGS_ARM:", stdout);
}

for (i = 0; flags[i].name; ++i)
{
Expand Down
28 changes: 17 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@
#include <getopt.h>
#include <stdio.h>

int print_flags();
#include <stdbool.h>
bool quiet = false;
int print_flags(bool quiet);

struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'V' },
{ "quiet", no_argument, 0, 'q' },
{ 0, 0, 0, 0 }
};

const char* usage = "Usage: %s [options]\n"
"\n"
"Options:\n"
" -h, --help print this help message\n"
" -V, --version print program version\n";
" -V, --version print program version\n"
" -q, --quiet make output easily pipeable, remove cpu type\n";

int main(int argc, char* argv[])
{
int opt;

while ((opt = getopt_long(argc, argv, "hV", long_options, 0)) != -1)
while ((opt = getopt_long(argc, argv, "hVq", long_options, 0)) != -1)
{
switch (opt)
{
Expand All @@ -39,17 +43,19 @@ int main(int argc, char* argv[])
case 'V':
puts(PACKAGE_STRING);
return 0;
case 'q':
quiet = true; //TODO this doesn't work?
return print_flags(quiet);
case '?':
fprintf(stderr, usage, argv[0]);
return 1;
}
}
if (optind != argc)
{
fprintf(stderr, "%s: unexpected position parameter\n", argv[0]);
fprintf(stderr, usage, argv[0]);
return 1;
}

return print_flags();
if (optind != argc)
{
fprintf(stderr, "%s: unexpected position parameter\n", argv[0]);
fprintf(stderr, usage, argv[0]);
return 1;
}
return print_flags(quiet);
}
9 changes: 7 additions & 2 deletions src/ppc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#endif
#include <assert.h>

#include <stdbool.h>
extern bool quiet;
#include "hwcap.h"

/**
Expand Down Expand Up @@ -59,15 +61,18 @@ struct flag_info flags[] = {
*
* Returns exit status (0 on success, non-zero on failure).
*/
int print_flags()
int print_flags( bool quiet )
{
unsigned long hwcap = 0, hwcap2 = 0;
int i;

hwcap = get_hwcap();
hwcap2 = get_hwcap2();

fputs("CPU_FLAGS_PPC:", stdout);
if (!quiet)
{
fputs("CPU_FLAGS_PPC:", stdout);
}

for (i = 0; flags[i].name; ++i)
{
Expand Down
8 changes: 6 additions & 2 deletions src/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# include <stdint.h>
#endif
#include <assert.h>
#include <stdbool.h>

#include "x86.h"

Expand Down Expand Up @@ -91,7 +92,7 @@ struct flag_info flags[] = {
*
* Returns exit status (0 on success, non-zero on failure).
*/
int print_flags()
int print_flags( bool quiet )
{
uint32_t intel_ecx = 0, intel_edx = 0, intel_sub0_ebx = 0, intel_sub0_ecx = 0;
uint32_t amd_ecx = 0, amd_edx = 0;
Expand All @@ -111,7 +112,10 @@ int print_flags()
/* Centaur (VIA) */
got_centaur = run_cpuid(0xC0000001, 0, 0, 0, &centaur_edx);

fputs("CPU_FLAGS_X86:", stdout);
if (!quiet)
{
fputs("CPU_FLAGS_X86:", stdout);
}

for (i = 0; flags[i].name; ++i)
{
Expand Down
9 changes: 7 additions & 2 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ fi
echo "Expected: ${EXPECTED}"
echo "Result: ${RESULT}"
if [ "${EXPECTED}" != "${RESULT}" ]; then
echo "Result does not match!" >&2
RET=1
IFS=':' read -ra ADDR <<< "$IN"
for i in "${ADDR[@]}"; do
if [ "${EXPECTED}" != "${RESULT}" ]; then
echo "Result does not match!" >&2
RET=1
fi
done
fi

exit "${RET}"