Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
apk-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hassan Albahri
apk-tools
Commits
57391d1e
Commit
57391d1e
authored
16 years ago
by
Cameron Banta
Committed by
Timo Teras
16 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Created search applet
parent
e93cb1ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Makefile
+1
-0
1 addition, 0 deletions
src/Makefile
src/info.c
+1
-29
1 addition, 29 deletions
src/info.c
src/search.c
+148
-0
148 additions, 0 deletions
src/search.c
with
150 additions
and
29 deletions
src/Makefile
+
1
−
0
View file @
57391d1e
...
...
@@ -26,6 +26,7 @@ apk_OBJS = \
ver.o
\
index.o
\
info.o
\
search.o
\
audit.o
\
apk.o
...
...
This diff is collapsed.
Click to expand it.
src/info.c
+
1
−
29
View file @
57391d1e
...
...
@@ -35,30 +35,6 @@ static int info_list(struct apk_database *db, int argc, char **argv)
return
0
;
}
static
int
info_repo_pkgs_print
(
apk_hash_item
item
,
void
*
ctx
)
{
struct
apk_database
*
db
=
(
struct
apk_database
*
)
ctx
;
struct
apk_package
*
pkg
=
(
struct
apk_package
*
)
item
;
printf
(
"%s"
,
pkg
->
name
->
name
);
if
(
apk_verbosity
>
0
)
printf
(
"-%s"
,
pkg
->
version
);
if
(
apk_verbosity
>
1
)
{
printf
(
"
\n\t
%s"
,
db
->
repos
[
pkg
->
repos
].
url
);
printf
(
"
\n\t
%s"
,
pkg
->
description
);
}
printf
(
"
\n
"
);
return
0
;
}
static
int
info_repo_pkgs
(
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
apk_hash_foreach
(
&
db
->
available
.
packages
,
info_repo_pkgs_print
,
db
);
return
0
;
}
static
int
info_exists
(
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
struct
apk_name
*
name
;
...
...
@@ -207,9 +183,6 @@ static int info_parse(void *ctx, int optch, int optindex, const char *optarg)
case
'R'
:
ictx
->
action
=
info_depends
;
break
;
case
'o'
:
ictx
->
action
=
info_repo_pkgs
;
break
;
default:
return
-
1
;
}
...
...
@@ -239,12 +212,11 @@ static struct option info_options[] = {
{
"installed"
,
no_argument
,
NULL
,
'e'
},
{
"who-owns"
,
no_argument
,
NULL
,
'W'
},
{
"depends"
,
no_argument
,
NULL
,
'R'
},
{
"repo-pkgs"
,
no_argument
,
NULL
,
'o'
},
};
static
struct
apk_applet
apk_info
=
{
.
name
=
"info"
,
.
usage
=
"
[--repo-pkgs|-o]
"
,
.
usage
=
""
,
.
context_size
=
sizeof
(
struct
info_ctx
),
.
num_options
=
ARRAY_SIZE
(
info_options
),
.
options
=
info_options
,
...
...
This diff is collapsed.
Click to expand it.
src/search.c
0 → 100644
+
148
−
0
View file @
57391d1e
/* info.c - Alpine Package Keeper (APK)
*
* Copyright (C) 2005-2009 Natanael Copa <n@tanael.org>
* Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
#include
<stdio.h>
#include
"apk_defines.h"
#include
"apk_applet.h"
#include
"apk_package.h"
#include
"apk_database.h"
#include
"apk_state.h"
struct
search_ctx
{
int
(
*
action
)(
struct
apk_database
*
db
,
int
argc
,
char
**
argv
);
};
struct
search_query_ctx
{
struct
apk_database
*
db
;
const
char
*
query
;
};
static
int
search_list_print
(
apk_hash_item
item
,
void
*
ctx
)
{
//struct apk_database *db = (struct apk_database *) ctx;
struct
apk_package
*
pkg
=
(
struct
apk_package
*
)
item
;
printf
(
"%s"
,
pkg
->
name
->
name
);
if
(
apk_verbosity
>
0
)
printf
(
"-%s"
,
pkg
->
version
);
if
(
apk_verbosity
>
1
)
{
printf
(
" - %s"
,
pkg
->
description
);
}
printf
(
"
\n
"
);
return
0
;
}
static
int
search_query_print
(
apk_hash_item
item
,
void
*
ctx
)
{
struct
search_query_ctx
*
ictx
=
(
struct
search_query_ctx
*
)
ctx
;
struct
apk_package
*
pkg
=
(
struct
apk_package
*
)
item
;
if
(
strstr
(
pkg
->
name
->
name
,
ictx
->
query
)
==
NULL
)
return
0
;
search_list_print
(
item
,
ictx
->
db
);
return
0
;
}
static
int
search_list
(
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
int
i
;
struct
search_query_ctx
ctx
;
ctx
.
db
=
db
;
if
(
argc
==
0
)
apk_hash_foreach
(
&
db
->
available
.
packages
,
search_list_print
,
db
);
else
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
ctx
.
query
=
argv
[
i
];
apk_hash_foreach
(
&
db
->
available
.
packages
,
search_query_print
,
&
ctx
);
}
return
0
;
}
static
int
search_query_desc_print
(
apk_hash_item
item
,
void
*
ctx
)
{
struct
search_query_ctx
*
ictx
=
(
struct
search_query_ctx
*
)
ctx
;
struct
apk_package
*
pkg
=
(
struct
apk_package
*
)
item
;
if
(
strstr
(
pkg
->
description
,
ictx
->
query
)
==
NULL
)
return
0
;
search_list_print
(
item
,
ictx
->
db
);
return
0
;
}
static
int
search_desc
(
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
int
i
;
struct
search_query_ctx
ctx
;
ctx
.
db
=
db
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
ctx
.
query
=
argv
[
i
];
apk_hash_foreach
(
&
db
->
available
.
packages
,
search_query_desc_print
,
&
ctx
);
}
return
0
;
}
static
int
search_parse
(
void
*
ctx
,
int
optch
,
int
optindex
,
const
char
*
optarg
)
{
struct
search_ctx
*
ictx
=
(
struct
search_ctx
*
)
ctx
;
switch
(
optch
)
{
case
'd'
:
ictx
->
action
=
search_desc
;
break
;
default:
return
-
1
;
}
return
0
;
}
static
int
search_main
(
void
*
ctx
,
int
argc
,
char
**
argv
)
{
struct
search_ctx
*
ictx
=
(
struct
search_ctx
*
)
ctx
;
struct
apk_database
db
;
int
r
;
if
(
apk_db_open
(
&
db
,
apk_root
,
APK_OPENF_READ
)
<
0
)
return
-
1
;
if
(
ictx
->
action
!=
NULL
)
r
=
ictx
->
action
(
&
db
,
argc
,
argv
);
else
r
=
search_list
(
&
db
,
argc
,
argv
);
apk_db_close
(
&
db
);
return
r
;
}
static
struct
option
search_options
[]
=
{
{
"description"
,
no_argument
,
NULL
,
'd'
},
};
static
struct
apk_applet
apk_search
=
{
.
name
=
"search"
,
.
usage
=
"[--description|-d] [search_pattern]"
,
.
context_size
=
sizeof
(
struct
search_ctx
),
.
num_options
=
ARRAY_SIZE
(
search_options
),
.
options
=
search_options
,
.
parse
=
search_parse
,
.
main
=
search_main
,
};
APK_DEFINE_APPLET
(
apk_search
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment