事情があって,数字の名前が付いたディレクトリ毎のファイルリストを,リンク付きで一覧表示するプログラムが必要になった.
セレクトボックスでディレクトリ名を指定する.
注意:ここでは動作しません.
/******************************************************************** CGI Program by C Language for FILE LIST OUTPUT ********************************************************************/ #include#include #include int main() { int length; char *query; int data[20]; char szInData[1024]; char *psInData; char szDataArea[2][256]; char szDataAreaName[2][256]; char szCommand[32]; int command; char chcommand; float result,fa,fb; FILE *fp; char out_name[128][128], str[128]; int file_num=0; int i, year=2000; /* In case Request is "GET" */ if( strcmp(getenv("REQUEST_METHOD"),"GET") == 0 ) { length = strlen(getenv("QUERY_STRING")); query = (char *)malloc( length ); strcpy(query,getenv("QUERY_STRING")); } else { /* In case Request is "POST" */ length = atoi(getenv("CONTENT_LENGTH")); query = (char *)malloc( length ); scanf("%s",query); } /*** ***/ if( getenv( "QUERY_STRING" )!=NULL ) { strcpy( szInData, getenv( "QUERY_STRING" ) ); } else { strcpy( szInData, "No Input" ); } /*** Separate Data ***/ strcpy( szDataAreaName[0], strtok( szInData, "=" ) ); strcpy( szDataArea[0], strtok( NULL, "&" ) ); /*** ファイルリストの取得&ファイルに出力 ***/ year = atoi( szDataArea[0] ); /*** Configure the PATH of PDF Files ***/ /*** | | | | | | | | | | | | | | | | ***/ /*** V V V V V V V V V V V V V V V V ***/ sprintf( str, "( cd /home/pdf/%d; ls *pdf ) > /home/httpd/html/cgiout/lst", year ); system( str ); if( NULL==(fp=fopen("/home/httpd/html/cgiout/lst","r")) ) // File Open Error { printf("File Error!"); } else // File Open Succeed { while( fgets( &out_name[file_num][0], 128, fp )!=NULL ) { file_num++; } fclose( fp ); /*** HTML Write ***/ printf( "Content-type: text/html\n\n" ); printf(""); printf(""); printf(" \n"); printf(" \n"); printf("リスト
\n"); for( i=0; i
%s
\n", year, &out_name[i][0], &out_name[i][0] ); } printf(""); printf( "\n" ); } }