~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/linkm/test/try.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 **  Written by David Gerdes  US Army Construction Engineering Research Lab
 
3
 **     April 1992
 
4
 **  Copyright 1992 USA-CERL   All rights reserved.
 
5
 **
 
6
 */
 
7
 
 
8
/*
 
9
 **  takes 1st command line argument and stuffs each letter of it into
 
10
 **   a linked list.  then prints it back out to stdout.
 
11
 **  If a second argument is specified, the first argument is put in the
 
12
 **   list backwards.
 
13
 */
 
14
#include <stdio.h>
 
15
#include <grass/linkm.h>
 
16
 
 
17
struct link
 
18
{
 
19
    char let;
 
20
    struct link *next;
 
21
};
 
22
 
 
23
int main(int argc, char *argv[])
 
24
{
 
25
    register int i;
 
26
    VOID_T *head;
 
27
    struct link List, *tmp, *p;
 
28
    int rev = 0;
 
29
 
 
30
    if (argc < 2)
 
31
        fprintf(stderr, "Usage: %s str [rev]\n", argv[0]), exit(1);
 
32
 
 
33
    if (argc > 2)
 
34
        rev = 1;
 
35
 
 
36
 
 
37
    List.next = NULL;
 
38
    List.let = ' ';
 
39
 
 
40
 
 
41
    head = (VOID_T *) link_init(sizeof(struct link));
 
42
 
 
43
    for (i = 0; argv[1][i]; i++) {
 
44
        tmp = (struct link *)link_new(head);
 
45
        tmp->let = argv[1][i];
 
46
        if (rev)
 
47
            add_link_rev(&List, tmp);
 
48
        else
 
49
            add_link(&List, tmp);
 
50
    }
 
51
 
 
52
    dumplist(&List);
 
53
 
 
54
    p = List.next;
 
55
    while (p->next != NULL) {
 
56
        tmp = p->next;
 
57
        link_dispose(head, p);
 
58
        p = tmp;
 
59
    }
 
60
 
 
61
    link_cleanup(head);
 
62
 
 
63
    exit(0);
 
64
}
 
65
 
 
66
int add_link_rev(struct link *List, struct link *link)
 
67
{
 
68
    struct link *p;
 
69
 
 
70
    p = List->next;
 
71
    List->next = link;
 
72
    link->next = p;
 
73
}
 
74
 
 
75
int add_link(struct link *List, struct link *link)
 
76
{
 
77
    struct link *p;
 
78
 
 
79
    p = List;
 
80
    while (p->next != NULL)
 
81
        p = p->next;
 
82
    p->next = link;
 
83
    link->next = NULL;
 
84
}
 
85
 
 
86
int dumplist(struct link *List)
 
87
{
 
88
    struct link *p;
 
89
 
 
90
    p = List->next;
 
91
    while (p != NULL) {
 
92
        putchar(p->let);
 
93
        p = p->next;
 
94
    }
 
95
    putchar('\n');
 
96
}