⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fs.c

📁 keil c编写的单片机实现web服务 包含原程序和可执行文件
💻 C
字号:
/* * Copyright (c) 2001, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. 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. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software developed by the Swedish Institute *      of Computer Science and its contributors. * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. * * This file is part of the lwIP TCP/IP stack. * * Author: Adam Dunkels <adam@sics.se> * * $Id: fs.c,v 1.6 2001/11/25 18:47:36 adam Exp $ */#include "uip.h"#include "fs.h"//#include "fsdata.h"#define NULL (void *)0#define FS_ROOT file_index_html//#define FS_NUMFILES 10//extern char debugStr[3000];#ifdef FS_STATISTICS#if FS_STATISTICS == 1static u16_t count[FS_NUMFILES];#endif /* FS_STATISTICS */#endif /* FS_STATISTICS */void fsdata_init();#include "fsdata.c"struct fsdata_file_noconst file_index_html;struct fsdata_file_noconst file_cgi_stats;struct fsdata_file_noconst file_stats_header_html;struct fsdata_file_noconst file_stats_footer_plain;struct fsdata_file_noconst file_cgi_tcp;struct fsdata_file_noconst file_tcp_header_html;struct fsdata_file_noconst file_tcp_footer_plain;struct fsdata_file_noconst file_cgi_files;struct fsdata_file_noconst file_files_header_html;struct fsdata_file_noconst file_files_footer_plain;struct fsdata_file_noconst file_cgi_thermo;struct fsdata_file_noconst file_thermo_header_html;struct fsdata_file_noconst file_thermo_footer_plain;/*-----------------------------------------------------------------------------------*/static u8_tfs_strcmp(const char *str1, const char *str2){  u8_t i;  i = 0; loop:  if(str2[i] == 0 ||     str1[i] == '\r' ||     str1[i] == '\n') {    return 0;  }  if(str1[i] != str2[i]) {    return 1;  }  ++i;  goto loop;}/*-----------------------------------------------------------------------------------*/intfs_open(const char *name, struct fs_file *file){#ifdef FS_STATISTICS#if FS_STATISTICS == 1  u16_t i;#endif /* FS_STATISTICS */#endif /* FS_STATISTICS */  struct fsdata_file_noconst *f; i = 0; for(f = FS_ROOT;     f != NULL;     f = f->next) {    if(fs_strcmp(name, f->f_name) == 0) {	  //strcat(debugStr,"Found ");	  //strcat(debugStr,f->f_name);      file->data = f->f_data;      file->datalen = f->f_len;#ifdef FS_STATISTICS#if FS_STATISTICS == 1      ++count[i];#endif  /* FS_STATISTICS */#endif  /* FS_STATISTICS */      return 1;   }#ifdef FS_STATISTICS#if FS_STATISTICS == 1    ++i;#endif  /* FS_STATISTICS */#endif /* FS_STATISTICS */  }  return 1;}/*-----------------------------------------------------------------------------------*/voidfs_init(void){#ifdef FS_STATISTICS#if FS_STATISTICS == 1  u16_t i;  for(i = 0; i < FS_NUMFILES; i++) {    count[i] = 0;  }#endif /* FS_STATISTICS */#endif /* FS_STATISTICS */  fsdata_init();}/*-----------------------------------------------------------------------------------*/#ifdef FS_STATISTICS#if FS_STATISTICS == 1u16_t fs_count(char *name){  struct fsdata_file_noconst *f;  u16_t i;  i = 0;  for(f = FS_ROOT;      f != NULL;      f = f->next) {    if(fs_strcmp(name, f->f_name) == 0) {      return count[i];    }    ++i;  }  return 0;}#endif /* FS_STATISTICS */#endif /* FS_STATISTICS *//*-----------------------------------------------------------------------------------*/void fsdata_init(){	file_tcp_footer_plain.next = NULL;    file_tcp_footer_plain.f_name = data_tcp_footer_plain;    file_tcp_footer_plain.f_data = &data_tcp_footer_plain[18];    file_tcp_footer_plain.f_len = sizeof(data_tcp_footer_plain) - 18;	file_tcp_header_html.next = file_tcp_footer_plain;    file_tcp_header_html.f_name = data_tcp_header_html;    file_tcp_header_html.f_data = &data_tcp_header_html[17];    file_tcp_header_html.f_len = sizeof(data_tcp_header_html) - 17;	file_cgi_tcp.next = file_tcp_header_html;    file_cgi_tcp.f_name = data_cgi_tcp;    file_cgi_tcp.f_data = &data_cgi_tcp[9];    file_cgi_tcp.f_len = sizeof(data_cgi_tcp) - 9;	file_stats_footer_plain.next = file_cgi_tcp;	file_stats_footer_plain.f_name = data_stats_footer_plain;	file_stats_footer_plain.f_data = &data_stats_footer_plain[20];    file_stats_footer_plain.f_len = sizeof(data_stats_footer_plain) - 20;	file_stats_header_html.next = file_stats_footer_plain;	file_stats_header_html.f_name = data_stats_header_html;	file_stats_header_html.f_data = &data_stats_header_html[19];    file_stats_header_html.f_len = sizeof(data_stats_header_html) - 19;	file_files_footer_plain.next = file_stats_header_html;	file_files_footer_plain.f_name = data_files_footer_plain;	file_files_footer_plain.f_data = &data_files_footer_plain[20];	file_files_footer_plain.f_len = sizeof(data_files_footer_plain) - 20;	file_files_header_html.next = file_files_footer_plain;	file_files_header_html.f_name = data_files_header_html;	file_files_header_html.f_data = &data_files_header_html[19];	file_files_header_html.f_len = sizeof(data_files_header_html) - 19;    file_thermo_footer_plain.next = file_files_header_html;    file_thermo_footer_plain.f_name = data_thermo_footer_plain;    file_thermo_footer_plain.f_data = &data_thermo_footer_plain[21];    file_thermo_footer_plain.f_len = sizeof(data_thermo_footer_plain) - 21;	file_thermo_header_html.next = file_thermo_footer_plain;	file_thermo_header_html.f_name = data_thermo_header_html;	file_thermo_header_html.f_data = &data_thermo_header_html[20];	file_thermo_header_html.f_len = sizeof(data_thermo_header_html) - 20;    file_cgi_thermo.next = file_thermo_header_html;    file_cgi_thermo.f_name = data_cgi_thermo;    file_cgi_thermo.f_data = &data_cgi_thermo[12];    file_cgi_thermo.f_len = sizeof(data_cgi_thermo) - 12;	file_cgi_files.next = file_cgi_thermo;    file_cgi_files.f_name = data_cgi_files;    file_cgi_files.f_data = &data_cgi_files[11];    file_cgi_files.f_len = sizeof(data_cgi_files) - 11;    file_cgi_stats.next = file_cgi_files;	file_cgi_stats.f_name = data_cgi_stats;	file_cgi_stats.f_data = &data_cgi_stats[11];    file_cgi_stats.f_len = sizeof(data_cgi_stats) - 11;    file_index_html.next = file_cgi_stats;    file_index_html.f_name = data_index_html;    file_index_html.f_data = &data_index_html[12];    file_index_html.f_len = sizeof(data_index_html) - 12;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -