Simple database: Difference between revisions

m
(→‎{{header|D}}: make private)
Line 45:
#define FREE(a) if(a) {free(a);a=NULL;}
#define sort_by(foo) \
static int by_##foo (pdb_tconst void*p1, pdb_tconst void*p2) { \
return strcmp ((*(const pdb_t*)p1)->foo, (*(const pdb_t*)p2)->foo); }
typedef struct db {
char title[26];
Line 56:
}
db_t,*pdb_t;
typedef int (sort)(pdb_tconst void*, pdb_tconst void*);
typedef int (*compfn)(const void*, const void*);
enum {CREATE,PRINT,TITLE,DATE,AUTH,READLINE,READ,SORT,DESTROY};
static pdb_t dao (int cmd, FILE *f, pdb_t db, sort sortby);
Line 68 ⟶ 67:
/* main */
int main (int argc, char **argv) {
char buf[100], *commands[]={"-c", "-p", "-t", "-d", "-a", NULL};
const char *commands[]={"-c", "-p", "-t", "-d", "-a", NULL};
db_t db;
db.next=NULL;
Line 189:
in_db=in_db->next;
}
qsort (pdb,i,sizeof in_db,(compfn)sortby);
pdb[i-1]->next=NULL;
for (;i;i--) {
Anonymous user