顯示具有 code sample 標籤的文章。 顯示所有文章
顯示具有 code sample 標籤的文章。 顯示所有文章

2010年11月1日 星期一

Sample.c

/*
* $Id: $
*/
/****************************************************************************/
/*
*    Copyright <Company logo>
*/
/****************************************************************************/
/*
* $Log: $
*/
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "global.h"


#ifdef SAMPLE_SUPPORT

#if 1 /* macro */
/*************************************************************
*
* macro
*
*************************************************************/
#endif /* macro */

#if 1 /* prototype */
/**************************************************************
*
* prototype
*
**************************************************************/
#endif /* prototype */

#if 1 /* global variable */
/**************************************************************
*
* global variable
*
**************************************************************/
#endif /* global variable */

#if 1 /* local variable */
/**************************************************************
*
* local variable
*
**************************************************************/
#endif  /* local variable */

#if 1 /* local function */
/**************************************************************
*
* local function
*
**************************************************************/
#endif  /* local function */

#if 1 /* global function */
/**************************************************************
*
* global function
*
**************************************************************/
#endif /* global function */

#endif /* SAMPLE_SUPPORT */

Sample.h

/*
* $Id:  $
*/

/****************************************************************************/
/*
*    Copyright <Company logo>
*/
/****************************************************************************/

/*
* $Log:  $
*/

#ifndef _SAMPLE_H_
#define _SAMPLE_H_

#if 1  /* define */
/**************************************************************
*
* define
*
**************************************************************/
#endif /* define */

#if 1  /* enum */
/**************************************************************
*
* enum
*
**************************************************************/
#endif /* enum */

#if 1  /* type */
/**************************************************************
*
* type
*
**************************************************************/
#endif /* type */

#if 1  /* prototype */
/**************************************************************
*
* prototype
*
**************************************************************/
#endif /* prototype */

#endif /* !_SAMPLE_H_ */

Comment Templete

/*
* Function:
*      <function name>
* Purpose:
*      <purpose>
* Parameters:
*      <p1 name> - <parameter 1 description>
*      <p2 name> - <parameter 2 description>
*      <p3 name> - <parameter 3 description>
* Returns:
*     <error 1 enum>    - <ERROR 1 description>
*     <error 2 enum>    - <ERROR 2 description>
*     <error 3 enum>    - <ERROR 3 description>
*     <error 4 enum>    - <ERROR 4 description>
*     <error 5 enum>    - <ERROR 5 description>
* Notes:
*/

Auto fill function name

/*----------------------------------------------------
*/
/* This file try auto fill funciton name in the begin of debug 20090703 smo
*/
/* Key word: __VA_ARGS__         
*/
/*------------------------------------------------------
*/

#include <stdio.h>
#include <stdarg.h>

/*if no ##, there must be one argument at least. */
#define mldsnppxyFuncPrint(a,...) mldsnppxyDbg(__PRETTY_FUNCTION__,a,##__VA_ARGS__)

int mldsnppxyDbg(char* funcName,char* format,...)
{
    char buffer[256];
    printf("@%s: ",funcName);
    va_list args;
    va_start (args, format);
    vsprintf (buffer,format, args);
    printf (buffer);
    va_end (args);
    return 0;
}

int main()
{
    int testInt=3;
    char testStr[]="smo";
    mldsnppxyFuncPrint("int =%d, string= %s\n\n",testInt,testStr);   
    return 0;
}

Error return

static int
_l2mldpxyHst_insertToGroupDB(
l2mldpxyHstVlanInfo_t * hstInfo_p,
l2mldpxyHstGroup_t *group_p
)
{

int ret=L2MLDPXY_E_NONE;
in6_addr_t * addr_p =(&group_p->groupAddr);
int hashValue=_l2mldpxyHst_hashGroup(addr_p);


l2mldpxyFuncPrint("@_l2mldpxyHst_insertToGroupDB\n");

/*sanity check*/
if (!hstInfo_p){
  ret = -1;
  goto exit;
}


LIST_INSERT_HEAD(hstInfo_p->groupDB[hashValue],group_p,linkHead_hash);

exit:
if (ret) l2mldpxyFuncPrint("Fail! ret code=%d\n", ret); 
return ret;

}