<?php
/*
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
function get_contents($field_name,$filestring)
{
# stripos(string,find,start)
# 返回字符串在另一个字符串中第一次出现的位置。
# ------------------------------------------
# | 参数 | 描述 |
# ------------------------------------------
# | string | 必需。规定被搜索的字符串。 |
# | find | 必需。规定要查找的字符。 |
# | start | 可选。规定开始搜索的位置。 |
# ------------------------------------------
# 如果没有找到该字符串,则返回 false。
$pos = stripos($filestring,$field_name."="); if($pos != false)
{
$pos += strlen($field_name."=");
# 找到当前行结束的地方
$newlinepos = stripos($filestring,"\n",$pos);
if($newlinepos == -)
$newlinepos = stripos($filestring,"\r",$pos); # substr(string,start,length)
# ---------------------------------------------------
# | 参数 | 描述 |
# ---------------------------------------------------
# | string | 必需。规定要返回其中一部分的字符串。 |
# | start | 必需。规定在字符串的何处开始。 |
# ---------------------------------------------------
$returnedstring = substr($filestring,$pos,$newlinepos-$pos);
return $returnedstring;
}
return -;
} # 每个app都有一个这样的对应文件
system("find -name '*.desktop' -print > catdesktop.txt"); if(filesize("catdesktop.txt") == )
{
echo "No .desktop files found";
return;
} # 读取文件
$handle = fopen("catdesktop.txt", "rb");
$contents = fread($handle,filesize("catdesktop.txt"));
fclose($handle);
# unlink() 函数删除文件。
# 若成功,则返回 true,失败则返回 false。
unlink('catdesktop.txt'); # 函数把字符串打散为数组。
# explode(separator,string,limit)
# ---------------------------------------------------------------------------------
# | 参数 | 描述 |
# |--------------------------------------------------------------------------------
# | separator | 必需。规定在哪里分割字符串。 |
# |-------------------------------------------------------------------------------|
# | string | 必需。要分割的字符串。 |
# |-------------------------------------------------------------------------------|
# | limit | 可选。规定所返回的数组元素的数目。 |
# | | 可能的值: |
# | | 大于 - 返回包含最多 limit 个元素的数组 |
# | | 小于 - 返回包含除了最后的 -limit 个元素以外的所有元素的数组 |
# | | - 返回包含一个元素的数组 |
# ---------------------------------------------------------------------------------
$contents = explode("\n",$contents); # 这里strlen($contents[$x])>0限制了数据之间不能出现空行
for($x = ;$x<count($contents)&&strlen($contents[$x])>;$x++)
{
# 从这里可以看出catdesktop.txt文件里是一些文件路径的配置
$handle = fopen($contents[$x], "rb");
$dotdesktop = fread($handle,filesize($contents[$x]));
fclose($handle); # 应用名
$top["Name"] = get_contents("Name",$dotdesktop); # 序号
if(get_contents("X-MATRIX-DisplayPriority",$dotdesktop)!=-)
$top["Order"] = get_contents("X-MATRIX-DisplayPriority",$dotdesktop);
else
$top["Order"] = ; # 图标的绝对路径
$icon_path = get_contents("Icon",$dotdesktop);
$webserver_root = "/usr/share/matrix-gui-2.0/";
# 获取Icon的相对路径
$top["Icon"] = substr($icon_path,strlen($webserver_root)); # 类型
$type = strtolower(get_contents("Type",$dotdesktop));
$top["Type"] = $type; # 分类
$category = get_contents("Categories",$dotdesktop);
$category = trim(strtolower($category)); if($type == "directory")
{
$top["Category"] = get_contents("X-MATRIX-CategoryTarget",$dotdesktop); }elseif($type == "application")
{
# 可执行程序的执行命令
$top["Exec"] = get_contents("Exec",$dotdesktop); # 可执行程序的类型
$top["ProgramType"] = get_contents("ProgramType",$dotdesktop); # 连接描述
$top["Description_Link"] = get_contents("X-MATRIX-Description",$dotdesktop); # 锁
$top["Lock"] = get_contents("X-MATRIX-LOCK",$dotdesktop);
} # 非分类放在主菜单中,其他的放在对应的分类中
# 这里采用PHP的动态添加数组成员的方法
if($category == -)
$application["main_menu"]["apps"][] = $top;
else
$application[$category]["apps"][] = $top; # 用来销毁变量的,但很多时候,这个函数只把变量给销毁了,内存中存放的该变量的值
# 仍然没有销毁,也就是没能达到我们想要的释放内存的效果。
unset($top);
} # 主要是完成数字大小的比较
function cmp($a, $b)
{
if($a["Order"] < $b["Order"])
return -;
elseif($a["Order"] == $b["Order"])
return ;
elseif($a["Order"] > $b["Order"])
return ;
} foreach ($application as $key => $value) {
# 使用用户自定义的函数对数组排序,自动的函数名叫cmp,
# 其实就是前面那个数字比较函数
usort($application[$key]["apps"], "cmp");
} # 将php对象编码成json对象,写到json.txt文件里面去
$ourFileName = "json.txt";
# die() 函数输出一条消息,并退出当前脚本。
# 该函数是 exit() 函数的别名。
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle,json_encode($application));
fclose($ourFileHandle);
?>

Texas Instruments matrix-gui-2.0 hacking -- generate.php的更多相关文章

  1. Texas Instruments matrix-gui-2.0 hacking -- index.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  2. Texas Instruments matrix-gui-2.0 hacking -- app_description.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  3. Texas Instruments matrix-gui-2.0 hacking -- submenu.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  4. Texas Instruments matrix-gui-2.0 hacking -- run_script.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  5. Texas Instruments matrix-gui-2.0 hacking -- menubar.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  6. Texas Instruments matrix-gui-2.0 hacking -- execute_command.sh

    #!/bin/sh #Copyright (C) Texas Instruments Incorporated - http://www.ti.com/ # # # Redistribution an ...

  7. 【LeetCode每天一题】Set Matrix Zeroes(设置0矩阵)

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Exampl ...

  8. Texas Instruments matrix-gui-2.0 hacking -- json.txt

    { "main_menu": { "apps": [ { "Name":"Profiling", ", &qu ...

  9. Texas Instruments matrix-gui-2.0 hacking -- helper_functions.php

    <?php # PHP_SELF: 但前正在执行脚本的文件名,与document root相关 # QUERY_STRING: 查询(query)的字符串 $cachefile = " ...

随机推荐

  1. win10 操作系统 修改桌面图标

    桌面右击出现菜单后,点击个性化: 点击左边菜单的主题,点击桌面图标设置,在新窗口中选择需要显示的图标接口 details please check following screenshot

  2. 《剑指offer》第十四题(剪绳子)

    // 面试题:剪绳子 // 题目:给你一根长度为n绳子,请把绳子剪成m段(m.n都是整数,n>1并且m≥1). // 每段的绳子的长度记为k[0].k[1].…….k[m].k[0]*k[1]* ...

  3. charles的破解方法

    http://blog.csdn.net/tech4j/article/details/53509329 mac下的charles遇到的问题. http://blog.csdn.net/songzhu ...

  4. Java8 Lambda代码备份

    简单研究了一下,贴出来,相当于笔记 import java.lang.reflect.*; import java.util.ArrayList; import java.util.List; imp ...

  5. 递推2--过河卒(Noip2002)

    递推2--过河卒(Noip2002) 一.心得 写出递推公式就OK了,具体编程还是很简单的 二.题目及分析 过河卒(NOIp2002) [问题描述] 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的 ...

  6. Html概述

    Html概述 主要思想,主要思想很重要 一.Html是什么 一种标记语言(用标签进行标记) 对要显示的文字进行标记 二.Html核心 标签(只认标签) 封装,所以必须有头尾,你才知道标签的范围,你才知 ...

  7. CentOS配置iptables规则并使其永久生效

    1. 目的 最近为了使用nginx,配置远程连接的使用需要使用iptable是设置允许外部访问80端口,但是设置完成后重启总是失效.因此百度了一下如何设置永久生效,并记录.  2. 设置 2.1 添加 ...

  8. Python并行(parallel)之谈

    简介 可以先看看并发Concurrent与并行Parallel的区别 在谈并行前,头脑中总会浮出多线程.多进程.线程/进程同步.线程/进程通信等词语. 那为什么需要同步.通信,它们之间的作用是怎样的呢 ...

  9. BZOJ 1601 [Usaco2008 Oct]灌水 (最小生成树)

    题意 Farmer John已经决定把水灌到他的n(1<=n<=300)块农田,农田被数字1到n标记.把一块土地进行灌水有两种方法,从其他农田饮水,或者这块土地建造水库. 建造一个水库需要 ...

  10. python爬虫-链家租房信息获取

    #导入需要用到的模块 import requests import pymysql import time from bs4 import BeautifulSoup import tkinter a ...