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

« back to all changes in this revision

Viewing changes to lib/linkm/try2.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
 
/*
10
 
 **  read from stdin and each line into a linked list of chars
11
 
 **  then print it back out.   if there is any argument specified
12
 
 **  the lines will be printed out reversed.
13
 
 */
14
 
 
15
 
#include <stdio.h>
16
 
#include <grass/linkm.h>
17
 
 
18
 
struct link
19
 
{
20
 
    char let;
21
 
    struct link *next;
22
 
};
23
 
 
24
 
int main(int argc, char *argv[])
25
 
{
26
 
    register int i;
27
 
    VOID_T *head;
28
 
    struct link List, *tmp, *p;
29
 
    int rev = 0;
30
 
    char buf[4096];
31
 
 
32
 
    if (argc == 2)
33
 
        rev = 1;
34
 
 
35
 
 
36
 
    List.next = NULL;
37
 
    List.let = ' ';
38
 
 
39
 
 
40
 
    link_set_chunk_size(1);
41
 
    head = (VOID_T *) link_init(sizeof(struct link));
42
 
 
43
 
 
44
 
    while (NULL != gets(buf)) {
45
 
        for (i = 0; buf[i] != '\0'; i++) {
46
 
            tmp = (struct link *)link_new(head);
47
 
            tmp->let = buf[i];
48
 
            if (rev)
49
 
                add_link_rev(&List, tmp);
50
 
            else
51
 
                add_link(&List, tmp);
52
 
        }
53
 
 
54
 
        dumplist(&List);
55
 
 
56
 
        p = List.next;
57
 
 
58
 
        while (p != NULL && p->next != NULL) {
59
 
            tmp = p->next;
60
 
            link_dispose(head, p);
61
 
            p = tmp;
62
 
        }
63
 
        List.next = NULL;
64
 
    }
65
 
 
66
 
    link_cleanup(head);
67
 
 
68
 
    exit(0);
69
 
}
70
 
 
71
 
int add_link_rev(struct link *List, struct link *link)
72
 
{
73
 
    struct link *p;
74
 
 
75
 
    p = List->next;
76
 
    List->next = link;
77
 
    link->next = p;
78
 
}
79
 
 
80
 
int add_link(struct link *List, struct link *link)
81
 
{
82
 
    struct link *p;
83
 
 
84
 
    p = List;
85
 
    while (p->next != NULL)
86
 
        p = p->next;
87
 
    p->next = link;
88
 
    link->next = NULL;
89
 
}
90
 
 
91
 
int dumplist(struct link *List)
92
 
{
93
 
    struct link *p;
94
 
 
95
 
    p = List->next;
96
 
    while (p != NULL) {
97
 
        putchar(p->let);
98
 
        p = p->next;
99
 
    }
100
 
    putchar('\n');
101
 
}