cpio是用来建立,还原备份档的工具程序,它可以加入,解开 cpio或tra 备份档内的文件。
cpio一般能够解压后缀名为xz文件。
参 数:
-0 或--null 接受新增列控制字符,通常配合 find 指令的"-print0"参数使用。
-a 或--reset-access-time 重新设置文件的存取时间。
-A 或--append 附加到已存在的备份档中,且这个备份档必须存放在磁盘上,而不能放置于磁带机里。
-b 或--swap 此参数的效果和同时指定"-sS"参数相同。
-B 将输入/输出的区块大小改成 5210 Bytes。
-c 使用旧 ASCII 备份格式。
-C<区块大小>或--io-size=<区块大小> 设置输入/输出的区块大小,单位是Byte。
-d 或--make-directories 如有需要 cpio 会自行建立目录。
-E<范本文件>或--pattern-file=<范本文件> 指定范本文件,其内含有一个或多个范本样式,让cpio 解开符合范本条件的文件,格式为每列一个范本样式。
-f 或--nonmatching 让 cpio 解开所有不符合范本条件的文件。
-F<备份档>或--file=<备份档> 指定备份档的名称,用来取代标准输入或输出,也能借此通过网络使用另一台主机的保存设备存取备份档。
-H<备份格式> 指定备份时欲使用的文件格式。
-i 或--extract 执行 copy-in 模式,还原备份档。
-l<备份档> 指定备份档的名称,用来取代标准输入,也能借此通过网络使用另一台主机的保存设备读取备份档。
-k 此参数将忽略不予处理,仅负责解决 cpio 不同版本间的兼容性问题。
-l 或--link 以硬连接的方式取代复制文件,可在 copy-pass 模式下运用。
-L 或--dereference 不建立符号连接,直接复制该连接所指向的原始文件。
-m 或preserve-modification-time 不去更换文件的更改时间。
-M<回传信息>或--message=<回传信息> 设置更换保存媒体的信息。
-n 或--numeric-uid-gid 使用"-tv"参数列出备份档的内容时,若再加上参数
"-n",则会以用户识别码和群组识别码替代拥有者和群组名称列出文件清单。
-o 或--create 执行 copy-out 模式,建立备份档。
-O<备份档> 指定备份档的名称,用来取代标准输出,也能借此通过网络 使用另一台主机的保存设备存放备份档。
-p 或--pass-through 执行 copy-pass 模式,略过备份步骤,直接将文件复制到目的目录。
-r 或--rename 当有文件名称需要更动时,采用互动模式。
-R<拥有者><:/.><所属群组>或
----owner<拥有者><:/.><所属群组> 在 copy-in 模式还原备份档,或copy-pass模式复制文件时,可指定这些备份,复制的文件的拥有者与所属群组。
-s 或--swap-bytes 交换每对字节的内容。
-S 或--swap-halfwords 交换每半个字节的内容。
-t 或--list 将输入的内容呈现出来。
-u 或--unconditional 置换所有文件,不论日期时间的新旧与否,皆不予询问而直接覆盖。
-v 或--verbose 详细显示指令的执行过程。
-V 或--dot 执行指令时,在每个文件的执行程序前面加上"."号
--block-size=<区块大小> 设置输入/输出的区块大小,假如设置数值为 5,则区块大小为2500,若设置成 10,则区块大小为5120,依次类推。
--force-local 强制将备份档存放在本地主机。
--no-absolute-filenames 使用相对路径建立文件名称。
--no-preserve-owner 不保留文件的拥有者,谁解开了备份档,那些文件就归谁所有。
-only-verify-crc 当备份档采用 CRC 备份格式时,可使用这项参数检查备份档内的每个文件是否正确无误。
--quiet 不显示复制了多少区块。
--sparse 倘若一个文件内含大量的连续 0 字节,则将此文件存成稀疏文件。
// 算法:扑克牌乱序
#include <stdio.h>
#include <stdlib.h> // srand(),rand()
#include <time.h> // time()
int main(int argc, char* argv[])
{
int poker[54]; // 四组1~13,另外包括大小王
int i;
for(i = 0; i < 54; i++)
poker[i] = i+1;
srand(time(0));
for(i = 0; i < 54; i++)
{
int j = rand()%54;
int temp = poker[i];
poker[i] = poker[j];
poker[j] = temp;
}
for(i = 0; i < 54; i++)
{
int type = poker[i]/13;
int number = poker[i]%13;
number == 0 ? number = 13:number = number;
switch(type)
{
case 0:
printf("黑桃 %d\n",number);
break;
case 1:
printf("红桃 %d\n",number);
break;
case 2:
printf("方块 %d\n",number);
break;
case 3:
printf("梅花 %d\n",number);
break;
case 4:
if(number == 1)
printf("小王\n");
else
printf("大王\n");
break;
default:
printf("error!\n");
break;
}
}
return 0;
}
简单的算法,利用srand和rand来进行数据的随机排序,实现随机的方式有很多,这是一种。
做项目时,感觉android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个。
废话不说先上图片:
1.先自定义一个弹出框的样式
2.自己实现CustomDialog类,继承自Dialog,实现里面方法,在里面加载自定义样式的弹出框;
3.使用时,与使用Dialog一样
具体代码 dialog_normal_layout.xml样式文件<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:orientation="vertical"
android:padding="20.0dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/bg_bombbox"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
style="@style/text_18_ffffff"
android:layout_width="fill_parent"
android:layout_height="40.0dip"
android:gravity="center"
android:text="@string/title_alert"
android:visibility="visible" />
<TextView
android:id="@+id/message"
style="@style/text_16_666666"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left|center"
android:lineSpacingMultiplier="1.5"
android:minHeight="120.0dip"
android:paddingBottom="15.0dip"
android:paddingLeft="20.0dip"
android:paddingRight="20.0dip"
android:paddingTop="15.0dip" />
<View
android:layout_width="fill_parent"
android:layout_height="1.0px"
android:background="#ffd0d0d0" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60.0dip"
android:layout_gravity="bottom"
android:background="@drawable/dialog_bottom_bg"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/positiveButton"
style="@style/text_15_ffffff_sdw"
android:layout_width="114.0dip"
android:layout_height="40.0dip"
android:background="@drawable/btn_ok_selector"
android:gravity="center"
android:text="@string/ok" />
<Button
android:id="@+id/negativeButton"
style="@style/text_15_666666_sdw"
android:layout_width="114.0dip"
android:layout_height="40.0dip"
android:layout_marginLeft="20.0dip"
android:background="@drawable/btn_cancel_selector"
android:gravity="center"
android:text="@string/cancel" />
</LinearLayout>
</LinearLayout>
</FrameLayout>其中引用的样式文件styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<style name="AppTheme" parent="AppBaseTheme"></style>
<style name="text_18_ffffff">
<item name="android:textSize">18.0dip</item>
<item name="android:textColor">#ffffffff</item>
</style>
<style name="text_16_666666">
<item name="android:textSize">16.0dip</item>
<item name="android:textColor">#ff666666</item>
</style>
<style name="sdw_white">
<item name="android:shadowColor">#7fffffff</item>
<item name="android:shadowDx">0.0</item>
<item name="android:shadowDy">0.65</item>
<item name="android:shadowRadius">1.0</item>
</style>
<style name="sdw_79351b">
<item name="android:shadowColor">#ff79351b</item>
<item name="android:shadowDx">0.0</item>
<item name="android:shadowDy">1.0</item>
<item name="android:shadowRadius">1.0</item>
</style>
<style name="text_15_ffffff_sdw" parent="@style/sdw_79351b">
<item name="android:textSize">15.0dip</item>
<item name="android:textColor">#ffffffff</item>
</style>
<style name="text_15_666666_sdw" parent="@style/sdw_white">
<item name="android:textSize">15.0dip</item>
<item name="android:textColor">#ff666666</item>
</style>
<style name="Dialog" parent="android:style/Theme.Dialog">
<item name="android:background">#00000000</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
</style>
</resources>自定义Dialog的实现类CustomDialog
package com.dyr.custom;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dyr.view.R;
public class CustomDialog extends Dialog {
public CustomDialog(Context context) {
super(context);
}
public CustomDialog(Context context, int theme) {
super(context, theme);
}
public static class Builder {
private Context context;
private String title;
private String message;
private String positiveButtonText;
private String negativeButtonText;
private View contentView;
private DialogInterface.OnClickListener positiveButtonClickListener;
private DialogInterface.OnClickListener negativeButtonClickListener;
public Builder(Context context) {
this.context = context;
}
public Builder setMessage(String message) {
this.message = message;
return this;
}
/**
* Set the Dialog message from resource
*
* @param title
* @return
*/
public Builder setMessage(int message) {
this.message = (String) context.getText(message);
return this;
}
/**
* Set the Dialog title from resource
*
* @param title
* @return
*/
public Builder setTitle(int title) {
this.title = (String) context.getText(title);
return this;
}
/**
* Set the Dialog title from String
*
* @param title
* @return
*/
public Builder setTitle(String title) {
this.title = title;
return this;
}
public Builder setContentView(View v) {
this.contentView = v;
return this;
}
/**
* Set the positive button resource and it's listener
*
* @param positiveButtonText
* @return
*/
public Builder setPositiveButton(int positiveButtonText,
DialogInterface.OnClickListener listener) {
this.positiveButtonText = (String) context
.getText(positiveButtonText);
this.positiveButtonClickListener = listener;
return this;
}
public Builder setPositiveButton(String positiveButtonText,
DialogInterface.OnClickListener listener) {
this.positiveButtonText = positiveButtonText;
this.positiveButtonClickListener = listener;
return this;
}
public Builder setNegativeButton(int negativeButtonText,
DialogInterface.OnClickListener listener) {
this.negativeButtonText = (String) context
.getText(negativeButtonText);
this.negativeButtonClickListener = listener;
return this;
}
public Builder setNegativeButton(String negativeButtonText,
DialogInterface.OnClickListener listener) {
this.negativeButtonText = negativeButtonTex