headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / code_to_name / code_to_name.cpp
blob89c70002c07bdd4e08f5417edf063eab8c8dc17f
1 /*
2 * Copyright 2005, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
10 #include <Entry.h>
11 #include <Path.h>
12 #include <Query.h>
13 #include <Volume.h>
15 #include <fs_info.h>
17 #include <ctype.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
23 extern const char* __progname;
26 void
27 skip_white_space(char*& line)
29 while (isspace(line[0]))
30 line++;
34 void
35 get_name(char* line)
37 while (isalnum(line[0]) || line[0] == '_') {
38 line++;
41 line[0] = '\0';
45 void
46 print_code(BPath& path, int32 code)
48 FILE* file = fopen(path.Path(), "r");
49 if (file == NULL)
50 return;
52 int32 lineNumber = 0;
53 char buffer[4096];
55 while (fgets(buffer, sizeof(buffer), file) != NULL) {
56 char* line = buffer;
57 skip_white_space(line);
59 if (strncmp(line, "AS_", 3))
60 continue;
62 if (++lineNumber != code)
63 continue;
65 get_name(line);
66 printf("code %ld: %s\n", lineNumber, line);
67 fclose(file);
68 return;
71 printf("unknown code %ld!\n", code);
72 fclose(file);
76 int
77 main(int argc, char** argv)
79 if (argc < 2) {
80 fprintf(stderr, "usage: %s <message-code>\n", __progname);
81 return -1;
84 int32 number = atol(argv[1]);
86 BQuery query;
87 query.SetPredicate("name=ServerProtocol.h");
89 // search on current volume only
90 dev_t device = dev_for_path(".");
91 BVolume volume(device);
93 query.SetVolume(&volume);
94 query.Fetch();
96 status_t status;
97 BEntry entry;
98 while ((status = query.GetNextEntry(&entry)) == B_OK) {
99 BPath path(&entry);
100 puts(path.Path());
101 if (strstr(path.Path(), "headers/private/app/ServerProtocol.h") != NULL) {
102 print_code(path, number);
103 break;
107 if (status != B_OK) {
108 fprintf(stderr, "%s: could not find ServerProtocol.h", __progname);
109 return -1;
111 return 0;