Plan 9 from Bell Labs’s /usr/web/sources/contrib/arpunk/pp.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>

int getday(void);
int checkplaca(char *placa);
int checkpar(int num);
void usage(void);

int
getday(void)
{
	ulong now;
	Tm *tm;

	now = time(0);
	tm = localtime(now);

	return(tm->mday);
}

int
checkplaca(char *placa)
{
	int dia;
	int num = atoi(placa);

	dia = getday();

	if((checkpar(dia) == 1 && checkpar(num) == 1 ) ||
	   (checkpar(dia) == -1 && checkpar(num) == -1)) {
		fprint(2, "hoy hay pico y placa (%d - %d)\n", dia, num);
		return 1;
	}

	return 0;
}

int
checkpar(int num)
{
	int res = num % 2;
	if(res == 0)
		return 1;
	return -1;
}

void
usage(void)
{
	fprint(2, "usage: pp -p [placa]\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	char *placa;

	ARGBEGIN{
	case 'p':
		placa = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND;

	if(argc)
		usage();
	
	if(placa == nil)
		usage();

	if(placa)
		if(checkplaca(placa) != 1)
			fprint(2, "no hay pico y placa\n");

	exits(0);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.