Source Code For Program "Tokens". File "Tokens.c"
Source Code For Program "Tokens". File "Tokens.c"
Source Code For Program "Tokens". File "Tokens.c"
1 3
55 if (cond < 0) //Si cond es menor a 0 tree se dirige a la izquierda
56 tree->left = install(string, tree->left);
57 else if (cond == 0) //Si cond es igual a 0 tree aumenta
58 tree->count++;
59 else
60 tree->right = install(string, tree->right);
61 }
62 return(tree); //La funcion retorna una variable nodo tree
63 }
64
65 char *
66 getword(ioptr) FILE *ioptr;
67 {
68 static char string[1024];
69 char *ptr = string;
70 register int c;
71 assert(ioptr != NULL);
72 for (;;)
73 {
74 c = getc(ioptr);
75 if (c == EOF)
76 if (ptr == string)
77 return(NULL);
78 else
79 break;
80 if (!MapAllowed[c])
81 if (ptr == string)
82 continue;
83 else
84 break;
85 *ptr++ = MapAllowed[c];
86 }
87 *ptr = '\0';
88 return(string);
89 }
90
91 void tokens(ioptr) FILE *ioptr;
92 //primero declara, entra al while y luego sale
93 //Primero la declaracion, no ingresa al while y luego sale
94 {
95 TNODE *root = NULL;
96 char *s;
97 assert(ioptr != NULL);
98 while (s = getword(ioptr)) //en el ciclo s se mantiene mientra que sea
99 igual a getword(ioptr)
100 root = install(s, root);
101 treeprint(root);
102 }
103
104 int main(argc, argv) int argc; char ** argv;
105 {
106 int c, errcnt = 0;
107 extern char *optarg;
108
109 while ((c = getopt(argc, argv, "ac:im:")) != EOF)
110 switch(c)
111 {
2 4
112 case 'a': Alpha = 0; break;
113 case 'c':
114 while (*optarg)
115 {
116 MapAllowed[*optarg] = *optarg;
117 optarg++;
118 }
119 break;
120 case 'i': Ignore = 1; break;
121 case 'm': Mincount = atoi(optarg); break;
122 default: errcnt++;
123 }
124 if (errcnt)
125 {
126 fprintf(stderr, "Usage: %s [-i] [-c chars] [-m count]\n", *argv);
127 return(1);
128 }
129 for (c = 'a'; c <= 'z'; c++)
130 MapAllowed[c] = c;
131 for (c = 'A'; c <= 'Z'; c++)
132 MapAllowed[c] = Ignore ? c - 'A' + 'a' : c;
133 if (!Alpha)
134 for (c = '0'; c <= '9'; c++)
135 MapAllowed[c] = c;
136 tokens(stdin);
137 return(0);
138 }
3 5