-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from cs50/develop
eliminates gnu11 dependency
- Loading branch information
Showing
10 changed files
with
151 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
build/ | ||
debian/changelog | ||
debian/docs/ | ||
debian/files | ||
debian/libcs50 | ||
debian/*.log | ||
hackerrank/ | ||
libcs50-* | ||
libcs50_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION := 8.0.3 | ||
VERSION := 8.0.4 | ||
|
||
# soname - libcs50.so.<major_version> | ||
SONAME := libcs50.so.$(shell echo $(VERSION) | head -c 1) | ||
|
@@ -8,7 +8,7 @@ DESTDIR ?= /usr/local | |
|
||
.PHONY: build | ||
build: clean | ||
$(CC) -c -fPIC -std=gnu99 -Wall -o cs50.o src/cs50.c | ||
$(CC) -c -fPIC -std=c99 -Wall -o cs50.o src/cs50.c | ||
$(CC) -shared -Wl,-soname,$(SONAME) -o libcs50.so.$(VERSION) cs50.o | ||
rm -f cs50.o | ||
ln -s libcs50.so.$(VERSION) $(SONAME) | ||
|
@@ -37,7 +37,7 @@ docs: | |
deb: build docs | ||
@echo "libcs50 ($(VERSION)-0ubuntu1) trusty; urgency=low" > debian/changelog | ||
@echo " * v$(VERSION)" >> debian/changelog | ||
@echo " -- CS50 Sysadmins <[email protected]> $$(date --rfc-2822)" >> debian/changelog | ||
@echo " -- CS50 Sysadmins <[email protected]> $$(date --rfc-2822)" >> debian/changelog | ||
mkdir -p libcs50-$(VERSION)/usr | ||
rsync -a build/* libcs50-$(VERSION)/usr --exclude=hack | ||
tar -cvzf libcs50_$(VERSION).orig.tar.gz libcs50-$(VERSION) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Automatically added by dh_makeshlibs | ||
if [ "$1" = "configure" ]; then | ||
ldconfig | ||
fi | ||
# End automatically added section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Automatically added by dh_makeshlibs | ||
if [ "$1" = "remove" ]; then | ||
ldconfig | ||
fi | ||
# End automatically added section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
shlibs:Depends=libc6 (>= 2.3) | ||
misc:Depends= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
# postinst script for libcs50 | ||
# | ||
# see: dh_installdeb(1) | ||
|
||
set -e | ||
|
||
# summary of how this script can be called: | ||
# * <postinst> `configure' <most-recently-configured-version> | ||
# * <old-postinst> `abort-upgrade' <new version> | ||
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> | ||
# <new-version> | ||
# * <postinst> `abort-remove' | ||
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' | ||
# <failed-install-package> <version> `removing' | ||
# <conflicting-package> <version> | ||
# for details, see http://www.debian.org/doc/debian-policy/ or | ||
# the debian-policy package | ||
|
||
|
||
case "$1" in | ||
configure) | ||
;; | ||
|
||
abort-upgrade|abort-remove|abort-deconfigure) | ||
;; | ||
|
||
*) | ||
echo "postinst called with unknown argument \`$1'" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# dh_installdeb will replace this with shell code automatically | ||
# generated by other debhelper scripts. | ||
|
||
#DEBHELPER# | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
# postrm script for libcs50 | ||
# | ||
# see: dh_installdeb(1) | ||
|
||
set -e | ||
|
||
# summary of how this script can be called: | ||
# * <postrm> `remove' | ||
# * <postrm> `purge' | ||
# * <old-postrm> `upgrade' <new-version> | ||
# * <new-postrm> `failed-upgrade' <old-version> | ||
# * <new-postrm> `abort-install' | ||
# * <new-postrm> `abort-install' <old-version> | ||
# * <new-postrm> `abort-upgrade' <old-version> | ||
# * <disappearer's-postrm> `disappear' <overwriter> | ||
# <overwriter-version> | ||
# for details, see http://www.debian.org/doc/debian-policy/ or | ||
# the debian-policy package | ||
|
||
|
||
case "$1" in | ||
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) | ||
;; | ||
|
||
*) | ||
echo "postrm called with unknown argument \`$1'" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# dh_installdeb will replace this with shell code automatically | ||
# generated by other debhelper scripts. | ||
|
||
#DEBHELPER# | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
* | ||
* Based on Eric Roberts' genlib.c and simpio.c. | ||
* | ||
* Copyright (c) 2017, | ||
* Glenn Holloway <[email protected]> | ||
* David J. Malan <[email protected]> | ||
* Copyright (c) 2017. | ||
* All rights reserved. | ||
* | ||
* BSD 3-Clause License | ||
|
@@ -52,14 +50,23 @@ | |
|
||
#include "cs50.h" | ||
|
||
// temporarily here for backwards compatibility | ||
#undef get_char | ||
#undef get_double | ||
#undef get_float | ||
#undef get_int | ||
#undef get_long_long | ||
#undef get_string | ||
#define null (&(struct prompt) {0}) | ||
|
||
/** | ||
* Prints an error message, formatted like printf, to standard error, prefixing it with | ||
* file name and line number from which function was called (which a macro provides). | ||
* | ||
* This function is not intended to be called directly. Instead, call the macro of the same name, | ||
* which expects fewer arguments. | ||
* | ||
* Inspired by http://www.gnu.org/software/libc/manual/html_node/Variable-Arguments-Output.html | ||
* Inspired by http://www.gnu.org/software/libc/manual/html_node/Variable-Arguments-Output.html, | ||
* http://www.gnu.org/software/libc/manual/html_node/Error-Messages.html#Error-Messages, and | ||
* https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html. | ||
*/ | ||
|
@@ -87,13 +94,13 @@ void eprintf(const char *file, int line, const char *format, ...) | |
* equivalent char; if text is not a single char, user is prompted | ||
* to retry. If line can't be read, returns CHAR_MAX. | ||
*/ | ||
char get_char(string prompt) | ||
char get_char(struct prompt *p) | ||
{ | ||
// try to get a char from user | ||
while (true) | ||
{ | ||
// get line of text, returning CHAR_MAX on failure | ||
string line = get_string(prompt); | ||
string line = get_string(p); | ||
if (line == NULL) | ||
{ | ||
return CHAR_MAX; | ||
|
@@ -107,15 +114,15 @@ char get_char(string prompt) | |
} | ||
|
||
// temporarily here for backwards compatibility | ||
if (prompt == NULL) | ||
if (p->prompt == NULL) | ||
{ | ||
printf("Retry: "); | ||
} | ||
} | ||
} | ||
char GetChar(void) | ||
{ | ||
return get_char(NULL); | ||
return get_char(null); | ||
} | ||
|
||
/** | ||
|
@@ -124,13 +131,13 @@ char GetChar(void) | |
* a double or if value would cause underflow or overflow, user is | ||
* prompted to retry. If line can't be read, returns DBL_MAX. | ||
*/ | ||
double get_double(string prompt) | ||
double get_double(struct prompt *p) | ||
{ | ||
// try to get a double from user | ||
while (true) | ||
{ | ||
// get line of text, returning DBL_MAX on failure | ||
string line = get_string(prompt); | ||
string line = get_string(p); | ||
if (line == NULL) | ||
{ | ||
return DBL_MAX; | ||
|
@@ -153,15 +160,15 @@ double get_double(string prompt) | |
} | ||
|
||
// temporarily here for backwards compatibility | ||
if (prompt == NULL) | ||
if (p->prompt == NULL) | ||
{ | ||
printf("Retry: "); | ||
} | ||
} | ||
} | ||
double GetDouble(void) | ||
{ | ||
return get_double(NULL); | ||
return get_double(null); | ||
} | ||
|
||
/** | ||
|
@@ -170,13 +177,13 @@ double GetDouble(void) | |
* a float or if value would cause underflow or overflow, user is prompted | ||
* to retry. If line can't be read, returns FLT_MAX. | ||
*/ | ||
float get_float(string prompt) | ||
float get_float(struct prompt *p) | ||
{ | ||
// try to get a float from user | ||
while (true) | ||
{ | ||
// get line of text, returning FLT_MAX on failure | ||
string line = get_string(prompt); | ||
string line = get_string(p); | ||
if (line == NULL) | ||
{ | ||
return FLT_MAX; | ||
|
@@ -199,15 +206,15 @@ float get_float(string prompt) | |
} | ||
|
||
// temporarily here for backwards compatibility | ||
if (prompt == NULL) | ||
if (p->prompt == NULL) | ||
{ | ||
printf("Retry: "); | ||
} | ||
} | ||
} | ||
float GetFloat(void) | ||
{ | ||
return get_float(NULL); | ||
return get_float(null); | ||
} | ||
|
||
/** | ||
|
@@ -216,13 +223,13 @@ float GetFloat(void) | |
* or would cause underflow or overflow, user is prompted to retry. If line | ||
* can't be read, returns INT_MAX. | ||
*/ | ||
int get_int(string prompt) | ||
int get_int(struct prompt *p) | ||
{ | ||
// try to get an int from user | ||
while (true) | ||
{ | ||
// get line of text, returning INT_MAX on failure | ||
string line = get_string(prompt); | ||
string line = get_string(p); | ||
if (line == NULL) | ||
{ | ||
return INT_MAX; | ||
|
@@ -241,15 +248,15 @@ int get_int(string prompt) | |
} | ||
|
||
// temporarily here for backwards compatibility | ||
if (prompt == NULL) | ||
if (p->prompt == NULL) | ||
{ | ||
printf("Retry: "); | ||
} | ||
} | ||
} | ||
int GetInt(void) | ||
{ | ||
return get_int(NULL); | ||
return get_int(null); | ||
} | ||
|
||
/** | ||
|
@@ -258,13 +265,13 @@ int GetInt(void) | |
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is | ||
* prompted to retry. If line can't be read, returns LLONG_MAX. | ||
*/ | ||
long long get_long_long(string prompt) | ||
long long get_long_long(struct prompt *p) | ||
{ | ||
// try to get a long long from user | ||
while (true) | ||
{ | ||
// get line of text, returning LLONG_MAX on failure | ||
string line = get_string(prompt); | ||
string line = get_string(p); | ||
if (line == NULL) | ||
{ | ||
return LLONG_MAX; | ||
|
@@ -283,15 +290,15 @@ long long get_long_long(string prompt) | |
} | ||
|
||
// temporarily here for backwards compatibility | ||
if (prompt == NULL) | ||
if (p->prompt == NULL) | ||
{ | ||
printf("Retry: "); | ||
} | ||
} | ||
} | ||
long long GetLongLong(void) | ||
{ | ||
return get_long_long(NULL); | ||
return get_long_long(null); | ||
} | ||
|
||
/** | ||
|
@@ -312,7 +319,7 @@ static string *strings = NULL; | |
* upon error or no input whatsoever (i.e., just EOF). Stores string | ||
* on heap, but library's destructor frees memory on program's exit. | ||
*/ | ||
string get_string(string prompt) | ||
string get_string(struct prompt *p) | ||
{ | ||
// check whether we have room for another string | ||
if (allocations * sizeof(string) == SIZE_MAX) | ||
|
@@ -333,9 +340,9 @@ string get_string(string prompt) | |
int c; | ||
|
||
// prompt user | ||
if (prompt != NULL) | ||
if (p->prompt != NULL) | ||
{ | ||
printf("%s", prompt); | ||
printf("%s", p->prompt); | ||
} | ||
|
||
// iteratively get characters from standard input, checking for CR (Mac OS), LF (Linux), and CRLF (Windows) | ||
|
Oops, something went wrong.